Spaces:
Sleeping
Sleeping
fix tunnel_client.sh: remove --no-check-certificate, add rc checks
Browse files123456789101112131415162 unmodified lines19202122232425262728293031327 unmodified lines4041424344454647484950515253545556575859606162636465#!/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/apiSERVER="https://mtsky-free-server-docker.hf.space"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}respond() {local rid="$1" status="$2" content_type="$3" file="$4"wget $WGET_POST_OPTS \--post-file="$file" \"$SERVER/respond?rid=$rid&status=$status&content_type=$content_type" 2>/dev/null}cleanup() {7 unmodified lineslog "starting wstunnel client"while true; doif resp=$(fetch_poll); thenrid=$(echo "$resp" | sed -n 's/.*"rid":"\([^"]*\)".*/\1/p')url=$(echo "$resp" | sed -n 's/.*"url":"\([^"]*\)".*/\1/p')if [ -n "$rid" ] && [ -n "$url" ]; thenlocal_url=$(echo "$url" | sed "s|https://shabakaty\.com|$LOCAL_CGI|")log "request $rid: $url -> $local_url"body_file="$TMPDIR/body-$rid"wget -q -O "$body_file" --timeout=10 --no-check-certificate "$local_url" 2>/dev/nullstatus=$?if [ "$status" = "0" ] && [ -s "$body_file" ]; thenlog "response $rid: success"respond "$rid" "200" "text/html" "$body_file" &elselog "response $rid: wget failed ($status)"echo "wget failed" > "$body_file"respond "$rid" "502" "text/plain" "$body_file" &fififi1234567892 unmodified lines12131415161718192021222324257 unmodified lines33343536373839404142434445464748495051525354555657585960616263646566#!/bin/shSERVER="https://mtsky-free-server-docker.hf.space"LOCAL_CGI="${LOCAL_CGI:-http://192.168.1.1/cgi-bin/api}"TMPDIR="/tmp/wstunnel"POLL_INTERVAL="${POLL_INTERVAL:-1}"mkdir -p "$TMPDIR"2 unmodified lines}fetch_poll() {wget -q -O - --timeout=10 "$SERVER/poll" 2>&1}respond() {local rid="$1" status="$2" content_type="$3" file="$4"wget -q -O /dev/null --timeout=10 \--post-file="$file" \"$SERVER/respond?rid=$rid&status=$status&content_type=$content_type" 2>&1}cleanup() {7 unmodified lineslog "starting wstunnel client"while true; doresp=$(fetch_poll)fetch_rc=$?if [ "$fetch_rc" != "0" ] || [ -z "$resp" ]; then[ "$fetch_rc" != "0" ] && log "poll failed (rc=$fetch_rc)"sleep "$POLL_INTERVAL"continuefirid=$(echo "$resp" | sed -n 's/.*"rid":"\([^"]*\)".*/\1/p')url=$(echo "$resp" | sed -n 's/.*"url":"\([^"]*\)".*/\1/p')if [ -n "$rid" ] && [ -n "$url" ]; thenlocal_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 "$local_url" 2>&1wget_rc=$?if [ "$wget_rc" = "0" ] && [ -s "$body_file" ]; thenlog "response $rid: success"respond "$rid" "200" "text/html" "$body_file" &elsefsize=$(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" &fifi
tunnel_client.sh+29-28