From 3974b7e8c7ee34da4b543fb350ea93109df57901 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Thu, 4 Aug 2022 19:45:44 -0400 Subject: [PATCH 01/68] poorly attempt to add "add to home" feature --- .../static/assets/images/Crafty_4-0.png | Bin 0 -> 5013 bytes app/frontend/templates/base.html | 15 ++++++++++----- app/frontend/templates/crafty.webmanifest | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 app/frontend/static/assets/images/Crafty_4-0.png create mode 100644 app/frontend/templates/crafty.webmanifest diff --git a/app/frontend/static/assets/images/Crafty_4-0.png b/app/frontend/static/assets/images/Crafty_4-0.png new file mode 100644 index 0000000000000000000000000000000000000000..d873eedc46f1f3c3d9be420e8a8e44ec015f6ced GIT binary patch literal 5013 zcmZ`-bx;&e^uM5w?(PtzLrz3E;eew-N{qr~T`_0b2H~V7u?aZ6^_OloRJq-#nRx$tpK%t3%KgRQf|0W3$o^GkHHR2h8 z%Ol-K06^_K$dw%-e$DNGc&rNmJQoB2P%i<13%m%m4FCj60suR<0DwX|0Knvv-E63c zR}k52Yrp}w|Bbx1;$*ypI6zZZjrb=C0TT~f1!Btx0HDp#gg-Jy{@D8v>cQR@-lvRh zIor4tFqi#B{I|wYJJxCLv8a4%6l-mAqZeJh530d;?S_W?1-)99QUXA4oYD0g=pUaL zD?P}a4Cf%UHWrsSeziRu z(SU04rnSgmm#;^>U&x%Wb+F3RyGfvc0RS*g3^#&PUs13He=tGco~8{a_g! zfe#~;w3WD(konS#}VqoN0jSt0X`@o0EN63fn8*x40r-jw6NRKM1Gb%@S+ z0BrzDkcF5!>C9eRA}HXB8p+E1`l97aGeLcS`y5#q>ABd-#q+UpbE7&O1b2qIC93-y zQ&PmX2O-X*Lz0|}3`#Y0dU5F5ii7k4FNoQJj$$fh&2P*%xDNf;99%8A1J>(G%`NvHCIp&whM6d%J1)0RL@@jx&HP z_;WZ)%>Ihm&8X0^f;OLw0jdE@n;;9}^BK}B(wYamtgb3T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5<*#21 z&JIMm(J-R9{ZcK~jiYaHhW`@^L^CE7iPxiK1MR+b-_4SBe+Q)BQF`;UtOp=%$D~4M zMZTgk8~qK=1ZIY`P-kx21AsyV?y_d~fIhUVS6VSC2N+4bhj4$^4Ok)^jkcoJ-8e*r zfCX~+{(~;}d(j0%lEkes@d)>_b%H}vH_=`0i$H554hg`PHb{Yzoumbx*)IuHgdlsj z4JwD}yYU0^Aweb}m}hj71X=uv+A@4LIcX)A2O3!h{*<`w&?=Yq zSP8|Ab&59$28;riRS2`vo^YY=9*67b#!JcFS2sJuu|NA1A@Ack`}x~T6{2(ZsjRf% zCS=}mb4>wG9(C4Ph55->47f_Ztxcn&5_Ldpotu)Z@DF}m0tZA}-5t@0q_~nfOv6oS zt)ZnskpjF5Xfn>lct%645v&K)j(N`K^2~1&!^+^F^N%;F#A`R)R>+`d=}{(0BKU^p z91?c)9;-wRgVn&{LMVB(E{>ZbgWb@GZymP`dI8pnr{ofK578nRZEi%siw$L%Cvnc) zG(jWyod5W?bH*@Y?5RLGHoa^jNcVSiEGvC@9DNJUe%1{RT=?@* zH}p|7FbHTv$Vu?L%Zo;r+heNY%|SkqhD%;uJC;4rlEMbziK_;^16-m{Yb+61QSlw8 z?PXLSiUu~#n@w9jv3Jf3+9uiua)S1WrmLsrWCIg5#1=1v4+*s3UJpBkYj@;>6V-kI z7v9wA%o`jPTu86GNAenib6pI;AC)!4GND6csZ{i-}VobU`FEh#N6 zCJ7ajlr@%?QIL^QkiK_UQc^)u@^H4v^nW>cdONx~hy4Ez=xE>$-T|PgrU$Q5v5ov6 D3&c&V literal 0 HcmV?d00001 diff --git a/app/frontend/templates/base.html b/app/frontend/templates/base.html index 4133dfac..f13fc2f4 100755 --- a/app/frontend/templates/base.html +++ b/app/frontend/templates/base.html @@ -15,9 +15,14 @@ + href="https://cdn.datatables.net/v/bs4/dt-1.10.22/fh-3.1.7/r-2.2.6/sc-2.0.3/sp-1.2.2/datatables.min.css" /> + + + + + @@ -72,7 +77,7 @@ {% include notify.html %} @@ -163,7 +168,7 @@ + src="https://cdn.datatables.net/v/bs4/dt-1.10.22/fh-3.1.7/r-2.2.6/sc-2.0.3/sp-1.2.2/datatables.min.js"> @@ -191,7 +196,7 @@ $.extend($.fn.dataTable.defaults, { // {{ '\nlanguage:' }} {% raw translate('datatables', 'i18n', data['lang']) %} - }) + }) //used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security function getCookie(name) { @@ -525,4 +530,4 @@ - + \ No newline at end of file diff --git a/app/frontend/templates/crafty.webmanifest b/app/frontend/templates/crafty.webmanifest new file mode 100644 index 00000000..c2db095c --- /dev/null +++ b/app/frontend/templates/crafty.webmanifest @@ -0,0 +1,16 @@ +{ + "background_color": "purple", + "description": "Server management control.", + "display": "fullscreen", + "icons": [ + { + "src": "../static/assets/images/Crafty_4-0.png", + "sizes": "192x192", + "type": "icon/png" + } + ], + "scope": "/", + "name": "Crafty 4", + "short_name": "Crafty", + "start_url": "/panel/dashboard" +} \ No newline at end of file From 8adcfbaf452bea807f989d7849dfab470a2e0805 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 7 Aug 2022 13:23:45 -0400 Subject: [PATCH 02/68] Updates --- app/frontend/templates/base.html | 5 ++++ app/frontend/templates/crafty.webmanifest | 34 +++++++++++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/frontend/templates/base.html b/app/frontend/templates/base.html index f13fc2f4..cdb0b5e4 100755 --- a/app/frontend/templates/base.html +++ b/app/frontend/templates/base.html @@ -20,6 +20,11 @@ + + + + + diff --git a/app/frontend/templates/crafty.webmanifest b/app/frontend/templates/crafty.webmanifest index c2db095c..06d6cafe 100644 --- a/app/frontend/templates/crafty.webmanifest +++ b/app/frontend/templates/crafty.webmanifest @@ -1,16 +1,32 @@ { - "background_color": "purple", - "description": "Server management control.", - "display": "fullscreen", + "$schema": "https://json.schemastore.org/web-manifest-combined.json", + "short_name": "Crafty", + "name": "Crafty Controller 4", "icons": [ { - "src": "../static/assets/images/Crafty_4-0.png", - "sizes": "192x192", - "type": "icon/png" + "src": "../static/images/Crafty_4-0.png", + "type": "image/png", + "sizes": "192x192" } ], + "start_url": "/public/login", + "background_color": "#3367D6", + "display": "fullscreen", "scope": "/", - "name": "Crafty 4", - "short_name": "Crafty", - "start_url": "/panel/dashboard" + "theme_color": "#3367D6", + "shortcuts": [ + { + "name": "Crafty Controller 4", + "short_name": "Crafty", + "description": "View weather information for today", + "url": "/panel/dashboard", + "icons": [ + { + "src": "../static/images/Crafty_4-0.png", + "sizes": "192x192" + } + ] + } + ], + "description": "Server Management Console/Wrapper" } \ No newline at end of file From 893d166c7224f73aa90a5a45eadd3872a6467fd0 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 8 Aug 2022 13:04:36 -0400 Subject: [PATCH 03/68] More testing --- app/frontend/templates/base.html | 2 +- app/frontend/templates/{crafty.webmanifest => crafty.json} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename app/frontend/templates/{crafty.webmanifest => crafty.json} (85%) diff --git a/app/frontend/templates/base.html b/app/frontend/templates/base.html index cdb0b5e4..a1abb058 100755 --- a/app/frontend/templates/base.html +++ b/app/frontend/templates/base.html @@ -18,7 +18,7 @@ href="https://cdn.datatables.net/v/bs4/dt-1.10.22/fh-3.1.7/r-2.2.6/sc-2.0.3/sp-1.2.2/datatables.min.css" /> - + diff --git a/app/frontend/templates/crafty.webmanifest b/app/frontend/templates/crafty.json similarity index 85% rename from app/frontend/templates/crafty.webmanifest rename to app/frontend/templates/crafty.json index 06d6cafe..ab83b913 100644 --- a/app/frontend/templates/crafty.webmanifest +++ b/app/frontend/templates/crafty.json @@ -4,7 +4,7 @@ "name": "Crafty Controller 4", "icons": [ { - "src": "../static/images/Crafty_4-0.png", + "src": "../static/assets/images/Crafty_4-0.png", "type": "image/png", "sizes": "192x192" } @@ -22,7 +22,7 @@ "url": "/panel/dashboard", "icons": [ { - "src": "../static/images/Crafty_4-0.png", + "src": "../static/assets/images/Crafty_4-0.png", "sizes": "192x192" } ] From cd475e0cf59c9587dbda49a8c5844172d9d97249 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Wed, 1 Mar 2023 13:04:51 -0500 Subject: [PATCH 04/68] Use API to send remote commands to server --- app/classes/web/ajax_handler.py | 63 +------------------ app/frontend/templates/panel/dashboard.html | 49 ++++----------- .../templates/panel/server_backup.html | 2 +- 3 files changed, 14 insertions(+), 100 deletions(-) diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py index cd1ccc04..3887a00b 100644 --- a/app/classes/web/ajax_handler.py +++ b/app/classes/web/ajax_handler.py @@ -281,73 +281,12 @@ class AjaxHandler(BaseHandler): exec_user["user_id"], server_id ) - if page == "send_command": - command = self.get_body_argument("command", default=None, strip=True) - server_id = self.get_argument("id", None) - - if server_id is None: - logger.warning("Server ID not found in send_command ajax call") - Console.warning("Server ID not found in send_command ajax call") - - srv_obj = self.controller.servers.get_server_instance_by_id(server_id) - - if command == srv_obj.settings["stop_command"]: - logger.info( - "Stop command detected as terminal input - intercepting." - + f"Starting Crafty's stop process for server with id: {server_id}" - ) - self.controller.management.send_command( - exec_user["user_id"], server_id, self.get_remote_ip(), "stop_server" - ) - command = None - elif command == "restart": - logger.info( - "Restart command detected as terminal input - intercepting." - + f"Starting Crafty's stop process for server with id: {server_id}" - ) - self.controller.management.send_command( - exec_user["user_id"], - server_id, - self.get_remote_ip(), - "restart_server", - ) - command = None - if command: - if srv_obj.check_running(): - srv_obj.send_command(command) - - self.controller.management.add_to_audit_log( - exec_user["user_id"], - f"Sent command to " - f"{self.controller.servers.get_server_friendly_name(server_id)} " - f"terminal: {command}", - server_id, - self.get_remote_ip(), - ) - - elif page == "send_order": + if page == "send_order": self.controller.users.update_server_order( exec_user["user_id"], bleach.clean(self.get_argument("order")) ) return - elif page == "backup_now": - server_id = self.get_argument("id", None) - if server_id is None: - logger.error("Server ID is none. Canceling backup!") - return - - server = self.controller.servers.get_server_instance_by_id(server_id) - self.controller.management.add_to_audit_log_raw( - self.controller.users.get_user_by_id(exec_user["user_id"])["username"], - exec_user["user_id"], - server_id, - f"Backup now executed for server {server_id} ", - source_ip=self.get_remote_ip(), - ) - - server.backup_server() - elif page == "select_photo": if exec_user["superuser"]: photo = urllib.parse.unquote(self.get_argument("photo", "")) diff --git a/app/frontend/templates/panel/dashboard.html b/app/frontend/templates/panel/dashboard.html index 981a4163..a1c25231 100644 --- a/app/frontend/templates/panel/dashboard.html +++ b/app/frontend/templates/panel/dashboard.html @@ -645,10 +645,13 @@ $.ajax({ type: "POST", headers: { 'X-XSRFToken': token }, - url: '/server/command?command=' + command + '&id=' + server_id, + url: `/api/v2/servers/${server_id}/action/${command}`, success: function (data) { console.log("got response:"); console.log(data); + if (command === "clone_server" && data.status === "ok") { + window.location.reload(); + } /*setTimeout(function () { if (command != 'start_server') { location.reload(); @@ -703,24 +706,6 @@ document.querySelector('.dynamicMsg').appendChild(parentEl); } - function send_kill(server_id) { - /* this getCookie function is in base.html */ - const token = getCookie("_xsrf"); - - $.ajax({ - type: "POST", - headers: { 'X-XSRFToken': token }, - url: '/ajax/kill?id=' + server_id, - success: function (data) { - console.log("got response:"); - console.log(data); - /*setTimeout(function () { - location.reload(); - }, 10000);*/ - } - }); - } - function update_one_server_status(server) { /* Mobile view update */ server_cpu = document.getElementById('server_cpu_' + server.id); @@ -899,17 +884,11 @@ }, callback: function (result) { if (result) { - send_kill(server_id); + send_command(server_id, "kill_server"); let dialog = bootbox.dialog({ title: '{% raw translate("dashboard", "killing", data["lang"]) %}', message: '

