2020-12-14 21:52:46 +00:00
|
|
|
import time
|
|
|
|
import datetime
|
2021-03-22 04:02:18 +00:00
|
|
|
import os
|
2022-01-26 01:45:30 +00:00
|
|
|
from typing import Dict, Any, Tuple
|
|
|
|
import json
|
|
|
|
import logging
|
2022-01-13 05:56:32 +00:00
|
|
|
import threading
|
2022-01-26 01:45:30 +00:00
|
|
|
import bleach
|
2022-01-18 21:44:36 +00:00
|
|
|
import libgravatar
|
|
|
|
import requests
|
2020-08-13 14:38:36 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
import tornado.web
|
|
|
|
import tornado.escape
|
|
|
|
from tornado import iostream
|
2021-12-17 02:07:36 +00:00
|
|
|
from tornado.ioloop import IOLoop
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
#TZLocal is set as a hidden import on win pipeline
|
|
|
|
from tzlocal import get_localzone
|
|
|
|
from cron_validator import CronValidator
|
2022-01-29 00:00:14 +00:00
|
|
|
from app.classes.controllers.servers_controller import Servers_Controller
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
from app.classes.models.server_permissions import Enum_Permissions_Server
|
|
|
|
from app.classes.models.crafty_permissions import Enum_Permissions_Crafty
|
2021-11-30 20:46:30 +00:00
|
|
|
from app.classes.models.management import management_helper
|
2021-09-08 22:01:10 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
from app.classes.shared.authentication import authentication
|
2020-08-28 18:38:42 +00:00
|
|
|
from app.classes.shared.helpers import helper
|
2020-08-19 01:04:43 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
from app.classes.web.base_handler import BaseHandler
|
2020-08-13 14:38:36 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2020-08-17 02:47:53 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
class PanelHandler(BaseHandler):
|
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
def get_user_roles(self) -> Dict[str, list]:
|
|
|
|
user_roles = {}
|
|
|
|
for user in self.controller.users.get_all_users():
|
|
|
|
user_roles_list = self.controller.users.get_user_roles_names(user.user_id)
|
|
|
|
# user_servers = self.controller.servers.get_authorized_servers(user.user_id)
|
|
|
|
user_roles[user.user_id] = user_roles_list
|
|
|
|
return user_roles
|
|
|
|
|
|
|
|
def get_role_servers(self) -> set:
|
|
|
|
servers = set()
|
|
|
|
for server in self.controller.list_defined_servers():
|
|
|
|
argument = int(float(
|
|
|
|
bleach.clean(
|
2022-01-26 01:45:30 +00:00
|
|
|
self.get_argument(f"server_{server['server_id']}_access", '0')
|
2022-01-15 00:23:50 +00:00
|
|
|
)
|
|
|
|
))
|
|
|
|
if argument:
|
|
|
|
servers.add(server['server_id'])
|
|
|
|
return servers
|
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
def get_perms_quantity(self) -> Tuple[str, dict]:
|
2022-01-15 00:23:50 +00:00
|
|
|
permissions_mask: str = "000"
|
|
|
|
server_quantity: dict = {}
|
|
|
|
for permission in self.controller.crafty_perms.list_defined_crafty_permissions():
|
|
|
|
argument = int(float(bleach.clean(
|
2022-01-26 01:45:30 +00:00
|
|
|
self.get_argument(f'permission_{permission.name}', '0')
|
2022-01-15 00:23:50 +00:00
|
|
|
)))
|
|
|
|
if argument:
|
|
|
|
permissions_mask = self.controller.crafty_perms.set_permission(permissions_mask, permission, argument)
|
|
|
|
|
|
|
|
q_argument = int(float(
|
|
|
|
bleach.clean(
|
2022-01-26 01:45:30 +00:00
|
|
|
self.get_argument(f'quantity_{permission.name}', '0')
|
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"
|
|
|
|
for permission in self.controller.crafty_perms.list_defined_crafty_permissions():
|
2022-01-26 01:45:30 +00:00
|
|
|
argument = self.get_argument(f'permission_{permission.name}', None)
|
2022-01-15 00:23:50 +00:00
|
|
|
if argument is not None:
|
|
|
|
permissions_mask = self.controller.crafty_perms.set_permission(permissions_mask, permission,
|
|
|
|
1 if argument == '1' else 0)
|
|
|
|
return permissions_mask
|
|
|
|
|
|
|
|
def get_perms_server(self) -> str:
|
|
|
|
permissions_mask = "00000000"
|
|
|
|
for permission in self.controller.server_perms.list_defined_permissions():
|
2022-01-26 01:45:30 +00:00
|
|
|
argument = self.get_argument(f'permission_{permission.name}', None)
|
2022-01-15 00:23:50 +00:00
|
|
|
if argument is not None:
|
|
|
|
permissions_mask = self.controller.server_perms.set_permission(permissions_mask, permission,
|
|
|
|
1 if argument == '1' else 0)
|
|
|
|
return permissions_mask
|
|
|
|
|
|
|
|
def get_user_role_memberships(self) -> set:
|
|
|
|
roles = set()
|
|
|
|
for role in self.controller.roles.get_all_roles():
|
2022-01-26 01:45:30 +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):
|
|
|
|
self.set_header('Content-Type', 'application/octet-stream')
|
2022-01-26 01:45:30 +00:00
|
|
|
self.set_header('Content-Disposition', f'attachment; filename={name}')
|
2022-01-15 00:23:50 +00:00
|
|
|
chunk_size = 1024 * 1024 * 4 # 4 MiB
|
|
|
|
|
|
|
|
with open(file, 'rb') as f:
|
|
|
|
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
|
|
|
|
|
2022-01-19 21:22:22 +00:00
|
|
|
def check_server_id(self):
|
2022-01-15 00:23:50 +00:00
|
|
|
server_id = self.get_argument('id', None)
|
|
|
|
|
|
|
|
api_key, _, exec_user = self.current_user
|
|
|
|
superuser = exec_user['superuser']
|
|
|
|
|
|
|
|
# Commented out because there is no server access control for API keys, they just inherit from the host user
|
|
|
|
# if api_key is not None:
|
|
|
|
# superuser = superuser and api_key.superuser
|
|
|
|
|
|
|
|
if server_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
# 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 not superuser: # TODO: Figure out a better solution
|
|
|
|
if api_key is not None:
|
|
|
|
if not self.controller.servers.server_id_authorized_api_key(server_id, api_key):
|
|
|
|
print(f'API key {api_key.name} (id: {api_key.token_id}) does not have permission')
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
if not self.controller.servers.server_id_authorized(server_id, exec_user["user_id"]):
|
|
|
|
print(f'User {exec_user["user_id"]} does not have permission')
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return None
|
|
|
|
return server_id
|
|
|
|
|
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
|
|
|
|
for server in page_data['servers']:
|
|
|
|
total_players += len(self.controller.stats.get_server_players(server['server_data']['server_id']))
|
|
|
|
page_data['num_players'] = total_players
|
|
|
|
|
|
|
|
for s in page_data['servers']:
|
|
|
|
try:
|
|
|
|
data = json.loads(s['int_ping_results'])
|
|
|
|
s['int_ping_results'] = data
|
|
|
|
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-01-15 00:23:50 +00:00
|
|
|
error = self.get_argument('error', "WTF Error!")
|
2020-08-13 14:38:36 +00:00
|
|
|
|
|
|
|
template = "panel/denied.html"
|
|
|
|
|
2020-12-14 21:52:46 +00:00
|
|
|
now = time.time()
|
|
|
|
formatted_time = str(datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
# pylint: disable=unused-variable
|
2022-01-15 00:23:50 +00:00
|
|
|
api_key, token_data, exec_user = self.current_user
|
|
|
|
superuser = exec_user['superuser']
|
|
|
|
if api_key is not None:
|
|
|
|
superuser = superuser and api_key.superuser
|
2021-09-28 16:41:54 +00:00
|
|
|
|
2021-04-03 17:36:01 +00:00
|
|
|
exec_user_role = set()
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser: # TODO: Figure out a better solution
|
2021-03-22 04:44:22 +00:00
|
|
|
defined_servers = self.controller.list_defined_servers()
|
2021-04-03 17:36:01 +00:00
|
|
|
exec_user_role.add("Super User")
|
2021-09-06 17:27:01 +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:
|
|
|
|
exec_user_crafty_permissions = self.controller.crafty_perms.get_api_key_permissions_list(api_key)
|
|
|
|
else:
|
|
|
|
exec_user_crafty_permissions = self.controller.crafty_perms.get_crafty_permissions_list(
|
|
|
|
exec_user["user_id"])
|
2021-04-03 17:36:01 +00:00
|
|
|
logger.debug(exec_user['roles'])
|
|
|
|
for r in exec_user['roles']:
|
2021-09-08 22:01:10 +00:00
|
|
|
role = self.controller.roles.get_role(r)
|
2021-04-03 17:36:01 +00:00
|
|
|
exec_user_role.add(role['role_name'])
|
2022-01-15 00:23:50 +00:00
|
|
|
defined_servers = self.controller.servers.get_authorized_servers(exec_user["user_id"])
|
2020-08-19 01:04:43 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
page_data: Dict[str, Any] = {
|
2020-09-23 01:43:22 +00:00
|
|
|
# todo: make this actually pull and compare version data
|
2020-09-23 01:42:41 +00:00
|
|
|
'update_available': False,
|
2022-01-14 21:06:02 +00:00
|
|
|
'serverTZ':get_localzone(),
|
2020-09-01 17:29:39 +00:00
|
|
|
'version_data': helper.get_version_string(),
|
2022-01-15 00:23:50 +00:00
|
|
|
'user_data': exec_user,
|
2021-04-03 17:36:01 +00:00
|
|
|
'user_role' : exec_user_role,
|
2021-08-24 21:07:00 +00:00
|
|
|
'user_crafty_permissions' : exec_user_crafty_permissions,
|
|
|
|
'crafty_permissions': {
|
|
|
|
'Server_Creation': Enum_Permissions_Crafty.Server_Creation,
|
|
|
|
'User_Config': Enum_Permissions_Crafty.User_Config,
|
|
|
|
'Roles_Config': Enum_Permissions_Crafty.Roles_Config,
|
|
|
|
},
|
2020-08-19 01:04:43 +00:00
|
|
|
'server_stats': {
|
2020-08-24 17:08:17 +00:00
|
|
|
'total': len(defined_servers),
|
2021-03-22 04:02:18 +00:00
|
|
|
'running': len(self.controller.list_running_servers()),
|
|
|
|
'stopped': (len(self.controller.list_defined_servers()) - len(self.controller.list_running_servers()))
|
2020-08-19 01:04:43 +00:00
|
|
|
},
|
2021-08-06 17:47:06 +00:00
|
|
|
'menu_servers': defined_servers,
|
2021-09-08 22:01:10 +00:00
|
|
|
'hosts_data': self.controller.management.get_latest_hosts_stats(),
|
2020-09-01 17:29:39 +00:00
|
|
|
'show_contribute': helper.get_setting("show_contribute_link", True),
|
2020-12-14 21:52:46 +00:00
|
|
|
'error': error,
|
2022-01-15 00:23:50 +00:00
|
|
|
'time': formatted_time,
|
|
|
|
'lang': self.controller.users.get_user_lang_by_id(exec_user["user_id"]),
|
|
|
|
'super_user': superuser,
|
|
|
|
'api_key': {
|
|
|
|
'name': api_key.name,
|
|
|
|
'created': api_key.created,
|
|
|
|
'server_permissions': api_key.server_permissions,
|
|
|
|
'crafty_permissions': api_key.crafty_permissions,
|
|
|
|
'superuser': api_key.superuser
|
|
|
|
} if api_key is not None else None,
|
|
|
|
'superuser': superuser
|
2020-08-13 14:38:36 +00:00
|
|
|
}
|
2022-01-18 21:44:36 +00:00
|
|
|
if helper.get_setting("allow_nsfw_profile_pictures"):
|
|
|
|
rating = "x"
|
|
|
|
else:
|
|
|
|
rating = "g"
|
|
|
|
|
|
|
|
|
|
|
|
#Get grvatar hash for profile pictures
|
|
|
|
if exec_user['email'] != 'default@example.com' or "":
|
|
|
|
g = libgravatar.Gravatar(libgravatar.sanitize_email(exec_user['email']))
|
|
|
|
url = g.get_image(size=80, default="404", force_default=False, rating=rating, filetype_extension=False, use_ssl=True) # + "?d=404"
|
|
|
|
if requests.head(url).status_code != 404:
|
|
|
|
profile_url = url
|
|
|
|
else:
|
|
|
|
profile_url = "/static/assets/images/faces-clipart/pic-3.png"
|
|
|
|
else:
|
|
|
|
profile_url = "/static/assets/images/faces-clipart/pic-3.png"
|
|
|
|
|
|
|
|
page_data['user_image'] = profile_url
|
2020-08-13 14:38:36 +00:00
|
|
|
|
|
|
|
if page == 'unauthorized':
|
|
|
|
template = "panel/denied.html"
|
|
|
|
|
2020-09-01 17:29:39 +00:00
|
|
|
elif page == "error":
|
|
|
|
template = "public/error.html"
|
|
|
|
|
2020-08-28 03:21:55 +00:00
|
|
|
elif page == 'credits':
|
2022-01-26 01:45:30 +00:00
|
|
|
with open(helper.credits_cache, encoding='utf-8') as republic_credits_will_do:
|
2022-01-15 00:23:50 +00:00
|
|
|
credits_dict: dict = json.load(republic_credits_will_do)
|
|
|
|
timestamp = credits_dict["lastUpdate"] / 1000.0
|
|
|
|
page_data["patrons"] = credits_dict["patrons"]
|
|
|
|
page_data["staff"] = credits_dict["staff"]
|
|
|
|
page_data["translations"] = credits_dict["translations"]
|
2021-11-18 21:08:19 +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"
|
|
|
|
|
2020-08-28 18:38:42 +00:00
|
|
|
elif page == 'contribute':
|
|
|
|
template = "panel/contribute.html"
|
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
elif page == 'dashboard':
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser: # TODO: Figure out a better solution
|
2021-11-29 21:22:46 +00:00
|
|
|
try:
|
|
|
|
page_data['servers'] = self.controller.servers.get_all_servers_stats()
|
|
|
|
except IndexError:
|
|
|
|
self.controller.stats.record_stats()
|
|
|
|
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-01-15 00:23:50 +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:
|
|
|
|
self.controller.stats.record_stats()
|
2022-01-15 00:23:50 +00:00
|
|
|
user_auth = self.controller.servers.get_authorized_servers_stats(exec_user["user_id"])
|
|
|
|
logger.debug(f"ASFR: {user_auth}")
|
2021-08-06 04:34:57 +00:00
|
|
|
page_data['servers'] = user_auth
|
2022-01-15 00:23:50 +00:00
|
|
|
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']
|
|
|
|
|
2022-01-28 01:43:23 +00:00
|
|
|
for data in page_data['servers']:
|
|
|
|
data['stats']['crashed'] = self.controller.servers.is_crashed(
|
|
|
|
str(data['stats']['server_id']['server_id']))
|
|
|
|
try:
|
|
|
|
data['stats']['waiting_start'] = self.controller.servers.get_waiting_start(
|
|
|
|
str(data['stats']['server_id']['server_id']))
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(f"Failed to get server waiting to start: {e}")
|
|
|
|
data['stats']['waiting_start'] = False
|
2021-09-28 16:41:54 +00:00
|
|
|
|
2022-01-15 01:05:50 +00:00
|
|
|
try:
|
|
|
|
self.fetch_server_data(page_data)
|
|
|
|
except:
|
|
|
|
page_data['num_players'] = 0
|
2021-09-28 16:41:54 +00:00
|
|
|
|
2021-12-17 02:07:36 +00:00
|
|
|
IOLoop.current().add_callback(self.fetch_server_data, page_data)
|
2020-08-28 03:21:55 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
template = "panel/dashboard.html"
|
|
|
|
|
2020-08-31 17:46:25 +00:00
|
|
|
elif page == 'server_detail':
|
2020-09-01 17:29:39 +00:00
|
|
|
subpage = bleach.clean(self.get_argument('subpage', ""))
|
|
|
|
|
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-09 22:17:50 +00:00
|
|
|
|
2021-11-30 20:46:30 +00:00
|
|
|
valid_subpages = ['term', 'logs', 'backup', 'config', 'files', 'admin_controls', 'tasks']
|
2020-09-01 17:29:39 +00:00
|
|
|
|
|
|
|
if subpage not in valid_subpages:
|
2021-01-19 13:56:00 +00:00
|
|
|
logger.debug('not a valid subpage')
|
2020-09-01 17:29:39 +00:00
|
|
|
subpage = 'term'
|
2022-01-26 01:45:30 +00:00
|
|
|
logger.debug(f'Subpage: "{subpage}"')
|
2020-09-01 17:29:39 +00:00
|
|
|
|
2021-03-22 04:02:18 +00:00
|
|
|
server = self.controller.get_server_obj(server_id)
|
2020-09-01 17:29:39 +00:00
|
|
|
# server_data isn't needed since the server_stats also pulls server data
|
2021-09-08 22:01:10 +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)
|
2021-09-25 15:56:12 +00:00
|
|
|
try:
|
2021-09-25 20:58:01 +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}")
|
2021-09-25 15:56:12 +00:00
|
|
|
page_data['waiting_start'] = False
|
2021-03-22 04:02:18 +00:00
|
|
|
page_data['get_players'] = lambda: self.controller.stats.get_server_players(server_id)
|
2021-08-21 08:44:03 +00:00
|
|
|
page_data['active_link'] = subpage
|
|
|
|
page_data['permissions'] = {
|
2021-08-22 09:57:02 +00:00
|
|
|
'Commands': Enum_Permissions_Server.Commands,
|
|
|
|
'Terminal': Enum_Permissions_Server.Terminal,
|
|
|
|
'Logs': Enum_Permissions_Server.Logs,
|
|
|
|
'Schedule': Enum_Permissions_Server.Schedule,
|
|
|
|
'Backup': Enum_Permissions_Server.Backup,
|
|
|
|
'Files': Enum_Permissions_Server.Files,
|
|
|
|
'Config': Enum_Permissions_Server.Config,
|
|
|
|
'Players': Enum_Permissions_Server.Players,
|
2021-08-21 08:44:03 +00:00
|
|
|
}
|
2022-01-15 00:23:50 +00:00
|
|
|
page_data['user_permissions'] = self.controller.server_perms.get_user_id_permissions_list(exec_user["user_id"], server_id)
|
2022-01-28 01:43:23 +00:00
|
|
|
page_data['server_stats']['crashed'] = self.controller.servers.is_crashed(server_id)
|
2021-11-30 17:29:53 +00:00
|
|
|
|
|
|
|
if subpage == 'term':
|
|
|
|
if not page_data['permissions']['Terminal'] 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 to Terminal")
|
2021-11-30 19:37:45 +00:00
|
|
|
return
|
2021-11-30 17:29:53 +00:00
|
|
|
|
|
|
|
if subpage == 'logs':
|
|
|
|
if not page_data['permissions']['Logs'] in page_data['user_permissions']:
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2022-01-26 01:45:30 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access to Logs")
|
|
|
|
return
|
2021-11-30 17:29:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
if subpage == 'tasks':
|
|
|
|
if not page_data['permissions']['Schedule'] 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 To Scheduled Tasks")
|
2021-11-30 19:37:45 +00:00
|
|
|
return
|
2021-11-30 20:46:30 +00:00
|
|
|
page_data['schedules'] = management_helper.get_schedules_by_server(server_id)
|
2021-11-30 17:29:53 +00:00
|
|
|
|
|
|
|
if subpage == 'config':
|
|
|
|
if not page_data['permissions']['Config'] 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 Server Config")
|
2021-11-30 19:37:45 +00:00
|
|
|
return
|
2021-11-30 17:29:53 +00:00
|
|
|
|
|
|
|
if subpage == 'files':
|
|
|
|
if not page_data['permissions']['Files'] 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 Files")
|
2021-11-30 19:37:45 +00:00
|
|
|
return
|
2021-11-30 17:29:53 +00:00
|
|
|
|
2021-08-21 08:44:03 +00:00
|
|
|
|
2021-03-22 04:02:18 +00:00
|
|
|
if subpage == "backup":
|
2021-11-30 17:29:53 +00:00
|
|
|
if not page_data['permissions']['Backup'] 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 to Backups")
|
2021-11-30 19:37:45 +00:00
|
|
|
return
|
2021-11-20 03:17:24 +00:00
|
|
|
server_info = self.controller.servers.get_server_data_by_id(server_id)
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['backup_config'] = self.controller.management.get_backup_config(server_id)
|
2021-11-29 21:22:46 +00:00
|
|
|
self.controller.refresh_server_settings(server_id)
|
|
|
|
try:
|
|
|
|
page_data['backup_list'] = server.list_backups()
|
|
|
|
except:
|
|
|
|
page_data['backup_list'] = []
|
2021-11-21 10:52:29 +00:00
|
|
|
page_data['backup_path'] = helper.wtol_path(server_info["backup_path"])
|
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
|
|
|
|
if subpage == "admin_controls":
|
2021-11-30 17:29:53 +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")
|
2021-03-05 08:58:38 +00:00
|
|
|
page_data['banned_players'] = get_banned_players_html()
|
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
|
|
|
|
2021-03-22 04:02:18 +00:00
|
|
|
elif page == 'download_backup':
|
|
|
|
file = self.get_argument('file', "")
|
|
|
|
|
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)
|
2021-11-21 10:52:29 +00:00
|
|
|
backup_file = os.path.abspath(os.path.join(helper.get_os_understandable_path(server_info["backup_path"]), file))
|
|
|
|
if not helper.in_path(helper.get_os_understandable_path(server_info["backup_path"]), backup_file) \
|
2021-03-22 04:02:18 +00:00
|
|
|
or not os.path.isfile(backup_file):
|
|
|
|
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
|
|
|
|
|
|
|
elif page == 'backup_now':
|
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
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
server = self.controller.get_server_obj(server_id)
|
2021-03-22 04:02:18 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
server.backup_server()
|
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
|
|
|
|
2020-12-06 20:42:49 +00:00
|
|
|
elif page == 'panel_config':
|
2021-08-08 20:43:04 +00:00
|
|
|
auth_servers = {}
|
|
|
|
auth_role_servers = {}
|
2021-08-09 21:11:45 +00:00
|
|
|
users_list = []
|
|
|
|
role_users = {}
|
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():
|
|
|
|
user_roles_list = self.controller.users.get_user_roles_names(user.user_id)
|
|
|
|
user_servers = self.controller.servers.get_authorized_servers(user.user_id)
|
2021-08-08 20:43:04 +00:00
|
|
|
servers = []
|
|
|
|
for server in user_servers:
|
2021-11-17 18:08:41 +00:00
|
|
|
if server['server_name'] not in servers:
|
|
|
|
servers.append(server['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)
|
2021-08-08 20:43:04 +00:00
|
|
|
for serv_id in role['servers']:
|
2021-09-08 22:01:10 +00:00
|
|
|
role_servers.append(self.controller.servers.get_server_data_by_id(serv_id)['server_name'])
|
2021-08-08 20:43:04 +00:00
|
|
|
data = {role['role_id']: role_servers}
|
|
|
|
auth_role_servers.update(data)
|
|
|
|
|
2021-08-09 21:11:45 +00:00
|
|
|
|
2021-08-08 20:43:04 +00:00
|
|
|
page_data['auth-servers'] = auth_servers
|
|
|
|
page_data['role-servers'] = auth_role_servers
|
|
|
|
page_data['user-roles'] = user_roles
|
|
|
|
|
2022-01-09 23:04:54 +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
|
|
|
|
2020-12-26 03:00:28 +00:00
|
|
|
for user in page_data['users']:
|
|
|
|
if user.user_id != exec_user['user_id']:
|
|
|
|
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-01-09 23:04:54 +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
|
|
|
|
|
2020-12-06 20:42:49 +00:00
|
|
|
template = "panel/panel_config.html"
|
2020-08-31 17:46:25 +00:00
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
elif page == "add_user":
|
|
|
|
page_data['new_user'] = True
|
|
|
|
page_data['user'] = {}
|
|
|
|
page_data['user']['username'] = ""
|
|
|
|
page_data['user']['user_id'] = -1
|
2022-01-08 23:03:45 +00:00
|
|
|
page_data['user']['email'] = ""
|
2020-12-24 22:55:15 +00:00
|
|
|
page_data['user']['enabled'] = True
|
|
|
|
page_data['user']['superuser'] = False
|
2020-12-26 03:00:28 +00:00
|
|
|
page_data['user']['created'] = "N/A"
|
|
|
|
page_data['user']['last_login'] = "N/A"
|
|
|
|
page_data['user']['last_ip'] = "N/A"
|
2021-03-09 22:17:50 +00:00
|
|
|
page_data['user']['last_update'] = "N/A"
|
2020-12-26 03:00:28 +00:00
|
|
|
page_data['user']['roles'] = set()
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2021-08-24 21:07:00 +00:00
|
|
|
if Enum_Permissions_Crafty.User_Config not in exec_user_crafty_permissions:
|
|
|
|
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
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['roles_all'] = self.controller.roles.get_all_roles()
|
2021-04-03 17:36:01 +00:00
|
|
|
page_data['servers'] = []
|
2021-03-22 04:02:18 +00:00
|
|
|
page_data['servers_all'] = self.controller.list_defined_servers()
|
2021-08-09 05:44:16 +00:00
|
|
|
page_data['role-servers'] = []
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['permissions_all'] = self.controller.crafty_perms.list_defined_crafty_permissions()
|
2021-08-24 21:07:00 +00:00
|
|
|
page_data['permissions_list'] = set()
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['quantity_server'] = self.controller.crafty_perms.list_all_crafty_permissions_quantity_limits()
|
2021-09-29 21:46:54 +00:00
|
|
|
page_data['languages'] = []
|
2022-01-15 00:23:50 +00:00
|
|
|
page_data['languages'].append(self.controller.users.get_user_lang_by_id(exec_user["user_id"]))
|
|
|
|
if superuser:
|
2022-01-10 04:16:11 +00:00
|
|
|
page_data['super-disabled'] = ''
|
|
|
|
else:
|
|
|
|
page_data['super-disabled'] = 'disabled'
|
2021-09-29 21:46:54 +00:00
|
|
|
for file in os.listdir(os.path.join(helper.root_dir, 'app', 'translations')):
|
|
|
|
if file.endswith('.json'):
|
2021-09-29 23:32:21 +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
|
|
|
|
2022-01-11 22:24:05 +00:00
|
|
|
elif page == "add_schedule":
|
|
|
|
server_id = self.get_argument('id', None)
|
|
|
|
page_data['get_players'] = lambda: self.controller.stats.get_server_players(server_id)
|
|
|
|
page_data['active_link'] = 'tasks'
|
|
|
|
page_data['permissions'] = {
|
|
|
|
'Commands': Enum_Permissions_Server.Commands,
|
|
|
|
'Terminal': Enum_Permissions_Server.Terminal,
|
|
|
|
'Logs': Enum_Permissions_Server.Logs,
|
|
|
|
'Schedule': Enum_Permissions_Server.Schedule,
|
|
|
|
'Backup': Enum_Permissions_Server.Backup,
|
|
|
|
'Files': Enum_Permissions_Server.Files,
|
|
|
|
'Config': Enum_Permissions_Server.Config,
|
|
|
|
'Players': Enum_Permissions_Server.Players,
|
|
|
|
}
|
2022-01-15 00:23:50 +00:00
|
|
|
page_data['user_permissions'] = self.controller.server_perms.get_user_id_permissions_list(exec_user["user_id"], server_id)
|
2022-01-11 22:24:05 +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)
|
|
|
|
page_data['new_schedule'] = True
|
|
|
|
page_data['schedule'] = {}
|
|
|
|
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'] = ""
|
|
|
|
page_data['schedule']['time'] = ""
|
|
|
|
page_data['schedule']['interval'] = ""
|
|
|
|
#we don't need to check difficulty here. We'll just default to basic for new schedules
|
|
|
|
page_data['schedule']['difficulty'] = "basic"
|
|
|
|
page_data['schedule']['interval_type'] = 'days'
|
|
|
|
|
2022-01-19 18:07:26 +00:00
|
|
|
if not Enum_Permissions_Server.Schedule in page_data['user_permissions']:
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2022-01-11 22:24:05 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access To Scheduled Tasks")
|
|
|
|
return
|
|
|
|
|
|
|
|
template = "panel/server_schedule_edit.html"
|
|
|
|
|
|
|
|
elif page == "edit_schedule":
|
|
|
|
server_id = self.get_argument('id', None)
|
|
|
|
sch_id = self.get_argument('sch_id', None)
|
|
|
|
schedule = self.controller.management.get_scheduled_task_model(sch_id)
|
|
|
|
page_data['get_players'] = lambda: self.controller.stats.get_server_players(server_id)
|
|
|
|
page_data['active_link'] = 'tasks'
|
|
|
|
page_data['permissions'] = {
|
|
|
|
'Commands': Enum_Permissions_Server.Commands,
|
|
|
|
'Terminal': Enum_Permissions_Server.Terminal,
|
|
|
|
'Logs': Enum_Permissions_Server.Logs,
|
|
|
|
'Schedule': Enum_Permissions_Server.Schedule,
|
|
|
|
'Backup': Enum_Permissions_Server.Backup,
|
|
|
|
'Files': Enum_Permissions_Server.Files,
|
|
|
|
'Config': Enum_Permissions_Server.Config,
|
|
|
|
'Players': Enum_Permissions_Server.Players,
|
|
|
|
}
|
2022-01-15 00:23:50 +00:00
|
|
|
page_data['user_permissions'] = self.controller.server_perms.get_user_id_permissions_list(exec_user["user_id"], server_id)
|
2022-01-11 22:24:05 +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)
|
|
|
|
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-01-26 01:45:30 +00:00
|
|
|
# We check here to see if the command is any of the default ones.
|
|
|
|
# We do not want a user changing to a custom command and seeing our command there.
|
2022-01-11 22:24:05 +00:00
|
|
|
if schedule.action != 'start' or schedule.action != 'stop' or schedule.action != 'restart' or schedule.action != 'backup':
|
|
|
|
page_data['schedule']['command'] = schedule.command
|
|
|
|
else:
|
|
|
|
page_data['schedule']['command'] = ''
|
|
|
|
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.cron_string == '':
|
|
|
|
difficulty = 'basic'
|
|
|
|
else:
|
|
|
|
difficulty = 'advanced'
|
|
|
|
page_data['schedule']['difficulty'] = difficulty
|
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
if sch_id is None or server_id is None:
|
2022-01-11 22:24:05 +00:00
|
|
|
self.redirect("/panel/error?error=Invalid server ID or Schedule ID")
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2022-01-19 18:07:26 +00:00
|
|
|
if not Enum_Permissions_Server.Schedule in page_data['user_permissions']:
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2022-01-11 22:24:05 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access To Scheduled Tasks")
|
|
|
|
return
|
|
|
|
|
|
|
|
template = "panel/server_schedule_edit.html"
|
2020-12-24 22:55:15 +00:00
|
|
|
|
|
|
|
elif page == "edit_user":
|
2020-12-27 16:00:26 +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 = []
|
2021-08-06 04:34:57 +00:00
|
|
|
servers = set()
|
2021-08-08 22:26:28 +00:00
|
|
|
for server in role_servers:
|
|
|
|
page_role_servers.append(server['server_id'])
|
2021-08-06 04:34:57 +00:00
|
|
|
page_data['new_user'] = False
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['user'] = self.controller.users.get_user_by_id(user_id)
|
2021-08-06 04:34:57 +00:00
|
|
|
page_data['servers'] = servers
|
2021-08-08 22:26:28 +00:00
|
|
|
page_data['role-servers'] = page_role_servers
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['roles_all'] = self.controller.roles.get_all_roles()
|
2021-03-22 04:02:18 +00:00
|
|
|
page_data['servers_all'] = self.controller.list_defined_servers()
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['permissions_all'] = self.controller.crafty_perms.list_defined_crafty_permissions()
|
2021-09-06 17:27:01 +00:00
|
|
|
page_data['permissions_list'] = self.controller.crafty_perms.get_crafty_permissions_list(user_id)
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['quantity_server'] = self.controller.crafty_perms.list_crafty_permissions_quantity_limits(user_id)
|
2021-09-29 21:46:54 +00:00
|
|
|
page_data['languages'] = []
|
2021-09-29 23:50:51 +00:00
|
|
|
page_data['languages'].append(self.controller.users.get_user_lang_by_id(user_id))
|
2022-01-09 23:04:54 +00:00
|
|
|
#checks if super user. If not we disable the button.
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser and str(exec_user['user_id']) != str(user_id):
|
2022-01-09 23:04:54 +00:00
|
|
|
page_data['super-disabled'] = ''
|
|
|
|
else:
|
|
|
|
page_data['super-disabled'] = 'disabled'
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2021-12-21 20:39:33 +00:00
|
|
|
for file in sorted(os.listdir(os.path.join(helper.root_dir, 'app', 'translations'))):
|
2021-09-29 21:46:54 +00:00
|
|
|
if file.endswith('.json'):
|
2021-09-29 23:32:21 +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
|
2021-08-24 21:07:00 +00:00
|
|
|
elif Enum_Permissions_Crafty.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"]):
|
2021-08-24 21:07:00 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not a user editor")
|
|
|
|
return
|
|
|
|
|
2021-08-09 05:29:13 +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
|
|
|
|
2020-12-26 03:00:28 +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
|
|
|
|
|
|
|
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":
|
|
|
|
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)
|
|
|
|
# self.controller.crafty_perms.list_defined_crafty_permissions()
|
|
|
|
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()
|
|
|
|
|
|
|
|
if user_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return
|
|
|
|
|
|
|
|
template = "panel/panel_edit_user_apikeys.html"
|
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
elif page == "remove_user":
|
|
|
|
user_id = bleach.clean(self.get_argument('id', None))
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser and Enum_Permissions_Crafty.User_Config 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-01-15 00:23:50 +00:00
|
|
|
elif str(exec_user["user_id"]) == str(user_id):
|
2022-01-10 04:34:11 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access: you cannot delete yourself")
|
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
elif user_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
else:
|
|
|
|
# does this user id exist?
|
2021-09-08 22:01:10 +00:00
|
|
|
target_user = self.controller.users.get_user_by_id(user_id)
|
2020-12-24 22:55:15 +00:00
|
|
|
if not target_user:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
elif target_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Cannot remove a superuser")
|
2021-03-22 04:02:18 +00:00
|
|
|
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
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-15 00:23:50 +00:00
|
|
|
f"Removed user {target_user['username']} (UID:{user_id})",
|
2020-12-24 22:55:15 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
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()
|
2020-12-27 16:00:26 +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()
|
2021-08-09 21:18:02 +00:00
|
|
|
page_data['user-roles'] = user_roles
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['users'] = self.controller.users.get_all_users()
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2021-08-24 21:07:00 +00:00
|
|
|
if Enum_Permissions_Crafty.Roles_Config not in exec_user_crafty_permissions:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not a role editor")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2021-03-22 04:02:18 +00:00
|
|
|
page_data['servers_all'] = self.controller.list_defined_servers()
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['permissions_all'] = self.controller.server_perms.list_defined_permissions()
|
2021-08-19 22:18:50 +00:00
|
|
|
page_data['permissions_list'] = set()
|
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()
|
2020-12-27 16:00:26 +00:00
|
|
|
page_data['new_role'] = False
|
|
|
|
role_id = self.get_argument('id', None)
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['role'] = self.controller.roles.get_role_with_servers(role_id)
|
2021-03-22 04:02:18 +00:00
|
|
|
page_data['servers_all'] = self.controller.list_defined_servers()
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['permissions_all'] = self.controller.server_perms.list_defined_permissions()
|
|
|
|
page_data['permissions_list'] = self.controller.server_perms.get_role_permissions(role_id)
|
2021-08-09 21:11:45 +00:00
|
|
|
page_data['user-roles'] = user_roles
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['users'] = self.controller.users.get_all_users()
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2021-08-24 21:07:00 +00:00
|
|
|
if Enum_Permissions_Crafty.Roles_Config not in exec_user_crafty_permissions:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not a role editor")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-27 16:00:26 +00:00
|
|
|
elif role_id is None:
|
|
|
|
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"
|
|
|
|
|
|
|
|
elif page == "remove_role":
|
|
|
|
role_id = bleach.clean(self.get_argument('id', None))
|
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2020-12-27 16:00:26 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-27 16:00:26 +00:00
|
|
|
elif role_id is None:
|
|
|
|
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
|
|
|
else:
|
|
|
|
# does this user id exist?
|
2021-09-08 22:01:10 +00:00
|
|
|
target_role = self.controller.roles.get_role(role_id)
|
2020-12-27 16:00:26 +00:00
|
|
|
if not target_role:
|
|
|
|
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
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.roles.remove_role(role_id)
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-15 00:23:50 +00:00
|
|
|
f"Removed role {target_role['role_name']} (RID:{role_id})",
|
2020-12-27 16:00:26 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
|
2020-12-13 18:40:55 +00:00
|
|
|
elif page == "activity_logs":
|
2021-09-08 22:01:10 +00:00
|
|
|
page_data['audit_logs'] = self.controller.management.get_actity_log()
|
2020-12-13 18:40:55 +00:00
|
|
|
|
|
|
|
template = "panel/activity_logs.html"
|
|
|
|
|
2021-08-25 01:33:29 +00:00
|
|
|
elif page == 'download_file':
|
2021-11-21 10:52:29 +00:00
|
|
|
file = helper.get_os_understandable_path(self.get_argument('path', ""))
|
2021-08-25 01:33:29 +00:00
|
|
|
name = 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
|
|
|
|
2021-11-21 10:52:29 +00:00
|
|
|
if not helper.in_path(helper.get_os_understandable_path(server_info["path"]), file) \
|
2021-08-25 01:33:29 +00:00
|
|
|
or not os.path.isfile(file):
|
|
|
|
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-01-14 01:42:53 +00:00
|
|
|
elif page == 'download_support_package':
|
|
|
|
tempZipStorage = exec_user['support_logs']
|
|
|
|
#We'll reset the support path for this user now.
|
2022-01-15 00:23:50 +00:00
|
|
|
self.controller.users.set_support_path(exec_user["user_id"], "")
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2022-01-13 02:12:28 +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-01-14 01:42:53 +00:00
|
|
|
if tempZipStorage != '':
|
|
|
|
with open(tempZipStorage, 'rb') as f:
|
|
|
|
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
|
|
|
|
self.redirect('/panel/dashboard')
|
|
|
|
else:
|
|
|
|
self.redirect('/panel/error?error=No path found for support logs')
|
|
|
|
return
|
2022-01-13 02:12:28 +00:00
|
|
|
|
2022-01-14 01:42:53 +00:00
|
|
|
elif page == "support_logs":
|
2022-01-26 01:45:30 +00:00
|
|
|
logger.info(f"Support logs requested. Packinging logs for user with ID: {exec_user['user_id']}")
|
|
|
|
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()
|
|
|
|
self.redirect('/panel/dashboard')
|
|
|
|
return
|
2022-01-13 02:12:28 +00:00
|
|
|
|
|
|
|
|
2021-08-25 01:33:29 +00:00
|
|
|
|
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
|
|
|
)
|
2020-09-04 16:35:06 +00:00
|
|
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
def post(self, page):
|
2022-01-26 01:45:30 +00:00
|
|
|
# pylint: disable=unused-variable
|
2022-01-15 00:23:50 +00:00
|
|
|
api_key, token_data, exec_user = self.current_user
|
|
|
|
superuser = exec_user['superuser']
|
|
|
|
if api_key is not None:
|
|
|
|
superuser = superuser and api_key.superuser
|
|
|
|
|
2021-11-30 19:37:45 +00:00
|
|
|
server_id = self.get_argument('id', None)
|
|
|
|
permissions = {
|
|
|
|
'Commands': Enum_Permissions_Server.Commands,
|
|
|
|
'Terminal': Enum_Permissions_Server.Terminal,
|
|
|
|
'Logs': Enum_Permissions_Server.Logs,
|
|
|
|
'Schedule': Enum_Permissions_Server.Schedule,
|
|
|
|
'Backup': Enum_Permissions_Server.Backup,
|
|
|
|
'Files': Enum_Permissions_Server.Files,
|
|
|
|
'Config': Enum_Permissions_Server.Config,
|
|
|
|
'Players': Enum_Permissions_Server.Players,
|
|
|
|
}
|
2021-04-03 17:36:01 +00:00
|
|
|
exec_user_role = set()
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser:
|
|
|
|
# defined_servers = self.controller.list_defined_servers()
|
2021-04-03 17:36:01 +00:00
|
|
|
exec_user_role.add("Super User")
|
2021-09-08 22:01:10 +00:00
|
|
|
exec_user_crafty_permissions = self.controller.crafty_perms.list_defined_crafty_permissions()
|
2021-04-03 17:36:01 +00:00
|
|
|
else:
|
2022-01-15 00:23:50 +00:00
|
|
|
exec_user_crafty_permissions = self.controller.crafty_perms.get_crafty_permissions_list(exec_user["user_id"])
|
|
|
|
# defined_servers = self.controller.servers.get_authorized_servers(exec_user["user_id"])
|
2021-04-03 17:36:01 +00:00
|
|
|
for r in exec_user['roles']:
|
2021-09-08 22:01:10 +00:00
|
|
|
role = self.controller.roles.get_role(r)
|
2021-04-03 17:36:01 +00:00
|
|
|
exec_user_role.add(role['role_name'])
|
2020-09-04 16:35:06 +00:00
|
|
|
|
|
|
|
if page == 'server_detail':
|
2022-01-20 19:14:03 +00:00
|
|
|
if not permissions['Config'] in self.controller.server_perms.get_user_id_permissions_list(exec_user["user_id"], server_id):
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2022-01-26 01:45:30 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access to Config")
|
2022-01-15 00:23:50 +00:00
|
|
|
return
|
2020-09-04 16:35:06 +00:00
|
|
|
server_name = self.get_argument('server_name', None)
|
2021-11-30 19:37:45 +00:00
|
|
|
server_obj = self.controller.servers.get_server_obj(server_id)
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser:
|
2021-11-30 19:37:45 +00:00
|
|
|
server_path = self.get_argument('server_path', None)
|
2022-01-19 20:14:56 +00:00
|
|
|
if helper.is_os_windows():
|
2022-01-19 22:08:29 +00:00
|
|
|
server_path.replace(' ', '^ ')
|
2022-01-19 20:14:56 +00:00
|
|
|
server_path = helper.wtol_path(server_path)
|
2021-11-30 19:37:45 +00:00
|
|
|
log_path = self.get_argument('log_path', None)
|
2022-01-19 20:14:56 +00:00
|
|
|
if helper.is_os_windows():
|
2022-01-19 22:08:29 +00:00
|
|
|
log_path.replace(' ', '^ ')
|
2022-01-19 20:14:56 +00:00
|
|
|
log_path = helper.wtol_path(log_path)
|
2021-11-30 19:37:45 +00:00
|
|
|
executable = self.get_argument('executable', None)
|
|
|
|
execution_command = self.get_argument('execution_command', None)
|
|
|
|
server_ip = self.get_argument('server_ip', None)
|
|
|
|
server_port = self.get_argument('server_port', None)
|
|
|
|
executable_update_url = self.get_argument('executable_update_url', None)
|
|
|
|
else:
|
|
|
|
execution_command = server_obj.execution_command
|
|
|
|
executable = server_obj.executable
|
2020-09-04 16:35:06 +00:00
|
|
|
stop_command = self.get_argument('stop_command', None)
|
2020-09-04 18:05:42 +00:00
|
|
|
auto_start_delay = self.get_argument('auto_start_delay', '10')
|
|
|
|
auto_start = int(float(self.get_argument('auto_start', '0')))
|
|
|
|
crash_detection = int(float(self.get_argument('crash_detection', '0')))
|
2021-01-20 15:20:42 +00:00
|
|
|
logs_delete_after = int(float(self.get_argument('logs_delete_after', '0')))
|
2022-01-15 00:23:50 +00:00
|
|
|
# subpage = self.get_argument('subpage', None)
|
2020-09-04 16:35:06 +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
|
2020-09-04 16:35:06 +00:00
|
|
|
|
2021-11-21 10:52:29 +00:00
|
|
|
server_obj = self.controller.servers.get_server_obj(server_id)
|
2021-11-27 19:29:28 +00:00
|
|
|
stale_executable = server_obj.executable
|
2021-11-28 00:28:53 +00:00
|
|
|
#Compares old jar name to page data being passed. If they are different we replace the executable name in the
|
2021-11-27 19:29:28 +00:00
|
|
|
if str(stale_executable) != str(executable):
|
|
|
|
execution_command = execution_command.replace(str(stale_executable), str(executable))
|
|
|
|
|
2021-11-21 10:52:29 +00:00
|
|
|
server_obj.server_name = server_name
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser:
|
2021-11-28 02:52:49 +00:00
|
|
|
if helper.validate_traversal(helper.get_servers_root_dir(), server_path):
|
|
|
|
server_obj.path = server_path
|
|
|
|
server_obj.log_path = log_path
|
|
|
|
if helper.validate_traversal(helper.get_servers_root_dir(), executable):
|
|
|
|
server_obj.executable = executable
|
|
|
|
server_obj.execution_command = execution_command
|
|
|
|
server_obj.server_ip = server_ip
|
|
|
|
server_obj.server_port = server_port
|
|
|
|
server_obj.executable_update_url = executable_update_url
|
2021-11-30 19:37:45 +00:00
|
|
|
else:
|
|
|
|
server_obj.path = server_obj.path
|
|
|
|
server_obj.log_path = server_obj.log_path
|
|
|
|
server_obj.executable = server_obj.executable
|
|
|
|
print(server_obj.execution_command)
|
|
|
|
server_obj.execution_command = server_obj.execution_command
|
|
|
|
server_obj.server_ip = server_obj.server_ip
|
|
|
|
server_obj.server_port = server_obj.server_port
|
|
|
|
server_obj.executable_update_url = server_obj.executable_update_url
|
|
|
|
server_obj.stop_command = stop_command
|
2021-11-21 10:52:29 +00:00
|
|
|
server_obj.auto_start_delay = auto_start_delay
|
|
|
|
server_obj.auto_start = auto_start
|
|
|
|
server_obj.crash_detection = crash_detection
|
|
|
|
server_obj.logs_delete_after = logs_delete_after
|
|
|
|
self.controller.servers.update_server(server_obj)
|
2020-09-04 16:35:06 +00:00
|
|
|
|
2021-03-22 04:02:18 +00:00
|
|
|
self.controller.refresh_server_settings(server_id)
|
2020-10-07 13:19:47 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-26 01:45:30 +00:00
|
|
|
f"Edited server {server_id} named {server_name}",
|
2020-09-04 18:05:42 +00:00
|
|
|
server_id,
|
|
|
|
self.get_remote_ip())
|
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
self.redirect(f"/panel/server_detail?id={server_id}&subpage=config")
|
2020-12-24 22:55:15 +00:00
|
|
|
|
2021-03-22 04:02:18 +00:00
|
|
|
if page == "server_backup":
|
|
|
|
logger.debug(self.request.arguments)
|
|
|
|
server_id = self.get_argument('id', None)
|
2021-11-30 19:37:45 +00:00
|
|
|
server_obj = self.controller.servers.get_server_obj(server_id)
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser:
|
2021-11-30 19:37:45 +00:00
|
|
|
backup_path = bleach.clean(self.get_argument('backup_path', None))
|
2022-01-19 20:14:56 +00:00
|
|
|
if helper.is_os_windows():
|
2022-01-19 22:08:29 +00:00
|
|
|
backup_path.replace(' ', '^ ')
|
2022-01-19 20:14:56 +00:00
|
|
|
backup_path = helper.wtol_path(backup_path)
|
2021-11-30 19:37:45 +00:00
|
|
|
else:
|
|
|
|
backup_path = server_obj.backup_path
|
2021-03-22 04:02:18 +00:00
|
|
|
max_backups = bleach.clean(self.get_argument('max_backups', None))
|
|
|
|
|
2022-01-20 19:14:03 +00:00
|
|
|
if not permissions['Backup'] in self.controller.server_perms.get_user_id_permissions_list(exec_user["user_id"], server_id):
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2021-11-30 19:37:45 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access: User not authorized")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
|
|
|
elif server_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
# does this server id exist?
|
2021-09-08 22:01:10 +00:00
|
|
|
if not self.controller.servers.server_id_exists(server_id):
|
2021-03-22 04:02:18 +00:00
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return
|
|
|
|
|
2022-01-11 22:24:05 +00:00
|
|
|
server_obj = self.controller.servers.get_server_obj(server_id)
|
|
|
|
server_obj.backup_path = backup_path
|
|
|
|
self.controller.servers.update_server(server_obj)
|
|
|
|
self.controller.management.set_backup_config(server_id, max_backups=max_backups)
|
2021-03-22 04:02:18 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-15 00:23:50 +00:00
|
|
|
f"Edited server {server_id}: updated backups",
|
2021-03-22 04:02:18 +00:00
|
|
|
server_id,
|
|
|
|
self.get_remote_ip())
|
|
|
|
self.tasks_manager.reload_schedule_from_db()
|
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-01-11 23:51:07 +00:00
|
|
|
if page == "new_schedule":
|
2022-01-11 05:26:33 +00:00
|
|
|
server_id = bleach.clean(self.get_argument('id', None))
|
|
|
|
difficulty = bleach.clean(self.get_argument('difficulty', None))
|
2022-01-11 01:11:52 +00:00
|
|
|
server_obj = self.controller.servers.get_server_obj(server_id)
|
2022-01-11 05:26:33 +00:00
|
|
|
enabled = bleach.clean(self.get_argument('enabled', '0'))
|
2022-01-11 01:11:52 +00:00
|
|
|
if difficulty == 'basic':
|
2022-01-11 05:26:33 +00:00
|
|
|
action = bleach.clean(self.get_argument('action', None))
|
|
|
|
interval = bleach.clean(self.get_argument('interval', None))
|
|
|
|
interval_type = bleach.clean(self.get_argument('interval_type', None))
|
2022-01-11 01:11:52 +00:00
|
|
|
#only check for time if it's number of days
|
|
|
|
if interval_type == "days":
|
2022-01-26 01:45:30 +00:00
|
|
|
sch_time = bleach.clean(self.get_argument('time', None))
|
2022-01-11 01:11:52 +00:00
|
|
|
if action == "command":
|
2022-01-11 05:26:33 +00:00
|
|
|
command = bleach.clean(self.get_argument('command', None))
|
2022-01-11 01:11:52 +00:00
|
|
|
elif action == "start":
|
|
|
|
command = "start_server"
|
|
|
|
elif action == "stop":
|
|
|
|
command = "stop_server"
|
|
|
|
elif action == "restart":
|
2022-01-11 05:26:33 +00:00
|
|
|
command = "restart_server"
|
|
|
|
elif action == "backup":
|
|
|
|
command = "backup_server"
|
|
|
|
else:
|
2022-01-11 17:17:57 +00:00
|
|
|
interval_type = ''
|
2022-01-11 05:26:33 +00:00
|
|
|
cron_string = bleach.clean(self.get_argument('cron', ''))
|
2022-01-14 17:57:23 +00:00
|
|
|
try:
|
|
|
|
CronValidator.parse(cron_string)
|
|
|
|
except Exception as e:
|
2022-01-26 01:45:30 +00:00
|
|
|
self.redirect(f"/panel/error?error=INVALID FORMAT: Invalid Cron Format. {e}")
|
2022-01-11 22:41:46 +00:00
|
|
|
return
|
2022-01-11 05:26:33 +00:00
|
|
|
action = bleach.clean(self.get_argument('action', None))
|
|
|
|
if action == "command":
|
|
|
|
command = bleach.clean(self.get_argument('command', None))
|
|
|
|
elif action == "start":
|
|
|
|
command = "start_server"
|
|
|
|
elif action == "stop":
|
|
|
|
command = "stop_server"
|
|
|
|
elif action == "restart":
|
|
|
|
command = "restart_server"
|
|
|
|
elif action == "backup":
|
|
|
|
command = "backup_server"
|
2022-01-12 00:17:20 +00:00
|
|
|
if bleach.clean(self.get_argument('enabled', '0')) == '1':
|
2022-01-11 06:29:27 +00:00
|
|
|
enabled = True
|
|
|
|
else:
|
|
|
|
enabled = False
|
|
|
|
if bleach.clean(self.get_argument('one_time', '0')) == '1':
|
|
|
|
one_time = True
|
|
|
|
else:
|
|
|
|
one_time = False
|
2022-01-26 01:45:30 +00:00
|
|
|
|
|
|
|
if not superuser and not permissions['Backup'] in self.controller.server_perms.get_user_id_permissions_list(exec_user["user_id"],
|
|
|
|
server_id):
|
2022-01-11 01:11:52 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access: User not authorized")
|
|
|
|
return
|
|
|
|
elif server_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
# does this server id exist?
|
|
|
|
if not self.controller.servers.server_id_exists(server_id):
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return
|
|
|
|
|
|
|
|
if interval_type == "days":
|
|
|
|
job_data = {
|
|
|
|
"server_id": server_id,
|
|
|
|
"action": action,
|
|
|
|
"interval_type": interval_type,
|
|
|
|
"interval": interval,
|
|
|
|
"command": command,
|
2022-01-26 01:45:30 +00:00
|
|
|
"start_time": sch_time,
|
2022-01-11 01:11:52 +00:00
|
|
|
"enabled": enabled,
|
2022-01-11 17:17:57 +00:00
|
|
|
"one_time": one_time,
|
|
|
|
"cron_string": ''
|
2022-01-11 01:11:52 +00:00
|
|
|
}
|
2022-01-11 05:26:33 +00:00
|
|
|
elif difficulty == "advanced":
|
2022-01-26 01:45:30 +00:00
|
|
|
job_data = {
|
2022-01-11 05:26:33 +00:00
|
|
|
"server_id": server_id,
|
|
|
|
"action": action,
|
2022-01-11 17:17:57 +00:00
|
|
|
"interval_type": '',
|
|
|
|
"interval": '',
|
2022-01-12 16:33:08 +00:00
|
|
|
#We'll base every interval off of a midnight start time.
|
2022-01-15 07:01:51 +00:00
|
|
|
"start_time": '',
|
2022-01-11 05:26:33 +00:00
|
|
|
"command": command,
|
|
|
|
"cron_string": cron_string,
|
|
|
|
"enabled": enabled,
|
|
|
|
"one_time": one_time
|
|
|
|
}
|
2022-01-11 01:11:52 +00:00
|
|
|
else:
|
|
|
|
job_data = {
|
|
|
|
"server_id": server_id,
|
|
|
|
"action": action,
|
|
|
|
"interval_type": interval_type,
|
|
|
|
"interval": interval,
|
|
|
|
"command": command,
|
|
|
|
"enabled": enabled,
|
2022-01-12 16:33:08 +00:00
|
|
|
#We'll base every interval off of a midnight start time.
|
|
|
|
"start_time": '00:00',
|
2022-01-11 17:17:57 +00:00
|
|
|
"one_time": one_time,
|
|
|
|
"cron_string": ''
|
2022-01-11 01:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.tasks_manager.schedule_job(job_data)
|
|
|
|
|
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-26 01:45:30 +00:00
|
|
|
f"Edited server {server_id}: added scheduled job",
|
2022-01-11 22:24:05 +00:00
|
|
|
server_id,
|
|
|
|
self.get_remote_ip())
|
|
|
|
self.tasks_manager.reload_schedule_from_db()
|
2022-01-26 01:45:30 +00:00
|
|
|
self.redirect(f"/panel/server_detail?id={server_id}&subpage=tasks")
|
2022-01-11 22:24:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
if page == "edit_schedule":
|
|
|
|
server_id = bleach.clean(self.get_argument('id', None))
|
|
|
|
difficulty = bleach.clean(self.get_argument('difficulty', None))
|
|
|
|
server_obj = self.controller.servers.get_server_obj(server_id)
|
|
|
|
enabled = bleach.clean(self.get_argument('enabled', '0'))
|
|
|
|
if difficulty == 'basic':
|
|
|
|
action = bleach.clean(self.get_argument('action', None))
|
|
|
|
interval = bleach.clean(self.get_argument('interval', None))
|
|
|
|
interval_type = bleach.clean(self.get_argument('interval_type', None))
|
|
|
|
#only check for time if it's number of days
|
|
|
|
if interval_type == "days":
|
2022-01-26 01:45:30 +00:00
|
|
|
sch_time = bleach.clean(self.get_argument('time', None))
|
2022-01-11 22:24:05 +00:00
|
|
|
if action == "command":
|
|
|
|
command = bleach.clean(self.get_argument('command', None))
|
|
|
|
elif action == "start":
|
|
|
|
command = "start_server"
|
|
|
|
elif action == "stop":
|
|
|
|
command = "stop_server"
|
|
|
|
elif action == "restart":
|
|
|
|
command = "restart_server"
|
|
|
|
elif action == "backup":
|
|
|
|
command = "backup_server"
|
|
|
|
else:
|
|
|
|
interval_type = ''
|
|
|
|
cron_string = bleach.clean(self.get_argument('cron', ''))
|
|
|
|
sch_id = self.get_argument('sch_id', None)
|
2022-01-14 17:59:33 +00:00
|
|
|
try:
|
|
|
|
CronValidator.parse(cron_string)
|
|
|
|
except Exception as e:
|
2022-01-26 01:45:30 +00:00
|
|
|
self.redirect(f"/panel/error?error=INVALID FORMAT: Invalid Cron Format. {e}")
|
2022-01-11 22:41:46 +00:00
|
|
|
return
|
2022-01-11 22:24:05 +00:00
|
|
|
action = bleach.clean(self.get_argument('action', None))
|
|
|
|
if action == "command":
|
|
|
|
command = bleach.clean(self.get_argument('command', None))
|
|
|
|
elif action == "start":
|
|
|
|
command = "start_server"
|
|
|
|
elif action == "stop":
|
|
|
|
command = "stop_server"
|
|
|
|
elif action == "restart":
|
|
|
|
command = "restart_server"
|
|
|
|
elif action == "backup":
|
|
|
|
command = "backup_server"
|
2022-01-12 00:20:26 +00:00
|
|
|
if bleach.clean(self.get_argument('enabled', '0'))=='1':
|
2022-01-11 22:24:05 +00:00
|
|
|
enabled = True
|
|
|
|
else:
|
|
|
|
enabled = False
|
|
|
|
if bleach.clean(self.get_argument('one_time', '0')) == '1':
|
|
|
|
one_time = True
|
|
|
|
else:
|
|
|
|
one_time = False
|
2022-01-26 01:45:30 +00:00
|
|
|
|
|
|
|
if not superuser and not permissions['Backup'] in self.controller.server_perms.get_user_id_permissions_list(exec_user["user_id"],
|
|
|
|
server_id):
|
2022-01-11 22:24:05 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access: User not authorized")
|
|
|
|
return
|
|
|
|
elif server_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
# does this server id exist?
|
|
|
|
if not self.controller.servers.server_id_exists(server_id):
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return
|
|
|
|
|
|
|
|
if interval_type == "days":
|
|
|
|
job_data = {
|
|
|
|
"server_id": server_id,
|
|
|
|
"action": action,
|
|
|
|
"interval_type": interval_type,
|
|
|
|
"interval": interval,
|
|
|
|
"command": command,
|
2022-01-26 01:45:30 +00:00
|
|
|
"start_time": sch_time,
|
2022-01-11 22:24:05 +00:00
|
|
|
"enabled": enabled,
|
|
|
|
"one_time": one_time,
|
|
|
|
"cron_string": ''
|
|
|
|
}
|
|
|
|
elif difficulty == "advanced":
|
2022-01-26 01:45:30 +00:00
|
|
|
job_data = {
|
2022-01-11 22:24:05 +00:00
|
|
|
"server_id": server_id,
|
|
|
|
"action": action,
|
|
|
|
"interval_type": '',
|
|
|
|
"interval": '',
|
2022-01-12 16:33:08 +00:00
|
|
|
#We'll base every interval off of a midnight start time.
|
2022-01-15 07:01:51 +00:00
|
|
|
"start_time": '',
|
2022-01-11 22:24:05 +00:00
|
|
|
"command": command,
|
|
|
|
"cron_string": cron_string,
|
|
|
|
"enabled": enabled,
|
|
|
|
"one_time": one_time
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
job_data = {
|
|
|
|
"server_id": server_id,
|
|
|
|
"action": action,
|
|
|
|
"interval_type": interval_type,
|
|
|
|
"interval": interval,
|
|
|
|
"command": command,
|
|
|
|
"enabled": enabled,
|
2022-01-12 16:33:08 +00:00
|
|
|
#We'll base every interval off of a midnight start time.
|
|
|
|
"start_time": '00:00',
|
2022-01-11 22:24:05 +00:00
|
|
|
"one_time": one_time,
|
|
|
|
"cron_string": ''
|
|
|
|
}
|
|
|
|
sch_id = self.get_argument('sch_id', None)
|
|
|
|
self.tasks_manager.update_job(sch_id, job_data)
|
|
|
|
|
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-26 01:45:30 +00:00
|
|
|
f"Edited server {server_id}: updated schedule",
|
2022-01-11 01:11:52 +00:00
|
|
|
server_id,
|
|
|
|
self.get_remote_ip())
|
|
|
|
self.tasks_manager.reload_schedule_from_db()
|
2022-01-26 01:45:30 +00:00
|
|
|
self.redirect(f"/panel/server_detail?id={server_id}&subpage=tasks")
|
2022-01-11 01:11:52 +00:00
|
|
|
|
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
elif page == "edit_user":
|
2021-12-21 04:04:07 +00:00
|
|
|
if bleach.clean(self.get_argument('username', None)) == 'system':
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: system user is not editable")
|
2020-12-24 22:55:15 +00:00
|
|
|
user_id = bleach.clean(self.get_argument('id', None))
|
|
|
|
username = bleach.clean(self.get_argument('username', None))
|
|
|
|
password0 = bleach.clean(self.get_argument('password0', None))
|
|
|
|
password1 = bleach.clean(self.get_argument('password1', None))
|
2022-01-08 23:03:45 +00:00
|
|
|
email = bleach.clean(self.get_argument('email', "default@example.com"))
|
2021-04-04 18:22:52 +00:00
|
|
|
enabled = int(float(self.get_argument('enabled', '0')))
|
2022-01-15 15:38:08 +00:00
|
|
|
lang = bleach.clean(self.get_argument('language'), helper.get_setting('language'))
|
2022-01-15 00:23:50 +00:00
|
|
|
|
|
|
|
if superuser:
|
2022-01-26 01:45:30 +00:00
|
|
|
#Checks if user is trying to change super user status of self. We don't want that.
|
|
|
|
# Automatically make them stay super user since we know they are.
|
2022-01-09 23:04:54 +00:00
|
|
|
if str(exec_user['user_id']) != str(user_id):
|
|
|
|
superuser = bleach.clean(self.get_argument('superuser', '0'))
|
|
|
|
else:
|
|
|
|
superuser = '1'
|
|
|
|
else:
|
|
|
|
superuser = '0'
|
|
|
|
if superuser == '1':
|
|
|
|
superuser = True
|
|
|
|
else:
|
|
|
|
superuser = False
|
2020-12-24 22:55:15 +00:00
|
|
|
|
2021-08-24 21:07:00 +00:00
|
|
|
if Enum_Permissions_Crafty.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"]):
|
2021-08-24 21:07:00 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not a user editor")
|
|
|
|
return
|
|
|
|
|
2021-08-09 05:29:13 +00:00
|
|
|
user_data = {
|
|
|
|
"username": username,
|
|
|
|
"password": password0,
|
2021-09-29 23:50:51 +00:00
|
|
|
"lang": lang,
|
2021-08-09 05:29:13 +00:00
|
|
|
}
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.users.update_user(user_id, user_data=user_data)
|
2021-08-09 05:29:13 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-15 00:23:50 +00:00
|
|
|
f"Edited user {username} (UID:{user_id}) password",
|
2021-08-09 05:29:13 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
self.redirect("/panel/panel_config")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
elif username is None or username == "":
|
|
|
|
self.redirect("/panel/error?error=Invalid username")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
elif user_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
else:
|
|
|
|
# does this user id exist?
|
2021-09-08 22:01:10 +00:00
|
|
|
if not self.controller.users.user_id_exists(user_id):
|
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
|
2020-12-24 22:55:15 +00:00
|
|
|
|
|
|
|
if password0 != password1:
|
|
|
|
self.redirect("/panel/error?error=Passwords must match")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
roles = self.get_user_role_memberships()
|
|
|
|
permissions_mask, server_quantity = self.get_perms_quantity()
|
2021-08-24 23:19:33 +00:00
|
|
|
|
2022-01-08 23:03:45 +00:00
|
|
|
# if email is None or "":
|
|
|
|
# email = "default@example.com"
|
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
user_data = {
|
|
|
|
"username": username,
|
|
|
|
"password": password0,
|
2022-01-08 23:03:45 +00:00
|
|
|
"email": email,
|
2020-12-24 22:55:15 +00:00
|
|
|
"enabled": enabled,
|
2020-12-26 03:00:28 +00:00
|
|
|
"roles": roles,
|
2021-09-29 23:50:51 +00:00
|
|
|
"lang": lang,
|
2022-01-09 23:04:54 +00:00
|
|
|
"superuser": superuser,
|
2020-12-24 22:55:15 +00:00
|
|
|
}
|
2021-08-24 21:07:00 +00:00
|
|
|
user_crafty_data = {
|
|
|
|
"permissions_mask": permissions_mask,
|
|
|
|
"server_quantity": server_quantity
|
|
|
|
}
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.users.update_user(user_id, user_data=user_data, user_crafty_data=user_crafty_data)
|
2020-12-24 22:55:15 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-15 00:23:50 +00:00
|
|
|
f"Edited user {username} (UID:{user_id}) with roles {roles} and permissions {permissions_mask}",
|
2020-12-24 22:55:15 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
elif page == "edit_user_apikeys":
|
|
|
|
user_id = self.get_argument('id', None)
|
|
|
|
name = self.get_argument('name', None)
|
|
|
|
superuser = self.get_argument('superuser', None) == '1'
|
|
|
|
|
|
|
|
if name is None or name == "":
|
|
|
|
self.redirect("/panel/error?error=Invalid API key name")
|
|
|
|
return
|
|
|
|
elif user_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
# does this user id exist?
|
|
|
|
if not self.controller.users.user_id_exists(user_id):
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return
|
|
|
|
|
|
|
|
crafty_permissions_mask = self.get_perms()
|
|
|
|
server_permissions_mask = self.get_perms_server()
|
|
|
|
|
|
|
|
self.controller.users.add_user_api_key(name, user_id, superuser, crafty_permissions_mask, server_permissions_mask)
|
|
|
|
|
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-26 01:45:30 +00:00
|
|
|
f"Added API key {name} with crafty permissions {crafty_permissions_mask}" +
|
|
|
|
f" and {server_permissions_mask} for user with UID: {user_id}",
|
2022-01-15 00:23:50 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
self.redirect(f"/panel/edit_user_apikeys?id={user_id}")
|
|
|
|
|
|
|
|
elif page == "get_token":
|
|
|
|
key_id = self.get_argument('id', None)
|
|
|
|
|
|
|
|
if key_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Key ID")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
key = self.controller.users.get_user_api_key(key_id)
|
|
|
|
# does this user id exist?
|
|
|
|
if key is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Key ID")
|
|
|
|
return
|
|
|
|
|
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
|
|
|
f"Generated a new API token for the key {key.name} from user with UID: {key.user.user_id}",
|
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
|
|
|
|
self.write(authentication.generate(key.user.user_id, {
|
|
|
|
'token_id': key.token_id
|
|
|
|
}))
|
|
|
|
self.finish()
|
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
|
|
|
|
elif page == "add_user":
|
2021-12-21 20:39:33 +00:00
|
|
|
if bleach.clean(self.get_argument('username', None)).lower() == 'system':
|
2022-01-26 01:45:30 +00:00
|
|
|
self.redirect("/panel/error?error=Unauthorized access: username system is reserved for the Crafty system." +
|
|
|
|
" Please choose a different username.")
|
2021-12-21 20:39:33 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
username = bleach.clean(self.get_argument('username', None))
|
|
|
|
password0 = bleach.clean(self.get_argument('password0', None))
|
|
|
|
password1 = bleach.clean(self.get_argument('password1', None))
|
2022-01-08 23:03:45 +00:00
|
|
|
email = bleach.clean(self.get_argument('email', "default@example.com"))
|
2022-01-26 01:45:30 +00:00
|
|
|
enabled = int(float(self.get_argument('enabled', '0')))
|
2022-01-15 15:38:08 +00:00
|
|
|
lang = bleach.clean(self.get_argument('lang', helper.get_setting('language')))
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser:
|
2022-01-09 23:04:54 +00:00
|
|
|
superuser = bleach.clean(self.get_argument('superuser', '0'))
|
|
|
|
else:
|
|
|
|
superuser = '0'
|
|
|
|
if superuser == '1':
|
|
|
|
superuser = True
|
|
|
|
else:
|
2022-01-26 01:45:30 +00:00
|
|
|
superuser = False
|
2020-12-24 22:55:15 +00:00
|
|
|
|
2021-08-24 21:07:00 +00:00
|
|
|
if Enum_Permissions_Crafty.User_Config not in exec_user_crafty_permissions:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not a user editor")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
elif username is None or username == "":
|
|
|
|
self.redirect("/panel/error?error=Invalid username")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
else:
|
|
|
|
# does this user id exist?
|
2021-09-08 22:01:10 +00:00
|
|
|
if self.controller.users.get_id_by_name(username) is not None:
|
2020-12-24 22:55:15 +00:00
|
|
|
self.redirect("/panel/error?error=User exists")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
|
|
|
|
if password0 != password1:
|
|
|
|
self.redirect("/panel/error?error=Passwords must match")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-24 22:55:15 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
roles = self.get_user_role_memberships()
|
|
|
|
permissions_mask, server_quantity = self.get_perms_quantity()
|
2021-08-24 23:25:35 +00:00
|
|
|
|
2022-01-10 04:16:11 +00:00
|
|
|
user_id = self.controller.users.add_user(username, password=password0, email=email, enabled=enabled, superuser=superuser)
|
2021-08-06 04:34:57 +00:00
|
|
|
user_data = {
|
|
|
|
"roles": roles,
|
2021-09-29 21:46:54 +00:00
|
|
|
'lang': lang
|
2021-08-06 04:34:57 +00:00
|
|
|
}
|
2021-08-24 21:07:00 +00:00
|
|
|
user_crafty_data = {
|
|
|
|
"permissions_mask": permissions_mask,
|
|
|
|
"server_quantity": server_quantity
|
|
|
|
}
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.users.update_user(user_id, user_data=user_data, user_crafty_data=user_crafty_data)
|
2020-12-24 22:55:15 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-26 01:45:30 +00:00
|
|
|
f"Added user {username} (UID:{user_id})",
|
2020-12-24 22:55:15 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-26 01:45:30 +00:00
|
|
|
f"Edited user {username} (UID:{user_id}) with roles {roles}",
|
2020-12-24 22:55:15 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
2020-12-27 16:00:26 +00:00
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
|
|
|
|
elif page == "edit_role":
|
|
|
|
role_id = bleach.clean(self.get_argument('id', None))
|
|
|
|
role_name = bleach.clean(self.get_argument('role_name', None))
|
|
|
|
|
2021-08-24 21:07:00 +00:00
|
|
|
if Enum_Permissions_Crafty.Roles_Config not in exec_user_crafty_permissions:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not a role editor")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-27 16:00:26 +00:00
|
|
|
elif role_name is None or role_name == "":
|
|
|
|
self.redirect("/panel/error?error=Invalid username")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-27 16:00:26 +00:00
|
|
|
elif role_id is None:
|
|
|
|
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
|
|
|
else:
|
|
|
|
# does this user id exist?
|
2021-09-08 22:01:10 +00:00
|
|
|
if not self.controller.roles.role_id_exists(role_id):
|
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
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
servers = self.get_role_servers()
|
|
|
|
permissions_mask = self.get_perms_server()
|
2020-12-27 16:00:26 +00:00
|
|
|
|
|
|
|
role_data = {
|
|
|
|
"role_name": role_name,
|
|
|
|
"servers": servers
|
|
|
|
}
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.roles.update_role(role_id, role_data=role_data, permissions_mask=permissions_mask)
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-26 01:45:30 +00:00
|
|
|
f"Edited role {role_name} (RID:{role_id}) with servers {servers}",
|
2020-12-27 16:00:26 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
|
|
|
|
|
|
|
|
elif page == "add_role":
|
|
|
|
role_name = bleach.clean(self.get_argument('role_name', None))
|
|
|
|
|
2021-08-24 21:07:00 +00:00
|
|
|
if Enum_Permissions_Crafty.Roles_Config not in exec_user_crafty_permissions:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not a role editor")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-27 16:00:26 +00:00
|
|
|
elif role_name is None or role_name == "":
|
|
|
|
self.redirect("/panel/error?error=Invalid role name")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-27 16:00:26 +00:00
|
|
|
else:
|
|
|
|
# does this user id exist?
|
2021-09-08 22:01:10 +00:00
|
|
|
if self.controller.roles.get_roleid_by_name(role_name) is not None:
|
2020-12-27 16:00:26 +00:00
|
|
|
self.redirect("/panel/error?error=Role exists")
|
2021-03-22 04:02:18 +00:00
|
|
|
return
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
servers = self.get_role_servers()
|
|
|
|
permissions_mask = self.get_perms_server()
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
role_id = self.controller.roles.add_role(role_name)
|
|
|
|
self.controller.roles.update_role(role_id, {"servers": servers}, permissions_mask)
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-26 01:45:30 +00:00
|
|
|
f"Added role {role_name} (RID:{role_id})",
|
2020-12-27 16:00:26 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
2021-09-08 22:01:10 +00:00
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
2022-01-26 01:45:30 +00:00
|
|
|
f"Edited role {role_name} (RID:{role_id}) with servers {servers}",
|
2020-12-27 16:00:26 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
2021-03-06 20:48:02 +00:00
|
|
|
self.redirect("/panel/panel_config")
|
2021-03-22 04:02:18 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
self.set_status(404)
|
2022-01-15 15:38:08 +00:00
|
|
|
page_data = {'lang': helper.get_setting('language')}
|
2021-03-26 13:57:50 +00:00
|
|
|
self.render(
|
|
|
|
"public/404.html",
|
|
|
|
translate=self.translator.translate,
|
2021-11-23 22:29:34 +00:00
|
|
|
data=page_data
|
2021-03-26 13:57:50 +00:00
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
def delete(self, page):
|
2022-01-26 01:45:30 +00:00
|
|
|
# pylint: disable=unused-variable
|
2022-01-15 00:23:50 +00:00
|
|
|
api_key, token_data, exec_user = self.current_user
|
|
|
|
superuser = exec_user['superuser']
|
|
|
|
if api_key is not None:
|
|
|
|
superuser = superuser and api_key.superuser
|
|
|
|
|
|
|
|
page_data = {
|
|
|
|
# todo: make this actually pull and compare version data
|
|
|
|
'update_available': False,
|
|
|
|
'version_data': helper.get_version_string(),
|
|
|
|
'user_data': exec_user,
|
|
|
|
'hosts_data': self.controller.management.get_latest_hosts_stats(),
|
|
|
|
'show_contribute': helper.get_setting("show_contribute_link", True),
|
|
|
|
'lang': self.controller.users.get_user_lang_by_id(exec_user["user_id"])
|
|
|
|
}
|
|
|
|
|
|
|
|
if page == "remove_apikey":
|
|
|
|
key_id = bleach.clean(self.get_argument('id', None))
|
|
|
|
|
|
|
|
if not superuser:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return
|
|
|
|
elif key_id is None or self.controller.users.get_user_api_key(key_id) is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Key ID")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
# does this user id exist?
|
|
|
|
target_key = self.controller.users.get_user_api_key(key_id)
|
|
|
|
if not target_key:
|
|
|
|
self.redirect("/panel/error?error=Invalid Key ID")
|
|
|
|
return
|
|
|
|
|
|
|
|
self.controller.users.delete_user_api_key(key_id)
|
|
|
|
|
|
|
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
|
|
|
f"Removed API key {target_key} (ID: {key_id}) from user {exec_user['user_id']}",
|
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
else:
|
|
|
|
self.set_status(404)
|
|
|
|
self.render(
|
|
|
|
"public/404.html",
|
|
|
|
data=page_data,
|
|
|
|
translate=self.translator.translate,
|
|
|
|
)
|