First commit
This commit is contained in:
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