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; |
cc3fb3
|
36 |
public $conf; |
ca5291
|
37 |
public $install_ispconfig_interface = true; |
0d0cd9
|
38 |
|
09e141
|
39 |
|
P |
40 |
|
32814e
|
41 |
public function __construct() |
5133cc
|
42 |
{ |
b0a1cc
|
43 |
global $conf; //TODO: maybe $conf should be passed to constructor |
cd972d
|
44 |
//$this->conf = $conf; |
5133cc
|
45 |
} |
9200ad
|
46 |
|
4f7028
|
47 |
//: TODO Implement the translation function and language files for the installer. |
32814e
|
48 |
public function lng($text) |
P |
49 |
{ |
ce9544
|
50 |
return $text; |
9200ad
|
51 |
} |
T |
52 |
|
32814e
|
53 |
public function error($msg) |
P |
54 |
{ |
9200ad
|
55 |
die("ERROR: ".$msg."\n"); |
T |
56 |
} |
|
57 |
|
32814e
|
58 |
public function simple_query($query, $answers, $default) |
P |
59 |
{ |
ce9544
|
60 |
$finished = false; |
T |
61 |
do { |
32814e
|
62 |
$answers_str = implode(',', $answers); |
239ce8
|
63 |
swrite($this->lng($query).' ('.$answers_str.') ['.$default.']: '); |
ce9544
|
64 |
$input = sread(); |
T |
65 |
|
32814e
|
66 |
//* Stop the installation |
ce9544
|
67 |
if($input == 'quit') { |
32814e
|
68 |
swriteln($this->lng("Installation terminated by user.\n")); |
239ce8
|
69 |
die(); |
ce9544
|
70 |
} |
T |
71 |
|
32814e
|
72 |
//* Select the default |
ce9544
|
73 |
if($input == '') { |
T |
74 |
$answer = $default; |
|
75 |
$finished = true; |
|
76 |
} |
|
77 |
|
32814e
|
78 |
//* Set answer id valid |
P |
79 |
if(in_array($input, $answers)) { |
ce9544
|
80 |
$answer = $input; |
T |
81 |
$finished = true; |
|
82 |
} |
|
83 |
|
|
84 |
} while ($finished == false); |
239ce8
|
85 |
swriteln(); |
ce9544
|
86 |
return $answer; |
T |
87 |
} |
|
88 |
|
32814e
|
89 |
public function free_query($query,$default) |
P |
90 |
{ |
239ce8
|
91 |
swrite($this->lng($query).' ['.$default.']: '); |
ce9544
|
92 |
$input = sread(); |
T |
93 |
|
32814e
|
94 |
//* Stop the installation |
ce9544
|
95 |
if($input == 'quit') { |
32814e
|
96 |
swriteln($this->lng("Installation terminated by user.\n")); |
P |
97 |
die(); |
ce9544
|
98 |
} |
T |
99 |
|
32814e
|
100 |
$answer = ($input == '') ? $default : $input; |
239ce8
|
101 |
swriteln(); |
ce9544
|
102 |
return $answer; |
T |
103 |
} |
|
104 |
|
1b063e
|
105 |
/* |
32814e
|
106 |
// TODO: this function is not used atmo I think - pedro |
P |
107 |
function request_language(){ |
9200ad
|
108 |
|
T |
109 |
swriteln(lng('Enter your language')); |
|
110 |
swriteln(lng('de, en')); |
|
111 |
|
|
112 |
} |
1b063e
|
113 |
*/ |
9200ad
|
114 |
|
facccb
|
115 |
/** Create the database for ISPConfig */ |
P |
116 |
public function configure_database() |
|
117 |
{ |
9200ad
|
118 |
global $conf; |
01074a
|
119 |
|
facccb
|
120 |
$cf = $conf['mysql']; // make $conf['mysql'] more accessible |
P |
121 |
//** Create the database |
|
122 |
if(!$this->db->query('CREATE DATABASE IF NOT EXISTS '.$cf['database'])) { |
|
123 |
$this->error('Unable to create MySQL database: '.$cf['database'].'.'); |
9200ad
|
124 |
} |
T |
125 |
|
facccb
|
126 |
//* Set the database name in the DB library |
P |
127 |
$this->db->dbName = $cf['database']; |
9200ad
|
128 |
|
facccb
|
129 |
//* Load the database dump into the database, if database contains no tables |
9200ad
|
130 |
$db_tables = $this->db->getTables(); |
T |
131 |
if(count($db_tables) > 0) { |
66b4f9
|
132 |
$this->error('Stopped: Database already contains some tables.'); |
9200ad
|
133 |
} else { |
facccb
|
134 |
if($cf['admin_password'] == '') { |
faf3f5
|
135 |
caselog("mysql -h '".$cf['host']."' -u '".$cf['admin_user']."' '".$cf['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", |
66b4f9
|
136 |
__FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); |
9200ad
|
137 |
} else { |
faf3f5
|
138 |
caselog("mysql -h '".$cf['host']."' -u '".$cf['admin_user']."' -p'".$cf['admin_password']."' '".$cf['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", |
66b4f9
|
139 |
__FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); |
9200ad
|
140 |
} |
T |
141 |
$db_tables = $this->db->getTables(); |
|
142 |
if(count($db_tables) == 0) { |
|
143 |
$this->error('Unable to load SQL-Dump into database table.'); |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
|
4f7028
|
148 |
//** Create the server record in the database |
94411b
|
149 |
public function add_database_server_record() { |
7bd4b4
|
150 |
|
T |
151 |
global $conf; |
01074a
|
152 |
|
7bd4b4
|
153 |
$cf = $conf['mysql']; // make $conf['mysql'] more accessible |
T |
154 |
|
ac4a37
|
155 |
if($cf['host'] == 'localhost') { |
T |
156 |
$from_host = 'localhost'; |
|
157 |
} else { |
cd972d
|
158 |
$from_host = $conf['hostname']; |
ac4a37
|
159 |
} |
T |
160 |
|
f1b989
|
161 |
// Delete ISPConfig user, in case that it exists |
T |
162 |
$this->db->query("DELETE FROM mysql.user WHERE User = '".$cf['ispconfig_user']."' AND Host = '".$from_host."';"); |
|
163 |
$this->db->query("DELETE FROM mysql.db WHERE Db = '".$cf['database']."' AND Host = '".$from_host."';"); |
|
164 |
$this->db->query('FLUSH PRIVILEGES;'); |
|
165 |
|
7bd4b4
|
166 |
//* Create the ISPConfig database user |
T |
167 |
$query = 'GRANT SELECT, INSERT, UPDATE, DELETE ON '.$cf['database'].".* " |
ac4a37
|
168 |
."TO '".$cf['ispconfig_user']."'@'".$from_host."' " |
7bd4b4
|
169 |
."IDENTIFIED BY '".$cf['ispconfig_password']."';"; |
T |
170 |
if(!$this->db->query($query)) { |
f1b989
|
171 |
$this->error('Unable to create database user: '.$cf['ispconfig_user'].' Error: '.$this->db->errorMessage); |
7bd4b4
|
172 |
} |
T |
173 |
|
|
174 |
//* Reload database privelages |
|
175 |
$this->db->query('FLUSH PRIVILEGES;'); |
|
176 |
|
a768b9
|
177 |
//* Set the database name in the DB library |
T |
178 |
$this->db->dbName = $cf['database']; |
94411b
|
179 |
|
d4c9b3
|
180 |
$server_ini_content = rf("tpl/server.ini.master"); |
8500be
|
181 |
$server_ini_content = mysql_real_escape_string($server_ini_content); |
94411b
|
182 |
|
cd972d
|
183 |
$sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', 1, 1, 1, 1, 1, 1, '$server_ini_content', 0, 1);"; |
94411b
|
184 |
$this->db->query($sql); |
a768b9
|
185 |
$conf['server_id'] = $this->db->insertID(); |
cd972d
|
186 |
$conf['server_id'] = $conf['server_id']; |
94411b
|
187 |
} |
T |
188 |
|
b41692
|
189 |
|
09e141
|
190 |
//** writes postfix configuration files |
7d89f5
|
191 |
public function process_postfix_config($configfile) |
01074a
|
192 |
{ |
T |
193 |
global $conf; |
|
194 |
|
cd972d
|
195 |
$config_dir = $conf['postfix']['config_dir'].'/'; |
b41692
|
196 |
$full_file_name = $config_dir.$configfile; |
P |
197 |
//* Backup exiting file |
|
198 |
if(is_file($full_file_name)){ |
|
199 |
copy($full_file_name, $config_dir.$configfile.'~'); |
|
200 |
} |
|
201 |
$content = rf('tpl/'.$configfile.'.master'); |
cd972d
|
202 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content); |
T |
203 |
$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content); |
|
204 |
$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
|
205 |
$content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content); |
|
206 |
$content = str_replace('{server_id}', $conf['server_id'], $content); |
b41692
|
207 |
wf($full_file_name, $content); |
P |
208 |
} |
|
209 |
|
61d290
|
210 |
public function configure_jailkit() |
D |
211 |
{ |
01074a
|
212 |
global $conf; |
T |
213 |
|
|
214 |
$cf = $conf['jailkit']; |
61d290
|
215 |
$config_dir = $cf['config_dir']; |
D |
216 |
$jk_init = $cf['jk_init']; |
|
217 |
$jk_chrootsh = $cf['jk_chrootsh']; |
|
218 |
|
3e8065
|
219 |
if (is_dir($config_dir)) |
61d290
|
220 |
{ |
fad1df
|
221 |
if(is_file($config_dir.'/'.$jk_init)) copy($config_dir.'/'.$jk_init, $config_dir.'/'.$jk_init.'~'); |
T |
222 |
if(is_file($config_dir.'/'.$jk_chrootsh.".master")) copy($config_dir.'/'.$jk_chrootsh.".master", $config_dir.'/'.$jk_chrootsh.'~'); |
61d290
|
223 |
|
D |
224 |
copy('tpl/'.$jk_init.".master", $config_dir.'/'.$jk_init); |
|
225 |
copy('tpl/'.$jk_chrootsh.".master", $config_dir.'/'.$jk_chrootsh); |
|
226 |
} |
|
227 |
|
|
228 |
} |
|
229 |
|
b41692
|
230 |
public function configure_postfix($options = '') |
P |
231 |
{ |
cd972d
|
232 |
global $conf; |
T |
233 |
$cf = $conf['postfix']; |
77ab0a
|
234 |
$config_dir = $cf['config_dir']; |
P |
235 |
|
b41692
|
236 |
if(!is_dir($config_dir)){ |
P |
237 |
$this->error("The postfix configuration directory '$config_dir' does not exist."); |
|
238 |
} |
|
239 |
|
|
240 |
//* mysql-virtual_domains.cf |
|
241 |
$this->process_postfix_config('mysql-virtual_domains.cf'); |
|
242 |
|
|
243 |
//* mysql-virtual_forwardings.cf |
|
244 |
$this->process_postfix_config('mysql-virtual_forwardings.cf'); |
|
245 |
|
|
246 |
//* mysql-virtual_mailboxes.cf |
|
247 |
$this->process_postfix_config('mysql-virtual_mailboxes.cf'); |
|
248 |
|
|
249 |
//* mysql-virtual_email2email.cf |
|
250 |
$this->process_postfix_config('mysql-virtual_email2email.cf'); |
|
251 |
|
|
252 |
//* mysql-virtual_transports.cf |
|
253 |
$this->process_postfix_config('mysql-virtual_transports.cf'); |
|
254 |
|
|
255 |
//* mysql-virtual_recipient.cf |
|
256 |
$this->process_postfix_config('mysql-virtual_recipient.cf'); |
|
257 |
|
|
258 |
//* mysql-virtual_sender.cf |
|
259 |
$this->process_postfix_config('mysql-virtual_sender.cf'); |
|
260 |
|
|
261 |
//* mysql-virtual_client.cf |
|
262 |
$this->process_postfix_config('mysql-virtual_client.cf'); |
5bf366
|
263 |
|
T |
264 |
//* mysql-virtual_relaydomains.cf |
|
265 |
$this->process_postfix_config('mysql-virtual_relaydomains.cf'); |
b41692
|
266 |
|
P |
267 |
//* Changing mode and group of the new created config files. |
77ab0a
|
268 |
caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', |
P |
269 |
__FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed'); |
|
270 |
caselog('chgrp '.$cf['group'].' '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', |
|
271 |
__FILE__, __LINE__, 'chgrp on mysql-virtual_*.cf*', 'chgrp on mysql-virtual_*.cf* failed'); |
9200ad
|
272 |
|
77ab0a
|
273 |
//* Creating virtual mail user and group |
P |
274 |
$command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname']; |
|
275 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
276 |
|
|
277 |
$command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m'; |
|
278 |
caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
279 |
|
T |
280 |
$postconf_commands = array ( |
cd972d
|
281 |
'myhostname = '.$conf['hostname'], |
T |
282 |
'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain', |
9200ad
|
283 |
'mynetworks = 127.0.0.0/8', |
T |
284 |
'virtual_alias_domains =', |
438d9f
|
285 |
'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf', |
P |
286 |
'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf', |
77ab0a
|
287 |
'virtual_mailbox_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailboxes.cf', |
P |
288 |
'virtual_mailbox_base = '.$cf['vmail_mailbox_base'], |
|
289 |
'virtual_uid_maps = static:'.$cf['vmail_userid'], |
|
290 |
'virtual_gid_maps = static:'.$cf['vmail_groupid'], |
9200ad
|
291 |
'smtpd_sasl_auth_enable = yes', |
T |
292 |
'broken_sasl_auth_clients = yes', |
438d9f
|
293 |
'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:'.$config_dir.'/mysql-virtual_recipient.cf, reject_unauth_destination', |
9200ad
|
294 |
'smtpd_use_tls = yes', |
438d9f
|
295 |
'smtpd_tls_cert_file = '.$config_dir.'/smtpd.cert', |
P |
296 |
'smtpd_tls_key_file = '.$config_dir.'/smtpd.key', |
|
297 |
'transport_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_transports.cf', |
5bf366
|
298 |
'relay_domains = mysql:'.$config_dir.'/mysql-virtual_relaydomains.cf', |
9200ad
|
299 |
'virtual_create_maildirsize = yes', |
T |
300 |
'virtual_mailbox_extended = yes', |
438d9f
|
301 |
'virtual_mailbox_limit_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailbox_limit_maps.cf', |
9200ad
|
302 |
'virtual_mailbox_limit_override = yes', |
T |
303 |
'virtual_maildir_limit_message = "The user you are trying to reach is over quota."', |
|
304 |
'virtual_overquota_bounce = yes', |
|
305 |
'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', |
438d9f
|
306 |
'smtpd_sender_restrictions = check_sender_access mysql:'.$config_dir.'/mysql-virtual_sender.cf', |
P |
307 |
'smtpd_client_restrictions = check_client_access mysql:'.$config_dir.'/mysql-virtual_client.cf', |
9200ad
|
308 |
'maildrop_destination_concurrency_limit = 1', |
T |
309 |
'maildrop_destination_recipient_limit = 1', |
54fb59
|
310 |
'virtual_transport = maildrop', |
438d9f
|
311 |
'header_checks = regexp:'.$config_dir.'/header_checks', |
P |
312 |
'mime_header_checks = regexp:'.$config_dir.'/mime_header_checks', |
|
313 |
'nested_header_checks = regexp:'.$config_dir.'/nested_header_checks', |
|
314 |
'body_checks = regexp:'.$config_dir.'/body_checks' |
9200ad
|
315 |
); |
T |
316 |
|
438d9f
|
317 |
//* Create the header and body check files |
P |
318 |
touch($config_dir.'/header_checks'); |
|
319 |
touch($config_dir.'/mime_header_checks'); |
|
320 |
touch($config_dir.'/nested_header_checks'); |
|
321 |
touch($config_dir.'/body_checks'); |
54fb59
|
322 |
|
T |
323 |
|
438d9f
|
324 |
//* Make a backup copy of the main.cf file |
P |
325 |
copy($config_dir.'/main.cf', $config_dir.'/main.cf~'); |
9200ad
|
326 |
|
438d9f
|
327 |
//* Executing the postconf commands |
9200ad
|
328 |
foreach($postconf_commands as $cmd) { |
T |
329 |
$command = "postconf -e '$cmd'"; |
438d9f
|
330 |
caselog($command." &> /dev/null", __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
9200ad
|
331 |
} |
T |
332 |
|
fb7155
|
333 |
if(!stristr($options,'dont-create-certs')) { |
438d9f
|
334 |
//* Create the SSL certificate |
P |
335 |
$command = 'cd '.$config_dir.'; ' |
|
336 |
.'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout ' |
|
337 |
.'smtpd.key -keyform PEM -days 365 -x509'; |
c58e3f
|
338 |
exec($command); |
9200ad
|
339 |
|
438d9f
|
340 |
$command = 'chmod o= '.$config_dir.'/smtpd.key'; |
P |
341 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
c58e3f
|
342 |
} |
9200ad
|
343 |
|
77ab0a
|
344 |
//** We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop. |
438d9f
|
345 |
$command = 'chmod 755 /var/run/courier/authdaemon/'; |
P |
346 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
9200ad
|
347 |
|
438d9f
|
348 |
//* Changing maildrop lines in posfix master.cf |
P |
349 |
if(is_file($config_dir.'/master.cf')){ |
|
350 |
copy($config_dir.'/master.cf', $config_dir.'/master.cf~'); |
|
351 |
} |
|
352 |
if(is_file($config_dir.'/master.cf~')){ |
|
353 |
exec('chmod 400 '.$config_dir.'/master.cf~'); |
|
354 |
} |
|
355 |
$configfile = $config_dir.'/master.cf'; |
20e642
|
356 |
$content = rf($configfile); |
77ab0a
|
357 |
$content = str_replace(' flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}', |
P |
358 |
' flags=R user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}', |
|
359 |
$content); |
|
360 |
wf($configfile, $content); |
20e642
|
361 |
|
438d9f
|
362 |
//* Writing the Maildrop mailfilter file |
9200ad
|
363 |
$configfile = 'mailfilter'; |
77ab0a
|
364 |
if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)){ |
P |
365 |
copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~'); |
|
366 |
} |
|
367 |
$content = rf("tpl/$configfile.master"); |
|
368 |
$content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content); |
|
369 |
wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content); |
9200ad
|
370 |
|
77ab0a
|
371 |
//* Create the directory for the custom mailfilters |
a3ec01
|
372 |
if(!is_dir($cf['vmail_mailbox_base'].'/mailfilters')) { |
T |
373 |
$command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters'; |
|
374 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
375 |
} |
9200ad
|
376 |
|
77ab0a
|
377 |
//* Chmod and chown the .mailfilter file |
P |
378 |
$command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter'; |
|
379 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
380 |
|
77ab0a
|
381 |
$command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter'; |
P |
382 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
383 |
|
T |
384 |
} |
|
385 |
|
7d89f5
|
386 |
public function configure_saslauthd() { |
9200ad
|
387 |
global $conf; |
T |
388 |
|
20e642
|
389 |
|
9200ad
|
390 |
$configfile = 'sasl_smtpd.conf'; |
cc3fb3
|
391 |
if(is_file($conf["postfix"]["config_dir"].'/sasl/smtpd.conf')) copy($conf["postfix"]["config_dir"].'/sasl/smtpd.conf',$conf["postfix"]["config_dir"].'/sasl/smtpd.conf~'); |
O |
392 |
if(is_file($conf["postfix"]["config_dir"].'/sasl/smtpd.conf~')) exec('chmod 400 '.$conf["postfix"]["config_dir"].'/sasl/smtpd.conf~'); |
9200ad
|
393 |
$content = rf("tpl/".$configfile.".master"); |
cd972d
|
394 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
T |
395 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
396 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content); |
|
397 |
$content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content); |
cc3fb3
|
398 |
wf($conf["postfix"]["config_dir"].'/sasl/smtpd.conf',$content); |
9200ad
|
399 |
|
T |
400 |
// TODO: Chmod and chown on the config file |
20e642
|
401 |
|
T |
402 |
|
|
403 |
|
|
404 |
// Create the spool directory |
20218c
|
405 |
exec('mkdir -p /var/spool/postfix/var/run/saslauthd'); |
20e642
|
406 |
|
T |
407 |
// Edit the file /etc/default/saslauthd |
cc3fb3
|
408 |
$configfile = $conf["saslauthd"]["config"]; |
20e642
|
409 |
if(is_file($configfile)) copy($configfile,$configfile.'~'); |
e32699
|
410 |
if(is_file($configfile.'~')) exec('chmod 400 '.$configfile.'~'); |
20e642
|
411 |
$content = rf($configfile); |
T |
412 |
$content = str_replace('START=no','START=yes',$content); |
20aa6b
|
413 |
// Debian |
20e642
|
414 |
$content = str_replace('OPTIONS="-c"','OPTIONS="-m /var/spool/postfix/var/run/saslauthd -r"',$content); |
20aa6b
|
415 |
// Ubuntu |
T |
416 |
$content = str_replace('OPTIONS="-c -m /var/run/saslauthd"','OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"',$content); |
20e642
|
417 |
wf($configfile,$content); |
T |
418 |
|
20218c
|
419 |
// Edit the file /etc/init.d/saslauthd |
cc3fb3
|
420 |
$configfile = $conf["init_scripts"].'/'.$conf["saslauthd"]["init_script"]; |
20e642
|
421 |
$content = rf($configfile); |
T |
422 |
$content = str_replace('PIDFILE=$RUN_DIR/saslauthd.pid','PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid"',$content); |
|
423 |
wf($configfile,$content); |
20aa6b
|
424 |
|
T |
425 |
// add the postfix user to the sasl group (at least nescessary for ubuntu 8.04 and most likely debian lenny too. |
|
426 |
exec('adduser postfix sasl'); |
9200ad
|
427 |
|
T |
428 |
|
|
429 |
} |
|
430 |
|
09e141
|
431 |
public function configure_pam() |
P |
432 |
{ |
cd972d
|
433 |
global $conf; |
T |
434 |
$pam = $conf['pam']; |
09e141
|
435 |
//* configure pam for SMTP authentication agains the ispconfig database |
9200ad
|
436 |
$configfile = 'pamd_smtp'; |
09e141
|
437 |
if(is_file("$pam/smtp")) copy("$pam/smtp", "$pam/smtp~"); |
P |
438 |
if(is_file("$pam/smtp~")) exec("chmod 400 $pam/smtp~"); |
|
439 |
|
|
440 |
$content = rf("tpl/$configfile.master"); |
cd972d
|
441 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content); |
T |
442 |
$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content); |
|
443 |
$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
|
444 |
$content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content); |
09e141
|
445 |
wf("$pam/smtp", $content); |
P |
446 |
exec("chmod 660 $pam/smtp"); |
|
447 |
exec("chown daemon:daemon $pam/smtp"); |
9200ad
|
448 |
|
T |
449 |
} |
|
450 |
|
09e141
|
451 |
public function configure_courier() |
P |
452 |
{ |
cd972d
|
453 |
global $conf; |
T |
454 |
$config_dir = $conf['courier']['config_dir']; |
09e141
|
455 |
//* authmysqlrc |
9200ad
|
456 |
$configfile = 'authmysqlrc'; |
09e141
|
457 |
if(is_file("$config_dir/$configfile")){ |
P |
458 |
copy("$config_dir/$configfile", "$config_dir/$configfile~"); |
|
459 |
} |
|
460 |
exec("chmod 400 $config_dir/$configfile~"); |
|
461 |
$content = rf("tpl/$configfile.master"); |
cd972d
|
462 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
T |
463 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
464 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content); |
|
465 |
$content = str_replace('{mysql_server_host}',$conf['mysql']['host'],$content); |
09e141
|
466 |
wf("$config_dir/$configfile", $content); |
9200ad
|
467 |
|
09e141
|
468 |
exec("chmod 660 $config_dir/$configfile"); |
P |
469 |
exec("chown daemon:daemon $config_dir/$configfile"); |
20e642
|
470 |
|
09e141
|
471 |
//* authdaemonrc |
cd972d
|
472 |
$configfile = $conf['courier']['config_dir'].'/authdaemonrc'; |
09e141
|
473 |
if(is_file($configfile)){ |
P |
474 |
copy($configfile, $configfile.'~'); |
|
475 |
} |
|
476 |
if(is_file($configfile.'~')){ |
|
477 |
exec('chmod 400 '.$configfile.'~'); |
|
478 |
} |
20e642
|
479 |
$content = rf($configfile); |
09e141
|
480 |
$content = str_replace('authmodulelist="authpam"', 'authmodulelist="authmysql"', $content); |
P |
481 |
wf($configfile, $content); |
9200ad
|
482 |
} |
T |
483 |
|
7d89f5
|
484 |
public function configure_amavis() { |
9200ad
|
485 |
global $conf; |
T |
486 |
|
|
487 |
// amavisd user config file |
|
488 |
$configfile = 'amavisd_user_config'; |
cc3fb3
|
489 |
if(is_file($conf["amavis"]["config_dir"].'/conf.d/50-user')) copy($conf["amavis"]["config_dir"].'/conf.d/50-user',$conf["courier"]["config_dir"].'/50-user~'); |
O |
490 |
if(is_file($conf["amavis"]["config_dir"].'/conf.d/50-user~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/conf.d/50-user~'); |
9200ad
|
491 |
$content = rf("tpl/".$configfile.".master"); |
cd972d
|
492 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
T |
493 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
494 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content); |
20218c
|
495 |
$content = str_replace('{mysql_server_port}',$conf["mysql"]["port"],$content); |
cd972d
|
496 |
$content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content); |
cc3fb3
|
497 |
wf($conf["amavis"]["config_dir"].'/conf.d/50-user',$content); |
9200ad
|
498 |
|
T |
499 |
// TODO: chmod and chown on the config file |
|
500 |
|
|
501 |
|
|
502 |
// Adding the amavisd commands to the postfix configuration |
|
503 |
$postconf_commands = array ( |
|
504 |
'content_filter = amavis:[127.0.0.1]:10024', |
|
505 |
'receive_override_options = no_address_mappings' |
|
506 |
); |
|
507 |
|
|
508 |
// Make a backup copy of the main.cf file |
cc3fb3
|
509 |
copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~2'); |
9200ad
|
510 |
|
T |
511 |
// Executing the postconf commands |
|
512 |
foreach($postconf_commands as $cmd) { |
|
513 |
$command = "postconf -e '$cmd'"; |
76b6b6
|
514 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
515 |
} |
T |
516 |
|
|
517 |
// Append the configuration for amavisd to the master.cf file |
cc3fb3
|
518 |
if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf',$conf["postfix"]["config_dir"].'/master.cf~'); |
7d89f5
|
519 |
$content = rf($conf["postfix"]["config_dir"].'/master.cf'); |
9200ad
|
520 |
// Only add the content if we had not addded it before |
4d4495
|
521 |
if(!stristr($content,"127.0.0.1:10025")) { |
7d89f5
|
522 |
unset($content); |
T |
523 |
$content = rf("tpl/master_cf_amavis.master"); |
cc3fb3
|
524 |
af($conf["postfix"]["config_dir"].'/master.cf',$content); |
9200ad
|
525 |
} |
7d89f5
|
526 |
unset($content); |
9200ad
|
527 |
|
T |
528 |
// Add the clamav user to the amavis group |
|
529 |
exec('adduser clamav amavis'); |
|
530 |
|
|
531 |
|
|
532 |
} |
|
533 |
|
77ab0a
|
534 |
public function configure_spamassassin() |
P |
535 |
{ |
cd972d
|
536 |
global $conf; |
T |
537 |
|
09e141
|
538 |
//* Enable spamasasssin on debian and ubuntu |
9200ad
|
539 |
$configfile = '/etc/default/spamassassin'; |
77ab0a
|
540 |
if(is_file($configfile)){ |
09e141
|
541 |
copy($configfile, $configfile.'~'); |
77ab0a
|
542 |
} |
9200ad
|
543 |
$content = rf($configfile); |
77ab0a
|
544 |
$content = str_replace('ENABLED=0', 'ENABLED=1', $content); |
P |
545 |
wf($configfile, $content); |
9200ad
|
546 |
} |
T |
547 |
|
09e141
|
548 |
public function configure_getmail() |
P |
549 |
{ |
af5c9b
|
550 |
global $conf; |
T |
551 |
|
cd972d
|
552 |
$config_dir = $conf['getmail']['config_dir']; |
03ade5
|
553 |
|
T |
554 |
if(!is_dir($config_dir)) exec("mkdir -p ".escapeshellcmd($config_dir)); |
09e141
|
555 |
|
P |
556 |
$command = "useradd -d $config_dir getmail"; |
|
557 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
ba747c
|
558 |
|
09e141
|
559 |
$command = "chown -R getmail $config_dir"; |
P |
560 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
3edf9d
|
561 |
|
09e141
|
562 |
$command = "chmod -R 700 $config_dir"; |
P |
563 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
ba747c
|
564 |
} |
T |
565 |
|
9200ad
|
566 |
|
09e141
|
567 |
public function configure_pureftpd() |
P |
568 |
{ |
7bd4b4
|
569 |
global $conf; |
T |
570 |
|
cd972d
|
571 |
$config_dir = $conf['pureftpd']['config_dir']; |
09e141
|
572 |
|
P |
573 |
//* configure pam for SMTP authentication agains the ispconfig database |
20218c
|
574 |
$configfile = 'db/mysql.conf'; |
09e141
|
575 |
if(is_file("$config_dir/$configfile")){ |
P |
576 |
copy("$config_dir/$configfile", "$config_dir/$configfile~"); |
|
577 |
} |
|
578 |
if(is_file("$config_dir/$configfile~")){ |
|
579 |
exec("chmod 400 $config_dir/$configfile~"); |
|
580 |
} |
|
581 |
$content = rf('tpl/pureftpd_mysql.conf.master'); |
7bd4b4
|
582 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf["mysql"]["ispconfig_user"], $content); |
T |
583 |
$content = str_replace('{mysql_server_ispconfig_password}', $conf["mysql"]["ispconfig_password"], $content); |
|
584 |
$content = str_replace('{mysql_server_database}', $conf["mysql"]["database"], $content); |
|
585 |
$content = str_replace('{mysql_server_ip}', $conf["mysql"]["ip"], $content); |
|
586 |
$content = str_replace('{server_id}', $conf["server_id"], $content); |
09e141
|
587 |
wf("$config_dir/$configfile", $content); |
P |
588 |
exec("chmod 600 $config_dir/$configfile"); |
|
589 |
exec("chown root:root $config_dir/$configfile"); |
|
590 |
// **enable chrooting |
af8f1b
|
591 |
//exec('mkdir -p '.$config_dir.'/conf/ChrootEveryone'); |
09e141
|
592 |
exec('echo "yes" > '.$config_dir.'/conf/ChrootEveryone'); |
b4c750
|
593 |
} |
T |
594 |
|
09e141
|
595 |
public function configure_mydns() |
P |
596 |
{ |
99d85e
|
597 |
global $conf; |
T |
598 |
|
|
599 |
// configure pam for SMTP authentication agains the ispconfig database |
|
600 |
$configfile = 'mydns.conf'; |
cc3fb3
|
601 |
if(is_file($conf["mydns"]["config_dir"].'/'.$configfile)) copy($conf["mydns"]["config_dir"].'/'.$configfile,$conf["mydns"]["config_dir"].'/'.$configfile.'~'); |
O |
602 |
if(is_file($conf["mydns"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["mydns"]["config_dir"].'/'.$configfile.'~'); |
99d85e
|
603 |
$content = rf("tpl/".$configfile.".master"); |
7bd4b4
|
604 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
T |
605 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
606 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content); |
20218c
|
607 |
$content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content); |
99d85e
|
608 |
$content = str_replace('{server_id}',$conf["server_id"],$content); |
cc3fb3
|
609 |
wf($conf["mydns"]["config_dir"].'/'.$configfile,$content); |
O |
610 |
exec('chmod 600 '.$conf["mydns"]["config_dir"].'/'.$configfile); |
|
611 |
exec('chown root:root '.$conf["mydns"]["config_dir"].'/'.$configfile); |
99d85e
|
612 |
|
T |
613 |
} |
|
614 |
|
76b6b6
|
615 |
public function configure_apache() |
P |
616 |
{ |
af5c9b
|
617 |
global $conf; |
T |
618 |
|
76b6b6
|
619 |
//* Create the logging directory for the vhost logfiles |
P |
620 |
exec('mkdir -p /var/log/ispconfig/httpd'); |
313e33
|
621 |
|
871b33
|
622 |
if(is_file('/etc/suphp/suphp.conf')) { |
20aa6b
|
623 |
replaceLine('/etc/suphp/suphp.conf','php=php:/usr/bin','x-httpd-suphp=php:/usr/bin/php-cgi',0); |
871b33
|
624 |
replaceLine('/etc/suphp/suphp.conf','docroot=','docroot=/var/clients',0); |
T |
625 |
} |
|
626 |
|
313e33
|
627 |
} |
T |
628 |
|
7c99ef
|
629 |
public function configure_firewall() |
T |
630 |
{ |
|
631 |
global $conf; |
|
632 |
|
|
633 |
$dist_init_scripts = $conf['init_scripts']; |
|
634 |
|
af5c9b
|
635 |
if(is_dir("/etc/Bastille.backup")) caselog("rm -rf /etc/Bastille.backup", __FILE__, __LINE__); |
dce071
|
636 |
if(is_dir("/etc/Bastille")) caselog("mv -f /etc/Bastille /etc/Bastille.backup", __FILE__, __LINE__); |
7c99ef
|
637 |
@mkdir("/etc/Bastille", octdec($directory_mode)); |
dce071
|
638 |
if(is_dir("/etc/Bastille.backup/firewall.d")) caselog("cp -pfr /etc/Bastille.backup/firewall.d /etc/Bastille/", __FILE__, __LINE__); |
T |
639 |
caselog("cp -f tpl/bastille-firewall.cfg.master /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__); |
|
640 |
caselog("chmod 644 /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__); |
7c99ef
|
641 |
$content = rf("/etc/Bastille/bastille-firewall.cfg"); |
T |
642 |
$content = str_replace("{DNS_SERVERS}", "", $content); |
|
643 |
|
|
644 |
$tcp_public_services = ''; |
|
645 |
$udp_public_services = ''; |
|
646 |
|
cd972d
|
647 |
$row = $this->db->queryOneRecord("SELECT * FROM firewall WHERE server_id = ".intval($conf['server_id'])); |
7c99ef
|
648 |
|
T |
649 |
if(trim($row["tcp_port"]) != '' || trim($row["udp_port"]) != ''){ |
|
650 |
$tcp_public_services = trim(str_replace(',',' ',$row["tcp_port"])); |
|
651 |
$udp_public_services = trim(str_replace(',',' ',$row["udp_port"])); |
|
652 |
} else { |
|
653 |
$tcp_public_services = '21 22 25 53 80 110 443 8080 10000'; |
|
654 |
$udp_public_services = '53'; |
|
655 |
} |
|
656 |
$content = str_replace("{TCP_PUBLIC_SERVICES}", $tcp_public_services, $content); |
|
657 |
$content = str_replace("{UDP_PUBLIC_SERVICES}", $udp_public_services, $content); |
|
658 |
|
|
659 |
wf("/etc/Bastille/bastille-firewall.cfg", $content); |
|
660 |
|
6912b2
|
661 |
if(is_file($dist_init_scripts."/bastille-firewall")) caselog("mv -f $dist_init_scripts/bastille-firewall $dist_init_scripts/bastille-firewall.backup", __FILE__, __LINE__); |
dce071
|
662 |
caselog("cp -f apps/bastille-firewall $dist_init_scripts", __FILE__, __LINE__); |
T |
663 |
caselog("chmod 700 $dist_init_scripts/bastille-firewall", __FILE__, __LINE__); |
7c99ef
|
664 |
|
dce071
|
665 |
if(is_file("/sbin/bastille-ipchains")) caselog("mv -f /sbin/bastille-ipchains /sbin/bastille-ipchains.backup", __FILE__, __LINE__); |
T |
666 |
caselog("cp -f apps/bastille-ipchains /sbin", __FILE__, __LINE__); |
|
667 |
caselog("chmod 700 /sbin/bastille-ipchains", __FILE__, __LINE__); |
7c99ef
|
668 |
|
dce071
|
669 |
if(is_file("/sbin/bastille-netfilter")) caselog("mv -f /sbin/bastille-netfilter /sbin/bastille-netfilter.backup", __FILE__, __LINE__); |
T |
670 |
caselog("cp -f apps/bastille-netfilter /sbin", __FILE__, __LINE__); |
|
671 |
caselog("chmod 700 /sbin/bastille-netfilter", __FILE__, __LINE__); |
|
672 |
|
|
673 |
if(!@is_dir('/var/lock/subsys')) caselog("mkdir /var/lock/subsys", __FILE__, __LINE__); |
7c99ef
|
674 |
|
T |
675 |
exec("which ipchains &> /dev/null", $ipchains_location, $ret_val); |
dce071
|
676 |
if(!is_file("/sbin/ipchains") && !is_link("/sbin/ipchains") && $ret_val == 0) phpcaselog(@symlink(shell_exec("which ipchains"), "/sbin/ipchains"), 'create symlink', __FILE__, __LINE__); |
7c99ef
|
677 |
unset($ipchains_location); |
T |
678 |
exec("which iptables &> /dev/null", $iptables_location, $ret_val); |
dce071
|
679 |
if(!is_file("/sbin/iptables") && !is_link("/sbin/iptables") && $ret_val == 0) phpcaselog(@symlink(trim(shell_exec("which iptables")), "/sbin/iptables"), 'create symlink', __FILE__, __LINE__); |
7c99ef
|
680 |
unset($iptables_location); |
T |
681 |
|
|
682 |
} |
|
683 |
|
b4c750
|
684 |
|
76b6b6
|
685 |
public function install_ispconfig() |
P |
686 |
{ |
7bd4b4
|
687 |
global $conf; |
T |
688 |
|
cd972d
|
689 |
$install_dir = $conf['ispconfig_install_dir']; |
9200ad
|
690 |
|
76b6b6
|
691 |
//* Create the ISPConfig installation directory |
613744
|
692 |
if(!@is_dir("$install_dir")) { |
88d899
|
693 |
$command = "mkdir $install_dir"; |
T |
694 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
695 |
} |
9200ad
|
696 |
|
76b6b6
|
697 |
//* Create a ISPConfig user and group |
P |
698 |
$command = 'groupadd ispconfig'; |
b73329
|
699 |
if(!is_group('vacp')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
76b6b6
|
700 |
|
P |
701 |
$command = "useradd -g ispconfig -d $install_dir ispconfig"; |
b73329
|
702 |
if(!is_user('vacp')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
76b6b6
|
703 |
|
P |
704 |
//* copy the ISPConfig interface part |
|
705 |
$command = "cp -rf ../interface $install_dir"; |
|
706 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
707 |
|
|
708 |
//* copy the ISPConfig server part |
|
709 |
$command = "cp -rf ../server $install_dir"; |
|
710 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
711 |
|
|
712 |
//* Create a symlink, so ISPConfig is accessible via web |
b722a1
|
713 |
// Replaced by a separate vhost definition for port 8080 |
T |
714 |
// $command = "ln -s $install_dir/interface/web/ /var/www/ispconfig"; |
|
715 |
// caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
76b6b6
|
716 |
|
P |
717 |
//* Create the config file for ISPConfig interface |
|
718 |
$configfile = 'config.inc.php'; |
|
719 |
if(is_file($install_dir.'/interface/lib/'.$configfile)){ |
|
720 |
copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~"); |
|
721 |
} |
|
722 |
$content = rf("tpl/$configfile.master"); |
7bd4b4
|
723 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content); |
T |
724 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
725 |
$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
|
726 |
$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
fa7958
|
727 |
$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
76b6b6
|
728 |
wf("$install_dir/interface/lib/$configfile", $content); |
P |
729 |
|
|
730 |
//* Create the config file for ISPConfig server |
|
731 |
$configfile = 'config.inc.php'; |
|
732 |
if(is_file($install_dir.'/server/lib/'.$configfile)){ |
|
733 |
copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~"); |
|
734 |
} |
|
735 |
$content = rf("tpl/$configfile.master"); |
7bd4b4
|
736 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content); |
T |
737 |
$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content); |
|
738 |
$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
|
739 |
$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
|
740 |
$content = str_replace('{server_id}', $conf['server_id'], $content); |
614365
|
741 |
$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
76b6b6
|
742 |
wf("$install_dir/server/lib/$configfile", $content); |
P |
743 |
|
710f35
|
744 |
|
1b063e
|
745 |
//* Enable the server modules and plugins. |
T |
746 |
// TODO: Implement a selector which modules and plugins shall be enabled. |
|
747 |
$dir = $install_dir.'/server/mods-available/'; |
|
748 |
if (is_dir($dir)) { |
|
749 |
if ($dh = opendir($dir)) { |
|
750 |
while (($file = readdir($dh)) !== false) { |
|
751 |
if($file != '.' && $file != '..') { |
6a95c8
|
752 |
if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file); |
0d0cd9
|
753 |
if (strpos($file, '_core_module') !== false) { |
V |
754 |
if(!@is_link($install_dir.'/server/mods-core/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file); |
|
755 |
} |
1b063e
|
756 |
} |
T |
757 |
} |
|
758 |
closedir($dh); |
|
759 |
} |
|
760 |
} |
|
761 |
|
|
762 |
$dir = $install_dir.'/server/plugins-available/'; |
|
763 |
if (is_dir($dir)) { |
|
764 |
if ($dh = opendir($dir)) { |
|
765 |
while (($file = readdir($dh)) !== false) { |
|
766 |
if($file != '.' && $file != '..') { |
6a95c8
|
767 |
if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file); |
0d0cd9
|
768 |
if (strpos($file, '_core_plugin') !== false) { |
V |
769 |
if(!@is_link($install_dir.'/server/plugins-core/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file); |
|
770 |
} |
1b063e
|
771 |
} |
T |
772 |
} |
|
773 |
closedir($dh); |
|
774 |
} |
|
775 |
} |
76b6b6
|
776 |
|
P |
777 |
//* Chmod the files |
|
778 |
$command = "chmod -R 750 $install_dir"; |
|
779 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
780 |
|
|
781 |
//* chown the files to the ispconfig user and group |
|
782 |
$command = "chown -R ispconfig:ispconfig $install_dir"; |
|
783 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
784 |
|
710f35
|
785 |
//* Make the global language file directory group writable |
f3e2f0
|
786 |
exec("chmod -R 770 $install_dir/interface/lib/lang"); |
710f35
|
787 |
|
1e2414
|
788 |
//* Make the temp directory for language file exports writable |
T |
789 |
exec("chmod -R 770 $install_dir/interface/web/temp"); |
|
790 |
|
710f35
|
791 |
//* Make all interface language file directories group writable |
T |
792 |
$handle = @opendir($install_dir.'/interface/web'); |
|
793 |
while ($file = @readdir ($handle)) { |
|
794 |
if ($file != '.' && $file != '..') { |
|
795 |
if(@is_dir($install_dir.'/interface/web'.'/'.$file.'/lib/lang')) { |
|
796 |
$handle2 = opendir($install_dir.'/interface/web'.'/'.$file.'/lib/lang'); |
f3e2f0
|
797 |
chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang',0770); |
710f35
|
798 |
while ($lang_file = @readdir ($handle2)) { |
T |
799 |
if ($lang_file != '.' && $lang_file != '..') { |
f3e2f0
|
800 |
chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang/'.$lang_file,0770); |
710f35
|
801 |
} |
T |
802 |
} |
|
803 |
} |
|
804 |
} |
|
805 |
} |
|
806 |
|
76b6b6
|
807 |
//* make sure that the server config file (not the interface one) is only readable by the root user |
P |
808 |
exec("chmod 600 $install_dir/server/lib/$configfile"); |
|
809 |
exec("chown root:root $install_dir/server/lib/$configfile"); |
7c99ef
|
810 |
if(@is_file("$install_dir/server/lib/mysql_clientdb.conf")) { |
a61345
|
811 |
exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf"); |
T |
812 |
exec("chown root:root $install_dir/server/lib/mysql_clientdb.conf"); |
|
813 |
} |
2e1086
|
814 |
|
9200ad
|
815 |
// TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing |
T |
816 |
// and must be fixed as this will allow the apache user to read the ispconfig files. |
|
817 |
// Later this must run as own apache server or via suexec! |
76b6b6
|
818 |
$command = 'adduser www-data ispconfig'; |
P |
819 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
820 |
|
76b6b6
|
821 |
//* Make the shell scripts executable |
P |
822 |
$command = "chmod +x $install_dir/server/scripts/*.sh"; |
|
823 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
824 |
|
76b6b6
|
825 |
//* Copy the ISPConfig vhost for the controlpanel |
1b063e
|
826 |
// TODO: These are missing! should they be "vhost_dist_*_dir" ? |
cd972d
|
827 |
$vhost_conf_dir = $conf['apache']['vhost_conf_dir']; |
T |
828 |
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir']; |
9b9ba4
|
829 |
|
D |
830 |
|
|
831 |
// Dont just copy over the virtualhost template but add some custom settings |
|
832 |
|
|
833 |
$content = rf("tpl/apache_ispconfig.vhost.master"); |
cd972d
|
834 |
$content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content); |
f6d745
|
835 |
|
T |
836 |
// comment out the listen directive if port is 80 or 443 |
|
837 |
if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) { |
|
838 |
$content = str_replace('{vhost_port_listen}', '#', $content); |
|
839 |
} else { |
|
840 |
$content = str_replace('{vhost_port_listen}', '', $content); |
|
841 |
} |
|
842 |
|
9b9ba4
|
843 |
wf("$vhost_conf_dir/ispconfig.vhost", $content); |
D |
844 |
|
|
845 |
//copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost"); |
76b6b6
|
846 |
//* and create the symlink |
ac4a37
|
847 |
if($this->install_ispconfig_interface == true) { |
0c78af
|
848 |
if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost"); |
3707cf
|
849 |
if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) { |
R |
850 |
exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost"); |
ac4a37
|
851 |
} |
a35764
|
852 |
} |
bc41bb
|
853 |
|
T |
854 |
// Make the Clamav log files readable by ISPConfig |
|
855 |
exec('chmod +r /var/log/clamav/clamav.log'); |
|
856 |
exec('chmod +r /var/log/clamav/freshclam.log'); |
83994b
|
857 |
|
T |
858 |
//* Install the SVN update script |
|
859 |
exec('cp ../helper_scripts/update_from_svn.sh /usr/local/bin/ispconfig_update_from_svn.sh'); |
|
860 |
exec('chown root /usr/local/bin/ispconfig_update_from_svn.sh'); |
|
861 |
exec('chmod 700 /usr/local/bin/ispconfig_update_from_svn.sh'); |
|
862 |
|
a014c2
|
863 |
//set the fast cgi starter script to executable |
D |
864 |
exec('chmod 755 '.$install_dir.'/interface/bin/php-fcgi'); |
3c5c2d
|
865 |
|
T |
866 |
//* Make the logs readable for the ispconfig user |
|
867 |
if(@is_file('/var/log/mail.log')) exec('chmod +r /var/log/mail.log'); |
|
868 |
if(@is_file('/var/log/mail.warn')) exec('chmod +r /var/log/mail.warn'); |
|
869 |
if(@is_file('/var/log/mail.err')) exec('chmod +r /var/log/mail.err'); |
|
870 |
if(@is_file('/var/log/messages')) exec('chmod +r /var/log/messages'); |
|
871 |
|
d9c8a7
|
872 |
//* Create the ispconfig log directory |
T |
873 |
if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig'); |
|
874 |
|
3c5c2d
|
875 |
|
9200ad
|
876 |
} |
T |
877 |
|
d83fcf
|
878 |
public function configure_dbserver() |
T |
879 |
{ |
|
880 |
global $conf; |
|
881 |
|
|
882 |
//* If this server shall act as database server for client DB's, we configure this here |
cd972d
|
883 |
$install_dir = $conf['ispconfig_install_dir']; |
d83fcf
|
884 |
|
T |
885 |
// Create a file with the database login details which |
|
886 |
// are used to create the client databases. |
|
887 |
|
|
888 |
if(!is_dir("$install_dir/server/lib")) { |
|
889 |
$command = "mkdir $install_dir/server/lib"; |
|
890 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
891 |
} |
|
892 |
|
|
893 |
$content = rf("tpl/mysql_clientdb.conf.master"); |
|
894 |
$content = str_replace('{username}',$conf['mysql']['admin_user'],$content); |
|
895 |
$content = str_replace('{password}',$conf['mysql']['admin_password'], $content); |
|
896 |
wf("$install_dir/server/lib/mysql_clientdb.conf",$content); |
|
897 |
exec('chmod 600 '."$install_dir/server/lib/mysql_clientdb.conf"); |
|
898 |
exec('chown root:root '."$install_dir/server/lib/mysql_clientdb.conf"); |
|
899 |
|
|
900 |
} |
|
901 |
|
76b6b6
|
902 |
public function install_crontab() |
5d54be
|
903 |
{ |
cd972d
|
904 |
global $conf; |
T |
905 |
|
5d54be
|
906 |
//* Root Crontab |
P |
907 |
exec('crontab -u root -l > crontab.txt'); |
daff5c
|
908 |
$existing_root_cron_jobs = file('crontab.txt'); |
T |
909 |
|
79bc50
|
910 |
// remove existing ispconfig cronjobs, in case the syntax has changed |
T |
911 |
foreach($existing_root_cron_jobs as $key => $val) { |
|
912 |
if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]); |
|
913 |
} |
|
914 |
|
30aa08
|
915 |
$root_cron_jobs = array( |
79bc50
|
916 |
'* * * * * /usr/local/ispconfig/server/server.sh > /dev/null', |
T |
917 |
'30 00 * * * /usr/local/ispconfig/server/cron_daily.sh > /dev/null' |
30aa08
|
918 |
); |
daff5c
|
919 |
foreach($root_cron_jobs as $cron_job) { |
5d54be
|
920 |
if(!in_array($cron_job."\n", $existing_root_cron_jobs)) { |
daff5c
|
921 |
$existing_root_cron_jobs[] = $cron_job."\n"; |
T |
922 |
} |
|
923 |
} |
5d54be
|
924 |
file_put_contents('crontab.txt', $existing_root_cron_jobs); |
P |
925 |
exec('crontab -u root crontab.txt &> /dev/null'); |
daff5c
|
926 |
unlink('crontab.txt'); |
T |
927 |
|
5d54be
|
928 |
//* Getmail crontab |
a8a328
|
929 |
if(is_user('getmail')) { |
T |
930 |
$cf = $conf['getmail']; |
|
931 |
exec('crontab -u getmail -l > crontab.txt'); |
|
932 |
$existing_cron_jobs = file('crontab.txt'); |
daff5c
|
933 |
|
a8a328
|
934 |
$cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf > /dev/null'); |
79bc50
|
935 |
|
a8a328
|
936 |
// remove existing ispconfig cronjobs, in case the syntax has changed |
T |
937 |
foreach($cron_jobs as $key => $val) { |
|
938 |
if(stristr($val,$cf['program'])) unset($cron_jobs[$key]); |
daff5c
|
939 |
} |
a8a328
|
940 |
|
T |
941 |
foreach($cron_jobs as $cron_job) { |
|
942 |
if(!in_array($cron_job."\n", $existing_cron_jobs)) { |
|
943 |
$existing_cron_jobs[] = $cron_job."\n"; |
|
944 |
} |
|
945 |
} |
|
946 |
file_put_contents('crontab.txt', $existing_cron_jobs); |
|
947 |
exec('crontab -u getmail crontab.txt &> /dev/null'); |
|
948 |
unlink('crontab.txt'); |
daff5c
|
949 |
} |
T |
950 |
} |
9200ad
|
951 |
|
T |
952 |
} |
|
953 |
|
5d54be
|
954 |
?> |