2020-08-19 17:54:10 +00:00
|
|
|
import json
|
|
|
|
import logging
|
2021-01-28 18:46:13 +00:00
|
|
|
import os
|
2022-04-11 05:23:55 +00:00
|
|
|
import tornado.web
|
|
|
|
import tornado.escape
|
|
|
|
import bleach
|
|
|
|
import libgravatar
|
|
|
|
import requests
|
2020-08-19 17:54:10 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
from app.classes.models.crafty_permissions import EnumPermissionsCrafty
|
2022-04-11 05:23:55 +00:00
|
|
|
from app.classes.shared.helpers import Helpers
|
|
|
|
from app.classes.shared.file_helpers import FileHelpers
|
2022-05-30 20:05:36 +00:00
|
|
|
from app.classes.shared.main_models import DatabaseShortcuts
|
2020-08-19 17:54:10 +00:00
|
|
|
from app.classes.web.base_handler import BaseHandler
|
|
|
|
|
2022-03-08 04:40:44 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2020-08-19 17:54:10 +00:00
|
|
|
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
class ServerHandler(BaseHandler):
|
2022-06-21 05:18:19 +00:00
|
|
|
def get_user_roles(self):
|
|
|
|
user_roles = {}
|
|
|
|
for user_id in self.controller.users.get_all_user_ids():
|
|
|
|
user_roles_list = self.controller.users.get_user_roles_names(user_id)
|
|
|
|
# user_servers =
|
|
|
|
# self.controller.servers.get_authorized_servers(user.user_id)
|
|
|
|
user_roles[user_id] = user_roles_list
|
|
|
|
return user_roles
|
|
|
|
|
2020-08-19 17:54:10 +00:00
|
|
|
@tornado.web.authenticated
|
|
|
|
def get(self, page):
|
2022-04-14 02:10:25 +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:
|
|
|
|
superuser = superuser and api_key.superuser
|
2021-10-09 08:32:52 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
if superuser:
|
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-11-17 18:08:41 +00:00
|
|
|
list_roles = []
|
|
|
|
for role in self.controller.roles.get_all_roles():
|
|
|
|
list_roles.append(self.controller.roles.get_role(role.role_id))
|
2021-03-13 22:12:42 +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"]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
defined_servers = self.controller.servers.get_authorized_servers(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
2021-11-17 18:08:41 +00:00
|
|
|
list_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"])
|
|
|
|
list_roles.append(self.controller.roles.get_role(role["role_id"]))
|
2020-08-19 17:54:10 +00:00
|
|
|
|
2022-07-18 21:12:43 +00:00
|
|
|
user_order = self.controller.users.get_user_by_id(exec_user["user_id"])
|
|
|
|
user_order = user_order["server_order"].split(",")
|
2022-05-30 20:05:36 +00:00
|
|
|
page_servers = []
|
2022-07-18 21:12:43 +00:00
|
|
|
server_ids = []
|
|
|
|
|
|
|
|
for server_id in user_order[:]:
|
|
|
|
for server in defined_servers[:]:
|
|
|
|
if str(server.server_id) == str(server_id):
|
|
|
|
page_servers.append(
|
|
|
|
DatabaseShortcuts.get_data_obj(server.server_object)
|
|
|
|
)
|
|
|
|
user_order.remove(server_id)
|
|
|
|
defined_servers.remove(server)
|
|
|
|
|
2022-05-30 20:05:36 +00:00
|
|
|
for server in defined_servers:
|
2022-07-18 21:12:43 +00:00
|
|
|
server_ids.append(str(server.server_id))
|
2022-05-30 20:05:36 +00:00
|
|
|
if server not in page_servers:
|
|
|
|
page_servers.append(
|
|
|
|
DatabaseShortcuts.get_data_obj(server.server_object)
|
|
|
|
)
|
2022-07-18 21:12:43 +00:00
|
|
|
|
|
|
|
for server_id in user_order[:]:
|
|
|
|
# remove IDs in list that user no longer has access to
|
|
|
|
if str(server_id) not in server_ids:
|
|
|
|
user_order.remove(server_id)
|
2022-05-30 20:05:36 +00:00
|
|
|
defined_servers = page_servers
|
|
|
|
|
2020-08-19 17:54:10 +00:00
|
|
|
template = "public/404.html"
|
|
|
|
|
|
|
|
page_data = {
|
2022-04-11 05:23:55 +00:00
|
|
|
"version_data": self.helper.get_version_string(),
|
2022-03-23 02:50:12 +00:00
|
|
|
"user_data": exec_user,
|
|
|
|
"user_role": exec_user_role,
|
|
|
|
"roles": list_roles,
|
|
|
|
"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": {
|
2022-05-26 12:50:20 +00:00
|
|
|
"total": len(self.controller.servers.list_defined_servers()),
|
|
|
|
"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 17:54:10 +00:00
|
|
|
},
|
2022-03-23 02:50:12 +00:00
|
|
|
"hosts_data": self.controller.management.get_latest_hosts_stats(),
|
2022-07-18 21:12:43 +00:00
|
|
|
"menu_servers": page_servers,
|
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
|
|
|
"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"])
|
|
|
|
),
|
|
|
|
"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-19 17:54:10 +00:00
|
|
|
}
|
2022-03-05 11:01:36 +00:00
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
if self.helper.get_setting("allow_nsfw_profile_pictures"):
|
2022-01-19 20:14:56 +00:00
|
|
|
rating = "x"
|
|
|
|
else:
|
|
|
|
rating = "g"
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
if exec_user["email"] != "default@example.com" or "":
|
2022-04-14 02:10:25 +00:00
|
|
|
gravatar = libgravatar.Gravatar(
|
|
|
|
libgravatar.sanitize_email(exec_user["email"])
|
|
|
|
)
|
|
|
|
url = gravatar.get_image(
|
2022-03-23 02:50:12 +00:00
|
|
|
size=80,
|
|
|
|
default="404",
|
|
|
|
force_default=False,
|
|
|
|
rating=rating,
|
|
|
|
filetype_extension=False,
|
|
|
|
use_ssl=True,
|
|
|
|
) # + "?d=404"
|
2022-03-27 22:09:49 +00:00
|
|
|
try:
|
|
|
|
if requests.head(url).status_code != 404:
|
|
|
|
profile_url = url
|
|
|
|
else:
|
|
|
|
profile_url = "/static/assets/images/faces-clipart/pic-3.png"
|
|
|
|
except:
|
2022-01-19 20:14:56 +00:00
|
|
|
profile_url = "/static/assets/images/faces-clipart/pic-3.png"
|
|
|
|
else:
|
|
|
|
profile_url = "/static/assets/images/faces-clipart/pic-3.png"
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["user_image"] = profile_url
|
2022-01-15 15:38:08 +00:00
|
|
|
if superuser:
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["roles"] = list_roles
|
2020-08-23 22:43:28 +00:00
|
|
|
|
|
|
|
if page == "step1":
|
2022-03-23 02:50:12 +00:00
|
|
|
if not superuser and not self.controller.crafty_perms.can_create_server(
|
|
|
|
exec_user["user_id"]
|
|
|
|
):
|
|
|
|
self.redirect(
|
2022-03-23 06:06:13 +00:00
|
|
|
"/panel/error?error=Unauthorized access: "
|
|
|
|
"not a server creator or server limit reached"
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2021-08-24 21:07:00 +00:00
|
|
|
return
|
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
page_data["online"] = Helpers.check_internet()
|
|
|
|
page_data["server_types"] = self.controller.server_jars.get_serverjar_data()
|
2022-03-23 02:50:12 +00:00
|
|
|
page_data["js_server_types"] = json.dumps(
|
2022-04-11 05:23:55 +00:00
|
|
|
self.controller.server_jars.get_serverjar_data()
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-07-05 20:15:49 +00:00
|
|
|
if page_data["server_types"] is None:
|
|
|
|
page_data["server_types"] = []
|
|
|
|
page_data["js_server_types"] = []
|
2020-08-23 22:43:28 +00:00
|
|
|
template = "server/wizard.html"
|
|
|
|
|
2022-02-10 20:54:00 +00:00
|
|
|
if page == "bedrock_step1":
|
2022-03-23 02:50:12 +00:00
|
|
|
if not superuser and not self.controller.crafty_perms.can_create_server(
|
|
|
|
exec_user["user_id"]
|
|
|
|
):
|
|
|
|
self.redirect(
|
2022-03-23 06:06:13 +00:00
|
|
|
"/panel/error?error=Unauthorized access: "
|
|
|
|
"not a server creator or server limit reached"
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-02-10 20:54:00 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
template = "server/bedrock_wizard.html"
|
|
|
|
|
2020-08-23 22:43:28 +00:00
|
|
|
self.render(
|
|
|
|
template,
|
2021-03-26 13:57:50 +00:00
|
|
|
data=page_data,
|
|
|
|
translate=self.translator.translate,
|
2020-08-23 22:43:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
def post(self, page):
|
2022-04-14 02:10:25 +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:
|
|
|
|
superuser = superuser and api_key.superuser
|
2020-08-23 22:43:28 +00:00
|
|
|
|
|
|
|
template = "public/404.html"
|
|
|
|
page_data = {
|
2022-03-23 02:50:12 +00:00
|
|
|
"version_data": "version_data_here", # TODO
|
|
|
|
"user_data": exec_user,
|
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
|
|
|
"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"])
|
|
|
|
),
|
2020-08-23 22:43:28 +00:00
|
|
|
}
|
2020-08-19 17:54:10 +00:00
|
|
|
|
2020-08-24 23:11:17 +00:00
|
|
|
if page == "command":
|
|
|
|
server_id = bleach.clean(self.get_argument("id", None))
|
|
|
|
command = bleach.clean(self.get_argument("command", None))
|
|
|
|
|
|
|
|
if server_id is not None:
|
2021-01-28 18:46:13 +00:00
|
|
|
if command == "clone_server":
|
2022-03-23 02:50:12 +00:00
|
|
|
|
2021-01-28 18:46:13 +00:00
|
|
|
def is_name_used(name):
|
2021-09-08 22:01:10 +00:00
|
|
|
for server in self.controller.servers.get_all_defined_servers():
|
2022-03-23 02:50:12 +00:00
|
|
|
if server["server_name"] == name:
|
2021-01-28 18:46:13 +00:00
|
|
|
return True
|
2021-07-30 16:20:01 +00:00
|
|
|
return
|
2021-10-09 08:32:52 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
server_data = self.controller.servers.get_server_data_by_id(
|
|
|
|
server_id
|
|
|
|
)
|
|
|
|
new_server_name = server_data.get("server_name") + " (Copy)"
|
2021-01-28 18:46:13 +00:00
|
|
|
|
|
|
|
name_counter = 1
|
|
|
|
while is_name_used(new_server_name):
|
|
|
|
name_counter += 1
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_name = (
|
|
|
|
server_data.get("server_name") + f" (Copy {name_counter})"
|
|
|
|
)
|
2021-01-28 18:46:13 +00:00
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
new_server_uuid = Helpers.create_uuid()
|
2022-03-23 02:50:12 +00:00
|
|
|
while os.path.exists(
|
2022-04-11 05:23:55 +00:00
|
|
|
os.path.join(self.helper.servers_dir, new_server_uuid)
|
2022-03-23 02:50:12 +00:00
|
|
|
):
|
2022-04-11 05:23:55 +00:00
|
|
|
new_server_uuid = Helpers.create_uuid()
|
2022-04-11 10:08:36 +00:00
|
|
|
new_server_path = os.path.join(
|
|
|
|
self.helper.servers_dir, new_server_uuid
|
|
|
|
)
|
2021-01-28 18:46:13 +00:00
|
|
|
|
|
|
|
# copy the old server
|
2022-04-11 05:23:55 +00:00
|
|
|
FileHelpers.copy_dir(server_data.get("path"), new_server_path)
|
2021-01-28 18:46:13 +00:00
|
|
|
|
|
|
|
# TODO get old server DB data to individual variables
|
2022-03-23 02:50:12 +00:00
|
|
|
stop_command = server_data.get("stop_command")
|
2022-06-15 23:10:26 +00:00
|
|
|
new_server_command = str(server_data.get("execution_command"))
|
2022-03-23 02:50:12 +00:00
|
|
|
new_executable = server_data.get("executable")
|
|
|
|
new_server_log_file = str(
|
2022-04-11 05:23:55 +00:00
|
|
|
Helpers.get_os_understandable_path(server_data.get("log_path"))
|
2022-06-15 23:10:26 +00:00
|
|
|
)
|
2022-04-12 21:17:12 +00:00
|
|
|
backup_path = os.path.join(self.helper.backup_path, new_server_uuid)
|
2022-03-23 02:50:12 +00:00
|
|
|
server_port = server_data.get("server_port")
|
|
|
|
server_type = server_data.get("type")
|
|
|
|
|
2022-06-02 12:51:12 +00:00
|
|
|
new_server_id = self.controller.servers.create_server(
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_name,
|
|
|
|
new_server_uuid,
|
|
|
|
new_server_path,
|
2022-04-12 21:17:12 +00:00
|
|
|
backup_path,
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_command,
|
|
|
|
new_executable,
|
|
|
|
new_server_log_file,
|
|
|
|
stop_command,
|
|
|
|
server_type,
|
|
|
|
server_port,
|
|
|
|
)
|
2022-06-02 12:51:12 +00:00
|
|
|
if not exec_user["superuser"]:
|
|
|
|
new_server_uuid = self.controller.servers.get_server_data_by_id(
|
|
|
|
new_server_id
|
|
|
|
).get("server_uuid")
|
|
|
|
role_id = self.controller.roles.add_role(
|
|
|
|
f"Creator of Server with uuid={new_server_uuid}"
|
|
|
|
)
|
|
|
|
self.controller.server_perms.add_role_server(
|
|
|
|
new_server_id, role_id, "11111111"
|
|
|
|
)
|
|
|
|
self.controller.users.add_role_to_user(
|
|
|
|
exec_user["user_id"], role_id
|
|
|
|
)
|
|
|
|
self.controller.crafty_perms.add_server_creation(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
2021-01-28 18:46:13 +00:00
|
|
|
|
2022-05-30 05:36:25 +00:00
|
|
|
self.controller.servers.init_all_servers()
|
2021-01-28 18:46:13 +00:00
|
|
|
|
|
|
|
return
|
2021-10-09 08:32:52 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
self.controller.management.send_command(
|
|
|
|
exec_user["user_id"], server_id, self.get_remote_ip(), command
|
|
|
|
)
|
2020-08-24 23:11:17 +00:00
|
|
|
|
2020-08-23 22:43:28 +00:00
|
|
|
if page == "step1":
|
2022-06-20 19:26:21 +00:00
|
|
|
if not superuser and not self.controller.crafty_perms.can_create_server(
|
|
|
|
exec_user["user_id"]
|
|
|
|
):
|
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=Unauthorized access: "
|
|
|
|
"not a server creator or server limit reached"
|
|
|
|
)
|
|
|
|
return
|
2020-08-23 22:43:28 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2021-11-17 18:08:41 +00:00
|
|
|
user_roles = self.controller.roles.get_all_roles()
|
|
|
|
else:
|
2022-06-21 05:18:19 +00:00
|
|
|
user_roles = self.get_user_roles()
|
2022-03-23 02:50:12 +00:00
|
|
|
server = bleach.clean(self.get_argument("server", ""))
|
|
|
|
server_name = bleach.clean(self.get_argument("server_name", ""))
|
|
|
|
min_mem = bleach.clean(self.get_argument("min_memory", ""))
|
|
|
|
max_mem = bleach.clean(self.get_argument("max_memory", ""))
|
|
|
|
port = bleach.clean(self.get_argument("port", ""))
|
|
|
|
import_type = bleach.clean(self.get_argument("create_type", ""))
|
|
|
|
import_server_path = bleach.clean(self.get_argument("server_path", ""))
|
|
|
|
import_server_jar = bleach.clean(self.get_argument("server_jar", ""))
|
2020-08-23 22:43:28 +00:00
|
|
|
server_parts = server.split("|")
|
2021-11-17 18:08:41 +00:00
|
|
|
captured_roles = []
|
|
|
|
for role in user_roles:
|
2022-03-23 02:50:12 +00:00
|
|
|
if bleach.clean(self.get_argument(str(role), "")) == "on":
|
2022-01-26 01:45:30 +00:00
|
|
|
captured_roles.append(role)
|
2020-08-23 22:43:28 +00:00
|
|
|
|
2021-05-02 15:57:53 +00:00
|
|
|
if not server_name:
|
|
|
|
self.redirect("/panel/error?error=Server name cannot be empty!")
|
2021-07-30 16:20:01 +00:00
|
|
|
return
|
2021-05-02 15:57:53 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
if import_type == "import_jar":
|
|
|
|
good_path = self.controller.verify_jar_server(
|
|
|
|
import_server_path, import_server_jar
|
|
|
|
)
|
2020-09-14 20:01:38 +00:00
|
|
|
|
|
|
|
if not good_path:
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=Server path or Server Jar not found!"
|
|
|
|
)
|
2022-02-10 20:54:00 +00:00
|
|
|
return
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_id = self.controller.import_jar_server(
|
|
|
|
server_name,
|
|
|
|
import_server_path,
|
|
|
|
import_server_jar,
|
|
|
|
min_mem,
|
|
|
|
max_mem,
|
|
|
|
port,
|
|
|
|
)
|
|
|
|
self.controller.management.add_to_audit_log(
|
|
|
|
exec_user["user_id"],
|
2022-03-23 06:06:13 +00:00
|
|
|
f'imported a jar server named "{server_name}"',
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_id,
|
|
|
|
self.get_remote_ip(),
|
|
|
|
)
|
|
|
|
elif import_type == "import_zip":
|
2022-02-10 20:54:00 +00:00
|
|
|
# here import_server_path means the zip path
|
2022-03-23 02:50:12 +00:00
|
|
|
zip_path = bleach.clean(self.get_argument("root_path"))
|
2022-04-11 05:23:55 +00:00
|
|
|
good_path = Helpers.check_path_exists(zip_path)
|
2022-02-10 20:54:00 +00:00
|
|
|
if not good_path:
|
|
|
|
self.redirect("/panel/error?error=Temp path not found!")
|
|
|
|
return
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_id = self.controller.import_zip_server(
|
|
|
|
server_name, zip_path, import_server_jar, min_mem, max_mem, port
|
|
|
|
)
|
2022-02-10 20:54:00 +00:00
|
|
|
if new_server_id == "false":
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect(
|
2022-03-23 06:06:13 +00:00
|
|
|
f"/panel/error?error=Zip file not accessible! "
|
|
|
|
f"You can fix this permissions issue with "
|
|
|
|
f"sudo chown -R crafty:crafty {import_server_path} "
|
|
|
|
f"And sudo chmod 2775 -R {import_server_path}"
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-02-10 20:54:00 +00:00
|
|
|
return
|
2022-03-23 02:50:12 +00:00
|
|
|
self.controller.management.add_to_audit_log(
|
|
|
|
exec_user["user_id"],
|
2022-03-23 06:06:13 +00:00
|
|
|
f'imported a zip server named "{server_name}"',
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_id,
|
|
|
|
self.get_remote_ip(),
|
|
|
|
)
|
|
|
|
# deletes temp dir
|
2022-04-11 05:23:55 +00:00
|
|
|
FileHelpers.del_dirs(zip_path)
|
2022-02-10 20:54:00 +00:00
|
|
|
else:
|
|
|
|
if len(server_parts) != 2:
|
|
|
|
self.redirect("/panel/error?error=Invalid server data")
|
|
|
|
return
|
|
|
|
server_type, server_version = server_parts
|
2022-03-23 06:06:13 +00:00
|
|
|
# TODO: add server type check here and call the correct server
|
|
|
|
# add functions if not a jar
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_id = self.controller.create_jar_server(
|
|
|
|
server_type, server_version, server_name, min_mem, max_mem, port
|
|
|
|
)
|
|
|
|
self.controller.management.add_to_audit_log(
|
|
|
|
exec_user["user_id"],
|
2022-03-23 06:06:13 +00:00
|
|
|
f"created a {server_version} {str(server_type).capitalize()}"
|
|
|
|
f' server named "{server_name}"',
|
2022-03-23 02:50:12 +00:00
|
|
|
# Example: Admin created a 1.16.5 Bukkit server named "survival"
|
|
|
|
new_server_id,
|
|
|
|
self.get_remote_ip(),
|
|
|
|
)
|
2022-02-10 20:54:00 +00:00
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# These lines create a new Role for the Server with full permissions
|
|
|
|
# and add the user to it if he's not a superuser
|
2022-02-10 20:54:00 +00:00
|
|
|
if len(captured_roles) == 0:
|
|
|
|
if not superuser:
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_uuid = self.controller.servers.get_server_data_by_id(
|
|
|
|
new_server_id
|
|
|
|
).get("server_uuid")
|
|
|
|
role_id = self.controller.roles.add_role(
|
|
|
|
f"Creator of Server with uuid={new_server_uuid}"
|
|
|
|
)
|
|
|
|
self.controller.server_perms.add_role_server(
|
|
|
|
new_server_id, role_id, "11111111"
|
|
|
|
)
|
|
|
|
self.controller.users.add_role_to_user(
|
|
|
|
exec_user["user_id"], role_id
|
|
|
|
)
|
|
|
|
self.controller.crafty_perms.add_server_creation(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
2022-02-10 20:54:00 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
for role in captured_roles:
|
|
|
|
role_id = role
|
2022-03-23 02:50:12 +00:00
|
|
|
self.controller.server_perms.add_role_server(
|
|
|
|
new_server_id, role_id, "11111111"
|
|
|
|
)
|
2022-02-10 20:54:00 +00:00
|
|
|
|
2022-05-26 12:50:20 +00:00
|
|
|
self.controller.servers.stats.record_stats()
|
2022-02-10 20:54:00 +00:00
|
|
|
self.redirect("/panel/dashboard")
|
|
|
|
|
|
|
|
if page == "bedrock_step1":
|
2022-06-20 19:26:21 +00:00
|
|
|
if not superuser and not self.controller.crafty_perms.can_create_server(
|
|
|
|
exec_user["user_id"]
|
|
|
|
):
|
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=Unauthorized access: "
|
|
|
|
"not a server creator or server limit reached"
|
|
|
|
)
|
|
|
|
return
|
2022-02-10 20:54:00 +00:00
|
|
|
if not superuser:
|
|
|
|
user_roles = self.controller.roles.get_all_roles()
|
|
|
|
else:
|
|
|
|
user_roles = self.controller.roles.get_all_roles()
|
2022-03-23 02:50:12 +00:00
|
|
|
server = bleach.clean(self.get_argument("server", ""))
|
|
|
|
server_name = bleach.clean(self.get_argument("server_name", ""))
|
|
|
|
port = bleach.clean(self.get_argument("port", ""))
|
|
|
|
import_type = bleach.clean(self.get_argument("create_type", ""))
|
|
|
|
import_server_path = bleach.clean(self.get_argument("server_path", ""))
|
|
|
|
import_server_exe = bleach.clean(self.get_argument("server_jar", ""))
|
2022-02-10 20:54:00 +00:00
|
|
|
server_parts = server.split("|")
|
|
|
|
captured_roles = []
|
|
|
|
for role in user_roles:
|
2022-03-23 02:50:12 +00:00
|
|
|
if bleach.clean(self.get_argument(str(role), "")) == "on":
|
2022-02-10 20:54:00 +00:00
|
|
|
captured_roles.append(role)
|
|
|
|
|
|
|
|
if not server_name:
|
|
|
|
self.redirect("/panel/error?error=Server name cannot be empty!")
|
|
|
|
return
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
if import_type == "import_jar":
|
|
|
|
good_path = self.controller.verify_jar_server(
|
|
|
|
import_server_path, import_server_exe
|
|
|
|
)
|
2022-02-10 20:54:00 +00:00
|
|
|
|
|
|
|
if not good_path:
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect(
|
|
|
|
"/panel/error?error=Server path or Server Jar not found!"
|
|
|
|
)
|
2021-07-30 16:20:01 +00:00
|
|
|
return
|
2020-09-14 20:01:38 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_id = self.controller.import_bedrock_server(
|
|
|
|
server_name, import_server_path, import_server_exe, port
|
|
|
|
)
|
|
|
|
self.controller.management.add_to_audit_log(
|
|
|
|
exec_user["user_id"],
|
2022-03-23 06:06:13 +00:00
|
|
|
f'imported a jar server named "{server_name}"',
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_id,
|
|
|
|
self.get_remote_ip(),
|
|
|
|
)
|
|
|
|
elif import_type == "import_zip":
|
2021-04-19 10:36:12 +00:00
|
|
|
# here import_server_path means the zip path
|
2022-03-23 02:50:12 +00:00
|
|
|
zip_path = bleach.clean(self.get_argument("root_path"))
|
2022-04-11 05:23:55 +00:00
|
|
|
good_path = Helpers.check_path_exists(zip_path)
|
2020-12-12 17:54:10 +00:00
|
|
|
if not good_path:
|
2022-01-10 03:21:28 +00:00
|
|
|
self.redirect("/panel/error?error=Temp path not found!")
|
2021-07-30 16:20:01 +00:00
|
|
|
return
|
2020-09-14 20:01:38 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_id = self.controller.import_bedrock_zip_server(
|
|
|
|
server_name, zip_path, import_server_exe, port
|
|
|
|
)
|
2020-12-12 19:35:41 +00:00
|
|
|
if new_server_id == "false":
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect(
|
2022-03-23 06:06:13 +00:00
|
|
|
f"/panel/error?error=Zip file not accessible! "
|
|
|
|
f"You can fix this permissions issue with"
|
|
|
|
f"sudo chown -R crafty:crafty {import_server_path} "
|
|
|
|
f"And sudo chmod 2775 -R {import_server_path}"
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2021-07-30 16:20:01 +00:00
|
|
|
return
|
2022-03-23 02:50:12 +00:00
|
|
|
self.controller.management.add_to_audit_log(
|
|
|
|
exec_user["user_id"],
|
2022-03-23 06:06:13 +00:00
|
|
|
f'imported a zip server named "{server_name}"',
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_id,
|
|
|
|
self.get_remote_ip(),
|
|
|
|
)
|
|
|
|
# deletes temp dir
|
2022-04-11 05:23:55 +00:00
|
|
|
FileHelpers.del_dirs(zip_path)
|
2021-04-19 10:36:12 +00:00
|
|
|
else:
|
|
|
|
if len(server_parts) != 2:
|
|
|
|
self.redirect("/panel/error?error=Invalid server data")
|
2021-07-30 16:20:01 +00:00
|
|
|
return
|
2021-04-19 10:36:12 +00:00
|
|
|
server_type, server_version = server_parts
|
2022-03-23 06:06:13 +00:00
|
|
|
# TODO: add server type check here and call the correct server
|
|
|
|
# add functions if not a jar
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_id = self.controller.create_jar_server(
|
|
|
|
server_type, server_version, server_name, min_mem, max_mem, port
|
|
|
|
)
|
|
|
|
self.controller.management.add_to_audit_log(
|
|
|
|
exec_user["user_id"],
|
2022-03-23 06:06:13 +00:00
|
|
|
f"created a {server_version} {str(server_type).capitalize()} "
|
|
|
|
f'server named "{server_name}"',
|
2022-03-23 02:50:12 +00:00
|
|
|
# Example: Admin created a 1.16.5 Bukkit server named "survival"
|
|
|
|
new_server_id,
|
|
|
|
self.get_remote_ip(),
|
|
|
|
)
|
2021-04-03 23:21:05 +00:00
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# These lines create a new Role for the Server with full permissions
|
|
|
|
# and add the user to it if he's not a superuser
|
2021-11-17 18:08:41 +00:00
|
|
|
if len(captured_roles) == 0:
|
2022-01-15 00:23:50 +00:00
|
|
|
if not superuser:
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_uuid = self.controller.servers.get_server_data_by_id(
|
|
|
|
new_server_id
|
|
|
|
).get("server_uuid")
|
|
|
|
role_id = self.controller.roles.add_role(
|
|
|
|
f"Creator of Server with uuid={new_server_uuid}"
|
|
|
|
)
|
|
|
|
self.controller.server_perms.add_role_server(
|
|
|
|
new_server_id, role_id, "11111111"
|
|
|
|
)
|
|
|
|
self.controller.users.add_role_to_user(
|
|
|
|
exec_user["user_id"], role_id
|
|
|
|
)
|
|
|
|
self.controller.crafty_perms.add_server_creation(
|
|
|
|
exec_user["user_id"]
|
|
|
|
)
|
2021-11-17 06:17:36 +00:00
|
|
|
|
|
|
|
else:
|
2021-11-17 18:08:41 +00:00
|
|
|
for role in captured_roles:
|
|
|
|
role_id = role
|
2022-03-23 02:50:12 +00:00
|
|
|
self.controller.server_perms.add_role_server(
|
|
|
|
new_server_id, role_id, "11111111"
|
|
|
|
)
|
2021-08-22 09:06:44 +00:00
|
|
|
|
2022-05-26 12:50:20 +00:00
|
|
|
self.controller.servers.stats.record_stats()
|
2020-09-14 20:01:38 +00:00
|
|
|
self.redirect("/panel/dashboard")
|
2020-08-23 22:43:28 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
try:
|
|
|
|
self.render(
|
|
|
|
template,
|
|
|
|
data=page_data,
|
|
|
|
translate=self.translator.translate,
|
|
|
|
)
|
|
|
|
except RuntimeError:
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect("/panel/dashboard")
|