From af178737daae4f31ecb293d91e7e567fb5724cac Mon Sep 17 00:00:00 2001 From: Sergey Dvoriancev Date: Fri, 11 May 2012 23:50:35 +0400 Subject: SQStat 2 --- config/lightsquid/sqstat.php | 1063 ++++++++++++++++-------------------------- 1 file changed, 389 insertions(+), 674 deletions(-) (limited to 'config/lightsquid/sqstat.php') diff --git a/config/lightsquid/sqstat.php b/config/lightsquid/sqstat.php index 6a31159b..b61da811 100644 --- a/config/lightsquid/sqstat.php +++ b/config/lightsquid/sqstat.php @@ -1,708 +1,423 @@ + - - - - - Downloads · dvserg/pfsense-packages · GitHub - - - +?> - - + + + - - + + - - - - +function getactivity(action) { + var url = ""; + var pars = "getactivity=yes"; - - - - - - - + var myAjax = new Ajax.Request( url, + { + method: 'post', + parameters: pars, + onComplete: activitycallback + }); +} - +function activitycallback(transport) { - + if (200 == transport.status) { + result = transport.responseText; + } +} - +function update_start() { + var cmax = parseInt(el('refresh').value); + update_stop(); - -
+ if (cmax > 0) { + intervalID = window.setInterval('getactivity();', cmax * 1000); + } +} - - - +function update_stop() { + window.clearInterval(intervalID); + intervalID = 0; +} - - - - -
-
-
-
- - - - - - -

- public - - - / - pfsense-packages - - forked from bsdperimeter/pfsense-packages - -

-
- - - - - - -
-
- - -
- - - - - - - +function sqstat_AJAX_prep($text) +{ + $text = str_replace("'", "\'", $text); + $text = str_replace("\n", "\\r\\n", $text); + return $text; +} -
-

Markdown Cheat Sheet

- -
- -
-
-

Format Text

-

Headers

-
-# This is an <h1> tag
-## This is an <h2> tag
-###### This is an <h6> tag
-

Text styles

-
-*This text will be italic*
-_This will also be italic_
-**This text will be bold**
-__This will also be bold__
-
-*You **can** combine them*
-
-
-
-

Lists

-

Unordered

-
-* Item 1
-* Item 2
-  * Item 2a
-  * Item 2b
-

Ordered

-
-1. Item 1
-2. Item 2
-3. Item 3
-   * Item 3a
-   * Item 3b
-
-
-

Miscellaneous

-

Images

-
-![GitHub Logo](/images/logo.png)
-Format: ![Alt Text](url)
-
-

Links

-
-http://github.com - automatic!
-[GitHub](http://github.com)
-

Blockquotes

-
-As Kanye West said:
-
-> We're living the future so
-> the present is our past.
-
-
-
-
- -

Code Examples in Markdown

-
-

Syntax highlighting with GFM

-
-```javascript
-function fancyAlert(arg) {
-  if(arg) {
-    $.facebox({div:'#foo'})
-  }
+function sqstat_AJAX_error($err)
+{
+    $err = sqstat_AJAX_prep($err);
+    $t .= "el('sqstat_result').innerHTML = '$err';";
+    return $t;
 }
-```
-
-
-

Or, indent your code 4 spaces

-
-Here is a Python code example
-without syntax highlighting:
-
-    def foo:
-      if not bar:
-        return true
-
-
-

Inline code for comments

-
-I think you should use an
-`<addr>` element here instead.
-
-
- -
-
+# ------------------------------------------------------------------------------ +# Reports +# ------------------------------------------------------------------------------ + +function sqstat_headerHTML() +{ + global $squidclass; + + $date = date("h:i:s d/m/Y"); + $squidinfo = sqstat_serverInfoHTML(); + + if (empty($squidclass->autorefresh)) $squidclass->autorefresh = 0; + + return +<< + + Squid RealTime stat {$squidclass->sqstat_version} for the {$servers} proxy server {$squidinfo}.
+ Auto refresh: + sec. + + Created at: {$date}
+ +EOD; +} -
-

Something went wrong with that request. Please try again. Dismiss

-
- -
-

Looking for the GitHub logo?

