<?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>stunnel</name>
	<version>4.18</version>
	<title>Services: Secure Tunnel</title>
	<!-- Menu is where this packages menu will appear -->
	<menu>
		<name>STunnel</name>
		<tooltiptext>The stunnel program is designed to work as an SSL encryption wrapper between remote client and local (inetd-startable) or remote server. It can be used to add SSL functionality to commonly used inetd daemons like POP2, POP3, and IMAP servers without any changes in the programs' code. It will negotiate an SSL connection using the OpenSSL or SSLeay libraries. It calls the underlying crypto libraries, so stunnel supports whatever cryptographic algorithms you compiled into your crypto package.</tooltiptext>
		<section>Services</section>
		<configfile>stunnel.xml</configfile>
	</menu>
	<!-- configpath gets expanded out automatically and config items will be
         stored in that location -->
	<configpath>['installedpackages']['package']['$packagename']['configuration']</configpath>
	<!-- adddeleteeditpagefields items will appear on the first page where you can add / delete or edit
         items.  An example of this would be the nat page where you add new nat redirects -->
	<adddeleteeditpagefields>
		<columnitem>
			<fielddescr>Description</fielddescr>
			<fieldname>description</fieldname>
		</columnitem>
		<columnitem>
			<fielddescr>Listen on IP</fielddescr>
			<fieldname>localip</fieldname>
		</columnitem>
		<columnitem>
			<fielddescr>Listen on Port</fielddescr>
			<fieldname>localport</fieldname>
		</columnitem>
		<columnitem>
			<fielddescr>Redirects to IP</fielddescr>
			<fieldname>redirectip</fieldname>
		</columnitem>
		<columnitem>
			<fielddescr>Redirects to Port</fielddescr>
			<fieldname>redirectport</fieldname>
		</columnitem>
	</adddeleteeditpagefields>
	<!-- fields gets invoked when the user adds or edits a item.   the following items
         will be parsed and rendered for the user as a gui with input, and selectboxes. -->
	<fields>
		<field>
			<fielddescr>Description</fielddescr>
			<fieldname>description</fieldname>
			<description>Enter a description for this redirection.</description>
			<type>input</type>
		</field>
		<field>
			<fielddescr>Listen on IP</fielddescr>
			<fieldname>localip</fieldname>
			<description>Enter the local IP address to bind this redirection to.</description>
			<type>input</type>
		</field>
		<field>
			<fielddescr>Listen on port</fielddescr>
			<fieldname>localport</fieldname>
			<description>Enter the local port to bind this redirection to.</description>
			<type>input</type>
		</field>
		<field>
			<fielddescr>Redirects to IP</fielddescr>
			<fieldname>redirectip</fieldname>
			<description>Enter the IP address to redirect this to.</description>
			<type>input</type>
		</field>
		<field>
			<fielddescr>Redirects to Port</fielddescr>
			<fieldname>redirectport</fieldname>
			<description>Enter the port to redirect to.</description>
			<type>input</type>
		</field>
	</fields>
	<custom_add_php_command_late>
	  conf_mount_rw();
	  config_lock();
	  $fout = fopen("/usr/local/etc/stunnel/stunnel.conf","w");
	  fwrite($fout, "cert = /usr/local/etc/stunnel/stunnel.pem \n");
	  fwrite($fout, "chroot = /var/tmp/stunnel \n");
	  fwrite($fout, "setuid = stunnel \n");
	  fwrite($fout, "setgid = stunnel \n");
	  foreach($config['installedpackages']['stunnel']['config'] as $pkgconfig) {
	    fwrite($fout, "\n[" . $pkgconfig['description'] . "]\n");
	    fwrite($fout, "accept = " . $pkgconfig['localip'] . ":" . $pkgconfig['localport'] . "\n");
	    fwrite($fout, "connect = " . $pkgconfig['redirectip'] . ":" . $pkgconfig['redirectport'] . "\n");
	    fwrite($fout, "TIMEOUTclose = 0\n\n");
	  }
	  fclose($fout);
	  conf_mount_ro();
	  config_unlock();
	  system("/usr/bin/killall stunnel 2>/dev/null");
	  system("/usr/local/etc/rc.d/stunnel.sh start 2>/dev/null");
	</custom_add_php_command_late>
	<custom_php_install_command>
	    safe_mkdir("/usr/local/etc/stunnel");
	    system("/usr/bin/openssl req -new -x509 -days 365 -nodes -out /usr/local/etc/stunnel/stunnel.pem -keyout /usr/local/etc/stunnel/stunnel.pem 2>/dev/null");
	    chmod("/usr/local/etc/stunnel/stunnel.pem", 600);
            system("/bin/mkdir /var/tmp/stunnel");
	    system("/bin/mkdir /var/tmp/stunnel/var");
	    system("/bin/mkdir /var/tmp/stunnel/var/tmp");
	    system("/usr/sbin/chown -R stunnel:stunnel /var/tmp/stunnel");
	    chmod("/var/tmp/stunnel/var/tmp/", 1777);
	    $fout = fopen("/usr/local/etc/rc.d/stunnel.sh","w");
	    system("/usr/sbin/chown -R stunnel:stunnel /var/tmp/stunnel/var/stunnel");
	    fwrite($fout, "#!/bin/sh\n");
	    fwrite($fout, "# PACKAGE: STunnel\n");
	    fwrite($fout, "# EXECUTABLE: stunnel\n");
	    fwrite($fout, "/usr/local/sbin/stunnel /usr/local/etc/stunnel/stunnel.conf\n\n");
	    fclose($fout);
	    chmod("/usr/local/etc/rc.d/stunnel.sh", 0555);
	</custom_php_install_command>
	<custom_php_deinstall_command>
	    rmdir_recursive("/var/tmp/stunnel");
	    rmdir_recursive("/usr/local/etc/stunnel*");
	</custom_php_deinstall_command>
</packagegui>