<?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[
/* ========================================================================== */
/*
    varnish_lb_directors.xml
    part of pfSense (http://www.pfSense.com)
    Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
    Copyright (C) 2011 Marcello Coutinho
    
    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>varnishlbdirectors</name>
	<version>0.0.6</version>
	<title>Varnish: Backends</title>
	<include_file>/usr/local/pkg/varnish.inc</include_file>
   	<additional_files_needed>
	    <prefix>/usr/local/pkg/</prefix>
	    <chmod>0755</chmod>
	    <item>https://packages.pfsense.org/packages/config/varnish64/varnish_settings.xml</item>
	</additional_files_needed>
   	<additional_files_needed>
	    <prefix>/usr/local/pkg/</prefix>
	    <chmod>0755</chmod>
	    <item>https://packages.pfsense.org/packages/config/varnish64/varnish_custom_vcl.xml</item>
	</additional_files_needed>
   	<additional_files_needed>
	    <prefix>/usr/local/pkg/</prefix>
	    <chmod>0755</chmod>
	    <item>https://packages.pfsense.org/packages/config/varnish64/varnish.inc</item>
	</additional_files_needed>
	<menu>
		<name>Varnish </name>
		<tooltiptext></tooltiptext>
		<section>Services</section>
		<configfile>varnish_lb_directors.xml</configfile>
	</menu>
	<tabs>
		<tab>
			<text>Backends</text>
			<url>/pkg.php?xml=varnish_backends.xml</url>
		</tab>
		<tab>
			<text>Settings</text>
			<url>/pkg_edit.php?xml=varnish_settings.xml&amp;id=0</url>
		</tab>
		<tab>
			<text>Custom VCL</text>
			<url>/pkg_edit.php?xml=varnish_custom_vcl.xml&amp;id=0</url>
		</tab>
		<tab>
			<text>LB Directors</text>
			<url>/pkg.php?xml=varnish_lb_directors.xml</url>
			<active/>
		</tab>
		<tab>
			<text>XMLRPC Sync</text>
			<url>/pkg_edit.php?xml=varnish_sync.xml&amp;id=0</url>
		</tab>
		<tab>
			<text>View Configuration</text>
			<url>/varnish_view_config.php</url>
		</tab>
		<tab>
			<text>VarnishSTAT</text>
			<url>/varnishstat.php</url>
		</tab>
	</tabs>
	<adddeleteeditpagefields>
		<columnitem>
			<fielddescr>Director name</fielddescr>
			<fieldname>directorname</fieldname>
		</columnitem>	
		<columnitem>
			<fielddescr>HOST</fielddescr>
			<fieldname>directorurl</fieldname>
		</columnitem>
		<columnitem>
			<fielddescr>URL</fielddescr>
			<fieldname>directorurl2</fieldname>
		</columnitem>
		 <columnitem>
                        <fielddescr>Rewrite Host</fielddescr>
                        <fieldname>rewritehost</fieldname>
                </columnitem>
                <columnitem>
                        <fielddescr>Rewrite url</fielddescr>
                        <fieldname>rewriteurl</fieldname>
                </columnitem>
		<columnitem>
			<fielddescr>Type</fielddescr>
			<fieldname>directortype</fieldname>
		</columnitem>
		<columnitem>
			<fielddescr>Grace</fielddescr>
			<fieldname>grace</fieldname>
		</columnitem>
		<columnitem>
			<fielddescr>Failover</fielddescr>
			<fieldname>failover</fieldname>
		</columnitem>		
	</adddeleteeditpagefields>
	<fields>
		<field>
			<fielddescr>DirectorSettings</fielddescr>
			<fieldname>Director Settings</fieldname>
			<type>listtopic</type>
			<name>Director settings</name>
		</field>
		<field>
			<fielddescr>Director name</fielddescr>
			<fieldname>directorname</fieldname>
			<type>input</type>
			<size>40</size>
		</field>
		<field>
		<fielddescr>Match type</fielddescr>
				    <fieldname>fieldtype</fieldname>
				    <description>Select the field type that you would like to use in matching the HOST/URL.</description>
					<type>select</type>
					<options>
						<option>
							<name>Equals</name>
							<value>==</value>
						</option>
						<option>
							<name>Regex</name>
							<value>~</value>
						</option>
			</options>
			</field>
		<field>
			<fielddescr>Host</fielddescr>
			<fieldname>directorurl</fieldname>
			<description>Hint www.mysite.com</description>
			<type>input</type>
			<size>40</size>
		</field>
		<field>
			<fielddescr>URL</fielddescr>
			<fieldname>directorurl2</fieldname>
			<description>Hint /images</description>
			<type>input</type>
			<size>40</size>
		</field>
		  <field>
                        <fielddescr>Rewrite Host</fielddescr>
                        <fieldname>rewritehost</fieldname>
                        <description>Hint image.mysite.com</description>
                        <type>input</type>
                        <size>40</size>
                </field>
                <field>
                        <fielddescr>Rewrite URL</fielddescr>
                        <fieldname>rewriteurl</fieldname>
                        <description>Hint /images</description>
                        <type>input</type>
                        <size>40</size>
                </field>

		<field>
			<fielddescr>Req Grace</fielddescr>
			<fieldname>grace</fieldname>
			<description><![CDATA[<a href="https://www.varnish-cache.org/trac/wiki/VCLExampleGrace">How many time varnish will keep cached objects for this director.</a> HINT 60s, 30m, 1h<br>Use 0s grace time to force no cache.]]></description>
	    	<type>input</type>
	    	<size>5</size>
 		</field>
 		<field>
			<fielddescr>Additions options</fielddescr>
			<fieldname>customapping</fieldname>
			<description>Paste your custom varnish code for this host/url.</description>
			<type>textarea</type>
			<cols>70</cols>
			<rows>3</rows>
			<encoding>base64</encoding>
		</field>
		<field>
			<fielddescr>Backendlist</fielddescr>
			<fieldname>Backendlist</fieldname>
			<type>listtopic</type>
			<name>Backend Settings</name>
		</field>
		<field>
			<fielddescr>Algorithms</fielddescr>
			<fieldname>directortype</fieldname>
			<description><![CDATA[<a href="https://www.varnish-cache.org/docs/2.1/reference/vcl.html#the-client-director">Choose how varnish will balance clientes.</a>]]></description>
			<type>select</type>
			<options>
				<option><name>Round-robin</name><value>round-robin</value></option>
				<option><name>Random</name><value>random</value></option>
				<option><name>Client</name><value>client</value></option>
				<option><name>Hash</name><value>hash</value></option>
			</options>
		</field>
		<field>
			<fielddescr>Backend</fielddescr>
			<fieldname>Backend</fieldname>
		    <type>rowhelper</type>
		    <rowhelper>
				<rowhelperfield>
				    <fielddescr>Backend</fielddescr>
				    <fieldname>backendname</fieldname>
				    <description>Enter the URL that will be mapped to this lb_directors.</description>
					<source><![CDATA[$config['installedpackages']['varnishbackends']['config']]]></source>
					<source_name>backendname</source_name>
					<source_value>backendname</source_value>
				    <type>select_source</type>
				</rowhelperfield>
				<rowhelperfield>
				    <fielddescr>Weight</fielddescr>
				    <fieldname>weight</fieldname>
				    <description>Enter the weight of this backend.</description>
				    <type>input</type>
				</rowhelperfield>
			</rowhelper>
		</field>
		<field>
			<fielddescr>FailoverSettings</fielddescr>
			<fieldname>FailoverSettings</fieldname>
			<type>listtopic</type>
			<name>Failover Settings</name>
		</field>
		<field>
			<fielddescr>Failover Director</fielddescr>
			<fieldname>failover</fieldname>
			<description>Select a Director for failover or choose same director to do not configure it.</description>
			<source><![CDATA[$config['installedpackages']['varnishlbdirectors']['config']]]></source>
			<source_name>directorname</source_name>
			<source_value>directorname</source_value>
			<type>select_source</type>
		</field>
	</fields>
	<custom_php_command_before_form>
	</custom_php_command_before_form>
	<custom_delete_php_command>
		sync_package_varnish();
		create_varnish_rcd_file();
		varnish_start();
	</custom_delete_php_command>	
	<custom_php_resync_config_command>
		sync_package_varnish();
		create_varnish_rcd_file();
		varnish_start();
	</custom_php_resync_config_command>
	<custom_php_validation_command>
		varnish_lb_directors_post_validate($_POST, $input_errors);
	</custom_php_validation_command>	
</packagegui>