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!!
This commit is contained in:
Andrew 2021-03-09 16:57:45 -05:00
parent 58f6949fad
commit 03d7cfae80
4 changed files with 10 additions and 17 deletions

View File

@ -73,7 +73,6 @@ class Player:
# For the rest of requests see wiki.vg/Protocol # For the rest of requests see wiki.vg/Protocol
def ping(ip, port): def ping(ip, port):
print("IN PING PORT: " + str(port))
def read_var_int(): def read_var_int():
i = 0 i = 0
j = 0 j = 0
@ -91,12 +90,10 @@ def ping(ip, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: try:
print("SOCKET PORT: " + str(port)) sock.connect((ip, port))
sock.connect((ip, int(port)))
except: except socket.error as err:
pass pass
print('FALSE 1')
return False return False
try: try:
@ -112,10 +109,8 @@ def ping(ip, port):
length = read_var_int() # full packet length length = read_var_int() # full packet length
if length < 10: if length < 10:
if length < 0: if length < 0:
print("LEN < 0 FALSE")
return False return False
else: else:
print("FALSE 2")
return False return False
sock.recv(1) # packet type, 0 for pings sock.recv(1) # packet type, 0 for pings
@ -124,12 +119,10 @@ def ping(ip, port):
while len(data) != length: while len(data) != length:
chunk = sock.recv(length - len(data)) chunk = sock.recv(length - len(data))
if not chunk: if not chunk:
print("NOT CHUNK FALSE")
return False return False
data += chunk data += chunk
logger.debug("Server reports this data on ping: {}".format(data)) logger.debug("Server reports this data on ping: {}".format(data))
print("Server reports this data on ping: {}".format(data))
return Server(json.loads(data)) return Server(json.loads(data))
finally: finally:
sock.close() sock.close()

View File

@ -198,6 +198,7 @@ class Stats:
# get our server object, settings and data dictionaries # get our server object, settings and data dictionaries
server_obj = s.get('server_obj', None) server_obj = s.get('server_obj', None)
server_obj.reload_server_settings()
server_settings = s.get('server_settings', {}) server_settings = s.get('server_settings', {})
server_data = s.get('server_data_obj', {}) server_data = s.get('server_data_obj', {})
@ -212,15 +213,14 @@ class Stats:
internal_ip = server_data.get('server-ip', "127.0.0.1") internal_ip = server_data.get('server-ip', "127.0.0.1")
server_port = server_settings.get('server-port', "25565") server_port = server_settings.get('server-port', "25565")
print(str(server_port)) for item in server_data:
if item is not list:
print("Pinging {} on port {}".format(internal_ip, server_port)) print(str(item))
print("Server IP: " + internal_ip)
logger.debug("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)) int_mc_ping = ping(internal_ip, int(server_port))
print("PING: " + str(int_mc_ping))
int_data = False int_data = False
ping_data = {} ping_data = {}
@ -246,7 +246,6 @@ class Stats:
'desc': ping_data.get("server_description", False), 'desc': ping_data.get("server_description", False),
'version': ping_data.get("server_version", 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 # add this servers data to the stack
server_stats_list.append(server_stats) server_stats_list.append(server_stats)

View File

@ -48,6 +48,8 @@ class Server:
def reload_server_settings(self): def reload_server_settings(self):
server_data = db_helper.get_server_data_by_id(self.server_id) 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 self.settings = server_data
def do_server_setup(self, server_data_obj): def do_server_setup(self, server_data_obj):
@ -234,7 +236,6 @@ class Server:
def check_running(self): def check_running(self):
running = False running = False
# if process is None, we never tried to start # if process is None, we never tried to start
if self.PID is None: if self.PID is None:
return running return running

View File

@ -324,7 +324,7 @@ class PanelHandler(BaseHandler):
user_data = json.loads(self.get_secure_cookie("user_data")) user_data = json.loads(self.get_secure_cookie("user_data"))
exec_user = db_helper.get_user(user_data['user_id']) 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") self.redirect("/panel/error?error=Unauthorized access: not superuser")
return False return False
elif server_id is None: elif server_id is None: