Implement set-ptr. Closes #51 . Make 'true/false' prettier

This commit is contained in:
Mark Schouten 2016-08-04 16:55:03 +02:00
parent 5cd225cb43
commit d103c7b04f
3 changed files with 42 additions and 16 deletions

View file

@ -112,21 +112,21 @@ class Zone {
$this->masters = Array(); $this->masters = Array();
} }
public function addRRSet($name, $type, $content, $disabled = FALSE, $ttl = 3600) { public function addRRSet($name, $type, $content, $disabled = FALSE, $ttl = 3600, $setptr = FALSE) {
if ($this->getRRSet($name, $type) !== FALSE) { if ($this->getRRSet($name, $type) !== FALSE) {
throw new Exception("This rrset already exists."); throw new Exception("This rrset already exists.");
} }
$rrset = new RRSet($name, $type, $content, $disabled, $ttl); $rrset = new RRSet($name, $type, $content, $disabled, $ttl, $setptr);
array_push($this->rrsets, $rrset); array_push($this->rrsets, $rrset);
} }
public function addRecord($name, $type, $content, $disabled = FALSE, $ttl = 3600) { public function addRecord($name, $type, $content, $disabled = FALSE, $ttl = 3600, $setptr = FALSE) {
$rrset = $this->getRRSet($name, $type); $rrset = $this->getRRSet($name, $type);
if ($rrset) { if ($rrset) {
$rrset->addRecord($content, $disabled); $rrset->addRecord($content, $disabled, $setptr);
} else { } else {
$this->addRRSet($name, $type, $content, $disabled, $ttl); $this->addRRSet($name, $type, $content, $disabled, $ttl, $setptr);
} }
return $this->getRecord($name, $type, $content); return $this->getRecord($name, $type, $content);
@ -211,7 +211,7 @@ class Zone {
} }
class RRSet { class RRSet {
public function __construct($name = '', $type = '', $content = '', $disabled = FALSE, $ttl = 3600) { public function __construct($name = '', $type = '', $content = '', $disabled = FALSE, $ttl = 3600, $setptr = FALSE) {
$this->name = $name; $this->name = $name;
$this->type = $type; $this->type = $type;
$this->ttl = $ttl; $this->ttl = $ttl;
@ -220,7 +220,7 @@ class RRSet {
$this->comments = Array(); $this->comments = Array();
if (isset($content) and $content != '') { if (isset($content) and $content != '') {
$this->addRecord($content, $disabled); $this->addRecord($content, $disabled, $setptr);
} }
} }
@ -236,14 +236,14 @@ class RRSet {
$this->name = $name; $this->name = $name;
} }
public function addRecord($content, $disabled = FALSE) { public function addRecord($content, $disabled = FALSE, $setptr) {
foreach ($this->records as $record) { foreach ($this->records as $record) {
if ($record->content == $content) { if ($record->content == $content) {
throw Exception("Record already exists"); throw Exception("Record already exists");
} }
} }
$record = new Record($content, $disabled); $record = new Record($content, $disabled, $setptr);
array_push($this->records, $record); array_push($this->records, $record);
} }
@ -275,6 +275,9 @@ class RRSet {
public function exportRecords() { public function exportRecords() {
$ret = Array(); $ret = Array();
foreach ($this->records as $record) { foreach ($this->records as $record) {
if ($this->type != "A" and $this->type != "AAAA") {
$record->setptr = FALSE;
}
array_push($ret, $record->export()); array_push($ret, $record->export());
} }
@ -293,9 +296,10 @@ class RRSet {
} }
class Record { class Record {
public function __construct($content, $disabled = FALSE) { public function __construct($content, $disabled = FALSE, $setptr = FALSE) {
$this->content = $content; $this->content = $content;
$this->disabled = $disabled; $this->disabled = $disabled;
$this->setptr = $setptr;
} }
public function export() { public function export() {
@ -303,6 +307,9 @@ class Record {
$ret['content'] = $this->content; $ret['content'] = $this->content;
$ret['disabled'] = ( bool ) $this->disabled; $ret['disabled'] = ( bool ) $this->disabled;
if ($this->setptr) {
$ret['set-ptr'] = ( bool ) TRUE;
}
return $ret; return $ret;
} }

View file

@ -252,7 +252,11 @@ function displayContent(fieldName, zone) {
var zspan = $('<span class="lightgrey">').text(zone); var zspan = $('<span class="lightgrey">').text(zone);
return lspan.add(zspan); return lspan.add(zspan);
} else { } else {
return $('<span>').text(data.record[fieldName]); var text = data.record[fieldName];
if (typeof data.record[fieldName] == 'boolean') {
text == false ? text = 'No' : text = 'Yes';
}
return $('<span>').text(text);
} }
} }
} }
@ -657,18 +661,33 @@ $(document).ready(function () {
inputClass: 'ttl', inputClass: 'ttl',
listClass: 'ttl' listClass: 'ttl'
}, },
setptr: {
title: 'Set PTR Record',
width: '2%',
list: false,
create: true,
defaultValue: 'false',
inputClass: 'setptr',
listClass: 'setptr',
options: function() {
return {
'0': 'No',
'1': 'Yes',
};
},
},
disabled: { disabled: {
title: 'Disabled', title: 'Disabled',
width: '2%', width: '2%',
create: true, create: true,
display: displayContent('disabled'), display: displayContent('disabled'),
defaultValue: '<?php echo $defaults['disabled'] ? 'false' : 'true'; ?>', defaultValue: '<?php echo $defaults['disabled'] ? 'No' : 'Yes'; ?>',
inputClass: 'disabled', inputClass: 'disabled',
listClass: 'disabled', listClass: 'disabled',
options: function() { options: function() {
return { return {
'0': 'false', '0': 'No',
'1': 'true', '1': 'Yes',
}; };
}, },
}, },

View file

@ -324,7 +324,7 @@ case "createrecord":
jtable_respond(null, 'error', "Please only use ASCII-characters in your fields"); jtable_respond(null, 'error', "Please only use ASCII-characters in your fields");
} }
$record = $zone->addRecord($name, $type, $content, $_POST['disabled'], $_POST['ttl']); $record = $zone->addRecord($name, $type, $content, $_POST['disabled'], $_POST['ttl'], $_POST['setptr']);
$api->savezone($zone->export()); $api->savezone($zone->export());
jtable_respond($record, 'single'); jtable_respond($record, 'single');
@ -338,7 +338,7 @@ case "editrecord":
$rrset = $zone->getRRSet($old_record['name'], $old_record['type']); $rrset = $zone->getRRSet($old_record['name'], $old_record['type']);
$rrset->deleteRecord($old_record['content']); $rrset->deleteRecord($old_record['content']);
$zone->addRecord($_POST['name'], $_POST['type'], $_POST['content'], $_POST['disabled'], $_POST['ttl']); $zone->addRecord($_POST['name'], $_POST['type'], $_POST['content'], $_POST['disabled'], $_POST['ttl'], $_POST['setptr']);
$api->savezone($zone->export()); $api->savezone($zone->export());