diff --git a/config.ini b/config.ini index 451d13b..48e8b36 100644 --- a/config.ini +++ b/config.ini @@ -29,7 +29,7 @@ nginx_config_path = "/etc/nginx/ht" tor_config_path = "/etc/tor/instances/niver/torrc" ; Tor keys directory tor_keys_path = "/var/lib/tor-instances/niver/keys" -tor_service = "tor@niver" +tor_service = "tor" sudo_path = "/usr/bin/sudo" systemctl_path = "/usr/bin/systemctl" diff --git a/public/ht/http-onion.php b/public/ht/http-onion.php index bf8bc8f..1e96687 100644 --- a/public/ht/http-onion.php +++ b/public/ht/http-onion.php @@ -35,13 +35,18 @@ if ($dirsStatuses[$_POST['dir']] !== false) // Add Tor config $torConf = file_get_contents(CONF['ht']['tor_config_path']); +if ($torConf === false) + serverError("Failed to read current Tor configuration."); $torConf = $torConf . "HiddenServiceDir " . CONF['ht']['tor_keys_path'] . "/" . $_POST['dir'] . "/ HiddenServicePort 80 [::1]:" . CONF['ht']['internal_onion_http_port'] . " "; -file_put_contents(CONF['ht']['tor_config_path'], $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); +exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload " . CONF['ht']['tor_service'], $output, $code); +if ($code !== 0) + serverError("Failed to reload Tor."); // Get the address generated by Tor exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['cat_path'] . " " . CONF['ht']['tor_keys_path'] . "/" . $_POST['dir'] . "/hostname", $output); @@ -61,10 +66,13 @@ $nginxConf = 'server { include inc/ht-onion.conf; } '; -file_put_contents(CONF['ht']['nginx_config_path'] . "/" . $onion . ".conf", $nginxConf); +if (file_put_contents(CONF['ht']['nginx_config_path'] . "/" . $onion . ".conf", $nginxConf) === false) + serverError("Failed to write Nginx configuration."); // Reload Nginx -exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx"); +exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx", result_code: $code); +if ($code !== 0) + serverError("Failed to reload Nginx."); // Tell the user their site address success("L'adresse de votre service Onion HTTP est : http://" . $onion . "/"); diff --git a/public/ht/https-domain.php b/public/ht/https-domain.php index bf1fd40..4f9efb8 100644 --- a/public/ht/https-domain.php +++ b/public/ht/https-domain.php @@ -55,9 +55,12 @@ $nginxConf = 'server { include inc/ht-tls.conf; } '; -file_put_contents(CONF['ht']['nginx_config_path'] . "/" . $_POST['domain'] . ".conf", $nginxConf); +if (file_put_contents(CONF['ht']['nginx_config_path'] . "/" . $_POST['domain'] . ".conf", $nginxConf) === false) + serverError("Failed to write Nginx configuration."); // Reload Nginx -exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx"); +exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx", result_code: $code); +if ($code !== 0) + serverError("Failed to reload Nginx."); success("Accès HTTP par domaine ajouté sur ce dossier !");