Spaces:
Sleeping
Sleeping
File size: 2,737 Bytes
9a7e570 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | from flask import Flask, request, jsonify
import json, os, uuid
app = Flask(__name__)
# Directorio temporal seguro con permisos totales de escritura en Hugging Face
DB_FILE = "/tmp/central_licenses.json"
def load_db():
if not os.path.exists(DB_FILE):
return {}
try:
with open(DB_FILE, "r", encoding="utf-8") as f:
return json.load(f)
except:
return {}
def save_db(data):
with open(DB_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4)
@app.route("/", methods=["GET"])
def home():
return jsonify({"status": "AURUM CENTRAL LICENSE SERVER OPERATIONAL 🟢"})
# =========================================================
# WEB DE VENTAS: GENERA UN SERIAL NUEVO
# =========================================================
@app.route("/generate_serial", methods=["POST"])
def generate_serial():
token = request.headers.get("Authorization")
if token != "SECRET_WEB_TOKEN_999":
return jsonify({"ok": False, "error": "Unauthorized"}), 401
db = load_db()
new_uuid = str(uuid.uuid4()).upper().split("-")
serial_key = f"AURUM-{new_uuid[0]}-{new_uuid[1]}"
db[serial_key] = {
"hwid": None,
"activated": False,
"type": "normal"
}
save_db(db)
return jsonify({"ok": True, "serial": serial_key})
# =========================================================
# CLIENTE LOCAL: INTENTA ACTIVAR DESDE SU PC
# =========================================================
@app.route("/activate_client", methods=["POST"])
def activate_client():
data = request.get_json(silent=True) or {}
serial = data.get("serial", "").strip()
hwid = data.get("hwid", "").strip()
if not serial or not hwid:
return jsonify({"ok": False, "error": "Missing data"}), 400
db = load_db()
if serial not in db:
return jsonify({"ok": False, "error": "Serial does not exist"}), 404
lic = db[serial]
# Si la licencia ya fue amarrada a otra PC (HWID diferente), bloquea de inmediato
if lic["hwid"] is not None and lic["hwid"] != hwid:
return jsonify({"ok": False, "error": "Serial already used on another PC."}), 403
# Si está libre, la vincula a esta máquina de forma perpetua
if lic["hwid"] is None:
lic["hwid"] = hwid
lic["activated"] = True
save_db(db)
return jsonify({"ok": True, "msg": "Bound to this PC.", "type": lic["type"]})
return jsonify({"ok": True, "msg": "License verified.", "type": lic["type"]})
if __name__ == "__main__":
# Captura de manera dinámica el puerto asignado internamente por la plataforma
port = int(os.environ.get("PORT", 7860))
app.run(host="0.0.0.0", port=port, debug=False)
|