diff options
author | marcelloc <marcellocoutinho@gmail.com> | 2011-11-14 19:40:10 -0200 |
---|---|---|
committer | marcelloc <marcellocoutinho@gmail.com> | 2011-11-14 19:40:10 -0200 |
commit | 1a900aafa3d7996900e61ee3656fbffa6c7effb2 (patch) | |
tree | da7b661736ab4ebd42714b34e2a4280b5143e5cc /config | |
parent | 9ff3c62d06aa14a68c7b3c882a86b7418c01a0f7 (diff) | |
download | pfsense-packages-1a900aafa3d7996900e61ee3656fbffa6c7effb2.tar.gz pfsense-packages-1a900aafa3d7996900e61ee3656fbffa6c7effb2.tar.bz2 pfsense-packages-1a900aafa3d7996900e61ee3656fbffa6c7effb2.zip |
postfix - include sqlite databases, mail search, cron updates and minor gui changes
Diffstat (limited to 'config')
-rw-r--r-- | config/postfix/postfix.inc | 138 | ||||
-rw-r--r-- | config/postfix/postfix.php | 423 | ||||
-rw-r--r-- | config/postfix/postfix.xml | 43 | ||||
-rw-r--r-- | config/postfix/postfix_acl.xml | 4 | ||||
-rw-r--r-- | config/postfix/postfix_antispam.xml | 26 | ||||
-rw-r--r-- | config/postfix/postfix_recipients.xml | 4 | ||||
-rwxr-xr-x | config/postfix/postfix_search.php | 227 | ||||
-rw-r--r-- | config/postfix/postfix_sync.xml | 4 | ||||
-rw-r--r-- | config/postfix/postfix_view_config.php | 4 |
9 files changed, 838 insertions, 35 deletions
diff --git a/config/postfix/postfix.inc b/config/postfix/postfix.inc index e8152be7..ca81be8e 100644 --- a/config/postfix/postfix.inc +++ b/config/postfix/postfix.inc @@ -42,6 +42,7 @@ function px_get_real_interface_address($iface) { global $config; $iface = convert_friendly_interface_to_real_interface_name($iface); $line = trim(shell_exec("ifconfig $iface | grep inet | grep -v inet6")); + $postfix_enabled=$config['installedpackages']['postfix']['config'][0]['enable_postfix']; list($dummy, $ip, $dummy2, $netmask) = explode(" ", $line); return array($ip, long2ip(hexdec($netmask))); } @@ -53,6 +54,8 @@ function sync_relay_recipients($via_cron="cron"){ $relay_recipients=""; $relay_ldap_recipients=""; $ad_export="/usr/local/etc/postfix/adexport.pl"; + $cron_cmd="/usr/local/bin/php -q /usr/local/www/postfix_recipients.php"; + $postfix_enabled=$config['installedpackages']['postfix']['config'][0]['enable_postfix']; foreach ($config['installedpackages']['postfixrecipients']['config'] as $postfix_recipients_config) { if($postfix_recipients_config['location'] && file_exists($postfix_recipients_config['location'])) $relay_recipients .= file_get_contents($postfix_recipients_config['location']); @@ -61,36 +64,26 @@ function sync_relay_recipients($via_cron="cron"){ if($postfix_recipients_config['enable_ldap']){ #validate cront job if(preg_match("/(\d+)(\w)/",$postfix_recipients_config['freq'],$matches)){ - $cron_sufix="\t*\t*\troot\t/usr/local/bin/php /usr/local/www/postfix_recipients.php"; + $cron_postfix=array("minute" => "*", + "hour" => "*", + "mday" => "*", + "month" => "*", + "wday" => "*", + "who" => "root", + "command"=> $cron_cmd); switch ($matches[2]){ case m: - $cron= "*/".$matches[1]."\t*\t*".$cron_sufix; + $cron_postfix["month"]="*/".$matches[1]; break; case h: - $cron= "0\t*/".$matches[1]."\t*".$cron_sufix; + $cron_postfix["hour"]="*/".$matches[1]; break; case d: - $cron= "0\t0\t*/".$matches[1].$cron_sufix; + $cron_postfix["mday"]="*/".$matches[1]; break; default: $input_errors[] = "A valid number with a time reference is required for the field 'Frequency'"; } - #update cront job file - $crontab = file('/etc/crontab'); - foreach ($crontab as $line) - $new_cron.=(preg_match("/postfix_recipients.php/",$line)?$cron."\n":$line); - #include if conf does not exist in crontab - $new_cron.=(!preg_match("/postfix_recipients.php/",$new_cron)?"\n".$cron."\n\n":""); - file_put_contents("/etc/crontab",$new_cron, LOCK_EX); - #check crontab changes - $md5_new_file = trim(md5_file('/etc/crontab')); - if(file_exists('/etc/crontab.md5')) - $md5_old_file = trim(file_get_contents('/etc/crontab.md5')); - if($md5_new_file <> $md5_old_file){ - mwexec('/usr/bin/killall -HUP cron'); - file_put_contents("/etc/crontab.md5",$md5_new_file, LOCK_EX); - } - } $relay_ldap_recipients=""; if ($via_cron == "gui"){ #running via pfsense gui, not time for ldap fetch. @@ -139,7 +132,106 @@ function sync_relay_recipients($via_cron="cron"){ file_put_contents("/usr/local/etc/postfix/relay_ldap_recipients.txt",$relay_ldap_recipients, LOCK_EX); } } + } + #check crontab + $new_cron=array(); + $cron_cmd_sqlite = ""; + $cron_postfix_sqlite=""; + #check crontab Sqlite databases + if (is_array($config['installedpackages']['postfix']['config']) && $postfix_enabled=="on"){ + $cron_sqlite_queue=$config['installedpackages']['postfix']['config'][0]['update_sqlite']; + $cron_cmd_sqlite="/usr/local/bin/php -q /usr/local/www/postfix.php"; + if ($cron_sqlite_queue != "" && $cron_sqlite_queue != "never"){ + $cron_postfix_sqlite=array("minute" => "*", + "hour" => "*", + "mday" => "*", + "month" => "*", + "wday" => "*", + "who" => "root", + "command"=> ""); + switch ($cron_sqlite_queue){ + case '10min': + $cron_postfix_sqlite["minute"]="*/10"; + $cron_postfix_sqlite["command"] = $cron_cmd_sqlite ." 10min"; + break; + case '01hour': + $cron_postfix_sqlite["minute"]="0"; + $cron_postfix_sqlite["command"] = $cron_cmd_sqlite ." 01hour"; + break; + case '24hours': + $cron_postfix_sqlite["minute"]="0"; + $cron_postfix_sqlite["hour"]="0"; + $cron_postfix_sqlite["command"] = $cron_cmd_sqlite ." 24hours"; + break; + } + } + } + + #check crontab relay recipients + $cron_found=""; + if (is_array($config['cron']['item'])){ + #print "<pre>"; + foreach($config['cron']['item'] as $cron){ + #check valid_recipients cron + if ($cron["command"] == $cron_cmd){ + #postfix cron cmd found + if($postfix_enabled=="on") + $cron_found=$cron; + if($postfix_recipients_config['enable_ldap'] && $postfix_enabled=="on") + #update cron schedule + $new_cron['item'][]=$cron_postfix; + } + #check sqlite update queue + else if(!preg_match("/.usr.local.www.postfix.php/",$cron["command"])){ + #keep all non postfix cron cmds if not empty + if ($cron["command"] != "") + $new_cron['item'][]=$cron; + } + } + $write_cron=1; + # Check if crontab must be changed to valid recipients cmd + if ($postfix_recipients_config['enable_ldap']){ + if ($cron_found!=$cron_postfix){ + #update postfix cron schedule + if (! is_array($cron_found) && $postfix_enabled=="on") + $new_cron['item'][]=$cron_postfix; + $write_cron=1; + } + } + else{ + if (is_array($cron_found)){ + #remove postfix cron cmd + $write_cron=1; + } + } + #check if cron must be changed to Sqlite cmd + if($cron_sqlite_queue != "" && $cron_sqlite_queue != "never"){ + $new_cron['item'][]=$cron_postfix_sqlite; + $config['cron']=$new_cron; + $write_cron=1; + } + } + + #call cron functions + if ($write_cron==1){ + $config['cron']=$new_cron; + write_config(); + configure_cron(); + } + #remove postfix old cron call + $old_cron=0; + $crontab = file('/etc/crontab'); + $new_crontab=""; + foreach ($crontab as $line){ + if (preg_match("/php..usr.local.www.postfix_recipients.php/",$line)) + $old_cron=1; + else + $new_crontab .= $line; + } + if ($old_cron==1) + file_put_contents("/etc/crontab",$new_crontab, LOCK_EX); } + #save all relay recipients and reload postfix file_put_contents("/usr/local/etc/postfix/relay_recipients",$relay_ldap_recipients."\n".$relay_recipients, LOCK_EX); exec("/usr/local/sbin/postmap /usr/local/etc/postfix/relay_recipients"); @@ -286,7 +378,7 @@ EOF; break; } } - + $reject_unknown_helo_hostname=($antispam['reject_unknown_helo_hostname']?"reject_unknown_helo_hostname":""); if ($antispam['header_check'] == "strong") { $postfix_main .= <<<EOF @@ -298,7 +390,7 @@ smtpd_delay_reject = yes # Don't talk to mail systems that don't know their own hostname. smtpd_helo_required = yes -smtpd_helo_restrictions = reject_unknown_helo_hostname +smtpd_helo_restrictions ={$reject_unknown_helo_hostname} smtpd_sender_restrictions = reject_non_fqdn_sender, reject_unknown_sender_domain, @@ -334,7 +426,7 @@ smtpd_delay_reject = yes # Don't talk to mail systems that don't know their own hostname. smtpd_helo_required = yes -smtpd_helo_restrictions = reject_unknown_helo_hostname +smtpd_helo_restrictions = {$reject_unknown_helo_hostname} smtpd_sender_restrictions = reject_unknown_sender_domain, RBLRBLRBL diff --git a/config/postfix/postfix.php b/config/postfix/postfix.php new file mode 100644 index 00000000..992c82c2 --- /dev/null +++ b/config/postfix/postfix.php @@ -0,0 +1,423 @@ +<?php
+/*
+ postfix.php
+ part of pfSense (http://www.pfsense.com/)
+ Copyright (C) 2011 Marcello Coutinho <marcellocoutinho@gmail.com>
+ based on varnish_view_config.
+ 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_once("/etc/inc/util.inc");
+require_once("/etc/inc/functions.inc");
+require_once("/etc/inc/pkg-utils.inc");
+require_once("/etc/inc/globals.inc");
+function grep_log($from="",$to="",$subject=""){
+ global $postfix_dir,$postfix_db,$postfix_arg;
+ create_db();
+
+ $total_lines=0;
+ $grep="postfix.\(cleanup\|smtp\|error\|qmgr\)";
+ $curr_time = time();
+ $m=date('M',strtotime($postfix_arg['time'],$curr_time));
+ $j=substr(" ".date('j',strtotime($postfix_arg['time'],$curr_time)),-3);
+ # file grep loop
+ foreach ($postfix_arg['grep'] as $hour){
+ print "/usr/bin/grep '^".$m.$j." ".$hour.".*".$grep."' /var/log/maillog\n";
+ $lists=array();
+ exec("/usr/bin/grep " . escapeshellarg('^'.$m.$j." ".$hour.".*".$grep)." /var/log/maillog", $lists);
+ $stm_noqueue="BEGIN;\n";
+ $stm_queue="BEGIN;\n";
+ foreach ($lists as $line){
+ $status=array();
+ $total_lines++;
+ #Nov 8 09:31:50 srvchunk01 postfix/smtpd[43585]: 19C281F59C8: client=pm03-974.auinmeio.com.br[177.70.232.225]
+ if(preg_match("/(\w+\s+\d+\s+[0-9,:]+) (\w+) postfix.smtpd\W\d+\W+(\w+): client=(.*)/",$line,$email)){
+ $values="'".$email[3]."','".$email[1]."','".$email[2]."','".$email[4]."'";
+ if(${$email[3]}!=$email[3])
+ $stm_queue.='insert into mail_queue(sid,date,server,client) values('.$values.');'."\n";
+ ${$email[3]}=$email[3];
+ }
+ #Nov 13 00:09:07 srvchunk01 postfix/smtp[51436]: 9145C1F67F7: to=<lidia.santos@ma.mail.test.com>, relay=srvmail1-ma.ma.mail.test.com[172.23.3.6]:25, delay=2.4, delays=2.2/0/0.13/0.11, dsn=5.7.1, status=bounced (host srvmail1-ma.ma.mail.test.com[172.23.3.6] said: 550 5.7.1 Unable to relay for lidia.santos@ma.mail.test.com (in reply to RCPT TO command))
+ #Nov 3 21:45:32 srvchunk01 postfix/smtp[18041]: 4CE321F4887: to=<vitrineabril@vitrineabril.alphainteractive.com.br>, relay=smtpe1.emv3.com[81.92.120.9]:25, delay=1.9, delays=0.06/0.01/0.68/1.2, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 2C33E2382C8)
+ else if(preg_match("/(\w+\s+\d+\s+[0-9,:]+) (\w+) postfix.smtp\W\d+\W+(\w+): to=\<(.*)\>, relay=(.*), delay=([0-9.]+).*dsn=([0-9.]+), status=(\w+) (.*)/",$line,$email)){
+ $stm_queue.= "update mail_queue set too='".$email[4]."', relay='".$email[5]."', dsn='".$email[7]."', status='".$email[8]."', status_info='".preg_replace("/(\s+|\'|\")/"," ",$email[9])."', delay='".$email[6]."' where sid='".$email[3]."';\n";
+ #print "update mail_queue set too='".$email[4]."', relay='".$email[5]."', dsn='".$email[9]."',status='".$email[8]."', status_info='".$email[9]."', delay='".$email[6]."' where sid='".$email[3]."';\n";
+ }
+ #Nov 13 01:48:44 srvch011 postfix/cleanup[16914]: D995B1F570B: message-id=<61.40.11745.10E3FBE4@ofertas6>
+ else if(preg_match("/(\w+\s+\d+\s+[0-9,:]+) (\w+) postfix.cleanup\W\d+\W+(\w+): message-id=\<(.*)\>/",$line,$email)){
+ $stm_queue.="update mail_queue set msgid='".$email[4]."' where sid='".$email[3]."';";
+ }
+ #Nov 14 02:40:05 srvchunk01 postfix/qmgr[46834]: BC5931F4F13: from=<ceag@mx.crmall.com.br>, size=32727, nrcpt=1 (queue active)
+ else if(preg_match("/(\w+\s+\d+\s+[0-9,:]+) (\w+) postfix.qmgr\W\d+\W+(\w+): from=\<(.*)\>\W+size=(\d+)/",$line,$email)){
+ $stm_queue.= "update mail_queue set fromm='".$email[4]."', size='".$email[5]."' where sid='".$email[3]."';\n";
+ }
+ #Nov 13 00:09:07 srvchunk01 postfix/bounce[56376]: 9145C1F67F7: sender non-delivery notification: D5BD31F6865
+ else if(preg_match("/(\w+\s+\d+\s+[0-9,:]+) (\w+) postfix.bounce\W\d+\W+(\w+): sender non-delivery notification: (\w+)/",$line,$email)){
+ $stm_queue.= "update mail_queue set bounce='".$email[4]."' where sid='".$email[3]."';\n";
+ }
+ #Nov 9 02:14:57 srvch011 postfix/cleanup[6856]: 617A51F5AC5: warning: header Subject: Mapeamento de Processos from lxalpha.12b.com.br[66.109.29.225]; from=<apache@lxalpha.12b.com.br> to=<ritiele.faria@mail.test.com> proto=ESMTP helo=<lxalpha.12b.com.br>
+ #Nov 8 09:31:50 srvch011 postfix/cleanup[11471]: 19C281F59C8: reject: header From: "Giuliana Flores - Parceiro do Grupo Virtual" <publicidade@parceiro-grupovirtual.com.br> from pm03-974.auinmeio.com.br[177.70.232.225]; from=<publicidade@parceiro-grupovirtual.com.br> to=<jorge.lustosa@mail.test.com> proto=ESMTP helo=<pm03-974.auinmeio.com.br>: 5.7.1 [SN007]
+ else if(preg_match("/(\w+\s+\d+\s+[0-9,:]+) (\w+) postfix.cleanup\W\d+\W+(\w+): (\w+): header (.*) from ([a-z,A-Z,0-9,.,-]+)\W([0-9,.]+)\W+from=\<(.*)\> to=\<(.*)\>.*helo=\W([a-z,A-Z,0-9,.,-]+)\W(.*|)/",$line,$email)){
+ $status['date']=$email[1];
+ $status['server']=$email[2];
+ $status['sid']=$email[3];
+ $status['remote_hostname']=$email[6];
+ $status['remote_ip']=$email[7];
+ $status['from']=$email[8];
+ $status['to']=$email[9];
+ $status['helo']=$email[10];
+ $status['status']=$email[4];
+
+ if ($email[4] =="warning"){
+ $status['status_info']=preg_replace("/(\s+|\'|\")/"," ",$email[11]);
+ $status['subject']=preg_replace("/Subject: /","",$email[5]);
+ $status['subject']=preg_replace("/(\s+|\'|\")/"," ",$status['subject']);
+ $stm_queue.="update mail_queue set subject='".$status['subject']."', status='".$status['status']."', status_info='".$status['info']."', fromm='".$status['from']."',too='".$status['size']."',helo='".$status['helo']."' where sid='".$status['sid']."';\n";
+ }
+ else{
+ $status['status_info']=$email[5].$email[11];
+ $stm_queue.="update mail_queue set status='".$status['status']."', status_info='".$status['status_info']."', fromm='".$status['from']."',too='".$status['to']."',helo='".$status['helo']."' where sid='".$status['sid']."';\n";
+ }
+ }
+ #Nov 9 02:14:34 srvchunk01 postfix/smtpd[38129]: NOQUEUE: reject: RCPT from unknown[201.36.98.7]: 450 4.7.1 Client host rejected: cannot find your hostname, [201.36.98.7]; from=<maladireta@esadcursos.com.br> to=<sexec.09vara@go.domain.test.com> proto=ESMTP helo=<capri0.wb.com.br>
+ else if(preg_match("/(\w+\s+\d+\s+[0-9,:]+) (\w+) postfix.smtpd\W\d+\W+NOQUEUE:\s+(\w+): (.*); from=\<(.*)\> to=\<(.*)\>.*helo=\<(.*)\>/",$line,$email)){
+ $status['sid']='NOQUEUE';
+ $status['date']=$email[1];
+ $status['server']=$email[2];
+ $status['status']=$email[3];
+ $status['status_info']=$email[4];
+ $status['from']=$email[5];
+ $status['to']=$email[6];
+ $status['helo']=$email[7];
+ $values="'".$status['date']."','".$status['status']."','".$status['status_info']."','".$status['from']."','".$status['to']."','".$status['helo']."'";
+ $stm_noqueue.='insert into mail_noqueue(date,status,status_info,fromm,too,helo) values('.$values.');'."\n";
+ }
+ if ($total_lines%1000 == 0){
+ #save log in database
+ write_db($stm_noqueue."COMMIT;","noqueue");
+ write_db($stm_queue."COMMIT;","queue");
+ $stm_noqueue="BEGIN;\n";
+ $stm_queue="BEGIN;\n";
+ }
+ if ($total_lines%1000 == 0)
+ print "$line\n";
+ }
+ #save log in database
+ write_db($stm_noqueue."COMMIT;","noqueue");
+ write_db($stm_queue."COMMIT;","queue");
+ $stm_noqueue="BEGIN;\n";
+ $stm_queue="BEGIN;\n";
+ }
+}
+
+function write_db($stm,$table){
+ global $postfix_dir,$postfix_db;
+ print date("H:i:s") . " writing db...";
+ $dbhandle = sqlite_open($postfix_dir.'/'.$postfix_db, 0666, $error);
+ $ok = sqlite_exec($dbhandle, $stm, $error);
+ if (!$ok)
+ die ("Cannot execute query. $error\n$stm\n");
+
+ print "ok ";
+ $result = sqlite_query($dbhandle, "select count(*) ".$table." from mail_".$table);
+ $row = sqlite_fetch_array($result, SQLITE_ASSOC);
+ print $table .":". $row[$table]."\n";
+ sqlite_close($dbhandle);
+echo "<br>";
+}
+
+function create_db(){
+ global $postfix_dir,$postfix_db,$postfix_arg;
+ if ($postfix_arg['time']== "-01 day"){
+ unlink_if_exists($postfix_dir.'/'.$postfix_db);
+ unlink_if_exists($postfix_dir.'/'.$postfix_db."-journal");
+ }
+ if (! is_dir($postfix_dir))
+ mkdir($postfix_dir,0775);
+ $new_db=(file_exists($postfix_dir.'/'.$postfix_db)?1:0);
+ $dbhandle = sqlite_open($postfix_dir.'/'.$postfix_db, 0666, $error);
+ if (!$dbhandle) die ($error);
+$stm = <<<EOF
+ CREATE TABLE mail_queue(
+ "id" INTEGER PRIMARY KEY,
+ "sid" TEXT NOT NULL,
+ "client" TEXT NOT NULL,
+ "msgid" TEXT,
+ "fromm" TEXT,
+ "too" TEXT,
+ "status" TEXT,
+ "size" INTEGER,
+ "status_info" TEXT,
+ "subject" TEXT,
+ "smtp" TEXT,
+ "delay" TEXT,
+ "relay" TEXT,
+ "dsn" TEXT,
+ "date" TEXT NOT NULL,
+ "server" TEXT,
+ "helo" TEXT,
+ "bounce" TEXT
+);
+CREATE TABLE "mail_noqueue"(
+ "id" INTEGER PRIMARY KEY,
+ "date" TEXT NOT NULL,
+ "status" INTEGER NOT NULL,
+ "status_info" INTEGER NOT NULL,
+ "fromm" TEXT NOT NULL,
+ "too" TEXT NOT NULL,
+ "helo" TEXT NOT NULL
+);
+
+CREATE UNIQUE INDEX "queue_sid" on mail_queue (sid ASC);
+CREATE INDEX "queue_bounce" on mail_queue (bounce ASC);
+CREATE INDEX "queue_relay" on mail_queue (relay ASC);
+CREATE INDEX "queue_client" on mail_queue (client ASC);
+CREATE INDEX "queue_helo" on mail_queue (helo ASC);
+CREATE INDEX "queue_server" on mail_queue (server ASC);
+CREATE INDEX "queue_date" on mail_queue (date ASC);
+CREATE INDEX "queue_smtp" on mail_queue (smtp ASC);
+CREATE INDEX "queue_subject" on mail_queue (subject ASC);
+CREATE INDEX "queue_info" on mail_queue (status_info ASC);
+CREATE INDEX "queue_status" on mail_queue (status ASC);
+CREATE INDEX "queue_msgid" on mail_queue (msgid ASC);
+CREATE INDEX "queue_too" on mail_queue (too ASC);
+CREATE INDEX "queue_fromm" on mail_queue (fromm ASC);
+CREATE INDEX "noqueue_unique" on mail_noqueue (date ASC, fromm ASC, too ASC);
+CREATE INDEX "noqueue_helo" on mail_noqueue (helo ASC);
+CREATE INDEX "noqueue_too" on mail_noqueue (too ASC);
+CREATE INDEX "noqueue_fromm" on mail_noqueue (fromm ASC);
+CREATE INDEX "noqueue_info" on mail_noqueue (status_info ASC);
+CREATE INDEX "noqueue_status" on mail_noqueue (status ASC);
+CREATE INDEX "noqueue_date" on mail_noqueue (date ASC);
+EOF;
+if ($new_db==0){
+ $ok = sqlite_exec($dbhandle, $stm, $error);
+ if (!$ok)
+ print ("Cannot execute query. $error\n");
+ sqlite_close($dbhandle);
+ }
+}
+function print_html($status="CANNOT_BE_NULL"){
+ if (is_array($status)){
+
+ }
+}
+$postfix_dir="/var/db/postfix/";
+$curr_time = time();
+#console script call
+if ($argv[1]!=""){
+switch ($argv[1]){
+ case "10min":
+ $postfix_arg=array( 'grep' => array(substr(date("H:i",strtotime('-10 min',$curr_time)),0,-1)),
+ 'time' => '-10 min');
+ break;
+ case "01hour":
+ $postfix_arg=array( 'grep' => array(date("H:",strtotime('-01 hour',$curr_time))),
+ 'time' => '-01 hour');
+ break;
+ case "24hours":
+ $postfix_arg=array( 'grep' => array('00:','01:','02:','03:','04:','05:','06:','07:','08:','09:','10:','11:',
+ '12:','13:','14:','15:','16:','17:','18:','19:','20:','21:','22:','23:'),
+ 'time' => '-01 day');
+ break;
+ case "24hours2":
+ $postfix_arg=array( 'grep' => array('00:','01:','02:','03:','04:','05:','06:','07:','08:','09:','10:','11:',
+ '12:','13:','14:','15:','16:','17:','18:','19:','20:','21:','22:','23:'),
+ 'time' => '-02 day');
+ break;
+ case "24hours3":
+ $postfix_arg=array( 'grep' => array('00:','01:','02:','03:','04:','05:','06:','07:','08:','09:','10:','11:',
+ '12:','13:','14:','15:','16:','17:','18:','19:','20:','21:','22:','23:'),
+ 'time' => '-03 day');
+ break;
+
+ default:
+ die ("invalid parameters\n");
+}
+$postfix_db=date("Y-m-d",strtotime($postfix_arg['time'],$curr_time)).".db";
+grep_log();
+}
+
+#http client call
+if ($_REQUEST['files']!= ""){
+ #do search
+ $queue=($_REQUEST['queue']=="QUEUE"?"mail_queue":"mail_noqueue");
+ $limit_prefix=(preg_match("/\d+/",$_REQUEST['limit'])?"limit ":"");
+ $limit=(preg_match("/\d+/",$_REQUEST['limit'])?$_REQUEST['limit']:"");
+ $files= explode(",", $_REQUEST['files']);
+ $stm_fetch=array();
+ $total_result=0;
+ foreach ($files as $postfix_db)
+ if (file_exists($postfix_dir.'/'.$postfix_db)){
+ $last_next="";
+ $dbhandle = sqlite_open($postfix_dir.'/'.$postfix_db, 0666, $error);
+ $stm='select * from '.$queue;
+ if ($_REQUEST['from']!= ""){
+ $next=($last_next==" and "?" and ":" where ");
+ $last_next=" and ";
+ $stm .=$next."fromm in('".$_REQUEST['from']."')";
+ }
+ if ($_REQUEST['to']!= ""){
+ $next=($last_next==" and "?" and ":" where ");
+ $last_next=" and ";
+ $stm .=$next."too in('".$_REQUEST['to']."')";
+ }
+ if ($_REQUEST['sid']!= ""){
+ $next=($last_next==" and "?" and ":" where ");
+ $last_next=" and ";
+ $stm .=$next."sid in('".$_REQUEST['sid']."')";
+ }
+ if ($_REQUEST['subject']!= ""){
+ $next=($last_next==" and "?" and ":" where ");
+ $last_next=" and ";
+ $stm .=$next."subject like '%".$_REQUEST['subject']."%'";
+ }
+ if ($_REQUEST['msgid']!= ""){
+ $next=($last_next==" and "?" and ":" where ");
+ $last_next=" and ";
+ $stm .=$next."msgid = '".$_REQUEST['msgid']."'";
+ }
+ if ($_REQUEST['status']!= ""){
+ $next=($last_next==" and "?" and ":" where ");
+ $last_next=" and ";
+ $stm .=$next."status = '".$_REQUEST['status']."'";
+ }
+ $result = sqlite_query($dbhandle, $stm." order by date desc $limit_prefix $limit ");
+ if (preg_match("/\d+/",$_REQUEST['limit'])){
+ for ($i = 1; $i <= $limit; $i++) {
+ $row = sqlite_fetch_array($result, SQLITE_ASSOC);
+ if (is_array($row))
+ $stm_fetch[]=$row;
+ }
+ }
+ else{
+ $stm_fetch = sqlite_fetch_all($result, SQLITE_ASSOC);
+ }
+ sqlite_close($dbhandle);
+ }
+ $fields= explode(",", $_REQUEST['fields']);
+ if ($queue=="mail_noqueue"){
+ print '<table class="tabcont" width="100%" border="0" cellpadding="8" cellspacing="0">';
+ print '<tr><td colspan="'.count($fields).'" valign="top" class="listtopic">'.gettext("Search Results").'</td></tr>';
+ print '<tr>';
+ if(in_array("date",$fields))
+ print '<td class="listlr"><strong>date</strong></td>';
+ if(in_array("from",$fields))
+ print '<td class="listlr"><strong>From</strong></td>';
+ if(in_array("to",$fields))
+ print '<td class="listlr"><strong>to</strong></td>';
+ if(in_array("helo",$fields))
+ print '<td class="listlr"><strong>Helo</strong></td>';
+ if(in_array("status",$fields))
+ print '<td class="listlr"><strong>Status</strong></td>';
+ if(in_array("status_info",$fields))
+ print '<td class="listlr"><strong>Status Info</strong></td>';
+ print '</tr>';
+ foreach ($stm_fetch as $mail){
+ print '<tr>';
+ if(in_array("date",$fields))
+ print '<td class="listlr">'.$mail['date'].'</td>';
+ if(in_array("from",$fields))
+ print '<td class="listlr">'.$mail['fromm'].'</td>';
+ if(in_array("to",$fields))
+ print '<td class="listlr">'.$mail['too'].'</td>';
+ if(in_array("helo",$fields))
+ print '<td class="listlr">'.$mail['helo'].'</td>';
+ if(in_array("status",$fields))
+ print '<td class="listlr">'.$mail['status'].'</td>';
+ if(in_array("status_info",$fields))
+ print '<td class="listlr">'.$mail['status_info'].'</td>';
+ print '</tr>';
+ $total_result++;
+ }
+ }
+ else{
+ print '<table class="tabcont" width="100%" border="0" cellpadding="8" cellspacing="0">';
+ print '<tr><td colspan="'.count($fields).'" valign="top" class="listtopic">'.gettext("Search Results").'</td></tr>';
+ print '<tr>';
+ if(in_array("date",$fields))
+ print '<td class="listlr" ><strong>Date</strong></td>';
+ if(in_array("from",$fields))
+ print '<td class="listlr" ><strong>From</strong></td>';
+ if(in_array("to",$fields))
+ print '<td class="listlr" ><strong>to</strong></td>';
+ if(in_array("subject",$fields))
+ print '<td class="listlr" ><strong>Subject</strong></td>';
+ if(in_array("delay",$fields))
+ print '<td class="listlr" ><strong>Delay</strong></td>';
+ if(in_array("status",$fields))
+ print '<td class="listlr" ><strong>Status</strong></td>';
+ if(in_array("status_info",$fields))
+ print '<td class="listlr" ><strong>Status Info</strong></td>';
+ if(in_array("size",$fields))
+ print '<td class="listlr" ><strong>Size</strong></td>';
+ if(in_array("helo",$fields))
+ print '<td class="listlr" ><strong>Helo</strong></td>';
+ if(in_array("sid",$fields))
+ print '<td class="listlr" ><strong>SID</strong></td>';
+ if(in_array("msgid",$fields))
+ print '<td class="listlr" ><strong>MSGID</strong></td>';
+ if(in_array("bounce",$fields))
+ print '<td class="listlr" ><strong>Bounce</strong></td>';
+ if(in_array("relay",$fields))
+ print '<td class="listlr" ><strong>Relay</strong></td>';
+ print '</tr>';
+ foreach ($stm_fetch as $mail){
+ print '<tr>';
+ if(in_array("date",$fields))
+ print '<td class="listlr">'.$mail['date'].'</td>';
+ if(in_array("from",$fields))
+ print '<td class="listlr">'.$mail['fromm'].'</td>';
+ if(in_array("to",$fields))
+ print '<td class="listlr">'.$mail['too'].'</td>';
+ if(in_array("subject",$fields))
+ print '<td class="listlr">'.$mail['subject'].'</td>';
+ if(in_array("delay",$fields))
+ print '<td class="listlr">'.$mail['delay'].'</td>';
+ if(in_array("status",$fields))
+ print '<td class="listlr">'.$mail['status'].'</td>';
+ if(in_array("status_info",$fields))
+ print '<td class="listlr">'.$mail['status_info'].'</td>';
+ if(in_array("size",$fields))
+ print '<td class="listlr">'.$mail['size'].'</td>';
+ if(in_array("helo",$fields))
+ print '<td class="listlr">'.$mail['helo'].'</td>';
+ if(in_array("sid",$fields))
+ print '<td class="listlr">'.$mail['sid'].'</td>';
+ if(in_array("msgid",$fields))
+ print '<td class="listlr">'.$mail['msgid'].'</td>';
+ if(in_array("bounce",$fields))
+ print '<td class="listlr">'.$mail['bounce'].'</td>';
+ if(in_array("relay",$fields))
+ print '<td class="listlr">'.$mail['relay'].'</td>';
+ print '</tr>';
+ $total_result++;
+ }
+ }
+ print '<tr>';
+ print '<td ><strong>Total:</strong></td>';
+ print '<td ><strong>'.$total_result.'</strong></td>';
+ print '</tr>';
+ print '</table>';
+}
+?>
\ No newline at end of file diff --git a/config/postfix/postfix.xml b/config/postfix/postfix.xml index 91659e71..06caf4ec 100644 --- a/config/postfix/postfix.xml +++ b/config/postfix/postfix.xml @@ -44,7 +44,7 @@ <requirements>Describe your package requirements here</requirements> <faq>Currently there are no FAQ items provided.</faq> <name>postfix</name> - <version>1.2</version> + <version>1.3</version> <title>Services: Postfix relay and antispam</title> <include_file>/usr/local/pkg/postfix.inc</include_file> <menu> @@ -53,6 +53,12 @@ <section>Services</section> <url>pkg_edit.php?xml=postfix.xml&id=0</url> </menu> + <menu> + <name>Search Email</name> + <tooltiptext>Search postfix logs</tooltiptext> + <section>Diagnostics</section> + <url>/postfix_search.php</url> + </menu> <service> <name>postfix</name> <rcfile>postfix.sh</rcfile> @@ -94,6 +100,17 @@ <chmod>0755</chmod> </additional_files_needed> <additional_files_needed> + <item>http://www.pfsense.org/packages/config/postfix/postfix_search.php</item> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + </additional_files_needed> + <additional_files_needed> + <item>http://www.pfsense.org/packages/config/postfix/postfix.php</item> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + </additional_files_needed> + + <additional_files_needed> <item>http://www.pfsense.org/packages/config/postfix/adexport.pl</item> <prefix>/usr/local/etc/postfix/</prefix> <chmod>0755</chmod> @@ -124,6 +141,10 @@ <text>View config files</text> <url>/postfix_view_config.php</url> </tab> + <tab> + <text>Search Email</text> + <url>/postfix_search.php</url> + </tab> </tabs> <fields> <field> @@ -139,7 +160,8 @@ <field> <fielddescr>Listen interface(s)</fielddescr> <fieldname>enabled_interface</fieldname> - <description><![CDATA[Interface(s) that daemon will bind to.<br>Do not listen on WAN without a good "antispam/close relay" configuration.]]></description> + <description><![CDATA[Interface(s) that daemon will bind to.<br>Do not listen on WAN without a good "antispam/close relay" configuration.<br> + If you need postfix on other ip then Interface address, choose localhost and then create a nat rule from external ip to localhost.]]></description> <type>interfaces_selection</type> <required/> <default_value>loopback</default_value> @@ -189,7 +211,22 @@ <option><name>Disable logging</name><value>none</value></option> </options> </field> - + <field> + <fielddescr>Update Sqlite</fielddescr> + <fieldname>update_sqlite</fieldname> + <description><![CDATA[Choose how often pfSense will transfer log files to Sqlite database.<BR> + To use <strong>Diagnostics -> Search mail</strong> you need to:<br> + Select Loggin Destination to /var/log/maillog<br> + Select update Sqlite frequency<br> + Inlcude <strong>/^Subject:/ WARN</strong> line in Acl Headers after all your Subject rules.]]></description> + <type>select</type> + <options> + <option><name>Every 10 minutes</name><value>10min</value></option> + <option><name>Every Hour</name><value>01hour</value></option> + <option><name>Once a day</name><value>24hours</value></option> + <option><name>Never</name><value>never</value></option> + </options> + </field> <field> <fielddescr>Debug peer list</fielddescr> <fieldname>debug_list</fieldname> diff --git a/config/postfix/postfix_acl.xml b/config/postfix/postfix_acl.xml index f3f944e5..5227228d 100644 --- a/config/postfix/postfix_acl.xml +++ b/config/postfix/postfix_acl.xml @@ -118,6 +118,10 @@ <text>View config files</text> <url>/postfix_view_config.php</url> </tab> + <tab> + <text>Search Email</text> + <url>/postfix_search.php</url> + </tab> </tabs> <fields> <field> diff --git a/config/postfix/postfix_antispam.xml b/config/postfix/postfix_antispam.xml index 8561d571..8d293522 100644 --- a/config/postfix/postfix_antispam.xml +++ b/config/postfix/postfix_antispam.xml @@ -119,6 +119,10 @@ <text>View config files</text> <url>/postfix_view_config.php</url> </tab> + <tab> + <text>Search Email</text> + <url>/postfix_search.php</url> + </tab> </tabs> <fields> <field> @@ -133,13 +137,21 @@ <option><name>Strong</name><value>strong</value></option> <option><name>Basic</name><value>basic</value></option> </options> - <description>Enable sender, client, recipients and rfc verification</description> + <description><![CDATA[<strong>Default: Strong</strong><br> + Enable sender, client, recipients and rfc verification.<br>]]></description> + </field> + <field> + <fielddescr>Helo Hostname</fielddescr> + <fieldname>reject_unknown_helo_hostname</fieldname> + <type>checkbox</type> + <description><![CDATA[<strong>Default: Checked</strong><br> + Reject unknow helo hostname during smtp communication.]]></description> </field> <field> <fielddescr>Zombie blocker</fielddescr> <fieldname>zombie_blocker</fieldname> <description> - <![CDATA[<a target=_new href='http://www.postfix.org/POSTSCREEN_README.html'>Use postfix 2.8 Postscreen feature to detect zombie spammers</a>]]> + <![CDATA[<strong>Default: Enabled with enforce</strong><br><a target=_new href='http://www.postfix.org/POSTSCREEN_README.html'>Use postfix 2.8 Postscreen feature to detect zombie spammers</a>]]> </description> <type>select</type> <options> @@ -154,7 +166,7 @@ <fieldname>greet_time</fieldname> <type>input</type> <size>10</size> - <description><![CDATA[<strong>syntax: 2,6s </strong>(default: up to 2 seconds under stress, up to 6 seconds otherwise)<br> + <description><![CDATA[<strong>Default: up to 2 seconds under stress, up to 6 seconds otherwises</strong><br>syntax: 2,6s<br> The amount of time that postscreen will wait for an SMTP client to send a command before its turn, and for DNS blocklist lookup results to arrive .<br> Specify a non-zero time value (an integral value plus an optional one-letter suffix that specifies the time unit).<br> Time units: s (seconds), m (minutes), h (hours), d (days), w (weeks).]]> @@ -186,7 +198,7 @@ <option><name>Enabled</name><value>enabled</value></option> <option><name>Disabled</name><value>disabled</value></option> </options> - <description><![CDATA[Safety net to keep mail queued that would otherwise be returned to the sender.<br> + <description><![CDATA[<strong>Default: Enabled only in postscreen</strong><br>Safety net to keep mail queued that would otherwise be returned to the sender.<br> This parameter disables locally-generated bounces, and prevents the Postfix SMTP server from rejecting mail permanently, by changing 5xx reply codes into 4xx.<br> However, soft_bounce is no cure for address rewriting mistakes or mail routing mistakes.]]> </description> @@ -208,7 +220,7 @@ <field> <fielddescr>RBL threshold</fielddescr> <fieldname>rbl_threshold</fieldname> - <description>How many RBL Lists Postscreen must find clien's ip address to block sender.</description> + <description><![CDATA[<strong>Default: 2</strong><br>How many RBL Lists Postscreen must find clien's ip address to block sender.]]></description> <type>select</type> <options> <option><name>1</name><value>1</value></option> @@ -223,13 +235,13 @@ <fieldname>postfix_spf</fieldname> <type>select</type> <options> - <option><name>REJECT the mail when the sender credentials FAILS (Recomended)</name><value>reject_spf_invalid_sender</value></option> + <option><name>REJECT the mail when the sender credentials FAILS</name><value>reject_spf_invalid_sender</value></option> <option><name>PERMIT the mail when the sender credentials SUCCEED</name><value>permit_spf_valid_sender</value></option> <option><name>Just show in header that the mail failed the test</name><value>spf_mark_only</value></option> <option><name>Do not check SPF records</name><value>disable</value></option> </options> <description> - <![CDATA[<a target=_new href='http://www.openspf.org/Introduction'>The Sender Policy Framework (SPF) is an open standard specifying a technical method to prevent sender address forgery.</a>]]> + <![CDATA[<strong>Default: REJECT the mail when the sender credentials FAILS</strong><br><a target=_new href='http://www.openspf.org/Introduction'>The Sender Policy Framework (SPF) is an open standard specifying a technical method to prevent sender address forgery.</a>]]> </description> </field> <field> diff --git a/config/postfix/postfix_recipients.xml b/config/postfix/postfix_recipients.xml index 450b6df4..88f4916b 100644 --- a/config/postfix/postfix_recipients.xml +++ b/config/postfix/postfix_recipients.xml @@ -118,6 +118,10 @@ <text>View config files</text> <url>/postfix_view_config.php</url> </tab> + <tab> + <text>Search Email</text> + <url>/postfix_search.php</url> + </tab> </tabs> <fields> <field> diff --git a/config/postfix/postfix_search.php b/config/postfix/postfix_search.php new file mode 100755 index 00000000..f347dbf0 --- /dev/null +++ b/config/postfix/postfix_search.php @@ -0,0 +1,227 @@ +<?php +/* + postfix_search.php + part of pfSense (http://www.pfsense.com/) + Copyright (C) 2011 Marcello Coutinho <marcellocoutinho@gmail.com> + based on varnish_view_config. + 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"); + +$pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); +if(strstr($pfSversion, "1.2")) + $one_two = true; + +$pgtitle = "Diagnostics: Search Mail"; +include("head.inc"); + +?> +<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> +<?php include("fbegin.inc"); ?> + +<?php if($one_two): ?> +<p class="pgtitle"><?=$pgtitle?></font></p> +<?php endif; ?> +<?php if ($input_errors) print_input_errors($input_errors); ?> +<?php if ($savemsg) print_info_box($savemsg); ?> + +<!-- <form action="postfix_view_config.php" method="post"> --> + +<div id="mainlevel"> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr><td> + <?php + $tab_array = array(); + $tab_array[] = array(gettext("General"), false, "/pkg_edit.php?xml=postfix.xml&id=0"); + $tab_array[] = array(gettext("ACLs / Filter Maps"), false, "/pkg_edit.php?xml=postfix_acl.xml&id=0"); + $tab_array[] = array(gettext("Valid Recipients"), false, "/pkg_edit.php?xml=postfix_recipients.xml&id=0"); + $tab_array[] = array(gettext("Antispam"), false, "/pkg_edit.php?xml=postfix_antispam.xml&id=0"); + $tab_array[] = array(gettext("XMLRPC Sync"), false, "/pkg_edit.php?xml=postfix_sync.xml&id=0"); + $tab_array[] = array(gettext("View config files"), false, "/postfix_view_config.php"); + $tab_array[] = array(gettext("Search Email"), true, "/postfix_search.php"); + display_top_tabs($tab_array); +?> + </td></tr> + <tr> + + <td> + <div id="mainarea"> + <table class="tabcont" width="100%" border="0" cellpadding="8" cellspacing="0"> + <tr><td></td></tr> + <tr> + <td colspan="2" valign="top" class="listtopic"><?=gettext("Search options"); ?></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("From: ");?></td> + <td width="78%" class="vtable"><textarea id="from" rows="2" cols="50%"></textarea> + <br><?=gettext("One email per line.");?></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("To: ");?></td> + <td width="78%" class="vtable"><textarea id="to" rows="2" cols="50%"></textarea> + <br><?=gettext("One email per line.");?></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("SID: ");?></td> + <td width="78%" class="vtable"><textarea id="sid" rows="2" cols="20%"></textarea> + <br><?=gettext("Postfix queue file unique id. One per line.");?></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Subject: ");?></td> + <td width="78%" class="vtable"><input type="text" class="formfld unknown" id="subject" size="65%"> + <br><?=gettext("");?></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Message_id: ");?></td> + <td width="78%" class="vtable"><input type="text" class="formfld unknown" id="msgid" size="65%"> + <br><?=gettext("Message unique id.");?></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Message Status: ");?></td> + <td width="78%" class="vtable"> + <select name="drop3" id="status"> + <option value="" selected="selected">any</option> + <option value="sent">sent</option> + <option value="bounced">bounced</option> + <option value="reject">reject</option> + <option value="warning">warning</option> + </select><br><?=gettext("Max log messages to fetch per Sqlite file.");?></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Log type: ");?></td> + <td width="78%" class="vtable"> + <select name="drop2" id="queuetype"> + <option value="NOQUEUE" selected="selected">NOQUEUE</option> + <option value="QUEUE">QUEUE</option> + </select><br><?=gettext("NOQUEUE logs means messages that where rejected in smtp negotiation.");?></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Query Limit: ");?></td> + <td width="78%" class="vtable"> + <select name="drop3" id="queuemax"> + <option value="50" selected="selected">50</option> + <option value="150">150</option> + <option value="250">250</option> + <option value="250">500</option> + <option value="250">1000</option> + <option value="250">Unlimited</option> + </select><br><?=gettext("Max log messages to fetch per Sqlite file.");?></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Sqlite files: ");?></td> + <td width="78%" class="vtable"> + + <?php if ($handle = opendir('/var/db/postfix')) { + $total_files=0; + while (false !== ($file = readdir($handle))) + if (preg_match("/(\d+-\d+-\d+).db$/",$file,$matches)){ + $total_files++; + $select_output= '<option value="'.$file.'">'.$matches[1]."</option>\n" . $select_output; + } + closedir($handle); + echo '<select name="drop1" id="Select1" size="'.($total_files>8?8:$total_files+2).'" multiple="multiple">'; + echo $select_output; + echo '</select><br>'.gettext("Select what database files you want to use in your search.").'</td></td>'; + }?> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Message Fields: ");?></td> + <td width="78%" class="vtable"> + <select name="drop3" id="fields" size="13" multiple="multiple"> + <option value="date" selected="selected">Date</option> + <option value="from" selected="selected">From</option> + <option value="to" selected="selected">To</option> + <option value="delay" selected="selected">Delay</option> + <option value="status" selected="selected">Status</option> + <option value="status_info">Status Info</option> + <option value="subject">Subject</option> + <option value="size">Size</option> + <option value="sid">SID</option> + <option value="msgid">msgid</option> + <option value="bounce">bounce</option> + <option value="relay">Relay</option> + <option value="helo">Helo</option> + </select><br><?=gettext("Max log messages to fetch per Sqlite file.");?></td> + </tr> + + <tr> + <td width="22%" valign="top"></td> + <td width="78%"><input name="Submit" type="submit" class="formbtn" value="<?=gettext("Search");?>" onclick="getsearch_results(true)"> + </table> + + </div> + </td> + </tr> + + + </table> + <br> + <div id="search_results"></div> +</div> +<script type="text/javascript"> +function loopSelected(id) +{ + var selectedArray = new Array(); + var selObj = document.getElementById(id); + var i; + var count = 0; + for (i=0; i<selObj.options.length; i++) { + if (selObj.options[i].selected) { + selectedArray[count] = selObj.options[i].value; + count++; + } + } + return(selectedArray); +} + +function getsearch_results() { + scroll(0,0); + var $new_from=$('from').value.replace("\n", "','"); + var $new_to=$('to').value.replace("\n", "','"); + var $new_sid=$('sid').value.replace("\n", "','"); + var $files=loopSelected('Select1'); + var $fields=loopSelected('fields'); + var $queuetype=$('queuetype').options[$('queuetype').selectedIndex].text; + var $queuemax=$('queuemax').options[$('queuemax').selectedIndex].text; + var $pars="from="+$new_from+"&to="+$new_to+"&sid="+$new_sid+"&limit="+$queuemax+"&fields="+$fields+"&status="+$('status').value; + var $pars= $pars+"&subject="+$('subject').value+"&msgid="+$('msgid').value+"&files="+$files+"&queue="+$queuetype; + //alert($pars); + var url = "/postfix.php"; + var myAjax = new Ajax.Request( + url, + { + method: 'post', + parameters: $pars, + onComplete: activitycallback_postfix_search + }); + } + function activitycallback_postfix_search(transport) { + $('search_results').innerHTML = transport.responseText; + } +</script> +<!-- </form> --> +<?php include("fend.inc"); ?> +</body> +</html> diff --git a/config/postfix/postfix_sync.xml b/config/postfix/postfix_sync.xml index f859e795..afceaf9a 100644 --- a/config/postfix/postfix_sync.xml +++ b/config/postfix/postfix_sync.xml @@ -118,6 +118,10 @@ <text>View config files</text> <url>/postfix_view_config.php</url> </tab> + <tab> + <text>Search Email</text> + <url>/postfix_search.php</url> + </tab> </tabs> <fields> <field> diff --git a/config/postfix/postfix_view_config.php b/config/postfix/postfix_view_config.php index c73e9cb4..ab136a2a 100644 --- a/config/postfix/postfix_view_config.php +++ b/config/postfix/postfix_view_config.php @@ -34,7 +34,7 @@ $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); if(strstr($pfSversion, "1.2")) $one_two = true; -$pgtitle = "Postfix: View Configuration"; +$pgtitle = "Services: Postfix View Configuration"; include("head.inc"); ?> @@ -60,7 +60,7 @@ include("head.inc"); $tab_array[] = array(gettext("Antispam"), false, "/pkg_edit.php?xml=postfix_antispam.xml&id=0"); $tab_array[] = array(gettext("XMLRPC Sync"), false, "/pkg_edit.php?xml=postfix_sync.xml&id=0"); $tab_array[] = array(gettext("View config files"), true, "/postfix_view_config.php"); - + $tab_array[] = array(gettext("Search Email"), false, "/postfix_search.php"); display_top_tabs($tab_array); ?> </td></tr> |