aboutsummaryrefslogtreecommitdiffstats
path: root/config/haproxy-devel
diff options
context:
space:
mode:
Diffstat (limited to 'config/haproxy-devel')
-rw-r--r--config/haproxy-devel/haproxy.widget.inc10
-rw-r--r--config/haproxy-devel/haproxy.widget.php105
-rw-r--r--config/haproxy-devel/haproxy.xml5
-rw-r--r--config/haproxy-devel/haproxy_socketinfo.inc16
4 files changed, 95 insertions, 41 deletions
diff --git a/config/haproxy-devel/haproxy.widget.inc b/config/haproxy-devel/haproxy.widget.inc
deleted file mode 100644
index 72113e1c..00000000
--- a/config/haproxy-devel/haproxy.widget.inc
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-
-//set variables
-$refresh_rate = 5000; //miliseconds
-$show_frontends = "NO";
-$show_clients = "YES";
-$show_clients_traffic = "YES";
-
-?>
-
diff --git a/config/haproxy-devel/haproxy.widget.php b/config/haproxy-devel/haproxy.widget.php
index b084cc62..abc5d935 100644
--- a/config/haproxy-devel/haproxy.widget.php
+++ b/config/haproxy-devel/haproxy.widget.php
@@ -32,10 +32,18 @@
require_once("guiconfig.inc");
require_once("pfsense-utils.inc");
require_once("functions.inc");
-#Retrieve parameters
require_once("haproxy_socketinfo.inc");
-require_once("/usr/local/www/widgets/include/haproxy.widget.inc");
-?><div id='HAProxy'><?php
+$first_time = false;
+if (!is_array($config["widgets"]["haproxy"])) {
+ $first_time = true;
+ $config["widgets"]["haproxy"] = array();
+}
+$a_config = &$config["widgets"]["haproxy"];
+
+$getupdatestatus=false;
+if(!empty($_GET['getupdatestatus'])) {
+ $getupdatestatus=true;
+}
#Backends/Servers Actions if asked
if(!empty($_GET['act']) and !empty($_GET['be']) and !empty($_GET['srv'])) {
@@ -45,6 +53,29 @@ if(!empty($_GET['act']) and !empty($_GET['be']) and !empty($_GET['srv'])) {
haproxy_set_server_enabled($backend, $server, $enable);
}
+$simplefields = array("haproxy_widget_timer","haproxy_widget_showfrontends","haproxy_widget_showclients","haproxy_widget_showclienttraffic");
+if ($_POST) {
+ foreach($simplefields as $fieldname)
+ $a_config[$fieldname] = $_POST[$fieldname];
+
+ write_config("Updated traffic graph settings via dashboard.");
+ header("Location: /");
+ exit(0);
+}
+
+// Set default values
+if (!$a_config['haproxy_widget_timer']) {
+ $a_config['haproxy_widget_timer'] = 5000;
+ $a_config['haproxy_widget_showfrontends'] = 'no';
+ $a_config['haproxy_widget_showclients'] = 'yes';
+ $a_config['haproxy_widget_showclienttraffic'] = 'no';
+}
+
+$refresh_rate = $a_config['haproxy_widget_timer'];
+$show_frontends = $a_config['haproxy_widget_showfrontends']=='yes';
+$show_clients = $a_config['haproxy_widget_showclients']=='yes';
+$show_clients_traffic = $a_config['haproxy_widget_showclienttraffic']=='yes';
+
$out="<img src ='/themes/{$g['theme']}/images/icons/icon_interface_down.gif'>";
$in="<img src ='/themes/{$g['theme']}/images/icons/icon_interface_up.gif'>";
$running="<img src ='/themes/{$g['theme']}/images/icons/icon_pass.gif'>";
@@ -62,7 +93,36 @@ $backends = $statistics['backends'];
$servers = $statistics['servers'];
if ($show_clients == "YES") {
- $clients = haproxy_get_clients();
+ $clients = haproxy_get_clients($show_clients_traffic == "YES");
+}
+if (!$getupdatestatus) {
+?>
+<div id="haproxy-settings" name="haproxy-settings" class="widgetconfigdiv" style="display:none;">
+<form action="/widgets/widgets/haproxy.widget.php" method="post" name="iform" id="iform">
+ <table>
+ <tr><td>
+ Refresh Interval:</td><td>
+ <input id="haproxy_widget_timer" name="haproxy_widget_timer" type="text" value="<?=$a_config['haproxy_widget_timer']?>"/></td>
+ </tr><tr>
+ <td>Show frontends:</td><td>
+ <input id="haproxy_widget_showfrontends" name="haproxy_widget_showfrontends" type="checkbox" value="yes" <?php if ($a_config['haproxy_widget_showfrontends']=='yes') echo "checked"; ?>/></td>
+ </tr><tr>
+ <td>Show clients:</td>
+ <td><input id="haproxy_widget_showclients" name="haproxy_widget_showclients" type="checkbox" value="yes" <?php if ($a_config['haproxy_widget_showclients']=='yes') echo "checked"; ?>/>
+ Note: showing clients increases CPU/memory usage.
+ </td>
+ </tr><tr>
+ <td>Show client traffic:</td>
+ <td><input id="haproxy_widget_showclienttraffic" name="haproxy_widget_showclienttraffic" type="checkbox" value="yes" <?php if ($a_config['haproxy_widget_showclienttraffic']=='yes') echo "checked"; ?>/>
+ Note: showing client traffic considerably increases CPU/memory usage.
+ </td>
+ </tr></table>
+ <br>
+ <input id="submit" name="submit" type="submit" onclick="return updatePref();" class="formbtn" value="Save Settings" />
+</form>
+</div>
+<div name="haproxy_content" id="haproxy_content">
+<?
}
echo "<table style=\"padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"";
@@ -157,23 +217,8 @@ foreach ($backends as $be => $bedata) {
if ($clidata['be'] == $bedata['pxname'] && $clidata['srv'] == $srvdata['svname']) {
print "<tr><td class=\"listlr\">&nbsp;&nbsp;<font color=\"blue\"><i>".$clidata['src']."</i></font>&nbsp;<a href=\"diag_dns.php?host=".$clidata['srcip']."\" title=\"Reverse Resolve with DNS\">".$log."</a></td>";
if ($show_clients_traffic == "YES") {
- $clisessoutput=exec("/bin/echo 'show sess ".$clidata['sessid']."' | /usr/local/bin/socat unix-connect:/tmp/haproxy.socket stdio | /usr/bin/grep 'total=' | /usr/bin/awk '{print $5}'",$clidebug);
- $i=0;
- foreach($clidebug as $cliline) {
- $clibytes = explode("=", $cliline);
- if ($clibytes[1] >= 1024 and $clibytes[1] <= 1048576) {
- $clibytes = (int)($clibytes[1]/1024)."Kb";
- } elseif ($clibytes[1] >= 1048576 and $clibytes[1] <= 10485760) {
- $clibytes = round(($clibytes[1]/1048576),2)."Mb";
- } elseif ($clibytes[1] >= 10485760) {
- $clibytes = round(($clibytes[1]/1048576),1)."Mb";
- } else {
- $clibytes = $clibytes[1]."B";
- }
- $clientstraffic[$i] = $clibytes;
- $i++;
- }
- $clidebug="";
+ $clientstraffic[0] = format_bytes($clidata['session_datareq']);
+ $clientstraffic[1] = format_bytes($clidata['session_datares']);
print "<td class=\"listlr\" colspan=\"3\"><font color=\"blue\">".$clidata['age']." / ".$clientstraffic[0]." / ".$clientstraffic[1]."</font></td></tr>";
} else {
print "<td class=\"listlr\" colspan=\"3\"><font color=\"blue\">".$clidata['age']." / ".$clidata['sessid']."</font></td></tr>";
@@ -185,8 +230,17 @@ foreach ($backends as $be => $bedata) {
}
}
-echo"</table></div>";
+echo "</table>";
+if (!$getupdatestatus)
+{
+ echo "</div>";
?>
+<script language="javascript" type="text/javascript">
+ d = document;
+ selectIntLink = "haproxy-configure";
+ textlink = d.getElementById(selectIntLink);
+ textlink.style.display = "inline";
+</script>
<script type="text/javascript">
function getstatusgetupdate() {
var url = "/widgets/widgets/haproxy.widget.php";
@@ -204,9 +258,9 @@ echo"</table></div>";
setTimeout('getstatus_haproxy()', <?= $refresh_rate ?>);
}
function activitycallback_haproxy(transport) {
- $('HAProxy').innerHTML = transport.responseText;
+ $('haproxy_content').innerHTML = transport.responseText;
}
- getstatus_haproxy();
+ setTimeout('getstatus_haproxy()', <?= $refresh_rate ?>);
</script>
<script type="text/javascript">
function control_haproxy(act,be,srv) {
@@ -222,3 +276,6 @@ echo"</table></div>";
});
}
</script>
+<?
+}
+?> \ No newline at end of file
diff --git a/config/haproxy-devel/haproxy.xml b/config/haproxy-devel/haproxy.xml
index 0d03527c..4511bde4 100644
--- a/config/haproxy-devel/haproxy.xml
+++ b/config/haproxy-devel/haproxy.xml
@@ -95,11 +95,6 @@
<item>http://www.pfsense.com/packages/config/haproxy-devel/haproxy_socketinfo.inc</item>
</additional_files_needed>
<additional_files_needed>
- <prefix>/usr/local/www/widgets/include/</prefix>
- <chmod>077</chmod>
- <item>http://www.pfsense.com/packages/config/haproxy-devel/haproxy.widget.inc</item>
- </additional_files_needed>
- <additional_files_needed>
<prefix>/usr/local/www/widgets/widgets/</prefix>
<chmod>077</chmod>
<item>http://www.pfsense.com/packages/config/haproxy-devel/haproxy.widget.php</item>
diff --git a/config/haproxy-devel/haproxy_socketinfo.inc b/config/haproxy-devel/haproxy_socketinfo.inc
index 117e7334..5b31afeb 100644
--- a/config/haproxy-devel/haproxy_socketinfo.inc
+++ b/config/haproxy-devel/haproxy_socketinfo.inc
@@ -96,7 +96,7 @@ function haproxy_get_statistics(){// "show stat"
return $result;
}
-function haproxy_get_clients(){// "show sess"
+function haproxy_get_clients($show_traffic = false){// "show sess"
$clients=array();
$sessions = haproxy_socket_command("show sess");
foreach($sessions as $line) {
@@ -122,8 +122,20 @@ function haproxy_get_clients(){// "show sess"
"calls" => $calls[1],
"exp" => $exp[1]);
}
+ if ($show_traffic) {
+ foreach($clients as &$client) {
+ $session_data = haproxy_socket_command("show sess {$client['sessid']}");
+ $client['session_data'] = $session_data;
+
+ $req = explode(" ",$session_data[13]);
+ $x = explode("=",$req[7]);
+ $client['session_datareq'] = $x[1];
+ $res = explode(" ",$session_data[16]);
+ $x = explode("=",$res[7]);
+ $client['session_datares'] = $x[1];
+ }
+ }
return $clients;
}
?>
-