Fix zone deletion process (again)

This commit is contained in:
Miraty 2023-05-06 02:39:19 +02:00
parent 23d7e7fc5b
commit a83ae30ce7

View file

@ -1,30 +1,21 @@
<?php
define('SOA_VALUES', [
const SOA_VALUES = [
'ttl' => 10800,
'email' => CONF['ns']['public_soa_email'],
'refresh' => 10800,
'retry' => 3600,
'expire' => 3628800,
'negative' => 10800,
]);
];
define('MIN_TTL', 300);
define('DEFAULT_TTL', 10800);
define('MAX_TTL', 1728000);
const MIN_TTL = 300;
const DEFAULT_TTL = 10800;
const MAX_TTL = 1728000;
define('ALLOWED_TYPES', ['AAAA', 'A', 'TXT', 'SRV', 'MX', 'SVCB', 'HTTPS', 'NS', 'DS', 'CAA', 'CNAME', 'DNAME', 'LOC', 'SSHFP', 'TLSA']);
const ALLOWED_TYPES = ['AAAA', 'A', 'TXT', 'SRV', 'MX', 'SVCB', 'HTTPS', 'NS', 'DS', 'CAA', 'CNAME', 'DNAME', 'LOC', 'SSHFP', 'TLSA'];
define('ZONE_MAX_CHARACTERS', 10000);
function nsCommonRequirements() {
return (isset($_POST['action'])
AND isset($_POST['zone'])
AND isset($_POST['ttl-value'])
AND isset($_POST['ttl-multiplier'])
AND isset($_SESSION['id'])
);
}
const ZONE_MAX_CHARACTERS = 10000;
function nsParseCommonRequirements() {
nsCheckZonePossession($_POST['zone']);
@ -34,7 +25,7 @@ function nsParseCommonRequirements() {
else
$values['domain'] = formatAbsoluteDomain(formatEndWithDot($_POST['subdomain']) . $_POST['zone']);
$values['ttl'] = $_POST['ttl-value'] * $_POST['ttl-multiplier'];
$values['ttl'] = intval($_POST['ttl-value'] * $_POST['ttl-multiplier']);
if ($values['ttl'] < MIN_TTL)
output(403, sprintf(_('TTLs shorter than %s seconds are forbidden.'), MIN_TTL));
@ -58,14 +49,18 @@ function nsCheckZonePossession($zone) {
}
function nsDeleteZone($zone) {
// Delete zone data
exec(CONF['dns']['knotc_path'] . ' --blocking --timeout 3 --force zone-purge ' . $zone, result_code: $code);
if ($code !== 0)
output(500, 'Failed to purge zone data.');
// Remove from Knot configuration
knotcConfExec(["unset 'zone[$zone]'"]);
// Remove Knot zone file
if (unlink(CONF['ns']['knot_zones_path'] . '/' . $zone . 'zone') !== true)
output(500, 'Failed to remove Knot zone file.');
// Remove Knot related data
exec(CONF['dns']['knotc_path'] . ' --blocking --timeout 3 --force zone-purge ' . $zone . ' +orphan', result_code: $code);
if ($code !== 0)
output(500, 'Failed to purge zone data.');
// Remove from database
query('delete', 'zones', [
'zone' => $zone,