HUGE WebUI overhaul

- Removed ugly styles in header
- Properly implemented Bootstrap's NavBar
- Added username to session
This commit is contained in:
Dniel97
2023-09-09 00:36:22 +02:00
parent 08927db100
commit c51103aaf5
11 changed files with 380 additions and 257 deletions

View File

@@ -18,22 +18,26 @@ from core.data import Data
class IUserSession(Interface):
userId = Attribute("User's ID")
user_id = Attribute("User's ID")
username = Attribute("User's username")
current_ip = Attribute("User's current ip address")
permissions = Attribute("User's permission level")
class PermissionOffset(Enum):
USER = 0 # Regular user
USERMOD = 1 # Can moderate other users
ACMOD = 2 # Can add arcades and cabs
SYSADMIN = 3 # Can change settings
USER = 0 # Regular user
USERMOD = 1 # Can moderate other users
ACMOD = 2 # Can add arcades and cabs
SYSADMIN = 3 # Can change settings
# 4 - 6 reserved for future use
OWNER = 7 # Can do anything
OWNER = 7 # Can do anything
@implementer(IUserSession)
class UserSession(object):
def __init__(self, session):
self.userId = 0
self.user_id = 0
self.username = None
self.current_ip = "0.0.0.0"
self.permissions = 0
@@ -106,6 +110,7 @@ class FrontendServlet(resource.Resource):
server_name=self.config.server.name,
title=self.config.server.name,
game_list=self.game_list,
active_page="/",
sesh=vars(IUserSession(request.getSession())),
).encode("utf-16")
@@ -134,7 +139,7 @@ class FE_Gate(FE_Base):
sesh = request.getSession()
usr_sesh = IUserSession(sesh)
if usr_sesh.userId > 0:
if usr_sesh.user_id > 0:
return redirectTo(b"/user", request)
if uri.startswith("/gate/create"):
@@ -153,6 +158,7 @@ class FE_Gate(FE_Base):
return template.render(
title=f"{self.core_config.server.name} | Login Gate",
error=err,
active_page="gate",
sesh=vars(usr_sesh),
).encode("utf-16")
@@ -161,7 +167,7 @@ class FE_Gate(FE_Base):
ip = Utils.get_ip_addr(request)
if uri == "/gate/gate.login":
access_code: str = request.args[b"access_code"][0].decode()
access_code: str = request.args[b"access-code"][0].decode()
passwd: bytes = request.args[b"passwd"][0]
if passwd == b"":
passwd = None
@@ -187,9 +193,10 @@ class FE_Gate(FE_Base):
sesh = request.getSession()
usr_sesh = IUserSession(sesh)
usr_sesh.userId = uid
usr_sesh.user_id = uid
usr_sesh.username = user["username"]
usr_sesh.current_ip = ip
usr_sesh.permissions = user['permissions']
usr_sesh.permissions = user["permissions"]
return redirectTo(b"/user", request)
@@ -228,20 +235,23 @@ class FE_Gate(FE_Base):
card = self.data.card.get_card_by_access_code(ac)
if card is None:
return redirectTo(b"/gate?e=1", request)
user = self.data.user.get_user(card['user'])
user = self.data.user.get_user(card["user"])
if user is None:
self.logger.warning(f"Card {ac} exists with no/invalid associated user ID {card['user']}")
self.logger.warning(
f"Card {ac} exists with no/invalid associated user ID {card['user']}"
)
return redirectTo(b"/gate?e=0", request)
if user['password'] is not None:
if user["password"] is not None:
return redirectTo(b"/gate?e=1", request)
template = self.environment.get_template("core/frontend/gate/create.jinja")
return template.render(
title=f"{self.core_config.server.name} | Create User",
code=ac,
sesh={"userId": 0, "permissions": 0},
active_page="gate",
sesh={"user_id": 0, "permissions": 0},
).encode("utf-16")
@@ -252,48 +262,51 @@ class FE_User(FE_Base):
sesh: Session = request.getSession()
usr_sesh = IUserSession(sesh)
if usr_sesh.userId == 0:
if usr_sesh.user_id == 0:
return redirectTo(b"/gate", request)
m = re.match("\/user\/(\d*)", uri)
if m is not None:
if m is not None:
usrid = m.group(1)
if usr_sesh.permissions < 1 << PermissionOffset.USERMOD.value or not usrid == usr_sesh.userId:
if (
usr_sesh.permissions < 1 << PermissionOffset.USERMOD.value
or not usrid == usr_sesh.user_id
):
return redirectTo(b"/user", request)
else:
usrid = usr_sesh.userId
usrid = usr_sesh.user_id
user = self.data.user.get_user(usrid)
if user is None:
return redirectTo(b"/user", request)
cards = self.data.card.get_user_cards(usrid)
arcades = self.data.arcade.get_arcades_managed_by_user(usrid)
card_data = []
arcade_data = []
for c in cards:
if c['is_locked']:
status = 'Locked'
elif c['is_banned']:
status = 'Banned'
for i, c in enumerate(cards):
if c["is_locked"]:
status = "Locked"
elif c["is_banned"]:
status = "Banned"
else:
status = 'Active'
card_data.append({'access_code': c['access_code'], 'status': status})
for a in arcades:
arcade_data.append({'id': a['id'], 'name': a['name']})
status = "Active"
card_data.append({"index": i+1, "access_code": c["access_code"], "status": status})
for i, a in enumerate(arcades):
arcade_data.append({"index": i+1, "id": a["id"], "name": a["name"]})
return template.render(
title=f"{self.core_config.server.name} | Account",
sesh=vars(usr_sesh),
cards=card_data,
username=user['username'],
arcades=arcade_data
title=f"{self.core_config.server.name} | Account",
sesh=vars(usr_sesh),
cards=card_data,
arcades=arcade_data,
active_page="user",
).encode("utf-16")
def render_POST(self, request: Request):
@@ -310,11 +323,16 @@ class FE_System(FE_Base):
sesh: Session = request.getSession()
usr_sesh = IUserSession(sesh)
if usr_sesh.userId == 0 or usr_sesh.permissions < 1 << PermissionOffset.USERMOD.value:
if (
usr_sesh.user_id == 0
or usr_sesh.permissions < 1 << PermissionOffset.USERMOD.value
):
return redirectTo(b"/gate", request)
if uri.startswith("/sys/lookup.user?"):
uri_parse = parse.parse_qs(uri.replace("/sys/lookup.user?", "")) # lop off the first bit
uri_parse = parse.parse_qs(
uri.replace("/sys/lookup.user?", "")
) # lop off the first bit
uid_search = uri_parse.get("usrId")
email_search = uri_parse.get("usrEmail")
uname_search = uri_parse.get("usrName")
@@ -335,7 +353,9 @@ class FE_System(FE_Base):
usrlist.append(u._asdict())
elif uri.startswith("/sys/lookup.arcade?"):
uri_parse = parse.parse_qs(uri.replace("/sys/lookup.arcade?", "")) # lop off the first bit
uri_parse = parse.parse_qs(
uri.replace("/sys/lookup.arcade?", "")
) # lop off the first bit
ac_id_search = uri_parse.get("arcadeId")
ac_name_search = uri_parse.get("arcadeName")
ac_user_search = uri_parse.get("arcadeUser")
@@ -354,9 +374,11 @@ class FE_System(FE_Base):
ul = self.data.arcade.get_arcades_managed_by_user(ac_user_search[0])
for u in ul:
aclist.append(u._asdict())
elif uri.startswith("/sys/lookup.cab?"):
uri_parse = parse.parse_qs(uri.replace("/sys/lookup.cab?", "")) # lop off the first bit
uri_parse = parse.parse_qs(
uri.replace("/sys/lookup.cab?", "")
) # lop off the first bit
cab_id_search = uri_parse.get("cabId")
cab_serial_search = uri_parse.get("cabSerial")
cab_acid_search = uri_parse.get("cabAcId")
@@ -377,11 +399,12 @@ class FE_System(FE_Base):
cablist.append(u._asdict())
return template.render(
title=f"{self.core_config.server.name} | System",
sesh=vars(usr_sesh),
title=f"{self.core_config.server.name} | System",
sesh=vars(usr_sesh),
usrlist=usrlist,
aclist=aclist,
cablist=cablist,
active_page="sys",
).encode("utf-16")
@@ -403,31 +426,32 @@ class FE_Arcade(FE_Base):
uri = request.uri.decode()
template = self.environment.get_template("core/frontend/arcade/index.jinja")
managed = []
sesh: Session = request.getSession()
usr_sesh = IUserSession(sesh)
if usr_sesh.userId == 0:
if usr_sesh.user_id == 0:
return redirectTo(b"/gate", request)
m = re.match("\/arcade\/(\d*)", uri)
if m is not None:
arcadeid = m.group(1)
perms = self.data.arcade.get_manager_permissions(usr_sesh.userId, arcadeid)
perms = self.data.arcade.get_manager_permissions(usr_sesh.user_id, arcadeid)
arcade = self.data.arcade.get_arcade(arcadeid)
if perms is None:
perms = 0
else:
return redirectTo(b"/user", request)
return template.render(
title=f"{self.core_config.server.name} | Arcade",
title=f"{self.core_config.server.name} | Arcade",
sesh=vars(usr_sesh),
error=0,
perms=perms,
arcade=arcade._asdict()
arcade=arcade._asdict(),
active_page="arcade",
).encode("utf-16")
@@ -435,15 +459,16 @@ class FE_Machine(FE_Base):
def render_GET(self, request: Request):
uri = request.uri.decode()
template = self.environment.get_template("core/frontend/machine/index.jinja")
sesh: Session = request.getSession()
usr_sesh = IUserSession(sesh)
if usr_sesh.userId == 0:
if usr_sesh.user_id == 0:
return redirectTo(b"/gate", request)
return template.render(
title=f"{self.core_config.server.name} | Machine",
sesh=vars(usr_sesh),
title=f"{self.core_config.server.name} | Machine",
sesh=vars(usr_sesh),
arcade={},
error=0,
).encode("utf-16")
active_page="machine",
).encode("utf-16")