mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-04-19 20:09:14 +03:00
Implement cloning of zones, closes #81
This commit is contained in:
parent
30f43e98a5
commit
5cd225cb43
3 changed files with 108 additions and 8 deletions
|
@ -95,7 +95,7 @@ class Zone {
|
|||
$this->dnssec = $dnssec;
|
||||
}
|
||||
|
||||
private function setId($id) {
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
|
@ -232,6 +232,10 @@ class RRSet {
|
|||
$this->ttl = $ttl;
|
||||
}
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function addRecord($content, $disabled = FALSE) {
|
||||
foreach ($this->records as $record) {
|
||||
if ($record->content == $content) {
|
||||
|
|
69
index.php
69
index.php
|
@ -135,6 +135,7 @@ if ($blocklogin === TRUE) {
|
|||
<div id="zones">
|
||||
<?php if (is_adminuser() or $allowzoneadd === TRUE) { ?>
|
||||
<div style="visibility: hidden;" id="ImportZone"></div>
|
||||
<div style="visibility: hidden;" id="CloneZone"></div>
|
||||
<?php } ?>
|
||||
<div class="tables" id="MasterZones">
|
||||
<div class="searchbar" id="searchbar">
|
||||
|
@ -428,15 +429,24 @@ $(document).ready(function () {
|
|||
hoverAnimation: true,
|
||||
hoverAnimationDuration: 60,
|
||||
hoverAnimationEasing: undefined,
|
||||
items: [{
|
||||
items: [
|
||||
<?php if (is_adminuser() or $allowzoneadd === TRUE) { ?>
|
||||
icon: 'jtable/lib/themes/metro/add.png',
|
||||
text: 'Import a new zone',
|
||||
click: function() {
|
||||
$('#ImportZone').jtable('showCreateForm');
|
||||
}
|
||||
{
|
||||
icon: 'jtable/lib/themes/metro/add.png',
|
||||
text: 'Import a new zone',
|
||||
click: function() {
|
||||
$('#ImportZone').jtable('showCreateForm');
|
||||
}
|
||||
},
|
||||
{
|
||||
icon: 'jtable/lib/themes/metro/add.png',
|
||||
text: 'Clone a zone',
|
||||
click: function() {
|
||||
$('#CloneZone').jtable('showCreateForm');
|
||||
}
|
||||
},
|
||||
<?php } ?>
|
||||
}],
|
||||
],
|
||||
},
|
||||
sorting: false,
|
||||
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({
|
||||
onClear: function() { $('#MasterZones').jtable('load'); }
|
||||
});
|
||||
|
|
41
zones.php
41
zones.php
|
@ -363,6 +363,34 @@ case "export":
|
|||
jtable_respond($api->exportzone($_GET['zoneid']), 'single');
|
||||
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":
|
||||
$ret = array();
|
||||
$type = $_GET['prisec'];
|
||||
|
@ -394,6 +422,19 @@ case "getformnameservers":
|
|||
}
|
||||
}
|
||||
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:
|
||||
jtable_respond(null, 'error', 'No such action');
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue