View Single Post
  #5  
Old 24th January 2012, 19:50
tio289 tio289 is offline
Member
 
Join Date: Mar 2009
Posts: 70
Thanks: 2
Thanked 14 Times in 9 Posts
Default

Fixed conf:

PHP Code:
<?php 
// file /etc/postfix/map_relay.php 

$link mysql_connect('mx1.example.com''username''password'falseMYSQL_CLIENT_SSL); 

if(!
$link) die; 

mysql_select_db('dbispconfig'$link); 

$result mysql_query('SELECT `domain` FROM `mail_domain` WHERE `active` = "y"'); 
create_map($result'domain''/etc/postfix/relay_domains'); 

$result mysql_query('SELECT `source` FROM `mail_forwarding` WHERE `active` = "y"'); 
create_map($result'source''/etc/postfix/relay_recipients'); 

$result mysql_query('SELECT `email` FROM `mail_user` WHERE `disabledeliver` = "n"'); 
create_map($result'email''/etc/postfix/relay_recipients''a'); 

exec('postmap hash:/etc/postfix/relay_domains & postmap hash:/etc/postfix/relay_recipients');

function 
create_map($result$key$file$type 'w'

    if(
mysql_num_rows($result) == 0)return false
     
    
$content ''
     
    while(
$row mysql_fetch_array($result)) 
    { 
        
$content .= $row[$key]."\tOK\n"
    } 
     
    
write_file($file$content$type); 


function 
write_file($file$content$type 'w'

    
$handle fopen($file$type); 
    
fwrite($handle$content); 
    
fclose($handle); 
     
    return; 
}
crontab:

Code:
0 * * * * /usr/bin/php -q /etc/postfix/map_relay.php
__________________
Independent Senior Webdeveloper
Reply With Quote