Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
commit | author | age
532ae5 1 <?php
L 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 installer.
b04e82 33     
TB 34     -------------------------------------------------------------------------------------
35     - Interactive install
36     -------------------------------------------------------------------------------------
37     run:
38     
39     php install.php
40     
41     -------------------------------------------------------------------------------------
42     - Noninteractive (autoinstall) mode
43     -------------------------------------------------------------------------------------
44     
45     The autoinstall mode can read the installer questions from a .ini style file or from
46     a php config file. Examples for both file types are in the docs folder. 
47     See autoinstall.ini.sample and autoinstall.conf_sample.php.
48     
49     run:
50     
51     php install.php --autoinstall=autoinstall.ini
52     
53     or
54     
55     php install.php --autoinstall=autoinstall.conf.php
56     
532ae5 57 */
L 58
59 error_reporting(E_ALL|E_STRICT);
60
7334d4 61 define('INSTALLER_RUN', true);
T 62
532ae5 63 //** The banner on the command line
b1a6a5 64 echo "\n\n".str_repeat('-', 80)."\n";
532ae5 65 echo " _____ ___________   _____              __ _         ____
L 66 |_   _/  ___| ___ \ /  __ \            / _(_)       /__  \
67   | | \ `--.| |_/ / | /  \/ ___  _ __ | |_ _  __ _    _/ /
68   | |  `--. \  __/  | |    / _ \| '_ \|  _| |/ _` |  |_ |
69  _| |_/\__/ / |     | \__/\ (_) | | | | | | | (_| | ___\ \
70  \___/\____/\_|      \____/\___/|_| |_|_| |_|\__, | \____/
71                                               __/ |
72                                              |___/ ";
b1a6a5 73 echo "\n".str_repeat('-', 80)."\n";
532ae5 74 echo "\n\n>> Initial configuration  \n\n";
L 75
76 //** Include the library with the basic installer functions
b1a6a5 77 require_once 'lib/install.lib.php';
532ae5 78
L 79 //** Include the base class of the installer class
b1a6a5 80 require_once 'lib/installer_base.lib.php';
532ae5 81
L 82 //** Ensure that current working directory is install directory
83 $cur_dir = getcwd();
84 if(realpath(dirname(__FILE__)) != $cur_dir) {
85     chdir( realpath(dirname(__FILE__)) );
86 }
87
88 //** Install logfile
89 define('ISPC_LOG_FILE', '/var/log/ispconfig_install.log');
90 define('ISPC_INSTALL_ROOT', realpath(dirname(__FILE__).'/../'));
91
ccbf14 92 //** Include the templating lib
TB 93 require_once 'lib/classes/tpl.inc.php';
94
532ae5 95 //** Check for existing installation
L 96 /*if(is_dir("/usr/local/ispconfig")) {
97     die('We will stop here. There is already a ISPConfig installation, use the update script to update this installation.');
98 }*/
99
100 //** Get distribution identifier
101 $dist = get_distname();
102
103 if($dist['id'] == '') die('Linux distribution or version not recognized.');
104
bcd725 105 //** Include the autoinstaller configuration (for non-interactive setups)
FT 106 error_reporting(E_ALL ^ E_NOTICE);
b04e82 107
TB 108 //** Get commandline options
109 $cmd_opt = getopt('', array('autoinstall::'));
110
111 //** Load autoinstall file
112 if(isset($cmd_opt['autoinstall']) && is_file($cmd_opt['autoinstall'])) {
113     $path_parts = pathinfo($cmd_opt['autoinstall']);
114     if($path_parts['extension'] == 'php') {
115         include_once $cmd_opt['autoinstall'];
116     } elseif($path_parts['extension'] == 'ini') {
117         $tmp = ini_to_array(file_get_contents('autoinstall.ini'));
c8509b 118         if(!is_array($tmp['install'])) $tmp['install'] = array();
MC 119         if(!is_array($tmp['ssl_cert'])) $tmp['ssl_cert'] = array();
120         if(!is_array($tmp['expert'])) $tmp['expert'] = array();
121         if(!is_array($tmp['update'])) $tmp['update'] = array();
b04e82 122         $autoinstall = $tmp['install'] + $tmp['ssl_cert'] + $tmp['expert'] + $tmp['update'];
TB 123         unset($tmp);
124     }
125     unset($path_parts);
126     define('AUTOINSTALL', true);
127 } else {
128     $autoinstall = array();
129     define('AUTOINSTALL', false);
130 }
131
bcd725 132
532ae5 133 //** Include the distribution-specific installer class library and configuration
b1a6a5 134 if(is_file('dist/lib/'.$dist['baseid'].'.lib.php')) include_once 'dist/lib/'.$dist['baseid'].'.lib.php';
MC 135 include_once 'dist/lib/'.$dist['id'].'.lib.php';
136 include_once 'dist/conf/'.$dist['id'].'.conf.php';
532ae5 137
L 138 //****************************************************************************************************
b1a6a5 139 //** Installer Interface
532ae5 140 //****************************************************************************************************
L 141 $inst = new installer();
cc45ab 142 if (!$inst->get_php_version()) die('ISPConfig requieres PHP '.$inst->min_php."\n");
60b700 143
532ae5 144 swriteln($inst->lng('    Following will be a few questions for primary configuration so be careful.'));
L 145 swriteln($inst->lng('    Default values are in [brackets] and can be accepted with <ENTER>.'));
146 swriteln($inst->lng('    Tap in "quit" (without the quotes) to stop the installer.'."\n\n"));
147
148 //** Check log file is writable (probably not root or sudo)
149 if(!is_writable(dirname(ISPC_LOG_FILE))){
b1a6a5 150     die("ERROR: Cannot write to the ".dirname(ISPC_LOG_FILE)." directory. Are you root or sudo ?\n\n");
532ae5 151 }
L 152
153 if(is_dir('/root/ispconfig') || is_dir('/home/admispconfig')) {
154     die('This software cannot be installed on a server wich runs ISPConfig 2.x.');
155 }
156
157 if(is_dir('/usr/local/ispconfig')) {
158     die('ISPConfig 3 installation found. Please use update.php instead if install.php to update the installation.');
159 }
160
161 //** Detect the installed applications
162 $inst->find_installed_apps();
163
8cf78b 164 //** Select the language and set default timezone
b04e82 165 $conf['language'] = $inst->simple_query('Select language', array('en', 'de'), 'en','language');
3898c9 166 $conf['timezone'] = get_system_timezone();
532ae5 167
992797 168 //* Set default theme
f598b0 169 $conf['theme'] = 'default';
992797 170 $conf['language_file_import_enabled'] = true;
f598b0 171
532ae5 172 //** Select installation mode
b04e82 173 $install_mode = $inst->simple_query('Installation mode', array('standard', 'expert'), 'standard','install_mode');
532ae5 174
L 175
176 //** Get the hostname
177 $tmp_out = array();
178 exec('hostname -f', $tmp_out);
5a56e6 179 $conf['hostname'] = @$tmp_out[0];
7eade0 180 unset($tmp_out);
bb690d 181 //** Prevent empty hostname
FS 182 $check = false;
183 do {
184     $conf['hostname'] = $inst->free_query('Full qualified hostname (FQDN) of the server, eg server1.domain.tld ', $conf['hostname'], 'hostname');
185     $conf['hostname']=trim($conf['hostname']);
186     $check = @($conf['hostname'] !== '')?true:false;
187     if(!$check) swriteln('Hostname may not be empty.');
188 } while (!$check);
ee405d 189
532ae5 190 // Check if the mysql functions are loaded in PHP
f1926a 191 if(!function_exists('mysqli_connect')) die('No PHP MySQLi functions available. Please ensure that the PHP MySQL module is loaded.');
532ae5 192
L 193 //** Get MySQL root credentials
194 $finished = false;
195 do {
b04e82 196     $tmp_mysql_server_host = $inst->free_query('MySQL server hostname', $conf['mysql']['host'],'mysql_hostname');     
82e9b9 197     $tmp_mysql_server_port = $inst->free_query('MySQL server port', $conf['mysql']['port'],'mysql_port');
b04e82 198     $tmp_mysql_server_admin_user = $inst->free_query('MySQL root username', $conf['mysql']['admin_user'],'mysql_root_user');     
TB 199     $tmp_mysql_server_admin_password = $inst->free_query('MySQL root password', $conf['mysql']['admin_password'],'mysql_root_password');     
200     $tmp_mysql_server_database = $inst->free_query('MySQL database to create', $conf['mysql']['database'],'mysql_database');     
201     $tmp_mysql_server_charset = $inst->free_query('MySQL charset', $conf['mysql']['charset'],'mysql_charset');
bcd725 202     
8cf78b 203     if($install_mode == 'expert') {
T 204         swriteln("The next two questions are about the internal ISPConfig database user and password.\nIt is recommended to accept the defaults which are 'ispconfig' as username and a random password.\nIf you use a different password, use only numbers and chars for the password.\n");
bcd725 205         
b04e82 206         $conf['mysql']['ispconfig_user'] = $inst->free_query('ISPConfig mysql database username', $conf['mysql']['ispconfig_user'],'mysql_ispconfig_user');     
TB 207         $conf['mysql']['ispconfig_password'] = $inst->free_query('ISPConfig mysql database password', $conf['mysql']['ispconfig_password'],'mysql_ispconfig_password');
8cf78b 208     }
b1a6a5 209
532ae5 210     //* Initialize the MySQL server connection
7baf73 211     if(@mysqli_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password, '', (int)$tmp_mysql_server_port)) {
532ae5 212         $conf['mysql']['host'] = $tmp_mysql_server_host;
82e9b9 213         $conf['mysql']['port'] = $tmp_mysql_server_port;
532ae5 214         $conf['mysql']['admin_user'] = $tmp_mysql_server_admin_user;
L 215         $conf['mysql']['admin_password'] = $tmp_mysql_server_admin_password;
216         $conf['mysql']['database'] = $tmp_mysql_server_database;
217         $conf['mysql']['charset'] = $tmp_mysql_server_charset;
218         $finished = true;
219     } else {
8a8cc2 220         swriteln($inst->lng('Unable to connect to the specified MySQL server').' '.mysqli_connect_error());
532ae5 221     }
L 222 } while ($finished == false);
223 unset($finished);
224
225 // Resolve the IP address of the MySQL hostname.
b1a6a5 226 $tmp = explode(':', $conf['mysql']['host']);
532ae5 227 if(!$conf['mysql']['ip'] = gethostbyname($tmp[0])) die('Unable to resolve hostname'.$tmp[0]);
L 228 unset($tmp);
229
230
231 //** Initializing database connection
b1a6a5 232 include_once 'lib/mysql.lib.php';
532ae5 233 $inst->db = new db();
L 234
235 //** Begin with standard or expert installation
a75c81 236
FS 237 $conf['services']['mail'] = false;
238 $conf['services']['web'] = false;
239 $conf['services']['dns'] = false;
240 $conf['services']['file'] = false;
241 $conf['services']['db'] = true;
242 $conf['services']['vserver'] = false;
243 $conf['services']['firewall'] = false;
244 $conf['services']['proxy'] = false;
245 $conf['services']['xmpp'] = false;
246
532ae5 247 if($install_mode == 'standard') {
b1a6a5 248
d22277 249     $inst->dbmaster = $inst->db;
MB 250     
532ae5 251     //* Create the MySQL database
L 252     $inst->configure_database();
b1a6a5 253
a75c81 254     //* Insert the Server record into the database
FS 255     $inst->add_database_server_record();
256
257     //* Configure Postgrey
bedf79 258     $force = @($conf['postgrey']['installed']) ? true : $inst->force_configure_app('Postgrey', false);
a75c81 259     if($force) swriteln('Configuring Postgrey');
FS 260
261     //* Configure Postfix
bedf79 262     $force = @($conf['postfix']['installed']) ? true : $inst->force_configure_app('Postfix', false);
a75c81 263     if($force) {
FS 264         swriteln('Configuring Postfix');
265         $inst->configure_postfix();
266         $conf['services']['mail'] = true;
267     }
268
269     if($conf['services']['mail']) {
270
271         //* Configure Mailman
bedf79 272         $force = @($conf['mailman']['installed']) ? true : $inst->force_configure_app('Mailman', false);
a75c81 273         if($force) {
FS 274             swriteln('Configuring Mailman');
275             $inst->configure_mailman();
276         } 
277
278         //* Check for Dovecot and Courier
279         if(!$conf['dovecot']['installed'] && !$conf['courier']['installed']) {
bedf79 280             $conf['dovecot']['installed'] = $inst->force_configure_app('Dovecot', false);
FS 281             $conf['courier']['installed'] = $inst->force_configure_app('Courier', false);
a75c81 282         }
FS 283         //* Configure Mailserver - Dovecot or Courier
284         if($conf['dovecot']['installed'] && $conf['courier']['installed']) {
285             $mail_server_to_use = $inst->simple_query('Dovecot and Courier detected. Select server to use with ISPConfig:', array('dovecot', 'courier'), 'dovecot','mail_server');
286             if($mail_server_to_use == 'dovecot'){
287                 $conf['courier']['installed'] = false;
288             } else {
289                 $conf['dovecot']['installed'] = false;
290             }
291         }
292         //* Configure Dovecot
293         if($conf['dovecot']['installed']) {
294             swriteln('Configuring Dovecot');
295             $inst->configure_dovecot();
296         }
297         //* Configure Courier
298         if($conf['courier']['installed']) {
299             swriteln('Configuring Courier');
300             $inst->configure_courier();
301             swriteln('Configuring SASL');
302             $inst->configure_saslauthd();
303             swriteln('Configuring PAM');
304             $inst->configure_pam();
305         }
306
307         //* Configure Spamasassin
bedf79 308         $force = @($conf['spamassassin']['installed']) ? true : $inst->force_configure_app('Spamassassin', false);
a75c81 309         if($force) {
FS 310             swriteln('Configuring Spamassassin');
311             $inst->configure_spamassassin();
312         }
313     
314         //* Configure Amavis
bedf79 315         $force = @($conf['amavis']['installed']) ? true : $inst->force_configure_app('Amavisd', false);
a75c81 316         if($force) {
FS 317             swriteln('Configuring Amavisd');
318             $inst->configure_amavis();
319         }
320
321         //* Configure Getmail
bedf79 322         $force = @($conf['getmail']['installed']) ? true : $inst->force_configure_app('Getmail', false);
a75c81 323         if($force) {
FS 324             swriteln('Configuring Getmail');
325             $inst->configure_getmail();
326         }
327
328     } else swriteln('[ERROR] Postfix not installed - skipping Mail');
329
330     //* Check for DNS
460a60 331 //    if(!$conf['powerdns']['installed'] && !$conf['bind']['installed'] && !$conf['mydns']['installed']) {
FS 332     if(!$conf['bind']['installed'] && !$conf['mydns']['installed']) {
333 //        $conf['powerdns']['installed'] = $inst->force_configure_app('PowerDNS', false);
bedf79 334         $conf['bind']['installed'] = $inst->force_configure_app('BIND', false);
FS 335         $conf['mydns']['installed'] = $inst->force_configure_app('MyDNS', false);
a75c81 336     }
FS 337     //* Configure PowerDNS
460a60 338 /*
a75c81 339     if($conf['powerdns']['installed']) {
FS 340         swriteln('Configuring PowerDNS');
341         $inst->configure_powerdns();
342         $conf['services']['dns'] = true;
343     }
460a60 344 */
a75c81 345     //* Configure Bind
FS 346     if($conf['bind']['installed']) {
347         swriteln('Configuring BIND');
348         $inst->configure_bind();
349         $conf['services']['dns'] = true;
350     }
351     //* Configure MyDNS
352     if($conf['mydns']['installed']) {
353         swriteln('Configuring MyDNS');
354         $inst->configure_mydns();
355         $conf['services']['dns'] = true;
356     }
357
358     //* Configure Jailkit
bedf79 359     $force = @($conf['jailkit']['installed']) ? true : $inst->force_configure_app('Jailkit', false);
a75c81 360     if($force) {
FS 361         swriteln('Configuring Jailkit');
362         $inst->configure_jailkit();
363     }
364
365     //* Configure Pureftpd
bedf79 366     $force = @($conf['pureftpd']['installed']) ? true : $inst->force_configure_app('pureftpd', false);
a75c81 367     if($force) {
FS 368         swriteln('Configuring Pureftpd');
369         $inst->configure_pureftpd();
370     }
371
372     //* Check for Web-Server
373     if(!$conf['apache']['installed'] && !$conf['nginx']['installed']) {
bedf79 374         $conf['apache']['installed'] = $inst->force_configure_app('Apache', false);
FS 375         $conf['nginx']['installed'] = $inst->force_configure_app('nginx', false);
a75c81 376     }
FS 377
4ffb51 378     //* Configure Webserver - Apache or nginx
a75c81 379     if($conf['apache']['installed'] && $conf['nginx']['installed']) {
b04e82 380         $http_server_to_use = $inst->simple_query('Apache and nginx detected. Select server to use for ISPConfig:', array('apache', 'nginx'), 'apache','http_server');
4ffb51 381         if($http_server_to_use == 'apache'){
F 382             $conf['nginx']['installed'] = false;
383         } else {
384             $conf['apache']['installed'] = false;
385         }
386     }
b1a6a5 387
532ae5 388     //* Configure Apache
a75c81 389     if($conf['apache']['installed']){
4ffb51 390         swriteln('Configuring Apache');
F 391         $inst->configure_apache();
a75c81 392         $conf['services']['web'] = true;
FS 393         $conf['services']['file'] = true;
394         //* Configure Vlogger
bedf79 395         $force = @($conf['vlogger']['installed']) ? true : $inst->force_configure_app('vlogger', false);
a75c81 396         if($force) {
FS 397             swriteln('Configuring vlogger');
398             $inst->configure_vlogger();
399         }
400         //* Configure squid
401 /*
402         $force = @($conf['squid']['installed']) ? true : $inst->force_configure_app('squid');
403         if($force) {
404             swriteln('Configuring Squid');
405             $inst->configure_squid();
406             $conf['services']['proxy'] = true;
407         }
408 */
4ffb51 409     }
b1a6a5 410
4ffb51 411     //* Configure nginx
a75c81 412     if($conf['nginx']['installed']){
4ffb51 413         swriteln('Configuring nginx');
F 414         $inst->configure_nginx();
a75c81 415         $conf['services']['web'] = true;
4ffb51 416     }
b1a6a5 417
a75c81 418     //* Configure XMPP
bedf79 419     $force = @($conf['xmpp']['installed']) ? true : $inst->force_configure_app('Metronome XMPP Server', false);
a75c81 420     if($force) {
FS 421         swriteln('Configuring Metronome XMPP Server');
422         $inst->configure_xmpp();
423         $conf['services']['xmpp'] = true;
424     }
b1a6a5 425
a75c81 426     //* Check for Firewall
FS 427     if(!$conf['ufw']['installed'] && !$conf['firewall']['installed']) {
bedf79 428         $conf['ufw']['installed'] = $inst->force_configure_app('Ubuntu Firewall', false);
FS 429         $conf['firewall']['installed'] = $inst->force_configure_app('Bastille Firewall', false);
a75c81 430     }
FS 431     //* Configure Firewall - Ubuntu or Bastille
432     if($conf['ufw']['installed'] && $conf['firewall']['installed']) {
433         $firewall_to_use = $inst->simple_query('Ubuntu and Bastille Firewall detected. Select firewall to use with ISPConfig:', array('bastille', 'ubuntu'), 'bastille','firewall_server');
434         if($firewall_to_use == 'bastille'){
435             $conf['ufw']['installed'] = false;
436         } else {
437             $conf['firewall']['installed'] = false;
438         }
439     }
440     //* Configure Ubuntu Firewall
441     if($conf['ufw']['installed']){
bd68aa 442         swriteln('Configuring Ubuntu Firewall');
MC 443         $inst->configure_ufw_firewall();
444         $conf['services']['firewall'] = true;
a75c81 445     }
FS 446     //* Configure Bastille Firewall
447     if($conf['firewall']['installed']){
bd68aa 448         swriteln('Configuring Bastille Firewall');
MC 449         $inst->configure_bastille_firewall();
a75c81 450         $conf['services']['firewall'] = true;
56ad03 451         $conf['bastille']['installed'] = true;
bd68aa 452     }
c12af9 453
b1a6a5 454     //* Configure Fail2ban
bedf79 455     $force = @($conf['fail2ban']['installed']) ? true : $inst->force_configure_app('Fail2ban', false);
a75c81 456     if($force) {
b1a6a5 457         swriteln('Configuring Fail2ban');
MC 458         $inst->configure_fail2ban();
459     }
460
a75c81 461     //* Configure OpenVZ
bedf79 462     $force = @($conf['openvz']['installed']) ? true : $inst->force_configure_app('OpenVZ', false);
a75c81 463     if($force) {
FS 464         $conf['services']['vserver'] = true;
465         swriteln('Configuring OpenVZ');
80e3c9 466     }
b1a6a5 467
a75c81 468     //** Configure apps vhost
FS 469     swriteln('Configuring Apps vhost');
470     $inst->configure_apps_vhost();
9f94a1 471
532ae5 472     //* Configure ISPConfig
L 473     swriteln('Installing ISPConfig');
b1a6a5 474
532ae5 475     //** Customize the port ISPConfig runs on
b04e82 476     $ispconfig_vhost_port = $inst->free_query('ISPConfig Port', '8080','ispconfig_port');
55cb02 477     $conf['interface_password'] = $inst->free_query('Admin password', 'admin');
272da6 478     if($conf['interface_password'] != 'admin') {
FS 479         $check = false;
480         do {
481             unset($temp_password);
480eba 482             $temp_password = $inst->free_query('Re-enter admin password', '');
272da6 483             $check = @($temp_password == $conf['interface_password'])?true:false;
480eba 484             if(!$check) swriteln('Passwords do not match.');
272da6 485         } while (!$check);
FS 486     }
487     unset($check);
488     unset($temp_password);
dec0df 489     if($conf['apache']['installed'] == true) $conf['apache']['vhost_port']  = $ispconfig_vhost_port;
T 490     if($conf['nginx']['installed'] == true) $conf['nginx']['vhost_port']  = $ispconfig_vhost_port;
491     unset($ispconfig_vhost_port);
532ae5 492
b04e82 493     if(strtolower($inst->simple_query('Do you want a secure (SSL) connection to the ISPConfig web interface', array('y', 'n'), 'y','ispconfig_use_ssl')) == 'y') {     
b1a6a5 494         $inst->make_ispconfig_ssl_cert();
939b92 495     }
M 496
532ae5 497     $inst->install_ispconfig();
b1a6a5 498
532ae5 499     //* Configure DBServer
L 500     swriteln('Configuring DBServer');
501     $inst->configure_dbserver();
502
503     //* Configure ISPConfig
a75c81 504     if($conf['cron']['installed']) {
FS 505         swriteln('Installing ISPConfig crontab');
506         $inst->install_crontab();
507     } else swriteln('[ERROR] Cron not found');
b1a6a5 508
d22277 509     swriteln('Detect IP addresses');
MB 510     $inst->detect_ips();
511
532ae5 512     swriteln('Restarting services ...');
574a16 513     if($conf['mysql']['installed'] == true && $conf['mysql']['init_script'] != '') system($inst->getinitcommand($conf['mysql']['init_script'], 'restart').' >/dev/null 2>&1');
3327ed 514     if($conf['postfix']['installed'] == true && $conf['postfix']['init_script'] != '') system($inst->getinitcommand($conf['postfix']['init_script'], 'restart'));
FT 515     if($conf['saslauthd']['installed'] == true && $conf['saslauthd']['init_script'] != '') system($inst->getinitcommand($conf['saslauthd']['init_script'], 'restart'));
516     if($conf['amavis']['installed'] == true && $conf['amavis']['init_script'] != '') system($inst->getinitcommand($conf['amavis']['init_script'], 'restart'));
517     if($conf['clamav']['installed'] == true && $conf['clamav']['init_script'] != '') system($inst->getinitcommand($conf['clamav']['init_script'], 'restart'));
518     if($conf['courier']['installed'] == true){
519         if($conf['courier']['courier-authdaemon'] != '') system($inst->getinitcommand($conf['courier']['courier-authdaemon'], 'restart'));
520         if($conf['courier']['courier-imap'] != '') system($inst->getinitcommand($conf['courier']['courier-imap'], 'restart'));
521         if($conf['courier']['courier-imap-ssl'] != '') system($inst->getinitcommand($conf['courier']['courier-imap-ssl'], 'restart'));
522         if($conf['courier']['courier-pop'] != '') system($inst->getinitcommand($conf['courier']['courier-pop'], 'restart'));
523         if($conf['courier']['courier-pop-ssl'] != '') system($inst->getinitcommand($conf['courier']['courier-pop-ssl'], 'restart'));
524     }
525     if($conf['dovecot']['installed'] == true && $conf['dovecot']['init_script'] != '') system($inst->getinitcommand($conf['dovecot']['init_script'], 'restart'));
526     if($conf['mailman']['installed'] == true && $conf['mailman']['init_script'] != '') system('nohup '.$inst->getinitcommand($conf['mailman']['init_script'], 'restart').' >/dev/null 2>&1 &');
33bcd0 527     if($conf['apache']['installed'] == true && $conf['apache']['init_script'] != '') system($inst->getinitcommand($conf['apache']['init_script'], 'restart'));
4ffb51 528     //* Reload is enough for nginx
F 529     if($conf['nginx']['installed'] == true){
33bcd0 530         if($conf['nginx']['php_fpm_init_script'] != '') system($inst->getinitcommand($conf['nginx']['php_fpm_init_script'], 'reload'));
FT 531         if($conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'reload'));
4ffb51 532     }
3327ed 533     if($conf['pureftpd']['installed'] == true && $conf['pureftpd']['init_script'] != '') system($inst->getinitcommand($conf['pureftpd']['init_script'], 'restart'));
33bcd0 534     if($conf['mydns']['installed'] == true && $conf['mydns']['init_script'] != '') system($inst->getinitcommand($conf['mydns']['init_script'], 'restart').' &> /dev/null');
FT 535     if($conf['powerdns']['installed'] == true && $conf['powerdns']['init_script'] != '') system($inst->getinitcommand($conf['powerdns']['init_script'], 'restart').' &> /dev/null');
536     if($conf['bind']['installed'] == true && $conf['bind']['init_script'] != '') system($inst->getinitcommand($conf['bind']['init_script'], 'restart').' &> /dev/null');
b1a6a5 537     //if($conf['squid']['installed'] == true && $conf['squid']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['squid']['init_script']))     system($conf['init_scripts'].'/'.$conf['squid']['init_script'].' restart &> /dev/null');
33bcd0 538     if($conf['nginx']['installed'] == true && $conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'restart').' &> /dev/null');
7cf3e9 539     if($conf['ufw']['installed'] == true && $conf['ufw']['init_script'] != '') system($inst->getinitcommand($conf['ufw']['init_script'], 'restart').' &> /dev/null');
9f94a1 540     if($conf['xmpp']['installed'] == true && $conf['xmpp']['init_script'] != '') system($inst->getinitcommand($conf['xmpp']['init_script'], 'restart').' &> /dev/null');
b1a6a5 541
a75c81 542 } else { //* expert mode
b1a6a5 543
532ae5 544     //** Get Server ID
L 545     // $conf['server_id'] = $inst->free_query('Unique Numeric ID of the server','1');
546     // Server ID is an autoInc value of the mysql database now
b04e82 547     if(strtolower($inst->simple_query('Shall this server join an existing ISPConfig multiserver setup', array('y', 'n'), 'n','join_multiserver_setup')) == 'y') {
532ae5 548         $conf['mysql']['master_slave_setup'] = 'y';
b1a6a5 549
532ae5 550         //** Get MySQL root credentials
L 551         $finished = false;
552         do {
b04e82 553             $tmp_mysql_server_host = $inst->free_query('MySQL master server hostname', $conf['mysql']['master_host'],'mysql_master_hostname'); 
82e9b9 554             $tmp_mysql_server_port = $inst->free_query('MySQL master server port', $conf['mysql']['master_port'],'mysql_master_port');
b04e82 555             $tmp_mysql_server_admin_user = $inst->free_query('MySQL master server root username', $conf['mysql']['master_admin_user'],'mysql_master_root_user');     
TB 556             $tmp_mysql_server_admin_password = $inst->free_query('MySQL master server root password', $conf['mysql']['master_admin_password'],'mysql_master_root_password'); 
557             $tmp_mysql_server_database = $inst->free_query('MySQL master server database name', $conf['mysql']['master_database'],'mysql_master_database');
b1a6a5 558
532ae5 559             //* Initialize the MySQL server connection
8a8cc2 560             if(@mysqli_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password, $tmp_mysql_server_database, (int)$tmp_mysql_server_port)) {
532ae5 561                 $conf['mysql']['master_host'] = $tmp_mysql_server_host;
82e9b9 562                 $conf['mysql']['master_port'] = $tmp_mysql_server_port;
532ae5 563                 $conf['mysql']['master_admin_user'] = $tmp_mysql_server_admin_user;
L 564                 $conf['mysql']['master_admin_password'] = $tmp_mysql_server_admin_password;
565                 $conf['mysql']['master_database'] = $tmp_mysql_server_database;
566                 $finished = true;
567             } else {
8a8cc2 568                 swriteln($inst->lng('Unable to connect to mysql server').' '.mysqli_connect_error());
532ae5 569             }
L 570         } while ($finished == false);
571         unset($finished);
b1a6a5 572
532ae5 573         // initialize the connection to the master database
L 574         $inst->dbmaster = new db();
575         if($inst->dbmaster->linkId) $inst->dbmaster->closeConn();
305dda 576         $inst->dbmaster->setDBData($conf['mysql']["master_host"], $conf['mysql']["master_admin_user"], $conf['mysql']["master_admin_password"]);
MC 577         $inst->dbmaster->setDBName($conf['mysql']["master_database"]);
b1a6a5 578
532ae5 579     } else {
L 580         // the master DB is the same then the slave DB
581         $inst->dbmaster = $inst->db;
582     }
b1a6a5 583
532ae5 584     //* Create the mysql database
L 585     $inst->configure_database();
b1a6a5 586
a75c81 587     //* Check for Web-Server
FS 588     if($conf['apache']['installed'] != true && $conf['nginx']['installed'] != true) {
589         $conf['apache']['installed'] = $inst->force_configure_app('Apache');
590         $conf['nginx']['installed'] = $inst->force_configure_app('nginx');
591     }
4ffb51 592     //* Configure Webserver - Apache or nginx
F 593     if($conf['apache']['installed'] == true && $conf['nginx']['installed'] == true) {
b04e82 594         $http_server_to_use = $inst->simple_query('Apache and nginx detected. Select server to use for ISPConfig:', array('apache', 'nginx'), 'apache','http_server');
4ffb51 595         if($http_server_to_use == 'apache'){
F 596             $conf['nginx']['installed'] = false;
a75c81 597             $conf['services']['file'] = true;
4ffb51 598         } else {
F 599             $conf['apache']['installed'] = false;
600         }
601     }
b1a6a5 602
532ae5 603     //* Insert the Server record into the database
L 604     swriteln('Adding ISPConfig server record to database.');
605     swriteln('');
606     $inst->add_database_server_record();
607
b04e82 608     if(strtolower($inst->simple_query('Configure Mail', array('y', 'n') , 'y','configure_mail') ) == 'y') {
b1a6a5 609
532ae5 610         $conf['services']['mail'] = true;
b1a6a5 611
a75c81 612         //* Configure Postgrey
FS 613         $force = @($conf['postgrey']['installed']) ? true : $inst->force_configure_app('Postgrey');
614         if($force) swriteln('Configuring Postgrey');
615
532ae5 616         //* Configure Postfix
a75c81 617         $force = @($conf['postfix']['installed']) ? true : $inst->force_configure_app('Postfix');
FS 618         if($force) {
619             swriteln('Configuring Postfix');
620             $inst->configure_postfix();
621         }
b1a6a5 622
532ae5 623         //* Configure Mailman
a75c81 624         $force = @($conf['mailman']['installed']) ? true : $inst->force_configure_app('Mailman');
FS 625         if($force) {
626             swriteln('Configuring Mailman');
627             $inst->configure_mailman();
628         }
532ae5 629
a75c81 630         //* Check for Dovecot and Courier
FS 631         if(!$conf['dovecot']['installed'] && !$conf['courier']['installed']) {
12ab95 632             $conf['dovecot']['installed'] = $inst->force_configure_app('Dovecot');
FS 633             $conf['courier']['installed'] = $inst->force_configure_app('Courier');
a75c81 634         }
FS 635         //* Configure Mailserver - Dovecot or Courier
636         if($conf['dovecot']['installed'] && $conf['courier']['installed']) {
637             $mail_server_to_use = $inst->simple_query('Dovecot and Courier detected. Select server to use with ISPConfig:', array('dovecot', 'courier'), 'dovecot','mail_server');
638             if($mail_server_to_use == 'dovecot'){
639                 $conf['courier']['installed'] = false;
640             } else {
641                 $conf['dovecot']['installed'] = false;
642             }
643         }
644         //* Configure Dovecot
645         if($conf['dovecot']['installed']) {
532ae5 646             swriteln('Configuring Dovecot');
L 647             $inst->configure_dovecot();
a75c81 648         }
FS 649         //* Configure Courier
650         if($conf['courier']['installed']) {
532ae5 651             swriteln('Configuring Courier');
L 652             $inst->configure_courier();
a75c81 653             swriteln('Configuring SASL');
FS 654             $inst->configure_saslauthd();
655             swriteln('Configuring PAM');
656             $inst->configure_pam();
532ae5 657         }
L 658
659         //* Configure Spamasassin
a75c81 660         $force = @($conf['spamassassin']['installed']) ? true : $inst->force_configure_app('Spamassassin');
FS 661         if($force) {
662             swriteln('Configuring Spamassassin');
663             $inst->configure_spamassassin();
664         }
665     
532ae5 666         //* Configure Amavis
a75c81 667         $force = @($conf['amavis']['installed']) ? true : $inst->force_configure_app('Amavisd');
FS 668         if($force) {
669             swriteln('Configuring Amavisd');
670             $inst->configure_amavis();
671         }
532ae5 672
L 673         //* Configure Getmail
a75c81 674         $force = @($conf['getmail']['installed']) ? true : $inst->force_configure_app('Getmail');
FS 675         if($force) {
676             swriteln('Configuring Getmail');
677             $inst->configure_getmail();
678         }
b1a6a5 679
3327ed 680         if($conf['postfix']['installed'] == true && $conf['postfix']['init_script'] != '') system($inst->getinitcommand($conf['postfix']['init_script'], 'restart'));
FT 681         if($conf['saslauthd']['installed'] == true && $conf['saslauthd']['init_script'] != '') system($inst->getinitcommand($conf['saslauthd']['init_script'], 'restart'));
682         if($conf['amavis']['installed'] == true && $conf['amavis']['init_script'] != '') system($inst->getinitcommand($conf['amavis']['init_script'], 'restart'));
683         if($conf['clamav']['installed'] == true && $conf['clamav']['init_script'] != '') system($inst->getinitcommand($conf['clamav']['init_script'], 'restart'));
684         if($conf['courier']['installed'] == true){
685             if($conf['courier']['courier-authdaemon'] != '') system($inst->getinitcommand($conf['courier']['courier-authdaemon'], 'restart'));
686             if($conf['courier']['courier-imap'] != '') system($inst->getinitcommand($conf['courier']['courier-imap'], 'restart'));
687             if($conf['courier']['courier-imap-ssl'] != '') system($inst->getinitcommand($conf['courier']['courier-imap-ssl'], 'restart'));
688             if($conf['courier']['courier-pop'] != '') system($inst->getinitcommand($conf['courier']['courier-pop'], 'restart'));
689             if($conf['courier']['courier-pop-ssl'] != '') system($inst->getinitcommand($conf['courier']['courier-pop-ssl'], 'restart'));
690         }
691         if($conf['dovecot']['installed'] == true && $conf['dovecot']['init_script'] != '') system($inst->getinitcommand($conf['dovecot']['init_script'], 'restart'));
692         if($conf['mailman']['installed'] == true && $conf['mailman']['init_script'] != '') system('nohup '.$inst->getinitcommand($conf['mailman']['init_script'], 'restart').' >/dev/null 2>&1 &');
532ae5 693     }
b1a6a5 694
a75c81 695     //* Configure Jailkit
FS 696     $force = @($conf['jailkit']['installed']) ? true : $inst->force_configure_app('Jailkit');
697     if($force) {
532ae5 698         swriteln('Configuring Jailkit');
L 699         $inst->configure_jailkit();
700     }
b1a6a5 701
a75c81 702     //* Configure Pureftpd
FS 703     $force = @($conf['pureftpd']['installed']) ? true : $inst->force_configure_app('pureftpd');
704     if($force) {
532ae5 705         swriteln('Configuring Pureftpd');
L 706         $inst->configure_pureftpd();
707     }
d22277 708     
532ae5 709     //** Configure DNS
b04e82 710     if(strtolower($inst->simple_query('Configure DNS Server', array('y', 'n'), 'y','configure_dns')) == 'y') {
532ae5 711         $conf['services']['dns'] = true;
a75c81 712
FS 713         //* Check for DNS
714         if(!$conf['powerdns']['installed'] && !$conf['bind']['installed'] && !$conf['mydns']['installed']) {
715             $conf['powerdns']['installed'] = $inst->force_configure_app('PowerDNS');
716             $conf['bind']['installed'] = $inst->force_configure_app('BIND');
717             $conf['mydns']['installed'] = $inst->force_configure_app('MyDNS');
718         }
719         //* Configure PowerDNS
720         if($conf['powerdns']['installed']) {
532ae5 721             swriteln('Configuring PowerDNS');
L 722             $inst->configure_powerdns();
a75c81 723             $conf['services']['dns'] = true;
FS 724         }
725         //* Configure Bind
726         if($conf['bind']['installed']) {
532ae5 727             swriteln('Configuring BIND');
L 728             $inst->configure_bind();
a75c81 729             $conf['services']['dns'] = true;
FS 730         }
731         //* Configure MyDNS
732         if($conf['mydns']['installed']) {
532ae5 733             swriteln('Configuring MyDNS');
L 734             $inst->configure_mydns();
a75c81 735             $conf['services']['dns'] = true;
532ae5 736         }
b1a6a5 737
532ae5 738     }
b1a6a5 739
a75c81 740     if(strtolower($inst->simple_query('Configure Web Server', array('y', 'n'), 'y','configure_webserver')) == 'y') {
FS 741         $conf['services']['web'] = true;
b1a6a5 742
a75c81 743         //* Configure Apache
FS 744         if($conf['apache']['installed']){
4ffb51 745             swriteln('Configuring Apache');
F 746             $inst->configure_apache();
a75c81 747             $conf['services']['file'] = true;
FS 748             //* Configure Vlogger
749             $force = @($conf['vlogger']['installed']) ? true : $inst->force_configure_app('vlogger');
750             if($force) {
751                 swriteln('Configuring vlogger');
752                 $inst->configure_vlogger();
753             }
754             //* Configure squid
755 /*
756             $force = @($conf['squid']['installed']) ? true : $inst->force_configure_app('squid');
757             if($force) {
758                 swriteln('Configuring Squid');
759                 $inst->configure_squid();
760                 $conf['services']['proxy'] = true;
761                 if($conf['squid']['init_script'] != '' && is_executable($conf['init_scripts'].'/'.$conf['squid']['init_script']))system($conf['init_scripts'].'/'.$conf['squid']['init_script'].' restart &> /dev/null');
762             }
763 */
4ffb51 764         }
a75c81 765         //* Configure nginx
FS 766         if($conf['nginx']['installed']){
4ffb51 767             swriteln('Configuring nginx');
F 768             $inst->configure_nginx();
769         }
532ae5 770     }
b1a6a5 771
319dd9 772     //* Configure OpenVZ
FS 773     $force = @($conf['openvz']['installed']) ? true : $inst->force_configure_app('OpenVZ');
774     if($force) {
775         $conf['services']['vserver'] = true;
776         swriteln('Configuring OpenVZ');
777     }
a75c81 778
b04e82 779     if(strtolower($inst->simple_query('Configure Firewall Server', array('y', 'n'), 'y','configure_firewall')) == 'y') {
a75c81 780         //* Check for Firewall
FS 781         if(!$conf['ufw']['installed'] && !$conf['firewall']['installed']) {
782             $conf['ufw']['installed'] = $inst->force_configure_app('Ubuntu Firewall');
783             $conf['firewall']['installed'] = $inst->force_configure_app('Bastille Firewall');
784         }
785         //* Configure Firewall - Ubuntu or Bastille
786         if($conf['ufw']['installed'] && $conf['firewall']['installed']) {
787             $firewall_to_use = $inst->simple_query('Ubuntu and Bastille Firewall detected. Select firewall to use with ISPConfig:', array('bastille', 'ubuntu'), 'bastille','firewall_server');
788             if($firewall_to_use == 'bastille'){
789                 $conf['ufw']['installed'] = false;
790             } else {
791                 $conf['firewall']['installed'] = false;
792             }
793         }
794         //* Configure Ubuntu Firewall
795         if($conf['ufw']['installed']){
796             swriteln('Configuring Ubuntu Firewall');
797             $inst->configure_ufw_firewall();
798             $conf['services']['firewall'] = true;
799         }
800         //* Configure Bastille Firewall
801         if($conf['firewall']['installed']){
802             swriteln('Configuring Bastille Firewall');
803             $inst->configure_bastille_firewall();
804             $conf['services']['firewall'] = true;
805         }
80e3c9 806     }
b1a6a5 807
a75c81 808     //* Configure XMPP
FS 809     $force = @($conf['xmpp']['installed']) ? true : $inst->force_configure_app('Metronome XMPP Server');
810     if($force) {
811         swriteln('Configuring Metronome XMPP Server');
812         $inst->configure_xmpp();
813         $conf['services']['xmpp'] = true;
814     }
9f94a1 815
532ae5 816     //** Configure ISPConfig :-)
7b47c0 817     $install_ispconfig_interface_default = ($conf['mysql']['master_slave_setup'] == 'y')?'n':'y';
b04e82 818     if(strtolower($inst->simple_query('Install ISPConfig Web Interface', array('y', 'n'), $install_ispconfig_interface_default,'install_ispconfig_web_interface')) == 'y') {
532ae5 819         swriteln('Installing ISPConfig');
b1a6a5 820
532ae5 821         //** We want to check if the server is a module or cgi based php enabled server
L 822         //** TODO: Don't always ask for this somehow ?
823         /*
824         $fast_cgi = $inst->simple_query('CGI PHP Enabled Server?', array('yes','no'),'no');
825
826         if($fast_cgi == 'yes') {
827              $alias = $inst->free_query('Script Alias', '/php/');
828              $path = $inst->free_query('Script Alias Path', '/path/to/cgi/bin');
829              $conf['apache']['vhost_cgi_alias'] = sprintf('ScriptAlias %s %s', $alias, $path);
830         } else {
831              $conf['apache']['vhost_cgi_alias'] = "";
832         }
833         */
834
835         //** Customise the port ISPConfig runs on
b04e82 836         $ispconfig_vhost_port = $inst->free_query('ISPConfig Port', '8080','ispconfig_port');
55cb02 837         $conf['interface_password'] = $inst->free_query('Admin password', 'admin');
272da6 838         if($conf['interface_password'] != 'admin') {
FS 839             $check = false;
840             do {
841                 unset($temp_password);
480eba 842                 $temp_password = $inst->free_query('Re-enter admin password', '');
272da6 843                 $check = @($temp_password == $conf['interface_password'])?true:false;
480eba 844                 if(!$check) swriteln('Passwords do not match.');
272da6 845             } while (!$check);
FS 846         }
847         unset($check);
848         unset($temp_password);
4ffb51 849         if($conf['apache']['installed'] == true) $conf['apache']['vhost_port']  = $ispconfig_vhost_port;
F 850         if($conf['nginx']['installed'] == true) $conf['nginx']['vhost_port']  = $ispconfig_vhost_port;
851         unset($ispconfig_vhost_port);
b1a6a5 852
b04e82 853         if(strtolower($inst->simple_query('Enable SSL for the ISPConfig web interface', array('y', 'n'), 'y','ispconfig_use_ssl')) == 'y') {
532ae5 854             $inst->make_ispconfig_ssl_cert();
L 855         }
b1a6a5 856
532ae5 857         $inst->install_ispconfig_interface = true;
b1a6a5 858
532ae5 859     } else {
L 860         $inst->install_ispconfig_interface = false;
861     }
b1a6a5 862
532ae5 863     $inst->install_ispconfig();
b1a6a5 864
532ae5 865     //* Configure DBServer
L 866     swriteln('Configuring DBServer');
867     $inst->configure_dbserver();
b1a6a5 868
532ae5 869     //* Configure ISPConfig
L 870     swriteln('Installing ISPConfig crontab');
871     $inst->install_crontab();
33bcd0 872     if($conf['apache']['installed'] == true && $conf['apache']['init_script'] != '') system($inst->getinitcommand($conf['apache']['init_script'], 'restart'));
4ffb51 873     //* Reload is enough for nginx
F 874     if($conf['nginx']['installed'] == true){
33bcd0 875         if($conf['nginx']['php_fpm_init_script'] != '') system($inst->getinitcommand($conf['nginx']['php_fpm_init_script'], 'reload'));
FT 876         if($conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'reload'));
4ffb51 877     }
d22277 878     
MB 879     swriteln('Detect IP addresses');
880     $inst->detect_ips();
b1a6a5 881
MC 882
883
532ae5 884 } //* << $install_mode / 'Standard' or Genius
L 885
d5f2d5 886 $inst->create_mount_script();
MC 887
1ed92e 888 //* Create md5 filelist
TB 889 $md5_filename = '/usr/local/ispconfig/security/data/file_checksums_'.date('Y-m-d_h-i').'.md5';
890 exec('find /usr/local/ispconfig -type f -print0 | xargs -0 md5sum > '.$md5_filename);
891 chmod($md5_filename,0700);
892
532ae5 893
L 894 echo "Installation completed.\n";
895
896
bedf79 897 ?>