From bbbd857ca695b94cc5bd1c5cbb9db5568f3e5991 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Wed, 15 May 2024 13:16:44 +0300 Subject: [PATCH] update --- web/app/Console/Commands/RunRepair.php | 11 +- web/app/Jobs/ApacheBuild.php | 5 +- web/app/Models/Domain.php | 13 ++ .../samples/apache/html/app-broken-page.html | 186 ++++++++++++++++++ 4 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 web/resources/views/actions/samples/apache/html/app-broken-page.html diff --git a/web/app/Console/Commands/RunRepair.php b/web/app/Console/Commands/RunRepair.php index 3287c72..6b44856 100644 --- a/web/app/Console/Commands/RunRepair.php +++ b/web/app/Console/Commands/RunRepair.php @@ -61,8 +61,9 @@ class RunRepair extends Command public function fixApacheErrors() { - // Restart Apache - shell_exec('service apache2 restart'); + // Rebuild apache config + $apacheBuild = new ApacheBuild(); + $apacheBuild->handle(); $checkApacheStatus = shell_exec('service apache2 status'); @@ -99,17 +100,21 @@ class RunRepair extends Command } if (count($apacheBrokenVirtualHosts) > 0) { + $this->error('Broken virtual hosts found'); + foreach ($apacheBrokenVirtualHosts as $brokenVirtualHost) { $this->error('Virtual host found: ' . $brokenVirtualHost['ServerName']); $this->error('Turn on maintenance mode: ' . $brokenVirtualHost['ServerName']); $findDomain = Domain::where('domain', $brokenVirtualHost['ServerName'])->first(); if ($findDomain) { - $findDomain->status = Domain::STATUS_SUSPENDED; + $findDomain->status = Domain::STATUS_BROKEN; $findDomain->save(); } } + $this->info('Run apache build...'); + $apacheBuild = new ApacheBuild(); $apacheBuild->handle(); } diff --git a/web/app/Jobs/ApacheBuild.php b/web/app/Jobs/ApacheBuild.php index cd5b643..4b24dea 100644 --- a/web/app/Jobs/ApacheBuild.php +++ b/web/app/Jobs/ApacheBuild.php @@ -29,7 +29,7 @@ class ApacheBuild implements ShouldQueue */ public function handle(): void { - $getAllDomains = Domain::all(); + $getAllDomains = Domain::whereNot('status','<=>', 'broken')->get(); $virtualHosts = []; foreach ($getAllDomains as $domain) { $virtualHostSettings = $domain->configureVirtualHost(); @@ -41,7 +41,6 @@ class ApacheBuild implements ShouldQueue } } - // Make master domain virtual host if (!empty(setting('general.master_domain'))) { // Make master domain virtual host @@ -74,6 +73,8 @@ class ApacheBuild implements ShouldQueue 'virtualHosts' => $virtualHosts ])->render(); + $apache2 = preg_replace('~(*ANY)\A\s*\R|\s*(?!\r\n)\s$~mu', '', $apache2); + file_put_contents('/etc/apache2/apache2.conf', $apache2); shell_exec('systemctl reload apache2'); diff --git a/web/app/Models/Domain.php b/web/app/Models/Domain.php index 7207811..01664d3 100644 --- a/web/app/Models/Domain.php +++ b/web/app/Models/Domain.php @@ -20,6 +20,8 @@ class Domain extends Model public const STATUS_DELETED = 'deleted'; public const STATUS_DEACTIVATED = 'deactivated'; + public const STATUS_BROKEN = 'broken'; + protected $fillable = [ 'domain', 'domain_root', @@ -272,6 +274,17 @@ class Domain extends Model } $apacheVirtualHostBuilder->setDomainRoot($deactivatedPath); $apacheVirtualHostBuilder->setDomainPublic($deactivatedPath); + } else if ($this->status == self::STATUS_BROKEN) { + $brokenPath = '/var/www/html/broken'; + if (!is_dir($brokenPath)) { + mkdir($brokenPath, 0755, true); + } + if (!is_file($brokenPath . '/index.html')) { + $brokenPageHtmlPath = base_path('resources/views/actions/samples/apache/html/app-broken-page.html'); + file_put_contents($brokenPath . '/index.html', file_get_contents($brokenPageHtmlPath)); + } + $apacheVirtualHostBuilder->setDomainRoot($brokenPath); + $apacheVirtualHostBuilder->setDomainPublic($brokenPath); } else { // $apacheVirtualHostBuilder->setEnableLogs(true); diff --git a/web/resources/views/actions/samples/apache/html/app-broken-page.html b/web/resources/views/actions/samples/apache/html/app-broken-page.html new file mode 100644 index 0000000..bda838e --- /dev/null +++ b/web/resources/views/actions/samples/apache/html/app-broken-page.html @@ -0,0 +1,186 @@ + + + + Phyre Panel - Website is broken + + + + + + + + + + + +
+ +
+
+

+ Website is broken +

+

+ Please contact your administrator. +

+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +