2024-05-14 09:12:10 +00:00
|
|
|
<?php
|
|
|
|
|
2024-05-15 08:15:51 +00:00
|
|
|
namespace App\Jobs;
|
2024-05-14 09:12:10 +00:00
|
|
|
|
2024-05-14 10:15:26 +00:00
|
|
|
use App\MasterDomain;
|
2024-05-14 09:12:10 +00:00
|
|
|
use App\Models\Domain;
|
2024-05-15 08:15:51 +00:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2024-05-14 09:12:10 +00:00
|
|
|
|
2024-05-15 08:15:51 +00:00
|
|
|
class ApacheBuild implements ShouldQueue
|
2024-05-14 09:12:10 +00:00
|
|
|
{
|
2024-05-15 08:15:51 +00:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
2024-05-14 09:40:53 +00:00
|
|
|
|
|
|
|
public $fixPermissions = false;
|
|
|
|
|
2024-05-15 08:15:51 +00:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*/
|
|
|
|
public function __construct($fixPermissions = false)
|
2024-05-14 09:40:53 +00:00
|
|
|
{
|
2024-05-15 08:15:51 +00:00
|
|
|
$this->fixPermissions = $fixPermissions;
|
2024-05-14 09:40:53 +00:00
|
|
|
}
|
|
|
|
|
2024-05-15 08:15:51 +00:00
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*/
|
|
|
|
public function handle(): void
|
2024-05-14 09:12:10 +00:00
|
|
|
{
|
2024-05-15 10:16:44 +00:00
|
|
|
$getAllDomains = Domain::whereNot('status','<=>', 'broken')->get();
|
2024-05-14 11:36:59 +00:00
|
|
|
$virtualHosts = [];
|
2024-05-14 09:12:10 +00:00
|
|
|
foreach ($getAllDomains as $domain) {
|
2024-09-10 13:52:01 +00:00
|
|
|
$virtualHostSettings = $domain->configureVirtualHost($this->fixPermissions);
|
2024-05-14 11:36:59 +00:00
|
|
|
if (isset($virtualHostSettings['virtualHostSettings'])) {
|
|
|
|
$virtualHosts[] = $virtualHostSettings['virtualHostSettings'];
|
2024-05-14 10:15:26 +00:00
|
|
|
}
|
2024-05-14 11:36:59 +00:00
|
|
|
if (isset($virtualHostSettings['virtualHostSettingsWithSSL'])) {
|
|
|
|
$virtualHosts[] = $virtualHostSettings['virtualHostSettingsWithSSL'];
|
2024-05-14 10:15:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-14 13:23:26 +00:00
|
|
|
// 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'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-14 11:36:59 +00:00
|
|
|
$apache2 = view('actions.samples.ubuntu.apache2-conf-build', [
|
2024-08-26 11:57:04 +00:00
|
|
|
'virtualHosts' => $virtualHosts,
|
|
|
|
'serverName' => setting('general.master_domain') ?? 'localhost',
|
2024-05-14 11:36:59 +00:00
|
|
|
])->render();
|
2024-05-14 10:15:26 +00:00
|
|
|
|
2024-05-15 10:16:44 +00:00
|
|
|
$apache2 = preg_replace('~(*ANY)\A\s*\R|\s*(?!\r\n)\s$~mu', '', $apache2);
|
|
|
|
|
2024-05-14 11:36:59 +00:00
|
|
|
file_put_contents('/etc/apache2/apache2.conf', $apache2);
|
2024-05-14 09:12:10 +00:00
|
|
|
|
2024-06-14 13:53:33 +00:00
|
|
|
shell_exec('systemctl reload apache2'); // IMPORTANT: MUST BE RELOAD! NOT RESTART!
|
2024-05-15 09:59:08 +00:00
|
|
|
|
2024-05-14 09:12:10 +00:00
|
|
|
}
|
|
|
|
}
|