74 lines
2 KiB
PHP
74 lines
2 KiB
PHP
<?php
|
|
|
|
define('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);
|
|
|
|
define('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['username'])
|
|
);
|
|
}
|
|
|
|
function nsParseCommonRequirements() {
|
|
nsCheckZonePossession($_POST['zone']);
|
|
|
|
if (($_POST['subdomain'] === '') OR ($_POST['subdomain'] === '@'))
|
|
$values['domain'] = $_POST['zone'];
|
|
else
|
|
$values['domain'] = formatAbsoluteDomain(formatEndWithDot($_POST['subdomain']) . $_POST['zone']);
|
|
|
|
$values['ttl'] = $_POST['ttl-value'] * $_POST['ttl-multiplier'];
|
|
|
|
if ($values['ttl'] < MIN_TTL)
|
|
output(403, 'Les TTLs inférieurs à ' . MIN_TTL . ' secondes ne sont pas autorisés.');
|
|
if ($values['ttl'] > MAX_TTL)
|
|
output(403, 'Les TTLs supérieurs à ' . MAX_TTL . ' secondes ne sont pas autorisés.');
|
|
|
|
return $values;
|
|
}
|
|
|
|
function nsListUserZones($username) {
|
|
return query('select', 'zones', ['username' => $username], 'zone');
|
|
}
|
|
|
|
function nsCheckZonePossession($zone) {
|
|
checkAbsoluteDomainFormat($zone);
|
|
|
|
if (!in_array($zone, query('select', 'zones', ['username' => $_SESSION['username']], 'zone'), true))
|
|
output(403, '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)
|
|
output(500, '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'],
|
|
]);
|
|
}
|