<packagegui>
	<name>freeradiusclients</name>
	<title>FreeRADIUS: Clients</title>
	<tabs>
                <tab>
                        <text>Users</text>
                        <url>/pkg.php?xml=freeradius.xml</url>
                </tab>
                <tab>
                        <text>Clients</text>
                        <url>/pkg.php?xml=freeradiusclients.xml</url>
			<active/>
                </tab>
                <tab>
                        <text>Settings</text>
                        <url>/pkg_edit.php?xml=freeradiussettings.xml&amp;id=0</url>
                </tab>
        </tabs>
	<configpath>installedpackages->package->$packagename->configuration->settings</configpath>
	<adddeleteeditpagefields>
		<columnitem>
			<fielddescr>Client</fielddescr>
			<fieldname>client</fieldname>
		</columnitem>
		<columnitem>
			<fielddescr>Shortname</fielddescr>
			<fieldname>shortname</fieldname>
		</columnitem>
		<columnitem>
			<fielddescr>Description</fielddescr>
			<fieldname>description</fieldname>
		</columnitem>
	</adddeleteeditpagefields>
	<fields>
		<field>
			<fielddescr>Client</fielddescr>
			<fieldname>client</fieldname>
			<description>Enter the client's IP address here</description>
			<type>input</type>
		</field>
		<field>
			<fielddescr>Shortname</fielddescr>
			<fieldname>shortname</fieldname>
			<description>Enter the client's shortname here</description>
			<type>input</type>
		</field>
		<field>
			<fielddescr>Shared Secret</fielddescr>
			<fieldname>sharedsecret</fieldname>
			<description>Enter the client's shared secret here</description>
			<type>password</type>
		</field>
		<field>
			<fielddescr>Description</fielddescr>
			<fieldname>description</fieldname>
			<description>Enter the description of the user here</description>
			<type>input</type>
		</field>
	</fields>
	<custom_php_command_before_form>
		function sync_package() {
			global $config;
			$fout = fopen("/usr/local/etc/raddb/clients.conf","w");
			fwrite($fout, "client 127.0.0.1" . "{\n" . "secret = pfsense\n" . "shortname = localhost\n}\n\n");
			if($config['installedpackages']['freeradiusclients']['config'] != "") {
				foreach($config['installedpackages']['freeradiusclients']['config'] as $rowhelper) {
					fwrite($fout, "client " . $rowhelper['client'] . "{\n" . "secret = " . $rowhelper['sharedsecret'] . "\nshortname = " . $rowhelper['shortname'] . "\n}\n\n");
				}
			}
		 	fclose($fout);
			mwexec("killall radiusd");
			mwexec("/usr/local/etc/rc.d/radiusd");
		}
		sync_package();
	</custom_php_command_before_form>
	<custom_add_php_command>
		sync_package();
	</custom_add_php_command>
</packagegui>