View Single Post
  #8  
Old 26th October 2012, 19:18
Plastivore Plastivore is offline
Junior Member
 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks a lot for this quick tutorial.

I have a suggestion to make:
Personally, at first, I did not use aliases. Therefore, I ended up with relay_recipients containing the same entries several times, as they just ended up being appended at the end of the file.

My understanding is that the relay_recipients file is first overwritten using aliases, and only then will the actual mailboxes be appended.

It is better to first look for mailboxes, and only then for the aliases, for the following reasons:
- It seems more logical (but I admit that could just be a point of view! )
- A mailbox needs to exist first for an alias to be created
- Mailboxes are repeated at the end of the file if no alias is configured in ISPConfig (but we already know that).


The code should therefore become:
PHP Code:
 <?php
// file /etc/postfix/map_relay.php 

$link mysql_connect('s0.ikfsystems.sk''map_relay''RRhQe8qa4Qhmezeq'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 `email` FROM `mail_user` WHERE `disabledeliver` = "n"');
create_map($result'email''/etc/postfix/relay_recipients');

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

exec('/usr/sbin/postmap hash:/etc/postfix/relay_domains & /usr/sbin/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;
}
Cheers!

Last edited by Plastivore; 26th October 2012 at 19:21. Reason: Weird meaning sentece corrected to make proper sense...
Reply With Quote