vpanel-stack/panel/classes/Panel/Vdns.php
Matthew Saunders Brown 144d8a23b3 add vdns code
2024-02-13 14:41:15 -08:00

107 lines
2.2 KiB
PHP

<?php
/**
* vpanel-stack
* https://git.stack-source.com/msb/vpanel-stack
* Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
* GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
*/
namespace Panel;
class Vdns extends \Panel {
function beforeRoute($f3) {
parent::beforeRoute($f3);
if ($f3->get('PDNSADMIN') != '1') {
$f3->reroute('/');
}
}
public static function verifyZoneExists($zone) {
global $f3;
exec("/usr/local/bin/vdns-zone-ext.sh -z $zone", $output, $result_code);
if ($result_code == 0 && $output[0] == 'true') {
return TRUE;
} else {
return FALSE;
}
}
public static function returnZoneDefaultsArray($zone) {
global $f3;
if ($defaults_array = $f3->call('\Panel::vGet', array("vdns-zone-def.sh -z $zone -c", FALSE))) {
return $defaults_array;
} else {
return FALSE;
}
}
public static function returnZoneDefaultsNameserverArray($zone) {
global $f3;
if ($defaults_array = $f3->call('\Panel\Vdns::returnZoneDefaultsArray', $zone)) {
$defaults_ns_array = array();
foreach($defaults_array as $record_array) {
if ($record_array['type'] == "NS") {
$defaults_ns_array[] = $record_array['content'];
}
}
sort($defaults_ns_array);
return $defaults_ns_array;
} else {
return FALSE;
}
}
public static function returnNameserverArray($zone) {
global $f3;
$ns_array = array();
if ($dns_ns_array = dns_get_record("$zone", DNS_NS)) {
foreach ($dns_ns_array as $record_array) {
$ns_array[] = $record_array['target'];
}
sort($ns_array);
return $ns_array;
} else {
return FALSE;
}
}
public static function returnNameserverStatus($zone) {
global $f3;
if ($defaults_ns_array = $f3->call('\Panel\Vdns::returnZoneDefaultsNameserverArray', $zone)) {
if ($ns_array = $f3->call('\Panel\Vdns::returnNameserverArray', $zone)) {
if ($defaults_ns_array === $ns_array) {
return "Verified";
} else {
return "Pending";
}
} else {
return "Unknown";
}
} else {
return "Error";
}
}
}