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 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():
|
||||||
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)
|
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
|
return
|
||||||
else:
|
if config["database_type"].lower() == "sqlite":
|
||||||
if config["database_type"].lower() != "mariadb":
|
create_sqlite_database()
|
||||||
from custom_functions.database.cache_to_db_sqlite import create_database
|
return
|
||||||
|
return
|
||||||
create_database()
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def check_for_user_database():
|
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
|
return
|
||||||
else:
|
create_user_database()
|
||||||
from custom_functions.database.user_db import create_user_database
|
|
||||||
|
|
||||||
create_user_database()
|
|
||||||
|
|
||||||
|
|
||||||
def check_for_mariadb_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)
|
config = yaml.safe_load(file)
|
||||||
if config["database_type"].lower() == "mariadb":
|
if config["database_type"].lower() == "mariadb":
|
||||||
from custom_functions.database.cache_to_db_mariadb import create_database
|
create_mariadb_database()
|
||||||
|
|
||||||
create_database()
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
return
|
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()
|
||||||
|
@ -1,48 +1,51 @@
|
|||||||
|
"""Module to check for the folders."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def check_for_config_folder():
|
def check_for_config_folder():
|
||||||
if os.path.isdir(f"{os.getcwd()}/configs"):
|
"""Check for the config folder."""
|
||||||
return
|
if os.path.isdir(os.path.join(os.getcwd(), "configs")):
|
||||||
else:
|
|
||||||
os.mkdir(f"{os.getcwd()}/configs")
|
|
||||||
return
|
return
|
||||||
|
os.mkdir(os.path.join(os.getcwd(), "configs"))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def check_for_database_folder():
|
def check_for_database_folder():
|
||||||
if os.path.isdir(f"{os.getcwd()}/databases"):
|
"""Check for the database folder."""
|
||||||
return
|
if os.path.isdir(os.path.join(os.getcwd(), "databases")):
|
||||||
else:
|
|
||||||
os.mkdir(f"{os.getcwd()}/databases")
|
|
||||||
os.mkdir(f"{os.getcwd()}/databases/sql")
|
|
||||||
return
|
return
|
||||||
|
os.mkdir(os.path.join(os.getcwd(), "databases"))
|
||||||
|
os.mkdir(os.path.join(os.getcwd(), "databases", "sql"))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def check_for_cdm_folder():
|
def check_for_cdm_folder():
|
||||||
if os.path.isdir(f"{os.getcwd()}/configs/CDMs"):
|
"""Check for the CDM folder."""
|
||||||
return
|
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs")):
|
||||||
else:
|
|
||||||
os.mkdir(f"{os.getcwd()}/configs/CDMs")
|
|
||||||
return
|
return
|
||||||
|
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs"))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def check_for_wv_cdm_folder():
|
def check_for_wv_cdm_folder():
|
||||||
if os.path.isdir(f"{os.getcwd()}/configs/CDMs/WV"):
|
"""Check for the Widevine CDM folder."""
|
||||||
return
|
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs", "WV")):
|
||||||
else:
|
|
||||||
os.mkdir(f"{os.getcwd()}/configs/CDMs/WV")
|
|
||||||
return
|
return
|
||||||
|
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs", "WV"))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def check_for_cdm_pr_folder():
|
def check_for_cdm_pr_folder():
|
||||||
if os.path.isdir(f"{os.getcwd()}/configs/CDMs/PR"):
|
"""Check for the PlayReady CDM folder."""
|
||||||
return
|
if os.path.isdir(os.path.join(os.getcwd(), "configs", "CDMs", "PR")):
|
||||||
else:
|
|
||||||
os.mkdir(f"{os.getcwd()}/configs/CDMs/PR")
|
|
||||||
return
|
return
|
||||||
|
os.mkdir(os.path.join(os.getcwd(), "configs", "CDMs", "PR"))
|
||||||
|
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()
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
"""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
|
||||||
@ -5,8 +7,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
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
|
"""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
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import sys
|
"""Module to handle the React routes."""
|
||||||
|
|
||||||
import os
|
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
|
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 = sys._MEIPASS
|
base_path = getattr(sys, "_MEIPASS", os.path.abspath("."))
|
||||||
else: # Running in a normal Python environment
|
else: # Running in a normal Python environment
|
||||||
base_path = os.path.abspath(".")
|
base_path = os.path.abspath(".")
|
||||||
|
|
||||||
@ -23,12 +26,23 @@ 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=""):
|
||||||
if request.method == "GET":
|
"""Handle the index route."""
|
||||||
file_path = os.path.join(react_bp.static_folder, path)
|
# Ensure static_folder is not None
|
||||||
if path != "" and os.path.exists(file_path):
|
if react_bp.static_folder is None:
|
||||||
return send_from_directory(react_bp.static_folder, path)
|
raise ValueError("Static folder is not configured for the blueprint")
|
||||||
elif path.lower() in ["", "cache", "api", "testplayer", "account"]:
|
|
||||||
data = index_tags.tags.get(path.lower(), index_tags.tags["index"])
|
# Normalize the path to prevent directory traversal
|
||||||
return render_template("index.html", data=data)
|
safe_path = os.path.normpath(path)
|
||||||
else:
|
file_path = os.path.join(react_bp.static_folder, safe_path)
|
||||||
return send_from_directory(react_bp.static_folder, "index.html")
|
|
||||||
|
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