diff --git a/app.py b/app.py new file mode 100644 index 0000000..404e683 --- /dev/null +++ b/app.py @@ -0,0 +1,81 @@ +# Created by loki_101 on Discord or loki@crazycoder.dev + +import os +import json +import aiomysql +from robyn import Robyn + +os.environ["ROBYN_URL"] = "0.0.0.0" + +app = Robyn(__file__) + +pool = None + +@app.startup_handler +async def startup_handler(): + # Read configuration from environment variables + db_user = os.getenv("DB_USER", "username") + db_password = os.getenv("DB_PASSWORD", "password") + db_host = os.getenv("DB_HOST", "Configure me first, moron!") + db_name = os.getenv("DB_NAME", "license_db") + db_port = int(os.getenv("DB_PORT", "3306")) + + global pool + pool = await aiomysql.create_pool( + host=db_host, port=db_port, + user=db_user, password=db_password, + db=db_name + ) + print("Database connected") + +@app.shutdown_handler +async def shutdown_handler(): + global pool + pool.close() + await pool.wait_closed() + print("Database disconnected") + +@app.post("/") +async def check_license(request): + debug = os.getenv("DEBUG", "").lower() == "true" + try: + # Extract the license_key from the JSON payload + data = json.loads(request.body) + license_key = data.get("license_key") + + # Extract the client's IP address from the request + ip_address = request.headers.get("cf-connecting-ip") + if debug: + print(ip_address) + + # Input validation + if not license_key or not ip_address: + return {"error": "Invalid input"}, 400 + + # Query to check if the license and IP match + async with pool.acquire() as conn: + async with conn.cursor() as cur: + await cur.execute( + "SELECT * FROM license_check WHERE license=%s AND ip=%s", + (license_key, ip_address) + ) + valid = await cur.fetchone() + if debug: + print(f"IP Address: {ip_address}") + print(f"License Key: {license_key}") + print(f"Query Result: {valid}") + if valid: + if debug: + print("License verified") + return {"status": "success", "message": "License verified."} + else: + if debug: + print("License not found or IP mismatch") + return {"status": "failure", "message": "License not found or IP mismatch."} + except Exception as e: + import traceback + traceback.print_exc() + print(f"Error occurred: {e}") + return {"error": "Internal Server Error"}, 500 + +app.start(port=57157) \ No newline at end of file diff --git a/egg-licensing-server.json b/egg-licensing-server.json new file mode 100644 index 0000000..4dca053 --- /dev/null +++ b/egg-licensing-server.json @@ -0,0 +1,127 @@ +{ + "_comment": "DO NOT EDIT: FILE GENERATED AUTOMATICALLY BY PTERODACTYL PANEL - PTERODACTYL.IO", + "meta": { + "version": "PTDL_v2", + "update_url": null + }, + "exported_at": "2023-06-25T16:37:29-07:00", + "name": "Licensing Server", + "author": "loki@crazycoder.dev", + "description": "Licensing Server", + "features": null, + "docker_images": { + "Python 3.11": "ghcr.io\/parkervcp\/yolks:python_3.11", + "Python 3.10": "ghcr.io\/parkervcp\/yolks:python_3.10", + "Python 3.9": "ghcr.io\/parkervcp\/yolks:python_3.9", + "Python 3.8": "ghcr.io\/parkervcp\/yolks:python_3.8", + "Python 3.7": "ghcr.io\/parkervcp\/yolks:python_3.7", + "Python 2.7": "ghcr.io\/parkervcp\/yolks:python_2.7" + }, + "file_denylist": [], + "startup": "trap_handler() { kill -INT \"$python_pid\"; }; trap trap_handler SIGTERM SIGINT; python -m pip install --upgrade pip; if [[ ! -z \"{{PY_PACKAGES}}\" ]]; then pip install -U --prefix .local {{PY_PACKAGES}}; fi; if [[ -f \/home\/container\/{{REQUIREMENTS_FILE}} ]]; then pip install -U --prefix .local -r {{REQUIREMENTS_FILE}}; fi; \/usr\/local\/bin\/python \/home\/container\/{{PY_FILE}} --log-level WARN & python_pid=$!; wait", + "config": { + "files": "{}", + "startup": "{\r\n \"done\": \"Database connected\"\r\n}", + "logs": "{}", + "stop": "^C" + }, + "scripts": { + "installation": { + "script": "#!\/bin\/bash\r\n#\r\n# Server Files: \/mnt\/server\r\n#!\/bin\/bash\r\n# Update and install dependencies\r\napt update\r\napt -y install mariadb-client\r\n# Construct the DATABASE_URL from environment variables\r\nDB_USER=${DB_USER}\r\nDB_PASSWORD=${DB_PASSWORD}\r\nDB_HOST=${DB_HOST}\r\nDB_PORT=${DB_PORT}\r\nDB_NAME=${DB_NAME}\r\nDATABASE_URL=\"mysql:\/\/${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}\/${DB_NAME}\"\r\nexport DATABASE_URL=${DATABASE_URL}\r\n# Connect to the database and create the table if it does not exist\r\nmysql -h ${DB_HOST} -P ${DB_PORT} -u ${DB_USER} -p${DB_PASSWORD} -D ${DB_NAME} <