File size: 2,497 Bytes
b267e74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && apt install -y \
    bash \
    curl \
    ca-certificates \
    python3 \
    procps \
    iproute2 \
    net-tools \
    coreutils \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /root
EXPOSE 7860

# Web app that shows sshx link (no auto-refresh)
RUN printf '%s\n' \
'from http.server import BaseHTTPRequestHandler, HTTPServer' \
'import os' \
'' \
'PORT = 7860' \
'LINK_FILE = "/tmp/sshx_link.txt"' \
'' \
'class Handler(BaseHTTPRequestHandler):' \
'    def do_GET(self):' \
'        self.send_response(200)' \
'        self.send_header("Content-type","text/html")' \
'        self.end_headers()' \
'        link = "Starting sshx… please refresh the page after a few seconds."' \
'        if os.path.exists(LINK_FILE):' \
'            try:' \
'                with open(LINK_FILE) as f:' \
'                    t = f.read().strip()' \
'                if t:' \
'                    link = t' \
'            except Exception:' \
'                pass' \
'' \
'        html = f"""<!doctype html>' \
'<html><head>' \
'<meta charset="utf-8">' \
'<title>Ubuntu Hacker Space</title>' \
'</head>' \
'<body style="background:#0b0b0b;color:#00ff9c;font-family:monospace;padding:20px">' \
'<h1>Ubuntu Hacker Space (Educational)</h1>' \
'<p>SSHX session:</p>' \
'<pre style="border:1px solid #00ff9c33;padding:12px;border-radius:10px;white-space:pre-wrap;word-break:break-word;">{link}</pre>' \
'<p><small>Manual refresh • Temporary • Free tier</small></p>' \
'</body></html>"""' \
'        self.wfile.write(html.encode())' \
'' \
'HTTPServer(("0.0.0.0", PORT), Handler).serve_forever()' \
> app.py

CMD ["bash","-lc", "\
set -e; \
echo '===== UBUNTU CONTAINER STARTED ====='; \
echo 'Waiting for sshx link…' > /tmp/sshx_link.txt; \
: > /tmp/sshx_raw.log; \
echo 'Installing sshx…'; \
curl -fsSL https://sshx.io/get | sh; \
echo 'Starting sshx…'; \
( stdbuf -oL -eL sshx 2>&1 | tee -a /tmp/sshx_raw.log ) & \
echo 'Extracting sshx link…'; \
( for i in $(seq 1 600); do \
    LINK=$(grep -Eo 'https?://sshx\\.io/s/[A-Za-z0-9]+' /tmp/sshx_raw.log | tail -n1); \
    if [ -z \"$LINK\" ]; then \
      RAW=$(grep -Eo 'sshx\\.io/s/[A-Za-z0-9]+' /tmp/sshx_raw.log | tail -n1); \
      [ -n \"$RAW\" ] && LINK=\"https://$RAW\"; \
    fi; \
    if [ -n \"$LINK\" ]; then \
      echo \"$LINK\" | tee /tmp/sshx_link.txt; \
      break; \
    fi; \
    sleep 1; \
  done ) & \
echo 'Web UI running on :7860'; \
python3 app.py \
"]