tbrehm
2009-03-23 7bf980d9a21b8cb77f7d8c5fbf79dc85802b40da
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.
399f82 132 $tmp = explode(':',$conf['mysql']['host']);
T 133 if(!$conf['mysql']['ip'] = gethostbyname($tmp[0])) die('Unable to resolve hostname'.$tmp[0]);
134 unset($tmp);
cd972d 135
9200ad 136
57706b 137 //** initializing database connection
239ce8 138 include_once('lib/mysql.lib.php');
T 139 $inst->db = new db();
9200ad 140
57706b 141 //** Begin with standard or expert installation
12e3ba 142 if($install_mode == 'standard') {
ce9544 143     
57706b 144     //* Create the mysql database
ce9544 145     $inst->configure_database();
94411b 146     
T 147     //* Insert the Server record into the database
148     $inst->add_database_server_record();
9200ad 149
57706b 150     //* Configure postfix
ce9544 151     $inst->configure_postfix();
61d290 152     
faf3f5 153     //* Configure jailkit
61d290 154     swriteln('Configuring Jailkit');
D 155     $inst->configure_jailkit();
9200ad 156
57706b 157     //* Configure saslauthd
ce9544 158     swriteln('Configuring SASL');
T 159     $inst->configure_saslauthd();
9200ad 160
57706b 161     //* Configure PAM
ce9544 162     swriteln('Configuring PAM');
T 163     $inst->configure_pam();
ba747c 164
57706b 165     //* Configure courier
ce9544 166     swriteln('Configuring Courier');
T 167     $inst->configure_courier();
99d85e 168
57706b 169     //* Configure Spamasassin
ce9544 170     swriteln('Configuring Spamassassin');
T 171     $inst->configure_spamassassin();
b4c750 172
57706b 173     //* Configure Amavis
ce9544 174     swriteln('Configuring Amavisd');
T 175     $inst->configure_amavis();
9200ad 176
57706b 177     //* Configure Getmail
ce9544 178     swriteln('Configuring Getmail');
T 179     $inst->configure_getmail();
180     
daff5c 181
57706b 182     //* Configure Pureftpd
ce9544 183     swriteln('Configuring Pureftpd');
T 184     $inst->configure_pureftpd();
9200ad 185
57706b 186     //* Configure MyDNS
ce9544 187     swriteln('Configuring MyDNS');
T 188     $inst->configure_mydns();
313e33 189     
57706b 190     //* Configure Apache
313e33 191     swriteln('Configuring Apache');
T 192     $inst->configure_apache();
7c99ef 193     
T 194     //* Configure Firewall
195     swriteln('Configuring Firewall');
196     $inst->configure_firewall();
9200ad 197
57706b 198     //* Configure ISPConfig
ce9544 199     swriteln('Installing ISPConfig');
9b9ba4 200     
D 201     //** Customise the port ISPConfig runs on
cd972d 202     $conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', '8080');
9b9ba4 203
ce9544 204     $inst->install_ispconfig();
d83fcf 205     
T 206     //* Configure DBServer
207     swriteln('Configuring DBServer');
208     $inst->configure_dbserver();
9200ad 209
57706b 210     //* Configure ISPConfig
ce9544 211     swriteln('Installing Crontab');
T 212     $inst->install_crontab();
213     
214     swriteln('Restarting services ...');
2ce158 215     if($conf['mysql']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['mysql']['init_script']))                    system($conf['init_scripts'].'/'.$conf['mysql']['init_script'].' restart');
T 216     if($conf['postfix']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['postfix']['init_script']))                system($conf['init_scripts'].'/'.$conf['postfix']['init_script'].' restart');
217     if($conf['saslauthd']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['saslauthd']['init_script']))            system($conf['init_scripts'].'/'.$conf['saslauthd']['init_script'].' restart');
218     if($conf['amavis']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['amavis']['init_script']))                    system($conf['init_scripts'].'/'.$conf['amavis']['init_script'].' restart');
219     if($conf['clamav']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['clamav']['init_script']))                    system($conf['init_scripts'].'/'.$conf['clamav']['init_script'].' restart');
220     if($conf['courier']['courier-authdaemon'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'])) system($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'].' restart');
221     if($conf['courier']['courier-imap'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-imap']))             system($conf['init_scripts'].'/'.$conf['courier']['courier-imap'].' restart');
222     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');
223     if($conf['courier']['courier-pop'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-pop']))                 system($conf['init_scripts'].'/'.$conf['courier']['courier-pop'].' restart');
224     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');
225     if($conf['apache']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['apache']['init_script']))                 system($conf['init_scripts'].'/'.$conf['apache']['init_script'].' restart');
226     if($conf['pureftpd']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['pureftpd']['init_script']))                system($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'].' restart');
227     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 228     
57706b 229 }else{
0a1f02 230     
T 231     //* In expert mode, we select the services in the following steps, only db is always available
232     $conf['services']['mail'] = false;
233     $conf['services']['web'] = false;
234     $conf['services']['dns'] = false;
235     $conf['services']['db'] = true;
236     
237     
57706b 238     //** Get Server ID
94411b 239     // $conf['server_id'] = $inst->free_query('Unique Numeric ID of the server','1');
T 240     // Server ID is an autoInc value of the mysql database now
ce9544 241     
12e3ba 242     if(strtolower($inst->simple_query('Shall this server join an existing ISPConfig multiserver setup',array('y','n'),'n')) == 'y') {
T 243         $conf['mysql']['master_slave_setup'] = 'y';
244         
245         //** Get MySQL root credentials
246         $finished = false;
247         do {
248             $tmp_mysql_server_host = $inst->free_query('MySQL master server hostname', $conf['mysql']['master_host']);
249             $tmp_mysql_server_admin_user = $inst->free_query('MySQL master server root username', $conf['mysql']['master_admin_user']);
250             $tmp_mysql_server_admin_password = $inst->free_query('MySQL master server root password', $conf['mysql']['master_admin_password']);
251             $tmp_mysql_server_database = $inst->free_query('MySQL master server database name', $conf['mysql']['master_database']);
252     
253             //* Initialize the MySQL server connection
254             if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
255                 $conf['mysql']['master_host'] = $tmp_mysql_server_host;
256                 $conf['mysql']['master_admin_user'] = $tmp_mysql_server_admin_user;
257                 $conf['mysql']['master_admin_password'] = $tmp_mysql_server_admin_password;
258                 $conf['mysql']['master_database'] = $tmp_mysql_server_database;
259                 $finished = true;
260             } else {
261                 swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error());
262             }
263         } while ($finished == false);
264         unset($finished);
265         
266         // initialize the connection to the master database
267         $inst->dbmaster = new db();
268         if($inst->dbmaster->linkId) $inst->dbmaster->closeConn();
269         $inst->dbmaster->dbHost = $conf['mysql']["master_host"];
270         $inst->dbmaster->dbName = $conf['mysql']["master_database"];
271         $inst->dbmaster->dbUser = $conf['mysql']["master_admin_user"];
272         $inst->dbmaster->dbPass = $conf['mysql']["master_admin_password"];
273         
274     } else {
275         // the master DB is the same then the slave DB
276         $inst->dbmaster = $inst->db;
ce9544 277     }
12e3ba 278     
T 279     //* Create the mysql database
280     $inst->configure_database();
ee0e1c 281         
T 282     //* Insert the Server record into the database
a768b9 283     swriteln('Adding ISPConfig server record to database.');
81b5e2 284     swriteln('');
ee0e1c 285     $inst->add_database_server_record();
T 286
ce9544 287     
57706b 288     if(strtolower($inst->simple_query('Configure Mail', array('y','n') ,'y') ) == 'y') {
ce9544 289         
0a1f02 290         $conf['services']['mail'] = true;
T 291         
57706b 292         //* Configure Postfix
ce9544 293         swriteln('Configuring Postfix');
T 294         $inst->configure_postfix();
295         
27037a 296         //* Configure saslauthd
T 297         swriteln('Configuring SASL');
298         $inst->configure_saslauthd();
299         
57706b 300         //* Configure PAM
ce9544 301         swriteln('Configuring PAM');
T 302         $inst->configure_pam();
303
57706b 304         //* Configure courier
ce9544 305         swriteln('Configuring Courier');
T 306         $inst->configure_courier();
307
57706b 308         //* Configure Spamasassin
ce9544 309         swriteln('Configuring Spamassassin');
T 310         $inst->configure_spamassassin();
311
57706b 312         //* Configure Amavis
ce9544 313         swriteln('Configuring Amavisd');
T 314         $inst->configure_amavis();
315
57706b 316         //* Configure Getmail
ce9544 317         swriteln('Configuring Getmail');
T 318         $inst->configure_getmail();
319         
1a14f4 320         if($conf['postfix']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['postfix']['init_script'].' restart');
T 321         if($conf['saslauthd']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['saslauthd']['init_script'].' restart');
322         if($conf['amavis']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['amavis']['init_script'].' restart');
323         if($conf['clamav']['init_script'] != '')            system($conf['init_scripts'].'/'.$conf['clamav']['init_script'].' restart');
324         if($conf['courier']['courier-authdaemon'] != '')     system($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'].' restart');
325         if($conf['courier']['courier-imap'] != '')             system($conf['init_scripts'].'/'.$conf['courier']['courier-imap'].' restart');
326         if($conf['courier']['courier-imap-ssl'] != '')         system($conf['init_scripts'].'/'.$conf['courier']['courier-imap-ssl'].' restart');
327         if($conf['courier']['courier-pop'] != '')             system($conf['init_scripts'].'/'.$conf['courier']['courier-pop'].' restart');
328         if($conf['courier']['courier-pop-ssl'] != '')         system($conf['init_scripts'].'/'.$conf['courier']['courier-pop-ssl'].' restart');
ce9544 329     }
T 330     
faf3f5 331     //** Configure Jailkit
T 332     if(strtolower($inst->simple_query('Configure Jailkit', array('y','n'),'y') ) == 'y') {    
333         swriteln('Configuring Jailkit');
334         $inst->configure_jailkit();
335     }
336     
57706b 337     //** Configure Pureftpd
P 338     if(strtolower($inst->simple_query('Configure FTP Server', array('y','n'),'y') ) == 'y') {    
ce9544 339         swriteln('Configuring Pureftpd');
T 340         $inst->configure_pureftpd();
1a14f4 341         if($conf['pureftpd']['init_script'] != '') system($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'].' restart');
ce9544 342     }
T 343     
57706b 344     //** Configure MyDNS
ce9544 345     if(strtolower($inst->simple_query('Configure DNS Server',array('y','n'),'y')) == 'y') {
0a1f02 346         $conf['services']['dns'] = true;
ce9544 347         swriteln('Configuring MyDNS');
T 348         $inst->configure_mydns();
1a14f4 349         if($conf['mydns']['init_script'] != '')    system($conf['init_scripts'].'/'.$conf['mydns']['init_script'].' restart &> /dev/null');
ce9544 350     }
T 351     
57706b 352     //** Configure Apache
12e3ba 353     swriteln("\nHint: If this server shall run the ispconfig interface, select 'y' in the next option.\n");
57706b 354     if(strtolower($inst->simple_query('Configure Apache Server',array('y','n'),'y')) == 'y') {    
0a1f02 355         $conf['services']['web'] = true;
313e33 356         swriteln('Configuring Apache');
T 357         $inst->configure_apache();
358     }
359     
7c99ef 360     //** Configure Firewall
T 361     if(strtolower($inst->simple_query('Configure Firewall Server',array('y','n'),'y')) == 'y') {    
362         swriteln('Configuring Firewall');
363         $inst->configure_firewall();
364     }
365     
57706b 366     //** Configure ISPConfig :-)
ac4a37 367     if(strtolower($inst->simple_query('Install ISPConfig Web-Interface',array('y','n'),'y')) == 'y') {
ce9544 368         swriteln('Installing ISPConfig');
54c0c3 369         
T 370         //** We want to check if the server is a module or cgi based php enabled server
a768b9 371         //** TODO: Don't always ask for this somehow ?
T 372         /*
54c0c3 373         $fast_cgi = $inst->simple_query('CGI PHP Enabled Server?', array('yes','no'),'no');
T 374
375         if($fast_cgi == 'yes') {
376              $alias = $inst->free_query('Script Alias', '/php/');
377              $path = $inst->free_query('Script Alias Path', '/path/to/cgi/bin');
cd972d 378              $conf['apache']['vhost_cgi_alias'] = sprintf('ScriptAlias %s %s', $alias, $path);
54c0c3 379         } else {
cd972d 380              $conf['apache']['vhost_cgi_alias'] = "";
54c0c3 381         }
a768b9 382         */
54c0c3 383
T 384         //** Customise the port ISPConfig runs on
cd972d 385         $conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', '8080');
54c0c3 386         
ac4a37 387         $inst->install_ispconfig_interface = true;
T 388             
389     } else {
390         $inst->install_ispconfig_interface = false;
ce9544 391     }
T 392     
ac4a37 393     $inst->install_ispconfig();
d83fcf 394     
T 395     //* Configure DBServer
396     swriteln('Configuring DBServer');
397     $inst->configure_dbserver();
ac4a37 398         
T 399     //* Configure ISPConfig
400     swriteln('Installing Crontab');
401     $inst->install_crontab();
8fb5dd 402     if($conf['apache']['init_script'] != '' && @is_file($conf['init_scripts'].'/'.$conf['apache']['init_script'])) system($conf['init_scripts'].'/'.$conf['apache']['init_script'].' restart');
ac4a37 403     
T 404     
405     
57706b 406 } //* << $install_mode / 'Standard' or Genius
ce9544 407
9200ad 408
57706b 409 echo "Installation completed.\n";
9200ad 410
T 411
57706b 412 ?>