Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-mw committed Dec 17, 2024
1 parent 4816d4a commit 9990d43
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\Api\Request\HostingSubscriptionCreateRequest;
use App\Http\Controllers\ApiController;
use App\Jobs\ApacheBuild;
use App\Models\Domain;
use App\Models\HostingSubscription;
use Carbon\Carbon;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function store(HostingSubscriptionCreateRequest $request)

$hostingSubscription->setup_date = Carbon::now();
$hostingSubscription->save();

ApacheBuild::dispatchSync();
return response()->json([
'status' => 'ok',
'message' => 'Hosting subscription created',
Expand Down
28 changes: 23 additions & 5 deletions web/app/Jobs/ApacheBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,40 @@ public function __construct($fixPermissions = false)
*/
public function handle(): void
{
$getAllDomains = Domain::whereNot('status','<=>', 'broken')->get();
$getAllDomains = Domain::whereNot('status', '<=>', 'broken')->get();
$virtualHosts = [];
foreach ($getAllDomains as $domain) {


file_put_contents(storage_path('logs/apache2.log'),1111);

foreach ($getAllDomains as $domain) {
$isBroken = false;
// $findHostingSubscription = \App\Models\HostingSubscription::where('id', $domain->hosting_subscription_id)
// ->first();
// // check is valid domain
// if (!$findHostingSubscription) {
// $isBroken = true;
// }
if ($domain->status === 'broken') {
continue;
}
// check is valid domain
if (!filter_var($domain->domain, FILTER_VALIDATE_DOMAIN)) {
$isBroken = true;
}

if ($isBroken) {
// mark domain as broken
$domain->status = 'broken';
$domain->save();
continue;
}


/* @var Domain $domain */
$virtualHostSettings = $domain->configureVirtualHost($this->fixPermissions);

if(!$virtualHostSettings){
if (!$virtualHostSettings) {
// mark domain as broken
$domain->status = 'broken';
$domain->save();
Expand All @@ -54,7 +72,7 @@ public function handle(): void
if (isset($virtualHostSettings['virtualHostSettings'])) {
$virtualHosts[] = $virtualHostSettings['virtualHostSettings'];
}
if (isset($virtualHostSettings['virtualHostSettingsWithSSL'])) {
if (isset($virtualHostSettings['virtualHostSettingsWithSSL']) and $virtualHostSettings['virtualHostSettingsWithSSL']) {
$virtualHosts[] = $virtualHostSettings['virtualHostSettingsWithSSL'];
}
}
Expand All @@ -67,7 +85,7 @@ public function handle(): void
if (isset($domainVirtualHost['virtualHostSettings'])) {
$virtualHosts[] = $domainVirtualHost['virtualHostSettings'];
}
if (isset($domainVirtualHost['virtualHostSettingsWithSSL'])) {
if (isset($domainVirtualHost['virtualHostSettingsWithSSL']) and $domainVirtualHost['virtualHostSettingsWithSSL']) {
$virtualHosts[] = $domainVirtualHost['virtualHostSettingsWithSSL'];
}
}
Expand Down
23 changes: 12 additions & 11 deletions web/app/MasterDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function configureVirtualHost($fixPermissions = false)
$apacheVirtualHost->setDomainRoot($this->domainRoot);
$apacheVirtualHost->setHomeRoot($this->domainRoot);
$apacheVirtualHost->setServerAdmin($this->email);
$apacheVirtualHost->setDomainAlias('*.'.$this->domain);
$apacheVirtualHost->setDomainAlias('*.' . $this->domain);

$virtualHostSettings = $apacheVirtualHost->getSettings();

Expand Down Expand Up @@ -78,7 +78,7 @@ public function configureVirtualHost($fixPermissions = false)
if ($findDomainSSL) {
$findDomainSSLCertificate = $findDomainSSL;
} else {
$findMainDomainWildcardSSLCertificate = \App\Models\DomainSslCertificate::where('domain', '*.'.$catchMainDomain)
$findMainDomainWildcardSSLCertificate = \App\Models\DomainSslCertificate::where('domain', '*.' . $catchMainDomain)
->first();
if ($findMainDomainWildcardSSLCertificate) {
$findDomainSSLCertificate = $findMainDomainWildcardSSLCertificate;
Expand Down Expand Up @@ -115,13 +115,14 @@ public function configureVirtualHost($fixPermissions = false)
}
file_put_contents($sslCertificateChainFile, $findDomainSSLCertificate->certificate_chain);
}
if (is_file($sslCertificateFile)) {
$apacheVirtualHost->setPort(443);
$apacheVirtualHost->setSSLCertificateFile($sslCertificateFile);
$apacheVirtualHost->setSSLCertificateKeyFile($sslCertificateKeyFile);
$apacheVirtualHost->setSSLCertificateChainFile($sslCertificateChainFile);

$apacheVirtualHost->setPort(443);
$apacheVirtualHost->setSSLCertificateFile($sslCertificateFile);
$apacheVirtualHost->setSSLCertificateKeyFile($sslCertificateKeyFile);
$apacheVirtualHost->setSSLCertificateChainFile($sslCertificateChainFile);

$virtualHostSettingsWithSSL = $apacheVirtualHost->getSettings();
$virtualHostSettingsWithSSL = $apacheVirtualHost->getSettings();
}

}
// End install SSL
Expand All @@ -131,15 +132,15 @@ public function configureVirtualHost($fixPermissions = false)
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);
$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);
}
if(!is_dir($this->domainPublic)){
if (!is_dir($this->domainPublic)) {
return false;
}

Expand Down

0 comments on commit 9990d43

Please sign in to comment.