query_exec(); } if ($squidclass->errno == 0) { $data = sqstat_resultHTML($data); } else { # error $data = sqstat_errorHTML(); } ?>
query_exec(); $ver = sqstat_serverInfoHTML(); $res .= "el('sqstat_serverver').innerHTML = '$ver';"; $time = date("h:i:s d/m/Y"); $res .= "el('sqstat_updtime').innerHTML = '$time';"; $data = sqstat_resultHTML( $data ); if ($squidclass->errno == 0) { $data = sqstat_AJAX_prep($data); $res .= "el('sqstat_result').innerHTML = '$data';"; } else { # error $res .= sqstat_AJAX_error(sqstat_errorHTML()); } return $res; } function sqstat_AJAX_prep($text) { $text = str_replace("'", "\'", $text); $text = str_replace("\n", "\\r\\n", $text); return $text; } function sqstat_AJAX_error($err) { $err = sqstat_AJAX_prep($err); $t .= "el('sqstat_result').innerHTML = '$err';"; return $t; } # ------------------------------------------------------------------------------ # 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; } 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))); } ?>