Spaces:
Sleeping
Sleeping
fix tunnel_client.sh: remove --no-check-certificate, add rc checks
Browse files12345673945612137892 unmodified lines12131422151617181927202129222324257 unmodified lines333435363738394041424343444544454647474849484950515152535253545555565758596061625657585960616263646566#!/bin/sh
# WebSocket Tunnel Client for OpenWRT# Uses HTTP long-polling to relay requests through Hugging Face Space# Server: https://mtsky-free-server-docker.hf.space# Local CGI: http://192.168.1.1/cgi-bin/api
SERVER="https://mtsky-free-server-docker.hf.space"LOCAL_CGI="http://192.168.1.1/cgi-bin/api"LOCAL_CGI="${LOCAL_CGI:-http://192.168.1.1/cgi-bin/api}"TMPDIR="/tmp/wstunnel"POLL_INTERVAL="${POLL_INTERVAL:-1}"WGET_OPTS="-q -O - --timeout=10 --no-check-certificate"WGET_POST_OPTS="-q -O /dev/null --timeout=10 --no-check-certificate"
mkdir -p "$TMPDIR"
2 unmodified lines}
fetch_poll() { wget $WGET_OPTS "$SERVER/poll" 2>/dev/null wget -q -O - --timeout=10 "$SERVER/poll" 2>&1}
respond() { local rid="$1" status="$2" content_type="$3" file="$4" wget $WGET_POST_OPTS \ wget -q -O /dev/null --timeout=10 \ --post-file="$file" \ "$SERVER/respond?rid=$rid&status=$status&content_type=$content_type" 2>/dev/null "$SERVER/respond?rid=$rid&status=$status&content_type=$content_type" 2>&1}
cleanup() {7 unmodified lineslog "starting wstunnel client"
while true; do resp=$(fetch_poll) fetch_rc=$?
if [ "$fetch_rc" != "0" ] || [ -z "$resp" ]; then [ "$fetch_rc" != "0" ] && log "poll failed (rc=$fetch_rc)" sleep "$POLL_INTERVAL" continue fi if resp=$(fetch_poll); then rid=$(echo "$resp" | sed -n 's/.*"rid":"\([^"]*\)".*/\1/p') url=$(echo "$resp" | sed -n 's/.*"url":"\([^"]*\)".*/\1/p')
rid=$(echo "$resp" | sed -n 's/.*"rid":"\([^"]*\)".*/\1/p') url=$(echo "$resp" | sed -n 's/.*"url":"\([^"]*\)".*/\1/p')
if [ -n "$rid" ] && [ -n "$url" ]; then local_url=$(echo "$url" | sed "s|https://shabakaty\.com|$LOCAL_CGI|") log "request $rid: $url -> $local_url" if [ -n "$rid" ] && [ -n "$url" ]; then local_url=$(echo "$url" | sed "s|https://shabakaty\.com|$LOCAL_CGI|") log "request $rid: $local_url"
body_file="$TMPDIR/body-$rid" wget -q -O "$body_file" --timeout=10 --no-check-certificate "$local_url" 2>/dev/null status=$? body_file="$TMPDIR/body-$rid" wget -q -O "$body_file" --timeout=10 "$local_url" 2>&1 wget_rc=$?
if [ "$status" = "0" ] && [ -s "$body_file" ]; then log "response $rid: success" respond "$rid" "200" "text/html" "$body_file" & else log "response $rid: wget failed ($status)" echo "wget failed" > "$body_file" respond "$rid" "502" "text/plain" "$body_file" & fi if [ "$wget_rc" = "0" ] && [ -s "$body_file" ]; then log "response $rid: success" respond "$rid" "200" "text/html" "$body_file" & else fsize=$(stat -c%s "$body_file" 2>/dev/null || echo 0) log "wget failed (rc=$wget_rc, size=$fsize)" echo "wget failed rc=$wget_rc" > "$body_file" respond "$rid" "502" "text/plain" "$body_file" & fi fi
tunnel_client.sh+29-28