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 +++++++++++++++++++++++++++------------------ 1 file changed, 167 insertions(+), 109 deletions(-) (limited to 'config/postfix/postfix.inc') 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).");
+		}
 	}
-
 }
 
 ?>
-- 
cgit v1.2.3