Spaces:
Sleeping
Sleeping
Download app.py from jorgeas6402/internet: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/spaces/jorgeas6402/internet/resolve/main/app.py
- Command line
-
hf download hf://spaces/jorgeas6402/internet/app.py
-
curl -L -o app.py https://huggingface.co/spaces/jorgeas6402/internet/resolve/main/app.py
2.74 kB
| 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) | |
| def home(): | |
| return jsonify({"status": "AURUM CENTRAL LICENSE SERVER OPERATIONAL 🟢"}) | |
| # ========================================================= | |
| # WEB DE VENTAS: GENERA UN SERIAL NUEVO | |
| # ========================================================= | |
| 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 | |
| # ========================================================= | |
| 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) | |