Implement cloning of zones, closes #81

This commit is contained in:
Mark Schouten 2016-08-04 16:18:45 +02:00
parent 30f43e98a5
commit 5cd225cb43
3 changed files with 108 additions and 8 deletions

View file

@ -95,7 +95,7 @@ class Zone {
$this->dnssec = $dnssec; $this->dnssec = $dnssec;
} }
private function setId($id) { public function setId($id) {
$this->id = $id; $this->id = $id;
} }
@ -232,6 +232,10 @@ class RRSet {
$this->ttl = $ttl; $this->ttl = $ttl;
} }
public function setName($name) {
$this->name = $name;
}
public function addRecord($content, $disabled = FALSE) { public function addRecord($content, $disabled = FALSE) {
foreach ($this->records as $record) { foreach ($this->records as $record) {
if ($record->content == $content) { if ($record->content == $content) {

View file

@ -135,6 +135,7 @@ if ($blocklogin === TRUE) {
<div id="zones"> <div id="zones">
<?php if (is_adminuser() or $allowzoneadd === TRUE) { ?> <?php if (is_adminuser() or $allowzoneadd === TRUE) { ?>
<div style="visibility: hidden;" id="ImportZone"></div> <div style="visibility: hidden;" id="ImportZone"></div>
<div style="visibility: hidden;" id="CloneZone"></div>
<?php } ?> <?php } ?>
<div class="tables" id="MasterZones"> <div class="tables" id="MasterZones">
<div class="searchbar" id="searchbar"> <div class="searchbar" id="searchbar">
@ -428,15 +429,24 @@ $(document).ready(function () {
hoverAnimation: true, hoverAnimation: true,
hoverAnimationDuration: 60, hoverAnimationDuration: 60,
hoverAnimationEasing: undefined, hoverAnimationEasing: undefined,
items: [{ items: [
<?php if (is_adminuser() or $allowzoneadd === TRUE) { ?> <?php if (is_adminuser() or $allowzoneadd === TRUE) { ?>
icon: 'jtable/lib/themes/metro/add.png', {
text: 'Import a new zone', icon: 'jtable/lib/themes/metro/add.png',
click: function() { text: 'Import a new zone',
$('#ImportZone').jtable('showCreateForm'); click: function() {
} $('#ImportZone').jtable('showCreateForm');
}
},
{
icon: 'jtable/lib/themes/metro/add.png',
text: 'Clone a zone',
click: function() {
$('#CloneZone').jtable('showCreateForm');
}
},
<?php } ?> <?php } ?>
}], ],
}, },
sorting: false, sorting: false,
openChildAsAccordion: true, openChildAsAccordion: true,
@ -742,6 +752,51 @@ $(document).ready(function () {
} }
}); });
$('#CloneZone').jtable({
title: 'Clone zone',
actions: {
createAction: 'zones.php?action=clone'
},
fields: {
id: {
key: true,
type: 'hidden'
},
sourcename: {
title: 'Source domain',
options: function(data) {
return 'zones.php?action=formzonelist&e='+$epoch;
},
inputClass: 'sourcename'
},
destname: {
title: 'Domain',
inputClass: 'destname'
},
account: {
title: 'Account',
options: function(data) {
return 'users.php?action=listoptions&e='+$epoch;
},
defaultValue: 'admin',
inputClass: 'account'
},
kind: {
title: 'Type',
options: {'Native': 'Native', 'Master': 'Master'},
defaultValue: '<?php echo $defaults['defaulttype']; ?>',
edit: false,
inputClass: 'type'
},
},
recordAdded: function() {
$("#MasterZones").jtable('load');
$("#SlaveZones").jtable('load');
}
});
$('#domsearch').addClear({ $('#domsearch').addClear({
onClear: function() { $('#MasterZones').jtable('load'); } onClear: function() { $('#MasterZones').jtable('load'); }
}); });

View file

@ -363,6 +363,34 @@ case "export":
jtable_respond($api->exportzone($_GET['zoneid']), 'single'); jtable_respond($api->exportzone($_GET['zoneid']), 'single');
break; break;
case "clone":
$name = $_POST['destname'];
$src = $_POST['sourcename'];
if (!_valid_label($name)) {
jtable_respond(null, 'error', "Invalid destination zonename");
}
$srczone = new Zone();
$srczone->parse($api->loadzone($src));
$srczone->setId('');
$srczone->setName($name);
$srczone->setSerial('');
$zone = $api->savezone($srczone->export());
$srczone->parse($zone);
foreach ($srczone->rrsets as $rrset) {
$newname = $rrset->name;
$newname = preg_replace('/'.$src.'$/', $name, $newname);
$rrset->setName($newname);
}
$zone = $api->savezone($srczone->export());
jtable_respond($zone, 'single');
break;
case "gettemplatenameservers": case "gettemplatenameservers":
$ret = array(); $ret = array();
$type = $_GET['prisec']; $type = $_GET['prisec'];
@ -394,6 +422,19 @@ case "getformnameservers":
} }
} }
break; break;
case "formzonelist":
$zones = $api->listzones();
$ret = array();
foreach ($zones as $zone) {
if ($zone['kind'] == 'Slave')
continue;
array_push($ret, array(
'DisplayText' => $zone['name'],
'Value' => $zone['id']));
}
jtable_respond($ret, 'options');
break;
default: default:
jtable_respond(null, 'error', 'No such action'); jtable_respond(null, 'error', 'No such action');
break; break;