70 lines
2.0 KiB
PHP
70 lines
2.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* vpanel-stack
|
|
* https://git.stack-source.com/msb/vpanel-stack
|
|
* Copyright (c) 2024 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\Vdns;
|
|
|
|
class ZonesAdd extends \Panel\Vdns {
|
|
|
|
function beforeRoute($f3) {
|
|
|
|
parent::beforeRoute($f3);
|
|
|
|
}
|
|
|
|
static function get($f3) {
|
|
|
|
echo \Template::instance()->render('vdns/zones-add.html');
|
|
|
|
}
|
|
|
|
function post($f3) {
|
|
|
|
// print_r($_POST);
|
|
|
|
/* force zone to be all lower case */
|
|
$zone = strtolower($_POST['zone']);
|
|
/* strip spaces */
|
|
$zone = trim($zone);
|
|
/* remove leading www. */
|
|
$zone = preg_replace('/^www\./', '', $zone);
|
|
/* remove trailing . (dot) */
|
|
$zone = rtrim($zone, '.');
|
|
if ($f3->call('\Panel::validateDomain', $zone)) {
|
|
/* check if zone exists */
|
|
if ($f3->call('\Panel\Vdns::verifyZoneExists', $zone)) {
|
|
$messages[] = "Zone $zone already exists in DNS.";
|
|
$messages[] = "Note if $zone should be associated with this server but it's now showing up in the list below please contact support.";
|
|
$f3->set('SESSION.messages', $messages);
|
|
$f3->call('\Panel\Vdns\ZonesAdd::get', $f3);
|
|
} else {
|
|
$hostname = $f3->get('NAV.hostname');
|
|
exec("/usr/local/bin/vdns-zone-add.sh -z $zone -w hostname=$hostname/$zone", $output, $result_code);
|
|
if ($result_code == 0) {
|
|
$messages[] = "Zone (Domain Name) $zone has been added to DNS.";
|
|
$f3->set('SESSION.messages', $messages);
|
|
$f3->reroute("/DNS/$zone");
|
|
} else {
|
|
if (count($output) > 0) {
|
|
foreach ($output as $k=>$output_message) {
|
|
$messages[] = "$output_message";
|
|
}
|
|
} else {
|
|
$messages[] = "Unknown error adding Zone $zone to DNS.";
|
|
}
|
|
$f3->set('SESSION.messages', $messages);
|
|
$f3->call('\Panel\Vdns\ZonesAdd::get', $f3);
|
|
}
|
|
}
|
|
} else {
|
|
$f3->call('\Panel\Vdns\ZonesAdd::get', $f3);
|
|
}
|
|
}
|
|
|
|
}
|