Loading...

' }); - - dialog.init(function () { - setTimeout(function () { - location.reload(); - }, 15000); - }); } } }); @@ -998,7 +977,13 @@ }, callback: function (result) { if (result) { - cloneServer(server_id); + send_command(server_id, 'clone_server'); + bootbox.dialog({ + backdrop: true, + title: '{% raw translate("dashboard", "sendingCommand", data["lang"]) %}', + message: '
  {% raw translate("dashboard", "bePatientClone", data["lang"]) %}
', + closeButton: false, + }); } } @@ -1006,16 +991,6 @@ }); }); - - function cloneServer(server_id) { - send_command(server_id, 'clone_server'); - bootbox.dialog({ - backdrop: true, - title: '{% raw translate("dashboard", "sendingCommand", data["lang"]) %}', - message: '
  {% raw translate("dashboard", "bePatientClone", data["lang"]) %}
', - closeButton: false, - }); - } diff --git a/app/frontend/templates/panel/server_backup.html b/app/frontend/templates/panel/server_backup.html index ab9b4f2e..1cb8f087 100644 --- a/app/frontend/templates/panel/server_backup.html +++ b/app/frontend/templates/panel/server_backup.html @@ -326,7 +326,7 @@ $.ajax({ type: "POST", headers: { 'X-XSRFToken': token }, - url: '/ajax/backup_now?id=' + server_id, + url: `/api/v2/servers/${server_id}/action/backup_server`, success: function (data) { return; }, From c0bca38319d54503859803b8af956ce3fa8c27c5 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Wed, 1 Mar 2023 13:27:06 -0500 Subject: [PATCH 05/68] Cleanup ajax a bit more --- app/classes/web/ajax_handler.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py index 3887a00b..fd8ffe4b 100644 --- a/app/classes/web/ajax_handler.py +++ b/app/classes/web/ajax_handler.py @@ -321,23 +321,6 @@ class AjaxHandler(BaseHandler): self.controller.cached_login = "login_1.jpg" return - elif page == "kill": - if not permissions["Commands"] in user_perms: - if not superuser: - self.redirect("/panel/error?error=Unauthorized access to Commands") - return - server_id = self.get_argument("id", None) - svr = self.controller.servers.get_server_instance_by_id(server_id) - try: - svr.kill() - time.sleep(5) - svr.cleanup_server_object() - svr.record_server_stats() - except Exception as e: - logger.error( - f"Could not find PID for requested termsig. Full error: {e}" - ) - return elif page == "eula": server_id = self.get_argument("id", None) svr = self.controller.servers.get_server_instance_by_id(server_id) From 1b6c7dd4787e1e4f88f91a35167b56d3aed65313 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Wed, 1 Mar 2023 13:30:21 -0500 Subject: [PATCH 06/68] Edit panel config for API --- app/frontend/templates/panel/server_config.html | 8 ++++---- app/frontend/templates/panel/server_term.html | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/frontend/templates/panel/server_config.html b/app/frontend/templates/panel/server_config.html index ed5186f9..500322ec 100644 --- a/app/frontend/templates/panel/server_config.html +++ b/app/frontend/templates/panel/server_config.html @@ -359,7 +359,7 @@ $.ajax({ type: "DELETE", headers: { 'X-XSRFToken': token }, - url: '/ajax/delete_server?id=' + serverId, + url: `/api/v2/servers/${serverId}`, data: { }, success: function (data) { @@ -373,7 +373,7 @@ $.ajax({ type: "DELETE", headers: { 'X-XSRFToken': token }, - url: '/ajax/delete_server_files?id=' + serverId, + url: `/api/v2/servers/${serverId}?files=true`, data: { }, success: function (data) { @@ -393,7 +393,7 @@ $.ajax({ type: "POST", headers: { 'X-XSRFToken': token }, - url: '/server/command?command=' + command + '&id=' + serverId, + url: `/api/v2/servers/${serverId}/action/${command}`, success: function (data) { console.log("got response:"); console.log(data); @@ -522,7 +522,7 @@ $.ajax({ type: "DELETE", headers: { 'X-XSRFToken': token }, - url: '/ajax/delete_unloaded_server?id=' + serverId, + url: `/api/v2/servers/${serverId}`, data: { }, success: function (data) { diff --git a/app/frontend/templates/panel/server_term.html b/app/frontend/templates/panel/server_term.html index 54ac127a..965d14ab 100644 --- a/app/frontend/templates/panel/server_term.html +++ b/app/frontend/templates/panel/server_term.html @@ -179,7 +179,7 @@ $.ajax({ type: "POST", headers: { 'X-XSRFToken': token }, - url: '/server/command?command=' + command + '&id=' + serverId, + url: `/api/v2/servers/${serverId}/action/${command}`, success: function (data) { console.log("got response:"); console.log(data); From c51d94023442cd389104b104318ca5f792e39996 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Wed, 1 Mar 2023 14:38:14 -0500 Subject: [PATCH 07/68] Allow unloaded servers to be deleted API --- app/classes/web/routes/api/servers/server/index.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/classes/web/routes/api/servers/server/index.py b/app/classes/web/routes/api/servers/server/index.py index 3d5e3e2f..1d68b2e8 100644 --- a/app/classes/web/routes/api/servers/server/index.py +++ b/app/classes/web/routes/api/servers/server/index.py @@ -134,7 +134,15 @@ class ApiServersServerIndexHandler(BaseApiHandler): ) self.tasks_manager.remove_all_server_tasks(server_id) - self.controller.remove_server(server_id, remove_files) + failed = False + for item in self.controller.servers.failed_servers[:]: + if item["server_id"] == int(server_id): + self.controller.servers.failed_servers.remove(item) + + if failed: + self.controller.remove_unloaded_server(server_id) + else: + self.controller.remove_server(server_id, remove_files) self.controller.management.add_to_audit_log( auth_data[4]["user_id"], From ec1076fbce753f39e97e72310ff92914d284ae2a Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Wed, 1 Mar 2023 14:40:02 -0500 Subject: [PATCH 08/68] Cleanup ajax handler --- app/classes/web/ajax_handler.py | 78 --------------------------------- 1 file changed, 78 deletions(-) diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py index fd8ffe4b..750badd3 100644 --- a/app/classes/web/ajax_handler.py +++ b/app/classes/web/ajax_handler.py @@ -590,84 +590,6 @@ class AjaxHandler(BaseHandler): ): os.remove(file_path) - elif page == "delete_server": - if not permissions["Config"] in user_perms: - if not superuser: - self.redirect("/panel/error?error=Unauthorized access to Config") - return - server_id = self.get_argument("id", None) - logger.info( - f"Removing server from panel for server: " - f"{self.controller.servers.get_server_friendly_name(server_id)}" - ) - - server_data = self.controller.servers.get_server_data(server_id) - server_name = server_data["server_name"] - - self.controller.management.add_to_audit_log( - exec_user["user_id"], - f"Deleted server {server_id} named {server_name}", - server_id, - self.get_remote_ip(), - ) - - self.tasks_manager.remove_all_server_tasks(server_id) - self.controller.remove_server(server_id, False) - - elif page == "delete_server_files": - if not permissions["Config"] in user_perms: - if not superuser: - self.redirect("/panel/error?error=Unauthorized access to Config") - return - server_id = self.get_argument("id", None) - logger.info( - f"Removing server and all associated files for server: " - f"{self.controller.servers.get_server_friendly_name(server_id)}" - ) - - server_data = self.controller.servers.get_server_data(server_id) - server_name = server_data["server_name"] - - self.controller.management.add_to_audit_log( - exec_user["user_id"], - f"Deleted server {server_id} named {server_name}", - server_id, - self.get_remote_ip(), - ) - - for server in self.controller.servers.failed_servers: - if server["server_id"] == int(server_id): - return - self.tasks_manager.remove_all_server_tasks(server_id) - self.controller.remove_server(server_id, True) - - elif page == "delete_unloaded_server": - if not permissions["Config"] in user_perms: - if not superuser: - self.redirect("/panel/error?error=Unauthorized access to Config") - return - server_id = self.get_argument("id", None) - logger.info( - f"Removing server and all associated files for server: " - f"{self.controller.servers.get_server_friendly_name(server_id)}" - ) - - server_data = self.controller.servers.get_server_data_by_id(server_id) - server_name = server_data["server_name"] - - self.controller.management.add_to_audit_log( - exec_user["user_id"], - f"Deleted server {server_id} named {server_name}", - server_id, - self.get_remote_ip(), - ) - - self.tasks_manager.remove_all_server_tasks(server_id) - for item in self.controller.servers.failed_servers[:]: - if item["server_id"] == int(server_id): - self.controller.servers.failed_servers.remove(item) - self.controller.remove_unloaded_server(server_id) - def check_server_id(self, server_id, page_name): if server_id is None: logger.warning( From c0381da880a3da0963d1f5b4266bdd2c39853223 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Wed, 1 Mar 2023 14:59:30 -0500 Subject: [PATCH 09/68] Fix bug with unloaded server delete --- app/classes/web/routes/api/servers/server/index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/classes/web/routes/api/servers/server/index.py b/app/classes/web/routes/api/servers/server/index.py index 1d68b2e8..a3623beb 100644 --- a/app/classes/web/routes/api/servers/server/index.py +++ b/app/classes/web/routes/api/servers/server/index.py @@ -138,6 +138,7 @@ class ApiServersServerIndexHandler(BaseApiHandler): for item in self.controller.servers.failed_servers[:]: if item["server_id"] == int(server_id): self.controller.servers.failed_servers.remove(item) + failed = True if failed: self.controller.remove_unloaded_server(server_id) From d473a6ccf408feba499ff8fc0482e8ec98f29c17 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Wed, 1 Mar 2023 15:25:28 -0500 Subject: [PATCH 10/68] Add server order to api call --- app/classes/controllers/users_controller.py | 1 + app/frontend/templates/panel/dashboard.html | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/classes/controllers/users_controller.py b/app/classes/controllers/users_controller.py index b9c019e8..667e01b4 100644 --- a/app/classes/controllers/users_controller.py +++ b/app/classes/controllers/users_controller.py @@ -89,6 +89,7 @@ class UsersController: }, }, "hints": {"type": "boolean"}, + "server_order": {"type": "string"}, } # ********************************************************************************** diff --git a/app/frontend/templates/panel/dashboard.html b/app/frontend/templates/panel/dashboard.html index a1c25231..f781cf7a 100644 --- a/app/frontend/templates/panel/dashboard.html +++ b/app/frontend/templates/panel/dashboard.html @@ -1042,12 +1042,12 @@ const token = getCookie("_xsrf") $.ajax({ - type: "POST", + type: "PATCH", headers: { 'X-XSRFToken': token }, - url: '/ajax/send_order?order=' + id_string, - data: { - order: id_string, - }, + url: `/api/v2/users/@me`, + data: JSON.stringify({ + server_order: id_string, + }), success: function (data) { console.log("got response:"); console.log(data); From 81e4e7e450208111214c25ab77b1f7c3ca54052b Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Thu, 2 Mar 2023 13:24:07 -0500 Subject: [PATCH 11/68] Fix command sends to server --- .../panel/server_admin_controls.html | 34 +++++++++++-------- app/frontend/templates/panel/server_term.html | 4 +-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/frontend/templates/panel/server_admin_controls.html b/app/frontend/templates/panel/server_admin_controls.html index 02e28356..ff7ef83d 100644 --- a/app/frontend/templates/panel/server_admin_controls.html +++ b/app/frontend/templates/panel/server_admin_controls.html @@ -14,7 +14,8 @@
-