From 51f497343aaff857e82115a27db9010435a43105 Mon Sep 17 00:00:00 2001 From: thompsa Date: Sun, 7 Feb 2010 23:41:35 +1300 Subject: Add server pools which encapsulate the backends. --- config/haproxy-dev/haproxy.inc | 72 ++--- config/haproxy-dev/haproxy.xml | 12 +- config/haproxy-dev/haproxy_global.php | 4 +- config/haproxy-dev/haproxy_listeners.php | 28 +- config/haproxy-dev/haproxy_listeners_edit.php | 28 +- config/haproxy-dev/haproxy_pool_edit.php | 270 +++++++--------- config/haproxy-dev/haproxy_pools.php | 92 +++--- config/haproxy-dev/haproxy_servers_edit.php | 431 -------------------------- 8 files changed, 226 insertions(+), 711 deletions(-) delete mode 100755 config/haproxy-dev/haproxy_servers_edit.php diff --git a/config/haproxy-dev/haproxy.inc b/config/haproxy-dev/haproxy.inc index 2d7b671f..4ab000da 100644 --- a/config/haproxy-dev/haproxy.inc +++ b/config/haproxy-dev/haproxy.inc @@ -101,8 +101,7 @@ function haproxy_configure() { $a_global = &$config['installedpackages']['haproxy']; $a_backends = &$config['installedpackages']['haproxy']['ha_backends']['item']; - $a_frontends = &$config['installedpackages']['haproxy']['ha_frontends']['item']; - $a_servers = &$config['installedpackages']['haproxy']['ha_servers']['item']; + $a_pools = &$config['installedpackages']['haproxy']['ha_pools']['item']; $fd = fopen("{$g['varetc_path']}/haproxy.cfg", "w"); @@ -170,7 +169,7 @@ function haproxy_configure() { $httpchk = "httpchk"; } - fwrite ($fd, "\tmode\t\t\t" . $backend_type . "\n"); + fwrite ($fd, "\tmode\t\t\t" . $backend_type . "\n"); fwrite ($fd, "\tlog\t\t\tglobal\n"); fwrite ($fd, "\toption\t\t\tdontlognull\n"); @@ -198,11 +197,6 @@ function haproxy_configure() { if($backend['retries']) fwrite ($fd, "\tretries\t\t\t" . $backend['retries'] . "\n"); - if($backend['cookie_name']) - fwrite ($fd, "\tcookie\t\t\t" . $backend['cookie_name'] . " insert indirect\n"); - - fwrite ($fd, "\toption\t\t\t{$httpchk} HEAD " . $backend['monitor_uri'] . " HTTP/1.0\n"); - if($backend['stats_enabled']=='yes') { fwrite ($fd, "\tstats\t\t\tenable\n"); if($backend['stats_uri']) @@ -245,40 +239,34 @@ function haproxy_configure() { fwrite ($fd, "\tacl\t\t\t".$acl['name']."\t".$expr."\n"); } - $server['backend'] .= " "; - if(is_array($a_servers)) { - foreach ($a_servers as $server) { - $backends_to_process = split(" ", $server['backend']); - foreach($backends_to_process as $backends) { - if($backends == "") - continue; - if($backends == $backend['name']) { - $server_ports = array(); - if($server['status']=='active') { - if($server['cookie']) - $cookie = " cookie {$server['cookie']} "; - else - $cookie = ""; - if(!$server['port']) { - foreach($ports as $port) { - if($port) - $server_ports[] = $port; - } - } else { - $server_ports[] = $server['port']; - } - if($server['advanced']) { - $advanced = base64_decode($server['advanced']); - $advanced_txt = " " . $advanced; - } else { - $advanced_txt = ""; - } - if($server['checkinter']) - $checkinter = "check inter {$server['checkinter']}"; - else - $checkinter = "check inter 1000"; - foreach($server_ports as $pport) - fwrite ($fd, "\tserver\t\t\t" . $server['name'] . " " . $server['address'].":" . $pport . " $cookie " . " $checkinter weight " . $server['weight'] . "{$advanced_txt}\n"); + if (is_array($a_pools)) { + foreach ($a_pools as $pool) { + if ($backend['pool'] == $pool['name'] && is_array($pool['ha_servers']['item'])) { + if($pool['status']=='active') { + if($pool['cookie_name']) + fwrite ($fd, "\tcookie\t\t\t" . $pool['cookie_name'] . " insert indirect\n"); + + fwrite ($fd, "\toption\t\t\t{$httpchk} HEAD " . $pool['monitor_uri'] . " HTTP/1.0\n"); + + if($pool['cookie']) + $cookie = " cookie {$pool['cookie']} "; + else + $cookie = ""; + if($pool['advanced']) { + $advanced = base64_decode($pool['advanced']); + $advanced_txt = " " . $advanced; + } else { + $advanced_txt = ""; + } + if($pool['checkinter']) + $checkinter = "check inter {$pool['checkinter']}"; + else + $checkinter = "check inter 1000"; + $a_servers = &$pool['ha_servers']['item']; + foreach($a_servers as $be) { + if(!$be['port']) + $be['port'] = $backend['port']; + fwrite ($fd, "\tserver\t\t\t" . $be['address'] . " " . $be['address'].":" . $be['port'] . " $cookie " . " $checkinter weight " . $be['weight'] . "{$advanced_txt}\n"); } } } diff --git a/config/haproxy-dev/haproxy.xml b/config/haproxy-dev/haproxy.xml index f0e13a27..04c1c0bc 100644 --- a/config/haproxy-dev/haproxy.xml +++ b/config/haproxy-dev/haproxy.xml @@ -44,13 +44,13 @@ haproxy 1.0 HAProxy - /pkg_ediwt.php?xml=haproxy_servers.php + /pkg_ediwt.php?xml=haproxy_pools.php /usr/local/pkg/haproxy.inc HAProxy
Services
- /haproxy_frontends.php + /haproxy_listeners.php
HAProxy @@ -67,12 +67,12 @@ /usr/local/www/ 077 - http://www.pfsense.com/packages/config/haproxy-dev/haproxy_frontends.php + http://www.pfsense.com/packages/config/haproxy-dev/haproxy_listeners.php /usr/local/www/ 077 - http://www.pfsense.com/packages/config/haproxy-dev/haproxy_frontends_edit.php + http://www.pfsense.com/packages/config/haproxy-dev/haproxy_listeners_edit.php /usr/local/www/ @@ -82,12 +82,12 @@ /usr/local/www/ 077 - http://www.pfsense.com/packages/config/haproxy-dev/haproxy_servers.php + http://www.pfsense.com/packages/config/haproxy-dev/haproxy_pools.php /usr/local/www/ 077 - http://www.pfsense.com/packages/config/haproxy-dev/haproxy_servers_edit.php + http://www.pfsense.com/packages/config/haproxy-dev/haproxy_pool_edit.php diff --git a/config/haproxy-dev/haproxy_global.php b/config/haproxy-dev/haproxy_global.php index dddb0413..9de45fdb 100755 --- a/config/haproxy-dev/haproxy_global.php +++ b/config/haproxy-dev/haproxy_global.php @@ -133,8 +133,8 @@ function enable_change(enable_change) { /* active tabs */ $tab_array = array(); $tab_array[] = array("Settings", true, "haproxy_global.php"); - $tab_array[] = array("Listener", false, "haproxy_frontends.php"); - $tab_array[] = array("Server Pool", false, "haproxy_servers.php"); + $tab_array[] = array("Listener", false, "haproxy_listeners.php"); + $tab_array[] = array("Server Pool", false, "haproxy_pools.php"); display_top_tabs($tab_array); ?> diff --git a/config/haproxy-dev/haproxy_listeners.php b/config/haproxy-dev/haproxy_listeners.php index 87efb87f..3a8d6701 100755 --- a/config/haproxy-dev/haproxy_listeners.php +++ b/config/haproxy-dev/haproxy_listeners.php @@ -54,14 +54,14 @@ if ($_POST) { } if ($_GET['act'] == "del") { - if ($a_backend[$_GET['id']]) { + if (isset($a_backend[$_GET['id']])) { if (!$input_errors) { unset($a_backend[$_GET['id']]); write_config(); touch($d_haproxyconfdirty_path); - header("Location: haproxy_frontends.php"); - exit; } + header("Location: haproxy_listeners.php"); + exit; } } @@ -75,7 +75,7 @@ include("head.inc"); ?> -
+

@@ -90,8 +90,8 @@ include("head.inc"); /* active tabs */ $tab_array = array(); $tab_array[] = array("Settings", false, "haproxy_global.php"); - $tab_array[] = array("Listener", true, "haproxy_frontends.php"); - $tab_array[] = array("Server Pool", false, "haproxy_servers.php"); + $tab_array[] = array("Listener", true, "haproxy_listeners.php"); + $tab_array[] = array("Server Pool", false, "haproxy_pools.php"); display_top_tabs($tab_array); ?> @@ -103,24 +103,28 @@ include("head.inc"); Name Description Type + Server pool - + - + - + + + + - - + +
@@ -131,7 +135,7 @@ include("head.inc"); - +
diff --git a/config/haproxy-dev/haproxy_listeners_edit.php b/config/haproxy-dev/haproxy_listeners_edit.php index c60415e3..91635260 100755 --- a/config/haproxy-dev/haproxy_listeners_edit.php +++ b/config/haproxy-dev/haproxy_listeners_edit.php @@ -1,7 +1,7 @@ Copyright (C) 2008 Remco Hoef @@ -38,6 +38,7 @@ if (!is_array($config['installedpackages']['haproxy']['ha_backends']['item'])) { } $a_backend = &$config['installedpackages']['haproxy']['ha_backends']['item']; +$a_pools = &$config['installedpackages']['haproxy']['ha_pools']['item']; $a_expr = array(); $a_expr[] = array("host_starts_with", "Host starts with:", "HTTP"); @@ -79,6 +80,7 @@ if (isset($id) && $a_backend[$id]) { $pconfig['type'] = $a_backend[$id]['type']; $pconfig['extaddr'] = $a_backend[$id]['extaddr']; + $pconfig['pool'] = $a_backend[$id]['pool']; $pconfig['max_connections'] = $a_backend[$id]['max_connections']; $pconfig['client_timeout'] = $a_backend[$id]['client_timeout']; $pconfig['port'] = $a_backend[$id]['port']; @@ -245,6 +247,7 @@ if ($_POST) { 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("pool", $backend['pool'], $_POST['pool']); update_if_changed("max_connections", $backend['max_connections'], $_POST['max_connections']); update_if_changed("client_timeout", $backend['client_timeout'], $_POST['client_timeout']); update_if_changed("advanced", $backend['advanced'], base64_encode($_POST['advanced'])); @@ -262,7 +265,7 @@ if ($_POST) { write_config($changedesc); } - header("Location: haproxy_frontends.php"); + header("Location: haproxy_listeners.php"); exit; } } @@ -384,7 +387,7 @@ include("head.inc");

- + @@ -449,8 +452,8 @@ include("head.inc"); - + - +
-
@@ -689,9 +692,8 @@ set by the 'retries' parameter (2). diff --git a/config/haproxy-dev/haproxy_pool_edit.php b/config/haproxy-dev/haproxy_pool_edit.php index 63f15741..9044e930 100755 --- a/config/haproxy-dev/haproxy_pool_edit.php +++ b/config/haproxy-dev/haproxy_pool_edit.php @@ -1,7 +1,7 @@ Copyright (C) 2008 Remco Hoef @@ -34,30 +34,28 @@ 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(); +if (!is_array($config['installedpackages']['haproxy']['ha_pools']['item'])) { + $config['installedpackages']['haproxy']['ha_pools']['item'] = array(); } -$a_server = &$config['installedpackages']['haproxy']['ha_servers']['item']; +$a_pools = &$config['installedpackages']['haproxy']['ha_pools']['item']; if (isset($_POST['id'])) $id = $_POST['id']; else $id = $_GET['id']; -if (isset($id) && $a_server[$id]) { - $pconfig['name'] = $a_server[$id]['name']; - $pconfig['address'] = $a_server[$id]['address']; - $pconfig['port'] = $a_server[$id]['port']; - $pconfig['backend'] = $a_server[$id]['backend']; - $pconfig['weight'] = $a_server[$id]['weight']; - $pconfig['checkinter'] = $a_server[$id]['checkinter']; - $pconfig['cookie'] = $a_server[$id]['cookie']; - $pconfig['status'] = $a_server[$id]['status']; - $pconfig['advanced'] = base64_decode($a_server[$id]['advanced']); +if (isset($id) && $a_pools[$id]) { + $pconfig['name'] = $a_pools[$id]['name']; + $pconfig['checkinter'] = $a_pools[$id]['checkinter']; + $pconfig['monitor_uri'] = $a_pools[$id]['monitor_uri']; + $pconfig['cookie'] = $a_pools[$id]['cookie']; + $pconfig['status'] = $a_pools[$id]['status']; + $pconfig['advanced'] = base64_decode($a_pools[$id]['advanced']); + $pconfig['a_servers']=&$a_pools[$id]['ha_servers']['item']; } -$changedesc = "Services: HAProxy: Servers: "; +$changedesc = "Services: HAProxy: pools: "; $changecount = 0; if ($_POST) { @@ -66,71 +64,62 @@ if ($_POST) { unset($input_errors); $pconfig = $_POST; - $reqdfields = explode(" ", "name address weight"); - $reqdfieldsn = explode(",", "Name,Address,Weight"); + $reqdfields = explode(" ", "name"); + $reqdfieldsn = explode(",", "Name"); 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 (preg_match("/[^a-zA-Z0-9\.]/", $_POST['address'])) - $input_errors[] = "The field 'Address' contains invalid characters."; + /* Ensure that our pool names are unique */ + for ($i=0; isset($config['installedpackages']['haproxy']['ha_pools']['item'][$i]); $i++) + if (($_POST['name'] == $config['installedpackages']['haproxy']['ha_pools']['item'][$i]['name']) && ($i != $id)) + $input_errors[] = "This pool name has already been used. Pool names must be unique."; - if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['cookie'])) - $input_errors[] = "The field 'Cookie' contains invalid characters."; + $a_servers=array(); + for($x=0; $x<99; $x++) { + $server_address=$_POST['server_address'.$x]; + $server_port=$_POST['server_port'.$x]; + $server_weight=$_POST['server_weight'.$x]; - if ($_POST['port'] && !is_numeric($_POST['port'])) - $input_errors[] = "The field 'Port' value is not a number."; - else { - if ($_POST['port']) - if (!($_POST['port']>=1 && $_POST['port']<=65535)) - $input_errors[] = "The field 'Port' value must be between 1 and 65535."; - } - - if (!is_numeric($_POST['weight'])) - $input_errors[] = "The field 'Weight' value is not a number."; - else { - if (!($_POST['weight']>=1 && $_POST['weight']<=256)) - $input_errors[] = "The field 'Weight' value must be between 1 and 256."; - } - - /* Ensure that our pool names are unique */ - for ($i=0; isset($config['installedpackages']['haproxy']['ha_servers']['item'][$i]); $i++) - 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 "; + if ($server_address) { + + $server=array(); + $server['address']=$server_address; + $server['port']=$server_port; + $server['weight']=$server_weight; + $a_servers[]=$server; + + if (preg_match("/[^a-zA-Z0-9\.\-_]/", $server_address)) + $input_errors[] = "The field 'Address' contains invalid characters."; + + if (!preg_match("/.{2,}/", $server_weight)) + $input_errors[] = "The field 'Weight' is required."; + + } } - $backend = trim($backend); if (!$input_errors) { - $server = array(); - if(isset($id) && $a_server[$id]) - $server = $a_server[$id]; + $pool = array(); + if(isset($id) && $a_pools[$id]) + $pool = $a_pools[$id]; - if($server['name'] != "") - $changedesc .= " modified '{$server['name']}' pool:"; - - update_if_changed("name", $server['name'], $_POST['name']); - update_if_changed("port", $server['port'], $_POST['port']); - 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']); - update_if_changed("advanced", $server['advanced'], base64_encode($_POST['advanced'])); - update_if_changed("checkinter", $server['checkinter'], $_POST['checkinter']); - - if (isset($id) && $a_server[$id]) { - $a_server[$id] = $server; + if($pool['name'] != "") + $changedesc .= " modified '{$pool['name']}' pool:"; + + $pool['ha_servers']['item']=$a_servers; + + update_if_changed("name", $pool['name'], $_POST['name']); + update_if_changed("status", $pool['status'], $_POST['status']); + update_if_changed("advanced", $pool['advanced'], base64_encode($_POST['advanced'])); + update_if_changed("checkinter", $pool['checkinter'], $_POST['checkinter']); + update_if_changed("monitor_uri", $pool['monitor_uri'], $_POST['monitor_uri']); + + if (isset($id) && $a_pools[$id]) { + $a_pools[$id] = $pool; } else { - $a_server[] = $server; + $a_pools[] = $pool; } if ($changecount > 0) { @@ -152,7 +141,7 @@ $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); if(strstr($pfSversion, "1.2")) $one_two = true; -$pgtitle = "HAProxy: Server: Edit"; +$pgtitle = "HAProxy: pool: Edit"; include("head.inc"); row_helper(); @@ -173,19 +162,25 @@ function clearcombo(){ }

- + - + @@ -193,78 +188,6 @@ function clearcombo(){ size="16" maxlength="16"> - - - - - - - - - - - - + + + - + - + @@ -319,7 +271,7 @@ function clearcombo(){ @@ -329,10 +281,10 @@ function clearcombo(){
diff --git a/config/haproxy-dev/haproxy_pools.php b/config/haproxy-dev/haproxy_pools.php index 4a0b08c9..5b9942b3 100755 --- a/config/haproxy-dev/haproxy_pools.php +++ b/config/haproxy-dev/haproxy_pools.php @@ -1,7 +1,7 @@ Copyright (C) 2008 Remco Hoef @@ -34,11 +34,11 @@ require_once("haproxy.inc"); $d_haproxyconfdirty_path = $g['varrun_path'] . "/haproxy.conf.dirty"; -if (!is_array($config['installedpackages']['haproxy']['ha_servers']['item'])) { - $config['installedpackages']['haproxy']['ha_servers']['item'] = array(); +if (!is_array($config['installedpackages']['haproxy']['ha_pools']['item'])) { + $config['installedpackages']['haproxy']['ha_pools']['item'] = array(); } -$a_server = &$config['installedpackages']['haproxy']['ha_servers']['item']; +$a_pools = &$config['installedpackages']['haproxy']['ha_pools']['item']; $a_backends = &$config['installedpackages']['haproxy']['ha_backends']['item']; if ($_POST) { @@ -55,22 +55,20 @@ if ($_POST) { } if ($_GET['act'] == "del") { - if ($a_server[$_GET['id']]) { - if (!$input_errors) { - unset($a_server[$_GET['id']]); - write_config(); - touch($d_haproxyconfdirty_path); - header("Location: haproxy_servers.php"); - exit; - } + if (isset($a_pools[$_GET['id']])) { + unset($a_pools[$_GET['id']]); + write_config(); + touch($d_haproxyconfdirty_path); } + header("Location: haproxy_pools.php"); + exit; } $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); if(strstr($pfSversion, "1.2")) $one_two = true; -$pgtitle = "Services: HAProxy: Servers"; +$pgtitle = "Services: HAProxy: Server pools"; include("head.inc"); ?> @@ -79,11 +77,11 @@ include("head.inc");

- +

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

Edit HAProxy serverEdit HAProxy pool
Name
Frontend(s) - - - - - - 0) - $tracker = $counter + 1; - ?> - - - - - - - - -
- - - 0) - echo ""; - ?> -
- - - -
-
- IP Address -
-
- -
Port - size="5"> -
- NOTE: Leave blank to use Frontend port selection. -
Status @@ -279,7 +202,7 @@ function clearcombo(){ size="64">
This value will be checked in incoming requests, and the first - operational server possessing the same value will be selected. In return, in + operational pool possessing the same value will be selected. In return, in cookie insertion or rewrite modes, this value will be assigned to the cookie sent to the client. There is nothing wrong in having several servers sharing the same cookie value, and it is in fact somewhat common between normal and @@ -287,23 +210,52 @@ function clearcombo(){
+ + + + + + + + + + + + + + + +
AddressPortWeight
+ + + +
Check interCheck freq size="64">
Defaults to 1000 if left blank.
WeightHealth check URI - size="64">
- The default weight is 1, and the maximal value is 255.
- NOTE: If this - parameter is used to distribute the load according to server's capacity, it - is recommended to start with values which can both grow and shrink, for - instance between 10 and 100 to leave enough room above and below for later - adjustments. + size="64">
- +
@@ -104,47 +102,49 @@ include("head.inc"); - - - + - + - - - - - - @@ -155,7 +155,7 @@ include("head.inc"); diff --git a/config/haproxy-dev/haproxy_servers_edit.php b/config/haproxy-dev/haproxy_servers_edit.php deleted file mode 100755 index 5a37e7a2..00000000 --- a/config/haproxy-dev/haproxy_servers_edit.php +++ /dev/null @@ -1,431 +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"; -$a_backend = &$config['installedpackages']['haproxy']['ha_backends']['item']; - -if (!is_array($config['installedpackages']['haproxy']['ha_servers']['item'])) { - $config['installedpackages']['haproxy']['ha_servers']['item'] = array(); -} - -$a_server = &$config['installedpackages']['haproxy']['ha_servers']['item']; - -if (isset($_POST['id'])) - $id = $_POST['id']; -else - $id = $_GET['id']; - -if (isset($id) && $a_server[$id]) { - $pconfig['name'] = $a_server[$id]['name']; - $pconfig['address'] = $a_server[$id]['address']; - $pconfig['port'] = $a_server[$id]['port']; - $pconfig['backend'] = $a_server[$id]['backend']; - $pconfig['weight'] = $a_server[$id]['weight']; - $pconfig['checkinter'] = $a_server[$id]['checkinter']; - $pconfig['cookie'] = $a_server[$id]['cookie']; - $pconfig['status'] = $a_server[$id]['status']; - $pconfig['advanced'] = base64_decode($a_server[$id]['advanced']); -} - -$changedesc = "Services: HAProxy: Servers: "; -$changecount = 0; - -if ($_POST) { - $changecount++; - - unset($input_errors); - $pconfig = $_POST; - - $reqdfields = explode(" ", "name address weight"); - $reqdfieldsn = explode(",", "Name,Address,Weight"); - - 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 (preg_match("/[^a-zA-Z0-9\.]/", $_POST['address'])) - $input_errors[] = "The field 'Address' contains invalid characters."; - - if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['cookie'])) - $input_errors[] = "The field 'Cookie' contains invalid characters."; - - if ($_POST['port'] && !is_numeric($_POST['port'])) - $input_errors[] = "The field 'Port' value is not a number."; - else { - if ($_POST['port']) - if (!($_POST['port']>=1 && $_POST['port']<=65535)) - $input_errors[] = "The field 'Port' value must be between 1 and 65535."; - } - - if (!is_numeric($_POST['weight'])) - $input_errors[] = "The field 'Weight' value is not a number."; - else { - if (!($_POST['weight']>=1 && $_POST['weight']<=256)) - $input_errors[] = "The field 'Weight' value must be between 1 and 256."; - } - - /* Ensure that our pool names are unique */ - for ($i=0; isset($config['installedpackages']['haproxy']['ha_servers']['item'][$i]); $i++) - 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]) - $server = $a_server[$id]; - - if($server['name'] != "") - $changedesc .= " modified '{$server['name']}' pool:"; - - update_if_changed("name", $server['name'], $_POST['name']); - update_if_changed("port", $server['port'], $_POST['port']); - 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']); - update_if_changed("advanced", $server['advanced'], base64_encode($_POST['advanced'])); - update_if_changed("checkinter", $server['checkinter'], $_POST['checkinter']); - - if (isset($id) && $a_server[$id]) { - $a_server[$id] = $server; - } else { - $a_server[] = $server; - } - - if ($changecount > 0) { - touch($d_haproxyconfdirty_path); - write_config($changedesc); - /* - echo "
";
-			print_r($config);
-			echo "
"; - */ - } - - header("Location: haproxy_servers.php"); - exit; - } -} - -$pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); -if(strstr($pfSversion, "1.2")) - $one_two = true; - -$pgtitle = "HAProxy: Server: Edit"; -include("head.inc"); - -row_helper(); - -?> - - - - - - - - - - - -

- - -
@@ -91,8 +89,8 @@ include("head.inc"); /* active tabs */ $tab_array = array(); $tab_array[] = array("Settings", false, "haproxy_global.php"); - $tab_array[] = array("Listener", false, "haproxy_frontends.php"); - $tab_array[] = array("Server Pool", true, "haproxy_servers.php"); + $tab_array[] = array("Listener", false, "haproxy_listeners.php"); + $tab_array[] = array("Server Pool", true, "haproxy_pools.php"); display_top_tabs($tab_array); ?>
Name Server StatusFrontendCookieWeightListener
- + + - + + - - - - - + + - + + - - + +
- +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Edit HAProxy server
Name - size="16" maxlength="16"> -
Frontend(s) - - - - - - 0) - $tracker = $counter + 1; - ?> - - - - - - - - -
- - - 0) - echo ""; - ?> -
- - - -
-
- IP Address -
-
- -
Port - size="5"> -
- NOTE: Leave blank to use Frontend port selection. -
Status - -
Cookie - size="64">
- This value will be checked in incoming requests, and the first - operational server possessing the same value will be selected. In return, in - cookie insertion or rewrite modes, this value will be assigned to the cookie - sent to the client. There is nothing wrong in having several servers sharing - the same cookie value, and it is in fact somewhat common between normal and - backup servers. See also the "cookie" keyword in backend section. - -
Check inter - size="64"> -
Defaults to 1000 if left blank. -
Weight - size="64">
- The default weight is 1, and the maximal value is 255.
- NOTE: If this - parameter is used to distribute the load according to server's capacity, it - is recommended to start with values which can both grow and shrink, for - instance between 10 and 100 to leave enough room above and below for later - adjustments. -
Advanced pass thru - -
- NOTE: paste text into this box that you would like to pass thru. -
  - - - - - -
- -
- - - - - -"; - $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