|
@@ -15,42 +15,53 @@ function parseZoneFile($zone_content, $types, $filter_domain = false) {
|
|
|
return $parsed_zone_content;
|
|
|
}
|
|
|
|
|
|
-function knotcConfExec($cmds) {
|
|
|
- exec(CONF['dns']['knotc_path'] . ' --blocking --timeout 3 conf-begin', $output['begin'], $code['begin']);
|
|
|
+function knotc(array $cmds, array &$output = NULL, int &$return_code = NULL): void {
|
|
|
+ exescape([
|
|
|
+ CONF['dns']['knotc_path'],
|
|
|
+ '--blocking',
|
|
|
+ '--timeout',
|
|
|
+ '3',
|
|
|
+ '--',
|
|
|
+ ...$cmds,
|
|
|
+ ], $output, $return_code);
|
|
|
+}
|
|
|
+
|
|
|
+function knotcConfExec(array $cmds): void {
|
|
|
+ knotc(['conf-begin'], $output['begin'], $code['begin']);
|
|
|
if ($code['begin'] !== 0)
|
|
|
output(500, 'knotcConfExec: <code>knotc</code> failed with exit code <samp>' . $code['begin'] . '</samp>: <samp>' . $output['begin'][0] . '</samp>.');
|
|
|
|
|
|
foreach ($cmds as $cmd) {
|
|
|
- exec(CONF['dns']['knotc_path'] . ' --blocking --timeout 3 conf-' . $cmd, $output['op'], $code['op']);
|
|
|
+ knotc($cmd, $output['op'], $code['op']);
|
|
|
if ($code['op'] !== 0) {
|
|
|
- exec(CONF['dns']['knotc_path'] . ' --blocking conf-abort');
|
|
|
+ knotc(['conf-abort']);
|
|
|
output(500, 'knotcConfExec: <code>knotc</code> failed with exit code <samp>' . $code['op'] . '</samp>: <samp>' . $output['op'][0] . '</samp>.');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- exec(CONF['dns']['knotc_path'] . ' --blocking --timeout 3 conf-commit', $output['commit'], $code['commit']);
|
|
|
+ knotc(['conf-commit'], $output['commit'], $code['commit']);
|
|
|
if ($code['commit'] !== 0) {
|
|
|
- exec(CONF['dns']['knotc_path'] . ' --blocking conf-abort');
|
|
|
+ knotc(['conf-abort']);
|
|
|
output(500, 'knotcConfExec: <code>knotc</code> failed with exit code <samp>' . $code['commit'] . '</samp>: <samp>' . $output['commit'][0] . '</samp>.');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function knotcZoneExec($zone, $cmd, $action = NULL) {
|
|
|
+function knotcZoneExec(string $zone, array $cmd, string $action = NULL) {
|
|
|
$action = checkAction($action ?? $_POST['action']);
|
|
|
|
|
|
- exec(CONF['dns']['knotc_path'] . ' --blocking --timeout 3 zone-begin ' . $zone, $output['begin'], $code['begin']);
|
|
|
+ knotc(['zone-begin', $zone], $output['begin'], $code['begin']);
|
|
|
if ($code['begin'] !== 0)
|
|
|
output(500, 'knotcZoneExec: <code>knotc</code> failed with exit code <samp>' . $code['begin'] . '</samp>: <samp>' . $output['begin'][0] . '</samp>.');
|
|
|
|
|
|
- exec(CONF['dns']['knotc_path'] . ' --blocking --timeout 3 zone-' . $action . 'set ' . $zone . ' ' . implode(' ', $cmd), $output['op'], $code['op']);
|
|
|
+ knotc(['zone-' . $action . 'set', $zone, ...$cmd], $output['op'], $code['op']);
|
|
|
if ($code['op'] !== 0) {
|
|
|
- exec(CONF['dns']['knotc_path'] . ' --blocking --timeout 3 zone-abort ' . $zone);
|
|
|
+ knotc(['zone-abort', $zone]);
|
|
|
output(500, 'knotcZoneExec: <code>knotc</code> failed with exit code <samp>' . $code['op'] . '</samp>: <samp>' . $output['op'][0] . '</samp>.');
|
|
|
}
|
|
|
|
|
|
- exec(CONF['dns']['knotc_path'] . ' --blocking --timeout 3 zone-commit ' . $zone, $output['commit'], $code['commit']);
|
|
|
+ knotc(['zone-commit', $zone], $output['commit'], $code['commit']);
|
|
|
if ($code['commit'] !== 0) {
|
|
|
- exec(CONF['dns']['knotc_path'] . ' --blocking --timeout 3 zone-abort ' . $zone);
|
|
|
+ knotc(['zone-abort', $zone]);
|
|
|
output(500, 'knotcZoneExec: <code>knotc</code> failed with exit code <samp>' . $code['commit'] . '</samp>: <samp>' . $output['commit'][0] . '</samp>.');
|
|
|
}
|
|
|
}
|