aboutsummaryrefslogtreecommitdiffstats
path: root/config/tinydns
diff options
context:
space:
mode:
authorBill Marquette <bill.marquette@gmail.com>2009-02-06 19:18:00 -0600
committerBill Marquette <bill.marquette@gmail.com>2009-02-06 19:18:00 -0600
commit55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1 (patch)
treeba4783bab1dd65f1ceef2dfac9fdbd515531d18b /config/tinydns
parent67780cc9d469288742aea5bc378c29a54edd5ec5 (diff)
downloadpfsense-packages-55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1.tar.gz
pfsense-packages-55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1.tar.bz2
pfsense-packages-55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1.zip
mv packages to config dir to match web layout
Diffstat (limited to 'config/tinydns')
-rw-r--r--config/tinydns/new_zone_wizard.xml226
-rw-r--r--config/tinydns/tinydns.inc964
-rw-r--r--config/tinydns/tinydns.xml309
-rw-r--r--config/tinydns/tinydns_dhcp_filter.php129
-rw-r--r--config/tinydns/tinydns_domains.xml234
-rw-r--r--config/tinydns/tinydns_down.php42
-rw-r--r--config/tinydns/tinydns_filter.php38
-rw-r--r--config/tinydns/tinydns_parse_logs.php96
-rw-r--r--config/tinydns/tinydns_status.php188
-rw-r--r--config/tinydns/tinydns_sync.xml146
-rw-r--r--config/tinydns/tinydns_up.php42
-rw-r--r--config/tinydns/tinydns_view_logs.php122
-rw-r--r--config/tinydns/tinydns_xmlrpc_sync.php59
13 files changed, 2595 insertions, 0 deletions
diff --git a/config/tinydns/new_zone_wizard.xml b/config/tinydns/new_zone_wizard.xml
new file mode 100644
index 00000000..82d8d62b
--- /dev/null
+++ b/config/tinydns/new_zone_wizard.xml
@@ -0,0 +1,226 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<pfsensewizard>
+<copyright>
+/* $Id$ */
+/*
+ new_zone_wizard.xml
+ part of pfSense (http://www.pfsense.org/)
+ Copyright (C) 2008 Scott Ullrich
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+</copyright>
+<totalsteps>2</totalsteps>
+<step>
+ <id>1</id>
+ <title>pfSense New Zone Wizard</title>
+ <disableheader>true</disableheader>
+ <description>This wizard will guide you through the adding a new domain name service zone to TinyDNS.</description>
+ <fields>
+ <field>
+ <name>Next</name>
+ <type>submit</type>
+ </field>
+ </fields>
+ <stepbeforeformdisplay>
+ </stepbeforeformdisplay>
+</step>
+<step>
+ <id>2</id>
+ <title>Domain Name</title>
+ <description>On this screen you will define various options for your new DNS Zone</description>
+ <fields>
+ <field>
+ <name>Domain Name</name>
+ <type>input</type>
+ <unsetfield>yes</unsetfield>
+ <arraynum>0</arraynum>
+ <description>Enter the domain name for this zone (example: pfsense.org)</description>
+ </field>
+ <field>
+ <name>Primary Nameserver</name>
+ <type>listtopic</type>
+ </field>
+ <field>
+ <name>Primary Nameserver</name>
+ <type>input</type>
+ <unsetfield>yes</unsetfield>
+ <arraynum>0</arraynum>
+ <description>Enter the primary nameserver for this domain (example: ns.pfsense.org)</description>
+ </field>
+ <field>
+ <name>Secondary Nameserver</name>
+ <type>listtopic</type>
+ </field>
+ <field>
+ <name>Secondary Nameserver</name>
+ <type>input</type>
+ <arraynum>1</arraynum>
+ <description>Enter the secondary nameserver for this domain (example: ns2.pfsense.org)</description>
+ </field>
+ <field>
+ <name>Mail Exchanger (optional)</name>
+ <type>listtopic</type>
+ </field>
+ <field>
+ <name>Mail exchanger record hostname</name>
+ <type>input</type>
+ <arraynum>1</arraynum>
+ <description>Enter the hostname of your Mail exchanger (MX) - (example: exchange.pfsense.org)</description>
+ </field>
+ <field>
+ <name>Mail exchanger record IP address</name>
+ <type>input</type>
+ <arraynum>1</arraynum>
+ <description>Enter the IP address of your Mail exchanger (MX) - (example: 9.10.11.12)</description>
+ </field>
+ <field>
+ <name>First A record (optional)</name>
+ <type>listtopic</type>
+ </field>
+ <field>
+ <name>First A record hostname</name>
+ <type>input</type>
+ <arraynum>1</arraynum>
+ <description>Enter the first A records hostname (example: www.pfsense.org)</description>
+ </field>
+ <field>
+ <name>First A record IP address</name>
+ <type>input</type>
+ <arraynum>1</arraynum>
+ <description>Enter the first A records IP address (example: 1.2.3.4)</description>
+ </field>
+ <field>
+ <name>Secondary A record (optional)</name>
+ <type>listtopic</type>
+ </field>
+ <field>
+ <name>Second A record IP hostname</name>
+ <type>input</type>
+ <arraynum>1</arraynum>
+ <description>Enter the second A records hostname (example: pfsense.org)</description>
+ </field>
+ <field>
+ <name>Second A record IP address</name>
+ <type>input</type>
+ <arraynum>1</arraynum>
+ <description>Enter the second A records IP address (example: 5.6.7.8)</description>
+ </field>
+ <field>
+ <name>Third A record (optional)</name>
+ <type>listtopic</type>
+ </field>
+ <field>
+ <name>Third A record IP hostname</name>
+ <type>input</type>
+ <arraynum>1</arraynum>
+ <description>Enter the third A records hostname (example: www2.pfsense.org)</description>
+ </field>
+ <field>
+ <name>Third A record IP address</name>
+ <type>input</type>
+ <arraynum>1</arraynum>
+ <description>Enter the third A records IP address (example: 9.10.11.12)</description>
+ </field>
+ <field>
+ <name>Next</name>
+ <type>submit</type>
+ </field>
+ </fields>
+ <stepsubmitbeforesave>
+ <![CDATA[
+
+ $changed = false;
+
+ if($_POST['domainname'] and $_POST['primarynameserver']) {
+ $tmp = array();
+ $tmp['hostname'] = $_POST['domainname'];
+ $tmp['recordtype'] = "SOA";
+ $tmp['ipaddress'] = $_POST['primarynameserver'];
+ $config['installedpackages']['tinydnsdomains']['config'][] = $tmp;
+ unset($tmp);
+ $changed = true;
+ }
+
+ if($_POST['domainname'] and $_POST['secondarynameserver']) {
+ $tmp = array();
+ $tmp['hostname'] = $_POST['domainname'];
+ $tmp['recordtype'] = "SOA";
+ $tmp['ipaddress'] = $_POST['secondarynameserver'];
+ $config['installedpackages']['tinydnsdomains']['config'][] = $tmp;
+ unset($tmp);
+ $changed = true;
+ }
+
+ if($_POST['firstarecordhostname'] and $_POST['firstarecordipaddress']) {
+ $tmp = array();
+ $tmp['hostname'] = $_POST['firstarecordhostname'];
+ $tmp['recordtype'] = "A";
+ $tmp['ipaddress'] = $_POST['firstarecordipaddress'];
+ $config['installedpackages']['tinydnsdomains']['config'][] = $tmp;
+ unset($tmp);
+ $changed = true;
+ }
+
+ if($_POST['secondarecordiphostname'] and $_POST['secondarecordipaddress']) {
+ $tmp = array();
+ $tmp['hostname'] = $_POST['secondarecordiphostname'];
+ $tmp['recordtype'] = "A";
+ $tmp['ipaddress'] = $_POST['secondarecordipaddress'];
+ $config['installedpackages']['tinydnsdomains']['config'][] = $tmp;
+ unset($tmp);
+ $changed = true;
+ }
+
+ if($_POST['thirdarecordiphostname'] and $_POST['thirdarecordipaddress']) {
+ $tmp = array();
+ $tmp['hostname'] = $_POST['thirdarecordiphostname'];
+ $tmp['recordtype'] = "A";
+ $tmp['ipaddress'] = $_POST['thirdarecordipaddress'];
+ $config['installedpackages']['tinydnsdomains']['config'][] = $tmp;
+ unset($tmp);
+ $changed = true;
+ }
+
+ if($_POST['mailexchangerrecordipaddress'] and $_POST['mailexchangerrecordhostname']) {
+ $tmp = array();
+ $tmp['hostname'] = $_POST['mailexchangerrecordhostname'];
+ $tmp['recordtype'] = "MX";
+ $tmp['ipaddress'] = $_POST['secondarecordipaddress'];
+ unset($tmp);
+ $changed = true;
+ }
+
+ if($changed) {
+ write_config("new_zone_wizard.xml is creating a new zone {$_POST['domainname']}");
+ require_once("/usr/local/pkg/tinydns.inc");
+ tinydns_create_zone_file();
+ tinydns_setup_ping_items();
+ tinydns_sync_on_changes();
+ }
+
+ Header("Location: /tinydns_status.php");
+ ]]>
+ </stepsubmitbeforesave>
+</step>
+</pfsensewizard>
diff --git a/config/tinydns/tinydns.inc b/config/tinydns/tinydns.inc
new file mode 100644
index 00000000..24de1cab
--- /dev/null
+++ b/config/tinydns/tinydns.inc
@@ -0,0 +1,964 @@
+<?php
+
+/* $Id$ */
+/*
+ tinydns.inc
+ Copyright (C) 2006, 2007, 2008 Scott Ullrich
+ Parts Copyright (C) 2007 Goffredo Andreone
+ part of pfSense
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+require_once("filter.inc");
+
+function tinydns_custom_php_install_command() {
+ global $g, $config;
+ conf_mount_rw();
+ $fd = fopen("/usr/local/etc/rc.d/svscan.sh", "w");
+ if(!$fd) {
+ log_error("Could not open /usr/local/etc/rc.d/svscan.sh for writing.");
+ return;
+ }
+ $ipaddress = $config['installedpackages']['tinydns']['config'][0]['ipaddress'];
+
+ $minsegment = "10240";
+ $maxfilesize = "10240";
+ $maxsegment = "20480";
+ $maxfd = "100";
+ $maxchild = "40";
+
+ if($config['installedpackages']['tinydns']['config'][0]['minsegment'])
+ $minsegment = $config['installedpackages']['tinydns']['config'][0]['minsegment'];
+
+ if($config['installedpackages']['tinydns']['config'][0]['maxfilesize'])
+ $maxfilesize = $config['installedpackages']['tinydns']['config'][0]['maxfilesize'];
+
+ if($config['installedpackages']['tinydns']['config'][0]['maxsegment'])
+ $maxsegment = $config['installedpackages']['tinydns']['config'][0]['maxsegment'];
+
+ if($config['installedpackages']['tinydns']['config'][0]['maxfd'])
+ $maxfd = $config['installedpackages']['tinydns']['config'][0]['maxfd'];
+
+ if($config['installedpackages']['tinydns']['config'][0]['maxchild'])
+ $maxchild = $config['installedpackages']['tinydns']['config'][0]['maxchild'];
+
+ if($config['installedpackages']['tinydns']['config'][0]['refreshinterval'])
+ $refreshinterval = $config['installedpackages']['tinydns']['config'][0]['refreshinterval'];
+
+ $svscan = <<<EOD
+#!/bin/sh
+
+# PROVIDE: svscan
+# REQUIRE: LOGIN
+# KEYWORD: FreeBSD
+
+. /etc/rc.subr
+
+name="svscan"
+rcvar=`set_rcvar`
+command="/usr/local/bin/svscan"
+svscan_enable=\${svscan_enable-"YES"}
+svscan_servicedir=\${svscan_servicedir-"/service"}
+
+start_cmd="svscan_start"
+stop_postcmd="svscan_stop_post"
+
+load_rc_config \$name
+
+required_dirs="\${svscan_servicedir}"
+
+svscan_start () {
+ echo "Starting svscan."
+ /usr/bin/env \
+ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
+ /usr/sbin/daemon -f /bin/sh -c "\$command \$svscan_servicedir 2>&1 | /usr/local/bin/readproctitle service errors: ................................................................................................................................................................................................................................................................................................................................................................................................................ &" > /dev/null
+ minicron {$refreshinterval} /var/run/ping_hosts.pid "/etc/ping_hosts.sh; cd /etc/tinydns/root && /usr/local/bin/tinydns-data"
+}
+
+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
+ PIDTOKILL=`cat /var/run/ping_hosts.pid`
+ kill $PIDTOKILL
+}
+
+run_rc_command "\$1"
+
+EOD;
+
+ fwrite($fd, $svscan);
+ fclose($fd);
+ conf_mount_ro();
+ filter_configure();
+
+ tinydns_custom_php_changeip_command();
+
+ exec("/usr/local/etc/rc.d/svscan.sh start");
+}
+
+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 Gdnscache");
+ exec("/usr/sbin/pw groupdel Gdnslog");
+ exec("/usr/sbin/pw userdel Gtinydns");
+ exec("/usr/sbin/pw userdel Gdnscache");
+ exec("/usr/sbin/pw userdel Gdnslog");
+ exec("/usr/sbin/pw groupdel Gaxfrdns");
+ exec("rm /usr/local/www/*tinydns*");
+ exec("rm /usr/local/pkg/*tinydns*");
+ exec("rm /usr/local/pkg/pf/*tinydns*");
+ conf_mount_ro();
+ filter_configure();
+}
+
+function tinydns_custom_php_changeip_command() {
+ global $g, $config;
+ conf_mount_rw();
+
+ $ip = $config['interfaces']['lan']['ipaddr'];
+ $ipmask = $config['interfaces']['lan']['subnet'];
+ $arr = tinydns_get_ip_subnet_arpa($ip, $ipmask);
+ $dnscacheip = $ip;
+ $dnsuserip = $arr[0];
+
+ /* For now force $dnsserverip to to 127.0.0.1 unless a separate IP is specified */
+ $localhost = "127.0.0.1";
+ $dnsserverip = $localhost;
+ if($config['installedpackages']['tinydns']['config'][0]['ipaddress'] != $localhost AND $config['installedpackages']['tinydns']['config'][0]['ipaddress'] != "")
+ $dnsserverip = $config['installedpackages']['tinydns']['config'][0]['ipaddress'];
+ if($config['installedpackages']['tinydns']['config'][0]['regdhcpstatic'] OR $config['installedpackages']['tinydns']['config'][0]['regdhcp'])
+ $dnsserverip = $localhost;
+ $config['installedpackages']['tinydns']['config'][0]['ipaddress'] = $dnsserverip;
+
+ $updatecron = $config['installedpackages']['tinydns']['config'][0]['updatecron'];
+
+ /* Populate Zone Transfer array */
+ $ztipaddress = populate_zt_array();
+
+ /* setup daemon tools service area */
+ if(!is_dir("/service"))
+ exec("/bin/mkdir /service");
+
+ exec("/usr/sbin/pw useradd Gtinydns");
+ exec("/usr/sbin/pw useradd Gdnslog");
+ exec("/usr/sbin/pw useradd Gdnscache");
+ exec("/usr/sbin/pw useradd Gaxfrdns");
+
+ /* TinyDNS Server */
+ exec("/usr/local/bin/tinydns-conf Gtinydns Gdnslog /etc/tinydns {$dnsserverip}");
+ exec("/bin/ln -s /etc/tinydns /service/");
+
+ /* AXFRDNS - Zone transfers */
+ if(is_array($ztipaddress))
+ exec("/usr/local/bin/axfrdns-conf Gaxfrdns Gdnslog /etc/axfrdns /etc/tinydns {$dnsserverip}");
+ exec("/bin/ln -s /etc/axfrdns /service/");
+
+ exec("echo {$dnsserverip} > /etc/tinydns/env/IP");
+ exec("/usr/bin/killall -9 tinydns");
+
+ if($config['installedpackages']['tinydns']['config'][0]['enableforwarding']) {
+ if(!is_dir("/service/dnscache")) {
+ exec("/usr/sbin/pw useradd Gdnscache");
+ exec("/usr/local/bin/dnscache-conf Gdnscache Gdnslog /etc/dnscache {$dnscacheip}");
+ exec("/bin/ln -s /etc/dnscache /service/");
+ exec("/bin/cp /var/etc/resolv.conf /var/etc/resolv.conf.original");
+ exec("/bin/cp /var/etc/resolv.conf /var/etc/resolv.conf.dnscache");
+ }
+ exec("echo {$dnscacheip} > /etc/dnscache/env/IP");
+ tinydns_dnscache_forwarding_servers();
+ exec("touch /etc/dnscache/root/ip/{$dnsuserip}");
+ tinydns_create_soa_domain_list($dnsserverip);
+ exec("echo domain {$config['system']['domain']} > /var/etc/resolv.conf");
+ exec("echo nameserver {$dnscacheip} >> /var/etc/resolv.conf");
+ exec("/usr/bin/killall -9 dnscache");
+ } else {
+ if(file_exists("/var/etc/resolv.conf.original"))
+ exec("/bin/cp /var/etc/resolv.conf.original /var/etc/resolv.conf");
+ if(is_dir("/etc/dnscache")) {
+ dnscache_use_root_servers();
+ exec("/usr/bin/killall -9 dnscache");
+ }
+ }
+ conf_mount_ro();
+ filter_configure();
+}
+
+function populate_zt_array() {
+ global $g, $config;
+ /* Populate Zone Transfer array */
+ if($config['installedpackages']['tinydns']['config'][0]['row']) {
+ $ztipaddress = array();
+ foreach($config['installedpackages']['tinydns']['config'][0]['row'] as $zt) {
+ $tmp = array();
+ $tmp['ztipaddress'] = $zt['ztipaddress'];
+ $tmp['dnszone'] = $zt['dnszone'];
+ $ztipaddress[] = $tmp;
+ }
+ }
+ return $ztipaddress;
+}
+
+function tinydns_setup_axfrdns() {
+ global $g, $config;
+ /* Populate Zone Transfer array */
+ $ztipaddress = populate_zt_array();
+ if(!is_array($ztipaddress))
+ return;
+ $fd = fopen("/etc/axfrdns/tcp","w");
+ if(!$fd) {
+ log_error("Could not open /etc/axfrdns/tcp for writing");
+ return;
+ }
+ foreach($ztipaddress as $zt) {
+ if($zt['ztipaddress'] && $zt['dnszone'])
+ $zonet = "{$zt['ztipaddress']}:allow";
+ if($zt['dnszone'] <> "*")
+ $zonet .= ",AXFR=\"{$zt['dnszone']}\"";
+ fwrite($fd, $zone . "\n");
+ }
+ fclose($fd);
+ // Recompile database
+ exec("cd /service/axfrdns && /usr/local/bin/tinydns-data");
+}
+
+function tinydns_get_record_status($record, $pingthreshold = "", $wanpingthreshold = "") {
+ global $g, $config;
+ if(file_exists("/var/db/pingstatus/{$record}")) {
+ $status = "";
+ $status = file_get_contents("/var/db/pingstatus/{$record}");
+ if(stristr($status,"DOWN"))
+ return "DOWN";
+ }
+ if($pingthreshold) {
+ $current_ms = "";
+ if(file_exists("var/db/pingmsstatus/$record"))
+ $current_ms = file_get_contents("/var/db/pingmsstatus/$record");
+ if($pingthreshold > $current_ms)
+ return "DOWN";
+ }
+ if($wanpingthreshold) {
+ $current_avg = "";
+ if(file_exists("/var/db/wanaverage"))
+ $current_avg = file_get_contents("/var/db/wanaverage");
+ if($wanpingthreshold > $current_avg)
+ return "DOWN";
+ }
+ return "UP";
+}
+
+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($row['failoverip']);
+ if($status == "UP")
+ 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();
+ $processed = array();
+ /* 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;
+ }
+ config_lock();
+ /* 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) {
+ if(!in_array($domain['ipaddress'], $processed)) {
+ fwrite($fd, $ip . "|" . $domain['ipaddress'] . "|1|/usr/local/pkg/tinydns_down.php|/usr/local/pkg/tinydns_up.php\n");
+ $processed[] = $domain['ipaddress'];
+ }
+ if($domain['monitorip'] <> "")
+ $monitorip = $domain['monitorip'];
+ if($domain['row']) {
+ foreach($domain['row'] as $row) {
+ if($row['pingthreshold'])
+ $pingthreshold = $row['pingthreshold'];
+ else
+ $row['pingthreshold'] = "";
+ if($row['monitorip']) {
+ if(!in_array($row['monitorip'], $processed)) {
+ fwrite($fd, $ip . "|" . $row['monitorip'] . "|1|/usr/local/pkg/tinydns_down.php|/usr/local/pkg/tinydns_up.php|{$pingthreshold}\n");
+ $processed[] = $row['monitorip'];
+ }
+ } else {
+ if(!in_array($monitorip, $processed)) {
+ fwrite($fd, $ip . "|" . $monitorip . "|1|/usr/local/pkg/tinydns_down.php|/usr/local/pkg/tinydns_up.php|{$pingthreshold}\n");
+ $processed[] = $monitorip;
+ }
+ }
+ }
+ }
+ if($domain['monitorip']) {
+ if(!in_array($domain['monitorip'], $processed)) {
+ fwrite($fd, $ip . "|" . $domain['monitorip'] . "|1|/usr/local/pkg/tinydns_down.php|/usr/local/pkg/tinydns_up.php|{$pingthreshold}\n");
+ $processed[] = $domain['monitorip'];
+ }
+ } else {
+ if(!in_array($row['failoverip'], $processed)) {
+ fwrite($fd, $ip . "|" . $row['failoverip'] . "|1|/usr/local/pkg/tinydns_down.php|/usr/local/pkg/tinydns_up.php|{$pingthreshold}\n");
+ $processed[] = $row['failoverip'];
+ }
+ }
+ }
+ fclose($fd);
+ config_unlock();
+ conf_mount_ro();
+}
+
+function tinydns_create_zone_file() {
+ global $g, $config;
+ conf_mount_rw();
+ if(file_exists("/tmp/config.cache"))
+ unlink("/tmp/config.cache");
+ parse_config(true);
+ config_lock();
+ if(file_exists("/service/tinydns/root/data"))
+ exec("rm -f /service/tinydns/root/data");
+ if(!is_dir("/service/tinydns/root"))
+ return;
+ $fd = fopen("/service/tinydns/root/data", "w");
+ if(!$fd) {
+ log_error("Could not open /service/tinydns/root/data for writing.");
+ return;
+ }
+
+ /* For now do not allow registration of 'local' DNS data if tinyDNS not bound to 127.0.0.1 */
+ if($config['installedpackages']['tinydns']['config'][0]['ipaddress'] == "127.0.0.1") {
+ /* Load the root servers if Forwarding is enabled */
+ /* Register LAN IP and SOA Forward and Reverse DNS recors in TinyDNS Server*/
+ if($config['installedpackages']['tinydns']['config'][0]['enableforwarding']) {
+ $forwardingservers = tinydns_register_root_servers();
+ if($forwardingservers)
+ fwrite($fd, $forwardingservers);
+ if($config['system']['hostname']['domain']) {
+ $dhcpdhostname = $config['system']['hostname'];
+ if($config['dhcpd']['lan'])
+ $dhcpddomain = $config['system']['domain'];
+ $dhcpdlanip = $config['interfaces']['lan']['ipaddr'];
+ $dhcpdipmask = $config['interfaces']['lan']['subnet'];
+ $dhcpdfqdn = "{$dhcpdhostname}.{$dhcpddomain}";
+ tinydns_complete_soa_record($fd, $dhcpdlanip, $dhcpdipmask, $dhcpdhostname, $dhcpddomain);
+ }
+ }
+
+ /* Register Static IPs */
+ if($config['installedpackages']['tinydns']['config'][0]['regdhcpstatic']) {
+ foreach($config['dhcpd'] as $zone_key => $zone ) {
+ $dhcpdhostname = $config['system']['hostname'];
+ if ($zone['ddnsdomain'])
+ $dhcpddomain = $zone['ddnsdomain'];
+ else
+ $dhcpddomain = $config['system']['domain'];
+ $dhcpdlanip = $config['interfaces'][$zone_key]['ipaddr'];
+ $dhcpdipmask = $config['interfaces'][$zone_key]['subnet'];
+ $dhcpdfqdn = "{$dhcpdhostname}.{$dhcpddomain}";
+ tinydns_complete_soa_record($fd, $dhcpdlanip, $dhcpdipmask, $dhcpdhostname, $dhcpddomain);
+
+ if(is_array($zone['staticmap'])) {
+ foreach($zone['staticmap'] as $dhcpdstatic) {
+ $dhcpdhostname = $dhcpdstatic['hostname'];
+ $dhcpdfqdn = "{$dhcpdhostname}.{$dhcpddomain}";
+ $dhcpdlanip = $dhcpdstatic['ipaddr'];
+ $dhcpda = "={$dhcpdfqdn}:{$dhcpdlanip}";
+ if($dhcpdhostname)
+ fwrite($fd, $dhcpda . "\n");
+ }
+ }
+ }
+ }
+
+ /* Register Dynamic IPs */
+ if($config['installedpackages']['tinydns']['config'][0]['regdhcp']) {
+ $leasesfile = "{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases";
+ $fl = fopen($leasesfile, "r");
+ if(!$fl) {
+ log_error("Could not open {$leasesfile} for reading.");
+ return;
+ }
+ tinydns_add_active_leases($fl,$fd, $dhcpddomain);
+ }
+ }
+
+ if($config['installedpackages']['tinydnsdomains']) {
+ for($x=0; $x< count($config['installedpackages']['tinydnsdomains']['config']); $x++) {
+ $domain = $config['installedpackages']['tinydnsdomains']['config'][$x];
+ $record_data = "";
+ $hostname = $domain['hostname'];
+ $ipaddress = $domain['ipaddress'];
+ $ttl = $domain['ttl'];
+ /* check record status, if it is down request
+ * backup server if defined.
+ */
+ if($domain['monitorip'])
+ $monitorip = $domain['monitorip'];
+ if($monitorip) {
+ $status = tinydns_get_record_status($monitorip);
+ if($status == "DOWN") {
+ if($debug)
+ log_error("$ipaddress monitor ip $monitorip is offline.");
+ $ipaddress = tinydns_get_backup_record($ipaddress);
+ if($debug)
+ log_error("tinydns_get_backup_record returned $ipaddress ");
+ }
+ }
+ $record_data = tinydns_get_rowline_data($ipaddress, $domain['recordtype'], $ttl, $hostname, $domain['rdns']);
+ if($record_data)
+ fwrite($fd, $record_data . "\n");
+ /* process load balanced items */
+ if($domain['row']) {
+ foreach($domain['row'] as $row) {
+ if($row['loadbalance']) {
+ if($row['pingthreshold'])
+ $pingthreshold = $row['pingthreshold'];
+ else
+ $pingthreshold = "";
+ if($row['wanpingthreshold'])
+ $wanpingthreshold = $row['wanpingthreshold'];
+ else
+ $wanpingthreshold = "";
+ $status = tinydns_get_record_status($row['failoverip'], $pingthreshold, $wanpingthreshold);
+ if($status == "DOWN") {
+ $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");
+ config_unlock();
+ conf_mount_ro();
+}
+
+function tinydns_sync_on_changes() {
+ global $g, $config;
+ $synconchanges = $config['installedpackages']['tinydnssync']['config'][0]['synconchanges'];
+ if(!$synconchanges)
+ return;
+ $sync_hosts = $config['installedpackages']['tinydnssync']['config'];
+ foreach($sync_hosts as $sh) {
+ $sync_to_ip = $sh['ipaddress'];
+ $password = $sh['password'];
+ if($password and $sync_to_ip)
+ tinydns_do_xmlrpc_sync($sync_to_ip, $password);
+ }
+}
+
+function tinydns_do_xmlrpc_sync($sync_to_ip, $password) {
+ global $config, $g;
+
+ if(!$password)
+ return;
+
+ if(!$sync_to_ip)
+ return;
+
+ $xmlrpc_sync_neighbor = $sync_to_ip;
+ if($config['system']['webgui']['protocol'] != "") {
+ $synchronizetoip = $config['system']['webgui']['protocol'];
+ $synchronizetoip .= "://";
+ }
+ $port = $config['system']['webgui']['port'];
+ /* if port is empty lets rely on the protocol selection */
+ if($port == "") {
+ if($config['system']['webgui']['protocol'] == "http")
+ $port = "80";
+ else
+ $port = "443";
+ }
+ $synchronizetoip .= $sync_to_ip;
+
+ /* xml will hold the sections to sync */
+ $xml = array();
+ $xml['tinydnsdomains'] = $config['installedpackages']['tinydnsdomains'];
+
+ /* assemble xmlrpc payload */
+ $params = array(
+ XML_RPC_encode($password),
+ XML_RPC_encode($xml)
+ );
+
+ /* set a few variables needed for sync code borrowed from filter.inc */
+ $url = $synchronizetoip;
+ log_error("Beginning TinyDNS XMLRPC sync to {$url}:{$port}.");
+ $method = 'pfsense.merge_installedpackages_section_xmlrpc';
+ $msg = new XML_RPC_Message($method, $params);
+ $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
+ $cli->setCredentials('admin', $password);
+ if($g['debug'])
+ $cli->setDebug(1);
+ /* send our XMLRPC message and timeout after 250 seconds */
+ $resp = $cli->send($msg, "250");
+ if(!$resp) {
+ $error = "A communications error occured while attempting tinydns XMLRPC sync with {$url}:{$port}.";
+ log_error($error);
+ file_notice("sync_settings", $error, "tinydns Settings Sync", "");
+ } elseif($resp->faultCode()) {
+ $cli->setDebug(1);
+ $resp = $cli->send($msg, "250");
+ $error = "An error code was received while attempting tinydns XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
+ log_error($error);
+ file_notice("sync_settings", $error, "tinydns Settings Sync", "");
+ } else {
+ log_error("tinydns XMLRPC sync successfully completed with {$url}:{$port}.");
+ }
+
+ /* tell tinydns to reload our settings on the destionation sync host. */
+ $method = 'pfsense.exec_php';
+ $execcmd = "require('/usr/local/pkg/tinydns.inc');\n";
+ $execcmd .= "tinydns_custom_php_changeip_command();\n";
+ $execcmd .= "tinydns_custom_php_install_command();\n";
+ $execcmd .= "tinydns_create_zone_file();\n";
+ $execcmd .= "tinydns_setup_ping_items();\n";
+
+ /* assemble xmlrpc payload */
+ $params = array(
+ XML_RPC_encode($password),
+ XML_RPC_encode($execcmd)
+ );
+
+ $msg = new XML_RPC_Message($method, $params);
+ $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
+ $cli->setCredentials('admin', $password);
+ $resp = $cli->send($msg, "250");
+ if(!$resp) {
+ $error = "A communications error occured while attempting tinydns XMLRPC sync with {$url}:{$port} (pfsense.exec_php).";
+ log_error($error);
+ file_notice("sync_settings", $error, "tinydns Settings Sync", "");
+ } elseif($resp->faultCode()) {
+ $cli->setDebug(1);
+ $resp = $cli->send($msg, "250");
+ $error = "An error code was received while attempting tinydns XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
+ log_error($error);
+ file_notice("sync_settings", $error, "tinydns Settings Sync", "");
+ } else {
+ log_error("tinydns XMLRPC sync successfully completed with {$url}:{$port} (pfsense.exec_php).");
+ }
+
+ log_error("[tinydns] tinydns_xmlrpc_sync.php is ending.");
+}
+
+/* formats data as a tinydns data row item */
+/* A full description of the data format is available at 'man tinydns-data' */
+function tinydns_get_rowline_data($recordip, $recordtype, $ttl, $hostname, $rdns) {
+ if($ttl)
+ $ttl_string = ":{$ttl}";
+ else
+ $ttl_string = "";
+ switch ($recordtype) {
+ case "SOA":
+ $record_data = ".{$hostname}::{$recordip}{$ttl_string}";
+ break;
+ case "NS":
+ $record_data = "&{$hostname}:{$recordip}{$ttl_string}";
+ break;
+ case "MX":
+ $record_data = "@{$hostname}:{$recordip}::{$ttl_string}";
+ break;
+ case "PTR":
+ /* "^" creates "PTR" record only to allow reverse DNS */
+ $record_data = "^{$hostname}:{$recordip}{$ttl_string}";
+ break;
+ case "A":
+ /* "=" creates both "A" and "PTR" records to allow both forward and reverse DNS */
+ if($rdns)
+ $record_data = "={$hostname}:{$recordip}{$ttl_string}";
+ else
+ /* "+" creates "A" records only to allow forward DNS */
+ $record_data = "+{$hostname}:{$recordip}{$ttl_string}";
+ break;
+ case "CNAME":
+ $record_data = "C{$hostname}:{$recordip}{$ttl_string}";
+ break;
+ case "TXT":
+ /* "'" creates "TXT" record that can be used for SPF */
+ $record_data = "'{$hostname}:{$recordip}{$ttl_string}";
+ break;
+ }
+ return $record_data;
+}
+
+/* Returns the last IP byte and the Trimmed IP*/
+function tinydns_get_lastip_byte($ipsub) {
+ $len= strlen($ipsub);
+ $pos = strrpos($ipsub, ".");
+ $last_byte = "";
+ if ($pos === false) {
+ $last_byte = $ipsub;
+ return array ($last_byte,$ipsub);
+ }
+ $last_byte = substr($ipsub,$pos + 1);
+ $ipsub = substr($ipsub,0,$pos);
+ return array ($last_byte,$ipsub);
+}
+
+/* in-add.arpa IP calculated from D.C.B.A and Mask to A.B.C.D.in-addr.arpa */
+/* subnet IP calculated from A.B.C.D and Mask */
+function tinydns_get_ip_subnet_arpa($ip, $ipmask) {
+ $ipsub = $ip;
+ $arpaip = "";
+ $array = tinydns_get_lastip_byte($ipsub);
+ $a = $array[0];
+ $ipsub = $array[1];
+ $array = tinydns_get_lastip_byte($ipsub);
+ $b = $array[0];
+ $ipsub = $array[1];
+ $array = tinydns_get_lastip_byte($ipsub);
+ $c = $array[0];
+ $ipsub = $array[1];
+ $array = tinydns_get_lastip_byte($ipsub);
+ $d = $array[0];
+ $ipsub = $array[1];
+ switch ($ipmask) {
+ case ($ipmask <= 32 AND $ipmask > 24):
+ $s = 32 - $ipmask;
+ $a >> $s;
+ $arpaip = "{$a}.{$b}.{$c}.{$d}.in-addr.arpa";
+ $subnet = "{$d}.{$c}.{$b}.{$a}";
+ break;
+ case ($ipmask <= 24 AND $ipmask > 16):
+ $s = 24 - $ipmask;
+ $b >> $s;
+ $arpaip = "{$b}.{$c}.{$d}.in-addr.arpa";
+ $subnet = "{$d}.{$c}.{$b}";
+ break;
+ case ($ipmask <= 16 AND $ipmask > 8):
+ $s = 16 - $ipmask;
+ $c >> $s;
+ $arpaip = "{$c}.{$d}.in-addr.arpa";
+ $subnet = "{$d}.{$c}";
+ break;
+ case ($ipmask <= 8 AND $ipmask > 0):
+ $s = 8 - $ipmask;
+ $d >> $s;
+ $arpaip = "{$d}.in-addr.arpa";
+ $subnet = "{$d}";
+ break;
+ }
+ return array($subnet,$arpaip);
+}
+
+/* Create a Forward and a Reverse DNS (SOA, A, PTR) records for Fully Qualififed Domain Name*/
+function tinydns_complete_soa_record($fd, $ip, $ipmask, $nsname, $domain) {
+ $fqdn = "{$nsname}.{$domain}";
+ $rip = tinydns_get_ip_subnet_arpa($ip, $ipmask);
+ $soa = ".{$domain}::{$fqdn}";
+ $rsoa = ".{$rip[1]}::{$fqdn}";
+ $a = "={$fqdn}:{$ip}";
+ if($fqdn)
+ fwrite($fd, $soa . "\n");
+ if($rip)
+ fwrite($fd, $rsoa . "\n");
+ if($nsname)
+ fwrite($fd, $a . "\n");
+}
+
+/* Search for active leases in the dhcpd.leases file and add them to tinyDNS */
+/* Currently it will add duplicate leases that are ignored by thee tinyDNS server*/
+/* Should duplicate leases be purged by DCHCP server in a remove stale records operation? */
+function tinydns_add_active_leases($fl,$fd, $leasedomain) {
+ $i = 0;
+ $lip = strlen("lease") + 1;
+ $lis = strlen("binding state active");
+ $lic = strlen("client-hostname");
+ $leaseip = "";
+ $leasestatus = "";
+ $leasehostname = "";
+ while (!feof($fl)) {
+ $leases = fgets($fl, 4096);
+ $discard = ($leases[0] == "#") OR ($leases[0] == "\n");
+ if(!$discard) {
+ if($leaseip == "") {
+ if ($leaseip = strstr($leases,"lease")) {
+ $leaseip = substr($leaseip,$lip,strpos($leases,"{") - $lip - 1);
+ }
+ }
+ elseif($leasestatus == FALSE) {
+ if (stristr($leases,"binding state active")) {
+ $leasestatus = TRUE;
+ }
+ }
+ elseif($leasestatus == TRUE AND $leasehostname == "") {
+ if($leasehostname = stristr($leases,"client-hostname")) {
+ $qstrt = strpos($leasehostname,'"') + 1;
+ $qlen = strrpos($leasehostname,'"') - $qstrt;
+ $leasehostname = substr($leasehostname,$qstrt,$qlen);
+ }
+ }
+ if($leases[0] == "}") {
+ $leasefqdn = "{$leasehostname}.{$leasedomain}";
+ $leasea = "={$leasefqdn}:{$leaseip}";
+ if($leasehostname AND $leasestatus)fwrite($fd, $leasea . "\n");
+ $leaseip = "";
+ $leasehostname = "";
+ $leasestatus = FALSE;
+ }
+ $i = $i + 1;
+ }
+ }
+ fclose($fl);
+ $leaselines = $i;
+}
+
+function tinydns_get_dns_record_type($tinydnsrecord) {
+ $rtype = "";
+ $rtype2 = "";
+ $rdns = "";
+ switch ($tinydnsrecord) {
+ case($tinydnsrecord[0] == "."):
+ $rtype = "SOA";
+ $rtype2 = "NS";
+ break;
+ case($tinydnsrecord[0] == "="):
+ $rtype = "A";
+ $rtype2 = "PTR";
+ $rdns = "on";
+ break;
+ case($tinydnsrecord[0] == "+"):
+ $rtype = "A";
+ break;
+ case($tinydnsrecord[0] == "@"):
+ $rtype = "MX";
+ break;
+ case($tinydnsrecord[0] == "^"):
+ $rtype = "PTR";
+ $rdns = "on";
+ break;
+ case($tinydnsrecord[0] == "&"):
+ $rtype = "NS";
+ break;
+ case($tinydnsrecord[0] == "'"):
+ $rtype = "TXT";
+ break;
+ case($tinydnsrecord[0] == "C"):
+ $rtype = "CNAME";
+ break;
+ case($tinydnsrecord[0] == "Z"):
+ $rtype = "SOA";
+ break;
+ default:
+ $rtype = "";
+ }
+ return array ($rtype, $rtype2, $rdns);
+}
+
+/* This function will be replaced by an auto detect DNS cache servers routine */
+/* At the moment there is no tagging of DNSroute to a WAN port. It needs to be added */
+function tinydns_dnscache_forwarding_servers() {
+ $fr = fopen("/var/etc/resolv.conf.dnscache", "r");
+ if (! $fr) {
+ printf("Error: cannot open resolv.conf.dnscache in tinydns_register_forwarding_servers().\n");
+ return 1;
+ }
+
+ $lip = strlen("nameserver") + 1;
+ $j = 0;
+ $iprecords = "";
+ while (!feof($fr)) {
+ $routers = fgets($fr, 4096);
+ $discard = ($routers[0] == "\n");
+ if(!$discard) {
+ if ($routerip = strstr($routers,"nameserver")) {
+ $routerip = substr($routerip,$lip);
+ if($routerip) {
+ $j += 1;
+ $routera = "{$routerip}";
+ $iprecords .= $routera;
+ }
+ }
+ }
+ }
+ fclose($fr);
+ exec("echo 1 > /etc/dnscache/env/FORWARDONLY");
+ if(is_dir("/etc/dnscache/root/servers/"))
+ exec("rm -R /etc/dnscache/root/servers/");
+ exec("mkdir /etc/dnscache/root/servers/");
+ $fr = fopen("/etc/dnscache/root/servers/@", "w");
+ if (! $fr) {
+ printf("Error: cannot write to /etc/dnscache/root/servers/@ in tinydns_dnscache_forwarding_servers().\n");
+ return 1;
+ }
+ if($iprecords)
+ fwrite($fr, $iprecords);
+ fclose($fr);
+}
+
+/* This routine adds filenames to /etc/dnscache/root/servers/ with the contents pointing to the tinyDNS server */
+function tinydns_create_soa_domain_list($dnsserverip) {
+ if(file_exists("/service/tinydns/root/data"))
+ $tinydns_data = file_get_contents("/service/tinydns/root/data");
+ else
+ $tinydns_data = "";
+
+ $datalen = strlen($tinydns_data);
+ $startofrecord = 0;
+ while ($startofrecord < $datalen ) {
+ $endofrecord = strpos($tinydns_data,"\n",$startofrecord);
+ $dnsrecord = substr($tinydns_data,$startofrecord,$endofrecord-$startofrecord);
+ $startofrecord = $endofrecord + 1;
+
+ $col1 = strpos($dnsrecord,":");
+ $fqdn = substr($dnsrecord,1,$col1-1);
+ if($fqdn) {
+ $rtypes = tinydns_get_dns_record_type($dnsrecord);
+ if($rtypes[0] == "SOA") {
+ $fr = fopen("/etc/dnscache/root/servers/{$fqdn}", "w");
+ if (! $fr) {
+ printf("Error: cannot open /etc/dnscache/root/servers/{$fqdn} in tinydns_create_soa_domain_list().\n");
+ return 1;
+ }
+ if($fqdn)fwrite($fr, $dnsserverip);
+ fclose($fr);
+ }
+ }
+ }
+}
+
+/* This function is not called */
+/* At the moment there is no tagging of DNSroute to a WAN port. It needs to be added */
+function tinydns_register_forwarding_servers() {
+ $fr = fopen("/var/etc/resolv.conf", "r");
+ if (! $fr) {
+ printf("Error: cannot open resolv.conf in tinydns_register_forwarding_servers().\n");
+ return 1;
+ }
+
+ $lip = strlen("nameserver") + 1;
+ $j = 0;
+ $nsrecords = "";
+ $arecords = "";
+ while (!feof($fr)) {
+ $routers = fgets($fr, 4096);
+ $discard = ($routers[0] == "\n");
+ if(!$discard) {
+ if ($routerip = strstr($routers,"nameserver")) {
+ $routerip = substr($routerip,$lip);
+ if($routerip) {
+ $j += 1;
+ $routerfqdn = "DNSroute-{$j}.wan{$j}";
+ $routerns = "&::{$routerfqdn}";
+ $routera = "={$routerfqdn}:{$routerip}";
+ $nsrecords .= $routerns . "\n";
+ $arecords .= $routera;
+ }
+ }
+ }
+ }
+ fclose($fr);
+ $dnsroutes ="{$nsrecords}{$arecords}";
+ return $dnsroutes;
+}
+
+function tinydns_register_root_servers() {
+ $rootservers =<<<EOD
+&::a.root-servers.net
+&::b.root-servers.net
+&::c.root-servers.net
+&::d.root-servers.net
+&::e.root-servers.net
+&::f.root-servers.net
+&::g.root-servers.net
+&::h.root-servers.net
+&::i.root-servers.net
+&::j.root-servers.net
+&::k.root-servers.net
+&::l.root-servers.net
+&::m.root-servers.net
+=a.root-servers.net:198.41.0.4
+=b.root-servers.net:128.9.0.107
+=c.root-servers.net:192.33.4.12
+=d.root-servers.net:128.8.10.90
+=e.root-servers.net:192.203.230.10
+=f.root-servers.net:192.5.5.241
+=g.root-servers.net:192.112.36.4
+=h.root-servers.net:128.63.2.53
+=i.root-servers.net:192.36.148.17
+=j.root-servers.net:192.58.128.30
+=k.root-servers.net:193.0.14.129
+=l.root-servers.net:199.7.83.42
+=m.root-servers.net:202.12.27.33
+
+EOD;
+ return $rootservers;
+}
+
+function dnscache_use_root_servers() {
+ $rootservers =<<<EOD
+198.41.0.4
+128.9.0.107
+192.33.4.12
+128.8.10.90
+192.203.230.10
+192.5.5.241
+192.112.36.4
+128.63.2.53
+192.36.148.17
+192.58.128.30
+193.0.14.129
+199.7.83.42
+202.12.27.33
+
+EOD;
+
+ exec("echo 0 > /etc/dnscache/env/FORWARDONLY");
+ if(is_dir("/etc/dnscache/root/servers/"))
+ exec("rm -R /etc/dnscache/root/servers/");
+ exec("mkdir /etc/dnscache/root/servers/");
+ $fr = fopen("/etc/dnscache/root/servers/@", "w");
+ if (! $fr) {
+ printf("Error: cannot write to /etc/dnscache/root/servers/@ in dnscache_use_root_servers().\n");
+ return 1;
+ }
+ fwrite($fr, $rootservers);
+ fclose($fr);
+}
+
+?> \ No newline at end of file
diff --git a/config/tinydns/tinydns.xml b/config/tinydns/tinydns.xml
new file mode 100644
index 00000000..fc1c3482
--- /dev/null
+++ b/config/tinydns/tinydns.xml
@@ -0,0 +1,309 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE packagegui SYSTEM "../schema/packages.dtd">
+<?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?>
+<packagegui>
+ <copyright>
+ <![CDATA[
+/* $Id$ */
+/* ========================================================================== */
+/*
+ authng.xml
+ part of pfSense (http://www.pfSense.com)
+ Copyright (C) 2007 to whom it may belong
+ All rights reserved.
+
+ Based on m0n0wall (http://m0n0.ch/wall)
+ Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
+ All rights reserved.
+ */
+/* ========================================================================== */
+/*
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+/* ========================================================================== */
+ ]]>
+ </copyright>
+ <description>Describe your package here</description>
+ <requirements>Describe your package requirements here</requirements>
+ <faq>Currently there are no FAQ items provided.</faq>
+ <name>tinydns</name>
+ <version>1.0</version>
+ <title>DNS Server: Settings</title>
+ <aftersaveredirect>/pkg_edit.php?xml=tinydns.xml&amp;id=0</aftersaveredirect>
+ <include_file>/usr/local/pkg/tinydns.inc</include_file>
+ <menu>
+ <name>DNS Servers</name>
+ <tooltiptext></tooltiptext>
+ <section>Services</section>
+ <url>/tinydns_status.php</url>
+ </menu>
+ <service>
+ <name>DNS Server</name>
+ <rcfile>svscan.sh</rcfile>
+ <executable>tinydns</executable>
+ <description>TinyDNS DNS Server</description>
+ </service>
+ <tabs>
+ <tab>
+ <text>Settings</text>
+ <url>/pkg_edit.php?xml=tinydns.xml&amp;id=0</url>
+ <active/>
+ </tab>
+ <tab>
+ <text>Add/Edit Record</text>
+ <url>/tinydns_filter.php</url>
+ </tab>
+ <tab>
+ <text>Failover Status</text>
+ <url>/tinydns_status.php</url>
+ </tab>
+ <tab>
+ <text>Logs</text>
+ <url>/tinydns_view_logs.php</url>
+ </tab>
+ <tab>
+ <text>Zone Sync</text>
+ <url>/pkg_edit.php?xml=tinydns_sync.xml&amp;id=0</url>
+ </tab>
+ <tab>
+ <text>New domain wizard</text>
+ <url>/wizard.php?xml=new_zone_wizard.xml</url>
+ </tab>
+ </tabs>
+ <configpath>installedpackages->package->tinydns</configpath>
+ <additional_files_needed>
+ <prefix>/usr/local/pkg/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns.inc</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/pkg/pf/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns_xmlrpc_sync.php</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/pkg/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns_domains.xml</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/www/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns_status.php</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/www/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns_dhcp_filter.php</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/www/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns_filter.php</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/pkg/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns_down.php</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/pkg/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns_up.php</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/pkg/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns_parse_logs.php</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/www/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns_view_logs.php</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/pkg/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/tinydns_sync.xml</item>
+ </additional_files_needed>
+ <additional_files_needed>
+ <prefix>/usr/local/www/wizards/</prefix>
+ <chmod>077</chmod>
+ <item>http://www.pfsense.com/packages/config/tinydns/new_zone_wizard.xml</item>
+ </additional_files_needed>
+ <fields>
+ <field>
+ <type>listtopic</type>
+ <name>Binding IP Address</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>IP Address</fielddescr>
+ <fieldname>ipaddress</fieldname>
+ <description>Bind TinyDNS to this IP address. Enable DNS Forwarders bind TinyDNS to the LAN IP.</description>
+ <type>input</type>
+ </field>
+ <field>
+ <type>listtopic</type>
+ <name>DNS-Cache server</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>Enable DNS Forwarders</fielddescr>
+ <fieldname>enableforwarding</fieldname>
+ <description>Enable DNScache forwarder on LAN IP and register LAN's SOA, NS, A, and PTR Records with TinyDNS Server.</description>
+ <type>checkbox</type>
+ </field>
+ <field>
+ <fielddescr>Register DHCP static mappings with server</fielddescr>
+ <fieldname>regdhcpstatic</fieldname>
+ <description>Register static DHCP leases with TinyDNS server using the Fully Qualified Domain Name specified in System: General.</description>
+ <type>checkbox</type>
+ </field>
+ <field>
+ <fielddescr>Register DHCP leases with server</fielddescr>
+ <fieldname>regdhcp</fieldname>
+ <description>Register active DHCP leases with TinyDNS server using the Fully Qualified Domain Name specified in System: General.</description>
+ <type>checkbox</type>
+ </field>
+ <field>
+ <type>listtopic</type>
+ <name>Monitoring address refresh interval</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>Refresh Interval</fielddescr>
+ <fieldname>refreshinterval</fieldname>
+ <description>Controls how often the monitoring ip adresses are polled</description>
+ <type>input</type>
+ </field>
+ <field>
+ <type>listtopic</type>
+ <name>Sync TinyDNS settings via XMLRPC</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>XMLRPC Sync</fielddescr>
+ <fieldname>syncxmlrpc</fieldname>
+ <description>Sync TinyDNS configuration to backup firewalls</description>
+ <type>checkbox</type>
+ </field>
+ <field>
+ <type>listtopic</type>
+ <name>Zone transfers</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>Hosts allowed to perform DNS Zone Transfers - Note: this requires TCP port 53 firewall permit rule!</fielddescr>
+ <fieldname>none</fieldname>
+ <type>rowhelper</type>
+ <rowhelper>
+ <rowhelperfield>
+ <fielddescr>IP Address</fielddescr>
+ <fieldname>ztipaddress</fieldname>
+ <description>Enter the IP Address that is allowed to transfer zone records (ex: 4.2.2.1)</description>
+ <type>input</type>
+ <size>20</size>
+ </rowhelperfield>
+ <rowhelperfield>
+ <fielddescr>DNS Zone - Use * for all Zones</fielddescr>
+ <fieldname>dnszone</fieldname>
+ <description>Enter the DNS zone that this IP address is allowed to transfer (ex: domain.com)</description>
+ <type>input</type>
+ <size>20</size>
+ </rowhelperfield>
+ </rowhelper>
+ </field>
+ <field>
+ <type>listtopic</type>
+ <name>Advanced tunables (OPTIONAL)</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>Minimum segment size</fielddescr>
+ <fieldname>minsegment</fieldname>
+ <description>Recommended size: 10240 or larger.</description>
+ <type>input</type>
+ <value>10240</value>
+ </field>
+ <field>
+ <fielddescr>Maximum file size</fielddescr>
+ <fieldname>maxfilesize</fieldname>
+ <description>Recommended size: 10240 or larger.</description>
+ <type>input</type>
+ <value>10240</value>
+ </field>
+ <field>
+ <fielddescr>Max Segment size</fielddescr>
+ <fieldname>maxsegment</fieldname>
+ <description>Recommended size: 20480 or larger.</description>
+ <type>input</type>
+ <value>20480</value>
+ </field>
+ <field>
+ <fielddescr>Maximum file descriptors</fielddescr>
+ <fieldname>maxfd</fieldname>
+ <description>Recommended size: 100 or larger.</description>
+ <type>input</type>
+ <value>100</value>
+ </field>
+ <field>
+ <fielddescr>Maximum children processes</fielddescr>
+ <fieldname>maxchild</fieldname>
+ <description>Recommended size: 40 or larger.</description>
+ <type>input</type>
+ <value>40</value>
+ </field>
+ </fields>
+ <custom_delete_php_command>
+ tinydns_custom_php_changeip_command();
+ tinydns_custom_php_install_command();
+ tinydns_create_zone_file();
+ tinydns_setup_ping_items();
+ tinydns_sync_on_changes();
+ </custom_delete_php_command>
+ <custom_add_php_command>
+ tinydns_custom_php_changeip_command();
+ tinydns_custom_php_install_command();
+ tinydns_create_zone_file();
+ tinydns_setup_ping_items();
+ tinydns_sync_on_changes();
+ </custom_add_php_command>
+ <custom_php_resync_config_command>
+ tinydns_custom_php_changeip_command();
+ tinydns_custom_php_install_command();
+ tinydns_create_zone_file();
+ tinydns_setup_ping_items();
+ tinydns_sync_on_changes();
+ </custom_php_resync_config_command>
+ <custom_php_install_command>
+ tinydns_custom_php_install_command();
+ tinydns_sync_on_changes();
+ </custom_php_install_command>
+ <custom_php_deinstall_command>
+ tinydns_custom_php_deinstall_command();
+ tinydns_sync_on_changes();
+ </custom_php_deinstall_command>
+ <custom_php_command_before_form>
+ unset($_POST['temp']);
+ </custom_php_command_before_form>
+</packagegui> \ No newline at end of file
diff --git a/config/tinydns/tinydns_dhcp_filter.php b/config/tinydns/tinydns_dhcp_filter.php
new file mode 100644
index 00000000..c92abcf8
--- /dev/null
+++ b/config/tinydns/tinydns_dhcp_filter.php
@@ -0,0 +1,129 @@
+<?php
+/* $Id$ */
+/*
+ tinydns_dhcp_filter.php
+ Copyright (C) 2006 Scott Ullrich
+ Parts Copyright (C) 2007 Goffredo Andreone <GAndreone@imapro.com>
+ part of pfSense
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+##|+PRIV
+##|*IDENT=page-tinydns-dhcp-filter
+##|*NAME=TinyDNS: DHCP Domains
+##|*DESCR=Allow access to the TinyDNS View Domains page
+##|*MATCH=tinydns_dhcp_filter*
+##|-PRIV
+
+require("/usr/local/pkg/tinydns.inc");
+require("guiconfig.inc");
+
+$pgtitle = "TinyDNS: DHCP Domains";
+include("head.inc");
+
+$pfSversion = str_replace("\n", "", file_get_contents("/etc/version"));
+if(strstr($pfSversion, "1.2"))
+ $one_two = true;
+
+?>
+<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
+<?php include("fbegin.inc"); ?>
+
+<?php if($one_two): ?>
+<p class="pgtitle"><?=$pgtitle?></font></p>
+<?php endif; ?>
+
+<?php if ($savemsg) print_info_box($savemsg); ?>
+
+<div id="mainlevel">
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+<?php
+ $tab_array = array();
+ $tab_array[] = array(gettext("Settings"), false, "/pkg_edit.php?xml=tinydns.xml&id=0");
+ $tab_array[] = array(gettext("Add/Edit Record"), false, "/tinydns_filter.php");
+ $tab_array[] = array(gettext("Failover Status"), false, "/tinydns_status.php");
+ $tab_array[] = array(gettext("Logs"), false, "/tinydns_view_logs.php");
+ $tab_array[] = array(gettext("Zone Sync"), false, "/tinydns_xmlrpc_sync.php");
+ $tab_array[] = array(gettext("New domain wizard"), false, "/wizard.php?xml=new_zone_wizard.xml");
+ display_top_tabs($tab_array);
+?>
+</table>
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td class="tabcont" >
+ <form action="tinydns_dhcp_filter.php" method="post">
+ </form>
+ </td>
+ </tr>
+ <tr>
+ <td class="tabcont" >
+ <table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td width="45%" class="listhdrr">Fully Qualified Domain Name (Hostname)</td>
+ <td width="15%" class="listhdrr">Record types</td>
+ <td width="5%" class="listhdrr">rDNS</td>
+ <td width="35%" class="listhdrr">IP Address or FQDN</td>
+ </tr>
+
+<?php
+if(file_exists("/service/tinydns/root/data"))
+ $tinydns_data = file_get_contents("/service/tinydns/root/data");
+else
+ $tinydns_data = "";
+
+$datalen = strlen($tinydns_data);
+$startofrecord = 0;
+while ($startofrecord < $datalen ){
+ $endofrecord = strpos($tinydns_data,"\n",$startofrecord);
+ $dnsrecord = substr($tinydns_data,$startofrecord,$endofrecord-$startofrecord);
+ $startofrecord = $endofrecord + 1;
+
+ $col1 = strpos($dnsrecord,":");
+ $fqdn = substr($dnsrecord,1,$col1-1);
+ $rtypes = tinydns_get_dns_record_type($dnsrecord);
+ if($rtypes[0] == "SOA")
+ $ip = substr($dnsrecord,$col1+2);
+ else
+ $ip = substr($dnsrecord,$col1+1);
+ /* For root-servers get rid of the leading colon */
+ if($ip[0] == ":")$ip = substr($ip,1);
+ if(!$rtypes[2])$rtypes[2] = "na";
+ if(!$fqdn)$fqdn = ".";
+ echo "<tr>";
+ echo "<td class=\"listlr\">$fqdn</td>";
+ echo "<td class=\"listlr\">$rtypes[0] $rtypes[1]</td>";
+ echo "<td class=\"listlr\">$rtypes[2]</td>";
+ echo "<td class=\"listlr\">$ip</td>";
+ echo "</tr>";
+}
+?>
+ </table>
+ </td>
+ </tr>
+</table>
+</div>
+<?php include("fend.inc"); ?>
+<meta http-equiv="refresh" content="60;url=<?php print $_SERVER['SCRIPT_NAME']; ?>">
+</body>
+</html>
diff --git a/config/tinydns/tinydns_domains.xml b/config/tinydns/tinydns_domains.xml
new file mode 100644
index 00000000..3e313511
--- /dev/null
+++ b/config/tinydns/tinydns_domains.xml
@@ -0,0 +1,234 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE packagegui SYSTEM "../schema/packages.dtd">
+<?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?>
+<packagegui>
+ <copyright>
+ <![CDATA[
+/* $Id$ */
+/* ========================================================================== */
+/*
+ tinydns_domains.xml
+ part of pfSense (http://www.pfSense.com)
+ Copyright (C) 2008 Scott Ullrich
+ All rights reserved.
+ */
+/* ========================================================================== */
+/*
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+/* ========================================================================== */
+ ]]>
+ </copyright>
+ <description>Describe your package here</description>
+ <requirements>Describe your package requirements here</requirements>
+ <faq>Currently there are no FAQ items provided.</faq>
+ <name>tinydnsdomains</name>
+ <version>none</version>
+ <title>TinyDNS: Domains</title>
+ <include_file>/usr/local/pkg/tinydns.inc</include_file>
+ <tabs>
+ <tab>
+ <text>Settings</text>
+ <url>/pkg_edit.php?xml=tinydns.xml&amp;id=0</url>
+ </tab>
+ <tab>
+ <text>Add/Edit Record</text>
+ <url>/tinydns_filter.php</url>
+ <active/>
+ </tab>
+ <tab>
+ <text>Failover Status</text>
+ <url>/tinydns_status.php</url>
+ </tab>
+ <tab>
+ <text>Logs</text>
+ <url>/tinydns_view_logs.php</url>
+ </tab>
+ <tab>
+ <text>Sync</text>
+ <url>/pkg_edit.php?xml=tinydns_sync.xml&amp;id=0</url>
+ </tab>
+ <tab>
+ <text>New domain wizard</text>
+ <url>/wizard.php?xml=new_zone_wizard.xml</url>
+ </tab>
+ </tabs>
+ <configpath>installedpackages->package->tinydnsdomains</configpath>
+ <adddeleteeditpagefields>
+ <columnitem>
+ <fielddescr>Fully Qualified Domain Name (Hostname)</fielddescr>
+ <fieldname>hostname</fieldname>
+ </columnitem>
+ <columnitem>
+ <fielddescr>Record type</fielddescr>
+ <fieldname>recordtype</fieldname>
+ </columnitem>
+ <columnitem>
+ <fielddescr>rDNS</fielddescr>
+ <fieldname>rdns</fieldname>
+ </columnitem>
+ <columnitem>
+ <fielddescr>IP Address</fielddescr>
+ <fieldname>ipaddress</fieldname>
+ </columnitem>
+ </adddeleteeditpagefields>
+ <fields>
+ <field>
+ <type>listtopic</type>
+ <name>General</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>Hostname or FQDN www.exampledomain.com</fielddescr>
+ <fieldname>hostname</fieldname>
+ <description>The DNS server will supply Records for the Fully Qualified Domain Name that is entered</description>
+ <type>input</type>
+ <size>35</size>
+ <required/>
+ </field>
+ <field>
+ <fielddescr>Record type</fielddescr>
+ <fieldname>recordtype</fieldname>
+ <description>DNS Record types. A, PTR, MX, NS, SOA, TXT, CNAME</description>
+ <type>select</type>
+ <size>1</size>
+ <required/>
+ <options>
+ <option><name></name><value></value></option>
+ <option><name>A</name><value>A</value></option>
+ <option><name>MX</name><value>MX</value></option>
+ <option><name>NS</name><value>NS</value></option>
+ <option><name>SOA</name><value>SOA</value></option>
+ <option><name>PTR</name><value>PTR</value></option>
+ <option><name>CNAME</name><value>CNAME</value></option>
+ <option><name>TXT</name><value>TXT</value></option>
+ </options>
+ </field>
+ <field>
+ <fielddescr> FQDN or IP Address</fielddescr>
+ <fieldname>ipaddress</fieldname>
+ <description>IP Address for A Records. FQDN or Hostname for SOA, PTR, CNAME Records. For NS Records an IP:FQDN</description>
+ <type>input</type>
+ <size>40</size>
+ <required/>
+ </field>
+ <field>
+ <fielddescr>DNS record time to live</fielddescr>
+ <fieldname>ttl</fieldname>
+ <type>input</type>
+ <size>35</size>
+ </field>
+ <field>
+ <type>listtopic</type>
+ <name>Reverse lookup</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>Automatic PTR entry</fielddescr>
+ <fieldname>rdns</fieldname>
+ <description>Create a reverse DNS (PTR) entry for this A Record?</description>
+ <type>checkbox</type>
+ </field>
+ <field>
+ <type>listtopic</type>
+ <name>Failover</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>IP to ping to ensure service is up</fielddescr>
+ <fieldname>monitorip</fieldname>
+ <type>input</type>
+ <size>35</size>
+ </field>
+ <field>
+ <fielddescr>Time in minutes before DNS switches to backup host</fielddescr>
+ <fieldname>threshhold</fieldname>
+ <type>input</type>
+ <size>35</size>
+ </field>
+ <field>
+ <fielddescr>none</fielddescr>
+ <fieldname>none</fieldname>
+ <type>rowhelper</type>
+ <rowhelper>
+ <rowhelperfield>
+ <fielddescr>Failover IP</fielddescr>
+ <fieldname>failoverip</fieldname>
+ <description>Failover IP when host is not responding to ICMP/PING traffic</description>
+ <type>input</type>
+ <size>25</size>
+ </rowhelperfield>
+ <rowhelperfield>
+ <fielddescr>Load balance</fielddescr>
+ <fieldname>loadbalance</fieldname>
+ <description>Adds this member to active group when host is alive.</description>
+ <type>checkbox</type>
+ </rowhelperfield>
+ <rowhelperfield>
+ <fielddescr>Ping threshold</fielddescr>
+ <fieldname>pingthreshold</fieldname>
+ <description>When the MS time is surpassed, item will failover to next host</description>
+ <type>input</type>
+ <size>7</size>
+ </rowhelperfield>
+ <rowhelperfield>
+ <fielddescr>Wan ping threshold</fielddescr>
+ <fieldname>wanpingthreshold</fieldname>
+ <description>When the WAN MS ping time is surpassed, item will failover to next host</description>
+ <type>input</type>
+ <size>7</size>
+ </rowhelperfield>
+ <rowhelperfield>
+ <fielddescr>IP to ping to ensure service is up</fielddescr>
+ <fieldname>monitorip</fieldname>
+ <description>When the WAN MS ping time is surpassed, item will failover to next host</description>
+ <type>input</type>
+ <size>15</size>
+ </rowhelperfield>
+ </rowhelper>
+ </field>
+ </fields>
+ <custom_delete_php_command>
+ tinydns_create_zone_file();
+ tinydns_setup_ping_items();
+ tinydns_sync_on_changes();
+ </custom_delete_php_command>
+ <custom_add_php_command>
+ log_error("Begin tinydns add");
+ tinydns_create_zone_file();
+ log_error("Zone file done.");
+ tinydns_setup_ping_items();
+ log_error("Ping items done.");
+ tinydns_sync_on_changes();
+ </custom_add_php_command>
+ <custom_php_resync_config_command>
+ log_error("Begin tinydns resync");
+ tinydns_create_zone_file();
+ log_error("Zone file done.");
+ tinydns_setup_ping_items();
+ log_error("Ping items done.");
+ tinydns_sync_on_changes();
+ </custom_php_resync_config_command>
+ <custom_php_command_before_form>
+ unset($_POST['temp']);
+ </custom_php_command_before_form>
+</packagegui>
diff --git a/config/tinydns/tinydns_down.php b/config/tinydns/tinydns_down.php
new file mode 100644
index 00000000..19eaa4ae
--- /dev/null
+++ b/config/tinydns/tinydns_down.php
@@ -0,0 +1,42 @@
+#!/usr/local/bin/php -f
+<?php
+
+/* $Id$ */
+/*
+ tinydns_down.php
+ Copyright (C) 2006 Scott Ullrich
+ part of pfSense
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+require_once("functions.inc");
+require_once("config.inc");
+require_once("/usr/local/pkg/tinydns.inc");
+
+tinydns_create_zone_file();
+tinydns_setup_ping_items();
+
+exit(0);
+
+?> \ No newline at end of file
diff --git a/config/tinydns/tinydns_filter.php b/config/tinydns/tinydns_filter.php
new file mode 100644
index 00000000..88819932
--- /dev/null
+++ b/config/tinydns/tinydns_filter.php
@@ -0,0 +1,38 @@
+<?php
+
+/* $Id$ */
+/*
+ tinydns_filter.php
+ Copyright (C) 2006 Scott Ullrich
+ part of pfSense
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* for now, redirect to unsorted raw CoreGUI page */
+Header("Location: pkg.php?xml=tinydns_domains.xml");
+exit;
+
+require("/usr/local/pkg/tinydns.inc");
+
+?> \ No newline at end of file
diff --git a/config/tinydns/tinydns_parse_logs.php b/config/tinydns/tinydns_parse_logs.php
new file mode 100644
index 00000000..2b316d4c
--- /dev/null
+++ b/config/tinydns/tinydns_parse_logs.php
@@ -0,0 +1,96 @@
+#!/usr/local/bin/php
+<?php
+
+/* $Id$ */
+/*
+ tinydns_parse_logs.inc
+ Copyright (C) 2006 Scott Ullrich
+ part of pfSense
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+$query_type = array(
+ "0001" => "A",
+ "0002" => "NS",
+ "0005" => "CNAME",
+ "0006" => "SOA",
+ "000c" => "PTR",
+ "000f" => "MX",
+ "0010" => "TXT",
+ "001c" => "AAAA",
+ "0021" => "RT",
+ "0026" => "A6",
+ "00fb" => "IXFR",
+ "00fc" => "AXFR",
+ "00ff" => "*"
+ );
+
+$results = array(
+ "+" => "responded",
+ "-" => "not_authority",
+ "I" => "not_implemented/invalid",
+ "C" => "wrong_class",
+ "/" => "not_parsed"
+ );
+
+$fp = fopen('php://stdin', 'r');
+
+/* loop through stdin and process text */
+while (!feof($fp)) {
+ $stdintext = chop(fgets($fp));
+ preg_match('/^(\S+ \S+) ([^:]+):([^:]+):([^:]+) (\S+) (\S+) (\S+)$/', $stdintext, $items);
+ $stamp = $items[1];
+ $rawip = $items[2];
+ $port = $items[3];
+ $id = $items[4];
+ $result = $items[5];
+ $type = $items[6];
+ $name = $items[7];
+ if (isset($query_type[$type]))
+ $qtype = $query_type[$type];
+ else
+ $qtype = $type;
+ $desc = $results[$result];
+ $ip = decodeipaddress($rawip);
+ //echo "RAWIP: $rawip $ip";
+ printf("%s %15.15s:%-4.4s %-8.8s %-24.24s %s\n",$stamp,$ip,hexdec($port),$qtype,$desc,$name);
+}
+
+function decodeipaddress($text) {
+ preg_match('/(..)(..)(..)(..)/', $text, $hexitems);
+ $ipaddr = "";
+ unset($hexitems[0]);
+ $isfirst = true;
+ foreach($hexitems as $hexitem) {
+ if(!$isfirst)
+ $ipaddr .= ".";
+ $ipaddr .= hexdec($hexitem);
+ $isfirst = false;
+ }
+ return $ipaddr;
+}
+
+fclose($fp);
+
+?> \ No newline at end of file
diff --git a/config/tinydns/tinydns_status.php b/config/tinydns/tinydns_status.php
new file mode 100644
index 00000000..147001af
--- /dev/null
+++ b/config/tinydns/tinydns_status.php
@@ -0,0 +1,188 @@
+<?php
+/* $Id$ */
+/*
+ tinydns_status.php
+ part of pfSense (http://www.pfsense.com/)
+
+ Copyright (C) 2006 Scott Ullrich <sullrich@gmail.com>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+require("guiconfig.inc");
+
+/* Defaults to this page but if no settings are present, redirect to setup page */
+if(!$config['installedpackages']['tinydnsdomains']['config'])
+ Header("Location: /wizard.php?xml=new_zone_wizard.xml");
+
+if(!$config['installedpackages']['tinydns']['config'][0]['ipaddress'])
+ Header("Location: /pkg_edit.php?xml=tinydns.xml&id=0&savemsg=Please+set+the+binding+ip+address+for+server+operation");
+
+$pgtitle = "TinyDNS: Status";
+include("head.inc");
+
+$pfSversion = str_replace("\n", "", file_get_contents("/etc/version"));
+if(strstr($pfSversion, "1.2"))
+ $one_two = true;
+
+?>
+<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
+<?php include("fbegin.inc"); ?>
+
+<?php if($one_two): ?>
+<p class="pgtitle"><?=$pgtitle?></font></p>
+<?php endif; ?>
+
+<?php if ($savemsg) print_info_box($savemsg); ?>
+
+<div id="mainlevel">
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+<?php
+ $tab_array = array();
+ $tab_array[] = array(gettext("Settings"), false, "/pkg_edit.php?xml=tinydns.xml&id=0");
+ $tab_array[] = array(gettext("Add/Edit Record"), false, "/tinydns_filter.php");
+ $tab_array[] = array(gettext("Failover Status"), true, "/tinydns_status.php");
+ $tab_array[] = array(gettext("Logs"), false, "/tinydns_view_logs.php");
+ $tab_array[] = array(gettext("Zone Sync"), false, "/pkg_edit.php?xml=tinydns_sync.xml&id=0");
+ $tab_array[] = array(gettext("New domain wizard"), false, "/wizard.php?xml=new_zone_wizard.xml");
+ display_top_tabs($tab_array);
+?>
+</table>
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td class="tabcont" >
+ <form action="tinydns_status.php" method="post">
+ </form>
+ </td>
+ </tr>
+ <tr>
+ <td class="tabcont" >
+ <table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td width="55%" class="listhdrr">IP</td>
+ <td width="15%" class="listhdrr">Status</td>
+ <td width="15%" class="listhdrr">In Service</td>
+ <td width="25%" class="listhdrr">Response time</td>
+ </tr>
+
+<?php
+$pingdir = return_dir_as_array("/var/db/pingstatus");
+if(file_exists("/service/tinydns/root/data"))
+ $tinydns_data = file_get_contents("/service/tinydns/root/data");
+else
+ $tinydns_data = "";
+if($config['installedpackages']['tinydnsdomains'])
+foreach($config['installedpackages']['tinydnsdomains']['config'] as $ping) {
+ if($ping['recordtype'] == "SOA")
+ continue;
+ if(!$ping['row'])
+ continue;
+ $ipaddress = $ping['ipaddress'];
+ $hostname = $ping['hostname'];
+ $monitorip = $ping['monitorip'];
+ if(file_exists("/var/db/pingstatus/$monitorip"))
+ $status = file_get_contents("/var/db/pingstatus/$monitorip");
+ else
+ $status = "N/A";
+ if(stristr($tinydns_data, "+{$hostname}:{$ipaddress}"))
+ $inservice = "<FONT COLOR='GREEN'>YES</FONT>";
+ else
+ $inservice = "<FONT COLOR='BLUE'>NO</FONT>";
+ echo "<tr>";
+ echo "<td class=\"listlr\">";
+ echo "$hostname<br>&nbsp;&nbsp;&nbsp;|->&nbsp;$ipaddress";
+ echo "</td>";
+ echo "<td class=\"listlr\">";
+ if(stristr($status,"DOWN"))
+ echo "<FONT COLOR='red'>DOWN</FONT>";
+ else
+ echo "UP";
+ echo "</td>";
+
+ echo "<td class=\"listlr\">";
+ echo $inservice;
+ echo "</td>";
+
+ echo "<td class=\"listlr\">";
+ if(!$monitorip)
+ $monitorip = $ipaddress;
+ if(file_exists("/var/db/pingmsstatus/$monitorip"))
+ $msstatus = file_get_contents("/var/db/pingmsstatus/$monitorip");
+ else
+ $msstatus = "N/A";
+ echo "<!-- " . $monitorip . " -->" . $msstatus;
+ echo "</td>";
+ echo "</tr>";
+
+ foreach($ping['row'] as $row) {
+ $ipaddress = $row['failoverip'];
+ $monitorip = $row['monitorip'];
+ if(file_exists("/var/db/pingstatus/$monitorip"))
+ $status = file_get_contents("/var/db/pingstatus/$monitorip");
+ else
+ $status = "N/A";
+ echo "<tr>";
+ echo "<td class=\"listlr\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|->&nbsp;&nbsp;";
+ echo $ipaddress;
+ if($row['loadbalance'])
+ echo " (LB)";
+ if(stristr($tinydns_data, "+{$hostname}:{$row['monitorip']}"))
+ $inservice = "<FONT COLOR='GREEN'>YES</FONT>";
+ else
+ $inservice = "<FONT COLOR='BLUE'>NO</FONT>";
+ echo "</td>";
+ echo "<td class=\"listlr\">";
+ if(stristr($status,"DOWN"))
+ echo "<FONT COLOR='red'>DOWN</FONT>";
+ else
+ echo "UP";
+ echo "</td>";
+
+ echo "<td class=\"listlr\">";
+ echo $inservice;
+ echo "</td>";
+
+ echo "<td class=\"listlr\">";
+ if(!$monitorip)
+ $monitorip = $ipaddress;
+ if(file_exists("/var/db/pingmsstatus/$monitorip"))
+ $msstatus = file_get_contents("/var/db/pingmsstatus/$monitorip");
+ else
+ $msstatus = "N/A";
+
+ echo "<!-- " . $monitorip . " -->" . $msstatus;
+ echo "</td>";
+ echo "</tr>";
+ }
+ echo "<tr><td>&nbsp;</td></tr>";
+}
+?>
+ </table>
+ </td>
+ </tr>
+</table>
+</div>
+<?php include("fend.inc"); ?>
+<meta http-equiv="refresh" content="60;url=<?php print $_SERVER['SCRIPT_NAME']; ?>">
+</body>
+</html>
diff --git a/config/tinydns/tinydns_sync.xml b/config/tinydns/tinydns_sync.xml
new file mode 100644
index 00000000..091ae90a
--- /dev/null
+++ b/config/tinydns/tinydns_sync.xml
@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE packagegui SYSTEM "../schema/packages.dtd">
+<?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?>
+<packagegui>
+ <copyright>
+ <![CDATA[
+/* $Id$ */
+/* ========================================================================== */
+/*
+ tinydns_sync.xml
+ part of pfSense (http://www.pfSense.com)
+ Copyright (C) 2008 Scott Ullrich
+ All rights reserved.
+ */
+/* ========================================================================== */
+/*
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+/* ========================================================================== */
+ ]]>
+ </copyright>
+ <description>Describe your package here</description>
+ <requirements>Describe your package requirements here</requirements>
+ <faq>Currently there are no FAQ items provided.</faq>
+ <name>tinydnssync</name>
+ <version>1.0</version>
+ <title>TinyDNS: Manual Sync</title>
+ <include_file>/usr/local/pkg/tinydns.inc</include_file>
+ <tabs>
+ <tab>
+ <text>Settings</text>
+ <url>/pkg_edit.php?xml=tinydns.xml&amp;id=0</url>
+ </tab>
+ <tab>
+ <text>Add/Edit Record</text>
+ <url>/tinydns_filter.php</url>
+ </tab>
+ <tab>
+ <text>Failover Status</text>
+ <url>/tinydns_status.php</url>
+ </tab>
+ <tab>
+ <text>Logs</text>
+ <url>/tinydns_view_logs.php</url>
+ </tab>
+ <tab>
+ <text>Zone Sync</text>
+ <url>/pkg_edit.php?xml=tinydns_sync.xml&amp;id=0</url>
+ <active/>
+ </tab>
+ <tab>
+ <text>New domain wizard</text>
+ <url>/wizard.php?xml=new_zone_wizard.xml</url>
+ </tab>
+ </tabs>
+ <configpath>installedpackages->package->tinydns</configpath>
+ <fields>
+ <field>
+ <type>listtopic</type>
+ <fieldname>temp</fieldname>
+ <name>Enbable DNS zone sync</name>
+ </field>
+ <field>
+ <fielddescr>Automatically sync DNS zone changes</fielddescr>
+ <fieldname>synconchanges</fieldname>
+ <description>pfSense will automatically sync changes to the hosts defined below.</description>
+ <type>checkbox</type>
+ </field>
+ <field>
+ <type>listtopic</type>
+ <name>Sync host #1</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>IP Address</fielddescr>
+ <fieldname>ipaddress</fieldname>
+ <description>The IP address of the first host that TinyDNS will Sync its DNS zone data to.</description>
+ <type>input</type>
+ </field>
+ <field>
+ <fielddescr>Password</fielddescr>
+ <fieldname>password</fieldname>
+ <description>Admin password of the first host that TinyDNS will Sync its DNS zone data to.</description>
+ <type>password</type>
+ </field>
+ <field>
+ <type>listtopic</type>
+ <name>Sync host #2</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>IP Address 2</fielddescr>
+ <fieldname>ipaddress2</fieldname>
+ <description>OPTIONAL. The IP address of the second host that TinyDNS will Sync its DNS zone data to.</description>
+ <type>input</type>
+ </field>
+ <field>
+ <fielddescr>Password 2</fielddescr>
+ <fieldname>password2</fieldname>
+ <description>Admin password of the second host that TinyDNS will Sync its DNS zone data to.</description>
+ <type>password</type>
+ </field>
+ <field>
+ <type>listtopic</type>
+ <name>Sync host #3</name>
+ <fieldname>temp</fieldname>
+ </field>
+ <field>
+ <fielddescr>IP Address 3</fielddescr>
+ <fieldname>ipaddress3</fieldname>
+ <description>OPTIONAL. The IP address of the third host that TinyDNS will Sync its DNS zone data to.</description>
+ <type>input</type>
+ </field>
+ <field>
+ <fielddescr>Password 3</fielddescr>
+ <fieldname>password3</fieldname>
+ <description>Admin password of the third host that TinyDNS will Sync its DNS zone data to.</description>
+ <type>password</type>
+ </field>
+ </fields>
+ <custom_php_resync_config_command>
+ tinydns_sync_on_changes();
+ </custom_php_resync_config_command>
+ <custom_php_command_before_form>
+ unset($_POST['temp']);
+ </custom_php_command_before_form>
+</packagegui> \ No newline at end of file
diff --git a/config/tinydns/tinydns_up.php b/config/tinydns/tinydns_up.php
new file mode 100644
index 00000000..c06ad74c
--- /dev/null
+++ b/config/tinydns/tinydns_up.php
@@ -0,0 +1,42 @@
+#!/usr/local/bin/php -f
+<?php
+
+/* $Id$ */
+/*
+ tinydns_up.php
+ Copyright (C) 2006 Scott Ullrich
+ part of pfSense
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+require_once("functions.inc");
+require_once("config.inc");
+require_once("/usr/local/pkg/tinydns.inc");
+
+tinydns_create_zone_file();
+tinydns_setup_ping_items();
+
+exit(0);
+
+?> \ No newline at end of file
diff --git a/config/tinydns/tinydns_view_logs.php b/config/tinydns/tinydns_view_logs.php
new file mode 100644
index 00000000..d205a630
--- /dev/null
+++ b/config/tinydns/tinydns_view_logs.php
@@ -0,0 +1,122 @@
+<?php
+/* $Id$ */
+/*
+ tinydns_view_logs.php
+ part of pfSense (http://www.pfsense.com/)
+
+ Copyright (C) 2006 Scott Ullrich <sullrich@gmail.com>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+require("guiconfig.inc");
+
+if($_REQUEST['getactivity']) {
+ $tinydnslogs = `cat /etc/tinydns/log/main/current | /usr/local/bin/tai64nlocal | php -f /usr/local/pkg/tinydns_parse_logs.php | grep -v ":0"`;
+ echo "TinyDNS Server logs as of " . date("D M j G:i:s T Y") . "\n\n";
+ echo $tinydnslogs;
+ exit;
+}
+
+/* Defaults to this page but if no settings are present, redirect to setup page */
+if(!$config['installedpackages']['tinydns']['config'][0])
+ Header("Location: /pkg_edit.php?xml=tinydns.xml&id=0");
+
+$pfSversion = str_replace("\n", "", file_get_contents("/etc/version"));
+if(strstr($pfSversion, "1.2"))
+ $one_two = true;
+
+$pgtitle = "TinyDNS: View Logs";
+include("head.inc");
+
+/* NEED TO FIX there are 2 logs /etc/tinydns/log/main/current and /etc/dnscache/log/main/current */
+
+/* NEED TO FIX */
+if ($_POST['clear']) {
+// exec("rm /etc/tinydns/log/main/current");
+// exec("touch /etc/tinydns/log/main/current");
+}
+
+?>
+<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
+<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
+ <script type="text/javascript">
+ function getlogactivity() {
+ var url = "/tinydns_view_logs.php";
+ var pars = 'getactivity=yes';
+ var myAjax = new Ajax.Request(
+ url,
+ {
+ method: 'post',
+ parameters: pars,
+ onComplete: activitycallback
+ });
+ }
+ function activitycallback(transport) {
+ $('tinydnslogs').innerHTML = '<font face="Courier"><pre>' + transport.responseText + '</pre></font>';
+ setTimeout('getlogactivity()', 2500);
+ }
+ setTimeout('getlogactivity()', 1000);
+ </script>
+<?php include("fbegin.inc"); ?>
+
+<?php if($one_two): ?>
+<p class="pgtitle"><?=$pgtitle?></font></p>
+<?php endif; ?>
+
+<?php if ($savemsg) print_info_box($savemsg); ?>
+
+<div id="mainlevel">
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+<?php
+ $tab_array = array();
+ $tab_array[] = array(gettext("Settings"), false, "/pkg_edit.php?xml=tinydns.xml&id=0");
+ $tab_array[] = array(gettext("Add/Edit Record"), false, "/tinydns_filter.php");
+ $tab_array[] = array(gettext("Failover Status"), false, "/tinydns_status.php");
+ $tab_array[] = array(gettext("Logs"), true, "/tinydns_view_logs.php");
+ $tab_array[] = array(gettext("Zone Sync"), false, "/pkg_edit.php?xml=tinydns_sync.xml&id=0");
+ $tab_array[] = array(gettext("New domain wizard"), false, "/wizard.php?xml=new_zone_wizard.xml");
+ display_top_tabs($tab_array);
+?>
+</table>
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td class="tabcont" >
+ <form action="tinydns_view_logs.php" method="post">
+ <br>
+ <div id="tinydnslogs">
+ <pre>One moment please, loading TinyDNS logs...</pre>
+ </div>
+ </td>
+ </tr>
+</table>
+<td align="left" valign="top">
+ <form id="filterform" name="filterform" action="tinydns_view_logs.php" method="post" style="margin-top: 14px;">
+ <p/>
+ <input id="submit" name="clear" type="submit" class="formbtn" value="<?=gettext("Clear log");?>" />
+ </form>
+</td>
+</div>
+<?php include("fend.inc"); ?>
+</body>
+</html>
diff --git a/config/tinydns/tinydns_xmlrpc_sync.php b/config/tinydns/tinydns_xmlrpc_sync.php
new file mode 100644
index 00000000..0610e286
--- /dev/null
+++ b/config/tinydns/tinydns_xmlrpc_sync.php
@@ -0,0 +1,59 @@
+<?php
+
+/* $Id$ */
+/*
+ tinydns_xmlrcpc_sync.php
+ Copyright (C) 2006 Scott Ullrich
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* NOTE: this file gets included from the pfSense filter.inc plugin process */
+
+require_once("config.inc");
+require_once("/usr/local/pkg/tinydns.inc");
+require_once("service-utils.inc");
+
+if($notnow) {
+
+ /* disabled until Ticket #1318 can be fixed */
+
+ if(!$config) {
+ log_error("\$config is not enabled from tinydns_xmlrpc_sync.php!!");
+ } else {
+ if($config['installedpackages']['carpsettings']['config'])
+ $password = $config['installedpackages']['carpsettings']['config'][0]['password'];
+ if($config['installedpackages']['carpsettings']['config'])
+ $syncip = $config['installedpackages']['carpsettings']['config'][0]['synchronizetoip'];
+ if($config['installedpackages']['carpsettings']['config'])
+ $syncxmlrpc = $config['installedpackages']['tinydns']['config'][0]['syncxmlrpc'];
+ /* option enabled? */
+ if($syncxmlrpc)
+ if($syncip)
+ if($password)
+ tinydns_do_xmlrpc_sync($syncip, $password);
+ }
+
+}
+
+?> \ No newline at end of file