servnest/jobs/ns-update.php

28 lines
903 B
PHP
Raw Normal View History

2023-09-20 11:27:00 +00:00
<?php declare(strict_types=1);
require __DIR__ . '/../init.php';
foreach (query('select', 'zones') as $zone) {
// Get current NS records
$zone_raw = file_get_contents(CONF['ns']['knot_zones_path'] . '/' . $zone['zone'] . 'zone');
if ($zone_raw === false)
output(403, 'Unable to read zone file.');
$current_ns_records = array_column(parseZoneFile($zone_raw, ['NS'], $zone['zone'], false), 3);
// Add config NS records that are not yet in current
foreach (array_diff(CONF['ns']['servers'], $current_ns_records) as $value_to_add)
knotcZoneExec($zone['zone'], [
$zone['zone'],
CONF['reg']['ttl'],
'NS',
$value_to_add,
], 'add');
// Delete current NS records that are not part of config anymore
foreach (array_diff($current_ns_records, CONF['ns']['servers']) as $value_to_delete)
knotcZoneExec($zone['zone'], [
$zone['zone'],
'NS',
$value_to_delete,
], 'delete');
}