tbrehm
2013-02-22 526b997c9891a796b152cdbab8e329b356b1f596
commit | author | age
edebc4 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 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
edebc4 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~');
edebc4 112         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/amavisd.conf~');
9f56bd 113         if(!is_dir($conf["amavis"]["config_dir"])) mkdir($conf["amavis"]["config_dir"]);
edebc4 114         $content = rf("tpl/".$configfile.".master");
T 115         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
116         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
117         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
118         $content = str_replace('{mysql_server_port}',$conf["mysql"]["port"],$content);
119         $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
120         $content = str_replace('{hostname}',$conf['hostname'],$content);
121         $content = str_replace('/var/spool/amavisd/clamd.sock','/var/run/clamav/clamd.sock',$content);
122         wf($conf["amavis"]["config_dir"].'/amavisd.conf',$content);
123         
124         
125         // Adding the amavisd commands to the postfix configuration
126         $postconf_commands = array (
127             'content_filter = amavis:[127.0.0.1]:10024',
128             'receive_override_options = no_address_mappings'
129         );
130         
131         // Make a backup copy of the main.cf file
132         copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~2');
133         
134         // Executing the postconf commands
135         foreach($postconf_commands as $cmd) {
136             $command = "postconf -e '$cmd'";
137             caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
138         }
139         
140         // Append the configuration for amavisd to the master.cf file
141         if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf',$conf["postfix"]["config_dir"].'/master.cf~');
142         $content = rf($conf["postfix"]["config_dir"].'/master.cf');
143         // Only add the content if we had not addded it before
144         if(!stristr($content,"127.0.0.1:10025")) {
145             unset($content);
146             $content = rf("tpl/master_cf_amavis.master");
147             af($conf["postfix"]["config_dir"].'/master.cf',$content);
148         }
149         unset($content);
150         
151         removeLine('/etc/sysconfig/freshclam','FRESHCLAM_DELAY=disabled-warn   # REMOVE ME',1);
152         replaceLine('/etc/freshclam.conf','Example','# Example',1);
153         
154         
155     }
156
157
158 }
159
160 ?>