aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Wagoner <rsw686@pfsense.org>2006-12-15 16:47:15 +0000
committerRyan Wagoner <rsw686@pfsense.org>2006-12-15 16:47:15 +0000
commit5e1940e84a88f8f1332a61ab9b8fe2ea8e72e253 (patch)
tree0203470c616820c2360dea4a15318c1d32d4698f
parent40bc7cb32abaa8bd04862658cce48a0453704ca7 (diff)
downloadpfsense-packages-5e1940e84a88f8f1332a61ab9b8fe2ea8e72e253.tar.gz
pfsense-packages-5e1940e84a88f8f1332a61ab9b8fe2ea8e72e253.tar.bz2
pfsense-packages-5e1940e84a88f8f1332a61ab9b8fe2ea8e72e253.zip
add enable checkbox to imspector, cleanup include code
-rw-r--r--packages/imspector/imspector.inc83
-rw-r--r--packages/imspector/imspector.xml11
2 files changed, 64 insertions, 30 deletions
diff --git a/packages/imspector/imspector.inc b/packages/imspector/imspector.inc
index 875bcf43..70fea3d5 100644
--- a/packages/imspector/imspector.inc
+++ b/packages/imspector/imspector.inc
@@ -68,27 +68,24 @@
$proto="";
$pf_rules="";
- imspector_notice("Syncing package");
-
/* remove existing rules */
- exec("/sbin/pfctl -a imspector -Fr");
+ exec("/sbin/pfctl -a imspector -Fr");
exec("/sbin/pfctl -a imspector -Fn");
- conf_mount_rw();
- config_lock();
+ 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 != "")
+ if($proto != "")
$proto_array = explode(",",$proto);
- if(imspector_config("iface_array"))
+ if(imspector_config("enable") && imspector_config("iface_array"))
$iface_array = explode(",",imspector_config("iface_array"));
- if($iface_array && $proto_array) {
+ if($iface_array && $proto_array) {
foreach($iface_array as $iface) {
$if = convert_friendly_interface_to_real_interface_name($iface);
/* above function returns iface if fail */
@@ -102,26 +99,39 @@
/* we can use rdr pass to auto create the filter rule */
$pf_rules .= imspector_pf_rdr($if,imspector_proto_to_port($proto));
}
- }
+ }
+ if(!$ifaces_active)
+ $ifaces_active = "{$iface}";
+ else
+ $ifaces_active .= ", {$iface}";
+ } else {
+ imspector_warn("Interface {$iface} has no ip address, ignoring");
}
+ } else {
+ imspector_warn("Could not resolve real interface for {$iface}");
}
}
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";
+
+ if(imspector_config("filter_badwords"))
+ $configtext .= "badwords_filename=/usr/local/etc/imspector/badwords.txt\n";
if(imspector_config("log_file"))
+ {
+ exec("mkdir -p /var/log/imspector");
$configtext .= "file_logging_dir=/var/log/imspector\n";
-
- if(imspector_config("filter_badwords"))
- $configtext .= "badwords_filename=/usr/local/etc/imspector/badwords.txt\n";
+ }
if(imspector_config("log_mysql"))
{
@@ -142,8 +152,11 @@ if [ `pgrep imspector | wc -l` != 0 ]; then
fi
EOD;
- $start = $stop."\n\tldconfig -m /usr/local/lib/mysql\n";
- $start .= "\t/usr/local/sbin/imspector -c \"{$configfile}\"";
+ $start = <<<EOD
+{$stop}
+ ldconfig -m /usr/local/lib/mysql
+ /usr/local/sbin/imspector -c "{$configfile}"
+EOD;
write_rcfile(array(
"file" => "imspector.sh",
@@ -151,27 +164,41 @@ EOD;
"stop" => $stop
)
);
+
+ conf_mount_ro();
+
+ /* if imspector not running start it */
+ if(!is_service_running("imspector")) {
+ imspector_notice("Starting service on interface: {$ifaces_active}");
+ start_service("imspector");
+ }
+ /* or restart imspector if settings were changed */
+ elseif($_POST['iface_array']) {
+ imspector_notice("Restarting service on interface: {$ifaces_active}");
+ restart_service("imspector");
+ }
}
-
- if((int)exec("pgrep imspector | wc -l") == 0 || $_POST['iface_array']) {
- imspector_notice("Starting service");
- if(imspector_config("log_file"))
- exec("mkdir -p /var/log/imspector");
- start_service("imspector");
- }
}
if(!$iface_array || !$proto_array || $pf_rules = "") {
/* no parameters user does not want imspector running */
/* lets stop the service and remove the rc file */
-
- stop_service("imspector");
- imspector_warn("No interfaces and/or protocols stopping service");
- exec("rm -f /usr/local/etc/rc.d/imspector*");
- exec("rm -f {$configfile}");
+
+ if(file_exists("/usr/local/etc/rc.d/imspector.sh")) {
+ if(!imspector_config("enable"))
+ imspector_notice("Stopping service, imspector disabled");
+ else
+ imspector_notice("Stopping service, no interfaces and/or protocols selected");
+
+ stop_service("imspector");
+
+ conf_mount_rw();
+ unlink("/usr/local/etc/rc.d/imspector.sh");
+ unlink($configfile);
+ conf_mount_ro();
+ }
}
- config_unlock();
- conf_mount_ro();
+ config_unlock();
}
?>
diff --git a/packages/imspector/imspector.xml b/packages/imspector/imspector.xml
index 8678b08f..dd5b4301 100644
--- a/packages/imspector/imspector.xml
+++ b/packages/imspector/imspector.xml
@@ -24,12 +24,18 @@
</service>
<fields>
<field>
- <fielddescr>Interface (generally LAN)</fielddescr>
+ <fielddescr>Enable IMSpector</fielddescr>
+ <fieldname>enable</fieldname>
+ <type>checkbox</type>
+ </field>
+ <field>
+ <fielddescr>Interfaces (generally LAN)</fielddescr>
<fieldname>iface_array</fieldname>
<value>lan</value>
<multiple>true</multiple>
<size>3</size>
<type>interfaces_selection</type>
+ <description>You can use the CTRL or COMMAND key to select multiple interfaces.</description>
</field>
<field>
<fielddescr>Listen on MSN protocol</fielddescr>
@@ -57,9 +63,10 @@
<type>checkbox</type>
</field>
<field>
- <fielddescr>Enable file logging (stored in /var/log/imspector)</fielddescr>
+ <fielddescr>Enable file logging</fielddescr>
<fieldname>log_file</fieldname>
<type>checkbox</type>
+ <description>Log files stored in /var/log/imspector</description>
</field>
<field>
<fielddescr>Enable MySQL logging</fielddescr>