File size: 3,488 Bytes
7908c39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import json
from datetime import datetime, timezone
import requests
import gradio as gr
from huggingface_hub import HfApi, hf_hub_download

HF_TOKEN = os.environ.get("HF_TOKEN", "")
DATASET_REPO = os.environ.get("HF_DATASET_REPO", "your_hf_username/ViperGearLab-Analyst-DB")
GUMROAD_PRODUCT_ID = os.environ.get("GUMROAD_PRODUCT_ID", "your_gumroad_product_id")
DB_FILENAME = "analyst_intel.jsonl"

api = HfApi(token=HF_TOKEN)

def verify_gumroad_license(license_key: str) -> tuple[bool, str]:
    if not license_key.strip():
        return False, "Missing license key."
    try:
        resp = requests.post(
            "https://api.gumroad.com/v2/licenses/verify",
            data={
                "product_id": GUMROAD_PRODUCT_ID,
                "license_key": license_key.strip(),
                "increment_uses_count": "false"
            },
            timeout=10
        )
        data = resp.json()
        if data.get("success") and not data.get("purchase", {}).get("refunded"):
            email = data["purchase"].get("email", "Verified Operator")
            return True, f"Authenticated: {email}"
        return False, "Invalid or expired Gumroad license key."
    except Exception as e:
        return False, f"Verification error: {e}"

def fetch_database_records() -> list[dict]:
    try:
        local_path = hf_hub_download(
            repo_id=DATASET_REPO,
            filename=DB_FILENAME,
            repo_type="dataset",
            token=HF_TOKEN
        )
        with open(local_path, "r", encoding="utf-8") as f:
            return [json.loads(line) for line in f if line.strip()]
    except Exception:
        return []

def submit_analyst_entry(license_key: str, handle: str, category: str, payload: str) -> str:
    valid, msg = verify_gumroad_license(license_key)
    if not valid:
        return f"[ACCESS DENIED] {msg}"

    records = fetch_database_records()
    entry = {
        "timestamp": datetime.now(timezone.utc).isoformat(),
        "analyst": handle.strip() or "Anonymous",
        "category": category,
        "payload": payload.strip()
    }
    records.append(entry)

    with open(DB_FILENAME, "w", encoding="utf-8") as f:
        for r in records:
            f.write(json.dumps(r) + "\n")

    api.upload_file(
        path_or_fileobj=DB_FILENAME,
        path_in_repo=DB_FILENAME,
        repo_id=DATASET_REPO,
        repo_type="dataset",
        commit_message=f"Update from {entry['analyst']} [{category}]"
    )
    return json.dumps(records[-10:], indent=2)

with gr.Blocks(title="ViperGearLab Analyst Hub") as demo:
    gr.Markdown("### ViperGearLab // Shared Analyst Database & Telemetry Node")
    license_input = gr.Textbox(label="Gumroad License Key", type="password")
    with gr.Row():
        handle_input = gr.Textbox(label="Analyst Callsign / Handle")
        category_input = gr.Dropdown(
            choices=["Benchmark", "Script Patch", "Hardware Config", "Field Telemetry"],
            value="Script Patch",
            label="Module Category"
        )
    payload_input = gr.Textbox(label="Technical Finding / Config Snippet", lines=4)
    submit_btn = gr.Button("Verify License & Commit to Database")
    output_log = gr.Code(label="Latest Shared Analyst Entries (JSON)", language="json")

    submit_btn.click(
        fn=submit_analyst_entry,
        inputs=[license_input, handle_input, category_input, payload_input],
        outputs=output_log
    )

if __name__ == "__main__":
    demo.launch()