From 1536d3590d52e56a67f3443df9aa3dfe378c3c18 Mon Sep 17 00:00:00 2001 From: marcelloc Date: Thu, 1 Dec 2011 13:36:59 -0200 Subject: postfix - package version 2.3 --- config/postfix/postfix.inc | 276 +++++++++------- config/postfix/postfix.php | 560 +++++++++++++++++++++++++-------- config/postfix/postfix.priv.inc | 24 ++ config/postfix/postfix.sh | 27 ++ config/postfix/postfix.widget.php | 75 +++-- config/postfix/postfix.xml | 99 ++++-- config/postfix/postfix_about.php | 102 ++++++ config/postfix/postfix_acl.xml | 91 +++--- config/postfix/postfix_antispam.xml | 78 ++--- config/postfix/postfix_domains.xml | 145 +++++++++ config/postfix/postfix_queue.php | 242 ++++++++++++++ config/postfix/postfix_recipients.xml | 68 ++-- config/postfix/postfix_search.php | 66 ++-- config/postfix/postfix_sync.xml | 101 +++--- config/postfix/postfix_view_config.php | 196 +++++++----- 15 files changed, 1558 insertions(+), 592 deletions(-) create mode 100644 config/postfix/postfix.priv.inc create mode 100755 config/postfix/postfix.sh create mode 100755 config/postfix/postfix_about.php create mode 100644 config/postfix/postfix_domains.xml create mode 100755 config/postfix/postfix_queue.php (limited to 'config') diff --git a/config/postfix/postfix.inc b/config/postfix/postfix.inc index ca81be8e..323c3e3f 100644 --- a/config/postfix/postfix.inc +++ b/config/postfix/postfix.inc @@ -48,42 +48,21 @@ function px_get_real_interface_address($iface) { } function sync_relay_recipients($via_cron="cron"){ - global $config; + global $config,$g; #relay recipients if ($config['installedpackages']['postfixrecipients']['config']) { $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 (is_array($config['installedpackages']['postfixrecipients']['config'])) { + $postfix_recipients_config=$config['installedpackages']['postfixrecipients']['config'][0]; if($postfix_recipients_config['location'] && file_exists($postfix_recipients_config['location'])) $relay_recipients .= file_get_contents($postfix_recipients_config['location']); if($postfix_recipients_config['custom_recipients']) $relay_recipients .= px_text_area_decode($postfix_recipients_config['custom_recipients']); if($postfix_recipients_config['enable_ldap']){ #validate cront job - if(preg_match("/(\d+)(\w)/",$postfix_recipients_config['freq'],$matches)){ - $cron_postfix=array("minute" => "*", - "hour" => "*", - "mday" => "*", - "month" => "*", - "wday" => "*", - "who" => "root", - "command"=> $cron_cmd); - switch ($matches[2]){ - case m: - $cron_postfix["month"]="*/".$matches[1]; - break; - case h: - $cron_postfix["hour"]="*/".$matches[1]; - break; - case d: - $cron_postfix["mday"]="*/".$matches[1]; - break; - default: - $input_errors[] = "A valid number with a time reference is required for the field 'Frequency'"; - } $relay_ldap_recipients=""; if ($via_cron == "gui"){ #running via pfsense gui, not time for ldap fetch. @@ -132,11 +111,52 @@ function sync_relay_recipients($via_cron="cron"){ file_put_contents("/usr/local/etc/postfix/relay_ldap_recipients.txt",$relay_ldap_recipients, 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"); + mwexec("/usr/local/sbin/postfix reload"); + } + if($relay_recipients !="" || $relay_ldap_recipients!="") + return("relay_recipient_maps = hash:/usr/local/etc/postfix/relay_recipients\n"); + +} +function check_cron(){ + global $config, $g; #check crontab $new_cron=array(); $cron_cmd_sqlite = ""; $cron_postfix_sqlite=""; + $cron_cmd="/usr/local/bin/php -q /usr/local/www/postfix_recipients.php"; + $postfix_enabled=$config['installedpackages']['postfix']['config'][0]['enable_postfix']; + #check ldap update + if (is_array($config['installedpackages']['postfixrecipients']['config'])) + $postfix_recipients_config=$config['installedpackages']['postfixrecipients']['config'][0]; + if(preg_match("/(\d+)(\w)/",$postfix_recipients_config['freq'],$matches)){ + $cron_postfix=array("minute" => "*", + "hour" => "*", + "mday" => "*", + "month" => "*", + "wday" => "*", + "who" => "root", + "command"=> $cron_cmd); + switch ($matches[2]){ + case m: + $cron_postfix["month"]="*/".$matches[1]; + break; + case h: + $cron_postfix["minute"]="0"; + $cron_postfix["hour"]="*/".$matches[1]; + break; + case d: + $cron_postfix["minute"]="0"; + $cron_postfix["hour"]="0"; + $cron_postfix["mday"]="*/".$matches[1]; + break; + default: + $input_errors[] = "A valid number with a time reference is required for the field 'Frequency'"; + } + } #check crontab Sqlite databases if (is_array($config['installedpackages']['postfix']['config']) && $postfix_enabled=="on"){ $cron_sqlite_queue=$config['installedpackages']['postfix']['config'][0]['update_sqlite']; @@ -150,6 +170,9 @@ function sync_relay_recipients($via_cron="cron"){ "who" => "root", "command"=> ""); switch ($cron_sqlite_queue){ + case '01min': + $cron_postfix_sqlite["command"] = $cron_cmd_sqlite ." 01min"; + break; case '10min': $cron_postfix_sqlite["minute"]="*/10"; $cron_postfix_sqlite["command"] = $cron_cmd_sqlite ." 10min"; @@ -215,7 +238,7 @@ function sync_relay_recipients($via_cron="cron"){ #call cron functions if ($write_cron==1){ $config['cron']=$new_cron; - write_config(); + write_config('Postfix - sync remote sqlite database',$backup = false); configure_cron(); } #remove postfix old cron call @@ -230,30 +253,31 @@ function sync_relay_recipients($via_cron="cron"){ } 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"); - mwexec("/usr/local/sbin/postfix reload"); - } - if($relay_recipients !="" || $relay_ldap_recipients!="") - return("relay_recipient_maps = hash:/usr/local/etc/postfix/relay_recipients\n"); + #print "
". var_dump($new_cron). var_dump($cron_postfix_sqlite).var_dump($config['cron']);
+			#exit;
+			
+		
 }
 function sync_package_postfix() {
 	global $config;
+	
+	#check patch in /etc/inc/config.
 	$relay_domains = "";
 	$transport = "";
 	$postfix_config=$config['installedpackages']['postfix']['config'][0];
+	$postfix_domains=$config['installedpackages']['postfixdomains']['config'][0];
 	$message_size_limit=($postfix_config['message_size_limit']?$postfix_config['message_size_limit']:"10240000");
 	$process_limit=($postfix_config['process_limit']?$postfix_config['process_limit']:"100");
-	if (is_array($postfix_config['row'])) {
-		foreach ($postfix_config['row'] as $postfix_row) {
+	if (is_array($postfix_domains['row'])) {
+		foreach ($postfix_domains['row'] as $postfix_row) {
 			$relay_domains .= ' ' . $postfix_row['domain'];
 			if (!empty($postfix_row['mailserverip']))
 				$transport .= $postfix_row['domain'] . " smtp:[" . $postfix_row['mailserverip'] . "]\n";
 				}
 			}
+	#check cron
+	check_cron();
 	#check logging
 	if ($postfix_config['log_to']){
 			switch($postfix_config['log_to']){
@@ -311,7 +335,18 @@ function sync_package_postfix() {
 
 
 ABOUT;
-	$postfix_main="#main.cf\n".$copyright;
+	$postfix_main=<< 0){
+		/* assemble xmlrpc payload */
+		$params = array(
+			XML_RPC_encode($password),
+			XML_RPC_encode($xml)
+		);
 	
-	/* assemble xmlrpc payload */
-	$params = array(
-		XML_RPC_encode($password),
-		XML_RPC_encode($xml)
-	);
-
-	/* set a few variables needed for sync code borrowed from filter.inc */
-	$url = $synchronizetoip;
-	log_error("Beginning Postfix XMLRPC sync to {$url}:{$port}.");
-	$method = 'pfsense.merge_installedpackages_section_xmlrpc';
-	$msg = new XML_RPC_Message($method, $params);
-	$cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
-	$cli->setCredentials('admin', $password);
-	if($g['debug'])
-		$cli->setDebug(1);
-	/* send our XMLRPC message and timeout after 250 seconds */
-	$resp = $cli->send($msg, "250");
-	if(!$resp) {
-		$error = "A communications error occurred while attempting postfix XMLRPC sync with {$url}:{$port}.";
-		log_error($error);
-		file_notice("sync_settings", $error, "Postfix Settings Sync", "");
-	} elseif($resp->faultCode()) {
-		$cli->setDebug(1);
+		/* set a few variables needed for sync code borrowed from filter.inc */
+		$url = $synchronizetoip;
+		log_error("Beginning Postfix XMLRPC sync to {$url}:{$port}.");
+		$method = 'pfsense.merge_installedpackages_section_xmlrpc';
+		$msg = new XML_RPC_Message($method, $params);
+		$cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
+		$cli->setCredentials('admin', $password);
+		if($g['debug'])
+			$cli->setDebug(1);
+		/* send our XMLRPC message and timeout after 250 seconds */
 		$resp = $cli->send($msg, "250");
-		$error = "An error code was received while attempting postfix XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
-		log_error($error);
-		file_notice("sync_settings", $error, "Postfix Settings Sync", "");
-	} else {
-		log_error("Postfix XMLRPC sync successfully completed with {$url}:{$port}.");
-	}
-	
-	/* tell postfix to reload our settings on the destionation sync host. */
-	$method = 'pfsense.exec_php';
-	$execcmd  = "require_once('/usr/local/pkg/postfix.inc');\n";
-	$execcmd .= "sync_package_postfix();";
+		if(!$resp) {
+			$error = "A communications error occurred while attempting postfix XMLRPC sync with {$url}:{$port}.";
+			log_error($error);
+			file_notice("sync_settings", $error, "Postfix Settings Sync", "");
+		} elseif($resp->faultCode()) {
+			$cli->setDebug(1);
+			$resp = $cli->send($msg, "250");
+			$error = "An error code was received while attempting postfix XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
+			log_error($error);
+			file_notice("sync_settings", $error, "Postfix Settings Sync", "");
+		} else {
+			log_error("Postfix XMLRPC sync successfully completed with {$url}:{$port}.");
+		}
+		
+		/* tell postfix to reload our settings on the destionation sync host. */
+		$method = 'pfsense.exec_php';
+		$execcmd  = "require_once('/usr/local/pkg/postfix.inc');\n";
+		$execcmd .= "sync_package_postfix();";
+		
+		/* assemble xmlrpc payload */
+		$params = array(
+			XML_RPC_encode($password),
+			XML_RPC_encode($execcmd)
+		);
 	
-	/* assemble xmlrpc payload */
-	$params = array(
-		XML_RPC_encode($password),
-		XML_RPC_encode($execcmd)
-	);
-
-	log_error("postfix XMLRPC reload data {$url}:{$port}.");
-	$msg = new XML_RPC_Message($method, $params);
-	$cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
-	$cli->setCredentials('admin', $password);
-	$resp = $cli->send($msg, "250");
-	if(!$resp) {
-		$error = "A communications error occurred while attempting postfix XMLRPC sync with {$url}:{$port} (pfsense.exec_php).";
-		log_error($error);
-		file_notice("sync_settings", $error, "postfix Settings Sync", "");
-	} elseif($resp->faultCode()) {
-		$cli->setDebug(1);
+		log_error("postfix XMLRPC reload data {$url}:{$port}.");
+		$msg = new XML_RPC_Message($method, $params);
+		$cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
+		$cli->setCredentials('admin', $password);
 		$resp = $cli->send($msg, "250");
-		$error = "An error code was received while attempting postfix XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
-		log_error($error);
-		file_notice("sync_settings", $error, "postfix Settings Sync", "");
-	} else {
-		log_error("postfix XMLRPC reload data success with {$url}:{$port} (pfsense.exec_php).");
+		if(!$resp) {
+			$error = "A communications error occurred while attempting postfix XMLRPC sync with {$url}:{$port} (pfsense.exec_php).";
+			log_error($error);
+			file_notice("sync_settings", $error, "postfix Settings Sync", "");
+		} elseif($resp->faultCode()) {
+			$cli->setDebug(1);
+			$resp = $cli->send($msg, "250");
+			$error = "An error code was received while attempting postfix XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
+			log_error($error);
+			file_notice("sync_settings", $error, "postfix Settings Sync", "");
+		} else {
+			log_error("postfix XMLRPC reload data success with {$url}:{$port} (pfsense.exec_php).");
+		}
 	}
-
 }
 
 ?>
diff --git a/config/postfix/postfix.php b/config/postfix/postfix.php
index d50fd326..0f397cc9 100644
--- a/config/postfix/postfix.php
+++ b/config/postfix/postfix.php
@@ -31,13 +31,118 @@ 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();
+require_once("/usr/local/pkg/postfix.inc");
+
+function get_remote_log(){
+	global $config,$g,$postfix_dir;
+	$curr_time = time();
+	$log_time=date('YmdHis',$curr_time);
+	#get protocol
+    if($config['system']['webgui']['protocol'] != "") 
+		$synchronizetoip = $config['system']['webgui']['protocol']. "://";
+   	#get port
+    $port = $config['system']['webgui']['port'];
+    #if port is empty lets rely on the protocol selection 
+    if($port == "")
+    	$port =($config['system']['webgui']['protocol'] == "http"?"80":"443"); 
+	$synchronizetoip .= $sync_to_ip;
+	if (is_array($config['installedpackages']['postfixsync']))
+		foreach($config['installedpackages']['postfixsync']['config'][0]['row'] as $sh){
+			$sync_to_ip = $sh['ipaddress'];
+			$sync_type = $sh['sync_type'];
+			$password = $sh['password'];
+			$file= '/var/db/postfix/'.$server.'.sql';
+			#get remote data
+			if ($sync_type=='fetch'){
+				$url= $synchronizetoip . $sync_to_ip;
+				print "$sync_to_ip $url, $port\n";			
+				$method = 'pfsense.exec_php';
+				$execcmd  = "require_once('/usr/local/www/postfix.php');\n";
+				$execcmd .= '$toreturn=get_sql('.$log_time.');';
+				/* assemble xmlrpc payload */
+				$params = array(XML_RPC_encode($password),
+								XML_RPC_encode($execcmd));
+				log_error("postfix get sql data from {$sync_to_ip}.");
+				$msg = new XML_RPC_Message($method, $params);
+				$cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
+				$cli->setCredentials('admin', $password);
+				#$cli->setDebug(1);
+				$resp = $cli->send($msg, "250");
+				$a=$resp->value();
+				$errors=0;
+				#var_dump($sql);
+				foreach($a as $b)
+					foreach ($b as $c)
+						foreach ($c as $d)
+							foreach ($d as $e){
+							$update=unserialize($e['string']);
+							print $update['day']."\n";
+							if ($update['day'] != ""){
+							create_db($update['day'].".db");
+							if ($debug=true)
+								print $update['day'] ." writing from remote system to db...";
+							$dbhandle = sqlite_open($postfix_dir.'/'.$update['day'].".db", 0666, $error);
+							#file_put_contents("/tmp/".$key.'-'.$update['day'].".sql",gzuncompress(base64_decode($update['sql'])), LOCK_EX);
+							$ok = sqlite_exec($dbhandle, gzuncompress(base64_decode($update['sql'])), $error);
+								if (!$ok){
+									$errors++;
+									die ("Cannot execute query. $error\n".$update['sql']."\n");
+								}
+								else{
+									if ($debug=true)	
+										print "ok\n";
+								}
+								sqlite_close($dbhandle);
+							}
+							}
+				if ($errors ==0){
+					$method = 'pfsense.exec_php';
+					$execcmd  = "require_once('/usr/local/www/postfix.php');\n";
+					$execcmd .= 'flush_sql('.$log_time.');';
+					/* assemble xmlrpc payload */
+					$params = array(XML_RPC_encode($password),
+									XML_RPC_encode($execcmd));
+					log_error("postfix flush sql buffer file from {$sync_to_ip}.");
+					$msg = new XML_RPC_Message($method, $params);
+					$cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
+					$cli->setCredentials('admin', $password);
+					#$cli->setDebug(1);
+					$resp = $cli->send($msg, "250");
+					}
+				}
+		}	
+}
+function get_sql($log_time){
+	global $config,$xmlrpc_g;
+	$server=$_SERVER['REMOTE_ADDR'];
+	
+	if (is_array($config['installedpackages']['postfixsync']))
+		foreach($config['installedpackages']['postfixsync']['config'][0]['row']  as $sh){
+			$sync_to_ip = $sh['ipaddress'];
+			$sync_type = $sh['sync_type'];
+			$password = $sh['password'];
+			$file= '/var/db/postfix/'.$server.'.sql';
+			if ($sync_to_ip==$server && $sync_type=='share' && file_exists($file)){
+				rename($file,$file.".$log_time");
+				return (file($file.".$log_time"));
+				}
+		}
+		return "";
+}
+
+function flush_sql($log_time){
+	if (preg_match("/\d+\.\d+\.\d+\.\d+/",$_SERVER['REMOTE_ADDR']))
+		unlink_if_exists('/var/db/postfix/'.$_SERVER['REMOTE_ADDR'].".sql.$log_time");
+}
+
+function grep_log(){
+	global $postfix_dir,$postfix_arg,$config,$g;
 	
 	$total_lines=0;
+	$days=array();
 	$grep="postfix.\(cleanup\|smtp\|error\|qmgr\)";
 	$curr_time = time();
+	$log_time=strtotime($postfix_arg['time'],$curr_time);
 	$m=date('M',strtotime($postfix_arg['time'],$curr_time));
 	$j=substr("  ".date('j',strtotime($postfix_arg['time'],$curr_time)),-3);
 	# file grep loop
@@ -45,39 +150,68 @@ function grep_log($from="",$to="",$subject=""){
 	  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){
+	  	#check where is first mail record
+	  	if (preg_match("/ delay=(\d+)/",$line,$delay)){
+	  		$day=date("Y-m-d",strtotime("-".$delay[1]." second",$log_time));
+	  		if (! in_array($day,$days)){
+	  			$days[]=$day;
+	  			create_db($day.".db");
+	  			print "Found logs to $day.db\n";
+	  			$stm_queue[$day]="BEGIN;\n";
+	  			$stm_noqueue[$day]="BEGIN;\n";
+	  			}
+	  		}
+	  	else{
+		  	$day=date("Y-m-d",strtotime($postfix_arg['time'],$curr_time));
+		  	if (! in_array($day,$days)){
+	  			$days[]=$day;
+	  			create_db($day.".db");
+	  			print "Found logs to $day.db\n";
+	  			$stm_queue[$day]="BEGIN;\n";
+	  			$stm_noqueue[$day]="BEGIN;\n";
+		  		}
+	  		}
 		$status=array();
 		$total_lines++;
-		#Nov  8 09:31:50 srvchunk01 postfix/smtpd[43585]: 19C281F59C8: client=pm03-974.auinmeio.com.br[177.70.232.225]
+		#Nov  8 09:31:50 srvch011 postfix/smtpd[43585]: 19C281F59C8: client=pm03-974.auinmem.br[177.70.0.3]
 		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";
+				$stm_queue[$day].='insert or ignore into mail_from(sid,date,server,client) values ('.$values.');'."\n";
 			${$email[3]}=$email[3];
 		}
-		#Nov 13 00:09:07 srvchunk01 postfix/smtp[51436]: 9145C1F67F7: to=, 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=, 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 14 09:29:32 srvch011 postfix/error[58443]: 2B8EB1F5A5A: to=, relay=none, delay=0.66, delays=0.63/0/0/0.02, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=mail.pi.trf1.gov.br type=A: Host not found, try again)
+		#Nov  3 21:45:32 srvch011 postfix/smtp[18041]: 4CE321F4887: to=, relay=smtpe1.eom[81.00.20.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)
+		#Nov 16 00:00:14 srvch011 postfix/smtp[7363]: 7AEB91F797D: to=, relay=mail.mg.trf1.gov.br[172.25.3.5]:25, delay=39, delays=35/1.1/0.04/2.7, dsn=5.7.1, status=bounced (host mail.mg.trf1.gov.br[172.25.3.5] said: 550 5.7.1 Unable to relay for alessandra.bueno@mg.trf1.gov.br (in reply to RCPT TO command))
+		else if(preg_match("/(\w+\s+\d+\s+[0-9,:]+) (\w+) postfix.\w+\W\d+\W+(\w+): to=\<(.*)\>, relay=(.*), delay=([0-9,.]+), .* dsn=([0-9,.]+), status=(\w+) (.*)/",$line,$email)){
+			$stm_queue[$day].= "insert or ignore into mail_status (info) values ('".$email[8]."');\n";
+			$stm_queue[$day].= "insert or ignore into mail_to (from_id,too,status,status_info,relay,delay,dsn) values ((select id from mail_from where sid='".$email[3]."' and server='".$email[2]."'),'".strtolower($email[4])."',(select id from mail_status where info='".$email[8]."'),'".preg_replace("/(\<|\>|\s+|\'|\")/"," ",$email[9])."','".$email[5]."','".$email[6]."','".$email[7]."');\n";	
+			$stm_queue[$day].= "update or ignore mail_to set status=(select id from mail_status where info='".$email[8]."'), status_info='".preg_replace("/(\<|\>|\s+|\'|\")/"," ",$email[9])."', dsn='".$email[7]."', delay='".$email[6]."', relay='".$email[5]."', too='".strtolower($email[4])."' where from_id in (select id from mail_from where sid='".$email[3]."' and server='".$email[2]."');\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]."';";
+			$stm_queue[$day].="update mail_from set msgid='".$email[4]."' where sid='".$email[3]."';\n";
 		}
-		#Nov 14 02:40:05 srvchunk01 postfix/qmgr[46834]: BC5931F4F13: from=, size=32727, nrcpt=1 (queue active)
+		#Nov 14 02:40:05 srvch011 postfix/qmgr[46834]: BC5931F4F13: from=, 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";
+			$stm_queue[$day].= "update mail_from set fromm='".strtolower($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 13 00:09:07 srvch011 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[$day].= "update mail_queue set bounce='".$email[4]."' where sid='".$email[3]."';\n";
+		#}
+		#Nov 14 01:41:44 srvch011 postfix/smtpd[15259]: warning: 1EF3F1F573A: queue file size limit exceeded
+	  else if(preg_match("/(\w+\s+\d+\s+[0-9,:]+) (\w+) postfix.smtpd\W\d+\W+warning: (\w+): queue file size limit exceeded/",$line,$email)){
+	  		$stm_queue[$day].= "insert or ignore into mail_status (info) values ('".$email[8]."');\n";
+			$stm_queue[$day].= "update mail_to set status=(select id from mail_status where info='reject'), status_info='queue file size limit exceeded' where from_id in (select id from mail_from where sid='".$email[3]."' and server='".$email[2]."');\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= to= proto=ESMTP helo=
 		#Nov  8 09:31:50 srvch011 postfix/cleanup[11471]: 19C281F59C8: reject: header From: "Giuliana Flores - Parceiro do Grupo Virtual"  from pm03-974.auinmeio.com.br[177.70.232.225]; from= to= proto=ESMTP helo=: 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)){
+		#Nov 13 00:03:24 srvch011 postfix/cleanup[4192]: 8A5B31F52D2: reject: body http://platform.roastcrack.info/mj0ie6p-48qtiyq from move2.igloojack.info[173.239.63.16]; from= to= proto=SMTP helo=: 5.7.1 [BD040]
+		#Nov 14 01:41:35 srvch011 postfix/cleanup[58446]: 1EF3F1F573A: warning: header Subject: =?windows-1252?Q?IMOVEL_Voc=EA_=E9_um_Cliente_especial_da_=93CENTURY21=22?=??=?windows-1252?Q?Veja_o_que_tenho_para_voc=EA?= from mail-yw0-f51.google.com[209.85.213.51]; from= to= proto=ESMTP helo=
+		else if(preg_match("/(\w+\s+\d+\s+[0-9,:]+) (\w+) postfix.cleanup\W\d+\W+(\w+): (\w+): (.*) from ([a-z,A-Z,0-9,.,-]+)\W([0-9,.]+)\W+from=\<(.*)\> to=\<(.*)\>.*helo=\W([a-z,A-Z,0-9,.,-]+)(.*)/",$line,$email)){
 			$status['date']=$email[1];
 			$status['server']=$email[2];
 			$status['sid']=$email[3];
@@ -87,21 +221,26 @@ function grep_log($from="",$to="",$subject=""){
 			$status['to']=$email[9];
 			$status['helo']=$email[10];
 			$status['status']=$email[4];
-			
+			$stm_queue[$day].= "insert or ignore into mail_status (info) values ('".$email[4]."');\n";
 			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";
+				$stm_queue[$day].= "insert or ignore into mail_status (info) values ('incoming');\n";
+				#print "$line\n";
+				$status['status_info']=preg_replace("/(\<|\>|\s+|\'|\")/"," ",$email[11]);
+				$status['subject']=preg_replace("/header Subject: /","",$email[5]);
+				$status['subject']=preg_replace("/(\<|\>|\s+|\'|\")/"," ",$status['subject']);
+				$stm_queue[$day].="update mail_from set subject='".$status['subject']."', fromm='".strtolower($status['from'])."',helo='".$status['helo']."' where sid='".$status['sid']."';\n";
+				$stm_queue[$day].="insert or ignore into mail_to (from_id,too,status,status_info) VALUES ((select id from mail_from where sid='".$email[3]."' and server='".$email[2]."'),'".strtolower($status['to'])."',(select id from mail_status where info='incoming'),'".$status['status_info']."');\n";
+				$stm_queue[$day].="update or ignore mail_to set status=(select id from mail_status where info='incoming'), status_info='".$status['status_info']."', too='".strtolower($status['to'])."' where from_id in (select id from mail_from where sid='".$status['sid']."' and server='".$email[2]."');\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";
-				}
+				$stm_queue[$day].="update mail_from set fromm='".strtolower($status['from'])."',helo='".$status['helo']."' where sid='".$status['sid']."';\n";
+				$status['status_info']=preg_replace("/(\<|\>|\s+|\'|\")/"," ",$email[5].$email[11]);
+				$stm_queue[$day].="insert or ignore into mail_to (from_id,too,status,status_info) VALUES ((select id from mail_from where sid='".$email[3]."' and server='".$email[2]."'),'".strtolower($status['to'])."',(select id from mail_status where info='".$email[4]."'),'".$status['status_info']."');\n";
+				$stm_queue[$day].="update or ignore mail_to set status=(select id from mail_status where info='".$email[4]."'), status_info='".$status['status_info']."', too='".strtolower($status['to'])."' where from_id in (select id from mail_from where sid='".$status['sid']."' and server='".$email[2]."');\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= to= proto=ESMTP helo=
+		#Nov  9 02:14:34 srvch011 postfix/smtpd[38129]: NOQUEUE: reject: RCPT from unknown[201.36.0.7]: 450 4.7.1 Client host rejected: cannot find your hostname, [201.36.98.7]; from= to= proto=ESMTP helo=
 		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];
@@ -109,124 +248,219 @@ function grep_log($from="",$to="",$subject=""){
 			$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";		
+			$values="'".$status['date']."','".$status['status']."','".$status['status_info']."','".strtolower($status['from'])."','".strtolower($status['to'])."','".$status['helo']."','".$status['server']."'";
+			$stm_noqueue[$day].='insert or ignore into mail_noqueue(date,status,status_info,fromm,too,helo,server) values ('.$values.');'."\n";		
 		}
-		if ($total_lines%1000 == 0){
+		if ($total_lines%1500 == 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)
+			write_db($stm_noqueue,"noqueue",$days);
+			write_db($stm_queue,"from",$days);
+			foreach ($days as $d){
+				$stm_noqueue[$d]="BEGIN;\n";
+				$stm_queue[$d]="BEGIN;\n";
+				}
+			}
+	if ($total_lines%1500 == 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";
+	write_db($stm_noqueue,"noqueue",$days);
+	write_db($stm_queue,"from",$days);
+	foreach ($days as $d){
+		$stm_noqueue[$d]="BEGIN;\n";
+		$stm_queue[$d]="BEGIN;\n";
+		}
 	}
+	
+	$config=parse_xml_config("{$g['conf_path']}/config.xml", $g['xml_rootobj']);
+	print count($config['installedpackages']);
+	#start db replication if configured
+	if ($config['installedpackages']['postfixsync']['config'][0]['rsync'])
+		foreach ($config['installedpackages']['postfixsync']['config'] as $rs )
+			foreach($rs['row'] as $sh){
+				$sync_to_ip = $sh['ipaddress'];
+				$sync_type = $sh['sync_type'];
+				$password = $sh['password'];
+				print "checking replication to $sync_to_ip...";
+				if ($password && $sync_to_ip && preg_match("/(both|database)/",$sync_type))
+					postfix_do_xmlrpc_sync($sync_to_ip, $password,$sync_type);
+				print "ok\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");
+function write_db($stm,$table,$days){
+	global $postfix_dir,$config,$g;
+	conf_mount_rw();
+	$do_sync=array();
+	print "writing to database...";
+	foreach ($days as $day)
+		if (strlen($stm[$day]) > 10){
+		  if ($config['installedpackages']['postfixsync']['config'][0])
+			foreach ($config['installedpackages']['postfixsync']['config'] as $rs )
+				foreach($rs['row'] as $sh){
+					$sync_to_ip = $sh['ipaddress'];
+					$sync_type = $sh['sync_type'];
+					$password = $sh['password'];
+					$sql_file='/var/db/postfix/'.$sync_to_ip.'.sql';
+					${$sync_to_ip}="";
+					if (file_exists($sql_file))
+						${$sync_to_ip}=file_get_contents($sql_file);
+					if ($sync_to_ip && $sync_type=="share"){
+						${$sync_to_ip}.=serialize(array('day'=> $day,'sql'=> base64_encode(gzcompress($stm[$day]."COMMIT;",9))))."\n";
+						if (! in_array($sync_to_ip,$do_sync))
+							$do_sync[]=$sync_to_ip;
+						}
+					}
+			#write local db file
+			create_db($day.".db");
+			if ($debug=true)
+				print " writing to local db $day...";
+			$dbhandle = sqlite_open($postfix_dir.$day.".db", 0666, $error);
+			if (!$dbhandle) die ($error);	
+			#file_put_contents("/tmp/".$key.'-'.$update['day'].".sql",gzuncompress(base64_decode($update['sql'])), LOCK_EX);
+			$ok = sqlite_exec($dbhandle, $stm[$day]."COMMIT;", $error);
+			if (!$ok){
+				if ($debug=true)
+					print ("Cannot execute query. $error\n".$stm[$day]."COMMIT;\n");
+				}
+			else{
+				if ($debug=true)
+					print "ok\n";
+				}
+			sqlite_close($dbhandle);
+			}
+	#write update sql files
+	if (count ($do_sync) > 0 ){
+		
+		foreach($do_sync as $ip)
+			file_put_contents('/var/db/postfix/'.$ip.'.sql',${$ip},LOCK_EX);
+		conf_mount_ro();
+	}
+	#write local file
 	
-	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 "
"; } -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"); - } +function create_db($postfix_db){ + global $postfix_dir,$postfix_arg; 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); + $new_db=(file_exists($postfix_dir.$postfix_db)?1:0); $stm = << array(date("H:i",strtotime('-1 min',$curr_time))), + 'time' => '-1 min'); + break; case "10min": $postfix_arg=array( 'grep' => array(substr(date("H:i",strtotime('-10 min',$curr_time)),0,-1)), 'time' => '-10 min'); @@ -235,17 +469,22 @@ switch ($argv[1]){ $postfix_arg=array( 'grep' => array(date("H:",strtotime('-01 hour',$curr_time))), 'time' => '-01 hour'); break; + case "04hour": + $postfix_arg=array( 'grep' => array(date("H:",strtotime('-04 hour',$curr_time)),date("H:",strtotime('-03 hour',$curr_time)), + date("H:",strtotime('-02 hour',$curr_time)),date("H:",strtotime('-01 hour',$curr_time))), + 'time' => '-04 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": + case "02days": $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": + case "03days": $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'); @@ -254,14 +493,23 @@ switch ($argv[1]){ default: die ("invalid parameters\n"); } -$postfix_db=date("Y-m-d",strtotime($postfix_arg['time'],$curr_time)).".db"; +# get remote log from remote server +get_remote_log(); +# get local log from logfile grep_log(); } #http client call if ($_REQUEST['files']!= ""){ #do search - $queue=($_REQUEST['queue']=="QUEUE"?"mail_queue":"mail_noqueue"); + if($_REQUEST['queue']=="QUEUE"){ + $stm="select * from mail_from, mail_to ,mail_status where mail_from.id=mail_to.from_id and mail_to.status=mail_status.id "; + $last_next=" and "; + } + else{ + $stm="select * from mail_noqueue"; + $last_next=" where "; + } $limit_prefix=(preg_match("/\d+/",$_REQUEST['limit'])?"limit ":""); $limit=(preg_match("/\d+/",$_REQUEST['limit'])?$_REQUEST['limit']:""); $files= explode(",", $_REQUEST['files']); @@ -269,40 +517,70 @@ if ($_REQUEST['files']!= ""){ $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 (preg_match('/\*/',$_REQUEST['from'])) + $stm .=$next."fromm like '".preg_replace('/\*/','%',$_REQUEST['from'])."'"; + else + $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 (preg_match('/\*/',$_REQUEST['to'])) + $stm .=$next."too like '".preg_replace('/\*/','%',$_REQUEST['to'])."'"; + else + $stm .=$next."too in('".$_REQUEST['to']."')"; } - if ($_REQUEST['sid']!= ""){ + if ($_REQUEST['sid']!= "" && $_REQUEST['queue']=="QUEUE"){ $next=($last_next==" and "?" and ":" where "); $last_next=" and "; $stm .=$next."sid in('".$_REQUEST['sid']."')"; } - if ($_REQUEST['subject']!= ""){ + if ($_REQUEST['relay']!= "" && $_REQUEST['queue']=="QUEUE"){ $next=($last_next==" and "?" and ":" where "); $last_next=" and "; - $stm .=$next."subject like '%".$_REQUEST['subject']."%'"; + if (preg_match('/\*/',$_REQUEST['subject'])) + $stm .=$next."relay like '".preg_replace('/\*/','%',$_REQUEST['relay'])."'"; + else + $stm .=$next."relay = '".$_REQUEST['relay']."'"; } - if ($_REQUEST['msgid']!= ""){ + if ($_REQUEST['subject']!= "" && $_REQUEST['queue']=="QUEUE"){ $next=($last_next==" and "?" and ":" where "); $last_next=" and "; - $stm .=$next."msgid = '".$_REQUEST['msgid']."'"; + if (preg_match('/\*/',$_REQUEST['subject'])) + $stm .=$next."subject like '".preg_replace('/\*/','%',$_REQUEST['subject'])."'"; + else + $stm .=$next."subject = '".$_REQUEST['subject']."'"; } + if ($_REQUEST['msgid']!= "" && $_REQUEST['queue']=="QUEUE"){ + $next=($last_next==" and "?" and ":" where "); + $last_next=" and "; + if (preg_match('/\*/',$_REQUEST['msgid'])) + $stm .=$next."msgid like '".preg_replace('/\*/','%',$_REQUEST['msgid'])."'"; + else + $stm .=$next."msgid = '".$_REQUEST['msgid']."'"; + } + if ($_REQUEST['server']!= "" ){ + $next=($last_next==" and "?" and ":" where "); + $last_next=" and "; + if( $_REQUEST['queue']=="QUEUE") + $stm .=$next."mail_from.server = '".$_REQUEST['server']."'"; + else + $stm .=$next."server = '".$_REQUEST['server']."'"; + } + if ($_REQUEST['status']!= ""){ $next=($last_next==" and "?" and ":" where "); $last_next=" and "; - $stm .=$next."status = '".$_REQUEST['status']."'"; + $stm .=$next."mail_status.info = '".$_REQUEST['status']."'"; } - $result = sqlite_query($dbhandle, $stm." order by date desc $limit_prefix $limit "); + #print "
".$stm;
+				#$stm = "select * from mail_to,mail_status where mail_to.status=mail_status.id";
+				$result = sqlite_query($dbhandle, $stm." order by date desc $limit_prefix $limit ");
+				#$result = sqlite_query($dbhandle, $stm."  $limit_prefix $limit ");	
 			if (preg_match("/\d+/",$_REQUEST['limit'])){
 				for ($i = 1; $i <= $limit; $i++) {
 					$row = sqlite_fetch_array($result, SQLITE_ASSOC);
@@ -316,12 +594,32 @@ if ($_REQUEST['files']!= ""){
 			sqlite_close($dbhandle);
 	}
 	$fields= explode(",", $_REQUEST['fields']);
-	if ($queue=="mail_noqueue"){
+	if ($_REQUEST['sbutton']=='export'){
+		print '';
+		print '';
+		print '';
+		$header="";
+		foreach ($stm_fetch as $mail){
+			foreach ($mail as $key => $data){
+				if (!preg_match("/$key/",$header))
+					$header .= $key.",";
+				$export.=preg_replace('/,/',"",$mail[$key]).",";
+				}
+			$export.= "\n";
+		}
+		print '
'.gettext("Search Results").'
"; + } + else{ + if ($_REQUEST['queue']=="NOQUEUE"){ print ''; print ''; print ''; if(in_array("date",$fields)) print ''; + if(in_array("server",$fields)) + print ''; if(in_array("from",$fields)) print ''; if(in_array("to",$fields)) @@ -337,6 +635,8 @@ if ($_REQUEST['files']!= ""){ print ''; if(in_array("date",$fields)) print ''; + if(in_array("server",$fields)) + print ''; if(in_array("from",$fields)) print ''; if(in_array("to",$fields)) @@ -357,6 +657,8 @@ if ($_REQUEST['files']!= ""){ print ''; if(in_array("date",$fields)) print ''; + if(in_array("server",$fields)) + print ''; if(in_array("from",$fields)) print ''; if(in_array("to",$fields)) @@ -383,33 +685,34 @@ if ($_REQUEST['files']!= ""){ print ''; print ''; foreach ($stm_fetch as $mail){ - print ''; if(in_array("date",$fields)) - print ''; + print ''; + if(in_array("server",$fields)) + print ''; if(in_array("from",$fields)) - print ''; + print ''; if(in_array("to",$fields)) - print ''; + print ''; if(in_array("subject",$fields)) - print ''; + print ''; if(in_array("delay",$fields)) - print ''; + print ''; if(in_array("status",$fields)) - print ''; + print ''; if(in_array("status_info",$fields)) - print ''; + print ''; if(in_array("size",$fields)) - print ''; + print ''; if(in_array("helo",$fields)) - print ''; + print ''; if(in_array("sid",$fields)) - print ''; + print ''; if(in_array("msgid",$fields)) - print ''; + print ''; if(in_array("bounce",$fields)) - print ''; + print ''; if(in_array("relay",$fields)) - print ''; + print ''; print ''; $total_result++; } @@ -418,6 +721,7 @@ if ($_REQUEST['files']!= ""){ print ''; print ''; print ''; - print '
'.gettext("Search Results").'
dateserverFrom
'.$mail['date'].''.$mail['server'].''.$mail['fromm'].'
DateServerFromRelay
'.$mail['date'].''.$mail['mail_from.date'].''.$mail['mail_from.server'].''.$mail['fromm'].''.$mail['mail_from.fromm'].''.$mail['too'].''.$mail['mail_to.too'].''.$mail['subject'].''.$mail['mail_from.subject'].''.$mail['delay'].''.$mail['mail_to.delay'].''.$mail['status'].''.$mail['mail_status.info'].''.$mail['status_info'].''.$mail['mail_to.status_info'].''.$mail['size'].''.$mail['mail_from.size'].''.$mail['helo'].''.$mail['mail_from.helo'].''.$mail['sid'].''.$mail['mail_from.sid'].''.$mail['msgid'].''.$mail['mail_from.msgid'].''.$mail['bounce'].''.$mail['mail_to.bounce'].''.$mail['relay'].''.$mail['mail_to.relay'].'
Total:'.$total_result.'
'; + print ''; + } } ?> \ No newline at end of file diff --git a/config/postfix/postfix.priv.inc b/config/postfix/postfix.priv.inc new file mode 100644 index 00000000..6e8b5554 --- /dev/null +++ b/config/postfix/postfix.priv.inc @@ -0,0 +1,24 @@ + \ No newline at end of file diff --git a/config/postfix/postfix.sh b/config/postfix/postfix.sh new file mode 100755 index 00000000..97fa5122 --- /dev/null +++ b/config/postfix/postfix.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# This file was automatically generated +# by the pfSense service handler. + +rc_start() { + /usr/local/sbin/postfix start + +} + +rc_stop() { + /usr/local/sbin/postfix stop + +} + +case $1 in + start) + rc_start + ;; + stop) + rc_stop + ;; + restart) + rc_stop + rc_start + ;; +esac + diff --git a/config/postfix/postfix.widget.php b/config/postfix/postfix.widget.php index dd43afa4..4c0c2b45 100755 --- a/config/postfix/postfix.widget.php +++ b/config/postfix/postfix.widget.php @@ -45,10 +45,22 @@ $img['Healthy']="
-3; $z--){ +for ($z = 0; $z > $days; $z--){ if ($z==0) $postfix_db=date("Y-m-d"); @@ -56,39 +68,45 @@ else $postfix_db=date("Y-m-d",strtotime("$z day",$curr_time)); if (file_exists($postfix_dir.'/'.$postfix_db.".db")){ - $dbhandle = sqlite_open($postfix_dir.'/'.$postfix_db.".db", 0666, $error); #noqueue open_table(); print "
$postfix_db
"; close_table(); open_table(); - $stm="select count(*) as total from mail_noqueue"; - $result = sqlite_query($dbhandle, $stm); - $row_noqueue = sqlite_fetch_array($result, SQLITE_ASSOC); - - #queue - $result = sqlite_query($dbhandle, $stm); - $stm="select status,count(*) as total from mail_queue group by status order by status"; - $result = sqlite_query($dbhandle, $stm); - $reader=""; - $count=""; - for ($i = 1; $i <= 15; $i++) { - $row = sqlite_fetch_array($result, SQLITE_ASSOC); - if (is_array($row)){ - if (preg_match("/\w+/",$row['status'])){ - $reader.="".ucfirst($row['status'])."\n"; - if ($row['status']=="reject") - $row['total']=+$row_noqueue['total']; - $count.="".$row['total']."\n"; - } - } - } - print "".$reader.""; - print "".$count.""; + if (@filesize($postfix_dir.'/'.$postfix_db.".db")< $size){ + $dbhandle = sqlite_open($postfix_dir.'/'.$postfix_db.".db", 0666, $error); + $stm="select count(*) as total from mail_noqueue"; + $result = sqlite_query($dbhandle, $stm); + $row_noqueue = sqlite_fetch_array($result, SQLITE_ASSOC); + + #queue + $result = sqlite_query($dbhandle, $stm); + $stm="select mail_status.info as status,count(*) as total from mail_to,mail_status where mail_to.status=mail_status.id group by status order by mail_status.info"; + $result = sqlite_query($dbhandle, $stm); + $reader=""; + $count=""; + for ($i = 1; $i <= 15; $i++) { + $row = sqlite_fetch_array($result, SQLITE_ASSOC); + if (is_array($row)){ + if (preg_match("/\w+/",$row['status'])){ + $reader.="".ucfirst($row['status'])."\n"; + if ($row['status']=="reject") + $row['total']=+$row_noqueue['total']; + $count.="".$row['total']."\n"; + } + } + } + print "".$reader.""; + print "".$count.""; + $result = sqlite_query($dbhandle, $stm); + sqlite_close($dbhandle); + } + else{ + print "
File size is too large.
"; + } close_table(); echo "
"; - $result = sqlite_query($dbhandle, $stm); - sqlite_close($dbhandle); + } } echo" "; @@ -107,11 +125,10 @@ echo"
"; parameters: pars, onComplete: activitycallback_postfix }); - //I know it's ugly but works. - setTimeout('getstatus_postfix()', 60000); } function activitycallback_postfix(transport) { $('postfix').innerHTML = transport.responseText; + setTimeout('getstatus_postfix()', 60000); } getstatus_postfix(); diff --git a/config/postfix/postfix.xml b/config/postfix/postfix.xml index e7150267..29dbe170 100644 --- a/config/postfix/postfix.xml +++ b/config/postfix/postfix.xml @@ -54,11 +54,17 @@ pkg_edit.php?xml=postfix.xml&id=0 - Search Email + Search Mail Search postfix logs
Diagnostics
/postfix_search.php
+ + Postfix Queue + check postfix queue +
Status
+ /postfix_queue.php +
postfix postfix.sh @@ -74,6 +80,11 @@ /usr/local/pkg/ 0755 + + http://www.pfsense.org/packages/config/postfix/postfix_domains.xml + /usr/local/pkg/ + 0755 + http://www.pfsense.org/packages/config/postfix/postfix_recipients.xml /usr/local/pkg/ @@ -114,6 +125,21 @@ /usr/local/www/widgets/widgets/ 0755 + + http://www.pfsense.org/packages/config/postfix/postfix_about.php + /usr/local/www/ + 0755 + + + http://www.pfsense.org/packages/config/postfix/postfix_queue.php + /usr/local/www/ + 0755 + + + http://www.pfsense.org/packages/config/postfix/postfix.priv.inc + /etc/inc/priv/ + 0755 + http://www.pfsense.org/packages/config/postfix/adexport.pl /usr/local/etc/postfix/ @@ -126,29 +152,43 @@ - ACLs / Filter Maps - /pkg_edit.php?xml=postfix_acl.xml&id=0 + Domains + /pkg_edit.php?xml=postfix_domains.xml&id=0 - Valid recipients + Recipients /pkg_edit.php?xml=postfix_recipients.xml&id=0 + + Access Lists + /pkg_edit.php?xml=postfix_acl.xml&id=0 + Antispam /pkg_edit.php?xml=postfix_antispam.xml&id=0 - XMLRPC Sync + Sync /pkg_edit.php?xml=postfix_sync.xml&id=0 - View config files + View config /postfix_view_config.php - Search Email + Search mail /postfix_search.php + + Queue + /postfix_queue.php + + + + About + /postfix_about.php + + @@ -225,6 +265,7 @@ Inlcude /^Subject:/ WARN line in Acl Headers after all your Subject rules.]]> select + @@ -256,29 +297,31 @@ - Domains to Forward + Widget options listtopic - - Forwarding - none - rowhelper - - - Domain - domain - Enter the domain here (ex: example.com) - input - 30 - - - Mail Server IP - mailserverip - Enter the mail server IP to forward to here. - input - 40 - - + + list days + widget_days + select + + + + + + + + + How many days to display in widget. Default is 3. + + + Max file size + widget_size + input + 10 + + The maximun size in bytes sqlite file we get stats. Default is 100000000 (100mb). + diff --git a/config/postfix/postfix_about.php b/config/postfix/postfix_about.php new file mode 100755 index 00000000..3f3e272a --- /dev/null +++ b/config/postfix/postfix_about.php @@ -0,0 +1,102 @@ + + 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"); + +?> + + + + +

+ + + + + + +
+ + + + + + + + +
+ +
+
+ + + + + + + + + + + + + +
Marcello Coutinho

");?>
donate to pfSense project.

+ If you want that your donation goes to this package developer, make a note on donation forwarding it to me.

");?>
+ +
+
+
+
+
+ + + + diff --git a/config/postfix/postfix_acl.xml b/config/postfix/postfix_acl.xml index 5227228d..9837bf0a 100644 --- a/config/postfix/postfix_acl.xml +++ b/config/postfix/postfix_acl.xml @@ -51,77 +51,49 @@
Services
pkg_edit.php?xml=postfix.xml&id=0 - - postfix - postfix.sh - master - - - http://www.pfsense.org/packages/config/postfix/postfix.inc - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_acl.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_recipients.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_antispam.xml - /usr/local/pkg/ - 0755 - - - - http://www.pfsense.org/packages/config/postfix/postfix_sync.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_view_config.php - /usr/local/www/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_recipients.php - /usr/local/www/ - 0755 - - + General /pkg_edit.php?xml=postfix.xml&id=0 - ACLs / Filter Maps - /pkg_edit.php?xml=postfix_acl.xml&id=0 - + Domains + /pkg_edit.php?xml=postfix_domains.xml&id=0 - Valid recipients + Recipients /pkg_edit.php?xml=postfix_recipients.xml&id=0 + + Access Lists + /pkg_edit.php?xml=postfix_acl.xml&id=0 + + Antispam /pkg_edit.php?xml=postfix_antispam.xml&id=0 - XMLRPC Sync + Sync /pkg_edit.php?xml=postfix_sync.xml&id=0 - View config files + View config /postfix_view_config.php - Search Email + Search mail /postfix_search.php + + Queue + /postfix_queue.php + + + About + /postfix_about.php + + @@ -171,6 +143,19 @@ Client Access List listtopic + + MyNetworks + mynetworks + Paste the list of "trusted" SMTP clients that have more privileges than "strangers" one per line.
+ In particular, "trusted" SMTP clients are allowed to relay mail through Postfix. See the smtpd_recipient_restrictions parameter description in the postconf(5) manual.Hint:
192.168.0.3
+ 192.168.1.0/24]]> +
+ textarea + 60 + 10 + base64 +
+ CIDR cal_cidr @@ -179,8 +164,8 @@ 192.168.3.2 OK
spammer.junkdomain.com REJECT]]> textarea - 83 - 15 + 60 + 10 base64
@@ -192,8 +177,8 @@ /.*\.adsl\..*/ REJECT DSLs not allowed]]> textarea - 83 - 15 + 70 + 10 base64
diff --git a/config/postfix/postfix_antispam.xml b/config/postfix/postfix_antispam.xml index 8d293522..c4772085 100644 --- a/config/postfix/postfix_antispam.xml +++ b/config/postfix/postfix_antispam.xml @@ -52,77 +52,49 @@
Services
pkg_edit.php?xml=postfix_antispam.xml&id=0 - - postfix - postfix.sh - master - - - http://www.pfsense.org/packages/config/postfix/postfix.inc - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_acl.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_recipients.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_antispam.xml - /usr/local/pkg/ - 0755 - - - - http://www.pfsense.org/packages/config/postfix/postfix_sync.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_view_config.php - /usr/local/www/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_recipients.php - /usr/local/www/ - 0755 - General /pkg_edit.php?xml=postfix.xml&id=0 - ACLs / Filter Maps - /pkg_edit.php?xml=postfix_acl.xml&id=0 + Domains + /pkg_edit.php?xml=postfix_domains.xml&id=0 - Valid recipients + Recipients /pkg_edit.php?xml=postfix_recipients.xml&id=0 + + Access Lists + /pkg_edit.php?xml=postfix_acl.xml&id=0 + Antispam /pkg_edit.php?xml=postfix_antispam.xml&id=0 - XMLRPC Sync + Sync /pkg_edit.php?xml=postfix_sync.xml&id=0 - View config files + View config /postfix_view_config.php - Search Email + Search mail /postfix_search.php + + Queue + /postfix_queue.php + + + About + /postfix_about.php + + @@ -203,6 +175,18 @@ However, soft_bounce is no cure for address rewriting mistakes or mail routing mistakes.]]> + + Anvil Daemon + anvil + select + + + + + + Postfix session count and request rate control.
You can disable it if your server relays mail from internal clients to internet.]]> +
+
RBL server List rbl_servers diff --git a/config/postfix/postfix_domains.xml b/config/postfix/postfix_domains.xml new file mode 100644 index 00000000..23d80e12 --- /dev/null +++ b/config/postfix/postfix_domains.xml @@ -0,0 +1,145 @@ + + + + + + + + Describe your package here + Describe your package requirements here + Currently there are no FAQ items provided. + postfixdomains + 1.0 + Services: Postfix relay and antispam + /usr/local/pkg/postfix.inc + + Postfix Forwarder + Configure Postfix Forwarder +
Services
+ pkg_edit.php?xml=postfix.xml&id=0 +
+ + Search Email + Search postfix logs +
Diagnostics
+ /postfix_search.php +
+ + + General + /pkg_edit.php?xml=postfix.xml&id=0 + + + Domains + /pkg_edit.php?xml=postfix_domains.xml&id=0 + + + + Recipients + /pkg_edit.php?xml=postfix_recipients.xml&id=0 + + + Access Lists + /pkg_edit.php?xml=postfix_acl.xml&id=0 + + + Antispam + /pkg_edit.php?xml=postfix_antispam.xml&id=0 + + + Sync + /pkg_edit.php?xml=postfix_sync.xml&id=0 + + + View config + /postfix_view_config.php + + + Search mail + /postfix_search.php + + + Queue + /postfix_queue.php + + + About + /postfix_about.php + + + + + + Domains to Forward + listtopic + + + Forwarding + none + rowhelper + + + Domain + domain + Enter the domain here (ex: example.com) + input + 30 + + + Mail Server IP + mailserverip + Enter the mail server IP to forward to here. + input + 40 + + + + + + postfix_php_install_command(); + + + postfix_php_deinstall_command(); + + + postfix_validate_input($_POST, &$input_errors); + + + sync_package_postfix(); + +
diff --git a/config/postfix/postfix_queue.php b/config/postfix/postfix_queue.php new file mode 100755 index 00000000..eaf6b7f5 --- /dev/null +++ b/config/postfix/postfix_queue.php @@ -0,0 +1,242 @@ + + 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"); +function get_cmd(){ + if ($_REQUEST['cmd'] =='mailq'){ + #exec("/usr/local/bin/mailq" . escapeshellarg('^'.$m.$j." ".$hour.".*".$grep)." /var/log/maillog", $lists); + exec("/usr/local/bin/mailq", $mailq); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + #print '
'.gettext($_REQUEST['cmd']." Results").'
SIDsizedatesenderinfoRecipient
'; + $td=''.$td.$matches[1].''.$td.$matches[2].''.$td.$matches[3].''.$td.$matches[4]; + $sid=$matches[1]; + } + elseif (preg_match("/(\s+|)(\W\w+.*)/",$line,$matches) && $sid !="") + print $td.$matches[2].''; + elseif (preg_match("/\s+(\w+.*)/",$line,$matches) && $sid !=""){ + print $td.$matches[1].''; + $sid=""; + } + } + print '
'; + $sid=""; + foreach ($mailq as $line){ + if(preg_match("/-Queue ID- --Size--/",$line,$matches)) + print""; + elseif (preg_match("/(\w+)\s+(\d+)\s+(\w+\s+\w+\s+\d+\s+\d+:\d+:\d+)\s+(.*)/",$line,$matches)){ + print '
'; + } + if ($_REQUEST['cmd'] =='qshape'){ + if ($_REQUEST['qshape']!="") + exec("/usr/local/bin/qshape ". preg_replace("/\W/"," ",$_REQUEST['qshape']), $qshape); + else + exec("/usr/local/bin/qshape", $qshape); + print ''; + print ''; + $td=''; + foreach (explode (" ",preg_replace("/\s+/"," ",$matches[1])) as $count) + print ''; + print ""; + } + else{ + print ""; + $line=preg_replace("/^\s+/","",$line); + $line=preg_replace("/\s+/"," ",$line); + foreach (explode (" ",$line) as $count) + print ''; + print ""; + } + + } + } +} + +if ($_REQUEST['cmd']!=""){ + get_cmd(); + } +else{ + $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); + if(strstr($pfSversion, "1.2")) + $one_two = true; + + $pgtitle = "Status: Postfix Mail Queue"; + include("head.inc"); + + ?> + + + + +

+ + + + + + +
+
'.gettext($_REQUEST['cmd']." Results").'
'; + $sid=""; + foreach ($qshape as $line){ + if (preg_match("/\s+(T\s.*)/",$line,$matches)){ + print '
'.$count.'
'.$count.'
+ + + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + +
+
+
+
" onclick="get_queue('mailq')">
+
+
+
+
+ + + + +
+
+ +
+
+ + + + + + diff --git a/config/postfix/postfix_recipients.xml b/config/postfix/postfix_recipients.xml index 88f4916b..5b46e32c 100644 --- a/config/postfix/postfix_recipients.xml +++ b/config/postfix/postfix_recipients.xml @@ -51,77 +51,49 @@
Services
pkg_edit.php?xml=postfix.xml&id=0 - - postfix - postfix.sh - master - - - http://www.pfsense.org/packages/config/postfix/postfix.inc - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_acl.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_recipients.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_antispam.xml - /usr/local/pkg/ - 0755 - - - - http://www.pfsense.org/packages/config/postfix/postfix_sync.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_view_config.php - /usr/local/www/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_recipients.php - /usr/local/www/ - 0755 - General /pkg_edit.php?xml=postfix.xml&id=0 - ACLs / Filter Maps - /pkg_edit.php?xml=postfix_acl.xml&id=0 + Domains + /pkg_edit.php?xml=postfix_domains.xml&id=0 - Valid recipients + Recipients /pkg_edit.php?xml=postfix_recipients.xml&id=0 + + Access Lists + /pkg_edit.php?xml=postfix_acl.xml&id=0 + Antispam /pkg_edit.php?xml=postfix_antispam.xml&id=0 - XMLRPC Sync + Sync /pkg_edit.php?xml=postfix_sync.xml&id=0 - View config files + View config /postfix_view_config.php - - Search Email + + Search mail /postfix_search.php + + Queue + /postfix_queue.php + + + About + /postfix_about.php + + diff --git a/config/postfix/postfix_search.php b/config/postfix/postfix_search.php index d11505d4..b76f0554 100755 --- a/config/postfix/postfix_search.php +++ b/config/postfix/postfix_search.php @@ -55,12 +55,15 @@ include("head.inc"); @@ -76,12 +79,12 @@ include("head.inc"); -
+
");?> -
+
@@ -91,12 +94,22 @@ include("head.inc"); -
+

+ + + + +
+ + + + +
@@ -106,7 +119,7 @@ include("head.inc"); - +
@@ -135,13 +148,16 @@ include("head.inc"); '.$matches[1]."\n" . $select_output; - } - closedir($handle); - echo ''; echo $select_output; echo '
'.gettext("Select what database files you want to use in your search.").''; }?> @@ -156,6 +172,7 @@ include("head.inc"); + @@ -168,7 +185,8 @@ include("head.inc"); - " onclick="getsearch_results(true)"> + " onclick="getsearch_results('search')"> +  " onclick="getsearch_results('export')"> @@ -196,7 +214,7 @@ function loopSelected(id) return(selectedArray); } -function getsearch_results() { +function getsearch_results(sbutton) { var $new_from=$('from').value.replace("\n", "','"); var $new_to=$('to').value.replace("\n", "','"); var $new_sid=$('sid').value.replace("\n", "','"); @@ -209,12 +227,15 @@ function getsearch_results() { alert ("Please select at least one message field to display results."); } else{ - $('search').value="Searching..."; + if (sbutton == "search"){ + $('search').value="Searching...";} + else{ + $('export').value="exporting...";} $('search_results').innerHTML=""; 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; + var $pars="from="+$new_from+"&to="+$new_to+"&sid="+$new_sid+"&limit="+$queuemax+"&fields="+$fields+"&status="+$('status').value+"&server="+$('server').value; + var $pars= $pars+"&subject="+$('subject').value+"&msgid="+$('msgid').value+"&files="+$files+"&queue="+$queuetype+"&relay="+$('relay').value+"&sbutton="+sbutton; //alert($pars); var url = "/postfix.php"; var myAjax = new Ajax.Request( @@ -228,8 +249,9 @@ function getsearch_results() { } function activitycallback_postfix_search(transport) { $('search_results').innerHTML = transport.responseText; - scroll(0,900); + scroll(0,1100); $('search').value="Search"; + $('export').value="Export"; } diff --git a/config/postfix/postfix_sync.xml b/config/postfix/postfix_sync.xml index afceaf9a..08a62d87 100644 --- a/config/postfix/postfix_sync.xml +++ b/config/postfix/postfix_sync.xml @@ -51,107 +51,104 @@
Services
pkg_edit.php?xml=postfix.xml&id=0 - - postfix - postfix.sh - master - - - http://www.pfsense.org/packages/config/postfix/postfix.inc - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_acl.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_recipients.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_antispam.xml - /usr/local/pkg/ - 0755 - - - - http://www.pfsense.org/packages/config/postfix/postfix_sync.xml - /usr/local/pkg/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_view_config.php - /usr/local/www/ - 0755 - - - http://www.pfsense.org/packages/config/postfix/postfix_recipients.php - /usr/local/www/ - 0755 - General /pkg_edit.php?xml=postfix.xml&id=0 - ACLs / Filter Maps - /pkg_edit.php?xml=postfix_acl.xml&id=0 + Domains + /pkg_edit.php?xml=postfix_domains.xml&id=0 - Valid recipients + Recipients /pkg_edit.php?xml=postfix_recipients.xml&id=0 + + Access Lists + /pkg_edit.php?xml=postfix_acl.xml&id=0 + Antispam /pkg_edit.php?xml=postfix_antispam.xml&id=0 - XMLRPC Sync + Sync /pkg_edit.php?xml=postfix_sync.xml&id=0 - View config files + View config /postfix_view_config.php - Search Email + Search mail + /postfix_search.php + + + Queue + /postfix_queue.php + + + About /postfix_search.php - Postfix XMLRPC Sync + Postfix Sync listtopic Automatically sync Postfix configuration changes synconchanges - pfSense will automatically sync changes to the hosts defined below. +
+ Remote server options are:
+ XMLRPC Sync - Forward postfix settings to other pfsense boxes. Remote password required
+ Share Database To - Allow other pfsense boxes to fetch maillog data via xml. Remote password NOT required.
+ Fetch Database From - Merge logs from other pfsense boxes to this local database. Remote password required.
+ Disabled - Ignore this host while sync.

+ While sharing databases, you must setup 'Share Database To' in one box and 'Fetch Database From' on other box.]]>
checkbox
- Remote Server + none rowhelper + + Sync Type + sync_type + select + + + + + + + Default: Strong
+ Enable sender, client, recipients and rfc verification.
]]>
+
+ IP Address ipaddress IP Address of remote server input - 20 + 10 Password password Password for remote server. password - 20 + 10 + + + Description + description + input + 25
diff --git a/config/postfix/postfix_view_config.php b/config/postfix/postfix_view_config.php index ab136a2a..2c0b973e 100644 --- a/config/postfix/postfix_view_config.php +++ b/config/postfix/postfix_view_config.php @@ -2,7 +2,7 @@ /* postfix_view_config.php part of pfSense (http://www.pfsense.com/) - Copyright (C) 2010 Marcello Coutinho + Copyright (C) 2011 Marcello Coutinho based on varnish_view_config. All rights reserved. @@ -29,83 +29,127 @@ */ require("guiconfig.inc"); +function get_file($file){ + $files['main']="/usr/local/etc/postfix/main.cf"; + $files['master']="/usr/local/etc/postfix/master.cf"; + $files['recipients']="/usr/local/etc/postfix/relay_recipients"; + $files['header']="/usr/local/etc/postfix/header_check"; + $files['mime']="/usr/local/etc/postfix/mime_check"; + $files['body']="/usr/local/etc/postfix/body_check"; + $files['cidr']="/usr/local/etc/postfix/cal_cidr"; + $files['pcre']="/usr/local/etc/postfix/cal_pcre"; -$pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); -if(strstr($pfSversion, "1.2")) - $one_two = true; + if ($files[$file]!="" && file_exists($files[$file])){ + print ''; + } +} -$pgtitle = "Services: Postfix View Configuration"; -include("head.inc"); - -?> - - - - -

- - - - -
+if ($_REQUEST['file']!=""){ + get_file($_REQUEST['file']); + } +else{ + $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); + if(strstr($pfSversion, "1.2")) + $one_two = true; -
- - - - + + + + + +
- -
-
- + $pgtitle = "Services: Postfix View Configuration"; + include("head.inc"); + + ?> + + + + +

+ + + + + + +
+
+ + + - -
+ +
+
+ + - - - - + + -
-   -   -   -   -   -   -   -   -
- -
-
-
-
- - - - +
+   +   +   +   +   +   +   +   +
+
+ +
+
+ + + + + + + + + -- cgit v1.2.3