From 7dbea06e158c10fc59962ba2b988ca0976d5c000 Mon Sep 17 00:00:00 2001 From: tbrehm Date: Fri, 30 Oct 2009 14:17:30 +0000 Subject: [PATCH] Implemented: FS#868 - Add support for BIND --- install/dist/conf/centos52.conf.php | 9 + install/dist/conf/centos53.conf.php | 9 + install/dist/conf/debian40.conf.php | 9 + install/dist/conf/fedora9.conf.php | 9 + install/dist/conf/opensuse110.conf.php | 9 + install/install.php | 8 + install/lib/installer_base.lib.php | 9 +- install/tpl/server.ini.master | 7 + install/update.php | 4 + .../web/admin/form/server_config.tform.php | 69 ++++++ .../web/admin/lib/lang/en_server_config.lng | 9 + .../templates/server_config_dns_edit.htm | 38 ++++ server/conf/bind_named.conf.local.master | 7 + server/conf/bind_pri.domain.master | 51 +++++ server/mods-available/dns_module.inc.php | 23 ++ server/plugins-available/bind_plugin.inc.php | 199 ++++++++++++++++++ 16 files changed, 468 insertions(+), 1 deletion(-) create mode 100644 interface/web/admin/templates/server_config_dns_edit.htm create mode 100644 server/conf/bind_named.conf.local.master create mode 100644 server/conf/bind_pri.domain.master create mode 100644 server/plugins-available/bind_plugin.inc.php diff --git a/install/dist/conf/centos52.conf.php b/install/dist/conf/centos52.conf.php index 5d1216be2..4a745f863 100644 --- a/install/dist/conf/centos52.conf.php +++ b/install/dist/conf/centos52.conf.php @@ -154,6 +154,15 @@ $conf['powerdns']['database'] = 'powerdns'; $conf["powerdns"]["config_dir"] = '/etc/powerdns/pdns.d'; $conf['powerdns']['init_script'] = 'pdns'; +//* BIND DNS Server +$conf['bind']['installed'] = false; // will be detected automatically during installation +$conf['bind']['bind_user'] = 'root'; +$conf['bind']['bind_group'] = 'bind'; +$conf['bind']['bind_zonefiles_dir'] = '/etc/bind'; +$conf['bind']['named_conf_path'] = '/etc/bind/named.conf'; +$conf['bind']['named_conf_local_path'] = '/etc/bind/named.conf.local'; +$conf['bind']['init_script'] = 'named'; + //* Jailkit $conf['jailkit']['installed'] = false; // will be detected automatically during installation $conf['jailkit']['config_dir'] = '/etc/jailkit'; diff --git a/install/dist/conf/centos53.conf.php b/install/dist/conf/centos53.conf.php index 5d1216be2..4a745f863 100644 --- a/install/dist/conf/centos53.conf.php +++ b/install/dist/conf/centos53.conf.php @@ -154,6 +154,15 @@ $conf['powerdns']['database'] = 'powerdns'; $conf["powerdns"]["config_dir"] = '/etc/powerdns/pdns.d'; $conf['powerdns']['init_script'] = 'pdns'; +//* BIND DNS Server +$conf['bind']['installed'] = false; // will be detected automatically during installation +$conf['bind']['bind_user'] = 'root'; +$conf['bind']['bind_group'] = 'bind'; +$conf['bind']['bind_zonefiles_dir'] = '/etc/bind'; +$conf['bind']['named_conf_path'] = '/etc/bind/named.conf'; +$conf['bind']['named_conf_local_path'] = '/etc/bind/named.conf.local'; +$conf['bind']['init_script'] = 'named'; + //* Jailkit $conf['jailkit']['installed'] = false; // will be detected automatically during installation $conf['jailkit']['config_dir'] = '/etc/jailkit'; diff --git a/install/dist/conf/debian40.conf.php b/install/dist/conf/debian40.conf.php index cdfdb26f2..a124489f4 100644 --- a/install/dist/conf/debian40.conf.php +++ b/install/dist/conf/debian40.conf.php @@ -154,6 +154,15 @@ $conf['powerdns']['database'] = 'powerdns'; $conf["powerdns"]["config_dir"] = '/etc/powerdns/pdns.d'; $conf['powerdns']['init_script'] = 'pdns'; +//* BIND DNS Server +$conf['bind']['installed'] = false; // will be detected automatically during installation +$conf['bind']['bind_user'] = 'root'; +$conf['bind']['bind_group'] = 'bind'; +$conf['bind']['bind_zonefiles_dir'] = '/etc/bind'; +$conf['bind']['named_conf_path'] = '/etc/bind/named.conf'; +$conf['bind']['named_conf_local_path'] = '/etc/bind/named.conf.local'; +$conf['bind']['init_script'] = 'bind9'; + //* Jailkit $conf['jailkit']['installed'] = false; // will be detected automatically during installation $conf['jailkit']['config_dir'] = '/etc/jailkit'; diff --git a/install/dist/conf/fedora9.conf.php b/install/dist/conf/fedora9.conf.php index 0ab5a0ba7..86693cb59 100644 --- a/install/dist/conf/fedora9.conf.php +++ b/install/dist/conf/fedora9.conf.php @@ -154,6 +154,15 @@ $conf['powerdns']['database'] = 'powerdns'; $conf["powerdns"]["config_dir"] = '/etc/powerdns/pdns.d'; $conf['powerdns']['init_script'] = 'pdns'; +//* BIND DNS Server +$conf['bind']['installed'] = false; // will be detected automatically during installation +$conf['bind']['bind_user'] = 'root'; +$conf['bind']['bind_group'] = 'bind'; +$conf['bind']['bind_zonefiles_dir'] = '/etc/bind'; +$conf['bind']['named_conf_path'] = '/etc/bind/named.conf'; +$conf['bind']['named_conf_local_path'] = '/etc/bind/named.conf.local'; +$conf['bind']['init_script'] = 'named'; + //* Jailkit $conf['jailkit']['installed'] = false; // will be detected automatically during installation $conf['jailkit']['config_dir'] = '/etc/jailkit'; diff --git a/install/dist/conf/opensuse110.conf.php b/install/dist/conf/opensuse110.conf.php index 8c40a8813..5ebc5367e 100644 --- a/install/dist/conf/opensuse110.conf.php +++ b/install/dist/conf/opensuse110.conf.php @@ -154,6 +154,15 @@ $conf['powerdns']['database'] = 'powerdns'; $conf["powerdns"]["config_dir"] = '/etc/powerdns/pdns.d'; $conf['powerdns']['init_script'] = 'pdns'; +//* BIND DNS Server +$conf['bind']['installed'] = false; // will be detected automatically during installation +$conf['bind']['bind_user'] = 'root'; +$conf['bind']['bind_group'] = 'bind'; +$conf['bind']['bind_zonefiles_dir'] = '/etc/bind'; +$conf['bind']['named_conf_path'] = '/etc/bind/named.conf'; +$conf['bind']['named_conf_local_path'] = '/etc/bind/named.conf.local'; +$conf['bind']['init_script'] = 'named'; + //* Jailkit $conf['jailkit']['installed'] = false; // will be detected automatically during installation $conf['jailkit']['config_dir'] = '/etc/jailkit'; diff --git a/install/install.php b/install/install.php index 544902898..5c19b54bf 100644 --- a/install/install.php +++ b/install/install.php @@ -194,6 +194,9 @@ if($install_mode == 'standard') { if($conf['powerdns']['installed'] == true) { swriteln('Configuring PowerDNS'); $inst->configure_powerdns(); + } elseif($conf['bind']['installed'] == true) { + swriteln('Configuring BIND'); + $inst->configure_bind(); } else { swriteln('Configuring MyDNS'); $inst->configure_mydns(); @@ -246,6 +249,7 @@ if($install_mode == 'standard') { if($conf['pureftpd']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'])) system($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'].' restart'); if($conf['mydns']['installed'] == true && $conf['mydns']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['mydns']['init_script'])) system($conf['init_scripts'].'/'.$conf['mydns']['init_script'].' restart &> /dev/null'); if($conf['powerdns']['installed'] == true && $conf['powerdns']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['powerdns']['init_script'])) system($conf['init_scripts'].'/'.$conf['powerdns']['init_script'].' restart &> /dev/null'); + if($conf['bind']['installed'] == true && $conf['bind']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['bind']['init_script'])) system($conf['init_scripts'].'/'.$conf['bind']['init_script'].' restart &> /dev/null'); }else{ @@ -370,6 +374,10 @@ if($install_mode == 'standard') { swriteln('Configuring PowerDNS'); $inst->configure_powerdns(); if($conf['powerdns']['init_script'] != '') system($conf['init_scripts'].'/'.$conf['powerdns']['init_script'].' restart &> /dev/null'); + } elseif($conf['bind']['installed'] == true) { + swriteln('Configuring BIND'); + $inst->configure_bind(); + if($conf['bind']['init_script'] != '') system($conf['init_scripts'].'/'.$conf['bind']['init_script'].' restart &> /dev/null'); } else { swriteln('Configuring MyDNS'); $inst->configure_mydns(); diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 7b4eba886..9e79b5501 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -128,7 +128,7 @@ class installer_base { if(is_installed('mydns') || is_installed('mydns-ng')) $conf['mydns']['installed'] = true; if(is_installed('jk_chrootsh')) $conf['jailkit']['installed'] = true; if(is_installed('pdns_server') || is_installed('pdns_control')) $conf['powerdns']['installed'] = true; - + if(is_installed('named') || is_installed('bind') || is_installed('bind9')) $conf['bind']['installed'] = true; } @@ -818,6 +818,13 @@ class installer_base { } + public function configure_bind() { + global $conf; + + //* Nothing to do + + } + public function configure_apache() diff --git a/install/tpl/server.ini.master b/install/tpl/server.ini.master index 9cc4e6f14..080f9fd71 100644 --- a/install/tpl/server.ini.master +++ b/install/tpl/server.ini.master @@ -43,6 +43,13 @@ apps_vhost_port=8081 apps_vhost_ip=_default_ apps_vhost_servername= +[dns] +bind_user=root +bind_group=bind +bind_zonefiles_dir=/etc/bind +named_conf_path=/etc/bind/named.conf +named_conf_local_path=/etc/bind/named.conf.local + [fastcgi] fastcgi_starter_path=/var/www/php-fcgi-scripts/[system_user]/ fastcgi_starter_script=.php-fcgi-starter diff --git a/install/update.php b/install/update.php index 01158e6e7..479ad9e8d 100644 --- a/install/update.php +++ b/install/update.php @@ -342,6 +342,9 @@ if($reconfigure_services_answer == 'yes') { if($conf['powerdns']['installed'] == true) { swriteln('Configuring PowerDNS'); $inst->configure_powerdns(); + } elseif($conf['bind']['installed'] == true) { + swriteln('Configuring BIND'); + $inst->configure_bind(); } else { swriteln('Configuring MyDNS'); $inst->configure_mydns(); @@ -413,6 +416,7 @@ if($reconfigure_services_answer == 'yes') { if($conf['services']['dns']) { if($conf['mydns']['installed'] == true && $conf['mydns']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['mydns']['init_script'])) system($conf['init_scripts'].'/'.$conf['mydns']['init_script'].' restart &> /dev/null'); if($conf['powerdns']['installed'] == true && $conf['powerdns']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['powerdns']['init_script'])) system($conf['init_scripts'].'/'.$conf['powerdns']['init_script'].' restart &> /dev/null'); + if($conf['bind']['installed'] == true && $conf['bind']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['bind']['init_script'])) system($conf['init_scripts'].'/'.$conf['bind']['init_script'].' restart &> /dev/null'); } } diff --git a/interface/web/admin/form/server_config.tform.php b/interface/web/admin/form/server_config.tform.php index 31f554205..7d9d493ec 100644 --- a/interface/web/admin/form/server_config.tform.php +++ b/interface/web/admin/form/server_config.tform.php @@ -411,6 +411,75 @@ $form["tabs"]['web'] = array ( ) ); +$form["tabs"]['dns'] = array ( + 'title' => "DNS", + 'width' => 60, + 'template' => "templates/server_config_dns_edit.htm", + 'fields' => array ( + ################################## + # Begin Datatable fields + ################################## + 'bind_user' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'default' => '', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'bind_user_error_empty'), + ), + 'value' => '', + 'width' => '40', + 'maxlength' => '255' + ), + 'bind_group' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'default' => '', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'bind_group_error_empty'), + ), + 'value' => '', + 'width' => '40', + 'maxlength' => '255' + ), + 'bind_zonefiles_dir' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'default' => '', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'bind_zonefiles_dir_error_empty'), + ), + 'value' => '', + 'width' => '40', + 'maxlength' => '255' + ), + 'named_conf_path' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'default' => '', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'named_conf_path_error_empty'), + ), + 'value' => '', + 'width' => '40', + 'maxlength' => '255' + ), + 'named_conf_local_path' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'default' => '', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'named_conf_local_path_error_empty'), + ), + 'value' => '', + 'width' => '40', + 'maxlength' => '255' + ), + ################################## + # ENDE Datatable fields + ################################## + ) +); + $form["tabs"]['fastcgi'] = array ( 'title' => "FastCGI", 'width' => 80, diff --git a/interface/web/admin/lib/lang/en_server_config.lng b/interface/web/admin/lib/lang/en_server_config.lng index c3c7019e4..858281814 100644 --- a/interface/web/admin/lib/lang/en_server_config.lng +++ b/interface/web/admin/lib/lang/en_server_config.lng @@ -50,4 +50,13 @@ $wb["loglevel_txt"] = 'Loglevel'; $wb["apps_vhost_port_txt"] = 'Apps-vhost port'; $wb["apps_vhost_ip_txt"] = 'Apps-vhost IP'; $wb["apps_vhost_servername_txt"] = 'Apps-vhost Domain'; +$wb["bind_user_txt"] = 'BIND User'; +$wb["bind_group_txt"] = 'BIND Group'; +$wb["bind_zonefiles_dir_txt"] = 'BIND zonefiles directory'; +$wb["named_conf_path_txt"] = 'BIND named.conf path'; +$wb["bind_user_error_empty"] = 'BIND user is empty.'; +$wb["bind_group_error_empty"] = 'BIND group is empty.'; +$wb["bind_zonefiles_dir_error_empty"] = 'BIND zonefiles directory is empty.'; +$wb["named_conf_path_error_empty"] = 'BIND named.conf path is empty.'; +$wb["named_conf_local_path_error_empty"] = 'BIND named.conf.local path is empty.'; ?> \ No newline at end of file diff --git a/interface/web/admin/templates/server_config_dns_edit.htm b/interface/web/admin/templates/server_config_dns_edit.htm new file mode 100644 index 000000000..eee6626f3 --- /dev/null +++ b/interface/web/admin/templates/server_config_dns_edit.htm @@ -0,0 +1,38 @@ +

