From 7657b77785413e385603323bef275e4e3a0821de Mon Sep 17 00:00:00 2001 From: Phillip Tarrant Date: Mon, 21 Sep 2020 22:01:16 -0400 Subject: [PATCH 1/9] adding virtual console ajax to actually send the command --- app/classes/web/ajax_handler.py | 21 +++++++++++++++++++ app/config/serverjars.json | 2 +- app/frontend/templates/panel/server_term.html | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py index 0591ecf7..1b422848 100644 --- a/app/classes/web/ajax_handler.py +++ b/app/classes/web/ajax_handler.py @@ -74,4 +74,25 @@ class AjaxHandler(BaseHandler): logger.warning("Skipping Log Line due to error: {}".format(e)) pass + def post(self, page): + user_data = json.loads(self.get_secure_cookie("user_data")) + error = bleach.clean(self.get_argument('error', "WTF Error!")) + + page_data = { + 'user_data': user_data, + 'error': error + } + + if page == "send_command": + command = bleach.clean(self.get_body_argument('command', default=None, strip=True)) + server_id = bleach.clean(self.get_argument('id')) + + if server_id is None: + logger.warning("Server ID not found in send_command ajax call") + + srv_obj = controller.get_server_obj(server_id) + + if command: + if srv_obj.check_running(): + srv_obj.send_command(command) diff --git a/app/config/serverjars.json b/app/config/serverjars.json index 45343a2c..736bef8a 100644 --- a/app/config/serverjars.json +++ b/app/config/serverjars.json @@ -1,5 +1,5 @@ { - "last_refreshed": "09/17/2020, 18:43:17", + "last_refreshed": "09/21/2020, 21:59:31", "servers": { "nukkitx": [ "1.14" diff --git a/app/frontend/templates/panel/server_term.html b/app/frontend/templates/panel/server_term.html index 95283193..488e08bb 100644 --- a/app/frontend/templates/panel/server_term.html +++ b/app/frontend/templates/panel/server_term.html @@ -75,6 +75,7 @@
+
From c896a12b17acbb02e3c814f1eaf97acefca6644d Mon Sep 17 00:00:00 2001 From: Phillip Tarrant Date: Tue, 22 Sep 2020 12:11:16 -0400 Subject: [PATCH 2/9] Added server_ip to DB, also removed max_stats_count as it's not needed --- app/classes/minecraft/stats.py | 2 +- app/classes/shared/models.py | 1 + app/classes/web/panel_handler.py | 2 ++ app/frontend/templates/panel/server_config.html | 7 ++++++- config.json | 1 - 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index fc983fe7..305239e8 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -250,7 +250,7 @@ class Stats: Server_Stats.version: server.get("version", False) }).execute() - # delete 1 week old data + # delete old data max_age = helper.get_setting("history_max_age") now = datetime.datetime.now() last_week = now.day - max_age diff --git a/app/classes/shared/models.py b/app/classes/shared/models.py index 12bbfd11..ef4e20c5 100644 --- a/app/classes/shared/models.py +++ b/app/classes/shared/models.py @@ -83,6 +83,7 @@ class Servers(BaseModel): auto_start_delay = IntegerField(default=10) crash_detection = BooleanField(default=0) stop_command = CharField(default="stop") + server_ip = CharField(default="127.0.0.1") server_port = IntegerField(default=25565) class Meta: diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index e4a3460a..977c51ad 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -128,6 +128,7 @@ class PanelHandler(BaseHandler): execution_command = self.get_argument('execution_command', None) stop_command = self.get_argument('stop_command', None) auto_start_delay = self.get_argument('auto_start_delay', '10') + server_ip = self.get_argument('server_ip', None) server_port = self.get_argument('server_port', None) auto_start = int(float(self.get_argument('auto_start', '0'))) crash_detection = int(float(self.get_argument('crash_detection', '0'))) @@ -152,6 +153,7 @@ class PanelHandler(BaseHandler): Servers.execution_command: execution_command, Servers.stop_command: stop_command, Servers.auto_start_delay: auto_start_delay, + Servers.server_ip: server_ip, Servers.server_port: server_port, Servers.auto_start: auto_start, Servers.crash_detection: crash_detection, diff --git a/app/frontend/templates/panel/server_config.html b/app/frontend/templates/panel/server_config.html index a14732fb..39d6d0b1 100644 --- a/app/frontend/templates/panel/server_config.html +++ b/app/frontend/templates/panel/server_config.html @@ -103,7 +103,12 @@
- + + +
+ +
+
diff --git a/config.json b/config.json index a5f43e5e..f6b866f3 100644 --- a/config.json +++ b/config.json @@ -8,7 +8,6 @@ "show_errors": true, "history_max_age": 7, "stats_update_frequency": 30, - "max_stats_count": 1000, "delete_default_json": false, "show_contribute_link": true, "virtual_terminal_lines": 10, From 2eeee9d6c42ad272424a42ff894281bce5596fc3 Mon Sep 17 00:00:00 2001 From: Phillip Tarrant Date: Tue, 22 Sep 2020 15:00:05 -0400 Subject: [PATCH 3/9] fixed bug where tables/default settings were firing each restart --- app/classes/shared/models.py | 12 ++++++++---- main.py | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/classes/shared/models.py b/app/classes/shared/models.py index ef4e20c5..33a12b98 100644 --- a/app/classes/shared/models.py +++ b/app/classes/shared/models.py @@ -43,6 +43,7 @@ class Users(BaseModel): class Meta: table_name = "users" + class Audit_Log(BaseModel): audit_id = AutoField() created = DateTimeField(default=datetime.datetime.now) @@ -53,7 +54,6 @@ class Audit_Log(BaseModel): log_msg = TextField(default='') - class Host_Stats(BaseModel): time = DateTimeField(default=datetime.datetime.now) boot_time = CharField(default="") @@ -167,7 +167,8 @@ class db_builder: @staticmethod def default_settings(): - + logger.info("Fresh Install Detected - Creating Default Settings") + console.info("Fresh Install Detected - Creating Default Settings") default_data = helper.find_default_password() username = default_data.get("username", 'admin') @@ -185,9 +186,12 @@ class db_builder: @staticmethod def is_fresh_install(): - if helper.check_file_exists(helper.db_path): + try: + user = Users.get_by_id(1) return False - return True + except: + return True + pass class db_shortcuts: diff --git a/main.py b/main.py index 388f08ab..108abefc 100644 --- a/main.py +++ b/main.py @@ -82,7 +82,9 @@ if __name__ == '__main__': helper.create_session_file(ignore=args.ignore) # do our installer stuff - if not installer.is_fresh_install(): + fresh_install = installer.is_fresh_install() + + if fresh_install: installer.create_tables() installer.default_settings() From 8e2010af75be3108efa65b03a805408cb29a20ec Mon Sep 17 00:00:00 2001 From: Phillip Tarrant Date: Tue, 22 Sep 2020 16:17:17 -0400 Subject: [PATCH 4/9] added version to bottom of pages --- app/classes/web/server_handler.py | 2 +- app/frontend/templates/footer.html | 7 +++++-- app/frontend/templates/notify.html | 11 +++-------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/classes/web/server_handler.py b/app/classes/web/server_handler.py index 08436cad..f368fec1 100644 --- a/app/classes/web/server_handler.py +++ b/app/classes/web/server_handler.py @@ -36,7 +36,7 @@ class ServerHandler(BaseHandler): defined_servers = controller.list_defined_servers() page_data = { - 'version_data': "version_data_here", + 'version_data': helper.get_version_string(), 'user_data': user_data, 'server_stats': { 'total': len(controller.list_defined_servers()), diff --git a/app/frontend/templates/footer.html b/app/frontend/templates/footer.html index 03c4cfab..fe371681 100644 --- a/app/frontend/templates/footer.html +++ b/app/frontend/templates/footer.html @@ -1,8 +1,11 @@
-
- Copyright © 2020 RMDC. All rights reserved. +
+ + Copyright © 2020 Crafty Controller. All rights reserved. + Version: {{ data['version_data'] }}
+
\ No newline at end of file diff --git a/app/frontend/templates/notify.html b/app/frontend/templates/notify.html index 0c63b37e..3d29b290 100644 --- a/app/frontend/templates/notify.html +++ b/app/frontend/templates/notify.html @@ -2,13 +2,10 @@ From 09a74ef188c17ff54478696c92e0e583fd0aa61f Mon Sep 17 00:00:00 2001 From: Phillip Tarrant Date: Tue, 22 Sep 2020 18:23:14 -0400 Subject: [PATCH 5/9] polishing menu, removing a few things, modified the admin profile some --- app/frontend/templates/base.html | 25 +---------------- app/frontend/templates/main_menu.html | 31 ++------------------- app/frontend/templates/panel/dashboard.html | 4 +-- 3 files changed, 5 insertions(+), 55 deletions(-) diff --git a/app/frontend/templates/base.html b/app/frontend/templates/base.html index c8f2b1fa..77715e74 100644 --- a/app/frontend/templates/base.html +++ b/app/frontend/templates/base.html @@ -44,30 +44,7 @@ - + {% include notify.html %} diff --git a/app/frontend/templates/main_menu.html b/app/frontend/templates/main_menu.html index b08fbc67..8e6b6d97 100644 --- a/app/frontend/templates/main_menu.html +++ b/app/frontend/templates/main_menu.html @@ -33,43 +33,16 @@ -