- -
- - - - - - - +function sqstat_serverInfoHTML() +{ + global $squidclass; + return $squidclass->server_version . " ({$squidclass->squidhost}:{$squidclass->squidport})"; +} + +function sqstat_resultHTML($data) +{ + global $squidclass; + + $group_by_name = $squidclass->group_by_name; + $use_js = true; + + $t = array(); + + # table header + $t[] = ""; + $t[] = ""; + $t[] = ""; + if ($squidclass->use_sessions) + $t[] = ""; + $t[] = ""; + $t[] = ""; + + # table body + if (is_array($data['users'])) { + $tbl = array(); + + $con_color = 0; + foreach($data['users'] as $key => $v) { + # skeep total info + if ($key == 'total') continue; + # group row + $tbl[] = ""; + $tbl[] = ""; + $tbl[] = ""; + $tbl[] = ""; + + # connections row + foreach ($v['con'] as $con) { + if ($use_js) + $js = "onMouseout='hideddrivetip()' onMouseover='ddrivetip(\"" . $squidclass->implode_with_keys($con,"
") . "\")'"; + else $js=''; + + # begin new row + $class = (++$con_color % 2 == 0) ? " class='odd'" : ""; + $tbl[] = ""; + + # URL + $uri = "{$con['uritext']}"; + $tbl[] = ""; + $tbl[] = ""; + + # speed + if ($squidclass->use_sessions) { + $cur_s = round($con['cur_speed'], 2) > 0 ? sprintf("%01.2f KB/s", $con['cur_speed']) : ''; + $avg_s = round($con['avg_speed'], 2) > 0 ? sprintf("%01.2f KB/s", $con['avg_speed']) : ''; + $tbl[] = ""; + $tbl[] = ""; + } + + # file size + $filesize = $squidclass->filesize_format($con["bytes"]); + $duration = $squidclass->duration($con["seconds"], "short"); + $tbl[] = ""; + $tbl[] = ""; + + # end row + $tbl[] = ""; + } + + # total user speed + if ($squidclass->use_sessions) { + $user_curr = sprintf("%01.2f KB/s", $v['user_curr']); + $user_avg = sprintf("%01.2f KB/s", $v['user_avg']); + $tbl[] =""; + $tbl[] =""; + $tbl[] =""; + $tbl[] =""; + $tbl[] =""; + } + } + + + # status row + $stat = array(); + $ausers = sprintf("%d", $data['ausers']); + $acon = sprintf("%d", $data['acon']); + $stat[] = ""; + if ($squidclass->use_sessions) { + $total_curr = sprintf("%01.2f", $data['total_curr']); + $total_avg = sprintf("%01.2f", $data['total_avg']); + $stat[] = ""; + } + else { + $stat[] = ""; + } + $t[] = ""; + } + + if ($ausers == 0) { + $t[] = ""; + } + else { + $stat = implode("\n", $stat); + $tbl = implode("\n", $tbl); + $t[] = $stat . $tbl . $stat; + } + + $t[] = "
{$group_by_name}URICurr. SpeedAvg. SpeedSizeTime
" . (is_int($key) ? long2ip($key) : $key) . " 
{$uri}{$cur_s}{$avg_s}{$filesize}{$duration}
{$user_curr}{$user_avg}
Total:{$ausers} users and {$acon} connections @ {$total_curr}/{$total_avg} KB/s (CURR/AVG){$ausers} users and {$acon} connections
No active connections
"; + $t[] = "

Report based on SQStat © Alex Samorukov, 2006

"; + + return implode("\n", $t); +} + +function sqstat_errorHTML() +{ + global $squidclass; + $t = array(); + + # table header + $t[] = ""; + $t[] = ""; + $t[] = ""; + $t[] = "
SqStat error
"; + $t[] = '

Error (' . $squidclass->errno . '): ' . $squidclass->errstr . '

'; + $t[] = "
"; + + return implode ("\n", $t); +} + +function sqstat_loadconfig() +{ + global $squidclass, $config; + + $squidclass->errno = 0; + $squidclass->errstr = ''; + + $squidclass->sqstat_version = SQSTAT_VERSION; + + # === load config from pfSense === + $iface = '127.0.0.1'; + $iport = 3128; + $squid_settings = $config['installedpackages']['squid']['config'][0]; + if (!empty($squid_settings)) { + # squid interface IP & port + if ($squid_settings['transparent_proxy'] == 'on') { + $iface = '127.0.0.1'; + $iport = 80; + } + else { + $realif = array(); + $iface = ($squid_settings['active_interface'] ? $squid_settings['active_interface'] : 'lan'); + $iface = explode(",", $iface); + foreach ($iface as $i => $if) { + $realif[] = sqstat_get_real_interface_address($if); + $iface = $realif[$i][0] ? $realif[$i][0] : '127.0.0.1'; + } + $iport = $squid_settings['proxy_port'] ? $squid_settings['proxy_port'] : 3128; + } + } + $squidclass->squidhost = $iface; + $squidclass->squidport = $iport; + + $squidclass->group_by = "host"; + $squidclass->resolveip = true; + $squidclass->hosts_file = ''; # hosts file not used + $squidclass->autorefresh = 3; # refresh 3 sec by default + $squidclass->cachemgr_passwd = ''; + + # load hosts file, if defined + if (!empty($squidclass->hosts_file)) { + $squidclass->load_hosts(); + } + + return $squidclass->errno; +} + +function sqstat_get_real_interface_address($iface) +{ + global $config; + + $iface = convert_friendly_interface_to_real_interface_name($iface); + $line = trim(shell_exec("ifconfig $iface | grep inet | grep -v inet6")); + list($dummy, $ip, $dummy2, $netmask) = explode(" ", $line); + + return array($ip, long2ip(hexdec($netmask))); +} +?> \ No newline at end of file -- cgit v1.2.3