Skip to content

Commit 4f70280

Browse files
committed
The updater is now able to update the config (in server mysql table) from the master template.
1 parent 253e876 commit 4f70280

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

install/lib/install.lib.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,42 @@ function edit_xinetd_conf($service){
402402
wf($xinetd_conf, $contents);
403403
}
404404

405+
//* Converts a ini string to array
406+
function ini_to_array($ini) {
407+
$config = '';
408+
$ini = str_replace("\r\n", "\n", $ini);
409+
$lines = explode("\n", $ini);
410+
foreach($lines as $line) {
411+
$line = trim($line);
412+
if($line != '') {
413+
if(preg_match("/^\[([\w\d_]+)\]$/", $line, $matches)) {
414+
$section = strtolower($matches[1]);
415+
} elseif(preg_match("/^([\w\d_]+)=(.*)$/", $line, $matches) && $section != null) {
416+
$item = trim($matches[1]);
417+
$config[$section][$item] = trim($matches[2]);
418+
}
419+
}
420+
}
421+
return $config;
422+
}
423+
424+
425+
//* Converts a config array to a string
426+
public function array_to_ini($config_array = '') {
427+
if($config_array == '') $config_array = $this->config;
428+
$content = '';
429+
foreach($config_array as $section => $data) {
430+
$content .= "[$section]\n";
431+
foreach($data as $item => $value) {
432+
if($item != ''){
433+
$content .= "$item=$value\n";
434+
}
435+
}
436+
$content .= "\n";
437+
}
438+
return $content;
439+
}
440+
441+
442+
405443
?>

install/lib/installer_base.lib.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct()
4242
$this->conf = $conf;
4343
}
4444

45-
//: TODO Implement the translation function and langauge files for the installer.
45+
//: TODO Implement the translation function and language files for the installer.
4646
public function lng($text)
4747
{
4848
return $text;
@@ -153,7 +153,7 @@ public function configure_database()
153153
}
154154
}
155155

156-
//** Create a recors in the
156+
//** Create the server record in the database
157157
public function add_database_server_record() {
158158

159159
$server_ini_content = rf("tpl/server.ini.master");

install/update.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
$conf["mysql"]["ispconfig_user"] = $conf_old["db_user"];
7676
$conf["mysql"]["ispconfig_password"] = $conf_old["db_password"];
7777

78+
$conf['server_id'] = $conf_old["server_id"];
79+
7880
$inst = new installer();
7981

8082
echo "This application will update ISPConfig 3 on your server.\n";
@@ -128,6 +130,26 @@
128130
system("mysql -h ".$conf['mysql']['host']." -u ".$conf['mysql']['admin_user']." ".$conf['mysql']['database']." < existing_db.sql");
129131
}
130132

133+
//** Update server ini
134+
$tmp_server_rec = $inst->db->queryOneRecord("SELECT config FROM server WHERE server_id = ".$conf['server_id']);
135+
$old_ini_array = ini_to_array(stripslashes($tmp_server_rec['config']));
136+
unset($tmp_server_rec);
137+
$tpl_ini_array = ini_to_array(rf('tpl/server.ini.master'));
138+
139+
// update the new template with the old values
140+
foreach($old_ini_array as $tmp_section_name => $tmp_section_content) {
141+
foreach($tmp_section_content as $tmp_var_name => $tmp_var_content) {
142+
$tpl_ini_array[$tmp_section_name][$tmp_var_name] = $tmp_var_content;
143+
}
144+
}
145+
146+
$new_ini = array_to_ini($tpl_ini_array);
147+
$inst->db->query("UPDATE server SET config = '".addslashes($new_ini)."' WHERE server_id = ".$conf['server_id']);
148+
unset($old_ini_array);
149+
unset($tpl_ini_array);
150+
unset($new_ini);
151+
152+
131153
//** Shall the services be reconfigured during update
132154
$reconfigure_services_answer = $inst->simple_query('Reconfigure Services?', array('yes','no'),'yes');
133155

0 commit comments

Comments
 (0)