forked from tpd94/CDRM-Project
Compare commits
5 Commits
8940d57b25
...
003508aabd
Author | SHA1 | Date | |
---|---|---|---|
|
003508aabd | ||
|
d6cf10ccaf | ||
|
c82d23aabc | ||
|
2e520da006 | ||
|
a2a12b4c49 |
@ -1,44 +1,52 @@
|
||||
"""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():
|
||||
with open(f"{os.getcwd()}/configs/config.yaml", "r") as file:
|
||||
"""Check for the SQLite database."""
|
||||
with open(
|
||||
os.path.join(os.getcwd(), "configs", "config.yaml"), "r", encoding="utf-8"
|
||||
) as file:
|
||||
config = yaml.safe_load(file)
|
||||
if os.path.exists(f"{os.getcwd()}/databases/key_cache.db"):
|
||||
if os.path.exists(os.path.join(os.getcwd(), "databases", "key_cache.db")):
|
||||
return
|
||||
else:
|
||||
if config["database_type"].lower() != "mariadb":
|
||||
from custom_functions.database.cache_to_db_sqlite import create_database
|
||||
|
||||
create_database()
|
||||
return
|
||||
else:
|
||||
return
|
||||
if config["database_type"].lower() == "sqlite":
|
||||
create_sqlite_database()
|
||||
return
|
||||
return
|
||||
|
||||
|
||||
def check_for_user_database():
|
||||
if os.path.exists(f"{os.getcwd()}/databases/users.db"):
|
||||
"""Check for the user database."""
|
||||
if os.path.exists(os.path.join(os.getcwd(), "databases", "users.db")):
|
||||
return
|
||||
else:
|
||||
from custom_functions.database.user_db import create_user_database
|
||||
|
||||
create_user_database()
|
||||
create_user_database()
|
||||
|
||||
|
||||
def check_for_mariadb_database():
|
||||
with open(f"{os.getcwd()}/configs/config.yaml", "r") as file:
|
||||
"""Check for the MariaDB database."""
|
||||
with open(
|
||||
os.path.join(os.getcwd(), "configs", "config.yaml"), "r", encoding="utf-8"
|
||||
) as file:
|
||||
config = yaml.safe_load(file)
|
||||
if config["database_type"].lower() == "mariadb":
|
||||
from custom_functions.database.cache_to_db_mariadb import create_database
|
||||
|
||||
create_database()
|
||||
return
|
||||
else:
|
||||
create_mariadb_database()
|
||||
return
|
||||
return
|
||||
|
||||
|
||||
def check_for_sql_database():
|
||||
"""Check for the SQL database."""
|
||||
check_for_sqlite_database()
|
||||
check_for_mariadb_database()
|
||||
check_for_user_database()
|
||||
|
@ -1,48 +1,51 @@
|
||||
"""Module to check for the folders."""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def check_for_config_folder():
|
||||
if os.path.isdir(f"{os.getcwd()}/configs"):
|
||||
return
|
||||
else:
|
||||
os.mkdir(f"{os.getcwd()}/configs")
|
||||
"""Check for the config folder."""
|
||||
if os.path.isdir(os.path.join(os.getcwd(), "configs")):
|
||||
return
|
||||
os.mkdir(os.path.join(os.getcwd(), "configs"))
|
||||
return
|
||||
|
||||
|
||||
def check_for_database_folder():
|
||||
if os.path.isdir(f"{os.getcwd()}/databases"):
|
||||
return
|
||||
else:
|
||||
os.mkdir(f"{os.getcwd()}/databases")
|
||||
os.mkdir(f"{os.getcwd()}/databases/sql")
|
||||
"""Check for the database folder."""
|
||||
if os.path.isdir(os.path.join(os.getcwd(), "databases")):
|
||||
return
|
||||
os.mkdir(os.path.join(os.getcwd(), "databases"))
|
||||
os.mkdir(os.path.join(os.getcwd(), "databases", "sql"))
|
||||
return
|
||||
|
||||
|
||||
def check_for_cdm_folder():
|
||||
if os.path.isdir(f"{os.getcwd()}/configs/CDMs"):
|
||||
return
|
||||
else:
|
||||
os.mkdir(f"{os.getcwd()}/configs/CDMs")
|
||||
"""Check for the CDM folder."""
|
||||
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs")):
|
||||
return
|
||||
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs"))
|
||||
return
|
||||
|
||||
|
||||
def check_for_wv_cdm_folder():
|
||||
if os.path.isdir(f"{os.getcwd()}/configs/CDMs/WV"):
|
||||
return
|
||||
else:
|
||||
os.mkdir(f"{os.getcwd()}/configs/CDMs/WV")
|
||||
"""Check for the Widevine CDM folder."""
|
||||
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs", "WV")):
|
||||
return
|
||||
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs", "WV"))
|
||||
return
|
||||
|
||||
|
||||
def check_for_cdm_pr_folder():
|
||||
if os.path.isdir(f"{os.getcwd()}/configs/CDMs/PR"):
|
||||
return
|
||||
else:
|
||||
os.mkdir(f"{os.getcwd()}/configs/CDMs/PR")
|
||||
"""Check for the PlayReady CDM folder."""
|
||||
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs", "PR")):
|
||||
return
|
||||
os.mkdir(os.path.join(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()
|
||||
|
@ -1,3 +1,5 @@
|
||||
"""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
|
||||
@ -5,8 +7,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
|
||||
|
@ -1,8 +1,11 @@
|
||||
"""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
|
||||
|
@ -1,10 +1,13 @@
|
||||
import sys
|
||||
"""Module to handle the React routes."""
|
||||
|
||||
import os
|
||||
from flask import Blueprint, send_from_directory, request, render_template
|
||||
import sys
|
||||
|
||||
from flask import Blueprint, send_from_directory, render_template
|
||||
from configs import index_tags
|
||||
|
||||
if getattr(sys, "frozen", False): # Running as a bundled app
|
||||
base_path = sys._MEIPASS
|
||||
base_path = getattr(sys, "_MEIPASS", os.path.abspath("."))
|
||||
else: # Running in a normal Python environment
|
||||
base_path = os.path.abspath(".")
|
||||
|
||||
@ -23,12 +26,23 @@ react_bp = Blueprint(
|
||||
@react_bp.route("/<path:path>", methods=["GET"])
|
||||
@react_bp.route("/<path>", methods=["GET"])
|
||||
def index(path=""):
|
||||
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)
|
||||
else:
|
||||
return send_from_directory(react_bp.static_folder, "index.html")
|
||||
"""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", {}))
|
||||
return render_template("index.html", data=data)
|
||||
|
||||
# Fallback: serve index.html for all other routes (SPA)
|
||||
return send_from_directory(react_bp.static_folder, "index.html")
|
||||
|
Loading…
x
Reference in New Issue
Block a user