-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Created by loki_101 on Discord or [email protected] | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]", | ||
"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} <<EOF\r\nCREATE TABLE IF NOT EXISTS Licensing (\r\nlicense VARCHAR(255) NOT NULL PRIMARY KEY,\r\nip VARCHAR(255) NOT NULL,\r\ndiscordId VARCHAR(255),\r\nemail VARCHAR(255)\r\n);\r\nEOF\r\n# Create the license_check view if it does not already exist\r\nview_exists=$(mysql -h ${DB_HOST} -P ${DB_PORT} -u ${DB_USER} -p${DB_PASSWORD} -D ${DB_NAME} -N -B -e \"SELECT COUNT(*) FROM information_schema.VIEWS WHERE TABLE_NAME = 'license_check';\")\r\nif [[ ${view_exists} -eq 0 ]]; then\r\n# Create the license_check view only if it doesn't exist\r\nmysql -h ${DB_HOST} -P ${DB_PORT} -u ${DB_USER} -p${DB_PASSWORD} -D ${DB_NAME} <<EOF\r\nCREATE VIEW license_check AS\r\nSELECT license, ip FROM Licensing;\r\nEOF\r\nfi\r\necho -e \"install complete\"\r\nexit 0", | ||
"container": "python:3.8-slim", | ||
"entrypoint": "bash" | ||
} | ||
}, | ||
"variables": [ | ||
{ | ||
"name": "App py file", | ||
"description": "The file that starts the App.", | ||
"env_variable": "PY_FILE", | ||
"default_value": "app.py", | ||
"user_viewable": true, | ||
"user_editable": true, | ||
"rules": "required|string", | ||
"field_type": "text" | ||
}, | ||
{ | ||
"name": "Additional Python packages", | ||
"description": "Install additional python packages.\r\n\r\nUse spaces to separate", | ||
"env_variable": "PY_PACKAGES", | ||
"default_value": "", | ||
"user_viewable": true, | ||
"user_editable": true, | ||
"rules": "nullable|string", | ||
"field_type": "text" | ||
}, | ||
{ | ||
"name": "Requirements file", | ||
"description": "if there are other requirements files to choose from.", | ||
"env_variable": "REQUIREMENTS_FILE", | ||
"default_value": "requirements.txt", | ||
"user_viewable": true, | ||
"user_editable": true, | ||
"rules": "required|string", | ||
"field_type": "text" | ||
}, | ||
{ | ||
"name": "DB_HOST", | ||
"description": "Database Host", | ||
"env_variable": "DB_HOST", | ||
"default_value": "172.18.0.1", | ||
"user_viewable": false, | ||
"user_editable": false, | ||
"rules": "required|string|max:20", | ||
"field_type": "text" | ||
}, | ||
{ | ||
"name": "DB_USER", | ||
"description": "Database User", | ||
"env_variable": "DB_USER", | ||
"default_value": "", | ||
"user_viewable": false, | ||
"user_editable": false, | ||
"rules": "required|string|max:40", | ||
"field_type": "text" | ||
}, | ||
{ | ||
"name": "DB_PASSWORD", | ||
"description": "Database Password", | ||
"env_variable": "DB_PASSWORD", | ||
"default_value": "", | ||
"user_viewable": false, | ||
"user_editable": false, | ||
"rules": "required|string|max:40", | ||
"field_type": "text" | ||
}, | ||
{ | ||
"name": "DB_NAME", | ||
"description": "Database Name", | ||
"env_variable": "DB_NAME", | ||
"default_value": "", | ||
"user_viewable": false, | ||
"user_editable": false, | ||
"rules": "required|string|max:20", | ||
"field_type": "text" | ||
}, | ||
{ | ||
"name": "DB_PORT", | ||
"description": "Database Port", | ||
"env_variable": "DB_PORT", | ||
"default_value": "3306", | ||
"user_viewable": false, | ||
"user_editable": false, | ||
"rules": "required|string|max:5", | ||
"field_type": "text" | ||
}, | ||
{ | ||
"name": "Debug", | ||
"description": "True or False, not case-sensitive", | ||
"env_variable": "DEBUG", | ||
"default_value": "False", | ||
"user_viewable": true, | ||
"user_editable": true, | ||
"rules": "required|string|max:20", | ||
"field_type": "text" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
robyn == 0.35.0 | ||
aiomysql == 0.2.0 |