From 58f6949fadcd4836fb935893fde5e5a3e890bc2c Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 8 Mar 2021 22:01:42 -0500 Subject: [PATCH 1/3] Port/ip-get patched Working issue is the socket will only work for 25565. !!CAUTION LOTS OF PRINT STATEMENTS!! --- app/classes/minecraft/mc_ping.py | 14 +++++++++++--- app/classes/minecraft/stats.py | 17 +++++++++++++---- main.py | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/classes/minecraft/mc_ping.py b/app/classes/minecraft/mc_ping.py index 9995ddd4..2d34dc71 100644 --- a/app/classes/minecraft/mc_ping.py +++ b/app/classes/minecraft/mc_ping.py @@ -72,7 +72,8 @@ class Player: # For the rest of requests see wiki.vg/Protocol -def ping(ip, port=25565): +def ping(ip, port): + print("IN PING PORT: " + str(port)) def read_var_int(): i = 0 j = 0 @@ -88,11 +89,14 @@ def ping(ip, port=25565): if not (k & 0x80): return i - sock = socket.socket() + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: - sock.connect((ip, port)) + print("SOCKET PORT: " + str(port)) + sock.connect((ip, int(port))) + except: pass + print('FALSE 1') return False try: @@ -108,8 +112,10 @@ def ping(ip, port=25565): length = read_var_int() # full packet length if length < 10: if length < 0: + print("LEN < 0 FALSE") return False else: + print("FALSE 2") return False sock.recv(1) # packet type, 0 for pings @@ -118,10 +124,12 @@ def ping(ip, port=25565): while len(data) != length: chunk = sock.recv(length - len(data)) if not chunk: + print("NOT CHUNK FALSE") return False data += chunk logger.debug("Server reports this data on ping: {}".format(data)) + print("Server reports this data on ping: {}".format(data)) return Server(json.loads(data)) finally: sock.close() diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index 2d4a4209..4c90aef2 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -165,8 +165,10 @@ class Stats: # TODO: search server properties file for possible override of 127.0.0.1 - internal_ip = server_data.get('server_ip', "127.0.0.1") - server_port = server_settings.get('server_port', "25565") + internal_ip = server_data.get('server-ip', "127.0.0.1") + server_port = server_settings.get('server-port', "25565") + + print("PORT!!!!!: " + str(server_port)) logger.debug("Pinging {} on port {}".format(internal_ip, server_port)) int_mc_ping = ping(internal_ip, int(server_port)) @@ -207,12 +209,18 @@ class Stats: p_stats = self._get_process_stats(server_obj.PID) # TODO: search server properties file for possible override of 127.0.0.1 - internal_ip = server_data.get('server_ip', "127.0.0.1") - server_port = server_settings.get('server_port', "25565") + internal_ip = server_data.get('server-ip', "127.0.0.1") + server_port = server_settings.get('server-port', "25565") + + print(str(server_port)) + + print("Pinging {} on port {}".format(internal_ip, server_port)) logger.debug("Pinging {} on port {}".format(internal_ip, server_port)) int_mc_ping = ping(internal_ip, int(server_port)) + print("PING: " + str(int_mc_ping)) + int_data = False ping_data = {} @@ -238,6 +246,7 @@ class Stats: 'desc': ping_data.get("server_description", False), 'version': ping_data.get("server_version", False) } + print("SERVER STATS LIST LEN(" + str(len(server_stats_list)) + "): ") # add this servers data to the stack server_stats_list.append(server_stats) diff --git a/main.py b/main.py index 7ef4b02f..bc538ba6 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,7 @@ def do_intro(): console.magenta(intro) -def setup_logging(debug=False): +def setup_logging(debug=True): logging_config_file = os.path.join(os.path.curdir, 'app', 'config', From 03d7cfae80eb4c281e3b438647e5bbfaff540e20 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 9 Mar 2021 16:57:45 -0500 Subject: [PATCH 2/3] Port/ip-get patched Patched super user in panel_handler Working issue is the server doesn not reload settings from DB after value changes in table. !!CAUTION LOTS OF PRINT STATEMENTS!! --- app/classes/minecraft/mc_ping.py | 11 ++--------- app/classes/minecraft/stats.py | 11 +++++------ app/classes/shared/server.py | 3 ++- app/classes/web/panel_handler.py | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app/classes/minecraft/mc_ping.py b/app/classes/minecraft/mc_ping.py index 2d34dc71..4a27d686 100644 --- a/app/classes/minecraft/mc_ping.py +++ b/app/classes/minecraft/mc_ping.py @@ -73,7 +73,6 @@ class Player: # For the rest of requests see wiki.vg/Protocol def ping(ip, port): - print("IN PING PORT: " + str(port)) def read_var_int(): i = 0 j = 0 @@ -91,12 +90,10 @@ def ping(ip, port): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: - print("SOCKET PORT: " + str(port)) - sock.connect((ip, int(port))) + sock.connect((ip, port)) - except: + except socket.error as err: pass - print('FALSE 1') return False try: @@ -112,10 +109,8 @@ def ping(ip, port): length = read_var_int() # full packet length if length < 10: if length < 0: - print("LEN < 0 FALSE") return False else: - print("FALSE 2") return False sock.recv(1) # packet type, 0 for pings @@ -124,12 +119,10 @@ def ping(ip, port): while len(data) != length: chunk = sock.recv(length - len(data)) if not chunk: - print("NOT CHUNK FALSE") return False data += chunk logger.debug("Server reports this data on ping: {}".format(data)) - print("Server reports this data on ping: {}".format(data)) return Server(json.loads(data)) finally: sock.close() diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index 4c90aef2..1b52e728 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -198,6 +198,7 @@ class Stats: # get our server object, settings and data dictionaries server_obj = s.get('server_obj', None) + server_obj.reload_server_settings() server_settings = s.get('server_settings', {}) server_data = s.get('server_data_obj', {}) @@ -212,15 +213,14 @@ class Stats: internal_ip = server_data.get('server-ip', "127.0.0.1") server_port = server_settings.get('server-port', "25565") - print(str(server_port)) - - print("Pinging {} on port {}".format(internal_ip, server_port)) + for item in server_data: + if item is not list: + print(str(item)) + print("Server IP: " + internal_ip) logger.debug("Pinging {} on port {}".format(internal_ip, server_port)) int_mc_ping = ping(internal_ip, int(server_port)) - print("PING: " + str(int_mc_ping)) - int_data = False ping_data = {} @@ -246,7 +246,6 @@ class Stats: 'desc': ping_data.get("server_description", False), 'version': ping_data.get("server_version", False) } - print("SERVER STATS LIST LEN(" + str(len(server_stats_list)) + "): ") # add this servers data to the stack server_stats_list.append(server_stats) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 6f5c27ec..2b259a8e 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -48,6 +48,8 @@ class Server: def reload_server_settings(self): server_data = db_helper.get_server_data_by_id(self.server_id) + for item in server_data: + print("ITEM: " + str(item)) self.settings = server_data def do_server_setup(self, server_data_obj): @@ -234,7 +236,6 @@ class Server: def check_running(self): running = False - # if process is None, we never tried to start if self.PID is None: return running diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 8241c7f3..99071ee3 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -324,7 +324,7 @@ class PanelHandler(BaseHandler): user_data = json.loads(self.get_secure_cookie("user_data")) exec_user = db_helper.get_user(user_data['user_id']) - if not exec_user.superuser: + if not exec_user['superuser']: self.redirect("/panel/error?error=Unauthorized access: not superuser") return False elif server_id is None: From 287d45a1bc98645f95835c7f07128c4bd82d934a Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 13 Mar 2021 09:29:05 -0500 Subject: [PATCH 3/3] Port/ip-get patched Patched super user in panel_handler --- app/classes/minecraft/stats.py | 7 ------- app/classes/shared/server.py | 2 -- 2 files changed, 9 deletions(-) diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index 1b52e728..8dc2cbd9 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -168,8 +168,6 @@ class Stats: internal_ip = server_data.get('server-ip', "127.0.0.1") server_port = server_settings.get('server-port', "25565") - print("PORT!!!!!: " + str(server_port)) - logger.debug("Pinging {} on port {}".format(internal_ip, server_port)) int_mc_ping = ping(internal_ip, int(server_port)) @@ -213,11 +211,6 @@ class Stats: internal_ip = server_data.get('server-ip', "127.0.0.1") server_port = server_settings.get('server-port', "25565") - for item in server_data: - if item is not list: - print(str(item)) - print("Server IP: " + internal_ip) - logger.debug("Pinging {} on port {}".format(internal_ip, server_port)) int_mc_ping = ping(internal_ip, int(server_port)) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 2b259a8e..4189bd22 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -48,8 +48,6 @@ class Server: def reload_server_settings(self): server_data = db_helper.get_server_data_by_id(self.server_id) - for item in server_data: - print("ITEM: " + str(item)) self.settings = server_data def do_server_setup(self, server_data_obj):