Compare commits

..

No commits in common. "003508aabd0dd9874d442ecc32a7c85cc7e21da6" and "8940d57b252116b42ce7aa2208f33ef538797349" have entirely different histories.

5 changed files with 55 additions and 85 deletions

View File

@ -1,52 +1,44 @@
"""Module to check for the database."""
import os import os
import yaml import yaml
from custom_functions.database.cache_to_db_mariadb import (
create_database as create_mariadb_database,
)
from custom_functions.database.cache_to_db_sqlite import (
create_database as create_sqlite_database,
)
from custom_functions.database.user_db import create_user_database
def check_for_sqlite_database(): def check_for_sqlite_database():
"""Check for the SQLite database.""" with open(f"{os.getcwd()}/configs/config.yaml", "r") as file:
with open(
os.path.join(os.getcwd(), "configs", "config.yaml"), "r", encoding="utf-8"
) as file:
config = yaml.safe_load(file) config = yaml.safe_load(file)
if os.path.exists(os.path.join(os.getcwd(), "databases", "key_cache.db")): if os.path.exists(f"{os.getcwd()}/databases/key_cache.db"):
return return
if config["database_type"].lower() == "sqlite": else:
create_sqlite_database() if config["database_type"].lower() != "mariadb":
from custom_functions.database.cache_to_db_sqlite import create_database
create_database()
return return
else:
return return
def check_for_user_database(): def check_for_user_database():
"""Check for the user database.""" if os.path.exists(f"{os.getcwd()}/databases/users.db"):
if os.path.exists(os.path.join(os.getcwd(), "databases", "users.db")):
return return
else:
from custom_functions.database.user_db import create_user_database
create_user_database() create_user_database()
def check_for_mariadb_database(): def check_for_mariadb_database():
"""Check for the MariaDB database.""" with open(f"{os.getcwd()}/configs/config.yaml", "r") as file:
with open(
os.path.join(os.getcwd(), "configs", "config.yaml"), "r", encoding="utf-8"
) as file:
config = yaml.safe_load(file) config = yaml.safe_load(file)
if config["database_type"].lower() == "mariadb": if config["database_type"].lower() == "mariadb":
create_mariadb_database() from custom_functions.database.cache_to_db_mariadb import create_database
create_database()
return return
else:
return return
def check_for_sql_database(): def check_for_sql_database():
"""Check for the SQL database."""
check_for_sqlite_database() check_for_sqlite_database()
check_for_mariadb_database() check_for_mariadb_database()
check_for_user_database() check_for_user_database()

View File

@ -1,51 +1,48 @@
"""Module to check for the folders."""
import os import os
def check_for_config_folder(): def check_for_config_folder():
"""Check for the config folder.""" if os.path.isdir(f"{os.getcwd()}/configs"):
if os.path.isdir(os.path.join(os.getcwd(), "configs")):
return return
os.mkdir(os.path.join(os.getcwd(), "configs")) else:
os.mkdir(f"{os.getcwd()}/configs")
return return
def check_for_database_folder(): def check_for_database_folder():
"""Check for the database folder.""" if os.path.isdir(f"{os.getcwd()}/databases"):
if os.path.isdir(os.path.join(os.getcwd(), "databases")):
return return
os.mkdir(os.path.join(os.getcwd(), "databases")) else:
os.mkdir(os.path.join(os.getcwd(), "databases", "sql")) os.mkdir(f"{os.getcwd()}/databases")
os.mkdir(f"{os.getcwd()}/databases/sql")
return return
def check_for_cdm_folder(): def check_for_cdm_folder():
"""Check for the CDM folder.""" if os.path.isdir(f"{os.getcwd()}/configs/CDMs"):
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs")):
return return
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs")) else:
os.mkdir(f"{os.getcwd()}/configs/CDMs")
return return
def check_for_wv_cdm_folder(): def check_for_wv_cdm_folder():
"""Check for the Widevine CDM folder.""" if os.path.isdir(f"{os.getcwd()}/configs/CDMs/WV"):
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs", "WV")):
return return
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs", "WV")) else:
os.mkdir(f"{os.getcwd()}/configs/CDMs/WV")
return return
def check_for_cdm_pr_folder(): def check_for_cdm_pr_folder():
"""Check for the PlayReady CDM folder.""" if os.path.isdir(f"{os.getcwd()}/configs/CDMs/PR"):
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs", "PR")):
return return
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs", "PR")) else:
os.mkdir(f"{os.getcwd()}/configs/CDMs/PR")
return return
def folder_checks(): def folder_checks():
"""Check for the folders."""
check_for_config_folder() check_for_config_folder()
check_for_database_folder() check_for_database_folder()
check_for_cdm_folder() check_for_cdm_folder()

View File

@ -1,5 +1,3 @@
"""Module to run the prechecks."""
from custom_functions.prechecks.folder_checks import folder_checks from custom_functions.prechecks.folder_checks import folder_checks
from custom_functions.prechecks.config_file_checks import check_for_config_file from custom_functions.prechecks.config_file_checks import check_for_config_file
from custom_functions.prechecks.database_checks import check_for_sql_database from custom_functions.prechecks.database_checks import check_for_sql_database
@ -7,8 +5,8 @@ from custom_functions.prechecks.cdm_checks import check_for_cdms
def run_precheck(): def run_precheck():
"""Run the prechecks."""
folder_checks() folder_checks()
check_for_config_file() check_for_config_file()
check_for_cdms() check_for_cdms()
check_for_sql_database() check_for_sql_database()
return

View File

@ -1,11 +1,8 @@
"""Module to check if the user is allowed to use the device."""
import os import os
import glob import glob
def user_allowed_to_use_device(device, username): def user_allowed_to_use_device(device, username):
"""Check if the user is allowed to use the device."""
base_path = os.path.join(os.getcwd(), "configs", "CDMs", username) base_path = os.path.join(os.getcwd(), "configs", "CDMs", username)
# Get filenames with extensions # Get filenames with extensions

View File

@ -1,13 +1,10 @@
"""Module to handle the React routes."""
import os
import sys import sys
import os
from flask import Blueprint, send_from_directory, render_template from flask import Blueprint, send_from_directory, request, render_template
from configs import index_tags from configs import index_tags
if getattr(sys, "frozen", False): # Running as a bundled app if getattr(sys, "frozen", False): # Running as a bundled app
base_path = getattr(sys, "_MEIPASS", os.path.abspath(".")) base_path = sys._MEIPASS
else: # Running in a normal Python environment else: # Running in a normal Python environment
base_path = os.path.abspath(".") base_path = os.path.abspath(".")
@ -26,23 +23,12 @@ react_bp = Blueprint(
@react_bp.route("/<path:path>", methods=["GET"]) @react_bp.route("/<path:path>", methods=["GET"])
@react_bp.route("/<path>", methods=["GET"]) @react_bp.route("/<path>", methods=["GET"])
def index(path=""): def index(path=""):
"""Handle the index route.""" if request.method == "GET":
# Ensure static_folder is not None file_path = os.path.join(react_bp.static_folder, path)
if react_bp.static_folder is None: if path != "" and os.path.exists(file_path):
raise ValueError("Static folder is not configured for the blueprint") return send_from_directory(react_bp.static_folder, path)
elif path.lower() in ["", "cache", "api", "testplayer", "account"]:
# Normalize the path to prevent directory traversal data = index_tags.tags.get(path.lower(), index_tags.tags["index"])
safe_path = os.path.normpath(path)
file_path = os.path.join(react_bp.static_folder, safe_path)
if path and os.path.exists(file_path):
return send_from_directory(react_bp.static_folder, safe_path)
# Only allow certain paths to render index.html with tags
allowed_paths = ["", "cache", "api", "testplayer", "account"]
if safe_path.lower() in allowed_paths:
data = index_tags.tags.get(safe_path.lower(), index_tags.tags.get("index", {}))
return render_template("index.html", data=data) return render_template("index.html", data=data)
else:
# Fallback: serve index.html for all other routes (SPA)
return send_from_directory(react_bp.static_folder, "index.html") return send_from_directory(react_bp.static_folder, "index.html")