Bozhidar Slaveykov 1 年之前
父節點
當前提交
f3ac1486a5

+ 3 - 3
web/Modules/LetsEncrypt/Listeners/HostingAccountIsCreatedListener.php

@@ -31,6 +31,7 @@ class HostingAccountIsCreatedListener
         $acmeConfigYaml = view('letsencrypt::actions.acme-config-yaml', [
         $acmeConfigYaml = view('letsencrypt::actions.acme-config-yaml', [
             'domain' => $event->model->domain,
             'domain' => $event->model->domain,
             'domainRoot' => $event->model->domain_root,
             'domainRoot' => $event->model->domain_root,
+            'domainPublic' => $event->model->domain_public,
             'email' => $generalSettings['master_email'],
             'email' => $generalSettings['master_email'],
             'country' => $generalSettings['master_country'],
             'country' => $generalSettings['master_country'],
             'locality' => $generalSettings['master_locality'],
             'locality' => $generalSettings['master_locality'],
@@ -45,9 +46,8 @@ class HostingAccountIsCreatedListener
         $phyrePHP = ApiClient::getPhyrePHP();
         $phyrePHP = ApiClient::getPhyrePHP();
         $phyrePHP = 'php';
         $phyrePHP = 'php';
 
 
-//        $command = $phyrePHP . ' ' . $amePHPPharFile . ' run ' . $event->model->domain_root . '/acme-config.yaml';
-//        $execPhar = ShellApi::exec($command);
-
+        $command = $phyrePHP . ' ' . $amePHPPharFile . ' run ' . $event->model->domain_root . '/acme-config.yaml';
+        $execPhar = ShellApi::exec($command);
 
 
         $validateCertificates = [];
         $validateCertificates = [];
         $sslCertificateFilePath = '/root/.acmephp/master/certs/'.$event->model->domain.'/public/cert.pem';
         $sslCertificateFilePath = '/root/.acmephp/master/certs/'.$event->model->domain.'/public/cert.pem';

+ 8 - 2
web/app/Actions/ApacheWebsiteCreate.php

@@ -48,10 +48,13 @@ class ApacheWebsiteCreate
             $linuxUser = $getLinuxUser->handle();
             $linuxUser = $getLinuxUser->handle();
         }
         }
 
 
+        $domainRoot = '/home/'.$this->user.'/domains/'.$this->domain;
         $settings = [
         $settings = [
             'port'=> 80,
             'port'=> 80,
             'domain' => $this->domain,
             'domain' => $this->domain,
-            'domainRoot' => '/var/www/'.$this->domain,
+            'domainPublic' => $domainRoot. '/public_html',
+            'domainRoot' => $domainRoot,
+            'homeRoot' => '/home/'.$this->user,
             'user' => $this->user,
             'user' => $this->user,
             'group' => 'www-data',
             'group' => 'www-data',
         ];
         ];
@@ -68,10 +71,13 @@ class ApacheWebsiteCreate
         ShellApi::exec('a2ensite '.$settings['domain'].'.conf');
         ShellApi::exec('a2ensite '.$settings['domain'].'.conf');
         ShellApi::exec('systemctl reload apache2');
         ShellApi::exec('systemctl reload apache2');
 
 
-        $fileManagerApi->filePutContents($settings['domainRoot'].'/index.php', "PHP Time: <?php echo time(); ?> Domain: " . $settings['domain']);
+        $fileManagerApi->filePutContents($settings['domainPublic'].'/index.php', "PHP Time: <?php echo time(); ?> Domain: " . $settings['domain']);
 
 
         return [
         return [
             'domain' => $this->domain,
             'domain' => $this->domain,
+            'domainPublic' => $settings['domainPublic'],
+            'domainRoot' => $settings['domainRoot'],
+            'homeRoot' => $settings['homeRoot'],
             'user' => $this->user,
             'user' => $this->user,
             'email' => $this->email,
             'email' => $this->email,
             'linuxUser' => $linuxUser,
             'linuxUser' => $linuxUser,

+ 11 - 1
web/app/Listeners/ModelWebsiteCreatingListener.php

@@ -6,6 +6,8 @@ use App\Actions\ApacheWebsiteCreate;
 use App\Events\ModelWebsiteCreating;
 use App\Events\ModelWebsiteCreating;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Support\Str;
+use function Symfony\Component\String\u;
 
 
 class ModelWebsiteCreatingListener
 class ModelWebsiteCreatingListener
 {
 {
@@ -24,7 +26,8 @@ class ModelWebsiteCreatingListener
     {
     {
         $model = $event->model;
         $model = $event->model;
 
 
-        $username = md5($model->domain);
+        $username = Str::slug($model->domain);
+
         $email = $username . '@phyrepanel.test';
         $email = $username . '@phyrepanel.test';
         $password = uniqid();
         $password = uniqid();
 
 
@@ -37,6 +40,13 @@ class ModelWebsiteCreatingListener
         $create = $newApacheWebsite->handle();
         $create = $newApacheWebsite->handle();
 
 
         if (!empty($create)) {
         if (!empty($create)) {
+
+            $model->domain_username = $username;
+            $model->home_root = $create['homeRoot'];
+            $model->domain_root = $create['domainRoot'];
+            $model->domain_public = $create['domainPublic'];
+            $model->save();
+
             event(new \App\Events\HostingAccountIsCreated($model));
             event(new \App\Events\HostingAccountIsCreated($model));
         }
         }
 
 

+ 4 - 0
web/database/migrations/2023_11_23_214342_create_websites_table.php

@@ -17,9 +17,13 @@ return new class extends Migration
             $table->string('domain');
             $table->string('domain');
             $table->string('ip')->nullable();
             $table->string('ip')->nullable();
             $table->string('domain_root');
             $table->string('domain_root');
+            $table->string('domain_public');
+            $table->string('domain_username');
+            $table->string('home_root');
             $table->string('screenshot')->nullable();
             $table->string('screenshot')->nullable();
             $table->integer('user_id')->nullable();
             $table->integer('user_id')->nullable();
             $table->integer('is_active')->nullable();
             $table->integer('is_active')->nullable();
+            $table->integer('is_secure_with_ssl')->nullable();
 
 
             $table->timestamps();
             $table->timestamps();
         });
         });

+ 2 - 15
web/resources/views/actions/samples/ubuntu/apache2-conf.blade.php

@@ -1,28 +1,15 @@
 <VirtualHost *:{{$port}}>
 <VirtualHost *:{{$port}}>
 
 
     ServerName {{$domain}}
     ServerName {{$domain}}
-    DocumentRoot {{$domainRoot}}
+    DocumentRoot {{$domainPublic}}
     SetEnv APP_DOMAIN {{$domain}}
     SetEnv APP_DOMAIN {{$domain}}
 
 
-{{--    ErrorLog /var/log/apache2/error_{{$domain}}.log
-    CustomLog /var/log/apache2/access_{{$domain}}.log combined--}}
-
-    <Directory {{$domainRoot}}>
+    <Directory {{$domainPublic}}>
         Options Indexes FollowSymLinks MultiViews
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         AllowOverride All
         Require all granted
         Require all granted
 
 
     </Directory>
     </Directory>
 
 
-{{--
-    RewriteEngine on
-    RewriteCond %{SERVER_NAME} =$domain
-    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
-
-    SSLEngine on
-    SSLCertificateFile /etc/apache2/ssl/multiweber.com.pem
-    SSLCertificateKeyFile /etc/apache2/ssl/multiweber.com.key
---}}
-
 </VirtualHost>
 </VirtualHost>
 
 

+ 2 - 2
web/resources/views/actions/samples/ubuntu/apache2-ssl-conf.blade.php

@@ -2,10 +2,10 @@
     <VirtualHost *:{{$port}}>
     <VirtualHost *:{{$port}}>
 
 
         ServerName {{$domain}}
         ServerName {{$domain}}
-        DocumentRoot {{$domainRoot}}/public_html
+        DocumentRoot {{$domainPublic}}
         SetEnv APP_DOMAIN {{$domain}}
         SetEnv APP_DOMAIN {{$domain}}
 
 
-        <Directory {{$domainRoot}}/public_html>
+        <Directory {{$domainPublic}}>
         Options Indexes FollowSymLinks MultiViews
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         AllowOverride All
         Require all granted
         Require all granted