2022-03-23 06:06:13 +00:00
|
|
|
# pylint: disable=too-many-lines
|
2020-12-14 21:52:46 +00:00
|
|
|
import time
|
|
|
|
import datetime
|
2021-03-22 04:02:18 +00:00
|
|
|
import os
|
2022-05-09 23:08:49 +00:00
|
|
|
import typing as t
|
2022-01-26 01:45:30 +00:00
|
|
|
import json
|
|
|
|
import logging
|
2022-01-13 05:56:32 +00:00
|
|
|
import threading
|
2022-12-01 01:28:24 +00:00
|
|
|
import urllib.parse
|
2023-10-07 17:55:36 +00:00
|
|
|
from zoneinfo import ZoneInfoNotFoundError
|
2023-09-05 02:44:44 +00:00
|
|
|
import nh3
|
2022-04-11 05:23:55 +00:00
|
|
|
import requests
|
|
|
|
import tornado.web
|
|
|
|
import tornado.escape
|
|
|
|
from tornado import iostream
|
|
|
|
|
|
|
|
# TZLocal is set as a hidden import on win pipeline
|
|
|
|
from tzlocal import get_localzone
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-05-30 05:36:25 +00:00
|
|
|
from app.classes.models.servers import Servers
|
2022-05-20 11:06:46 +00:00
|
|
|
from app.classes.models.server_permissions import EnumPermissionsServer
|
2022-04-14 02:10:25 +00:00
|
|
|
from app.classes.models.crafty_permissions import EnumPermissionsCrafty
|
|
|
|
from app.classes.models.management import HelpersManagement
|
2022-06-13 18:29:25 +00:00
|
|
|
from app.classes.controllers.roles_controller import RolesController
|
2022-04-11 05:23:55 +00:00
|
|
|
from app.classes.shared.helpers import Helpers
|
2022-05-26 21:19:59 +00:00
|
|
|
from app.classes.shared.main_models import DatabaseShortcuts
|
2022-01-26 01:45:30 +00:00
|
|
|
from app.classes.web.base_handler import BaseHandler
|
2023-09-28 18:17:47 +00:00
|
|
|
from app.classes.web.webhooks.webhook_factory import WebhookFactory
|
2020-08-13 14:38:36 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2024-01-28 22:15:20 +00:00
|
|
|
# You must put any new subpages in here
|
2024-01-17 00:21:00 +00:00
|
|
|
SUBPAGE_PERMS = {
|
|
|
|
"term": EnumPermissionsServer.TERMINAL,
|
|
|
|
"logs": EnumPermissionsServer.LOGS,
|
|
|
|
"schedules": EnumPermissionsServer.SCHEDULE,
|
|
|
|
"backup": EnumPermissionsServer.BACKUP,
|
|
|
|
"files": EnumPermissionsServer.FILES,
|
|
|
|
"config": EnumPermissionsServer.CONFIG,
|
|
|
|
"admin_controls": EnumPermissionsServer.PLAYERS,
|
|
|
|
"metrics": EnumPermissionsServer.LOGS,
|
|
|
|
"webhooks": EnumPermissionsServer.CONFIG,
|
|
|
|
}
|
2020-08-17 02:47:53 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
class PanelHandler(BaseHandler):
|
2022-05-09 23:08:49 +00:00
|
|
|
def get_user_roles(self) -> t.Dict[str, list]:
|
2022-01-15 00:23:50 +00:00
|
|
|
user_roles = {}
|
2022-05-07 21:07:55 +00:00
|
|
|
for user_id in self.controller.users.get_all_user_ids():
|
|
|
|
user_roles_list = self.controller.users.get_user_roles_names(user_id)
|
|
|
|
user_roles[user_id] = user_roles_list
|
2022-01-15 00:23:50 +00:00
|
|
|
return user_roles
|
|
|
|
|
2022-05-19 13:13:25 +00:00
|
|
|
def get_role_servers(self) -> t.List[RolesController.RoleServerJsonType]:
|
2022-05-20 11:06:46 +00:00
|
|
|
servers = []
|
2022-05-30 20:05:36 +00:00
|
|
|
for server in self.controller.servers.get_all_defined_servers():
|
2022-05-17 22:09:58 +00:00
|
|
|
argument = self.get_argument(f"server_{server['server_id']}_access", "0")
|
|
|
|
if argument == "0":
|
|
|
|
continue
|
|
|
|
|
|
|
|
permission_mask = "0" * len(EnumPermissionsServer)
|
|
|
|
for permission in self.controller.server_perms.list_defined_permissions():
|
|
|
|
argument = self.get_argument(
|
|
|
|
f"permission_{server['server_id']}_{permission.name}", "0"
|
2022-01-15 00:23:50 +00:00
|
|
|
)
|
2022-05-17 22:09:58 +00:00
|
|
|
if argument == "1":
|
|
|
|
permission_mask = self.controller.server_perms.set_permission(
|
|
|
|
permission_mask, permission, "1"
|
|
|
|
)
|
|
|
|
|
2022-05-19 13:13:25 +00:00
|
|
|
servers.append(
|
|
|
|
{"server_id": server["server_id"], "permissions": permission_mask}
|
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
return servers
|
|
|
|
|
2022-05-09 23:08:49 +00:00
|
|
|
def get_perms_quantity(self) -> t.Tuple[str, dict]:
|
2022-01-15 00:23:50 +00:00
|
|
|
permissions_mask: str = "000"
|
|
|
|
server_quantity: dict = {}
|
2022-03-23 02:50:12 +00:00
|
|
|
for (
|
|
|
|
permission
|
|
|
|
) in self.controller.crafty_perms.list_defined_crafty_permissions():
|
|
|
|
argument = int(
|
|
|
|
float(
|
2024-02-02 20:36:04 +00:00
|
|
|
# pylint: disable=no-member
|
2023-09-05 03:59:24 +00:00
|
|
|
nh3.clean(self.get_argument(f"permission_{permission.name}", "0"))
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
if argument:
|
2022-03-23 02:50:12 +00:00
|
|
|
permissions_mask = self.controller.crafty_perms.set_permission(
|
|
|
|
permissions_mask, permission, argument
|
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
q_argument = int(
|
2024-02-02 19:51:17 +00:00
|
|
|
float(
|
2024-02-02 20:36:04 +00:00
|
|
|
# pylint: disable=no-member
|
2024-02-02 19:51:17 +00:00
|
|
|
nh3.clean(self.get_argument(f"quantity_{permission.name}", "0"))
|
2024-02-02 20:36:04 +00:00
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
if q_argument:
|
|
|
|
server_quantity[permission.name] = q_argument
|
|
|
|
else:
|
|
|
|
server_quantity[permission.name] = 0
|
|
|
|
return permissions_mask, server_quantity
|
|
|
|
|
|
|
|
def get_perms(self) -> str:
|
|
|
|
permissions_mask: str = "000"
|
2022-03-23 02:50:12 +00:00
|
|
|
for (
|
|
|
|
permission
|
|
|
|
) in self.controller.crafty_perms.list_defined_crafty_permissions():
|
|
|
|
argument = self.get_argument(f"permission_{permission.name}", None)
|
2022-05-17 22:09:58 +00:00
|
|
|
if argument is not None and argument == "1":
|
2022-03-23 02:50:12 +00:00
|
|
|
permissions_mask = self.controller.crafty_perms.set_permission(
|
2022-05-17 22:09:58 +00:00
|
|
|
permissions_mask, permission, "1"
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
return permissions_mask
|
|
|
|
|
2022-05-18 23:19:58 +00:00
|
|
|
def get_perms_server(self) -> str:
|
|
|
|
permissions_mask: str = "00000000"
|
|
|
|
for permission in self.controller.server_perms.list_defined_permissions():
|
|
|
|
argument = self.get_argument(f"permission_{permission.name}", None)
|
|
|
|
if argument is not None:
|
|
|
|
permissions_mask = self.controller.server_perms.set_permission(
|
|
|
|
permissions_mask, permission, 1 if argument == "1" else 0
|
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
return permissions_mask
|
|
|
|
|
|
|
|
def get_user_role_memberships(self) -> set:
|
|
|
|
roles = set()
|
|
|
|
for role in self.controller.roles.get_all_roles():
|
2022-03-23 02:50:12 +00:00
|
|
|
if self.get_argument(f"role_{role.role_id}_membership", None) == "1":
|
2022-01-15 00:23:50 +00:00
|
|
|
roles.add(role.role_id)
|
|
|
|
return roles
|
|
|
|
|
|
|
|
def download_file(self, name: str, file: str):
|
2022-03-23 02:50:12 +00:00
|
|
|
self.set_header("Content-Type", "application/octet-stream")
|
|
|
|
self.set_header("Content-Disposition", f"attachment; filename={name}")
|
2022-01-15 00:23:50 +00:00
|
|
|
chunk_size = 1024 * 1024 * 4 # 4 MiB
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
with open(file, "rb") as f:
|
2022-01-15 00:23:50 +00:00
|
|
|
while True:
|
|
|
|
chunk = f.read(chunk_size)
|
|
|
|
if not chunk:
|
|
|
|
break
|
|
|
|
try:
|
|
|
|
self.write(chunk) # write the chunk to response
|
|
|
|
self.flush() # send the chunk to client
|
|
|
|
except iostream.StreamClosedError:
|
|
|
|
# this means the client has closed the connection
|
|
|
|
# so break the loop
|
|
|
|
break
|
|
|
|
finally:
|
|
|
|
# deleting the chunk is very important because
|
|
|
|
# if many clients are downloading files at the
|
|
|
|
# same time, the chunks in memory will keep
|
|
|
|
# increasing and will eat up the RAM
|
|
|
|
del chunk
|
|
|
|
|
2024-01-17 00:21:00 +00:00
|
|
|
def check_subpage_perms(self, user_perms, subpage):
|
|
|
|
if SUBPAGE_PERMS.get(subpage, False) in user_perms:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2022-01-19 21:22:22 +00:00
|
|
|
def check_server_id(self):
|
2022-03-23 02:50:12 +00:00
|
|
|
server_id = self.get_argument("id", None)
|
2022-01-15 00:23:50 +00:00
|
|
|
|
|
|
|
api_key, _, exec_user = self.current_user
|
2022-03-23 02:50:12 +00:00
|
|
|
superuser = exec_user["superuser"]
|
2022-01-15 00:23:50 +00:00
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# Commented out because there is no server access control for API keys,
|
|
|
|
# they just inherit from the host user
|
2022-01-15 00:23:50 +00:00
|
|
|
# if api_key is not None:
|
2024-03-17 16:50:11 +00:00
|
|
|
# superuser = superuser and api_key.full_access
|
2022-01-15 00:23:50 +00:00
|
|
|
|
|
|
|
if server_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return None
|
2022-08-06 00:04:34 +00:00
|
|
|
for server in self.controller.servers.failed_servers:
|
2023-11-01 17:44:56 +00:00
|
|
|
if server_id == server["server_id"]:
|
2022-08-06 00:04:34 +00:00
|
|
|
self.failed_server = True
|
|
|
|
return server_id
|
2022-06-14 12:40:57 +00:00
|
|
|
# Does this server exist?
|
|
|
|
if not self.controller.servers.server_id_exists(server_id):
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return None
|
|
|
|
|
|
|
|
# Does the user have permission?
|
|
|
|
if superuser: # TODO: Figure out a better solution
|
|
|
|
return server_id
|
|
|
|
if api_key is not None:
|
|
|
|
if not self.controller.servers.server_id_authorized_api_key(
|
|
|
|
server_id, api_key
|
|
|
|
):
|
|
|
|
logger.debug(
|
|
|
|
f"API key {api_key.name} (id: {api_key.token_id}) "
|
|
|
|
f"does not have permission"
|
|
|
|
)
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return None
|
2022-01-15 00:23:50 +00:00
|
|
|
else:
|
2022-06-14 12:40:57 +00:00
|
|
|
if not self.controller.servers.server_id_authorized(
|
|
|
|
server_id, exec_user["user_id"]
|
|
|
|
):
|
|
|
|
logger.debug(f'User {exec_user["user_id"]} does not have permission')
|
2022-01-15 00:23:50 +00:00
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return None
|
2022-06-17 04:58:18 +00:00
|
|
|
return server_id
|
2022-01-15 00:23:50 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
# Server fetching, spawned asynchronously
|
2021-12-17 02:07:36 +00:00
|
|
|
# TODO: Make the related front-end elements update with AJAX
|
|
|
|
def fetch_server_data(self, page_data):
|
|
|
|
total_players = 0
|
2022-03-23 02:50:12 +00:00
|
|
|
for server in page_data["servers"]:
|
|
|
|
total_players += len(
|
2022-07-16 07:52:30 +00:00
|
|
|
self.controller.servers.get_server_instance_by_id(
|
2022-03-23 02:50:12 +00:00
|
|
|
server["server_data"]["server_id"]
|
2022-07-16 07:52:30 +00:00
|
|
|
).get_server_players()
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
|
|
|
page_data["num_players"] = total_players
|
2021-12-17 02:07:36 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
for server in page_data["servers"]:
|
2021-12-17 02:07:36 +00:00
|
|
|
try:
|
2022-04-14 02:10:25 +00:00
|
|
|
data = json.loads(server["int_ping_results"])
|
|
|
|
server["int_ping_results"] = data
|
2021-12-17 02:07:36 +00:00
|
|
|
except Exception as e:
|
2022-01-26 01:45:30 +00:00
|
|
|
logger.error(f"Failed server data for page with error: {e}")
|
|
|
|
|
2021-12-17 02:07:36 +00:00
|
|
|
return page_data
|
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
@tornado.web.authenticated
|
2021-12-17 02:07:36 +00:00
|
|
|
async def get(self, page):
|
2022-08-06 00:04:34 +00:00
|
|
|
self.failed_server = False
|
2022-03-23 02:50:12 +00:00
|
|
|
error = self.get_argument("error", "WTF Error!")
|
2020-08-13 14:38:36 +00:00
|
|
|
|
|
|
|
template = "panel/denied.html"
|
2023-11-30 06:05:00 +00:00
|
|
|
if self.helper.crafty_starting:
|
|
|
|
page = "loading"
|
2020-08-13 14:38:36 +00:00
|
|
|
|
2020-12-14 21:52:46 +00:00
|
|
|
now = time.time()
|
2022-03-23 02:50:12 +00:00
|
|
|
formatted_time = str(
|
|
|
|
datetime.datetime.fromtimestamp(now).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
)
|
2020-12-14 21:52:46 +00:00
|
|
|
|
2022-03-20 16:39:57 +00:00
|
|
|
api_key, _token_data, exec_user = self.current_user
|
2022-03-23 02:50:12 +00:00
|
|
|
superuser = exec_user["superuser"]
|
2022-01-15 00:23:50 +00:00
|
|
|
if api_key is not None:
|
2024-03-17 16:50:11 +00:00
|
|
|
superuser = superuser and api_key.full_access
|
2021-09-28 16:41:54 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
if superuser: # TODO: Figure out a better solution
|
2022-05-26 12:50:20 +00:00
|
|
|
defined_servers = self.controller.servers.list_defined_servers()
|
2022-05-15 21:55:22 +00:00
|
|
|
exec_user_role = {"Super User"}
|
2022-03-23 02:50:12 +00:00
|
|
|
exec_user_crafty_permissions = (
|
|
|
|
self.controller.crafty_perms.list_defined_crafty_permissions()
|
|
|
|
)
|
2021-03-09 22:17:50 +00:00
|
|
|
else:
|
2022-01-15 00:23:50 +00:00
|
|
|
if api_key is not None:
|
2022-03-23 02:50:12 +00:00
|
|
|
exec_user_crafty_permissions = (
|
|
|
|
self.controller.crafty_perms.get_api_key_permissions_list(api_key)
|
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
exec_user_crafty_permissions = (
|
|
|
|
self.controller.crafty_perms.get_crafty_permissions_list(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
logger.debug(exec_user["roles"])
|
2022-05-15 21:55:22 +00:00
|
|
|
exec_user_role = set()
|
2022-03-23 02:50:12 +00:00
|
|
|
for r in exec_user["roles"]:
|
2021-09-08 22:01:10 +00:00
|
|
|
role = self.controller.roles.get_role(r)
|
2022-03-23 02:50:12 +00:00
|
|
|
exec_user_role.add(role["role_name"])
|
2023-11-30 06:05:00 +00:00
|
|
|
# get_auth_servers will throw an exception if run while Crafty is starting
|
|
|
|
if not self.helper.crafty_starting:
|
|
|
|
defined_servers = self.controller.servers.get_authorized_servers(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
defined_servers = []
|
2022-03-01 01:02:30 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
user_order = self.controller.users.get_user_by_id(exec_user["user_id"])
|
|
|
|
user_order = user_order["server_order"].split(",")
|
2022-03-01 01:02:30 +00:00
|
|
|
page_servers = []
|
|
|
|
server_ids = []
|
2023-04-12 16:14:37 +00:00
|
|
|
for server in defined_servers:
|
|
|
|
server_ids.append(str(server.server_id))
|
|
|
|
if str(server.server_id) not in user_order:
|
|
|
|
# a little unorthodox, but this will cut out a loop.
|
|
|
|
# adding servers to the user order that don't already exist there.
|
|
|
|
user_order.append(str(server.server_id))
|
2022-03-04 17:42:12 +00:00
|
|
|
for server_id in user_order[:]:
|
|
|
|
for server in defined_servers[:]:
|
2022-05-26 21:19:59 +00:00
|
|
|
if str(server.server_id) == str(server_id):
|
|
|
|
page_servers.append(
|
2022-06-12 15:13:39 +00:00
|
|
|
DatabaseShortcuts.get_data_obj(server.server_object)
|
2022-05-26 21:19:59 +00:00
|
|
|
)
|
2023-04-09 00:33:11 +00:00
|
|
|
user_order.remove(server_id)
|
2022-03-04 17:42:12 +00:00
|
|
|
defined_servers.remove(server)
|
2023-04-09 00:33:11 +00:00
|
|
|
break
|
2022-03-04 17:42:12 +00:00
|
|
|
for server_id in user_order[:]:
|
2022-03-23 02:50:12 +00:00
|
|
|
# remove IDs in list that user no longer has access to
|
2022-03-01 01:02:30 +00:00
|
|
|
if str(server_id) not in server_ids:
|
|
|
|
user_order.remove(server_id)
|
|
|
|
defined_servers = page_servers
|
|
|
|
|
2022-06-13 18:29:25 +00:00
|
|
|
try:
|
|
|
|
tz = get_localzone()
|
|
|
|
except ZoneInfoNotFoundError:
|
|
|
|
logger.error(
|
|
|
|
"Could not capture time zone from system. Falling back to Europe/London"
|
|
|
|
)
|
|
|
|
tz = "Europe/London"
|
2024-01-28 17:58:18 +00:00
|
|
|
if exec_user["username"] == "anti-lockout-user":
|
|
|
|
page = "panel_config"
|
2022-06-13 18:29:25 +00:00
|
|
|
|
2022-05-09 23:08:49 +00:00
|
|
|
page_data: t.Dict[str, t.Any] = {
|
2020-09-23 01:43:22 +00:00
|
|
|
# todo: make this actually pull and compare version data
|
2022-08-05 01:56:26 +00:00
|
|
|
"update_available": self.helper.update_available,
|
2023-02-12 17:29:05 +00:00
|
|
|
"docker": self.helper.is_env_docker(),
|
2022-12-04 01:48:22 +00:00
|
|
|
"background": self.controller.cached_login,
|
2023-01-17 19:40:16 +00:00
|
|
|
"login_opacity": self.controller.management.get_login_opacity(),
|
2022-06-13 18:29:25 +00:00
|
|
|
"serverTZ": tz,
|
2023-02-06 00:05:20 +00:00
|
|
|
"monitored": self.helper.get_setting("monitored_mounts"),
|
2022-04-11 05:23:55 +00:00
|
|
|
"version_data": self.helper.get_version_string(),
|
2022-08-05 21:56:44 +00:00
|
|
|
"failed_servers": self.controller.servers.failed_servers,
|
2022-03-23 02:50:12 +00:00
|
|
|
"user_data": exec_user,
|
|
|
|
"user_role": exec_user_role,
|
|
|
|
"user_crafty_permissions": exec_user_crafty_permissions,
|
|
|
|
"crafty_permissions": {
|
2022-04-14 02:10:25 +00:00
|
|
|
"Server_Creation": EnumPermissionsCrafty.SERVER_CREATION,
|
|
|
|
"User_Config": EnumPermissionsCrafty.USER_CONFIG,
|
|
|
|
"Roles_Config": EnumPermissionsCrafty.ROLES_CONFIG,
|
2021-08-24 21:07:00 +00:00
|
|
|
},
|
2022-03-23 02:50:12 +00:00
|
|
|
"server_stats": {
|
|
|
|
"total": len(defined_servers),
|
2022-05-26 12:50:20 +00:00
|
|
|
"running": len(self.controller.servers.list_running_servers()),
|
2022-03-23 02:50:12 +00:00
|
|
|
"stopped": (
|
2022-05-26 12:50:20 +00:00
|
|
|
len(self.controller.servers.list_defined_servers())
|
|
|
|
- len(self.controller.servers.list_running_servers())
|
2022-03-23 02:50:12 +00:00
|
|
|
),
|
2020-08-19 01:04:43 +00:00
|
|
|
},
|
2022-03-23 02:50:12 +00:00
|
|
|
"menu_servers": defined_servers,
|
|
|
|
"hosts_data": self.controller.management.get_latest_hosts_stats(),
|
2022-04-11 05:23:55 +00:00
|
|
|
"show_contribute": self.helper.get_setting("show_contribute_link", True),
|
2022-03-23 02:50:12 +00:00
|
|
|
"error": error,
|
|
|
|
"time": formatted_time,
|
|
|
|
"lang": self.controller.users.get_user_lang_by_id(exec_user["user_id"]),
|
2022-04-14 02:10:25 +00:00
|
|
|
"lang_page": Helpers.get_lang_page(
|
2022-03-23 02:50:12 +00:00
|
|
|
self.controller.users.get_user_lang_by_id(exec_user["user_id"])
|
|
|
|
),
|
|
|
|
"super_user": superuser,
|
2024-02-19 20:02:09 +00:00
|
|
|
"api_key": (
|
|
|
|
{
|
|
|
|
"name": api_key.name,
|
|
|
|
"created": api_key.created,
|
|
|
|
"server_permissions": api_key.server_permissions,
|
|
|
|
"crafty_permissions": api_key.crafty_permissions,
|
2024-03-17 16:50:11 +00:00
|
|
|
"full_access": api_key.full_access,
|
2024-02-19 20:02:09 +00:00
|
|
|
}
|
|
|
|
if api_key is not None
|
|
|
|
else None
|
|
|
|
),
|
2022-03-23 02:50:12 +00:00
|
|
|
"superuser": superuser,
|
2020-08-13 14:38:36 +00:00
|
|
|
}
|
2023-02-05 21:47:12 +00:00
|
|
|
try:
|
|
|
|
page_data["hosts_data"]["disk_json"] = json.loads(
|
|
|
|
page_data["hosts_data"]["disk_json"].replace("'", '"')
|
|
|
|
)
|
|
|
|
except:
|
|
|
|
page_data["hosts_data"]["disk_json"] = {}
|
2022-03-23 02:50:12 +00:00
|
|
|
if page == "unauthorized":
|
2020-08-13 14:38:36 +00:00
|
|
|
template = "panel/denied.html"
|
|
|
|
|
2020-09-01 17:29:39 +00:00
|
|
|
elif page == "error":
|
|
|
|
template = "public/error.html"
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
elif page == "credits":
|
2022-04-11 10:08:36 +00:00
|
|
|
with open(
|
|
|
|
self.helper.credits_cache, encoding="utf-8"
|
|
|
|
) as credits_default_local:
|
2022-02-10 06:13:52 +00:00
|
|
|
try:
|
2022-03-23 02:50:12 +00:00
|
|
|
remote = requests.get(
|
2023-09-28 18:17:47 +00:00
|
|
|
"https://craftycontrol.com/credits-v2",
|
|
|
|
allow_redirects=True,
|
|
|
|
timeout=10,
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-02-10 06:13:52 +00:00
|
|
|
credits_dict: dict = remote.json()
|
|
|
|
if not credits_dict["staff"]:
|
|
|
|
logger.error("Issue with upstream Staff, using local.")
|
|
|
|
credits_dict: dict = json.load(credits_default_local)
|
|
|
|
except:
|
|
|
|
logger.error("Request to credits bucket failed, using local.")
|
|
|
|
credits_dict: dict = json.load(credits_default_local)
|
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
timestamp = credits_dict["lastUpdate"] / 1000.0
|
|
|
|
page_data["patrons"] = credits_dict["patrons"]
|
|
|
|
page_data["staff"] = credits_dict["staff"]
|
2022-03-04 23:38:36 +00:00
|
|
|
|
|
|
|
# Filter Language keys to exclude joke prefix '*'
|
2022-03-23 02:50:12 +00:00
|
|
|
clean_dict = {
|
|
|
|
user.replace("*", ""): translation
|
|
|
|
for user, translation in credits_dict["translations"].items()
|
|
|
|
}
|
2022-03-04 23:38:36 +00:00
|
|
|
page_data["translations"] = clean_dict
|
|
|
|
|
|
|
|
# 0 Defines if we are using local credits file andd displays sadcat.
|
2022-02-10 06:13:52 +00:00
|
|
|
if timestamp == 0:
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["lastUpdate"] = "😿"
|
2022-02-10 06:13:52 +00:00
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["lastUpdate"] = str(
|
|
|
|
datetime.datetime.fromtimestamp(timestamp).strftime(
|
|
|
|
"%Y-%m-%d %H:%M:%S"
|
|
|
|
)
|
|
|
|
)
|
2020-08-28 03:21:55 +00:00
|
|
|
template = "panel/credits.html"
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
elif page == "contribute":
|
2020-08-28 18:38:42 +00:00
|
|
|
template = "panel/contribute.html"
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
elif page == "dashboard":
|
2022-06-12 21:17:58 +00:00
|
|
|
page_data["first_log"] = self.controller.first_login
|
|
|
|
if self.controller.first_login and exec_user["username"] == "admin":
|
2022-06-12 21:03:42 +00:00
|
|
|
self.controller.first_login = False
|
2022-03-23 02:50:12 +00:00
|
|
|
if superuser: # TODO: Figure out a better solution
|
2021-11-29 21:22:46 +00:00
|
|
|
try:
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["servers"] = (
|
|
|
|
self.controller.servers.get_all_servers_stats()
|
|
|
|
)
|
2021-11-29 21:22:46 +00:00
|
|
|
except IndexError:
|
2022-05-26 12:50:20 +00:00
|
|
|
self.controller.servers.stats.record_stats()
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["servers"] = (
|
|
|
|
self.controller.servers.get_all_servers_stats()
|
|
|
|
)
|
2021-03-09 22:17:50 +00:00
|
|
|
else:
|
2021-11-29 21:22:46 +00:00
|
|
|
try:
|
2022-03-23 02:50:12 +00:00
|
|
|
user_auth = self.controller.servers.get_authorized_servers_stats(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
2021-11-29 21:22:46 +00:00
|
|
|
except IndexError:
|
2022-05-26 12:50:20 +00:00
|
|
|
self.controller.servers.stats.record_stats()
|
2022-03-23 02:50:12 +00:00
|
|
|
user_auth = self.controller.servers.get_authorized_servers_stats(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
logger.debug(f"ASFR: {user_auth}")
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["servers"] = user_auth
|
|
|
|
page_data["server_stats"]["running"] = len(
|
|
|
|
list(filter(lambda x: x["stats"]["running"], page_data["servers"]))
|
|
|
|
)
|
|
|
|
page_data["server_stats"]["stopped"] = (
|
|
|
|
len(page_data["servers"]) - page_data["server_stats"]["running"]
|
|
|
|
)
|
|
|
|
|
|
|
|
# set user server order
|
|
|
|
user_order = self.controller.users.get_user_by_id(exec_user["user_id"])
|
|
|
|
user_order = user_order["server_order"].split(",")
|
2022-02-26 23:00:54 +00:00
|
|
|
page_servers = []
|
|
|
|
server_ids = []
|
2022-03-23 02:50:12 +00:00
|
|
|
un_used_servers = page_data["servers"]
|
2022-03-04 00:36:36 +00:00
|
|
|
flag = 0
|
2022-03-04 17:42:12 +00:00
|
|
|
for server_id in user_order[:]:
|
|
|
|
for server in un_used_servers[:]:
|
|
|
|
if flag == 0:
|
2024-02-19 20:02:09 +00:00
|
|
|
server["stats"]["importing"] = (
|
|
|
|
self.controller.servers.get_import_status(
|
|
|
|
str(server["stats"]["server_id"]["server_id"])
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
|
|
|
server["stats"]["crashed"] = self.controller.servers.is_crashed(
|
|
|
|
str(server["stats"]["server_id"]["server_id"])
|
|
|
|
)
|
2022-03-04 17:42:12 +00:00
|
|
|
try:
|
2024-02-19 20:02:09 +00:00
|
|
|
server["stats"]["waiting_start"] = (
|
|
|
|
self.controller.servers.get_waiting_start(
|
|
|
|
str(server["stats"]["server_id"]["server_id"])
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-03-04 17:42:12 +00:00
|
|
|
except Exception as e:
|
|
|
|
logger.error(f"Failed to get server waiting to start: {e}")
|
2022-03-23 02:50:12 +00:00
|
|
|
server["stats"]["waiting_start"] = False
|
2022-02-26 23:00:54 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
if str(server["server_data"]["server_id"]) == str(server_id):
|
2022-02-26 23:00:54 +00:00
|
|
|
page_servers.append(server)
|
2022-03-04 17:42:12 +00:00
|
|
|
un_used_servers.remove(server)
|
|
|
|
user_order.remove(server_id)
|
2023-04-09 11:34:22 +00:00
|
|
|
break
|
2022-03-23 06:06:13 +00:00
|
|
|
# we only want to set these server stats values once.
|
|
|
|
# We need to update the flag so it only hits that if once.
|
2022-03-04 17:42:12 +00:00
|
|
|
flag += 1
|
|
|
|
|
|
|
|
for server in un_used_servers:
|
2022-03-23 02:50:12 +00:00
|
|
|
server_ids.append(str(server["server_data"]["server_id"]))
|
2022-02-26 23:00:54 +00:00
|
|
|
if server not in page_servers:
|
|
|
|
page_servers.append(server)
|
|
|
|
for server_id in user_order:
|
2022-03-23 02:50:12 +00:00
|
|
|
# remove IDs in list that user no longer has access to
|
2022-03-04 17:42:12 +00:00
|
|
|
if str(server_id) not in server_ids[:]:
|
2022-02-26 23:00:54 +00:00
|
|
|
user_order.remove(server_id)
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["servers"] = page_servers
|
2022-06-21 19:59:08 +00:00
|
|
|
for server in page_data["servers"]:
|
|
|
|
server_obj = self.controller.servers.get_server_instance_by_id(
|
|
|
|
server["server_data"]["server_id"]
|
|
|
|
)
|
|
|
|
alert = False
|
|
|
|
if server_obj.last_backup_status():
|
|
|
|
alert = True
|
|
|
|
server["alert"] = alert
|
2022-02-26 23:00:54 +00:00
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# num players is set to zero here. If we poll all servers while
|
|
|
|
# dashboard is loading it takes FOREVER. We leave this to the
|
2022-03-23 02:50:12 +00:00
|
|
|
# async polling once dashboard is served.
|
|
|
|
page_data["num_players"] = 0
|
2020-08-28 03:21:55 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
template = "panel/dashboard.html"
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
elif page == "server_detail":
|
2024-02-02 20:36:04 +00:00
|
|
|
# pylint: disable=no-member
|
2023-09-05 02:44:44 +00:00
|
|
|
subpage = nh3.clean(self.get_argument("subpage", ""))
|
2024-02-02 20:36:04 +00:00
|
|
|
# pylint: enable=no-member
|
2020-09-01 17:29:39 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
server_id = self.check_server_id()
|
2023-11-05 16:09:57 +00:00
|
|
|
# load page the user was on last
|
|
|
|
server_subpage = self.controller.servers.server_subpage.get(server_id, "")
|
2024-01-17 00:21:00 +00:00
|
|
|
if (
|
|
|
|
subpage == ""
|
|
|
|
and server_subpage != ""
|
|
|
|
and self.check_subpage_perms(
|
|
|
|
self.controller.server_perms.get_user_id_permissions_list(
|
|
|
|
exec_user["user_id"], server_id
|
|
|
|
),
|
|
|
|
server_subpage,
|
|
|
|
)
|
|
|
|
):
|
|
|
|
subpage = server_subpage
|
2023-11-05 16:09:57 +00:00
|
|
|
else:
|
|
|
|
self.controller.servers.server_subpage[server_id] = subpage
|
2022-01-26 01:45:30 +00:00
|
|
|
if server_id is None:
|
|
|
|
return
|
2022-08-06 00:04:34 +00:00
|
|
|
if not self.failed_server:
|
|
|
|
server_obj = self.controller.servers.get_server_instance_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
|
|
|
page_data["backup_failed"] = server_obj.last_backup_status()
|
2022-06-20 21:16:56 +00:00
|
|
|
server_obj = None
|
|
|
|
|
2022-08-06 00:04:34 +00:00
|
|
|
if not self.failed_server:
|
|
|
|
server = self.controller.servers.get_server_instance_by_id(server_id)
|
2020-09-01 17:29:39 +00:00
|
|
|
# server_data isn't needed since the server_stats also pulls server data
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["server_data"] = self.controller.servers.get_server_data_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
2022-08-06 00:04:34 +00:00
|
|
|
if not self.failed_server:
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["server_stats"] = (
|
|
|
|
self.controller.servers.get_server_stats_by_id(server_id)
|
|
|
|
)
|
2022-08-06 00:04:34 +00:00
|
|
|
else:
|
|
|
|
server_temp_obj = self.controller.servers.get_server_data_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
|
|
|
page_data["server_stats"] = {
|
|
|
|
"server_id": {
|
|
|
|
"server_id": server_id,
|
|
|
|
"server_name": server_temp_obj["server_name"],
|
2023-11-01 17:44:56 +00:00
|
|
|
"server_uuid": server_temp_obj["server_id"],
|
2022-08-06 00:04:34 +00:00
|
|
|
"path": server_temp_obj["path"],
|
|
|
|
"log_path": server_temp_obj["log_path"],
|
|
|
|
"executable": server_temp_obj["executable"],
|
|
|
|
"execution_command": server_temp_obj["execution_command"],
|
2022-09-14 17:13:32 +00:00
|
|
|
"shutdown_timeout": server_temp_obj["shutdown_timeout"],
|
2022-08-06 00:04:34 +00:00
|
|
|
"stop_command": server_temp_obj["stop_command"],
|
|
|
|
"executable_update_url": server_temp_obj[
|
|
|
|
"executable_update_url"
|
|
|
|
],
|
|
|
|
"auto_start_delay": server_temp_obj["auto_start_delay"],
|
|
|
|
"server_ip": server_temp_obj["server_ip"],
|
|
|
|
"server_port": server_temp_obj["server_port"],
|
|
|
|
"logs_delete_after": server_temp_obj["logs_delete_after"],
|
|
|
|
"auto_start": server_temp_obj["auto_start"],
|
|
|
|
"crash_detection": server_temp_obj["crash_detection"],
|
|
|
|
"show_status": server_temp_obj["show_status"],
|
2023-03-01 18:35:36 +00:00
|
|
|
"ignored_exits": server_temp_obj["ignored_exits"],
|
2024-02-21 03:30:32 +00:00
|
|
|
"count_players": server_temp_obj["count_players"],
|
2022-08-06 00:04:34 +00:00
|
|
|
},
|
|
|
|
"running": False,
|
|
|
|
"crashed": False,
|
|
|
|
"server_type": "N/A",
|
|
|
|
"cpu": "N/A",
|
|
|
|
"mem": "N/A",
|
|
|
|
"int_ping_results": [],
|
|
|
|
"version": "N/A",
|
|
|
|
"desc": "N/A",
|
|
|
|
"started": "False",
|
|
|
|
}
|
|
|
|
if not self.failed_server:
|
2022-08-17 18:48:05 +00:00
|
|
|
page_data["importing"] = self.controller.servers.get_import_status(
|
2022-08-06 00:04:34 +00:00
|
|
|
server_id
|
|
|
|
)
|
|
|
|
else:
|
2022-08-17 18:48:05 +00:00
|
|
|
page_data["importing"] = False
|
2022-06-22 22:57:29 +00:00
|
|
|
page_data["server_id"] = server_id
|
2021-09-25 15:56:12 +00:00
|
|
|
try:
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["waiting_start"] = self.controller.servers.get_waiting_start(
|
|
|
|
server_id
|
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
except Exception as e:
|
2022-01-26 01:45:30 +00:00
|
|
|
logger.error(f"Failed to get server waiting to start: {e}")
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["waiting_start"] = False
|
2022-08-06 00:04:34 +00:00
|
|
|
if not self.failed_server:
|
|
|
|
page_data["get_players"] = server.get_server_players()
|
|
|
|
else:
|
|
|
|
page_data["get_players"] = []
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["permissions"] = {
|
2022-04-14 02:10:25 +00:00
|
|
|
"Commands": EnumPermissionsServer.COMMANDS,
|
|
|
|
"Terminal": EnumPermissionsServer.TERMINAL,
|
|
|
|
"Logs": EnumPermissionsServer.LOGS,
|
|
|
|
"Schedule": EnumPermissionsServer.SCHEDULE,
|
|
|
|
"Backup": EnumPermissionsServer.BACKUP,
|
|
|
|
"Files": EnumPermissionsServer.FILES,
|
|
|
|
"Config": EnumPermissionsServer.CONFIG,
|
|
|
|
"Players": EnumPermissionsServer.PLAYERS,
|
2021-08-21 08:44:03 +00:00
|
|
|
}
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["user_permissions"] = (
|
|
|
|
self.controller.server_perms.get_user_id_permissions_list(
|
|
|
|
exec_user["user_id"], server_id
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-08-06 00:04:34 +00:00
|
|
|
if not self.failed_server:
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["server_stats"]["crashed"] = (
|
|
|
|
self.controller.servers.is_crashed(server_id)
|
|
|
|
)
|
2022-08-06 00:04:34 +00:00
|
|
|
if not self.failed_server:
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["server_stats"]["server_type"] = (
|
|
|
|
self.controller.servers.get_server_type_by_id(server_id)
|
|
|
|
)
|
2024-01-17 00:21:00 +00:00
|
|
|
|
2022-03-22 14:24:15 +00:00
|
|
|
if not subpage:
|
2024-01-17 00:21:00 +00:00
|
|
|
for spage, perm in SUBPAGE_PERMS.items():
|
|
|
|
if perm in page_data["user_permissions"]:
|
|
|
|
subpage = spage
|
|
|
|
break
|
|
|
|
# If we still don't have a subpage we're going to assume they
|
|
|
|
# have no perms
|
|
|
|
if not subpage:
|
2022-03-22 14:24:15 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access to Server")
|
2024-01-28 22:15:20 +00:00
|
|
|
if subpage not in SUBPAGE_PERMS.keys():
|
|
|
|
self.set_status(404)
|
|
|
|
page_data["background"] = self.controller.cached_login
|
|
|
|
return self.render(
|
|
|
|
"public/404.html",
|
|
|
|
data=page_data,
|
|
|
|
translate=self.translator.translate,
|
|
|
|
)
|
2024-01-17 00:21:00 +00:00
|
|
|
page_data["active_link"] = subpage
|
2022-03-22 14:24:15 +00:00
|
|
|
logger.debug(f'Subpage: "{subpage}"')
|
2021-11-30 17:29:53 +00:00
|
|
|
|
2024-01-17 00:21:00 +00:00
|
|
|
if (
|
|
|
|
not self.check_subpage_perms(page_data["user_permissions"], subpage)
|
|
|
|
and not superuser
|
|
|
|
):
|
|
|
|
return self.redirect(
|
|
|
|
f"/panel/error?error=Unauthorized access to {subpage}"
|
|
|
|
)
|
2021-11-30 17:29:53 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
if subpage == "schedules":
|
2022-04-14 02:10:25 +00:00
|
|
|
page_data["schedules"] = HelpersManagement.get_schedules_by_server(
|
2022-03-23 02:50:12 +00:00
|
|
|
server_id
|
|
|
|
)
|
2021-11-30 17:29:53 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
if subpage == "config":
|
2022-06-20 22:44:33 +00:00
|
|
|
page_data["java_versions"] = Helpers.find_java_installs()
|
2022-06-21 05:18:19 +00:00
|
|
|
server_obj: Servers = self.controller.servers.get_server_obj(server_id)
|
2022-08-06 00:04:34 +00:00
|
|
|
page_data["failed"] = self.failed_server
|
2022-06-21 05:18:19 +00:00
|
|
|
page_java = []
|
|
|
|
page_data["java_versions"].append("java")
|
|
|
|
for version in page_data["java_versions"]:
|
|
|
|
if os.name == "nt":
|
2022-06-21 18:53:23 +00:00
|
|
|
page_java.append(version)
|
2022-06-21 05:18:19 +00:00
|
|
|
else:
|
2022-06-21 18:28:53 +00:00
|
|
|
if len(version) > 0:
|
2022-06-21 18:53:23 +00:00
|
|
|
page_java.append(version)
|
2022-06-21 05:18:19 +00:00
|
|
|
|
|
|
|
page_data["java_versions"] = page_java
|
2021-03-22 04:02:18 +00:00
|
|
|
if subpage == "backup":
|
2021-11-20 03:17:24 +00:00
|
|
|
server_info = self.controller.servers.get_server_data_by_id(server_id)
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["backup_config"] = (
|
|
|
|
self.controller.management.get_backup_config(server_id)
|
|
|
|
)
|
2022-03-01 01:02:30 +00:00
|
|
|
exclusions = []
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["exclusions"] = (
|
|
|
|
self.controller.management.get_excluded_backup_dirs(server_id)
|
|
|
|
)
|
|
|
|
page_data["backing_up"] = (
|
|
|
|
self.controller.servers.get_server_instance_by_id(
|
|
|
|
server_id
|
|
|
|
).is_backingup
|
|
|
|
)
|
|
|
|
page_data["backup_stats"] = (
|
|
|
|
self.controller.servers.get_server_instance_by_id(
|
|
|
|
server_id
|
|
|
|
).send_backup_status()
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
# makes it so relative path is the only thing shown
|
|
|
|
for file in page_data["exclusions"]:
|
2022-04-11 05:23:55 +00:00
|
|
|
if Helpers.is_os_windows():
|
2022-03-23 02:50:12 +00:00
|
|
|
exclusions.append(file.replace(server_info["path"] + "\\", ""))
|
2022-03-01 01:02:30 +00:00
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
exclusions.append(file.replace(server_info["path"] + "/", ""))
|
|
|
|
page_data["exclusions"] = exclusions
|
2022-05-26 12:50:20 +00:00
|
|
|
self.controller.servers.refresh_server_settings(server_id)
|
2021-11-29 21:22:46 +00:00
|
|
|
try:
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["backup_list"] = server.list_backups()
|
2021-11-29 21:22:46 +00:00
|
|
|
except:
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["backup_list"] = []
|
2022-04-11 05:23:55 +00:00
|
|
|
page_data["backup_path"] = Helpers.wtol_path(server_info["backup_path"])
|
2021-03-05 08:58:38 +00:00
|
|
|
|
2022-08-21 21:04:23 +00:00
|
|
|
if subpage == "metrics":
|
2022-09-04 20:21:33 +00:00
|
|
|
try:
|
|
|
|
days = int(self.get_argument("days", "1"))
|
|
|
|
except ValueError as e:
|
|
|
|
self.redirect(
|
|
|
|
f"/panel/error?error=Type error: Argument must be an int {e}"
|
|
|
|
)
|
|
|
|
page_data["options"] = [1, 2, 3]
|
|
|
|
if not days in page_data["options"]:
|
|
|
|
page_data["options"].insert(0, days)
|
|
|
|
else:
|
|
|
|
page_data["options"].insert(
|
|
|
|
0, page_data["options"].pop(page_data["options"].index(days))
|
|
|
|
)
|
2022-08-21 21:04:23 +00:00
|
|
|
page_data["history_stats"] = self.controller.servers.get_history_stats(
|
2023-09-19 19:46:31 +00:00
|
|
|
server_id, hours=(days * 24)
|
2022-08-21 21:04:23 +00:00
|
|
|
)
|
2023-06-03 16:00:03 +00:00
|
|
|
if subpage == "webhooks":
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["webhooks"] = (
|
|
|
|
self.controller.management.get_webhooks_by_server(
|
|
|
|
server_id, model=True
|
|
|
|
)
|
2023-06-03 22:11:50 +00:00
|
|
|
)
|
2023-09-28 21:47:03 +00:00
|
|
|
page_data["triggers"] = WebhookFactory.get_monitored_events()
|
2022-08-21 21:04:23 +00:00
|
|
|
|
2021-03-05 08:58:38 +00:00
|
|
|
def get_banned_players_html():
|
2021-09-08 22:01:10 +00:00
|
|
|
banned_players = self.controller.servers.get_banned_players(server_id)
|
2021-03-05 08:58:38 +00:00
|
|
|
if banned_players is None:
|
|
|
|
return """
|
|
|
|
<li class="playerItem banned">
|
|
|
|
<h3>Error while reading banned-players.json</h3>
|
|
|
|
</li>
|
|
|
|
"""
|
|
|
|
html = ""
|
|
|
|
for player in banned_players:
|
2022-01-26 01:45:30 +00:00
|
|
|
html += f"""
|
2021-03-05 08:58:38 +00:00
|
|
|
<li class="playerItem banned">
|
2022-01-26 01:45:30 +00:00
|
|
|
<h3>{player['name']}</h3>
|
|
|
|
<span>Banned by {player['source']} for reason: {player['reason']}</span>
|
|
|
|
<button onclick="send_command_to_server('pardon {player['name']}')" type="button" class="btn btn-danger">Unban</button>
|
2021-03-05 08:58:38 +00:00
|
|
|
</li>
|
2022-01-26 01:45:30 +00:00
|
|
|
"""
|
2021-09-28 16:41:54 +00:00
|
|
|
|
2021-03-05 08:58:38 +00:00
|
|
|
return html
|
2022-03-23 02:50:12 +00:00
|
|
|
|
2021-03-05 08:58:38 +00:00
|
|
|
if subpage == "admin_controls":
|
2022-03-23 02:50:12 +00:00
|
|
|
if (
|
|
|
|
not page_data["permissions"]["Players"]
|
|
|
|
in page_data["user_permissions"]
|
|
|
|
):
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2021-11-30 17:29:53 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access")
|
2023-04-15 18:47:35 +00:00
|
|
|
page_data["banned_players_html"] = get_banned_players_html()
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["banned_players"] = (
|
|
|
|
self.controller.servers.get_banned_players(server_id)
|
|
|
|
)
|
2023-05-29 23:34:40 +00:00
|
|
|
server_instance = self.controller.servers.get_server_instance_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
|
|
|
page_data["cached_players"] = server_instance.player_cache
|
2023-04-15 18:47:35 +00:00
|
|
|
|
|
|
|
for player in page_data["banned_players"]:
|
|
|
|
player["banned"] = True
|
|
|
|
temp_date = datetime.datetime.strptime(
|
|
|
|
player["created"], "%Y-%m-%d %H:%M:%S %z"
|
|
|
|
)
|
|
|
|
player["banned_on"] = (temp_date).strftime("%Y/%m/%d %H:%M:%S")
|
2020-08-31 17:46:25 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
template = f"panel/server_{subpage}.html"
|
2020-08-31 17:46:25 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
elif page == "download_backup":
|
|
|
|
file = self.get_argument("file", "")
|
2021-03-22 04:02:18 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
server_id = self.check_server_id()
|
2022-01-26 01:45:30 +00:00
|
|
|
if server_id is None:
|
|
|
|
return
|
2021-03-22 04:02:18 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
server_info = self.controller.servers.get_server_data_by_id(server_id)
|
2022-03-23 02:50:12 +00:00
|
|
|
backup_file = os.path.abspath(
|
|
|
|
os.path.join(
|
2022-04-11 05:23:55 +00:00
|
|
|
Helpers.get_os_understandable_path(server_info["backup_path"]), file
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
|
|
|
)
|
2023-07-04 19:02:47 +00:00
|
|
|
if not self.helper.is_subdir(
|
2022-03-23 02:50:12 +00:00
|
|
|
backup_file,
|
2023-06-14 22:57:15 +00:00
|
|
|
Helpers.get_os_understandable_path(server_info["backup_path"]),
|
2022-03-23 02:50:12 +00:00
|
|
|
) or not os.path.isfile(backup_file):
|
2021-03-22 04:02:18 +00:00
|
|
|
self.redirect("/panel/error?error=Invalid path detected")
|
|
|
|
return
|
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
self.download_file(file, backup_file)
|
2021-03-22 04:02:18 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
self.redirect(f"/panel/server_detail?id={server_id}&subpage=backup")
|
2021-03-22 04:02:18 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
elif page == "panel_config":
|
2021-08-08 20:43:04 +00:00
|
|
|
auth_servers = {}
|
|
|
|
auth_role_servers = {}
|
2021-09-08 22:01:10 +00:00
|
|
|
roles = self.controller.roles.get_all_roles()
|
2021-08-08 20:43:04 +00:00
|
|
|
user_roles = {}
|
2021-09-08 22:01:10 +00:00
|
|
|
for user in self.controller.users.get_all_users():
|
2022-03-23 02:50:12 +00:00
|
|
|
user_roles_list = self.controller.users.get_user_roles_names(
|
|
|
|
user.user_id
|
|
|
|
)
|
2022-12-17 17:21:15 +00:00
|
|
|
try:
|
|
|
|
user_servers = self.controller.servers.get_authorized_servers(
|
|
|
|
user.user_id
|
|
|
|
)
|
|
|
|
except:
|
|
|
|
return self.redirect(
|
|
|
|
"/panel/error?error=Cannot load panel config"
|
|
|
|
" while servers are unloaded"
|
|
|
|
)
|
2021-08-08 20:43:04 +00:00
|
|
|
servers = []
|
|
|
|
for server in user_servers:
|
2022-06-01 22:25:27 +00:00
|
|
|
if server.name not in servers:
|
|
|
|
servers.append(server.name)
|
2021-08-08 20:43:04 +00:00
|
|
|
new_item = {user.user_id: servers}
|
|
|
|
auth_servers.update(new_item)
|
|
|
|
data = {user.user_id: user_roles_list}
|
|
|
|
user_roles.update(data)
|
|
|
|
for role in roles:
|
2021-08-09 04:24:08 +00:00
|
|
|
role_servers = []
|
2021-09-08 22:01:10 +00:00
|
|
|
role = self.controller.roles.get_role_with_servers(role.role_id)
|
2022-03-23 02:50:12 +00:00
|
|
|
for serv_id in role["servers"]:
|
|
|
|
role_servers.append(
|
|
|
|
self.controller.servers.get_server_data_by_id(serv_id)[
|
|
|
|
"server_name"
|
|
|
|
]
|
|
|
|
)
|
|
|
|
data = {role["role_id"]: role_servers}
|
2021-08-08 20:43:04 +00:00
|
|
|
auth_role_servers.update(data)
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["auth-servers"] = auth_servers
|
|
|
|
page_data["role-servers"] = auth_role_servers
|
|
|
|
page_data["user-roles"] = user_roles
|
2023-03-01 19:22:33 +00:00
|
|
|
page_data["servers_dir"], _tail = os.path.split(
|
|
|
|
self.controller.management.get_master_server_dir()
|
|
|
|
)
|
2021-08-09 21:11:45 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["users"] = self.controller.users.user_query(exec_user["user_id"])
|
|
|
|
page_data["roles"] = self.controller.users.user_role_query(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
2021-08-08 20:43:04 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
for user in page_data["users"]:
|
|
|
|
if user.user_id != exec_user["user_id"]:
|
2020-12-26 03:00:28 +00:00
|
|
|
user.api_token = "********"
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser:
|
2022-01-09 23:04:54 +00:00
|
|
|
for user in self.controller.users.get_all_users():
|
2022-01-15 15:38:08 +00:00
|
|
|
if user.superuser:
|
2022-01-15 00:23:50 +00:00
|
|
|
super_auth_servers = ["Super User Access To All Servers"]
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["users"] = self.controller.users.get_all_users()
|
|
|
|
page_data["roles"] = self.controller.roles.get_all_roles()
|
|
|
|
page_data["auth-servers"][user.user_id] = super_auth_servers
|
2022-08-19 17:09:59 +00:00
|
|
|
page_data["managed_users"] = []
|
|
|
|
else:
|
|
|
|
page_data["managed_users"] = self.controller.users.get_managed_users(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
2022-08-20 12:32:39 +00:00
|
|
|
page_data["assigned_roles"] = []
|
|
|
|
for item in page_data["roles"]:
|
|
|
|
page_data["assigned_roles"].append(item.role_id)
|
|
|
|
|
2022-08-20 17:00:20 +00:00
|
|
|
page_data["managed_roles"] = self.controller.users.get_managed_roles(
|
2022-08-20 12:32:39 +00:00
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
2022-01-09 23:04:54 +00:00
|
|
|
|
2023-01-21 11:29:08 +00:00
|
|
|
page_data["active_link"] = "panel_config"
|
2020-12-06 20:42:49 +00:00
|
|
|
template = "panel/panel_config.html"
|
2020-08-31 17:46:25 +00:00
|
|
|
|
2023-01-09 23:52:45 +00:00
|
|
|
elif page == "config_json":
|
2023-01-10 00:01:05 +00:00
|
|
|
if exec_user["superuser"]:
|
|
|
|
with open(self.helper.settings_file, "r", encoding="utf-8") as f:
|
|
|
|
data = json.load(f)
|
|
|
|
page_data["config-json"] = data
|
2023-01-18 21:01:23 +00:00
|
|
|
page_data["availables_languages"] = []
|
|
|
|
page_data["all_languages"] = []
|
2023-02-10 20:17:36 +00:00
|
|
|
page_data["all_partitions"] = self.helper.get_all_mounts()
|
2023-01-18 21:01:23 +00:00
|
|
|
|
|
|
|
for file in sorted(
|
|
|
|
os.listdir(
|
|
|
|
os.path.join(self.helper.root_dir, "app", "translations")
|
|
|
|
)
|
|
|
|
):
|
|
|
|
if file.endswith(".json"):
|
|
|
|
if file.split(".")[0] not in self.helper.get_setting(
|
|
|
|
"disabled_language_files"
|
|
|
|
):
|
|
|
|
page_data["availables_languages"].append(file.split(".")[0])
|
|
|
|
page_data["all_languages"].append(file.split(".")[0])
|
2023-01-09 23:52:45 +00:00
|
|
|
|
2023-01-21 11:29:08 +00:00
|
|
|
page_data["active_link"] = "config_json"
|
2023-01-10 00:01:05 +00:00
|
|
|
template = "panel/config_json.html"
|
2023-01-09 23:52:45 +00:00
|
|
|
|
2023-01-28 00:37:41 +00:00
|
|
|
elif page == "custom_login":
|
|
|
|
if exec_user["superuser"]:
|
|
|
|
page_data["backgrounds"] = []
|
|
|
|
cached_split = self.controller.cached_login.split("/")
|
|
|
|
|
|
|
|
if len(cached_split) == 1:
|
|
|
|
page_data["backgrounds"].append(self.controller.cached_login)
|
|
|
|
else:
|
|
|
|
page_data["backgrounds"].append(cached_split[1])
|
|
|
|
if "login_1.jpg" not in page_data["backgrounds"]:
|
|
|
|
page_data["backgrounds"].append("login_1.jpg")
|
|
|
|
self.helper.ensure_dir_exists(
|
|
|
|
os.path.join(
|
|
|
|
self.controller.project_root,
|
|
|
|
"app/frontend/static/assets/images/auth/custom",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
for item in os.listdir(
|
|
|
|
os.path.join(
|
|
|
|
self.controller.project_root,
|
|
|
|
"app/frontend/static/assets/images/auth/custom",
|
|
|
|
)
|
|
|
|
):
|
|
|
|
if item not in page_data["backgrounds"]:
|
|
|
|
page_data["backgrounds"].append(item)
|
|
|
|
page_data["background"] = self.controller.cached_login
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["login_opacity"] = (
|
|
|
|
self.controller.management.get_login_opacity()
|
|
|
|
)
|
2023-01-28 00:37:41 +00:00
|
|
|
|
|
|
|
page_data["active_link"] = "custom_login"
|
|
|
|
template = "panel/custom_login.html"
|
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
elif page == "add_user":
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["new_user"] = True
|
|
|
|
page_data["user"] = {}
|
|
|
|
page_data["user"]["username"] = ""
|
|
|
|
page_data["user"]["user_id"] = -1
|
|
|
|
page_data["user"]["email"] = ""
|
|
|
|
page_data["user"]["enabled"] = True
|
|
|
|
page_data["user"]["superuser"] = False
|
|
|
|
page_data["user"]["created"] = "N/A"
|
|
|
|
page_data["user"]["last_login"] = "N/A"
|
|
|
|
page_data["user"]["last_ip"] = "N/A"
|
|
|
|
page_data["user"]["last_update"] = "N/A"
|
|
|
|
page_data["user"]["roles"] = set()
|
2022-04-03 01:25:26 +00:00
|
|
|
page_data["user"]["hints"] = True
|
2022-05-18 18:33:22 +00:00
|
|
|
page_data["superuser"] = superuser
|
2022-09-27 01:23:47 +00:00
|
|
|
page_data["themes"] = self.helper.get_themes()
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
if EnumPermissionsCrafty.USER_CONFIG not in exec_user_crafty_permissions:
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=Unauthorized access: not a user editor"
|
|
|
|
)
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2022-08-20 22:51:35 +00:00
|
|
|
page_data["roles"] = self.controller.roles.get_all_roles()
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["servers"] = []
|
2022-05-30 20:05:36 +00:00
|
|
|
page_data["servers_all"] = self.controller.servers.get_all_defined_servers()
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["role-servers"] = []
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["permissions_all"] = (
|
|
|
|
self.controller.crafty_perms.list_defined_crafty_permissions()
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["permissions_list"] = set()
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["quantity_server"] = (
|
2022-03-23 06:06:13 +00:00
|
|
|
self.controller.crafty_perms.list_all_crafty_permissions_quantity_limits() # pylint: disable=line-too-long
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
|
|
|
page_data["languages"] = []
|
|
|
|
page_data["languages"].append(
|
|
|
|
self.controller.users.get_user_lang_by_id(exec_user["user_id"])
|
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser:
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["super-disabled"] = ""
|
2022-08-19 17:09:59 +00:00
|
|
|
page_data["users"] = self.controller.users.get_all_users()
|
2022-01-10 04:16:11 +00:00
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["super-disabled"] = "disabled"
|
2022-08-19 17:09:59 +00:00
|
|
|
|
2022-08-20 22:51:35 +00:00
|
|
|
page_data["exec_user"] = exec_user["user_id"]
|
|
|
|
|
2022-08-19 17:09:59 +00:00
|
|
|
page_data["manager"] = {
|
|
|
|
"user_id": -100,
|
|
|
|
"username": "None",
|
|
|
|
}
|
2022-03-23 02:50:12 +00:00
|
|
|
for file in sorted(
|
2022-04-11 05:23:55 +00:00
|
|
|
os.listdir(os.path.join(self.helper.root_dir, "app", "translations"))
|
2022-03-23 02:50:12 +00:00
|
|
|
):
|
|
|
|
if file.endswith(".json"):
|
2023-01-18 21:01:23 +00:00
|
|
|
if file.split(".")[0] not in self.helper.get_setting(
|
|
|
|
"disabled_language_files"
|
|
|
|
):
|
2022-03-23 02:50:12 +00:00
|
|
|
if file != str(page_data["languages"][0] + ".json"):
|
|
|
|
page_data["languages"].append(file.split(".")[0])
|
2021-08-24 21:07:00 +00:00
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
template = "panel/panel_edit_user.html"
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2023-06-03 17:36:38 +00:00
|
|
|
elif page == "add_webhook":
|
|
|
|
server_id = self.get_argument("id", None)
|
|
|
|
if server_id is None:
|
|
|
|
return self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
server_obj = self.controller.servers.get_server_instance_by_id(server_id)
|
|
|
|
page_data["backup_failed"] = server_obj.last_backup_status()
|
|
|
|
server_obj = None
|
|
|
|
page_data["active_link"] = "webhooks"
|
|
|
|
page_data["server_data"] = self.controller.servers.get_server_data_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["user_permissions"] = (
|
|
|
|
self.controller.server_perms.get_user_id_permissions_list(
|
|
|
|
exec_user["user_id"], server_id
|
|
|
|
)
|
2023-06-03 17:36:38 +00:00
|
|
|
)
|
|
|
|
page_data["permissions"] = {
|
|
|
|
"Commands": EnumPermissionsServer.COMMANDS,
|
|
|
|
"Terminal": EnumPermissionsServer.TERMINAL,
|
|
|
|
"Logs": EnumPermissionsServer.LOGS,
|
|
|
|
"Schedule": EnumPermissionsServer.SCHEDULE,
|
|
|
|
"Backup": EnumPermissionsServer.BACKUP,
|
|
|
|
"Files": EnumPermissionsServer.FILES,
|
|
|
|
"Config": EnumPermissionsServer.CONFIG,
|
|
|
|
"Players": EnumPermissionsServer.PLAYERS,
|
|
|
|
}
|
|
|
|
page_data["server_stats"] = self.controller.servers.get_server_stats_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["server_stats"]["server_type"] = (
|
|
|
|
self.controller.servers.get_server_type_by_id(server_id)
|
|
|
|
)
|
2023-06-03 17:36:38 +00:00
|
|
|
page_data["new_webhook"] = True
|
2023-06-03 22:11:50 +00:00
|
|
|
page_data["webhook"] = {}
|
|
|
|
page_data["webhook"]["webhook_type"] = "Custom"
|
|
|
|
page_data["webhook"]["name"] = ""
|
|
|
|
page_data["webhook"]["url"] = ""
|
|
|
|
page_data["webhook"]["bot_name"] = "Crafty Controller"
|
|
|
|
page_data["webhook"]["trigger"] = []
|
|
|
|
page_data["webhook"]["body"] = ""
|
2023-09-28 23:07:03 +00:00
|
|
|
page_data["webhook"]["color"] = "#005cd1"
|
2023-06-03 22:11:50 +00:00
|
|
|
page_data["webhook"]["enabled"] = True
|
|
|
|
|
2023-09-28 18:17:47 +00:00
|
|
|
page_data["providers"] = WebhookFactory.get_supported_providers()
|
|
|
|
page_data["triggers"] = WebhookFactory.get_monitored_events()
|
2023-06-03 22:11:50 +00:00
|
|
|
|
|
|
|
if not EnumPermissionsServer.CONFIG in page_data["user_permissions"]:
|
|
|
|
if not superuser:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access To Webhooks")
|
|
|
|
return
|
|
|
|
|
|
|
|
template = "panel/server_webhook_edit.html"
|
|
|
|
|
|
|
|
elif page == "webhook_edit":
|
|
|
|
server_id = self.get_argument("id", None)
|
|
|
|
webhook_id = self.get_argument("webhook_id", None)
|
|
|
|
if server_id is None:
|
|
|
|
return self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
server_obj = self.controller.servers.get_server_instance_by_id(server_id)
|
|
|
|
page_data["backup_failed"] = server_obj.last_backup_status()
|
|
|
|
server_obj = None
|
|
|
|
page_data["active_link"] = "webhooks"
|
|
|
|
page_data["server_data"] = self.controller.servers.get_server_data_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["user_permissions"] = (
|
|
|
|
self.controller.server_perms.get_user_id_permissions_list(
|
|
|
|
exec_user["user_id"], server_id
|
|
|
|
)
|
2023-06-03 22:11:50 +00:00
|
|
|
)
|
|
|
|
page_data["permissions"] = {
|
|
|
|
"Commands": EnumPermissionsServer.COMMANDS,
|
|
|
|
"Terminal": EnumPermissionsServer.TERMINAL,
|
|
|
|
"Logs": EnumPermissionsServer.LOGS,
|
|
|
|
"Schedule": EnumPermissionsServer.SCHEDULE,
|
|
|
|
"Backup": EnumPermissionsServer.BACKUP,
|
|
|
|
"Files": EnumPermissionsServer.FILES,
|
|
|
|
"Config": EnumPermissionsServer.CONFIG,
|
|
|
|
"Players": EnumPermissionsServer.PLAYERS,
|
|
|
|
}
|
|
|
|
page_data["server_stats"] = self.controller.servers.get_server_stats_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["server_stats"]["server_type"] = (
|
|
|
|
self.controller.servers.get_server_type_by_id(server_id)
|
|
|
|
)
|
2023-06-04 02:40:39 +00:00
|
|
|
page_data["new_webhook"] = False
|
2023-06-03 22:11:50 +00:00
|
|
|
page_data["webhook"] = self.controller.management.get_webhook_by_id(
|
|
|
|
webhook_id
|
|
|
|
)
|
|
|
|
page_data["webhook"]["trigger"] = str(
|
|
|
|
page_data["webhook"]["trigger"]
|
|
|
|
).split(",")
|
|
|
|
|
2023-09-28 21:17:49 +00:00
|
|
|
page_data["providers"] = WebhookFactory.get_supported_providers()
|
|
|
|
page_data["triggers"] = WebhookFactory.get_monitored_events()
|
2023-06-03 17:36:38 +00:00
|
|
|
|
|
|
|
if not EnumPermissionsServer.CONFIG in page_data["user_permissions"]:
|
|
|
|
if not superuser:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access To Webhooks")
|
|
|
|
return
|
|
|
|
|
|
|
|
template = "panel/server_webhook_edit.html"
|
|
|
|
|
2022-01-11 22:24:05 +00:00
|
|
|
elif page == "add_schedule":
|
2022-03-23 02:50:12 +00:00
|
|
|
server_id = self.get_argument("id", None)
|
2022-06-21 22:40:16 +00:00
|
|
|
if server_id is None:
|
|
|
|
return self.redirect("/panel/error?error=Invalid Schedule ID")
|
|
|
|
server_obj = self.controller.servers.get_server_instance_by_id(server_id)
|
|
|
|
page_data["backup_failed"] = server_obj.last_backup_status()
|
|
|
|
server_obj = None
|
2022-04-14 02:10:25 +00:00
|
|
|
page_data["schedules"] = HelpersManagement.get_schedules_by_server(
|
2022-03-23 02:50:12 +00:00
|
|
|
server_id
|
|
|
|
)
|
|
|
|
page_data["active_link"] = "schedules"
|
|
|
|
page_data["permissions"] = {
|
2022-04-14 02:10:25 +00:00
|
|
|
"Commands": EnumPermissionsServer.COMMANDS,
|
|
|
|
"Terminal": EnumPermissionsServer.TERMINAL,
|
|
|
|
"Logs": EnumPermissionsServer.LOGS,
|
|
|
|
"Schedule": EnumPermissionsServer.SCHEDULE,
|
|
|
|
"Backup": EnumPermissionsServer.BACKUP,
|
|
|
|
"Files": EnumPermissionsServer.FILES,
|
|
|
|
"Config": EnumPermissionsServer.CONFIG,
|
|
|
|
"Players": EnumPermissionsServer.PLAYERS,
|
2022-01-11 22:24:05 +00:00
|
|
|
}
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["user_permissions"] = (
|
|
|
|
self.controller.server_perms.get_user_id_permissions_list(
|
|
|
|
exec_user["user_id"], server_id
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
|
|
|
page_data["server_data"] = self.controller.servers.get_server_data_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
|
|
|
page_data["server_stats"] = self.controller.servers.get_server_stats_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["server_stats"]["server_type"] = (
|
|
|
|
self.controller.servers.get_server_type_by_id(server_id)
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["new_schedule"] = True
|
|
|
|
page_data["schedule"] = {}
|
|
|
|
page_data["schedule"]["children"] = []
|
2022-08-05 20:01:26 +00:00
|
|
|
page_data["schedule"]["name"] = ""
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["schedule"]["server_id"] = server_id
|
|
|
|
page_data["schedule"]["schedule_id"] = ""
|
|
|
|
page_data["schedule"]["action"] = ""
|
|
|
|
page_data["schedule"]["enabled"] = True
|
|
|
|
page_data["schedule"]["command"] = ""
|
|
|
|
page_data["schedule"]["one_time"] = False
|
|
|
|
page_data["schedule"]["cron_string"] = ""
|
2022-08-07 05:30:59 +00:00
|
|
|
page_data["schedule"]["delay"] = 0
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["schedule"]["time"] = ""
|
2023-05-12 01:56:31 +00:00
|
|
|
page_data["schedule"]["interval"] = 1
|
2022-03-23 06:06:13 +00:00
|
|
|
# we don't need to check difficulty here.
|
|
|
|
# We'll just default to basic for new schedules
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["schedule"]["difficulty"] = "basic"
|
|
|
|
page_data["schedule"]["interval_type"] = "days"
|
2022-09-16 17:15:07 +00:00
|
|
|
page_data["parent"] = None
|
2022-03-23 02:50:12 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
if not EnumPermissionsServer.SCHEDULE in page_data["user_permissions"]:
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2022-02-27 01:23:20 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access To Schedules")
|
2022-01-11 22:24:05 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
template = "panel/server_schedule_edit.html"
|
|
|
|
|
|
|
|
elif page == "edit_schedule":
|
2022-05-17 17:52:32 +00:00
|
|
|
server_id = self.check_server_id()
|
|
|
|
if not server_id:
|
2022-06-21 22:40:16 +00:00
|
|
|
return self.redirect("/panel/error?error=Invalid Schedule ID")
|
|
|
|
server_obj = self.controller.servers.get_server_instance_by_id(server_id)
|
|
|
|
page_data["backup_failed"] = server_obj.last_backup_status()
|
|
|
|
server_obj = None
|
2022-05-17 17:52:32 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
page_data["schedules"] = HelpersManagement.get_schedules_by_server(
|
2022-03-23 02:50:12 +00:00
|
|
|
server_id
|
|
|
|
)
|
|
|
|
sch_id = self.get_argument("sch_id", None)
|
2022-05-17 17:52:32 +00:00
|
|
|
if sch_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Schedule ID")
|
2022-06-21 22:40:16 +00:00
|
|
|
return
|
2022-01-11 22:24:05 +00:00
|
|
|
schedule = self.controller.management.get_scheduled_task_model(sch_id)
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["active_link"] = "schedules"
|
|
|
|
page_data["permissions"] = {
|
2022-04-14 02:10:25 +00:00
|
|
|
"Commands": EnumPermissionsServer.COMMANDS,
|
|
|
|
"Terminal": EnumPermissionsServer.TERMINAL,
|
|
|
|
"Logs": EnumPermissionsServer.LOGS,
|
|
|
|
"Schedule": EnumPermissionsServer.SCHEDULE,
|
|
|
|
"Backup": EnumPermissionsServer.BACKUP,
|
|
|
|
"Files": EnumPermissionsServer.FILES,
|
|
|
|
"Config": EnumPermissionsServer.CONFIG,
|
|
|
|
"Players": EnumPermissionsServer.PLAYERS,
|
2022-01-11 22:24:05 +00:00
|
|
|
}
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["user_permissions"] = (
|
|
|
|
self.controller.server_perms.get_user_id_permissions_list(
|
|
|
|
exec_user["user_id"], server_id
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
|
|
|
page_data["server_data"] = self.controller.servers.get_server_data_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
|
|
|
page_data["server_stats"] = self.controller.servers.get_server_stats_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["server_stats"]["server_type"] = (
|
|
|
|
self.controller.servers.get_server_type_by_id(server_id)
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["new_schedule"] = False
|
|
|
|
page_data["schedule"] = {}
|
|
|
|
page_data["schedule"]["server_id"] = server_id
|
|
|
|
page_data["schedule"]["schedule_id"] = schedule.schedule_id
|
|
|
|
page_data["schedule"]["action"] = schedule.action
|
2022-08-05 17:52:50 +00:00
|
|
|
if schedule.name:
|
|
|
|
page_data["schedule"]["name"] = schedule.name
|
|
|
|
else:
|
|
|
|
page_data["schedule"]["name"] = ""
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["schedule"]["children"] = (
|
|
|
|
self.controller.management.get_child_schedules(sch_id)
|
|
|
|
)
|
2022-01-26 01:45:30 +00:00
|
|
|
# We check here to see if the command is any of the default ones.
|
2022-03-23 06:06:13 +00:00
|
|
|
# We do not want a user changing to a custom command
|
|
|
|
# and seeing our command there.
|
2022-03-23 02:50:12 +00:00
|
|
|
if (
|
|
|
|
schedule.action != "start"
|
|
|
|
or schedule.action != "stop"
|
|
|
|
or schedule.action != "restart"
|
|
|
|
or schedule.action != "backup"
|
|
|
|
):
|
|
|
|
page_data["schedule"]["command"] = schedule.command
|
2022-01-11 22:24:05 +00:00
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["schedule"]["command"] = ""
|
2022-08-07 05:30:59 +00:00
|
|
|
page_data["schedule"]["delay"] = schedule.delay
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["schedule"]["enabled"] = schedule.enabled
|
|
|
|
page_data["schedule"]["one_time"] = schedule.one_time
|
|
|
|
page_data["schedule"]["cron_string"] = schedule.cron_string
|
|
|
|
page_data["schedule"]["time"] = schedule.start_time
|
|
|
|
page_data["schedule"]["interval"] = schedule.interval
|
|
|
|
page_data["schedule"]["interval_type"] = schedule.interval_type
|
|
|
|
if schedule.interval_type == "reaction":
|
|
|
|
difficulty = "reaction"
|
2022-09-16 17:15:07 +00:00
|
|
|
page_data["parent"] = self.controller.management.get_scheduled_task(
|
|
|
|
schedule.parent
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
elif schedule.cron_string == "":
|
|
|
|
difficulty = "basic"
|
2022-09-16 17:15:07 +00:00
|
|
|
page_data["parent"] = None
|
2022-01-11 22:24:05 +00:00
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
difficulty = "advanced"
|
2022-09-20 21:52:11 +00:00
|
|
|
page_data["parent"] = None
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["schedule"]["difficulty"] = difficulty
|
2022-01-11 22:24:05 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
if not EnumPermissionsServer.SCHEDULE in page_data["user_permissions"]:
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2022-02-27 01:23:20 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access To Schedules")
|
2022-01-11 22:24:05 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
template = "panel/server_schedule_edit.html"
|
2020-12-24 22:55:15 +00:00
|
|
|
|
|
|
|
elif page == "edit_user":
|
2022-03-23 02:50:12 +00:00
|
|
|
user_id = self.get_argument("id", None)
|
2021-09-08 22:01:10 +00:00
|
|
|
role_servers = self.controller.servers.get_authorized_servers(user_id)
|
2021-08-08 22:26:28 +00:00
|
|
|
page_role_servers = []
|
|
|
|
for server in role_servers:
|
2022-06-01 22:25:27 +00:00
|
|
|
page_role_servers.append(server.server_id)
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["new_user"] = False
|
|
|
|
page_data["user"] = self.controller.users.get_user_by_id(user_id)
|
2022-05-15 21:55:22 +00:00
|
|
|
page_data["servers"] = set()
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["role-servers"] = page_role_servers
|
2022-08-20 22:51:35 +00:00
|
|
|
page_data["roles"] = self.controller.roles.get_all_roles()
|
|
|
|
page_data["exec_user"] = exec_user["user_id"]
|
2022-05-30 20:05:36 +00:00
|
|
|
page_data["servers_all"] = self.controller.servers.get_all_defined_servers()
|
2022-05-18 18:33:22 +00:00
|
|
|
page_data["superuser"] = superuser
|
2022-09-27 01:23:47 +00:00
|
|
|
page_data["themes"] = self.helper.get_themes()
|
2022-08-19 17:09:59 +00:00
|
|
|
if page_data["user"]["manager"] is not None:
|
|
|
|
page_data["manager"] = self.controller.users.get_user_by_id(
|
|
|
|
page_data["user"]["manager"]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
page_data["manager"] = {
|
|
|
|
"user_id": -100,
|
|
|
|
"username": "None",
|
|
|
|
}
|
|
|
|
if exec_user["superuser"]:
|
|
|
|
page_data["users"] = self.controller.users.get_all_users()
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["permissions_all"] = (
|
|
|
|
self.controller.crafty_perms.list_defined_crafty_permissions()
|
|
|
|
)
|
|
|
|
page_data["permissions_list"] = (
|
|
|
|
self.controller.crafty_perms.get_crafty_permissions_list(user_id)
|
|
|
|
)
|
|
|
|
page_data["quantity_server"] = (
|
|
|
|
self.controller.crafty_perms.list_crafty_permissions_quantity_limits(
|
|
|
|
user_id
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
|
|
|
page_data["languages"] = []
|
|
|
|
page_data["languages"].append(
|
|
|
|
self.controller.users.get_user_lang_by_id(user_id)
|
|
|
|
)
|
|
|
|
# checks if super user. If not we disable the button.
|
|
|
|
if superuser and str(exec_user["user_id"]) != str(user_id):
|
|
|
|
page_data["super-disabled"] = ""
|
2022-01-09 23:04:54 +00:00
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["super-disabled"] = "disabled"
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
for file in sorted(
|
2022-04-11 05:23:55 +00:00
|
|
|
os.listdir(os.path.join(self.helper.root_dir, "app", "translations"))
|
2022-03-23 02:50:12 +00:00
|
|
|
):
|
|
|
|
if file.endswith(".json"):
|
2023-01-18 21:01:23 +00:00
|
|
|
if file.split(".")[0] not in self.helper.get_setting(
|
|
|
|
"disabled_language_files"
|
|
|
|
):
|
2022-03-23 02:50:12 +00:00
|
|
|
if file != str(page_data["languages"][0] + ".json"):
|
|
|
|
page_data["languages"].append(file.split(".")[0])
|
2020-12-26 03:00:28 +00:00
|
|
|
|
2021-08-09 21:11:45 +00:00
|
|
|
if user_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return
|
2022-06-14 12:40:57 +00:00
|
|
|
if EnumPermissionsCrafty.USER_CONFIG not in exec_user_crafty_permissions:
|
2022-01-15 00:23:50 +00:00
|
|
|
if str(user_id) != str(exec_user["user_id"]):
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=Unauthorized access: not a user editor"
|
|
|
|
)
|
2021-08-24 21:07:00 +00:00
|
|
|
return
|
2022-08-19 17:09:59 +00:00
|
|
|
if (
|
2022-08-19 19:14:42 +00:00
|
|
|
(
|
|
|
|
self.controller.users.get_user_by_id(user_id)["manager"]
|
|
|
|
!= exec_user["user_id"]
|
|
|
|
)
|
|
|
|
and not exec_user["superuser"]
|
|
|
|
and str(exec_user["user_id"]) != str(user_id)
|
|
|
|
):
|
2022-08-19 17:09:59 +00:00
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=Unauthorized access: you cannot edit this user"
|
|
|
|
)
|
2021-08-24 21:07:00 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["servers"] = []
|
|
|
|
page_data["role-servers"] = []
|
|
|
|
page_data["roles_all"] = []
|
|
|
|
page_data["servers_all"] = []
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
if exec_user["user_id"] != page_data["user"]["user_id"]:
|
|
|
|
page_data["user"]["api_token"] = "********"
|
2022-01-08 23:03:45 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
if exec_user["email"] == "default@example.com":
|
|
|
|
page_data["user"]["email"] = ""
|
2020-12-24 22:55:15 +00:00
|
|
|
template = "panel/panel_edit_user.html"
|
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
elif page == "edit_user_apikeys":
|
2022-03-23 02:50:12 +00:00
|
|
|
user_id = self.get_argument("id", None)
|
|
|
|
page_data["user"] = self.controller.users.get_user_by_id(user_id)
|
|
|
|
page_data["api_keys"] = self.controller.users.get_user_api_keys(user_id)
|
2022-01-15 00:23:50 +00:00
|
|
|
# self.controller.crafty_perms.list_defined_crafty_permissions()
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["server_permissions_all"] = (
|
|
|
|
self.controller.server_perms.list_defined_permissions()
|
|
|
|
)
|
|
|
|
page_data["crafty_permissions_all"] = (
|
|
|
|
self.controller.crafty_perms.list_defined_crafty_permissions()
|
|
|
|
)
|
2024-03-25 17:04:09 +00:00
|
|
|
page_data["user_crafty_permissions"] = (
|
|
|
|
self.controller.crafty_perms.get_crafty_permissions_list(user_id)
|
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
|
|
|
|
if user_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return
|
2022-06-18 21:27:06 +00:00
|
|
|
if int(user_id) != exec_user["user_id"] and not exec_user["superuser"]:
|
2022-06-18 21:03:44 +00:00
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=You are not authorized to view this page."
|
|
|
|
)
|
2022-06-18 21:02:10 +00:00
|
|
|
return
|
2022-01-15 00:23:50 +00:00
|
|
|
|
|
|
|
template = "panel/panel_edit_user_apikeys.html"
|
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
elif page == "remove_user":
|
2024-02-02 20:36:04 +00:00
|
|
|
# pylint: disable=no-member
|
2023-09-05 02:44:44 +00:00
|
|
|
user_id = nh3.clean(self.get_argument("id", None))
|
2024-02-02 20:36:04 +00:00
|
|
|
# pylint: enable=no-member
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
if (
|
|
|
|
not superuser
|
2022-04-14 02:10:25 +00:00
|
|
|
and EnumPermissionsCrafty.USER_CONFIG
|
2022-03-23 02:50:12 +00:00
|
|
|
not in exec_user_crafty_permissions
|
|
|
|
):
|
2020-12-24 22:55:15 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2022-01-10 04:34:11 +00:00
|
|
|
|
2022-06-14 12:40:57 +00:00
|
|
|
if str(exec_user["user_id"]) == str(user_id):
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=Unauthorized access: you cannot delete yourself"
|
|
|
|
)
|
2022-01-10 04:34:11 +00:00
|
|
|
return
|
2022-06-14 12:40:57 +00:00
|
|
|
if user_id is None:
|
2020-12-24 22:55:15 +00:00
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2022-06-14 12:40:57 +00:00
|
|
|
# does this user id exist?
|
|
|
|
target_user = self.controller.users.get_user_by_id(user_id)
|
|
|
|
if not target_user:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return
|
|
|
|
if target_user["superuser"]:
|
|
|
|
self.redirect("/panel/error?error=Cannot remove a superuser")
|
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.users.remove_user(user_id)
|
2020-12-24 22:55:15 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
self.controller.management.add_to_audit_log(
|
|
|
|
exec_user["user_id"],
|
|
|
|
f"Removed user {target_user['username']} (UID:{user_id})",
|
2024-03-24 19:39:10 +00:00
|
|
|
server_id=None,
|
2022-03-23 02:50:12 +00:00
|
|
|
source_ip=self.get_remote_ip(),
|
|
|
|
)
|
2020-12-24 22:55:15 +00:00
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
|
2020-12-27 16:00:26 +00:00
|
|
|
elif page == "add_role":
|
2022-01-15 00:23:50 +00:00
|
|
|
user_roles = self.get_user_roles()
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["new_role"] = True
|
|
|
|
page_data["role"] = {}
|
|
|
|
page_data["role"]["role_name"] = ""
|
|
|
|
page_data["role"]["role_id"] = -1
|
|
|
|
page_data["role"]["created"] = "N/A"
|
|
|
|
page_data["role"]["last_update"] = "N/A"
|
|
|
|
page_data["role"]["servers"] = set()
|
|
|
|
page_data["user-roles"] = user_roles
|
|
|
|
page_data["users"] = self.controller.users.get_all_users()
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
if EnumPermissionsCrafty.ROLES_CONFIG not in exec_user_crafty_permissions:
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=Unauthorized access: not a role editor"
|
|
|
|
)
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2022-06-01 23:26:57 +00:00
|
|
|
if exec_user["superuser"]:
|
2022-06-02 11:34:17 +00:00
|
|
|
defined_servers = self.controller.servers.list_defined_servers()
|
2022-06-01 23:26:57 +00:00
|
|
|
else:
|
2022-06-02 11:34:17 +00:00
|
|
|
defined_servers = self.controller.servers.get_authorized_servers(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
2022-08-20 12:32:39 +00:00
|
|
|
|
|
|
|
page_data["role_manager"] = {
|
|
|
|
"user_id": -100,
|
|
|
|
"username": "None",
|
|
|
|
}
|
2022-06-02 11:34:17 +00:00
|
|
|
page_servers = []
|
|
|
|
for server in defined_servers:
|
|
|
|
if server not in page_servers:
|
|
|
|
page_servers.append(
|
|
|
|
DatabaseShortcuts.get_data_obj(server.server_object)
|
|
|
|
)
|
|
|
|
page_data["servers_all"] = page_servers
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["permissions_all"] = (
|
|
|
|
self.controller.server_perms.list_defined_permissions()
|
|
|
|
)
|
2022-05-17 22:09:58 +00:00
|
|
|
page_data["permissions_dict"] = {}
|
2020-12-27 16:00:26 +00:00
|
|
|
template = "panel/panel_edit_role.html"
|
|
|
|
|
|
|
|
elif page == "edit_role":
|
2022-01-15 00:23:50 +00:00
|
|
|
user_roles = self.get_user_roles()
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["new_role"] = False
|
|
|
|
role_id = self.get_argument("id", None)
|
2022-08-20 22:51:35 +00:00
|
|
|
role = self.controller.roles.get_role(role_id)
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["role"] = self.controller.roles.get_role_with_servers(role_id)
|
2022-06-01 23:26:57 +00:00
|
|
|
if exec_user["superuser"]:
|
2022-06-02 11:34:17 +00:00
|
|
|
defined_servers = self.controller.servers.list_defined_servers()
|
2022-06-01 23:26:57 +00:00
|
|
|
else:
|
2022-06-02 11:34:17 +00:00
|
|
|
defined_servers = self.controller.servers.get_authorized_servers(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
|
|
|
page_servers = []
|
|
|
|
for server in defined_servers:
|
|
|
|
if server not in page_servers:
|
|
|
|
page_servers.append(
|
|
|
|
DatabaseShortcuts.get_data_obj(server.server_object)
|
|
|
|
)
|
|
|
|
page_data["servers_all"] = page_servers
|
2024-02-19 20:02:09 +00:00
|
|
|
page_data["permissions_all"] = (
|
|
|
|
self.controller.server_perms.list_defined_permissions()
|
|
|
|
)
|
|
|
|
page_data["permissions_dict"] = (
|
|
|
|
self.controller.server_perms.get_role_permissions_dict(role_id)
|
|
|
|
)
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["user-roles"] = user_roles
|
|
|
|
page_data["users"] = self.controller.users.get_all_users()
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2022-08-20 12:32:39 +00:00
|
|
|
if page_data["role"]["manager"] is not None:
|
|
|
|
page_data["role_manager"] = self.controller.users.get_user_by_id(
|
|
|
|
page_data["role"]["manager"]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
page_data["role_manager"] = {
|
|
|
|
"user_id": -100,
|
|
|
|
"username": "None",
|
|
|
|
}
|
|
|
|
|
2022-08-20 22:51:35 +00:00
|
|
|
if (
|
|
|
|
EnumPermissionsCrafty.ROLES_CONFIG not in exec_user_crafty_permissions
|
2022-08-21 00:58:46 +00:00
|
|
|
or exec_user["user_id"] != role["manager"]
|
2022-08-20 22:51:35 +00:00
|
|
|
and not exec_user["superuser"]
|
|
|
|
):
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=Unauthorized access: not a role editor"
|
|
|
|
)
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2022-06-14 12:40:57 +00:00
|
|
|
if role_id is None:
|
2020-12-27 16:00:26 +00:00
|
|
|
self.redirect("/panel/error?error=Invalid Role ID")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-27 16:00:26 +00:00
|
|
|
|
|
|
|
template = "panel/panel_edit_role.html"
|
|
|
|
|
2020-12-13 18:40:55 +00:00
|
|
|
elif page == "activity_logs":
|
2023-08-20 21:01:32 +00:00
|
|
|
page_data["audit_logs"] = self.controller.management.get_activity_log()
|
2020-12-13 18:40:55 +00:00
|
|
|
|
|
|
|
template = "panel/activity_logs.html"
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
elif page == "download_file":
|
2022-12-01 01:28:24 +00:00
|
|
|
file = Helpers.get_os_understandable_path(
|
|
|
|
urllib.parse.unquote(self.get_argument("path", ""))
|
|
|
|
)
|
|
|
|
name = urllib.parse.unquote(self.get_argument("name", ""))
|
2022-01-15 00:23:50 +00:00
|
|
|
server_id = self.check_server_id()
|
2022-01-26 01:45:30 +00:00
|
|
|
if server_id is None:
|
|
|
|
return
|
2021-08-25 01:33:29 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
server_info = self.controller.servers.get_server_data_by_id(server_id)
|
2021-08-25 01:33:29 +00:00
|
|
|
|
2023-07-04 19:02:47 +00:00
|
|
|
if not self.helper.is_subdir(
|
2023-06-14 22:57:15 +00:00
|
|
|
file,
|
|
|
|
Helpers.get_os_understandable_path(server_info["path"]),
|
2022-03-23 02:50:12 +00:00
|
|
|
) or not os.path.isfile(file):
|
2021-08-25 01:33:29 +00:00
|
|
|
self.redirect("/panel/error?error=Invalid path detected")
|
|
|
|
return
|
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
self.download_file(name, file)
|
2022-01-26 01:45:30 +00:00
|
|
|
self.redirect(f"/panel/server_detail?id={server_id}&subpage=files")
|
2021-08-25 01:33:29 +00:00
|
|
|
|
2022-06-18 19:57:37 +00:00
|
|
|
elif page == "wiki":
|
|
|
|
template = "panel/wiki.html"
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
elif page == "download_support_package":
|
2022-04-14 02:10:25 +00:00
|
|
|
temp_zip_storage = exec_user["support_logs"]
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
self.set_header("Content-Type", "application/octet-stream")
|
|
|
|
self.set_header(
|
|
|
|
"Content-Disposition", "attachment; filename=" + "support_logs.zip"
|
|
|
|
)
|
|
|
|
chunk_size = 1024 * 1024 * 4 # 4 MiB
|
2022-04-14 02:10:25 +00:00
|
|
|
if temp_zip_storage != "":
|
|
|
|
with open(temp_zip_storage, "rb") as f:
|
2022-01-14 01:42:53 +00:00
|
|
|
while True:
|
|
|
|
chunk = f.read(chunk_size)
|
|
|
|
if not chunk:
|
|
|
|
break
|
|
|
|
try:
|
2022-03-23 02:50:12 +00:00
|
|
|
self.write(chunk) # write the chunk to response
|
|
|
|
self.flush() # send the chunk to client
|
2022-01-14 01:42:53 +00:00
|
|
|
except iostream.StreamClosedError:
|
|
|
|
# this means the client has closed the connection
|
|
|
|
# so break the loop
|
|
|
|
break
|
|
|
|
finally:
|
|
|
|
# deleting the chunk is very important because
|
|
|
|
# if many clients are downloading files at the
|
|
|
|
# same time, the chunks in memory will keep
|
|
|
|
# increasing and will eat up the RAM
|
|
|
|
del chunk
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect("/panel/dashboard")
|
2022-01-14 01:42:53 +00:00
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect("/panel/error?error=No path found for support logs")
|
2022-01-14 01:42:53 +00:00
|
|
|
return
|
2022-01-13 02:12:28 +00:00
|
|
|
|
2022-01-14 01:42:53 +00:00
|
|
|
elif page == "support_logs":
|
2022-03-23 02:50:12 +00:00
|
|
|
logger.info(
|
2022-03-23 06:06:13 +00:00
|
|
|
f"Support logs requested. "
|
|
|
|
f"Packinging logs for user with ID: {exec_user['user_id']}"
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
|
|
|
logs_thread = threading.Thread(
|
|
|
|
target=self.controller.package_support_logs,
|
|
|
|
daemon=True,
|
|
|
|
args=(exec_user,),
|
|
|
|
name=f"{exec_user['user_id']}_logs_thread",
|
|
|
|
)
|
2022-01-14 01:42:53 +00:00
|
|
|
logs_thread.start()
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect("/panel/dashboard")
|
2022-01-14 01:42:53 +00:00
|
|
|
return
|
2023-11-03 20:41:23 +00:00
|
|
|
if self.helper.crafty_starting:
|
|
|
|
template = "panel/loading.html"
|
2020-08-13 14:38:36 +00:00
|
|
|
self.render(
|
|
|
|
template,
|
2020-12-15 23:17:41 +00:00
|
|
|
data=page_data,
|
|
|
|
time=time,
|
|
|
|
utc_offset=(time.timezone * -1 / 60 / 60),
|
2021-03-26 13:57:50 +00:00
|
|
|
translate=self.translator.translate,
|
2020-08-24 17:08:17 +00:00
|
|
|
)
|