From 75350c76eebfedb665180250194427bc659b61b6 Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Mon, 17 Feb 2014 23:59:39 +0100 Subject: haproxy-devel, explain and reduce required fields on stats settings --- config/haproxy-devel/haproxy.inc | 14 ++++-- config/haproxy-devel/haproxy_pool_edit.php | 77 +++++++++++++++++------------- 2 files changed, 54 insertions(+), 37 deletions(-) (limited to 'config/haproxy-devel') diff --git a/config/haproxy-devel/haproxy.inc b/config/haproxy-devel/haproxy.inc index 5ae86bb9..93019ede 100644 --- a/config/haproxy-devel/haproxy.inc +++ b/config/haproxy-devel/haproxy.inc @@ -456,17 +456,25 @@ function write_backend($fd, $name, $pool, $frontend) { fwrite ($fd, "\tstats\t\t\trealm " . haproxy_escapestring($pool['stats_realm']) . "\n"); else fwrite ($fd, "\tstats\t\t\trealm .\n"); - fwrite ($fd, "\tstats\t\t\tauth " . haproxy_escapestring($pool['stats_username']).":". haproxy_escapestring($pool['stats_password'])."\n"); + + if ($pool['stats_username'] && $pool['stats_password']) + fwrite ($fd, "\tstats\t\t\tauth " . haproxy_escapestring($pool['stats_username']).":". haproxy_escapestring($pool['stats_password'])."\n"); if($pool['stats_admin']=='yes') fwrite ($fd, "\tstats\t\t\tadmin if TRUE" . "\n"); - if($pool['stats_node_enabled']=='yes') + if($pool['stats_node']) fwrite ($fd, "\tstats\t\t\tshow-node " . $pool['stats_node'] . "\n"); if($pool['stats_desc']) - fwrite ($fd, "\tstats\t\t\tshow-desc " . $pool['stats_desc'] . "\n"); + fwrite ($fd, "\tstats\t\t\tshow-desc " . haproxy_escapestring($pool['stats_desc']) . "\n"); if($pool['stats_refresh']) fwrite ($fd, "\tstats\t\t\trefresh " . $pool['stats_refresh'] . "\n"); + + if ($pool['stats_scope']) { + $scope_items = explode(",", $pool['stats_scope']); + foreach($scope_items as $scope_item) + fwrite ($fd, "\tstats\t\t\tscope " . $scope_item . "\n"); + } } $uri = $pool['monitor_uri']; diff --git a/config/haproxy-devel/haproxy_pool_edit.php b/config/haproxy-devel/haproxy_pool_edit.php index 4eb280ca..18eb4e0a 100644 --- a/config/haproxy-devel/haproxy_pool_edit.php +++ b/config/haproxy-devel/haproxy_pool_edit.php @@ -36,8 +36,6 @@ require_once("haproxy_utils.inc"); require_once("haproxy_htmllist.inc"); require_once("pkg_haproxy_tabs.inc"); -$d_haproxyconfdirty_path = $g['varrun_path'] . "/haproxy.conf.dirty"; - if (!is_array($config['installedpackages']['haproxy']['ha_pools']['item'])) { $config['installedpackages']['haproxy']['ha_pools']['item'] = array(); } @@ -124,9 +122,14 @@ if ($_POST) { do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); if ($_POST['stats_enabled']) { - $reqdfields = explode(" ", "name stats_username stats_password stats_uri stats_realm"); - $reqdfieldsn = explode(",", "Name,Stats Username,Stats Password,Stats Uri,Stats Realm"); + $reqdfields = explode(" ", "name stats_uri"); + $reqdfieldsn = explode(",", "Name,Stats Uri"); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + if ($_POST['stats_username']) { + $reqdfields = explode(" ", "stats_password stats_realm"); + $reqdfieldsn = explode(",", "Stats Password,Stats Realm"); + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + } } if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['name'])) @@ -152,6 +155,9 @@ if ($_POST) { if (preg_match("/[^a-zA-Z0-9!-~ ]/", $_POST['stats_password'])) $input_errors[] = "The field 'Stats Password' contains invalid characters."; + if (preg_match("/[^a-zA-Z0-9\-_]/", $_POST['stats_node'])) + $input_errors[] = "The field 'Stats Node' contains invalid characters. Should be a string with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_)"; + /* 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)) @@ -163,18 +169,17 @@ if ($_POST) { $server_address = $server['address']; $server_port = $server['port']; $server_weight = $server['weight']; + if (preg_match("/[^a-zA-Z0-9\.\-_]/", $server_name)) $input_errors[] = "The field 'Name' contains invalid characters."; - if (!is_ipaddr($server_address)) - $input_errors[] = "The field 'Address' is not a valid ip address."; + + if (!is_ipaddr($server_address) && !is_hostname($server_address)) + $input_errors[] = "The field 'Address' is not a valid ip address or hostname."; if (!preg_match("/.{2,}/", $server_name)) $input_errors[] = "The field 'Name' is required (and must be at least 2 characters)."; - if (!preg_match("/.{2,}/", $server_address)) - $input_errors[] = "The field 'Address' is required (and must be at least 2 characters)."; - - if (!is_numeric($server_weight)) + if ($server_weight && !is_numeric($server_weight)) $input_errors[] = "The field 'Weight' value is not a number."; if ($server_port && !is_numeric($server_port)) @@ -612,63 +617,67 @@ set by the 'retries' parameter. onclick='updatevisibility();' /> - - Stats Realm - - size="64" />
- EXAMPLE: haproxystats - - Stats Uri size="64" />
- EXAMPLE: /haproxy?stats + This url can be used when this same backend is used for passing connections to backends
+ EXAMPLE: / or /haproxy?stats + + + + Stats Scope + + size="64" />
+ Determines which frontends and backends are shown, leave empty to show all.
+ EXAMPLE: frontendA,backend1,backend2 + + + + Stats Realm + + size="64" />
+ The realm is shown when authentication is requested by haproxy.
+ EXAMPLE: haproxystats - Stats Username + Stats Username size="64" /> + EXAMPLE: admin - - Stats Password + Stats Password size="64" /> -
+ EXAMPLE: 1Your2Secret3P@ssword Stats Admin /> -
- - - - Stats Enable Node Name - - /> -
+ Makes available the options disable/enable/softstop/softstart/killsessions from the stats page.
+ Note: This is not persisted when haproxy restarts. For publicly visible stats pages this should be disabled. - Stats Node + Stats Nodename size="64" />
- The node name is displayed in the stats and helps to differentiate which server in a cluster is actually serving clients.
- Leave blank to use the system name. + The short name is displayed in the stats and helps to differentiate which server in a cluster is actually serving clients. Stats Description - size="64" />
+ size="64" />

+ The description is displayed behind the Nodename set above. -- cgit v1.2.3