Marius Cramer
2014-08-13 31230cb7cda673db7a96fb14d93dfaf9262c74cf
commit | author | age
8896ab 1 <?php
N 2
3 /*
4 Copyright (c) 2007-2010, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 /*
32     ISPConfig 3 updater.
33 */
34
35 error_reporting(E_ALL|E_STRICT);
36
992797 37 define('INSTALLER_RUN', true);
MC 38
8896ab 39 //** The banner on the command line
7fe908 40 echo "\n\n".str_repeat('-', 80)."\n";
8896ab 41 echo " _____ ___________   _____              __ _         ____
N 42 |_   _/  ___| ___ \ /  __ \            / _(_)       /__  \
43   | | \ `--.| |_/ / | /  \/ ___  _ __ | |_ _  __ _    _/ /
44   | |  `--. \  __/  | |    / _ \| '_ \|  _| |/ _` |  |_ |
45  _| |_/\__/ / |     | \__/\ (_) | | | | | | | (_| | ___\ \
46  \___/\____/\_|      \____/\___/|_| |_|_| |_|\__, | \____/
47                                               __/ |
48                                              |___/ ";
7fe908 49 echo "\n".str_repeat('-', 80)."\n";
8896ab 50 echo "\n\n>> Update  \n\n";
N 51
52 //** Include the library with the basic installer functions
7fe908 53 require_once 'lib/install.lib.php';
8896ab 54
N 55 //** Include the library with the basic updater functions
7fe908 56 require_once 'lib/update.lib.php';
8896ab 57
N 58 //** Include the base class of the installer class
7fe908 59 require_once 'lib/installer_base.lib.php';
8896ab 60
N 61 //** Ensure that current working directory is install directory
62 $cur_dir = getcwd();
63 if(realpath(dirname(__FILE__)) != $cur_dir) die("Please run installation/update from _inside_ the install directory!\n");
64
65 //** Install logfile
66 define('ISPC_LOG_FILE', '/var/log/ispconfig_install.log');
67 define('ISPC_INSTALL_ROOT', realpath(dirname(__FILE__).'/../'));
68
ccbf14 69 //** Include the templating lib
TB 70 require_once 'lib/classes/tpl.inc.php';
71
8896ab 72 //** Check for ISPConfig 2.x versions
N 73 if(is_dir('/root/ispconfig') || is_dir('/home/admispconfig')) {
74     die('This software cannot be installed on a server wich runs ISPConfig 2.x.');
75 }
76
77 //** Get distribution identifier
78 $dist = get_distname();
79
7fe908 80 include_once "/usr/local/ispconfig/server/lib/config.inc.php";
8896ab 81 $conf_old = $conf;
N 82 unset($conf);
83
84 if($dist['id'] == '') die('Linux distribution or version not recognized.');
85
86 //** Include the distribution-specific installer class library and configuration
7fe908 87 if(is_file('dist/lib/'.$dist['baseid'].'.lib.php')) include_once 'dist/lib/'.$dist['baseid'].'.lib.php';
MC 88 include_once 'dist/lib/'.$dist['id'].'.lib.php';
89 include_once 'dist/conf/'.$dist['id'].'.conf.php';
8896ab 90
N 91 //** Get hostname
92 exec('hostname -f', $tmp_out);
93 $conf['hostname'] = $tmp_out[0];
94 unset($tmp_out);
95
96 //** Set the mysql login information
97 $conf["mysql"]["host"] = $conf_old["db_host"];
98 $conf["mysql"]["database"] = $conf_old["db_database"];
99 $conf['mysql']['charset'] = 'utf8';
100 $conf["mysql"]["ispconfig_user"] = $conf_old["db_user"];
101 $conf["mysql"]["ispconfig_password"] = $conf_old["db_password"];
102 $conf['language'] = $conf_old['language'];
d6b361 103 $conf['theme'] = $conf_old['theme'];
8896ab 104 if($conf['language'] == '{language}') $conf['language'] = 'en';
355efb 105 $conf['timezone'] = (isset($conf_old['timezone']))?$conf_old['timezone']:'UTC';
8cf78b 106 if($conf['timezone'] == '{timezone}' or trim($conf['timezone']) == '') $conf['timezone'] = 'UTC';
992797 107 $conf['language_file_import_enabled'] = (isset($conf_old['language_file_import_enabled']))?$conf_old['language_file_import_enabled']:true;
8896ab 108
N 109 if(isset($conf_old["dbmaster_host"])) $conf["mysql"]["master_host"] = $conf_old["dbmaster_host"];
110 if(isset($conf_old["dbmaster_database"])) $conf["mysql"]["master_database"] = $conf_old["dbmaster_database"];
111 if(isset($conf_old["dbmaster_user"])) $conf["mysql"]["master_ispconfig_user"] = $conf_old["dbmaster_user"];
112 if(isset($conf_old["dbmaster_password"])) $conf["mysql"]["master_ispconfig_password"] = $conf_old["dbmaster_password"];
113
114 //* Check if this is a master / slave setup
115 if($conf["mysql"]["master_host"] != '' && $conf["mysql"]["host"] != $conf["mysql"]["master_host"]) {
116     $conf['mysql']['master_slave_setup'] = 'y';
117 }
118
119 // Resolve the IP address of the mysql hostname.
120 if(!$conf['mysql']['ip'] = gethostbyname($conf['mysql']['host'])) die('Unable to resolve hostname'.$conf['mysql']['host']);
121
122 $conf['server_id'] = intval($conf_old["server_id"]);
123 $conf['ispconfig_log_priority'] = $conf_old["log_priority"];
124
125 $inst = new installer();
126 $inst->is_update = true;
127
128 //** Detect the installed applications
129 $inst->find_installed_apps();
130
8cf78b 131 echo "This application will update ISPConfig 3 on your server.\n\n";
T 132
133 //* Make a backup before we start the update
7fe908 134 $do_backup = $inst->simple_query('Shall the script create a ISPConfig backup in /var/backup/ now?', array('yes', 'no'), 'yes');
8cf78b 135 if($do_backup == 'yes') {
7fe908 136
8cf78b 137     //* Create the backup directory
cc6568 138     $backup_path = '/var/backup/ispconfig_'.@date('Y-m-d_H-i');
8cf78b 139     $conf['backup_path'] = $backup_path;
T 140     exec("mkdir -p $backup_path");
141     exec("chown root:root $backup_path");
142     exec("chmod 700 $backup_path");
7fe908 143
8cf78b 144     //* Do the backup
T 145     swriteln('Creating backup of "/usr/local/ispconfig" directory...');
7fe908 146     exec("tar pcfz $backup_path/ispconfig_software.tar.gz /usr/local/ispconfig 2> /dev/null", $out, $returnvar);
8cf78b 147     if($returnvar != 0) die("Backup failed. We stop here...\n");
7fe908 148
8cf78b 149     swriteln('Creating backup of "/etc" directory...');
7fe908 150     exec("tar pcfz $backup_path/etc.tar.gz /etc 2> /dev/null", $out, $returnvar);
8cf78b 151     if($returnvar != 0) die("Backup failed. We stop here...\n");
7fe908 152
8cf78b 153     exec("chown root:root $backup_path/*.tar.gz");
T 154     exec("chmod 700 $backup_path/*.tar.gz");
155 }
156
8896ab 157
N 158 //** Initialize the MySQL server connection
7fe908 159 include_once 'lib/mysql.lib.php';
8896ab 160
N 161 //** Database update is a bit brute force and should be rebuild later ;)
162
163 /*
164  * Try to read the DB-admin settings
165  */
7fe908 166 $clientdb_host   = '';
MC 167 $clientdb_user   = '';
168 $clientdb_password  = '';
169 include_once "/usr/local/ispconfig/server/lib/mysql_clientdb.conf";
8896ab 170 $conf["mysql"]["admin_user"] = $clientdb_user;
N 171 $conf["mysql"]["admin_password"] = $clientdb_password;
7fe908 172 $clientdb_host   = '';
MC 173 $clientdb_user   = '';
174 $clientdb_password  = '';
8896ab 175
edf806 176 //** Test mysql root connection
T 177 $finished = false;
178 do {
7fe908 179     if(@mysql_connect($conf["mysql"]["host"], $conf["mysql"]["admin_user"], $conf["mysql"]["admin_password"])) {
edf806 180         $finished = true;
T 181     } else {
182         swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error());
183         $conf["mysql"]["admin_password"] = $inst->free_query('MySQL root password', $conf['mysql']['admin_password']);
184     }
185 } while ($finished == false);
186 unset($finished);
8896ab 187
N 188 /*
7fe908 189  *  Prepare the dump of the database
8896ab 190  */
N 191 prepareDBDump();
192
193 //* initialize the database
194 $inst->db = new db();
195
196 //* initialize the master DB, if we have a multiserver setup
197 if($conf['mysql']['master_slave_setup'] == 'y') {
7fe908 198     //** Get MySQL root credentials
MC 199     $finished = false;
200     do {
201         $tmp_mysql_server_host = $inst->free_query('MySQL master server hostname', $conf['mysql']['master_host']);
202         $tmp_mysql_server_admin_user = $inst->free_query('MySQL master server root username', $conf['mysql']['master_admin_user']);
203         $tmp_mysql_server_admin_password = $inst->free_query('MySQL master server root password', $conf['mysql']['master_admin_password']);
204         $tmp_mysql_server_database = $inst->free_query('MySQL master server database name', $conf['mysql']['master_database']);
205
206         //* Initialize the MySQL server connection
207         if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
208             $conf['mysql']['master_host'] = $tmp_mysql_server_host;
209             $conf['mysql']['master_admin_user'] = $tmp_mysql_server_admin_user;
210             $conf['mysql']['master_admin_password'] = $tmp_mysql_server_admin_password;
211             $conf['mysql']['master_database'] = $tmp_mysql_server_database;
212             $finished = true;
213         } else {
214             swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error());
215         }
216     } while ($finished == false);
217     unset($finished);
218
219     // initialize the connection to the master database
220     $inst->dbmaster = new db();
221     if($inst->dbmaster->linkId) $inst->dbmaster->closeConn();
222     $inst->dbmaster->dbHost = $conf['mysql']["master_host"];
223     $inst->dbmaster->dbName = $conf['mysql']["master_database"];
224     $inst->dbmaster->dbUser = $conf['mysql']["master_admin_user"];
225     $inst->dbmaster->dbPass = $conf['mysql']["master_admin_password"];
8896ab 226 } else {
N 227     $inst->dbmaster = $inst->db;
228 }
229
230 /*
231  *  Check all tables
232 */
233 checkDbHealth();
234
235 /*
236  *  dump the new Database and reconfigure the server.ini
237  */
238 updateDbAndIni();
239
240 /*
241  * Reconfigure the permisson if needed
242  * (if this is done at client side, only this client is updated.
243  * If this is done at server side, all clients are updated.
244  */
245 //if($conf_old['dbmaster_user'] != '' or $conf_old['dbmaster_host'] != '') {
7fe908 246 //** Update master database rights
MC 247 $reconfigure_master_database_rights_answer = $inst->simple_query('Reconfigure Permissions in master database?', array('yes', 'no'), 'no');
8896ab 248
7fe908 249 if($reconfigure_master_database_rights_answer == 'yes') {
MC 250     $inst->grant_master_database_rights();
251 }
8896ab 252 //}
N 253
254 //** Shall the services be reconfigured during update
7fe908 255 $reconfigure_services_answer = $inst->simple_query('Reconfigure Services?', array('yes', 'no'), 'yes');
8896ab 256
N 257 if($reconfigure_services_answer == 'yes') {
7fe908 258
8896ab 259     if($conf['services']['mail']) {
N 260         //** Configure postfix
261         swriteln('Configuring Postfix');
262         $inst->configure_postfix('dont-create-certs');
7fe908 263
8896ab 264         //** Configure mailman
f9d95c 265         if($conf['mailman']['installed'] == true) {
CS 266             swriteln('Configuring Mailman');
267             $inst->configure_mailman('update');
268         }
7fe908 269
8896ab 270         //* Configure Jailkit
N 271         swriteln('Configuring Jailkit');
272         $inst->configure_jailkit();
273
274         if($conf['dovecot']['installed'] == true) {
275             //* Configure dovecot
276             swriteln('Configuring Dovecot');
277             $inst->configure_dovecot();
278         } else {
279             //** Configure saslauthd
280             swriteln('Configuring SASL');
281             $inst->configure_saslauthd();
7fe908 282
8896ab 283             //** Configure PAM
N 284             swriteln('Configuring PAM');
285             $inst->configure_pam();
7fe908 286
8896ab 287             //* Configure courier
N 288             swriteln('Configuring Courier');
289             $inst->configure_courier();
290         }
291
292         //** Configure Spamasassin
293         swriteln('Configuring Spamassassin');
294         $inst->configure_spamassassin();
295
296         //** Configure Amavis
297         swriteln('Configuring Amavisd');
298         $inst->configure_amavis();
299
300         //** Configure Getmail
301         swriteln('Configuring Getmail');
302         $inst->configure_getmail();
303     }
7fe908 304
8896ab 305     if($conf['services']['web'] && $conf['pureftpd']['installed'] == true) {
N 306         //** Configure Pureftpd
307         swriteln('Configuring Pureftpd');
308         $inst->configure_pureftpd();
309     }
7fe908 310
8896ab 311     if($conf['services']['dns']) {
N 312         //* Configure DNS
313         if($conf['powerdns']['installed'] == true) {
314             swriteln('Configuring PowerDNS');
315             $inst->configure_powerdns();
316         } elseif($conf['bind']['installed'] == true) {
317             swriteln('Configuring BIND');
318             $inst->configure_bind();
319         } else {
320             swriteln('Configuring MyDNS');
321             $inst->configure_mydns();
322         }
323     }
7fe908 324
8896ab 325     if($conf['services']['web']) {
4ffb51 326         if($conf['webserver']['server_type'] == 'apache'){
F 327             //** Configure Apache
328             swriteln('Configuring Apache');
329             $inst->configure_apache();
7fe908 330
4ffb51 331             //** Configure vlogger
F 332             swriteln('Configuring vlogger');
333             $inst->configure_vlogger();
334         } else {
335             //** Configure nginx
336             swriteln('Configuring nginx');
337             $inst->configure_nginx();
338         }
7fe908 339
8896ab 340         //** Configure apps vhost
N 341         swriteln('Configuring Apps vhost');
342         $inst->configure_apps_vhost();
343     }
344
345
346     //* Configure DBServer
347     swriteln('Configuring Database');
348     $inst->configure_dbserver();
349
7fe908 350
8896ab 351     if($conf['services']['firewall']) {
992797 352         if($conf['bastille']['installed'] == true) {
8896ab 353             //* Configure Bastille Firewall
N 354             swriteln('Configuring Bastille Firewall');
992797 355             $inst->configure_firewall();
8896ab 356         }
N 357     }
7fe908 358
4ffb51 359     /*
8896ab 360     if($conf['squid']['installed'] == true) {
N 361         swriteln('Configuring Squid');
362         $inst->configure_squid();
363     } else if($conf['nginx']['installed'] == true) {
364         swriteln('Configuring Nginx');
365         $inst->configure_nginx();
366     }
4ffb51 367     */
8896ab 368 }
N 369
370 //** Configure ISPConfig
371 swriteln('Updating ISPConfig');
6ba4fa 372 if($conf['apache']['installed'] == true){
FT 373     if(!is_file($conf['apache']['vhost_conf_dir'].'/ispconfig.vhost')) $inst->install_ispconfig_interface = false;
374 }
375 if($conf['nginx']['installed'] == true){
376     if(!is_file($conf['nginx']['vhost_conf_dir'].'/ispconfig.vhost')) $inst->install_ispconfig_interface = false;
377 }
8896ab 378
b67344 379 if ($conf['services']['web'] && $inst->install_ispconfig_interface) {
8896ab 380     //** Customise the port ISPConfig runs on
N 381     $ispconfig_port_number = get_ispconfig_port_number();
4ffb51 382     if($conf['webserver']['server_type'] == 'nginx'){
F 383         $conf['nginx']['vhost_port'] = $inst->free_query('ISPConfig Port', $ispconfig_port_number);
384     } else {
385         $conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', $ispconfig_port_number);
386     }
7fe908 387
MC 388
8896ab 389     // $ispconfig_ssl_default = (is_ispconfig_ssl_enabled() == true)?'y':'n';
7fe908 390     if(strtolower($inst->simple_query('Create new ISPConfig SSL certificate', array('yes', 'no'), 'no')) == 'yes') {
8896ab 391         $inst->make_ispconfig_ssl_cert();
N 392     }
393 }
394
395 $inst->install_ispconfig();
396
397 //** Configure Crontab
7fe908 398 $update_crontab_answer = $inst->simple_query('Reconfigure Crontab?', array('yes', 'no'), 'yes');
8896ab 399 if($update_crontab_answer == 'yes') {
N 400     swriteln('Updating Crontab');
401     $inst->install_crontab();
402 }
403
404 //** Restart services:
405 if($reconfigure_services_answer == 'yes') {
406     swriteln('Restarting services ...');
3327ed 407     if($conf['mysql']['installed'] == true && $conf['mysql']['init_script'] != '') system($inst->getinitcommand($conf['mysql']['init_script'], 'restart'));
8896ab 408     if($conf['services']['mail']) {
3327ed 409         if($conf['postfix']['installed'] == true && $conf['postfix']['init_script'] != '') system($inst->getinitcommand($conf['postfix']['init_script'], 'restart'));
FT 410         if($conf['saslauthd']['installed'] == true && $conf['saslauthd']['init_script'] != '') system($inst->getinitcommand($conf['saslauthd']['init_script'], 'restart'));
411         if($conf['amavis']['installed'] == true && $conf['amavis']['init_script'] != '') system($inst->getinitcommand($conf['amavis']['init_script'], 'restart'));
412         if($conf['clamav']['installed'] == true && $conf['clamav']['init_script'] != '') system($inst->getinitcommand($conf['clamav']['init_script'], 'restart'));
413         if($conf['courier']['installed'] == true){
414             if($conf['courier']['courier-authdaemon'] != '') system($inst->getinitcommand($conf['courier']['courier-authdaemon'], 'restart'));
415             if($conf['courier']['courier-imap'] != '') system($inst->getinitcommand($conf['courier']['courier-imap'], 'restart'));
416             if($conf['courier']['courier-imap-ssl'] != '') system($inst->getinitcommand($conf['courier']['courier-imap-ssl'], 'restart'));
417             if($conf['courier']['courier-pop'] != '') system($inst->getinitcommand($conf['courier']['courier-pop'], 'restart'));
418             if($conf['courier']['courier-pop-ssl'] != '') system($inst->getinitcommand($conf['courier']['courier-pop-ssl'], 'restart'));
419         }
420         if($conf['dovecot']['installed'] == true && $conf['dovecot']['init_script'] != '') system($inst->getinitcommand($conf['dovecot']['init_script'], 'restart'));
421         if($conf['mailman']['installed'] == true && $conf['mailman']['init_script'] != '') system('nohup '.$inst->getinitcommand($conf['mailman']['init_script'], 'restart').' >/dev/null 2>&1 &');
8896ab 422     }
N 423     if($conf['services']['web']) {
33bcd0 424         if($conf['webserver']['server_type'] == 'apache' && $conf['apache']['init_script'] != '') system($inst->getinitcommand($conf['apache']['init_script'], 'restart'));
4ffb51 425         //* Reload is enough for nginx
F 426         if($conf['webserver']['server_type'] == 'nginx'){
33bcd0 427             if($conf['nginx']['php_fpm_init_script'] != '') system($inst->getinitcommand($conf['nginx']['php_fpm_init_script'], 'reload'));
FT 428             if($conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'reload'));
4ffb51 429         }
3327ed 430         if($conf['pureftpd']['installed'] == true && $conf['pureftpd']['init_script'] != '') system($inst->getinitcommand($conf['pureftpd']['init_script'], 'restart'));
8896ab 431     }
N 432     if($conf['services']['dns']) {
33bcd0 433         if($conf['mydns']['installed'] == true && $conf['mydns']['init_script'] != '') system($inst->getinitcommand($conf['mydns']['init_script'], 'restart').' &> /dev/null');
FT 434         if($conf['powerdns']['installed'] == true && $conf['powerdns']['init_script'] != '') system($inst->getinitcommand($conf['powerdns']['init_script'], 'restart').' &> /dev/null');
435         if($conf['bind']['installed'] == true && $conf['bind']['init_script'] != '') system($inst->getinitcommand($conf['bind']['init_script'], 'restart').' &> /dev/null');
8896ab 436     }
7fe908 437
8896ab 438     if($conf['services']['proxy']) {
7fe908 439         // if($conf['squid']['installed'] == true && $conf['squid']['init_script'] != '' && is_executable($conf['init_scripts'].'/'.$conf['squid']['init_script']))     system($conf['init_scripts'].'/'.$conf['squid']['init_script'].' restart &> /dev/null');
33bcd0 440         if($conf['nginx']['installed'] == true && $conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'restart').' &> /dev/null');
8896ab 441     }
7fe908 442
8896ab 443     if($conf['services']['firewall']) {
7fe908 444         //if($conf['ufw']['installed'] == true && $conf['ufw']['init_script'] != '' && is_executable($conf['init_scripts'].'/'.$conf['ufw']['init_script']))     system($conf['init_scripts'].'/'.$conf['ufw']['init_script'].' restart &> /dev/null');
8896ab 445     }
N 446 }
447
448 echo "Update finished.\n";
449
450 ?>