From 5c646346e25a743bbdbaaf57d21e977644d6398a Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Tue, 14 May 2024 12:33:01 +0300 Subject: [PATCH] update --- web/app/Models/Domain.php | 32 ++++++------------- .../Unit/AHostingSubscriptionCreateTest.php | 5 +-- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/web/app/Models/Domain.php b/web/app/Models/Domain.php index 0a3dddb..ec67050 100644 --- a/web/app/Models/Domain.php +++ b/web/app/Models/Domain.php @@ -6,6 +6,7 @@ use App\Actions\ApacheWebsiteDelete; use App\Events\DomainIsCreated; use App\Events\ModelDomainDeleting; use App\ShellApi; +use App\VirtualHosts\ApacheBuild; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Modules\Docker\App\Models\DockerContainer; @@ -76,18 +77,23 @@ class Domain extends Model $model->save(); - $model->configureVirtualHost(); + $model->configureVirtualHost(true); event(new DomainIsCreated($model)); }); static::updating(function ($model) { - $model->configureVirtualHost(); + $model->configureVirtualHost(true); }); static::saved(function ($model) { - $model->configureVirtualHost(); + + $model->configureVirtualHost(true); + + $apacheBuild = new ApacheBuild(); + $apacheBuild->build(); + }); static::deleting(function ($model) { @@ -102,24 +108,6 @@ class Domain extends Model ShellApi::safeDelete($model->domain_root, ['/home/' . $findHostingSubscription->system_username]); - $whiteListedPathsForDelete = [ - '/etc/apache2/sites-available', - '/etc/apache2/sites-enabled', - ]; - - $apacheConf = '/etc/apache2/sites-available/'.$model->domain.'.conf'; - ShellApi::safeDelete($apacheConf, $whiteListedPathsForDelete); - - $apacheConfEnabled = '/etc/apache2/sites-enabled/'.$model->domain.'.conf'; - ShellApi::safeDelete($apacheConfEnabled, $whiteListedPathsForDelete); - - // SSL - $apacheSSLConf = '/etc/apache2/sites-available/'.$model->domain.'-ssl.conf'; - ShellApi::safeDelete($apacheSSLConf, $whiteListedPathsForDelete); - - $apacheSSLConfEnabled = '/etc/apache2/sites-enabled/'.$model->domain.'-ssl.conf'; - ShellApi::safeDelete($apacheSSLConfEnabled, $whiteListedPathsForDelete); - }); } @@ -342,7 +330,7 @@ class Domain extends Model // Certificate setup - + $catchMainDomain = ''; $domainExp = explode('.', $this->domain); if (count($domainExp) > 0) { diff --git a/web/tests/Unit/AHostingSubscriptionCreateTest.php b/web/tests/Unit/AHostingSubscriptionCreateTest.php index 57f4514..4864969 100644 --- a/web/tests/Unit/AHostingSubscriptionCreateTest.php +++ b/web/tests/Unit/AHostingSubscriptionCreateTest.php @@ -171,10 +171,11 @@ class AHostingSubscriptionCreateTest extends ActionTestCase $domainData = $callDomainDetailsResponseData[0]; // Check virtual host is created - $virtualHostFile = '/etc/apache2/sites-available/'.$hostingSubscriptionDomain.'.conf'; + $virtualHostFile = '/etc/apache2/apache2.conf'; $this->assertFileExists($virtualHostFile); $virtualHostFileContent = file_get_contents($virtualHostFile); + $this->assertStringContainsString('ServerName '.$hostingSubscriptionDomain, $virtualHostFileContent); //$this->assertStringContainsString('ServerAlias www.'.$hostingSubscriptionDomain, $virtualHostFileContent); @@ -183,7 +184,7 @@ class AHostingSubscriptionCreateTest extends ActionTestCase $this->assertStringContainsString('php_admin_value open_basedir '.$domainData['home_root'], $virtualHostFileContent); // Check virtual host is enabled - $this->assertFileExists('/etc/apache2/sites-enabled/'.$hostingSubscriptionDomain.'.conf'); + $this->assertFileExists('/etc/apache2/apache2.conf'); // Check apache config is valid shell_exec('apachectl -t >> /tmp/apache_config_check.txt 2>&1');