From 0293a8f6b843135a3b97917e09a1de5314bdd721 Mon Sep 17 00:00:00 2001 From: Marcello Coutinho Date: Thu, 10 May 2012 12:28:33 -0300 Subject: imspector-dev - include report template option and fetch limit for log files --- config/imspector-dev/imspector.inc | 16 +- config/imspector-dev/imspector.xml | 30 ++- config/imspector-dev/imspector_acls.xml | 14 +- config/imspector-dev/imspector_replacements.xml | 8 +- config/imspector-dev/imspector_sync.xml | 2 +- config/imspector-dev/services_imspector_logs.php | 8 +- config/imspector-dev/services_imspector_logs2.php | 310 ++++++++++++++++++++++ 7 files changed, 372 insertions(+), 16 deletions(-) create mode 100644 config/imspector-dev/services_imspector_logs2.php (limited to 'config/imspector-dev') diff --git a/config/imspector-dev/imspector.inc b/config/imspector-dev/imspector.inc index 7ac603ba..a4af7771 100644 --- a/config/imspector-dev/imspector.inc +++ b/config/imspector-dev/imspector.inc @@ -149,6 +149,7 @@ #bannedphraselist if (!is_array($config['installedpackages']['imspectoracls'])){ $config['installedpackages']['imspectoracls']['config'][]=array('enable'=> 'on', + 'description' => 'allow access to all ids', 'action' => 'allow', 'localid' => 'all', 'remoteid' => base64_encode('all')); @@ -250,9 +251,6 @@ if($ims_replacements['block_webcams']) $conf['block_webcams'] = 'on'; - - if($ims_replacements['block_unlisted']) - $conf['block_unlisted'] = 'on'; $acls=""; $conf['acl_filename'] = IMSPECTOR_ETC . '/acls.txt'; @@ -342,7 +340,17 @@ foreach($conf as $var => $key) $conftext .= "{$var}={$key}\n"; write_imspector_config(IMSPECTOR_CONFIG, $conftext); - + + /*Check template settings*/ + if ($ims_config['template'] == "") + $template="services_imspector_logs.php"; + else + $template=$ims_config['template']; + + if (file_exists("/usr/local/www/{$template}")) + $log_file=file_get_contents("/usr/local/www/{$template}"); + file_put_contents("/usr/local/www/imspector_logs.php",$log_file,LOCK_EX); + /* generate rc file start and stop */ $stop = << Log - /services_imspector_logs.php + /imspector_logs.php Sync @@ -107,6 +107,11 @@ 0755 http://www.pfsense.org/packages/config/imspector-dev/services_imspector_logs.php + + /usr/local/www/ + 0755 + http://www.pfsense.org/packages/config/imspector-dev/services_imspector_logs2.php + General Settings @@ -179,6 +184,25 @@ Log files stored in /var/imspector. checkbox + + Report limit + limit + Max entries to fetch from log dir. Default is 1000 + input + 10 + + + Report template + template + Template to use on reports + select + + + + + + + Enable mySQL logging log_mysql @@ -189,21 +213,25 @@ mySQL server mysql_server input + 35 mySQL database mysql_database input + 35 mySQL username mysql_username input + 35 mySQL password mysql_password password + 35 diff --git a/config/imspector-dev/imspector_acls.xml b/config/imspector-dev/imspector_acls.xml index 02d57052..3176c75f 100644 --- a/config/imspector-dev/imspector_acls.xml +++ b/config/imspector-dev/imspector_acls.xml @@ -82,7 +82,7 @@ Log - /services_imspector_logs.php + /imspector_logs.php Sync @@ -102,6 +102,10 @@ local ID localid + + Description + description + @@ -127,6 +131,14 @@ + + Description + description + + input + 50 + + Local ID localid diff --git a/config/imspector-dev/imspector_replacements.xml b/config/imspector-dev/imspector_replacements.xml index e0ff4a06..7f53bbd4 100644 --- a/config/imspector-dev/imspector_replacements.xml +++ b/config/imspector-dev/imspector_replacements.xml @@ -74,7 +74,7 @@ Log - /services_imspector_logs.php + /imspector_logs.php Sync @@ -155,12 +155,6 @@ This option will block all webcam sessions. Currently IMSpector can only spot webcam sessions on Yahoo. checkbox - - Block non ACL defined - block_unlisted - Overide the default of allowing user's not defined the whitelist or blacklist ACLs. - checkbox - Enable bad word filtering filter_badwords diff --git a/config/imspector-dev/imspector_sync.xml b/config/imspector-dev/imspector_sync.xml index 8959af02..3ff88d41 100644 --- a/config/imspector-dev/imspector_sync.xml +++ b/config/imspector-dev/imspector_sync.xml @@ -60,7 +60,7 @@ Log - /services_imspector_logs.php + /imspector_logs.php Sync diff --git a/config/imspector-dev/services_imspector_logs.php b/config/imspector-dev/services_imspector_logs.php index 09e732b8..aa6a9a9b 100644 --- a/config/imspector-dev/services_imspector_logs.php +++ b/config/imspector-dev/services_imspector_logs.php @@ -6,6 +6,7 @@ JavaScript Code is GPL Licensed from SmoothWall Express. Copyright (C) 2007 Ryan Wagoner . + Copyright (C) 2012 Marcello Coutinho All rights reserved. Redistribution and use in source and binary forms, with or without @@ -62,13 +63,16 @@ $convo_remote_bgcolor = '#eeeeee'; function convert_dir_list ($topdir) { if (!is_dir($topdir)) return; if ($dh = opendir($topdir)) { - while (($file = readdir($dh)) !== false) { + $limit=(is_numericint($imspector_config['limit'])?$imspector_config['limit']:"1000"); + $count=0; + while (($file = readdir($dh)) !== false && $count < $limit) { if(!preg_match('/^\./', $file) == 0) continue; if (is_dir("$topdir/$file")) { $list .= convert_dir_list("$topdir/$file"); } else { $list .= "$topdir/$file\n"; } + $count ++; } closedir($dh); } @@ -160,7 +164,7 @@ include("head.inc"); $tab_array[] = array(gettext("Settings "), false, "/pkg_edit.php?xml=imspector.xml&id=0"); $tab_array[] = array(gettext("Replacements "), false, "/pkg_edit.php?xml=imspector_replacements.xml&id=0"); $tab_array[] = array(gettext("Access Lists "), false, "/pkg.php?xml=imspector_acls.xml"); - $tab_array[] = array(gettext("Log "), true, "/services_imspector_logs.php"); + $tab_array[] = array(gettext("Log "), true, "/imspector_logs.php"); $tab_array[] = array(gettext("Sync "), false, "/pkg_edit.php?xml=imspector_sync.xml&id=0"); display_top_tabs($tab_array); diff --git a/config/imspector-dev/services_imspector_logs2.php b/config/imspector-dev/services_imspector_logs2.php new file mode 100644 index 00000000..a90ae6ca --- /dev/null +++ b/config/imspector-dev/services_imspector_logs2.php @@ -0,0 +1,310 @@ +. + Copyright (C) 2012 0guzcan at pfsense forum. + Copyright (C) 2012 Marcello Coutinho + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ +require("guiconfig.inc"); + +/* variables */ +$log_dir = '/var/imspector'; +$imspector_config = $config['installedpackages']['imspector']['config'][0]; + +$border_color = '#c0c0c0'; +$default_bgcolor = '#eeeeee'; + +$list_protocol_color = '#000000'; +$list_local_color = '#ffffff'; +$list_remote_color = '#666666'; +$list_convo_color = '#888888'; + +$list_protocol_bgcolor = '#cccccc'; +$list_local_bgcolor = '#850000'; +$list_remote_bgcolor = '#eeeeee'; +$list_end_bgcolor = '#bbbbbb'; + +$convo_title_color = 'black'; +$convo_local_color = 'blue'; +$convo_remote_color = 'red'; + +$convo_title_bgcolor = '#cccccc'; +$convo_local_bgcolor = '#dddddd'; +$convo_remote_bgcolor = '#eeeeee'; + + +/* functions */ + +function convert_dir_list ($topdir) { + if (!is_dir($topdir)) return; + if ($dh = opendir($topdir)) { + $limit=(is_numericint($imspector_config['limit'])?$imspector_config['limit']:"1000"); + $count=0; + while (($file = readdir($dh)) !== false && $count < $limit) { + if(!preg_match('/^\./', $file) == 0) continue; + if (is_dir("$topdir/$file")) { + $list .= convert_dir_list("$topdir/$file"); + } else { + $list .= "$topdir/$file\n"; + } + $count ++; + } + closedir($dh); + } + return $list; +} + +/* ajax response */ +if ($_POST['mode'] == "render") { + + /* user list */ + print(str_replace(array($log_dir,'/'),array('','|'),convert_dir_list($log_dir))); + print("--END--\n"); + + /* log files */ + if ($_POST['section'] != "none") { + $section = explode('|',$_POST['section']); + $protocol = $section[0]; + $localuser = $section[1]; + $remoteuser = $section[2]; + $conversation = $section[3]; + + /* conversation title */ + print(implode(', ', $section)."\n"); + print("--END--\n"); + + /* conversation content */ + $filename = $log_dir.'/'.implode('/', $section); + if($fd = fopen($filename, 'r')) { + $satir_oku = fgets($fd); + $ipsinibulduk = explode(':',$satir_oku); + + print("\n"); + while (!feof($fd)) { + $line = fgets($fd); + if(feof($fd)) continue; + $new_format = '([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),(.*)'; + $old_format = '([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),(.*)'; + preg_match("/${new_format}|${old_format}/", $line, $matches); + $address = $matches[1]; + $addresbul = explode(':',$address); + $addressnew =$addresbul[0] ; + $timestamp = $matches[2]; + $direction = $matches[3]; + $type = $matches[4]; + $filtered = $matches[5]; + if(count($matches) == 8) { + $category = $matches[6]; + $data = $matches[7]; + } else { + $category = ""; + $data = $matches[6]; + } + + if($direction == '0') { + $bgcolor = $convo_remote_bgcolor; + $user = "$remoteuser"; + } + if($direction == '1') { + $bgcolor = $convo_local_bgcolor; + $user = "$localuser"; + } + + $time = strftime("%H:%M", $timestamp); + + + print(" + \n + \n + \n + \n"); + } + print("
kullanilan [$localuser] adresine ait local ip: [$ipsinibulduk[0]]
[$time]$user$category$data
\n"); + fclose($fd); + } + } + exit; +} +/* defaults to this page but if no settings are present, redirect to setup page */ +if(!$imspector_config["enable"] || !$imspector_config["iface_array"] || !$imspector_config["proto_array"]) + Header("Location: /pkg_edit.php?xml=imspector.xml&id=0"); + +$pgtitle = "Services: IMSpector Log Viewer"; +include("head.inc"); +/* put your custom HTML head content here */ +/* using some of the $pfSenseHead function calls */ +//$pfSenseHead->addMeta(""); +//echo $pfSenseHead->getHTML(); +?> + + + + +
+ + +
+ + +var section = 'none'; +var moveit = 1; +var the_timeout; + +function xmlhttpPost() +{ + var xmlHttpReq = false; + var self = this; + + if (window.XMLHttpRequest) + self.xmlHttpReq = new XMLHttpRequest(); + else if (window.ActiveXObject) + self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); + + self.xmlHttpReq.open('POST', 'services_imspector_logs.php', true); + self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + + self.xmlHttpReq.onreadystatechange = function() { + if (self.xmlHttpReq && self.xmlHttpReq.readyState == 4) + updatepage(self.xmlHttpReq.responseText); + } + + document.getElementById('im_status').style.display = "inline"; + self.xmlHttpReq.send("mode=render§ion=" + section); +} + +function updatepage(str) +{ + /* update the list of conversations ( if we need to ) */ + var parts = str.split("--END--\\n"); + var lines = parts[0].split("\\n"); + + for (var line = 0 ; line < lines.length ; line ++) { + var a = lines[line].split("|"); + + if (!a[1] || !a[2] || !a[3]) continue; + + /* create titling information if needed */ + if (!document.getElementById(a[1])) { + document.getElementById('im_convos').innerHTML += + "
" + a[1] + "
" + + "
"; + } + if (!document.getElementById(a[1] + "_" + a[2])) { + var imageref = ""; + if (a[0]) imageref = "" + a[1] + ""; + document.getElementById(a[1]).innerHTML += + "
" + imageref + a[2] + "
" + + "
"; + } + if (!document.getElementById(a[1] + "_" + a[2] + "_" + a[3])) { + document.getElementById(a[1] + "_" + a[2]).innerHTML += + "
" + a[3] + "
" + + "
"; + } + if (!document.getElementById(a[1] + "_" + a[2] + "_" + a[3] + "_" + a[4])) { + document.getElementById(a[1] + "_" + a[2] + "_" + a[3]).innerHTML += + "
»" + a[4] + "
"; + } + } + + /* determine the title of this conversation */ + var details = parts[1].split(","); + var title = "
"+ details[3]+ " tarihli " + "[" + details[1]+ " ]"+ " ile " + "[ " + details[2] + " ] " + details[0] + " görüsme kaydi
"; + if (!details[1]) title = " "; + if (!parts[2]) parts[2] = " "; + + document.getElementById('im_status').style.display = "none"; + var bottom = parseInt(document.getElementById('im_content').scrollTop); + var bottom2 = parseInt(document.getElementById('im_content').style.height); + var absheight = parseInt( bottom + bottom2 ); + if (absheight == document.getElementById('im_content').scrollHeight) { + moveit = 1; + } else { + moveit = 0; + } + document.getElementById('im_content').innerHTML = parts[2]; + if (moveit == 1) { + document.getElementById('im_content').scrollTop = 0; + document.getElementById('im_content').scrollTop = document.getElementById('im_content').scrollHeight; + } + document.getElementById('im_content_title').innerHTML = title; + the_timeout = setTimeout( "xmlhttpPost();", 5000 ); +} + +function setsection(value) +{ + section = value; + clearTimeout(the_timeout); + xmlhttpPost(); + document.getElementById('im_content').scrollTop = 0; + document.getElementById('im_content').scrollTop = document.getElementById('im_content').scrollHeight; +} + +EOD; +print($zz); +?> + + + + + +
+
 
+ + + + + +
+
+
+
+
+
+
+ + + +
+ + + \ No newline at end of file -- cgit v1.2.3