&1 | /usr/local/bin/readproctitle service errors: ................................................................................................................................................................................................................................................................................................................................................................................................................ &" > /dev/null } svscan_stop_post () { echo "Stopping svscan." find -L "\$svscan_servicedir" -mindepth 1 -maxdepth 2 -type d \( \! -path "\$svscan_servicedir/*/*" -or -name 'log' \) -print0 | xargs -0 /usr/local/bin/svc -dx } run_rc_command "\$1" EOD; fwrite($fd, $svscan); fclose($fd); conf_mount_ro(); } function tinydns_custom_php_deinstall_command() { global $g, $config; conf_mount_rw(); /* destroy all daemontools items */ exec("/usr/sbin/pw groupdel Gtinydns"); exec("/usr/sbin/pw groupdel Gdnslog"); exec("/usr/sbin/pw userdel Gtinydns"); exec("/usr/sbin/pw userdel Gdnslog"); conf_mount_ro(); } function tinydns_custom_php_changeip_command() { global $g, $config; conf_mount_rw(); $ip = $config['installedpackages']['tinydns']['config'][0]['ipaddress']; $updatecron = $config['installedpackages']['tinydns']['config'][0]['updatecron']; /* setup daemon tools service area */ exec("/usr/sbin/pw useradd Gtinydns"); exec("/usr/sbin/pw useradd Gdnslog"); exec("/usr/local/bin/tinydns-conf Gtinydns Gdnslog /etc/tinydns {$ip}"); exec("/bin/ln -s /etc/tinydns /service"); sleep(5); exec("/usr/local/bin/svstat /service/tinydns"); if($updatecron) { $text_1 = "*/1 * * * * root /usr/bin/nice -n20 /etc/ping_hosts.sh"; $text_5 = "*/5 * * * * root /usr/bin/nice -n20 /etc/ping_hosts.sh"; $filenamea = "/etc/crontab"; remove_text_from_file($filenamea, $text_5); add_text_to_file($filenamea, $text_1); } else { $text_1 = "*/1 * * * * root /usr/bin/nice -n20 /etc/ping_hosts.sh"; $text_5 = "*/5 * * * * root /usr/bin/nice -n20 /etc/ping_hosts.sh"; $filenamea = "/etc/crontab"; remove_text_from_file($filenamea, $text_1); add_text_to_file($filenamea, $text_5); } exec("killall -HUP cron"); conf_mount_ro(); } function tinydns_get_record_status($record) { global $g, $config; if(file_exists("/var/db/pingstatus/{$record}")) { $status = file_get_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) { $status = tinydns_get_record_status($record); if($status) return $row['failoverip']; } } } } return $record; } function tinydns_setup_ping_items() { global $g, $config; if(!$config['installedpackages']['tinydnsdomains']) return; $wanif = get_real_wan_interface(); $ip = find_interface_ip($wanif); conf_mount_rw(); /* XXX: make this work with other packages */ $fd = fopen("/var/db/pkgpinghosts", "w"); if(!$fd) { log_error("Could not open /var/db/pkgpinghosts for writing."); return; } /* write out each ip address so ping_hosts.sh can begin monitoring ip * status and create a database of the status information that we can use. */ foreach($config['installedpackages']['tinydnsdomains']['config'] as $domain) { fwrite($fd, $ip . "|" . $domain['ipaddress'] . "|3|/usr/local/pkg/tinydns_down.php|/usr/local/pkg/tinydns_up.php\n"); if($domain['row']) { foreach($domain['row'] as $row) { fwrite($fd, $ip . "|" . $row['failoverip'] . "|3|/usr/local/pkg/tinydns_down.php|/usr/local/pkg/tinydns_up.php\n"); } } } fclose($fd); conf_mount_ro(); } function tinydns_create_zone_file() { global $g, $config; conf_mount_rw(); $fd = fopen("/service/tinydns/root/data", "w"); if(!$fd) { log_error("Could not open /service/tinydns/root/data for writing."); return; } 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); $record_data = tinydns_get_rowline_data($ipaddress, $domain['recordtype'], $ttl, $hostname); if($record_data) fwrite($fd, $record_data . "\n"); /* process load balanced items */ if($domain['row']) { foreach($domain['row'] as $row) { if($row['loadbalance']) { $status = tinydns_get_record_status($row['failoverip']); if($status) { $record_data = tinydns_get_rowline_data($row['failoverip'], $domain['recordtype'], $ttl, $hostname); fwrite($fd, $record_data . "\n"); } } } } } } fclose($fd); /* tell tinydns to reload zone file */ exec("cd /service/tinydns/root && /usr/local/bin/tinydns-data"); conf_mount_ro(); } /* formats data as a tinydns data row item */ function tinydns_get_rowline_data($recordip, $recordtype, $ttl, $hostname) { if($ttl) $ttl_string = "::{$ttl}"; else $ttl_string = ""; switch ($recordtype) { case "SOA": $record_data = ".{$hostname}::{$recordip}"; break; case "MX": $record_data = "@{$hostname}:{$recordip}{$ttl_string}"; break; case "A": $record_data = "+{$hostname}:{$recordip}{$ttl_string}"; break; case "PTR": $record_data = "={$hostname}:{$recordip}{$ttl_string}"; break; case "CNAME": $record_data = "C{$hostname}:{$recordip}{$ttl_string}"; break; } return $record_data; } ?>