- 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
This commit is contained in:
bfbones 2015-03-02 10:10:46 +01:00
parent 94f722b4d5
commit 0a09deb50a
3 changed files with 29 additions and 43 deletions

View file

@ -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

View file

@ -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 = $('<input type="text" name="nameserver1" />');
$elem.val(<?php echo "'".$defaults['primaryns']."'"; ?>);
var ns_form = '<?php foreach($defaults['ns'] as $ns) echo '<input type="text" name="nameserver[]" value="'.$ns.'" /><br />'; ?>';
var $elem = $('<div id="nameservers">' + ns_form + '</div>');
$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(<?php echo "'".$defaults['primaryns']."'"; ?>);
$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 = $('<input type="text" name="nameserver2" />');
$elem.val(<?php echo "'".$defaults['secondaryns']."'"; ?>);
$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(<?php echo "'".$defaults['secondaryns']."'"; ?>);
$elem.attr('readonly', false);
}
});
});
return $elem;
},
inputClass: 'nameserver nameserver2'
},
serial: {
title: 'Serial',
width: '10%',

View file

@ -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 '<input type="text" name="nameserver[]" value="'.$record['content'].'" readonly /><br />';
}
}
}
break;
default:
jtable_respond(null, 'error', 'No such action');
break;