diff options
author | PiBa-NL <pba_2k3@yahoo.com> | 2013-05-05 19:53:04 +0200 |
---|---|---|
committer | PiBa-NL <pba_2k3@yahoo.com> | 2013-05-05 19:53:04 +0200 |
commit | 8586a6318f6c7429df260944b95baf9e55ac2257 (patch) | |
tree | 02b4a57034a5dc4f70291804617aed20272b0369 /config/haproxy-devel/haproxy.widget.php | |
parent | a46f939b8886ad4cb4860b26016a7b5f0b1a7e8b (diff) | |
download | pfsense-packages-8586a6318f6c7429df260944b95baf9e55ac2257.tar.gz pfsense-packages-8586a6318f6c7429df260944b95baf9e55ac2257.tar.bz2 pfsense-packages-8586a6318f6c7429df260944b95baf9e55ac2257.zip |
haproxy-devel, widget, added widget-configuration settings, fixed retrieving client traffic.
Diffstat (limited to 'config/haproxy-devel/haproxy.widget.php')
-rw-r--r-- | config/haproxy-devel/haproxy.widget.php | 105 |
1 files changed, 81 insertions, 24 deletions
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\"> <font color=\"blue\"><i>".$clidata['src']."</i></font> <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 |