Skip to content

Commit 77ab0a9

Browse files
author
pedro_morgan
committed
More tidy of postfix and php5 spamassasin
1 parent 438d9f8 commit 77ab0a9

File tree

1 file changed

+49
-47
lines changed

1 file changed

+49
-47
lines changed

install/lib/installer_base.lib.php

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ private function process_postfix_config($configfile)
183183

184184
public function configure_postfix($options = '')
185185
{
186-
global $conf;
187-
$config_dir = $this->conf['dist']['postfix']['config_dir'];
186+
$cf = $this->conf['dist']['postfix'];
187+
$config_dir = $cf['config_dir'];
188+
188189
if(!is_dir($config_dir)){
189190
$this->error("The postfix configuration directory '$config_dir' does not exist.");
190191
}
@@ -214,27 +215,29 @@ public function configure_postfix($options = '')
214215
$this->process_postfix_config('mysql-virtual_client.cf');
215216

216217
//* Changing mode and group of the new created config files.
217-
caselog("chmod o= ".$config_dir."/mysql-virtual_*.cf* &> /dev/null", __FILE__, __LINE__,"chmod on mysql-virtual_*.cf*","chmod on mysql-virtual_*.cf* failed");
218-
caselog("chgrp ".$conf["dist"]["postfix"]["group"]." ".$config_dir."/mysql-virtual_*.cf* &> /dev/null", __FILE__, __LINE__,"chgrp on mysql-virtual_*.cf*","chgrp on mysql-virtual_*.cf* failed");
219-
220-
// Creating virtual mail user and group
221-
$command = "groupadd -g ".$conf["dist"]["postfix"]["vmail_groupid"]." ".$conf["dist"]["postfix"]["vmail_groupname"];
222-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
223-
224-
$command = "useradd -g ".$conf["dist"]["postfix"]["vmail_groupname"]." -u ".$conf["dist"]["postfix"]["vmail_userid"]." ".$conf["dist"]["postfix"]["vmail_username"]." -d ".$conf["dist"]["postfix"]["vmail_mailbox_base"]." -m";
225-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
218+
caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
219+
__FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed');
220+
caselog('chgrp '.$cf['group'].' '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
221+
__FILE__, __LINE__, 'chgrp on mysql-virtual_*.cf*', 'chgrp on mysql-virtual_*.cf* failed');
222+
223+
//* Creating virtual mail user and group
224+
$command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname'];
225+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
226+
227+
$command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m';
228+
caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
226229

227230
$postconf_commands = array (
228-
'myhostname = '.$conf["hostname"],
229-
'mydestination = '.$conf["hostname"].', localhost, localhost.localdomain',
231+
'myhostname = '.$this->conf['hostname'],
232+
'mydestination = '.$this->conf['hostname'].', localhost, localhost.localdomain',
230233
'mynetworks = 127.0.0.0/8',
231234
'virtual_alias_domains =',
232235
'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf',
233236
'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf',
234-
'virtual_mailbox_maps = proxy:mysql:'.$conf["dist"]["postfix"]["config_dir"].'/mysql-virtual_mailboxes.cf',
235-
'virtual_mailbox_base = '.$conf["dist"]["postfix"]["vmail_mailbox_base"],
236-
'virtual_uid_maps = static:'.$conf["dist"]["postfix"]["vmail_userid"],
237-
'virtual_gid_maps = static:'.$conf["dist"]["postfix"]["vmail_groupid"],
237+
'virtual_mailbox_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailboxes.cf',
238+
'virtual_mailbox_base = '.$cf['vmail_mailbox_base'],
239+
'virtual_uid_maps = static:'.$cf['vmail_userid'],
240+
'virtual_gid_maps = static:'.$cf['vmail_groupid'],
238241
'smtpd_sasl_auth_enable = yes',
239242
'broken_sasl_auth_clients = yes',
240243
'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:'.$config_dir.'/mysql-virtual_recipient.cf, reject_unauth_destination',
@@ -279,9 +282,8 @@ public function configure_postfix($options = '')
279282
// TODO: Change the master.cf file
280283
/*
281284
Add:
282-
maildrop unix - n n - - pipe
283-
flags=R user=vmail argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}
284-
285+
maildrop unix - n n - - pipe
286+
flags=R user=vmail argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}
285287
*/
286288
if(!stristr($options,'dont-create-certs')) {
287289
//* Create the SSL certificate
@@ -294,11 +296,7 @@ public function configure_postfix($options = '')
294296
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
295297
}
296298

297-
/*
298-
We have to change the permissions of the courier authdaemon directory
299-
to make it accessible for maildrop.
300-
*/
301-
299+
//** We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop.
302300
$command = 'chmod 755 /var/run/courier/authdaemon/';
303301
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
304302

@@ -311,27 +309,30 @@ public function configure_postfix($options = '')
311309
}
312310
$configfile = $config_dir.'/master.cf';
313311
$content = rf($configfile);
314-
$content = str_replace(' flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}', ' flags=R user='.$conf["dist"]["postfix"]["vmail_username"].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}', $content);
315-
wf($configfile,$content);
312+
$content = str_replace(' flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}',
313+
' flags=R user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
314+
$content);
315+
wf($configfile, $content);
316316

317317
//* Writing the Maildrop mailfilter file
318318
$configfile = 'mailfilter';
319-
if(is_file($conf["dist"]["postfix"]["vmail_mailbox_base"].'/.'.$configfile)) copy($conf["dist"]["postfix"]["vmail_mailbox_base"].'/.'.$configfile,$conf["dist"]["postfix"]["vmail_mailbox_base"].'/.'.$configfile.'~');
320-
$content = rf("tpl/".$configfile.".master");
321-
$content = str_replace('{dist_postfix_vmail_mailbox_base}',$conf["dist"]["postfix"]["vmail_mailbox_base"],$content);
322-
wf($conf["dist"]["postfix"]["vmail_mailbox_base"].'/.'.$configfile,$content);
323-
324-
// Create the directory for the custom mailfilters
325-
$command = "mkdir ".$conf["dist"]["postfix"]["vmail_mailbox_base"]."/mailfilters";
326-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
319+
if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)){
320+
copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~');
321+
}
322+
$content = rf("tpl/$configfile.master");
323+
$content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content);
324+
wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content);
327325

