commit | author | age
|
465c9e
|
1 |
<?php |
V |
2 |
/* |
|
3 |
Copyright (c) 2007-2010, Till Brehm, projektfarm Gmbh |
|
4 |
All rights reserved. |
|
5 |
|
|
6 |
Redistribution and use in source and binary forms, with or without modification, |
|
7 |
are permitted provided that the following conditions are met: |
|
8 |
|
|
9 |
* Redistributions of source code must retain the above copyright notice, |
|
10 |
this list of conditions and the following disclaimer. |
|
11 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
12 |
this list of conditions and the following disclaimer in the documentation |
|
13 |
and/or other materials provided with the distribution. |
|
14 |
* Neither the name of ISPConfig nor the names of its contributors |
|
15 |
may be used to endorse or promote products derived from this software without |
|
16 |
specific prior written permission. |
|
17 |
|
|
18 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
19 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
21 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
22 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
23 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
25 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
26 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
27 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
*/ |
|
29 |
|
|
30 |
function prepareDBDump() { |
|
31 |
global $conf; |
|
32 |
|
|
33 |
//** load the pre update sql script do perform modifications on the database before the database is dumped |
|
34 |
if(is_file(ISPC_INSTALL_ROOT."/install/sql/pre_update.sql")) { |
|
35 |
if($conf['mysql']['admin_password'] == '') { |
|
36 |
caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' '".$conf['mysql']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/pre_update.sql' &> /dev/null", __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); |
|
37 |
} else { |
|
38 |
caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' '".$conf['mysql']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/pre_update.sql' &> /dev/null", __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 |
//** export the current database data |
|
43 |
if( !empty($conf["mysql"]["admin_password"]) ) { |
|
44 |
|
|
45 |
system("mysqldump -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' -c -t --add-drop-table --create-options --quick --result-file=existing_db.sql ".$conf['mysql']['database']); |
|
46 |
} |
|
47 |
else { |
|
48 |
|
|
49 |
system("mysqldump -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -c -t --add-drop-table --create-options --quick --result-file=existing_db.sql ".$conf['mysql']['database']); |
|
50 |
} |
|
51 |
|
0f5973
|
52 |
/* |
V |
53 |
* If we have a server with nothing in it except VE's then the database of thie server is empty. |
|
54 |
* so the following line will no longer work! |
|
55 |
*/ |
|
56 |
//if(filesize('existing_db.sql') < 30000) die('Possible problem with dumping the database. We will stop here. Please check the file existing_db.sql'); |
465c9e
|
57 |
|
V |
58 |
// create a backup copy of the ispconfig database in the root folder |
|
59 |
$backup_db_name = '/root/ispconfig_db_backup_'.@date('Y-m-d_h-i').'.sql'; |
|
60 |
copy('existing_db.sql',$backup_db_name); |
|
61 |
exec("chmod 700 $backup_db_name"); |
|
62 |
exec("chown root:root $backup_db_name"); |
|
63 |
} |
|
64 |
|
|
65 |
function updateDbAndIni() { |
|
66 |
global $inst, $conf; |
|
67 |
|
|
68 |
//* Update $conf array with values from the server.ini that shall be preserved |
|
69 |
$tmp = $inst->db->queryOneRecord("SELECT * FROM ".$conf["mysql"]["database"].".server WHERE server_id = ".$conf['server_id']); |
|
70 |
$ini_array = ini_to_array(stripslashes($tmp['config'])); |
3250e5
|
71 |
$current_db_version = (isset($tmp['dbversion']))?intval($tmp['dbversion']):0; |
465c9e
|
72 |
|
V |
73 |
if(count($ini_array) == 0) die('Unable to read server configuration from database.'); |
|
74 |
|
|
75 |
$conf['services']['mail'] = ($tmp['mail_server'] == 1)?true:false; |
|
76 |
$conf['services']['web'] = ($tmp['web_server'] == 1)?true:false; |
|
77 |
$conf['services']['dns'] = ($tmp['dns_server'] == 1)?true:false; |
|
78 |
$conf['services']['file'] = ($tmp['file_server'] == 1)?true:false; |
|
79 |
$conf['services']['db'] = ($tmp['db_server'] == 1)?true:false; |
|
80 |
$conf['services']['vserver'] = ($tmp['vserver_server'] == 1)?true:false; |
|
81 |
$conf['postfix']['vmail_mailbox_base'] = $ini_array['mail']['homedir_path']; |
3250e5
|
82 |
|
T |
83 |
//* Do incremental DB updates only on installed ISPConfig versions > 3.0.3 |
|
84 |
if(compare_ispconfig_version('3.0.3',ISPC_APP_VERSION) >= 0) { |
|
85 |
|
|
86 |
swriteln($inst->lng('Starting incremental database update.')); |
|
87 |
|
|
88 |
//* get the version of the db schema from the server table |
|
89 |
$found = true; |
|
90 |
while($found == true) { |
|
91 |
$next_db_version = intval($current_db_version + 1); |
|
92 |
$patch_filename = realpath(dirname(__FILE__).'/../').'/sql/incremental/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.sql'; |
|
93 |
if(is_file($patch_filename)) { |
|
94 |
//* Load patch file into database |
|
95 |
if( !empty($conf["mysql"]["admin_password"]) ) { |
|
96 |
system("mysql --default-character-set=".$conf['mysql']['charset']." --force -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' ".$conf['mysql']['database']." < ".$patch_filename); |
|
97 |
} else { |
|
98 |
system("mysql --default-character-set=".$conf['mysql']['charset']." --force -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' ".$conf['mysql']['database']." < ".$patch_filename); |
|
99 |
} |
|
100 |
swriteln($inst->lng('Loading SQL patch file').': '.$patch_filename); |
|
101 |
$current_db_version = $next_db_version; |
|
102 |
} else { |
|
103 |
$found = false; |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
//* update the database version in server table |
|
108 |
$inst->db->query("UPDATE ".$conf["mysql"]["database"].".server SET dbversion = '".$current_db_version."' WHERE server_id = ".$conf['server_id']); |
|
109 |
|
|
110 |
|
|
111 |
//* If ISPConfig Version < 3.0.3, we will do a full db update |
465c9e
|
112 |
} else { |
3250e5
|
113 |
|
T |
114 |
swriteln($inst->lng('Starting full database update.')); |
|
115 |
|
|
116 |
//** Delete the old database |
|
117 |
if( !$inst->db->query('DROP DATABASE IF EXISTS '.$conf['mysql']['database']) ) { |
|
118 |
$inst->error('Unable to drop MySQL database: '.$conf['mysql']['database'].'.'); |
|
119 |
} |
465c9e
|
120 |
|
3250e5
|
121 |
//** Create the mysql database |
T |
122 |
$inst->configure_database(); |
|
123 |
|
|
124 |
//** empty all databases |
|
125 |
$db_tables = $inst->db->getTables(); |
|
126 |
|
|
127 |
foreach($db_tables as $table) { |
|
128 |
$inst->db->query("TRUNCATE $table"); |
|
129 |
} |
|
130 |
|
|
131 |
//** load old data back into database |
|
132 |
if( !empty($conf["mysql"]["admin_password"]) ) { |
|
133 |
system("mysql --default-character-set=".$conf['mysql']['charset']." --force -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' ".$conf['mysql']['database']." < existing_db.sql"); |
|
134 |
} else { |
|
135 |
system("mysql --default-character-set=".$conf['mysql']['charset']." --force -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' ".$conf['mysql']['database']." < existing_db.sql"); |
|
136 |
} |
465c9e
|
137 |
} |
V |
138 |
|
|
139 |
|
|
140 |
//** Update server ini |
|
141 |
$tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM server WHERE server_id = ".$conf['server_id']); |
|
142 |
$old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config'])); |
|
143 |
unset($tmp_server_rec); |
|
144 |
$tpl_ini_array = ini_to_array(rf('tpl/server.ini.master')); |
3250e5
|
145 |
|
T |
146 |
//* Update further distribution specific parameters for server config here |
|
147 |
//* HINT: Every line added here has to be added in installer_base.lib.php too!! |
|
148 |
$tpl_ini_array['web']['vhost_conf_dir'] = $conf['apache']['vhost_conf_dir']; |
|
149 |
$tpl_ini_array['web']['vhost_conf_enabled_dir'] = $conf['apache']['vhost_conf_enabled_dir']; |
|
150 |
$tpl_ini_array['jailkit']['jailkit_chroot_app_programs'] = $conf['jailkit']['jailkit_chroot_app_programs']; |
|
151 |
$tpl_ini_array['fastcgi']['fastcgi_phpini_path'] = $conf['fastcgi']['fastcgi_phpini_path']; |
|
152 |
$tpl_ini_array['fastcgi']['fastcgi_starter_path'] = $conf['fastcgi']['fastcgi_starter_path']; |
|
153 |
$tpl_ini_array['server']['hostname'] = $conf['hostname']; |
|
154 |
$tpl_ini_array['server']['ip_address'] = @gethostbyname($conf['hostname']); |
|
155 |
$tpl_ini_array['web']['website_basedir'] = $conf['web']['website_basedir']; |
|
156 |
$tpl_ini_array['web']['website_path'] = $conf['web']['website_path']; |
|
157 |
$tpl_ini_array['web']['website_symlinks'] = $conf['web']['website_symlinks']; |
|
158 |
$tpl_ini_array['cron']['crontab_dir'] = $conf['cron']['crontab_dir']; |
|
159 |
$tpl_ini_array['web']['security_level'] = 20; |
|
160 |
$tpl_ini_array['web']['user'] = $conf['apache']['user']; |
|
161 |
$tpl_ini_array['web']['group'] = $conf['apache']['group']; |
|
162 |
$tpl_ini_array['web']['php_ini_path_apache'] = $conf['apache']['php_ini_path_apache']; |
|
163 |
$tpl_ini_array['web']['php_ini_path_cgi'] = $conf['apache']['php_ini_path_cgi']; |
|
164 |
$tpl_ini_array['mail']['pop3_imap_daemon'] = ($conf['dovecot']['installed'] == true)?'dovecot':'courier'; |
|
165 |
$tpl_ini_array['mail']['mail_filter_syntax'] = ($conf['dovecot']['installed'] == true)?'sieve':'maildrop'; |
|
166 |
$tpl_ini_array['dns']['bind_user'] = $conf['bind']['bind_user']; |
|
167 |
$tpl_ini_array['dns']['bind_group'] = $conf['bind']['bind_group']; |
|
168 |
$tpl_ini_array['dns']['bind_zonefiles_dir'] = $conf['bind']['bind_zonefiles_dir']; |
|
169 |
$tpl_ini_array['dns']['named_conf_path'] = $conf['bind']['named_conf_path']; |
|
170 |
$tpl_ini_array['dns']['named_conf_local_path'] = $conf['bind']['named_conf_local_path']; |
465c9e
|
171 |
|
V |
172 |
// update the new template with the old values |
|
173 |
if(is_array($old_ini_array)) { |
|
174 |
foreach($old_ini_array as $tmp_section_name => $tmp_section_content) { |
|
175 |
foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) { |
|
176 |
$tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content; |
|
177 |
} |
|
178 |
} |
|
179 |
} |
|
180 |
|
|
181 |
$new_ini = array_to_ini($tpl_ini_array); |
|
182 |
$inst->db->query("UPDATE server SET config = '".mysql_real_escape_string($new_ini)."' WHERE server_id = ".$conf['server_id']); |
|
183 |
unset($old_ini_array); |
|
184 |
unset($tpl_ini_array); |
|
185 |
unset($new_ini); |
|
186 |
|
|
187 |
|
|
188 |
//** Update system ini |
|
189 |
$tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM sys_ini WHERE sysini_id = 1"); |
|
190 |
$old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config'])); |
|
191 |
unset($tmp_server_rec); |
|
192 |
$tpl_ini_array = ini_to_array(rf('tpl/system.ini.master')); |
|
193 |
|
|
194 |
// update the new template with the old values |
|
195 |
if(is_array($old_ini_array)) { |
|
196 |
foreach($old_ini_array as $tmp_section_name => $tmp_section_content) { |
|
197 |
foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) { |
|
198 |
$tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content; |
|
199 |
} |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
$new_ini = array_to_ini($tpl_ini_array); |
|
204 |
$tmp = $inst->db->queryOneRecord('SELECT count(sysini_id) as number FROM sys_ini WHERE 1'); |
|
205 |
if($tmp['number'] == 0) { |
|
206 |
$inst->db->query("INSERT INTO sys_ini (sysini_id, config) VALUES (1,'".mysql_real_escape_string($new_ini)."')"); |
|
207 |
} else { |
|
208 |
$inst->db->query("UPDATE sys_ini SET config = '".mysql_real_escape_string($new_ini)."' WHERE sysini_id = 1"); |
|
209 |
} |
|
210 |
unset($old_ini_array); |
|
211 |
unset($tpl_ini_array); |
|
212 |
unset($new_ini); |
|
213 |
} |
|
214 |
|
|
215 |
?> |