<?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 adding your first domain to TinyDNS.</description>
	<fields>
		<field>
			<name>Next</name>
			<type>submit</type>
		</field>
	</fields>
</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) - (not needed if hostname above is in a different domain)</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'];
			if(!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$tmp['ipaddress']) && substr($tmp['ipaddress'],-1) != ".")
				$tmp['ipaddress'] = $tmp['ipaddress'] . ".";				
			$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'];
			if(!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$tmp['ipaddress']) && substr($tmp['ipaddress'],-1) != ".")
				$tmp['ipaddress'] = $tmp['ipaddress'] . ".";				
			$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['mailexchangerrecordhostname']) {
			$tmp = array();
			$tmp['hostname'] = $_POST['domainname'];
			$tmp['recordtype'] = "MX";
			$tmp['ipaddress'] = $_POST['mailexchangerrecordhostname'];
			if(substr($tmp['ipaddress'],-1) != ".")
				$tmp['ipaddress'] = $tmp['ipaddress'] . ".";				
			$config['installedpackages']['tinydnsdomains']['config'][] = $tmp;
			unset($tmp);
			$changed = true;

			if($_POST['mailexchangerrecordipaddress']) {
				$tmp = array();
				$tmp['hostname'] = $_POST['mailexchangerrecordhostname'];
				$tmp['recordtype'] = "A";
				$tmp['ipaddress'] = $_POST['mailexchangerrecordipaddress'];		
				$config['installedpackages']['tinydnsdomains']['config'][] = $tmp;
				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();
		}

		// If service is running redirect to domains page.  
		// Otherwise redirect to the tinydns settings page.
		if(is_dir("/service/tinydns"))
			Header("Location: /pkg.php?xml=tinydns_domains.xml");
		else 
			Header("Location: /pkg.php?xml=tinydns.xml");

	]]>	
	</stepsubmitbeforesave>	
</step>
</pfsensewizard>