328-
// Chmod and chown the .mailfilter file
329-
$command = "chown -R ".$conf["dist"]["postfix"]["vmail_username"].":".$conf["dist"]["postfix"]["vmail_groupname"]." ".$conf["dist"]["postfix"]["vmail_mailbox_base"]."/.mailfilter";
330-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
326+
//* Create the directory for the custom mailfilters
327+
$command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters';
328+
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
331329

332-
$command = "chmod -R 600 ".$conf["dist"]["postfix"]["vmail_mailbox_base"]."/.mailfilter";
333-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
330+
//* Chmod and chown the .mailfilter file
331+
$command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter';
332+
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
334333

334+
$command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter';
335+
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
335336

336337
}
337338

@@ -467,15 +468,16 @@ function configure_amavis() {
467468

468469
}
469470

470-
function configure_spamassassin() {
471-
global $conf;
472-
473-
// Enable spamasasssin in debian and ubunti
471+
public function configure_spamassassin()
472+
{
473+
//* Enable spamasasssin in debian and ubuntu
474474
$configfile = '/etc/default/spamassassin';
475-
if(is_file($configfile)) copy($configfile,$configfile.'~');
475+
if(is_file($configfile)){
476+
copy($configfile,$configfile.'~');
477+
}
476478
$content = rf($configfile);
477-
$content = str_replace('ENABLED=0','ENABLED=1',$content);
478-
wf($configfile,$content);
479+
$content = str_replace('ENABLED=0', 'ENABLED=1', $content);
480+
wf($configfile, $content);
479481
}
480482

481483
function configure_getmail() {

0 commit comments

Comments
 (0)