This commit is contained in:
Bozhidar 2024-05-14 12:33:01 +03:00
parent b94b1083b3
commit 5c646346e2
2 changed files with 13 additions and 24 deletions

View file

@ -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) {

View file

@ -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');