diff --git a/install/lib/install.lib.php b/install/lib/install.lib.php index b8f40f1eb7adc5bb5dee7d9f9086a1d37b1919bb..83c6d0b22a6c94ff32aa9ec502c885bbe46a1dab 100644 --- a/install/lib/install.lib.php +++ b/install/lib/install.lib.php @@ -402,4 +402,42 @@ function edit_xinetd_conf($service){ wf($xinetd_conf, $contents); } +//* Converts a ini string to array +function ini_to_array($ini) { + $config = ''; + $ini = str_replace("\r\n", "\n", $ini); + $lines = explode("\n", $ini); + foreach($lines as $line) { + $line = trim($line); + if($line != '') { + if(preg_match("/^\[([\w\d_]+)\]$/", $line, $matches)) { + $section = strtolower($matches[1]); + } elseif(preg_match("/^([\w\d_]+)=(.*)$/", $line, $matches) && $section != null) { + $item = trim($matches[1]); + $config[$section][$item] = trim($matches[2]); + } + } + } + return $config; +} + + +//* Converts a config array to a string +public function array_to_ini($config_array = '') { + if($config_array == '') $config_array = $this->config; + $content = ''; + foreach($config_array as $section => $data) { + $content .= "[$section]\n"; + foreach($data as $item => $value) { + if($item != ''){ + $content .= "$item=$value\n"; + } + } + $content .= "\n"; + } + return $content; +} + + + ?> \ No newline at end of file diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 02d9f8382413f57fe125b0b5e7bd1b6f1587b0cd..6880e9870585b1c4b91d6d3edb889f7c47880d87 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -42,7 +42,7 @@ class installer_base { $this->conf = $conf; } - //: TODO Implement the translation function and langauge files for the installer. + //: TODO Implement the translation function and language files for the installer. public function lng($text) { return $text; @@ -153,7 +153,7 @@ class installer_base { } } - //** Create a recors in the + //** Create the server record in the database public function add_database_server_record() { $server_ini_content = rf("tpl/server.ini.master"); diff --git a/install/update.php b/install/update.php index 3095b04c13ef80cd91781644e5041dc8979f6485..6bd4f18403bc47f7f2b073be389f7279ef68791a 100644 --- a/install/update.php +++ b/install/update.php @@ -75,6 +75,8 @@ $conf["mysql"]["database"] = $conf_old["db_database"]; $conf["mysql"]["ispconfig_user"] = $conf_old["db_user"]; $conf["mysql"]["ispconfig_password"] = $conf_old["db_password"]; +$conf['server_id'] = $conf_old["server_id"]; + $inst = new installer(); echo "This application will update ISPConfig 3 on your server.\n"; @@ -128,6 +130,26 @@ if( !empty($conf["mysql"]["admin_password"]) ) { system("mysql -h ".$conf['mysql']['host']." -u ".$conf['mysql']['admin_user']." ".$conf['mysql']['database']." < existing_db.sql"); } +//** Update server ini +$tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM server WHERE server_id = ".$conf['server_id']); +$old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config'])); +unset($tmp_server_rec); +$tpl_ini_array = ini_to_array(rf('tpl/server.ini.master')); + +// update the new template with the old values +foreach($old_ini_array as $tmp_section_name => $tmp_section_content) { + foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) { + $tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content; + } +} + +$new_ini = array_to_ini($tpl_ini_array); +$inst->db->query("UPDATE server SET config = '".addslashes($new_ini)."' WHERE server_id = ".$conf['server_id']); +unset($old_ini_array); +unset($tpl_ini_array); +unset($new_ini); + + //** Shall the services be reconfigured during update $reconfigure_services_answer = $inst->simple_query('Reconfigure Services?', array('yes','no'),'yes');