From 38aab1e37bc2336028c1337aead19c27696c7146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Thu, 16 Mar 2023 20:54:09 +0100 Subject: [PATCH] fix default and catch all hosts --- src/VirtualHostGenerator.php | 12 ++++--- templates/config-based-virtual-host.twig | 3 +- templates/config.twig | 46 ------------------------ 3 files changed, 8 insertions(+), 53 deletions(-) diff --git a/src/VirtualHostGenerator.php b/src/VirtualHostGenerator.php index 6428fd0..147ad1a 100644 --- a/src/VirtualHostGenerator.php +++ b/src/VirtualHostGenerator.php @@ -68,7 +68,6 @@ private function buildHostList(\PDOStatement $statement, array &$virtualhosts, s } $virtualhosts[] = [ 'domain' => $vhost, - 'vhost' => $vhost, 'webroot' => $row['extra_webroot'] === '1' ? "/var/$vhost/public" : "/var/$vhost", 'root' => "/var/$vhost", 'admin' => $row['admin'], @@ -100,7 +99,7 @@ private function buildDefaultHostList(\PDOStatement $statement, array &$virtualh } $virtualhosts[] = [ 'domain' => $vhost, - 'vhost' => '*.' . $row['domain'], + 'aliases' => ['*.' . $row['domain']], 'webroot' => "/var/www/public", 'root' => "/var/www", 'admin' => $row['admin'], @@ -118,7 +117,7 @@ private function buildServerHost(string $hostname, string $admin, array &$virtua } $virtualhosts[] = [ 'domain' => $hostname, - 'vhost' => $hostname, + 'aliases' => ['*'], 'webroot' => "/var/www/public", 'root' => "/var/www", 'admin' => $admin, @@ -141,13 +140,16 @@ public function create() $stmt = $this->database->prepare("SELECT domain.domain, domain.admin FROM domain"); $stmt->execute(); $defaulthosts = []; + $this->buildDefaultHostList($stmt, $defaulthosts, $ip); $stmt = $this->database->prepare('SELECT admin FROM server WHERE hostname=:hostname'); $stmt->execute([':hostname' => $hostname]); $this->buildServerHost($hostname, $stmt->fetchColumn(), $virtualhosts, $ip); - $this->buildDefaultHostList($stmt, $defaulthosts, $ip); file_put_contents( '/etc/apache2/sites-enabled/all.conf', - $this->twig->render('config.twig', ['virtualhosts' => $virtualhosts, 'defaulthosts' => $defaulthosts]) + $this->twig->render('config.twig', [ + 'virtualhosts' => $virtualhosts, + 'defaulthosts' => $defaulthosts, + ]) ); exec("service apache2 start"); } diff --git a/templates/config-based-virtual-host.twig b/templates/config-based-virtual-host.twig index 78f5e95..eba6078 100644 --- a/templates/config-based-virtual-host.twig +++ b/templates/config-based-virtual-host.twig @@ -1,6 +1,5 @@ ServerAdmin {{ host.admin }} -{% if host.vhost starts with '*' %}Servername {{ host.domain }} -ServerAlias {{ host.vhost }}{% else %}Servername {{ host.vhost }}{% endif %} +Servername {{ host.domain }} {% for alias in host.aliases %} diff --git a/templates/config.twig b/templates/config.twig index dd22d40..860f7cc 100644 --- a/templates/config.twig +++ b/templates/config.twig @@ -15,7 +15,6 @@ {% endfor %} {% for host in defaulthosts %} - {% set default_domain=host.domain %} {% include 'config-based-virtual-host.twig' %} @@ -36,48 +35,3 @@ SSLCertificateChainFile /etc/letsencrypt/live/{{ host.domain }}/chain.pem {% endfor %} - - DocumentRoot /var/www/public - ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ - - Options +FollowSymLinks - AllowOverride None - Require all denied - - - Options +ExecCGI -Indexes +FollowSymLinks +MultiViews - AllowOverride All - Require all granted - - - AllowOverride None - Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch - Require all granted - - - SSLEngine Off - RewriteEngine On - RewriteRule (.*) https://{{ default_domain }}$1 [R,L] - - - DocumentRoot /var/www/public - ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ - - Options +FollowSymLinks - AllowOverride None - Require all denied - - - Options +ExecCGI -Indexes +FollowSymLinks +MultiViews - AllowOverride All - Require all granted - - - AllowOverride None - Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch - Require all granted - - - RewriteEngine On - RewriteRule (.*) https://{{ default.domain }}$1 [R,L] -