38 lines
823 B
PHP
38 lines
823 B
PHP
|
<?php
|
||
|
|
||
|
$el_nb = count($_POST['syncs']);
|
||
|
if ($el_nb < 1 OR $el_nb > 8)
|
||
|
output(403, 'Wrong elements number.');
|
||
|
|
||
|
foreach ($_POST['syncs'] as $i => &$sync) {
|
||
|
if (($sync['source'] ?? '') === '') {
|
||
|
unset($_POST['syncs'][$i]);
|
||
|
continue;
|
||
|
}
|
||
|
$sync['source'] = formatAbsoluteDomain($sync['source']);
|
||
|
nsCheckZonePossession($sync['destination']);
|
||
|
}
|
||
|
$syncs = array_values($_POST['syncs']);
|
||
|
|
||
|
rateLimit();
|
||
|
|
||
|
try {
|
||
|
DB->beginTransaction();
|
||
|
|
||
|
query('delete', 'ns-syncs', ['username' => $_SESSION['id']]);
|
||
|
|
||
|
foreach ($syncs as $sync)
|
||
|
insert('ns-syncs', [
|
||
|
'username' => $_SESSION['id'],
|
||
|
'source' => $sync['source'],
|
||
|
'destination' => $sync['destination'],
|
||
|
]);
|
||
|
|
||
|
DB->commit();
|
||
|
} catch (Exception $e) {
|
||
|
DB->rollback();
|
||
|
output(500, 'Database error.', [$e->getMessage()]);
|
||
|
}
|
||
|
|
||
|
output(200, _('Synchronized records updated.'));
|