diff --git a/contrib/conf_merge/confdiffmerge.php b/contrib/conf_merge/confdiffmerge.php new file mode 100644 index 0000000000000..7bcaef5042e76 --- /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: