knotc failed with exit code " . $code['begin'] . ": " . $output['begin'][0] . "."); foreach ($cmds as $cmd) { exec(CONF['dns']['knotc_path'] . " conf-" . $cmd, $output['op'], $code['op']); if ($code['op'] !== 0) { exec(CONF['dns']['knotc_path'] . " conf-abort"); serverError("knotcConfExec: knotc failed with exit code " . $code['op'] . ": " . $output['op'][0] . "."); } } exec(CONF['dns']['knotc_path'] . " conf-commit", $output['commit'], $code['commit']); if ($code['commit'] !== 0) { exec(CONF['dns']['knotc_path'] . " conf-abort"); serverError("knotcConfExec: knotc failed with exit code " . $code['commit'] . ": " . $output['commit'][0] . "."); } } function knotcZoneExec($zone, $cmd) { $action = checkAction($_POST['action']); exec(CONF['dns']['knotc_path'] . " zone-begin " . $zone, $output['begin'], $code['begin']); if ($code['begin'] !== 0) serverError("knotcZoneExec: knotc failed with exit code " . $code['begin'] . ": " . $output['begin'][0] . "."); exec(CONF['dns']['knotc_path'] . " zone-" . $action . "set " . $zone . " " . implode(" ", $cmd), $output['op'], $code['op']); if ($code['op'] !== 0) { exec(CONF['dns']['knotc_path'] . " zone-abort " . $zone); serverError("knotcZoneExec: knotc failed with exit code " . $code['op'] . ": " . $output['op'][0] . "."); } exec(CONF['dns']['knotc_path'] . " zone-commit " . $zone, $output['commit'], $code['commit']); if ($code['commit'] !== 0) { exec(CONF['dns']['knotc_path'] . " zone-abort " . $zone); serverError("knotcZoneExec: knotc failed with exit code " . $code['commit'] . ": " . $output['commit'][0] . "."); } } function checkIpFormat($ip) { if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) userError("IP address is on the reserved range."); if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) return "A"; if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) return "AAAA"; userError("IP address malformed."); } function checkAbsoluteDomainFormat($domain) { // If the domain must end with a dot if (!filter_var($domain, FILTER_VALIDATE_DOMAIN) OR !preg_match("/^([a-z0-9_-]{1,63}\.){2,127}$/", $domain)) userError("Domain malformed."); } function formatEndWithDot($str) { if (!str_ends_with($str, '.')) $str .= '.'; return $str; } function formatAbsoluteDomain($domain) { $domain = formatEndWithDot(strtolower($domain)); checkAbsoluteDomainFormat($domain); return $domain; } function checkAction($action) { return match ($action) { 'add' => '', 'delete' => 'un', default => userError("Wrong value for action."), }; }