From 7eb458b55f1185e85d0c3e495d00aa65cfc6beca Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Mon, 29 Sep 2014 00:03:20 +0200 Subject: spamd, fix spamtrap and blacklist buttons, fix startup on pfSense 2.2 --- config/spamd/spamd.inc | 16 ++++++++++++---- config/spamd/spamd_db.php | 42 +++++++++++++++++++++++------------------ config/spamd/spamd_settings.xml | 2 +- 3 files changed, 37 insertions(+), 23 deletions(-) (limited to 'config') diff --git a/config/spamd/spamd.inc b/config/spamd/spamd.inc index 0bd29bd8..d55dc132 100644 --- a/config/spamd/spamd.inc +++ b/config/spamd/spamd.inc @@ -34,6 +34,13 @@ if(!function_exists("filter_configure")) function sync_package_spamd() { global $config, $g; + $pf_version = substr(trim(file_get_contents("/etc/version")),0,3); + if ($pf_version < 2.2) { + $localpath = "/usr/local"; + } else { + $ARCH = php_uname("m"); + $localpath = "/usr/pbi/spamd-$ARCH/local"; + } conf_mount_rw(); config_lock(); @@ -130,8 +137,8 @@ function sync_package_spamd() { "fi\n" . "/usr/local/sbin/spamd-setup -d &\n" . "/sbin/pflogd &\n" . - "/usr/local/libexec/spamd {$greyparms}{$identifier}{$greylisting}{$maxcon}{$maxblack}{$window}{$replysmtperror} 127.0.0.1 &\n" . - "/usr/local/libexec/spamlogd\n"; + "$localpath/libexec/spamd {$greyparms}{$identifier}{$greylisting}{$maxcon}{$maxblack}{$window}{$replysmtperror} 127.0.0.1 &\n" . + "$localpath/libexec/spamlogd\n"; $stop = "/usr/bin/killall spamd-setup\n" . "/usr/bin/killall spamlogd\n" . "/usr/bin/killall spamd\n" . @@ -153,8 +160,9 @@ function sync_package_spamd() { log_error("Restart cron"); mwexec("killall -HUP cron"); log_error("Setting up spamd.conf symlink"); - mwexec("rm -f /usr/local/etc/spamd/spamd.conf"); - mwexec("ln -s /etc/spamd.conf /usr/local/etc/spamd/spamd.conf"); + mwexec("rm -f $localpath/etc/spamd/spamd.conf"); + mwexec("ln -s /etc/spamd.conf $localpath/etc/spamd/spamd.conf"); + log_error("Stopping spamd"); mwexec("/usr/local/etc/rc.d/spamd.sh stop"); sleep(1); diff --git a/config/spamd/spamd_db.php b/config/spamd/spamd_db.php index c2df25d1..b2c4c476 100644 --- a/config/spamd/spamd_db.php +++ b/config/spamd/spamd_db.php @@ -30,6 +30,10 @@ require("guiconfig.inc"); +$pf_version=substr(trim(file_get_contents("/etc/version")),0,3); +if ($pf_version < 2.0) + $one_two = true; + if($_POST['filter']) $filter = $_POST['filter']; if($_POST['not']) @@ -53,8 +57,10 @@ if($_GET['action'] or $_POST['action']) { $srcip = $_GET['srcip']; if($_POST['srcip']) $srcip = $_POST['srcip']; - if($_POST['toaddress']) - $toaddress = escapeshellarg($_POST['toaddress']); + if($_GET['spamtrapemail']) + $spamtrapemail = escapeshellarg($_GET['spamtrapemail']); + if($_POST['spamtrapemail']) + $spamtrapemail = escapeshellarg($_POST['spamtrapemail']); $srcip = str_replace("<","",$srcip); $srcip = str_replace(">","",$srcip); $srcip = str_replace(" ","",$srcip); @@ -62,7 +68,6 @@ if($_GET['action'] or $_POST['action']) { $srcip = escapeshellarg($srcip); /* execute spamdb command */ if($action == "'whitelist'") { - exec("/usr/local/sbin/spamdb -d {$srcip}"); exec("/usr/local/sbin/spamdb -d {$srcip} -T"); exec("/usr/local/sbin/spamdb -d {$srcip} -t"); delete_from_blacklist($srcip); @@ -76,14 +81,13 @@ if($_GET['action'] or $_POST['action']) { delete_from_blacklist($srcip); mwexec("/sbin/pfctl -q -t spamd -T delete $srcip"); mwexec("/sbin/pfctl -q -t blacklist -T replace -f /var/db/blacklist.txt"); - } else if($action == "'spamtrap'") { - exec("/usr/local/sbin/spamdb -d {$srcip}"); - exec("/usr/local/sbin/spamdb -d {$srcip} -T"); - exec("/usr/local/sbin/spamdb -d {$srcip} -t"); - exec("/usr/local/sbin/spamdb -a {$srcip} -T"); } else if($action == "'trapped'") { - exec("/usr/local/sbin/spamdb -T -d {$toaddress}"); - exec("/usr/local/sbin/spamdb -T -a '{$toaddress}'"); + exec("/usr/local/sbin/spamdb -d {$srcip}"); + exec("/usr/local/sbin/spamdb -d {$srcip}"); + exec("/usr/local/sbin/spamdb -d -t {$srcip}"); + exec("/usr/local/sbin/spamdb -a -t {$srcip}"); + } else if($action == "'spamtrap'") { + exec("/usr/local/sbin/spamdb -a -T {$spamtrapemail}"); } /* signal a reload for real time effect. */ mwexec("killall -HUP spamlogd"); @@ -144,7 +148,7 @@ if($_GET['whitelist'] <> "") { function delete_from_blacklist($srcip) { config_lock(); - $blacklist = split("\n", file_get_contents("/var/db/blacklist.txt")); + $blacklist = explode("\n", file_get_contents("/var/db/blacklist.txt")); $fd = fopen("/var/db/blacklist.txt", "w"); foreach($blacklist as $bl) { if($bl <> "") @@ -159,7 +163,7 @@ function delete_from_blacklist($srcip) { function delete_from_whitelist($srcip) { config_lock(); - $whitelist = split("\n", file_get_contents("/var/db/whitelist.txt")); + $whitelist = explode("\n", file_get_contents("/var/db/whitelist.txt")); $fd = fopen("/var/db/whitelist.txt", "w"); foreach($whitelist as $wl) { if($wl <> "") @@ -200,7 +204,9 @@ $blacklist_items = $blacklist_items + $spamdb_black; ?> +

+
@@ -326,10 +332,10 @@ if (typeof getURL == 'undefined') { $cmd = "/usr/local/sbin/spamdb | grep -v \"" . escapeshellarg($filter) . "\" | tail -n {$limit}"; fwrite($fd, $cmd); fclose($fd); - $pkgdb = split("\n", `$cmd`); + $pkgdb = explode("\n", `$cmd`); if(file_exists("/var/db/blacklist.txt")) { $cmd = "cat /var/db/blacklist.txt | grep -v \"" . escapeshellarg($filter) . "\" "; - $pkgdba = split("\n", `$cmd`); + $pkgdba = explode("\n", `$cmd`); foreach($pkgdba as $pkg) { $pkgdb[] = "TRAPPED|{$pkg}|1149324397"; } @@ -338,10 +344,10 @@ if (typeof getURL == 'undefined') { $cmd = "/usr/local/sbin/spamdb | grep " . escapeshellarg($filter) . " | tail -n {$limit}"; - $pkgdb = split("\n", `$cmd`); + $pkgdb = explode("\n", `$cmd`); if(file_exists("/var/db/blacklist.txt")) { $cmd = "cat /var/db/blacklist.txt | grep " . escapeshellarg($filter); - $pkgdba = split("\n", `$cmd`); + $pkgdba = explode("\n", `$cmd`); foreach($pkgdba as $pkg) { $pkgdb[] = "TRAPPED|{$pkg}|1149324397"; } @@ -349,7 +355,7 @@ if (typeof getURL == 'undefined') { } } } else { - $pkgdb = split("\n", `/usr/local/sbin/spamdb | tail -n {$limit}`); + $pkgdb = explode("\n", `/usr/local/sbin/spamdb | tail -n {$limit}`); } $rows = 0; $lastseenip = ""; @@ -361,7 +367,7 @@ if (typeof getURL == 'undefined') { $dontdisplay = false; if(!$pkgdb_row) continue; - $pkgdb_split = split("\|", $pkgdb_row); + $pkgdb_split = explode("|", $pkgdb_row); /* diff --git a/config/spamd/spamd_settings.xml b/config/spamd/spamd_settings.xml index 7ed4c572..3fdab415 100644 --- a/config/spamd/spamd_settings.xml +++ b/config/spamd/spamd_settings.xml @@ -43,7 +43,7 @@ Currently there are no FAQ items provided. spamdsettings 1.1.1 - SpamD Settings + SpamD: Settings pkg_edit.php?xml=spamd_settings.xml&id=0 /usr/local/pkg/spamd.inc -- cgit v1.2.3 From ca670f24bdb0ec7488fbeeeaed14fc82f8e50a5e Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Tue, 30 Sep 2014 19:54:54 +0200 Subject: spamd, replace the shell calls by unlink_if_exists() and symlink() --- config/spamd/spamd.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'config') diff --git a/config/spamd/spamd.inc b/config/spamd/spamd.inc index d55dc132..e09b2b7f 100644 --- a/config/spamd/spamd.inc +++ b/config/spamd/spamd.inc @@ -160,8 +160,8 @@ function sync_package_spamd() { log_error("Restart cron"); mwexec("killall -HUP cron"); log_error("Setting up spamd.conf symlink"); - mwexec("rm -f $localpath/etc/spamd/spamd.conf"); - mwexec("ln -s /etc/spamd.conf $localpath/etc/spamd/spamd.conf"); + unlink_if_exists("$localpath/etc/spamd/spamd.conf"); + symlink("/etc/spamd.conf", "$localpath/etc/spamd/spamd.conf"); log_error("Stopping spamd"); mwexec("/usr/local/etc/rc.d/spamd.sh stop"); -- cgit v1.2.3 From 7aac4188282948ac508a1fa3b625dbf514e9d0e4 Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Thu, 2 Oct 2014 21:41:50 +0200 Subject: spamd, -fix 'add spamtrap' -use exec() instead of exploding output of directly invoking a shell command --- config/spamd/spamd_db.php | 54 ++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) (limited to 'config') diff --git a/config/spamd/spamd_db.php b/config/spamd/spamd_db.php index b2c4c476..e1d004f7 100644 --- a/config/spamd/spamd_db.php +++ b/config/spamd/spamd_db.php @@ -43,6 +43,13 @@ if($_POST['limit']) else $limit = "25"; +if($_GET['spamtrapemail']) + $spamtrapemail = $_GET['spamtrapemail']; +if($_POST['spamtrapemail']) + $spamtrapemail = $_POST['spamtrapemail']; +if ($spamtrapemail) + $spamtrapemailarg = escapeshellarg($spamtrapemail); + /* handle AJAX operations */ if($_GET['action'] or $_POST['action']) { /* echo back buttonid so it can be turned @@ -50,60 +57,52 @@ if($_GET['action'] or $_POST['action']) { */ echo $_GET['buttonid'] . "|"; if($_GET['action']) - $action = escapeshellarg($_GET['action']); + $action = $_GET['action']; if($_POST['action']) - $action = escapeshellarg($_POST['action']); + $action = $_POST['action']; if($_GET['srcip']) $srcip = $_GET['srcip']; if($_POST['srcip']) $srcip = $_POST['srcip']; - if($_GET['spamtrapemail']) - $spamtrapemail = escapeshellarg($_GET['spamtrapemail']); - if($_POST['spamtrapemail']) - $spamtrapemail = escapeshellarg($_POST['spamtrapemail']); $srcip = str_replace("<","",$srcip); $srcip = str_replace(">","",$srcip); $srcip = str_replace(" ","",$srcip); // Make input safe $srcip = escapeshellarg($srcip); /* execute spamdb command */ - if($action == "'whitelist'") { + if($action == "whitelist") { exec("/usr/local/sbin/spamdb -d {$srcip} -T"); exec("/usr/local/sbin/spamdb -d {$srcip} -t"); delete_from_blacklist($srcip); mwexec("/sbin/pfctl -q -t blacklist -T replace -f /var/db/blacklist.txt"); exec("echo spamdb -a {$srcip} > /tmp/tmp"); exec("/usr/local/sbin/spamdb -a {$srcip}"); - } else if($action == "'delete'") { + } else if($action == "delete") { exec("/usr/local/sbin/spamdb -d {$srcip}"); exec("/usr/local/sbin/spamdb -d {$srcip} -T"); exec("/usr/local/sbin/spamdb -d {$srcip} -t"); delete_from_blacklist($srcip); mwexec("/sbin/pfctl -q -t spamd -T delete $srcip"); mwexec("/sbin/pfctl -q -t blacklist -T replace -f /var/db/blacklist.txt"); - } else if($action == "'trapped'") { + } else if($action == "trapped") { exec("/usr/local/sbin/spamdb -d {$srcip}"); exec("/usr/local/sbin/spamdb -d {$srcip}"); exec("/usr/local/sbin/spamdb -d -t {$srcip}"); exec("/usr/local/sbin/spamdb -a -t {$srcip}"); - } else if($action == "'spamtrap'") { - exec("/usr/local/sbin/spamdb -a -T {$spamtrapemail}"); + } else if($action == "spamtrap") { + exec("/usr/local/sbin/spamdb -a -T {$spamtrapemailarg}"); } /* signal a reload for real time effect. */ mwexec("killall -HUP spamlogd"); exit; } -/* spam trap e-mail address */ -if($_POST['spamtrapemail'] <> "") { - $spamtrapemail = escapeshellarg($_POST['spamtrapemail']); - exec("/usr/local/sbin/spamdb -d {$spamtrapemail}"); - exec("/usr/local/sbin/spamdb -d -T {$spamtrapemail}"); - exec("/usr/local/sbin/spamdb -d -t {$spamtrapemail}"); - exec("/usr/local/sbin/spamdb -T -a '{$toaddress}'"); +/* spam trap e-mail address */ +if($spamtrapemail <> "") { + exec("spamdb -T -a {$spamtrapemailarg}"); mwexec("killall -HUP spamlogd"); - $savemsg = htmlentities($_POST['spamtrapemail']) . " added to spam trap database."; + $savemsg = htmlentities($spamtrapemail) . " added to spam trap database."; } if($_GET['getstatus'] <> "") { @@ -124,8 +123,7 @@ if($_GET['getstatus'] <> "") { /* spam trap e-mail address */ if($_GET['spamtrapemail'] <> "") { - $spamtrapemail = escapeshellarg($_GET['spamtrapemail']); - $status = exec("spamdb -T -a {$spamtrapemail}"); + $status = exec("spamdb -T -a {$spamtrapemailarg}"); mwexec("killall -HUP spamlogd"); if($status) echo $status; @@ -329,25 +327,23 @@ if (typeof getURL == 'undefined') { if($filter) { if($not) { $fd = fopen("/tmp/spamdb", "w"); - $cmd = "/usr/local/sbin/spamdb | grep -v \"" . escapeshellarg($filter) . "\" | tail -n {$limit}"; + $cmd = "/usr/local/sbin/spamdb | grep -v " . escapeshellarg($filter) . " | tail -n {$limit}"; fwrite($fd, $cmd); fclose($fd); - $pkgdb = explode("\n", `$cmd`); + exec($cmd, $pkgdb); if(file_exists("/var/db/blacklist.txt")) { $cmd = "cat /var/db/blacklist.txt | grep -v \"" . escapeshellarg($filter) . "\" "; - $pkgdba = explode("\n", `$cmd`); + exec($cmd, $pkgdba); foreach($pkgdba as $pkg) { $pkgdb[] = "TRAPPED|{$pkg}|1149324397"; } } } else { - $cmd = "/usr/local/sbin/spamdb | grep " . escapeshellarg($filter) . " | tail -n {$limit}"; - - $pkgdb = explode("\n", `$cmd`); + exec($cmd, $pkgdb); if(file_exists("/var/db/blacklist.txt")) { $cmd = "cat /var/db/blacklist.txt | grep " . escapeshellarg($filter); - $pkgdba = explode("\n", `$cmd`); + exec($cmd, $pkgdba); foreach($pkgdba as $pkg) { $pkgdb[] = "TRAPPED|{$pkg}|1149324397"; } @@ -355,7 +351,7 @@ if (typeof getURL == 'undefined') { } } } else { - $pkgdb = explode("\n", `/usr/local/sbin/spamdb | tail -n {$limit}`); + exec("/usr/local/sbin/spamdb | tail -n {$limit}", $pkgdb); } $rows = 0; $lastseenip = ""; -- cgit v1.2.3