+

+ +
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + +
+ + +
+
+ +
diff --git a/server/conf/bind_named.conf.local.master b/server/conf/bind_named.conf.local.master new file mode 100644 index 000000000..27ec3cfe1 --- /dev/null +++ b/server/conf/bind_named.conf.local.master @@ -0,0 +1,7 @@ + + +zone "" { + type master; + file "pri."; +}; + diff --git a/server/conf/bind_pri.domain.master b/server/conf/bind_pri.domain.master new file mode 100644 index 000000000..ce545cb6e --- /dev/null +++ b/server/conf/bind_pri.domain.master @@ -0,0 +1,51 @@ +$TTL {tmpl_var name='ttl'} +@ IN SOA {tmpl_var name='ns'} {tmpl_var name='mbox'}. ( + {tmpl_var name='serial'} ; serial, todays date + todays serial # + {tmpl_var name='refresh'} ; refresh, seconds + {tmpl_var name='retry'} ; retry, seconds + {tmpl_var name='expire'} ; expire, seconds + {tmpl_var name='ttl'} ) ; minimum, seconds +; + + + +{tmpl_var name='name'} NS {tmpl_var name='data'} + + +{tmpl_var name='name'} A {tmpl_var name='data'} + + +{tmpl_var name='name'} AAAA {tmpl_var name='data'} + + +{tmpl_var name='name'} CNAME {tmpl_var name='data'} + + +{tmpl_var name='name'} CNAME {tmpl_var name='data'} + + +{tmpl_var name='name'} HINFO {tmpl_var name='data'} + + +{tmpl_var name='name'} MX {tmpl_var name='aux'} {tmpl_var name='data'} + + +{tmpl_var name='name'} NAPTR {tmpl_var name='data'} + + +{tmpl_var name='name'} NS {tmpl_var name='data'} + + +{tmpl_var name='name'} PTR {tmpl_var name='data'} + + +{tmpl_var name='name'} RP {tmpl_var name='data'} + + +{tmpl_var name='name'} SRV {tmpl_var name='data'} + + +{tmpl_var name='name'} TXT {tmpl_var name='data'} + + + diff --git a/server/mods-available/dns_module.inc.php b/server/mods-available/dns_module.inc.php index 79b0e5b5a..72ae1df69 100644 --- a/server/mods-available/dns_module.inc.php +++ b/server/mods-available/dns_module.inc.php @@ -75,6 +75,10 @@ class dns_module { $app->modules->registerTableHook('dns_soa',$this->module_name,'process'); $app->modules->registerTableHook('dns_rr',$this->module_name,'process'); + + // Register service + $app->services->registerService('bind','dns_module','restartBind'); + } /* @@ -99,6 +103,25 @@ class dns_module { } // end switch } // end function + + function restartBind($action = 'restart') { + global $app; + + $command = ''; + if(is_file('/etc/init.d/bind9')) { + $command = '/etc/init.d/bind9'; + } else { + $command = '/etc/init.d/named'; + } + + if($action == 'restart') { + exec($command.' restart'); + } else { + exec($command.' reload'); + } + + } + } // end class diff --git a/server/plugins-available/bind_plugin.inc.php b/server/plugins-available/bind_plugin.inc.php new file mode 100644 index 000000000..5aebc3700 --- /dev/null +++ b/server/plugins-available/bind_plugin.inc.php @@ -0,0 +1,199 @@ +plugins->registerEvent('dns_soa_insert',$this->plugin_name,'soa_insert'); + $app->plugins->registerEvent('dns_soa_update',$this->plugin_name,'soa_update'); + $app->plugins->registerEvent('dns_soa_delete',$this->plugin_name,'soa_delete'); + + //* RR + $app->plugins->registerEvent('dns_rr_insert',$this->plugin_name,'rr_insert'); + $app->plugins->registerEvent('dns_rr_update',$this->plugin_name,'rr_update'); + $app->plugins->registerEvent('dns_rr_delete',$this->plugin_name,'rr_delete'); + + } + + + function soa_insert($event_name,$data) { + global $app, $conf; + + $this->action = 'insert'; + $this->soa_update($event_name,$data); + + } + + function soa_update($event_name,$data) { + global $app, $conf; + + //* load the server configuration options + $app->uses("getconf"); + $dns_config = $app->getconf->get_server_config($conf["server_id"], 'dns'); + + //* Write the domain file + $tpl = new tpl(); + $tpl->newTemplate("bind_pri.domain.master"); + + $zone = $data['new']; + $tpl->setVar($zone); + + $records = $app->db->queryAllRecords("SELECT * FROM dns_rr WHERE zone = ".$zone['id']); + $tpl->setLoop('records',$records); + + $filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri.'.$zone['origin']); + file_put_contents($filename,$tpl->grab()); + exec('chown '.escapeshellcmd($dns_config['bind_user']).':'.escapeshellcmd($dns_config['bind_group']).' '.$filename); + unset($tpl); + unset($records); + unset($zone); + + //* rebuild the named.conf file if the origin has changed or when the origin is inserted. + if($this->action == 'insert' || $data['old']['origin'] != $data['new']['origin']) { + $this->write_named_conf($data,$dns_config); + } + + //* Delete old domain file, if domain name has been changed + if($data['old']['origin'] != $data['new']['origin']) { + $filename = $dns_config['bind_zonefiles_dir'].'/pri.'.$data['old']['origin']; + if(is_file($filename)) unset($filename); + } + + //* Reload bind nameserver + $app->services->restartServiceDelayed('bind','reload'); + + } + + function soa_delete($event_name,$data) { + global $app, $conf; + + //* load the server configuration options + $app->uses("getconf"); + $dns_config = $app->getconf->get_server_config($conf["server_id"], 'dns'); + + //* rebuild the named.conf file + $this->write_named_conf($data,$dns_config); + + //* Delete the domain file + $filename = $dns_config['bind_zonefiles_dir'].'/pri.'.$data['old']['origin']; + if(is_file($filename)) unset($filename); + + //* Reload bind nameserver + $app->services->restartServiceDelayed('bind','reload'); + + } + + function rr_insert($event_name,$data) { + global $app, $conf; + + //* Get the data of the soa and call soa_update + $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".$data['new']['zone']); + $data["new"] = $tmp; + $data["old"] = $tmp; + $this->action = 'update'; + $this->soa_update($event_name,$data); + + } + + function rr_update($event_name,$data) { + global $app, $conf; + + //* Get the data of the soa and call soa_update + $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".$data['new']['zone']); + $data["new"] = $tmp; + $data["old"] = $tmp; + $this->action = 'update'; + $this->soa_update($event_name,$data); + + } + + function rr_delete($event_name,$data) { + global $app, $conf; + + //* Get the data of the soa and call soa_update + $tmp = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ".$data['old']['zone']); + $data["new"] = $tmp; + $data["old"] = $tmp; + $this->action = 'update'; + $this->soa_update($event_name,$data); + + } + + ################################################################### + + function write_named_conf($data, $dns_config) { + global $app, $conf; + + $zones = $app->db->queryAllRecords("SELECT origin FROM dns_soa WHERE active = 'Y'"); + + $tpl = new tpl(); + $tpl->newTemplate("bind_named.conf.local.master"); + $tpl->setLoop('zones',$zones); + + file_put_contents($dns_config['named_conf_local_path'],$tpl->grab()); + unset($tpl); + + } + + + + +} // end class + +?> \ No newline at end of file -- GitLab