Skip to content

Commit 82c374a

Browse files
authored
Add files via upload
1 parent 437d02d commit 82c374a

File tree

3 files changed

+210
-0
lines changed

3 files changed

+210
-0
lines changed

app.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Created by loki_101 on Discord or loki@crazycoder.dev
2+
3+
import os
4+
import json
5+
import aiomysql
6+
from robyn import Robyn
7+
8+
os.environ["ROBYN_URL"] = "0.0.0.0"
9+
10+
app = Robyn(__file__)
11+
12+
pool = None
13+
14+
@app.startup_handler
15+
async def startup_handler():
16+
# Read configuration from environment variables
17+
db_user = os.getenv("DB_USER", "username")
18+
db_password = os.getenv("DB_PASSWORD", "password")
19+
db_host = os.getenv("DB_HOST", "Configure me first, moron!")
20+
db_name = os.getenv("DB_NAME", "license_db")
21+
db_port = int(os.getenv("DB_PORT", "3306"))
22+
23+
global pool
24+
pool = await aiomysql.create_pool(
25+
host=db_host, port=db_port,
26+
user=db_user, password=db_password,
27+
db=db_name
28+
)
29+
print("Database connected")
30+
31+
@app.shutdown_handler
32+
async def shutdown_handler():
33+
global pool
34+
pool.close()
35+
await pool.wait_closed()
36+
print("Database disconnected")
37+
38+
@app.post("/")
39+
async def check_license(request):
40+
debug = os.getenv("DEBUG", "").lower() == "true"
41+
try:
42+
# Extract the license_key from the JSON payload
43+
data = json.loads(request.body)
44+
license_key = data.get("license_key")
45+
46+
# Extract the client's IP address from the request
47+
ip_address = request.headers.get("cf-connecting-ip")
48+
if debug:
49+
print(ip_address)
50+
51+
# Input validation
52+
if not license_key or not ip_address:
53+
return {"error": "Invalid input"}, 400
54+
55+
# Query to check if the license and IP match
56+
async with pool.acquire() as conn:
57+
async with conn.cursor() as cur:
58+
await cur.execute(
59+
"SELECT * FROM license_check WHERE license=%s AND ip=%s",
60+
(license_key, ip_address)
61+
)
62+
valid = await cur.fetchone()
63+
if debug:
64+
print(f"IP Address: {ip_address}")
65+
print(f"License Key: {license_key}")
66+
print(f"Query Result: {valid}")
67+
if valid:
68+
if debug:
69+
print("License verified")
70+
return {"status": "success", "message": "License verified."}
71+
else:
72+
if debug:
73+
print("License not found or IP mismatch")
74+
return {"status": "failure", "message": "License not found or IP mismatch."}
75+
except Exception as e:
76+
import traceback
77+
traceback.print_exc()
78+
print(f"Error occurred: {e}")
79+
return {"error": "Internal Server Error"}, 500
80+
81+
app.start(port=57157)

egg-licensing-server.json

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"_comment": "DO NOT EDIT: FILE GENERATED AUTOMATICALLY BY PTERODACTYL PANEL - PTERODACTYL.IO",
3+
"meta": {
4+
"version": "PTDL_v2",
5+
"update_url": null
6+
},
7+
"exported_at": "2023-06-25T16:37:29-07:00",
8+
"name": "Licensing Server",
9+
"author": "loki@crazycoder.dev",
10+
"description": "Licensing Server",
11+
"features": null,
12+
"docker_images": {
13+
"Python 3.11": "ghcr.io\/parkervcp\/yolks:python_3.11",
14+
"Python 3.10": "ghcr.io\/parkervcp\/yolks:python_3.10",
15+
"Python 3.9": "ghcr.io\/parkervcp\/yolks:python_3.9",
16+
"Python 3.8": "ghcr.io\/parkervcp\/yolks:python_3.8",
17+
"Python 3.7": "ghcr.io\/parkervcp\/yolks:python_3.7",
18+
"Python 2.7": "ghcr.io\/parkervcp\/yolks:python_2.7"
19+
},
20+
"file_denylist": [],
21+
"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",
22+
"config": {
23+
"files": "{}",
24+
"startup": "{\r\n \"done\": \"Database connected\"\r\n}",
25+
"logs": "{}",
26+
"stop": "^C"
27+
},
28+
"scripts": {
29+
"installation": {
30+
"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",
31+
"container": "python:3.8-slim",
32+
"entrypoint": "bash"
33+
}
34+
},
35+
"variables": [
36+
{
37+
"name": "App py file",
38+
"description": "The file that starts the App.",
39+
"env_variable": "PY_FILE",
40+
"default_value": "app.py",
41+
"user_viewable": true,
42+
"user_editable": true,
43+
"rules": "required|string",
44+
"field_type": "text"
45+
},
46+
{
47+
"name": "Additional Python packages",
48+
"description": "Install additional python packages.\r\n\r\nUse spaces to separate",
49+
"env_variable": "PY_PACKAGES",
50+
"default_value": "",
51+
"user_viewable": true,
52+
"user_editable": true,
53+
"rules": "nullable|string",
54+
"field_type": "text"
55+
},
56+
{
57+
"name": "Requirements file",
58+
"description": "if there are other requirements files to choose from.",
59+
"env_variable": "REQUIREMENTS_FILE",
60+
"default_value": "requirements.txt",
61+
"user_viewable": true,
62+
"user_editable": true,
63+
"rules": "required|string",
64+
"field_type": "text"
65+
},
66+
{
67+
"name": "DB_HOST",
68+
"description": "Database Host",
69+
"env_variable": "DB_HOST",
70+
"default_value": "172.18.0.1",
71+
"user_viewable": false,
72+
"user_editable": false,
73+
"rules": "required|string|max:20",
74+
"field_type": "text"
75+
},
76+
{
77+
"name": "DB_USER",
78+
"description": "Database User",
79+
"env_variable": "DB_USER",
80+
"default_value": "",
81+
"user_viewable": false,
82+
"user_editable": false,
83+
"rules": "required|string|max:40",
84+
"field_type": "text"
85+
},
86+
{
87+
"name": "DB_PASSWORD",
88+
"description": "Database Password",
89+
"env_variable": "DB_PASSWORD",
90+
"default_value": "",
91+
"user_viewable": false,
92+
"user_editable": false,
93+
"rules": "required|string|max:40",
94+
"field_type": "text"
95+
},
96+
{
97+
"name": "DB_NAME",
98+
"description": "Database Name",
99+
"env_variable": "DB_NAME",
100+
"default_value": "",
101+
"user_viewable": false,
102+
"user_editable": false,
103+
"rules": "required|string|max:20",
104+
"field_type": "text"
105+
},
106+
{
107+
"name": "DB_PORT",
108+
"description": "Database Port",
109+
"env_variable": "DB_PORT",
110+
"default_value": "3306",
111+
"user_viewable": false,
112+
"user_editable": false,
113+
"rules": "required|string|max:5",
114+
"field_type": "text"
115+
},
116+
{
117+
"name": "Debug",
118+
"description": "True or False, not case-sensitive",
119+
"env_variable": "DEBUG",
120+
"default_value": "False",
121+
"user_viewable": true,
122+
"user_editable": true,
123+
"rules": "required|string|max:20",
124+
"field_type": "text"
125+
}
126+
]
127+
}

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
robyn == 0.35.0
2+
aiomysql == 0.2.0

0 commit comments

Comments
 (0)