clash-linux commited on
Commit
16526c0
·
verified ·
1 Parent(s): fed9e59

Upload 5 files

Browse files
Files changed (1) hide show
  1. start.sh +49 -17
start.sh CHANGED
@@ -39,9 +39,17 @@ fi
39
 
40
  echo "Target WebSocket proxy: $TARGET_WSPROXY_URL"
41
 
42
- # 创建状态页面
43
- mkdir -p /app/html
44
- cat > /app/html/index.html << EOF
 
 
 
 
 
 
 
 
45
  <!DOCTYPE html>
46
  <html>
47
  <head>
@@ -91,21 +99,21 @@ cat > /app/html/index.html << EOF
91
  <div class="info">
92
  <h3>代理信息:</h3>
93
  <ul>
94
- <li><strong>SOCKS5 代理地址:</strong> <code>$(hostname):7860</code></li>
95
  <li><strong>目标 WebSocket 代理:</strong> <code>${TARGET_WSPROXY_URL}</code></li>
96
  <li><strong>源自URL:</strong> <code>${TARGET_BASE_URL}</code></li>
97
  </ul>
98
  </div>
99
 
100
  <h3>使用说明</h3>
101
- <p>将您的应用配置为使用此 Space 的地址作为 SOCKS5 代理:</p>
102
  <ul>
103
  <li><strong>主机:</strong> <code>$(hostname)</code> 或 <code>您的Space地址.hf.space</code></li>
104
- <li><strong>端口:</strong> <code>443</code> (或 Hugging Face 分配的端口)</li>
105
- <li><strong>类型:</strong> <code>SOCKS5</code></li>
106
  </ul>
107
 
108
- <p><em>注意: 此页面每30秒自动刷新以显示最新状态</em></p>
109
  <script>
