File size: 2,588 Bytes
2b1ccda
94a57c8
 
18b181f
 
94a57c8
 
 
 
 
 
 
18b181f
94a57c8
2b1ccda
94a57c8
18b181f
2b1ccda
 
18b181f
 
 
 
 
2b1ccda
18b181f
 
 
 
2b1ccda
 
18b181f
2b1ccda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18b181f
2b1ccda
18b181f
94a57c8
 
 
18b181f
94a57c8
 
 
18b181f
94a57c8
2b1ccda
 
94a57c8
 
2b1ccda
94a57c8
 
 
 
2b1ccda
94a57c8
 
 
 
 
 
2b1ccda
94a57c8
 
 
 
 
 
18b181f
94a57c8
 
 
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
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
import uvicorn
import subprocess
import threading
from pathlib import Path

app = FastAPI()
count_file = Path("/tmp/people_helped.txt")
count_file.write_text("0")

def increment_count():
    current = int(count_file.read_text().strip() or "0")
    count_file.write_text(str(current + 1))
    print(f"✅ Counter increased! New total: {current + 1}")

def monitor_snowflake():
    print("Starting Snowflake proxy and monitoring...")
    
    proc = subprocess.Popen(
        ["snowflake-proxy", "-verbose", "-relay", "https://snowflake.torproject.org/"],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        text=True,
        bufsize=1
    )
    
    for line in proc.stdout:
        line = line.strip()
        if not line:
            continue
            
        print(f"LOG: {line}")  # This will show in HF Logs
        
        # Broader detection for client connections
        lower_line = line.lower()
        if any(x in lower_line for x in [
            "client connected",
            "accepted connection", 
            "new session",
            "webrtc: peerconnection",
            "data channel opened",
            "proxy: client",
            "established connection",
            "starting session"
        ]):
            increment_count()

# Start monitoring
threading.Thread(target=monitor_snowflake, daemon=True).start()

@app.get("/", response_class=HTMLResponse)
async def dashboard():
    count = count_file.read_text().strip()
    return f"""
    <html>
    <head>
        <title>❄️ Living Snowflake Proxy</title>
        <style>
            body {{ font-family: monospace; text-align: center; padding: 40px; background: #0a0a0a; color: #00ff9d; }}
            .counter {{ font-size: 6rem; margin: 20px 0; font-weight: bold; }}
        </style>
        <script>
            async function update() {{
                const res = await fetch('/count');
                const data = await res.json();
                document.getElementById('count').textContent = data.count;
            }}
            setInterval(update, 2000);
        </script>
    </head>
    <body>
        <h1>❄️ Living Snowflake Proxy</h1>
        <p>People I've helped today:</p>
        <div class="counter" id="count">{count}</div>
        <p>Proxy is running 24/7</p>
    </body>
    </html>
    """

@app.get("/count")
async def get_count():
    return {"count": int(count_file.read_text().strip() or "0")}

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)