diff --git a/dns_slave_auto/README b/dns_slave_auto/README new file mode 100644 index 0000000000000000000000000000000000000000..d94c3d7d9c7d8d1b59d37dd3611b194fcab07736 --- /dev/null +++ b/dns_slave_auto/README @@ -0,0 +1,38 @@ + +Author: Florian Schaal, schaal @it + +ISPConfig version: 3.1.3 + +This addon adds dns-slave-zones on additional servers after creating a dns-zone +If you managed multiple servers with ISPConfig but did not use the mirror-function, +you can i.e. use server 1 for bind and server 2 as a bind-slave. This plugin +manages the slave-zones on server 2 when you create / change / delete the +dns-zone on server 1. + +Installation +-------------------- + +Download the addon to your server and run the install.sh script to install it. + + +Usage +-------------------- + +Adjust the following settings in /usr/local/ispconfig/interface/lib/plugins/dns_dns_slave_auto_plugin.inc.php + +1. +//* define your dns-ip(s) that the slave-server should accept the data from (same as NS (IP-address) in Secondary DNS Zones) +$this->nameservers[] = '192.168.0.1'; +$this->nameservers[] = 'fe80::2'; + +If your master-server has only one IP, remove one one the lines. + +2. +//* define the server_ids for slave-server(s) (see server_id in dbispconfig.server on the master) +$this->dns_slave_server_id[] = 2; + +If you want to run bind-slave on several servers, use more settings. I.e. +$this->dns_slave_server_id[] = 2; +$this->dns_slave_server_id[] = 12; +$this->dns_slave_server_id[] = 18; + diff --git a/dns_slave_auto/dns_dns_slave_auto_plugin.inc.php b/dns_slave_auto/dns_dns_slave_auto_plugin.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..64c6e0478c6a636e36d4ee347dc2fde429ff42e8 --- /dev/null +++ b/dns_slave_auto/dns_dns_slave_auto_plugin.inc.php @@ -0,0 +1,106 @@ +nameservers[] = '192.168.0.1'; + $this->nameservers[] = 'fe80::2'; + //* define the server_ids for slave-server(s) (see server_id in dbispconfig.server on the master) + $this->dns_slave_server_id[] = 2; + } + + function onLoad() { + global $app; + + $app->plugin->registerEvent('dns:dns_soa:on_after_insert', 'dns_dns_slave_auto_plugin', 'slave_insert'); + $app->plugin->registerEvent('dns:dns_soa:on_after_update', 'dns_dns_slave_auto_plugin', 'slave_update'); + $app->plugin->registerEvent('dns:dns_soa:on_after_delete', 'dns_dns_slave_auto_plugin', 'slave_delete'); + $app->plugin->registerEvent('dns:wizard:on_after_insert', 'dns_dns_slave_auto_plugin', 'slave_insert'); + } + + function slave_insert($event_name, $page_form) { + global $app; + + $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ?", $page_form); + $insert_data = array( + 'sys_userid' => $soa['sys_userid'], + 'sys_groupid' => $soa['sys_groupid'], + 'sys_perm_user' => $soa['sys_perm_user'], + 'sys_perm_group' => $soa['sys_perm_group'], + 'sys_perm_other' => $soa['sys_perm_other'], + 'origin' => $soa['origin'], + 'ns' => implode(',', $this->nameservers), + 'active' => $soa['active'], + 'xfer' => '' + ); + foreach($this->dns_slave_server_id as $slave) { + $insert_data['server_id'] = $slave; + $app->db->datalogInsert('dns_slave', $insert_data, 'id'); + } + } + + function slave_update($event_name, $page_form) { + global $app; + + if($page_form->dataRecord['origin'] != $page_form->oldDataRecord['origin']) { + $slave_zone_recs = $app->db->queryAllRecords("SELECT * FROM dns_slave WHERE origin = ?", $page_form->oldDataRecord['origin']); + foreach($slave_zone_recs as $slave_zone) { + $app->db->datalogDelete('dns_slave', 'id', $slave_zone['id']); + $this->slave_insert('', $page_form->dataRecord['id']); + } + } + if($page_form->dataRecord['active'] != $page_form->oldDataRecord['active']) { + $slave_zone_recs = $app->db->queryAllRecords("SELECT * FROM dns_slave WHERE origin = ?", $page_form->dataRecord['origin']); + foreach($slave_zone_recs as $slave_zone) { + if($page_form->dataRecord['active'] == 'Y') { + $app->db->datalogUpdate('dns_slave', array('active' => 'Y'), 'id', $slave_zone['id']); + } else { + $app->db->datalogUpdate('dns_slave', array('active' => 'N'), 'id', $slave_zone['id']); + } + } + } + } + + function slave_delete($event_name, $page_form) { + global $app; + + $slave_zone_recs = $app->db->queryAllRecords("SELECT * FROM dns_slave WHERE origin = ?", $page_form->dataRecord['origin']); + foreach($slave_zone_recs as $slave_zone) { + $app->db->datalogDelete('dns_slave', 'id', $slave_zone['id']); + } + } + +} diff --git a/dns_slave_auto/install.sh b/dns_slave_auto/install.sh new file mode 100755 index 0000000000000000000000000000000000000000..9e7ac6678383f09001d501ba95d10a2b1e155eda --- /dev/null +++ b/dns_slave_auto/install.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +mv -f dns_dns_slave_auto_plugin.inc.php mailbox_import.php /usr/local/ispconfig/interface/lib/plugins + +chown ispconfig:ispconfig /usr/local/ispconfig/interface/lib/plugins/dns_dns_slave_auto_plugin.inc.php