|
@@ -21,24 +21,22 @@ function listFsDirs($username) {
|
|
return $dirs;
|
|
return $dirs;
|
|
}
|
|
}
|
|
|
|
|
|
-function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
|
|
|
|
|
+function addSite($username, $siteDir, $address, $type) {
|
|
insert('sites', [
|
|
insert('sites', [
|
|
'username' => $username,
|
|
'username' => $username,
|
|
'site_dir' => $siteDir,
|
|
'site_dir' => $siteDir,
|
|
- 'domain' => $domain,
|
|
|
|
- 'domain_type' => $domainType,
|
|
|
|
- 'protocol' => $protocol,
|
|
|
|
|
|
+ 'address' => $address,
|
|
|
|
+ 'type' => $type,
|
|
'creation_date' => date('Y-m-d H:i:s'),
|
|
'creation_date' => date('Y-m-d H:i:s'),
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
-function dirsStatuses($domainType, $protocol) {
|
|
|
|
|
|
+function dirsStatuses($type) {
|
|
if (isset($_SESSION['id']) !== true)
|
|
if (isset($_SESSION['id']) !== true)
|
|
return [];
|
|
return [];
|
|
$dbDirs = query('select', 'sites', [
|
|
$dbDirs = query('select', 'sites', [
|
|
'username' => $_SESSION['id'],
|
|
'username' => $_SESSION['id'],
|
|
- 'domain_type' => $domainType,
|
|
|
|
- 'protocol' => $protocol,
|
|
|
|
|
|
+ 'type' => $type,
|
|
], 'site_dir');
|
|
], 'site_dir');
|
|
$dirs = [];
|
|
$dirs = [];
|
|
foreach (listFsDirs($_SESSION['id']) as $fsDir)
|
|
foreach (listFsDirs($_SESSION['id']) as $fsDir)
|
|
@@ -46,9 +44,31 @@ function dirsStatuses($domainType, $protocol) {
|
|
return $dirs;
|
|
return $dirs;
|
|
}
|
|
}
|
|
|
|
|
|
-function htDeleteSite($dir, $domainType, $protocol) {
|
|
|
|
|
|
+function htDeleteSite($address, $type) {
|
|
|
|
+ match ($type) {
|
|
|
|
+ 'onion', 'dns' => htDeleteDedicatedSite($address, $type),
|
|
|
|
+ 'subpath', 'subdomain' => htDeleteSubSite($address, $type)
|
|
|
|
+ };
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function htDeleteSubSite($address, $type) {
|
|
|
|
+ if (unlink(CONF['ht'][$type . '_path'] . '/' . $address) !== true)
|
|
|
|
+ output(500, 'Unable to delete symlink.');
|
|
|
|
+
|
|
|
|
+ query('delete', 'sites', [
|
|
|
|
+ 'username' => $_SESSION['id'],
|
|
|
|
+ 'type' => $type,
|
|
|
|
+ 'address' => $address,
|
|
|
|
+ ]);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function htDeleteDedicatedSite($address, $type) {
|
|
|
|
+ $dir = query('select', 'sites', [
|
|
|
|
+ 'address' => $address,
|
|
|
|
+ 'type' => $type,
|
|
|
|
+ ], 'site_dir')[0];
|
|
|
|
|
|
- if ($domainType === 'onion') {
|
|
|
|
|
|
+ if ($type === 'onion') {
|
|
// Delete Tor config
|
|
// Delete Tor config
|
|
if (unlink(CONF['ht']['tor_config_path'] . '/' . $_SESSION['id'] . '/' . $dir) !== true)
|
|
if (unlink(CONF['ht']['tor_config_path'] . '/' . $_SESSION['id'] . '/' . $dir) !== true)
|
|
output(500, 'Failed to delete Tor configuration.');
|
|
output(500, 'Failed to delete Tor configuration.');
|
|
@@ -65,13 +85,7 @@ function htDeleteSite($dir, $domainType, $protocol) {
|
|
}
|
|
}
|
|
|
|
|
|
// Delete Nginx config
|
|
// Delete Nginx config
|
|
- $domain = query('select', 'sites', [
|
|
|
|
- 'username' => $_SESSION['id'],
|
|
|
|
- 'domain_type' => $domainType,
|
|
|
|
- 'protocol' => $protocol,
|
|
|
|
- 'site_dir' => $dir,
|
|
|
|
- ], 'domain')[0];
|
|
|
|
- if (unlink(CONF['ht']['nginx_config_path'] . '/' . $domain . '.conf') !== true)
|
|
|
|
|
|
+ if (unlink(CONF['ht']['nginx_config_path'] . '/' . $address . '.conf') !== true)
|
|
output(500, 'Failed to delete Nginx configuration.');
|
|
output(500, 'Failed to delete Nginx configuration.');
|
|
|
|
|
|
// Reload Nginx
|
|
// Reload Nginx
|
|
@@ -79,9 +93,9 @@ function htDeleteSite($dir, $domainType, $protocol) {
|
|
if ($code !== 0)
|
|
if ($code !== 0)
|
|
output(500, 'Failed to reload Nginx.');
|
|
output(500, 'Failed to reload Nginx.');
|
|
|
|
|
|
- if ($domainType === 'dns') {
|
|
|
|
|
|
+ if ($type === 'dns') {
|
|
// Delete Let's Encrypt certificate
|
|
// Delete Let's Encrypt certificate
|
|
- exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['certbot_path'] . ' delete --quiet --cert-name ' . $domain, $output, $code);
|
|
|
|
|
|
+ exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['certbot_path'] . ' delete --quiet --cert-name ' . $address, $output, $code);
|
|
if ($code !== 0)
|
|
if ($code !== 0)
|
|
output(500, 'Certbot failed to delete the Let\'s Encrypt certificate.');
|
|
output(500, 'Certbot failed to delete the Let\'s Encrypt certificate.');
|
|
}
|
|
}
|
|
@@ -89,8 +103,7 @@ function htDeleteSite($dir, $domainType, $protocol) {
|
|
// Delete from database
|
|
// Delete from database
|
|
query('delete', 'sites', [
|
|
query('delete', 'sites', [
|
|
'username' => $_SESSION['id'],
|
|
'username' => $_SESSION['id'],
|
|
- 'domain_type' => $domainType,
|
|
|
|
- 'protocol' => $protocol,
|
|
|
|
|
|
+ 'type' => $type,
|
|
'site_dir' => $dir,
|
|
'site_dir' => $dir,
|
|
]);
|
|
]);
|
|
}
|
|
}
|