From ff195c7cf770dbd9385c22feb9a69289c5cfae23 Mon Sep 17 00:00:00 2001 From: Marcello Coutinho Date: Thu, 17 Oct 2013 16:12:45 -0300 Subject: bind - add widget, forward zone, rndc config and check slave zone dir permissions --- config/bind/bind.inc | 227 +++++++++++++++++++++++++++++--------------- config/bind/bind.widget.php | 86 +++++++++++++++++ config/bind/bind.xml | 5 + config/bind/bind_zones.xml | 37 +++++--- 4 files changed, 267 insertions(+), 88 deletions(-) create mode 100644 config/bind/bind.widget.php (limited to 'config') diff --git a/config/bind/bind.inc b/config/bind/bind.inc index 1bcefa16..6e04e649 100644 --- a/config/bind/bind.inc +++ b/config/bind/bind.inc @@ -51,40 +51,72 @@ function bind_zone_validate($post, $input_errors){ if (key_exists("mail",$_POST)) $_POST['mail']=preg_replace("/@/",".",$post['mail']); - if ($_POST['type']=='slave'){ - if( $_POST['slaveip'] == "") - $input_errors[] = 'The field \'Master Zone IP\' is required for slave zones.'; - } - else{ - if($_POST['nameserver']=='') - $input_errors[] = 'The field \'Name server\' is required for master zones.'; - for ($i=0;$i < count($_POST);$i++){ - if (key_exists("hostname$i",$_POST)){ - if ($_POST['reverso']=="on"){ - $_POST["hostvalue$i"]=""; - if (!preg_match("/(PTR|NS)/",$_POST["hosttype$i"])) - $input_errors[] = 'On reverse zones, valid record types are NS or PTR'; - } - if (preg_match("/(MX|NS)/",$_POST["hosttype$i"])) - $_POST["hostname$i"]=""; - if (!preg_match("/(MX|NS)/",$_POST["hosttype$i"]) && $_POST["hostname$i"]=="") - $input_errors[] = 'Record cannot be empty for '.$_POST["hosttype$i"].' type '; - if ($_POST["hosttype$i"]=="MX" && $_POST["hostvalue$i"]=="") - $_POST["hostvalue$i"]="10"; - if ($_POST["hosttype$i"]!="MX" && $_POST["hostvalue$i"]!="") - $_POST["hostvalue$i"]=""; - if ($_POST["hostdst$i"]=="") - $input_errors[] = 'Alias or IP address cannot be empty.'; + switch ($_POST['type']){ + case 'slave': + if( $_POST['slaveip'] == "") + $input_errors[] = 'The field \'Master Zone IP\' is required for slave zones.'; + break; + case 'forward': + if( $_POST['forwarders'] == "") + $input_errors[] = 'The field \'Forwarders\' is required for forward zones.'; + break; + default: + if($_POST['nameserver']=='') + $input_errors[] = 'The field \'Name server\' is required for master zones.'; + for ($i=0;$i < count($_POST);$i++){ + if (key_exists("hostname$i",$_POST)){ + if ($_POST['reverso']=="on"){ + $_POST["hostvalue$i"]=""; + if (!preg_match("/(PTR|NS)/",$_POST["hosttype$i"])) + $input_errors[] = 'On reverse zones, valid record types are NS or PTR'; + } + if (preg_match("/(MX|NS)/",$_POST["hosttype$i"])) + $_POST["hostname$i"]=""; + if (!preg_match("/(MX|NS)/",$_POST["hosttype$i"]) && $_POST["hostname$i"]=="") + $input_errors[] = 'Record cannot be empty for '.$_POST["hosttype$i"].' type '; + if ($_POST["hosttype$i"]=="MX" && $_POST["hostvalue$i"]=="") + $_POST["hostvalue$i"]="10"; + if ($_POST["hosttype$i"]!="MX" && $_POST["hostvalue$i"]!="") + $_POST["hostvalue$i"]=""; + if ($_POST["hostdst$i"]=="") + $input_errors[] = 'Alias or IP address cannot be empty.'; } } - } + } } function bind_sync(){ global $config; conf_mount_rw(); - + //create rndc + $rndc_confgen="/usr/local/sbin/rndc-confgen"; + if (!file_exists(BIND_LOCALBASE."/etc/rndc-confgen.pfsense") && file_exists($rndc_confgen)){ + exec("$rndc_confgen ",$rndc_conf); + foreach($rndc_conf as $line) + $confgen_file.="$line\n"; + file_put_contents(BIND_LOCALBASE."/etc/rndc-confgen.pfsese",$confgen_file); + } + if (file_exists(BIND_LOCALBASE."/etc/rndc-confgen.pfsese")){ + $rndc_conf=file(BIND_LOCALBASE."/etc/rndc-confgen.pfsese"); + $confgen="rndc.conf"; + $rndc_bindconf=""; + foreach ($rndc_conf as $line){ + if ($confgen =="rndc.conf"){ + if (!preg_match ("/^#/",$line)) + $rndc_file.=$line; + } + else{ + if (!preg_match ("/named.conf/",$line)) + $rndc_bindconf.=preg_replace('/#/',"",$line); + } + if (preg_match("/named.conf/",$line)){ + $confgen="named.conf"; + file_put_contents(BIND_LOCALBASE."/etc/rndc.conf",$rndc_file); + } + } + } + $bind = $config["installedpackages"]["bind"]["config"][0]; $bind_enable = $bind['enable_bind']; $bind_forwarder = $bind['bind_forwarder']; @@ -95,16 +127,17 @@ function bind_zone_validate($post, $input_errors){ $custom_options = base64_decode($bind['bind_custom_options']); $bind_logging = $bind['bind_logging']; $bind_conf ="#Bind pfsense configuration\n"; - $bind_conf .="#Do not edit this file!!!\n"; -$bind_conf .= << CHROOT_LOCALBASE."/etc/namedb/named.root" $named_root=file_get_contents("http://www.internic.net/domain/named.root"); file_put_contents(CHROOT_LOCALBASE."/etc/namedb/named.root",$named_root,LOCK_EX); } - + if (!file_exists(CHROOT_LOCALBASE."/etc/localtime")){ + copy("/etc/localtime", CHROOT_LOCALBASE."/etc/localtime"); + } + bind_write_rcfile(); chown(CHROOT_LOCALBASE."/var/log","bind"); chgrp(CHROOT_LOCALBASE."/var/log","bind"); @@ -395,32 +457,47 @@ function bind_print_javascript_type_zone(){ var field = document.iform.type; var tipo = field.options[field.selectedIndex].value; - if (tipo == 'master') { - - document.iform.slaveip.disabled = 1; - document.iform.tll.disabled = 0; - document.iform.nameserver.disabled = 0; - document.iform.ipns.disabled = 0; - document.iform.mail.disabled = 0; - document.iform.serial.disabled = 0; - document.iform.refresh.disabled = 0; - document.iform.retry.disabled = 0; - document.iform.expire.disabled = 0; - document.iform.minimum.disabled = 0; - - } - else { - document.iform.slaveip.disabled = 0; - document.iform.tll.disabled = 1; - document.iform.nameserver.disabled = 1; - document.iform.ipns.disabled = 1; - document.iform.mail.disabled = 1; - document.iform.serial.disabled = 1; - document.iform.refresh.disabled = 1; - document.iform.retry.disabled = 1; - document.iform.expire.disabled = 1; - document.iform.minimum.disabled = 1; - } + switch (tipo){ + case 'master': + document.iform.slaveip.disabled = 1; + document.iform.tll.disabled = 0; + document.iform.nameserver.disabled = 0; + document.iform.forwarders.disabled = 1; + document.iform.ipns.disabled = 0; + document.iform.mail.disabled = 0; + document.iform.serial.disabled = 0; + document.iform.refresh.disabled = 0; + document.iform.retry.disabled = 0; + document.iform.expire.disabled = 0; + document.iform.minimum.disabled = 0; + break; + case 'slave': + document.iform.slaveip.disabled = 0; + document.iform.tll.disabled = 1; + document.iform.nameserver.disabled = 1; + document.iform.forwarders.disabled = 1; + document.iform.ipns.disabled = 1; + document.iform.mail.disabled = 1; + document.iform.serial.disabled = 1; + document.iform.refresh.disabled = 1; + document.iform.retry.disabled = 1; + document.iform.expire.disabled = 1; + document.iform.minimum.disabled = 1; + break; + case 'forward': + document.iform.slaveip.disabled = 1; + document.iform.tll.disabled = 1; + document.iform.nameserver.disabled = 1; + document.iform.forwarders.disabled = 0; + document.iform.ipns.disabled = 1; + document.iform.mail.disabled = 1; + document.iform.serial.disabled = 1; + document.iform.refresh.disabled = 1; + document.iform.retry.disabled = 1; + document.iform.expire.disabled = 1; + document.iform.minimum.disabled = 1; + break; + } } --> diff --git a/config/bind/bind.widget.php b/config/bind/bind.widget.php new file mode 100644 index 00000000..490ded9b --- /dev/null +++ b/config/bind/bind.widget.php @@ -0,0 +1,86 @@ +"; + echo" "; +} +function close_table(){ + echo" "; + echo""; + +} + +$pfb_table=array(); +$img['Sick']=""; +$img['Healthy']=""; + + +#var_dump($pfb_table); +#exit; +?>
".ucfirst($fields[0])."\n"; + print "{$fields[1]}\n"; + } +close_table(); +echo"
"; + +?> + diff --git a/config/bind/bind.xml b/config/bind/bind.xml index 97dc7012..aa6a5f25 100644 --- a/config/bind/bind.xml +++ b/config/bind/bind.xml @@ -123,6 +123,11 @@ 0755 http://www.pfsense.org/packages/config/bind/pkg_bind.inc + + /usr/local/www/widgets/widgets/ + 0755 + http://www.pfsense.org/packages/config/bind/bind.widget.php + listtopic diff --git a/config/bind/bind_zones.xml b/config/bind/bind_zones.xml index 11cfb0e2..508056c0 100644 --- a/config/bind/bind_zones.xml +++ b/config/bind/bind_zones.xml @@ -93,6 +93,10 @@ View Name view + + Serial + serial + Description description @@ -119,18 +123,11 @@ type Select zone type select - - - - + + + + + on_type_zone_changed() @@ -176,6 +173,19 @@ If zone is slave, enter the IP address of the master DNS zone. input + + listtopic + Forward Zone Configuration + temp04 + + + Forwarders + forwarders + Enter forwarders IPs for this domain. Separate by semi-colons (;). + input + 60 + + listtopic Master Zone Configuration @@ -352,7 +362,8 @@ - $_POST['serial']=(date("U")+ 1000000000); + if ($_POST['type']=="master") + $_POST['serial']=(date("U")+ 1000000000); bind_zone_validate($_POST, &$input_errors); -- cgit v1.2.3