From b07bce1a7b918ade438851b60a25372abdef7908 Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Sun, 16 Feb 2014 21:04:47 +0100 Subject: haproxy-devel, integrated stats page with stick-table info WebGUI --- config/haproxy-devel/haproxy_stats.php | 256 +++++++++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 config/haproxy-devel/haproxy_stats.php (limited to 'config/haproxy-devel/haproxy_stats.php') diff --git a/config/haproxy-devel/haproxy_stats.php b/config/haproxy-devel/haproxy_stats.php new file mode 100644 index 00000000..8ad04c92 --- /dev/null +++ b/config/haproxy-devel/haproxy_stats.php @@ -0,0 +1,256 @@ + $arg) + $request .= ";$key=$arg"; + } + $options = array( + 'http'=>array( + 'method'=>"POST", + 'header'=>"Accept-language: en\r\n". + "Content-type: application/x-www-form-urlencoded\r\n", + 'content'=>http_build_query($_POST) + )); + $context = stream_context_create($options); + $response = file_get_contents("http://127.0.0.1:{$pconfig['localstatsport']}/haproxy_stats.php?haproxystats=1".$request, false, $context); + if (is_array($http_response_header)){ + foreach($http_response_header as $header){ + if (strpos($header,"Refresh: ") == 0) + header($header); + } + } + $fail = $response === false; + } catch (Exception $e) { + $fail = true; + } + if ($fail) + $response = "

Make sure HAProxy settings are applied and HAProxy is enabled and running"; + echo $response; + exit(0); +} +require_once("guiconfig.inc"); +if (isset($_GET['showsticktablecontent'])){ + header("Refresh: 2"); +} +$shortcut_section = "haproxy"; +require_once("haproxy.inc"); +require_once("certs.inc"); +require_once("haproxy_utils.inc"); +require_once("pkg_haproxy_tabs.inc"); + +if (!is_array($config['installedpackages']['haproxy']['ha_backends']['item'])) { + $config['installedpackages']['haproxy']['ha_backends']['item'] = array(); +} +$a_frontend = &$config['installedpackages']['haproxy']['ha_backends']['item']; + +function haproxy_add_stats_example() { + global $config, $d_haproxyconfdirty_path; + $a_backends = &$config['installedpackages']['haproxy']['ha_pools']['item']; + $a_frontends = &$config['installedpackages']['haproxy']['ha_backends']['item']; + $webcert = haproxy_find_create_certificate("HAProxy stats default"); + + $backend = array(); + $backend["name"] = "HAProxy_stats_ssl_backend"; + $backend["stats_enabled"] = "yes"; + $backend["stats_uri"] = "/"; + $backend["stats_refresh"] = "10"; + $a_backends[] = $backend; + $changecount++; + + $frontend = array(); + $frontend["name"] = "HAProxy_stats_ssl_frontend"; + $frontend["status"] = "active"; + $frontend["type"] = "http"; + $frontend["port"] = "444"; + $frontend["extaddr"] = "lan_ipv4"; + $frontend["ssloffload"] = "yes"; + $frontend["ssloffloadcert"] = $webcert['refid']; + $frontend["backend_serverpool"] = $backend["name"]; + $a_frontends[] = $frontend; + $changecount++; + $changedesc = "add new HAProxy stats example"; + + if ($changecount > 0) { + echo "touching: $d_haproxyconfdirty_path"; + touch($d_haproxyconfdirty_path); + write_config($changedesc); + } +} + +if (isset($_GET['add_stats_example'])) { + haproxy_add_stats_example(); + write_config(); + touch($d_haproxyconfdirty_path); + header("Location: haproxy_listeners.php"); + exit; +} + +if ($_POST) { + if ($_POST['apply']) { + $result = haproxy_check_and_run($savemsg, true); + if ($result) + unlink_if_exists($d_haproxyconfdirty_path); + } +} + +$pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); +if(strstr($pfSversion, "1.2")) + $one_two = true; + +$pgtitle = "Services: HAProxy: Stats"; +include("head.inc"); + +?> + + +
+ +

+ + + + +You must apply the changes in order for them to take effect.");?>
+ +
+ + + + + +
+ +
+
+ + + "; + echo "TESTJe
"; + $res = haproxy_socket_command("show table $sticktablename"); + foreach($res as $line){ + echo "
".print_r($line,true); + } +echo ""; +} else { +?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ This page contains a 'stats' page available from haproxy accessible through the pfSense gui.
+
+ As the page is forwarded through the pfSense gui, this might cause some functionality to not work.
+ Though the normal haproxy stats page can be tweaked more, and doesn't use a user/pass from pfSense itself.
+ Some examples are configurable automatic page refresh,
+ only showing certain servers, not providing admin options, and can be accessed from wherever the associated frontend is accessible.(as long as rules permit access)
+ To use this or for simply an example how to use SSL-offloading configure stats on either a real backend while utilizing the 'stats uri'. + Or create a backend specifically for serving stats, for that you can start with the 'stats example' template below.
+
 
Stats example template
Example + As an basic example you can use the link below to create a 'stats' frontend/backend page which offers with more options like setting user/password and 'admin mode' when you go to the backend settings.
+ TEMPLATE: Create stats example configuration using a frontend/backend combination with ssl
+
+ After applying the changes made by the template use this link to visit the stats page: :444">https://pfSense-LAN-ip:444/ +
 
HAProxy stick-tables
+ These tables are used to store information for session persistence and can be used with ssl-session-id information, application-cookies, or other information that is used to persist a user to a server. + + + + + + + + $table) { ?> + + + + + + + +
Stick-tableTypeSizeUsed
+
 
HAProxy stats
Fullscreen stats page
+ + + +
+ In the "Settings" configure a internal stats port and enable haproxy for this to be functional.
+
+ + +
+
+
+ + + -- cgit v1.2.3