Skip to content

Commit

Permalink
adding atatus api-key for sub-group usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn Büttner committed Jun 27, 2023
1 parent e30d244 commit 6a40db1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
12 changes: 11 additions & 1 deletion bin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@
DB_PASSWORD=$password
DB_HOST=$host");
$pdo = new PDO("mysql:dbname=$database;host=$host", $username, $password);
$pdo->exec("CREATE TABLE `owner` (
`aid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL COLLATE 'ascii_bin',
`atatus_license_key` VARCHAR(255) NOT NULL COLLATE 'ascii_bin',
PRIMARY KEY (`aid`) USING BTREE
)
COLLATE='ascii_bin'
ENGINE=InnoDB;");
$pdo->exec("CREATE TABLE `domain` (
`aid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`domain` VARCHAR(255) NULL DEFAULT NULL COLLATE 'ascii_bin',
`admin` VARCHAR(255) NOT NULL COLLATE 'ascii_bin',
`owner` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`aid`) USING BTREE,
UNIQUE INDEX `domain` (`domain`) USING BTREE
UNIQUE INDEX `domain` (`domain`) USING BTREE,
CONSTRAINT `owner` FOREIGN KEY (`owner`) REFERENCES `virtualhosts`.`owner` (`aid`) ON UPDATE NO ACTION ON DELETE CASCADE
)
COLLATE='ascii_bin'
ENGINE=InnoDB;");
Expand Down
11 changes: 7 additions & 4 deletions src/VirtualHostGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace De\Idrinth\WebRoot;

use PDO;
use PDOStatement;
use Twig\Environment;

class VirtualHostGenerator
Expand Down Expand Up @@ -34,7 +35,7 @@ private function certificate(string $vhost, string $admin): bool
}
return true;
}
private function buildHostList(\PDOStatement $statement, array &$virtualhosts, string $ip): void
private function buildHostList(PDOStatement $statement, array &$virtualhosts, string $ip): void
{
foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) {
$vhost = trim($row['name'] . '.' . $row['domain'], '.');
Expand Down Expand Up @@ -71,7 +72,8 @@ private function buildHostList(\PDOStatement $statement, array &$virtualhosts, s
'webroot' => $row['extra_webroot'] === '1' ? "/var/$vhost/public" : "/var/$vhost",
'root' => "/var/$vhost",
'admin' => $row['admin'],
'aliases' => $aliases
'aliases' => $aliases,
'atatus_license_key' => $row['atatus_license_key'],
];
if (!is_dir('/var/' . $vhost)) {
mkdir('/var/' . $vhost);
Expand All @@ -83,7 +85,7 @@ private function buildHostList(\PDOStatement $statement, array &$virtualhosts, s
}
}
}
private function buildDefaultHostList(\PDOStatement $statement, array &$virtualhosts, string $ip): void
private function buildDefaultHostList(PDOStatement $statement, array &$virtualhosts, string $ip): void
{
foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) {
$vhost = 'default.' . $row['domain'];
Expand Down Expand Up @@ -129,10 +131,11 @@ public function create()
sleep(60);
$hostname = gethostname();
$ip = gethostbyname($hostname);
$stmt = $this->database->prepare('SELECT virtualhost.aid,virtualhost.name,virtualhost.extra_webroot,domain.domain, domain.admin
$stmt = $this->database->prepare('SELECT virtualhost.aid,virtualhost.name,virtualhost.extra_webroot,domain.domain, domain.admin,owner.atatus_api_key
FROM virtualhost
INNER JOIN server ON server.aid=virtualhost.server
INNER JOIN domain ON domain.aid=virtualhost.domain
INNER JOIN owner ON owner.aid=domain.owner
WHERE server.hostname=:hostname');
$stmt->execute([':hostname' => $hostname]);
$virtualhosts = [];
Expand Down
4 changes: 4 additions & 0 deletions templates/config-based-virtual-host.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ CustomLog /var/log/{{ host.domain }}-access.log "%l %u %t \"%r\" %>s %b"
</Directory>
<IfModule php7_module>
php_value atatus.app_name "{{ host.domain }}"

{% if host.atatus_license_key %}php_value atatus.license_key "{{ host.atatus_license_key }}"{% endif %}
</IfModule>
<IfModule php_module>
php_value atatus.app_name "{{ host.domain }}"

{% if host.atatus_license_key %}php_value atatus.license_key "{{ host.atatus_license_key }}"{% endif %}
</IfModule>
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header set Content-Security-Policy upgrade-insecure-requests
Expand Down

0 comments on commit 6a40db1

Please sign in to comment.