From 05780f2c50dc304360d252ee95fd22a8358f06d5 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Tue, 11 May 2021 17:46:28 +0200 Subject: [PATCH] feat(apps): Config Merger (#5779) * feat(apps): Config Merger * update for ac * Update README.md --- apps/config-merger/README.md | 22 +++++ apps/config-merger/index.php | 44 +++++++++ apps/config-merger/merge.php | 179 +++++++++++++++++++++++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 apps/config-merger/README.md create mode 100644 apps/config-merger/index.php create mode 100644 apps/config-merger/merge.php diff --git a/apps/config-merger/README.md b/apps/config-merger/README.md new file mode 100644 index 000000000..4a5301e8f --- /dev/null +++ b/apps/config-merger/README.md @@ -0,0 +1,22 @@ +# ==== PHP merger (index.php + merge.php) ==== + +This is a PHP script for merging a new .dist file with your existing .conf file (worldserver.conf.dist and authserver.conf.dist) + +It uses sessions so it is multi user safe, it adds any options that are removed to the bottom of the file commented out, just in case it removes something it shouldn't. +If you add your custom patch configs below "# Custom" they will be copied exactly as they are. + +Your new config will be found under $basedir/session_id/newconfig.conf.merge + +If you do not run a PHP server on your machiene you can read this guide on ["How to execute PHP code using command line?"](https://www.geeksforgeeks.org/how-to-execute-php-code-using-command-line/) on geeksforgeeks.org. + +``` +php -S localhost:port -t E:\Azerothcore-wotlk\apps\config-merger\ +``` + +Change port to an available port to use. i.e 8000 + +Then go to your browser and type: + +``` +localhost:8000/index.php +``` diff --git a/apps/config-merger/index.php b/apps/config-merger/index.php new file mode 100644 index 000000000..8754d2995 --- /dev/null +++ b/apps/config-merger/index.php @@ -0,0 +1,44 @@ + + +
+Dist File (.conf.dist) +
+ +
+
+Current Conf File (.conf) +
+ +
+
+Windows - +UNIX/Linux +
+
+ +
+
+If you have any custom settings, such as from patches, +
+make sure they are at the bottom of the file following +
+this block (add it if it's not there) +
+############################################################################### +
+# Custom +
+############################################################################### +
+
+ +
diff --git a/apps/config-merger/merge.php b/apps/config-merger/merge.php new file mode 100644 index 000000000..17417e1a2 --- /dev/null +++ b/apps/config-merger/merge.php @@ -0,0 +1,179 @@ + $v) + { + if (array_key_exists($k, $array1)) + { + $array1[$k] = $v; + unset($array2[$k]); + } + } + $in_file1 = fopen($upload1,"r"); + $line = trim(fgets($in_file1)); + while (!feof($in_file1)) + { + if (substr($line,0,1) != '#' && substr($line,0,1) != '') + { + $array = array(); + while (substr($line,0,1) != '#' && substr($line,0,1) != '') + { + list($key, $val) = explode("=",$line); + $key = trim($key); + $val = trim($val); + $array[$key] = $val; + $line = trim(fgets($in_file1)); + } + foreach($array as $k => $v) + { + if (array_key_exists($k, $array1)) + fwrite($out_file, $k."=".$array1[$k].$eol); + else + continue; + } + unset($array); + if (!feof($in_file1)) + fwrite($out_file, $line.$eol); + } + else + fwrite($out_file, $line.$eol); + $line = trim(fgets($in_file1)); + } + if ($custom_found) + { + fwrite($out_file, $eol); + fwrite($out_file, "###############################################################################".$eol); + fwrite($out_file, "# Custom".$eol); + $line = trim(fgets($in_file2)); + while (!feof($in_file2)) + { + fwrite($out_file, $line.$eol); + $line = trim(fgets($in_file2)); + } + } + $first = true; + foreach($array2 as $k => $v) + { + if ($first) + { + fwrite($out_file, $eol); + fwrite($out_file, "###############################################################################".$eol); + fwrite($out_file, "# The Following values were removed from the config.".$eol); + $first = false; + } + fwrite($out_file, "# ".$k."=".$v.$eol); + } + + if (strpos($upload1, "worldserver") !== false) + { + file_put_contents($newconfig, str_replace("]=","]",file_get_contents($newconfig))); + } + else if (strpos($upload1, "authserver") !== false) + { + file_put_contents($newconfig, str_replace("]=","]",file_get_contents($newconfig))); + } + + unset($array1); + unset($array2); + fclose($in_file1); + fclose($in_file2); + fclose($out_file); + unlink($upload1); + unlink($upload2); + + echo "Process done"; + echo "
Click here to retrieve your merged conf"; + } +} +else +{ + echo "An error has occurred"; +} +?>