2021-02-19 12:23:26 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-20 00:05:03 +00:00
|
|
|
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);
|
|
|
|
|
2021-05-16 14:55:39 +00:00
|
|
|
function nsCommonRequirements() {
|
2022-05-22 15:47:00 +00:00
|
|
|
return (isset($_POST['action'])
|
2022-04-18 14:05:00 +00:00
|
|
|
AND isset($_POST['zone'])
|
|
|
|
AND isset($_POST['ttl-value'])
|
|
|
|
AND isset($_POST['ttl-multiplier'])
|
2022-11-30 22:12:42 +00:00
|
|
|
AND isset($_SESSION['id'])
|
2022-05-22 15:47:00 +00:00
|
|
|
);
|
2021-05-16 14:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function nsParseCommonRequirements() {
|
2022-04-18 14:05:00 +00:00
|
|
|
nsCheckZonePossession($_POST['zone']);
|
2021-07-15 13:36:34 +00:00
|
|
|
|
2022-11-20 00:05:03 +00:00
|
|
|
if (($_POST['subdomain'] === '') OR ($_POST['subdomain'] === '@'))
|
2022-04-18 14:05:00 +00:00
|
|
|
$values['domain'] = $_POST['zone'];
|
|
|
|
else
|
2022-06-15 13:30:18 +00:00
|
|
|
$values['domain'] = formatAbsoluteDomain(formatEndWithDot($_POST['subdomain']) . $_POST['zone']);
|
2021-05-16 14:55:39 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
$values['ttl'] = $_POST['ttl-value'] * $_POST['ttl-multiplier'];
|
2021-03-02 21:56:38 +00:00
|
|
|
|
2022-11-20 00:05:03 +00:00
|
|
|
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.');
|
2021-03-02 21:56:38 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
return $values;
|
2021-03-02 21:56:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 20:17:03 +00:00
|
|
|
function nsListUserZones() {
|
|
|
|
if (isset($_SESSION['id']))
|
|
|
|
return query('select', 'zones', ['username' => $_SESSION['id']], 'zone');
|
|
|
|
return [];
|
2021-04-14 12:56:02 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 13:30:18 +00:00
|
|
|
function nsCheckZonePossession($zone) {
|
|
|
|
checkAbsoluteDomainFormat($zone);
|
2021-02-19 12:23:26 +00:00
|
|
|
|
2022-11-30 22:12:42 +00:00
|
|
|
if (!in_array($zone, query('select', 'zones', ['username' => $_SESSION['id']], 'zone'), true))
|
2022-09-15 17:17:48 +00:00
|
|
|
output(403, 'You don\'t own this zone on the nameserver.');
|
2021-02-19 12:23:26 +00:00
|
|
|
}
|
2022-06-18 02:22:05 +00:00
|
|
|
|
|
|
|
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)
|
2022-09-15 17:17:48 +00:00
|
|
|
output(500, 'Failed to remove Knot zone file.');
|
2022-06-18 02:22:05 +00:00
|
|
|
|
|
|
|
// Remove Knot related data
|
2022-11-20 14:11:54 +00:00
|
|
|
exec(CONF['dns']['knotc_path'] . ' zone-purge ' . $zone);
|
2022-06-18 02:22:05 +00:00
|
|
|
|
|
|
|
// Remove from database
|
|
|
|
query('delete', 'zones', [
|
|
|
|
'zone' => $zone,
|
2022-11-30 22:12:42 +00:00
|
|
|
'username' => $_SESSION['id'],
|
2022-06-18 02:22:05 +00:00
|
|
|
]);
|
|
|
|
}
|