<?xml version="1.0" encoding="utf-8" ?>
<packagegui>
	<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>
	<additional_files_needed>
		<item>http://www.pfsense.com/packages/config/pure-ftpdsettings.xml</item>
	</additional_files_needed>
	<!-- 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>
	<!-- 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_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>
	<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_delete_php_command>
		rmdir_recursive("/home/" . $username);
		system("/usr/sbin/pw userdel " . $username);
	</custom_delete_php_command>
</packagegui>