Fix some PHP8 warnings and use constants for paths

This commit is contained in:
Miraty 2021-04-14 14:56:02 +02:00
parent 0e2fda0e3f
commit 07b68301c3
17 changed files with 144 additions and 135 deletions

View file

@ -22,25 +22,27 @@
$j = 0;
$alreadyEnabledDirs = NULL;
$notYetEnabledDirs = NULL;
foreach ($fsDirs as $fsDir) {
if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
$alreadyEnabledDirs[$i] = $fsDir;
$i++;
} else {
$notYetEnabledDirs[$j] = $fsDir;
$j++;
if ($fsDirs) {
foreach ($fsDirs as $fsDir) {
if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
$alreadyEnabledDirs[$i] = $fsDir;
$i++;
} else {
$notYetEnabledDirs[$j] = $fsDir;
$j++;
}
}
}
if (!is_null($notYetEnabledDirs)) {
foreach ($notYetEnabledDirs as $dir) {
echo "<option value='" . $dir . "'>" . $dir . "</option>";
if (!is_null($notYetEnabledDirs)) {
foreach ($notYetEnabledDirs as $dir) {
echo "<option value='" . $dir . "'>" . $dir . "</option>";
}
}
}
if (!is_null($alreadyEnabledDirs)) {
foreach ($alreadyEnabledDirs as $dir) {
echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
if (!is_null($alreadyEnabledDirs)) {
foreach ($alreadyEnabledDirs as $dir) {
echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
}
}
}
?>
@ -68,7 +70,7 @@ root=/srv/hyper/" . $_SESSION['username'] . "/hyper/" . $_POST['dir'] . "
file_put_contents("/etc/gmnisrv.ini", $conf, FILE_APPEND);
// Restart the gmnisrv daemon (as there is no reload support)
exec("sudo " . MANIVER_PATH . " restart-gmnisrv");
exec(SUDO_PATH . " " . MANIVER_PATH . " restart-gmnisrv");
echo "Accès par domaine ajouté sur ce dossier !";
}

View file

@ -16,25 +16,27 @@
$j = 0;
$alreadyEnabledDirs = NULL;
$notYetEnabledDirs = NULL;
foreach ($fsDirs as $fsDir) {
if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
$alreadyEnabledDirs[$i] = $fsDir;
$i++;
} else {
$notYetEnabledDirs[$j] = $fsDir;
$j++;
if ($fsDirs) {
foreach ($fsDirs as $fsDir) {
if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
$alreadyEnabledDirs[$i] = $fsDir;
$i++;
} else {
$notYetEnabledDirs[$j] = $fsDir;
$j++;
}
}
}
if (!is_null($notYetEnabledDirs)) {
foreach ($notYetEnabledDirs as $dir) {
echo "<option value='" . $dir . "'>" . $dir . "</option>";
if (!is_null($notYetEnabledDirs)) {
foreach ($notYetEnabledDirs as $dir) {
echo "<option value='" . $dir . "'>" . $dir . "</option>";
}
}
}
if (!is_null($alreadyEnabledDirs)) {
foreach ($alreadyEnabledDirs as $dir) {
echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
if (!is_null($alreadyEnabledDirs)) {
foreach ($alreadyEnabledDirs as $dir) {
echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
}
}
}
?>
@ -77,7 +79,7 @@ root=/srv/hyper/" . $_SESSION['username'] . "/hyper/" . $_POST['dir'] . "
file_put_contents("/etc/gmnisrv.ini", $conf, FILE_APPEND);
// Restart the gmnisrv daemon (as there is no reload support)
exec("sudo " . MANIVER_PATH . " restart-gmnisrv");
exec(SUDO_PATH . " " . MANIVER_PATH . " restart-gmnisrv");
// Tell the user their site address
echo "<p>L'adresse de votre capsule Onion Gemini est :<br><a href='http://" . $onion . "'<code>http://" . $onion . "</code></a></p>";

View file

@ -16,25 +16,27 @@
$j = 0;
$alreadyEnabledDirs = NULL;
$notYetEnabledDirs = NULL;
foreach ($fsDirs as $fsDir) {
if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
$alreadyEnabledDirs[$i] = $fsDir;
$i++;
} else {
$notYetEnabledDirs[$j] = $fsDir;
$j++;
if ($fsDirs) {
foreach ($fsDirs as $fsDir) {
if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
$alreadyEnabledDirs[$i] = $fsDir;
$i++;
} else {
$notYetEnabledDirs[$j] = $fsDir;
$j++;
}
}
}
if (!is_null($notYetEnabledDirs)) {
foreach ($notYetEnabledDirs as $dir) {
echo "<option value='" . $dir . "'>" . $dir . "</option>";
if (!is_null($notYetEnabledDirs)) {
foreach ($notYetEnabledDirs as $dir) {
echo "<option value='" . $dir . "'>" . $dir . "</option>";
}
}
}
if (!is_null($alreadyEnabledDirs)) {
foreach ($alreadyEnabledDirs as $dir) {
echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
if (!is_null($alreadyEnabledDirs)) {
foreach ($alreadyEnabledDirs as $dir) {
echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
}
}
}
?>
@ -77,7 +79,7 @@ if (isset($_POST['dir']) AND isset($_SESSION['username'])) {
file_put_contents(NGINX_CONFIG_PATH . "/" . $_POST['dir'] . ".conf", $nginxConf);
// Reload Nginx
exec("sudo " . MANIVER_PATH . " reload-nginx");
exec(SUDO_PATH . " " . MANIVER_PATH . " reload-nginx");
// Tell the user their site address
echo "<p>L'adresse de votre site Onion HTTP est :<br><a href='http://" . $onion . "'<code>http://" . $onion . "</code></a></p>";

View file

@ -22,27 +22,30 @@
$j = 0;
$alreadyEnabledDirs = NULL;
$notYetEnabledDirs = NULL;
foreach ($fsDirs as $fsDir) {
if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
$alreadyEnabledDirs[$i] = $fsDir;
$i++;
} else {
$notYetEnabledDirs[$j] = $fsDir;
$j++;
if ($fsDirs) {
foreach ($fsDirs as $fsDir) {
if ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs)) {
$alreadyEnabledDirs[$i] = $fsDir;
$i++;
} else {
$notYetEnabledDirs[$j] = $fsDir;
$j++;
}
}
if (!is_null($notYetEnabledDirs)) {
foreach ($notYetEnabledDirs as $dir) {
echo "<option value='" . $dir . "'>" . $dir . "</option>";
}
}
if (!is_null($alreadyEnabledDirs)) {
foreach ($alreadyEnabledDirs as $dir) {
echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
}
}
}
if (!is_null($notYetEnabledDirs)) {
foreach ($notYetEnabledDirs as $dir) {
echo "<option value='" . $dir . "'>" . $dir . "</option>";
}
}
if (!is_null($alreadyEnabledDirs)) {
foreach ($alreadyEnabledDirs as $dir) {
echo "<option disabled='' value='" . $dir . "'>" . $dir . "</option>";
}
}
?>
</select>
<br>

View file

@ -14,13 +14,13 @@
if (isset($_POST['domain'])) {
exec("sudo " . MANIVER_PATH . " le-install " . $_POST['domain'], $output);
exec(SUDO_PATH . " " . MANIVER_PATH . " le-install " . $_POST['domain'], $output);
addNiverLog($_SESSION['username'] . " installed a Let's Encrypt certificate on their site", $output);
$conf = file_get_contents(NGINX_CONFIG_PATH . "/" . $_POST['domain'] . ".conf");
$conf = preg_replace("#host\.atope\.art#", $_POST['domain'], $conf);
file_put_contents(NGINX_CONFIG_PATH . "/" . $_POST['domain'] . ".conf", $conf);
exec("sudo " . MANIVER_PATH . " reload-nginx");
exec(SUDO_PATH . " " . MANIVER_PATH . " reload-nginx");
echo "Formulaire traité !!";
} else {

View file

@ -19,7 +19,7 @@ if ($_SESSION['sftp_enabled'] == false) { ?>
if (isset($_SESSION['username']) AND isset($_POST['password'])) {
// Setup SFTP access
exec("sudo " . MANIVER_PATH . " setup-user " . $_SESSION['username'] . " " . $_POST['password'], $output);
exec(SUDO_PATH . " " . MANIVER_PATH . " setup-user " . $_SESSION['username'] . " " . $_POST['password'], $output);
addNiverLog($_SESSION['username'] . " enabled SFTP on their account", $output);
enableSftp($_SESSION['username']);
$_SESSION['sftp_enabled'] = true;

View file

@ -19,26 +19,6 @@ function checkAction($action) {
exit("ERROR: wrong value for action");
}
function listUserZones($username) {
$db = new PDO('sqlite:' . DB_PATH);
$usernameArray[0] = $username;
$op = $db->prepare('SELECT zone FROM zones WHERE username = ?');
$op->execute($usernameArray);
$zone = $op->fetch()['zone'];
$i = 0;
while ($zone != NULL) {
$zones[$i] = $zone;
$i++;
$zone = $op->fetch()['zone'];
}
return $zones;
}
function checkPassword($username, $password) {
$username2[0] = $username;

View file

@ -3,7 +3,8 @@ if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
exit("This file is meant to be included.");
function listFsDirs($username) {
exec("/usr/bin/ls ls --format=single-column -d /srv/hyper/" . $username . "/hyper/*/", $absoluteDirs);
exec(LS_PATH . " ls --format=single-column -d /srv/hyper/" . $username . "/hyper/*/", $absoluteDirs);
$relativeDirs = false;
foreach ($absoluteDirs as $i => $absoluteDir) {
$tree = explode("/", $absoluteDir); // The last key is NULL
end($tree);
@ -40,12 +41,20 @@ function listDbDirs($username, $domainType, $protocol) {
$op->execute();
$i = 0;
$siteDir = $op->fetch()['site_dir'];
$data = $op->fetch();
if (isset($data['site_dir']))
$siteDir = $data['site_dir'];
else
$siteDir = NULL;
while ($siteDir != NULL) {
$siteDirs[$i] = $siteDir;
$i++;
$siteDir = $op->fetch()['site_dir'];
$data = $op->fetch();
if (isset($data['site_dir']))
$siteDir = $data['site_dir'];
else
$siteDir = NULL;
}
if (isset($siteDirs))
return $siteDirs;

View file

@ -11,6 +11,31 @@ function nsTtl($value, $multiplier) {
return $ttl;
}
function nsListUserZones($username) {
$db = new PDO('sqlite:' . DB_PATH);
$usernameArray[0] = $username;
$op = $db->prepare('SELECT zone FROM zones WHERE username = ?');
$op->execute($usernameArray);
$data = $op->fetch();
$zone = $data['zone'];
$i = 0;
while ($zone != NULL) {
$zones[$i] = $zone;
$i++;
$data = $op->fetch();
if (isset($data['zone']))
$zone = $data['zone'];
else
$zone = NULL;
}
return $zones;
}
function nsCheckZonePossession($submittedZone) {
checkAbsoluteDomainFormat($submittedZone);

View file

@ -14,14 +14,19 @@ function regListUserDomains($username) {
$op->execute($usernameArray);
$domains = false;
$domain = $op->fetch()['domain'];
$i = 0;
$data = $op->fetch();
$domain = $data['domain'];
while ($domain != NULL) {
$domains[$i] = $domain;
$domain = $op->fetch()['domain'];
$data = $op->fetch();
if (isset($data['domain']))
$domain = $data['domain'];
else
$domain = NULL;
$i++;
}

View file

@ -13,7 +13,7 @@
<option value="" disabled="" selected="">---</option>
<?php
$zones = listUserZones($_SESSION['username']);
$zones = nsListUserZones($_SESSION['username']);
foreach ($zones as $zone) {
echo "<option value='" . $zone . "'>" . $zone . "</option>";

View file

@ -5,17 +5,12 @@
<option value="" disabled="" selected="">---</option>
<?php
$db = new PDO('sqlite:' . DB_PATH);
$username[0] = $_SESSION['username'];
$zones = nsListUserZones($_SESSION['username']);
$req = $db->prepare('SELECT zone FROM zones WHERE username = ?');
$req->execute($username);
$domain = $req->fetch()['zone'];
while ($domain != NULL) {
echo "<option value='" . $domain . "'>" . $domain . "</option>";
$domain = $req->fetch()['zone'];
if ($zones) {
foreach($zones as $zone) {
echo "<option value='" . $zone . "'>" . $zone . "</option>";
}
}
?>

View file

@ -20,19 +20,10 @@
<option value="" disabled="" selected="">---</option>
<?php
$db = new PDO('sqlite:' . DB_PATH);
$username[0] = $_SESSION['username'];
$zones = nsListUserZones($_SESSION['username']);
var_dump($username);
$req = $db->prepare('SELECT zone FROM zones WHERE username = ?');
$req->execute($username);
$domain = $req->fetch()['zone'];
while ($domain != NULL) {
echo "<option value='" . $domain . "'>" . $domain . "</option>";
$domain = $req->fetch()['zone'];
foreach ($zones as $zone) {
echo "<option value='" . $zone . "'>" . $zone . "</option>";
}
?>

View file

@ -13,7 +13,7 @@
<option value="" disabled="" selected="">---</option>
<?php
$zones = listUserZones($_SESSION['username']);
$zones = nsListUserZones($_SESSION['username']);
foreach ($zones as $zone) {
echo "<option value='" . $zone . "'>" . $zone . "</option>";

View file

@ -13,7 +13,7 @@
<option value="" disabled="" selected="">---</option>
<?php
$zones = listUserZones($_SESSION['username']);
$zones = nsListUserZones($_SESSION['username']);
foreach ($zones as $zone) {
echo "<option value='" . $zone . "'>" . $zone . "</option>";

View file

@ -7,22 +7,15 @@
<option value="" disabled="" selected="">---</option>
<?php
$db = new PDO('sqlite:' . DB_PATH);
$username[0] = $_SESSION['username'];
$domains = regListUserDomains($_SESSION['username']);
var_dump($username);
$req = $db->prepare('SELECT zone FROM zones WHERE username = ?');
$req->execute($username);
$domain = $req->fetch()['zone'];
while ($domain != NULL) {
echo "<option value='" . $domain . "'>" . $domain . "</option>";
$domain = $req->fetch()['zone'];
if ($domains) {
foreach($domains as $domain) {
echo "<option value='" . $domain . "'>" . $domain . "</option>";
}
}
?>
?>
</select>
<br>

View file

@ -28,9 +28,10 @@ define("NGINX_CONFIG_PATH", "/etc/nginx/hyper"); // Config directory
define("TOR_CONFIG_PATH", "/etc/tor/torrc"); // Config file
define("TOR_KEYS_PATH", "/var/lib/tor/niver"); // Keys directory
define("SUDO_PATH", "/usr/bin/sudo"); // Binary file
define("MANIVER_PATH", "/root/maniver/target/release/maniver"); // Binary file
define("LS_PATH", "/usr/bin/ls"); // Binary file
define("MANIVER_PATH", "/usr/local/bin/maniver"); // Binary file
// The mountpoint of the hypertext storage partition (that will be accessed over SFTP)
define("HT_PATH", "/srv/hyper");
define("HT_PATH", "/srv/ht");
define("SERVICE", substr(dirname($_SERVER['PHP_SELF']), strlen(PREFIX) + 1));
define("PAGE", basename($_SERVER['PHP_SELF'], '.php'));
@ -93,6 +94,7 @@ $cssFileName = Less_Cache::Get($absoluteLessFiles, $options, $theme);
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title><?php
if (isset($page['title']) AND $page['title'] != "Accueil")
echo $page['title'] . " · ";