From b7f14b04290fa64b6fd26fe1c2bc4c213b4bbecf Mon Sep 17 00:00:00 2001 From: sullrich Date: Fri, 11 Dec 2009 21:21:29 -0500 Subject: Overhaul haproxy package. Rename backends to frontends. Add rowhelper to the server edit screen for backend selection eliminating quite a number of needed configuration entries for common hosting items. --- config/haproxy/haproxy.inc | 29 +- config/haproxy/haproxy.xml | 6 +- config/haproxy/haproxy_backends.php | 149 ------- config/haproxy/haproxy_backends_edit.php | 625 ----------------------------- config/haproxy/haproxy_frontends.php | 149 +++++++ config/haproxy/haproxy_frontends_edit.php | 626 ++++++++++++++++++++++++++++++ config/haproxy/haproxy_global.php | 2 +- config/haproxy/haproxy_servers.php | 4 +- config/haproxy/haproxy_servers_edit.php | 216 +++++++++-- 9 files changed, 988 insertions(+), 818 deletions(-) delete mode 100755 config/haproxy/haproxy_backends.php delete mode 100755 config/haproxy/haproxy_backends_edit.php create mode 100755 config/haproxy/haproxy_frontends.php create mode 100755 config/haproxy/haproxy_frontends_edit.php (limited to 'config/haproxy') diff --git a/config/haproxy/haproxy.inc b/config/haproxy/haproxy.inc index 11fd3782..0dcacab3 100644 --- a/config/haproxy/haproxy.inc +++ b/config/haproxy/haproxy.inc @@ -147,7 +147,14 @@ function haproxy_configure() { fwrite ($fd, "{$backendinfo}"); fwrite ($fd, "{$listenip}"); - fwrite ($fd, "\tmode\t\t\t".$backend['type'] . "\n"); + + // https is an alias for tcp for clarity purpouses + if($backend['type'] == "https") + $backend = "tcp"; + else + $backend = $backend['type']; + + fwrite ($fd, "\tmode\t\t\t" . $backend . "\n"); fwrite ($fd, "\tlog\t\t\tglobal\n"); fwrite ($fd, "\toption\t\t\tdontlognull\n"); fwrite ($fd, "\toption\t\t\thttpclose\n"); @@ -197,15 +204,21 @@ function haproxy_configure() { foreach ($a_acl as $acl) fwrite ($fd, "\tacl\t\t\t".$acl['name']."\t\t".$acl['expression']."\n"); + $server['backend'] .= " "; if(is_array($a_servers)) { foreach ($a_servers as $server) { - if($server['backend']==$backend['name']) { - if($server['status']=='active') { - if($server['cookie']) - $cookie = " cookie {$server['cookie']} "; - else - $cookie = ""; - fwrite ($fd, "\tserver\t\t\t".$server['name']." ".$server['address'].":".$server['port']." $cookie "." check inter 1000 weight ".$server['weight']."\n"); + $backends_to_process = split(" ", $server['backend']); + foreach($backends_to_process as $backend) { + if($backend == "") + continue; + if($backend ==$backend['name']) { + if($server['status']=='active') { + if($server['cookie']) + $cookie = " cookie {$server['cookie']} "; + else + $cookie = ""; + fwrite ($fd, "\tserver\t\t\t".$server['name']." ".$server['address'].":".$server['port']." $cookie "." check inter 1000 weight ".$server['weight']."\n"); + } } } } diff --git a/config/haproxy/haproxy.xml b/config/haproxy/haproxy.xml index 6128f1ac..abfee4b6 100644 --- a/config/haproxy/haproxy.xml +++ b/config/haproxy/haproxy.xml @@ -50,7 +50,7 @@ HAProxy
Services
- /haproxy_backends.php + /haproxy_frontends.php HAProxy @@ -67,12 +67,12 @@ /usr/local/www/ 077 - http://www.pfsense.com/packages/config/haproxy/haproxy_backends.php + http://www.pfsense.com/packages/config/haproxy/haproxy_frontends.php /usr/local/www/ 077 - http://www.pfsense.com/packages/config/haproxy/haproxy_backends_edit.php + http://www.pfsense.com/packages/config/haproxy/haproxy_frontends_edit.php /usr/local/www/ diff --git a/config/haproxy/haproxy_backends.php b/config/haproxy/haproxy_backends.php deleted file mode 100755 index dacb9f35..00000000 --- a/config/haproxy/haproxy_backends.php +++ /dev/null @@ -1,149 +0,0 @@ - - Copyright (C) 2008 Remco Hoef - 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. -*/ - -require_once("guiconfig.inc"); - -$d_haproxyconfdirty_path = $g['varrun_path'] . "/haproxy.conf.dirty"; - -require_once("haproxy.inc"); - -if (!is_array($config['installedpackages']['haproxy']['ha_backends']['item'])) { - $config['installedpackages']['haproxy']['ha_backends']['item'] = array(); -} -$a_backend = &$config['installedpackages']['haproxy']['ha_backends']['item']; - -if ($_POST) { - $pconfig = $_POST; - - if ($_POST['apply']) { - $retval = 0; - config_lock(); - $retval = haproxy_configure(); - config_unlock(); - $savemsg = get_std_save_message($retval); - unlink_if_exists($d_haproxyconfdirty_path); - } -} - -if ($_GET['act'] == "del") { - if ($a_backend[$_GET['id']]) { - if (!$input_errors) { - unset($a_backend[$_GET['id']]); - write_config(); - touch($d_haproxyconfdirty_path); - header("Location: haproxy_backends.php"); - exit; - } - } -} - -$pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); -if(strstr($pfSversion, "1.2")) - $one_two = true; - -$pgtitle = "Services: HAProxy: Backends"; -include("head.inc"); - -?> - - -
- -

- - - -

-You must apply the changes in order for them to take effect.");?>
- - - - -
- -
-
- - - - - - - - - - - - - - - - - - - - - -
NameDescriptionStats URIType
- - - - - - - - - - - - - -
-
- - - - -
-
-
-
-

- - - diff --git a/config/haproxy/haproxy_backends_edit.php b/config/haproxy/haproxy_backends_edit.php deleted file mode 100755 index eb2e6c77..00000000 --- a/config/haproxy/haproxy_backends_edit.php +++ /dev/null @@ -1,625 +0,0 @@ - - Copyright (C) 2008 Remco Hoef - 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, 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. -*/ - -require("guiconfig.inc"); - -$d_haproxyconfdirty_path = $g['varrun_path'] . "/haproxy.conf.dirty"; - -if (!is_array($config['installedpackages']['haproxy']['ha_backends']['item'])) { - $config['installedpackages']['haproxy']['ha_backends']['item'] = array(); -} - -$a_backend = &$config['installedpackages']['haproxy']['ha_backends']['item']; - -if (isset($_POST['id'])) - $id = $_POST['id']; -else - $id = $_GET['id']; - -if (isset($id) && $a_backend[$id]) { - $pconfig['name'] = $a_backend[$id]['name']; - $pconfig['desc'] = $a_backend[$id]['desc']; - $pconfig['connection_timeout'] = $a_backend[$id]['connection_timeout']; - $pconfig['server_timeout'] = $a_backend[$id]['server_timeout']; - $pconfig['retries'] = $a_backend[$id]['retries']; - - $pconfig['type'] = $a_backend[$id]['type']; - $pconfig['balance'] = $a_backend[$id]['balance']; - $pconfig['monitor_uri'] = $a_backend[$id]['monitor_uri']; - - $pconfig['stats_enabled'] = $a_backend[$id]['stats_enabled']; - $pconfig['stats_username'] = $a_backend[$id]['stats_username']; - $pconfig['stats_password'] = $a_backend[$id]['stats_password']; - $pconfig['stats_uri'] = $a_backend[$id]['stats_uri']; - $pconfig['stats_realm'] = $a_backend[$id]['stats_realm']; - - $pconfig['type'] = $a_backend[$id]['type']; - $pconfig['extaddr'] = $a_backend[$id]['extaddr']; - $pconfig['max_connections'] = $a_backend[$id]['max_connections']; - $pconfig['client_timeout'] = $a_backend[$id]['client_timeout']; - $pconfig['stats_enabled'] = $a_backend[$id]['stats_enabled']; - $pconfig['stats_realm'] = $a_backend[$id]['stats_realm']; - $pconfig['stats_uri'] = $a_backend[$id]['stats_uri']; - $pconfig['stats_username'] = $a_backend[$id]['stats_username']; - $pconfig['stats_password'] = $a_backend[$id]['stats_password']; - $pconfig['port'] = $a_backend[$id]['port']; - $pconfig['a_acl']=&$a_backend[$id]['ha_acls']['item']; - -} - -$changedesc = "Services: HAProxy: Backends"; -$changecount = 0; - -if ($_POST) { - $changecount++; - - unset($input_errors); - $pconfig = $_POST; - - if ($_POST['stats_enabled']) { - $reqdfields = explode(" ", "name connection_timeout server_timeout retries stats_username stats_password stats_uri stats_realm"); - $reqdfieldsn = explode(",", "Name,Connection timeout,Server timeout,Retries,Stats Username,Stats Password,Stats Uri,Stats Realm"); - } else { - $reqdfields = explode(" ", "name connection_timeout server_timeout retries monitor_uri"); - $reqdfieldsn = explode(",", "Name,Connection timeout,Server timeout,Retries,Monitor Uri"); - } - - do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - - $reqdfields = explode(" ", "name type port max_connections client_timeout"); - $reqdfieldsn = explode(",", "Name,Type,Port,Max connections,Client timeout"); - - do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - - if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['name'])) - $input_errors[] = "The field 'Name' contains invalid characters."; - - if (!is_numeric($_POST['connection_timeout'])) - $input_errors[] = "The field 'Connection timeout' value is not a number."; - - if (!is_numeric($_POST['server_timeout'])) - $input_errors[] = "The field 'Server timeout' value is not a number."; - - if (!is_numeric($_POST['retries'])) - $input_errors[] = "The field 'Retries' value is not a number."; - - if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['stats_username'])) - $input_errors[] = "The field 'Stats Username' contains invalid characters."; - - if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['stats_password'])) - $input_errors[] = "The field 'Stats Password' contains invalid characters."; - - if (!is_numeric($_POST['max_connections'])) - $input_errors[] = "The field 'Max connections' value is not a number."; - - $ports = split(",", $_POST['port'] . ","); - foreach($ports as $port) - if ($port && !is_numeric($port)) - $input_errors[] = "The field 'Port' value is not a number."; - - if (!is_numeric($_POST['client_timeout'])) - $input_errors[] = "The field 'Client timeout' value is not a number."; - - /* Ensure that our pool names are unique */ - for ($i=0; isset($config['installedpackages']['haproxy']['ha_backends']['item'][$i]); $i++) - if (($_POST['name'] == $config['installedpackages']['haproxy']['ha_backends']['item'][$i]['name']) && ($i != $id)) - $input_errors[] = "This backend name has already been used. Backend names must be unique."; - - $a_acl=array(); - $acl_names=array(); - for($x=0; $x<99; $x++) { - $acl_name=$_POST['acl_name'.$x]; - $acl_expression=$_POST['acl_expression'.$x]; - - if ($acl_name) { - // check for duplicates - if (in_array($acl_name, $acl_names)) { - $input_errors[] = "The name '$acl_name' is duplicate."; - } - - $acl_names[]=$acl_name; - - $acl=array(); - $acl['name']=$acl_name; - $acl['expression']=$acl_expression; - $a_acl[]=$acl; - - if (preg_match("/[^a-zA-Z0-9\.\-_]/", $acl_name)) - $input_errors[] = "The field 'Name' contains invalid characters."; - - if (!preg_match("/.{2,}/", $acl_expression)) - $input_errors[] = "The field 'Expression' is required."; - - if (!preg_match("/.{2,}/", $acl_name)) - $input_errors[] = "The field 'Name' is required."; - - } - } - - $pconfig['a_acl']=$a_acl; - - if (!$input_errors) { - $backend = array(); - if(isset($id) && $a_backend[$id]) - $backend = $a_backend[$id]; - - if($backend['name'] != "") - $changedesc .= " modified '{$backend['name']}' pool:"; - - if ($backend['name']!=$_POST['name']) { - // name changed: - // * update servers - // * update frontend (default backend and acl) - if (!is_array($config['installedpackages']['haproxy']['ha_servers']['item'])) { - $config['installedpackages']['haproxy']['ha_servers']['item'] = array(); - } - $a_server = &$config['installedpackages']['haproxy']['ha_servers']['item']; - - for ( $i = 0; $i < count($a_server); $i++) { - if ($a_server[$i]['backend']==$backend['name']) { - $a_server[$i]['backend']=$_POST['name']; - } - } - - if (!is_array($config['installedpackages']['haproxy']['ha_frontends']['item'])) { - $config['installedpackages']['haproxy']['ha_frontends']['item'] = array(); - } - $a_frontend = &$config['installedpackages']['haproxy']['ha_frontends']['item']; - - for ( $i = 0; $i < count($a_frontend); $i++) { - if ($a_frontend[$i]['backend']==$backend['name']) { - $a_frontend[$i]['backend']=$_POST['name']; - } - - if (!is_array($a_frontend[$i]['ha_acls']['item'])) { - $a_frontend[$i]['ha_acls']['item'] = array(); - } - - $a_acl = &$a_frontend[$i]['ha_acls']['item']; - for ( $j = 0; $j < count($a_acl); $j++) { - if ($a_acl[$j]['backend']==$backend['name']) { - $a_acl[$j]['backend']=$_POST['name']; - } - } - } - } - - update_if_changed("name", $backend['name'], $_POST['name']); - update_if_changed("description", $backend['desc'], $_POST['desc']); - update_if_changed("connection_timeout", $backend['connection_timeout'], $_POST['connection_timeout']); - update_if_changed("server_timeout", $backend['server_timeout'], $_POST['server_timeout']); - update_if_changed("retries", $backend['retries'], $_POST['retries']); - update_if_changed("type", $backend['type'], $_POST['type']); - update_if_changed("balance", $backend['balance'], $_POST['balance']); - update_if_changed("cookie_name", $backend['cookie_name'], $_POST['cookie_name']); - update_if_changed("monitor_uri", $backend['monitor_uri'], $_POST['monitor_uri']); - update_if_changed("stats_enabled", $backend['stats_enabled'], $_POST['stats_enabled']); - update_if_changed("stats_username", $backend['stats_username'], $_POST['stats_username']); - update_if_changed("stats_password", $backend['stats_password'], $_POST['stats_password']); - update_if_changed("stats_uri", $backend['stats_uri'], $_POST['stats_uri']); - update_if_changed("stats_realm", $backend['stats_realm'], $_POST['stats_realm']); - update_if_changed("type", $backend['type'], $_POST['type']); - update_if_changed("port", $backend['port'], $_POST['port']); - update_if_changed("extaddr", $backend['extaddr'], $_POST['extaddr']); - update_if_changed("max_connections", $backend['max_connections'], $_POST['max_connections']); - update_if_changed("client_timeout", $backend['client_timeout'], $_POST['client_timeout']); - - $backend['ha_acls']['item']=$a_acl; - - if (isset($id) && $a_backend[$id]) { - $a_backend[$id] = $backend; - } else { - $a_backend[] = $backend; - } - - if ($changecount > 0) { - touch($d_haproxyconfdirty_path); - write_config($changedesc); - } - - header("Location: haproxy_backends.php"); - exit; - } -} - -$pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); -if(strstr($pfSversion, "1.2")) - $one_two = true; - -$pgtitle = "HAProxy: Backend: Edit"; -include("head.inc"); - -?> - - - - - - -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - > - - - - > - - - - - > - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ -?> - - - - - -
 
- - -
Edit haproxy backend
Name - size="25" maxlength="25"> -
Description - size="64"> -
Connection timeout - size="64"> -
the time (in milliseconds) we give up if the connection does not complete within (30000).
-
Server timeout - size="64"> -
the time (in milliseconds) we accept to wait for data from the server, or for the server to accept data (30000).
-
Retries - size="64"> -
After a connection failure to a server, it is possible to retry, potentially -on another server. This is useful if health-checks are too rare and you don't -want the clients to see the failures. The number of attempts to reconnect is -set by the 'retries' parameter (2).
-
Type - -
Balance - - - - - - - -
- >Round robin - - Each server is used in turns, according to their weights. - This is the smoothest and fairest algorithm when the server's - processing time remains equally distributed. This algorithm - is dynamic, which means that server weights may be adjusted - on the fly for slow starts for instance. -
>Source - The source IP address is hashed and divided by the total - weight of the running servers to designate which server will - receive the request. This ensures that the same client IP - address will always reach the same server as long as no - server goes down or up. If the hash result changes due to the - number of running servers changing, many clients will be - directed to a different server. This algorithm is generally - used in TCP mode where no cookie may be inserted. It may also - be used on the Internet to provide a best-effort stickyness - to clients which refuse session cookies. This algorithm is - static, which means that changing a server's weight on the - fly will have no effect. -
-
Stats Enabled - onclick='toggle_stats();'>
- EXAMPLE: haproxystats -
Stats Realm - size="64"> -
Stats Uri - size="64">
- EXAMPLE: /haproxy?stats -
Stats Username - size="64"> -
Stats Password - size="64"> -
-
Monitor Uri - size="50" maxlength="50"> -
- Example: / or /index.php or /index.html or /testmypage.cgi -
Port - size="10" maxlength="10"> -
The port to listen to. To specify multiple ports, separate with a comma (,). EXAMPLE: 80,443
-
External address - -
- - If you want this rule to apply to another IP address than the IP address of the interface chosen above, - select it here (you need to define Virtual IP addresses on the first). - Also note that if you are trying to redirect connections on the LAN select the "any" option. - -
Max connections - size="10" maxlength="10"> -
Client timeout - size="10" maxlength="10"> -
the time (in milliseconds) we accept to wait for data from the client, or for the client to accept data (30000).
-
Access Control lists - - - - - - - - - - - - - - - -
NameExpressionBackend
- -
- - -
- Fore more information about ACL's please see HAProxy Documentation Section 7 - Using ACL's -
  - - - - -
- NOTE: You must add a firewall rule permitting access to this backend! -
-
-
- - - - diff --git a/config/haproxy/haproxy_frontends.php b/config/haproxy/haproxy_frontends.php new file mode 100755 index 00000000..1dcc0483 --- /dev/null +++ b/config/haproxy/haproxy_frontends.php @@ -0,0 +1,149 @@ + + Copyright (C) 2008 Remco Hoef + 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. +*/ + +require_once("guiconfig.inc"); + +$d_haproxyconfdirty_path = $g['varrun_path'] . "/haproxy.conf.dirty"; + +require_once("haproxy.inc"); + +if (!is_array($config['installedpackages']['haproxy']['ha_backends']['item'])) { + $config['installedpackages']['haproxy']['ha_backends']['item'] = array(); +} +$a_backend = &$config['installedpackages']['haproxy']['ha_backends']['item']; + +if ($_POST) { + $pconfig = $_POST; + + if ($_POST['apply']) { + $retval = 0; + config_lock(); + $retval = haproxy_configure(); + config_unlock(); + $savemsg = get_std_save_message($retval); + unlink_if_exists($d_haproxyconfdirty_path); + } +} + +if ($_GET['act'] == "del") { + if ($a_backend[$_GET['id']]) { + if (!$input_errors) { + unset($a_backend[$_GET['id']]); + write_config(); + touch($d_haproxyconfdirty_path); + header("Location: haproxy_frontends.php"); + exit; + } + } +} + +$pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); +if(strstr($pfSversion, "1.2")) + $one_two = true; + +$pgtitle = "Services: HAProxy: Frontend"; +include("head.inc"); + +?> + + +
+ +

+ + + +

+You must apply the changes in order for them to take effect.");?>
+ + + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + +
NameDescriptionStats URIType
+ + + + + + + + + + + + + +
+
+ + + + +
+
+
+
+

+ + + diff --git a/config/haproxy/haproxy_frontends_edit.php b/config/haproxy/haproxy_frontends_edit.php new file mode 100755 index 00000000..e169b25e --- /dev/null +++ b/config/haproxy/haproxy_frontends_edit.php @@ -0,0 +1,626 @@ + + Copyright (C) 2008 Remco Hoef + 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, 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. +*/ + +require("guiconfig.inc"); + +$d_haproxyconfdirty_path = $g['varrun_path'] . "/haproxy.conf.dirty"; + +if (!is_array($config['installedpackages']['haproxy']['ha_backends']['item'])) { + $config['installedpackages']['haproxy']['ha_backends']['item'] = array(); +} + +$a_backend = &$config['installedpackages']['haproxy']['ha_backends']['item']; + +if (isset($_POST['id'])) + $id = $_POST['id']; +else + $id = $_GET['id']; + +if (isset($id) && $a_backend[$id]) { + $pconfig['name'] = $a_backend[$id]['name']; + $pconfig['desc'] = $a_backend[$id]['desc']; + $pconfig['connection_timeout'] = $a_backend[$id]['connection_timeout']; + $pconfig['server_timeout'] = $a_backend[$id]['server_timeout']; + $pconfig['retries'] = $a_backend[$id]['retries']; + + $pconfig['type'] = $a_backend[$id]['type']; + $pconfig['balance'] = $a_backend[$id]['balance']; + $pconfig['monitor_uri'] = $a_backend[$id]['monitor_uri']; + + $pconfig['stats_enabled'] = $a_backend[$id]['stats_enabled']; + $pconfig['stats_username'] = $a_backend[$id]['stats_username']; + $pconfig['stats_password'] = $a_backend[$id]['stats_password']; + $pconfig['stats_uri'] = $a_backend[$id]['stats_uri']; + $pconfig['stats_realm'] = $a_backend[$id]['stats_realm']; + + $pconfig['type'] = $a_backend[$id]['type']; + $pconfig['extaddr'] = $a_backend[$id]['extaddr']; + $pconfig['max_connections'] = $a_backend[$id]['max_connections']; + $pconfig['client_timeout'] = $a_backend[$id]['client_timeout']; + $pconfig['stats_enabled'] = $a_backend[$id]['stats_enabled']; + $pconfig['stats_realm'] = $a_backend[$id]['stats_realm']; + $pconfig['stats_uri'] = $a_backend[$id]['stats_uri']; + $pconfig['stats_username'] = $a_backend[$id]['stats_username']; + $pconfig['stats_password'] = $a_backend[$id]['stats_password']; + $pconfig['port'] = $a_backend[$id]['port']; + $pconfig['a_acl']=&$a_backend[$id]['ha_acls']['item']; + +} + +$changedesc = "Services: HAProxy: Frontend"; +$changecount = 0; + +if ($_POST) { + $changecount++; + + unset($input_errors); + $pconfig = $_POST; + + if ($_POST['stats_enabled']) { + $reqdfields = explode(" ", "name connection_timeout server_timeout retries stats_username stats_password stats_uri stats_realm"); + $reqdfieldsn = explode(",", "Name,Connection timeout,Server timeout,Retries,Stats Username,Stats Password,Stats Uri,Stats Realm"); + } else { + $reqdfields = explode(" ", "name connection_timeout server_timeout retries monitor_uri"); + $reqdfieldsn = explode(",", "Name,Connection timeout,Server timeout,Retries,Monitor Uri"); + } + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + $reqdfields = explode(" ", "name type port max_connections client_timeout"); + $reqdfieldsn = explode(",", "Name,Type,Port,Max connections,Client timeout"); + + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['name'])) + $input_errors[] = "The field 'Name' contains invalid characters."; + + if (!is_numeric($_POST['connection_timeout'])) + $input_errors[] = "The field 'Connection timeout' value is not a number."; + + if (!is_numeric($_POST['server_timeout'])) + $input_errors[] = "The field 'Server timeout' value is not a number."; + + if (!is_numeric($_POST['retries'])) + $input_errors[] = "The field 'Retries' value is not a number."; + + if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['stats_username'])) + $input_errors[] = "The field 'Stats Username' contains invalid characters."; + + if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['stats_password'])) + $input_errors[] = "The field 'Stats Password' contains invalid characters."; + + if (!is_numeric($_POST['max_connections'])) + $input_errors[] = "The field 'Max connections' value is not a number."; + + $ports = split(",", $_POST['port'] . ","); + foreach($ports as $port) + if ($port && !is_numeric($port)) + $input_errors[] = "The field 'Port' value is not a number."; + + if (!is_numeric($_POST['client_timeout'])) + $input_errors[] = "The field 'Client timeout' value is not a number."; + + /* Ensure that our pool names are unique */ + for ($i=0; isset($config['installedpackages']['haproxy']['ha_backends']['item'][$i]); $i++) + if (($_POST['name'] == $config['installedpackages']['haproxy']['ha_backends']['item'][$i]['name']) && ($i != $id)) + $input_errors[] = "This backend name has already been used. Frontend names must be unique."; + + $a_acl=array(); + $acl_names=array(); + for($x=0; $x<99; $x++) { + $acl_name=$_POST['acl_name'.$x]; + $acl_expression=$_POST['acl_expression'.$x]; + + if ($acl_name) { + // check for duplicates + if (in_array($acl_name, $acl_names)) { + $input_errors[] = "The name '$acl_name' is duplicate."; + } + + $acl_names[]=$acl_name; + + $acl=array(); + $acl['name']=$acl_name; + $acl['expression']=$acl_expression; + $a_acl[]=$acl; + + if (preg_match("/[^a-zA-Z0-9\.\-_]/", $acl_name)) + $input_errors[] = "The field 'Name' contains invalid characters."; + + if (!preg_match("/.{2,}/", $acl_expression)) + $input_errors[] = "The field 'Expression' is required."; + + if (!preg_match("/.{2,}/", $acl_name)) + $input_errors[] = "The field 'Name' is required."; + + } + } + + $pconfig['a_acl']=$a_acl; + + if (!$input_errors) { + $backend = array(); + if(isset($id) && $a_backend[$id]) + $backend = $a_backend[$id]; + + if($backend['name'] != "") + $changedesc .= " modified '{$backend['name']}' pool:"; + + if ($backend['name']!=$_POST['name']) { + // name changed: + // * update servers + // * update frontend (default backend and acl) + if (!is_array($config['installedpackages']['haproxy']['ha_servers']['item'])) { + $config['installedpackages']['haproxy']['ha_servers']['item'] = array(); + } + $a_server = &$config['installedpackages']['haproxy']['ha_servers']['item']; + + for ( $i = 0; $i < count($a_server); $i++) { + if ($a_server[$i]['backend']==$backend['name']) { + $a_server[$i]['backend']=$_POST['name']; + } + } + + if (!is_array($config['installedpackages']['haproxy']['ha_frontends']['item'])) { + $config['installedpackages']['haproxy']['ha_frontends']['item'] = array(); + } + $a_frontend = &$config['installedpackages']['haproxy']['ha_frontends']['item']; + + for ( $i = 0; $i < count($a_frontend); $i++) { + if ($a_frontend[$i]['backend']==$backend['name']) { + $a_frontend[$i]['backend']=$_POST['name']; + } + + if (!is_array($a_frontend[$i]['ha_acls']['item'])) { + $a_frontend[$i]['ha_acls']['item'] = array(); + } + + $a_acl = &$a_frontend[$i]['ha_acls']['item']; + for ( $j = 0; $j < count($a_acl); $j++) { + if ($a_acl[$j]['backend']==$backend['name']) { + $a_acl[$j]['backend']=$_POST['name']; + } + } + } + } + + update_if_changed("name", $backend['name'], $_POST['name']); + update_if_changed("description", $backend['desc'], $_POST['desc']); + update_if_changed("connection_timeout", $backend['connection_timeout'], $_POST['connection_timeout']); + update_if_changed("server_timeout", $backend['server_timeout'], $_POST['server_timeout']); + update_if_changed("retries", $backend['retries'], $_POST['retries']); + update_if_changed("type", $backend['type'], $_POST['type']); + update_if_changed("balance", $backend['balance'], $_POST['balance']); + update_if_changed("cookie_name", $backend['cookie_name'], $_POST['cookie_name']); + update_if_changed("monitor_uri", $backend['monitor_uri'], $_POST['monitor_uri']); + update_if_changed("stats_enabled", $backend['stats_enabled'], $_POST['stats_enabled']); + update_if_changed("stats_username", $backend['stats_username'], $_POST['stats_username']); + update_if_changed("stats_password", $backend['stats_password'], $_POST['stats_password']); + update_if_changed("stats_uri", $backend['stats_uri'], $_POST['stats_uri']); + update_if_changed("stats_realm", $backend['stats_realm'], $_POST['stats_realm']); + update_if_changed("type", $backend['type'], $_POST['type']); + update_if_changed("port", $backend['port'], $_POST['port']); + update_if_changed("extaddr", $backend['extaddr'], $_POST['extaddr']); + update_if_changed("max_connections", $backend['max_connections'], $_POST['max_connections']); + update_if_changed("client_timeout", $backend['client_timeout'], $_POST['client_timeout']); + + $backend['ha_acls']['item']=$a_acl; + + if (isset($id) && $a_backend[$id]) { + $a_backend[$id] = $backend; + } else { + $a_backend[] = $backend; + } + + if ($changecount > 0) { + touch($d_haproxyconfdirty_path); + write_config($changedesc); + } + + header("Location: haproxy_frontends.php"); + exit; + } +} + +$pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); +if(strstr($pfSversion, "1.2")) + $one_two = true; + +$pgtitle = "HAProxy: Frontend: Edit"; +include("head.inc"); + +?> + + + + + + +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + > + + + + > + + + + > + + + + + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + +*/ +?> + + + + + +
 
+ + +
Edit haproxy backend
Name + size="25" maxlength="25"> +
Description + size="64"> +
Connection timeout + size="64"> +
the time (in milliseconds) we give up if the connection does not complete within (30000).
+
Server timeout + size="64"> +
the time (in milliseconds) we accept to wait for data from the server, or for the server to accept data (30000).
+
Retries + size="64"> +
After a connection failure to a server, it is possible to retry, potentially +on another server. This is useful if health-checks are too rare and you don't +want the clients to see the failures. The number of attempts to reconnect is +set by the 'retries' parameter (2).
+
Type + +
Balance + + + + + + + +
+ >Round robin + + Each server is used in turns, according to their weights. + This is the smoothest and fairest algorithm when the server's + processing time remains equally distributed. This algorithm + is dynamic, which means that server weights may be adjusted + on the fly for slow starts for instance. +
>Source + The source IP address is hashed and divided by the total + weight of the running servers to designate which server will + receive the request. This ensures that the same client IP + address will always reach the same server as long as no + server goes down or up. If the hash result changes due to the + number of running servers changing, many clients will be + directed to a different server. This algorithm is generally + used in TCP mode where no cookie may be inserted. It may also + be used on the Internet to provide a best-effort stickyness + to clients which refuse session cookies. This algorithm is + static, which means that changing a server's weight on the + fly will have no effect. +
+
Stats Enabled + onclick='toggle_stats();'>
+ EXAMPLE: haproxystats +
Stats Realm + size="64"> +
Stats Uri + size="64">
+ EXAMPLE: /haproxy?stats +
Stats Username + size="64"> +
Stats Password + size="64"> +
+
Monitor Uri + size="50" maxlength="50"> +
+ Example: / or /index.php or /index.html or /testmypage.cgi +
Port + size="10" maxlength="10"> +
The port to listen to. To specify multiple ports, separate with a comma (,). EXAMPLE: 80,443
+
External address + +
+ + If you want this rule to apply to another IP address than the IP address of the interface chosen above, + select it here (you need to define Virtual IP addresses on the first). + Also note that if you are trying to redirect connections on the LAN select the "any" option. + +
Max connections + size="10" maxlength="10"> +
Client timeout + size="10" maxlength="10"> +
the time (in milliseconds) we accept to wait for data from the client, or for the client to accept data (30000).
+
Access Control lists + + + + + + + + + + + + + + + +
NameExpressionBackend
+ +
+ + +
+ Fore more information about ACL's please see HAProxy Documentation Section 7 - Using ACL's +
  + + + + +
+ NOTE: You must add a firewall rule permitting access to this frontend! +
+
+
+ + + + diff --git a/config/haproxy/haproxy_global.php b/config/haproxy/haproxy_global.php index e5f37cb5..20dc47a2 100755 --- a/config/haproxy/haproxy_global.php +++ b/config/haproxy/haproxy_global.php @@ -125,7 +125,7 @@ function enable_change(enable_change) { /* active tabs */ $tab_array = array(); $tab_array[] = array("Settings", true, "haproxy_global.php"); - $tab_array[] = array("Frontends/Backends", false, "haproxy_backends.php"); + $tab_array[] = array("Frontends", false, "haproxy_frontends.php"); $tab_array[] = array("Servers", false, "haproxy_servers.php"); display_top_tabs($tab_array); ?> diff --git a/config/haproxy/haproxy_servers.php b/config/haproxy/haproxy_servers.php index 4dffadca..3bf4eac2 100755 --- a/config/haproxy/haproxy_servers.php +++ b/config/haproxy/haproxy_servers.php @@ -68,7 +68,7 @@ $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); if(strstr($pfSversion, "1.2")) $one_two = true; -$pgtitle = "Services: HAProxy: Backends"; +$pgtitle = "Services: HAProxy: Servers"; include("head.inc"); ?> @@ -89,7 +89,7 @@ include("head.inc"); /* active tabs */ $tab_array = array(); $tab_array[] = array("Settings", false, "haproxy_global.php"); - $tab_array[] = array("Frontends/Backends", false, "haproxy_backends.php"); + $tab_array[] = array("Frontends", false, "haproxy_frontends.php"); $tab_array[] = array("Servers", true, "haproxy_servers.php"); display_top_tabs($tab_array); ?> diff --git a/config/haproxy/haproxy_servers_edit.php b/config/haproxy/haproxy_servers_edit.php index b2053f4a..a265353d 100755 --- a/config/haproxy/haproxy_servers_edit.php +++ b/config/haproxy/haproxy_servers_edit.php @@ -32,6 +32,7 @@ require("guiconfig.inc"); $d_haproxyconfdirty_path = $g['varrun_path'] . "/haproxy.conf.dirty"; +$a_backend = &$config['installedpackages']['haproxy']['ha_backends']['item']; if (!is_array($config['installedpackages']['haproxy']['ha_servers']['item'])) { $config['installedpackages']['haproxy']['ha_servers']['item'] = array(); @@ -63,8 +64,8 @@ if ($_POST) { unset($input_errors); $pconfig = $_POST; - $reqdfields = explode(" ", "name address port backend weight"); - $reqdfieldsn = explode(",", "Name,Address,Port,Backend,Weight"); + $reqdfields = explode(" ", "name address port weight"); + $reqdfieldsn = explode(",", "Name,Address,Port,Weight"); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); @@ -96,6 +97,15 @@ if ($_POST) { if (($_POST['name'] == $config['installedpackages']['haproxy']['ha_servers']['item'][$i]['name']) && ($i != $id)) $input_errors[] = "This server name has already been used. Server names must be unique."; + $backend = ""; + for($x=0; $x<299; $x++) { + $comd = "\$backends = \$_POST['backend" . $x . "'];"; + eval($comd); + if($backends) + $backend .= "$backends "; + } + $backend = trim($backend); + if (!$input_errors) { $server = array(); if(isset($id) && $a_server[$id]) @@ -103,14 +113,14 @@ if ($_POST) { if($server['name'] != "") $changedesc .= " modified '{$server['name']}' pool:"; - + update_if_changed("name", $server['name'], $_POST['name']); - update_if_changed("address", $server['address'], $_POST['address']); update_if_changed("port", $server['port'], $_POST['port']); - update_if_changed("backend", $server['backend'], $_POST['backend']); + update_if_changed("backend", $server['backend'], $backend); update_if_changed("cookie", $server['cookie'], $_POST['cookie']); update_if_changed("weight", $server['weight'], $_POST['weight']); update_if_changed("status", $server['status'], $_POST['status']); + update_if_changed("address", $server['address'], $_POST['address']); if (isset($id) && $a_server[$id]) { $a_server[$id] = $server; @@ -140,8 +150,12 @@ if(strstr($pfSversion, "1.2")) $pgtitle = "HAProxy: Server: Edit"; include("head.inc"); +row_helper(); + ?> + + @@ -153,7 +167,11 @@ function clearcombo(){ document.iform.serversSelect.selectedIndex = -1; } - + @@ -162,7 +180,7 @@ function clearcombo(){
- + @@ -171,10 +189,68 @@ function clearcombo(){ - - + + + + + + @@ -182,25 +258,6 @@ function clearcombo(){ size="5"> - - - -
Edit haproxy serverEdit HAProxy server
Name
Address - size="64"> - Frontend(s) + + + + + + 0) + $tracker = $counter + 1; + ?> + + + + + + + + +
+ + + 0) + echo ""; + ?> +
+ + + +
+
+ IP Address +
+
+ +
Port
Backend - -
-
Status @@ -249,5 +306,104 @@ function clearcombo(){
+ + +"; + $options .= $backend['name']; + $options .= ""; + } + + echo << +// Global Variables +var rowname = new Array(99); +var rowtype = new Array(99); +var newrow = new Array(99); +var rowsize = new Array(99); + +for (i = 0; i < 99; i++) { + rowname[i] = ''; + rowtype[i] = ''; + newrow[i] = ''; + rowsize[i] = '25'; +} + +var field_counter_js = 0; +var loaded = 0; +var is_streaming_progress_bar = 0; +var temp_streaming_text = ""; + +var addRowTo = (function() { + return (function (tableId) { + var d, tbody, tr, td, bgc, i, ii, j; + d = document; + tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0); + tr = d.createElement("tr"); + totalrows++; + for (i = 0; i < field_counter_js; i++) { + td = d.createElement("td"); + if(rowtype[i] == 'textbox') { + td.innerHTML=" "; + } else if(rowtype[i] == 'select') { + td.innerHTML=" "; + } else { + td.innerHTML=" "; + } + tr.appendChild(td); + } + td = d.createElement("td"); + td.rowSpan = "1"; + + td.innerHTML = ''; + tr.appendChild(td); + tbody.appendChild(tr); + }); +})(); + +function removeRow(el) { + var cel; + while (el && el.nodeName.toLowerCase() != "tr") + el = el.parentNode; + + if (el && el.parentNode) { + cel = el.getElementsByTagName("td").item(0); + el.parentNode.removeChild(el); + } +} + +function find_unique_field_name(field_name) { + // loop through field_name and strip off -NUMBER + var last_found_dash = 0; + for (var i = 0; i < field_name.length; i++) { + // is this a dash, if so, update + // last_found_dash + if (field_name.substr(i,1) == "-" ) + last_found_dash = i; + } + if (last_found_dash < 1) + return field_name; + return(field_name.substr(0,last_found_dash)); +} + + +EOF; + +} + +?> \ No newline at end of file -- cgit v1.2.3