aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorRenato Botelho <garga@pfSense.org>2014-03-21 07:38:38 -0300
committerRenato Botelho <garga@pfSense.org>2014-03-21 07:38:38 -0300
commit6e70897a6b5cee93ef42d5c962e641d232d378d2 (patch)
tree49ce7c8d4fc00f3382b0160af11328509d65404f /config
parent5684198146ffd32bd1c18e31a640523ab352fb32 (diff)
parent2dcbc82e0e71ee9944ba32e3c34fa8e4af200d25 (diff)
downloadpfsense-packages-6e70897a6b5cee93ef42d5c962e641d232d378d2.tar.gz
pfsense-packages-6e70897a6b5cee93ef42d5c962e641d232d378d2.tar.bz2
pfsense-packages-6e70897a6b5cee93ef42d5c962e641d232d378d2.zip
Merge pull request #626 from crocomo/bind
bind: Rework DHCP static mappings
Diffstat (limited to 'config')
-rw-r--r--config/bind/bind.inc67
1 files changed, 39 insertions, 28 deletions
diff --git a/config/bind/bind.inc b/config/bind/bind.inc
index 156e9eb8..17d171d1 100644
--- a/config/bind/bind.inc
+++ b/config/bind/bind.inc
@@ -445,35 +445,46 @@ EOD;
$zone_conf .= "$hostname \t IN $hosttype $hostvalue \t$hostdst\n";
}
+
+ # Register DHCP static mappings
if (($zone[regdhcpstatic] == 'on') && is_array($config['dhcpd'])) {
- foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf)
- if(is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable']))
- foreach ($dhcpifconf['staticmap'] as $host)
- if ($host['ipaddr'] && $host['hostname']) {
- if($zonereverso == "on") {
- $hostdomain = $dhcpifconf['domain'];
- if(strlen($hostdomain) == 0) {
- $hostdomain = $config['system']['domain'];
- }
- if(strlen($hostdomain) != 0) {
- $hostdomain .= '.';
- }
- $zoneparts = array_reverse(explode('.',$zonename));
- $addressparts = explode('.',$host['ipaddr']);
- $addressstart = 0;
- while($addressstart < count($zoneparts) && $addressstart < count($addressparts) && $zoneparts[$addressstart] == $addressparts[$addressstart]) {
- $addressstart++;
- }
- $shortaddress='';
- for($addresspointer = count($addressparts)-1; $addresspointer >= $addressstart; $addresspointer--) {
- $shortaddress .= (strlen($shortaddress) > 0 ? '.' : '') . $addressparts[$addresspointer];
- }
- $zone_conf .= "{$shortaddress}\tIN PTR\t{$host['hostname']}.{$hostdomain}\n";
- } else {
- $zone_conf .= "{$host['hostname']}\tIN A\t{$host['ipaddr']}\n";
- }
- }
- }
+ $zoneparts = array_reverse(explode('.',$zonename));
+ foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) {
+ if (!isset($dhcpifconf['enable']) || !is_array($dhcpifconf['staticmap'])) {
+ continue;
+ }
+ foreach ($dhcpifconf['staticmap'] as $host) {
+ if (is_domain($host['domain'])) {
+ $domain = $host['domain'];
+ } elseif (is_domain($dhcpifconf['domain'])) {
+ $domain = $dhcpifconf['domain'];
+ } elseif (is_domain($config['system']['domain'])) {
+ $domain = $config['system']['domain'];
+ } else {
+ continue;
+ }
+ if (!is_hostname($host['hostname']) || !is_ipaddr($host['ipaddr'])) {
+ continue;
+ }
+ if ($zonereverso == "on") {
+ $parts = explode('.',$host['ipaddr']);
+ $intersect = array_intersect_assoc($parts,$zoneparts);
+ if (count($zoneparts) == count($intersect)) {
+ $diff = array_diff_assoc($parts,$zoneparts);
+ $shortaddr = implode('.',array_reverse($diff));
+ $zone_conf .= "{$shortaddr}\tIN PTR\t{$host['hostname']}.{$domain}.\n";
+ }
+ } else {
+ $parts = array_reverse(explode('.',$domain));
+ $diff = array_diff_assoc($parts,$zoneparts);
+ if (count($diff) == 0) {
+ $zone_conf .= "{$host['hostname']}\tIN A\t{$host['ipaddr']}\n";
+ }
+ }
+ }
+ }
+ }
+
if ($zone['customzonerecords']!=""){
$zone_conf .= "\n\n;\n;custom zone records\n;\n".base64_decode($zone['customzonerecords'])."\n";
}