|
@@ -3,9 +3,9 @@
|
|
|
function htSetupUserFs($id) {
|
|
|
// Setup SFTP directory
|
|
|
umask(0002);
|
|
|
- if (mkdir(CONF['ht']['ht_path'] . '/' . $id, 0775) !== true)
|
|
|
+ if (mkdir(CONF['ht']['ht_path'] . '/fs/' . $id, 0775) !== true)
|
|
|
output(500, 'Can\'t create user directory.');
|
|
|
- exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['chgrp_path'] . ' ' . CONF['ht']['sftpgo_group'] . ' ' . CONF['ht']['ht_path'] . '/' . $id . ' --no-dereference', result_code: $code);
|
|
|
+ exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['chgrp_path'] . ' ' . CONF['ht']['sftpgo_group'] . ' ' . CONF['ht']['ht_path'] . '/fs/' . $id . ' --no-dereference', result_code: $code);
|
|
|
if ($code !== 0)
|
|
|
output(500, 'Can\'t change user directory group.');
|
|
|
|
|
@@ -32,7 +32,7 @@ function formatDomain($domain) {
|
|
|
}
|
|
|
|
|
|
function listFsDirs($username) {
|
|
|
- $absoluteDirs = glob(CONF['ht']['ht_path'] . '/' . $username . '/*/', GLOB_ONLYDIR);
|
|
|
+ $absoluteDirs = glob(CONF['ht']['ht_path'] . '/fs/' . $username . '/*/', GLOB_ONLYDIR);
|
|
|
$dirs = [];
|
|
|
foreach ($absoluteDirs as $absoluteDir)
|
|
|
if (preg_match('/^[a-zA-Z0-9_-]{1,64}$/D', basename($absoluteDir)))
|
|
@@ -63,31 +63,23 @@ function dirsStatuses($type) {
|
|
|
return $dirs;
|
|
|
}
|
|
|
|
|
|
-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 htRelativeSymlink($target, $name) {
|
|
|
+ chdir(pathinfo($name)['dirname']);
|
|
|
+ $symlink = symlink($target, pathinfo($name)['basename']);
|
|
|
+ chdir(ROOT_PATH);
|
|
|
+ if ($symlink !== true)
|
|
|
+ output(500, 'Unable to create symlink.');
|
|
|
}
|
|
|
|
|
|
-function htDeleteDedicatedSite($address, $type) {
|
|
|
- $dir = query('select', 'sites', [
|
|
|
- 'address' => $address,
|
|
|
- 'type' => $type,
|
|
|
- ], 'site_dir')[0];
|
|
|
+function htDeleteSite($address, $type) {
|
|
|
|
|
|
if ($type === 'onion') {
|
|
|
+ $dir = query('select', 'sites', [
|
|
|
+ 'username' => $_SESSION['id'],
|
|
|
+ 'address' => $address,
|
|
|
+ 'type' => $type,
|
|
|
+ ], 'site_dir')[0];
|
|
|
+
|
|
|
// Delete Tor config
|
|
|
if (unlink(CONF['ht']['tor_config_path'] . '/' . $_SESSION['id'] . '/' . $dir) !== true)
|
|
|
output(500, 'Failed to delete Tor configuration.');
|
|
@@ -103,15 +95,6 @@ function htDeleteDedicatedSite($address, $type) {
|
|
|
output(500, 'Failed to delete Tor keys.');
|
|
|
}
|
|
|
|
|
|
- // Delete Nginx config
|
|
|
- if (unlink(CONF['ht']['nginx_config_path'] . '/' . $address . '.conf') !== true)
|
|
|
- output(500, 'Failed to delete Nginx configuration.');
|
|
|
-
|
|
|
- // Reload Nginx
|
|
|
- exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['nginx_reload_cmd'], result_code: $code);
|
|
|
- if ($code !== 0)
|
|
|
- output(500, 'Failed to reload Nginx.');
|
|
|
-
|
|
|
if ($type === 'dns') {
|
|
|
// Delete Let's Encrypt certificate
|
|
|
exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['certbot_path'] . ' delete --quiet --cert-name ' . $address, $output, $code);
|
|
@@ -119,10 +102,18 @@ function htDeleteDedicatedSite($address, $type) {
|
|
|
output(500, 'Certbot failed to delete the Let\'s Encrypt certificate.');
|
|
|
}
|
|
|
|
|
|
- // Delete from database
|
|
|
+ $link = CONF['ht']['ht_path'] . '/uri/' . match ($type) {
|
|
|
+ 'onion', 'dns' => $address,
|
|
|
+ 'subdomain' => $address . '.' . CONF['ht']['subdomain_domain'],
|
|
|
+ 'subpath' => CONF['ht']['subpath_domain'] . '/' . $address,
|
|
|
+ };
|
|
|
+
|
|
|
+ if (unlink($link) !== true)
|
|
|
+ output(500, 'Unable to delete symlink.');
|
|
|
+
|
|
|
query('delete', 'sites', [
|
|
|
'username' => $_SESSION['id'],
|
|
|
'type' => $type,
|
|
|
- 'site_dir' => $dir,
|
|
|
+ 'address' => $address,
|
|
|
]);
|
|
|
}
|