Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
commit | author | age
9a3a78 1 <?php
L 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
992797 30 //* Installer patch stub class
MC 31 class installer_patch_update {
121e4d 32     public function onBeforeSQL() {
b1a6a5 33     }
MC 34
121e4d 35     public function onAfterSQL() {
b1a6a5 36     }
MC 37
992797 38 }
MC 39
40 //* DB dump function
9a3a78 41 function prepareDBDump() {
L 42     global $conf;
43
44     //** load the pre update sql script do perform modifications on the database before the database is dumped
45     if(is_file(ISPC_INSTALL_ROOT."/install/sql/pre_update.sql")) {
46         if($conf['mysql']['admin_password'] == '') {
02bf99 47             caselog("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." ".escapeshellarg($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');
9a3a78 48         } else {
02bf99 49             caselog("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." ".escapeshellarg($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');
9a3a78 50         }
L 51     }
52
53     //** export the current database data
54     if( !empty($conf["mysql"]["admin_password"]) ) {
55
02bf99 56         system("mysqldump -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." -c -t --add-drop-table --create-options --quick --result-file=existing_db.sql ".$conf['mysql']['database']);
9a3a78 57     }
L 58     else {
59
02bf99 60         system("mysqldump -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -c -t --add-drop-table --create-options --quick --result-file=existing_db.sql ".$conf['mysql']['database']);
9a3a78 61     }
L 62
63     /*
64      * If we have a server with nothing in it except VE's then the database of thie server is empty.
65      * so the following line will no longer work!
66      */
67     //if(filesize('existing_db.sql') < 30000) die('Possible problem with dumping the database. We will stop here. Please check the file existing_db.sql');
68
69     // create a backup copy of the ispconfig database in the root folder
8cf78b 70     if(isset($conf['backup_path'])) {
T 71         $backup_db_name = $conf['backup_path'].'/ispconfig_db_backup.sql';
72     } else {
73         $backup_db_name = '/root/ispconfig_db_backup_'.@date('Y-m-d_H-i').'.sql';
74     }
b1a6a5 75     copy('existing_db.sql', $backup_db_name);
9a3a78 76     chmod($backup_db_name, 0700);
L 77     chown($backup_db_name, 'root');
78     chgrp($backup_db_name, 'root');
79
80     if ($conf['powerdns']['installed']) {
81         //** export the current PowerDNS database data
b1a6a5 82         if( !empty($conf["mysql"]["admin_password"]) ) {
MC 83             system("mysqldump -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." -c -t --add-drop-table --create-options --quick --result-file=existing_powerdns_db.sql ".$conf['powerdns']['database']);
84         } else {
85             system("mysqldump -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -c -t --add-drop-table --create-options --quick --result-file=existing_powerdns_db.sql ".$conf['powerdns']['database']);
86         }
9a3a78 87
L 88         // create a backup copy of the PowerDNS database in the root folder
89         $backup_db_name = '/root/ispconfig_powerdns_db_backup_'.@date('Y-m-d_h-i').'.sql';
b1a6a5 90         copy('existing_powerdns_db.sql', $backup_db_name);
9a3a78 91         chmod($backup_db_name, 0700);
b1a6a5 92         chown($backup_db_name, 'root');
MC 93         chgrp($backup_db_name, 'root');
9a3a78 94     }
L 95 }
96
97 function checkDbHealth() {
98     global $conf;
99
100     //* Array containing non OK tables (can be repaired, crashed, corrupt)
101     $notok = array();
102
103     echo "Checking ISPConfig database .. ";
02bf99 104     exec("mysqlcheck -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." -r ".escapeshellarg($conf["mysql"]["database"]), $result);
9a3a78 105     for( $i=0; $i<sizeof($result);$i++) {
L 106         if ( substr($result[$i], -2) != "OK" ) {
107             $notok[] = $result[$i];
108         }
109     }
110
111     if ( sizeof($notok) > 0 ) {
112         echo "\nSome tables where not 'OK'. Please check the list below.\n\n";
113         foreach ($notok as $key => $value) {
114             echo "$value\n";
115         }
116         echo "\nPress enter to continue or CTRL-C to cancel the installation ..";
117         sread();
118     }
119     else
b1a6a5 120         echo "OK\n";
9a3a78 121 }
L 122
123 function updateDbAndIni() {
124     global $inst, $conf;
125
670d37 126     //* check sql-mode
FS 127     $check_sql_mode = $inst->db->queryOneRecord("SELECT @@sql_mode");
2b3b4c 128     if ($check_sql_mode['@@sql_mode'] != '' && $check_sql_mode['@@sql_mode'] != 'NO_ENGINE_SUBSTITUTION') {
FS 129         echo "Wrong SQL-mode. You should use NO_ENGINE_SUBSTITUTION. Add\n\n";
130         echo "    sql-mode=\"NO_ENGINE_SUBSTITUTION\"\n\n";
131         echo"to the mysqld-section in /etc/mysql/my.cnf and restart mysqld afterwards\n";
132         die();
133     }
670d37 134
9a3a78 135     //* Update $conf array with values from the server.ini that shall be preserved
2af58c 136     $tmp = $inst->db->queryOneRecord("SELECT * FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . '.server', $conf['server_id']);
9a3a78 137     $ini_array = ini_to_array(stripslashes($tmp['config']));
L 138     $current_db_version = (isset($tmp['dbversion']))?intval($tmp['dbversion']):0;
139
edf806 140     if(!is_array($ini_array) or count($ini_array) == 0) die('Unable to read server configuration from database.');
9a3a78 141
L 142     $conf['services']['mail'] = ($tmp['mail_server'] == 1)?true:false;
143     $conf['services']['web'] = ($tmp['web_server'] == 1)?true:false;
144     $conf['services']['dns'] = ($tmp['dns_server'] == 1)?true:false;
145     $conf['services']['file'] = ($tmp['file_server'] == 1)?true:false;
146     $conf['services']['db'] = ($tmp['db_server'] == 1)?true:false;
147     $conf['services']['vserver'] = ($tmp['vserver_server'] == 1)?true:false;
148     $conf['services']['proxy'] = (isset($tmp['proxy_server']) && $tmp['proxy_server'] == 1)?true:false;
149     $conf['services']['firewall'] = (isset($tmp['firewall_server']) && $tmp['firewall_server'] == 1)?true:false;
b1a6a5 150
9a3a78 151     $conf['postfix']['vmail_mailbox_base'] = $ini_array['mail']['homedir_path'];
b1a6a5 152
e41fba 153     if(isset($ini_array['web']['server_type']) && $ini_array['web']['server_type'] != ''){
4ffb51 154         $conf['webserver']['server_type'] = $ini_array['web']['server_type'];
F 155         if($conf['webserver']['server_type'] == 'nginx'){
156             $conf['apache']['installed'] = false;
157         } else {
158             $conf['nginx']['installed'] = false;
159         }
160     } else {
161         $conf['webserver']['server_type'] = 'apache';
162         $conf['nginx']['installed'] = false;
163     }
b1a6a5 164
eb3ab4 165     //* Do incremental DB updates only on installed ISPConfig versions >= 3.0.3
MC 166     if(version_compare('3.0.3', ISPC_APP_VERSION, '<=')) {
b1a6a5 167
9a3a78 168         swriteln($inst->lng('Starting incremental database update.'));
b1a6a5 169
MC 170         //* get the version of the db schema from the server table
9a3a78 171         $found = true;
3b42f0 172         $dev_patch = false;
9a3a78 173         while($found == true) {
3b42f0 174             if($dev_patch == true) $next_db_version = 'dev_collection';
MC 175             else $next_db_version = intval($current_db_version + 1);
992797 176             $sql_patch_filename = realpath(dirname(__FILE__).'/../').'/sql/incremental/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.sql';
MC 177             $php_patch_filename = realpath(dirname(__FILE__).'/../').'/patches/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.php';
0ccfef 178             
TB 179             // comma separated list of version numbers were a update has to be done silently
3b42f0 180             $silent_update_versions = 'dev_collection,75';
b1a6a5 181
992797 182             if(is_file($sql_patch_filename)) {
b1a6a5 183
992797 184                 //* Load php patch file and instantiate object
MC 185                 if(is_file($php_patch_filename)) {
186                     $php_patch_class_name = 'upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT);
b1a6a5 187                     include_once $php_patch_filename;
992797 188                     if(class_exists($php_patch_class_name)) {
MC 189                         $php_patch = new $php_patch_class_name;
190                     } else {
191                         swriteln($inst->lng('WARNING: PHP patch file').': '.$php_patch_filename.' '.$inst->lng('contains errors.'));
192                     }
193                 }
b1a6a5 194
992797 195                 //* Exec onBeforeSQL function
7b9c18 196                 if(isset($php_patch) && is_object($php_patch) && method_exists($php_patch, 'onBeforeSQL')) {
992797 197                     $php_patch->onBeforeSQL();
MC 198                     swriteln($inst->lng('Executing PHP patch file').': '.$php_patch_filename);
199                 }
b1a6a5 200
9a3a78 201                 //* Load patch file into database
L 202                 if( !empty($conf["mysql"]["admin_password"]) ) {
0ccfef 203                     $cmd = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." ".escapeshellarg($conf['mysql']['database'])." < ".$sql_patch_filename;
9a3a78 204                 } else {
0ccfef 205                     $cmd = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." ".escapeshellarg($conf['mysql']['database'])." < ".$sql_patch_filename;
9a3a78 206                 }
0ccfef 207                 
TB 208                 if(in_array($next_db_version,explode(',',$silent_update_versions))) $cmd .= ' > /dev/null 2> /dev/null';
209                 system($cmd);
210                 
992797 211                 swriteln($inst->lng('Loading SQL patch file').': '.$sql_patch_filename);
b1a6a5 212
992797 213                 //* Exec onAfterSQL function
7b9c18 214                 if(isset($php_patch) && is_object($php_patch) && method_exists($php_patch, 'onAfterSQL')) {
992797 215                     $php_patch->onAfterSQL();
MC 216                 }
b1a6a5 217
3b42f0 218                 if($dev_patch == false) $current_db_version = $next_db_version;
MC 219                 else $found = false;
220                 
992797 221                 if(isset($php_patch)) unset($php_patch);
3b42f0 222             } elseif($dev_patch == false) {
MC 223                 $dev_patch = true;
9a3a78 224             } else {
L 225                 $found = false;
226             }
227         }
b1a6a5 228
9a3a78 229         //* update the database version in server table
2af58c 230         $inst->db->query("UPDATE ?? SET dbversion = ? WHERE server_id = ?", $conf["mysql"]["database"] . ".server", $current_db_version, $conf['server_id']);
MC 231         if($inst->db->dbHost != $inst->dbmaster->dbHost) $inst->dbmaster->query("UPDATE ?? SET dbversion = ? WHERE server_id = ?", $conf["mysql"]["master_database"] . ".server", $current_db_version, $conf['server_id']);
b1a6a5 232
MC 233
234         //* If ISPConfig Version < 3.0.3, we will do a full db update
9a3a78 235     } else {
b1a6a5 236
9a3a78 237         swriteln($inst->lng('Starting full database update.'));
b1a6a5 238
9a3a78 239         //** Delete the old database
2af58c 240         if( !$inst->db->query('DROP DATABASE IF EXISTS ??', $conf['mysql']['database']) ) {
b1a6a5 241             $inst->error('Unable to drop MySQL database: '.$conf['mysql']['database'].'.');
9a3a78 242         }
L 243
244         //** Create the mysql database
245         $inst->configure_database();
246
247         //** empty all databases
248         $db_tables = $inst->db->getTables();
249
250         foreach($db_tables as $table) {
2af58c 251             $inst->db->query("TRUNCATE ??", $table);
9a3a78 252         }
L 253
254         //** load old data back into database
255         if( !empty($conf["mysql"]["admin_password"]) ) {
02bf99 256             system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." ".escapeshellarg($conf['mysql']['database'])." < existing_db.sql");
9a3a78 257         } else {
02bf99 258             system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." ".escapeshellarg($conf['mysql']['database'])." < existing_db.sql");
9a3a78 259         }
b1a6a5 260
9a3a78 261         //** Get the database version number based on the patchfile
L 262         $found = true;
263         while($found == true) {
264             $next_db_version = intval($current_db_version + 1);
265             $patch_filename = realpath(dirname(__FILE__).'/../').'/sql/incremental/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.sql';
266             if(is_file($patch_filename)) {
267                 $current_db_version = $next_db_version;
268             } else {
269                 $found = false;
270             }
271         }
b1a6a5 272
9a3a78 273         //* update the database version in server table
2af58c 274         $inst->db->query("UPDATE ?? SET dbversion = ? WHERE server_id = ?", $conf["mysql"]["database"] . ".server", $current_db_version, $conf['server_id']);
MC 275         if($inst->db->dbHost != $inst->dbmaster->dbHost) $inst->dbmaster->query("UPDATE ?? SET dbversion = ? WHERE server_id = ?", $conf["mysql"]["master_database"] . ".server", $current_db_version, $conf['server_id']);
9a3a78 276
L 277         if ($conf['powerdns']['installed']) {
b1a6a5 278
9a3a78 279             swriteln($inst->lng('Starting full PowerDNS database update.'));
L 280
b1a6a5 281             //** Delete the old PowerDNS database
2af58c 282             if( !$inst->db->query('DROP DATABASE IF EXISTS ??', $conf['powerdns']['database']) ) {
9a3a78 283                 $inst->error('Unable to drop MySQL database: '.$conf['powerdns']['database'].'.');
b1a6a5 284             }
9a3a78 285
b1a6a5 286             //** Create the mysql database
MC 287             $inst->configure_powerdns();
9a3a78 288
b1a6a5 289             //** load old data back into the PowerDNS database
MC 290             if( !empty($conf["mysql"]["admin_password"]) ) {
291                 system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." ".escapeshellarg($conf['powerdns']['database'])." < existing_powerdns_db.sql");
292             } else {
293                 system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." ".escapeshellarg($conf['powerdns']['database'])." < existing_powerdns_db.sql");
294             }
9a3a78 295         }
L 296     }
297
298
299     //** Update server ini
2af58c 300     $tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . ".server", $conf['server_id']);
9a3a78 301     $old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config']));
L 302     unset($tmp_server_rec);
303     $tpl_ini_array = ini_to_array(rf('tpl/server.ini.master'));
b1a6a5 304
9a3a78 305     //* Update further distribution specific parameters for server config here
L 306     //* HINT: Every line added here has to be added in installer_base.lib.php too!!
307     $tpl_ini_array['jailkit']['jailkit_chroot_app_programs'] = $conf['jailkit']['jailkit_chroot_app_programs'];
308     $tpl_ini_array['fastcgi']['fastcgi_phpini_path'] = $conf['fastcgi']['fastcgi_phpini_path'];
309     $tpl_ini_array['fastcgi']['fastcgi_starter_path'] = $conf['fastcgi']['fastcgi_starter_path'];
526b99 310     $tpl_ini_array['fastcgi']['fastcgi_bin'] = $conf['fastcgi']['fastcgi_bin'];
9a3a78 311     $tpl_ini_array['server']['hostname'] = $conf['hostname'];
L 312     $tpl_ini_array['server']['ip_address'] = @gethostbyname($conf['hostname']);
313     $tpl_ini_array['web']['website_basedir'] = $conf['web']['website_basedir'];
314     $tpl_ini_array['web']['website_path'] = $conf['web']['website_path'];
315     $tpl_ini_array['web']['website_symlinks'] = $conf['web']['website_symlinks'];
316     $tpl_ini_array['cron']['crontab_dir'] = $conf['cron']['crontab_dir'];
317     $tpl_ini_array['web']['security_level'] = 20;
318     $tpl_ini_array['web']['user'] = $conf['apache']['user'];
319     $tpl_ini_array['web']['group'] = $conf['apache']['group'];
320     $tpl_ini_array['web']['php_ini_path_apache'] = $conf['apache']['php_ini_path_apache'];
321     $tpl_ini_array['web']['php_ini_path_cgi'] = $conf['apache']['php_ini_path_cgi'];
322     $tpl_ini_array['mail']['pop3_imap_daemon'] = ($conf['dovecot']['installed'] == true)?'dovecot':'courier';
323     $tpl_ini_array['mail']['mail_filter_syntax'] = ($conf['dovecot']['installed'] == true)?'sieve':'maildrop';
324     $tpl_ini_array['dns']['bind_user'] = $conf['bind']['bind_user'];
325     $tpl_ini_array['dns']['bind_group'] = $conf['bind']['bind_group'];
326     $tpl_ini_array['dns']['bind_zonefiles_dir'] = $conf['bind']['bind_zonefiles_dir'];
327     $tpl_ini_array['dns']['named_conf_path'] = $conf['bind']['named_conf_path'];
328     $tpl_ini_array['dns']['named_conf_local_path'] = $conf['bind']['named_conf_local_path'];
b1a6a5 329
dba68f 330     $tpl_ini_array['web']['nginx_vhost_conf_dir'] = $conf['nginx']['vhost_conf_dir'];
T 331     $tpl_ini_array['web']['nginx_vhost_conf_enabled_dir'] = $conf['nginx']['vhost_conf_enabled_dir'];
332     $tpl_ini_array['web']['nginx_user'] = $conf['nginx']['user'];
333     $tpl_ini_array['web']['nginx_group'] = $conf['nginx']['group'];
334     $tpl_ini_array['web']['nginx_cgi_socket'] = $conf['nginx']['cgi_socket'];
335     $tpl_ini_array['web']['php_fpm_init_script'] = $conf['nginx']['php_fpm_init_script'];
336     $tpl_ini_array['web']['php_fpm_ini_path'] = $conf['nginx']['php_fpm_ini_path'];
337     $tpl_ini_array['web']['php_fpm_pool_dir'] = $conf['nginx']['php_fpm_pool_dir'];
338     $tpl_ini_array['web']['php_fpm_start_port'] = $conf['nginx']['php_fpm_start_port'];
339     $tpl_ini_array['web']['php_fpm_socket_dir'] = $conf['nginx']['php_fpm_socket_dir'];
b1a6a5 340
4ffb51 341     if ($conf['nginx']['installed'] == true) {
F 342         $tpl_ini_array['web']['server_type'] = 'nginx';
343         $tpl_ini_array['global']['webserver'] = 'nginx';
344     }
9a3a78 345
8cf78b 346     //* update the new template with the old values
9a3a78 347     if(is_array($old_ini_array)) {
L 348         foreach($old_ini_array as $tmp_section_name => $tmp_section_content) {
349             foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) {
350                 $tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content;
351             }
352         }
353     }
354
355     $new_ini = array_to_ini($tpl_ini_array);
2af58c 356     $sql = "UPDATE ?? SET config = ? WHERE server_id = ?";
MC 357     $inst->db->query($sql, $conf["mysql"]["database"] . ".server", $new_ini, $conf['server_id']);
b1a6a5 358
8cf78b 359     if($inst->db->dbHost != $inst->dbmaster->dbHost) {
2af58c 360         $sql = "UPDATE ?? SET config = ? WHERE server_id = ?";
MC 361         $inst->dbmaster->query($sql, $conf["mysql"]["master_database"].".server", $new_ini, $conf['server_id']);
8cf78b 362     }
9a3a78 363     unset($old_ini_array);
L 364     unset($tpl_ini_array);
365     unset($new_ini);
366
367
368     //** Update system ini
2af58c 369     $tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM ?? WHERE sysini_id = 1", $conf["mysql"]["database"] . ".sys_ini");
9a3a78 370     $old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config']));
L 371     unset($tmp_server_rec);
372     $tpl_ini_array = ini_to_array(rf('tpl/system.ini.master'));
373
374     // update the new template with the old values
375     if(is_array($old_ini_array)) {
376         foreach($old_ini_array as $tmp_section_name => $tmp_section_content) {
377             foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) {
378                 $tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content;
379             }
380         }
381     }
382
383     $new_ini = array_to_ini($tpl_ini_array);
2af58c 384     $tmp = $inst->db->queryOneRecord('SELECT count(sysini_id) as number FROM ?? WHERE 1', $conf["mysql"]["database"] . '.sys_ini');
9a3a78 385     if($tmp['number'] == 0) {
2af58c 386         $inst->db->query("INSERT INTO ?? (sysini_id, config) VALUES (1,?)", $conf["mysql"]["database"] . ".sys_ini", $new_ini);
9a3a78 387     } else {
2af58c 388         $inst->db->query("UPDATE ?? SET config = ? WHERE sysini_id = 1", $conf["mysql"]["database"] . ".sys_ini", $new_ini);
9a3a78 389     }
L 390     unset($old_ini_array);
391     unset($tpl_ini_array);
392     unset($new_ini);
393 }
394
992797 395
MC 396
75b7fc 397 function setDefaultServers(){
MC 398     global $inst, $conf;
399     
400     // clients
401     $clients = $inst->db->queryAllRecords("SELECT * FROM ".$conf["mysql"]["database"].".client");
402     if(is_array($clients) && !empty($clients)){
403         foreach($clients as $client){
404             // mailserver
ca2165 405             if(trim($client['mail_servers']) == '') $inst->db->query("UPDATE ?? SET mail_servers = ? WHERE client_id = ?", $conf["mysql"]["database"].".client", trim($client['default_mailserver']), $client['client_id']);
75b7fc 406             // webserver
ca2165 407             if(trim($client['web_servers']) == '') $inst->db->query("UPDATE ?? SET web_servers = ? WHERE client_id = ?", $conf["mysql"]["database"].".client", trim($client['default_webserver']), $client['client_id']);
75b7fc 408             // dns server
ca2165 409             if(trim($client['dns_servers']) == '') $inst->db->query("UPDATE ?? SET dns_servers = ? WHERE client_id = ?", $conf["mysql"]["database"].".client", trim($client['default_dnsserver']), $client['client_id']);
75b7fc 410             // db server
ca2165 411             if(trim($client['db_servers']) == '') $inst->db->query("UPDATE ?? SET db_servers = ? WHERE client_id = ?", $conf["mysql"]["database"].".client", trim($client['default_dbserver']), $client['client_id']);
75b7fc 412         }
MC 413     }
414     
415 }
416
9a3a78 417 ?>