|
@@ -96,8 +96,23 @@ function htRelativeSymlink(string $target, string $name): void {
|
|
|
output(500, 'Unable to create symlink.');
|
|
|
}
|
|
|
|
|
|
-function htDeleteSite(string $address, string $type, string $user_id): void {
|
|
|
+function reloadTor() { // Using Tor control protocol <https://spec.torproject.org/control-spec/>
|
|
|
+ $sock = stream_socket_client('unix://' . CONF['ht']['tor_control_socket']);
|
|
|
+ if ($sock === false)
|
|
|
+ output(500, 'Failed to connect to Tor control socket.', [$out]);
|
|
|
+ fwrite($sock, 'AUTHENTICATE' . CRLF);
|
|
|
+ if (($out = fgets($sock)) !== '250 OK' . CRLF)
|
|
|
+ output(500, 'Failed to authenticate to Tor control socket.', [$out]);
|
|
|
+ fwrite($sock, 'SIGNAL RELOAD' . CRLF);
|
|
|
+ if (($out = fgets($sock)) !== '250 OK' . CRLF)
|
|
|
+ output(500, 'Failed to reload Tor.', [$out]);
|
|
|
+ fwrite($sock, 'QUIT' . CRLF);
|
|
|
+ if (($out = fgets($sock)) !== '250 closing connection' . CRLF)
|
|
|
+ output(500, 'Failed to close connection to Tor control socket.', [$out]);
|
|
|
+ fclose($sock);
|
|
|
+}
|
|
|
|
|
|
+function htDeleteSite(string $address, string $type, string $user_id): void {
|
|
|
if ($type === 'onion') {
|
|
|
$dir = query('select', 'sites', [
|
|
|
'username' => $user_id,
|
|
@@ -110,13 +125,7 @@ function htDeleteSite(string $address, string $type, string $user_id): void {
|
|
|
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.');
|
|
|
+ reloadTor();
|
|
|
|
|
|
// Delete Tor keys
|
|
|
exescape([
|