First commit
This commit is contained in:
33
api/addrecord.php
Normal file
33
api/addrecord.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
// header("Content-Type: content/json");
|
||||
header("Content-Type: text/plain");
|
||||
|
||||
function stop($error)
|
||||
{
|
||||
http_response_code(513);
|
||||
$RESPONSE = new stdClass();
|
||||
$RESPONSE->status = "error";
|
||||
$RESPONSE->response = $error;
|
||||
printf(json_encode($RESPONSE));
|
||||
die;
|
||||
}
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] !== "POST" && stop("Method " . $_SERVER['REQUEST_METHOD'] . " not allowed");
|
||||
|
||||
$POST = json_decode(file_get_contents('php://input'));
|
||||
|
||||
$DATA = "<< EOF
|
||||
server 127.0.0.1
|
||||
update add $POST->name $POST->ttl $POST->class $POST->type $POST->rr
|
||||
send
|
||||
EOF";
|
||||
|
||||
passthru("/usr/bin/nsupdate $DATA", $result_code);
|
||||
$result_code === 0 || stop("Unable to update zone");
|
||||
|
||||
$RESPONSE = new stdClass();
|
||||
$RESPONSE->status = "success";
|
||||
$RESPONSE->response = "zone added successfully";
|
||||
|
||||
printf(json_encode($RESPONSE));
|
||||
47
api/getzones.php
Normal file
47
api/getzones.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
header("Content-Type: content/json");
|
||||
|
||||
function stop($error)
|
||||
{
|
||||
http_response_code(513);
|
||||
printf(json_encode($error));
|
||||
die;
|
||||
}
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] !== "GET" && stop("Method " . $_SERVER['REQUEST_METHOD'] . " not allowed");
|
||||
|
||||
$result_code = 0;
|
||||
passthru("/usr/bin/rndc dumpdb -zones", $result_code);
|
||||
$result_code === 0 || stop("Unable to get zone");
|
||||
sleep(2);
|
||||
|
||||
$HANDLE = fopen("/var/named/named_dump.db", "r");
|
||||
$HANDLE || stop("Unable to read zone db");
|
||||
|
||||
$ZONE = new stdClass();
|
||||
$CURRENTZONE = "";
|
||||
|
||||
while (($LINE = fgets($HANDLE)) !== false) {
|
||||
if (str_starts_with($LINE, ";")) continue;
|
||||
$LINE = preg_split("/\s+/", $LINE);
|
||||
if ($LINE[3] === "SOA") {
|
||||
$CURRENTZONE = $LINE[0];
|
||||
$ZONE->$CURRENTZONE = [];
|
||||
}
|
||||
|
||||
$RECORD = new stdClass();
|
||||
$RECORD->name = $LINE[0];
|
||||
array_shift($LINE);
|
||||
$RECORD->ttl = $LINE[0];
|
||||
array_shift($LINE);
|
||||
$RECORD->class = $LINE[0];
|
||||
array_shift($LINE);
|
||||
$RECORD->type = $LINE[0];
|
||||
array_shift($LINE);
|
||||
$RECORD->rr = implode(" ", $LINE);
|
||||
array_push($ZONE->$CURRENTZONE, $RECORD);
|
||||
unset($RECORD);
|
||||
}
|
||||
|
||||
printf(json_encode($ZONE));
|
||||
Reference in New Issue
Block a user