diff options
Diffstat (limited to 'packages/tinydns')
-rw-r--r-- | packages/tinydns/tinydns.inc | 58 | ||||
-rw-r--r-- | packages/tinydns/tinydns_domains.xml | 16 |
2 files changed, 57 insertions, 17 deletions
diff --git a/packages/tinydns/tinydns.inc b/packages/tinydns/tinydns.inc index 591610be..ac626a0c 100644 --- a/packages/tinydns/tinydns.inc +++ b/packages/tinydns/tinydns.inc @@ -31,7 +31,7 @@ function tinydns_custom_php_install_command() { global $g, $config; - conf_mount_rw(); + conf_mount_rw(); $fd = fopen("/usr/local/etc/rc.d/svscan.sh", "w"); $svscan = <<<EOD @@ -83,11 +83,11 @@ svscan_stop_post () { } run_rc_command "\$1" - + EOD; - + fwrite($fd, $svscan); - fclose($fd); + fclose($fd); conf_mount_ro(); } @@ -96,7 +96,7 @@ function tinydns_custom_php_deinstall_command() { conf_mount_rw(); /* destroy all daemontools items */ exec("/usr/sbin/pw groupdel Gtinydns"); - exec("/usr/sbin/pw groupdel Gdnslog"); + exec("/usr/sbin/pw groupdel Gdnslog"); exec("/usr/sbin/pw userdel Gtinydns"); exec("/usr/sbin/pw userdel Gdnslog"); conf_mount_ro(); @@ -116,31 +116,65 @@ function tinydns_custom_php_changeip_command() { conf_mount_ro(); } +function tinydns_get_record_status($record) { + global $g, $config; + if(file_exists("/var/db/pingstatus/{$record}")) { + $status = file_return_contents("/var/db/pingstatus/{$record}"); + if($status == "DOWN") + return false; + } + return true; +} + +function tinydns_get_backup_record($record) { + global $g, $config; + if($config['installedpackages']['tinydnsdomains']) { + foreach($config['installedpackages']['tinydnsdomains']['config'] as $domain) { + if($domain['ipaddress'] == $record) { + /* if no failover host exists, simply return original record */ + if(!$domain['row']) + return $record; + foreach($domain['row'] as $row) { + /* XXX: expand to two failover hosts, etc */ + return $row['failoverip']; + } + } + } + } +} + function tinydns_create_zone_file() { global $g, $config; conf_mount_rw(); - $fd = fopen("/service/tinydns/root/data", "w"); + $fd = fopen("/service/tinydns/root/data", "w"); if($config['installedpackages']['tinydnsdomains']) foreach($config['installedpackages']['tinydnsdomains']['config'] as $domain) { $record_data = ""; $hostname = $domain['hostname']; $ipaddress = $domain['ipaddress']; + $ttl = $domain['ttl']; + /* check record status, if it is down request + * backup server if defined. + */ + $status = tinydns_get_record_status($ipaddress); + if(!$status) + $ipaddress = tinydns_get_backup_record($ipaddress); switch ($domain['recordtype']) { case "SOA": - $record_data = ".{$hostname}::{$ipaddress}"; + $record_data = ".{$hostname}::{$ipaddress}::{$ttl}"; break; case "MX": - $record_data = "@{$hostname}:{$ipaddress}"; + $record_data = "@{$hostname}:{$ipaddress}::{$ttl}"; break; case "A": - $record_data = "+{$hostname}:{$ipaddress}"; + $record_data = "+{$hostname}:{$ipaddress}::{$ttl}"; break; case "PTR": - $record_data = "={$hostname}:{$ipaddress}"; + $record_data = "={$hostname}:{$ipaddress}::{$ttl}"; break; case "CNAME": - $record_data = "C{$hostname}:{$ipaddress}"; - break; + $record_data = "C{$hostname}:{$ipaddress}::{$ttl}"; + break; } if($record_data) fwrite($fd, $record_data . "\n"); diff --git a/packages/tinydns/tinydns_domains.xml b/packages/tinydns/tinydns_domains.xml index 548bad4c..5661c5fb 100644 --- a/packages/tinydns/tinydns_domains.xml +++ b/packages/tinydns/tinydns_domains.xml @@ -17,7 +17,7 @@ <fielddescr>Hostname</fielddescr> <fieldname>hostname</fieldname> </columnitem> - </adddeleteeditpagefields> + </adddeleteeditpagefields> <fields> <field> <fieldname>hostname</fieldname> @@ -48,9 +48,14 @@ <description>Enter the IP Address that this record will point to (primary). The only exception is for NS type records where we expect a complete hostname to point to a A record.</description> <required/> <type>input</type> - </field> + </field> <field> - <fieldname>Threshhold</fieldname> + <fieldname>ttl</fieldname> + <fielddescr>DNS record time to live</fielddescr> + <type>input</type> + </field> + <field> + <fieldname>threshhold</fieldname> <fielddescr>Time in minutes before DNS switches to backup host</fielddescr> <type>input</type> </field> @@ -62,11 +67,12 @@ <fieldname>failoverip</fieldname> <description>Failover IP when host is not responding to ICMP/PING traffic</description> <type>input</type> + <size>25</size> </rowhelperfield> </rowhelper> - </field> + </field> </fields> <custom_php_resync_config_command> tinydns_create_zone_file(); - </custom_php_resync_config_command> + </custom_php_resync_config_command> </packagegui> |