aboutsummaryrefslogtreecommitdiffstats
path: root/config/squidGuard/squidguard_log.php
diff options
context:
space:
mode:
Diffstat (limited to 'config/squidGuard/squidguard_log.php')
-rw-r--r--config/squidGuard/squidguard_log.php271
1 files changed, 227 insertions, 44 deletions
diff --git a/config/squidGuard/squidguard_log.php b/config/squidGuard/squidguard_log.php
index 9532c44d..e5f19407 100644
--- a/config/squidGuard/squidguard_log.php
+++ b/config/squidGuard/squidguard_log.php
@@ -30,31 +30,237 @@
$pgtitle = "Proxy filter SquidGuard: Log page";
-require_once('globals.inc');
-require_once('config.inc');
-require_once("guiconfig.inc");
-require_once('util.inc');
-require_once('pfsense-utils.inc');
-require_once('pkg-utils.inc');
-require_once('service-utils.inc');
-
-include("head.inc");
-
+require_once('guiconfig.inc');
+require_once('notices.inc');
if (file_exists("/usr/local/pkg/squidguard.inc")) {
require_once("/usr/local/pkg/squidguard.inc");
}
-$mode = $_GET["mode"];
+# ------------------------------------------------------------------------------
+# defines
+# ------------------------------------------------------------------------------
$selfpath = "/squidGuard/squidguard_log.php";
-if (!in_array( $mode, array("blocked", "fgui", "flog", "pconf", "fconf"))) $mode = "blocked";
+# ------------------------------------------------------------------------------
+# Requests
+# ------------------------------------------------------------------------------
+if ($_REQUEST['getactivity'])
+{
+ header("Content-type: text/javascript");
+ echo squidguard_log_AJAX_response( $_REQUEST );
+ exit;
+}
+
+# ------------------------------------------------------------------------------
+# Functions
+# ------------------------------------------------------------------------------
+
+function squidguard_log_AJAX_response( $request )
+{
+ $res = '';
+ $offset = $request['offset'] ? $request['offset'] : 0;
+ $reverse = $request['reverse'] == 'yes'? true : false;
+ $pcaption = ' ';
+
+ # Actions
+ switch($request['rep']) {
+ case 'filterconf':
+ if (function_exists("squidguard_conflist"))
+ $cont = squidguard_conflist( );
+ else $cont = "Function 'squidguard_conflist' not found.";
+ $res = squidguard_prep_textareacont($cont);
+ break;
+ case 'proxyconf':
+ if (function_exists("squidguard_squid_conflist"))
+ $cont = squidguard_squid_conflist( );
+ else $cont = "Function 'squidguard_squid_conflist' not found.";
+ $res = squidguard_prep_textareacont($cont);
+ break;
+ case 'guilog':
+ $res = squidguard_logrep(squidguard_guidump( &$offset, 50, true));
+ break;
+ case 'filterlog':
+ $res = squidguard_logrep(squidguard_filterdump( &$offset, 50, true));
+ break;
+ case "blocked":
+ default:
+ $res = squidguard_logrep(squidguard_blockdump( &$offset, 50, true));
+ break;
+ }
+
+ $res .= "el('offset').value = {$offset};";
+ $res .= "el('showoffset').innerHTML = {$offset};";
+ return $res;
+}
+
+function squidguard_logrep( $dump )
+{
+ $res = '';
+
+ if (!empty($dump)) {
+ if (is_array($dump)) {
+ $acount = count($dump[0]) ? count($dump[0]) : 1;
+ $res = "<table class=\'tabcont\' width=\'100%\' border=\'0\' cellpadding=\'0\' cellspacing=\'0\'>";
+ $res .= "<tr><td class=\'listtopic\' colspan=\'$acount\' nowrap>Show top 50 entries. List from the line:&nbsp;" .
+ "<span style=\'cursor: pointer;\' onclick=\'report_down();\'>&lt;&lt;</span>" .
+ "&nbsp;<span id='showoffset' >0</span>&nbsp;" .
+ "<span style=\'cursor: pointer;\' onclick=\'report_up();\'>&gt;&gt;</span>&nbsp;" .
+ "</td></tr>";
+
+ foreach($dump as $dm) {
+ if (!$dm[0] || !$dm[1]) continue;
+ # datetime
+ $dm[0] = date("d.m.Y H:i:s", strtotime($dm[0]));
+ $res .= "<tr><td class=\'listlr\' nowrap>{$dm[0]}</td>";
+
+ # col 1
+ $dm[1] = htmlentities($dm[1]);
+ $dm[1] = squidguard_html_autowrap($dm[1]);
+ $res .= "<td class=\'listr\'>{$dm[1]}</td>";
+
+ # for blocked rep
+ if (count($dm) > 2) {
+ $dm[2] = htmlentities($dm[2]);
+ $dm[2] = squidguard_html_autowrap($dm[2]);
+ $res .= "<td class=\'listr\' width=\'*\'>{$dm[2]}</td>";
+ $res .= "<td class=\'listr\'>{$dm[3]}</td>";
+ }
+ $res .= "</tr>";
+ }
+ $res .= "</table>";
+ }
+ else $res = "{$dump}";
+ } else {
+ $res = "No data.";
+ }
+
+ $res = "el(\"reportarea\").innerHTML = \"{$res}\";";
+ return $res;
+}
+
+function squidguard_prepfor_JS($cont)
+{
+ # replace for JS
+ $cont = str_replace("\n", "\\n", $cont);
+ $cont = str_replace("\r", "\\r", $cont);
+ $cont = str_replace("\t", "\\t", $cont);
+ $cont = str_replace("\"", "\'", $cont);
+ return $cont;
+}
+
+function squidguard_prep_textareacont($cont)
+{
+ $cont = squidguard_prepfor_JS($cont);
+ return
+ "el('reportarea').innerHTML = \"<br><center><textarea rows=25 cols=70 id='pconf' name='pconf' wrap='hard' readonly></textarea></center>\";" .
+ "el('pconf').innerHTML = '$cont';";
+}
+
+function squidguard_html_autowrap($cont)
+{
+ # split strings
+ $p = 0;
+ $pstep = 25;
+ $str = $cont;
+ $cont = '';
+ for ( $p = 0; $p < strlen($str); $p += $pstep ) {
+ $s = substr( $str, $p, $pstep );
+ if ( !$s ) break;
+ $cont .= $s . "<wbr/>";
+ }
+
+ return $cont;
+}
+
+# ------------------------------------------------------------------------------
+# HTML Page
+# ------------------------------------------------------------------------------
+include("head.inc");
+echo "\t<script type=\"text/javascript\" src=\"/javascript/scriptaculous/prototype.js\"></script>\n";
?>
+<!-- Ajax Script -->
+<script type="text/javascript">
+
+function el(id) {
+ return document.getElementById(id);
+}
+
+function getactivity(action) {
+ var url = "./squidguard_log.php";
+ var pars = 'getactivity=yes';
+ var act = action;
+ var offset = 0;
+ var reverse = 'yes';
+
+ if (action == 'report_up') {
+ act = el('reptype').value;
+ offset = parseInt(el('offset').value);
+ offset = offset + 50;
+ } else
+ if (action == 'report_down') {
+ act = el('reptype').value;
+ offset = parseInt(el('offset').value);
+ offset = offset - 50;
+ offset = offset >= 0 ? offset : 0;
+ } else {
+ el('reptype').value = action ? action : 'blocklog';
+ el('offset').value = 0;
+ offset = 0;
+ }
+
+ pars = pars + '&rep=' + act + '&reverse=' + reverse + '&offset=' + offset;
+
+ var myAjax = new Ajax.Request( url,
+ {
+ method: 'get',
+ parameters: pars,
+ onComplete: activitycallback
+ });
+}
+
+function activitycallback(transport) {
+
+ if (200 == transport.status) {
+ result = transport.responseText;
+ } else {
+ el('reportarea').innerHTML = 'Error! Returned code ' + transport.status + ' ' + transport.responseText;
+ }
+ sethdtab_selected();
+}
+
+function report_up()
+{
+ getactivity('report_up');
+}
+
+function report_down()
+{
+ getactivity('report_down');
+}
+
+function sethdtab_selected()
+{
+ var sel = "hd_" + el('reptype').value;
+
+ el('hd_blocklog').style.fontWeight = (sel == 'hd_blocklog') ? 'bold' : '';
+ el('hd_guilog').style.fontWeight = (sel == 'hd_guilog') ? 'bold' : '';
+ el('hd_filterlog').style.fontWeight = (sel == 'hd_filterlog') ? 'bold' : '';
+ el('hd_proxyconf').style.fontWeight = (sel == 'hd_proxyconf') ? 'bold' : '';
+ el('hd_filterconf').style.fontWeight = (sel == 'hd_filterconf') ? 'bold' : '';
+}
+
+window.setTimeout('getactivity()', 150);
+
+</script>
+
<!-- HTML -->
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<form action="sg_log.php" method="post">
+<input type="hidden" id="reptype" val="">
+<input type="hidden" id="offset" val="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<!-- Tabs -->
<tr>
@@ -84,47 +290,24 @@ if (!in_array( $mode, array("blocked", "fgui", "flog", "pconf", "fconf"))) $mode
# Subtabs
$mode = $mode ? $mode : "blocked";
$tab_array = array();
- $tab_array[] = array(gettext("Blocked"), ($mode == "blocked"), "{$selfpath}?mode=blocked");
- $tab_array[] = array(gettext("Filter GUI log"), ($mode == "fgui"), "{$selfpath}?mode=fgui");
- $tab_array[] = array(gettext("Filter log"), ($mode == "flog"), "{$selfpath}?mode=flog");
- $tab_array[] = array(gettext("Proxy config"), ($mode == "pconf"), "{$selfpath}?mode=pconf");
- $tab_array[] = array(gettext("Filter config"), ($mode == "fconf"), "{$selfpath}?mode=fconf");
+ $tab_array[] = array(gettext("Blocked"), ($mode == "blocked"), "blocklog");
+ $tab_array[] = array(gettext("Filter GUI log"), ($mode == "fgui"), "guilog");
+ $tab_array[] = array(gettext("Filter log"), ($mode == "flog"), "filterlog");
+ $tab_array[] = array(gettext("Proxy config"), ($mode == "pconf"), "proxyconf");
+ $tab_array[] = array(gettext("Filter config"), ($mode == "fconf"), "filterconf");
echo "<big>| ";
foreach ($tab_array as $ta) {
- $bl = $ta[1] ? "<b>" : "";
- $br = $ta[1] ? "</b>" : "";
- echo "<a href=\"{$ta[2]}\">$bl{$ta[0]}$br</a> | ";
+ $id = "hd_{$ta[2]}";
+ $bb = $ta[1] ? "font-weight: bold;" : '';
+ echo "<span id='{$id}' style='cursor: pointer; {$bb}' onclick=\"getactivity('{$ta[2]}');\">{$ta[0]}</span> | ";
}
echo "</big>";
?>
</td>
</tr>
<tr>
- <td>
-<?php
- $cont = "";
- switch( $mode ) {
- case "pconf": if (function_exists("squidguard_squid_conflist"))
- $cont = squidguard_squid_conflist( );
- else $cont = "Function 'squidguard_squid_conflist' not found.";
- echo "<br><center><textarea rows='30' cols='70' name='pconf' wrap='hard' readonly>{$cont}</textarea></center>" ;
- break;
- case "fconf": if (function_exists("squidguard_conflist"))
- $cont = squidguard_conflist( );
- else $cont = "Function 'squidguard_conflist' not found.";
- echo "<br><center><textarea rows='30' cols='70' name='pconf' wrap='hard' readonly>{$cont}</textarea></center>" ;
- break;
- case "flog": if (function_exists( "squidguard_logrep" )) echo squidguard_logrep( SQUIDGUARD_LOGDIR . '/squidGuard.log', 50, false );
- break;
- case "fgui": if (function_exists( "squidguard_logrep" )) echo squidguard_logrep( SQUIDGUARD_LOGDIR . SQUIDGUARD_CONFLOGFILE, 50, false );
- break;
- case "blocked":
- default: if (function_exists( "squidguard_logrep" )) echo squidguard_logrep( SQUIDGUARD_LOGDIR . '/' . SQUIDGUARD_LOGFILE, 50, false );
- break;
- }
-?>
- </td>
+ <td id="reportarea" name="reportarea"></td>
</tr>
</table>
</div>