Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
import uvicorn
|
| 4 |
-
import asyncio
|
| 5 |
import subprocess
|
| 6 |
-
import re
|
| 7 |
import threading
|
| 8 |
from pathlib import Path
|
| 9 |
|
|
@@ -14,36 +12,41 @@ count_file.write_text("0")
|
|
| 14 |
def increment_count():
|
| 15 |
current = int(count_file.read_text().strip() or "0")
|
| 16 |
count_file.write_text(str(current + 1))
|
|
|
|
| 17 |
|
| 18 |
-
# Background thread to monitor Snowflake logs
|
| 19 |
def monitor_snowflake():
|
|
|
|
|
|
|
| 20 |
proc = subprocess.Popen(
|
| 21 |
["snowflake-proxy", "-verbose", "-relay", "https://snowflake.torproject.org/"],
|
| 22 |
stdout=subprocess.PIPE,
|
| 23 |
stderr=subprocess.STDOUT,
|
| 24 |
text=True,
|
| 25 |
-
bufsize=1
|
| 26 |
-
universal_newlines=True
|
| 27 |
)
|
| 28 |
|
| 29 |
-
print("Snowflake proxy started... monitoring connections")
|
| 30 |
-
|
| 31 |
for line in proc.stdout:
|
| 32 |
line = line.strip()
|
| 33 |
-
if line:
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
# Start monitoring
|
| 47 |
threading.Thread(target=monitor_snowflake, daemon=True).start()
|
| 48 |
|
| 49 |
@app.get("/", response_class=HTMLResponse)
|
|
@@ -54,35 +57,23 @@ async def dashboard():
|
|
| 54 |
<head>
|
| 55 |
<title>❄️ Living Snowflake Proxy</title>
|
| 56 |
<style>
|
| 57 |
-
body {{
|
| 58 |
-
|
| 59 |
-
text-align: center;
|
| 60 |
-
padding: 50px;
|
| 61 |
-
background: #0a0a0a;
|
| 62 |
-
color: #00ff9d;
|
| 63 |
-
}}
|
| 64 |
-
.counter {{
|
| 65 |
-
font-size: 5rem;
|
| 66 |
-
margin: 30px 0;
|
| 67 |
-
font-weight: bold;
|
| 68 |
-
}}
|
| 69 |
-
.status {{ color: #00ff00; }}
|
| 70 |
</style>
|
| 71 |
<script>
|
| 72 |
-
async function
|
| 73 |
const res = await fetch('/count');
|
| 74 |
const data = await res.json();
|
| 75 |
document.getElementById('count').textContent = data.count;
|
| 76 |
}}
|
| 77 |
-
setInterval(
|
| 78 |
</script>
|
| 79 |
</head>
|
| 80 |
<body>
|
| 81 |
<h1>❄️ Living Snowflake Proxy</h1>
|
| 82 |
<p>People I've helped today:</p>
|
| 83 |
<div class="counter" id="count">{count}</div>
|
| 84 |
-
<p
|
| 85 |
-
<p>Thank you for using my proxy ❤️</p>
|
| 86 |
</body>
|
| 87 |
</html>
|
| 88 |
"""
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
import uvicorn
|
|
|
|
| 4 |
import subprocess
|
|
|
|
| 5 |
import threading
|
| 6 |
from pathlib import Path
|
| 7 |
|
|
|
|
| 12 |
def increment_count():
|
| 13 |
current = int(count_file.read_text().strip() or "0")
|
| 14 |
count_file.write_text(str(current + 1))
|
| 15 |
+
print(f"✅ Counter increased! New total: {current + 1}")
|
| 16 |
|
|
|
|
| 17 |
def monitor_snowflake():
|
| 18 |
+
print("Starting Snowflake proxy and monitoring...")
|
| 19 |
+
|
| 20 |
proc = subprocess.Popen(
|
| 21 |
["snowflake-proxy", "-verbose", "-relay", "https://snowflake.torproject.org/"],
|
| 22 |
stdout=subprocess.PIPE,
|
| 23 |
stderr=subprocess.STDOUT,
|
| 24 |
text=True,
|
| 25 |
+
bufsize=1
|
|
|
|
| 26 |
)
|
| 27 |
|
|
|
|
|
|
|
| 28 |
for line in proc.stdout:
|
| 29 |
line = line.strip()
|
| 30 |
+
if not line:
|
| 31 |
+
continue
|
| 32 |
|
| 33 |
+
print(f"LOG: {line}") # This will show in HF Logs
|
| 34 |
+
|
| 35 |
+
# Broader detection for client connections
|
| 36 |
+
lower_line = line.lower()
|
| 37 |
+
if any(x in lower_line for x in [
|
| 38 |
+
"client connected",
|
| 39 |
+
"accepted connection",
|
| 40 |
+
"new session",
|
| 41 |
+
"webrtc: peerconnection",
|
| 42 |
+
"data channel opened",
|
| 43 |
+
"proxy: client",
|
| 44 |
+
"established connection",
|
| 45 |
+
"starting session"
|
| 46 |
+
]):
|
| 47 |
+
increment_count()
|
| 48 |
|
| 49 |
+
# Start monitoring
|
| 50 |
threading.Thread(target=monitor_snowflake, daemon=True).start()
|
| 51 |
|
| 52 |
@app.get("/", response_class=HTMLResponse)
|
|
|
|
| 57 |
<head>
|
| 58 |
<title>❄️ Living Snowflake Proxy</title>
|
| 59 |
<style>
|
| 60 |
+
body {{ font-family: monospace; text-align: center; padding: 40px; background: #0a0a0a; color: #00ff9d; }}
|
| 61 |
+
.counter {{ font-size: 6rem; margin: 20px 0; font-weight: bold; }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
</style>
|
| 63 |
<script>
|
| 64 |
+
async function update() {{
|
| 65 |
const res = await fetch('/count');
|
| 66 |
const data = await res.json();
|
| 67 |
document.getElementById('count').textContent = data.count;
|
| 68 |
}}
|
| 69 |
+
setInterval(update, 2000);
|
| 70 |
</script>
|
| 71 |
</head>
|
| 72 |
<body>
|
| 73 |
<h1>❄️ Living Snowflake Proxy</h1>
|
| 74 |
<p>People I've helped today:</p>
|
| 75 |
<div class="counter" id="count">{count}</div>
|
| 76 |
+
<p>Proxy is running 24/7</p>
|
|
|
|
| 77 |
</body>
|
| 78 |
</html>
|
| 79 |
"""
|