83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
|
|
|
const SOA_VALUES = [
|
|
'ttl' => 10800,
|
|
'email' => CONF['ns']['public_soa_email'],
|
|
'refresh' => 10800,
|
|
'retry' => 3600,
|
|
'expire' => 3628800,
|
|
'negative' => 10800,
|
|
];
|
|
|
|
const MIN_TTL = 300;
|
|
const DEFAULT_TTL = 10800;
|
|
const MAX_TTL = 1728000;
|
|
|
|
const ALLOWED_TYPES = ['AAAA', 'A', 'TXT', 'SRV', 'MX', 'SVCB', 'HTTPS', 'NS', 'DS', 'CAA', 'CNAME', 'DNAME', 'LOC', 'SSHFP', 'TLSA'];
|
|
|
|
const ZONE_MAX_CHARACTERS = 10000;
|
|
|
|
const SYNC_TTL = 10800;
|
|
|
|
function nsParseCommonRequirements(): array {
|
|
nsCheckZonePossession($_POST['zone']);
|
|
|
|
if (($_POST['subdomain'] === '') OR ($_POST['subdomain'] === '@'))
|
|
$values['domain'] = $_POST['zone'];
|
|
else
|
|
$values['domain'] = formatAbsoluteDomain(formatEndWithDot($_POST['subdomain']) . $_POST['zone']);
|
|
|
|
$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));
|
|
if ($values['ttl'] > MAX_TTL)
|
|
output(403, sprintf(_('TTLs longer than %s seconds are forbidden.'), MAX_TTL));
|
|
|
|
return $values;
|
|
}
|
|
|
|
function nsListUserZones(): array {
|
|
if (isset($_SESSION['id']))
|
|
return query('select', 'zones', ['username' => $_SESSION['id']], 'zone');
|
|
return [];
|
|
}
|
|
|
|
function nsCheckZonePossession(string $zone): void {
|
|
checkAbsoluteDomainFormat($zone);
|
|
|
|
if (!in_array($zone, nsListUserZones(), true))
|
|
output(403, 'You don\'t own this zone on the name server.');
|
|
}
|
|
|
|
function nsDeleteZone(string $zone, string $user_id): void {
|
|
// Remove from Knot configuration
|
|
knotcConfExec([['conf-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
|
|
exescape([
|
|
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.');
|
|
|
|
query('delete', 'ns-syncs', ['destination' => $zone]);
|
|
|
|
// Remove from database
|
|
query('delete', 'zones', [
|
|
'zone' => $zone,
|
|
'username' => $user_id,
|
|
]);
|
|
}
|