|
@@ -20,18 +20,16 @@ function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
|
|
|
|
|
$op = $db->prepare("INSERT INTO sites(username, site_dir, domain, domain_type, protocol, creation_date, le_enabled) VALUES(:username, :site_dir, :domain, :domain_type, :protocol, :creation_date, :le_enabled)");
|
|
|
|
|
|
- if ($domainType === "dns" AND $protocol === "http")
|
|
|
- $le_enabled = 0;
|
|
|
- else
|
|
|
- $le_enabled = NULL;
|
|
|
-
|
|
|
$op->bindValue(':username', $username);
|
|
|
$op->bindValue(':site_dir', $siteDir);
|
|
|
$op->bindValue(':domain', $domain);
|
|
|
$op->bindValue(':domain_type', $domainType);
|
|
|
$op->bindValue(':protocol', $protocol);
|
|
|
$op->bindValue(':creation_date', date("Y-m-d H:i:s"));
|
|
|
- $op->bindValue(':le_enabled', $le_enabled);
|
|
|
+ if ($domainType === "dns" AND $protocol === "http")
|
|
|
+ $op->bindValue(':le_enabled', 0);
|
|
|
+ else
|
|
|
+ $op->bindValue(':le_enabled', NULL);
|
|
|
|
|
|
$op->execute();
|
|
|
}
|
|
@@ -47,3 +45,51 @@ function dirsStatuses($username, $domainType, $protocol) {
|
|
|
$dirs[$fsDir] = in_array($fsDir, $dbDirs);
|
|
|
return $dirs;
|
|
|
}
|
|
|
+
|
|
|
+function htDeleteSite($dir, $domainType, $protocol) {
|
|
|
+
|
|
|
+ if ($domainType === 'onion') {
|
|
|
+ // Delete Tor config
|
|
|
+ $torConf = file_get_contents(CONF['ht']['tor_config_path']);
|
|
|
+ if ($torConf === false)
|
|
|
+ serverError("Failed to read current Tor configuration.");
|
|
|
+ $torConf = str_replace('HiddenServiceDir ' . CONF['ht']['tor_keys_path'] . '/' . $dir . '/
|
|
|
+HiddenServicePort 80 [::1]:' . CONF['ht']['internal_onion_http_port'] . '
|
|
|
+', '', $torConf);
|
|
|
+ if (file_put_contents(CONF['ht']['tor_config_path'], $torConf) === false)
|
|
|
+ serverError("Failed to write new Tor configuration.");
|
|
|
+
|
|
|
+ // Reload Tor
|
|
|
+ exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload " . CONF['ht']['tor_service'], $output, $code);
|
|
|
+ if ($code !== 0)
|
|
|
+ serverError("Failed to reload Tor.");
|
|
|
+
|
|
|
+ // Delete Tor keys
|
|
|
+ exec(CONF['ht']['sudo_path'] . " -u " . CONF['ht']['tor_user'] . " " . CONF['ht']['rm_path'] . " --recursive " . CONF['ht']['tor_keys_path'] . "/" . $dir, $output, $code);
|
|
|
+ if ($code !== 0)
|
|
|
+ serverError("Failed to delete Tor keys.");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Delete Nginx config
|
|
|
+ $domain = query('select', 'sites', [
|
|
|
+ 'username' => $_SESSION['username'],
|
|
|
+ 'domain_type' => $domainType,
|
|
|
+ 'protocol' => $protocol,
|
|
|
+ 'site_dir' => $dir,
|
|
|
+ ], 'domain')[0];
|
|
|
+ if (unlink(CONF['ht']['nginx_config_path'] . '/' . $domain . '.conf') !== true)
|
|
|
+ serverError("Failed to delete Nginx configuration.");
|
|
|
+
|
|
|
+ // Reload Nginx
|
|
|
+ exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['systemctl_path'] . ' reload nginx', result_code: $code);
|
|
|
+ if ($code !== 0)
|
|
|
+ serverError("Failed to reload Nginx.");
|
|
|
+
|
|
|
+ // Delete from database
|
|
|
+ query('delete', 'sites', [
|
|
|
+ 'username' => $_SESSION['username'],
|
|
|
+ 'domain_type' => $domainType,
|
|
|
+ 'protocol' => $protocol,
|
|
|
+ 'site_dir' => $dir,
|
|
|
+ ]);
|
|
|
+}
|