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 |
|
00dfba
|
31 |
/* |
R |
32 |
ISPConfig 3 updater. |
|
33 |
*/ |
098b2f
|
34 |
|
00dfba
|
35 |
error_reporting(E_ALL|E_STRICT); |
R |
36 |
|
4585cf
|
37 |
//** The banner on the command line |
T |
38 |
echo "\n\n".str_repeat('-',80)."\n"; |
|
39 |
echo " _____ ___________ _____ __ _ |
|
40 |
|_ _/ ___| ___ \ / __ \ / _(_) |
|
41 |
| | \ `--.| |_/ / | / \/ ___ _ __ | |_ _ __ _ |
|
42 |
| | `--. \ __/ | | / _ \| '_ \| _| |/ _` | |
|
43 |
_| |_/\__/ / | | \__/\ (_) | | | | | | | (_| | |
|
44 |
\___/\____/\_| \____/\___/|_| |_|_| |_|\__, | |
|
45 |
__/ | |
|
46 |
|___/ "; |
|
47 |
echo "\n".str_repeat('-',80)."\n"; |
|
48 |
echo "\n\n>> Update \n\n"; |
e2d6ed
|
49 |
|
098b2f
|
50 |
//** Include the library with the basic installer functions |
e2d6ed
|
51 |
require_once('lib/install.lib.php'); |
T |
52 |
|
098b2f
|
53 |
//** Include the base class of the installer class |
e2d6ed
|
54 |
require_once('lib/installer_base.lib.php'); |
T |
55 |
|
00dfba
|
56 |
//** Install logfile |
cc3fb3
|
57 |
define('ISPC_LOG_FILE', '/var/log/ispconfig_install.log'); |
faf3f5
|
58 |
define('ISPC_INSTALL_ROOT', realpath(dirname(__FILE__).'/../')); |
cc3fb3
|
59 |
|
0c0d28
|
60 |
//** Check for ISPConfig 2.x versions |
T |
61 |
if(is_dir('/root/ispconfig') || is_dir('/home/admispconfig')) { |
|
62 |
die('This software can not be installed on a server wich runs ISPConfig 2.x.'); |
|
63 |
} |
|
64 |
|
cc3fb3
|
65 |
//** Get distribution identifier |
90511b
|
66 |
$dist = get_distname(); |
e2d6ed
|
67 |
|
T |
68 |
include_once("/usr/local/ispconfig/server/lib/config.inc.php"); |
|
69 |
$conf_old = $conf; |
b8d8d3
|
70 |
unset($conf); |
e2d6ed
|
71 |
|
90511b
|
72 |
if($dist['id'] == '') die('Linux Dustribution or Version not recognized.'); |
T |
73 |
|
098b2f
|
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'); |
T |
76 |
include_once('dist/lib/'.$dist['id'].'.lib.php'); |
|
77 |
include_once('dist/conf/'.$dist['id'].'.conf.php'); |
e2d6ed
|
78 |
|
35bcf2
|
79 |
//** Get hostname |
T |
80 |
exec('hostname -f', $tmp_out); |
|
81 |
$conf['hostname'] = $tmp_out[0]; |
|
82 |
unset($tmp_out); |
|
83 |
|
|
84 |
|
098b2f
|
85 |
//** Set the mysql login information |
20218c
|
86 |
$conf["mysql"]["host"] = $conf_old["db_host"]; |
M |
87 |
$conf["mysql"]["database"] = $conf_old["db_database"]; |
00dfba
|
88 |
$conf['mysql']['charset'] = 'utf8'; |
20218c
|
89 |
$conf["mysql"]["ispconfig_user"] = $conf_old["db_user"]; |
M |
90 |
$conf["mysql"]["ispconfig_password"] = $conf_old["db_password"]; |
e2d6ed
|
91 |
|
72d7c3
|
92 |
if(isset($conf_old["dbmaster_host"])) $conf["mysql"]["master_host"] = $conf_old["dbmaster_host"]; |
T |
93 |
if(isset($conf_old["dbmaster_database"])) $conf["mysql"]["master_database"] = $conf_old["dbmaster_database"]; |
|
94 |
if(isset($conf_old["dbmaster_user"])) $conf["mysql"]["master_ispconfig_user"] = $conf_old["dbmaster_user"]; |
|
95 |
if(isset($conf_old["dbmaster_password"])) $conf["mysql"]["master_ispconfig_password"] = $conf_old["dbmaster_password"]; |
00e597
|
96 |
|
cd972d
|
97 |
// Resolve the IP address of the mysql hostname. |
T |
98 |
if(!$conf['mysql']['ip'] = gethostbyname($conf['mysql']['host'])) die('Unable to resolve hostname'.$conf['mysql']['host']); |
|
99 |
|
392450
|
100 |
$conf['server_id'] = intval($conf_old["server_id"]); |
53ffea
|
101 |
$conf['ispconfig_log_priority'] = $conf_old["log_priority"]; |
4f7028
|
102 |
|
e2d6ed
|
103 |
$inst = new installer(); |
4f68a7
|
104 |
$inst->is_update = true; |
e2d6ed
|
105 |
|
0a1f02
|
106 |
//** Detect the installed applications |
T |
107 |
$inst->find_installed_apps(); |
|
108 |
|
e2d6ed
|
109 |
echo "This application will update ISPConfig 3 on your server.\n"; |
T |
110 |
|
098b2f
|
111 |
//** Initialize the MySQL server connection |
e2d6ed
|
112 |
include_once('lib/mysql.lib.php'); |
T |
113 |
|
098b2f
|
114 |
//** Database update is a bit brute force and should be rebuild later ;) |
e2d6ed
|
115 |
|
098b2f
|
116 |
//** Ask user for mysql admin_password if empty |
cc3fb3
|
117 |
if( empty($conf["mysql"]["admin_password"]) ) { |
O |
118 |
|
|
119 |
$conf["mysql"]["admin_password"] = $inst->free_query('MySQL root password', $conf['mysql']['admin_password']); |
|
120 |
} |
|
121 |
|
098b2f
|
122 |
//** export the current database data |
cc3fb3
|
123 |
if( !empty($conf["mysql"]["admin_password"]) ) { |
O |
124 |
|
|
125 |
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"); |
|
126 |
} |
|
127 |
else { |
|
128 |
|
|
129 |
system("mysqldump -h ".$conf['mysql']['host']." -u ".$conf['mysql']['admin_user']." -c -t --add-drop-table --all --quick ".$conf['mysql']['database']." > existing_db.sql"); |
|
130 |
} |
|
131 |
|
392450
|
132 |
|
T |
133 |
//* initialize the database |
cc3fb3
|
134 |
$inst->db = new db(); |
O |
135 |
|
392450
|
136 |
//* Update $conf array with values from the server.ini that shall be preserved |
T |
137 |
$tmp = $inst->db->queryOneRecord("SELECT * FROM ".$conf["mysql"]["database"].".server WHERE server_id = ".$conf['server_id']); |
9eff6c
|
138 |
$ini_array = ini_to_array(stripslashes($tmp['config'])); |
392450
|
139 |
|
T |
140 |
$conf['services']['mail'] = ($tmp['mail_server'] == 1)?true:false; |
|
141 |
$conf['services']['web'] = ($tmp['web_server'] == 1)?true:false; |
|
142 |
$conf['services']['dns'] = ($tmp['dns_server'] == 1)?true:false; |
|
143 |
$conf['services']['file'] = ($tmp['file_server'] == 1)?true:false; |
|
144 |
$conf['services']['db'] = ($tmp['db_server'] == 1)?true:false; |
|
145 |
$conf['services']['vserver'] = ($tmp['vserver_server'] == 1)?true:false; |
9eff6c
|
146 |
$conf['postfix']['vmail_mailbox_base'] = $ini_array['mail']['homedir_path']; |
392450
|
147 |
|
T |
148 |
//** Delete the old database |
cc3fb3
|
149 |
if( !$inst->db->query('DROP DATABASE IF EXISTS '.$conf['mysql']['database']) ) { |
O |
150 |
|
|
151 |
$inst->error('Unable to drop MySQL database: '.$conf['mysql']['database'].'.'); |
cb1d8b
|
152 |
} |
T |
153 |
|
098b2f
|
154 |
//** Create the mysql database |
e2d6ed
|
155 |
$inst->configure_database(); |
T |
156 |
|
098b2f
|
157 |
//** empty all databases |
e2d6ed
|
158 |
$db_tables = $inst->db->getTables(); |
098b2f
|
159 |
|
e2d6ed
|
160 |
foreach($db_tables as $table) { |
098b2f
|
161 |
|
e2d6ed
|
162 |
$inst->db->query("TRUNCATE $table"); |
T |
163 |
} |
|
164 |
|
098b2f
|
165 |
//** load old data back into database |
O |
166 |
if( !empty($conf["mysql"]["admin_password"]) ) { |
|
167 |
|
00dfba
|
168 |
system("mysql --default-character-set=".$conf['mysql']['charset']." -h ".$conf['mysql']['host']." -u ".$conf['mysql']['admin_user']." -p".$conf['mysql']['admin_password']." ".$conf['mysql']['database']." < existing_db.sql"); |
cb1d8b
|
169 |
} else { |
098b2f
|
170 |
|
00dfba
|
171 |
system("mysql --default-character-set=".$conf['mysql']['charset']." -h ".$conf['mysql']['host']." -u ".$conf['mysql']['admin_user']." ".$conf['mysql']['database']." < existing_db.sql"); |
cb1d8b
|
172 |
} |
098b2f
|
173 |
|
7f702a
|
174 |
// create a backup copy of the ispconfig database in the root folder |
faf3f5
|
175 |
$backup_db_name = '/root/ispconfig_db_backup_'.@date('Y-m-d_h-i').'.sql'; |
7f702a
|
176 |
copy('existing_db.sql',$backup_db_name); |
T |
177 |
exec("chmod 700 $backup_db_name"); |
|
178 |
exec("chown root:root $backup_db_name"); |
|
179 |
|
|
180 |
|
4f7028
|
181 |
//** Update server ini |
T |
182 |
$tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM server WHERE server_id = ".$conf['server_id']); |
|
183 |
$old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config'])); |
|
184 |
unset($tmp_server_rec); |
|
185 |
$tpl_ini_array = ini_to_array(rf('tpl/server.ini.master')); |
|
186 |
|
|
187 |
// update the new template with the old values |
faf3f5
|
188 |
if(is_array($old_ini_array)) { |
T |
189 |
foreach($old_ini_array as $tmp_section_name => $tmp_section_content) { |
|
190 |
foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) { |
|
191 |
$tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content; |
|
192 |
} |
4f7028
|
193 |
} |
T |
194 |
} |
|
195 |
|
|
196 |
$new_ini = array_to_ini($tpl_ini_array); |
8500be
|
197 |
$inst->db->query("UPDATE server SET config = '".mysql_real_escape_string($new_ini)."' WHERE server_id = ".$conf['server_id']); |
4f7028
|
198 |
unset($old_ini_array); |
T |
199 |
unset($tpl_ini_array); |
|
200 |
unset($new_ini); |
|
201 |
|
|
202 |
|
db5aa6
|
203 |
//** Update system ini |
T |
204 |
$tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM sys_ini WHERE sysini_id = 1"); |
|
205 |
$old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config'])); |
|
206 |
unset($tmp_server_rec); |
|
207 |
$tpl_ini_array = ini_to_array(rf('tpl/system.ini.master')); |
|
208 |
|
|
209 |
// update the new template with the old values |
|
210 |
if(is_array($old_ini_array)) { |
|
211 |
foreach($old_ini_array as $tmp_section_name => $tmp_section_content) { |
|
212 |
foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) { |
|
213 |
$tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content; |
|
214 |
} |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
$new_ini = array_to_ini($tpl_ini_array); |
78f1a6
|
219 |
$tmp = $inst->db->queryOneRecord('SELECT count(sysini_id) as number FROM sys_ini WHERE 1'); |
T |
220 |
if($tmp['number'] == 0) { |
|
221 |
$inst->db->query("INSERT INTO sys_ini (sysini_id, config) VALUES (1,'".mysql_real_escape_string($new_ini)."')"); |
|
222 |
} else { |
|
223 |
$inst->db->query("UPDATE sys_ini SET config = '".mysql_real_escape_string($new_ini)."' WHERE sysini_id = 1"); |
|
224 |
} |
db5aa6
|
225 |
unset($old_ini_array); |
T |
226 |
unset($tpl_ini_array); |
|
227 |
unset($new_ini); |
|
228 |
|
|
229 |
|
00d96b
|
230 |
//** Shall the services be reconfigured during update |
e2ef16
|
231 |
$reconfigure_services_answer = $inst->simple_query('Reconfigure Services?', array('yes','no'),'yes'); |
e2d6ed
|
232 |
|
00d96b
|
233 |
if($reconfigure_services_answer == 'yes') { |
61d290
|
234 |
|
392450
|
235 |
if($conf['services']['mail']) { |
T |
236 |
//** Configure postfix |
132223
|
237 |
swriteln('Configuring Postfix'); |
392450
|
238 |
$inst->configure_postfix('dont-create-certs'); |
61d290
|
239 |
|
132223
|
240 |
//* Configure Jailkit |
392450
|
241 |
swriteln('Configuring Jailkit'); |
T |
242 |
$inst->configure_jailkit(); |
00d96b
|
243 |
|
392450
|
244 |
//** Configure saslauthd |
T |
245 |
swriteln('Configuring SASL'); |
|
246 |
$inst->configure_saslauthd(); |
d83fcf
|
247 |
|
392450
|
248 |
//** Configure PAM |
T |
249 |
swriteln('Configuring PAM'); |
|
250 |
$inst->configure_pam(); |
|
251 |
|
|
252 |
//** Configure courier |
|
253 |
swriteln('Configuring Courier'); |
|
254 |
$inst->configure_courier(); |
|
255 |
|
|
256 |
//** Configure Spamasassin |
|
257 |
swriteln('Configuring Spamassassin'); |
|
258 |
$inst->configure_spamassassin(); |
|
259 |
|
|
260 |
//** Configure Amavis |
|
261 |
swriteln('Configuring Amavisd'); |
|
262 |
$inst->configure_amavis(); |
|
263 |
|
|
264 |
//** Configure Getmail |
|
265 |
swriteln('Configuring Getmail'); |
|
266 |
$inst->configure_getmail(); |
|
267 |
} |
|
268 |
|
|
269 |
if($conf['services']['web']) { |
|
270 |
//** Configure Pureftpd |
|
271 |
swriteln('Configuring Pureftpd'); |
|
272 |
$inst->configure_pureftpd(); |
|
273 |
} |
|
274 |
|
|
275 |
if($conf['services']['dns']) { |
|
276 |
//** Configure MyDNS |
|
277 |
swriteln('Configuring MyDNS'); |
|
278 |
$inst->configure_mydns(); |
|
279 |
} |
|
280 |
|
|
281 |
if($conf['services']['web']) { |
|
282 |
//** Configure Apache |
|
283 |
swriteln('Configuring Apache'); |
|
284 |
$inst->configure_apache(); |
|
285 |
} |
|
286 |
|
|
287 |
|
d83fcf
|
288 |
//* Configure DBServer |
392450
|
289 |
swriteln('Configuring Database'); |
d83fcf
|
290 |
$inst->configure_dbserver(); |
392450
|
291 |
|
7c99ef
|
292 |
|
69db55
|
293 |
//if(@is_dir('/etc/Bastille')) { |
392450
|
294 |
//* Configure Firewall |
T |
295 |
swriteln('Configuring Firewall'); |
|
296 |
$inst->configure_firewall(); |
69db55
|
297 |
//} |
00d96b
|
298 |
} |
313e33
|
299 |
|
098b2f
|
300 |
//** Configure ISPConfig |
00d96b
|
301 |
swriteln('Updating ISPConfig'); |
9b9ba4
|
302 |
|
D |
303 |
|
|
304 |
//** Customise the port ISPConfig runs on |
cd972d
|
305 |
$conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', '8080'); |
9b9ba4
|
306 |
|
e2d6ed
|
307 |
$inst->install_ispconfig(); |
T |
308 |
|
00d96b
|
309 |
//** Configure Crontab |
6eb2af
|
310 |
$update_crontab_answer = $inst->simple_query('Reconfigure Crontab?', array('yes','no'),'yes'); |
00d96b
|
311 |
if($update_crontab_answer == 'yes') { |
T |
312 |
swriteln('Updating Crontab'); |
|
313 |
$inst->install_crontab(); |
|
314 |
} |
e2d6ed
|
315 |
|
098b2f
|
316 |
//** Restart services: |
00d96b
|
317 |
if($reconfigure_services_answer == 'yes') { |
T |
318 |
swriteln('Restarting services ...'); |
2ce158
|
319 |
if($conf['mysql']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['mysql']['init_script'])) system($conf['init_scripts'].'/'.$conf['mysql']['init_script'].' restart'); |
392450
|
320 |
if($conf['services']['mail']) { |
2ce158
|
321 |
if($conf['postfix']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['postfix']['init_script'])) system($conf['init_scripts'].'/'.$conf['postfix']['init_script'].' restart'); |
T |
322 |
if($conf['saslauthd']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['saslauthd']['init_script'])) system($conf['init_scripts'].'/'.$conf['saslauthd']['init_script'].' restart'); |
|
323 |
if($conf['amavis']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['amavis']['init_script'])) system($conf['init_scripts'].'/'.$conf['amavis']['init_script'].' restart'); |
|
324 |
if($conf['clamav']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['clamav']['init_script'])) system($conf['init_scripts'].'/'.$conf['clamav']['init_script'].' restart'); |
|
325 |
if($conf['courier']['courier-authdaemon'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'])) system($conf['init_scripts'].'/'.$conf['courier']['courier-authdaemon'].' restart'); |
|
326 |
if($conf['courier']['courier-imap'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-imap'])) system($conf['init_scripts'].'/'.$conf['courier']['courier-imap'].' restart'); |
|
327 |
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'); |
|
328 |
if($conf['courier']['courier-pop'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-pop'])) system($conf['init_scripts'].'/'.$conf['courier']['courier-pop'].' restart'); |
|
329 |
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'); |
392450
|
330 |
} |
T |
331 |
if($conf['services']['web']) { |
2ce158
|
332 |
if($conf['apache']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['apache']['init_script'])) system($conf['init_scripts'].'/'.$conf['apache']['init_script'].' restart'); |
T |
333 |
if($conf['pureftpd']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'])) system($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'].' restart'); |
392450
|
334 |
} |
T |
335 |
if($conf['services']['dns']) { |
2ce158
|
336 |
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'); |
392450
|
337 |
} |
00d96b
|
338 |
} |
e2d6ed
|
339 |
|
T |
340 |
echo "Update finished.\n"; |
|
341 |
|
20218c
|
342 |
?> |