From dc7037cd5b4af9e47b21af345721ba4ffc679c4b Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Tue, 14 May 2024 16:23:26 +0300 Subject: [PATCH] update --- web/app/MasterDomain.php | 52 +++++++++---------- web/app/VirtualHosts/ApacheBuild.php | 29 +++++++++++ ...ldOriginal.php => ApacheBuildOriginal.txt} | 0 ...ilder.php => ApacheVirtualHostBuilder.txt} | 0 4 files changed, 55 insertions(+), 26 deletions(-) rename web/app/VirtualHosts/{ApacheBuildOriginal.php => ApacheBuildOriginal.txt} (100%) rename web/app/VirtualHosts/{ApacheVirtualHostBuilder.php => ApacheVirtualHostBuilder.txt} (100%) diff --git a/web/app/MasterDomain.php b/web/app/MasterDomain.php index 7ce6bb4..66b4b88 100644 --- a/web/app/MasterDomain.php +++ b/web/app/MasterDomain.php @@ -3,6 +3,7 @@ namespace App; use App\Models\DomainSslCertificate; +use App\VirtualHosts\DTO\ApacheVirtualHostSettings; class MasterDomain { @@ -39,15 +40,15 @@ class MasterDomain return false; } - $apacheVirtualHostBuilder = new \App\VirtualHosts\ApacheVirtualHostBuilder(); - $apacheVirtualHostBuilder->setDomain($this->domain); - $apacheVirtualHostBuilder->setDomainPublic($this->domainPublic); - $apacheVirtualHostBuilder->setDomainRoot($this->domainRoot); - $apacheVirtualHostBuilder->setHomeRoot($this->domainRoot); - $apacheVirtualHostBuilder->setServerAdmin($this->email); - $apacheVirtualHostBuilder->setDomainAlias('*.'.$this->domain); + $apacheVirtualHost = new ApacheVirtualHostSettings(); + $apacheVirtualHost->setDomain($this->domain); + $apacheVirtualHost->setDomainPublic($this->domainPublic); + $apacheVirtualHost->setDomainRoot($this->domainRoot); + $apacheVirtualHost->setHomeRoot($this->domainRoot); + $apacheVirtualHost->setServerAdmin($this->email); + $apacheVirtualHost->setDomainAlias('*.'.$this->domain); - $apacheBaseConfig = $apacheVirtualHostBuilder->buildConfig(); + $virtualHostSettings = $apacheVirtualHost->getSettings(); if ($fixPermissions) { shell_exec('mkdir -p /var/www/logs/apache2'); @@ -85,7 +86,7 @@ class MasterDomain } } - $apacheBaseConfigWithSSL = null; + $virtualHostSettingsWithSSL = null; if ($findDomainSSLCertificate) { @@ -115,34 +116,33 @@ class MasterDomain file_put_contents($sslCertificateChainFile, $findDomainSSLCertificate->certificate_chain); } - $apacheVirtualHostBuilder->setPort(443); - $apacheVirtualHostBuilder->setSSLCertificateFile($sslCertificateFile); - $apacheVirtualHostBuilder->setSSLCertificateKeyFile($sslCertificateKeyFile); - $apacheVirtualHostBuilder->setSSLCertificateChainFile($sslCertificateChainFile); - - $apacheBaseConfigWithSSL = $apacheVirtualHostBuilder->buildConfig(); + $apacheVirtualHost->setPort(443); + $apacheVirtualHost->setSSLCertificateFile($sslCertificateFile); + $apacheVirtualHost->setSSLCertificateKeyFile($sslCertificateKeyFile); + $apacheVirtualHost->setSSLCertificateChainFile($sslCertificateChainFile); + $virtualHostSettingsWithSSL = $apacheVirtualHost->getSettings(); } // End install SSL if ($fixPermissions) { - $domainIndexFile = $this->domainPublic . '/index.html'; - if (file_exists($domainIndexFile)) { - $domainIndexFileContent = file_get_contents($domainIndexFile); - if (str_contains($domainIndexFileContent, 'Apache2 Debian Default Page')) { - $indexContent = file_get_contents(base_path('resources/views/actions/samples/apache/html/app-index.html')); - file_put_contents($this->domainPublic . '/index.html', $indexContent); + $domainIndexFile = $this->domainPublic . '/index.html'; + if (file_exists($domainIndexFile)) { + $domainIndexFileContent = file_get_contents($domainIndexFile); + if (str_contains($domainIndexFileContent, 'Apache2 Debian Default Page')) { + $indexContent = file_get_contents(base_path('resources/views/actions/samples/apache/html/app-index.html')); + file_put_contents($this->domainPublic . '/index.html', $indexContent); + } } - } - shell_exec('chown -R www-data:www-data ' . $this->domainPublic); - shell_exec('chmod -R 755 ' . $this->domainPublic); + shell_exec('chown -R www-data:www-data ' . $this->domainPublic); + shell_exec('chmod -R 755 ' . $this->domainPublic); } return [ - 'apacheBaseConfig' => $apacheBaseConfig, - 'apacheBaseConfigWithSSL' => $apacheBaseConfigWithSSL ?? null + 'virtualHostSettings' => $virtualHostSettings, + 'virtualHostSettingsWithSSL' => $virtualHostSettingsWithSSL ?? null ]; } diff --git a/web/app/VirtualHosts/ApacheBuild.php b/web/app/VirtualHosts/ApacheBuild.php index 8bf7d08..50260eb 100644 --- a/web/app/VirtualHosts/ApacheBuild.php +++ b/web/app/VirtualHosts/ApacheBuild.php @@ -29,6 +29,35 @@ class ApacheBuild } } + + // Make master domain virtual host + if (!empty(setting('general.master_domain'))) { + // Make master domain virtual host + $masterDomain = new MasterDomain(); + $domainVirtualHost = $masterDomain->configureVirtualHost(); + if (isset($domainVirtualHost['virtualHostSettings'])) { + $virtualHosts[] = $domainVirtualHost['virtualHostSettings']; + } + if (isset($domainVirtualHost['virtualHostSettingsWithSSL'])) { + $virtualHosts[] = $domainVirtualHost['virtualHostSettingsWithSSL']; + } + } + + // Make wildcard domain virtual host + $wildcardDomain = setting('general.wildcard_domain'); + if (!empty($wildcardDomain)) { + // Make wildcard domain virtual host + $masterDomain = new MasterDomain(); + $masterDomain->domain = $wildcardDomain; + $domainVirtualHost = $masterDomain->configureVirtualHost(); + if (isset($domainVirtualHost['virtualHostSettings'])) { + $virtualHosts[] = $domainVirtualHost['virtualHostSettings']; + } + if (isset($domainVirtualHost['virtualHostSettingsWithSSL'])) { + $virtualHosts[] = $domainVirtualHost['virtualHostSettingsWithSSL']; + } + } + $apache2 = view('actions.samples.ubuntu.apache2-conf-build', [ 'virtualHosts' => $virtualHosts ])->render(); diff --git a/web/app/VirtualHosts/ApacheBuildOriginal.php b/web/app/VirtualHosts/ApacheBuildOriginal.txt similarity index 100% rename from web/app/VirtualHosts/ApacheBuildOriginal.php rename to web/app/VirtualHosts/ApacheBuildOriginal.txt diff --git a/web/app/VirtualHosts/ApacheVirtualHostBuilder.php b/web/app/VirtualHosts/ApacheVirtualHostBuilder.txt similarity index 100% rename from web/app/VirtualHosts/ApacheVirtualHostBuilder.php rename to web/app/VirtualHosts/ApacheVirtualHostBuilder.txt