@@ -162,101 +162,59 @@ public function configure_database()
162162 /*
163163 Create postfix configuration files
164164 */
165+
166+ private function process_postfix_config ($ configfile )
167+ {
168+ //$configfile = 'mysql-virtual_domains.cf';
169+ $ config_dir = $ this ->conf ['dist ' ]['postfix ' ]['config_dir ' ].'/ ' ;
170+ $ full_file_name = $ config_dir .$ configfile ;
171+ //* Backup exiting file
172+ if (is_file ($ full_file_name )){
173+ copy ($ full_file_name , $ config_dir .$ configfile .'~ ' );
174+ }
175+ $ content = rf ('tpl/ ' .$ configfile .'.master ' );
176+ $ content = str_replace ('{mysql_server_ispconfig_user} ' , $ this ->conf ['mysql ' ]['ispconfig_user ' ], $ content );
177+ $ content = str_replace ('{mysql_server_ispconfig_password} ' , $ this ->conf ['mysql ' ]['ispconfig_password ' ], $ content );
178+ $ content = str_replace ('{mysql_server_database} ' , $ this ->conf ['mysql ' ]['database ' ], $ content );
179+ $ content = str_replace ('{mysql_server_ip} ' , $ this ->conf ['mysql ' ]['ip ' ], $ content );
180+ $ content = str_replace ('{server_id} ' , $ this ->conf ['server_id ' ], $ content );
181+ wf ($ full_file_name , $ content );
182+ }
183+
165184
166- function configure_postfix ($ options = '' ) {
185+ public function configure_postfix ($ options = '' )
186+ {
167187 global $ conf ;
168-
169- if (!is_dir ($ conf ["dist " ]["postfix " ]["config_dir " ])) $ this ->error ("The postfix configuration directory " .$ conf ["dist " ]["postfix " ]["config_dir " ]." does not exist. " );
170-
171- // mysql-virtual_domains.cf
172- $ configfile = 'mysql-virtual_domains.cf ' ;
173- if (is_file ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile )) copy ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile .'~ ' );
174- $ content = rf ("tpl/ " .$ configfile .".master " );
175- $ content = str_replace ('{mysql_server_ispconfig_user} ' ,$ conf ["mysql " ]["ispconfig_user " ],$ content );
176- $ content = str_replace ('{mysql_server_ispconfig_password} ' ,$ conf ["mysql " ]["ispconfig_password " ],$ content );
177- $ content = str_replace ('{mysql_server_database} ' ,$ conf ["mysql " ]["database " ],$ content );
178- $ content = str_replace ('{mysql_server_ip} ' ,$ conf ["mysql " ]["ip " ],$ content );
179- $ content = str_replace ('{server_id} ' ,$ conf ["server_id " ],$ content );
180- wf ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ content );
181-
182- // mysql-virtual_forwardings.cf
183- $ configfile = 'mysql-virtual_forwardings.cf ' ;
184- if (is_file ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile )) copy ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile .'~ ' );
185- $ content = rf ("tpl/ " .$ configfile .".master " );
186- $ content = str_replace ('{mysql_server_ispconfig_user} ' ,$ conf ["mysql " ]["ispconfig_user " ],$ content );
187- $ content = str_replace ('{mysql_server_ispconfig_password} ' ,$ conf ["mysql " ]["ispconfig_password " ],$ content );
188- $ content = str_replace ('{mysql_server_database} ' ,$ conf ["mysql " ]["database " ],$ content );
189- $ content = str_replace ('{mysql_server_ip} ' ,$ conf ["mysql " ]["ip " ],$ content );
190- $ content = str_replace ('{server_id} ' ,$ conf ["server_id " ],$ content );
191- wf ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ content );
192-
193- // mysql-virtual_mailboxes.cf
194- $ configfile = 'mysql-virtual_mailboxes.cf ' ;
195- if (is_file ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile )) copy ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile .'~ ' );
196- $ content = rf ("tpl/ " .$ configfile .".master " );
197- $ content = str_replace ('{mysql_server_ispconfig_user} ' ,$ conf ["mysql " ]["ispconfig_user " ],$ content );
198- $ content = str_replace ('{mysql_server_ispconfig_password} ' ,$ conf ["mysql " ]["ispconfig_password " ],$ content );
199- $ content = str_replace ('{mysql_server_database} ' ,$ conf ["mysql " ]["database " ],$ content );
200- $ content = str_replace ('{mysql_server_ip} ' ,$ conf ["mysql " ]["ip " ],$ content );
201- $ content = str_replace ('{server_id} ' ,$ conf ["server_id " ],$ content );
202- wf ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ content );
203-
204- // mysql-virtual_email2email.cf
205- $ configfile = 'mysql-virtual_email2email.cf ' ;
206- if (is_file ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile )) copy ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile .'~ ' );
207- $ content = rf ("tpl/ " .$ configfile .".master " );
208- $ content = str_replace ('{mysql_server_ispconfig_user} ' ,$ conf ["mysql " ]["ispconfig_user " ],$ content );
209- $ content = str_replace ('{mysql_server_ispconfig_password} ' ,$ conf ["mysql " ]["ispconfig_password " ],$ content );
210- $ content = str_replace ('{mysql_server_database} ' ,$ conf ["mysql " ]["database " ],$ content );
211- $ content = str_replace ('{mysql_server_ip} ' ,$ conf ["mysql " ]["ip " ],$ content );
212- $ content = str_replace ('{server_id} ' ,$ conf ["server_id " ],$ content );
213- wf ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ content );
214-
215- // mysql-virtual_transports.cf
216- $ configfile = 'mysql-virtual_transports.cf ' ;
217- if (is_file ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile )) copy ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile .'~ ' );
218- $ content = rf ("tpl/ " .$ configfile .".master " );
219- $ content = str_replace ('{mysql_server_ispconfig_user} ' ,$ conf ["mysql " ]["ispconfig_user " ],$ content );
220- $ content = str_replace ('{mysql_server_ispconfig_password} ' ,$ conf ["mysql " ]["ispconfig_password " ],$ content );
221- $ content = str_replace ('{mysql_server_database} ' ,$ conf ["mysql " ]["database " ],$ content );
222- $ content = str_replace ('{mysql_server_ip} ' ,$ conf ["mysql " ]["ip " ],$ content );
223- $ content = str_replace ('{server_id} ' ,$ conf ["server_id " ],$ content );
224- wf ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ content );
225-
226- // mysql-virtual_recipient.cf
227- $ configfile = 'mysql-virtual_recipient.cf ' ;
228- if (is_file ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile )) copy ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile .'~ ' );
229- $ content = rf ("tpl/ " .$ configfile .".master " );
230- $ content = str_replace ('{mysql_server_ispconfig_user} ' ,$ conf ["mysql " ]["ispconfig_user " ],$ content );
231- $ content = str_replace ('{mysql_server_ispconfig_password} ' ,$ conf ["mysql " ]["ispconfig_password " ],$ content );
232- $ content = str_replace ('{mysql_server_database} ' ,$ conf ["mysql " ]["database " ],$ content );
233- $ content = str_replace ('{mysql_server_ip} ' ,$ conf ["mysql " ]["ip " ],$ content );
234- $ content = str_replace ('{server_id} ' ,$ conf ["server_id " ],$ content );
235- wf ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ content );
236-
237- // mysql-virtual_sender.cf
238- $ configfile = 'mysql-virtual_sender.cf ' ;
239- if (is_file ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile )) copy ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile .'~ ' );
240- $ content = rf ("tpl/ " .$ configfile .".master " );
241- $ content = str_replace ('{mysql_server_ispconfig_user} ' ,$ conf ["mysql " ]["ispconfig_user " ],$ content );
242- $ content = str_replace ('{mysql_server_ispconfig_password} ' ,$ conf ["mysql " ]["ispconfig_password " ],$ content );
243- $ content = str_replace ('{mysql_server_database} ' ,$ conf ["mysql " ]["database " ],$ content );
244- $ content = str_replace ('{mysql_server_ip} ' ,$ conf ["mysql " ]["ip " ],$ content );
245- $ content = str_replace ('{server_id} ' ,$ conf ["server_id " ],$ content );
246- wf ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ content );
247-
248- // mysql-virtual_client.cf
249- $ configfile = 'mysql-virtual_client.cf ' ;
250- if (is_file ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile )) copy ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile .'~ ' );
251- $ content = rf ("tpl/ " .$ configfile .".master " );
252- $ content = str_replace ('{mysql_server_ispconfig_user} ' ,$ conf ["mysql " ]["ispconfig_user " ],$ content );
253- $ content = str_replace ('{mysql_server_ispconfig_password} ' ,$ conf ["mysql " ]["ispconfig_password " ],$ content );
254- $ content = str_replace ('{mysql_server_database} ' ,$ conf ["mysql " ]["database " ],$ content );
255- $ content = str_replace ('{mysql_server_ip} ' ,$ conf ["mysql " ]["ip " ],$ content );
256- $ content = str_replace ('{server_id} ' ,$ conf ["server_id " ],$ content );
257- wf ($ conf ["dist " ]["postfix " ]["config_dir " ].'/ ' .$ configfile ,$ content );
258-
259- // Changing mode and group of the new created config files.
188+ $ config_dir = $ this ->conf ['dist ' ]['postfix ' ]['config_dir ' ];
189+ if (!is_dir ($ config_dir )){
190+ $ this ->error ("The postfix configuration directory ' $ config_dir' does not exist. " );
191+ }
192+
193+ //* mysql-virtual_domains.cf
194+ $ this ->process_postfix_config ('mysql-virtual_domains.cf ' );
195+
196+ //* mysql-virtual_forwardings.cf
197+ $ this ->process_postfix_config ('mysql-virtual_forwardings.cf ' );
198+
199+ //* mysql-virtual_mailboxes.cf
200+ $ this ->process_postfix_config ('mysql-virtual_mailboxes.cf ' );
201+
202+ //* mysql-virtual_email2email.cf
203+ $ this ->process_postfix_config ('mysql-virtual_email2email.cf ' );
204+
205+ //* mysql-virtual_transports.cf
206+ $ this ->process_postfix_config ('mysql-virtual_transports.cf ' );
207+
208+ //* mysql-virtual_recipient.cf
209+ $ this ->process_postfix_config ('mysql-virtual_recipient.cf ' );
210+
211+ //* mysql-virtual_sender.cf
212+ $ this ->process_postfix_config ('mysql-virtual_sender.cf ' );
213+
214+ //* mysql-virtual_client.cf
215+ $ this ->process_postfix_config ('mysql-virtual_client.cf ' );
216+
217+ //* Changing mode and group of the new created config files.
260218 caselog ("chmod o= " .$ conf ["dist " ]["postfix " ]["config_dir " ]."/mysql-virtual_*.cf* &> /dev/null " , __FILE__ , __LINE__ ,"chmod on mysql-virtual_*.cf* " ,"chmod on mysql-virtual_*.cf* failed " );
261219 caselog ("chgrp " .$ conf ["dist " ]["postfix " ]["groupname " ]." " .$ conf ["dist " ]["postfix " ]["config_dir " ]."/mysql-virtual_*.cf* &> /dev/null " , __FILE__ , __LINE__ ,"chgrp on mysql-virtual_*.cf* " ,"chgrp on mysql-virtual_*.cf* failed " );
262220
0 commit comments