dnsphpadmin/includes/zones.php
Petr Bena 5eda737dd2
Rewrite (#8)
* major rewrite

tool became larger than I originally expected so there is a need to
reorganize the code as it was already beginning to become a mess
2019-12-03 12:27:33 +01:00

82 lines
2.5 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");
// Namespace for all sorts of zone (domain) operations
class Zones
{
public static function GetZoneList()
{
global $g_domains;
$result = [];
foreach ($g_domains as $domain => $properties)
{
if (!IsAuthorizedToRead($domain))
continue;
$result[$domain] = [ 'domain' => $domain, 'update_server' => $properties['update_server'], 'transfer_server' => $properties['transfer_server'] ];
if (isset($properties['in_transfer']))
$result[$domain]['in_transfer'] = $properties['in_transfer'];
if (isset($properties['maintenance_note']))
$result[$domain]['maintenance_note'] = $properties['maintenance_note'];
if (isset($properties['read_only']))
$result[$domain]['read_only'] = $properties['read_only'];
}
return $result;
}
public static function IsEditable($domain)
{
global $g_domains;
if (!array_key_exists($domain, $g_domains))
die("No such zone: $domain");
$domain_info = $g_domains[$domain];
if (array_key_exists('read_only', $domain_info) && $domain_info['read_only'] === true)
return false;
return true;
}
public static function GetZoneForFQDN($fqdn)
{
global $g_domains;
do
{
if (!array_key_exists($fqdn, $g_domains))
{
$fqdn= substr($fqdn, strpos($fqdn, '.') + 1);
continue;
}
return $fqdn;
} while (psf_string_contains($fqdn, '.'));
return NULL;
}
public static function HasPTRZones()
{
global $g_domains;
foreach ($g_domains as $key => $info)
{
if (psf_string_endsWith($key, ".in-addr.arpa"))
return true;
}
return false;
}
}