From 0a09deb50a18db98dcec10d4c74bf1e5aa2b1690 Mon Sep 17 00:00:00 2001 From: bfbones Date: Mon, 2 Mar 2015 10:10:46 +0100 Subject: [PATCH] - added protocol config parameter and handling for it - changed nameserver entries in config to be dymanic - changed display and parsing of NS-entries from config or from template to be dynamic --- includes/config.inc.php-dist | 5 +++-- index.php | 40 +++++++----------------------------- zones.php | 27 ++++++++++++++++-------- 3 files changed, 29 insertions(+), 43 deletions(-) diff --git a/includes/config.inc.php-dist b/includes/config.inc.php-dist index 6a4e3fd..92b8ba2 100644 --- a/includes/config.inc.php-dist +++ b/includes/config.inc.php-dist @@ -5,6 +5,7 @@ $apipass = ''; # The PowerDNS API-user password or the PowerDNS-API key $apiip = ''; # The IP of the PowerDNS API $apiport = '8081'; # The port of the PowerDNS API $apisid = 'localhost'; # PowerDNS's :server_id +$apiprotocol = 'https://'; # protocol used to connect with trailing slashs $allowzoneadd = FALSE; # Allow normal users to add zones ### AUTHENTICATION ### @@ -47,6 +48,6 @@ $templates[] = array( $defaults['soa_edit'] = 'INCEPTION-INCREMENT'; $defaults['soa_edit_api'] = 'INCEPTION-INCREMENT'; $defaults['defaulttype'] = 'Master'; # Choose between 'Native' or 'Master' -$defaults['primaryns'] = 'unconfigured.primaryns'; # The value of the first NS-record -$defaults['secondaryns'] = 'unconfigured.secondaryns'; # The value of the second NS-record +$defaults['ns'][0] = 'unconfigured.primaryns'; # The value of the first NS-record +$defaults['ns'][1] = 'unconfigured.secondaryns'; # The value of the second NS-record $defaults['ttl'] = 3600; # Default TTL for records diff --git a/index.php b/index.php index 1570661..0c1dc4a 100644 --- a/index.php +++ b/index.php @@ -442,23 +442,21 @@ $(document).ready(function () { edit: false, inputClass: 'template' }, - nameserver1: { - title: 'Pri. Nameserver', + nameserver: { + title: 'Nameservers', create: true, list: false, edit: false, input: function(data) { var $template = data.form.find('#Edit-template'); - var $elem = $(''); - $elem.val(); + var ns_form = '
'; ?>'; + var $elem = $('
' + ns_form + '
'); $template.change(function() { - $.get('zones.php?action=gettemplatenameservers&template='+$template.val()+'&prisec=pri', function(getdata) { + $.get('zones.php?action=getformnameservers&template='+$template.val(), function(getdata) { if (getdata != "") { - $elem.val(getdata); - $elem.attr('readonly', true); + $("#nameservers").html(getdata); } else { - $elem.val(); - $elem.attr('readonly', false); + $("#nameservers").html(ns_form); } }); }); @@ -466,30 +464,6 @@ $(document).ready(function () { }, inputClass: 'nameserver nameserver1' }, - nameserver2: { - title: 'Sec. Nameserver', - create: true, - list: false, - edit: false, - input: function(data) { - var $template = data.form.find('#Edit-template'); - var $elem = $(''); - $elem.val(); - $template.change(function() { - $.get('zones.php?action=gettemplatenameservers&template='+$template.val()+'&prisec=sec', function(getdata) { - if (getdata != "") { - $elem.val(getdata); - $elem.attr('readonly', true); - } else { - $elem.val(); - $elem.attr('readonly', false); - } - }); - }); - return $elem; - }, - inputClass: 'nameserver nameserver2' - }, serial: { title: 'Serial', width: '10%', diff --git a/zones.php b/zones.php index 0dd31b4..2f38fb5 100644 --- a/zones.php +++ b/zones.php @@ -11,14 +11,14 @@ if (!is_csrf_safe()) { } function api_request($path, $opts = null, $type = null) { - global $apisid, $apiuser, $apipass, $apiip, $apiport, $authmethod; + global $apisid, $apiuser, $apipass, $apiip, $apiport, $authmethod, $apiprotocol; - $url = "http://$apiip:$apiport${path}"; + $url = $apiprotocol.$apiip.":".$apiport.$path; if ($authmethod == "auto") { $ad = curl_init(); curl_setopt($ad, CURLOPT_HTTPHEADER, array('X-API-Key: '.$apipass)); - curl_setopt($ad, CURLOPT_URL, "http://$apiip:$apiport/servers/localhost/statistics"); + curl_setopt($ad, CURLOPT_URL, $apiprotocol.$apiip.":".$apiport."/servers/localhost/statistics"); curl_setopt($ad, CURLOPT_RETURNTRANSFER, 1); curl_exec($ad); if (curl_getinfo($ad, CURLINFO_HTTP_CODE) == 401) { @@ -447,11 +447,10 @@ case "create": ); $nameservers = array(); - if (isset($_POST['nameserver1']) && $_POST['nameserver1'] != null) { - array_push($nameservers, $_POST['nameserver1']); - } - if (isset($_POST['nameserver2']) && $_POST['nameserver2'] != null) { - array_push($nameservers, $_POST['nameserver2']); + foreach($_POST['nameserver'] as $ns) { + if (isset($ns) && !empty($ns)) { + array_push($nameservers, $ns); + } } if ($zonekind != "Slave") { @@ -650,6 +649,18 @@ case "gettemplatenameservers": echo ""; } break; +case "getformnameservers": + $inputs = array(); + foreach (user_template_list() as $template) { + if ($template['name'] !== $_GET['template']) continue; + foreach ($template['records'] as $record) { + if ($record['type'] == "NS" and array_search($record['content'], $inputs) === false) { + array_push($inputs, $record['content']); + echo '
'; + } + } + } + break; default: jtable_respond(null, 'error', 'No such action'); break;