110
  setTimeout(function() {
111
  location.reload();
@@ -115,36 +123,60 @@ cat > /app/html/index.html << EOF
115
  </html>
116
  EOF
117
 
 
 
 
 
 
118
  # 启动 gost 服务
119
  # 默认监听 HTTP 代理 (更兼容 Hugging Face)
120
  echo "Starting gost HTTP proxy..."
121
  gost -L "http://:7860" -F "$TARGET_WSPROXY_URL" &
122
  GOST_PID=$!
 
123
 
124
  # 可选:启用 SOCKS5 代理转发 (需要客户端支持特定隧道)
125
- # 如果要使用 SOCKS5 代理而不是 HTTP,取消下面两行的注释,并注释掉上面的 gost HTTP 命令
126
  # echo "Starting gost SOCKS5 proxy..."
127
  # gost -L "socks5://:7860" -F "$TARGET_WSPROXY_URL" &
128
  # GOST_PID=$!
 
129
 
130
- # 启动一个简单的 HTTP 服务器提供状态页面
131
- cd /app/html
 
132
  python3 -m http.server 7861 &
133
  HTTP_PID=$!
 
134
 
135
- # 检查 gost 是否已经启动
136
- if ! ps -p $GOST_PID > /dev/null; then
137
- echo "Failed to start gost. Exiting..."
 
 
 
 
 
 
138
  exit 1
139
  fi
140
 
 
 
 
 
 
 
141
  echo "Proxy converter is running..."
142
  echo "- HTTP proxy listening internally at port 7860"
143
  echo "- Status page available at port 7861 (web UI)"
144
  echo "- Connected to target WebSocket: $TARGET_WSPROXY_URL"
145
 
146
  # 设置捕获信号
147
- trap "kill $GOST_PID $HTTP_PID; exit" SIGINT SIGTERM
148
 
149
- # 等待 gost 进程结束
150
- wait $GOST_PID
 
 
 
 
39
 
40
  echo "Target WebSocket proxy: $TARGET_WSPROXY_URL"
41
 
42
+ # 创建状态页面目录 (使用 /tmp)
43
+ HTML_DIR="/tmp/html"
44
+ mkdir -p "$HTML_DIR"
45
+ if [ $? -ne 0 ]; then
46
+ echo "Error: Failed to create directory $HTML_DIR"
47
+ exit 1
48
+ fi
49
+
50
+ # 创建状态页面文件 (写入 /tmp/html)
51
+ HTML_FILE="$HTML_DIR/index.html"
52
+ cat > "$HTML_FILE" << EOF
53
  <!DOCTYPE html>
54
  <html>
55
  <head>
 
99
  <div class="info">
100
  <h3>代理信息:</h3>
101
  <ul>
102
+ <li><strong>HTTP 代理监听内部端口:</strong> <code>7860</code></li>
103
  <li><strong>目标 WebSocket 代理:</strong> <code>${TARGET_WSPROXY_URL}</code></li>
104
  <li><strong>源自URL:</strong> <code>${TARGET_BASE_URL}</code></li>
105
  </ul>
106
  </div>
107
 
108
  <h3>使用说明</h3>
109
+ <p>将您的应用配置为使用此 Space 的地址作为 HTTP 代理:</p>
110
  <ul>
111
  <li><strong>主机:</strong> <code>$(hostname)</code> 或 <code>您的Space地址.hf.space</code></li>
112
+ <li><strong>端口:</strong> <code>443</code> (推荐, HTTPS) <code>80</code> (HTTP)</li>
113
+ <li><strong>类型:</strong> <code>HTTP / HTTPS</code></li>
114
  </ul>
115
 
116
+ <p><em>状态页面 (端口 7861) 每30秒自动刷新</em></p>
117
  <script>
118
  setTimeout(function() {
119
  location.reload();
 
123
  </html>
124
  EOF
125
 
126
+ if [ $? -ne 0 ]; then
127
+ echo "Error: Failed to write to $HTML_FILE"
128
+ exit 1
129
+ fi
130
+
131
  # 启动 gost 服务
132
  # 默认监听 HTTP 代理 (更兼容 Hugging Face)
133
  echo "Starting gost HTTP proxy..."
134
  gost -L "http://:7860" -F "$TARGET_WSPROXY_URL" &
135
  GOST_PID=$!
136
+ sleep 1 # 等待 gost 启动
137
 
138
  # 可选:启用 SOCKS5 代理转发 (需要客户端支持特定隧道)
139
+ # 如果要使用 SOCKS5 代理而不是 HTTP,取消下面三行的注释,并注释掉上面的 gost HTTP 命令
140
  # echo "Starting gost SOCKS5 proxy..."
141
  # gost -L "socks5://:7860" -F "$TARGET_WSPROXY_URL" &
142
  # GOST_PID=$!
143
+ # sleep 1
144
 
145
+ # 启动一个简单的 HTTP 服务器提供状态页面 (从 /tmp/html)
146
+ echo "Starting status page server at port 7861..."
147
+ cd "$HTML_DIR"
148
  python3 -m http.server 7861 &
149
  HTTP_PID=$!
150
+ sleep 1 # 等待 http server 启动
151
 
152
+ # 检查 gost 进程是否存在 (使用 kill -0)
153
+ echo "Checking if gost process (PID: $GOST_PID) started..."
154
+ if kill -0 $GOST_PID > /dev/null 2>&1; then
155
+ echo "Gost process is running."
156
+ else
157
+ echo "Error: Failed to start or find gost process (PID: $GOST_PID). Check logs above."
158
+ # 尝试显示最近的日志
159
+ echo "--- Recent gost logs (if any) ---"
160
+ # gost 通常不会自己写日志文件,错误会显示在标准错误流,应该已经被捕获
161
  exit 1
162
  fi
163
 
164
+ # 检查状态页面服务器进程是否存在
165
+ echo "Checking if status page server (PID: $HTTP_PID) started..."
166
+ if ! kill -0 $HTTP_PID > /dev/null 2>&1; then
167
+ echo "Warning: Failed to start or find status page server (PID: $HTTP_PID). Status page might be unavailable."
168
+ fi
169
+
170
  echo "Proxy converter is running..."
171
  echo "- HTTP proxy listening internally at port 7860"
172
  echo "- Status page available at port 7861 (web UI)"
173
  echo "- Connected to target WebSocket: $TARGET_WSPROXY_URL"
174
 
175
  # 设置捕获信号
176
+ trap "echo 'Shutting down...'; kill $GOST_PID $HTTP_PID; exit" SIGINT SIGTERM
177
 
178
+ # 等待 gost 进程结束 (主服务进程)
179
+ wait $GOST_PID
180
+ EXIT_CODE=$?
181
+ echo "Gost process exited with code $EXIT_CODE."
182
+ exit $EXIT_CODE