Compare commits

...

4 Commits

5 changed files with 35 additions and 13 deletions

View File

@ -1,3 +1,5 @@
"""Icon links module for social media links."""
data = { data = {
"discord": "https://discord.cdrm-project.com/", "discord": "https://discord.cdrm-project.com/",
"telegram": "https://telegram.cdrm-project.com/", "telegram": "https://telegram.cdrm-project.com/",

View File

@ -1,3 +1,5 @@
"""Index tags module for the index page."""
tags = { tags = {
"index": { "index": {
"description": "Decrypt Widevine and PlayReady protected content", "description": "Decrypt Widevine and PlayReady protected content",

View File

@ -1,9 +1,12 @@
"""Module to manage the user database."""
import sqlite3 import sqlite3
import os import os
import bcrypt import bcrypt
def create_user_database(): def create_user_database():
"""Create the user database."""
os.makedirs(f"{os.getcwd()}/databases/sql", exist_ok=True) os.makedirs(f"{os.getcwd()}/databases/sql", exist_ok=True)
with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn:
@ -21,6 +24,7 @@ def create_user_database():
def add_user(username, password, api_key): def add_user(username, password, api_key):
"""Add a user to the database."""
hashed_pw = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()) hashed_pw = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt())
with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn:
@ -37,6 +41,7 @@ def add_user(username, password, api_key):
def verify_user(username, password): def verify_user(username, password):
"""Verify a user."""
with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn:
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute( cursor.execute(
@ -55,6 +60,7 @@ def verify_user(username, password):
def fetch_api_key(username): def fetch_api_key(username):
"""Fetch the API key for a user."""
with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn:
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute( cursor.execute(
@ -69,7 +75,7 @@ def fetch_api_key(username):
def change_password(username, new_password): def change_password(username, new_password):
"""Change the password for a user."""
# Hash the new password # Hash the new password
new_hashed_pw = bcrypt.hashpw(new_password.encode("utf-8"), bcrypt.gensalt()) new_hashed_pw = bcrypt.hashpw(new_password.encode("utf-8"), bcrypt.gensalt())
@ -85,6 +91,7 @@ def change_password(username, new_password):
def change_api_key(username, new_api_key): def change_api_key(username, new_api_key):
"""Change the API key for a user."""
# Update the API key in the database # Update the API key in the database
with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn:
cursor = conn.cursor() cursor = conn.cursor()
@ -97,6 +104,7 @@ def change_api_key(username, new_api_key):
def fetch_styled_username(username): def fetch_styled_username(username):
"""Fetch the styled username for a user."""
with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn:
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute( cursor.execute(
@ -112,6 +120,7 @@ def fetch_styled_username(username):
def fetch_username_by_api_key(api_key): def fetch_username_by_api_key(api_key):
"""Fetch the username for a user by API key."""
with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn:
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute("SELECT Username FROM user_info WHERE API_Key = ?", (api_key,)) cursor.execute("SELECT Username FROM user_info WHERE API_Key = ?", (api_key,))

View File

@ -1,11 +1,13 @@
"""Module to check for the config file."""
import os import os
def check_for_config_file(): def check_for_config_file():
if os.path.exists(f"{os.getcwd()}/configs/config.yaml"): """Check for the config file."""
if os.path.exists(os.path.join(os.getcwd(), "configs", "config.yaml")):
return return
else: default_config = """
default_config = """\
default_wv_cdm: '' default_wv_cdm: ''
default_pr_cdm: '' default_pr_cdm: ''
secret_key_flask: 'secretkey' secret_key_flask: 'secretkey'
@ -22,6 +24,8 @@ remote_cdm_secret: ''
# port: '' # port: ''
# database: '' # database: ''
""" """
with open(f"{os.getcwd()}/configs/config.yaml", "w") as f: with open(
os.path.join(os.getcwd(), "configs", "config.yaml"), "w", encoding="utf-8"
) as f:
f.write(default_config) f.write(default_config)
return return

21
main.py
View File

@ -1,11 +1,10 @@
from custom_functions.prechecks.python_checks import run_python_checks """Main module to run the application."""
run_python_checks() import os
from custom_functions.prechecks.precheck import run_precheck import yaml
run_precheck()
from flask import Flask from flask import Flask
from flask_cors import CORS from flask_cors import CORS
from routes.react import react_bp from routes.react import react_bp
from routes.api import api_bp from routes.api import api_bp
from routes.remote_device_wv import remotecdm_wv_bp from routes.remote_device_wv import remotecdm_wv_bp
@ -15,11 +14,17 @@ from routes.user_info import user_info_bp
from routes.register import register_bp from routes.register import register_bp
from routes.login import login_bp from routes.login import login_bp
from routes.user_changes import user_change_bp from routes.user_changes import user_change_bp
import os from custom_functions.prechecks.python_checks import run_python_checks
import yaml from custom_functions.prechecks.precheck import run_precheck
run_python_checks()
run_precheck()
app = Flask(__name__) app = Flask(__name__)
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)
app.secret_key = config["secret_key_flask"] app.secret_key = config["secret_key_flask"]