Skip to content

Commit 34e0f5d

Browse files
author
Marius Burkard
committed
Merge branch '6141-conf-custom-for-postfix-and-dovecot-not-working-on-centos-using-fedora-dist-script' into 'develop'
Resolve "Conf-custom for postfix and dovecot not working on CentOS (using fedora dist script)" Closes #6141 See merge request ispconfig/ispconfig3!1477
2 parents 5bf7fcf + 7a08694 commit 34e0f5d

File tree

1 file changed

+0
-231
lines changed

1 file changed

+0
-231
lines changed

install/dist/lib/fedora.lib.php

Lines changed: 0 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -47,237 +47,6 @@ public function __construct() {
4747
}
4848
}
4949

50-
function configure_postfix($options = '')
51-
{
52-
global $conf,$autoinstall;
53-
$cf = $conf['postfix'];
54-
$config_dir = $cf['config_dir'];
55-
56-
if(!is_dir($config_dir)){
57-
$this->error("The postfix configuration directory '$config_dir' does not exist.");
58-
}
59-
60-
//* Install virtual mappings
61-
foreach (glob('tpl/mysql-virtual_*.master') as $filename) {
62-
$this->process_postfix_config( basename($filename, '.master') );
63-
}
64-
65-
//* mysql-verify_recipients.cf
66-
$this->process_postfix_config('mysql-verify_recipients.cf');
67-
68-
//* postfix-dkim
69-
$filename='tag_as_originating.re';
70-
$full_file_name=$config_dir.'/'.$filename;
71-
if(is_file($full_file_name)) copy($full_file_name, $full_file_name.'~');
72-
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/postfix-'.$filename.'.master', 'tpl/postfix-'.$filename.'.master');
73-
wf($full_file_name, $content);
74-
75-
$filename='tag_as_foreign.re';
76-
$full_file_name=$config_dir.'/'.$filename;
77-
if(is_file($full_file_name)) copy($full_file_name, $full_file_name.'~');
78-
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/postfix-'.$filename.'.master', 'tpl/postfix-'.$filename.'.master');
79-
wf($full_file_name, $content);
80-
81-
//* Creating virtual mail user and group
82-
$command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname'];
83-
if(!is_group($cf['vmail_groupname'])) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
84-
85-
$command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m';
86-
if(!is_user($cf['vmail_username'])) caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
87-
88-
//* These postconf commands will be executed on installation and update
89-
$server_ini_rec = $this->db->queryOneRecord("SELECT config FROM server WHERE server_id = ?", $conf['server_id']);
90-
$server_ini_array = ini_to_array(stripslashes($server_ini_rec['config']));
91-
unset($server_ini_rec);
92-
93-
//* If there are RBL's defined, format the list and add them to smtp_recipient_restrictions to prevent removeal after an update
94-
$rbl_list = '';
95-
if (@isset($server_ini_array['mail']['realtime_blackhole_list']) && $server_ini_array['mail']['realtime_blackhole_list'] != '') {
96-
$rbl_hosts = explode(",", str_replace(" ", "", $server_ini_array['mail']['realtime_blackhole_list']));
97-
foreach ($rbl_hosts as $key => $value) {
98-
$rbl_list .= ", reject_rbl_client ". $value;
99-
}
100-
}
101-
unset($rbl_hosts);
102-
103-
//* If Postgrey is installed, configure it
104-
$greylisting = '';
105-
if($conf['postgrey']['installed'] == true) {
106-
$greylisting = ', check_recipient_access mysql:/etc/postfix/mysql-virtual_policy_greylist.cf';
107-
}
108-
109-
$reject_sender_login_mismatch = '';
110-
$reject_authenticated_sender_login_mismatch = '';
111-
if(isset($server_ini_array['mail']['reject_sender_login_mismatch']) && ($server_ini_array['mail']['reject_sender_login_mismatch'] == 'y')) {
112-
$reject_sender_login_mismatch = ', reject_sender_login_mismatch';
113-
$reject_authenticated_sender_login_mismatch = 'reject_authenticated_sender_login_mismatch, ';
114-
}
115-
116-
# placeholder includes comment char
117-
$stress_adaptive_placeholder = '#{stress_adaptive} ';
118-
$stress_adaptive = (isset($server_ini_array['mail']['stress_adaptive']) && ($server_ini_array['mail']['stress_adaptive'] == 'y')) ? '' : $stress_adaptive_placeholder;
119-
120-
$reject_unknown_client_hostname='';
121-
if (isset($server_ini_array['mail']['reject_unknown']) && ($server_ini_array['mail']['reject_unknown'] == 'client' || $server_ini_array['mail']['reject_unknown'] == 'client_helo')) {
122-
$reject_unknown_client_hostname=',reject_unknown_client_hostname';
123-
}
124-
$reject_unknown_helo_hostname='';
125-
if ((!isset($server_ini_array['mail']['reject_unknown'])) || $server_ini_array['mail']['reject_unknown'] == 'helo' || $server_ini_array['mail']['reject_unknown'] == 'client_helo') {
126-
$reject_unknown_helo_hostname=',reject_unknown_helo_hostname';
127-
}
128-
129-
unset($server_ini_array);
130-
131-
$myhostname = str_replace('.','\.',$conf['hostname']);
132-
133-
$postconf_placeholders = array('{config_dir}' => $config_dir,
134-
'{vmail_mailbox_base}' => $cf['vmail_mailbox_base'],
135-
'{vmail_userid}' => $cf['vmail_userid'],
136-
'{vmail_groupid}' => $cf['vmail_groupid'],
137-
'{rbl_list}' => $rbl_list,
138-
'{greylisting}' => $greylisting,
139-
'{reject_slm}' => $reject_sender_login_mismatch,
140-
'{reject_aslm}' => $reject_authenticated_sender_login_mismatch,
141-
'{myhostname}' => $myhostname,
142-
$stress_adaptive_placeholder => $stress_adaptive,
143-
'{reject_unknown_client_hostname}' => $reject_unknown_client_hostname,
144-
'{reject_unknown_helo_hostname}' => $reject_unknown_helo_hostname,
145-
);
146-
147-
$postconf_tpl = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/fedora_postfix.conf.master', 'tpl/fedora_postfix.conf.master');
148-
$postconf_tpl = strtr($postconf_tpl, $postconf_placeholders);
149-
$postconf_commands = array_filter(explode("\n", $postconf_tpl)); // read and remove empty lines
150-
151-
//* These postconf commands will be executed on installation only
152-
if($this->is_update == false) {
153-
$postconf_commands = array_merge($postconf_commands, array(
154-
'myhostname = '.$conf['hostname'],
155-
'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain',
156-
'mynetworks = 127.0.0.0/8 [::1]/128'
157-
));
158-
}
159-
160-
//* Create the header and body check files
161-
touch($config_dir.'/header_checks');
162-
touch($config_dir.'/mime_header_checks');
163-
touch($config_dir.'/nested_header_checks');
164-
touch($config_dir.'/body_checks');
165-
touch($config_dir.'/sasl_passwd');
166-
167-
//* Create the mailman files
168-
if(!is_dir('/var/lib/mailman/data')) exec('mkdir -p /var/lib/mailman/data');
169-
//if(!is_file('/var/lib/mailman/data/aliases')) touch('/var/lib/mailman/data/aliases');
170-
if(is_file('/var/lib/mailman/data/aliases')) unlink('/var/lib/mailman/data/aliases');
171-
if(!is_link('/var/lib/mailman/data/aliases')) symlink('/etc/mailman/aliases', '/var/lib/mailman/data/aliases');
172-
if(!is_dir('/etc/mailman')) mkdir('/etc/mailman');
173-
if(!is_file('/etc/mailman/aliases')) touch('/etc/mailman/aliases');
174-
exec('postalias /var/lib/mailman/data/aliases');
175-
if(!is_file('/etc/mailman/virtual-mailman')) touch('/etc/mailman/virtual-mailman');
176-
exec('postmap /etc/mailman/virtual-mailman');
177-
if(!is_file('/var/lib/mailman/data/transport-mailman')) touch('/var/lib/mailman/data/transport-mailman');
178-
exec('/usr/sbin/postmap /var/lib/mailman/data/transport-mailman');
179-
180-
//* Create auxillary postfix conf files
181-
$configfile = 'helo_access';
182-
if(is_file($config_dir.'/'.$configfile)) {
183-
copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~');
184-
chmod($config_dir.'/'.$configfile.'~', 0400);
185-
}
186-
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/'.$configfile.'.master', 'tpl/'.$configfile.'.master');
187-
$content = strtr($content, $postconf_placeholders);
188-
# todo: look up this server's ip addrs and loop through each
189-
# todo: look up domains hosted on this server and loop through each
190-
wf($config_dir.'/'.$configfile, $content);
191-
192-
$configfile = 'blacklist_helo';
193-
if(is_file($config_dir.'/'.$configfile)) {
194-
copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~');
195-
chmod($config_dir.'/'.$configfile.'~', 0400);
196-
}
197-
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/'.$configfile.'.master', 'tpl/'.$configfile.'.master');
198-
$content = strtr($content, $postconf_placeholders);
199-
wf($config_dir.'/'.$configfile, $content);
200-
201-
//* Make a backup copy of the main.cf file
202-
copy($config_dir.'/main.cf', $config_dir.'/main.cf~');
203-
204-
//* Executing the postconf commands
205-
foreach($postconf_commands as $cmd) {
206-
$command = "postconf -e '$cmd'";
207-
caselog($command." &> /dev/null", __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
208-
}
209-
210-
if(!stristr($options, 'dont-create-certs')) {
211-
//* Create the SSL certificate
212-
if(AUTOINSTALL){
213-
$command = 'cd '.$config_dir.'; '
214-
."openssl req -new -subj '/C=".escapeshellcmd($autoinstall['ssl_cert_country'])."/ST=".escapeshellcmd($autoinstall['ssl_cert_state'])."/L=".escapeshellcmd($autoinstall['ssl_cert_locality'])."/O=".escapeshellcmd($autoinstall['ssl_cert_organisation'])."/OU=".escapeshellcmd($autoinstall['ssl_cert_organisation_unit'])."/CN=".escapeshellcmd($autoinstall['ssl_cert_common_name'])."' -outform PEM -out smtpd.cert -newkey rsa:4096 -nodes -keyout smtpd.key -keyform PEM -days 3650 -x509";
215-
} else {
216-
$command = 'cd '.$config_dir.'; '
217-
.'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:4096 -nodes -keyout smtpd.key -keyform PEM -days 3650 -x509';
218-
}
219-
exec($command);
220-
221-
$command = 'chmod o= '.$config_dir.'/smtpd.key';
222-
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
223-
}
224-
225-
//** We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop.
226-
$command = 'chmod 755 /var/spool/authdaemon';
227-
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
228-
229-
//* Changing maildrop lines in posfix master.cf
230-
if(is_file($config_dir.'/master.cf')){
231-
copy($config_dir.'/master.cf', $config_dir.'/master.cf~');
232-
}
233-
if(is_file($config_dir.'/master.cf~')){
234-
exec('chmod 400 '.$config_dir.'/master.cf~');
235-
}
236-
$configfile = $config_dir.'/master.cf';
237-
$content = rf($configfile);
238-
// if postfix package is from fedora or centios main repo
239-
$content = str_replace('# flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}',
240-
' flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
241-
$content);
242-
243-
// If postfix package is from centos plus repo
244-
$content = str_replace('# flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}',
245-
' flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
246-
$content);
247-
248-
$content = str_replace(' flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}',
249-
' flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
250-
$content);
251-
252-
253-
$content = str_replace('#maildrop unix - n n - - pipe',
254-
'maildrop unix - n n - - pipe',
255-
$content);
256-
257-
wf($configfile, $content);
258-
259-
//* Writing the Maildrop mailfilter file
260-
$configfile = 'mailfilter';
261-
if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)){
262-
copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~');
263-
}
264-
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/'.$configfile.'.master', "tpl/$configfile.master");
265-
$content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content);
266-
wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content);
267-
268-
//* Create the directory for the custom mailfilters
269-
$command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters';
270-
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
271-
272-
//* Chmod and chown the .mailfilter file
273-
$command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter';
274-
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
275-
276-
$command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter';
277-
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
278-
279-
}
280-
28150
public function configure_saslauthd() {
28251
global $conf;
28352

0 commit comments

Comments
 (0)