<?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>pure-ftpd</name>
	<version>1.0.20_1</version>
	<title>Services: PureFTPD Accounts</title>
	<!-- Menu is where this packages menu will appear -->
	<menu>
		<name>Pure FTPD Accounts</name>
		<tooltiptext>Pure FTPd Server is a fast, production quality, standards-conformant FTP server based on Troll-FTPd. It has no known vulnerability, it is trivial to set up, and it is especially designed for modern kernels. Features include PAM support, IPv6, chroot()ed home directories, virtual domains, built-in 'ls', FXP protocol, anti-warez system, bandwidth throttling, restricted ports for passive downloads, an LDAP backend, XML output, and more.</tooltiptext>
		<section>Services</section>
		<configfile>pure-ftpd.xml</configfile>
	</menu>
	<menu>
		<name>Pure FTPD Settings</name>
		<tooltiptext>Pure FTPd Server is a fast, production quality, standards-conformant FTP server based on Troll-FTPd. It has no known vulnerability, it is trivial to set up, and it is especially designed for modern kernels. Features include PAM support, IPv6, chroot()ed home directories, virtual domains, built-in 'ls', FXP protocol, anti-warez system, bandwidth throttling, restricted ports for passive downloads, an LDAP backend, XML output, and more.</tooltiptext>
		<section>Services</section>
		<url>pkg_edit.php?xml=pure-ftpdsettings.xml&amp;id=0</url>
	</menu>
	<!-- configpath gets expanded out automatically and config items will be
         stored in that location seperated with -> -->
	<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>Username</fielddescr>
			<fieldname>username</fieldname>
		</columnitem>
		<columnitem>
			<fielddescr>Description</fielddescr>
			<fieldname>description</fieldname>
		</columnitem>
	</adddeleteeditpagefields>
	
	<additional_files_needed>
		<item>https://packages.pfsense.org/packages/config/pure-ftpdsettings.xml</item>
	</additional_files_needed>

	<!-- 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>Username</fielddescr>
			<fieldname>username</fieldname>
			<description>Enter the username here</description>
			<type>input</type>
		</field>
		<field>
			<fielddescr>Password</fielddescr>
			<fieldname>password</fieldname>
			<description>Enter the password here</description>
			<type>password</type>
		</field>
		<field>
			<fielddescr>Username Description</fielddescr>
			<fieldname>description</fieldname>
			<description>Enter the description of the user here</description>
			<type>input</type>
		</field>
		<field>
			<fielddescr>Account Expiration</fielddescr>
			<fieldname>expiration</fieldname>
			<description>Amount of days when account expires.  Leave blank for never.</description>
			<type>input</type>
		</field>
	</fields>
	<custom_delete_php_command>
		rmdir_recursive("/home/" . $username);
		system("/usr/sbin/pw userdel " . $username);
	</custom_delete_php_command>
	<custom_add_php_command>
		conf_mount_rw();
		config_lock();
		$expires = "";
		if($_POST['expiration']) $expires = " -e " . $_POST['expiration'];
		mwexec("/bin/mkdir /home/{$_POST['username']}");
		mwexec("/usr/sbin/chown -R {$_POST['username']}:wheel /home/{$_POST['username']}");
		mwexec("/usr/sbin/pw useradd " . $_POST['username'] . $expires . " -m -d /home/" . $_POST['username'] . "/./ -s \"/usr/sbin/nologini\"");
		$fd = popen("/usr/sbin/pw usermod -n " . $_POST['username'] . " -H 0", "w");
		$salt = md5(time());
		$crypted_pw = crypt($_POST['password'],$salt);
		fwrite($fd, $crypted_pw);
		pclose($fd);
		mwexec("/usr/sbin/pw usermod " . $_POST['username'] . " -s /nonexistent");
		conf_mount_ro();
		config_unlock();
		$savemsg = "User has been added.";
	</custom_add_php_command>
	<custom_php_install_command>
		$fout = fopen("/usr/local/etc/rc.d/pure-ftpd.sh","w");
		fwrite($fout, "#!/bin/sh\n\n");
                fwrite($fout, "# PACKAGE: Pure-FTPD\n");
                fwrite($fout, "# EXECUTABLE: pure-ftpd\n");
		fwrite($fout, "/usr/local/sbin/pure-ftpd -A -B /usr/local/etc/pure-ftpd.conf\n");
		fclose($fout);
		chmod("/usr/local/etc/rc.d/pure-ftpd.sh", 0755);
		mwexec("/usr/local/etc/rc.d/pure-ftpd.sh");
	</custom_php_install_command>
	<custom_php_deinstall_command>
		mwexec("/usr/bin/killall pure-ftpd");
		rmdir_recursive("/usr/local/etc/pure*");
		rmdir_recursive("/usr/local/etc/rc.d/pure*");
	</custom_php_deinstall_command>
</packagegui>