commit | author | age
|
7393e9
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
57659b
|
4 |
Copyright (c) 2007-2010, Till Brehm, projektfarm Gmbh |
7393e9
|
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_base { |
abdc67
|
32 |
|
7393e9
|
33 |
var $wb = array(); |
T |
34 |
var $language = 'en'; |
|
35 |
var $db; |
|
36 |
public $conf; |
|
37 |
public $install_ispconfig_interface = true; |
|
38 |
public $is_update = false; // true if it is an update, falsi if it is a new install |
|
39 |
|
|
40 |
|
abdc67
|
41 |
public function __construct() { |
V |
42 |
global $conf; //TODO: maybe $conf should be passed to constructor |
|
43 |
//$this->conf = $conf; |
|
44 |
} |
|
45 |
|
|
46 |
//: TODO Implement the translation function and language files for the installer. |
|
47 |
public function lng($text) { |
7393e9
|
48 |
return $text; |
T |
49 |
} |
abdc67
|
50 |
|
V |
51 |
public function error($msg) { |
7393e9
|
52 |
die("ERROR: ".$msg."\n"); |
T |
53 |
} |
abdc67
|
54 |
|
V |
55 |
public function simple_query($query, $answers, $default) { |
7393e9
|
56 |
$finished = false; |
T |
57 |
do { |
|
58 |
$answers_str = implode(',', $answers); |
|
59 |
swrite($this->lng($query).' ('.$answers_str.') ['.$default.']: '); |
|
60 |
$input = sread(); |
abdc67
|
61 |
|
7393e9
|
62 |
//* Stop the installation |
T |
63 |
if($input == 'quit') { |
|
64 |
swriteln($this->lng("Installation terminated by user.\n")); |
|
65 |
die(); |
|
66 |
} |
abdc67
|
67 |
|
7393e9
|
68 |
//* Select the default |
T |
69 |
if($input == '') { |
|
70 |
$answer = $default; |
|
71 |
$finished = true; |
|
72 |
} |
abdc67
|
73 |
|
V |
74 |
//* Set answer id valid |
7393e9
|
75 |
if(in_array($input, $answers)) { |
T |
76 |
$answer = $input; |
|
77 |
$finished = true; |
|
78 |
} |
abdc67
|
79 |
|
7393e9
|
80 |
} while ($finished == false); |
T |
81 |
swriteln(); |
|
82 |
return $answer; |
|
83 |
} |
abdc67
|
84 |
|
V |
85 |
public function free_query($query,$default) { |
7393e9
|
86 |
swrite($this->lng($query).' ['.$default.']: '); |
T |
87 |
$input = sread(); |
abdc67
|
88 |
|
7393e9
|
89 |
//* Stop the installation |
T |
90 |
if($input == 'quit') { |
abdc67
|
91 |
swriteln($this->lng("Installation terminated by user.\n")); |
V |
92 |
die(); |
7393e9
|
93 |
} |
abdc67
|
94 |
|
V |
95 |
$answer = ($input == '') ? $default : $input; |
7393e9
|
96 |
swriteln(); |
T |
97 |
return $answer; |
|
98 |
} |
abdc67
|
99 |
|
7393e9
|
100 |
/* |
T |
101 |
// TODO: this function is not used atmo I think - pedro |
|
102 |
function request_language(){ |
|
103 |
|
|
104 |
swriteln(lng('Enter your language')); |
|
105 |
swriteln(lng('de, en')); |
|
106 |
|
|
107 |
} |
|
108 |
*/ |
abdc67
|
109 |
|
7393e9
|
110 |
//** Detect installed applications |
T |
111 |
public function find_installed_apps() { |
|
112 |
global $conf; |
abdc67
|
113 |
|
7393e9
|
114 |
if(is_installed('mysql') || is_installed('mysqld')) $conf['mysql']['installed'] = true; |
T |
115 |
if(is_installed('postfix')) $conf['postfix']['installed'] = true; |
|
116 |
if(is_installed('apache') || is_installed('apache2') || is_installed('httpd')) $conf['apache']['installed'] = true; |
|
117 |
if(is_installed('getmail')) $conf['getmail']['installed'] = true; |
|
118 |
if(is_installed('couriertcpd')) $conf['courier']['installed'] = true; |
6cc49f
|
119 |
if(is_installed('dovecot')) $conf['dovecot']['installed'] = true; |
7393e9
|
120 |
if(is_installed('saslsauthd')) $conf['saslauthd']['installed'] = true; |
T |
121 |
if(is_installed('amavisd-new')) $conf['amavis']['installed'] = true; |
|
122 |
if(is_installed('clamdscan')) $conf['clamav']['installed'] = true; |
|
123 |
if(is_installed('pure-ftpd') || is_installed('pure-ftpd-wrapper')) $conf['pureftpd']['installed'] = true; |
|
124 |
if(is_installed('mydns') || is_installed('mydns-ng')) $conf['mydns']['installed'] = true; |
|
125 |
if(is_installed('jk_chrootsh')) $conf['jailkit']['installed'] = true; |
6ecbdc
|
126 |
if(is_installed('pdns_server') || is_installed('pdns_control')) $conf['powerdns']['installed'] = true; |
7dbea0
|
127 |
if(is_installed('named') || is_installed('bind') || is_installed('bind9')) $conf['bind']['installed'] = true; |
abdc67
|
128 |
|
7393e9
|
129 |
} |
abdc67
|
130 |
|
V |
131 |
/** Create the database for ISPConfig */ |
7393e9
|
132 |
public function configure_database() { |
T |
133 |
global $conf; |
abdc67
|
134 |
|
7393e9
|
135 |
//** Create the database |
T |
136 |
if(!$this->db->query('CREATE DATABASE IF NOT EXISTS '.$conf['mysql']['database'].' DEFAULT CHARACTER SET '.$conf['mysql']['charset'])) { |
|
137 |
$this->error('Unable to create MySQL database: '.$conf['mysql']['database'].'.'); |
|
138 |
} |
abdc67
|
139 |
|
7393e9
|
140 |
//* Set the database name in the DB library |
T |
141 |
$this->db->dbName = $conf['mysql']['database']; |
abdc67
|
142 |
|
7393e9
|
143 |
//* Load the database dump into the database, if database contains no tables |
T |
144 |
$db_tables = $this->db->getTables(); |
|
145 |
if(count($db_tables) > 0) { |
|
146 |
$this->error('Stopped: Database already contains some tables.'); |
|
147 |
} else { |
|
148 |
if($conf['mysql']['admin_password'] == '') { |
abdc67
|
149 |
caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' '".$conf['mysql']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", |
V |
150 |
__FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); |
7393e9
|
151 |
} else { |
57659b
|
152 |
caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' '".$conf['mysql']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", |
abdc67
|
153 |
__FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); |
7393e9
|
154 |
} |
T |
155 |
$db_tables = $this->db->getTables(); |
|
156 |
if(count($db_tables) == 0) { |
|
157 |
$this->error('Unable to load SQL-Dump into database table.'); |
|
158 |
} |
abdc67
|
159 |
|
7393e9
|
160 |
//* Load system.ini into the sys_ini table |
T |
161 |
$system_ini = $this->db->quote(rf('tpl/system.ini.master')); |
|
162 |
$this->db->query("UPDATE sys_ini SET config = '$system_ini' WHERE sysini_id = 1"); |
abdc67
|
163 |
|
7393e9
|
164 |
} |
T |
165 |
} |
abdc67
|
166 |
|
7393e9
|
167 |
//** Create the server record in the database |
T |
168 |
public function add_database_server_record() { |
abdc67
|
169 |
|
7393e9
|
170 |
global $conf; |
abdc67
|
171 |
|
7393e9
|
172 |
if($conf['mysql']['host'] == 'localhost') { |
T |
173 |
$from_host = 'localhost'; |
|
174 |
} else { |
|
175 |
$from_host = $conf['hostname']; |
|
176 |
} |
abdc67
|
177 |
|
7393e9
|
178 |
// Delete ISPConfig user in the local database, in case that it exists |
T |
179 |
$this->db->query("DELETE FROM mysql.user WHERE User = '".$conf['mysql']['ispconfig_user']."' AND Host = '".$from_host."';"); |
|
180 |
$this->db->query("DELETE FROM mysql.db WHERE Db = '".$conf['mysql']['database']."' AND Host = '".$from_host."';"); |
|
181 |
$this->db->query('FLUSH PRIVILEGES;'); |
abdc67
|
182 |
|
7393e9
|
183 |
//* Create the ISPConfig database user in the local database |
abdc67
|
184 |
$query = 'GRANT SELECT, INSERT, UPDATE, DELETE ON '.$conf['mysql']['database'].".* " |
V |
185 |
."TO '".$conf['mysql']['ispconfig_user']."'@'".$from_host."' " |
|
186 |
."IDENTIFIED BY '".$conf['mysql']['ispconfig_password']."';"; |
7393e9
|
187 |
if(!$this->db->query($query)) { |
T |
188 |
$this->error('Unable to create database user: '.$conf['mysql']['ispconfig_user'].' Error: '.$this->db->errorMessage); |
|
189 |
} |
abdc67
|
190 |
|
7393e9
|
191 |
//* Reload database privelages |
T |
192 |
$this->db->query('FLUSH PRIVILEGES;'); |
abdc67
|
193 |
|
7393e9
|
194 |
//* Set the database name in the DB library |
T |
195 |
$this->db->dbName = $conf['mysql']['database']; |
abdc67
|
196 |
|
7393e9
|
197 |
$tpl_ini_array = ini_to_array(rf('tpl/server.ini.master')); |
abdc67
|
198 |
|
3250e5
|
199 |
//* Update further distribution specific parameters for server config here |
T |
200 |
//* HINT: Every line added here has to be added in update.lib.php too!! |
7393e9
|
201 |
$tpl_ini_array['web']['vhost_conf_dir'] = $conf['apache']['vhost_conf_dir']; |
T |
202 |
$tpl_ini_array['web']['vhost_conf_enabled_dir'] = $conf['apache']['vhost_conf_enabled_dir']; |
|
203 |
$tpl_ini_array['jailkit']['jailkit_chroot_app_programs'] = $conf['jailkit']['jailkit_chroot_app_programs']; |
|
204 |
$tpl_ini_array['fastcgi']['fastcgi_phpini_path'] = $conf['fastcgi']['fastcgi_phpini_path']; |
|
205 |
$tpl_ini_array['fastcgi']['fastcgi_starter_path'] = $conf['fastcgi']['fastcgi_starter_path']; |
|
206 |
$tpl_ini_array['server']['hostname'] = $conf['hostname']; |
|
207 |
$tpl_ini_array['server']['ip_address'] = @gethostbyname($conf['hostname']); |
|
208 |
$tpl_ini_array['web']['website_basedir'] = $conf['web']['website_basedir']; |
|
209 |
$tpl_ini_array['web']['website_path'] = $conf['web']['website_path']; |
|
210 |
$tpl_ini_array['web']['website_symlinks'] = $conf['web']['website_symlinks']; |
abdc67
|
211 |
$tpl_ini_array['cron']['crontab_dir'] = $conf['cron']['crontab_dir']; |
6b029a
|
212 |
$tpl_ini_array['web']['security_level'] = 20; |
67c4b3
|
213 |
$tpl_ini_array['web']['user'] = $conf['apache']['user']; |
T |
214 |
$tpl_ini_array['web']['group'] = $conf['apache']['group']; |
e81bf9
|
215 |
$tpl_ini_array['web']['php_ini_path_apache'] = $conf['apache']['php_ini_path_apache']; |
T |
216 |
$tpl_ini_array['web']['php_ini_path_cgi'] = $conf['apache']['php_ini_path_cgi']; |
6cc49f
|
217 |
$tpl_ini_array['mail']['pop3_imap_daemon'] = ($conf['dovecot']['installed'] == true)?'dovecot':'courier'; |
T |
218 |
$tpl_ini_array['mail']['mail_filter_syntax'] = ($conf['dovecot']['installed'] == true)?'sieve':'maildrop'; |
fdb514
|
219 |
$tpl_ini_array['dns']['bind_user'] = $conf['bind']['bind_user']; |
T |
220 |
$tpl_ini_array['dns']['bind_group'] = $conf['bind']['bind_group']; |
|
221 |
$tpl_ini_array['dns']['bind_zonefiles_dir'] = $conf['bind']['bind_zonefiles_dir']; |
|
222 |
$tpl_ini_array['dns']['named_conf_path'] = $conf['bind']['named_conf_path']; |
|
223 |
$tpl_ini_array['dns']['named_conf_local_path'] = $conf['bind']['named_conf_local_path']; |
abdc67
|
224 |
|
7393e9
|
225 |
$server_ini_content = array_to_ini($tpl_ini_array); |
T |
226 |
$server_ini_content = mysql_real_escape_string($server_ini_content); |
abdc67
|
227 |
|
7393e9
|
228 |
$mail_server_enabled = ($conf['services']['mail'])?1:0; |
T |
229 |
$web_server_enabled = ($conf['services']['web'])?1:0; |
|
230 |
$dns_server_enabled = ($conf['services']['dns'])?1:0; |
|
231 |
$file_server_enabled = ($conf['services']['file'])?1:0; |
|
232 |
$db_server_enabled = ($conf['services']['db'])?1:0; |
|
233 |
$vserver_server_enabled = ($conf['services']['vserver'])?1:0; |
abdc67
|
234 |
|
V |
235 |
|
|
236 |
|
7393e9
|
237 |
if($conf['mysql']['master_slave_setup'] == 'y') { |
abdc67
|
238 |
|
7393e9
|
239 |
//* Insert the server record in master DB |
T |
240 |
$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']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1);"; |
|
241 |
$this->dbmaster->query($sql); |
|
242 |
$conf['server_id'] = $this->dbmaster->insertID(); |
|
243 |
$conf['server_id'] = $conf['server_id']; |
abdc67
|
244 |
|
7393e9
|
245 |
//* Insert the same record in the local DB |
T |
246 |
$sql = "INSERT INTO `server` (`server_id`, `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 ('".$conf['server_id']."',1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1);"; |
|
247 |
$this->db->query($sql); |
abdc67
|
248 |
|
7393e9
|
249 |
//* username for the ispconfig user |
T |
250 |
$conf['mysql']['master_ispconfig_user'] = 'ispcsrv'.$conf['server_id']; |
abdc67
|
251 |
|
V |
252 |
$this->grant_master_database_rights(); |
|
253 |
|
7393e9
|
254 |
} else { |
T |
255 |
//* Insert the server, if its not a mster / slave setup |
|
256 |
$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']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1);"; |
|
257 |
$this->db->query($sql); |
|
258 |
$conf['server_id'] = $this->db->insertID(); |
|
259 |
$conf['server_id'] = $conf['server_id']; |
|
260 |
} |
abdc67
|
261 |
|
V |
262 |
|
7393e9
|
263 |
} |
01d120
|
264 |
|
abdc67
|
265 |
public function grant_master_database_rights() { |
7393e9
|
266 |
global $conf; |
T |
267 |
|
465c9e
|
268 |
/* |
V |
269 |
* The following code is a little bit tricky: |
|
270 |
* * If we HAVE a master-slave - Setup then the client has to grant the rights for himself |
|
271 |
* at the master. |
|
272 |
* * If we DO NOT have a master-slave - Setup then we have two possibilities |
|
273 |
* 1) it is a single server |
|
274 |
* 2) it is the MASTER of n clients |
|
275 |
*/ |
|
276 |
if($conf['mysql']['master_slave_setup'] == 'y') { |
|
277 |
/* |
|
278 |
* it is a master-slave - Setup so the slave has to grant its rights in the master |
|
279 |
* database |
|
280 |
*/ |
abdc67
|
281 |
|
465c9e
|
282 |
//* insert the ispconfig user in the remote server |
V |
283 |
$from_host = $conf['hostname']; |
|
284 |
$from_ip = gethostbyname($conf['hostname']); |
|
285 |
|
|
286 |
$hosts[$from_host]['user'] = $conf['mysql']['master_ispconfig_user']; |
|
287 |
$hosts[$from_host]['db'] = $conf['mysql']['master_database']; |
39c5d8
|
288 |
$hosts[$from_host]['pwd'] = $conf['mysql']['master_ispconfig_password']; |
abdc67
|
289 |
|
465c9e
|
290 |
$hosts[$from_ip]['user'] = $conf['mysql']['master_ispconfig_user']; |
V |
291 |
$hosts[$from_ip]['db'] = $conf['mysql']['master_database']; |
39c5d8
|
292 |
$hosts[$from_ip]['pwd'] = $conf['mysql']['master_ispconfig_password']; |
465c9e
|
293 |
} else{ |
V |
294 |
/* |
|
295 |
* it is NOT a master-slave - Setup so we have to find out all clients and their |
|
296 |
* host |
|
297 |
*/ |
|
298 |
$query = "SELECT Host, User FROM mysql.user WHERE User like 'ispcsrv%' ORDER BY User, Host"; |
|
299 |
$data = $this->dbmaster->queryAllRecords($query); |
|
300 |
if($data === false) { |
|
301 |
$this->error('Unable to get the user rights: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
abdc67
|
302 |
} |
465c9e
|
303 |
foreach ($data as $item){ |
V |
304 |
$hosts[$item['Host']]['user'] = $item['User']; |
|
305 |
$hosts[$item['Host']]['db'] = $conf['mysql']['master_database']; |
39c5d8
|
306 |
$hosts[$item['Host']]['pwd'] = ''; // the user already exists, so we need no pwd! |
abdc67
|
307 |
} |
V |
308 |
} |
2e9612
|
309 |
|
T |
310 |
if(is_array($hosts)) { |
465c9e
|
311 |
foreach($hosts as $host => $value) { |
V |
312 |
/* |
39c5d8
|
313 |
* If a pwd exists, this means, we have to add the new user (and his pwd). |
V |
314 |
* if not, the user already exists and we do not need the pwd |
|
315 |
*/ |
|
316 |
if ($value['pwd'] != ''){ |
|
317 |
$query = "CREATE USER '".$value['user']."'@'".$host."' IDENTIFIED BY '" . $value['pwd'] . "'"; |
|
318 |
$this->dbmaster->query($query); // ignore the error |
|
319 |
} |
|
320 |
|
|
321 |
/* |
|
322 |
* Try to delete all rights of the user in case that it exists. |
|
323 |
* In Case that it will not exist, do nothing (ignore the error!) |
465c9e
|
324 |
*/ |
V |
325 |
$query = "REVOKE ALL PRIVILEGES, GRANT OPTION FROM '".$value['user']."'@'".$host."' "; |
39c5d8
|
326 |
$this->dbmaster->query($query); // ignore the error |
465c9e
|
327 |
|
V |
328 |
//* Create the ISPConfig database user in the remote database |
|
329 |
$query = "GRANT SELECT ON ".$value['db'].".`server` TO '".$value['user']."'@'".$host."' "; |
|
330 |
if(!$this->dbmaster->query($query)) { |
|
331 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
332 |
} |
|
333 |
|
|
334 |
$query = "GRANT SELECT, INSERT ON ".$value['db'].".`sys_log` TO '".$value['user']."'@'".$host."' "; |
|
335 |
if(!$this->dbmaster->query($query)) { |
|
336 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
337 |
} |
|
338 |
|
|
339 |
$query = "GRANT SELECT, UPDATE(`status`) ON ".$value['db'].".`sys_datalog` TO '".$value['user']."'@'".$host."' "; |
|
340 |
if(!$this->dbmaster->query($query)) { |
|
341 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
342 |
} |
|
343 |
|
|
344 |
$query = "GRANT SELECT, UPDATE(`status`) ON ".$value['db'].".`software_update_inst` TO '".$value['user']."'@'".$host."' "; |
|
345 |
if(!$this->dbmaster->query($query)) { |
|
346 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
347 |
} |
|
348 |
|
|
349 |
$query = "GRANT SELECT, UPDATE(`updated`) ON ".$value['db'].".`server` TO '".$value['user']."'@'".$host."' "; |
|
350 |
if(!$this->dbmaster->query($query)) { |
|
351 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
352 |
} |
|
353 |
|
|
354 |
$query = "GRANT SELECT, UPDATE (`ssl_request`, `ssl_cert`, `ssl_action`) ON ".$value['db'].".`web_domain` TO '".$value['user']."'@'".$host."' "; |
|
355 |
if(!$this->dbmaster->query($query)) { |
|
356 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
357 |
} |
|
358 |
|
|
359 |
$query = "GRANT SELECT ON ".$value['db'].".`sys_group` TO '".$value['user']."'@'".$host."' "; |
|
360 |
if(!$this->dbmaster->query($query)) { |
|
361 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
362 |
} |
|
363 |
|
|
364 |
$query = "GRANT SELECT, UPDATE (`action_state`, `response`) ON ".$value['db'].".`sys_remoteaction` TO '".$value['user']."'@'".$host."' "; |
|
365 |
if(!$this->dbmaster->query($query)) { |
|
366 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
367 |
} |
|
368 |
|
|
369 |
$query = "GRANT SELECT, INSERT , DELETE ON ".$value['db'].".`monitor_data` TO '".$value['user']."'@'".$host."' "; |
|
370 |
if(!$this->dbmaster->query($query)) { |
|
371 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
372 |
} |
|
373 |
|
|
374 |
$query = "GRANT SELECT, INSERT, UPDATE ON ".$value['db'].".`mail_traffic` TO '".$value['user']."'@'".$host."' "; |
|
375 |
if(!$this->dbmaster->query($query)) { |
|
376 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
377 |
} |
|
378 |
|
|
379 |
$query = "GRANT SELECT, INSERT, UPDATE ON ".$value['db'].".`web_traffic` TO '".$value['user']."'@'".$host."' "; |
|
380 |
if(!$this->dbmaster->query($query)) { |
|
381 |
$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage); |
|
382 |
} |
|
383 |
} |
|
384 |
|
|
385 |
/* |
|
386 |
* It is all done. Relod the rights... |
|
387 |
*/ |
|
388 |
$this->dbmaster->query('FLUSH PRIVILEGES;'); |
2e9612
|
389 |
} |
465c9e
|
390 |
|
abdc67
|
391 |
} |
V |
392 |
|
|
393 |
//** writes postfix configuration files |
|
394 |
public function process_postfix_config($configfile) { |
|
395 |
global $conf; |
|
396 |
|
|
397 |
$config_dir = $conf['postfix']['config_dir'].'/'; |
|
398 |
$full_file_name = $config_dir.$configfile; |
|
399 |
//* Backup exiting file |
|
400 |
if(is_file($full_file_name)) { |
|
401 |
copy($full_file_name, $config_dir.$configfile.'~'); |
|
402 |
} |
|
403 |
$content = rf('tpl/'.$configfile.'.master'); |
|
404 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content); |
|
405 |
$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content); |
|
406 |
$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
|
407 |
$content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content); |
|
408 |
$content = str_replace('{server_id}', $conf['server_id'], $content); |
|
409 |
wf($full_file_name, $content); |
|
410 |
} |
|
411 |
|
|
412 |
public function configure_jailkit() { |
|
413 |
global $conf; |
|
414 |
|
7393e9
|
415 |
$cf = $conf['jailkit']; |
T |
416 |
$config_dir = $cf['config_dir']; |
|
417 |
$jk_init = $cf['jk_init']; |
|
418 |
$jk_chrootsh = $cf['jk_chrootsh']; |
abdc67
|
419 |
|
V |
420 |
if (is_dir($config_dir)) { |
7393e9
|
421 |
if(is_file($config_dir.'/'.$jk_init)) copy($config_dir.'/'.$jk_init, $config_dir.'/'.$jk_init.'~'); |
T |
422 |
if(is_file($config_dir.'/'.$jk_chrootsh.".master")) copy($config_dir.'/'.$jk_chrootsh.".master", $config_dir.'/'.$jk_chrootsh.'~'); |
abdc67
|
423 |
|
7393e9
|
424 |
copy('tpl/'.$jk_init.".master", $config_dir.'/'.$jk_init); |
T |
425 |
copy('tpl/'.$jk_chrootsh.".master", $config_dir.'/'.$jk_chrootsh); |
|
426 |
} |
abdc67
|
427 |
|
V |
428 |
} |
|
429 |
|
|
430 |
public function configure_postfix($options = '') { |
|
431 |
global $conf; |
7393e9
|
432 |
$cf = $conf['postfix']; |
T |
433 |
$config_dir = $cf['config_dir']; |
abdc67
|
434 |
|
V |
435 |
if(!is_dir($config_dir)) { |
|
436 |
$this->error("The postfix configuration directory '$config_dir' does not exist."); |
|
437 |
} |
|
438 |
|
7393e9
|
439 |
//* mysql-virtual_domains.cf |
abdc67
|
440 |
$this->process_postfix_config('mysql-virtual_domains.cf'); |
7393e9
|
441 |
|
T |
442 |
//* mysql-virtual_forwardings.cf |
abdc67
|
443 |
$this->process_postfix_config('mysql-virtual_forwardings.cf'); |
7393e9
|
444 |
|
T |
445 |
//* mysql-virtual_mailboxes.cf |
abdc67
|
446 |
$this->process_postfix_config('mysql-virtual_mailboxes.cf'); |
7393e9
|
447 |
|
T |
448 |
//* mysql-virtual_email2email.cf |
abdc67
|
449 |
$this->process_postfix_config('mysql-virtual_email2email.cf'); |
7393e9
|
450 |
|
T |
451 |
//* mysql-virtual_transports.cf |
abdc67
|
452 |
$this->process_postfix_config('mysql-virtual_transports.cf'); |
7393e9
|
453 |
|
T |
454 |
//* mysql-virtual_recipient.cf |
abdc67
|
455 |
$this->process_postfix_config('mysql-virtual_recipient.cf'); |
7393e9
|
456 |
|
T |
457 |
//* mysql-virtual_sender.cf |
abdc67
|
458 |
$this->process_postfix_config('mysql-virtual_sender.cf'); |
7393e9
|
459 |
|
T |
460 |
//* mysql-virtual_client.cf |
abdc67
|
461 |
$this->process_postfix_config('mysql-virtual_client.cf'); |
V |
462 |
|
7393e9
|
463 |
//* mysql-virtual_relaydomains.cf |
abdc67
|
464 |
$this->process_postfix_config('mysql-virtual_relaydomains.cf'); |
V |
465 |
|
429dcf
|
466 |
//* mysql-virtual_relayrecipientmaps.cf |
abdc67
|
467 |
$this->process_postfix_config('mysql-virtual_relayrecipientmaps.cf'); |
7393e9
|
468 |
|
T |
469 |
//* Changing mode and group of the new created config files. |
|
470 |
caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', |
abdc67
|
471 |
__FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed'); |
V |
472 |
caselog('chgrp '.$cf['group'].' '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', |
|
473 |
__FILE__, __LINE__, 'chgrp on mysql-virtual_*.cf*', 'chgrp on mysql-virtual_*.cf* failed'); |
|
474 |
|
7393e9
|
475 |
//* Creating virtual mail user and group |
T |
476 |
$command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname']; |
|
477 |
if(!is_group($cf['vmail_groupname'])) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
478 |
|
|
479 |
$command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m'; |
abdc67
|
480 |
if(!is_user($cf['vmail_username'])) caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
7393e9
|
481 |
|
T |
482 |
$postconf_commands = array ( |
abdc67
|
483 |
'myhostname = '.$conf['hostname'], |
V |
484 |
'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain', |
|
485 |
'mynetworks = 127.0.0.0/8 [::1]/128', |
|
486 |
'virtual_alias_domains =', |
|
487 |
'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf', |
|
488 |
'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf', |
|
489 |
'virtual_mailbox_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailboxes.cf', |
|
490 |
'virtual_mailbox_base = '.$cf['vmail_mailbox_base'], |
|
491 |
'virtual_uid_maps = static:'.$cf['vmail_userid'], |
|
492 |
'virtual_gid_maps = static:'.$cf['vmail_groupid'], |
|
493 |
'smtpd_sasl_auth_enable = yes', |
|
494 |
'broken_sasl_auth_clients = yes', |
|
495 |
'smtpd_sasl_authenticated_header = yes', |
|
496 |
'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:'.$config_dir.'/mysql-virtual_recipient.cf, reject_unauth_destination', |
|
497 |
'smtpd_use_tls = yes', |
|
498 |
'smtpd_tls_security_level = may', |
|
499 |
'smtpd_tls_cert_file = '.$config_dir.'/smtpd.cert', |
|
500 |
'smtpd_tls_key_file = '.$config_dir.'/smtpd.key', |
|
501 |
'transport_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_transports.cf', |
|
502 |
'relay_domains = mysql:'.$config_dir.'/mysql-virtual_relaydomains.cf', |
|
503 |
'relay_recipient_maps = mysql:'.$config_dir.'/mysql-virtual_relayrecipientmaps.cf', |
|
504 |
'virtual_create_maildirsize = yes', |
|
505 |
'virtual_maildir_extended = yes', |
|
506 |
'virtual_mailbox_limit_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailbox_limit_maps.cf', |
|
507 |
'virtual_mailbox_limit_override = yes', |
|
508 |
'virtual_maildir_limit_message = "The user you are trying to reach is over quota."', |
|
509 |
'virtual_overquota_bounce = yes', |
|
510 |
'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', |
|
511 |
'smtpd_sender_restrictions = check_sender_access mysql:'.$config_dir.'/mysql-virtual_sender.cf', |
|
512 |
'smtpd_client_restrictions = check_client_access mysql:'.$config_dir.'/mysql-virtual_client.cf', |
|
513 |
'maildrop_destination_concurrency_limit = 1', |
|
514 |
'maildrop_destination_recipient_limit = 1', |
|
515 |
'virtual_transport = maildrop', |
|
516 |
'header_checks = regexp:'.$config_dir.'/header_checks', |
|
517 |
'mime_header_checks = regexp:'.$config_dir.'/mime_header_checks', |
|
518 |
'nested_header_checks = regexp:'.$config_dir.'/nested_header_checks', |
|
519 |
'body_checks = regexp:'.$config_dir.'/body_checks' |
7393e9
|
520 |
); |
abdc67
|
521 |
|
7393e9
|
522 |
//* Create the header and body check files |
T |
523 |
touch($config_dir.'/header_checks'); |
|
524 |
touch($config_dir.'/mime_header_checks'); |
|
525 |
touch($config_dir.'/nested_header_checks'); |
|
526 |
touch($config_dir.'/body_checks'); |
abdc67
|
527 |
|
V |
528 |
|
7393e9
|
529 |
//* Make a backup copy of the main.cf file |
T |
530 |
copy($config_dir.'/main.cf', $config_dir.'/main.cf~'); |
abdc67
|
531 |
|
7393e9
|
532 |
//* Executing the postconf commands |
T |
533 |
foreach($postconf_commands as $cmd) { |
|
534 |
$command = "postconf -e '$cmd'"; |
|
535 |
caselog($command." &> /dev/null", __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
|
536 |
} |
abdc67
|
537 |
|
7393e9
|
538 |
if(!stristr($options,'dont-create-certs')) { |
T |
539 |
//* Create the SSL certificate |
|
540 |
$command = 'cd '.$config_dir.'; ' |
abdc67
|
541 |
.'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509'; |
7393e9
|
542 |
exec($command); |
abdc67
|
543 |
|
7393e9
|
544 |
$command = 'chmod o= '.$config_dir.'/smtpd.key'; |
T |
545 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
|
546 |
} |
abdc67
|
547 |
|
7393e9
|
548 |
//** We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop. |
T |
549 |
$command = 'chmod 755 /var/run/courier/authdaemon/'; |
94927b
|
550 |
if(is_file('/var/run/courier/authdaemon/')) caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
abdc67
|
551 |
|
7393e9
|
552 |
//* Changing maildrop lines in posfix master.cf |
abdc67
|
553 |
if(is_file($config_dir.'/master.cf')) { |
V |
554 |
copy($config_dir.'/master.cf', $config_dir.'/master.cf~'); |
|
555 |
} |
|
556 |
if(is_file($config_dir.'/master.cf~')) { |
|
557 |
exec('chmod 400 '.$config_dir.'/master.cf~'); |
|
558 |
} |
7393e9
|
559 |
$configfile = $config_dir.'/master.cf'; |
T |
560 |
$content = rf($configfile); |
abdc67
|
561 |
$content = str_replace('flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}', |
V |
562 |
'flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d '.$cf['vmail_username'].' ${extension} ${recipient} ${user} ${nexthop} ${sender}', |
|
563 |
$content); |
7393e9
|
564 |
wf($configfile, $content); |
abdc67
|
565 |
|
7393e9
|
566 |
//* Writing the Maildrop mailfilter file |
T |
567 |
$configfile = 'mailfilter'; |
abdc67
|
568 |
if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)) { |
V |
569 |
copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~'); |
|
570 |
} |
7393e9
|
571 |
$content = rf("tpl/$configfile.master"); |
T |
572 |
$content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content); |
|
573 |
wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content); |
abdc67
|
574 |
|
7393e9
|
575 |
//* Create the directory for the custom mailfilters |
T |
576 |
if(!is_dir($cf['vmail_mailbox_base'].'/mailfilters')) { |
|
577 |
$command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters'; |
|
578 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
579 |
} |
abdc67
|
580 |
|
7393e9
|
581 |
//* Chmod and chown the .mailfilter file |
T |
582 |
$command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter'; |
|
583 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
584 |
|
7393e9
|
585 |
$command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter'; |
T |
586 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
587 |
|
7393e9
|
588 |
} |
abdc67
|
589 |
|
7393e9
|
590 |
public function configure_saslauthd() { |
T |
591 |
global $conf; |
abdc67
|
592 |
|
V |
593 |
|
7393e9
|
594 |
$configfile = 'sasl_smtpd.conf'; |
T |
595 |
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~'); |
|
596 |
if(is_file($conf["postfix"]["config_dir"].'/sasl/smtpd.conf~')) exec('chmod 400 '.$conf["postfix"]["config_dir"].'/sasl/smtpd.conf~'); |
|
597 |
$content = rf("tpl/".$configfile.".master"); |
|
598 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
|
599 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
600 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content); |
|
601 |
$content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content); |
|
602 |
wf($conf["postfix"]["config_dir"].'/sasl/smtpd.conf',$content); |
abdc67
|
603 |
|
7393e9
|
604 |
// TODO: Chmod and chown on the config file |
abdc67
|
605 |
|
V |
606 |
|
|
607 |
|
7393e9
|
608 |
// Create the spool directory |
T |
609 |
exec('mkdir -p /var/spool/postfix/var/run/saslauthd'); |
abdc67
|
610 |
|
7393e9
|
611 |
// Edit the file /etc/default/saslauthd |
T |
612 |
$configfile = $conf["saslauthd"]["config"]; |
|
613 |
if(is_file($configfile)) copy($configfile,$configfile.'~'); |
|
614 |
if(is_file($configfile.'~')) exec('chmod 400 '.$configfile.'~'); |
|
615 |
$content = rf($configfile); |
|
616 |
$content = str_replace('START=no','START=yes',$content); |
|
617 |
// Debian |
|
618 |
$content = str_replace('OPTIONS="-c"','OPTIONS="-m /var/spool/postfix/var/run/saslauthd -r"',$content); |
|
619 |
// Ubuntu |
|
620 |
$content = str_replace('OPTIONS="-c -m /var/run/saslauthd"','OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"',$content); |
|
621 |
wf($configfile,$content); |
abdc67
|
622 |
|
7393e9
|
623 |
// Edit the file /etc/init.d/saslauthd |
T |
624 |
$configfile = $conf["init_scripts"].'/'.$conf["saslauthd"]["init_script"]; |
|
625 |
$content = rf($configfile); |
|
626 |
$content = str_replace('PIDFILE=$RUN_DIR/saslauthd.pid','PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid"',$content); |
|
627 |
wf($configfile,$content); |
abdc67
|
628 |
|
7393e9
|
629 |
// add the postfix user to the sasl group (at least nescessary for ubuntu 8.04 and most likely debian lenny too. |
T |
630 |
exec('adduser postfix sasl'); |
abdc67
|
631 |
|
V |
632 |
|
7393e9
|
633 |
} |
abdc67
|
634 |
|
V |
635 |
public function configure_pam() { |
7393e9
|
636 |
global $conf; |
T |
637 |
$pam = $conf['pam']; |
|
638 |
//* configure pam for SMTP authentication agains the ispconfig database |
|
639 |
$configfile = 'pamd_smtp'; |
|
640 |
if(is_file("$pam/smtp")) copy("$pam/smtp", "$pam/smtp~"); |
|
641 |
if(is_file("$pam/smtp~")) exec("chmod 400 $pam/smtp~"); |
|
642 |
|
|
643 |
$content = rf("tpl/$configfile.master"); |
|
644 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content); |
|
645 |
$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content); |
|
646 |
$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
|
647 |
$content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content); |
|
648 |
wf("$pam/smtp", $content); |
3250e5
|
649 |
// On some OSes smtp is world readable which allows for reading database information. Removing world readable rights should have no effect. |
T |
650 |
if(is_file("$pam/smtp")) exec("chmod o= $pam/smtp"); |
7393e9
|
651 |
exec("chmod 660 $pam/smtp"); |
T |
652 |
exec("chown daemon:daemon $pam/smtp"); |
abdc67
|
653 |
|
7393e9
|
654 |
} |
abdc67
|
655 |
|
V |
656 |
public function configure_courier() { |
7393e9
|
657 |
global $conf; |
T |
658 |
$config_dir = $conf['courier']['config_dir']; |
|
659 |
//* authmysqlrc |
|
660 |
$configfile = 'authmysqlrc'; |
abdc67
|
661 |
if(is_file("$config_dir/$configfile")) { |
V |
662 |
copy("$config_dir/$configfile", "$config_dir/$configfile~"); |
|
663 |
} |
7393e9
|
664 |
exec("chmod 400 $config_dir/$configfile~"); |
T |
665 |
$content = rf("tpl/$configfile.master"); |
|
666 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
|
667 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
668 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content); |
|
669 |
$content = str_replace('{mysql_server_host}',$conf['mysql']['host'],$content); |
|
670 |
wf("$config_dir/$configfile", $content); |
abdc67
|
671 |
|
7393e9
|
672 |
exec("chmod 660 $config_dir/$configfile"); |
T |
673 |
exec("chown daemon:daemon $config_dir/$configfile"); |
abdc67
|
674 |
|
7393e9
|
675 |
//* authdaemonrc |
T |
676 |
$configfile = $conf['courier']['config_dir'].'/authdaemonrc'; |
abdc67
|
677 |
if(is_file($configfile)) { |
V |
678 |
copy($configfile, $configfile.'~'); |
|
679 |
} |
|
680 |
if(is_file($configfile.'~')) { |
|
681 |
exec('chmod 400 '.$configfile.'~'); |
|
682 |
} |
7393e9
|
683 |
$content = rf($configfile); |
T |
684 |
$content = str_replace('authmodulelist="authpam"', 'authmodulelist="authmysql"', $content); |
|
685 |
wf($configfile, $content); |
|
686 |
} |
abdc67
|
687 |
|
V |
688 |
public function configure_dovecot() { |
6cc49f
|
689 |
global $conf; |
abdc67
|
690 |
|
6cc49f
|
691 |
$config_dir = $conf['dovecot']['config_dir']; |
abdc67
|
692 |
|
6cc49f
|
693 |
//* Configure master.cf and add a line for deliver |
abdc67
|
694 |
if(is_file($config_dir.'/master.cf')) { |
V |
695 |
copy($config_dir.'/master.cf', $config_dir.'/master.cf~2'); |
|
696 |
} |
|
697 |
if(is_file($config_dir.'/master.cf~')) { |
|
698 |
exec('chmod 400 '.$config_dir.'/master.cf~2'); |
|
699 |
} |
6cc49f
|
700 |
$content = rf($conf["postfix"]["config_dir"].'/master.cf'); |
T |
701 |
// Only add the content if we had not addded it before |
|
702 |
if(!stristr($content,"dovecot/deliver")) { |
1d7941
|
703 |
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}'; |
6cc49f
|
704 |
af($conf["postfix"]["config_dir"].'/master.cf',$deliver_content); |
T |
705 |
} |
|
706 |
unset($content); |
|
707 |
unset($deliver_content); |
abdc67
|
708 |
|
V |
709 |
|
6cc49f
|
710 |
//* Reconfigure postfix to use dovecot authentication |
T |
711 |
// Adding the amavisd commands to the postfix configuration |
|
712 |
$postconf_commands = array ( |
abdc67
|
713 |
'dovecot_destination_recipient_limit = 1', |
V |
714 |
'virtual_transport = dovecot', |
|
715 |
'smtpd_sasl_type = dovecot', |
|
716 |
'smtpd_sasl_path = private/auth' |
6cc49f
|
717 |
); |
abdc67
|
718 |
|
6cc49f
|
719 |
// Make a backup copy of the main.cf file |
T |
720 |
copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~3'); |
abdc67
|
721 |
|
6cc49f
|
722 |
// Executing the postconf commands |
T |
723 |
foreach($postconf_commands as $cmd) { |
|
724 |
$command = "postconf -e '$cmd'"; |
|
725 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
726 |
} |
abdc67
|
727 |
|
6cc49f
|
728 |
//* copy dovecot.conf |
T |
729 |
$configfile = 'dovecot.conf'; |
abdc67
|
730 |
if(is_file("$config_dir/$configfile")) { |
V |
731 |
copy("$config_dir/$configfile", "$config_dir/$configfile~"); |
|
732 |
} |
6cc49f
|
733 |
copy('tpl/debian_dovecot.conf.master',"$config_dir/$configfile"); |
abdc67
|
734 |
|
6cc49f
|
735 |
//* dovecot-sql.conf |
T |
736 |
$configfile = 'dovecot-sql.conf'; |
abdc67
|
737 |
if(is_file("$config_dir/$configfile")) { |
V |
738 |
copy("$config_dir/$configfile", "$config_dir/$configfile~"); |
|
739 |
} |
6cc49f
|
740 |
exec("chmod 400 $config_dir/$configfile~"); |
T |
741 |
$content = rf("tpl/debian_dovecot-sql.conf.master"); |
|
742 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
|
743 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
744 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content); |
|
745 |
$content = str_replace('{mysql_server_host}',$conf['mysql']['host'],$content); |
|
746 |
wf("$config_dir/$configfile", $content); |
abdc67
|
747 |
|
6cc49f
|
748 |
exec("chmod 600 $config_dir/$configfile"); |
T |
749 |
exec("chown root:root $config_dir/$configfile"); |
|
750 |
|
|
751 |
} |
abdc67
|
752 |
|
7393e9
|
753 |
public function configure_amavis() { |
T |
754 |
global $conf; |
abdc67
|
755 |
|
7393e9
|
756 |
// amavisd user config file |
T |
757 |
$configfile = 'amavisd_user_config'; |
b77113
|
758 |
if(is_file($conf["amavis"]["config_dir"].'/conf.d/50-user')) copy($conf["amavis"]["config_dir"].'/conf.d/50-user',$conf["amavis"]["config_dir"].'/50-user~'); |
7393e9
|
759 |
if(is_file($conf["amavis"]["config_dir"].'/conf.d/50-user~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/conf.d/50-user~'); |
T |
760 |
$content = rf("tpl/".$configfile.".master"); |
|
761 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
|
762 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
763 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content); |
|
764 |
$content = str_replace('{mysql_server_port}',$conf["mysql"]["port"],$content); |
|
765 |
$content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content); |
|
766 |
wf($conf["amavis"]["config_dir"].'/conf.d/50-user',$content); |
abdc67
|
767 |
|
7393e9
|
768 |
// TODO: chmod and chown on the config file |
abdc67
|
769 |
|
V |
770 |
|
7393e9
|
771 |
// Adding the amavisd commands to the postfix configuration |
T |
772 |
$postconf_commands = array ( |
abdc67
|
773 |
'content_filter = amavis:[127.0.0.1]:10024', |
V |
774 |
'receive_override_options = no_address_mappings' |
7393e9
|
775 |
); |
abdc67
|
776 |
|
7393e9
|
777 |
// Make a backup copy of the main.cf file |
T |
778 |
copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~2'); |
abdc67
|
779 |
|
7393e9
|
780 |
// Executing the postconf commands |
T |
781 |
foreach($postconf_commands as $cmd) { |
|
782 |
$command = "postconf -e '$cmd'"; |
|
783 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
784 |
} |
abdc67
|
785 |
|
7393e9
|
786 |
// Append the configuration for amavisd to the master.cf file |
T |
787 |
if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf',$conf["postfix"]["config_dir"].'/master.cf~'); |
|
788 |
$content = rf($conf["postfix"]["config_dir"].'/master.cf'); |
|
789 |
// Only add the content if we had not addded it before |
|
790 |
if(!stristr($content,"127.0.0.1:10025")) { |
|
791 |
unset($content); |
|
792 |
$content = rf("tpl/master_cf_amavis.master"); |
|
793 |
af($conf["postfix"]["config_dir"].'/master.cf',$content); |
|
794 |
} |
|
795 |
unset($content); |
abdc67
|
796 |
|
7393e9
|
797 |
// Add the clamav user to the amavis group |
T |
798 |
exec('adduser clamav amavis'); |
abdc67
|
799 |
|
V |
800 |
|
7393e9
|
801 |
} |
abdc67
|
802 |
|
V |
803 |
public function configure_spamassassin() { |
7393e9
|
804 |
global $conf; |
abdc67
|
805 |
|
7393e9
|
806 |
//* Enable spamasasssin on debian and ubuntu |
T |
807 |
$configfile = '/etc/default/spamassassin'; |
abdc67
|
808 |
if(is_file($configfile)) { |
V |
809 |
copy($configfile, $configfile.'~'); |
|
810 |
} |
7393e9
|
811 |
$content = rf($configfile); |
T |
812 |
$content = str_replace('ENABLED=0', 'ENABLED=1', $content); |
|
813 |
wf($configfile, $content); |
|
814 |
} |
abdc67
|
815 |
|
V |
816 |
public function configure_getmail() { |
7393e9
|
817 |
global $conf; |
abdc67
|
818 |
|
7393e9
|
819 |
$config_dir = $conf['getmail']['config_dir']; |
abdc67
|
820 |
|
7393e9
|
821 |
if(!is_dir($config_dir)) exec("mkdir -p ".escapeshellcmd($config_dir)); |
T |
822 |
|
|
823 |
$command = "useradd -d $config_dir getmail"; |
|
824 |
if(!is_user('getmail')) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
825 |
|
7393e9
|
826 |
$command = "chown -R getmail $config_dir"; |
T |
827 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
828 |
|
7393e9
|
829 |
$command = "chmod -R 700 $config_dir"; |
T |
830 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
831 |
} |
abdc67
|
832 |
|
V |
833 |
|
|
834 |
public function configure_pureftpd() { |
7393e9
|
835 |
global $conf; |
abdc67
|
836 |
|
7393e9
|
837 |
$config_dir = $conf['pureftpd']['config_dir']; |
T |
838 |
|
cb8c86
|
839 |
//* configure pure-ftpd for MySQL authentication against the ispconfig database |
7393e9
|
840 |
$configfile = 'db/mysql.conf'; |
abdc67
|
841 |
if(is_file("$config_dir/$configfile")) { |
V |
842 |
copy("$config_dir/$configfile", "$config_dir/$configfile~"); |
|
843 |
} |
|
844 |
if(is_file("$config_dir/$configfile~")) { |
|
845 |
exec("chmod 400 $config_dir/$configfile~"); |
|
846 |
} |
7393e9
|
847 |
$content = rf('tpl/pureftpd_mysql.conf.master'); |
T |
848 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf["mysql"]["ispconfig_user"], $content); |
|
849 |
$content = str_replace('{mysql_server_ispconfig_password}', $conf["mysql"]["ispconfig_password"], $content); |
|
850 |
$content = str_replace('{mysql_server_database}', $conf["mysql"]["database"], $content); |
|
851 |
$content = str_replace('{mysql_server_ip}', $conf["mysql"]["ip"], $content); |
|
852 |
$content = str_replace('{server_id}', $conf["server_id"], $content); |
|
853 |
wf("$config_dir/$configfile", $content); |
|
854 |
exec("chmod 600 $config_dir/$configfile"); |
|
855 |
exec("chown root:root $config_dir/$configfile"); |
|
856 |
// **enable chrooting |
|
857 |
//exec('mkdir -p '.$config_dir.'/conf/ChrootEveryone'); |
|
858 |
exec('echo "yes" > '.$config_dir.'/conf/ChrootEveryone'); |
|
859 |
exec('echo "yes" > '.$config_dir.'/conf/BrokenClientsCompatibility'); |
f13717
|
860 |
exec('echo "yes" > '.$config_dir.'/conf/DisplayDotFiles'); |
abdc67
|
861 |
|
3a9418
|
862 |
if(is_file('/etc/default/pure-ftpd-common')) { |
T |
863 |
replaceLine('/etc/default/pure-ftpd-common','STANDALONE_OR_INETD=inetd','STANDALONE_OR_INETD=standalone',1,0); |
|
864 |
replaceLine('/etc/default/pure-ftpd-common','VIRTUALCHROOT=false','VIRTUALCHROOT=true',1,0); |
|
865 |
} |
abdc67
|
866 |
|
3a9418
|
867 |
if(is_file('/etc/inetd.conf')) { |
b77113
|
868 |
replaceLine('/etc/inetd.conf','/usr/sbin/pure-ftpd-wrapper','#ftp stream tcp nowait root /usr/sbin/tcpd /usr/sbin/pure-ftpd-wrapper',0,0); |
3a9418
|
869 |
if(is_file('/etc/init.d/openbsd-inetd')) exec('/etc/init.d/openbsd-inetd restart'); |
T |
870 |
} |
abdc67
|
871 |
|
3a9418
|
872 |
if(!is_file('/etc/pure-ftpd/conf/DontResolve')) exec("echo 'yes' > /etc/pure-ftpd/conf/DontResolve"); |
7393e9
|
873 |
} |
abdc67
|
874 |
|
V |
875 |
public function configure_mydns() { |
7393e9
|
876 |
global $conf; |
abdc67
|
877 |
|
7393e9
|
878 |
// configure pam for SMTP authentication agains the ispconfig database |
T |
879 |
$configfile = 'mydns.conf'; |
|
880 |
if(is_file($conf["mydns"]["config_dir"].'/'.$configfile)) copy($conf["mydns"]["config_dir"].'/'.$configfile,$conf["mydns"]["config_dir"].'/'.$configfile.'~'); |
|
881 |
if(is_file($conf["mydns"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["mydns"]["config_dir"].'/'.$configfile.'~'); |
|
882 |
$content = rf("tpl/".$configfile.".master"); |
|
883 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
|
884 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
885 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content); |
|
886 |
$content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content); |
|
887 |
$content = str_replace('{server_id}',$conf["server_id"],$content); |
|
888 |
wf($conf["mydns"]["config_dir"].'/'.$configfile,$content); |
|
889 |
exec('chmod 600 '.$conf["mydns"]["config_dir"].'/'.$configfile); |
|
890 |
exec('chown root:root '.$conf["mydns"]["config_dir"].'/'.$configfile); |
abdc67
|
891 |
|
7393e9
|
892 |
} |
abdc67
|
893 |
|
6ecbdc
|
894 |
public function configure_powerdns() { |
T |
895 |
global $conf; |
abdc67
|
896 |
|
6ecbdc
|
897 |
//* Create the database |
T |
898 |
if(!$this->db->query('CREATE DATABASE IF NOT EXISTS '.$conf['powerdns']['database'].' DEFAULT CHARACTER SET '.$conf['mysql']['charset'])) { |
|
899 |
$this->error('Unable to create MySQL database: '.$conf['powerdns']['database'].'.'); |
|
900 |
} |
abdc67
|
901 |
|
6ecbdc
|
902 |
//* Create the ISPConfig database user in the local database |
abdc67
|
903 |
$query = "GRANT ALL ON `".$conf['powerdns']['database']."` . * TO '".$conf['mysql']['ispconfig_user']."'@'localhost';"; |
6ecbdc
|
904 |
if(!$this->db->query($query)) { |
T |
905 |
$this->error('Unable to create user for powerdns database Error: '.$this->db->errorMessage); |
|
906 |
} |
abdc67
|
907 |
|
6ecbdc
|
908 |
//* Reload database privelages |
T |
909 |
$this->db->query('FLUSH PRIVILEGES;'); |
abdc67
|
910 |
|
6ecbdc
|
911 |
//* load the powerdns databse dump |
T |
912 |
if($conf['mysql']['admin_password'] == '') { |
abdc67
|
913 |
caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' '".$conf['powerdns']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/powerdns.sql' &> /dev/null", |
V |
914 |
__FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in powerdns.sql'); |
6ecbdc
|
915 |
} else { |
abdc67
|
916 |
caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' '".$conf['powerdns']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/powerdns.sql' &> /dev/null", |
V |
917 |
__FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in powerdns.sql'); |
6ecbdc
|
918 |
} |
abdc67
|
919 |
|
6ecbdc
|
920 |
//* Create the powerdns config file |
T |
921 |
$configfile = 'pdns.local'; |
|
922 |
if(is_file($conf["powerdns"]["config_dir"].'/'.$configfile)) copy($conf["powerdns"]["config_dir"].'/'.$configfile,$conf["powerdns"]["config_dir"].'/'.$configfile.'~'); |
|
923 |
if(is_file($conf["powerdns"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["powerdns"]["config_dir"].'/'.$configfile.'~'); |
|
924 |
$content = rf("tpl/".$configfile.".master"); |
|
925 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
|
926 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
927 |
$content = str_replace('{powerdns_database}',$conf['powerdns']['database'],$content); |
|
928 |
$content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content); |
|
929 |
wf($conf["powerdns"]["config_dir"].'/'.$configfile,$content); |
|
930 |
exec('chmod 600 '.$conf["powerdns"]["config_dir"].'/'.$configfile); |
|
931 |
exec('chown root:root '.$conf["powerdns"]["config_dir"].'/'.$configfile); |
abdc67
|
932 |
|
V |
933 |
|
6ecbdc
|
934 |
} |
abdc67
|
935 |
|
7dbea0
|
936 |
public function configure_bind() { |
T |
937 |
global $conf; |
abdc67
|
938 |
|
7dbea0
|
939 |
//* Nothing to do |
abdc67
|
940 |
|
7dbea0
|
941 |
} |
abdc67
|
942 |
|
V |
943 |
|
|
944 |
|
|
945 |
public function configure_apache() { |
7393e9
|
946 |
global $conf; |
abdc67
|
947 |
|
7393e9
|
948 |
//* Create the logging directory for the vhost logfiles |
T |
949 |
exec('mkdir -p /var/log/ispconfig/httpd'); |
abdc67
|
950 |
|
7393e9
|
951 |
if(is_file('/etc/suphp/suphp.conf')) { |
7fddfe
|
952 |
replaceLine('/etc/suphp/suphp.conf','php=php:/usr/bin','x-httpd-suphp="php:/usr/bin/php-cgi"',0); |
7393e9
|
953 |
//replaceLine('/etc/suphp/suphp.conf','docroot=','docroot=/var/clients',0); |
a4f044
|
954 |
replaceLine('/etc/suphp/suphp.conf','umask=0077','umask=0022',0); |
7393e9
|
955 |
} |
abdc67
|
956 |
|
7393e9
|
957 |
if(is_file('/etc/apache2/sites-enabled/000-default')) { |
T |
958 |
replaceLine('/etc/apache2/sites-available/000-default','NameVirtualHost *','NameVirtualHost *:80',1,0); |
|
959 |
replaceLine('/etc/apache2/sites-available/000-default','<VirtualHost *>','<VirtualHost *:80>',1,0); |
|
960 |
} |
abdc67
|
961 |
|
7393e9
|
962 |
if(is_file('/etc/apache2/ports.conf')) { |
T |
963 |
// add a line "Listen 443" to ports conf if line does not exist |
|
964 |
replaceLine('/etc/apache2/ports.conf','Listen 443','Listen 443',1); |
|
965 |
} |
abdc67
|
966 |
|
V |
967 |
|
7393e9
|
968 |
//* Copy the ISPConfig configuration include |
abdc67
|
969 |
$vhost_conf_dir = $conf['apache']['vhost_conf_dir']; |
V |
970 |
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir']; |
|
971 |
|
7393e9
|
972 |
// copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf'); |
abdc67
|
973 |
|
7393e9
|
974 |
$content = rf("tpl/apache_ispconfig.conf.master"); |
T |
975 |
$records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'"); |
d31e90
|
976 |
if(is_array($records) && count($records) > 0) { |
7393e9
|
977 |
foreach($records as $rec) { |
T |
978 |
$content .= "NameVirtualHost ".$rec["ip_address"].":80\n"; |
|
979 |
$content .= "NameVirtualHost ".$rec["ip_address"].":443\n"; |
|
980 |
} |
|
981 |
} |
|
982 |
$content .= "\n"; |
|
983 |
wf($vhost_conf_dir.'/ispconfig.conf',$content); |
abdc67
|
984 |
|
7393e9
|
985 |
if(!@is_link($vhost_conf_enabled_dir."/000-ispconfig.conf")) { |
T |
986 |
exec("ln -s ".$vhost_conf_dir."/ispconfig.conf ".$vhost_conf_enabled_dir."/000-ispconfig.conf"); |
|
987 |
} |
abdc67
|
988 |
|
e92a24
|
989 |
//* make sure that webalizer finds its config file when it is directly in /etc |
T |
990 |
if(@is_file('/etc/webalizer.conf') && !@is_dir('/etc/webalizer')) { |
|
991 |
exec('mkdir /etc/webalizer'); |
|
992 |
exec('ln -s /etc/webalizer.conf /etc/webalizer/webalizer.conf'); |
|
993 |
} |
abdc67
|
994 |
|
99d5dc
|
995 |
if(is_file('/etc/webalizer/webalizer.conf')) { |
T |
996 |
// Change webalizer mode to incremental |
c4cf4d
|
997 |
replaceLine('/etc/webalizer/webalizer.conf','#IncrementalName','IncrementalName webalizer.current',0,0); |
f051c0
|
998 |
replaceLine('/etc/webalizer/webalizer.conf','#Incremental','Incremental yes',0,0); |
c4cf4d
|
999 |
replaceLine('/etc/webalizer/webalizer.conf','#HistoryName','HistoryName webalizer.hist',0,0); |
99d5dc
|
1000 |
} |
abdc67
|
1001 |
|
6b029a
|
1002 |
//* add a sshusers group |
T |
1003 |
$command = 'groupadd sshusers'; |
|
1004 |
if(!is_group('sshusers')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1005 |
|
7393e9
|
1006 |
} |
abdc67
|
1007 |
|
V |
1008 |
public function configure_firewall() { |
7393e9
|
1009 |
global $conf; |
abdc67
|
1010 |
|
7393e9
|
1011 |
$dist_init_scripts = $conf['init_scripts']; |
abdc67
|
1012 |
|
7393e9
|
1013 |
if(is_dir("/etc/Bastille.backup")) caselog("rm -rf /etc/Bastille.backup", __FILE__, __LINE__); |
T |
1014 |
if(is_dir("/etc/Bastille")) caselog("mv -f /etc/Bastille /etc/Bastille.backup", __FILE__, __LINE__); |
abdc67
|
1015 |
@mkdir("/etc/Bastille", 0700); |
V |
1016 |
if(is_dir("/etc/Bastille.backup/firewall.d")) caselog("cp -pfr /etc/Bastille.backup/firewall.d /etc/Bastille/", __FILE__, __LINE__); |
|
1017 |
caselog("cp -f tpl/bastille-firewall.cfg.master /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__); |
|
1018 |
caselog("chmod 644 /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__); |
|
1019 |
$content = rf("/etc/Bastille/bastille-firewall.cfg"); |
|
1020 |
$content = str_replace("{DNS_SERVERS}", "", $content); |
7393e9
|
1021 |
|
abdc67
|
1022 |
$tcp_public_services = ''; |
V |
1023 |
$udp_public_services = ''; |
|
1024 |
|
7393e9
|
1025 |
$row = $this->db->queryOneRecord("SELECT * FROM firewall WHERE server_id = ".intval($conf['server_id'])); |
abdc67
|
1026 |
|
V |
1027 |
if(trim($row["tcp_port"]) != '' || trim($row["udp_port"]) != '') { |
|
1028 |
$tcp_public_services = trim(str_replace(',',' ',$row["tcp_port"])); |
|
1029 |
$udp_public_services = trim(str_replace(',',' ',$row["udp_port"])); |
|
1030 |
} else { |
|
1031 |
$tcp_public_services = '21 22 25 53 80 110 143 443 3306 8080 10000'; |
|
1032 |
$udp_public_services = '53'; |
|
1033 |
} |
|
1034 |
|
7393e9
|
1035 |
if(!stristr($tcp_public_services, $conf['apache']['vhost_port'])) { |
T |
1036 |
$tcp_public_services .= ' '.intval($conf['apache']['vhost_port']); |
|
1037 |
if($row["tcp_port"] != '') $this->db->query("UPDATE firewall SET tcp_port = tcp_port + ',".intval($conf['apache']['vhost_port'])."' WHERE server_id = ".intval($conf['server_id'])); |
|
1038 |
} |
|
1039 |
|
abdc67
|
1040 |
$content = str_replace("{TCP_PUBLIC_SERVICES}", $tcp_public_services, $content); |
V |
1041 |
$content = str_replace("{UDP_PUBLIC_SERVICES}", $udp_public_services, $content); |
7393e9
|
1042 |
|
abdc67
|
1043 |
wf("/etc/Bastille/bastille-firewall.cfg", $content); |
7393e9
|
1044 |
|
abdc67
|
1045 |
if(is_file($dist_init_scripts."/bastille-firewall")) caselog("mv -f $dist_init_scripts/bastille-firewall $dist_init_scripts/bastille-firewall.backup", __FILE__, __LINE__); |
V |
1046 |
caselog("cp -f apps/bastille-firewall $dist_init_scripts", __FILE__, __LINE__); |
|
1047 |
caselog("chmod 700 $dist_init_scripts/bastille-firewall", __FILE__, __LINE__); |
7393e9
|
1048 |
|
abdc67
|
1049 |
if(is_file("/sbin/bastille-ipchains")) caselog("mv -f /sbin/bastille-ipchains /sbin/bastille-ipchains.backup", __FILE__, __LINE__); |
V |
1050 |
caselog("cp -f apps/bastille-ipchains /sbin", __FILE__, __LINE__); |
|
1051 |
caselog("chmod 700 /sbin/bastille-ipchains", __FILE__, __LINE__); |
|
1052 |
|
|
1053 |
if(is_file("/sbin/bastille-netfilter")) caselog("mv -f /sbin/bastille-netfilter /sbin/bastille-netfilter.backup", __FILE__, __LINE__); |
|
1054 |
caselog("cp -f apps/bastille-netfilter /sbin", __FILE__, __LINE__); |
|
1055 |
caselog("chmod 700 /sbin/bastille-netfilter", __FILE__, __LINE__); |
|
1056 |
|
7393e9
|
1057 |
if(!@is_dir('/var/lock/subsys')) caselog("mkdir /var/lock/subsys", __FILE__, __LINE__); |
T |
1058 |
|
abdc67
|
1059 |
exec("which ipchains &> /dev/null", $ipchains_location, $ret_val); |
V |
1060 |
if(!is_file("/sbin/ipchains") && !is_link("/sbin/ipchains") && $ret_val == 0) phpcaselog(@symlink(shell_exec("which ipchains"), "/sbin/ipchains"), 'create symlink', __FILE__, __LINE__); |
|
1061 |
unset($ipchains_location); |
|
1062 |
exec("which iptables &> /dev/null", $iptables_location, $ret_val); |
|
1063 |
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__); |
|
1064 |
unset($iptables_location); |
7393e9
|
1065 |
|
T |
1066 |
} |
abdc67
|
1067 |
|
V |
1068 |
public function configure_vlogger() { |
c9b9f2
|
1069 |
global $conf; |
abdc67
|
1070 |
|
V |
1071 |
//** Configure vlogger to use traffic logging to mysql (master) db |
|
1072 |
$configfile = 'vlogger-dbi.conf'; |
|
1073 |
if(is_file($conf["vlogger"]["config_dir"].'/'.$configfile)) copy($conf["vlogger"]["config_dir"].'/'.$configfile,$conf["vlogger"]["config_dir"].'/'.$configfile.'~'); |
|
1074 |
if(is_file($conf["vlogger"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["vlogger"]["config_dir"].'/'.$configfile.'~'); |
|
1075 |
$content = rf("tpl/".$configfile.".master"); |
|
1076 |
if($conf['mysql']['master_slave_setup'] == 'y') { |
|
1077 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['master_ispconfig_user'],$content); |
|
1078 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['master_ispconfig_password'], $content); |
|
1079 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['master_database'],$content); |
|
1080 |
$content = str_replace('{mysql_server_ip}',$conf["mysql"]["master_host"],$content); |
|
1081 |
} else { |
|
1082 |
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content); |
|
1083 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
1084 |
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content); |
|
1085 |
$content = str_replace('{mysql_server_ip}',$conf["mysql"]["host"],$content); |
|
1086 |
} |
|
1087 |
wf($conf["vlogger"]["config_dir"].'/'.$configfile,$content); |
|
1088 |
exec('chmod 600 '.$conf["vlogger"]["config_dir"].'/'.$configfile); |
|
1089 |
exec('chown root:root '.$conf["vlogger"]["config_dir"].'/'.$configfile); |
|
1090 |
|
|
1091 |
} |
|
1092 |
|
|
1093 |
public function configure_apps_vhost() { |
|
1094 |
global $conf; |
|
1095 |
|
c9b9f2
|
1096 |
//* Create the ispconfig apps vhost user and group |
abdc67
|
1097 |
|
df8a46
|
1098 |
$apps_vhost_user = escapeshellcmd($conf['web']['apps_vhost_user']); |
T |
1099 |
$apps_vhost_group = escapeshellcmd($conf['web']['apps_vhost_group']); |
|
1100 |
$install_dir = escapeshellcmd($conf['web']['website_basedir'].'/apps'); |
abdc67
|
1101 |
|
c9b9f2
|
1102 |
$command = 'groupadd '.$apps_vhost_user; |
T |
1103 |
if(!is_group($apps_vhost_group)) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1104 |
|
c9b9f2
|
1105 |
$command = "useradd -g '$apps_vhost_group' -d $install_dir $apps_vhost_group"; |
T |
1106 |
if(!is_user($apps_vhost_user)) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
1107 |
|
abdc67
|
1108 |
|
c9b9f2
|
1109 |
$command = 'adduser '.$conf['apache']['user'].' '.$apps_vhost_group; |
T |
1110 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1111 |
|
df8a46
|
1112 |
exec('mkdir -p '.$install_dir); |
T |
1113 |
exec("chown $apps_vhost_user:$apps_vhost_group $install_dir"); |
abdc67
|
1114 |
|
c9b9f2
|
1115 |
//* Copy the apps vhost file |
abdc67
|
1116 |
$vhost_conf_dir = $conf['apache']['vhost_conf_dir']; |
V |
1117 |
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir']; |
|
1118 |
$apps_vhost_servername = ($conf['web']['apps_vhost_servername'] == '')?'':'ServerName '.$conf['web']['apps_vhost_servername']; |
|
1119 |
|
|
1120 |
// Dont just copy over the virtualhost template but add some custom settings |
|
1121 |
$content = rf("tpl/apache_apps.vhost.master"); |
|
1122 |
|
cf192c
|
1123 |
$content = str_replace('{apps_vhost_ip}', $conf['web']['apps_vhost_ip'], $content); |
T |
1124 |
$content = str_replace('{apps_vhost_port}', $conf['web']['apps_vhost_port'], $content); |
c9b9f2
|
1125 |
$content = str_replace('{apps_vhost_dir}', $conf['web']['website_basedir'].'/apps', $content); |
05b8ea
|
1126 |
$content = str_replace('{website_basedir}', $conf['web']['website_basedir'], $content); |
c9b9f2
|
1127 |
$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content); |
abdc67
|
1128 |
|
V |
1129 |
|
c9b9f2
|
1130 |
// comment out the listen directive if port is 80 or 443 |
cf192c
|
1131 |
if($conf['web']['apps_vhost_ip'] == 80 or $conf['web']['apps_vhost_ip'] == 443) { |
c9b9f2
|
1132 |
$content = str_replace('{vhost_port_listen}', '#', $content); |
T |
1133 |
} else { |
|
1134 |
$content = str_replace('{vhost_port_listen}', '', $content); |
|
1135 |
} |
abdc67
|
1136 |
|
c9b9f2
|
1137 |
wf("$vhost_conf_dir/apps.vhost", $content); |
abdc67
|
1138 |
|
c9b9f2
|
1139 |
//copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost"); |
T |
1140 |
//* and create the symlink |
ff82d8
|
1141 |
if($this->install_ispconfig_interface == true) { |
c9b9f2
|
1142 |
if(@is_link("$vhost_conf_enabled_dir/apps.vhost")) unlink("$vhost_conf_enabled_dir/apps.vhost"); |
T |
1143 |
if(!@is_link("$vhost_conf_enabled_dir/000-apps.vhost")) { |
|
1144 |
exec("ln -s $vhost_conf_dir/apps.vhost $vhost_conf_enabled_dir/000-apps.vhost"); |
|
1145 |
} |
|
1146 |
} |
|
1147 |
if(!is_file($conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter')) { |
|
1148 |
exec('mkdir -p '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps'); |
|
1149 |
exec('cp tpl/apache_apps_fcgi_starter.master '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter'); |
|
1150 |
exec('chmod +x '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter'); |
|
1151 |
exec('chown -R ispapps:ispapps '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps'); |
abdc67
|
1152 |
|
c9b9f2
|
1153 |
} |
abdc67
|
1154 |
|
c9b9f2
|
1155 |
} |
abdc67
|
1156 |
|
V |
1157 |
public function install_ispconfig() { |
7393e9
|
1158 |
global $conf; |
abdc67
|
1159 |
|
7393e9
|
1160 |
$install_dir = $conf['ispconfig_install_dir']; |
T |
1161 |
|
|
1162 |
//* Create the ISPConfig installation directory |
|
1163 |
if(!@is_dir("$install_dir")) { |
|
1164 |
$command = "mkdir $install_dir"; |
|
1165 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
1166 |
} |
abdc67
|
1167 |
|
7393e9
|
1168 |
//* Create a ISPConfig user and group |
T |
1169 |
$command = 'groupadd ispconfig'; |
|
1170 |
if(!is_group('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1171 |
|
7393e9
|
1172 |
$command = "useradd -g ispconfig -d $install_dir ispconfig"; |
T |
1173 |
if(!is_user('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1174 |
|
7393e9
|
1175 |
//* copy the ISPConfig interface part |
T |
1176 |
$command = "cp -rf ../interface $install_dir"; |
|
1177 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1178 |
|
7393e9
|
1179 |
//* copy the ISPConfig server part |
T |
1180 |
$command = "cp -rf ../server $install_dir"; |
|
1181 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1182 |
|
7393e9
|
1183 |
//* Create a symlink, so ISPConfig is accessible via web |
T |
1184 |
// Replaced by a separate vhost definition for port 8080 |
|
1185 |
// $command = "ln -s $install_dir/interface/web/ /var/www/ispconfig"; |
|
1186 |
// caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1187 |
|
7393e9
|
1188 |
//* Create the config file for ISPConfig interface |
T |
1189 |
$configfile = 'config.inc.php'; |
abdc67
|
1190 |
if(is_file($install_dir.'/interface/lib/'.$configfile)) { |
V |
1191 |
copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~"); |
|
1192 |
} |
7393e9
|
1193 |
$content = rf("tpl/$configfile.master"); |
T |
1194 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content); |
|
1195 |
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
|
1196 |
$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
|
1197 |
$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
abdc67
|
1198 |
|
7393e9
|
1199 |
$content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content); |
T |
1200 |
$content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content); |
|
1201 |
$content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content); |
|
1202 |
$content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content); |
abdc67
|
1203 |
|
7c3b60
|
1204 |
$content = str_replace('{server_id}', $conf['server_id'], $content); |
7393e9
|
1205 |
$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
56f1f4
|
1206 |
$content = str_replace('{language}', $conf['language'], $content); |
abdc67
|
1207 |
|
7393e9
|
1208 |
wf("$install_dir/interface/lib/$configfile", $content); |
abdc67
|
1209 |
|
7393e9
|
1210 |
//* Create the config file for ISPConfig server |
T |
1211 |
$configfile = 'config.inc.php'; |
abdc67
|
1212 |
if(is_file($install_dir.'/server/lib/'.$configfile)) { |
V |
1213 |
copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~"); |
|
1214 |
} |
7393e9
|
1215 |
$content = rf("tpl/$configfile.master"); |
T |
1216 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content); |
|
1217 |
$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content); |
|
1218 |
$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
|
1219 |
$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
abdc67
|
1220 |
|
7393e9
|
1221 |
$content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content); |
T |
1222 |
$content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content); |
|
1223 |
$content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content); |
|
1224 |
$content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content); |
abdc67
|
1225 |
|
7393e9
|
1226 |
$content = str_replace('{server_id}', $conf['server_id'], $content); |
T |
1227 |
$content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
5898e6
|
1228 |
$content = str_replace('{language}', $conf['language'], $content); |
abdc67
|
1229 |
|
7393e9
|
1230 |
wf("$install_dir/server/lib/$configfile", $content); |
99ca2f
|
1231 |
|
abdc67
|
1232 |
//* Create the config file for remote-actions (but only, if it does not exist, because |
V |
1233 |
// the value is a autoinc-value and so changed by the remoteaction_core_module |
|
1234 |
if (!file_exists("$install_dir/server/lib/remote_action.inc.php")) { |
|
1235 |
$content = '<?php' . "\n" . '$maxid_remote_action = 0;' . "\n?>"; |
|
1236 |
wf("$install_dir/server/lib/remote_action.inc.php", $content); |
|
1237 |
} |
|
1238 |
|
7393e9
|
1239 |
//* Enable the server modules and plugins. |
T |
1240 |
// TODO: Implement a selector which modules and plugins shall be enabled. |
|
1241 |
$dir = $install_dir.'/server/mods-available/'; |
|
1242 |
if (is_dir($dir)) { |
|
1243 |
if ($dh = opendir($dir)) { |
|
1244 |
while (($file = readdir($dh)) !== false) { |
|
1245 |
if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') { |
|
1246 |
include_once($install_dir.'/server/mods-available/'.$file); |
|
1247 |
$module_name = substr($file,0,-8); |
|
1248 |
$tmp = new $module_name; |
|
1249 |
if($tmp->onInstall()) { |
7a4489
|
1250 |
if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) { |
6c343b
|
1251 |
@symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file); |
T |
1252 |
// @symlink($install_dir.'/server/mods-available/'.$file, '../mods-enabled/'.$file); |
7a4489
|
1253 |
} |
7393e9
|
1254 |
if (strpos($file, '_core_module') !== false) { |
7a4489
|
1255 |
if(!@is_link($install_dir.'/server/mods-core/'.$file)) { |
6c343b
|
1256 |
@symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file); |
T |
1257 |
// @symlink($install_dir.'/server/mods-available/'.$file, '../mods-core/'.$file); |
7a4489
|
1258 |
} |
7393e9
|
1259 |
} |
T |
1260 |
} |
|
1261 |
unset($tmp); |
|
1262 |
} |
|
1263 |
} |
|
1264 |
closedir($dh); |
|
1265 |
} |
|
1266 |
} |
abdc67
|
1267 |
|
7393e9
|
1268 |
$dir = $install_dir.'/server/plugins-available/'; |
T |
1269 |
if (is_dir($dir)) { |
|
1270 |
if ($dh = opendir($dir)) { |
|
1271 |
while (($file = readdir($dh)) !== false) { |
|
1272 |
if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') { |
|
1273 |
include_once($install_dir.'/server/plugins-available/'.$file); |
|
1274 |
$plugin_name = substr($file,0,-8); |
|
1275 |
$tmp = new $plugin_name; |
|
1276 |
if(method_exists($tmp,'onInstall') && $tmp->onInstall()) { |
7a4489
|
1277 |
if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) { |
6c343b
|
1278 |
@symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file); |
T |
1279 |
//@symlink($install_dir.'/server/plugins-available/'.$file, '../plugins-enabled/'.$file); |
7a4489
|
1280 |
} |
7393e9
|
1281 |
if (strpos($file, '_core_plugin') !== false) { |
7a4489
|
1282 |
if(!@is_link($install_dir.'/server/plugins-core/'.$file)) { |
6c343b
|
1283 |
@symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file); |
T |
1284 |
//@symlink($install_dir.'/server/plugins-available/'.$file, '../plugins-core/'.$file); |
7a4489
|
1285 |
} |
7393e9
|
1286 |
} |
T |
1287 |
} |
|
1288 |
unset($tmp); |
|
1289 |
} |
|
1290 |
} |
|
1291 |
closedir($dh); |
|
1292 |
} |
|
1293 |
} |
abdc67
|
1294 |
|
7393e9
|
1295 |
// Update the server config |
T |
1296 |
$mail_server_enabled = ($conf['services']['mail'])?1:0; |
|
1297 |
$web_server_enabled = ($conf['services']['web'])?1:0; |
|
1298 |
$dns_server_enabled = ($conf['services']['dns'])?1:0; |
|
1299 |
$file_server_enabled = ($conf['services']['file'])?1:0; |
|
1300 |
$db_server_enabled = ($conf['services']['db'])?1:0; |
|
1301 |
$vserver_server_enabled = ($conf['services']['vserver'])?1:0; |
abdc67
|
1302 |
|
V |
1303 |
|
|
1304 |
|
|
1305 |
|
|
1306 |
|
|
1307 |
|
7393e9
|
1308 |
$sql = "UPDATE `server` SET mail_server = '$mail_server_enabled', web_server = '$web_server_enabled', dns_server = '$dns_server_enabled', file_server = '$file_server_enabled', db_server = '$db_server_enabled', vserver_server = '$vserver_server_enabled' WHERE server_id = ".intval($conf['server_id']); |
abdc67
|
1309 |
|
7393e9
|
1310 |
if($conf['mysql']['master_slave_setup'] == 'y') { |
T |
1311 |
$this->dbmaster->query($sql); |
|
1312 |
$this->db->query($sql); |
|
1313 |
} else { |
|
1314 |
$this->db->query($sql); |
|
1315 |
} |
abdc67
|
1316 |
|
V |
1317 |
|
7393e9
|
1318 |
//* Chmod the files |
T |
1319 |
$command = "chmod -R 750 $install_dir"; |
|
1320 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
1321 |
|
|
1322 |
//* chown the files to the ispconfig user and group |
|
1323 |
$command = "chown -R ispconfig:ispconfig $install_dir"; |
|
1324 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1325 |
|
7393e9
|
1326 |
//* Make the global language file directory group writable |
T |
1327 |
exec("chmod -R 770 $install_dir/interface/lib/lang"); |
abdc67
|
1328 |
|
7393e9
|
1329 |
//* Make the temp directory for language file exports writable |
f045f1
|
1330 |
if(is_dir("$install_dir/interface/web/temp")) exec("chmod -R 770 $install_dir/interface/web/temp"); |
abdc67
|
1331 |
|
7393e9
|
1332 |
//* Make all interface language file directories group writable |
T |
1333 |
$handle = @opendir($install_dir.'/interface/web'); |
abdc67
|
1334 |
while ($file = @readdir ($handle)) { |
V |
1335 |
if ($file != '.' && $file != '..') { |
|
1336 |
if(@is_dir($install_dir.'/interface/web'.'/'.$file.'/lib/lang')) { |
7393e9
|
1337 |
$handle2 = opendir($install_dir.'/interface/web'.'/'.$file.'/lib/lang'); |
T |
1338 |
chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang',0770); |
|
1339 |
while ($lang_file = @readdir ($handle2)) { |
|
1340 |
if ($lang_file != '.' && $lang_file != '..') { |
|
1341 |
chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang/'.$lang_file,0770); |
|
1342 |
} |
|
1343 |
} |
|
1344 |
} |
|
1345 |
} |
|
1346 |
} |
abdc67
|
1347 |
|
7393e9
|
1348 |
//* make sure that the server config file (not the interface one) is only readable by the root user |
T |
1349 |
exec("chmod 600 $install_dir/server/lib/$configfile"); |
|
1350 |
exec("chown root:root $install_dir/server/lib/$configfile"); |
99ca2f
|
1351 |
|
abdc67
|
1352 |
exec("chmod 600 $install_dir/server/lib/remote_action.inc.php"); |
V |
1353 |
exec("chown root:root $install_dir/server/lib/remote_action.inc.php"); |
99ca2f
|
1354 |
|
7393e9
|
1355 |
if(@is_file("$install_dir/server/lib/mysql_clientdb.conf")) { |
T |
1356 |
exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf"); |
|
1357 |
exec("chown root:root $install_dir/server/lib/mysql_clientdb.conf"); |
|
1358 |
} |
abdc67
|
1359 |
|
7393e9
|
1360 |
// TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing |
T |
1361 |
// and must be fixed as this will allow the apache user to read the ispconfig files. |
|
1362 |
// Later this must run as own apache server or via suexec! |
|
1363 |
$command = 'adduser www-data ispconfig'; |
|
1364 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1365 |
|
7393e9
|
1366 |
//* Make the shell scripts executable |
T |
1367 |
$command = "chmod +x $install_dir/server/scripts/*.sh"; |
|
1368 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
abdc67
|
1369 |
|
7393e9
|
1370 |
//* Copy the ISPConfig vhost for the controlpanel |
abdc67
|
1371 |
$vhost_conf_dir = $conf['apache']['vhost_conf_dir']; |
V |
1372 |
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir']; |
|
1373 |
|
|
1374 |
|
|
1375 |
// Dont just copy over the virtualhost template but add some custom settings |
|
1376 |
$content = rf("tpl/apache_ispconfig.vhost.master"); |
7393e9
|
1377 |
$content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content); |
abdc67
|
1378 |
|
7393e9
|
1379 |
// comment out the listen directive if port is 80 or 443 |
T |
1380 |
if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) { |
|
1381 |
$content = str_replace('{vhost_port_listen}', '#', $content); |
|
1382 |
} else { |
|
1383 |
$content = str_replace('{vhost_port_listen}', '', $content); |
|
1384 |
} |
abdc67
|
1385 |
|
7393e9
|
1386 |
wf("$vhost_conf_dir/ispconfig.vhost", $content); |
abdc67
|
1387 |
|
7393e9
|
1388 |
//copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost"); |
T |
1389 |
//* and create the symlink |
|
1390 |
if($this->install_ispconfig_interface == true && $this->is_update == false) { |
|
1391 |
if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost"); |
|
1392 |
if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) { |
|
1393 |
exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost"); |
|
1394 |
} |
|
1395 |
} |
|
1396 |
if(!is_file('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) { |
|
1397 |
exec('mkdir -p /var/www/php-fcgi-scripts/ispconfig'); |
|
1398 |
exec('cp tpl/apache_ispconfig_fcgi_starter.master /var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter'); |
|
1399 |
exec('chmod +x /var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter'); |
|
1400 |
exec('ln -s /usr/local/ispconfig/interface/web /var/www/ispconfig'); |
|
1401 |
exec('chown -R ispconfig:ispconfig /var/www/php-fcgi-scripts/ispconfig'); |
abdc67
|
1402 |
|
7393e9
|
1403 |
} |
abdc67
|
1404 |
|
7393e9
|
1405 |
//* Install the update script |
T |
1406 |
if(is_file('/usr/local/bin/ispconfig_update_from_svn.sh')) unlink('/usr/local/bin/ispconfig_update_from_svn.sh'); |
|
1407 |
exec('chown root /usr/local/ispconfig/server/scripts/update_from_svn.sh'); |
|
1408 |
exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_svn.sh'); |
|
1409 |
exec('chown root /usr/local/ispconfig/server/scripts/update_from_tgz.sh'); |
|
1410 |
exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_tgz.sh'); |
|
1411 |
exec('chown root /usr/local/ispconfig/server/scripts/ispconfig_update.sh'); |
|
1412 |
exec('chmod 700 /usr/local/ispconfig/server/scripts/ispconfig_update.sh'); |
|
1413 |
if(!is_link('/usr/local/bin/ispconfig_update_from_svn.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update_from_svn.sh'); |
|
1414 |
if(!is_link('/usr/local/bin/ispconfig_update.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update.sh'); |
abdc67
|
1415 |
|
7393e9
|
1416 |
//* Make the logs readable for the ispconfig user |
T |
1417 |
if(@is_file('/var/log/mail.log')) exec('chmod +r /var/log/mail.log'); |
|
1418 |
if(@is_file('/var/log/mail.warn')) exec('chmod +r /var/log/mail.warn'); |
|
1419 |
if(@is_file('/var/log/mail.err')) exec('chmod +r /var/log/mail.err'); |
|
1420 |
if(@is_file('/var/log/messages')) exec('chmod +r /var/log/messages'); |
|
1421 |
if(@is_file('/var/log/clamav/clamav.log')) exec('chmod +r /var/log/clamav/clamav.log'); |
|
1422 |
if(@is_file('/var/log/clamav/freshclam.log')) exec('chmod +r /var/log/clamav/freshclam.log'); |
abdc67
|
1423 |
|
7393e9
|
1424 |
//* Create the ispconfig log directory |
T |
1425 |
if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig'); |
|
1426 |
if(!is_file('/var/log/ispconfig/ispconfig.log')) exec('touch /var/log/ispconfig/ispconfig.log'); |
abdc67
|
1427 |
|
7393e9
|
1428 |
exec('mv /usr/local/ispconfig/server/scripts/run-getmail.sh /usr/local/bin/run-getmail.sh'); |
28bf89
|
1429 |
if(is_user('getmail')) exec('chown getmail /usr/local/bin/run-getmail.sh'); |
7393e9
|
1430 |
exec('chmod 744 /usr/local/bin/run-getmail.sh'); |
57659b
|
1431 |
|
V |
1432 |
//* Add Log-Rotation |
abdc67
|
1433 |
if (is_dir('/etc/logrotate.d')) { |
196c29
|
1434 |
@unlink('/etc/logrotate.d/logispc3'); // ignore, if the file is not there |
57659b
|
1435 |
$fh = fopen('/etc/logrotate.d/logispc3', 'w'); |
V |
1436 |
fwrite($fh, |
|
1437 |
"/var/log/ispconfig/ispconfig.log { \n" . |
|
1438 |
" weekly \n" . |
|
1439 |
" missingok \n" . |
|
1440 |
" rotate 4 \n" . |
|
1441 |
" compress \n" . |
|
1442 |
" delaycompress \n" . |
|
1443 |
"} \n" . |
|
1444 |
"/var/log/ispconfig/cron.log { \n" . |
|
1445 |
" weekly \n" . |
|
1446 |
" missingok \n" . |
|
1447 |
" rotate 4 \n" . |
|
1448 |
" compress \n" . |
|
1449 |
" delaycompress \n" . |
|
1450 |
"}"); |
|
1451 |
fclose($fh); |
|
1452 |
} |
7393e9
|
1453 |
} |
abdc67
|
1454 |
|
V |
1455 |
public function configure_dbserver() { |
7393e9
|
1456 |
global $conf; |
abdc67
|
1457 |
|
7393e9
|
1458 |
//* If this server shall act as database server for client DB's, we configure this here |
T |
1459 |
$install_dir = $conf['ispconfig_install_dir']; |
abdc67
|
1460 |
|
V |
1461 |
// Create a file with the database login details which |
7393e9
|
1462 |
// are used to create the client databases. |
abdc67
|
1463 |
|
7393e9
|
1464 |
if(!is_dir("$install_dir/server/lib")) { |
T |
1465 |
$command = "mkdir $install_dir/server/lib"; |
|
1466 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
1467 |
} |
abdc67
|
1468 |
|
7393e9
|
1469 |
$content = rf("tpl/mysql_clientdb.conf.master"); |
T |
1470 |
$content = str_replace('{username}',$conf['mysql']['admin_user'],$content); |
|
1471 |
$content = str_replace('{password}',$conf['mysql']['admin_password'], $content); |
|
1472 |
wf("$install_dir/server/lib/mysql_clientdb.conf",$content); |
|
1473 |
exec('chmod 600 '."$install_dir/server/lib/mysql_clientdb.conf"); |
|
1474 |
exec('chown root:root '."$install_dir/server/lib/mysql_clientdb.conf"); |
abdc67
|
1475 |
|
7393e9
|
1476 |
} |
abdc67
|
1477 |
|
V |
1478 |
public function install_crontab() { |
7393e9
|
1479 |
global $conf; |
abdc67
|
1480 |
|
7393e9
|
1481 |
//* Root Crontab |
T |
1482 |
exec('crontab -u root -l > crontab.txt'); |
|
1483 |
$existing_root_cron_jobs = file('crontab.txt'); |
abdc67
|
1484 |
|
7393e9
|
1485 |
// remove existing ispconfig cronjobs, in case the syntax has changed |
T |
1486 |
foreach($existing_root_cron_jobs as $key => $val) { |
|
1487 |
if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]); |
|
1488 |
} |
abdc67
|
1489 |
|
7393e9
|
1490 |
$root_cron_jobs = array( |
abdc67
|
1491 |
'* * * * * /usr/local/ispconfig/server/server.sh > /dev/null 2>> /var/log/ispconfig/cron.log', |
V |
1492 |
'30 00 * * * /usr/local/ispconfig/server/cron_daily.sh > /dev/null 2>> /var/log/ispconfig/cron.log' |
7393e9
|
1493 |
); |
T |
1494 |
foreach($root_cron_jobs as $cron_job) { |
|
1495 |
if(!in_array($cron_job."\n", $existing_root_cron_jobs)) { |
|
1496 |
$existing_root_cron_jobs[] = $cron_job."\n"; |
|
1497 |
} |
|
1498 |
} |
|
1499 |
file_put_contents('crontab.txt', $existing_root_cron_jobs); |
|
1500 |
exec('crontab -u root crontab.txt &> /dev/null'); |
|
1501 |
unlink('crontab.txt'); |
abdc67
|
1502 |
|
7393e9
|
1503 |
//* Getmail crontab |
T |
1504 |
if(is_user('getmail')) { |
abdc67
|
1505 |
$cf = $conf['getmail']; |
7393e9
|
1506 |
exec('crontab -u getmail -l > crontab.txt'); |
T |
1507 |
$existing_cron_jobs = file('crontab.txt'); |
abdc67
|
1508 |
|
7393e9
|
1509 |
$cron_jobs = array( |
abdc67
|
1510 |
'*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> /var/log/ispconfig/cron.log' |
V |
1511 |
); |
|
1512 |
|
7393e9
|
1513 |
// remove existing ispconfig cronjobs, in case the syntax has changed |
T |
1514 |
foreach($existing_cron_jobs as $key => $val) { |
|
1515 |
if(stristr($val,'getmail')) unset($existing_cron_jobs[$key]); |
|
1516 |
} |
abdc67
|
1517 |
|
7393e9
|
1518 |
foreach($cron_jobs as $cron_job) { |
T |
1519 |
if(!in_array($cron_job."\n", $existing_cron_jobs)) { |
|
1520 |
$existing_cron_jobs[] = $cron_job."\n"; |
|
1521 |
} |
|
1522 |
} |
|
1523 |
file_put_contents('crontab.txt', $existing_cron_jobs); |
|
1524 |
exec('crontab -u getmail crontab.txt &> /dev/null'); |
|
1525 |
unlink('crontab.txt'); |
|
1526 |
} |
abdc67
|
1527 |
|
7393e9
|
1528 |
exec('touch /var/log/ispconfig/cron.log'); |
T |
1529 |
exec('chmod 666 /var/log/ispconfig/cron.log'); |
abdc67
|
1530 |
|
7393e9
|
1531 |
} |
abdc67
|
1532 |
|
cb8c86
|
1533 |
/** |
W |
1534 |
* Helper function - get the path to a template file based on |
|
1535 |
* the local part of the filename. Checks first for the existence |
|
1536 |
* of a distribution specific file and if not found looks in the |
|
1537 |
* base template folder. Optionally the behaviour can be changed |
|
1538 |
* by setting the 2nd parameter which will fetch the contents |
|
1539 |
* of the template file and return it instead of the path. The 3rd |
|
1540 |
* parameter further extends this behaviour by filtering the contents |
|
1541 |
* by inserting the ispconfig database credentials using the {} placeholders. |
abdc67
|
1542 |
* |
cb8c86
|
1543 |
* @param string $tLocal local part of filename |
W |
1544 |
* @param bool $tRf |
|
1545 |
* @param bool $tDBCred |
|
1546 |
* @return string Relative path to the chosen template file |
|
1547 |
*/ |
abdc67
|
1548 |
protected function get_template_file($tLocal, $tRf=false, $tDBCred=false) { |
cb8c86
|
1549 |
global $conf, $dist; |
abdc67
|
1550 |
|
cb8c86
|
1551 |
$final_path = ''; |
W |
1552 |
$dist_template = 'dist/tpl/'.strtolower($dist['name'])."/$tLocal.master"; |
|
1553 |
if (file_exists($dist_template)) { |
|
1554 |
$final_path = $dist_template; |
|
1555 |
} else { |
|
1556 |
$final_path = "tpl/$tLocal.master"; |
|
1557 |
} |
abdc67
|
1558 |
|
cb8c86
|
1559 |
if (!$tRf) { |
W |
1560 |
return $final_path; |
|
1561 |
} else { |
|
1562 |
return (!$tDBCred) ? rf($final_path) : $this->insert_db_credentials(rf($final_path)); |
|
1563 |
} |
|
1564 |
} |
abdc67
|
1565 |
|
cb8c86
|
1566 |
/** |
W |
1567 |
* Helper function - writes the contents to a config file |
|
1568 |
* and performs a backup if the file exist. Additionally |
|
1569 |
* if the file exists the new file will be given the |
|
1570 |
* same rights and ownership as the original. Optionally the |
|
1571 |
* rights and/or ownership can be overriden by appending umask, |
|
1572 |
* user and group to the parameters. Providing only uid and gid |
abdc67
|
1573 |
* values will result in only a chown. |
V |
1574 |
* |
cb8c86
|
1575 |
* @param $tConf |
W |
1576 |
* @param $tContents |
|
1577 |
* @return bool |
|
1578 |
*/ |
abdc67
|
1579 |
protected function write_config_file($tConf, $tContents) { |
cb8c86
|
1580 |
// Backup config file before writing new contents and stat file |
abdc67
|
1581 |
if ( is_file($tConf) ) { |
cb8c86
|
1582 |
$stat = exec('stat -c \'%a %U %G\' '.escapeshellarg($tConf), $output, $res); |
W |
1583 |
if ($res == 0) { // stat successfull |
|
1584 |
list($access, $user, $group) = split(" ", $stat); |
|
1585 |
} |
abdc67
|
1586 |
|
cb8c86
|
1587 |
if ( copy($tConf, $tConf.'~') ) { |
W |
1588 |
exec('chmod 400 '.$tConf.'~'); |
|
1589 |
} |
|
1590 |
} |
abdc67
|
1591 |
|
cb8c86
|
1592 |
wf($tConf, $tContents); // write file |
abdc67
|
1593 |
|
cb8c86
|
1594 |
if (func_num_args() >= 4) // override rights and/or ownership |
W |
1595 |
{ |
|
1596 |
$args = func_get_args(); |
|
1597 |
$output = array_slice($args, 2); |
abdc67
|
1598 |
|
cb8c86
|
1599 |
switch (sizeof($output)) { |
W |
1600 |
case 3: |
|
1601 |
$umask = array_shift($output); |
|
1602 |
if (is_numeric($umask) && preg_match('/^0?[0-7]{3}$/', $umask)) { |
|
1603 |
$access = $umask; |
|
1604 |
} |
|
1605 |
case 2: |
|
1606 |
if (is_user($output[0]) && is_group($output[1])) { |
|
1607 |
list($user,$group) = $output; |
|
1608 |
} |
|
1609 |
break; |
|
1610 |
} |
|
1611 |
} |
abdc67
|
1612 |
|
cb8c86
|
1613 |
if (!empty($user) && !empty($group)) { |
W |
1614 |
exec("chown $user:$group $tConf"); |
|
1615 |
} |
abdc67
|
1616 |
|
cb8c86
|
1617 |
if (!empty($access)) { |
W |
1618 |
exec("chmod $access $tConf"); |
|
1619 |
} |
|
1620 |
} |
abdc67
|
1621 |
|
cb8c86
|
1622 |
/** |
W |
1623 |
* Helper function - filter the contents of a config |
|
1624 |
* file by inserting the common ispconfig database |
|
1625 |
* credentials. |
abdc67
|
1626 |
* |
cb8c86
|
1627 |
* @param $tContents |
W |
1628 |
* @return string |
|
1629 |
*/ |
abdc67
|
1630 |
protected function insert_db_credentials($tContents) { |
cb8c86
|
1631 |
global $conf; |
abdc67
|
1632 |
|
cb8c86
|
1633 |
$tContents = str_replace('{mysql_server_ispconfig_user}', $conf["mysql"]["ispconfig_user"], $tContents); |
W |
1634 |
$tContents = str_replace('{mysql_server_ispconfig_password}', $conf["mysql"]["ispconfig_password"], $tContents); |
|
1635 |
$tContents = str_replace('{mysql_server_database}', $conf["mysql"]["database"], $tContents); |
|
1636 |
$tContents = str_replace('{mysql_server_ip}', $conf["mysql"]["ip"], $tContents); |
|
1637 |
$tContents = str_replace('{mysql_server_host}',$conf['mysql']['host'], $tContents); |
|
1638 |
$tContents = str_replace('{mysql_server_port}',$conf["mysql"]["port"], $tContents); |
abdc67
|
1639 |
|
cb8c86
|
1640 |
return $tContents; |
W |
1641 |
} |
7393e9
|
1642 |
} |
T |
1643 |
|
be3234
|
1644 |
?> |