Add form to delete account
Move service-specific deletion code to functions
This commit is contained in:
parent
4cafad3310
commit
6dbc63a36a
|
@ -13,12 +13,8 @@ define("PLACEHOLDER_IPV4", "203.0.113.42"); // From RFC5737: IPv4 Address Blocks
|
||||||
// Page titles definition
|
// Page titles definition
|
||||||
require "pages.php";
|
require "pages.php";
|
||||||
|
|
||||||
require CONF['common']['root_path'] . "/fn/common.php";
|
foreach (array_diff(scandir(CONF['common']['root_path'] . "/fn"), array('..', '.')) as $file)
|
||||||
// Service-specific functions and constants
|
require CONF['common']['root_path'] . '/fn/' . $file;
|
||||||
if (SERVICE === "reg" OR SERVICE === "ns")
|
|
||||||
require CONF['common']['root_path'] . "/fn/dns.php";
|
|
||||||
if (SERVICE !== "")
|
|
||||||
require CONF['common']['root_path'] . "/fn/" . SERVICE . ".php";
|
|
||||||
|
|
||||||
function success($msg = '') {
|
function success($msg = '') {
|
||||||
if ($msg !== '')
|
if ($msg !== '')
|
||||||
|
|
|
@ -6,6 +6,7 @@ define('TITLES', [
|
||||||
'index' => '<span aria-hidden="true">🔐 </span>Authentification',
|
'index' => '<span aria-hidden="true">🔐 </span>Authentification',
|
||||||
'login' => 'Se connecter',
|
'login' => 'Se connecter',
|
||||||
'register' => 'Créer un compte',
|
'register' => 'Créer un compte',
|
||||||
|
'unregister' => 'Supprimer son compte',
|
||||||
'password' => 'Changer la clé de passe',
|
'password' => 'Changer la clé de passe',
|
||||||
'logout' => 'Déconnexion',
|
'logout' => 'Déconnexion',
|
||||||
],
|
],
|
||||||
|
@ -48,6 +49,7 @@ define('DESCRIPTIONS', [
|
||||||
'index' => 'Gérer son compte',
|
'index' => 'Gérer son compte',
|
||||||
'login' => 'Démarrer une nouvelle session avec un compte existant',
|
'login' => 'Démarrer une nouvelle session avec un compte existant',
|
||||||
'register' => 'Créer un nouveau compte Niver',
|
'register' => 'Créer un nouveau compte Niver',
|
||||||
|
'unregister' => 'Effacer les données liées à son compte',
|
||||||
'password' => 'Changer la chaîne de caractères permettant de vous authentifier.',
|
'password' => 'Changer la chaîne de caractères permettant de vous authentifier.',
|
||||||
'logout' => 'Terminer la session et effacer ses cookies',
|
'logout' => 'Terminer la session et effacer ses cookies',
|
||||||
],
|
],
|
||||||
|
|
|
@ -29,7 +29,7 @@ function hashPassword($password) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function userExist($username) {
|
function userExist($username) {
|
||||||
return $username === query('select', 'users', ['username' => $username], 'username')[0];
|
return isset(query('select', 'users', ['username' => $username], 'username')[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPassword($username, $password) {
|
function checkPassword($username, $password) {
|
||||||
|
|
44
fn/dns.php
44
fn/dns.php
|
@ -1,22 +1,42 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
function knotcExec($suffix, $cmd) {
|
function knotcConfExec($cmds) {
|
||||||
$action = checkAction($_POST['action']);
|
exec(CONF['dns']['knotc_path'] . " conf-begin", $output['begin'], $code['begin']);
|
||||||
|
|
||||||
exec(CONF['dns']['knotc_path'] . " zone-begin " . $suffix, $output['begin'], $code['begin']);
|
|
||||||
if ($code['begin'] !== 0)
|
if ($code['begin'] !== 0)
|
||||||
serverError("<code>knotc</code> failed with exit code <samp>" . $code['begin'] . "</samp>: <samp>" . $output['begin'][0] . "</samp>.");
|
serverError("knotcConfExec: <code>knotc</code> failed with exit code <samp>" . $code['begin'] . "</samp>: <samp>" . $output['begin'][0] . "</samp>.");
|
||||||
|
|
||||||
exec(CONF['dns']['knotc_path'] . " zone-" . $action . "set " . $suffix . " " . implode(" ", $cmd), $output['op'], $code['op']);
|
foreach ($cmds as $cmd) {
|
||||||
if ($code['op'] !== 0) {
|
exec(CONF['dns']['knotc_path'] . " conf-" . $cmd, $output['op'], $code['op']);
|
||||||
exec(CONF['dns']['knotc_path'] . " zone-abort " . $suffix);
|
if ($code['op'] !== 0) {
|
||||||
serverError("<code>knotc</code> failed with exit code <samp>" . $code['op'] . "</samp>: <samp>" . $output['op'][0] . "</samp>.");
|
exec(CONF['dns']['knotc_path'] . " conf-abort");
|
||||||
|
serverError("knotcConfExec: <code>knotc</code> failed with exit code <samp>" . $code['op'] . "</samp>: <samp>" . $output['op'][0] . "</samp>.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exec(CONF['dns']['knotc_path'] . " zone-commit " . $suffix, $output['commit'], $code['commit']);
|
exec(CONF['dns']['knotc_path'] . " conf-commit", $output['commit'], $code['commit']);
|
||||||
if ($code['commit'] !== 0) {
|
if ($code['commit'] !== 0) {
|
||||||
exec(CONF['dns']['knotc_path'] . " zone-abort " . $suffix);
|
exec(CONF['dns']['knotc_path'] . " conf-abort");
|
||||||
serverError("<code>knotc</code> failed with exit code <samp>" . $code['commit'] . "</samp>: <samp>" . $output['commit'][0] . "</samp>.");
|
serverError("knotcConfExec: <code>knotc</code> failed with exit code <samp>" . $code['commit'] . "</samp>: <samp>" . $output['commit'][0] . "</samp>.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function knotcZoneExec($zone, $cmd) {
|
||||||
|
$action = checkAction($_POST['action']);
|
||||||
|
|
||||||
|
exec(CONF['dns']['knotc_path'] . " zone-begin " . $zone, $output['begin'], $code['begin']);
|
||||||
|
if ($code['begin'] !== 0)
|
||||||
|
serverError("knotcZoneExec: <code>knotc</code> failed with exit code <samp>" . $code['begin'] . "</samp>: <samp>" . $output['begin'][0] . "</samp>.");
|
||||||
|
|
||||||
|
exec(CONF['dns']['knotc_path'] . " zone-" . $action . "set " . $zone . " " . implode(" ", $cmd), $output['op'], $code['op']);
|
||||||
|
if ($code['op'] !== 0) {
|
||||||
|
exec(CONF['dns']['knotc_path'] . " zone-abort " . $zone);
|
||||||
|
serverError("knotcZoneExec: <code>knotc</code> failed with exit code <samp>" . $code['op'] . "</samp>: <samp>" . $output['op'][0] . "</samp>.");
|
||||||
|
}
|
||||||
|
|
||||||
|
exec(CONF['dns']['knotc_path'] . " zone-commit " . $zone, $output['commit'], $code['commit']);
|
||||||
|
if ($code['commit'] !== 0) {
|
||||||
|
exec(CONF['dns']['knotc_path'] . " zone-abort " . $zone);
|
||||||
|
serverError("knotcZoneExec: <code>knotc</code> failed with exit code <samp>" . $code['commit'] . "</samp>: <samp>" . $output['commit'][0] . "</samp>.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
58
fn/ht.php
58
fn/ht.php
|
@ -20,18 +20,16 @@ function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
||||||
|
|
||||||
$op = $db->prepare("INSERT INTO sites(username, site_dir, domain, domain_type, protocol, creation_date, le_enabled) VALUES(:username, :site_dir, :domain, :domain_type, :protocol, :creation_date, :le_enabled)");
|
$op = $db->prepare("INSERT INTO sites(username, site_dir, domain, domain_type, protocol, creation_date, le_enabled) VALUES(:username, :site_dir, :domain, :domain_type, :protocol, :creation_date, :le_enabled)");
|
||||||
|
|
||||||
if ($domainType === "dns" AND $protocol === "http")
|
|
||||||
$le_enabled = 0;
|
|
||||||
else
|
|
||||||
$le_enabled = NULL;
|
|
||||||
|
|
||||||
$op->bindValue(':username', $username);
|
$op->bindValue(':username', $username);
|
||||||
$op->bindValue(':site_dir', $siteDir);
|
$op->bindValue(':site_dir', $siteDir);
|
||||||
$op->bindValue(':domain', $domain);
|
$op->bindValue(':domain', $domain);
|
||||||
$op->bindValue(':domain_type', $domainType);
|
$op->bindValue(':domain_type', $domainType);
|
||||||
$op->bindValue(':protocol', $protocol);
|
$op->bindValue(':protocol', $protocol);
|
||||||
$op->bindValue(':creation_date', date("Y-m-d H:i:s"));
|
$op->bindValue(':creation_date', date("Y-m-d H:i:s"));
|
||||||
$op->bindValue(':le_enabled', $le_enabled);
|
if ($domainType === "dns" AND $protocol === "http")
|
||||||
|
$op->bindValue(':le_enabled', 0);
|
||||||
|
else
|
||||||
|
$op->bindValue(':le_enabled', NULL);
|
||||||
|
|
||||||
$op->execute();
|
$op->execute();
|
||||||
}
|
}
|
||||||
|
@ -47,3 +45,51 @@ function dirsStatuses($username, $domainType, $protocol) {
|
||||||
$dirs[$fsDir] = in_array($fsDir, $dbDirs);
|
$dirs[$fsDir] = in_array($fsDir, $dbDirs);
|
||||||
return $dirs;
|
return $dirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function htDeleteSite($dir, $domainType, $protocol) {
|
||||||
|
|
||||||
|
if ($domainType === 'onion') {
|
||||||
|
// Delete Tor config
|
||||||
|
$torConf = file_get_contents(CONF['ht']['tor_config_path']);
|
||||||
|
if ($torConf === false)
|
||||||
|
serverError("Failed to read current Tor configuration.");
|
||||||
|
$torConf = str_replace('HiddenServiceDir ' . CONF['ht']['tor_keys_path'] . '/' . $dir . '/
|
||||||
|
HiddenServicePort 80 [::1]:' . CONF['ht']['internal_onion_http_port'] . '
|
||||||
|
', '', $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, $code);
|
||||||
|
if ($code !== 0)
|
||||||
|
serverError("Failed to reload Tor.");
|
||||||
|
|
||||||
|
// Delete Tor keys
|
||||||
|
exec(CONF['ht']['sudo_path'] . " -u " . CONF['ht']['tor_user'] . " " . CONF['ht']['rm_path'] . " --recursive " . CONF['ht']['tor_keys_path'] . "/" . $dir, $output, $code);
|
||||||
|
if ($code !== 0)
|
||||||
|
serverError("Failed to delete Tor keys.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete Nginx config
|
||||||
|
$domain = query('select', 'sites', [
|
||||||
|
'username' => $_SESSION['username'],
|
||||||
|
'domain_type' => $domainType,
|
||||||
|
'protocol' => $protocol,
|
||||||
|
'site_dir' => $dir,
|
||||||
|
], 'domain')[0];
|
||||||
|
if (unlink(CONF['ht']['nginx_config_path'] . '/' . $domain . '.conf') !== true)
|
||||||
|
serverError("Failed to delete Nginx configuration.");
|
||||||
|
|
||||||
|
// Reload Nginx
|
||||||
|
exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['systemctl_path'] . ' reload nginx', result_code: $code);
|
||||||
|
if ($code !== 0)
|
||||||
|
serverError("Failed to reload Nginx.");
|
||||||
|
|
||||||
|
// Delete from database
|
||||||
|
query('delete', 'sites', [
|
||||||
|
'username' => $_SESSION['username'],
|
||||||
|
'domain_type' => $domainType,
|
||||||
|
'protocol' => $protocol,
|
||||||
|
'site_dir' => $dir,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
18
fn/ns.php
18
fn/ns.php
|
@ -35,3 +35,21 @@ function nsCheckZonePossession($zone) {
|
||||||
if (!in_array($zone, query('select', 'zones', ['username' => $_SESSION['username']], 'zone'), true))
|
if (!in_array($zone, query('select', 'zones', ['username' => $_SESSION['username']], 'zone'), true))
|
||||||
userError("You don't own this zone on the nameserver.");
|
userError("You don't own this zone on the nameserver.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nsDeleteZone($zone) {
|
||||||
|
// Remove from Knot configuration
|
||||||
|
knotcConfExec(["unset 'zone[$zone]'"]);
|
||||||
|
|
||||||
|
// Remove Knot zone file
|
||||||
|
if(unlink(CONF['ns']['knot_zones_path'] . '/' . $zone . 'zone') !== true)
|
||||||
|
serverError("Failed to remove Knot zone file.");
|
||||||
|
|
||||||
|
// Remove Knot related data
|
||||||
|
exec(CONF['dns']['knotc_path'] . " zone-purge " . $zone);
|
||||||
|
|
||||||
|
// Remove from database
|
||||||
|
query('delete', 'zones', [
|
||||||
|
'zone' => $zone,
|
||||||
|
'username' => $_SESSION['username'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
16
fn/reg.php
16
fn/reg.php
|
@ -12,3 +12,19 @@ function regCheckDomainPossession($domain) {
|
||||||
function regIsFree($domain) {
|
function regIsFree($domain) {
|
||||||
return empty(query('select', 'registry', ['domain' => $domain], 'domain'));
|
return empty(query('select', 'registry', ['domain' => $domain], 'domain'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function regDeleteDomain($domain) {
|
||||||
|
// Delete domain from registry file
|
||||||
|
$regFile = file_get_contents(CONF['reg']['registry_file']);
|
||||||
|
if ($regFile === false)
|
||||||
|
serverError("Failed to read current registry File.");
|
||||||
|
$regFile = preg_replace("#[^\n]{0,1024}" . $domain . " {0,1024}[^\n]{0,1024}\n#", "", $regFile);
|
||||||
|
if (file_put_contents(CONF['reg']['registry_file'], $regFile) === false)
|
||||||
|
serverError("Failed to write new registry file.");
|
||||||
|
|
||||||
|
// Delete from Niver's database
|
||||||
|
query('delete', 'registry', [
|
||||||
|
'domain' => $domain,
|
||||||
|
'username' => $_SESSION['username'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?php require "../../common/html.php"; ?>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<input type="checkbox" name="delete" id="delete">
|
||||||
|
<label for="delete">Supprimer mon compte et toutes ses données</label>
|
||||||
|
<br>
|
||||||
|
<input type="submit">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
switchToFormProcess();
|
||||||
|
|
||||||
|
if (!isset($_POST['delete']))
|
||||||
|
userError("Il faut confirmer la suppression du compte");
|
||||||
|
|
||||||
|
foreach (query('select', 'registry', ['username' => $_SESSION['username']], 'domain') as $domain)
|
||||||
|
regDeleteDomain($domain);
|
||||||
|
|
||||||
|
foreach (query('select', 'zones', ['username' => $_SESSION['username']], 'zone') as $zone)
|
||||||
|
nsDeleteZone($zone);
|
||||||
|
|
||||||
|
foreach (query('select', 'sites', [
|
||||||
|
'username' => $_SESSION['username'],
|
||||||
|
'domain_type' => 'onion',
|
||||||
|
'protocol' => 'http',
|
||||||
|
], 'site_dir') as $dir)
|
||||||
|
htDeleteSite($dir, domainType: 'onion', protocol: 'http');
|
||||||
|
|
||||||
|
foreach (query('select', 'sites', [
|
||||||
|
'username' => $_SESSION['username'],
|
||||||
|
'domain_type' => 'dns',
|
||||||
|
'protocol' => 'http',
|
||||||
|
], 'site_dir') as $dir)
|
||||||
|
htDeleteSite($dir, domainType: 'dns', protocol: 'http');
|
||||||
|
|
||||||
|
// PHP rmdir() only works on empty directories
|
||||||
|
$dirObj = new RecursiveDirectoryIterator(CONF['ht']['ht_path'] . "/" . $_SESSION['username'], RecursiveDirectoryIterator::SKIP_DOTS);
|
||||||
|
$files = new RecursiveIteratorIterator($dirObj, RecursiveIteratorIterator::CHILD_FIRST);
|
||||||
|
foreach ($files as $path)
|
||||||
|
$path->isDir() && !$path->isLink() ? rmdir($path->getPathname()) : unlink($path->getPathname());
|
||||||
|
if (rmdir(CONF['ht']['ht_path'] . '/' . $_SESSION['username']) !== true)
|
||||||
|
serverError("Unable to delete user's hypertext directory.");
|
||||||
|
|
||||||
|
query('delete', 'users', ['username' => $_SESSION['username']]);
|
||||||
|
|
||||||
|
redir();
|
||||||
|
|
||||||
|
success("Compte supprimé.");
|
|
@ -5,9 +5,9 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<label for="dir">Dossier ciblé</label><br>
|
<label for="dir">Dossier ciblé</label><br>
|
||||||
<select required="" name="dir" id="dir">
|
<select required="" name="dir" id="dir">
|
||||||
<option value="" disabled="" selected="">---</option>
|
<option value="" disabled="" selected="">---</option>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ if (isset($_SESSION['username'])) {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
<br>
|
<br>
|
||||||
<input value="Valider" type="submit">
|
<input value="Valider" type="submit">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
@ -34,27 +34,6 @@ switchToFormProcess();
|
||||||
if ($dirsStatuses[$_POST['dir']] !== true)
|
if ($dirsStatuses[$_POST['dir']] !== true)
|
||||||
userError("Wrong value for <code>dir</code>.");
|
userError("Wrong value for <code>dir</code>.");
|
||||||
|
|
||||||
// Delete Nginx config
|
htDeleteSite($_POST['dir'], domainType: 'dns', protocol: 'http');
|
||||||
$onion = query('select', 'sites', [
|
|
||||||
'username' => $_SESSION['username'],
|
|
||||||
'domain_type' => 'dns',
|
|
||||||
'protocol' => 'http',
|
|
||||||
'site_dir' => $_POST['dir'],
|
|
||||||
], 'domain')[0];
|
|
||||||
if (unlink(CONF['ht']['nginx_config_path'] . "/" . $onion . ".conf") !== true)
|
|
||||||
serverError("Failed to delete Nginx configuration.");
|
|
||||||
|
|
||||||
// Reload Nginx
|
success("Accès retiré.");
|
||||||
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx", result_code: $code);
|
|
||||||
if ($code !== 0)
|
|
||||||
serverError("Failed to reload Nginx.");
|
|
||||||
|
|
||||||
// Delete from database
|
|
||||||
query('delete', 'sites', [
|
|
||||||
'username' => $_SESSION['username'],
|
|
||||||
'domain_type' => 'dns',
|
|
||||||
'protocol' => 'http',
|
|
||||||
'site_dir' => $_POST['dir'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
success("Accès retiré avec succès.");
|
|
||||||
|
|
|
@ -34,47 +34,6 @@ switchToFormProcess();
|
||||||
if ($dirsStatuses[$_POST['dir']] !== true)
|
if ($dirsStatuses[$_POST['dir']] !== true)
|
||||||
userError("Wrong value for <code>dir</code>.");
|
userError("Wrong value for <code>dir</code>.");
|
||||||
|
|
||||||
// Delete Tor config
|
htDeleteSite($_POST['dir'], domainType: 'onion', protocol: 'http');
|
||||||
$torConf = file_get_contents(CONF['ht']['tor_config_path']);
|
|
||||||
if ($torConf === false)
|
|
||||||
serverError("Failed to read current Tor configuration.");
|
|
||||||
$torConf = str_replace("HiddenServiceDir " . CONF['ht']['tor_keys_path'] . "/" . $_POST['dir'] . "/
|
|
||||||
HiddenServicePort 80 [::1]:" . CONF['ht']['internal_onion_http_port'] . "
|
|
||||||
", "", $torConf);
|
|
||||||
if (file_put_contents(CONF['ht']['tor_config_path'], $torConf) === false)
|
|
||||||
serverError("Failed to write new Tor configuration.");
|
|
||||||
|
|
||||||
// Reload Tor
|
success("Accès retiré.");
|
||||||
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload " . CONF['ht']['tor_service'], $output, $code);
|
|
||||||
if ($code !== 0)
|
|
||||||
serverError("Failed to reload Tor.");
|
|
||||||
|
|
||||||
// Delete Tor keys
|
|
||||||
exec(CONF['ht']['sudo_path'] . " -u " . CONF['ht']['tor_user'] . " " . CONF['ht']['rm_path'] . " --recursive " . CONF['ht']['tor_keys_path'] . "/" . $_POST['dir'], $output, $code);
|
|
||||||
if ($code !== 0)
|
|
||||||
serverError("Failed to delete Tor keys.");
|
|
||||||
|
|
||||||
// Delete Nginx config
|
|
||||||
$onion = query('select', 'sites', [
|
|
||||||
'username' => $_SESSION['username'],
|
|
||||||
'domain_type' => 'onion',
|
|
||||||
'protocol' => 'http',
|
|
||||||
'site_dir' => $_POST['dir'],
|
|
||||||
], 'domain')[0];
|
|
||||||
if (unlink(CONF['ht']['nginx_config_path'] . "/" . $onion . ".conf") !== true)
|
|
||||||
serverError("Failed to delete Nginx configuration.");
|
|
||||||
|
|
||||||
// Reload Nginx
|
|
||||||
exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx", result_code: $code);
|
|
||||||
if ($code !== 0)
|
|
||||||
serverError("Failed to reload Nginx.");
|
|
||||||
|
|
||||||
// Delete from database
|
|
||||||
query('delete', 'sites', [
|
|
||||||
'username' => $_SESSION['username'],
|
|
||||||
'domain_type' => 'onion',
|
|
||||||
'protocol' => 'http',
|
|
||||||
'site_dir' => $_POST['dir'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
success("Accès retiré avec succès.");
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ if (!(preg_match("/^[a-z]{1,127}$/", $_POST['tag'])))
|
||||||
if (!(preg_match("/^[a-z0-9.-]{1,255}$/", $_POST['value'])))
|
if (!(preg_match("/^[a-z0-9.-]{1,255}$/", $_POST['value'])))
|
||||||
userError("Wrong value for <code>value</code>.");
|
userError("Wrong value for <code>value</code>.");
|
||||||
|
|
||||||
knotcExec($_POST['zone'], array(
|
knotcZoneExec($_POST['zone'], array(
|
||||||
$values['domain'],
|
$values['domain'],
|
||||||
$values['ttl'],
|
$values['ttl'],
|
||||||
"CAA",
|
"CAA",
|
||||||
|
|
|
@ -20,7 +20,7 @@ $values = nsParseCommonRequirements();
|
||||||
|
|
||||||
$record = checkIpFormat($_POST['ip']);
|
$record = checkIpFormat($_POST['ip']);
|
||||||
|
|
||||||
knotcExec($_POST['zone'], array(
|
knotcZoneExec($_POST['zone'], array(
|
||||||
$values['domain'],
|
$values['domain'],
|
||||||
$values['ttl'],
|
$values['ttl'],
|
||||||
$record,
|
$record,
|
||||||
|
|
|
@ -31,7 +31,7 @@ if (!($_POST['priority'] >= 0 AND $_POST['priority'] <= 255))
|
||||||
|
|
||||||
$_POST['host'] = formatAbsoluteDomain($_POST['host']);
|
$_POST['host'] = formatAbsoluteDomain($_POST['host']);
|
||||||
|
|
||||||
knotcExec($_POST['zone'], array(
|
knotcZoneExec($_POST['zone'], array(
|
||||||
$values['domain'],
|
$values['domain'],
|
||||||
$values['ttl'],
|
$values['ttl'],
|
||||||
"MX",
|
"MX",
|
||||||
|
|
|
@ -18,7 +18,7 @@ $values = nsParseCommonRequirements();
|
||||||
|
|
||||||
$_POST['ns'] = formatAbsoluteDomain($_POST['ns']);
|
$_POST['ns'] = formatAbsoluteDomain($_POST['ns']);
|
||||||
|
|
||||||
knotcExec($_POST['zone'], array(
|
knotcZoneExec($_POST['zone'], array(
|
||||||
$values['domain'],
|
$values['domain'],
|
||||||
$values['ttl'],
|
$values['ttl'],
|
||||||
"NS",
|
"NS",
|
||||||
|
|
|
@ -49,7 +49,7 @@ if (!($_POST['port'] >= 0 AND $_POST['port'] <= 65535))
|
||||||
|
|
||||||
$_POST['target'] = formatAbsoluteDomain($_POST['target']);
|
$_POST['target'] = formatAbsoluteDomain($_POST['target']);
|
||||||
|
|
||||||
knotcExec($_POST['zone'], array(
|
knotcZoneExec($_POST['zone'], array(
|
||||||
$values['domain'],
|
$values['domain'],
|
||||||
$values['ttl'],
|
$values['ttl'],
|
||||||
"SRV",
|
"SRV",
|
||||||
|
|
|
@ -48,7 +48,7 @@ if (!($_POST['type'] === "2"))
|
||||||
if (!(preg_match("/^[a-z0-9]{64}$/", $_POST['fp'])))
|
if (!(preg_match("/^[a-z0-9]{64}$/", $_POST['fp'])))
|
||||||
userError("Wrong value for <code>fp</code>.");
|
userError("Wrong value for <code>fp</code>.");
|
||||||
|
|
||||||
knotcExec($_POST['zone'], array(
|
knotcZoneExec($_POST['zone'], array(
|
||||||
$values['domain'],
|
$values['domain'],
|
||||||
$values['ttl'],
|
$values['ttl'],
|
||||||
"SSHFP",
|
"SSHFP",
|
||||||
|
|
|
@ -60,7 +60,7 @@ if (!($_POST['type'] >= 0 AND $_POST['type'] <= 2))
|
||||||
if (!(preg_match("/^[a-zA-Z0-9.-]{1,1024}$/", $_POST['content'])))
|
if (!(preg_match("/^[a-zA-Z0-9.-]{1,1024}$/", $_POST['content'])))
|
||||||
userError("Wrong value for <code>content</code>.");
|
userError("Wrong value for <code>content</code>.");
|
||||||
|
|
||||||
knotcExec($_POST['zone'], array(
|
knotcZoneExec($_POST['zone'], array(
|
||||||
$values['domain'],
|
$values['domain'],
|
||||||
$values['ttl'],
|
$values['ttl'],
|
||||||
"TLSA",
|
"TLSA",
|
||||||
|
|
|
@ -19,7 +19,7 @@ $values = nsParseCommonRequirements();
|
||||||
if (!(preg_match("/^[a-zA-Z0-9 =:!%$+\/\()[\]_-]{5,8192}$/", $_POST['txt'])))
|
if (!(preg_match("/^[a-zA-Z0-9 =:!%$+\/\()[\]_-]{5,8192}$/", $_POST['txt'])))
|
||||||
userError("Wrong value for <code>txt</code>.");
|
userError("Wrong value for <code>txt</code>.");
|
||||||
|
|
||||||
knotcExec($_POST['zone'], array(
|
knotcZoneExec($_POST['zone'], array(
|
||||||
$values['domain'],
|
$values['domain'],
|
||||||
$values['ttl'],
|
$values['ttl'],
|
||||||
"TXT",
|
"TXT",
|
||||||
|
|
|
@ -29,9 +29,9 @@ if (is_int(file_put_contents($knotZonePath, $knotZone)) !== true)
|
||||||
if (chmod($knotZonePath, 0660) !== true)
|
if (chmod($knotZonePath, 0660) !== true)
|
||||||
serverError("Failed to chmod new zone file.");
|
serverError("Failed to chmod new zone file.");
|
||||||
|
|
||||||
exec(CONF['dns']['knotc_path'] . " conf-begin");
|
knotcConfExec([
|
||||||
exec(CONF['dns']['knotc_path'] . " conf-set 'zone[" . $_POST['domain'] . "]'");
|
"set 'zone[" . $_POST['domain'] . "]'",
|
||||||
exec(CONF['dns']['knotc_path'] . " conf-set 'zone[" . $_POST['domain'] . "].template' 'niver'");
|
"set 'zone[" . $_POST['domain'] . "].template' 'niver'",
|
||||||
exec(CONF['dns']['knotc_path'] . " conf-commit");
|
]);
|
||||||
|
|
||||||
success("La requête a été traitée.");
|
success("La requête a été traitée.");
|
||||||
|
|
|
@ -20,22 +20,6 @@ switchToFormProcess();
|
||||||
|
|
||||||
nsCheckZonePossession($_POST['zone']);
|
nsCheckZonePossession($_POST['zone']);
|
||||||
|
|
||||||
// Remove from Knot configuration
|
nsDeleteZone($_POST['zone']);
|
||||||
exec(CONF['dns']['knotc_path'] . " conf-begin");
|
|
||||||
exec(CONF['dns']['knotc_path'] . " conf-unset 'zone[" . $_POST['zone'] . "]'");
|
|
||||||
exec(CONF['dns']['knotc_path'] . " conf-commit");
|
|
||||||
|
|
||||||
// Remove Knot zone file
|
|
||||||
if(unlink(CONF['ns']['knot_zones_path'] . "/" . $_POST['zone'] . "zone") !== true)
|
|
||||||
serverError("Failed to remove Knot zone file.");
|
|
||||||
|
|
||||||
// Remove Knot related data
|
|
||||||
exec(CONF['dns']['knotc_path'] . " zone-purge " . $_POST['zone']);
|
|
||||||
|
|
||||||
// Remove from database
|
|
||||||
query('delete', 'zones', [
|
|
||||||
'zone' => $_POST['zone'],
|
|
||||||
'username' => $_SESSION['username'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
success("Zone effacée.");
|
success("Zone effacée.");
|
||||||
|
|
|
@ -86,7 +86,7 @@ regCheckDomainPossession($_POST['zone']);
|
||||||
|
|
||||||
$action = checkAction($_POST['action']);
|
$action = checkAction($_POST['action']);
|
||||||
|
|
||||||
knotcExec(CONF['reg']['registry'], array(
|
knotcZoneExec(CONF['reg']['registry'], array(
|
||||||
$_POST['zone'],
|
$_POST['zone'],
|
||||||
CONF['reg']['ttl'],
|
CONF['reg']['ttl'],
|
||||||
"DS",
|
"DS",
|
||||||
|
|
|
@ -45,7 +45,7 @@ $domain = formatAbsoluteDomain(formatEndWithDot($_POST['subdomain']) . $_POST['s
|
||||||
|
|
||||||
$record = checkIpFormat($_POST['ip']);
|
$record = checkIpFormat($_POST['ip']);
|
||||||
|
|
||||||
knotcExec(CONF['reg']['registry'], array(
|
knotcZoneExec(CONF['reg']['registry'], array(
|
||||||
$domain,
|
$domain,
|
||||||
CONF['reg']['ttl'],
|
CONF['reg']['ttl'],
|
||||||
$record,
|
$record,
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
<option value="" disabled="" selected="">---</option>
|
<option value="" disabled="" selected="">---</option>
|
||||||
<?php
|
<?php
|
||||||
if (isset($_SESSION['username']))
|
if (isset($_SESSION['username']))
|
||||||
foreach(regListUserDomains($_SESSION['username']) as $suffix)
|
foreach(regListUserDomains($_SESSION['username']) as $domain)
|
||||||
echo " <option value='" . $suffix . "'>." . $suffix . "</option>\n";
|
echo " <option value='" . $domain . "'>" . $domain . "</option>\n";
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
@ -33,7 +33,7 @@ switchToFormProcess();
|
||||||
regCheckDomainPossession($_POST['domain']);
|
regCheckDomainPossession($_POST['domain']);
|
||||||
$_POST['ns'] = formatAbsoluteDomain($_POST['ns']);
|
$_POST['ns'] = formatAbsoluteDomain($_POST['ns']);
|
||||||
|
|
||||||
knotcExec(CONF['reg']['registry'], array(
|
knotcZoneExec(CONF['reg']['registry'], array(
|
||||||
$_POST['domain'],
|
$_POST['domain'],
|
||||||
CONF['reg']['ttl'],
|
CONF['reg']['ttl'],
|
||||||
"NS",
|
"NS",
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
<option value="" disabled="" selected="">---</option>
|
<option value="" disabled="" selected="">---</option>
|
||||||
<?php
|
<?php
|
||||||
if (isset($_SESSION['username']))
|
if (isset($_SESSION['username']))
|
||||||
foreach(regListUserDomains($_SESSION['username']) as $suffix)
|
foreach(regListUserDomains($_SESSION['username']) as $domain)
|
||||||
echo " <option value='" . $suffix . "'>." . $suffix . "</option>\n";
|
echo " <option value='" . $domain . "'>" . $domain . "</option>\n";
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
@ -22,21 +22,6 @@ switchToFormProcess();
|
||||||
|
|
||||||
regCheckDomainPossession($_POST['domain']);
|
regCheckDomainPossession($_POST['domain']);
|
||||||
|
|
||||||
// Add Tor config
|
regDeleteDomain($_POST['domain']);
|
||||||
$regFile = file_get_contents(CONF['reg']['registry_file']);
|
|
||||||
if ($regFile === false)
|
|
||||||
serverError("Failed to read current registry File.");
|
|
||||||
$regFile = preg_replace("#[^\n]{0,1024}" . $_POST['domain'] . " {0,1024}[^\n]{0,1024}\n#", "", $regFile);
|
|
||||||
if (file_put_contents(CONF['reg']['registry_file'], $regFile) === false)
|
|
||||||
serverError("Failed to write new registry file.");
|
|
||||||
|
|
||||||
// Remove from Niver's database
|
|
||||||
$db = new PDO('sqlite:' . DB_PATH);
|
|
||||||
$stmt = $db->prepare("DELETE FROM registry WHERE domain = :domain AND username = :username");
|
|
||||||
|
|
||||||
$stmt->bindValue(':domain', $_POST['domain']);
|
|
||||||
$stmt->bindValue(':username', $_SESSION['username']);
|
|
||||||
|
|
||||||
$stmt->execute();
|
|
||||||
|
|
||||||
success("Domaine effacé du registre.");
|
success("Domaine effacé du registre.");
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require "common/init.php";
|
require "common/init.php";
|
||||||
require "fn/auth.php";
|
|
||||||
|
|
||||||
$authData = json_decode(file_get_contents("php://input"), true);
|
$authData = json_decode(file_get_contents("php://input"), true);
|
||||||
$user = json_decode($authData['user'], true);
|
$user = json_decode($authData['user'], true);
|
||||||
|
|
Loading…
Reference in New Issue