commit | author | age
|
e2d6ed
|
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 |
|
098b2f
|
31 |
|
O |
32 |
//** ISPConfig 3 installer. |
4585cf
|
33 |
//** The banner on the command line |
T |
34 |
echo "\n\n".str_repeat('-',80)."\n"; |
|
35 |
echo " _____ ___________ _____ __ _ |
|
36 |
|_ _/ ___| ___ \ / __ \ / _(_) |
|
37 |
| | \ `--.| |_/ / | / \/ ___ _ __ | |_ _ __ _ |
|
38 |
| | `--. \ __/ | | / _ \| '_ \| _| |/ _` | |
|
39 |
_| |_/\__/ / | | \__/\ (_) | | | | | | | (_| | |
|
40 |
\___/\____/\_| \____/\___/|_| |_|_| |_|\__, | |
|
41 |
__/ | |
|
42 |
|___/ "; |
|
43 |
echo "\n".str_repeat('-',80)."\n"; |
|
44 |
echo "\n\n>> Update \n\n"; |
e2d6ed
|
45 |
|
008770
|
46 |
|
098b2f
|
47 |
//** Include the library with the basic installer functions |
e2d6ed
|
48 |
require_once('lib/install.lib.php'); |
T |
49 |
|
098b2f
|
50 |
//** Include the base class of the installer class |
e2d6ed
|
51 |
require_once('lib/installer_base.lib.php'); |
T |
52 |
|
098b2f
|
53 |
//** Installer/updater logfile |
cc3fb3
|
54 |
define('ISPC_LOG_FILE', '/var/log/ispconfig_install.log'); |
O |
55 |
|
0c0d28
|
56 |
//** Check for ISPConfig 2.x versions |
T |
57 |
if(is_dir('/root/ispconfig') || is_dir('/home/admispconfig')) { |
|
58 |
die('This software can not be installed on a server wich runs ISPConfig 2.x.'); |
|
59 |
} |
|
60 |
|
cc3fb3
|
61 |
//** Get distribution identifier |
90511b
|
62 |
$dist = get_distname(); |
e2d6ed
|
63 |
|
T |
64 |
include_once("/usr/local/ispconfig/server/lib/config.inc.php"); |
|
65 |
$conf_old = $conf; |
b8d8d3
|
66 |
unset($conf); |
e2d6ed
|
67 |
|
90511b
|
68 |
if($dist['id'] == '') die('Linux Dustribution or Version not recognized.'); |
T |
69 |
|
098b2f
|
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'); |
T |
72 |
include_once('dist/lib/'.$dist['id'].'.lib.php'); |
|
73 |
include_once('dist/conf/'.$dist['id'].'.conf.php'); |
e2d6ed
|
74 |
|
35bcf2
|
75 |
//** Get hostname |
T |
76 |
exec('hostname -f', $tmp_out); |
|
77 |
$conf['hostname'] = $tmp_out[0]; |
|
78 |
unset($tmp_out); |
|
79 |
|
|
80 |
|
098b2f
|
81 |
//** Set the mysql login information |
20218c
|
82 |
$conf["mysql"]["host"] = $conf_old["db_host"]; |
M |
83 |
$conf["mysql"]["database"] = $conf_old["db_database"]; |
|
84 |
$conf["mysql"]["ispconfig_user"] = $conf_old["db_user"]; |
|
85 |
$conf["mysql"]["ispconfig_password"] = $conf_old["db_password"]; |
e2d6ed
|
86 |
|
cd972d
|
87 |
// Resolve the IP address of the mysql hostname. |
T |
88 |
if(!$conf['mysql']['ip'] = gethostbyname($conf['mysql']['host'])) die('Unable to resolve hostname'.$conf['mysql']['host']); |
|
89 |
|
4f7028
|
90 |
$conf['server_id'] = $conf_old["server_id"]; |
53ffea
|
91 |
$conf['ispconfig_log_priority'] = $conf_old["log_priority"]; |
4f7028
|
92 |
|
e2d6ed
|
93 |
$inst = new installer(); |
T |
94 |
|
|
95 |
echo "This application will update ISPConfig 3 on your server.\n"; |
|
96 |
|
098b2f
|
97 |
//** Initialize the MySQL server connection |
e2d6ed
|
98 |
include_once('lib/mysql.lib.php'); |
T |
99 |
|
098b2f
|
100 |
//** Database update is a bit brute force and should be rebuild later ;) |
e2d6ed
|
101 |
|
098b2f
|
102 |
//** Ask user for mysql admin_password if empty |
cc3fb3
|
103 |
if( empty($conf["mysql"]["admin_password"]) ) { |
O |
104 |
|
|
105 |
$conf["mysql"]["admin_password"] = $inst->free_query('MySQL root password', $conf['mysql']['admin_password']); |
|
106 |
} |
|
107 |
|
098b2f
|
108 |
//** export the current database data |
cc3fb3
|
109 |
if( !empty($conf["mysql"]["admin_password"]) ) { |
O |
110 |
|
|
111 |
system("mysqldump -h ".$conf['mysql']['host']." -u ".$conf['mysql']['admin_user']." -p".$conf['mysql']['admin_password']." -c -t --add-drop-table --all --quick ".$conf['mysql']['database']." > existing_db.sql"); |
|
112 |
} |
|
113 |
else { |
|
114 |
|
|
115 |
system("mysqldump -h ".$conf['mysql']['host']." -u ".$conf['mysql']['admin_user']." -c -t --add-drop-table --all --quick ".$conf['mysql']['database']." > existing_db.sql"); |
|
116 |
} |
|
117 |
|
098b2f
|
118 |
//** Delete the old database |
cc3fb3
|
119 |
$inst->db = new db(); |
O |
120 |
|
|
121 |
if( !$inst->db->query('DROP DATABASE IF EXISTS '.$conf['mysql']['database']) ) { |
|
122 |
|
|
123 |
$inst->error('Unable to drop MySQL database: '.$conf['mysql']['database'].'.'); |
cb1d8b
|
124 |
} |
T |
125 |
|
098b2f
|
126 |
//** Create the mysql database |
e2d6ed
|
127 |
$inst->configure_database(); |
T |
128 |
|
098b2f
|
129 |
//** empty all databases |
e2d6ed
|
130 |
$db_tables = $inst->db->getTables(); |
098b2f
|
131 |
|
e2d6ed
|
132 |
foreach($db_tables as $table) { |
098b2f
|
133 |
|
e2d6ed
|
134 |
$inst->db->query("TRUNCATE $table"); |
T |
135 |
} |
|
136 |
|
098b2f
|
137 |
//** load old data back into database |
O |
138 |
if( !empty($conf["mysql"]["admin_password"]) ) { |
|
139 |
|
cc3fb3
|
140 |
system("mysql -h ".$conf['mysql']['host']." -u ".$conf['mysql']['admin_user']." -p".$conf['mysql']['admin_password']." ".$conf['mysql']['database']." < existing_db.sql"); |
cb1d8b
|
141 |
} else { |
098b2f
|
142 |
|
cc3fb3
|
143 |
system("mysql -h ".$conf['mysql']['host']." -u ".$conf['mysql']['admin_user']." ".$conf['mysql']['database']." < existing_db.sql"); |
cb1d8b
|
144 |
} |
098b2f
|
145 |
|
4f7028
|
146 |
//** Update server ini |
T |
147 |
$tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM server WHERE server_id = ".$conf['server_id']); |
|
148 |
$old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config'])); |
|
149 |
unset($tmp_server_rec); |
|
150 |
$tpl_ini_array = ini_to_array(rf('tpl/server.ini.master')); |
|
151 |
|
|
152 |
// update the new template with the old values |
|
153 |
foreach($old_ini_array as $tmp_section_name => $tmp_section_content) { |
|
154 |
foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) { |
|
155 |
$tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content; |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
$new_ini = array_to_ini($tpl_ini_array); |
8500be
|
160 |
$inst->db->query("UPDATE server SET config = '".mysql_real_escape_string($new_ini)."' WHERE server_id = ".$conf['server_id']); |
4f7028
|
161 |
unset($old_ini_array); |
T |
162 |
unset($tpl_ini_array); |
|
163 |
unset($new_ini); |
|
164 |
|
|
165 |
|
00d96b
|
166 |
//** Shall the services be reconfigured during update |
e2ef16
|
167 |
$reconfigure_services_answer = $inst->simple_query('Reconfigure Services?', array('yes','no'),'yes'); |
e2d6ed
|
168 |
|
00d96b
|
169 |
if($reconfigure_services_answer == 'yes') { |
T |
170 |
//** Configure postfix |
|
171 |
$inst->configure_postfix('dont-create-certs'); |
61d290
|
172 |
|
D |
173 |
//* Configure postfix |
|
174 |
swriteln('Configuring Jailkit'); |
|
175 |
$inst->configure_jailkit(); |
|
176 |
|
00d96b
|
177 |
//** Configure saslauthd |
T |
178 |
swriteln('Configuring SASL'); |
|
179 |
$inst->configure_saslauthd(); |
|
180 |
|
|
181 |
//** Configure PAM |
|
182 |
swriteln('Configuring PAM'); |
|
183 |
$inst->configure_pam(); |
e2d6ed
|
184 |
|
00d96b
|
185 |
//** Configure courier |
T |
186 |
swriteln('Configuring Courier'); |
|
187 |
$inst->configure_courier(); |
e2d6ed
|
188 |
|
00d96b
|
189 |
//** Configure Spamasassin |
T |
190 |
swriteln('Configuring Spamassassin'); |
|
191 |
$inst->configure_spamassassin(); |
e2d6ed
|
192 |
|
00d96b
|
193 |
//** Configure Amavis |
T |
194 |
swriteln('Configuring Amavisd'); |
|
195 |
$inst->configure_amavis(); |
e2d6ed
|
196 |
|
00d96b
|
197 |
//** Configure Getmail |
T |
198 |
swriteln('Configuring Getmail'); |
|
199 |
$inst->configure_getmail(); |
e2d6ed
|
200 |
|
00d96b
|
201 |
//** Configure Pureftpd |
T |
202 |
swriteln('Configuring Pureftpd'); |
|
203 |
$inst->configure_pureftpd(); |
99d85e
|
204 |
|
00d96b
|
205 |
//** Configure MyDNS |
T |
206 |
swriteln('Configuring MyDNS'); |
|
207 |
$inst->configure_mydns(); |
e2d6ed
|
208 |
|
00d96b
|
209 |
//** Configure Apache |
T |
210 |
swriteln('Configuring Apache'); |
|
211 |
$inst->configure_apache(); |
d83fcf
|
212 |
|
T |
213 |
//* Configure DBServer |
|
214 |
swriteln('Configuring DBServer'); |
|
215 |
$inst->configure_dbserver(); |
7c99ef
|
216 |
|
69db55
|
217 |
//if(@is_dir('/etc/Bastille')) { |
7c99ef
|
218 |
//* Configure Firewall |
T |
219 |
swriteln('Configuring Firewall'); |
|
220 |
$inst->configure_firewall(); |
69db55
|
221 |
//} |
00d96b
|
222 |
} |
313e33
|
223 |
|
098b2f
|
224 |
//** Configure ISPConfig |
00d96b
|
225 |
swriteln('Updating ISPConfig'); |
9b9ba4
|
226 |
|
D |
227 |
|
|
228 |
//** Customise the port ISPConfig runs on |
cd972d
|
229 |
$conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', '8080'); |
9b9ba4
|
230 |
|
e2d6ed
|
231 |
$inst->install_ispconfig(); |
T |
232 |
|
00d96b
|
233 |
//** Configure Crontab |
6eb2af
|
234 |
$update_crontab_answer = $inst->simple_query('Reconfigure Crontab?', array('yes','no'),'yes'); |
00d96b
|
235 |
if($update_crontab_answer == 'yes') { |
T |
236 |
swriteln('Updating Crontab'); |
|
237 |
$inst->install_crontab(); |
|
238 |
} |
e2d6ed
|
239 |
|
098b2f
|
240 |
//** Restart services: |
00d96b
|
241 |
if($reconfigure_services_answer == 'yes') { |
T |
242 |
swriteln('Restarting services ...'); |
6444a9
|
243 |
system($conf['init_scripts'].'/'.$conf['mysql']['init_script'].' restart'); |
T |
244 |
system($conf['init_scripts'].'/'.$conf['postfix']['init_script'].' restart'); |
|
245 |
system($conf['init_scripts'].'/'.$conf['saslauthd']['init_script'].' restart'); |
|
246 |
system($conf['init_scripts'].'/'.$conf['amavis']['init_script'].' restart'); |
|
247 |
system($conf['init_scripts'].'/'.$conf['clamav']['init_script'].' restart'); |
|
248 |
system($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'].' restart'); |
|
249 |
system($conf['init_scripts'].'/'.$conf['courier']['courier-imap'].' restart'); |
|
250 |
system($conf['init_scripts'].'/'.$conf['courier']['courier-imap-ssl'].' restart'); |
|
251 |
system($conf['init_scripts'].'/'.$conf['courier']['courier-pop'].' restart'); |
|
252 |
system($conf['init_scripts'].'/'.$conf['courier']['courier-pop-ssl'].' restart'); |
|
253 |
system($conf['init_scripts'].'/'.$conf['apache']['init_script'].' restart'); |
|
254 |
system($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'].' restart'); |
|
255 |
system($conf['init_scripts'].'/'.$conf['mydns']['init_script'].' restart &> /dev/null'); |
00d96b
|
256 |
} |
e2d6ed
|
257 |
|
T |
258 |
echo "Update finished.\n"; |
|
259 |
|
20218c
|
260 |
?> |