tbrehm
2009-02-15 2ce1583e0b72b221257633c37271890018e2651c
commit | author | age
9200ad 1 <?php
T 2
3 /*
4 Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 /*
32     ISPConfig 3 installer.
33 */
34
c87c0a 35 error_reporting(E_ALL|E_STRICT);
P 36
dc7d8b 37 //** The banner on the command line
P 38 echo "\n\n".str_repeat('-',80)."\n";
39 echo " _____ ___________   _____              __ _       
40 |_   _/  ___| ___ \ /  __ \            / _(_)      
41   | | \ `--.| |_/ / | /  \/ ___  _ __ | |_ _  __ _ 
42   | |  `--. \  __/  | |    / _ \| '_ \|  _| |/ _` |
43  _| |_/\__/ / |     | \__/\ (_) | | | | | | | (_| |
44  \___/\____/\_|      \____/\___/|_| |_|_| |_|\__, |
45                                               __/ |
46                                              |___/ ";
d5cf65 47 echo "\n".str_repeat('-',80)."\n";
P 48 echo "\n\n>> Initial configuration  \n\n";
ce9544 49
57706b 50 //** Include the library with the basic installer functions
9200ad 51 require_once('lib/install.lib.php');
T 52
57706b 53 //** Include the base class of the installer class
9200ad 54 require_once('lib/installer_base.lib.php');
T 55
00dfba 56 //** Install logfile
R 57 define('ISPC_LOG_FILE', '/var/log/ispconfig_install.log');
58 define('ISPC_INSTALL_ROOT', realpath(dirname(__FILE__).'/../'));
59
60 //** Check for existing installation
61 /*if(is_dir("/usr/local/ispconfig")) {
62     die('We will stop here. There is already a ISPConfig installation, use the update script to update this installation.');
63 }*/
64
cc3fb3 65 //** Get distribution identifier
344393 66 $dist = get_distname();
9200ad 67
00dfba 68 if($dist['id'] == '') die('Linux Distribution or Version not recognized.');
f629e2 69
cc3fb3 70 //** Include the distribution specific installer class library and configuration
90511b 71 if(is_file('dist/lib/'.$dist['baseid'].'.lib.php')) include_once('dist/lib/'.$dist['baseid'].'.lib.php');
344393 72 include_once('dist/lib/'.$dist['id'].'.lib.php');
T 73 include_once('dist/conf/'.$dist['id'].'.conf.php');
66b4f9 74
facccb 75 //****************************************************************************************************
P 76 //** Installer Interface 
77 //****************************************************************************************************
9200ad 78 $inst = new installer();
d5cf65 79 swriteln($inst->lng('    Following will be a few questions for primary configuration so be careful.'));
facccb 80 swriteln($inst->lng('    Default values are in [brackets] and can be accepted with <ENTER>.'));
P 81 swriteln($inst->lng('    Tap in "quit" (without the quotes) to stop the installer.'."\n\n"));
9200ad 82
4fe86d 83 //** Check log file is writable (probably not root or sudo)
cc3fb3 84 if(!is_writable(dirname(ISPC_LOG_FILE))){
O 85     die("ERROR: Cannot write to the directory ".dirname(ISPC_LOG_FILE).". Are you root or sudo ?\n\n");
66b4f9 86 }
P 87
0c0d28 88 if(is_dir('/root/ispconfig') || is_dir('/home/admispconfig')) {
T 89     die('This software can not be installed on a server wich runs ISPConfig 2.x.');
90 }
91
0a1f02 92 //** Detect the installed applications
T 93 $inst->find_installed_apps();
94
57706b 95 //** Select the language
P 96 $conf['language'] = $inst->simple_query('Select language', array('en','de'), 'en');
9200ad 97
57706b 98 //** Select installation mode
12e3ba 99 $install_mode = $inst->simple_query('Installation mode', array('standard','expert'), 'standard');
9200ad 100
66b4f9 101
57706b 102 //** Get the hostname
ce9544 103 $tmp_out = array();
57706b 104 exec('hostname -f', $tmp_out);
00dfba 105 $conf['hostname'] = $inst->free_query('Full qualified hostname (FQDN) of the server, eg server1.domain.tld ', $tmp_out[0]);
ce9544 106 unset($tmp_out);
T 107
57706b 108 //** Get MySQL root credentials
ce9544 109 $finished = false;
T 110 do {
dc7d8b 111     $tmp_mysql_server_host = $inst->free_query('MySQL server hostname', $conf['mysql']['host']);
P 112     $tmp_mysql_server_admin_user = $inst->free_query('MySQL root username', $conf['mysql']['admin_user']);
113     $tmp_mysql_server_admin_password = $inst->free_query('MySQL root password', $conf['mysql']['admin_password']);
b0a1cc 114     $tmp_mysql_server_database = $inst->free_query('MySQL database to create', $conf['mysql']['database']);
00dfba 115     $tmp_mysql_server_charset = $inst->free_query('MySQL charset', $conf['mysql']['charset']);
239ce8 116     
57706b 117     //* Initialize the MySQL server connection
239ce8 118     if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
57706b 119         $conf['mysql']['host'] = $tmp_mysql_server_host;
P 120         $conf['mysql']['admin_user'] = $tmp_mysql_server_admin_user;
121         $conf['mysql']['admin_password'] = $tmp_mysql_server_admin_password;
b0a1cc 122         $conf['mysql']['database'] = $tmp_mysql_server_database;
00dfba 123         $conf['mysql']['charset'] = $tmp_mysql_server_charset;
ce9544 124         $finished = true;
239ce8 125     } else {
57706b 126         swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error());
ce9544 127     }
T 128 } while ($finished == false);
239ce8 129 unset($finished);
cd972d 130
T 131 // Resolve the IP address of the mysql hostname.
132 if(!$conf['mysql']['ip'] = gethostbyname($conf['mysql']['host'])) die('Unable to resolve hostname'.$conf['mysql']['host']);
133
9200ad 134
57706b 135 //** initializing database connection
239ce8 136 include_once('lib/mysql.lib.php');
T 137 $inst->db = new db();
9200ad 138
57706b 139 //** Begin with standard or expert installation
12e3ba 140 if($install_mode == 'standard') {
ce9544 141     
57706b 142     //* Create the mysql database
ce9544 143     $inst->configure_database();
94411b 144     
T 145     //* Insert the Server record into the database
146     $inst->add_database_server_record();
9200ad 147
57706b 148     //* Configure postfix
ce9544 149     $inst->configure_postfix();
61d290 150     
faf3f5 151     //* Configure jailkit
61d290 152     swriteln('Configuring Jailkit');
D 153     $inst->configure_jailkit();
9200ad 154
57706b 155     //* Configure saslauthd
ce9544 156     swriteln('Configuring SASL');
T 157     $inst->configure_saslauthd();
9200ad 158
57706b 159     //* Configure PAM
ce9544 160     swriteln('Configuring PAM');
T 161     $inst->configure_pam();
ba747c 162
57706b 163     //* Configure courier
ce9544 164     swriteln('Configuring Courier');
T 165     $inst->configure_courier();
99d85e 166
57706b 167     //* Configure Spamasassin
ce9544 168     swriteln('Configuring Spamassassin');
T 169     $inst->configure_spamassassin();
b4c750 170
57706b 171     //* Configure Amavis
ce9544 172     swriteln('Configuring Amavisd');
T 173     $inst->configure_amavis();
9200ad 174
57706b 175     //* Configure Getmail
ce9544 176     swriteln('Configuring Getmail');
T 177     $inst->configure_getmail();
178     
daff5c 179
57706b 180     //* Configure Pureftpd
ce9544 181     swriteln('Configuring Pureftpd');
T 182     $inst->configure_pureftpd();
9200ad 183
57706b 184     //* Configure MyDNS
ce9544 185     swriteln('Configuring MyDNS');
T 186     $inst->configure_mydns();
313e33 187     
57706b 188     //* Configure Apache
313e33 189     swriteln('Configuring Apache');
T 190     $inst->configure_apache();
7c99ef 191     
T 192     //* Configure Firewall
193     swriteln('Configuring Firewall');
194     $inst->configure_firewall();
9200ad 195
57706b 196     //* Configure ISPConfig
ce9544 197     swriteln('Installing ISPConfig');
9b9ba4 198     
D 199     //** Customise the port ISPConfig runs on
cd972d 200     $conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', '8080');
9b9ba4 201
ce9544 202     $inst->install_ispconfig();
d83fcf 203     
T 204     //* Configure DBServer
205     swriteln('Configuring DBServer');
206     $inst->configure_dbserver();
9200ad 207
57706b 208     //* Configure ISPConfig
ce9544 209     swriteln('Installing Crontab');
T 210     $inst->install_crontab();
211     
212     swriteln('Restarting services ...');
2ce158 213     if($conf['mysql']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['mysql']['init_script']))                    system($conf['init_scripts'].'/'.$conf['mysql']['init_script'].' restart');
T 214     if($conf['postfix']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['postfix']['init_script']))                system($conf['init_scripts'].'/'.$conf['postfix']['init_script'].' restart');
215     if($conf['saslauthd']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['saslauthd']['init_script']))            system($conf['init_scripts'].'/'.$conf['saslauthd']['init_script'].' restart');
216     if($conf['amavis']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['amavis']['init_script']))                    system($conf['init_scripts'].'/'.$conf['amavis']['init_script'].' restart');
217     if($conf['clamav']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['clamav']['init_script']))                    system($conf['init_scripts'].'/'.$conf['clamav']['init_script'].' restart');
218     if($conf['courier']['courier-authdaemon'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'])) system($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'].' restart');
219     if($conf['courier']['courier-imap'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-imap']))             system($conf['init_scripts'].'/'.$conf['courier']['courier-imap'].' restart');
220     if($conf['courier']['courier-imap-ssl'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-imap-ssl']))     system($conf['init_scripts'].'/'.$conf['courier']['courier-imap-ssl'].' restart');
221     if($conf['courier']['courier-pop'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-pop']))                 system($conf['init_scripts'].'/'.$conf['courier']['courier-pop'].' restart');
222     if($conf['courier']['courier-pop-ssl'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-pop-ssl']))         system($conf['init_scripts'].'/'.$conf['courier']['courier-pop-ssl'].' restart');
223     if($conf['apache']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['apache']['init_script']))                 system($conf['init_scripts'].'/'.$conf['apache']['init_script'].' restart');
224     if($conf['pureftpd']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['pureftpd']['init_script']))                system($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'].' restart');
225     if($conf['mydns']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['mydns']['init_script']))                    system($conf['init_scripts'].'/'.$conf['mydns']['init_script'].' restart &> /dev/null');
ce9544 226     
57706b 227 }else{
0a1f02 228     
T 229     //* In expert mode, we select the services in the following steps, only db is always available
230     $conf['services']['mail'] = false;
231     $conf['services']['web'] = false;
232     $conf['services']['dns'] = false;
233     $conf['services']['db'] = true;
234     
235     
57706b 236     //** Get Server ID
94411b 237     // $conf['server_id'] = $inst->free_query('Unique Numeric ID of the server','1');
T 238     // Server ID is an autoInc value of the mysql database now
ce9544 239     
12e3ba 240     if(strtolower($inst->simple_query('Shall this server join an existing ISPConfig multiserver setup',array('y','n'),'n')) == 'y') {
T 241         $conf['mysql']['master_slave_setup'] = 'y';
242         
243         //** Get MySQL root credentials
244         $finished = false;
245         do {
246             $tmp_mysql_server_host = $inst->free_query('MySQL master server hostname', $conf['mysql']['master_host']);
247             $tmp_mysql_server_admin_user = $inst->free_query('MySQL master server root username', $conf['mysql']['master_admin_user']);
248             $tmp_mysql_server_admin_password = $inst->free_query('MySQL master server root password', $conf['mysql']['master_admin_password']);
249             $tmp_mysql_server_database = $inst->free_query('MySQL master server database name', $conf['mysql']['master_database']);
250     
251             //* Initialize the MySQL server connection
252             if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
253                 $conf['mysql']['master_host'] = $tmp_mysql_server_host;
254                 $conf['mysql']['master_admin_user'] = $tmp_mysql_server_admin_user;
255                 $conf['mysql']['master_admin_password'] = $tmp_mysql_server_admin_password;
256                 $conf['mysql']['master_database'] = $tmp_mysql_server_database;
257                 $finished = true;
258             } else {
259                 swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error());
260             }
261         } while ($finished == false);
262         unset($finished);
263         
264         // initialize the connection to the master database
265         $inst->dbmaster = new db();
266         if($inst->dbmaster->linkId) $inst->dbmaster->closeConn();
267         $inst->dbmaster->dbHost = $conf['mysql']["master_host"];
268         $inst->dbmaster->dbName = $conf['mysql']["master_database"];
269         $inst->dbmaster->dbUser = $conf['mysql']["master_admin_user"];
270         $inst->dbmaster->dbPass = $conf['mysql']["master_admin_password"];
271         
272     } else {
273         // the master DB is the same then the slave DB
274         $inst->dbmaster = $inst->db;
ce9544 275     }
12e3ba 276     
T 277     //* Create the mysql database
278     $inst->configure_database();
ee0e1c 279         
T 280     //* Insert the Server record into the database
a768b9 281     swriteln('Adding ISPConfig server record to database.');
81b5e2 282     swriteln('');
ee0e1c 283     $inst->add_database_server_record();
T 284
ce9544 285     
57706b 286     if(strtolower($inst->simple_query('Configure Mail', array('y','n') ,'y') ) == 'y') {
ce9544 287         
0a1f02 288         $conf['services']['mail'] = true;
T 289         
57706b 290         //* Configure Postfix
ce9544 291         swriteln('Configuring Postfix');
T 292         $inst->configure_postfix();
293         
27037a 294         //* Configure saslauthd
T 295         swriteln('Configuring SASL');
296         $inst->configure_saslauthd();
297         
57706b 298         //* Configure PAM
ce9544 299         swriteln('Configuring PAM');
T 300         $inst->configure_pam();
301
57706b 302         //* Configure courier
ce9544 303         swriteln('Configuring Courier');
T 304         $inst->configure_courier();
305
57706b 306         //* Configure Spamasassin
ce9544 307         swriteln('Configuring Spamassassin');
T 308         $inst->configure_spamassassin();
309
57706b 310         //* Configure Amavis
ce9544 311         swriteln('Configuring Amavisd');
T 312         $inst->configure_amavis();
313
57706b 314         //* Configure Getmail
ce9544 315         swriteln('Configuring Getmail');
T 316         $inst->configure_getmail();
317         
1a14f4 318         if($conf['postfix']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['postfix']['init_script'].' restart');
T 319         if($conf['saslauthd']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['saslauthd']['init_script'].' restart');
320         if($conf['amavis']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['amavis']['init_script'].' restart');
321         if($conf['clamav']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['clamav']['init_script'].' restart');
322         if($conf['courier']['courier-authdaemon'] != '')     system($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'].' restart');
323         if($conf['courier']['courier-imap'] != '')             system($conf['init_scripts'].'/'.$conf['courier']['courier-imap'].' restart');
324         if($conf['courier']['courier-imap-ssl'] != '')         system($conf['init_scripts'].'/'.$conf['courier']['courier-imap-ssl'].' restart');
325         if($conf['courier']['courier-pop'] != '')             system($conf['init_scripts'].'/'.$conf['courier']['courier-pop'].' restart');
326         if($conf['courier']['courier-pop-ssl'] != '')         system($conf['init_scripts'].'/'.$conf['courier']['courier-pop-ssl'].' restart');
ce9544 327     }
T 328     
faf3f5 329     //** Configure Jailkit
T 330     if(strtolower($inst->simple_query('Configure Jailkit', array('y','n'),'y') ) == 'y') {    
331         swriteln('Configuring Jailkit');
332         $inst->configure_jailkit();
333     }
334     
57706b 335     //** Configure Pureftpd
P 336     if(strtolower($inst->simple_query('Configure FTP Server', array('y','n'),'y') ) == 'y') {    
ce9544 337         swriteln('Configuring Pureftpd');
T 338         $inst->configure_pureftpd();
1a14f4 339         if($conf['pureftpd']['init_script'] != '') system($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'].' restart');
ce9544 340     }
T 341     
57706b 342     //** Configure MyDNS
ce9544 343     if(strtolower($inst->simple_query('Configure DNS Server',array('y','n'),'y')) == 'y') {
0a1f02 344         $conf['services']['dns'] = true;
ce9544 345         swriteln('Configuring MyDNS');
T 346         $inst->configure_mydns();
1a14f4 347         if($conf['mydns']['init_script'] != '')    system($conf['init_scripts'].'/'.$conf['mydns']['init_script'].' restart &> /dev/null');
ce9544 348     }
T 349     
57706b 350     //** Configure Apache
12e3ba 351     swriteln("\nHint: If this server shall run the ispconfig interface, select 'y' in the next option.\n");
57706b 352     if(strtolower($inst->simple_query('Configure Apache Server',array('y','n'),'y')) == 'y') {    
0a1f02 353         $conf['services']['web'] = true;
313e33 354         swriteln('Configuring Apache');
T 355         $inst->configure_apache();
356     }
357     
7c99ef 358     //** Configure Firewall
T 359     if(strtolower($inst->simple_query('Configure Firewall Server',array('y','n'),'y')) == 'y') {    
360         swriteln('Configuring Firewall');
361         $inst->configure_firewall();
362     }
363     
57706b 364     //** Configure ISPConfig :-)
ac4a37 365     if(strtolower($inst->simple_query('Install ISPConfig Web-Interface',array('y','n'),'y')) == 'y') {
ce9544 366         swriteln('Installing ISPConfig');
54c0c3 367         
T 368         //** We want to check if the server is a module or cgi based php enabled server
a768b9 369         //** TODO: Don't always ask for this somehow ?
T 370         /*
54c0c3 371         $fast_cgi = $inst->simple_query('CGI PHP Enabled Server?', array('yes','no'),'no');
T 372
373         if($fast_cgi == 'yes') {
374              $alias = $inst->free_query('Script Alias', '/php/');
375              $path = $inst->free_query('Script Alias Path', '/path/to/cgi/bin');
cd972d 376              $conf['apache']['vhost_cgi_alias'] = sprintf('ScriptAlias %s %s', $alias, $path);
54c0c3 377         } else {
cd972d 378              $conf['apache']['vhost_cgi_alias'] = "";
54c0c3 379         }
a768b9 380         */
54c0c3 381
T 382         //** Customise the port ISPConfig runs on
cd972d 383         $conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', '8080');
54c0c3 384         
ac4a37 385         $inst->install_ispconfig_interface = true;
T 386             
387     } else {
388         $inst->install_ispconfig_interface = false;
ce9544 389     }
T 390     
ac4a37 391     $inst->install_ispconfig();
d83fcf 392     
T 393     //* Configure DBServer
394     swriteln('Configuring DBServer');
395     $inst->configure_dbserver();
ac4a37 396         
T 397     //* Configure ISPConfig
398     swriteln('Installing Crontab');
399     $inst->install_crontab();
1a14f4 400     if($conf['apache']['init_script'] != '') system($conf['init_scripts'].'/'.$conf['apache']['init_script'].' restart');
ac4a37 401     
T 402     
403     
57706b 404 } //* << $install_mode / 'Standard' or Genius
ce9544 405
9200ad 406
57706b 407 echo "Installation completed.\n";
9200ad 408
T 409
57706b 410 ?>