tbrehm
2009-10-14 0cefd385239eb2367e6eec69c9dbc93588d50877
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
8c4aa3 56 //** Ensure that current working directory is install directory
T 57 $cur_dir = getcwd();
58 if(realpath(dirname(__FILE__)) != $cur_dir) die("Please run installation/update from _inside_ the install directory!\n");
59
00dfba 60 //** Install logfile
R 61 define('ISPC_LOG_FILE', '/var/log/ispconfig_install.log');
62 define('ISPC_INSTALL_ROOT', realpath(dirname(__FILE__).'/../'));
63
64 //** Check for existing installation
65 /*if(is_dir("/usr/local/ispconfig")) {
66     die('We will stop here. There is already a ISPConfig installation, use the update script to update this installation.');
67 }*/
68
cc3fb3 69 //** Get distribution identifier
344393 70 $dist = get_distname();
9200ad 71
00dfba 72 if($dist['id'] == '') die('Linux Distribution or Version not recognized.');
f629e2 73
cc3fb3 74 //** Include the distribution specific installer class library and configuration
90511b 75 if(is_file('dist/lib/'.$dist['baseid'].'.lib.php')) include_once('dist/lib/'.$dist['baseid'].'.lib.php');
344393 76 include_once('dist/lib/'.$dist['id'].'.lib.php');
T 77 include_once('dist/conf/'.$dist['id'].'.conf.php');
66b4f9 78
facccb 79 //****************************************************************************************************
P 80 //** Installer Interface 
81 //****************************************************************************************************
9200ad 82 $inst = new installer();
d5cf65 83 swriteln($inst->lng('    Following will be a few questions for primary configuration so be careful.'));
facccb 84 swriteln($inst->lng('    Default values are in [brackets] and can be accepted with <ENTER>.'));
P 85 swriteln($inst->lng('    Tap in "quit" (without the quotes) to stop the installer.'."\n\n"));
9200ad 86
4fe86d 87 //** Check log file is writable (probably not root or sudo)
cc3fb3 88 if(!is_writable(dirname(ISPC_LOG_FILE))){
O 89     die("ERROR: Cannot write to the directory ".dirname(ISPC_LOG_FILE).". Are you root or sudo ?\n\n");
66b4f9 90 }
P 91
0c0d28 92 if(is_dir('/root/ispconfig') || is_dir('/home/admispconfig')) {
T 93     die('This software can not be installed on a server wich runs ISPConfig 2.x.');
94 }
95
0a1f02 96 //** Detect the installed applications
T 97 $inst->find_installed_apps();
98
57706b 99 //** Select the language
P 100 $conf['language'] = $inst->simple_query('Select language', array('en','de'), 'en');
9200ad 101
57706b 102 //** Select installation mode
12e3ba 103 $install_mode = $inst->simple_query('Installation mode', array('standard','expert'), 'standard');
9200ad 104
66b4f9 105
57706b 106 //** Get the hostname
ce9544 107 $tmp_out = array();
57706b 108 exec('hostname -f', $tmp_out);
00dfba 109 $conf['hostname'] = $inst->free_query('Full qualified hostname (FQDN) of the server, eg server1.domain.tld ', $tmp_out[0]);
ce9544 110 unset($tmp_out);
T 111
8ba08e 112 // Check if the mysql functions are loaded in PHP
T 113 if(!function_exists('mysql_connect')) die('No PHP mysql functions available. Please ensure that the PHP mysql module is loaded.');
114
57706b 115 //** Get MySQL root credentials
ce9544 116 $finished = false;
T 117 do {
dc7d8b 118     $tmp_mysql_server_host = $inst->free_query('MySQL server hostname', $conf['mysql']['host']);
P 119     $tmp_mysql_server_admin_user = $inst->free_query('MySQL root username', $conf['mysql']['admin_user']);
120     $tmp_mysql_server_admin_password = $inst->free_query('MySQL root password', $conf['mysql']['admin_password']);
b0a1cc 121     $tmp_mysql_server_database = $inst->free_query('MySQL database to create', $conf['mysql']['database']);
00dfba 122     $tmp_mysql_server_charset = $inst->free_query('MySQL charset', $conf['mysql']['charset']);
239ce8 123     
57706b 124     //* Initialize the MySQL server connection
239ce8 125     if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
57706b 126         $conf['mysql']['host'] = $tmp_mysql_server_host;
P 127         $conf['mysql']['admin_user'] = $tmp_mysql_server_admin_user;
128         $conf['mysql']['admin_password'] = $tmp_mysql_server_admin_password;
b0a1cc 129         $conf['mysql']['database'] = $tmp_mysql_server_database;
00dfba 130         $conf['mysql']['charset'] = $tmp_mysql_server_charset;
ce9544 131         $finished = true;
239ce8 132     } else {
57706b 133         swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error());
ce9544 134     }
T 135 } while ($finished == false);
239ce8 136 unset($finished);
cd972d 137
T 138 // Resolve the IP address of the mysql hostname.
399f82 139 $tmp = explode(':',$conf['mysql']['host']);
T 140 if(!$conf['mysql']['ip'] = gethostbyname($tmp[0])) die('Unable to resolve hostname'.$tmp[0]);
141 unset($tmp);
cd972d 142
9200ad 143
57706b 144 //** initializing database connection
239ce8 145 include_once('lib/mysql.lib.php');
T 146 $inst->db = new db();
9200ad 147
57706b 148 //** Begin with standard or expert installation
12e3ba 149 if($install_mode == 'standard') {
ce9544 150     
57706b 151     //* Create the mysql database
ce9544 152     $inst->configure_database();
94411b 153     
T 154     //* Insert the Server record into the database
155     $inst->add_database_server_record();
9200ad 156
57706b 157     //* Configure postfix
ce9544 158     $inst->configure_postfix();
61d290 159     
faf3f5 160     //* Configure jailkit
61d290 161     swriteln('Configuring Jailkit');
D 162     $inst->configure_jailkit();
9200ad 163
57706b 164     //* Configure saslauthd
ce9544 165     swriteln('Configuring SASL');
T 166     $inst->configure_saslauthd();
9200ad 167
57706b 168     //* Configure PAM
ce9544 169     swriteln('Configuring PAM');
T 170     $inst->configure_pam();
ba747c 171
57706b 172     //* Configure courier
ce9544 173     swriteln('Configuring Courier');
T 174     $inst->configure_courier();
99d85e 175
57706b 176     //* Configure Spamasassin
ce9544 177     swriteln('Configuring Spamassassin');
T 178     $inst->configure_spamassassin();
b4c750 179
57706b 180     //* Configure Amavis
ce9544 181     swriteln('Configuring Amavisd');
T 182     $inst->configure_amavis();
9200ad 183
57706b 184     //* Configure Getmail
ce9544 185     swriteln('Configuring Getmail');
T 186     $inst->configure_getmail();
187     
daff5c 188
57706b 189     //* Configure Pureftpd
ce9544 190     swriteln('Configuring Pureftpd');
T 191     $inst->configure_pureftpd();
9200ad 192
57706b 193     //* Configure MyDNS
ce9544 194     swriteln('Configuring MyDNS');
T 195     $inst->configure_mydns();
313e33 196     
57706b 197     //* Configure Apache
313e33 198     swriteln('Configuring Apache');
T 199     $inst->configure_apache();
7c99ef 200     
8c4aa3 201     //** Configure vlogger
T 202     swriteln('Configuring vlogger');
203     $inst->configure_vlogger();
204     
7c99ef 205     //* Configure Firewall
T 206     swriteln('Configuring Firewall');
207     $inst->configure_firewall();
9200ad 208
57706b 209     //* Configure ISPConfig
ce9544 210     swriteln('Installing ISPConfig');
9b9ba4 211     
D 212     //** Customise the port ISPConfig runs on
cd972d 213     $conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', '8080');
9b9ba4 214
ce9544 215     $inst->install_ispconfig();
d83fcf 216     
T 217     //* Configure DBServer
218     swriteln('Configuring DBServer');
219     $inst->configure_dbserver();
9200ad 220
57706b 221     //* Configure ISPConfig
ce9544 222     swriteln('Installing Crontab');
T 223     $inst->install_crontab();
224     
225     swriteln('Restarting services ...');
2ce158 226     if($conf['mysql']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['mysql']['init_script']))                    system($conf['init_scripts'].'/'.$conf['mysql']['init_script'].' restart');
T 227     if($conf['postfix']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['postfix']['init_script']))                system($conf['init_scripts'].'/'.$conf['postfix']['init_script'].' restart');
228     if($conf['saslauthd']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['saslauthd']['init_script']))            system($conf['init_scripts'].'/'.$conf['saslauthd']['init_script'].' restart');
229     if($conf['amavis']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['amavis']['init_script']))                    system($conf['init_scripts'].'/'.$conf['amavis']['init_script'].' restart');
230     if($conf['clamav']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['clamav']['init_script']))                    system($conf['init_scripts'].'/'.$conf['clamav']['init_script'].' restart');
231     if($conf['courier']['courier-authdaemon'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'])) system($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'].' restart');
232     if($conf['courier']['courier-imap'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-imap']))             system($conf['init_scripts'].'/'.$conf['courier']['courier-imap'].' restart');
233     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');
234     if($conf['courier']['courier-pop'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-pop']))                 system($conf['init_scripts'].'/'.$conf['courier']['courier-pop'].' restart');
235     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');
236     if($conf['apache']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['apache']['init_script']))                 system($conf['init_scripts'].'/'.$conf['apache']['init_script'].' restart');
237     if($conf['pureftpd']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['pureftpd']['init_script']))                system($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'].' restart');
238     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 239     
57706b 240 }else{
0a1f02 241     
T 242     //* In expert mode, we select the services in the following steps, only db is always available
243     $conf['services']['mail'] = false;
244     $conf['services']['web'] = false;
245     $conf['services']['dns'] = false;
246     $conf['services']['db'] = true;
247     
248     
57706b 249     //** Get Server ID
94411b 250     // $conf['server_id'] = $inst->free_query('Unique Numeric ID of the server','1');
T 251     // Server ID is an autoInc value of the mysql database now
ce9544 252     
12e3ba 253     if(strtolower($inst->simple_query('Shall this server join an existing ISPConfig multiserver setup',array('y','n'),'n')) == 'y') {
T 254         $conf['mysql']['master_slave_setup'] = 'y';
255         
256         //** Get MySQL root credentials
257         $finished = false;
258         do {
259             $tmp_mysql_server_host = $inst->free_query('MySQL master server hostname', $conf['mysql']['master_host']);
260             $tmp_mysql_server_admin_user = $inst->free_query('MySQL master server root username', $conf['mysql']['master_admin_user']);
261             $tmp_mysql_server_admin_password = $inst->free_query('MySQL master server root password', $conf['mysql']['master_admin_password']);
262             $tmp_mysql_server_database = $inst->free_query('MySQL master server database name', $conf['mysql']['master_database']);
263     
264             //* Initialize the MySQL server connection
265             if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
266                 $conf['mysql']['master_host'] = $tmp_mysql_server_host;
267                 $conf['mysql']['master_admin_user'] = $tmp_mysql_server_admin_user;
268                 $conf['mysql']['master_admin_password'] = $tmp_mysql_server_admin_password;
269                 $conf['mysql']['master_database'] = $tmp_mysql_server_database;
270                 $finished = true;
271             } else {
272                 swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error());
273             }
274         } while ($finished == false);
275         unset($finished);
276         
277         // initialize the connection to the master database
278         $inst->dbmaster = new db();
279         if($inst->dbmaster->linkId) $inst->dbmaster->closeConn();
280         $inst->dbmaster->dbHost = $conf['mysql']["master_host"];
281         $inst->dbmaster->dbName = $conf['mysql']["master_database"];
282         $inst->dbmaster->dbUser = $conf['mysql']["master_admin_user"];
283         $inst->dbmaster->dbPass = $conf['mysql']["master_admin_password"];
284         
285     } else {
286         // the master DB is the same then the slave DB
287         $inst->dbmaster = $inst->db;
ce9544 288     }
12e3ba 289     
T 290     //* Create the mysql database
291     $inst->configure_database();
ee0e1c 292         
T 293     //* Insert the Server record into the database
a768b9 294     swriteln('Adding ISPConfig server record to database.');
81b5e2 295     swriteln('');
ee0e1c 296     $inst->add_database_server_record();
T 297
ce9544 298     
57706b 299     if(strtolower($inst->simple_query('Configure Mail', array('y','n') ,'y') ) == 'y') {
ce9544 300         
0a1f02 301         $conf['services']['mail'] = true;
T 302         
57706b 303         //* Configure Postfix
ce9544 304         swriteln('Configuring Postfix');
T 305         $inst->configure_postfix();
306         
27037a 307         //* Configure saslauthd
T 308         swriteln('Configuring SASL');
309         $inst->configure_saslauthd();
310         
57706b 311         //* Configure PAM
ce9544 312         swriteln('Configuring PAM');
T 313         $inst->configure_pam();
314
57706b 315         //* Configure courier
ce9544 316         swriteln('Configuring Courier');
T 317         $inst->configure_courier();
318
57706b 319         //* Configure Spamasassin
ce9544 320         swriteln('Configuring Spamassassin');
T 321         $inst->configure_spamassassin();
322
57706b 323         //* Configure Amavis
ce9544 324         swriteln('Configuring Amavisd');
T 325         $inst->configure_amavis();
326
57706b 327         //* Configure Getmail
ce9544 328         swriteln('Configuring Getmail');
T 329         $inst->configure_getmail();
330         
1a14f4 331         if($conf['postfix']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['postfix']['init_script'].' restart');
T 332         if($conf['saslauthd']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['saslauthd']['init_script'].' restart');
333         if($conf['amavis']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['amavis']['init_script'].' restart');
334         if($conf['clamav']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['clamav']['init_script'].' restart');
335         if($conf['courier']['courier-authdaemon'] != '')     system($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'].' restart');
336         if($conf['courier']['courier-imap'] != '')             system($conf['init_scripts'].'/'.$conf['courier']['courier-imap'].' restart');
337         if($conf['courier']['courier-imap-ssl'] != '')         system($conf['init_scripts'].'/'.$conf['courier']['courier-imap-ssl'].' restart');
338         if($conf['courier']['courier-pop'] != '')             system($conf['init_scripts'].'/'.$conf['courier']['courier-pop'].' restart');
339         if($conf['courier']['courier-pop-ssl'] != '')         system($conf['init_scripts'].'/'.$conf['courier']['courier-pop-ssl'].' restart');
ce9544 340     }
T 341     
faf3f5 342     //** Configure Jailkit
T 343     if(strtolower($inst->simple_query('Configure Jailkit', array('y','n'),'y') ) == 'y') {    
344         swriteln('Configuring Jailkit');
345         $inst->configure_jailkit();
346     }
347     
57706b 348     //** Configure Pureftpd
P 349     if(strtolower($inst->simple_query('Configure FTP Server', array('y','n'),'y') ) == 'y') {    
ce9544 350         swriteln('Configuring Pureftpd');
T 351         $inst->configure_pureftpd();
1a14f4 352         if($conf['pureftpd']['init_script'] != '') system($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'].' restart');
ce9544 353     }
T 354     
57706b 355     //** Configure MyDNS
ce9544 356     if(strtolower($inst->simple_query('Configure DNS Server',array('y','n'),'y')) == 'y') {
0a1f02 357         $conf['services']['dns'] = true;
ce9544 358         swriteln('Configuring MyDNS');
T 359         $inst->configure_mydns();
1a14f4 360         if($conf['mydns']['init_script'] != '')    system($conf['init_scripts'].'/'.$conf['mydns']['init_script'].' restart &> /dev/null');
ce9544 361     }
T 362     
57706b 363     //** Configure Apache
69944a 364     swriteln("\nHint: If this server shall run the ispconfig interface, select 'y' in the 'Configure Apache Server' option.\n");
57706b 365     if(strtolower($inst->simple_query('Configure Apache Server',array('y','n'),'y')) == 'y') {    
0a1f02 366         $conf['services']['web'] = true;
313e33 367         swriteln('Configuring Apache');
T 368         $inst->configure_apache();
8c4aa3 369         
T 370         //** Configure vlogger
371         swriteln('Configuring vlogger');
372         $inst->configure_vlogger();
313e33 373     }
T 374     
7c99ef 375     //** Configure Firewall
T 376     if(strtolower($inst->simple_query('Configure Firewall Server',array('y','n'),'y')) == 'y') {    
377         swriteln('Configuring Firewall');
378         $inst->configure_firewall();
379     }
380     
57706b 381     //** Configure ISPConfig :-)
ac4a37 382     if(strtolower($inst->simple_query('Install ISPConfig Web-Interface',array('y','n'),'y')) == 'y') {
ce9544 383         swriteln('Installing ISPConfig');
54c0c3 384         
T 385         //** We want to check if the server is a module or cgi based php enabled server
a768b9 386         //** TODO: Don't always ask for this somehow ?
T 387         /*
54c0c3 388         $fast_cgi = $inst->simple_query('CGI PHP Enabled Server?', array('yes','no'),'no');
T 389
390         if($fast_cgi == 'yes') {
391              $alias = $inst->free_query('Script Alias', '/php/');
392              $path = $inst->free_query('Script Alias Path', '/path/to/cgi/bin');
cd972d 393              $conf['apache']['vhost_cgi_alias'] = sprintf('ScriptAlias %s %s', $alias, $path);
54c0c3 394         } else {
cd972d 395              $conf['apache']['vhost_cgi_alias'] = "";
54c0c3 396         }
a768b9 397         */
54c0c3 398
T 399         //** Customise the port ISPConfig runs on
cd972d 400         $conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', '8080');
54c0c3 401         
ac4a37 402         $inst->install_ispconfig_interface = true;
T 403             
404     } else {
405         $inst->install_ispconfig_interface = false;
ce9544 406     }
T 407     
ac4a37 408     $inst->install_ispconfig();
d83fcf 409     
T 410     //* Configure DBServer
411     swriteln('Configuring DBServer');
412     $inst->configure_dbserver();
ac4a37 413         
T 414     //* Configure ISPConfig
415     swriteln('Installing Crontab');
416     $inst->install_crontab();
8fb5dd 417     if($conf['apache']['init_script'] != '' && @is_file($conf['init_scripts'].'/'.$conf['apache']['init_script'])) system($conf['init_scripts'].'/'.$conf['apache']['init_script'].' restart');
ac4a37 418     
T 419     
420     
57706b 421 } //* << $install_mode / 'Standard' or Genius
ce9544 422
9200ad 423
57706b 424 echo "Installation completed.\n";
9200ad 425
T 426
57706b 427 ?>