Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
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");
128     if ($check_sql_mode['@@sql_mode'] != '' && $check_sql_mode['@@sql_mode'] != 'NO_ENGINE_SUBSTITUTION') die('Wrong SQL-mode. You should use NO_ENGINE_SUBSTITUTION');
129
9a3a78 130     //* Update $conf array with values from the server.ini that shall be preserved
2af58c 131     $tmp = $inst->db->queryOneRecord("SELECT * FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . '.server', $conf['server_id']);
9a3a78 132     $ini_array = ini_to_array(stripslashes($tmp['config']));
L 133     $current_db_version = (isset($tmp['dbversion']))?intval($tmp['dbversion']):0;
134
edf806 135     if(!is_array($ini_array) or count($ini_array) == 0) die('Unable to read server configuration from database.');
9a3a78 136
L 137     $conf['services']['mail'] = ($tmp['mail_server'] == 1)?true:false;
138     $conf['services']['web'] = ($tmp['web_server'] == 1)?true:false;
139     $conf['services']['dns'] = ($tmp['dns_server'] == 1)?true:false;
140     $conf['services']['file'] = ($tmp['file_server'] == 1)?true:false;
141     $conf['services']['db'] = ($tmp['db_server'] == 1)?true:false;
142     $conf['services']['vserver'] = ($tmp['vserver_server'] == 1)?true:false;
143     $conf['services']['proxy'] = (isset($tmp['proxy_server']) && $tmp['proxy_server'] == 1)?true:false;
144     $conf['services']['firewall'] = (isset($tmp['firewall_server']) && $tmp['firewall_server'] == 1)?true:false;
b1a6a5 145
9a3a78 146     $conf['postfix']['vmail_mailbox_base'] = $ini_array['mail']['homedir_path'];
b1a6a5 147
e41fba 148     if(isset($ini_array['web']['server_type']) && $ini_array['web']['server_type'] != ''){
4ffb51 149         $conf['webserver']['server_type'] = $ini_array['web']['server_type'];
F 150         if($conf['webserver']['server_type'] == 'nginx'){
151             $conf['apache']['installed'] = false;
152         } else {
153             $conf['nginx']['installed'] = false;
154         }
155     } else {
156         $conf['webserver']['server_type'] = 'apache';
157         $conf['nginx']['installed'] = false;
158     }
b1a6a5 159
eb3ab4 160     //* Do incremental DB updates only on installed ISPConfig versions >= 3.0.3
MC 161     if(version_compare('3.0.3', ISPC_APP_VERSION, '<=')) {
b1a6a5 162
9a3a78 163         swriteln($inst->lng('Starting incremental database update.'));
b1a6a5 164
MC 165         //* get the version of the db schema from the server table
9a3a78 166         $found = true;
3b42f0 167         $dev_patch = false;
9a3a78 168         while($found == true) {
3b42f0 169             if($dev_patch == true) $next_db_version = 'dev_collection';
MC 170             else $next_db_version = intval($current_db_version + 1);
992797 171             $sql_patch_filename = realpath(dirname(__FILE__).'/../').'/sql/incremental/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.sql';
MC 172             $php_patch_filename = realpath(dirname(__FILE__).'/../').'/patches/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.php';
0ccfef 173             
TB 174             // comma separated list of version numbers were a update has to be done silently
3b42f0 175             $silent_update_versions = 'dev_collection,75';
b1a6a5 176
992797 177             if(is_file($sql_patch_filename)) {
b1a6a5 178
992797 179                 //* Load php patch file and instantiate object
MC 180                 if(is_file($php_patch_filename)) {
181                     $php_patch_class_name = 'upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT);
b1a6a5 182                     include_once $php_patch_filename;
992797 183                     if(class_exists($php_patch_class_name)) {
MC 184                         $php_patch = new $php_patch_class_name;
185                     } else {
186                         swriteln($inst->lng('WARNING: PHP patch file').': '.$php_patch_filename.' '.$inst->lng('contains errors.'));
187                     }
188                 }
b1a6a5 189
992797 190                 //* Exec onBeforeSQL function
7b9c18 191                 if(isset($php_patch) && is_object($php_patch) && method_exists($php_patch, 'onBeforeSQL')) {
992797 192                     $php_patch->onBeforeSQL();
MC 193                     swriteln($inst->lng('Executing PHP patch file').': '.$php_patch_filename);
194                 }
b1a6a5 195
9a3a78 196                 //* Load patch file into database
L 197                 if( !empty($conf["mysql"]["admin_password"]) ) {
0ccfef 198                     $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 199                 } else {
0ccfef 200                     $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 201                 }
0ccfef 202                 
TB 203                 if(in_array($next_db_version,explode(',',$silent_update_versions))) $cmd .= ' > /dev/null 2> /dev/null';
204                 system($cmd);
205                 
992797 206                 swriteln($inst->lng('Loading SQL patch file').': '.$sql_patch_filename);
b1a6a5 207
992797 208                 //* Exec onAfterSQL function
7b9c18 209                 if(isset($php_patch) && is_object($php_patch) && method_exists($php_patch, 'onAfterSQL')) {
992797 210                     $php_patch->onAfterSQL();
MC 211                 }
b1a6a5 212
3b42f0 213                 if($dev_patch == false) $current_db_version = $next_db_version;
MC 214                 else $found = false;
215                 
992797 216                 if(isset($php_patch)) unset($php_patch);
3b42f0 217             } elseif($dev_patch == false) {
MC 218                 $dev_patch = true;
9a3a78 219             } else {
L 220                 $found = false;
221             }
222         }
b1a6a5 223
9a3a78 224         //* update the database version in server table
2af58c 225         $inst->db->query("UPDATE ?? SET dbversion = ? WHERE server_id = ?", $conf["mysql"]["database"] . ".server", $current_db_version, $conf['server_id']);
MC 226         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 227
MC 228
229         //* If ISPConfig Version < 3.0.3, we will do a full db update
9a3a78 230     } else {
b1a6a5 231
9a3a78 232         swriteln($inst->lng('Starting full database update.'));
b1a6a5 233
9a3a78 234         //** Delete the old database
2af58c 235         if( !$inst->db->query('DROP DATABASE IF EXISTS ??', $conf['mysql']['database']) ) {
b1a6a5 236             $inst->error('Unable to drop MySQL database: '.$conf['mysql']['database'].'.');
9a3a78 237         }
L 238
239         //** Create the mysql database
240         $inst->configure_database();
241
242         //** empty all databases
243         $db_tables = $inst->db->getTables();
244
245         foreach($db_tables as $table) {
2af58c 246             $inst->db->query("TRUNCATE ??", $table);
9a3a78 247         }
L 248
249         //** load old data back into database
250         if( !empty($conf["mysql"]["admin_password"]) ) {
02bf99 251             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 252         } else {
02bf99 253             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 254         }
b1a6a5 255
9a3a78 256         //** Get the database version number based on the patchfile
L 257         $found = true;
258         while($found == true) {
259             $next_db_version = intval($current_db_version + 1);
260             $patch_filename = realpath(dirname(__FILE__).'/../').'/sql/incremental/upd_'.str_pad($next_db_version, 4, '0', STR_PAD_LEFT).'.sql';
261             if(is_file($patch_filename)) {
262                 $current_db_version = $next_db_version;
263             } else {
264                 $found = false;
265             }
266         }
b1a6a5 267
9a3a78 268         //* update the database version in server table
2af58c 269         $inst->db->query("UPDATE ?? SET dbversion = ? WHERE server_id = ?", $conf["mysql"]["database"] . ".server", $current_db_version, $conf['server_id']);
MC 270         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 271
L 272         if ($conf['powerdns']['installed']) {
b1a6a5 273
9a3a78 274             swriteln($inst->lng('Starting full PowerDNS database update.'));
L 275
b1a6a5 276             //** Delete the old PowerDNS database
2af58c 277             if( !$inst->db->query('DROP DATABASE IF EXISTS ??', $conf['powerdns']['database']) ) {
9a3a78 278                 $inst->error('Unable to drop MySQL database: '.$conf['powerdns']['database'].'.');
b1a6a5 279             }
9a3a78 280
b1a6a5 281             //** Create the mysql database
MC 282             $inst->configure_powerdns();
9a3a78 283
b1a6a5 284             //** load old data back into the PowerDNS database
MC 285             if( !empty($conf["mysql"]["admin_password"]) ) {
286                 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");
287             } else {
288                 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");
289             }
9a3a78 290         }
L 291     }
292
293
294     //** Update server ini
2af58c 295     $tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . ".server", $conf['server_id']);
9a3a78 296     $old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config']));
L 297     unset($tmp_server_rec);
298     $tpl_ini_array = ini_to_array(rf('tpl/server.ini.master'));
b1a6a5 299
9a3a78 300     //* Update further distribution specific parameters for server config here
L 301     //* HINT: Every line added here has to be added in installer_base.lib.php too!!
302     $tpl_ini_array['jailkit']['jailkit_chroot_app_programs'] = $conf['jailkit']['jailkit_chroot_app_programs'];
303     $tpl_ini_array['fastcgi']['fastcgi_phpini_path'] = $conf['fastcgi']['fastcgi_phpini_path'];
304     $tpl_ini_array['fastcgi']['fastcgi_starter_path'] = $conf['fastcgi']['fastcgi_starter_path'];
526b99 305     $tpl_ini_array['fastcgi']['fastcgi_bin'] = $conf['fastcgi']['fastcgi_bin'];
9a3a78 306     $tpl_ini_array['server']['hostname'] = $conf['hostname'];
L 307     $tpl_ini_array['server']['ip_address'] = @gethostbyname($conf['hostname']);
308     $tpl_ini_array['web']['website_basedir'] = $conf['web']['website_basedir'];
309     $tpl_ini_array['web']['website_path'] = $conf['web']['website_path'];
310     $tpl_ini_array['web']['website_symlinks'] = $conf['web']['website_symlinks'];
311     $tpl_ini_array['cron']['crontab_dir'] = $conf['cron']['crontab_dir'];
312     $tpl_ini_array['web']['security_level'] = 20;
313     $tpl_ini_array['web']['user'] = $conf['apache']['user'];
314     $tpl_ini_array['web']['group'] = $conf['apache']['group'];
315     $tpl_ini_array['web']['php_ini_path_apache'] = $conf['apache']['php_ini_path_apache'];
316     $tpl_ini_array['web']['php_ini_path_cgi'] = $conf['apache']['php_ini_path_cgi'];
317     $tpl_ini_array['mail']['pop3_imap_daemon'] = ($conf['dovecot']['installed'] == true)?'dovecot':'courier';
318     $tpl_ini_array['mail']['mail_filter_syntax'] = ($conf['dovecot']['installed'] == true)?'sieve':'maildrop';
319     $tpl_ini_array['dns']['bind_user'] = $conf['bind']['bind_user'];
320     $tpl_ini_array['dns']['bind_group'] = $conf['bind']['bind_group'];
321     $tpl_ini_array['dns']['bind_zonefiles_dir'] = $conf['bind']['bind_zonefiles_dir'];
322     $tpl_ini_array['dns']['named_conf_path'] = $conf['bind']['named_conf_path'];
323     $tpl_ini_array['dns']['named_conf_local_path'] = $conf['bind']['named_conf_local_path'];
b1a6a5 324
dba68f 325     $tpl_ini_array['web']['nginx_vhost_conf_dir'] = $conf['nginx']['vhost_conf_dir'];
T 326     $tpl_ini_array['web']['nginx_vhost_conf_enabled_dir'] = $conf['nginx']['vhost_conf_enabled_dir'];
327     $tpl_ini_array['web']['nginx_user'] = $conf['nginx']['user'];
328     $tpl_ini_array['web']['nginx_group'] = $conf['nginx']['group'];
329     $tpl_ini_array['web']['nginx_cgi_socket'] = $conf['nginx']['cgi_socket'];
330     $tpl_ini_array['web']['php_fpm_init_script'] = $conf['nginx']['php_fpm_init_script'];
331     $tpl_ini_array['web']['php_fpm_ini_path'] = $conf['nginx']['php_fpm_ini_path'];
332     $tpl_ini_array['web']['php_fpm_pool_dir'] = $conf['nginx']['php_fpm_pool_dir'];
333     $tpl_ini_array['web']['php_fpm_start_port'] = $conf['nginx']['php_fpm_start_port'];
334     $tpl_ini_array['web']['php_fpm_socket_dir'] = $conf['nginx']['php_fpm_socket_dir'];
b1a6a5 335
4ffb51 336     if ($conf['nginx']['installed'] == true) {
F 337         $tpl_ini_array['web']['server_type'] = 'nginx';
338         $tpl_ini_array['global']['webserver'] = 'nginx';
339     }
9a3a78 340
8cf78b 341     //* update the new template with the old values
9a3a78 342     if(is_array($old_ini_array)) {
L 343         foreach($old_ini_array as $tmp_section_name => $tmp_section_content) {
344             foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) {
345                 $tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content;
346             }
347         }
348     }
349
350     $new_ini = array_to_ini($tpl_ini_array);
2af58c 351     $sql = "UPDATE ?? SET config = ? WHERE server_id = ?";
MC 352     $inst->db->query($sql, $conf["mysql"]["database"] . ".server", $new_ini, $conf['server_id']);
b1a6a5 353
8cf78b 354     if($inst->db->dbHost != $inst->dbmaster->dbHost) {
2af58c 355         $sql = "UPDATE ?? SET config = ? WHERE server_id = ?";
MC 356         $inst->dbmaster->query($sql, $conf["mysql"]["master_database"].".server", $new_ini, $conf['server_id']);
8cf78b 357     }
9a3a78 358     unset($old_ini_array);
L 359     unset($tpl_ini_array);
360     unset($new_ini);
361
362
363     //** Update system ini
2af58c 364     $tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM ?? WHERE sysini_id = 1", $conf["mysql"]["database"] . ".sys_ini");
9a3a78 365     $old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config']));
L 366     unset($tmp_server_rec);
367     $tpl_ini_array = ini_to_array(rf('tpl/system.ini.master'));
368
369     // update the new template with the old values
370     if(is_array($old_ini_array)) {
371         foreach($old_ini_array as $tmp_section_name => $tmp_section_content) {
372             foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) {
373                 $tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content;
374             }
375         }
376     }
377
378     $new_ini = array_to_ini($tpl_ini_array);
2af58c 379     $tmp = $inst->db->queryOneRecord('SELECT count(sysini_id) as number FROM ?? WHERE 1', $conf["mysql"]["database"] . '.sys_ini');
9a3a78 380     if($tmp['number'] == 0) {
2af58c 381         $inst->db->query("INSERT INTO ?? (sysini_id, config) VALUES (1,?)", $conf["mysql"]["database"] . ".sys_ini", $new_ini);
9a3a78 382     } else {
2af58c 383         $inst->db->query("UPDATE ?? SET config = ? WHERE sysini_id = 1", $conf["mysql"]["database"] . ".sys_ini", $new_ini);
9a3a78 384     }
L 385     unset($old_ini_array);
386     unset($tpl_ini_array);
387     unset($new_ini);
388 }
389
992797 390
MC 391
75b7fc 392 function setDefaultServers(){
MC 393     global $inst, $conf;
394     
395     // clients
396     $clients = $inst->db->queryAllRecords("SELECT * FROM ".$conf["mysql"]["database"].".client");
397     if(is_array($clients) && !empty($clients)){
398         foreach($clients as $client){
399             // mailserver
ca2165 400             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 401             // webserver
ca2165 402             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 403             // dns server
ca2165 404             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 405             // db server
ca2165 406             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 407         }
MC 408     }
409     
410 }
411
9a3a78 412 ?>