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
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()

View File

@ -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)

View File

@ -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

View File

@ -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: