tbrehm
2007-06-02 277d5699af83ad8e155a613b2db86b0ab3b1ee2b
commit | author | age
9200ad 1 <?php
T 2
3 /*
4 Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 class installer_base {
32     
33     var $wb = array();
34     var $language = 'en';
35     var $db;
36     
37     /*
38     
39     */
40     
41     function lng() {
42         
43     }
44     
45     function error($msg) {
46         die("ERROR: ".$msg."\n");
47     }
48     
49     function request_language() {
50         
51         swriteln(lng('Enter your language'));
52         swriteln(lng('de, en'));
53         
54         /*
55         do {
56             $lang = sread(2);
57         } while (!$this->check_break($lang) or $this-> 
58         */
59         
60         
61     }
62     
63     /*
64         This function creates the database for ISPConfig
65     */
66     
67     function configure_database() {
68         global $conf;
69         
70         // Create the database
71         if(!$this->db->query("CREATE DATABASE IF NOT EXISTS ".$conf["mysql_server_database"])) {
72             $this->error('Unable to create MySQL database: '.$conf["mysql_server_database"].';');
73         }
74         
75         // Create the ISPConfig database user
76         if(!$this->db->query("GRANT SELECT, INSERT, UPDATE, DELETE ON ".$conf["mysql_server_database"].".* TO '".$conf["mysql_server_ispconfig_user"]."'@'".$conf["mysql_server_host"]."' IDENTIFIED BY '".$conf["mysql_server_ispconfig_password"]."';")) {
77             $this->error('Unable to create database user: '.$conf["mysql_server_ispconfig_user"]);
78         }
79         
80         // Reload database priveliges
81         $this->db->query('FLUSH PRIVILEGES;');
82         
83         // Set the database name in the DB library
84         $this->db->dbName = $conf["mysql_server_database"];
85         
86         // loading the database dump into the database, if database is empty
87         $db_tables = $this->db->getTables();
88         if(count($db_tables) > 0) {
89             $this->error('Stopped: Database contains already some tables.');
90         } else {
91             if($conf["mysql_server_admin_password"] == '') {
92                 caselog("mysql -h '".$conf["mysql_server_host"]."' -u '".$conf["mysql_server_admin_user"]."' '".$conf["mysql_server_database"]."' < 'sql/ispconfig3.sql' &> /dev/null", $FILE, __LINE__,"read in ispconfig3.sql","could not read in ispconfig3.sql");
93             } else {
94                 caselog("mysql -h '".$conf["mysql_server_host"]."' -u '".$conf["mysql_server_admin_user"]."' -p'".$conf["mysql_server_admin_password"]."' '".$conf["mysql_server_database"]."' < 'sql/ispconfig3.sql' &> /dev/null", $FILE, __LINE__,"read in ispconfig3.sql","could not read in ispconfig3.sql");
95             }
96             $db_tables = $this->db->getTables();
97             if(count($db_tables) == 0) {
98                 $this->error('Unable to load SQL-Dump into database table.');
99             }
100         }
101     }
102     
103     /*
104         Create postfix configuration files
105     */
106     
107     function configure_postfix() {
108         global $conf;
109         
110         if(!is_dir($conf["dist_postfix_config_dir"])) $this->error("The postfix configuration directory ".$conf["dist_postfix_config_dir"]." does not exist.");
111         
112         // mysql-virtual_domains.cf
113         $configfile = 'mysql-virtual_domains.cf';
114         if(is_file($conf["dist_postfix_config_dir"].'/'.$configfile)) copy($conf["dist_postfix_config_dir"].'/'.$configfile,$conf["dist_postfix_config_dir"].'/'.$configfile.'~');
115         $content = rf("tpl/".$configfile.".master");
116         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
117         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
118         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
119         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
120         wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
121         
122         // mysql-virtual_forwardings.cf
123         $configfile = 'mysql-virtual_forwardings.cf';
124         if(is_file($conf["dist_postfix_config_dir"].'/'.$configfile)) copy($conf["dist_postfix_config_dir"].'/'.$configfile,$conf["dist_postfix_config_dir"].'/'.$configfile.'~');
125         $content = rf("tpl/".$configfile.".master");
126         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
127         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
128         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
129         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
130         wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
131         
132         // mysql-virtual_mailboxes.cf
133         $configfile = 'mysql-virtual_mailboxes.cf';
134         if(is_file($conf["dist_postfix_config_dir"].'/'.$configfile)) copy($conf["dist_postfix_config_dir"].'/'.$configfile,$conf["dist_postfix_config_dir"].'/'.$configfile.'~');
135         $content = rf("tpl/".$configfile.".master");
136         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
137         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
138         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
139         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
140         wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
141         
142         // mysql-virtual_email2email.cf
143         $configfile = 'mysql-virtual_email2email.cf';
144         if(is_file($conf["dist_postfix_config_dir"].'/'.$configfile)) copy($conf["dist_postfix_config_dir"].'/'.$configfile,$conf["dist_postfix_config_dir"].'/'.$configfile.'~');
145         $content = rf("tpl/".$configfile.".master");
146         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
147         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
148         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
149         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
150         wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
151         
152         // mysql-virtual_transports.cf
153         $configfile = 'mysql-virtual_transports.cf';
154         if(is_file($conf["dist_postfix_config_dir"].'/'.$configfile)) copy($conf["dist_postfix_config_dir"].'/'.$configfile,$conf["dist_postfix_config_dir"].'/'.$configfile.'~');
155         $content = rf("tpl/".$configfile.".master");
156         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
157         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
158         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
159         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
160         wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
161         
162         // mysql-virtual_recipient.cf
163         $configfile = 'mysql-virtual_recipient.cf';
164         if(is_file($conf["dist_postfix_config_dir"].'/'.$configfile)) copy($conf["dist_postfix_config_dir"].'/'.$configfile,$conf["dist_postfix_config_dir"].'/'.$configfile.'~');
165         $content = rf("tpl/".$configfile.".master");
166         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
167         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
168         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
169         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
170         wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
171         
172         // mysql-virtual_sender.cf
173         $configfile = 'mysql-virtual_sender.cf';
174         if(is_file($conf["dist_postfix_config_dir"].'/'.$configfile)) copy($conf["dist_postfix_config_dir"].'/'.$configfile,$conf["dist_postfix_config_dir"].'/'.$configfile.'~');
175         $content = rf("tpl/".$configfile.".master");
176         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
177         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
178         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
179         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
180         wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
181         
182         // mysql-virtual_client.cf
183         $configfile = 'mysql-virtual_client.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_server_ispconfig_user"],$content);
187         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
188         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
189         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
190         wf($conf["dist_postfix_config_dir"].'/'.$configfile,$content);
191         
192         // Changing mode and group of the new created config files.
193         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");
194         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");
195         
196         // Creating virtual mail user and group
197         $command = "groupadd -g ".$conf["dist_postfix_vmail_groupid"]." ".$conf["dist_postfix_vmail_groupname"];
198         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
199         
200         $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";
201         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);        
202
203         $postconf_commands = array (
204             'myhostname = '.$conf["hostname"],
205             'mydestination = '.$conf["hostname"].', localhost, localhost.localdomain',
206             'mynetworks = 127.0.0.0/8',
207             'virtual_alias_domains =',
208             'virtual_alias_maps = proxy:mysql:'.$conf["dist_postfix_config_dir"].'/mysql-virtual_forwardings.cf, mysql:'.$conf["dist_postfix_config_dir"].'/mysql-virtual_email2email.cf',
209             'virtual_mailbox_domains = proxy:mysql:'.$conf["dist_postfix_config_dir"].'/mysql-virtual_domains.cf',
210             'virtual_mailbox_maps = proxy:mysql:'.$conf["dist_postfix_config_dir"].'/mysql-virtual_mailboxes.cf',
211             'virtual_mailbox_base = '.$conf["dist_postfix_vmail_mailbox_base"],
212             'virtual_uid_maps = static:'.$conf["dist_postfix_vmail_userid"],
213             'virtual_gid_maps = static:'.$conf["dist_postfix_vmail_groupid"],
214             'smtpd_sasl_auth_enable = yes',
215             'broken_sasl_auth_clients = yes',
216             'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:'.$conf["dist_postfix_config_dir"].'/mysql-virtual_recipient.cf, reject_unauth_destination',
217             'smtpd_use_tls = yes',
218             'smtpd_tls_cert_file = '.$conf["dist_postfix_config_dir"].'/smtpd.cert',
219             'smtpd_tls_key_file = '.$conf["dist_postfix_config_dir"].'/smtpd.key',
220             'transport_maps = proxy:mysql:'.$conf["dist_postfix_config_dir"].'/mysql-virtual_transports.cf',
221             'virtual_create_maildirsize = yes',
222             'virtual_mailbox_extended = yes',
223             'virtual_mailbox_limit_maps = proxy:mysql:'.$conf["dist_postfix_config_dir"].'/mysql-virtual_mailbox_limit_maps.cf',
224             'virtual_mailbox_limit_override = yes',
225             'virtual_maildir_limit_message = "The user you are trying to reach is over quota."',
226             'virtual_overquota_bounce = yes',
227             'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps',
228             'smtpd_sender_restrictions = check_sender_access mysql:'.$conf["dist_postfix_config_dir"].'/mysql-virtual_sender.cf',
229             'smtpd_client_restrictions = check_client_access mysql:'.$conf["dist_postfix_config_dir"].'/mysql-virtual_client.cf',
230             'maildrop_destination_concurrency_limit = 1',
231             'maildrop_destination_recipient_limit   = 1',
232             'virtual_transport = maildrop'
233         );
234         
235         // Make a backup copy of the main.cf file
236         copy($conf["dist_postfix_config_dir"].'/main.cf',$conf["dist_postfix_config_dir"].'/main.cf~');
237         
238         // Executing the postconf commands
239         foreach($postconf_commands as $cmd) {
240             $command = "postconf -e '$cmd'";
241             caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
242         }
243         
244         // TODO: Change the master.cf file
245         /*
246         Add:
247 maildrop  unix  -       n       n       -       -       pipe
248   flags=R user=vmail argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}
249         
250         */
251         
252         // Create the SSL certificate
253         $command = "cd ".$conf["dist_postfix_config_dir"]."; openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509";
254         exec($command);
255         
256         $command = "chmod o= ".$conf["dist_postfix_config_dir"]."/smtpd.key";
257         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
258         
259         /*
260         We have to change the permissions of the courier authdaemon directory
261         to make it accessible for maildrop.
262         */
263         
264         $command = "chmod 755  /var/run/courier/authdaemon/";
265         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
266         
267         // Writing the Maildrop mailfilter file
268         $configfile = 'mailfilter';
269         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.'~');
270         $content = rf("tpl/".$configfile.".master");
271         $content = str_replace('{dist_postfix_vmail_mailbox_base}',$conf["dist_postfix_vmail_mailbox_base"],$content);
272         wf($conf["dist_postfix_vmail_mailbox_base"].'/.'.$configfile,$content);
273         
274         // Create the directory for the custom mailfilters
275         $command = "mkdir ".$conf["dist_postfix_vmail_mailbox_base"]."/mailfilters";
276         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
277         
278         // Chmod and chown the .mailfilter file
279         $command = "chown -R ".$conf["dist_postfix_vmail_username"].":".$conf["dist_postfix_vmail_groupname"]." ".$conf["dist_postfix_vmail_mailbox_base"]."/.mailfilter";
280         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
281         
282         $command = "chmod -R 600 ".$conf["dist_postfix_vmail_mailbox_base"]."/.mailfilter";
283         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
284         
285         
286         
287     }
288     
289     function configure_saslauthd() {
290         global $conf;
291         
292         /*
293         
294         TODO: The example below is for Ubuntu 6.10
295         
296         mkdir -p /var/spool/postfix/var/run/saslauthd
297
298 Edit /etc/default/saslauthd. Remove the # in front of START=yes and add the line PARAMS="-m /var/spool/postfix/var/run/saslauthd -r". 
299
300 vi /etc/default/saslauthd
301
302 The file should then look like this:
303
304 # This needs to be uncommented before saslauthd will be run automatically
305 START=yes
306
307 # You must specify the authentication mechanisms you wish to use.
308 # This defaults to "pam" for PAM support, but may also include
309 # "shadow" or "sasldb", like this:
310 # MECHANISMS="pam shadow"
311
312 MECHANISMS="pam"
313 PARAMS="-m /var/spool/postfix/var/run/saslauthd -r"
314
315 We must also edit /etc/init.d/saslauthd and change the location of saslauthd's PID file. 
316
317 vi /etc/init.d/saslauthd
318
319 Change the value of PIDFILE to /var/spool/postfix/var/run/${NAME}/saslauthd.pid:
320
321 PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid"
322
323
324 Then restart Postfix and Saslauthd:
325
326 /etc/init.d/postfix restart
327 postfix check
328 /etc/init.d/saslauthd restart
329         
330         
331         */
332         
333         $configfile = 'sasl_smtpd.conf';
334         if(is_file($conf["dist_postfix_config_dir"].'/sasl/smtpd.conf')) copy($conf["dist_postfix_config_dir"].'/sasl/smtpd.conf',$conf["dist_postfix_config_dir"].'/sasl/smtpd.conf~');
a9a112 335         if(is_file($conf["dist_postfix_config_dir"].'/sasl/smtpd.conf~')) exec('chmod 400 '.$conf["dist_postfix_config_dir"].'/sasl/smtpd.conf~');
9200ad 336         $content = rf("tpl/".$configfile.".master");
T 337         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
338         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
339         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
340         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
341         wf($conf["dist_postfix_config_dir"].'/sasl/smtpd.conf',$content);
342         
343         // TODO: Chmod and chown on the config file
344         
345         
346     }
347     
348     function configure_pam() {
349         global $conf;
350         
351         // configure pam for SMTP authentication agains the ispconfig database
352         $configfile = 'pamd_smtp';
353         if(is_file('/etc/pam.d/smtp')) copy('/etc/pam.d/smtp','/etc/pam.d/smtp~');
a9a112 354         if(is_file('/etc/pam.d/smtp~')) exec('chmod 400 /etc/pam.d/smtp~');
9200ad 355         $content = rf("tpl/".$configfile.".master");
T 356         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
357         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
358         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
359         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
360         wf('/etc/pam.d/smtp',$content);
361         exec('chmod 660 /etc/pam.d/smtp');
362         exec('chown daemon:daemon /etc/pam.d/smtp');
363     
364     }
365     
366     function configure_courier() {
367         global $conf;
368         
369         // authmysqlrc
370         $configfile = 'authmysqlrc';
371         if(is_file($conf["dist_courier_config_dir"].'/'.$configfile)) copy($conf["dist_courier_config_dir"].'/'.$configfile,$conf["dist_courier_config_dir"].'/'.$configfile.'~');
372         exec('chmod 400 '.$conf["dist_courier_config_dir"].'/'.$configfile.'~');
373         $content = rf("tpl/".$configfile.".master");
374         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
375         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
376         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
377         $content = str_replace('{mysql_server_host}',$conf["mysql_server_host"],$content);
378         wf($conf["dist_courier_config_dir"].'/'.$configfile,$content);
379         
380         exec('chmod 660 '.$conf["dist_courier_config_dir"].'/'.$configfile);
381         exec('chown daemon:daemon '.$conf["dist_courier_config_dir"].'/'.$configfile);
382     }
383     
384     function configure_amavis() {
385         global $conf;
386         
387         // amavisd user config file
388         $configfile = 'amavisd_user_config';
5f0f02 389         if(is_file($conf["dist_amavis_config_dir"].'/conf.d/50-user')) copy($conf["dist_amavis_config_dir"].'/conf.d/50-user',$conf["dist_courier_config_dir"].'/50-user~');
T 390         if(is_file($conf["dist_amavis_config_dir"].'/conf.d/50-user~')) exec('chmod 400 '.$conf["dist_amavis_config_dir"].'/conf.d/50-user~');
9200ad 391         $content = rf("tpl/".$configfile.".master");
T 392         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
393         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
394         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
5f0f02 395         $content = str_replace('{mysql_server_port}',$conf["mysql_server_port"],$content);
9200ad 396         $content = str_replace('{mysql_server_ip}',$conf["mysql_server_ip"],$content);
5f0f02 397         wf($conf["dist_amavis_config_dir"].'/conf.d/50-user',$content);
9200ad 398         
T 399         // TODO: chmod and chown on the config file
400         
401         
402         // Adding the amavisd commands to the postfix configuration
403         $postconf_commands = array (
404             'content_filter = amavis:[127.0.0.1]:10024',
405             'receive_override_options = no_address_mappings'
406         );
407         
408         // Make a backup copy of the main.cf file
409         copy($conf["dist_postfix_config_dir"].'/main.cf',$conf["dist_postfix_config_dir"].'/main.cf~2');
410         
411         // Executing the postconf commands
412         foreach($postconf_commands as $cmd) {
413             $command = "postconf -e '$cmd'";
414             caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
415         }
416         
417         // Append the configuration for amavisd to the master.cf file
418         if(is_file($conf["dist_postfix_config_dir"].'/master.cf')) copy($conf["dist_postfix_config_dir"].'/master.cf',$conf["dist_postfix_config_dir"].'/master.cf~');
419         $content = rf("tpl/master_cf_amavis.master");
420         // Only add the content if we had not addded it before
421         if(!stristr("127.0.0.1:10025 inet n - - - - smtpd",$content)) {
422             af($conf["dist_postfix_config_dir"].'/master.cf',$content);
423         }
424         
425         // Add the clamav user to the amavis group
426         exec('adduser clamav amavis');
427         
428         
429     }
430     
431     function configure_spamassassin() {
432         global $conf;
433         
434         // Enable spamasasssin in debian and ubunti
435         $configfile = '/etc/default/spamassassin';
436         if(is_file($configfile)) copy($configfile,$configfile.'~');
437         $content = rf($configfile);
438         $content = str_replace('ENABLED=0','ENABLED=1',$content);
439         wf($configfile,$content);
440     }
441     
ba747c 442     function configure_getmail() {
T 443         global $conf;
444         
3edf9d 445         $command = "useradd -d /etc/getmail getmail";
T 446         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
447         
448         $command = "chown -R getmail /etc/getmail";
ba747c 449         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
T 450         
451         $command = "chmod -R 700 /etc/getmail";
452         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
453     }
454     
9200ad 455     
T 456     function install_ispconfig() {
457         global $conf;
458         
459         // Create the ISPConfig installation directory
460         $command = "mkdir ".$conf["ispconfig_install_dir"];
461         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
462         
463         // Create a ISPConfig user and group
464         $command = "groupadd ispconfig";
465         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
466         
467         $command = "useradd -g ispconfig -d ".$conf["ispconfig_install_dir"]." ispconfig";
468         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
469         
470         // copy the ISPConfig interface part
471         $command = "cp -rf ../interface ".$conf["ispconfig_install_dir"];
472         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
473         
474         // copy the ISPConfig server part
475         $command = "cp -rf ../server ".$conf["ispconfig_install_dir"];
476         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
477         
478         // Create a symlink, so ISPConfig is accessible via web
479         $command = "ln -s ".$conf["ispconfig_install_dir"]."/interface/web/ /var/www/ispconfig";
480         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
481         
ba747c 482         // Create the config file for ISPConfig interface
9200ad 483         $configfile = 'config.inc.php';
T 484         if(is_file($conf["ispconfig_install_dir"].'/interface/lib/'.$configfile)) copy($conf["ispconfig_install_dir"].'/interface/lib/'.$configfile,$conf["ispconfig_install_dir"].'/interface/lib/'.$configfile.'~');
485         $content = rf("tpl/".$configfile.".master");
486         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
487         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
488         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
489         $content = str_replace('{mysql_server_host}',$conf["mysql_server_host"],$content);
490         wf($conf["ispconfig_install_dir"].'/interface/lib/'.$configfile,$content);
ba747c 491         
T 492         // Create the config file for ISPConfig server
493         $configfile = 'config.inc.php';
494         if(is_file($conf["ispconfig_install_dir"].'/server/lib/'.$configfile)) copy($conf["ispconfig_install_dir"].'/server/lib/'.$configfile,$conf["ispconfig_install_dir"].'/interface/lib/'.$configfile.'~');
495         $content = rf("tpl/".$configfile.".master");
496         $content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql_server_ispconfig_user"],$content);
497         $content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql_server_ispconfig_password"],$content);
498         $content = str_replace('{mysql_server_database}',$conf["mysql_server_database"],$content);
499         $content = str_replace('{mysql_server_host}',$conf["mysql_server_host"],$content);
500         wf($conf["ispconfig_install_dir"].'/server/lib/'.$configfile,$content);
501         
9200ad 502         
T 503         // Chmod the files
504         $command = "chmod -R 750 ".$conf["ispconfig_install_dir"];
505         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
506
507         // chown the files to the ispconfig user and group
508         $command = "chown -R ispconfig:ispconfig ".$conf["ispconfig_install_dir"];
509         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
510         
511         // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
512         // and must be fixed as this will allow the apache user to read the ispconfig files.
513         // Later this must run as own apache server or via suexec!
514         
515         $command = "adduser www-data ispconfig";
516         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
517         
ba747c 518         // Make the shell scripts executable
T 519         $command = "chmod +x ".$conf["ispconfig_install_dir"]."/server/scripts/*.sh";
520         caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
9200ad 521         
T 522     }
523     
daff5c 524     function install_crontab() {
T 525         global $conf;
526         
527         // Root Crontab
528         exec("crontab -u root -l > crontab.txt");
529         $existing_root_cron_jobs = file('crontab.txt');
530         
531         $root_cron_jobs = array('* * * * * /usr/bin/php -q /usr/local/ispconfig/server/server.php &> /dev/null');
532         foreach($root_cron_jobs as $cron_job) {
533             if(!in_array($cron_job."\n",$existing_root_cron_jobs)) {
534                 $existing_root_cron_jobs[] = $cron_job."\n";
535             }
536         }
537         file_put_contents('crontab.txt',$existing_root_cron_jobs);
538         exec("crontab -u root crontab.txt &> /dev/null");
539         unlink('crontab.txt');
540         
541         // Getmail crontab
542         exec("crontab -u root -l > crontab.txt");
543         $existing_cron_jobs = file('crontab.txt');
544         
545         $cron_jobs = array('*/5 * * * * '.$conf["dist_getmail_program"].' -g '.$conf["dist_getmail_config_dir"].' -r '.$conf["dist_getmail_config_dir"].'/*.conf &> /dev/null');
546         foreach($cron_jobs as $cron_job) {
547             if(!in_array($cron_job."\n",$existing_cron_jobs)) {
548                 $existing_cron_jobs[] = $cron_job."\n";
549             }
550         }
551         file_put_contents('crontab.txt',$existing_cron_jobs);
552         exec("crontab -u root crontab.txt &> /dev/null");
553         unlink('crontab.txt');
554         
555     }
556     
9200ad 557     
T 558     
559 }
560
561 ?>