&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']; /* 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"); 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); switch ($domain['recordtype']) { case "SOA": $record_data = ".{$hostname}::{$ipaddress}"; break; case "MX": $record_data = "@{$hostname}:{$ipaddress}::{$ttl}"; break; case "A": $record_data = "+{$hostname}:{$ipaddress}::{$ttl}"; break; case "PTR": $record_data = "={$hostname}:{$ipaddress}::{$ttl}"; break; case "CNAME": $record_data = "C{$hostname}:{$ipaddress}::{$ttl}"; break; } if($record_data) 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(); } ?>