2020-08-12 00:36:09 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import json
|
2022-05-15 22:33:31 +00:00
|
|
|
from threading import Thread
|
2020-08-12 00:36:09 +00:00
|
|
|
import time
|
|
|
|
import argparse
|
|
|
|
import logging.config
|
2021-06-02 18:30:12 +00:00
|
|
|
import signal
|
2022-04-11 05:23:55 +00:00
|
|
|
import peewee
|
2022-07-20 23:39:29 +00:00
|
|
|
from packaging import version as pkg_version
|
2022-06-05 20:17:23 +00:00
|
|
|
|
2022-07-20 22:56:09 +00:00
|
|
|
from app.classes.shared.file_helpers import FileHelpers
|
2022-06-05 20:08:58 +00:00
|
|
|
from app.classes.shared.import3 import Import3
|
2022-04-11 05:23:55 +00:00
|
|
|
from app.classes.shared.console import Console
|
|
|
|
from app.classes.shared.helpers import Helpers
|
2022-06-05 20:17:23 +00:00
|
|
|
from app.classes.models.users import HelperUsers
|
2023-01-29 21:54:02 +00:00
|
|
|
from app.classes.models.management import HelpersManagement
|
2022-08-17 21:22:03 +00:00
|
|
|
from app.classes.shared.import_helper import ImportHelpers
|
2023-08-09 21:47:53 +00:00
|
|
|
from app.classes.shared.websocket_manager import WebSocketManager
|
2024-04-17 22:03:10 +00:00
|
|
|
from app.classes.logging.log_formatter import JsonFormatter
|
2022-03-23 02:50:12 +00:00
|
|
|
|
2022-04-11 05:23:55 +00:00
|
|
|
console = Console()
|
2022-04-12 01:34:46 +00:00
|
|
|
helper = Helpers()
|
2023-11-30 02:04:02 +00:00
|
|
|
# Get the path our application is running on.
|
|
|
|
if getattr(sys, "frozen", False):
|
|
|
|
APPLICATION_PATH = os.path.dirname(sys.executable)
|
|
|
|
RUNNING_MODE = "Frozen/executable"
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
app_full_path = os.path.realpath(__file__)
|
|
|
|
APPLICATION_PATH = os.path.dirname(app_full_path)
|
|
|
|
RUNNING_MODE = "Non-interactive (e.g. 'python main.py')"
|
|
|
|
except NameError:
|
|
|
|
APPLICATION_PATH = os.getcwd()
|
|
|
|
RUNNING_MODE = "Interactive"
|
2022-04-14 02:10:25 +00:00
|
|
|
if helper.check_root():
|
2022-04-12 01:34:46 +00:00
|
|
|
Console.critical(
|
2022-03-23 06:16:22 +00:00
|
|
|
"Root detected. Root/Admin access denied. "
|
|
|
|
"Run Crafty again with non-elevated permissions."
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-03-02 13:12:03 +00:00
|
|
|
time.sleep(5)
|
2022-04-12 01:34:46 +00:00
|
|
|
Console.critical("Crafty shutting down. Root/Admin access denied.")
|
2022-03-02 13:12:03 +00:00
|
|
|
sys.exit(0)
|
2023-04-20 20:29:13 +00:00
|
|
|
if not (sys.version_info.major == 3 and sys.version_info.minor >= 9):
|
2023-04-20 20:22:23 +00:00
|
|
|
Console.critical(
|
|
|
|
"Python version mismatch. Python "
|
2023-04-20 20:29:13 +00:00
|
|
|
f"{sys.version_info.major}.{sys.version_info.minor} detected."
|
2023-04-20 20:22:23 +00:00
|
|
|
)
|
2023-04-20 20:29:13 +00:00
|
|
|
Console.critical("Crafty requires Python 3.9 or above. Please upgrade python.")
|
2023-04-20 20:22:23 +00:00
|
|
|
time.sleep(5)
|
|
|
|
Console.critical("Crafty shutting down.")
|
|
|
|
time.sleep(3)
|
2023-04-20 20:29:13 +00:00
|
|
|
Console.info("Crafty stopped. Exiting...")
|
2023-04-20 20:22:23 +00:00
|
|
|
sys.exit(0)
|
2023-11-28 02:21:05 +00:00
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
# pylint: disable=wrong-import-position
|
2022-04-11 05:23:55 +00:00
|
|
|
try:
|
|
|
|
from app.classes.models.base_model import database_proxy
|
2022-04-14 02:10:25 +00:00
|
|
|
from app.classes.shared.main_models import DatabaseBuilder
|
2022-04-11 05:23:55 +00:00
|
|
|
from app.classes.shared.tasks import TasksManager
|
|
|
|
from app.classes.shared.main_controller import Controller
|
|
|
|
from app.classes.shared.migration import MigrationManager
|
|
|
|
from app.classes.shared.command import MainPrompt
|
|
|
|
except ModuleNotFoundError as err:
|
|
|
|
helper.auto_installer_fix(err)
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2020-08-19 01:04:43 +00:00
|
|
|
|
2023-11-29 23:15:11 +00:00
|
|
|
def internet_check():
|
|
|
|
"""
|
|
|
|
This checks to see if the Crafty host is connected to the
|
|
|
|
internet. This will show a warning in the console if no interwebs.
|
|
|
|
"""
|
|
|
|
print()
|
|
|
|
logger.info("Checking Internet. This may take a minute.")
|
|
|
|
Console.info("Checking Internet. This may take a minute.")
|
|
|
|
|
|
|
|
if not helper.check_internet():
|
|
|
|
logger.warning(
|
|
|
|
"We have detected the machine running Crafty has no "
|
|
|
|
"connection to the internet. Client connections to "
|
|
|
|
"the server may be limited."
|
|
|
|
)
|
|
|
|
Console.warning(
|
|
|
|
"We have detected the machine running Crafty has no "
|
|
|
|
"connection to the internet. Client connections to "
|
|
|
|
"the server may be limited."
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def controller_setup():
|
|
|
|
"""
|
|
|
|
Method sets up the software controllers.
|
|
|
|
This also sets the application path as well as the
|
|
|
|
master server dir (if not set).
|
|
|
|
|
|
|
|
This also clears the support logs status.
|
|
|
|
"""
|
|
|
|
if not controller.check_system_user():
|
|
|
|
controller.add_system_user()
|
|
|
|
|
|
|
|
master_server_dir = controller.management.get_master_server_dir()
|
|
|
|
if master_server_dir == "":
|
|
|
|
logger.debug("Could not find master server path. Setting default")
|
|
|
|
controller.set_master_server_dir(
|
|
|
|
os.path.join(controller.project_root, "servers")
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
helper.servers_dir = master_server_dir
|
|
|
|
|
2023-12-07 15:09:11 +00:00
|
|
|
logger.info(f"Execution Mode: {RUNNING_MODE}")
|
|
|
|
logger.info(f"Application path: '{APPLICATION_PATH}'")
|
|
|
|
Console.info(f"Execution Mode: {RUNNING_MODE}")
|
|
|
|
Console.info(f"Application path: '{APPLICATION_PATH}'")
|
2023-11-29 23:15:11 +00:00
|
|
|
|
|
|
|
controller.clear_support_status()
|
|
|
|
|
|
|
|
|
|
|
|
def tasks_starter():
|
|
|
|
"""
|
|
|
|
Method starts stats recording, app scheduler, and
|
2024-05-04 19:15:43 +00:00
|
|
|
big bucket/steamCMD cache refreshers
|
2023-11-29 23:15:11 +00:00
|
|
|
"""
|
|
|
|
# start stats logging
|
|
|
|
tasks_manager.start_stats_recording()
|
|
|
|
|
|
|
|
# once the controller is up and stats are logging, we can kick off
|
|
|
|
# the scheduler officially
|
|
|
|
tasks_manager.start_scheduler()
|
|
|
|
|
|
|
|
# refresh our cache and schedule for every 12 hoursour cache refresh
|
2024-05-04 19:15:43 +00:00
|
|
|
# for big bucket.com
|
|
|
|
tasks_manager.big_bucket_cache_refresher()
|
2023-11-29 23:15:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def signal_handler(signum, _frame):
|
|
|
|
"""
|
|
|
|
Method handles sigterm and shuts the app down.
|
|
|
|
"""
|
|
|
|
if not args.daemon:
|
|
|
|
print() # for newline after prompt
|
|
|
|
signame = signal.Signals(signum).name
|
|
|
|
logger.info(f"Recieved signal {signame} [{signum}], stopping Crafty...")
|
|
|
|
Console.info(f"Recieved signal {signame} [{signum}], stopping Crafty...")
|
|
|
|
tasks_manager._main_graceful_exit()
|
|
|
|
crafty_prompt.universal_exit()
|
|
|
|
|
|
|
|
|
|
|
|
def do_cleanup():
|
|
|
|
"""
|
|
|
|
Checks Crafty's temporary directory and clears it out on boot.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
logger.info("Removing old temp dirs")
|
|
|
|
FileHelpers.del_dirs(os.path.join(controller.project_root, "temp"))
|
|
|
|
except:
|
|
|
|
logger.info("Did not find old temp dir.")
|
|
|
|
os.mkdir(os.path.join(controller.project_root, "temp"))
|
|
|
|
|
|
|
|
|
|
|
|
def do_version_check():
|
|
|
|
"""
|
|
|
|
Checks for remote version differences.
|
|
|
|
|
|
|
|
Prints in terminal with differences if true.
|
|
|
|
|
|
|
|
Also sets helper variable to update available when pages
|
|
|
|
are served.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Check if new version available
|
|
|
|
remote_ver = helper.check_remote_version()
|
|
|
|
if remote_ver:
|
|
|
|
notice = f"""
|
|
|
|
A new version of Crafty is available!
|
|
|
|
{'/' * 37}
|
|
|
|
New version available: {remote_ver}
|
|
|
|
Current version: {pkg_version.parse(helper.get_version_string())}
|
|
|
|
{'/' * 37}
|
|
|
|
"""
|
|
|
|
Console.yellow(notice)
|
|
|
|
|
|
|
|
crafty_prompt.prompt = f"Crafty Controller v{helper.get_version_string()} > "
|
|
|
|
|
|
|
|
|
|
|
|
def setup_starter():
|
|
|
|
"""
|
|
|
|
This method starts our setup threads.
|
|
|
|
(tasks scheduler, internet checks, controller setups)
|
|
|
|
|
|
|
|
Once our threads complete we will set our startup
|
|
|
|
variable to false and send a reload to any clients waiting.
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
if not args.daemon:
|
|
|
|
time.sleep(0.01) # Wait for the prompt to start
|
|
|
|
print() # Make a newline after the prompt so logs are on an empty line
|
|
|
|
else:
|
|
|
|
time.sleep(0.01) # Wait for the daemon info message
|
|
|
|
|
|
|
|
Console.info("Setting up Crafty's internal components...")
|
|
|
|
# Start the setup threads
|
2023-11-30 17:14:09 +00:00
|
|
|
web_sock.broadcast("update", {"section": "tasks"})
|
2023-11-30 05:55:19 +00:00
|
|
|
time.sleep(2)
|
2023-11-29 23:15:11 +00:00
|
|
|
tasks_starter_thread.start()
|
2023-11-30 17:14:09 +00:00
|
|
|
web_sock.broadcast("update", {"section": "internet"})
|
2023-11-30 05:55:19 +00:00
|
|
|
time.sleep(2)
|
2023-11-29 23:15:11 +00:00
|
|
|
internet_check_thread.start()
|
2023-11-30 05:55:19 +00:00
|
|
|
web_sock.broadcast(
|
|
|
|
"update",
|
2023-11-30 17:14:09 +00:00
|
|
|
{"section": "internals"},
|
2023-11-30 05:55:19 +00:00
|
|
|
)
|
|
|
|
time.sleep(2)
|
2023-11-29 23:15:11 +00:00
|
|
|
controller_setup_thread.start()
|
|
|
|
|
2024-05-09 21:36:56 +00:00
|
|
|
web_sock.broadcast("update", {"section": "cache"})
|
|
|
|
controller.big_bucket.manual_refresh_cache()
|
2023-11-29 23:15:11 +00:00
|
|
|
# Wait for the setup threads to finish
|
2023-11-30 05:55:19 +00:00
|
|
|
web_sock.broadcast(
|
|
|
|
"update",
|
2023-11-30 17:14:09 +00:00
|
|
|
{"section": "almost"},
|
2023-11-30 05:55:19 +00:00
|
|
|
)
|
2023-11-29 23:15:11 +00:00
|
|
|
tasks_starter_thread.join()
|
|
|
|
internet_check_thread.join()
|
|
|
|
controller_setup_thread.join()
|
|
|
|
helper.crafty_starting = False
|
2023-11-30 05:55:19 +00:00
|
|
|
web_sock.broadcast("send_start_reload", "")
|
2023-11-29 23:15:11 +00:00
|
|
|
do_version_check()
|
|
|
|
Console.info("Crafty has fully started and is now ready for use!")
|
|
|
|
|
|
|
|
do_cleanup()
|
|
|
|
|
|
|
|
if not args.daemon:
|
|
|
|
# Put the prompt under the cursor
|
|
|
|
crafty_prompt.print_prompt()
|
|
|
|
|
|
|
|
|
2020-08-12 00:36:09 +00:00
|
|
|
def do_intro():
|
2023-11-29 23:15:11 +00:00
|
|
|
"""
|
|
|
|
Runs the Crafty Controller Terminal Intro with information about the software
|
|
|
|
This method checks for a "settings file" or config.json. If it does not find
|
|
|
|
one it will create one.
|
|
|
|
"""
|
2020-08-17 02:47:53 +00:00
|
|
|
logger.info("***** Crafty Controller Started *****")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-07-20 23:39:29 +00:00
|
|
|
version = helper.get_version_string()
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2021-11-02 14:08:27 +00:00
|
|
|
intro = f"""
|
|
|
|
{'/' * 75}
|
2022-07-20 23:39:29 +00:00
|
|
|
#{("Welcome to Crafty Controller - v." + version).center(73, " ")}#
|
2021-11-02 14:08:27 +00:00
|
|
|
{'/' * 75}
|
|
|
|
#{"Server Manager / Web Portal for your Minecraft server".center(73, " ")}#
|
|
|
|
#{"Homepage: www.craftycontrol.com".center(73, " ")}#
|
|
|
|
{'/' * 75}
|
|
|
|
"""
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-04-12 01:34:46 +00:00
|
|
|
Console.magenta(intro)
|
2023-01-29 19:54:25 +00:00
|
|
|
if not helper.check_file_exists(helper.settings_file):
|
|
|
|
Console.debug("No settings file detected. Creating one.")
|
|
|
|
helper.set_settings(Helpers.get_master_config())
|
2020-08-12 00:36:09 +00:00
|
|
|
|
|
|
|
|
2021-03-09 03:01:42 +00:00
|
|
|
def setup_logging(debug=True):
|
2023-11-29 23:15:11 +00:00
|
|
|
"""
|
|
|
|
This method sets up our logging for Crafty. It takes
|
|
|
|
one optional (defaulted to True) parameter which
|
|
|
|
determines whether or not the logging level is "debug" or verbose.
|
|
|
|
"""
|
2023-12-07 15:14:50 +00:00
|
|
|
logging_config_file = os.path.join(
|
|
|
|
APPLICATION_PATH, "app", "config", "logging.json"
|
|
|
|
)
|
2023-11-05 18:25:52 +00:00
|
|
|
if not helper.check_file_exists(
|
2023-12-07 15:14:50 +00:00
|
|
|
os.path.join(APPLICATION_PATH, "logs", "auth_tracker.log")
|
2023-11-05 18:25:52 +00:00
|
|
|
):
|
|
|
|
open(
|
2023-12-07 15:56:36 +00:00
|
|
|
os.path.join(APPLICATION_PATH, "logs", "auth_tracker.log"),
|
2023-11-05 18:25:52 +00:00
|
|
|
"a",
|
|
|
|
encoding="utf-8",
|
|
|
|
).close()
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2024-06-20 21:29:35 +00:00
|
|
|
if not helper.check_file_exists(
|
|
|
|
os.path.join(APPLICATION_PATH, "logs", "audit.log")
|
|
|
|
):
|
|
|
|
open(
|
|
|
|
os.path.join(APPLICATION_PATH, "logs", "audit.log"),
|
|
|
|
"a",
|
|
|
|
encoding="utf-8",
|
|
|
|
).close()
|
|
|
|
|
2020-08-12 00:36:09 +00:00
|
|
|
if os.path.exists(logging_config_file):
|
|
|
|
# open our logging config file
|
2022-03-23 02:50:12 +00:00
|
|
|
with open(logging_config_file, "rt", encoding="utf-8") as f:
|
2020-08-12 00:36:09 +00:00
|
|
|
logging_config = json.load(f)
|
|
|
|
if debug:
|
2022-03-23 02:50:12 +00:00
|
|
|
logging_config["loggers"][""]["level"] = "DEBUG"
|
2021-01-19 13:56:00 +00:00
|
|
|
|
2020-08-12 00:36:09 +00:00
|
|
|
logging.config.dictConfig(logging_config)
|
2021-01-19 13:56:00 +00:00
|
|
|
|
2024-04-17 22:03:10 +00:00
|
|
|
# Apply JSON formatting to the "audit" handler
|
|
|
|
for handler in logging.getLogger().handlers:
|
|
|
|
if handler.name == "audit_log_handler":
|
|
|
|
handler.setFormatter(JsonFormatter())
|
|
|
|
|
2020-08-12 00:36:09 +00:00
|
|
|
else:
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
2022-01-26 01:45:30 +00:00
|
|
|
logging.warning(f"Unable to read logging config from {logging_config_file}")
|
2022-04-12 01:34:46 +00:00
|
|
|
Console.critical(f"Unable to read logging config from {logging_config_file}")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
|
|
|
|
2022-01-26 01:45:30 +00:00
|
|
|
# Our Main Starter
|
2022-03-23 02:50:12 +00:00
|
|
|
if __name__ == "__main__":
|
2020-08-31 17:46:25 +00:00
|
|
|
parser = argparse.ArgumentParser("Crafty Controller - A Server Management System")
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-i", "--ignore", action="store_true", help="Ignore session.lock files"
|
|
|
|
)
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-v", "--verbose", action="store_true", help="Sets logging level to debug."
|
|
|
|
)
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-d",
|
|
|
|
"--daemon",
|
|
|
|
action="store_true",
|
|
|
|
help="Runs Crafty in daemon mode (no prompt)",
|
|
|
|
)
|
2021-03-06 20:48:02 +00:00
|
|
|
|
2020-08-12 00:36:09 +00:00
|
|
|
args = parser.parse_args()
|
2022-01-26 02:00:40 +00:00
|
|
|
helper.ensure_logging_setup()
|
2023-11-03 20:41:37 +00:00
|
|
|
helper.crafty_starting = True
|
|
|
|
# Init WebSocket Manager Here
|
2023-11-30 05:55:19 +00:00
|
|
|
web_sock = WebSocketManager()
|
2020-08-12 00:36:09 +00:00
|
|
|
setup_logging(debug=args.verbose)
|
2023-02-14 19:44:53 +00:00
|
|
|
if args.verbose:
|
|
|
|
Console.level = "debug"
|
|
|
|
|
2020-08-12 00:36:09 +00:00
|
|
|
# setting up the logger object
|
|
|
|
logger = logging.getLogger(__name__)
|
2022-04-12 01:34:46 +00:00
|
|
|
Console.cyan(f"Logging set to: {logger.level}")
|
2022-04-11 05:23:55 +00:00
|
|
|
peewee_logger = logging.getLogger("peewee")
|
|
|
|
peewee_logger.setLevel(logging.INFO)
|
2020-08-12 00:36:09 +00:00
|
|
|
|
|
|
|
# print our pretty start message
|
|
|
|
do_intro()
|
2020-08-31 17:46:25 +00:00
|
|
|
# our session file, helps prevent multiple controller agents on the same machine.
|
2020-08-12 00:36:09 +00:00
|
|
|
helper.create_session_file(ignore=args.ignore)
|
2022-04-11 05:23:55 +00:00
|
|
|
# start the database
|
|
|
|
database = peewee.SqliteDatabase(
|
2022-04-11 10:08:36 +00:00
|
|
|
helper.db_path, pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
2022-04-11 05:23:55 +00:00
|
|
|
)
|
|
|
|
database_proxy.initialize(database)
|
|
|
|
migration_manager = MigrationManager(database, helper)
|
2022-03-23 02:50:12 +00:00
|
|
|
migration_manager.up() # Automatically runs migrations
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2023-11-29 23:15:11 +00:00
|
|
|
# init classes
|
|
|
|
# now the tables are created, we can load the tasks_manager and server controller
|
2022-04-14 02:10:25 +00:00
|
|
|
user_helper = HelperUsers(database, helper)
|
2023-01-29 21:54:02 +00:00
|
|
|
management_helper = HelpersManagement(database, helper)
|
|
|
|
installer = DatabaseBuilder(database, helper, user_helper, management_helper)
|
2022-04-14 02:10:25 +00:00
|
|
|
FRESH_INSTALL = installer.is_fresh_install()
|
2020-09-22 19:00:05 +00:00
|
|
|
|
2022-04-14 02:10:25 +00:00
|
|
|
if FRESH_INSTALL:
|
2022-04-12 01:34:46 +00:00
|
|
|
Console.debug("Fresh install detected")
|
|
|
|
Console.warning(
|
2022-03-23 06:16:22 +00:00
|
|
|
f"We have detected a fresh install. Please be sure to forward "
|
|
|
|
f"Crafty's port, {helper.get_setting('https_port')}, "
|
|
|
|
f"through your router/firewall if you would like to be able "
|
|
|
|
f"to access Crafty remotely."
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2023-11-28 01:54:55 +00:00
|
|
|
PASSWORD = helper.create_pass()
|
|
|
|
installer.default_settings(PASSWORD)
|
2023-11-13 19:14:13 +00:00
|
|
|
with open(
|
2023-12-07 15:56:36 +00:00
|
|
|
os.path.join(APPLICATION_PATH, "app", "config", "default-creds.txt"),
|
2023-11-13 19:14:13 +00:00
|
|
|
"w",
|
|
|
|
encoding="utf-8",
|
2023-11-13 23:16:08 +00:00
|
|
|
) as cred_file:
|
|
|
|
cred_file.write(
|
2024-05-19 00:32:27 +00:00
|
|
|
json.dumps(
|
|
|
|
{
|
|
|
|
"username": "admin",
|
|
|
|
"password": PASSWORD,
|
|
|
|
"info": "This is NOT where you change your password."
|
|
|
|
" This file is only a means to give you a default password.",
|
|
|
|
},
|
|
|
|
indent=4,
|
|
|
|
)
|
2023-11-13 23:16:08 +00:00
|
|
|
)
|
2023-12-07 15:56:36 +00:00
|
|
|
os.chmod(
|
|
|
|
os.path.join(APPLICATION_PATH, "app", "config", "default-creds.txt"), 0o600
|
|
|
|
)
|
2021-03-22 04:02:18 +00:00
|
|
|
else:
|
2022-04-12 01:34:46 +00:00
|
|
|
Console.debug("Existing install detected")
|
2023-01-29 23:21:53 +00:00
|
|
|
Console.info("Checking for reset secret flag")
|
|
|
|
if helper.get_setting("reset_secrets_on_next_boot"):
|
|
|
|
Console.info("Found Reset")
|
|
|
|
management_helper.set_secret_api_key(str(helper.random_string_generator(64)))
|
|
|
|
management_helper.set_cookie_secret(str(helper.random_string_generator(32)))
|
|
|
|
helper.set_setting("reset_secrets_on_next_boot", False)
|
|
|
|
else:
|
|
|
|
Console.info("No flag found. Secrets are staying")
|
2023-11-29 23:15:11 +00:00
|
|
|
|
2023-12-07 15:56:36 +00:00
|
|
|
# now we've initialized our database for fresh install we
|
|
|
|
# can finishing initializing our controllers/modules
|
|
|
|
file_helper = FileHelpers(helper)
|
|
|
|
import_helper = ImportHelpers(helper, file_helper)
|
|
|
|
controller = Controller(database, helper, file_helper, import_helper)
|
|
|
|
controller.set_project_root(APPLICATION_PATH)
|
|
|
|
tasks_manager = TasksManager(helper, controller, file_helper)
|
|
|
|
import3 = Import3(helper, controller)
|
|
|
|
|
2023-11-29 23:15:11 +00:00
|
|
|
# Check to see if client config.json version is different than the
|
|
|
|
# Master config.json in helpers.py
|
2023-01-29 19:54:25 +00:00
|
|
|
Console.info("Checking for remote changes to config.json")
|
|
|
|
controller.get_config_diff()
|
2024-01-16 20:36:14 +00:00
|
|
|
# Delete anti-lockout-user
|
|
|
|
controller.users.stop_anti_lockout()
|
2023-01-29 19:54:25 +00:00
|
|
|
Console.info("Remote change complete.")
|
2023-01-29 21:54:02 +00:00
|
|
|
|
2023-11-29 23:15:11 +00:00
|
|
|
# startup the web server
|
2020-08-12 00:36:09 +00:00
|
|
|
tasks_manager.start_webserver()
|
2020-08-17 02:47:53 +00:00
|
|
|
|
2022-05-20 22:53:17 +00:00
|
|
|
signal.signal(signal.SIGTERM, signal_handler)
|
|
|
|
signal.signal(signal.SIGINT, signal_handler)
|
2020-08-12 00:36:09 +00:00
|
|
|
|
2020-08-24 23:16:33 +00:00
|
|
|
# init servers
|
|
|
|
logger.info("Initializing all servers defined")
|
2022-04-12 01:34:46 +00:00
|
|
|
Console.info("Initializing all servers defined")
|
2023-11-30 05:55:19 +00:00
|
|
|
web_sock.broadcast(
|
|
|
|
"update",
|
2023-11-30 17:14:09 +00:00
|
|
|
{"section": "serverInit"},
|
2023-11-30 05:55:19 +00:00
|
|
|
)
|
2022-05-26 12:50:20 +00:00
|
|
|
controller.servers.init_all_servers()
|
2020-08-24 23:16:33 +00:00
|
|
|
|
2023-11-29 23:15:11 +00:00
|
|
|
# start up our tasks handler in tasks.py
|
2022-05-15 22:33:31 +00:00
|
|
|
tasks_starter_thread = Thread(target=tasks_starter, name="tasks_starter")
|
2021-09-13 21:08:02 +00:00
|
|
|
|
2023-11-29 23:15:11 +00:00
|
|
|
# check to see if instance has internet
|
2022-05-15 22:33:31 +00:00
|
|
|
internet_check_thread = Thread(target=internet_check, name="internet_check")
|
2021-09-13 17:10:34 +00:00
|
|
|
|
2023-11-29 23:15:11 +00:00
|
|
|
# start the Crafty console.
|
2022-06-05 20:02:52 +00:00
|
|
|
crafty_prompt = MainPrompt(
|
|
|
|
helper, tasks_manager, migration_manager, controller, import3
|
|
|
|
)
|
2022-05-20 22:53:17 +00:00
|
|
|
|
2023-11-29 23:15:11 +00:00
|
|
|
# set up all controllers
|
2022-05-20 22:53:17 +00:00
|
|
|
controller_setup_thread = Thread(target=controller_setup, name="controller_setup")
|
|
|
|
|
2023-11-29 23:15:11 +00:00
|
|
|
setup_starter_thread = Thread(target=setup_starter, name="setup_starter")
|
2022-05-20 22:53:17 +00:00
|
|
|
|
2023-11-29 23:15:11 +00:00
|
|
|
setup_starter_thread.start()
|
2022-01-14 04:01:18 +00:00
|
|
|
|
2021-03-06 20:48:02 +00:00
|
|
|
if not args.daemon:
|
2022-05-20 22:53:17 +00:00
|
|
|
# Start the Crafty prompt
|
|
|
|
crafty_prompt.cmdloop()
|
2021-03-06 20:48:02 +00:00
|
|
|
else:
|
2022-05-20 22:53:17 +00:00
|
|
|
Console.info("Crafty started in daemon mode, no shell will be printed")
|
|
|
|
print()
|
2021-03-06 20:48:02 +00:00
|
|
|
while True:
|
2022-05-20 22:53:17 +00:00
|
|
|
if tasks_manager.get_main_thread_run_status():
|
2021-03-06 20:48:02 +00:00
|
|
|
break
|
2022-05-20 22:53:17 +00:00
|
|
|
time.sleep(1)
|
2021-12-09 23:35:00 +00:00
|
|
|
tasks_manager._main_graceful_exit()
|
2022-05-20 22:53:17 +00:00
|
|
|
crafty_prompt.universal_exit()
|