<?xml version="1.0" encoding="utf-8" ?>
<packagegui>
	<name>ntop</name>
        <donotsave>true</donotsave>
        <preoutput>yes</preoutput>
        <savetext>Change</savetext>
	<!-- Menu is where this packages menu will appear -->
	<menu>
		<name>NTop Settings</name>
		<tooltiptext>Set NTop settings such as password and port.</tooltiptext>
		<section>Diagnostics</section>
		<configfile>ntop.xml</configfile>
	</menu>
	<menu>
		<name>NTop</name>
		<tooltiptext>Access ntop</tooltiptext>
		<url>http://$myurl:3000</url>
		<section>Services</section>
	</menu>
        <!-- Do not save invokes a simple input menu and will not update
             the configuration database. -->
	<fields>
		<field>
			<fielddescr>NTOP Admin Password</fielddescr>
			<fieldname>password</fieldname>
			<description>Enter the password for the NTOP Web GUI.  Minimum 5 characters.</description>
			<type>password</type>
		</field>
		<field>
			<fielddescr>NTOP Admin Password AGAIN</fielddescr>
			<fieldname>passwordagain</fieldname>
			<type>password</type>
		</field>
		<field>
			<fielddescr>Interface</fielddescr>
			<fieldname>iface</fieldname>
			<size>3</size>
			<multiple>true</multiple>
			<type>interfaces_selection</type>
		</field>
    </fields>
	<custom_add_php_command>
	if($_POST['password'] == $_POST['passwordagain']) {
		$interfaces = " -i ";
		$ifaces=$_POST['iface'];
		$isfirst = 0;
		foreach($ifaces as $element=>$if)
		{
			if($isfirst == 1) $interfaces .= ",";
			$interfaces .= $ifaces[$element];
			$isfirst = 1;
		}
		system("/usr/local/bin/ntop --set-admin-password=" . $_POST['password']);
		system("killall ntop 2>/dev/null");
		system("rm /usr/local/etc/rc.d/ntop.sh");
		$fout = fopen("/usr/local/etc/rc.d/ntop.sh","w");
		fwrite($fout, "#!/bin/sh\n\n");
		fwrite($fout, "/usr/local/bin/ntop " . $interfaces . " -u root -d --ipv4 -M\n\n");
		fclose($fout);
		system("chmod 555 /usr/local/etc/rc.d/ntop.sh");
		system("/usr/local/etc/rc.d/ntop.sh");
	} else {
		echo "Passwords do not match!";
		exit;
	}
	</custom_add_php_command>
	<custom_php_deinstall_command>
		mwexec("/usr/bin/killall ntop");
	</custom_php_deinstall_command>
	<custom_php_install_command>
	    system("rm /usr/local/etc/rc.d/ntop.sh");
	    $fout = fopen("/usr/local/etc/rc.d/ntop.sh","w");
	    fwrite($fout, "#!/bin/sh\n\n");
	    fwrite($fout, "/usr/local/bin/ntop -u root -d --ipv4 -M\n\n");
	    fclose($fout);
	    system("chmod 555 /usr/local/etc/rc.d/ntop.sh");
	</custom_php_install_command>
</packagegui>