dnsphpadmin/includes/nsupdate.php
2018-12-13 11:53:20 +01:00

77 lines
2.2 KiB
PHP

<?php
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Security check
if (!defined('G_DNSTOOL_ENTRY_POINT'))
die("Not a valid entry point");
require_once("config.php");
require_once("debug.php");
require_once("fatal.php");
function nsupdate($input, $tsig_override = NULL, $tsig_override_key = NULL)
{
global $g_nsupdate, $g_tsig_key, $g_tsig;
// check if we want to use TSIG for this update
$using_tsig = $g_tsig;
if ($tsig_override === true || $tsig_override === false)
$using_tsig = $tsig_override;
// get TSIG key, it can be overriden on custom requests
$tsig_key = $g_tsig_key;
if ($tsig_override_key !== NULL)
$tsig_key = $tsig_override_key;
if ($using_tsig)
$input = "key " . $tsig_key . "\n" . $input;
$desc = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w')
);
$pipes = array();
$cwd = '/tmp';
$env = array();
$proc = proc_open($g_nsupdate, $desc, $pipes, $cwd, $env);
if (!is_resource($proc))
{
Error("Unable to execute " . $g_nsupdate);
}
Debug("Sending this to nsupdate:\n" . $input);
fwrite($pipes[0], $input);
$output = stream_get_contents($pipes[1]);
$errors = stream_get_contents($pipes[2]);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
$ret = proc_close($proc);
if ($ret > 0)
{
Error($g_nsupdate . " return code " . $ret . ": " . $errors);
}
return $output;
}
function dig($parameters)
{
global $g_dig;
return shell_exec($g_dig . " " . $parameters);
}
function get_zone_data($zone)
{
global $g_domains;
$zone_servers = $g_domains[$zone];
$data = dig("axfr " . $zone . " @" . $zone_servers["transfer_server"]);
return $data;
}