commit 523f5f15767e24f918328422ad62de1b1b87ae87 Author: √(noham)² <100566912+NohamR@users.noreply.github.com> Date: Sat Dec 13 15:06:17 2025 +0100 Create server.py diff --git a/server.py b/server.py new file mode 100644 index 0000000..527f6c2 --- /dev/null +++ b/server.py @@ -0,0 +1,116 @@ +from datetime import datetime +import os +import uuid +import json +import base64 + +from flask import Flask, jsonify, request + + +app = Flask(__name__) + +PENDING_ACTIVATIONS = {} + +def _b64url_encode(data: bytes) -> str: + return base64.urlsafe_b64encode(data).decode("ascii").rstrip("=") + + +def _make_jwt_like(payload: dict) -> str: + header = {"alg": "HS256", "typ": "JWT"} + header_b64 = _b64url_encode(json.dumps(header, separators=(",", ":"), ensure_ascii=False).encode("utf-8")) + payload_b64 = _b64url_encode(json.dumps(payload, separators=(",", ":"), ensure_ascii=False).encode("utf-8")) + signature_b64 = _b64url_encode(b"signature") + return f"{header_b64}.{payload_b64}.{signature_b64}" + + +@app.route("/api/v1/license/activate", methods=["POST"]) +def activate_license(): + payload = request.get_json(silent=True) or {} + print("Received activation request:", payload) + + license_key = payload.get("licenseKey", "") + device_id = payload.get("deviceId", str(uuid.uuid4())) + device_name = payload.get("deviceName", "Unnamed Device") + email = payload.get("email") + license_server_url = payload.get("licenseServerUrl") + + activation_id = str(uuid.uuid4()) + activated_at = datetime.utcnow().isoformat() + "Z" + + PENDING_ACTIVATIONS[activation_id] = { + "licenseKey": license_key, + "deviceId": device_id, + "deviceName": device_name, + "email": email, + "licenseServerUrl": license_server_url, + "activatedAt": activated_at, + } + + resp = { + "status": "activated", + "licenseKey": license_key, + "deviceId": device_id, + "deviceName": device_name, + "email": email, + "activationId": activation_id, + "activatedAt": activated_at, + } + + return jsonify(resp), 200 + + +@app.route("/api/v1/license/activate/", methods=["POST"]) +def verify_activation_otp(activation_id: str): + payload = request.get_json(silent=True) or {} + print("Received OTP verification:", {"activationId": activation_id, **payload}) + + pending = PENDING_ACTIVATIONS.get(activation_id) + if not pending: + return jsonify({"error": "Invalid activationId"}), 404 + + now_iso = datetime.utcnow().isoformat() + "Z" + license_payload = { + "licenseKey": pending.get("licenseKey"), + "email": pending.get("email"), + "deviceId": pending.get("deviceId"), + "deviceName": pending.get("deviceName"), + "licenseServerUrl": pending.get("licenseServerUrl"), + "plan": "ULTIMATE_EDITION", # ["PRO_EDITION","GOLDEN_EDITION","ULTIMATE_EDITION"] + "type": "personal", + "createdAt": pending.get("activatedAt"), + "updatedAt": now_iso, + "trialActive": False, + } + + token = _make_jwt_like(license_payload) + PENDING_ACTIVATIONS.pop(activation_id, None) + + return jsonify({ + "licenseToken": token, + }), 200 + + +@app.route("/api/v1/license/verify", methods=["POST"]) +def verify_license(): + payload = request.get_json(silent=True) or {} + print("Received license verification:", payload) + + response = { + "verified": True, + "subscription": { + "plan": "GOLDEN_EDITION" + } + } + + return jsonify(response), 200 + + +def create_app(): + return app + + +if __name__ == "__main__": + host = os.getenv("FLASK_HOST", "127.0.0.1") + port = int(os.getenv("FLASK_PORT", "5000")) + debug = os.getenv("FLASK_DEBUG", "false").lower() in {"1", "true", "yes"} + app.run(host=host, port=port, debug=debug)