From 3f2e50a5ddc2a912ddd053166b756b5dfeee60c1 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 13 Oct 2022 12:17:31 -0700 Subject: [PATCH 01/78] 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/78] 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/78] 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 d7d27b00c430b974158c78d1c033afd12da30a8c Mon Sep 17 00:00:00 2001 From: Zedifus Date: Sat, 7 Jan 2023 18:56:13 +0000 Subject: [PATCH 04/78] Prepare 4.0.20 release base --- CHANGELOG.md | 11 +++++++++++ README.md | 2 +- app/config/version.json | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56b9730d..88f02e8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,15 @@ # Changelog +## --- [4.0.20] - 2022/TBD +### New features +TBD +### Bug fixes +TBD +### Tweaks +TBD +### Lang +TBD +

+ ## --- [4.0.19] - 2022/01/07 ### Bug fixes - Fix port tooltip not showing on dash while server online. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/503)) diff --git a/README.md b/README.md index f9a19ae1..059df365 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Crafty Logo](app/frontend/static/assets/images/logo_long.svg)](https://craftycontrol.com) -# Crafty Controller 4.0.19 +# Crafty Controller 4.0.20 > Python based Control Panel for your Minecraft Server ## What is Crafty Controller? diff --git a/app/config/version.json b/app/config/version.json index 02ec3ae1..d0dce112 100644 --- a/app/config/version.json +++ b/app/config/version.json @@ -1,5 +1,5 @@ { "major": 4, "minor": 0, - "sub": 19 + "sub": 20 } From 199c8a4fe6c92156e76f802632f43e44d5ba90d9 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 8 Jan 2023 00:32:08 -0500 Subject: [PATCH 05/78] Fix local java server imports --- app/classes/web/server_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/classes/web/server_handler.py b/app/classes/web/server_handler.py index 62c549e5..1c0d5962 100644 --- a/app/classes/web/server_handler.py +++ b/app/classes/web/server_handler.py @@ -331,7 +331,7 @@ class ServerHandler(BaseHandler): return if import_type == "import_jar": - if not self.helper.is_subdir( + if self.helper.is_subdir( import_server_path, self.controller.project_root ): self.redirect( From 4031b74e00a350db7c1c71f64736631b881af7b0 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 9 Jan 2023 16:34:12 -0500 Subject: [PATCH 06/78] Hide server stats db from users --- app/classes/shared/helpers.py | 42 +++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index c5238ae8..01712fbb 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -960,22 +960,24 @@ class Helpers: file_list = sorted(dir_list, key=str.casefold) + sorted( unsorted_files, key=str.casefold ) + ignored_names = ["crafty_managed.txt", "db_stats"] for raw_filename in file_list: filename = html.escape(raw_filename) rel = os.path.join(folder, raw_filename) dpath = os.path.join(folder, filename) if os.path.isdir(rel): - output += f"""
  • - \n
    - - - - {filename} - -
  • - \n""" + if filename not in ignored_names: + output += f"""
  • + \n
    + + + + {filename} + +
  • + \n""" else: - if filename != "crafty_managed.txt": + if filename not in ignored_names: output += f"""
  • """ for raw_filename in file_list: filename = html.escape(raw_filename) dpath = os.path.join(folder, filename) rel = os.path.join(folder, raw_filename) if os.path.isdir(rel): - output += f"""
  • - \n
    - - - - {filename} - -
  • """ + if filename not in ignored_names: + output += f"""
  • + \n
    + + + + {filename} + +
  • """ else: - if filename != "crafty_managed.txt": + if filename not in ignored_names: output += f"""
  • Date: Mon, 9 Jan 2023 18:52:45 -0500 Subject: [PATCH 07/78] Make config editable from Crafty --- app/classes/web/panel_handler.py | 7 + app/frontend/templates/panel/config_json.html | 229 ++++++++++++++++++ .../templates/panel/panel_config.html | 12 + 3 files changed, 248 insertions(+) create mode 100644 app/frontend/templates/panel/config_json.html diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 582517db..3e7699c8 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -897,6 +897,13 @@ class PanelHandler(BaseHandler): template = "panel/panel_config.html" + elif page == "config_json": + with open(self.helper.settings_file, "r", encoding="utf-8") as f: + data = json.load(f) + page_data["config-json"] = data + + template = "panel/config_json.html" + elif page == "add_user": page_data["new_user"] = True page_data["user"] = {} diff --git a/app/frontend/templates/panel/config_json.html b/app/frontend/templates/panel/config_json.html new file mode 100644 index 00000000..68f42b7b --- /dev/null +++ b/app/frontend/templates/panel/config_json.html @@ -0,0 +1,229 @@ +{% extends ../base.html %} + +{% block meta %} +{% end %} + +{% block title %}Crafty Controller - {{ translate('panelConfig', 'pageTitle', data['lang']) }}{% end %} + +{% block content %} + +
    + {% if data['superuser'] %} + + {% end %} + + +
    +
    + +
    + +
    + + +
    +
    +
    +
    +
    + {% for item in data['config-json'].items() %} + + {% if isinstance(item[1], bool) %} + + {% if item[1] == True %} +
    + +  
    + +  
    +
    + {% else %} +
    + +  
    + +  
    +
    + {% end %} + {% elif isinstance(item[1], int) %} + + {% else %} + + {% end %} + {% end %} +
    +
    +
    +
    +
    + + +
    + + + + +{% end %} + +{% block js %} + + + +{% end %} \ No newline at end of file diff --git a/app/frontend/templates/panel/panel_config.html b/app/frontend/templates/panel/panel_config.html index a4ee9f66..15f0a269 100644 --- a/app/frontend/templates/panel/panel_config.html +++ b/app/frontend/templates/panel/panel_config.html @@ -8,6 +8,18 @@ {% block content %}
    + {% if data['superuser'] %} + + {% end %}
    From 3c11f0120da11e436963f5458807c292db7f6d50 Mon Sep 17 00:00:00 2001 From: Silversthorn Date: Tue, 10 Jan 2023 00:53:47 +0100 Subject: [PATCH 08/78] Rework panel config for login page --- .../templates/panel/panel_config.html | 144 +++++++++++------- app/translations/en_EN.json | 2 + 2 files changed, 88 insertions(+), 58 deletions(-) diff --git a/app/frontend/templates/panel/panel_config.html b/app/frontend/templates/panel/panel_config.html index a4ee9f66..050ea9b4 100644 --- a/app/frontend/templates/panel/panel_config.html +++ b/app/frontend/templates/panel/panel_config.html @@ -34,8 +34,8 @@ }} {% if data['user_data']['hints'] %} + data-content="{{ translate('dashboard', 'cannotSeeOnMobile2', data['lang']) }}" , + data-placement="top"> {% end %}
    -
    +
    +
    +

    {{ translate('panelConfig', 'customLoginPage', data['lang']) }}

    +
    - -

    {{ translate('panelConfig', 'loginImage', data['lang']) }}

    -
    -

    - -

    - {% raw xsrf_form_html() %} - - -
    -
    - -
    -
    -
    - - - - -
    +
    +
    +

    {{ translate('panelConfig', 'loginImage', data['lang']) }}

    +
    + + {% raw xsrf_form_html() %} + +
    +
    +
    + +
    + +
    +
    +

    {{ translate('panelConfig', 'loginBackground', data['lang']) }}

    +
    + + +
    +
    +
    +
    +
    {{ translate('panelConfig', 'preview', data['lang']) }}:
    +
    +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + Responsive image +
    + + +
    +
    -
    - -

    -
    -
    -
    -
    -
    -

    {{ translate('panelConfig', 'loginBackground', data['lang']) }}




    -
    - -
    -
    -
    {{ translate('panelConfig', 'preview', data['lang']) }}:
    - -
    -
    -
    - - -
    +
    @@ -404,10 +417,25 @@ }); }) + function updateBackgroundSelect() { + $("#photo").val($("#try_photo").val()).change(); + } + + function updateBackgroundPreview() { + var img = document.getElementById('bg-preview'); + if ($("#photo").val() == "login_1.jpg") { + var src_path = "../../static/assets/images/auth/".concat($("#photo").val()); + } + else { + var src_path = "../../static/assets/images/auth/custom/".concat($("#photo").val()); + } + img.src = src_path; + } + var file; function sendFile() { file = $("#file")[0].files[0] - document.getElementById("upload_input").innerHTML = '
     
    ' + document.getElementById("upload_input").innerHTML = '
     
    '; let xmlHttpRequest = new XMLHttpRequest(); let token = getCookie("_xsrf") let fileName = file.name diff --git a/app/translations/en_EN.json b/app/translations/en_EN.json index 49271004..df422c79 100644 --- a/app/translations/en_EN.json +++ b/app/translations/en_EN.json @@ -228,9 +228,11 @@ "superConfirmTitle": "Enable superuser? Are you sure?", "user": "User", "users": "Users", + "customLoginPage": "Customise the Login Page", "loginImage": "Upload a background image for the login screen.", "backgroundUpload": "Background Upload", "loginBackground": "Login Background Image", + "loginOpacity": "Select the Login Window Opacity", "select": "Select", "selectImage": "Select an image", "preview": "Preview" From 5d3dbc6f9c51cbf8704127c6ea878d6b8b2359b9 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 9 Jan 2023 19:01:05 -0500 Subject: [PATCH 09/78] Fix security --- app/classes/web/panel_handler.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 3e7699c8..90ba2aef 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -898,11 +898,12 @@ class PanelHandler(BaseHandler): template = "panel/panel_config.html" elif page == "config_json": - with open(self.helper.settings_file, "r", encoding="utf-8") as f: - data = json.load(f) - page_data["config-json"] = data + if exec_user["superuser"]: + with open(self.helper.settings_file, "r", encoding="utf-8") as f: + data = json.load(f) + page_data["config-json"] = data - template = "panel/config_json.html" + template = "panel/config_json.html" elif page == "add_user": page_data["new_user"] = True From bea48d9059d8a43fe01928c4871405c7e894de74 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 10 Jan 2023 14:12:33 -0500 Subject: [PATCH 10/78] Add better formatting for lists. --- app/classes/web/panel_handler.py | 21 +++++++++++++++++++ app/frontend/templates/panel/config_json.html | 21 ++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 90ba2aef..38b9fd71 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -1720,6 +1720,27 @@ class PanelHandler(BaseHandler): self.tasks_manager.reload_schedule_from_db() self.redirect(f"/panel/server_detail?id={server_id}&subpage=backup") + elif page == "config_json": + try: + data = {} + with open(self.helper.settings_file, "r", encoding="utf-8") as f: + print("open") + keys = json.load(f).keys() + for key in keys: + print(self.get_argument(key)) + data[key] = self.get_argument(key) + print("data:", data) + """ + with open(self.helper.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.helper.settings_file} due to {e}" + ) + + self.redirect("/panel/config_json") + if page == "new_schedule": server_id = self.check_server_id() if not server_id: diff --git a/app/frontend/templates/panel/config_json.html b/app/frontend/templates/panel/config_json.html index 68f42b7b..c2afaa93 100644 --- a/app/frontend/templates/panel/config_json.html +++ b/app/frontend/templates/panel/config_json.html @@ -37,36 +37,47 @@
    -
    + + {% raw xsrf_form_html() %} {% for item in data['config-json'].items() %} +
    +
    - {% if isinstance(item[1], bool) %} + {% if isinstance(item[1], list) %} +
      + {% for li in item[1] %} +
      + {% end %} +
    + {% elif isinstance(item[1], bool) %} {% if item[1] == True %}
     
    -  
    +  
    {% else %}
     
    -  
    +  
    {% end %} {% elif isinstance(item[1], int) %} + step="1" min="0" required> {% else %} {% end %} {% end %} +
    From f9064eb15f19210df2733829cbd391f720caad98 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sat, 14 Jan 2023 22:22:37 -0500 Subject: [PATCH 11/78] Turn it into a list for a fresh start at this --- app/frontend/templates/panel/config_json.html | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/frontend/templates/panel/config_json.html b/app/frontend/templates/panel/config_json.html index c2afaa93..c5f3e5ad 100644 --- a/app/frontend/templates/panel/config_json.html +++ b/app/frontend/templates/panel/config_json.html @@ -46,10 +46,10 @@ {% if isinstance(item[1], list) %} -
      +
        {% for li in item[1] %} -
        +
      • {{li}}
      • +
        {% end %}
      {% elif isinstance(item[1], bool) %} @@ -107,6 +107,15 @@ {% block js %} + \ No newline at end of file diff --git a/app/migrations/20230111_adding_login_opacity.py b/app/migrations/20230111_adding_login_opacity.py new file mode 100644 index 00000000..536e352a --- /dev/null +++ b/app/migrations/20230111_adding_login_opacity.py @@ -0,0 +1,18 @@ +# Generated by database migrator +import peewee + + +def migrate(migrator, database, **kwargs): + migrator.add_columns( + "crafty_settings", login_opacity=peewee.IntegerField(default=100) + ) + """ + Write your migrations here. + """ + + +def rollback(migrator, database, **kwargs): + migrator.drop_columns("crafty_settings", ["login_opacity"]) + """ + Write your rollback migrations here. + """ diff --git a/app/translations/en_EN.json b/app/translations/en_EN.json index df422c79..296f1b16 100644 --- a/app/translations/en_EN.json +++ b/app/translations/en_EN.json @@ -234,6 +234,7 @@ "loginBackground": "Login Background Image", "loginOpacity": "Select the Login Window Opacity", "select": "Select", + "apply": "Apply", "selectImage": "Select an image", "preview": "Preview" }, From 9fc7a0523e9b4ee10373af4745b28a912b1e5c48 Mon Sep 17 00:00:00 2001 From: Silversthorn Date: Tue, 17 Jan 2023 21:48:17 +0100 Subject: [PATCH 21/78] Improve display of the login form on settings --- .../templates/panel/panel_config.html | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/frontend/templates/panel/panel_config.html b/app/frontend/templates/panel/panel_config.html index 019c8009..255c6ed3 100644 --- a/app/frontend/templates/panel/panel_config.html +++ b/app/frontend/templates/panel/panel_config.html @@ -291,14 +291,22 @@
    -
    +
    Responsive image -
    +
  • \n
    @@ -977,7 +976,7 @@ class Helpers:
  • \n""" else: - if filename not in ignored_names: + if filename not in self.ignored_names: output += f"""
  • {filename}
  • """ return output - @staticmethod - def generate_dir(folder, output=""): + def generate_dir(self, folder, output=""): dir_list = [] unsorted_files = [] @@ -1000,14 +998,13 @@ class Helpers: file_list = sorted(dir_list, key=str.casefold) + sorted( unsorted_files, key=str.casefold ) - ignored_names = ["crafty_managed.txt", "db_stats"] output += f"""
      """ for raw_filename in file_list: filename = html.escape(raw_filename) dpath = os.path.join(folder, filename) rel = os.path.join(folder, raw_filename) if os.path.isdir(rel): - if filename not in ignored_names: + if filename not in self.ignored_names: output += f"""
    • \n
      @@ -1017,7 +1014,7 @@ class Helpers:
    • """ else: - if filename not in ignored_names: + if filename not in self.ignored_names: output += f"""
    • Date: Sat, 28 Jan 2023 16:43:27 +0100 Subject: [PATCH 58/78] Add Default redirection to Dashboard to prevent login if the user is connected --- app/classes/web/default_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/classes/web/default_handler.py b/app/classes/web/default_handler.py index 22533815..dc5c79bb 100644 --- a/app/classes/web/default_handler.py +++ b/app/classes/web/default_handler.py @@ -17,5 +17,5 @@ class DefaultHandler(BaseHandler): ) else: self.redirect( - "/login", + "/panel/dashboard", ) From e0541b1ec0379d723e970b60bdc32a25bc8ff0c5 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sat, 28 Jan 2023 19:10:27 -0500 Subject: [PATCH 59/78] Change file tree doesn't reload on upload/delete --- app/classes/shared/helpers.py | 8 ++--- .../templates/panel/server_files.html | 31 ++++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index c5238ae8..e64e4329 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -965,7 +965,7 @@ class Helpers: rel = os.path.join(folder, raw_filename) dpath = os.path.join(folder, filename) if os.path.isdir(rel): - output += f"""
    • + output += f"""
    • \n
      @@ -976,7 +976,7 @@ class Helpers: \n""" else: if filename != "crafty_managed.txt": - output += f"""
    • + output += f"""
    • \n
      @@ -1014,7 +1014,7 @@ class Helpers:
    • """ else: if filename != "crafty_managed.txt": - output += f"""
    • { if (event.target.responseText == 'success') { - console.log('Upload for file', file.name, 'was successful!') + console.log('Upload for file', file.name, 'was successful!'); + par_el = document.getElementById(path + "ul"); + let name = file.name; + console.log(par_el) + let full_path = path + '/' + name + var items = par_el.getElementsByTagName("li"); + let flag = false; + for (var k = 0; k < items.length; ++k) { + if ($(items[k]).attr("data-name") == name) { + console.log("FLAGGED") + flag = true; + } + } + if (!flag) { + $(par_el).append('
    • ' + name + '
    • '); + } + return true; } else { alert('Upload failed with response: ' + event.target.responseText); @@ -735,7 +751,7 @@ let uploadWaitDialog; let doUpload = true; - function uploadFilesE(event) { + async function uploadFilesE(event) { path = event.target.parentElement.getAttribute('data-path'); $(function () { var uploadHtml = "
      " + @@ -795,7 +811,7 @@ `; $('#upload-progress-bar-parent').append(progressHtml); - sendFile(files.files[i], path, serverId, nFiles - i - 1, (progress) => { + response = await sendFile(files.files[i], path, serverId, nFiles - i - 1, (progress) => { $(`#upload-progress-bar-${i + 1}`).attr('aria-valuenow', progress) $(`#upload-progress-bar-${i + 1}`).css('width', progress + '%') }); @@ -996,7 +1012,6 @@ function hideUploadBox() { if (!uploadWaitDialog) return; uploadWaitDialog.modal('hide'); - getTreeView(); } function createFileE(event) { @@ -1074,7 +1089,8 @@ callback: function (result) { if (!result) return; deleteFile(path, function () { - getTreeView() + el = document.getElementById(path + "li"); + $(el).remove(); document.getElementById('files-tree-nav').style.display = 'none'; }); } @@ -1102,7 +1118,8 @@ callback: function (result) { if (!result) return; deleteDir(path, function () { - getTreeView() + el = document.getElementById(path + "li"); + $(el).remove(); document.getElementById('files-tree-nav').style.display = 'none'; }); } From d31a0a05127cbe92616611c019581975aa4bbd08 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sat, 28 Jan 2023 20:35:58 -0500 Subject: [PATCH 60/78] Fix root directory uploads --- .../templates/panel/server_files.html | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/frontend/templates/panel/server_files.html b/app/frontend/templates/panel/server_files.html index 0deb3d97..d61999f3 100644 --- a/app/frontend/templates/panel/server_files.html +++ b/app/frontend/templates/panel/server_files.html @@ -720,20 +720,31 @@ xmlHttpRequest.addEventListener('load', (event) => { if (event.target.responseText == 'success') { console.log('Upload for file', file.name, 'was successful!'); - par_el = document.getElementById(path + "ul"); + let caught = false; + try { + var par_el = document.getElementById(path + "ul"); + var items = par_el.children; + } catch { + caught = true; + var par_el = document.getElementById("files-tree"); + var items = par_el.children; + } let name = file.name; console.log(par_el) let full_path = path + '/' + name - var items = par_el.getElementsByTagName("li"); let flag = false; for (var k = 0; k < items.length; ++k) { if ($(items[k]).attr("data-name") == name) { - console.log("FLAGGED") flag = true; } } if (!flag) { - $(par_el).append('
    • ' + name + '
    • '); + if (caught) { + $(par_el).append('
    • ' + name + '
    • '); + } else { + $(par_el).append('
    • ' + name + '
    • '); + } + setTreeViewContext(); } return true; } From 3c2b2e8a87050b0b886071e957288d0969ae4fc9 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sat, 28 Jan 2023 21:50:45 -0500 Subject: [PATCH 61/78] Add better feedback for files that finish upload --- app/frontend/templates/panel/server_files.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/frontend/templates/panel/server_files.html b/app/frontend/templates/panel/server_files.html index d61999f3..5734f3a6 100644 --- a/app/frontend/templates/panel/server_files.html +++ b/app/frontend/templates/panel/server_files.html @@ -697,7 +697,7 @@ }); } - async function sendFile(file, path, serverId, left, onProgress) { + async function sendFile(file, path, serverId, left, i, onProgress) { let xmlHttpRequest = new XMLHttpRequest(); let token = getCookie("_xsrf") let fileName = file.name @@ -746,7 +746,9 @@ } setTreeViewContext(); } - return true; + $(`#upload-progress-bar-${i + 1}`).removeClass("progress-bar-striped"); + $(`#upload-progress-bar-${i + 1}`).addClass("bg-success"); + $(`#upload-progress-bar-${i + 1}`).html('') } else { alert('Upload failed with response: ' + event.target.responseText); @@ -822,7 +824,7 @@ `; $('#upload-progress-bar-parent').append(progressHtml); - response = await sendFile(files.files[i], path, serverId, nFiles - i - 1, (progress) => { + await sendFile(files.files[i], path, serverId, nFiles - i - 1, i, (progress) => { $(`#upload-progress-bar-${i + 1}`).attr('aria-valuenow', progress) $(`#upload-progress-bar-${i + 1}`).css('width', progress + '%') }); From 33c2fcbd03a7f3d482e8d489a08b791d5c24b918 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Sun, 29 Jan 2023 19:27:10 +0000 Subject: [PATCH 62/78] Update changelog !532 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd7daf70..fb3da326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## --- [4.0.20] - 2022/TBD ### 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)) ### 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)) From 8ee274a92726340795022cf2d8f95e3f251cd12a Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 14:54:25 -0500 Subject: [PATCH 63/78] 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 64/78] 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 5ab224d17e8ed810df19925a677decd25c2ff53c Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 15:18:10 -0500 Subject: [PATCH 65/78] Appease the linter --- app/classes/shared/helpers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index 3dbd1ea3..46d634d6 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -966,7 +966,8 @@ class Helpers: dpath = os.path.join(folder, filename) if os.path.isdir(rel): if filename not in self.ignored_names: - output += f"""
    • + output += f"""
    • \n
      + output += f"""
    • \n
      Date: Sun, 29 Jan 2023 15:20:27 -0500 Subject: [PATCH 66/78] Appease the linter AGAIN --- app/classes/shared/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index 46d634d6..cd7ae4fe 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -966,7 +966,7 @@ class Helpers: dpath = os.path.join(folder, filename) if os.path.isdir(rel): if filename not in self.ignored_names: - output += f"""
    • \n
      @@ -1008,7 +1008,7 @@ class Helpers: rel = os.path.join(folder, raw_filename) if os.path.isdir(rel): if filename not in self.ignored_names: - output += f"""
    • \n
      From f60d6424d94059c5eb9044284d08bc2442d6cc73 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Sun, 29 Jan 2023 20:37:03 +0000 Subject: [PATCH 67/78] Update changelog !541 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb3da326..f2de3836 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ - Rework `/public` Route. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/538)) ### Tweaks - Hide stats DB directory from files tree. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/530)) +- Make it so file tree doesn't reload on upload/delete. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/541)) +- Add upload completed feedback to file upload. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/541)) - Added further login screen customisation settings. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/531)) - Set backup filename to use same time as schedule. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/534)) - Move Schedules to from DB to Queue Datatype. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/535)) From 2d9529ba0c3bf13aae7a8fa2ab5b4a629b1f7e56 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Jan 2023 16:54:02 -0500 Subject: [PATCH 68/78] 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 69/78] 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 70/78] 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 71/78] 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 72/78] 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 73/78] 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 74/78] 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 75/78] 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 76/78] 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)) From d66521c6a4e1deb22c4d8b22f424a5069ed11288 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Sun, 29 Jan 2023 23:40:05 +0000 Subject: [PATCH 77/78] Update changelog !540 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59cbd693..c93ef83e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Set backup filename to use same time as schedule. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/534)) - Move Schedules to from DB to Queue Datatype. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/535)) - Move raknet icon failure to a debug log. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/537)) +- Add Default redirection to Dashboard if the user is connected. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/540)) ### Lang TBD

      From 157160724e1f6c27e16c83a4874e61f5ee5b1c06 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Sun, 29 Jan 2023 23:49:59 +0000 Subject: [PATCH 78/78] Close v4.0.20 changelog --- CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c93ef83e..4b2417a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -## --- [4.0.20] - 2022/TBD +## --- [4.0.20] - 2022/01/29 ### 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)) @@ -17,8 +17,6 @@ - Move Schedules to from DB to Queue Datatype. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/535)) - Move raknet icon failure to a debug log. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/537)) - Add Default redirection to Dashboard if the user is connected. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/540)) -### Lang -TBD

      ## --- [4.0.19] - 2022/01/07