zk-Armor commited on
Commit
39bf367
·
verified ·
1 Parent(s): f4994e8

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. Dockerfile +5 -0
  2. server.py +52 -0
Dockerfile ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+ RUN apt-get update -qq && apt-get install -y -qq curl >/dev/null 2>&1
3
+ WORKDIR /app
4
+ COPY server.py /app/server.py
5
+ CMD ["python", "-u", "server.py"]
server.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import http.server
3
+ import subprocess
4
+
5
+ PORT = int(os.environ.get("PORT", "7860"))
6
+ PROXY = "http://hermes:f72e802bcb276eab77dc3da80cf2deb8293de87b6d38583a@51.75.119.147:18080"
7
+ PROXY_HOST = "51.75.119.147:18080"
8
+
9
+ def run(cmd):
10
+ try:
11
+ p = subprocess.run(cmd, capture_output=True, text=True, timeout=25)
12
+ return "rc=%s code=%s" % (p.returncode, p.stdout.strip())
13
+ except subprocess.TimeoutExpired:
14
+ return "TIMEOUT"
15
+ except Exception as e:
16
+ return "EXC:%s" % e
17
+
18
+ def probe():
19
+ lines = []
20
+ lines.append("ENV_PROXY: HTTPS_PROXY=%r HTTP_PROXY=%r ALL_PROXY=%r" % (
21
+ os.environ.get("HTTPS_PROXY"), os.environ.get("HTTP_PROXY"), os.environ.get("ALL_PROXY")))
22
+ lines.append("DIRECT_TG: " + run(["curl", "-sS", "-m", "12", "-o", "/dev/null", "-w",
23
+ "%{http_code}|%{time_total}s",
24
+ "https://api.telegram.org/"]))
25
+ lines.append("PROXIED_TG: " + run(["curl", "-sS", "-m", "12", "-x", PROXY, "-o", "/dev/null", "-w",
26
+ "%{http_code}|%{time_total}s",
27
+ "https://api.telegram.org/"]))
28
+ lines.append("PROXY_NOAUTH: " + run(["curl", "-sS", "-m", "8", "-x", "http://%s" % PROXY_HOST,
29
+ "-o", "/dev/null", "-w", "%{http_code}", "https://api.telegram.org/"]))
30
+ lines.append("PROXY_TCP: " + run(["bash", "-lc",
31
+ "exec 3<>/dev/tcp/%s && echo OPEN" % PROXY_HOST]))
32
+ lines.append("IPIFY_DIRECT: " + run(["curl", "-sS", "-m", "12", "-o", "/dev/null", "-w",
33
+ "%{http_code}", "https://api.ipify.org/"]))
34
+ return "\n".join(lines)
35
+
36
+ RESULT = None
37
+
38
+ class H(http.server.BaseHTTPRequestHandler):
39
+ def do_GET(self):
40
+ global RESULT
41
+ if RESULT is None:
42
+ RESULT = probe()
43
+ body = RESULT.encode()
44
+ self.send_response(200)
45
+ self.send_header("Content-Type", "text/plain; charset=utf-8")
46
+ self.send_header("Content-Length", str(len(body)))
47
+ self.end_headers()
48
+ self.wfile.write(body)
49
+ def log_message(self, *a):
50
+ pass
51
+
52
+ http.server.ThreadingHTTPServer(("0.0.0.0", PORT), H).serve_forever()