| 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 |
|
|
| |
| 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 \ |
| "] |