Till Brehm
2015-05-07 5538547761447df757fa42d68c0bf17e219a6a73
commit | author | age
ccebb9 1 <?php
TB 2
3 /*
4 Copyright (c) 2014, Till Brehm, ISPConfig UG
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 extends installer_dist {
32
33     public function configure_mailman($status = 'insert') {
34         global $conf;
35
36         $config_dir = $conf['mailman']['config_dir'].'/';
37         $full_file_name = $config_dir.'mm_cfg.py';
38         //* Backup exiting file
39         if(is_file($full_file_name)) {
40             copy($full_file_name, $config_dir.'mm_cfg.py~');
41         }
42
43         // load files
44         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/mm_cfg.py.master', 'tpl/mm_cfg.py.master');
45         $old_file = rf($full_file_name);
46
47         $old_options = array();
48         $lines = explode("\n", $old_file);
49         foreach ($lines as $line)
50         {
51             if (trim($line) != '' && substr($line, 0, 1) != '#')
52             {
53                 @list($key, $value) = @explode("=", $line);
54                 if (!empty($value))
55                 {
56                     $key = rtrim($key);
57                     $old_options[$key] = trim($value);
58                 }
59             }
60         }
61
62         $config_dir = $conf['mailman']['config_dir'].'/';
63         $full_file_name = $config_dir.'virtual_to_transport.sh';
64
65         //* Backup exiting virtual_to_transport.sh script
66         if(is_file($full_file_name)) {
67             copy($full_file_name, $config_dir.'virtual_to_transport.sh~');
68         }
69
70         if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/mailman-virtual_to_transport.sh')) {
71             copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/mailman-virtual_to_transport.sh', $full_file_name);
72         } else {
73             copy('tpl/mailman-virtual_to_transport.sh', $full_file_name);
74         }
75         chgrp($full_file_name, 'mailman');
76         chmod($full_file_name, 0750);
77
78         if(!is_file('/var/lib/mailman/data/transport-mailman')) touch('/var/lib/mailman/data/transport-mailman');
79         exec('/usr/sbin/postmap /var/lib/mailman/data/transport-mailman');
80
81         exec('/usr/lib/mailman/bin/genaliases 2>/dev/null');
82
83         $virtual_domains = '';
84         if($status == 'update')
85         {
86             // create virtual_domains list
87             $domainAll = $this->db->queryAllRecords("SELECT domain FROM mail_mailinglist GROUP BY domain");
88
89             if(is_array($domainAll)) {
90                 foreach($domainAll as $domain)
91                 {
92                     if ($domainAll[0]['domain'] == $domain['domain'])
93                         $virtual_domains .= "'".$domain['domain']."'";
94                     else
95                         $virtual_domains .= ", '".$domain['domain']."'";
96                 }
97             }
98         }
99         else
100             $virtual_domains = "' '";
101
102         $content = str_replace('{hostname}', $conf['hostname'], $content);
103         if(!isset($old_options['DEFAULT_SERVER_LANGUAGE'])) $old_options['DEFAULT_SERVER_LANGUAGE'] = '';
104         $content = str_replace('{default_language}', $old_options['DEFAULT_SERVER_LANGUAGE'], $content);
105         $content = str_replace('{virtual_domains}', $virtual_domains, $content);
106
107         wf($full_file_name, $content);
108     }
109
110     public function configure_amavis() {
111         global $conf;
112
113         // amavisd user config file
114         $configfile = 'fedora_amavisd_conf';
115         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf')) copy($conf["amavis"]["config_dir"].'/amavisd.conf', $conf["amavis"]["config_dir"].'/amavisd.conf~');
116         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/amavisd.conf~');
117         if(!is_dir($conf["amavis"]["config_dir"])) mkdir($conf["amavis"]["config_dir"]);
118         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/'.$configfile.'.master', "tpl/".$configfile.".master");
119         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
120         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
121         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
122         $content = str_replace('{mysql_server_port}', $conf["mysql"]["port"], $content);
123         $content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content);
124         $content = str_replace('{hostname}', $conf['hostname'], $content);
125         $content = str_replace('/var/spool/amavisd/clamd.sock', '/var/run/clamav/clamd.sock', $content);
126         wf($conf["amavis"]["config_dir"].'/amavisd.conf', $content);
553854 127         chmod($conf['amavis']['config_dir'].'/amavisd.conf', 0640);
ccebb9 128
TB 129
130         // Adding the amavisd commands to the postfix configuration
131         $postconf_commands = array (
132             'content_filter = amavis:[127.0.0.1]:10024',
133             'receive_override_options = no_address_mappings'
134         );
135
136         // Make a backup copy of the main.cf file
137         copy($conf["postfix"]["config_dir"].'/main.cf', $conf["postfix"]["config_dir"].'/main.cf~2');
138
139         // Executing the postconf commands
140         foreach($postconf_commands as $cmd) {
141             $command = "postconf -e '$cmd'";
142             caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
143         }
144
145         // Append the configuration for amavisd to the master.cf file
146         if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf', $conf["postfix"]["config_dir"].'/master.cf~');
147         $content = rf($conf["postfix"]["config_dir"].'/master.cf');
148         // Only add the content if we had not addded it before
149         if(!stristr($content, "127.0.0.1:10025")) {
150             unset($content);
151             $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/master_cf_amavis.master', "tpl/master_cf_amavis.master");
152             af($conf["postfix"]["config_dir"].'/master.cf', $content);
153         }
154         unset($content);
155
156         removeLine('/etc/sysconfig/freshclam', 'FRESHCLAM_DELAY=disabled-warn   # REMOVE ME', 1);
157         replaceLine('/etc/freshclam.conf', 'Example', '# Example', 1);
158
159
160     }
161
162
163 }
164
165 ?>