tbrehm
2013-02-22 526b997c9891a796b152cdbab8e329b356b1f596
commit | author | age
663619 1 <?php
T 2
3 /*
436ed8 4 Copyright (c) 2007, Till Brehm, projektfarm Gmbh
663619 5 All rights reserved.
T 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
526b99 33     public function configure_mailman($status = 'insert') {
T 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 = rf('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         copy('tpl/mailman-virtual_to_transport.sh',$full_file_name);
71         chgrp($full_file_name,'mailman');
72         chmod($full_file_name,0750);
73         
74         if(!is_file('/var/lib/mailman/data/transport-mailman')) touch('/var/lib/mailman/data/transport-mailman');
75         exec('/usr/sbin/postmap /var/lib/mailman/data/transport-mailman');
76         
77         exec('/usr/lib/mailman/bin/genaliases 2>/dev/null');
78
79         $virtual_domains = '';
80         if($status == 'update')
81         {
82             // create virtual_domains list
83             $domainAll = $this->db->queryAllRecords("SELECT domain FROM mail_mailinglist GROUP BY domain");
84
85             if(is_array($domainAll)) {
86             foreach($domainAll as $domain)
87             {
88                 if ($domainAll[0]['domain'] == $domain['domain'])
89                     $virtual_domains .= "'".$domain['domain']."'";
90                 else
91                     $virtual_domains .= ", '".$domain['domain']."'";
92             }
93             }
94         }
95         else
96             $virtual_domains = "' '";
97
98         $content = str_replace('{hostname}', $conf['hostname'], $content);
99         if(!isset($old_options['DEFAULT_SERVER_LANGUAGE'])) $old_options['DEFAULT_SERVER_LANGUAGE'] = '';
100         $content = str_replace('{default_language}', $old_options['DEFAULT_SERVER_LANGUAGE'], $content);
101         $content = str_replace('{virtual_domains}', $virtual_domains, $content);
102
103         wf($full_file_name, $content);
104     }
105
f28f40 106     public function configure_amavis() {
T 107         global $conf;
108         
109         // amavisd user config file
110         $configfile = 'fedora_amavisd_conf';
fb3a98 111         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf')) copy($conf["amavis"]["config_dir"].'/amavisd.conf',$conf["amavis"]["config_dir"].'/amavisd.conf~');
f28f40 112         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/amavisd.conf~');
T 113         $content = rf("tpl/".$configfile.".master");
114         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
115         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
116         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
117         $content = str_replace('{mysql_server_port}',$conf["mysql"]["port"],$content);
118         $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
119         $content = str_replace('{hostname}',$conf['hostname'],$content);
120         $content = str_replace('/var/spool/amavisd/clamd.sock','/tmp/clamd.socket',$content);
121         wf($conf["amavis"]["config_dir"].'/amavisd.conf',$content);
122         
123         
124         // Adding the amavisd commands to the postfix configuration
125         $postconf_commands = array (
126             'content_filter = amavis:[127.0.0.1]:10024',
127             'receive_override_options = no_address_mappings'
128         );
129         
130         // Make a backup copy of the main.cf file
131         copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~2');
132         
133         // Executing the postconf commands
134         foreach($postconf_commands as $cmd) {
135             $command = "postconf -e '$cmd'";
136             caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
137         }
138         
139         // Append the configuration for amavisd to the master.cf file
140         if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf',$conf["postfix"]["config_dir"].'/master.cf~');
141         $content = rf($conf["postfix"]["config_dir"].'/master.cf');
142         // Only add the content if we had not addded it before
143         if(!stristr($content,"127.0.0.1:10025")) {
144             unset($content);
145             $content = rf("tpl/master_cf_amavis.master");
146             af($conf["postfix"]["config_dir"].'/master.cf',$content);
147         }
148         unset($content);
149         
150         removeLine('/etc/sysconfig/freshclam','FRESHCLAM_DELAY=disabled-warn   # REMOVE ME',1);
151         replaceLine('/etc/freshclam.conf','Example','# Example',1);
152         
153         
154     }
155
663619 156
T 157 }
158
159 ?>