$username, 'site_dir' => $siteDir, 'address' => $address, 'type' => $type, 'creation_date' => date('Y-m-d H:i:s'), ]); } function dirsStatuses(string $type): array { if (isset($_SESSION['id']) !== true) return []; $dbDirs = query('select', 'sites', [ 'username' => $_SESSION['id'], 'type' => $type, ], 'site_dir'); $dirs = []; foreach (listFsDirs($_SESSION['id']) as $fsDir) $dirs[$fsDir] = in_array($fsDir, $dbDirs); return $dirs; } function htRelativeSymlink(string $target, string $name): void { chdir(pathinfo($name)['dirname']); $symlink = symlink($target, pathinfo($name)['basename']); chdir(ROOT_PATH); if ($symlink !== true) output(500, 'Unable to create symlink.'); } function htDeleteSite(string $address, string $type, string $user_id): void { if ($type === 'onion') { $dir = query('select', 'sites', [ 'username' => $user_id, 'address' => $address, 'type' => $type, ], 'site_dir')[0]; // Delete Tor config if (unlink(CONF['ht']['tor_config_path'] . '/' . $user_id . '/' . $dir) !== true) output(500, 'Failed to delete Tor configuration.'); // Reload Tor exescape([ CONF['ht']['sudo_path'], '--', ...explode(' ', CONF['ht']['tor_reload_cmd']), ], result_code: $code); if ($code !== 0) output(500, 'Failed to reload Tor.'); // Delete Tor keys exescape([ CONF['ht']['sudo_path'], '-u', CONF['ht']['tor_user'], '--', CONF['ht']['rm_path'], '-r', '--', CONF['ht']['tor_keys_path'] . '/' . $user_id . '/' . $dir, ], result_code: $code); if ($code !== 0) output(500, 'Failed to delete Tor keys.'); } if ($type === 'dns') { // Delete Let's Encrypt certificate exescape([ CONF['ht']['sudo_path'], CONF['ht']['certbot_path'], 'delete', '--quiet', '--cert-name', $address, ], result_code: $code); if ($code !== 0) output(500, 'Certbot failed to delete the Let\'s Encrypt certificate.'); } $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' => $user_id, 'type' => $type, 'address' => $address, ]); }