aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Wagoner <rsw686@pfsense.org>2007-02-10 02:20:28 +0000
committerRyan Wagoner <rsw686@pfsense.org>2007-02-10 02:20:28 +0000
commitb26f654ff75c697650ddd07ef8c00a033d603249 (patch)
treef7d946895a2524f82f1620ab41d009f63c469d78
parent0934d67de454dfb2edef47ec156cc5df18304b3c (diff)
downloadpfsense-packages-b26f654ff75c697650ddd07ef8c00a033d603249.tar.gz
pfsense-packages-b26f654ff75c697650ddd07ef8c00a033d603249.tar.bz2
pfsense-packages-b26f654ff75c697650ddd07ef8c00a033d603249.zip
added ajax log viewer to imspector
-rw-r--r--packages/imspector/imspector.inc101
-rw-r--r--packages/imspector/imspector.xml57
-rw-r--r--packages/imspector/services_imspector_logs.php270
-rw-r--r--pkg_config.xml2
4 files changed, 362 insertions, 68 deletions
diff --git a/packages/imspector/imspector.inc b/packages/imspector/imspector.inc
index 70fea3d5..62ec3b5a 100644
--- a/packages/imspector/imspector.inc
+++ b/packages/imspector/imspector.inc
@@ -4,15 +4,28 @@
/* IMSpector */
+ define('IMSPECTOR_RCFILE', '/usr/local/etc/rc.d/imspector.sh');
+ define('IMSPECTOR_CONFIG','/usr/local/etc/imspector/imspector.conf');
+
function imspector_notice ($msg) { syslog(LOG_NOTICE, "imspector: $msg"); return; }
function imspector_warn ($msg) { syslog(LOG_WARNING, "imspector: $msg"); return; }
+
+ function imspector_action ($action) {
+ if (file_exists(IMSPECTOR_RCFILE))
+ mwexec(IMSPECTOR_RCFILE.' '.$action);
+ }
+
+ function imspector_running () {
+ if((int)exec("pgrep imspector | wc -l") > 0)
+ return true;
+ return false;
+ }
function imspector_config ($name) {
global $config;
if($config['installedpackages']['imspector']['config'][0]["{$name}"])
return $config['installedpackages']['imspector']['config'][0]["{$name}"];
- else
- return NULL;
+ return NULL;
}
function write_imspector_config($conf_file, $conf_text) {
@@ -38,7 +51,7 @@
switch ($proto) {
case "msn":
return 1863;
- case "icqaim":
+ case "icq":
return 5190;
case "yahoo":
return 5050;
@@ -48,7 +61,7 @@
return NULL;
}
}
-
+
function before_form_imspector($pkg) {
global $config;
@@ -64,23 +77,15 @@
function sync_package_imspector() {
global $config;
global $input_errors;
- $configfile = "/usr/local/etc/imspector/imspector.conf";
- $proto="";
- $pf_rules="";
+
+ config_lock();
/* remove existing rules */
exec("/sbin/pfctl -a imspector -Fr");
- exec("/sbin/pfctl -a imspector -Fn");
+ exec("/sbin/pfctl -a imspector -Fn");
- config_lock();
-
- if(imspector_config("proto_msn")) $proto .= "msn,";
- if(imspector_config("proto_icqaim")) $proto .= "icqaim,";
- if(imspector_config("proto_yahoo")) $proto .= "yahoo,";
- if(imspector_config("proto_irc")) $proto .= "irc,";
-
- if($proto != "")
- $proto_array = explode(",",$proto);
+ if(imspector_config("enable") && imspector_config("proto_array"))
+ $proto_array = explode(",",imspector_config("proto_array"));
if(imspector_config("enable") && imspector_config("iface_array"))
$iface_array = explode(",",imspector_config("iface_array"));
@@ -103,7 +108,7 @@
if(!$ifaces_active)
$ifaces_active = "{$iface}";
else
- $ifaces_active .= ", {$iface}";
+ $ifaces_active .= ", {$iface}";
} else {
imspector_warn("Interface {$iface} has no ip address, ignoring");
}
@@ -112,37 +117,36 @@
}
}
- if($pf_rules != "") {
+ if($pf_rules) {
exec("echo \"{$pf_rules}\" | /sbin/pfctl -a imspector -f -");
- conf_mount_rw();
-
$configtext = "plugin_dir=/usr/local/lib/imspector\n";
-
- if(imspector_config("proto_msn")) $configtext .= "msn_protocol=on\n";
- if(imspector_config("proto_icqaim")) $configtext .= "icq_protocol=on\n";
- if(imspector_config("proto_yahoo")) $configtext .= "yahoo_protocol=on\n";
- if(imspector_config("proto_irc")) $configtext .= "irc_protocol=on\n";
+
+ foreach($proto_array as $proto)
+ $configtext .= "{$proto}_protocol=on\n";
if(imspector_config("filter_badwords"))
- $configtext .= "badwords_filename=/usr/local/etc/imspector/badwords.txt\n";
+ $configtext .= "badwords_filename=/usr/local/etc/imspector/badwords.txt\n";
- if(imspector_config("log_file"))
- {
+ if(imspector_config("log_file")) {
exec("mkdir -p /var/log/imspector");
$configtext .= "file_logging_dir=/var/log/imspector\n";
}
- if(imspector_config("log_mysql"))
- {
+ if(imspector_config("log_mysql")) {
$configtext .= "mysql_server=".imspector_config("mysql_server")."\n";
$configtext .= "mysql_database=".imspector_config("mysql_database")."\n";
$configtext .= "mysql_username=".imspector_config("mysql_username")."\n";
$configtext .= "mysql_password=".imspector_config("mysql_password")."\n";
}
- write_imspector_config($configfile,$configtext);
-
+ /* XXX: for now just enable tracing of errors */
+ if(1) {
+ exec("mkdir -p /tmp/trace");
+ $configtext .= "icq_trace_error=on\n";
+ }
+
+ /* generate rc file start and stop */
$stop = <<<EOD
if [ `pgrep imspector | wc -l` != 0 ]; then
/usr/bin/killall imspector
@@ -151,50 +155,49 @@ if [ `pgrep imspector | wc -l` != 0 ]; then
done
fi
EOD;
-
- $start = <<<EOD
-{$stop}
- ldconfig -m /usr/local/lib/mysql
- /usr/local/sbin/imspector -c "{$configfile}"
-EOD;
+ $start = $stop."\n\tldconfig -m /usr/local/lib/mysql\n";
+ $start .= "\t/usr/local/sbin/imspector -c \"".IMSPECTOR_CONFIG."\"";
+
+ /* write out the configuration */
+ conf_mount_rw();
+ write_imspector_config(IMSPECTOR_CONFIG,$configtext);
write_rcfile(array(
"file" => "imspector.sh",
"start" => $start,
"stop" => $stop
)
);
-
conf_mount_ro();
/* if imspector not running start it */
- if(!is_service_running("imspector")) {
+ if(!imspector_running()) {
imspector_notice("Starting service on interface: {$ifaces_active}");
- start_service("imspector");
+ imspector_action("start");
}
/* or restart imspector if settings were changed */
elseif($_POST['iface_array']) {
imspector_notice("Restarting service on interface: {$ifaces_active}");
- restart_service("imspector");
+ imspector_action("restart");
}
}
}
- if(!$iface_array || !$proto_array || $pf_rules = "") {
+ if(!$iface_array || !$proto_array || !$pf_rules) {
/* no parameters user does not want imspector running */
/* lets stop the service and remove the rc file */
if(file_exists("/usr/local/etc/rc.d/imspector.sh")) {
if(!imspector_config("enable"))
- imspector_notice("Stopping service, imspector disabled");
+ imspector_notice("Stopping service: imspector disabled");
else
- imspector_notice("Stopping service, no interfaces and/or protocols selected");
+ imspector_notice("Stopping service: no interfaces and/or protocols selected");
- stop_service("imspector");
+ imspector_action("stop");
conf_mount_rw();
- unlink("/usr/local/etc/rc.d/imspector.sh");
- unlink($configfile);
+ unlink(IMSPECTOR_RCFILE);
+ unlink(IMSPECTOR_CONFIG);
conf_mount_ro();
}
}
diff --git a/packages/imspector/imspector.xml b/packages/imspector/imspector.xml
index dd5b4301..5a04edad 100644
--- a/packages/imspector/imspector.xml
+++ b/packages/imspector/imspector.xml
@@ -22,6 +22,17 @@
<rcfile>imspector.sh</rcfile>
<executable>imspector</executable>
</service>
+ <tabs>
+ <tab>
+ <text>IMSpector Log Viewer</text>
+ <url>services_imspector_logs.php</url>
+ </tab>
+ <tab>
+ <text>IMSpector Settings</text>
+ <url>/pkg_edit.php?xml=imspector.xml&amp;id=0</url>
+ <active/>
+ </tab>
+ </tabs>
<fields>
<field>
<fielddescr>Enable IMSpector</fielddescr>
@@ -36,31 +47,40 @@
<size>3</size>
<type>interfaces_selection</type>
<description>You can use the CTRL or COMMAND key to select multiple interfaces.</description>
+ <required/>
</field>
<field>
- <fielddescr>Listen on MSN protocol</fielddescr>
- <fieldname>proto_msn</fieldname>
- <type>checkbox</type>
- </field>
- <field>
- <fielddescr>Listen on ICQ/AIM protocol</fielddescr>
- <fieldname>proto_icqaim</fieldname>
- <type>checkbox</type>
- </field>
- <field>
- <fielddescr>Listen on Yahoo protocol</fielddescr>
- <fieldname>proto_yahoo</fieldname>
- <type>checkbox</type>
- </field>
- <field>
- <fielddescr>Listen on IRC protocol</fielddescr>
- <fieldname>proto_irc</fieldname>
- <type>checkbox</type>
+ <fielddescr>Listen on protocols</fielddescr>
+ <fieldname>proto_array</fieldname>
+ <multiple>true</multiple>
+ <type>select</type>
+ <size>4</size>
+ <description>You can use the CTRL or COMMAND key to select multiple protocols.</description>
+ <options>
+ <option>
+ <name>MSN</name>
+ <value>msn</value>
+ </option>
+ <option>
+ <name>ICQ/AIM</name>
+ <value>icq</value>
+ </option>
+ <option>
+ <name>Yahoo</name>
+ <value>yahoo</value>
+ </option>
+ <option>
+ <name>IRC</name>
+ <value>irc</value>
+ </option>
+ </options>
+ <required/>
</field>
<field>
<fielddescr>Enable filtering of bad words</fielddescr>
<fieldname>filter_badwords</fieldname>
<type>checkbox</type>
+ <description>Replaces words specified in /usr/local/etc/imspector/badwords.txt with *</description>
</field>
<field>
<fielddescr>Enable file logging</fielddescr>
@@ -72,6 +92,7 @@
<fielddescr>Enable MySQL logging</fielddescr>
<fieldname>log_mysql</fieldname>
<type>checkbox</type>
+ <description>Make sure to specify your MySQL credentials below</description>
</field>
<field>
<fielddescr>MySQL Server</fielddescr>
diff --git a/packages/imspector/services_imspector_logs.php b/packages/imspector/services_imspector_logs.php
new file mode 100644
index 00000000..816c43dc
--- /dev/null
+++ b/packages/imspector/services_imspector_logs.php
@@ -0,0 +1,270 @@
+<?php
+/*
+ services_imspector_logs.php
+ part of pfSense (http://www.pfsense.com/)
+
+ JavaScript Code is GPL Licensed from SmoothWall Express.
+
+ Copyright (C) 2007 Ryan Wagoner <ryan@wgnrs.dynu.com>.
+ 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/log/imspector';
+
+$protocol_color = '#06264d';
+$local_color = '#1d398b';
+$remote_color = '#2149c1';
+$conversation_color = '#335ebe';
+
+$local_user_color = 'blue';
+$local_user_bgcolor = '#e5e5f3';
+$remote_user_color = 'green';
+$remote_user_bgcolor = '#efeffa';
+
+/* functions */
+function convert_dir_list ($topdir) {
+ if (!is_dir($topdir)) return;
+ if ($dh = opendir($topdir)) {
+ while (($file = readdir($dh)) !== false) {
+ if(!preg_match('/^\./', $file) == 0) continue;
+ if (is_dir("$topdir/$file")) {
+ $list .= convert_dir_list("$topdir/$file");
+ } else {
+ $list .= "$topdir/$file\n";
+ }
+ }
+ 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')) {
+ print("<table width='100%' border='0' cellpadding='2' cellspacing='0'>\n");
+ while (!feof($fd)) {
+ $line = fgets($fd);
+ if(feof($fd)) continue;
+
+ preg_match('/([^,]*),([^,]*),([^,]*),(.*)/', $line, $matches);
+ $address = $matches[1];
+ $timestamp = $matches[2];
+ $type = $matches[3];
+ $data = $matches[4];
+
+ if($type == '1') $user = "&lt;<span style='color: $remote_user_color;'>$remoteuser</span>&gt;";
+ if($type == '2') $user = "&lt;<span style='color: $local_user_color;'>$localuser</span>&gt;";
+
+ if($type == '1') $bgcolor = $remote_user_bgcolor;
+ if($type == '2') $bgcolor = $local_user_bgcolor;
+
+ $time = strftime("%H:%M:%S", $timestamp);
+
+ print("<tr bgcolor='$bgcolor'><td style='width: 30px; vertical-align: top;'>[$time]</td>\n
+ <td style=' width: 60px; vertical-align: top;'>$user</td>\n
+ <td style='vertical-align: top;'>$data</td></tr>\n");
+ }
+ print("</table>\n");
+ fclose($fd);
+ }
+ }
+ exit;
+}
+/* defaults to this page but if no settings are present, redirect to setup page */
+if(!$config['installedpackages']['imspector']['config'][0]['iface_array'] ||
+ !$config['installedpackages']['imspector']['config'][0]['enable'])
+ 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("<meta http-equiv=\"refresh\" content=\"120;url={$_SERVER['SCRIPT_NAME']}\" />");
+//echo $pfSenseHead->getHTML();
+?>
+<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
+<?php include("fbegin.inc"); ?>
+<p class="pgtitle"><?=$pgtitle?></font></p>
+<?php if ($savemsg) print_info_box($savemsg); ?>
+<div id="mainlevel">
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+<?php
+ $tab_array = array();
+ $tab_array[] = array(gettext("IMSpector Log Viwer "), true, "/services_imspector_logs.php");
+ $tab_array[] = array(gettext("IMSpector Settings "), false, "/pkg_edit.php?xml=imspector.xml&id=0");
+ display_top_tabs($tab_array);
+?>
+</table>
+
+<?php
+$zz = <<<EOD
+<script type="text/javascript">
+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&section=" + 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 +=
+ "<div id='" + a[1] + "_t' style='width: 100%; background-color: #d9d9f3; color: $protocol_color;'>" + a[1] + "</div>" +
+ "<div id='" + a[1] + "' style='width: 100%; background-color: #e5e5f3;'></div>";
+ }
+ if (!document.getElementById(a[1] + "_" + a[2])) {
+ var imageref = "";
+ if (a[0]) imageref = "<img src='" + a[0] + "' alt='" + a[1] + "'/>";
+ document.getElementById(a[1]).innerHTML +=
+ "<div id='" + a[1] + "_" + a[2] + "_t' style='width: 100%; color: $local_color; padding-left: 5px;'>" + imageref + a[2] + "</div>" +
+ "<div id='" + a[1] + "_" + a[2] + "' style='width: 100%; background-color: #efeffa; border-bottom: solid 1px #d9d9f3;'></div>";
+ }
+ if (!document.getElementById(a[1] + "_" + a[2] + "_" + a[3])) {
+ document.getElementById(a[1] + "_" + a[2]).innerHTML +=
+ "<div id='" + a[1] + "_" + a[2] + "_" + a[3] + "_t' style='width: 100%; color: $remote_color; padding-left: 10px;'>" + a[3] + "</div>" +
+ "<div id='" + a[1] + "_" + a[2] + "_" + a[3] + "' style='width: 100%;'></div>";
+ }
+ if (!document.getElementById(a[1] + "_" + a[2] + "_" + a[3] + "_" + a[4])) {
+ document.getElementById(a[1] + "_" + a[2] + "_" + a[3]).innerHTML +=
+ "<div id='" + a[1] + "_" + a[2] + "_" + a[3] + "_" + a[4] +
+ "' style='width: 100%; color: $conversation_color; cursor: pointer; padding-left: 15px;' onClick=" +
+ '"' + "setsection('" + a[1] + "|" + a[2] + "|" + a[3] + "|" + a[4] + "');" + '"' + "' + >&raquo;" + a[4] + "</div>";
+ }
+ }
+
+ /* determine the title of this conversation */
+ var details = parts[1].split(",");
+ var title = details[0] + " conversation between <span style='color: $local_user_color;'>" + details[ 1 ] +
+ "</span> and <span style='color: $remote_user_color;'>" + details[2] + "</span>";
+ if (!details[1]) title = "&nbsp;";
+ if (!parts[2]) parts[2] = "&nbsp;";
+
+ 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;
+}
+</script>
+EOD;
+print($zz);
+?>
+
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td class="tabcont">
+ <div style='width: 100%; text-align: right;'><span id='im_status' style='display: none;'>Updating</span>&nbsp;</div>
+ <table width="100%">
+ <tr>
+ <td width="15%" bgcolor="#efeffa" style="overflow: auto; border: solid 1px #c0c0c0;">
+ <div id="im_convos" style="height: 400px; overflow: auto; overflow-x: hidden;"></div>
+ </td>
+ <td width="75%" bgcolor="#efeffa" style="border: solid 1px #c0c0c0;">
+ <div id="im_content_title" style="height: 20px; overflow: auto; vertical-align: top; background-color: #d9d9f3;"></div>
+ <div id="im_content" style="height: 380px; overflow: auto; vertical-align: bottom; overflow-x: hidden;"></div>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+
+<script type="text/javascript">xmlhttpPost();</script>
+
+</div>
+<?php include("fend.inc"); ?>
+</body>
+</html>
diff --git a/pkg_config.xml b/pkg_config.xml
index 3cdb026c..e6d18e5e 100644
--- a/pkg_config.xml
+++ b/pkg_config.xml
@@ -168,7 +168,7 @@
</package>
<package>
<name>imspector</name>
- <descr>** REQUIRES: 1.0.1-SNAPSHOT-11-24-2006 OR LATER ** IMSpector is an Instant Messenger
+ <descr>** REQUIRES: 1.0.1-SNAPSHOT-01-22-2006 OR LATER ** IMSpector is an Instant Messenger
transparent proxy with logging capabilities. Currently it supports MSN, AIM, ICQ, Yahoo and
IRC to different degrees.</descr>
<website>http://www.imspector.org/</website>