From 3f2e50a5ddc2a912ddd053166b756b5dfeee60c1 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 13 Oct 2022 12:17:31 -0700 Subject: [PATCH 01/14] Add config compare to not overwrite user changes --- app/classes/shared/helpers.py | 32 +++++++++++++++++++ app/classes/shared/main_controller.py | 46 +++++++++++++++++++++++++++ main.py | 1 + 3 files changed, 79 insertions(+) diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index c4d9ad10..7202caa6 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -376,6 +376,38 @@ class Helpers: return default_return + def set_settings(self, data): + try: + with open(self.settings_file, "w", encoding="utf-8") as f: + json.dump(data, f, indent=4) + + except Exception as e: + logger.critical( + f"Config File Error: Unable to read {self.settings_file} due to {e}" + ) + Console.critical( + f"Config File Error: Unable to read {self.settings_file} due to {e}" + ) + return False + + return True + + def get_all_settings(self): + try: + with open(self.settings_file, "r", encoding="utf-8") as f: + data = json.load(f) + + except Exception as e: + data = {} + logger.critical( + f"Config File Error: Unable to read {self.settings_file} due to {e}" + ) + Console.critical( + f"Config File Error: Unable to read {self.settings_file} due to {e}" + ) + + return data + def set_setting(self, key, new_value): try: with open(self.settings_file, "r", encoding="utf-8") as f: diff --git a/app/classes/shared/main_controller.py b/app/classes/shared/main_controller.py index f61941ca..7ed949bc 100644 --- a/app/classes/shared/main_controller.py +++ b/app/classes/shared/main_controller.py @@ -243,6 +243,52 @@ class Controller: exec_user["user_id"], "support_status_update", results ) + def get_config_diff(self): + master_config = { + "config_ver": 1, + "http_port": 8000, + "https_port": 8443, + "language": "en_EN", + "cookie_expire": 30, + "cookie_secret": "random", + "apikey_secret": "random", + "show_errors": True, + "history_max_age": 7, + "stats_update_frequency": 30, + "delete_default_json": False, + "show_contribute_link": True, + "virtual_terminal_lines": 70, + "max_log_lines": 700, + "max_audit_entries": 300, + "disabled_language_files": ["lol_EN.json", ""], + "stream_size_GB": 1, + "keywords": ["help", "chunk"], + "allow_nsfw_profile_pictures": False, + "enable_user_self_delete": False, + } + user_config = self.helper.get_all_settings() + try: + if user_config["config_ver"] == master_config["config_ver"]: + return user_config + else: + user_config["config_ver"] = master_config["config_ver"] + except: + logger.debug("No config version found") + items_to_del = [] + + for key in user_config: + if key not in master_config.keys(): + items_to_del.append(key) + + for item in items_to_del[:]: + del user_config[item] + + for key, value in master_config.items(): + if key not in user_config.keys(): + user_config[key] = value + + self.helper.set_settings(user_config) + def send_log_status(self): try: return self.log_stats diff --git a/main.py b/main.py index b6fdd89f..60ad4409 100644 --- a/main.py +++ b/main.py @@ -159,6 +159,7 @@ if __name__ == "__main__": logger.info("Initializing all servers defined") Console.info("Initializing all servers defined") controller.servers.init_all_servers() + controller.get_config_diff() def tasks_starter(): # start stats logging From 51f507c4f87c2566c740a16be8b9ec57be085dfa Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 13 Oct 2022 12:25:29 -0700 Subject: [PATCH 02/14] Add comments --- app/classes/shared/main_controller.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/classes/shared/main_controller.py b/app/classes/shared/main_controller.py index 7ed949bc..de112f80 100644 --- a/app/classes/shared/main_controller.py +++ b/app/classes/shared/main_controller.py @@ -267,7 +267,9 @@ class Controller: "enable_user_self_delete": False, } user_config = self.helper.get_all_settings() + # Check user's config version try: + # If they are on the same version there is no need to remove this. if user_config["config_ver"] == master_config["config_ver"]: return user_config else: @@ -276,17 +278,22 @@ class Controller: logger.debug("No config version found") items_to_del = [] + # Iterate through user's config.json and check for + # Keys/values that need to be removed for key in user_config: if key not in master_config.keys(): items_to_del.append(key) + # Remove key/values from user config that were staged for item in items_to_del[:]: del user_config[item] + # Add new keys to user config. for key, value in master_config.items(): if key not in user_config.keys(): user_config[key] = value + # Call helper to set updated config. self.helper.set_settings(user_config) def send_log_status(self): From fbc506f2fd60c7a5da2b4d2857a308544762f4f9 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Mon, 19 Dec 2022 17:15:26 -0500 Subject: [PATCH 03/14] Fix issues after merge conflicts --- app/classes/shared/helpers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index 78ce47c5..e583e597 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -376,7 +376,6 @@ class Helpers: return default_return - def set_settings(self, data): try: with open(self.settings_file, "w", encoding="utf-8") as f: @@ -420,7 +419,6 @@ class Helpers: return False return True ->>>>>>> app/classes/shared/helpers.py def set_setting(self, key, new_value): try: with open(self.settings_file, "r", encoding="utf-8") as f: From 8ee274a92726340795022cf2d8f95e3f251cd12a Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 14:54:25 -0500 Subject: [PATCH 04/14] Remove config.json from repo. Remove version checking. Move master config to helpers. Add config.json when not found on start. --- app/classes/shared/helpers.py | 27 +++++++++++++++++++ app/classes/shared/main_controller.py | 37 +++++---------------------- app/config/config.json | 27 ------------------- main.py | 7 ++++- 4 files changed, 39 insertions(+), 59 deletions(-) delete mode 100644 app/config/config.json diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index e583e597..0f5f098c 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -392,6 +392,33 @@ class Helpers: return True + @staticmethod + def get_master_config(): + # Make changes for users' local config.json files here. As of 4.0.20 + # Config.json was removed from the repo to make it easier for users + # To make non-breaking changes to the file. + return { + "http_port": 8000, + "https_port": 8443, + "language": "en_EN", + "cookie_expire": 30, + "cookie_secret": "random", + "apikey_secret": "random", + "show_errors": True, + "history_max_age": 7, + "stats_update_frequency": 30, + "delete_default_json": False, + "show_contribute_link": True, + "virtual_terminal_lines": 70, + "max_log_lines": 700, + "max_audit_entries": 300, + "disabled_language_files": ["lol_EN.json", ""], + "stream_size_GB": 1, + "keywords": ["help", "chunk"], + "allow_nsfw_profile_pictures": False, + "enable_user_self_delete": False, + } + def get_all_settings(self): try: with open(self.settings_file, "r", encoding="utf-8") as f: diff --git a/app/classes/shared/main_controller.py b/app/classes/shared/main_controller.py index 1ab077ac..4a2856fe 100644 --- a/app/classes/shared/main_controller.py +++ b/app/classes/shared/main_controller.py @@ -245,38 +245,14 @@ class Controller: ) def get_config_diff(self): - master_config = { - "config_ver": 1, - "http_port": 8000, - "https_port": 8443, - "language": "en_EN", - "cookie_expire": 30, - "cookie_secret": "random", - "apikey_secret": "random", - "show_errors": True, - "history_max_age": 7, - "stats_update_frequency": 30, - "delete_default_json": False, - "show_contribute_link": True, - "virtual_terminal_lines": 70, - "max_log_lines": 700, - "max_audit_entries": 300, - "disabled_language_files": ["lol_EN.json", ""], - "stream_size_GB": 1, - "keywords": ["help", "chunk"], - "allow_nsfw_profile_pictures": False, - "enable_user_self_delete": False, - } - user_config = self.helper.get_all_settings() - # Check user's config version + master_config = Helpers.get_master_config() try: - # If they are on the same version there is no need to remove this. - if user_config["config_ver"] == master_config["config_ver"]: - return user_config - else: - user_config["config_ver"] = master_config["config_ver"] + user_config = self.helper.get_all_settings() except: - logger.debug("No config version found") + # Call helper to set updated config. + Console.warning("No Config found. Setting Default Config.json") + self.helper.set_settings(master_config) + return items_to_del = [] # Iterate through user's config.json and check for @@ -293,7 +269,6 @@ class Controller: for key, value in master_config.items(): if key not in user_config.keys(): user_config[key] = value - # Call helper to set updated config. self.helper.set_settings(user_config) diff --git a/app/config/config.json b/app/config/config.json deleted file mode 100644 index ea2e1f0a..00000000 --- a/app/config/config.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "http_port": 8000, - "https_port": 8443, - "language": "en_EN", - "cookie_expire": 30, - "cookie_secret": "random", - "apikey_secret": "random", - "show_errors": true, - "history_max_age": 7, - "stats_update_frequency": 30, - "delete_default_json": false, - "show_contribute_link": true, - "virtual_terminal_lines": 70, - "max_log_lines": 700, - "max_audit_entries": 300, - "disabled_language_files": [ - "lol_EN.json", - "" - ], - "stream_size_GB": 1, - "keywords": [ - "help", - "chunk" - ], - "allow_nsfw_profile_pictures": false, - "enable_user_self_delete": false -} diff --git a/main.py b/main.py index 344bf039..9f6c55fb 100644 --- a/main.py +++ b/main.py @@ -53,6 +53,9 @@ def do_intro(): """ Console.magenta(intro) + if not helper.check_file_exists(helper.settings_file): + Console.debug("No settings file detected. Creating one.") + helper.set_settings(Helpers.get_master_config()) def setup_logging(debug=True): @@ -139,6 +142,9 @@ if __name__ == "__main__": import_helper = ImportHelpers(helper, file_helper) # now the tables are created, we can load the tasks_manager and server controller controller = Controller(database, helper, file_helper, import_helper) + Console.info("Checking for remote changes to config.json") + controller.get_config_diff() + Console.info("Remote change complete.") import3 = Import3(helper, controller) tasks_manager = TasksManager(helper, controller) tasks_manager.start_webserver() @@ -159,7 +165,6 @@ if __name__ == "__main__": logger.info("Initializing all servers defined") Console.info("Initializing all servers defined") controller.servers.init_all_servers() - controller.get_config_diff() def tasks_starter(): # start stats logging From 68322a3a93cc9571dd39ea092c5de7f4422a5b10 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Sun, 29 Jan 2023 19:58:08 +0000 Subject: [PATCH 05/14] Remove config warning from container init --- docker_launcher.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/docker_launcher.sh b/docker_launcher.sh index 3e2cfd6c..c270ad2e 100644 --- a/docker_launcher.sh +++ b/docker_launcher.sh @@ -18,16 +18,6 @@ if [ ! "$(ls -A --ignore=.gitkeep ./app/config)" ]; then else # Keep version file up to date with image cp -f ./app/config_original/version.json ./app/config/version.json - - # Compare if user's config is different from image, and show differences. - echo "\033[36mWrapper | \033[35m🏗️ Checking for config.json changes..." - cp -f ./app/config_original/config.json ./app/config/config_image_template - if [ "$(diff -q ./app/config/config.json ./app/config/config_image_template)" ]; then - echo "\033[36mWrapper | \033[33m👷 We've found differences in your local config, please review!," - echo "\033[36m | \033[33m (This could be an outdated config.json)" - else - echo "\033[36mWrapper | \033[32m✅ Config good! Proceeding..." - fi fi From 2d9529ba0c3bf13aae7a8fa2ab5b4a629b1f7e56 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 16:54:02 -0500 Subject: [PATCH 06/14] Add cookie secret to DB Allow users to reset cookie and api secret Add Crafty row to table on fresh install Change inserts to updates for crafty settings table. --- .../controllers/management_controller.py | 8 +++++ app/classes/models/management.py | 29 ++++++++++++++++++- app/classes/shared/helpers.py | 3 +- app/classes/shared/main_models.py | 5 +++- app/classes/web/tornado_handler.py | 10 +++++-- app/migrations/20230129_secrets_shh.py | 16 ++++++++++ main.py | 16 +++++++++- 7 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 app/migrations/20230129_secrets_shh.py diff --git a/app/classes/controllers/management_controller.py b/app/classes/controllers/management_controller.py index dc0f5422..2811dce4 100644 --- a/app/classes/controllers/management_controller.py +++ b/app/classes/controllers/management_controller.py @@ -46,6 +46,14 @@ class ManagementController: def get_crafty_api_key(): return HelpersManagement.get_secret_api_key() + @staticmethod + def set_cookie_secret(key): + HelpersManagement.set_cookie_secret(key) + + @staticmethod + def add_crafty_row(): + HelpersManagement.create_crafty_row() + # ********************************************************************************** # Commands Methods # ********************************************************************************** diff --git a/app/classes/models/management.py b/app/classes/models/management.py index bb183eef..c2b5afde 100644 --- a/app/classes/models/management.py +++ b/app/classes/models/management.py @@ -43,6 +43,7 @@ class AuditLog(BaseModel): # ********************************************************************************** class CraftySettings(BaseModel): secret_api_key = CharField(default="") + cookie_secret = CharField(default="") login_photo = CharField(default="login_1.jpg") login_opacity = IntegerField(default=100) @@ -204,9 +205,22 @@ class HelpersManagement: else: return + @staticmethod + def create_crafty_row(): + CraftySettings.insert( + { + CraftySettings.secret_api_key: "", + CraftySettings.cookie_secret: "", + CraftySettings.login_photo: "login_1.jpg", + CraftySettings.login_opacity: 100, + } + ).execute() + @staticmethod def set_secret_api_key(key): - CraftySettings.insert(secret_api_key=key).execute() + CraftySettings.update({CraftySettings.secret_api_key: key}).where( + CraftySettings.id == 1 + ).execute() @staticmethod def get_secret_api_key(): @@ -215,6 +229,19 @@ class HelpersManagement: ) return settings[0].secret_api_key + @staticmethod + def get_cookie_secret(): + settings = CraftySettings.select(CraftySettings.cookie_secret).where( + CraftySettings.id == 1 + ) + return settings[0].cookie_secret + + @staticmethod + def set_cookie_secret(key): + CraftySettings.update({CraftySettings.cookie_secret: key}).where( + CraftySettings.id == 1 + ).execute() + # ********************************************************************************** # Config Methods # ********************************************************************************** diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index 4efe355a..f3643362 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -403,8 +403,6 @@ class Helpers: "https_port": 8443, "language": "en_EN", "cookie_expire": 30, - "cookie_secret": "random", - "apikey_secret": "random", "show_errors": True, "history_max_age": 7, "stats_update_frequency": 30, @@ -418,6 +416,7 @@ class Helpers: "keywords": ["help", "chunk"], "allow_nsfw_profile_pictures": False, "enable_user_self_delete": False, + "reset_secrets_on_boot": False, } def get_all_settings(self): diff --git a/app/classes/shared/main_models.py b/app/classes/shared/main_models.py index 7c43a131..4bfca52c 100644 --- a/app/classes/shared/main_models.py +++ b/app/classes/shared/main_models.py @@ -8,9 +8,10 @@ logger = logging.getLogger(__name__) class DatabaseBuilder: - def __init__(self, database, helper, users_helper): + def __init__(self, database, helper, users_helper, management_helper): self.database = database self.helper = helper + self.management_helper = management_helper self.users_helper = users_helper def default_settings(self): @@ -29,6 +30,8 @@ class DatabaseBuilder: manager=None, ) + self.management_helper.create_crafty_row() + def is_fresh_install(self): try: num_user = self.users_helper.get_user_total() diff --git a/app/classes/web/tornado_handler.py b/app/classes/web/tornado_handler.py index 4feae695..d0413beb 100644 --- a/app/classes/web/tornado_handler.py +++ b/app/classes/web/tornado_handler.py @@ -11,6 +11,7 @@ import tornado.escape import tornado.locale import tornado.httpserver +from app.classes.models.management import HelpersManagement from app.classes.shared.console import Console from app.classes.shared.helpers import Helpers from app.classes.shared.main_controller import Controller @@ -110,10 +111,13 @@ class Webserver: https_port = self.helper.get_setting("https_port") debug_errors = self.helper.get_setting("show_errors") - cookie_secret = self.helper.get_setting("cookie_secret") - - if cookie_secret is False: + try: + cookie_secret = HelpersManagement.get_cookie_secret() + except: + cookie_secret = False + if cookie_secret is False or cookie_secret == "": cookie_secret = self.helper.random_string_generator(32) + HelpersManagement.set_cookie_secret(cookie_secret) if not http_port: http_port = 8000 diff --git a/app/migrations/20230129_secrets_shh.py b/app/migrations/20230129_secrets_shh.py new file mode 100644 index 00000000..5610f6e0 --- /dev/null +++ b/app/migrations/20230129_secrets_shh.py @@ -0,0 +1,16 @@ +# Generated by database migrator +import peewee + + +def migrate(migrator, database, **kwargs): + migrator.add_columns("crafty_settings", cookie_secret=peewee.CharField(default="")) + """ + Write your migrations here. + """ + + +def rollback(migrator, database, **kwargs): + migrator.drop_columns("crafty_settings", ["cookie_secret"]) + """ + Write your rollback migrations here. + """ diff --git a/main.py b/main.py index accc8bfa..3db1ea07 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,7 @@ from app.classes.shared.import3 import Import3 from app.classes.shared.console import Console from app.classes.shared.helpers import Helpers from app.classes.models.users import HelperUsers +from app.classes.models.management import HelpersManagement from app.classes.shared.import_helper import ImportHelpers console = Console() @@ -124,7 +125,8 @@ if __name__ == "__main__": # do our installer stuff user_helper = HelperUsers(database, helper) - installer = DatabaseBuilder(database, helper, user_helper) + management_helper = HelpersManagement(database, helper) + installer = DatabaseBuilder(database, helper, user_helper, management_helper) FRESH_INSTALL = installer.is_fresh_install() if FRESH_INSTALL: @@ -145,6 +147,18 @@ if __name__ == "__main__": Console.info("Checking for remote changes to config.json") controller.get_config_diff() Console.info("Remote change complete.") + + Console.info("Checking for reset secret flag") + if helper.get_setting("reset_secrets_on_boot"): + Console.info("Found Reset") + controller.management.set_crafty_api_key( + str(helper.random_string_generator(64)) + ) + controller.management.set_cookie_secret(str(helper.random_string_generator(32))) + helper.set_setting("reset_secrets_on_boot", False) + else: + Console.info("No flag found. Secrets are staying") + import3 = Import3(helper, controller) tasks_manager = TasksManager(helper, controller) tasks_manager.start_webserver() From bd8e12f884bfe7ad77001af9641f57badddaea3e Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 17:00:28 -0500 Subject: [PATCH 07/14] Fix wording in reset --- app/classes/shared/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index f3643362..7dcbdeef 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -416,7 +416,7 @@ class Helpers: "keywords": ["help", "chunk"], "allow_nsfw_profile_pictures": False, "enable_user_self_delete": False, - "reset_secrets_on_boot": False, + "reset_secrets_on_next_boot": False, } def get_all_settings(self): From d24c3c5ba0c1236cb4c61998357ad12953fae286 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 17:05:17 -0500 Subject: [PATCH 08/14] Add red color to reset values --- app/frontend/templates/panel/config_json.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/frontend/templates/panel/config_json.html b/app/frontend/templates/panel/config_json.html index 9f7e78f7..8a6d5697 100644 --- a/app/frontend/templates/panel/config_json.html +++ b/app/frontend/templates/panel/config_json.html @@ -81,21 +81,23 @@ {% elif isinstance(item[1], list) %} {% elif isinstance(item[1], bool) %} - {% if item[1] == True %} + {% if item[0] == "reset_secrets_on_next_boot" %} +
+ {% else %}
+ {% end %} + {% if item[1] == True %}  
  -
{% else %} -
 
  -
{% end %} +
{% elif isinstance(item[1], int) %} {% else %} From af654bc89f82bde3cf81dfa8157bcd26127fae23 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 17:25:44 -0500 Subject: [PATCH 09/14] Make the color look nicer --- app/frontend/templates/panel/config_json.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/frontend/templates/panel/config_json.html b/app/frontend/templates/panel/config_json.html index 8a6d5697..a5acdcc1 100644 --- a/app/frontend/templates/panel/config_json.html +++ b/app/frontend/templates/panel/config_json.html @@ -48,7 +48,11 @@ {% raw xsrf_form_html() %} {% for item in data['config-json'].items() %} + {% if item[0] == "reset_secrets_on_next_boot" %} +
+ {% else %}
+ {% end %}
@@ -81,11 +85,7 @@ {% elif isinstance(item[1], list) %} {% elif isinstance(item[1], bool) %} - {% if item[0] == "reset_secrets_on_next_boot" %} -
- {% else %}
- {% end %} {% if item[1] == True %}  
From e04fee0ea12ddd38648eed720c728819980e0169 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 17:58:24 -0500 Subject: [PATCH 10/14] Fix key reset --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 3db1ea07..5a9604f5 100644 --- a/main.py +++ b/main.py @@ -155,7 +155,7 @@ if __name__ == "__main__": str(helper.random_string_generator(64)) ) controller.management.set_cookie_secret(str(helper.random_string_generator(32))) - helper.set_setting("reset_secrets_on_boot", False) + helper.set_setting("reset_secrets_on_next_boot", False) else: Console.info("No flag found. Secrets are staying") From 8707a1470cbc02e4280840fd4b659c5d97d05909 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 17:58:47 -0500 Subject: [PATCH 11/14] Fix naming --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 5a9604f5..4aa5880c 100644 --- a/main.py +++ b/main.py @@ -149,7 +149,7 @@ if __name__ == "__main__": Console.info("Remote change complete.") Console.info("Checking for reset secret flag") - if helper.get_setting("reset_secrets_on_boot"): + if helper.get_setting("reset_secrets_on_next_boot"): Console.info("Found Reset") controller.management.set_crafty_api_key( str(helper.random_string_generator(64)) From 3f3595acb4e121aa2408912c411fd792f3548727 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 18:21:04 -0500 Subject: [PATCH 12/14] Sort config.json in alphabetical order --- app/classes/shared/helpers.py | 2 +- app/classes/shared/main_controller.py | 11 +++++++++-- app/classes/web/panel_handler.py | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index 7dcbdeef..691a25f1 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -411,7 +411,7 @@ class Helpers: "virtual_terminal_lines": 70, "max_log_lines": 700, "max_audit_entries": 300, - "disabled_language_files": ["lol_EN.json", ""], + "disabled_language_files": [], "stream_size_GB": 1, "keywords": ["help", "chunk"], "allow_nsfw_profile_pictures": False, diff --git a/app/classes/shared/main_controller.py b/app/classes/shared/main_controller.py index 31b9c314..3bbe05f8 100644 --- a/app/classes/shared/main_controller.py +++ b/app/classes/shared/main_controller.py @@ -251,7 +251,11 @@ class Controller: except: # Call helper to set updated config. Console.warning("No Config found. Setting Default Config.json") - self.helper.set_settings(master_config) + user_config = master_config + keys = list(user_config.keys()) + keys.sort() + sorted_data = {i: user_config[i] for i in keys} + self.helper.set_settings(user_config) return items_to_del = [] @@ -270,7 +274,10 @@ class Controller: if key not in user_config.keys(): user_config[key] = value # Call helper to set updated config. - self.helper.set_settings(user_config) + keys = list(user_config.keys()) + keys.sort() + sorted_data = {i: user_config[i] for i in keys} + self.helper.set_settings(sorted_data) def send_log_status(self): try: diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index bf56c3e0..74c93b88 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -1774,8 +1774,11 @@ class PanelHandler(BaseHandler): data[key] = False else: data[key] = arg_data + keys = list(data.keys()) + keys.sort() + sorted_data = {i: data[i] for i in keys} with open(self.helper.settings_file, "w", encoding="utf-8") as f: - json.dump(data, f, indent=4) + json.dump(sorted_data, f, indent=4) except Exception as e: logger.critical( "Config File Error: Unable to read " From c8b8468030891374885da72e29a956bf601e1625 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 18:21:53 -0500 Subject: [PATCH 13/14] Move resets before controller is instanciated. --- main.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 4aa5880c..5f05390e 100644 --- a/main.py +++ b/main.py @@ -140,6 +140,14 @@ if __name__ == "__main__": installer.default_settings() else: Console.debug("Existing install detected") + Console.info("Checking for reset secret flag") + if helper.get_setting("reset_secrets_on_next_boot"): + Console.info("Found Reset") + management_helper.set_secret_api_key(str(helper.random_string_generator(64))) + management_helper.set_cookie_secret(str(helper.random_string_generator(32))) + helper.set_setting("reset_secrets_on_next_boot", False) + else: + Console.info("No flag found. Secrets are staying") file_helper = FileHelpers(helper) import_helper = ImportHelpers(helper, file_helper) # now the tables are created, we can load the tasks_manager and server controller @@ -148,17 +156,6 @@ if __name__ == "__main__": controller.get_config_diff() Console.info("Remote change complete.") - Console.info("Checking for reset secret flag") - if helper.get_setting("reset_secrets_on_next_boot"): - Console.info("Found Reset") - controller.management.set_crafty_api_key( - str(helper.random_string_generator(64)) - ) - controller.management.set_cookie_secret(str(helper.random_string_generator(32))) - helper.set_setting("reset_secrets_on_next_boot", False) - else: - Console.info("No flag found. Secrets are staying") - import3 = Import3(helper, controller) tasks_manager = TasksManager(helper, controller) tasks_manager.start_webserver() From c817d0dbb6a04e58456a57a1aa3295ad60f2b115 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Sun, 29 Jan 2023 23:29:36 +0000 Subject: [PATCH 14/14] Update changelog !485 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb3da326..15e51dd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### New features - Add option to run command before backup. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/536)) - Make Config.json editable from panel. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/532)) +- Managed config.json refector (See MR for details). ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/485)) ### Bug fixes - Fix local java server imports. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/529)) - Fix Schedule Restore | Add Backup Config Preservation. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/533))