2020-08-17 02:47:53 +00:00
|
|
|
import os
|
2021-11-29 21:22:46 +00:00
|
|
|
import pathlib
|
2022-03-08 02:36:23 +00:00
|
|
|
from pathlib import Path
|
2022-08-26 15:23:08 +00:00
|
|
|
from datetime import datetime
|
2022-07-17 20:37:10 +00:00
|
|
|
import platform
|
2022-03-01 23:31:38 +00:00
|
|
|
import shutil
|
2020-08-17 02:47:53 +00:00
|
|
|
import time
|
2023-08-15 20:09:06 +00:00
|
|
|
import json
|
2020-08-17 02:47:53 +00:00
|
|
|
import logging
|
2023-01-30 23:31:46 +00:00
|
|
|
import threading
|
2023-10-07 15:59:46 +00:00
|
|
|
from zoneinfo import ZoneInfoNotFoundError
|
2022-04-11 05:23:55 +00:00
|
|
|
from peewee import DoesNotExist
|
2022-04-11 10:08:36 +00:00
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
# TZLocal is set as a hidden import on win pipeline
|
|
|
|
from tzlocal import get_localzone
|
|
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
2020-08-17 02:47:53 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
from app.classes.models.server_permissions import EnumPermissionsServer
|
2022-06-02 12:23:18 +00:00
|
|
|
from app.classes.shared.main_models import DatabaseShortcuts
|
2022-04-14 02:10:25 +00:00
|
|
|
from app.classes.models.users import HelperUsers
|
|
|
|
from app.classes.models.roles import HelperRoles
|
|
|
|
from app.classes.models.management import HelpersManagement
|
|
|
|
from app.classes.models.servers import HelperServers
|
2022-06-13 18:29:25 +00:00
|
|
|
from app.classes.controllers.crafty_perms_controller import CraftyPermsController
|
|
|
|
from app.classes.controllers.management_controller import ManagementController
|
|
|
|
from app.classes.controllers.users_controller import UsersController
|
|
|
|
from app.classes.controllers.roles_controller import RolesController
|
|
|
|
from app.classes.controllers.server_perms_controller import ServerPermsController
|
|
|
|
from app.classes.controllers.servers_controller import ServersController
|
2022-04-11 05:23:55 +00:00
|
|
|
from app.classes.shared.authentication import Authentication
|
2022-04-12 01:34:46 +00:00
|
|
|
from app.classes.shared.console import Console
|
2022-04-11 05:23:55 +00:00
|
|
|
from app.classes.shared.helpers import Helpers
|
|
|
|
from app.classes.shared.file_helpers import FileHelpers
|
2022-08-17 21:22:03 +00:00
|
|
|
from app.classes.shared.import_helper import ImportHelpers
|
2022-04-11 05:23:55 +00:00
|
|
|
from app.classes.minecraft.serverjars import ServerJars
|
2023-08-09 21:47:53 +00:00
|
|
|
from app.classes.shared.websocket_manager import WebSocketManager
|
2022-03-08 04:40:44 +00:00
|
|
|
|
2020-08-17 02:47:53 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2022-04-11 10:08:36 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
class Controller:
|
2022-08-17 21:22:03 +00:00
|
|
|
def __init__(self, database, helper, file_helper, import_helper):
|
2022-05-26 13:20:21 +00:00
|
|
|
self.helper: Helpers = helper
|
2022-06-20 19:26:21 +00:00
|
|
|
self.file_helper: FileHelpers = file_helper
|
2022-08-17 21:22:03 +00:00
|
|
|
self.import_helper: ImportHelpers = import_helper
|
2022-05-26 13:20:21 +00:00
|
|
|
self.server_jars: ServerJars = ServerJars(helper)
|
|
|
|
self.users_helper: HelperUsers = HelperUsers(database, self.helper)
|
|
|
|
self.roles_helper: HelperRoles = HelperRoles(database)
|
|
|
|
self.servers_helper: HelperServers = HelperServers(database)
|
|
|
|
self.management_helper: HelpersManagement = HelpersManagement(
|
|
|
|
database, self.helper
|
|
|
|
)
|
|
|
|
self.authentication: Authentication = Authentication(self.helper)
|
|
|
|
self.crafty_perms: CraftyPermsController = CraftyPermsController()
|
|
|
|
self.management: ManagementController = ManagementController(
|
|
|
|
self.management_helper
|
|
|
|
)
|
|
|
|
self.roles: RolesController = RolesController(
|
|
|
|
self.users_helper, self.roles_helper
|
|
|
|
)
|
|
|
|
self.server_perms: ServerPermsController = ServerPermsController()
|
|
|
|
self.servers: ServersController = ServersController(
|
2022-06-20 19:26:21 +00:00
|
|
|
self.helper, self.servers_helper, self.management_helper, self.file_helper
|
2022-05-26 12:50:20 +00:00
|
|
|
)
|
2022-05-26 13:20:21 +00:00
|
|
|
self.users: UsersController = UsersController(
|
2022-04-11 10:08:36 +00:00
|
|
|
self.helper, self.users_helper, self.authentication
|
|
|
|
)
|
2022-06-13 18:29:25 +00:00
|
|
|
try:
|
|
|
|
tz = get_localzone()
|
|
|
|
except ZoneInfoNotFoundError:
|
|
|
|
logger.error(
|
|
|
|
"Could not capture time zone from system. Falling back to Europe/London"
|
|
|
|
)
|
|
|
|
tz = "Europe/London"
|
2022-05-26 13:20:21 +00:00
|
|
|
self.support_scheduler: BackgroundScheduler = BackgroundScheduler(
|
|
|
|
timezone=str(tz)
|
|
|
|
)
|
2022-06-12 21:03:42 +00:00
|
|
|
self.first_login = False
|
2022-11-09 19:13:35 +00:00
|
|
|
self.cached_login = self.management.get_login_image()
|
2022-03-13 12:29:26 +00:00
|
|
|
self.support_scheduler.start()
|
2023-11-05 18:26:27 +00:00
|
|
|
try:
|
|
|
|
with open(
|
|
|
|
os.path.join(os.path.curdir, "logs", "auth_tracker.log"),
|
|
|
|
"r",
|
|
|
|
encoding="utf-8",
|
|
|
|
) as f:
|
|
|
|
self.auth_tracker = json.load(f)
|
2023-12-07 11:29:18 +00:00
|
|
|
except (FileNotFoundError, json.JSONDecodeError):
|
2023-11-05 18:26:27 +00:00
|
|
|
self.auth_tracker = {}
|
|
|
|
|
|
|
|
def log_attempt(self, remote_ip, username):
|
|
|
|
remote = self.auth_tracker.get(str(remote_ip), None)
|
2024-02-01 05:08:34 +00:00
|
|
|
if not remote:
|
|
|
|
self.auth_tracker[str(remote_ip)] = {
|
|
|
|
"login": {
|
|
|
|
"names": [username],
|
|
|
|
"attempts": 1,
|
|
|
|
"times": [datetime.now().strftime("%d/%m/%Y %H:%M:%S")],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
if remote.get("login", None):
|
|
|
|
remote["login"]["names"].append(username)
|
|
|
|
remote["login"]["attempts"] += 1
|
|
|
|
remote["login"]["times"].append(
|
|
|
|
datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
|
|
|
)
|
2023-11-05 18:26:27 +00:00
|
|
|
self.auth_tracker[str(remote_ip)] = remote
|
|
|
|
else:
|
2024-02-01 05:08:34 +00:00
|
|
|
self.auth_tracker[str(remote_ip)]["login"] = {
|
2023-11-05 19:17:50 +00:00
|
|
|
"names": [username],
|
|
|
|
"attempts": 1,
|
|
|
|
"times": [datetime.now().strftime("%d/%m/%Y %H:%M:%S")],
|
|
|
|
}
|
|
|
|
|
2024-02-01 05:08:34 +00:00
|
|
|
def log_antilockout(self, remote_ip):
|
|
|
|
remote = self.auth_tracker.get(str(remote_ip), None)
|
|
|
|
if not remote:
|
|
|
|
self.auth_tracker[str(remote_ip)] = {
|
|
|
|
"anti-lockout": {
|
|
|
|
"attempts": 1,
|
|
|
|
"times": [datetime.now().strftime("%d/%m/%Y %H:%M:%S")],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
if remote.get("anti-lockout", None):
|
|
|
|
remote["anti-lockout"]["attempts"] += 1
|
|
|
|
remote["anti-lockout"]["times"].append(
|
|
|
|
datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
|
|
|
)
|
|
|
|
self.auth_tracker[str(remote_ip)] = remote
|
|
|
|
else:
|
|
|
|
self.auth_tracker[str(remote_ip)]["anti-lockout"] = {
|
|
|
|
"attempts": 1,
|
|
|
|
"times": [datetime.now().strftime("%d/%m/%Y %H:%M:%S")],
|
|
|
|
}
|
|
|
|
|
2023-11-05 19:17:50 +00:00
|
|
|
def write_auth_tracker(self):
|
2023-11-05 18:26:27 +00:00
|
|
|
with open(
|
|
|
|
os.path.join(os.path.curdir, "logs", "auth_tracker.log"),
|
|
|
|
"w",
|
|
|
|
encoding="utf-8",
|
|
|
|
) as f:
|
|
|
|
json.dump(self.auth_tracker, f, indent=4)
|
2020-08-17 02:47:53 +00:00
|
|
|
|
2021-12-21 01:17:28 +00:00
|
|
|
@staticmethod
|
|
|
|
def check_system_user():
|
2022-05-20 10:31:30 +00:00
|
|
|
return HelperUsers.get_user_id_by_name("system") is not None
|
2021-12-21 01:17:28 +00:00
|
|
|
|
2022-01-14 04:01:18 +00:00
|
|
|
def set_project_root(self, root_dir):
|
|
|
|
self.project_root = root_dir
|
|
|
|
|
2023-08-15 20:09:06 +00:00
|
|
|
def set_config_json(self, data):
|
2023-08-15 20:46:04 +00:00
|
|
|
current_config = self.helper.get_all_settings()
|
|
|
|
for key in current_config:
|
|
|
|
if key in data:
|
|
|
|
current_config[key] = data[key]
|
|
|
|
keys = list(current_config.keys())
|
2023-08-15 20:09:06 +00:00
|
|
|
keys.sort()
|
2023-08-15 20:46:04 +00:00
|
|
|
sorted_data = {i: current_config[i] for i in keys}
|
2023-08-15 20:09:06 +00:00
|
|
|
with open(self.helper.settings_file, "w", encoding="utf-8") as f:
|
|
|
|
json.dump(sorted_data, f, indent=4)
|
|
|
|
|
2022-01-14 01:42:53 +00:00
|
|
|
def package_support_logs(self, exec_user):
|
2022-03-23 02:50:12 +00:00
|
|
|
if exec_user["preparing"]:
|
2022-03-13 12:29:26 +00:00
|
|
|
return
|
2022-03-23 02:50:12 +00:00
|
|
|
self.users.set_prepare(exec_user["user_id"])
|
2022-06-16 16:11:21 +00:00
|
|
|
logger.info("Checking for previous support logs.")
|
|
|
|
if exec_user["support_logs"] != "":
|
2022-07-06 01:35:43 +00:00
|
|
|
if os.path.exists(exec_user["support_logs"]):
|
|
|
|
logger.info(
|
|
|
|
f"Found previous support log request at {exec_user['support_logs']}"
|
|
|
|
)
|
|
|
|
if self.helper.validate_traversal(
|
|
|
|
os.path.join(self.project_root, "temp"), exec_user["support_logs"]
|
|
|
|
):
|
|
|
|
logger.debug("No transversal detected. Going for the delete.")
|
|
|
|
self.del_support_file(exec_user["support_logs"])
|
2022-03-23 02:50:12 +00:00
|
|
|
# pausing so on screen notifications can run for user
|
2022-01-18 18:16:09 +00:00
|
|
|
time.sleep(7)
|
2023-08-09 21:47:53 +00:00
|
|
|
WebSocketManager().broadcast_user(
|
2022-03-23 02:50:12 +00:00
|
|
|
exec_user["user_id"], "notification", "Preparing your support logs"
|
|
|
|
)
|
2022-07-06 01:35:43 +00:00
|
|
|
self.helper.ensure_dir_exists(
|
|
|
|
os.path.join(self.project_root, "temp", str(exec_user["user_id"]))
|
|
|
|
)
|
|
|
|
temp_dir = os.path.join(
|
|
|
|
self.project_root, "temp", str(exec_user["user_id"]), "support_logs"
|
|
|
|
)
|
|
|
|
|
|
|
|
self.helper.ensure_dir_exists(
|
|
|
|
os.path.join(self.project_root, "temp", str(exec_user["user_id"]), "zip")
|
|
|
|
)
|
|
|
|
temp_zip_storage = os.path.join(
|
|
|
|
self.project_root, "temp", str(exec_user["user_id"]), "zip"
|
|
|
|
)
|
|
|
|
os.mkdir(temp_dir)
|
2022-04-14 02:10:25 +00:00
|
|
|
temp_zip_storage = os.path.join(temp_zip_storage, "support_logs")
|
2022-07-06 01:35:43 +00:00
|
|
|
crafty_path = os.path.join(temp_dir, "crafty")
|
2022-01-14 01:42:53 +00:00
|
|
|
os.mkdir(crafty_path)
|
2022-07-06 01:35:43 +00:00
|
|
|
server_path = os.path.join(temp_dir, "server")
|
2022-01-14 01:42:53 +00:00
|
|
|
os.mkdir(server_path)
|
2022-03-23 02:50:12 +00:00
|
|
|
if exec_user["superuser"]:
|
2022-06-02 12:57:36 +00:00
|
|
|
defined_servers = self.servers.list_defined_servers()
|
|
|
|
user_servers = []
|
|
|
|
for server in defined_servers:
|
|
|
|
if server not in user_servers:
|
|
|
|
user_servers.append(
|
|
|
|
DatabaseShortcuts.get_data_obj(server.server_object)
|
|
|
|
)
|
|
|
|
auth_servers = user_servers
|
2022-01-14 01:42:53 +00:00
|
|
|
else:
|
2022-06-02 12:23:18 +00:00
|
|
|
defined_servers = self.servers.get_authorized_servers(
|
2022-03-23 02:50:12 +00:00
|
|
|
int(exec_user["user_id"])
|
|
|
|
)
|
2022-06-02 12:23:18 +00:00
|
|
|
user_servers = []
|
|
|
|
for server in defined_servers:
|
|
|
|
if server not in user_servers:
|
|
|
|
user_servers.append(
|
|
|
|
DatabaseShortcuts.get_data_obj(server.server_object)
|
|
|
|
)
|
2022-01-14 01:42:53 +00:00
|
|
|
auth_servers = []
|
|
|
|
for server in user_servers:
|
2022-03-23 02:50:12 +00:00
|
|
|
if (
|
2022-04-14 02:10:25 +00:00
|
|
|
EnumPermissionsServer.LOGS
|
2022-03-23 02:50:12 +00:00
|
|
|
in self.server_perms.get_user_id_permissions_list(
|
|
|
|
exec_user["user_id"], server["server_id"]
|
|
|
|
)
|
|
|
|
):
|
2022-01-14 01:42:53 +00:00
|
|
|
auth_servers.append(server)
|
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
logger.info(
|
2022-03-23 06:06:13 +00:00
|
|
|
f"Logs permission not available for server "
|
|
|
|
f"{server['server_name']}. Skipping."
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
|
|
|
# we'll iterate through our list of log paths from auth servers.
|
2022-01-14 01:42:53 +00:00
|
|
|
for server in auth_servers:
|
2022-03-23 02:50:12 +00:00
|
|
|
final_path = os.path.join(server_path, str(server["server_name"]))
|
2022-03-14 21:39:19 +00:00
|
|
|
try:
|
|
|
|
os.mkdir(final_path)
|
|
|
|
except FileExistsError:
|
2023-11-01 17:44:56 +00:00
|
|
|
final_path += "_" + server["server_id"]
|
2022-03-14 21:39:19 +00:00
|
|
|
os.mkdir(final_path)
|
2022-01-19 22:23:04 +00:00
|
|
|
try:
|
2022-07-18 18:55:12 +00:00
|
|
|
FileHelpers.copy_file(
|
|
|
|
pathlib.Path(server["path"], server["log_path"]),
|
|
|
|
final_path,
|
|
|
|
)
|
2022-01-19 22:23:04 +00:00
|
|
|
except Exception as e:
|
2022-01-26 01:45:30 +00:00
|
|
|
logger.warning(f"Failed to copy file with error: {e}")
|
2022-03-23 02:50:12 +00:00
|
|
|
# Copy crafty logs to archive dir
|
|
|
|
full_log_name = os.path.join(crafty_path, "logs")
|
2022-04-11 05:23:55 +00:00
|
|
|
FileHelpers.copy_dir(os.path.join(self.project_root, "logs"), full_log_name)
|
2022-03-23 02:50:12 +00:00
|
|
|
self.support_scheduler.add_job(
|
|
|
|
self.log_status,
|
|
|
|
"interval",
|
|
|
|
seconds=1,
|
|
|
|
id="logs_" + str(exec_user["user_id"]),
|
2022-07-06 01:35:43 +00:00
|
|
|
args=[temp_dir, temp_zip_storage + ".zip", exec_user],
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-07-17 20:37:10 +00:00
|
|
|
# Make version file .txt when we download it for support
|
|
|
|
# Most people have a default editor for .txt also more mobile friendly...
|
2022-08-26 14:57:35 +00:00
|
|
|
sys_info_string = (
|
|
|
|
f"Crafty v{self.helper.get_version_string()} Support Logs\n"
|
|
|
|
f"\n"
|
2022-08-26 15:23:08 +00:00
|
|
|
f"OS Info:- \n"
|
2022-08-26 14:57:35 +00:00
|
|
|
f"OS: {str(platform.system())}\n"
|
|
|
|
f"Version: {str(platform.release())}"
|
2022-08-26 15:23:08 +00:00
|
|
|
f"\n \n"
|
|
|
|
f"Log archive created on: {datetime.now()}"
|
2022-07-17 20:37:10 +00:00
|
|
|
)
|
|
|
|
with open(
|
|
|
|
os.path.join(temp_dir, "crafty_sys_info.txt"), "a", encoding="utf-8"
|
|
|
|
) as f:
|
2022-08-26 14:57:35 +00:00
|
|
|
f.write(sys_info_string)
|
|
|
|
FileHelpers.make_compressed_archive(temp_zip_storage, temp_dir, sys_info_string)
|
2023-08-09 21:47:53 +00:00
|
|
|
if len(WebSocketManager().clients) > 0:
|
|
|
|
WebSocketManager().broadcast_user(
|
2022-03-23 02:50:12 +00:00
|
|
|
exec_user["user_id"],
|
|
|
|
"support_status_update",
|
2022-07-06 01:35:43 +00:00
|
|
|
Helpers.calc_percent(temp_dir, temp_zip_storage + ".zip"),
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-01-14 01:42:53 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
temp_zip_storage += ".zip"
|
2023-08-09 21:47:53 +00:00
|
|
|
WebSocketManager().broadcast_user(exec_user["user_id"], "send_logs_bootbox", {})
|
2022-01-19 20:33:24 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
self.users.set_support_path(exec_user["user_id"], temp_zip_storage)
|
2022-03-13 13:26:38 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
self.users.stop_prepare(exec_user["user_id"])
|
|
|
|
self.support_scheduler.remove_job("logs_" + str(exec_user["user_id"]))
|
2022-01-14 01:42:53 +00:00
|
|
|
|
2022-06-01 21:54:58 +00:00
|
|
|
FileHelpers.del_dirs(temp_dir)
|
|
|
|
|
2022-06-01 22:31:31 +00:00
|
|
|
def del_support_file(self, temp_zip_storage):
|
2022-06-01 21:54:58 +00:00
|
|
|
try:
|
|
|
|
FileHelpers.del_file(temp_zip_storage)
|
2022-06-16 16:11:21 +00:00
|
|
|
logger.info(
|
|
|
|
f"Old support logs successfully deleted from {temp_zip_storage}"
|
|
|
|
)
|
2022-06-01 21:54:58 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
logger.info("No temp file found. Assuming it's already been cleaned up")
|
2022-06-14 19:42:13 +00:00
|
|
|
except PermissionError:
|
|
|
|
logger.error("Unable to remove old logs. Permission denied error.")
|
2022-06-01 21:54:58 +00:00
|
|
|
|
2022-04-17 17:27:00 +00:00
|
|
|
def add_system_user(self):
|
|
|
|
self.users_helper.add_user(
|
2022-03-23 02:50:12 +00:00
|
|
|
"system",
|
2022-04-11 05:23:55 +00:00
|
|
|
Helpers.random_string_generator(64),
|
2022-03-23 02:50:12 +00:00
|
|
|
"default@example.com",
|
|
|
|
False,
|
|
|
|
False,
|
|
|
|
)
|
2021-12-21 01:17:28 +00:00
|
|
|
|
2022-03-13 12:29:26 +00:00
|
|
|
def log_status(self, source_path, dest_path, exec_user):
|
2022-04-11 05:23:55 +00:00
|
|
|
results = Helpers.calc_percent(source_path, dest_path)
|
2022-03-13 12:29:26 +00:00
|
|
|
self.log_stats = results
|
|
|
|
|
2023-08-09 21:47:53 +00:00
|
|
|
if len(WebSocketManager().clients) > 0:
|
|
|
|
WebSocketManager().broadcast_user(
|
2022-03-23 02:50:12 +00:00
|
|
|
exec_user["user_id"], "support_status_update", results
|
|
|
|
)
|
2022-03-13 13:26:38 +00:00
|
|
|
|
2022-10-13 19:17:31 +00:00
|
|
|
def get_config_diff(self):
|
2023-01-29 19:54:25 +00:00
|
|
|
master_config = Helpers.get_master_config()
|
2022-10-13 19:17:31 +00:00
|
|
|
try:
|
2023-01-29 19:54:25 +00:00
|
|
|
user_config = self.helper.get_all_settings()
|
2022-10-13 19:17:31 +00:00
|
|
|
except:
|
2023-01-29 19:54:25 +00:00
|
|
|
# Call helper to set updated config.
|
|
|
|
Console.warning("No Config found. Setting Default Config.json")
|
2023-01-29 23:21:04 +00:00
|
|
|
user_config = master_config
|
|
|
|
keys = list(user_config.keys())
|
|
|
|
keys.sort()
|
|
|
|
sorted_data = {i: user_config[i] for i in keys}
|
|
|
|
self.helper.set_settings(user_config)
|
2023-01-29 19:54:25 +00:00
|
|
|
return
|
2022-10-13 19:17:31 +00:00
|
|
|
items_to_del = []
|
|
|
|
|
2022-10-13 19:25:29 +00:00
|
|
|
# Iterate through user's config.json and check for
|
|
|
|
# Keys/values that need to be removed
|
2022-10-13 19:17:31 +00:00
|
|
|
for key in user_config:
|
|
|
|
if key not in master_config.keys():
|
|
|
|
items_to_del.append(key)
|
|
|
|
|
2022-10-13 19:25:29 +00:00
|
|
|
# Remove key/values from user config that were staged
|
2022-10-13 19:17:31 +00:00
|
|
|
for item in items_to_del[:]:
|
|
|
|
del user_config[item]
|
|
|
|
|
2022-10-13 19:25:29 +00:00
|
|
|
# Add new keys to user config.
|
2022-10-13 19:17:31 +00:00
|
|
|
for key, value in master_config.items():
|
|
|
|
if key not in user_config.keys():
|
|
|
|
user_config[key] = value
|
2022-10-13 19:25:29 +00:00
|
|
|
# Call helper to set updated config.
|
2023-01-29 23:21:04 +00:00
|
|
|
keys = list(user_config.keys())
|
|
|
|
keys.sort()
|
|
|
|
sorted_data = {i: user_config[i] for i in keys}
|
|
|
|
self.helper.set_settings(sorted_data)
|
2022-10-13 19:17:31 +00:00
|
|
|
|
2022-03-13 12:29:26 +00:00
|
|
|
def send_log_status(self):
|
|
|
|
try:
|
|
|
|
return self.log_stats
|
|
|
|
except:
|
2022-03-23 02:50:12 +00:00
|
|
|
return {"percent": 0, "total_files": 0}
|
2022-01-31 02:04:08 +00:00
|
|
|
|
2022-08-20 17:00:20 +00:00
|
|
|
def create_api_server(self, data: dict, user_id):
|
2022-05-05 11:02:23 +00:00
|
|
|
server_fs_uuid = Helpers.create_uuid()
|
|
|
|
new_server_path = os.path.join(self.helper.servers_dir, server_fs_uuid)
|
|
|
|
backup_path = os.path.join(self.helper.backup_path, server_fs_uuid)
|
|
|
|
|
|
|
|
if Helpers.is_os_windows():
|
|
|
|
new_server_path = Helpers.wtol_path(new_server_path)
|
|
|
|
backup_path = Helpers.wtol_path(backup_path)
|
|
|
|
new_server_path.replace(" ", "^ ")
|
|
|
|
backup_path.replace(" ", "^ ")
|
|
|
|
|
|
|
|
Helpers.ensure_dir_exists(new_server_path)
|
|
|
|
Helpers.ensure_dir_exists(backup_path)
|
|
|
|
|
|
|
|
def _create_server_properties_if_needed(port, empty=False):
|
|
|
|
properties_file = os.path.join(new_server_path, "server.properties")
|
|
|
|
has_properties = os.path.exists(properties_file)
|
|
|
|
|
|
|
|
if not has_properties:
|
|
|
|
logger.info(
|
|
|
|
f"No server.properties found on import."
|
|
|
|
f"Creating one with port selection of {port}"
|
|
|
|
)
|
|
|
|
with open(
|
|
|
|
properties_file,
|
|
|
|
"w",
|
|
|
|
encoding="utf-8",
|
|
|
|
) as file:
|
|
|
|
file.write(
|
|
|
|
"# generated by Crafty Controller"
|
|
|
|
+ ("" if empty else f"\nserver-port={port}")
|
|
|
|
)
|
|
|
|
|
2022-05-19 22:33:02 +00:00
|
|
|
server_file = "server.jar" # HACK: Throw this horrible default out of here
|
2022-05-05 11:02:23 +00:00
|
|
|
root_create_data = data[data["create_type"] + "_create_data"]
|
|
|
|
create_data = root_create_data[root_create_data["create_type"] + "_create_data"]
|
|
|
|
if data["create_type"] == "minecraft_java":
|
|
|
|
if root_create_data["create_type"] == "download_jar":
|
|
|
|
server_file = f"{create_data['type']}-{create_data['version']}.jar"
|
|
|
|
|
|
|
|
# Create an EULA file
|
2023-08-17 19:11:29 +00:00
|
|
|
if "agree_to_eula" in create_data:
|
|
|
|
with open(
|
|
|
|
os.path.join(new_server_path, "eula.txt"), "w", encoding="utf-8"
|
|
|
|
) as file:
|
|
|
|
file.write(
|
|
|
|
"eula="
|
|
|
|
+ ("true" if create_data["agree_to_eula"] else "false")
|
|
|
|
)
|
2022-05-05 11:02:23 +00:00
|
|
|
elif root_create_data["create_type"] == "import_server":
|
2022-05-19 22:33:02 +00:00
|
|
|
server_file = create_data["jarfile"]
|
2022-05-05 11:02:23 +00:00
|
|
|
elif root_create_data["create_type"] == "import_zip":
|
|
|
|
# TODO: Copy files from the zip file to the new server directory
|
2022-05-19 22:33:02 +00:00
|
|
|
server_file = create_data["jarfile"]
|
2023-02-15 23:40:20 +00:00
|
|
|
raise NotImplementedError("Not yet implemented")
|
2023-09-04 22:19:29 +00:00
|
|
|
# self.import_helper.import_java_zip_server()
|
2023-09-03 17:20:02 +00:00
|
|
|
if data["create_type"] == "minecraft_java":
|
2023-08-25 17:54:31 +00:00
|
|
|
_create_server_properties_if_needed(
|
|
|
|
create_data["server_properties_port"],
|
|
|
|
)
|
2022-05-05 11:02:23 +00:00
|
|
|
|
|
|
|
min_mem = create_data["mem_min"]
|
|
|
|
max_mem = create_data["mem_max"]
|
|
|
|
|
2022-05-19 22:33:02 +00:00
|
|
|
full_jar_path = os.path.join(new_server_path, server_file)
|
|
|
|
|
2022-05-05 11:02:23 +00:00
|
|
|
def _gibs_to_mibs(gibs: float) -> str:
|
|
|
|
return str(int(gibs * 1024))
|
|
|
|
|
|
|
|
def _wrap_jar_if_windows():
|
2022-06-15 23:10:26 +00:00
|
|
|
return f'"{server_file}"' if Helpers.is_os_windows() else server_file
|
2022-05-05 11:02:23 +00:00
|
|
|
|
2023-08-17 19:11:29 +00:00
|
|
|
if root_create_data["create_type"] == "download_jar":
|
|
|
|
if Helpers.is_os_windows():
|
|
|
|
# Let's check for and setup for install server commands
|
|
|
|
if create_data["type"] == "forge":
|
|
|
|
server_command = (
|
|
|
|
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
|
|
|
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
|
|
|
f'-jar "{server_file}" --installServer'
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
server_command = (
|
|
|
|
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
|
|
|
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
|
|
|
f'-jar "{server_file}" nogui'
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
if create_data["type"] == "forge":
|
|
|
|
server_command = (
|
|
|
|
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
|
|
|
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
|
|
|
f"-jar {server_file} --installServer"
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
server_command = (
|
|
|
|
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
|
|
|
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
|
|
|
f"-jar {server_file} nogui"
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
server_command = (
|
|
|
|
f"java -Xms{_gibs_to_mibs(min_mem)}M "
|
|
|
|
f"-Xmx{_gibs_to_mibs(max_mem)}M "
|
|
|
|
f"-jar {_wrap_jar_if_windows()} nogui"
|
|
|
|
)
|
|
|
|
|
2022-05-05 11:02:23 +00:00
|
|
|
elif data["create_type"] == "minecraft_bedrock":
|
|
|
|
if root_create_data["create_type"] == "import_server":
|
|
|
|
existing_server_path = Helpers.get_os_understandable_path(
|
|
|
|
create_data["existing_server_path"]
|
|
|
|
)
|
2023-08-24 00:44:11 +00:00
|
|
|
if Helpers.is_os_windows():
|
|
|
|
server_command = (
|
|
|
|
f'"{os.path.join(new_server_path, create_data["executable"])}"'
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
server_command = f"./{create_data['executable']}"
|
|
|
|
logger.debug("command: " + server_command)
|
2023-09-03 17:20:02 +00:00
|
|
|
server_file = create_data["executable"]
|
2022-05-05 11:02:23 +00:00
|
|
|
elif root_create_data["create_type"] == "import_zip":
|
|
|
|
# TODO: Copy files from the zip file to the new server directory
|
2023-02-15 23:40:20 +00:00
|
|
|
raise NotImplementedError("Not yet implemented")
|
2023-08-25 17:54:31 +00:00
|
|
|
else:
|
|
|
|
server_file = "bedrock_server"
|
|
|
|
if Helpers.is_os_windows():
|
|
|
|
# if this is windows we will override the linux bedrock server name.
|
|
|
|
server_file = "bedrock_server.exe"
|
2022-05-05 11:02:23 +00:00
|
|
|
|
2023-08-25 17:54:31 +00:00
|
|
|
full_jar_path = os.path.join(new_server_path, server_file)
|
2022-05-05 11:02:23 +00:00
|
|
|
|
2023-08-25 17:54:31 +00:00
|
|
|
if self.helper.is_os_windows():
|
2023-08-27 18:55:10 +00:00
|
|
|
server_command = f'"{full_jar_path}"'
|
2023-08-25 17:54:31 +00:00
|
|
|
else:
|
2023-08-27 18:55:10 +00:00
|
|
|
server_command = f"./{server_file}"
|
2022-05-05 11:02:23 +00:00
|
|
|
_create_server_properties_if_needed(0, True)
|
|
|
|
|
2023-08-27 18:55:10 +00:00
|
|
|
server_command = create_data.get("command", server_command)
|
2022-05-05 11:02:23 +00:00
|
|
|
elif data["create_type"] == "custom":
|
|
|
|
# TODO: working_directory, executable_update
|
|
|
|
if root_create_data["create_type"] == "raw_exec":
|
|
|
|
pass
|
|
|
|
elif root_create_data["create_type"] == "import_server":
|
|
|
|
existing_server_path = Helpers.get_os_understandable_path(
|
|
|
|
create_data["existing_server_path"]
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
FileHelpers.copy_dir(existing_server_path, new_server_path, True)
|
|
|
|
except shutil.Error as ex:
|
|
|
|
logger.error(f"Server import failed with error: {ex}")
|
|
|
|
elif root_create_data["create_type"] == "import_zip":
|
|
|
|
# TODO: Copy files from the zip file to the new server directory
|
2023-02-15 23:40:20 +00:00
|
|
|
raise NotImplementedError("Not yet implemented")
|
2022-05-05 11:02:23 +00:00
|
|
|
|
|
|
|
_create_server_properties_if_needed(0, True)
|
|
|
|
|
|
|
|
server_command = create_data["command"]
|
2022-05-19 22:33:02 +00:00
|
|
|
|
|
|
|
server_file_new = root_create_data["executable_update"].get("file", "")
|
|
|
|
if server_file_new != "":
|
|
|
|
# HACK: Horrible hack to make the server start
|
|
|
|
server_file = server_file_new
|
2022-05-05 11:02:23 +00:00
|
|
|
|
|
|
|
stop_command = data.get("stop_command", "")
|
|
|
|
if stop_command == "":
|
|
|
|
# TODO: different default stop commands for server creation types
|
|
|
|
stop_command = "stop"
|
|
|
|
|
|
|
|
log_location = data.get("log_location", "")
|
2022-06-15 23:10:26 +00:00
|
|
|
if log_location == "" and data["create_type"] == "minecraft_java":
|
2022-05-19 14:27:36 +00:00
|
|
|
log_location = "./logs/latest.log"
|
2022-05-05 11:02:23 +00:00
|
|
|
|
|
|
|
if data["monitoring_type"] == "minecraft_java":
|
|
|
|
monitoring_port = data["minecraft_java_monitoring_data"]["port"]
|
|
|
|
monitoring_host = data["minecraft_java_monitoring_data"]["host"]
|
|
|
|
monitoring_type = "minecraft-java"
|
|
|
|
elif data["monitoring_type"] == "minecraft_bedrock":
|
|
|
|
monitoring_port = data["minecraft_bedrock_monitoring_data"]["port"]
|
|
|
|
monitoring_host = data["minecraft_bedrock_monitoring_data"]["host"]
|
|
|
|
monitoring_type = "minecraft-bedrock"
|
|
|
|
elif data["monitoring_type"] == "none":
|
|
|
|
# TODO: this needs to be NUKED..
|
2022-05-19 22:33:02 +00:00
|
|
|
# There shouldn't be anything set if there is nothing to monitor
|
2022-05-05 11:02:23 +00:00
|
|
|
monitoring_port = 25565
|
|
|
|
monitoring_host = "127.0.0.1"
|
|
|
|
monitoring_type = "minecraft-java"
|
|
|
|
|
|
|
|
new_server_id = self.register_server(
|
|
|
|
name=data["name"],
|
|
|
|
server_uuid=server_fs_uuid,
|
|
|
|
server_dir=new_server_path,
|
|
|
|
backup_path=backup_path,
|
|
|
|
server_command=server_command,
|
|
|
|
server_file=server_file,
|
|
|
|
server_log_file=log_location,
|
|
|
|
server_stop=stop_command,
|
|
|
|
server_port=monitoring_port,
|
2022-08-20 17:00:20 +00:00
|
|
|
created_by=user_id,
|
2022-05-05 11:02:23 +00:00
|
|
|
server_host=monitoring_host,
|
|
|
|
server_type=monitoring_type,
|
|
|
|
)
|
2023-12-05 04:37:53 +00:00
|
|
|
self.management.set_backup_config(
|
|
|
|
new_server_id,
|
|
|
|
backup_path,
|
|
|
|
)
|
2023-08-24 00:44:11 +00:00
|
|
|
if data["create_type"] == "minecraft_java":
|
|
|
|
if root_create_data["create_type"] == "download_jar":
|
|
|
|
# modded update urls from server jars will only update the installer
|
2024-01-12 19:46:25 +00:00
|
|
|
if (
|
|
|
|
create_data["category"] != "modded"
|
|
|
|
and create_data["type"] not in ServerJars.get_paper_jars()
|
|
|
|
):
|
2023-08-24 00:44:11 +00:00
|
|
|
server_obj = self.servers.get_server_obj(new_server_id)
|
|
|
|
url = (
|
2024-04-05 19:01:37 +00:00
|
|
|
"https://api.serverjars.com/api/fetchJar/"
|
2024-01-12 19:46:25 +00:00
|
|
|
f"{create_data['category']}"
|
2023-08-24 00:44:11 +00:00
|
|
|
f"/{create_data['type']}/{create_data['version']}"
|
|
|
|
)
|
|
|
|
server_obj.executable_update_url = url
|
|
|
|
self.servers.update_server(server_obj)
|
|
|
|
self.server_jars.download_jar(
|
|
|
|
create_data["category"],
|
|
|
|
create_data["type"],
|
|
|
|
create_data["version"],
|
|
|
|
full_jar_path,
|
|
|
|
new_server_id,
|
2022-10-20 19:05:58 +00:00
|
|
|
)
|
2023-08-24 00:44:11 +00:00
|
|
|
elif root_create_data["create_type"] == "import_server":
|
|
|
|
ServersController.set_import(new_server_id)
|
|
|
|
self.import_helper.import_jar_server(
|
|
|
|
create_data["existing_server_path"],
|
2023-09-03 17:20:02 +00:00
|
|
|
new_server_path,
|
2023-08-24 00:44:11 +00:00
|
|
|
monitoring_port,
|
|
|
|
new_server_id,
|
|
|
|
)
|
|
|
|
elif root_create_data["create_type"] == "import_zip":
|
|
|
|
ServersController.set_import(new_server_id)
|
2020-09-10 15:01:57 +00:00
|
|
|
|
2023-08-25 17:54:31 +00:00
|
|
|
elif data["create_type"] == "minecraft_bedrock":
|
|
|
|
if root_create_data["create_type"] == "download_exe":
|
2023-08-24 00:44:11 +00:00
|
|
|
ServersController.set_import(new_server_id)
|
|
|
|
self.import_helper.download_bedrock_server(
|
|
|
|
new_server_path, new_server_id
|
2022-11-19 18:45:18 +00:00
|
|
|
)
|
2023-08-27 18:55:10 +00:00
|
|
|
elif root_create_data["create_type"] == "import_server":
|
2023-09-03 17:20:02 +00:00
|
|
|
ServersController.set_import(new_server_id)
|
2023-08-24 00:44:11 +00:00
|
|
|
full_exe_path = os.path.join(new_server_path, create_data["executable"])
|
|
|
|
self.import_helper.import_bedrock_server(
|
|
|
|
create_data["existing_server_path"],
|
2023-08-27 18:55:10 +00:00
|
|
|
new_server_path,
|
2023-08-24 00:44:11 +00:00
|
|
|
monitoring_port,
|
|
|
|
full_exe_path,
|
|
|
|
new_server_id,
|
2022-11-19 18:45:18 +00:00
|
|
|
)
|
2023-08-24 00:44:11 +00:00
|
|
|
elif root_create_data["create_type"] == "import_zip":
|
2023-09-03 17:20:02 +00:00
|
|
|
ServersController.set_import(new_server_id)
|
2023-08-24 00:44:11 +00:00
|
|
|
full_exe_path = os.path.join(new_server_path, create_data["executable"])
|
|
|
|
self.import_helper.import_bedrock_zip_server(
|
|
|
|
create_data["zip_path"],
|
|
|
|
new_server_path,
|
|
|
|
os.path.join(create_data["zip_root"], create_data["executable"]),
|
|
|
|
monitoring_port,
|
|
|
|
new_server_id,
|
2022-11-19 18:45:18 +00:00
|
|
|
)
|
2022-05-05 11:02:23 +00:00
|
|
|
|
2023-08-24 00:44:11 +00:00
|
|
|
exec_user = self.users.get_user_by_id(int(user_id))
|
|
|
|
captured_roles = data.get("roles", [])
|
|
|
|
# These lines create a new Role for the Server with full permissions
|
|
|
|
# and add the user to it if he's not a superuser
|
|
|
|
if len(captured_roles) == 0:
|
|
|
|
if not exec_user["superuser"]:
|
2023-11-01 17:44:56 +00:00
|
|
|
new_server_id = self.servers.get_server_data_by_id(new_server_id).get(
|
|
|
|
"server_id"
|
2022-11-19 18:45:18 +00:00
|
|
|
)
|
2023-08-24 00:44:11 +00:00
|
|
|
role_id = self.roles.add_role(
|
2023-11-01 17:44:56 +00:00
|
|
|
f"Creator of Server with id={new_server_id}",
|
2023-08-24 00:44:11 +00:00
|
|
|
exec_user["user_id"],
|
|
|
|
)
|
|
|
|
self.server_perms.add_role_server(new_server_id, role_id, "11111111")
|
|
|
|
self.users.add_role_to_user(exec_user["user_id"], role_id)
|
2020-09-10 15:01:57 +00:00
|
|
|
|
2023-08-24 00:44:11 +00:00
|
|
|
else:
|
|
|
|
for role in captured_roles:
|
|
|
|
role_id = role
|
|
|
|
self.server_perms.add_role_server(new_server_id, role_id, "11111111")
|
2022-03-04 00:36:36 +00:00
|
|
|
|
2023-11-10 22:16:04 +00:00
|
|
|
return new_server_id
|
2020-09-10 15:01:57 +00:00
|
|
|
|
2020-09-14 20:01:38 +00:00
|
|
|
@staticmethod
|
2022-03-23 02:50:12 +00:00
|
|
|
def verify_jar_server(server_path: str, server_jar: str):
|
2022-04-11 05:23:55 +00:00
|
|
|
server_path = Helpers.get_os_understandable_path(server_path)
|
|
|
|
path_check = Helpers.check_path_exists(server_path)
|
|
|
|
jar_check = Helpers.check_file_exists(os.path.join(server_path, server_jar))
|
2020-09-14 20:01:38 +00:00
|
|
|
if not path_check or not jar_check:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2020-12-12 17:54:10 +00:00
|
|
|
@staticmethod
|
|
|
|
def verify_zip_server(zip_path: str):
|
2022-04-11 05:23:55 +00:00
|
|
|
zip_path = Helpers.get_os_understandable_path(zip_path)
|
|
|
|
zip_check = Helpers.check_file_exists(zip_path)
|
2020-12-12 17:54:10 +00:00
|
|
|
if not zip_check:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2023-09-27 01:08:11 +00:00
|
|
|
def restore_java_zip_server(
|
|
|
|
self,
|
|
|
|
server_name: str,
|
|
|
|
zip_path: str,
|
|
|
|
server_jar: str,
|
|
|
|
min_mem: int,
|
|
|
|
max_mem: int,
|
|
|
|
port: int,
|
|
|
|
user_id: int,
|
|
|
|
):
|
|
|
|
server_id = Helpers.create_uuid()
|
|
|
|
new_server_dir = os.path.join(self.helper.servers_dir, server_id)
|
|
|
|
backup_path = os.path.join(self.helper.backup_path, server_id)
|
|
|
|
if Helpers.is_os_windows():
|
|
|
|
new_server_dir = Helpers.wtol_path(new_server_dir)
|
|
|
|
backup_path = Helpers.wtol_path(backup_path)
|
|
|
|
new_server_dir.replace(" ", "^ ")
|
|
|
|
backup_path.replace(" ", "^ ")
|
|
|
|
|
|
|
|
temp_dir = Helpers.get_os_understandable_path(zip_path)
|
|
|
|
Helpers.ensure_dir_exists(new_server_dir)
|
|
|
|
Helpers.ensure_dir_exists(backup_path)
|
|
|
|
|
|
|
|
full_jar_path = os.path.join(new_server_dir, server_jar)
|
|
|
|
|
|
|
|
if Helpers.is_os_windows():
|
|
|
|
server_command = (
|
|
|
|
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
|
|
|
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
|
|
|
f'-jar "{full_jar_path}" nogui'
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
server_command = (
|
|
|
|
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
|
|
|
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
|
|
|
f"-jar {full_jar_path} nogui"
|
|
|
|
)
|
|
|
|
logger.debug("command: " + server_command)
|
|
|
|
server_log_file = "./logs/latest.log"
|
|
|
|
server_stop = "stop"
|
|
|
|
|
|
|
|
new_id = self.register_server(
|
|
|
|
server_name,
|
|
|
|
server_id,
|
|
|
|
new_server_dir,
|
|
|
|
backup_path,
|
|
|
|
server_command,
|
|
|
|
server_jar,
|
|
|
|
server_log_file,
|
|
|
|
server_stop,
|
|
|
|
port,
|
|
|
|
user_id,
|
|
|
|
server_type="minecraft-java",
|
|
|
|
)
|
|
|
|
ServersController.set_import(new_id)
|
|
|
|
self.import_helper.import_java_zip_server(
|
|
|
|
temp_dir, new_server_dir, port, new_id
|
|
|
|
)
|
|
|
|
return new_id
|
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2022-02-10 23:20:36 +00:00
|
|
|
# BEDROCK IMPORTS
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2022-02-10 20:27:40 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
def import_bedrock_server(
|
2022-08-20 17:00:20 +00:00
|
|
|
self,
|
|
|
|
server_name: str,
|
|
|
|
server_path: str,
|
|
|
|
server_exe: str,
|
|
|
|
port: int,
|
|
|
|
user_id: int,
|
2022-03-23 02:50:12 +00:00
|
|
|
):
|
2022-04-11 05:23:55 +00:00
|
|
|
server_id = Helpers.create_uuid()
|
|
|
|
new_server_dir = os.path.join(self.helper.servers_dir, server_id)
|
|
|
|
backup_path = os.path.join(self.helper.backup_path, server_id)
|
|
|
|
if Helpers.is_os_windows():
|
|
|
|
new_server_dir = Helpers.wtol_path(new_server_dir)
|
|
|
|
backup_path = Helpers.wtol_path(backup_path)
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_dir.replace(" ", "^ ")
|
|
|
|
backup_path.replace(" ", "^ ")
|
2022-02-10 20:27:40 +00:00
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
Helpers.ensure_dir_exists(new_server_dir)
|
|
|
|
Helpers.ensure_dir_exists(backup_path)
|
|
|
|
server_path = Helpers.get_os_understandable_path(server_path)
|
2022-02-10 20:27:40 +00:00
|
|
|
|
|
|
|
full_jar_path = os.path.join(new_server_dir, server_exe)
|
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
if Helpers.is_os_windows():
|
2022-02-10 20:27:40 +00:00
|
|
|
server_command = f'"{full_jar_path}"'
|
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
server_command = f"./{server_exe}"
|
|
|
|
logger.debug("command: " + server_command)
|
2022-06-15 23:10:26 +00:00
|
|
|
server_log_file = ""
|
2022-02-10 20:27:40 +00:00
|
|
|
server_stop = "stop"
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
new_id = self.register_server(
|
|
|
|
server_name,
|
|
|
|
server_id,
|
|
|
|
new_server_dir,
|
|
|
|
backup_path,
|
|
|
|
server_command,
|
|
|
|
server_exe,
|
|
|
|
server_log_file,
|
|
|
|
server_stop,
|
|
|
|
port,
|
2022-08-20 17:00:20 +00:00
|
|
|
user_id,
|
2022-03-23 02:50:12 +00:00
|
|
|
server_type="minecraft-bedrock",
|
|
|
|
)
|
2022-08-17 23:07:56 +00:00
|
|
|
ServersController.set_import(new_id)
|
|
|
|
self.import_helper.import_bedrock_server(
|
|
|
|
server_path, new_server_dir, port, full_jar_path, new_id
|
|
|
|
)
|
2022-02-10 20:27:40 +00:00
|
|
|
return new_id
|
|
|
|
|
2022-08-31 23:45:19 +00:00
|
|
|
def create_bedrock_server(self, server_name, user_id):
|
|
|
|
server_id = Helpers.create_uuid()
|
|
|
|
new_server_dir = os.path.join(self.helper.servers_dir, server_id)
|
|
|
|
backup_path = os.path.join(self.helper.backup_path, server_id)
|
|
|
|
server_exe = "bedrock_server"
|
|
|
|
if Helpers.is_os_windows():
|
|
|
|
# if this is windows we will override the linux bedrock server name.
|
|
|
|
server_exe = "bedrock_server.exe"
|
|
|
|
new_server_dir = Helpers.wtol_path(new_server_dir)
|
|
|
|
backup_path = Helpers.wtol_path(backup_path)
|
|
|
|
new_server_dir.replace(" ", "^ ")
|
|
|
|
backup_path.replace(" ", "^ ")
|
|
|
|
|
|
|
|
Helpers.ensure_dir_exists(new_server_dir)
|
|
|
|
Helpers.ensure_dir_exists(backup_path)
|
|
|
|
|
|
|
|
full_jar_path = os.path.join(new_server_dir, server_exe)
|
|
|
|
|
|
|
|
if Helpers.is_os_windows():
|
|
|
|
server_command = f'"{full_jar_path}"'
|
|
|
|
else:
|
|
|
|
server_command = f"./{server_exe}"
|
|
|
|
logger.debug("command: " + server_command)
|
|
|
|
server_log_file = ""
|
|
|
|
server_stop = "stop"
|
|
|
|
|
|
|
|
new_id = self.register_server(
|
|
|
|
server_name,
|
|
|
|
server_id,
|
|
|
|
new_server_dir,
|
|
|
|
backup_path,
|
|
|
|
server_command,
|
|
|
|
server_exe,
|
|
|
|
server_log_file,
|
|
|
|
server_stop,
|
|
|
|
"19132",
|
|
|
|
user_id,
|
|
|
|
server_type="minecraft-bedrock",
|
|
|
|
)
|
|
|
|
ServersController.set_import(new_id)
|
|
|
|
self.import_helper.download_bedrock_server(new_server_dir, new_id)
|
|
|
|
return new_id
|
|
|
|
|
2023-09-27 01:08:11 +00:00
|
|
|
def restore_bedrock_zip_server(
|
2022-08-20 17:00:20 +00:00
|
|
|
self,
|
|
|
|
server_name: str,
|
|
|
|
zip_path: str,
|
|
|
|
server_exe: str,
|
|
|
|
port: int,
|
|
|
|
user_id: int,
|
2022-03-23 02:50:12 +00:00
|
|
|
):
|
2022-04-11 05:23:55 +00:00
|
|
|
server_id = Helpers.create_uuid()
|
|
|
|
new_server_dir = os.path.join(self.helper.servers_dir, server_id)
|
|
|
|
backup_path = os.path.join(self.helper.backup_path, server_id)
|
|
|
|
if Helpers.is_os_windows():
|
|
|
|
new_server_dir = Helpers.wtol_path(new_server_dir)
|
|
|
|
backup_path = Helpers.wtol_path(backup_path)
|
2022-03-23 02:50:12 +00:00
|
|
|
new_server_dir.replace(" ", "^ ")
|
|
|
|
backup_path.replace(" ", "^ ")
|
2022-02-10 20:27:40 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
temp_dir = Helpers.get_os_understandable_path(zip_path)
|
2022-04-11 05:23:55 +00:00
|
|
|
Helpers.ensure_dir_exists(new_server_dir)
|
|
|
|
Helpers.ensure_dir_exists(backup_path)
|
2022-02-10 20:27:40 +00:00
|
|
|
|
|
|
|
full_jar_path = os.path.join(new_server_dir, server_exe)
|
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
if Helpers.is_os_windows():
|
2022-02-10 20:27:40 +00:00
|
|
|
server_command = f'"{full_jar_path}"'
|
|
|
|
else:
|
2022-03-23 02:50:12 +00:00
|
|
|
server_command = f"./{server_exe}"
|
|
|
|
logger.debug("command: " + server_command)
|
2022-06-15 23:10:26 +00:00
|
|
|
server_log_file = ""
|
2022-02-10 20:27:40 +00:00
|
|
|
server_stop = "stop"
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
new_id = self.register_server(
|
|
|
|
server_name,
|
|
|
|
server_id,
|
|
|
|
new_server_dir,
|
|
|
|
backup_path,
|
|
|
|
server_command,
|
|
|
|
server_exe,
|
|
|
|
server_log_file,
|
|
|
|
server_stop,
|
|
|
|
port,
|
2022-08-20 17:00:20 +00:00
|
|
|
user_id,
|
2022-03-23 02:50:12 +00:00
|
|
|
server_type="minecraft-bedrock",
|
|
|
|
)
|
2023-01-02 19:26:42 +00:00
|
|
|
ServersController.set_import(new_id)
|
2022-08-17 23:07:56 +00:00
|
|
|
self.import_helper.import_bedrock_zip_server(
|
|
|
|
temp_dir, new_server_dir, full_jar_path, port, new_id
|
|
|
|
)
|
2022-03-01 23:31:38 +00:00
|
|
|
if os.name != "nt":
|
2022-04-11 05:23:55 +00:00
|
|
|
if Helpers.check_file_exists(full_jar_path):
|
2022-06-03 11:42:20 +00:00
|
|
|
os.chmod(full_jar_path, 0o2760)
|
2022-03-01 23:31:38 +00:00
|
|
|
|
2022-02-10 20:27:40 +00:00
|
|
|
return new_id
|
|
|
|
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2022-02-10 23:20:36 +00:00
|
|
|
# BEDROCK IMPORTS END
|
2022-03-23 06:06:13 +00:00
|
|
|
# **********************************************************************************
|
2022-02-10 20:27:40 +00:00
|
|
|
|
2021-11-29 21:22:46 +00:00
|
|
|
def rename_backup_dir(self, old_server_id, new_server_id, new_uuid):
|
|
|
|
server_data = self.servers.get_server_data_by_id(old_server_id)
|
2022-07-05 18:45:13 +00:00
|
|
|
server_obj = self.servers.get_server_obj(new_server_id)
|
2022-03-23 02:50:12 +00:00
|
|
|
old_bu_path = server_data["backup_path"]
|
2022-04-14 02:10:25 +00:00
|
|
|
ServerPermsController.backup_role_swap(old_server_id, new_server_id)
|
2022-07-05 18:45:13 +00:00
|
|
|
backup_path = old_bu_path
|
|
|
|
backup_path = Path(backup_path)
|
2021-11-29 21:22:46 +00:00
|
|
|
backup_path_components = list(backup_path.parts)
|
|
|
|
backup_path_components[-1] = new_uuid
|
|
|
|
new_bu_path = pathlib.PurePath(os.path.join(*backup_path_components))
|
2022-07-05 18:45:13 +00:00
|
|
|
server_obj.backup_path = new_bu_path
|
2022-07-05 18:55:17 +00:00
|
|
|
default_backup_dir = os.path.join(self.helper.backup_path, new_uuid)
|
|
|
|
try:
|
|
|
|
os.rmdir(default_backup_dir)
|
|
|
|
except:
|
|
|
|
logger.error("Could not delete default backup dir")
|
2022-07-05 18:45:13 +00:00
|
|
|
self.servers.update_server(server_obj)
|
2021-11-29 21:22:46 +00:00
|
|
|
backup_path.rename(new_bu_path)
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
def register_server(
|
|
|
|
self,
|
|
|
|
name: str,
|
|
|
|
server_uuid: str,
|
|
|
|
server_dir: str,
|
|
|
|
backup_path: str,
|
|
|
|
server_command: str,
|
|
|
|
server_file: str,
|
|
|
|
server_log_file: str,
|
|
|
|
server_stop: str,
|
|
|
|
server_port: int,
|
2022-08-20 17:00:20 +00:00
|
|
|
created_by: int,
|
2022-03-23 02:50:12 +00:00
|
|
|
server_type: str,
|
2022-05-05 11:02:23 +00:00
|
|
|
server_host: str = "127.0.0.1",
|
2022-03-23 02:50:12 +00:00
|
|
|
):
|
2020-09-10 15:01:57 +00:00
|
|
|
# put data in the db
|
2022-01-26 01:45:30 +00:00
|
|
|
new_id = self.servers.create_server(
|
2022-03-23 02:50:12 +00:00
|
|
|
name,
|
|
|
|
server_uuid,
|
|
|
|
server_dir,
|
|
|
|
backup_path,
|
|
|
|
server_command,
|
|
|
|
server_file,
|
|
|
|
server_log_file,
|
|
|
|
server_stop,
|
|
|
|
server_type,
|
2022-08-20 17:00:20 +00:00
|
|
|
created_by,
|
2022-03-23 02:50:12 +00:00
|
|
|
server_port,
|
2022-05-05 11:02:23 +00:00
|
|
|
server_host,
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2022-04-11 10:08:36 +00:00
|
|
|
if not Helpers.check_file_exists(
|
|
|
|
os.path.join(server_dir, "crafty_managed.txt")
|
|
|
|
):
|
2021-11-29 21:22:46 +00:00
|
|
|
try:
|
|
|
|
# place a file in the dir saying it's owned by crafty
|
2022-03-23 02:50:12 +00:00
|
|
|
with open(
|
|
|
|
os.path.join(server_dir, "crafty_managed.txt"),
|
|
|
|
"w",
|
|
|
|
encoding="utf-8",
|
2022-04-14 02:10:25 +00:00
|
|
|
) as file:
|
|
|
|
file.write(
|
2022-03-23 06:06:13 +00:00
|
|
|
"The server is managed by Crafty Controller.\n "
|
|
|
|
"Leave this directory/files alone please"
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2021-11-29 21:22:46 +00:00
|
|
|
|
|
|
|
except Exception as e:
|
2022-01-26 01:45:30 +00:00
|
|
|
logger.error(f"Unable to create required server files due to :{e}")
|
2021-11-29 21:22:46 +00:00
|
|
|
return False
|
2020-09-10 15:01:57 +00:00
|
|
|
|
|
|
|
# let's re-init all servers
|
2022-05-26 12:50:20 +00:00
|
|
|
self.servers.init_all_servers()
|
2020-09-10 15:01:57 +00:00
|
|
|
|
|
|
|
return new_id
|
|
|
|
|
2021-08-10 00:48:22 +00:00
|
|
|
def remove_server(self, server_id, files):
|
2020-09-14 18:05:17 +00:00
|
|
|
counter = 0
|
2022-05-26 12:50:20 +00:00
|
|
|
for server in self.servers.servers_list:
|
2020-09-14 18:05:17 +00:00
|
|
|
# if this is the droid... im mean server we are looking for...
|
2022-04-14 02:10:25 +00:00
|
|
|
if str(server["server_id"]) == str(server_id):
|
2022-05-30 05:36:25 +00:00
|
|
|
server_data = self.servers.get_server_data(server_id)
|
2022-03-23 02:50:12 +00:00
|
|
|
server_name = server_data["server_name"]
|
2020-09-14 18:05:17 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
logger.info(f"Deleting Server: ID {server_id} | Name: {server_name} ")
|
2022-04-12 01:34:46 +00:00
|
|
|
Console.info(f"Deleting Server: ID {server_id} | Name: {server_name} ")
|
2020-09-14 18:05:17 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
srv_obj = server["server_obj"]
|
2022-05-15 19:00:24 +00:00
|
|
|
srv_obj.server_scheduler.shutdown()
|
2023-09-27 01:08:11 +00:00
|
|
|
srv_obj.dir_scheduler.shutdown()
|
2020-09-14 18:05:17 +00:00
|
|
|
running = srv_obj.check_running()
|
|
|
|
|
|
|
|
if running:
|
2022-05-30 17:28:39 +00:00
|
|
|
self.servers.stop_server(server_id)
|
2021-08-10 00:48:22 +00:00
|
|
|
if files:
|
2021-11-29 21:22:46 +00:00
|
|
|
try:
|
2022-04-11 05:23:55 +00:00
|
|
|
FileHelpers.del_dirs(
|
|
|
|
Helpers.get_os_understandable_path(
|
2022-03-23 02:50:12 +00:00
|
|
|
self.servers.get_server_data_by_id(server_id)["path"]
|
|
|
|
)
|
|
|
|
)
|
2021-11-29 21:22:46 +00:00
|
|
|
except Exception as e:
|
2022-03-23 02:50:12 +00:00
|
|
|
logger.error(
|
2022-03-23 06:06:13 +00:00
|
|
|
f"Unable to delete server files for server with ID: "
|
|
|
|
f"{server_id} with error logged: {e}"
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-04-11 05:23:55 +00:00
|
|
|
if Helpers.check_path_exists(
|
2022-03-23 02:50:12 +00:00
|
|
|
self.servers.get_server_data_by_id(server_id)["backup_path"]
|
|
|
|
):
|
2022-04-11 05:23:55 +00:00
|
|
|
FileHelpers.del_dirs(
|
|
|
|
Helpers.get_os_understandable_path(
|
2022-03-23 02:50:12 +00:00
|
|
|
self.servers.get_server_data_by_id(server_id)[
|
|
|
|
"backup_path"
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Cleanup scheduled tasks
|
2021-11-29 21:22:46 +00:00
|
|
|
try:
|
2022-04-14 02:10:25 +00:00
|
|
|
HelpersManagement.delete_scheduled_task_by_server(server_id)
|
2021-11-29 21:22:46 +00:00
|
|
|
except DoesNotExist:
|
|
|
|
logger.info("No scheduled jobs exist. Continuing.")
|
2020-09-14 18:05:17 +00:00
|
|
|
# remove the server from the DB
|
2021-09-08 22:01:10 +00:00
|
|
|
self.servers.remove_server(server_id)
|
2020-09-14 18:05:17 +00:00
|
|
|
|
|
|
|
# remove the server from servers list
|
2022-05-26 12:50:20 +00:00
|
|
|
self.servers.servers_list.pop(counter)
|
2020-09-14 18:05:17 +00:00
|
|
|
|
|
|
|
counter += 1
|
2022-03-23 02:50:12 +00:00
|
|
|
|
2022-08-06 00:04:34 +00:00
|
|
|
def remove_unloaded_server(self, server_id):
|
|
|
|
try:
|
|
|
|
HelpersManagement.delete_scheduled_task_by_server(server_id)
|
|
|
|
except DoesNotExist:
|
|
|
|
logger.info("No scheduled jobs exist. Continuing.")
|
|
|
|
# remove the server from the DB
|
|
|
|
self.servers.remove_server(server_id)
|
|
|
|
|
2022-03-13 12:29:26 +00:00
|
|
|
@staticmethod
|
|
|
|
def clear_support_status():
|
2022-04-14 02:10:25 +00:00
|
|
|
HelperUsers.clear_support_status()
|
2023-01-27 00:21:39 +00:00
|
|
|
|
|
|
|
def set_master_server_dir(self, server_dir):
|
2023-01-30 20:23:10 +00:00
|
|
|
# This method should only be used on a first run basis if the server dir is ""
|
2023-01-27 00:21:39 +00:00
|
|
|
self.helper.servers_dir = server_dir
|
|
|
|
HelpersManagement.set_master_server_dir(server_dir)
|
2023-01-30 20:23:10 +00:00
|
|
|
|
|
|
|
def update_master_server_dir(self, server_dir, user_id):
|
2023-02-20 20:36:05 +00:00
|
|
|
self.helper.dir_migration = True
|
2023-01-30 23:31:46 +00:00
|
|
|
move_thread = threading.Thread(
|
|
|
|
name="dir_move",
|
|
|
|
target=self.t_update_master_server_dir,
|
|
|
|
daemon=True,
|
|
|
|
args=(
|
|
|
|
server_dir,
|
|
|
|
user_id,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
move_thread.start()
|
|
|
|
|
2023-02-23 16:57:00 +00:00
|
|
|
def t_update_master_server_dir(self, new_server_path, user_id):
|
|
|
|
new_server_path = self.helper.wtol_path(new_server_path)
|
2023-03-01 19:22:33 +00:00
|
|
|
new_server_path = os.path.join(new_server_path, "servers")
|
2023-08-09 21:47:53 +00:00
|
|
|
WebSocketManager().broadcast_page(
|
2023-01-30 23:31:46 +00:00
|
|
|
"/panel/panel_config", "move_status", "Checking dir"
|
|
|
|
)
|
2023-02-13 18:05:54 +00:00
|
|
|
current_master = self.helper.wtol_path(
|
|
|
|
HelpersManagement.get_master_server_dir()
|
|
|
|
)
|
2023-02-23 16:57:00 +00:00
|
|
|
if current_master == new_server_path:
|
2023-01-30 20:23:10 +00:00
|
|
|
logger.info(
|
|
|
|
"Admin tried to change server dir to current server dir. Canceling..."
|
|
|
|
)
|
2023-08-09 21:47:53 +00:00
|
|
|
WebSocketManager().broadcast_page(
|
2023-02-13 18:05:54 +00:00
|
|
|
"/panel/panel_config",
|
|
|
|
"move_status",
|
|
|
|
"done",
|
|
|
|
)
|
2023-01-30 20:23:10 +00:00
|
|
|
return
|
2023-02-23 16:57:00 +00:00
|
|
|
if self.helper.is_subdir(new_server_path, current_master):
|
2023-01-30 20:23:10 +00:00
|
|
|
logger.info(
|
|
|
|
"Admin tried to change server dir to be inside a sub directory of the"
|
|
|
|
" current server dir. This will result in a copy loop."
|
|
|
|
)
|
2023-08-09 21:47:53 +00:00
|
|
|
WebSocketManager().broadcast_page(
|
2023-02-13 18:05:54 +00:00
|
|
|
"/panel/panel_config",
|
|
|
|
"move_status",
|
|
|
|
"done",
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
2023-08-09 21:47:53 +00:00
|
|
|
WebSocketManager().broadcast_page(
|
2023-01-30 23:31:46 +00:00
|
|
|
"/panel/panel_config", "move_status", "Checking permissions"
|
|
|
|
)
|
2023-03-01 19:22:33 +00:00
|
|
|
if not self.helper.ensure_dir_exists(new_server_path):
|
2023-08-09 21:47:53 +00:00
|
|
|
WebSocketManager().broadcast_user(
|
2023-01-30 20:23:10 +00:00
|
|
|
user_id,
|
|
|
|
"send_start_error",
|
|
|
|
{
|
|
|
|
"error": "Crafty failed to move server dir. "
|
|
|
|
"It seems Crafty lacks permission to write to "
|
|
|
|
"the new directory."
|
|
|
|
},
|
|
|
|
)
|
2023-09-04 16:34:39 +00:00
|
|
|
self.helper.dir_migration = False
|
|
|
|
|
2023-01-30 20:23:10 +00:00
|
|
|
return
|
2023-02-13 18:05:54 +00:00
|
|
|
# set the cached serve dir
|
2023-02-23 16:57:00 +00:00
|
|
|
self.helper.servers_dir = new_server_path
|
2023-02-13 18:05:54 +00:00
|
|
|
# set DB server dir
|
2023-02-23 16:57:00 +00:00
|
|
|
HelpersManagement.set_master_server_dir(new_server_path)
|
2023-01-30 20:23:10 +00:00
|
|
|
servers = self.servers.get_all_defined_servers()
|
2023-02-13 18:05:54 +00:00
|
|
|
# move the servers
|
2023-01-30 20:23:10 +00:00
|
|
|
for server in servers:
|
|
|
|
server_path = server.get("path")
|
2023-03-01 19:22:33 +00:00
|
|
|
new_local_server_path = os.path.join(
|
2023-11-01 17:44:56 +00:00
|
|
|
new_server_path, server.get("server_id")
|
2023-01-30 20:23:10 +00:00
|
|
|
)
|
|
|
|
if os.path.isdir(server_path):
|
2023-08-09 21:47:53 +00:00
|
|
|
WebSocketManager().broadcast_page(
|
2023-01-30 23:31:46 +00:00
|
|
|
"/panel/panel_config",
|
|
|
|
"move_status",
|
|
|
|
f"Moving {server.get('server_name')}",
|
|
|
|
)
|
2023-02-13 18:05:54 +00:00
|
|
|
try:
|
|
|
|
self.file_helper.move_dir(
|
|
|
|
server_path,
|
2023-03-01 19:22:33 +00:00
|
|
|
new_local_server_path,
|
2023-02-13 18:05:54 +00:00
|
|
|
)
|
|
|
|
except FileExistsError as e:
|
|
|
|
logger.error(f"Failed to move server with error: {e}")
|
|
|
|
|
2023-01-30 20:23:10 +00:00
|
|
|
server_obj = self.servers.get_server_obj(server.get("server_id"))
|
2023-02-13 18:05:54 +00:00
|
|
|
|
|
|
|
# reset executable path
|
2023-02-13 16:48:06 +00:00
|
|
|
if current_master in server["executable"]:
|
|
|
|
server_obj.executable = str(server["executable"]).replace(
|
2023-03-01 19:22:33 +00:00
|
|
|
current_master, new_local_server_path
|
2023-02-13 16:48:06 +00:00
|
|
|
)
|
2023-02-13 18:05:54 +00:00
|
|
|
# reset run command path
|
2023-02-13 16:48:06 +00:00
|
|
|
if current_master in server["execution_command"]:
|
2023-02-13 18:05:54 +00:00
|
|
|
server_obj.execution_command = str(server["execution_command"]).replace(
|
2023-03-01 19:22:33 +00:00
|
|
|
current_master, new_local_server_path
|
2023-02-13 18:05:54 +00:00
|
|
|
)
|
|
|
|
# reset log path
|
|
|
|
if current_master in server["log_path"]:
|
|
|
|
server_obj.log_path = str(server["log_path"]).replace(
|
2023-03-01 19:22:33 +00:00
|
|
|
current_master, new_local_server_path
|
2023-02-13 16:48:06 +00:00
|
|
|
)
|
2023-03-01 19:22:33 +00:00
|
|
|
server_obj.path = new_local_server_path
|
2023-01-30 20:23:10 +00:00
|
|
|
failed = False
|
|
|
|
for s in self.servers.failed_servers:
|
|
|
|
if int(s["server_id"]) == int(server.get("server_id")):
|
|
|
|
failed = True
|
|
|
|
if not failed:
|
|
|
|
self.servers.update_server(server_obj)
|
|
|
|
else:
|
|
|
|
self.servers.update_unloaded_server(server_obj)
|
|
|
|
self.servers.init_all_servers()
|
2023-02-20 20:36:05 +00:00
|
|
|
self.helper.dir_migration = False
|
2023-08-09 21:47:53 +00:00
|
|
|
WebSocketManager().broadcast_page(
|
2023-01-30 23:31:46 +00:00
|
|
|
"/panel/panel_config",
|
|
|
|
"move_status",
|
|
|
|
"done",
|
|
|
|
)
|