From 488e4ef8e1f55aea3ac320390b4526c39ab4bfdb Mon Sep 17 00:00:00 2001 From: Warpten Date: Sat, 17 May 2014 14:54:17 +0200 Subject: Contrib: Added an updated version of the configuration file merger tool. This one lets you choose which value to keep between the two configuration files. Make sure to carefully read the file's lines 3 to 9 to make sure you don't misuse it and get back at me later raging. It is not exactly as I would like it to be, but current state will have to do. You can try it out live at: http://tinyurl.com/kzxmrlm --- contrib/conf_merge/confdiffmerge.php | 169 +++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 contrib/conf_merge/confdiffmerge.php (limited to 'contrib/conf_merge/confdiffmerge.php') diff --git a/contrib/conf_merge/confdiffmerge.php b/contrib/conf_merge/confdiffmerge.php new file mode 100644 index 00000000000..7bcaef5042e --- /dev/null +++ b/contrib/conf_merge/confdiffmerge.php @@ -0,0 +1,169 @@ + + + + + <world/auth>server.conf diff + + + + + +
+
+

Paste the new configuration file

+ +
+

Paste the old configuration file

+ + +
+ +
+"); + + define('EOL', "\n\n"); + $settingsData = array(); + + // Process them + $newFile = explode(EOL, $_POST['leftFile']); + $oldFile = explode(EOL, $_POST['rightFile']); + + for ($i = 0, $o = count($oldFile); $i < $o; ++$i) + { + $oldFile[$i] = explode(PHP_EOL, $oldFile[$i]); + for ($j = 0, $p = count($oldFile[$i]); $j < $p; ++$j) + { + $currentLine = $oldFile[$i][$j]; + if (preg_match("#^([A-Z.]+) = (?:\"?)(.*)(?:\"?)$#iU", $currentLine, $data) !== false) + if (strlen($data[1]) != 0) + $settingsData[$data[1]]["oldValue"] = str_replace('"', '', trim($data[2])); + } + } + + for ($i = 0, $o = count($newFile); $i < $o; ++$i) + { + $newFile[$i] = explode(PHP_EOL, $newFile[$i]); + for ($j = 0, $p = count($newFile[$i]); $j < $p; ++$j) + { + $currentLine = $newFile[$i][$j]; + if (preg_match("#^([A-Z.]+) = (?:\"?)(.*)(?:\"?)$#iU", $currentLine, $data) !== false) + if (strlen($data[1]) != 0) + $settingsData[$data[1]]["newValue"] = str_replace('"', '', trim($data[2])); + } + } + + printIndent("

Please select values you want to keep. Note the script will default to new values, unless said new value does not exist.
You also can take advantage of this form and edit fields.

", 1); + printIndent('
', 1); + + foreach ($settingsData as $itemName => &$values) + { + $displayOld = isset($values['oldValue']) ? $values['oldValue'] : "Value missing"; + $displayNew = isset($values['newValue']) ? $values['newValue'] : "Value missing"; + + if ($displayOld == $displayNew) + continue; + + $line = '

'; + $line .= ''; + $line .= ' '; + $line .= ''; + $line .= '

'; + printIndent($line, 2); + } + printIndent('', 2); + printIndent('', 2); + printIndent('', 2); + printIndent('
', 1); +} +else if ($_POST['step'] == 1) +{ + $errors = array(); + + $confFile = $_POST['file']; + + foreach ($_POST['optionSelector'] as $valueName => &$keyName) + { + $definiteValueIndex = -1; + foreach ($_POST['nameCross'] as $index => &$key) + { + if ($key == $valueName) + { + $definiteValueIndex = $index; + break; + } + } + + if ($definiteValueIndex == -1) + { + // TODO: Handle custom values that get lost + continue; + } + + $newStr = $_POST[$keyName][$definiteValueIndex]; + $oldStr = $_POST[$keyName == "oldValue" ? "newValue" : "oldValue"][$definiteValueIndex]; + if (!ctype_digit($newStr)) + $newStr = '"' . $newStr . '"'; + if (!ctype_digit($oldStr)) + $oldStr = '"' . $oldStr . '"'; + + $newValueString = $valueName . " = " . $newStr; + $oldValueString = $valueName . " = " . $oldStr; + $confFile = str_replace($oldValueString, $newValueString, $confFile); + } + echo "

Here is your new configuration file:

"; + echo '
'; + + if (!empty($errors)) + { + echo "

The following errors happened during processing: