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

View File

@ -1,51 +1,48 @@
"""Module to check for the folders."""
import os
def check_for_config_folder():
"""Check for the config folder."""
if os.path.isdir(os.path.join(os.getcwd(), "configs")):
if os.path.isdir(f"{os.getcwd()}/configs"):
return
os.mkdir(os.path.join(os.getcwd(), "configs"))
else:
os.mkdir(f"{os.getcwd()}/configs")
return
def check_for_database_folder():
"""Check for the database folder."""
if os.path.isdir(os.path.join(os.getcwd(), "databases")):
if os.path.isdir(f"{os.getcwd()}/databases"):
return
os.mkdir(os.path.join(os.getcwd(), "databases"))
os.mkdir(os.path.join(os.getcwd(), "databases", "sql"))
else:
os.mkdir(f"{os.getcwd()}/databases")
os.mkdir(f"{os.getcwd()}/databases/sql")
return
def check_for_cdm_folder():
"""Check for the CDM folder."""
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs")):
if os.path.isdir(f"{os.getcwd()}/configs/CDMs"):
return
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs"))
else:
os.mkdir(f"{os.getcwd()}/configs/CDMs")
return
def check_for_wv_cdm_folder():
"""Check for the Widevine CDM folder."""
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs", "WV")):
if os.path.isdir(f"{os.getcwd()}/configs/CDMs/WV"):
return
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs", "WV"))
else:
os.mkdir(f"{os.getcwd()}/configs/CDMs/WV")
return
def check_for_cdm_pr_folder():
"""Check for the PlayReady CDM folder."""
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs", "PR")):
if os.path.isdir(f"{os.getcwd()}/configs/CDMs/PR"):
return
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs", "PR"))
else:
os.mkdir(f"{os.getcwd()}/configs/CDMs/PR")
return
def folder_checks():
"""Check for the folders."""
check_for_config_folder()
check_for_database_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.config_file_checks import check_for_config_file
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():
"""Run the prechecks."""
folder_checks()
check_for_config_file()
check_for_cdms()
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 glob
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)
# Get filenames with extensions

View File

@ -1,13 +1,10 @@
"""Module to handle the React routes."""
import os
import sys
from flask import Blueprint, send_from_directory, render_template
import os
from flask import Blueprint, send_from_directory, request, render_template
from configs import index_tags
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
base_path = os.path.abspath(".")
@ -26,23 +23,12 @@ react_bp = Blueprint(
@react_bp.route("/<path:path>", methods=["GET"])
@react_bp.route("/<path>", methods=["GET"])
def index(path=""):
"""Handle the index route."""
# Ensure static_folder is not None
if react_bp.static_folder is None:
raise ValueError("Static folder is not configured for the blueprint")
# Normalize the path to prevent directory traversal
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", {}))
if request.method == "GET":
file_path = os.path.join(react_bp.static_folder, path)
if path != "" and os.path.exists(file_path):
return send_from_directory(react_bp.static_folder, path)
elif path.lower() in ["", "cache", "api", "testplayer", "account"]:
data = index_tags.tags.get(path.lower(), index_tags.tags["index"])
return render_template("index.html", data=data)
# Fallback: serve index.html for all other routes (SPA)
else:
return send_from_directory(react_bp.static_folder, "index.html")