aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcello Coutinho <marcellocoutinho@gmail.com>2013-10-16 22:40:12 -0300
committerMarcello Coutinho <marcellocoutinho@gmail.com>2013-10-16 22:40:12 -0300
commitcaf135854ec7df07301512e972e3bc637e3abe9e (patch)
treed90828f1fd19a052142b237e29158261b5b40091
parent8955978f70e3e865ca5a693d1962adcf4fa3d73f (diff)
downloadpfsense-packages-caf135854ec7df07301512e972e3bc637e3abe9e.tar.gz
pfsense-packages-caf135854ec7df07301512e972e3bc637e3abe9e.tar.bz2
pfsense-packages-caf135854ec7df07301512e972e3bc637e3abe9e.zip
bind - show result file on zone tab and fix slave zone check
-rw-r--r--config/bind/bind.inc193
-rw-r--r--config/bind/bind_zones.xml20
-rw-r--r--pkg_config.8.xml2
-rw-r--r--pkg_config.8.xml.amd642
4 files changed, 129 insertions, 88 deletions
diff --git a/config/bind/bind.inc b/config/bind/bind.inc
index 67677972..44ec0ed1 100644
--- a/config/bind/bind.inc
+++ b/config/bind/bind.inc
@@ -48,26 +48,36 @@ else
define('CHROOT_LOCALBASE','/conf/named');
function bind_zone_validate($post, $input_errors){
- if ($_POST['type']=='reverso'){
- if( $_POST['nameserver'] == "")
- $input_errors[] = 'The field \'Name Server\' is required';
- }
if (key_exists("mail",$_POST))
$_POST['mail']=preg_replace("/@/",".",$post['mail']);
- for ($i=0;$i < count($_POST);$i++){
- if (key_exists("hostname$i",$_POST)){
- 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.';
- }
+
+ 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.';
+ }
+ }
+ }
}
function bind_sync(){
@@ -75,7 +85,7 @@ function bind_zone_validate($post, $input_errors){
global $config;
conf_mount_rw();
- $bind = $config["installedpackages"]["bind"]["config"][0];
+ $bind = $config["installedpackages"]["bind"]["config"][0];
$bind_enable = $bind['enable_bind'];
$bind_forwarder = $bind['bind_forwarder'];
$forwarder_ips = $bind['bind_forwarder_ips'];
@@ -84,8 +94,8 @@ function bind_zone_validate($post, $input_errors){
$bind_notify = $bind['bind_notify'];
$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 ="#Bind pfsense configuration\n";
+ $bind_conf .="#Do not edit this file!!!\n";
$bind_conf .= <<<EOD
options {
@@ -176,7 +186,7 @@ EOD;
#Config Zone domain
if(!is_array($config["installedpackages"]["bindacls"]) || !is_array($config["installedpackages"]["bindacls"]["config"])){
$config["installedpackages"]["bindacls"]["config"][] =array("name"=>"any","description"=>"Default Access list","row" => array("value"=> "","description"=>""));
- write_config();
+ write_config("Create Default bind acl 'Any'");
}
$bindacls = $config["installedpackages"]["bindacls"]["config"];
for ($i=0; $i<sizeof($bindacls); $i++)
@@ -194,25 +204,25 @@ EOD;
}
}
- if(is_array($config["installedpackages"]["bindviews"]))
+ if(is_array($config["installedpackages"]["bindviews"]))
$bindview = $config["installedpackages"]["bindviews"]["config"];
else
$bindview =array();
-
+
for ($i=0; $i<sizeof($bindview); $i++)
- {
+ {
$views = $config["installedpackages"]["bindviews"]["config"][$i];
- $viewname = $views['name'];
+ $viewname = $views['name'];
$viewrecursion = $views['recursion'];
if($views['match-clients'] == '')
- $viewmatchclients = "none";
+ $viewmatchclients = "none";
else
$viewmatchclients = str_replace(',','; ',$views['match-clients']);
if($views['allow-recursion'] == '')
- $viewallowrecursion = "none";
+ $viewallowrecursion = "none";
else
$viewallowrecursion = str_replace(',','; ',$views['allow-recursion']);
- $viewcustomoptions = $views['bind_custom_options'];
+ $viewcustomoptions = $views['bind_custom_options'];
$bind_conf .= "view \"$viewname\" { \n\n";
$bind_conf .= "\trecursion $viewrecursion;\n";
@@ -226,74 +236,81 @@ EOD;
$bind_conf .= "\t};\n\n";
if(is_array($config["installedpackages"]["bindzone"]))
- $bindzone = $config["installedpackages"]["bindzone"]["config"];
- else
- $bindzone =array();
+ $bindzone = $config["installedpackages"]["bindzone"]["config"];
+ else
+ $bindzone =array();
+
+ $write_config=0;
for ($x=0; $x<sizeof($bindzone); $x++)
{
$zone = $bindzone[$x];
- $zonename = $zone['name'];
- $zonetype = $zone['type'];
- $zoneview = $zone['view'];
- $zonecustom = $zone['custom'];
- $zoneipslave = $zone['slaveip'];
- $zonereverso = $zone['reverso'];
+ $zonename = $zone['name'];
+ $zonetype = $zone['type'];
+ $zoneview = $zone['view'];
+ $zonecustom = $zone['custom'];
+ $zoneipslave = $zone['slaveip'];
+ $zonereverso = $zone['reverso'];
+
+ if (!(is_dir(CHROOT_LOCALBASE."/etc/namedb/$zonetype/$zoneview")))
+ mkdir(CHROOT_LOCALBASE."/etc/namedb/$zonetype/$zoneview",0755,true);
+
if($zone['allowupdate'] == '')
- $zoneallowupdate = "none";
+ $zoneallowupdate = "none";
else
$zoneallowupdate = str_replace(',','; ',$zone['allowupdate']);
if($zone['allowquery'] == '')
- $zoneallowquery = "none";
+ $zoneallowquery = "none";
else
$zoneallowquery = str_replace(',','; ',$zone['allowquery']);
if($zone['allowtransfer'] == '')
- $zoneallowtransfer = "none";
+ $zoneallowtransfer = "none";
else
$zoneallowtransfer = str_replace(',','; ',$zone['allowtransfer']);
- if ($zoneview == $viewname)
- {
+ if ($zoneview == $viewname){
if($zonereverso == "on")
- $bind_conf .= "\tzone \"$zonename.in-addr.arpa\" {\n";
- else
- $bind_conf .= "\tzone \"$zonename\" {\n";
+ $bind_conf .= "\tzone \"$zonename.in-addr.arpa\" {\n";
+ else
+ $bind_conf .= "\tzone \"$zonename\" {\n";
$bind_conf .= "\t\ttype $zonetype;\n";
- $bind_conf .= "\t\tfile \"/etc/namedb/$zonetype/$zoneview/$zonename.DB\";\n";
- if ($zonetype == "slave")
- $bind_conf .= "\t\tmasters { $zoneipslave };\n";
- if ($zonetype != "slave")
+ $bind_conf .= "\t\tfile \"/etc/namedb/$zonetype/$zoneview/$zonename.DB\";\n";
+ if ($zonetype == "slave")
+ $bind_conf .= "\t\tmasters { $zoneipslave; };\n";
+ if ($zonetype != "slave")
$bind_conf .= "\t\tallow-update { $zoneallowupdate;};\n";
- if ($zonetype != "slave")
+ if ($zonetype != "slave")
$bind_conf .= "\t\tallow-query { $zoneallowquery;};\n";
- if ($zonetype != "slave")
+ if ($zonetype != "slave")
$bind_conf .= "\t\tallow-transfer { $zoneallowtransfer;};\n";
- if ($zonecustom != '')
- $bind_conf .= "\t\t$zonecustom\n";
+ if ($zonecustom != '')
+ $bind_conf .= "\t\t$zonecustom\n";
+
$bind_conf .= "\t};\n\n";
if ($zonetype == "master"){
- $zonetll = $zone['tll'];
- $zonemail = preg_replace("/@/",".",$zone['mail']);
- $zoneserial = $zone['serial'];
- $zonerefresh = $zone['refresh'];
- $zoneretry = $zone['retry'];
- $zoneexpire = $zone['expire'];
- $zoneminimum = $zone['minimum'];
- $zonenameserver = $zone['nameserver'];
- $zoneipns = $zone['ipns'];
- $zonereverso = $zone['reverso'];
+ $zonetll = $zone['tll'];
+ $zonemail = ($zone['mail']?$zone['mail']:"zonemaster.{$zonename}");
+ $zonemail = preg_replace("/@/",".",$zonemail);
+ $zoneserial = $zone['serial'];
+ $zonerefresh = ($zone['refresh']?$zone['refresh']:"3600");
+ $zoneretry = ($zone['retry']?$zone['retry']:"600");
+ $zoneexpire = ($zone['expire']?$zone['expire']:"86400");
+ $zoneminimum = ($zone['minimum']?$zone['minimum']:"3600");
+ $zonenameserver = $zone['nameserver'];
+ $zoneipns = $zone['ipns'];
+ $zonereverso = $zone['reverso'];
if($zone['allowupdate'] == '')
- $zoneallowupdate = "none";
+ $zoneallowupdate = "none";
else
- $zoneallowupdate = str_replace(',','; ',$zone['allowupdate']);
+ $zoneallowupdate = str_replace(',','; ',$zone['allowupdate']);
if($zone['allowquery'] == '')
- $zoneallowquery = "none";
+ $zoneallowquery = "none";
else
- $zoneallowquery = str_replace(',','; ',$zone['allowquery']);
+ $zoneallowquery = str_replace(',','; ',$zone['allowquery']);
if($zone['allowtransfer'] == '')
- $zoneallowtransfer = "none";
+ $zoneallowtransfer = "none";
else
$zoneallowtransfer = str_replace(',','; ',$zone['allowtransfer']);
$zone_conf = "\$TTL $zonetll\n;\n";
@@ -307,17 +324,17 @@ EOD;
$zone_conf .= "\t\t$zoneserial ; serial\n";
$zone_conf .= "\t\t$zonerefresh ; refresh\n";
- $zone_conf .= "\t\t$zoneretry ; retry\n";
- $zone_conf .= "\t\t$zoneexpire ; expire\n";
+ $zone_conf .= "\t\t$zoneretry ; retry\n";
+ $zone_conf .= "\t\t$zoneexpire ; expire\n";
$zone_conf .= "\t\t$zoneminimum ; default_ttl\n\t\t)\n\n";
$zone_conf .= ";\n; Zone Records\n;\n";
if($zonereverso == "on")
- $zone_conf .= "\t IN NS \t\t$zonenameserver.\n";
- else{
- $zone_conf .= "@ \t IN NS \t\t$zonenameserver.\n";
+ $zone_conf .= "\t IN NS \t$zonenameserver.\n";
+ else{
+ $zone_conf .= "@ \t IN NS \t$zonenameserver.\n";
if ($zoneipns !="")
- $zone_conf .= "@ \t IN A \t\t$zoneipns\n";
+ $zone_conf .= "@ \t IN A \t$zoneipns\n";
}
for ($y=0; $y<sizeof($zone['row']); $y++)
{
@@ -328,18 +345,26 @@ EOD;
$hostdst .= ".";
$hostvalue = $zone['row'][$y]['hostvalue'];
- $zone_conf .= "$hostname \t IN $hosttype $hostvalue \t$hostdst\n";
- }
- if (!(is_dir(CHROOT_LOCALBASE."/etc/namedb/$zonetype/$zoneview"))) {
- mkdir(CHROOT_LOCALBASE."/etc/namedb/$zonetype/$zoneview",0755,true);
- }
+ $zone_conf .= "$hostname \t IN $hosttype $hostvalue \t$hostdst\n";
+ }
file_put_contents(CHROOT_LOCALBASE."/etc/namedb/$zonetype/$zoneview/$zonename.DB", $zone_conf);
-
+ $config["installedpackages"]["bindzone"]["config"][$x][resultconfig]=base64_encode($zone_conf);
+ $write_config++;
}
- }
+ else{
+ //check if exists slave zone file
+ if (file_exists(CHROOT_LOCALBASE."/etc/namedb/$zonetype/$zoneview/$zonename.DB")){
+ $slave_file=file_get_contents(CHROOT_LOCALBASE."/etc/namedb/$zonetype/$zoneview/$zonename.DB");
+ $config["installedpackages"]["bindzone"]["config"][$x][resultconfig]=base64_encode($slave_file);
+ $write_config++;
+ }
+ }
+ }
}
-
- $bind_conf .= "};\n";
+ if($write_config > 0){
+ write_config("save result config file for zone on xml");
+ }
+ $bind_conf .= "};\n";
}
$dirs=array("/etc/namedb","/var/run/named","/var/dump","/var/log","/var/stats");
foreach ($dirs as $dir){
@@ -403,7 +428,7 @@ function bind_print_javascript_type_zone(){
}
function bind_print_javascript_type_zone2(){
- print("<script language=\"JavaScript\">on_type_zone_changed()</script>\n");
+ print("<script language=\"JavaScript\">on_type_zone_changed();document.iform.resultconfig.disabled = 1;</script>\n");
}
function bind_write_rcfile() {
diff --git a/config/bind/bind_zones.xml b/config/bind/bind_zones.xml
index 93dffde0..11cfb0e2 100644
--- a/config/bind/bind_zones.xml
+++ b/config/bind/bind_zones.xml
@@ -108,7 +108,9 @@
<field>
<fielddescr>Zone Name</fielddescr>
<fieldname>name</fieldname>
- <description>Enter the name for zone (ex:mydomain.com)</description>
+ <description><![CDATA[Enter the name for zone (ex:mydomain.com)<br>
+ For reverse zones, include zone ip in reverse order or following your provider instructions.(Ex: 1.168.192)<br>
+ IN-ADDR.ARPA will be automaticaly included on conf files when reveser zone option is checked.]]></description>
<type>input</type>
<required/>
</field>
@@ -169,7 +171,7 @@
<fieldname>temp04</fieldname>
</field>
<field>
- <fielddescr>IP Master Zone</fielddescr>
+ <fielddescr>Master Zone IP</fielddescr>
<fieldname>slaveip</fieldname>
<description>If zone is slave, enter the IP address of the master DNS zone.</description>
<type>input</type>
@@ -326,6 +328,20 @@
</rowhelperfield>
</rowhelper>
</field>
+ <field>
+ <type>listtopic</type>
+ <name>Zone config file</name>
+ <fieldname>temp03</fieldname>
+ </field>
+ <field>
+ <fielddescr>Resulting config file</fielddescr>
+ <fieldname>resultconfig</fieldname>
+ <description>Resulting bind config file for this zone.</description>
+ <type>textarea</type>
+ <cols>75</cols>
+ <rows>15</rows>
+ <encoding>base64</encoding>
+ </field>
</fields>
<custom_php_after_form_command>
bind_print_javascript_type_zone2();
diff --git a/pkg_config.8.xml b/pkg_config.8.xml
index 63f0c87a..431cfe1b 100644
--- a/pkg_config.8.xml
+++ b/pkg_config.8.xml
@@ -53,7 +53,7 @@
<descr><![CDATA[The most widely used name server software]]></descr>
<website>http://www.isc.org/downloads/BIND/</website>
<category>Services</category>
- <version>9.9.4 pkg v 0.1.3</version>
+ <version>9.9.4 pkg v 0.1.4</version>
<status>Beta</status>
<required_version>2.1</required_version>
<config_file>http://www.pfsense.com/packages/config/bind/bind.xml</config_file>
diff --git a/pkg_config.8.xml.amd64 b/pkg_config.8.xml.amd64
index 35ccf26c..794fd27f 100644
--- a/pkg_config.8.xml.amd64
+++ b/pkg_config.8.xml.amd64
@@ -53,7 +53,7 @@
<descr><![CDATA[The most widely used name server software]]></descr>
<website>http://www.isc.org/downloads/BIND/</website>
<category>Services</category>
- <version>9.9.4 pkg v 0.1.3</version>
+ <version>9.9.4 pkg v 0.1.4</version>
<status>Beta</status>
<required_version>2.1</required_version>
<config_file>http://www.pfsense.com/packages/config/bind/bind.xml</config_file>