Fix exec()'s $output

This commit is contained in:
Miraty 2023-04-23 16:36:41 +02:00
parent b5b2f95bf5
commit 3749aa9b4a
3 changed files with 8 additions and 7 deletions

View file

@ -37,6 +37,8 @@ Upload site's files to the server using SFTP. The way the site is accessed can t
* Subdomain of a shared root domain * Subdomain of a shared root domain
* HTTP subpath of a shared domain * HTTP subpath of a shared domain
Some Apache configuration directive are available through `.htaccess`.
## Software used ## Software used
[PHP](https://www.php.net/) [PHP](https://www.php.net/)
@ -58,7 +60,7 @@ Upload site's files to the server using SFTP. The way the site is accessed can t
: static HTTP server, with content negotiation and `.htaccess` dynamic configuration : static HTTP server, with content negotiation and `.htaccess` dynamic configuration
[nginx](https://nginx.org/) [nginx](https://nginx.org/)
: HTTP reverse proxy for Apache; terminates TLS and enforces security header : HTTP reverse proxy for Apache; terminates TLS and enforces security headers
Tor Tor
: [Onion services](https://community.torproject.org/onion-services/) : [Onion services](https://community.torproject.org/onion-services/)

View file

@ -88,19 +88,19 @@ function htDeleteSite($address, $type) {
output(500, 'Failed to delete Tor configuration.'); output(500, 'Failed to delete Tor configuration.');
// Reload Tor // Reload Tor
exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['tor_reload_cmd'], $output, $code); exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['tor_reload_cmd'], result_code: $code);
if ($code !== 0) if ($code !== 0)
output(500, 'Failed to reload Tor.'); output(500, 'Failed to reload Tor.');
// Delete Tor keys // Delete Tor keys
exec(CONF['ht']['sudo_path'] . ' -u ' . CONF['ht']['tor_user'] . ' ' . CONF['ht']['rm_path'] . ' -r ' . CONF['ht']['tor_keys_path'] . '/' . $_SESSION['id'] . '/' . $dir, $output, $code); exec(CONF['ht']['sudo_path'] . ' -u ' . CONF['ht']['tor_user'] . ' ' . CONF['ht']['rm_path'] . ' -r ' . CONF['ht']['tor_keys_path'] . '/' . $_SESSION['id'] . '/' . $dir, result_code: $code);
if ($code !== 0) if ($code !== 0)
output(500, 'Failed to delete Tor keys.'); output(500, 'Failed to delete Tor keys.');
} }
if ($type === '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 ' . $address, $output, $code); exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['certbot_path'] . ' delete --quiet --cert-name ' . $address, result_code: $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.');
} }

View file

@ -15,13 +15,12 @@ if (chmod($torConfFile, 0644) !== true)
output(500, 'Failed to give correct permissions to new Tor configuration file.'); output(500, 'Failed to give correct permissions to new Tor configuration file.');
// Reload Tor // Reload Tor
exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['tor_reload_cmd'], $output, $code); exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['tor_reload_cmd'], result_code: $code);
if ($code !== 0) if ($code !== 0)
output(500, 'Failed to reload Tor.'); output(500, 'Failed to reload Tor.');
// Get the address generated by Tor // Get the address generated by Tor
exec(CONF['ht']['sudo_path'] . ' -u ' . CONF['ht']['tor_user'] . ' ' . CONF['ht']['cat_path'] . ' ' . CONF['ht']['tor_keys_path'] . '/' . $_SESSION['id'] . '/' . $_POST['dir'] . '/hostname', $output); $onion = exec(CONF['ht']['sudo_path'] . ' -u ' . CONF['ht']['tor_user'] . ' ' . CONF['ht']['cat_path'] . ' ' . CONF['ht']['tor_keys_path'] . '/' . $_SESSION['id'] . '/' . $_POST['dir'] . '/hostname');
$onion = $output[0];
if (preg_match('/^[0-9a-z]{56}\.onion$/D', $onion) !== 1) if (preg_match('/^[0-9a-z]{56}\.onion$/D', $onion) !== 1)
output(500, 'No onion address found.'); output(500, 'No onion address found.');