<?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>doorman</name>
	<version>none</version>
	<title>doorman: Settings</title>
	<aftersaveredirect>pkg_edit.php?xml=doorman.xml&amp;id=0</aftersaveredirect>
	<menu>
		<name>doorman</name>
		<tooltiptext>Modify doorman settings and users.</tooltiptext>
		<section>Services</section>
		<configfile>doorman.xml</configfile>
		<url>/pkg_edit.php?xml=doorman.xml&amp;id=0</url>
	</menu>
	<service>
                <name>doorman</name>
                <rcfile>doorman.sh</rcfile>
                <executable>doormand</executable>
        </service>
	<tabs>
		<tab> 
                        <text>Settings</text>
                        <url>/pkg_edit.php?xml=doorman.xml&amp;id=0</url>
                        <active/>
                </tab>
                <tab>
                        <text>Users</text>
                        <url>/pkg.php?xml=doormanusers.xml</url>
                </tab>
        </tabs>
	<configpath>installedpackages->package->$packagename->configuration->settings</configpath>
	<additional_files_needed>
		<item>http://www.pfsense.com/packages/config/doormanusers.xml</item>
	</additional_files_needed>
	<fields>
		<field>
			<fielddescr>Initial connection timeout</fielddescr>
			<fieldname>initdelay</fieldname>
			<description>Enter the desired number of *microseconds* to wait for a complete 3-way handshake between the client and requested service. (default one half second)</description>
			<type>input</type>
			<value>500000</value>
		</field>
		<field>
			<fielddescr>Connection check interval</fielddescr>
			<fieldname>checkdelay</fieldname>
			<description>Enter the desired number of *seconds* between checking for broken connections. (default 5 seconds)</description>
			<type>input</type>
			<value>5</value>
		</field>
		<field>
			<fielddescr>Connection initiation timeout</fielddescr>
			<fieldname>inittimeout</fieldname>
			<description>Enter the desired number of *seconds* to wait for a connection to be established after a successful knock.i (default 10 seconds)</description>
			<type>input</type>
			<value>10</value>
		</field>
		<!--
		<field>
			<fielddescr>Listening interface(s)</fielddescr>
			<fieldname>interface</fieldname>
			<description>Select the interfaces that doormand should listen on. (default WAN)</description>
			<value>wan</value>
			<type>interfaces_selection</type>
		</field>
		-->
		<field>
			<fielddescr>Listening port</fielddescr>
			<fieldname>port</fieldname>
			<description>Enter the port that doormand should listen on. (default 1001)</description>	
			<type>input</type>
			<value>1001</value>
		</field>
	</fields>
	<custom_php_global_functions>
	function sync_package_doorman() {
		conf_mount_rw();
		config_lock();
		global $config;
		$fout = fopen("/usr/local/etc/doormand/doormand.cf","w");
		fwrite($fout, "# This file was automatically generated by the pfSense\n# package management system.\n\n");
		/*
		 *	$int = convert_friendly_interface_to_real_interface_name($_POST['interface']);
		 *	fwrite($fout, "interface " . $int . "\n");
		 */
		fwrite($fout, "interface " . $config['interfaces']['wan']['if'] . "\n");
		if($_POST['port'] != "") fwrite($fout, "port " . $_POST['port'] . "\n");
		if($_POST['inittimeout'] != "") fwrite($fout, "waitfor " . $_POST['inittimeout'] . "\n");
		if($_POST['initdelay'] != "") fwrite($fout, "connection_delay_1 " . $_POST['initdelay'] . "\n");
		if($_POST['checkdelay'] != "") fwrite($fout, "connection_delay_2 " . $_POST['checkdelay'] . "\n");
		fwrite($fout, "pidfile /var/run/doormand.pid\nlogfile /var/log/messages\nloglevel NOTICE\nguestlist /usr/local/etc/doormand/guestlist\nfirewall-add /usr/local/etc/doormand/pfctl_add\nfirewall-del /usr/local/etc/doormand/pfctl_del\ntag-queue-length 100000\ntag-queue /var/doorman_tag_queue\ntag-db /var/doorman_tag_db.db\n");
		fwrite($fout, "hash-archive-size   50000\n");
        fwrite($fout, "hash-archive        /tmp/doormand.hash-archive\n");
		fclose($fout);
		restart_service("doorman");
		conf_mount_ro();
		config_unlock();
	}
	</custom_php_global_functions>
	<custom_add_php_command>
		sync_package_doorman();
	</custom_add_php_command>
	<custom_php_install_command>
		global $config;
		$start = "/usr/local/sbin/doormand -D &amp;";
		write_rcfile(array(
					"file" => "doorman.sh",
					"start" => $start,
					"stop" => "/usr/bin/killall doormand"
				)
		);
	</custom_php_install_command>
</packagegui>