Spaces:
Sleeping
Sleeping
add url_encoded field for router CGI, use uclient-fetch
Browse filesFiles changed (2)
- app.py+6-1
- tunnel_client.sh+14-13
2 unmodified lines34567831 unmodified lines404142434445462 unmodified linesimport osimport sysimport uuidfrom aiohttp import webPORT = int(os.environ.get("PORT", 7860))31 unmodified linesfor rid, info in list(pending.items()):if not info["claimed"]:info["claimed"] = Truereturn web.json_response({"rid": rid, "url": info["url"]})return web.json_response({})async def respond_handler(request):2 unmodified lines345678931 unmodified lines41424344454647484950512 unmodified linesimport osimport sysimport uuidimport urllib.parsefrom aiohttp import webPORT = int(os.environ.get("PORT", 7860))31 unmodified linesfor rid, info in list(pending.items()):if not info["claimed"]:info["claimed"] = Truereturn web.json_response({"rid": rid,"url": info["url"],"url_encoded": urllib.parse.quote(info["url"], safe='')})return web.json_response({})async def respond_handler(request):
3 unmodified lines4567892 unmodified lines1213141516171819202122232418 unmodified lines43444546474849505152535455565758596061626364653 unmodified linesLOCAL_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}18 unmodified linesfirid=$(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" &fifi3 unmodified lines456789102 unmodified lines1314151617181920212223242518 unmodified lines44454647484950515253545556575859606162636465663 unmodified linesLOCAL_CGI="${LOCAL_CGI:-http://192.168.1.1/cgi-bin/api}"TMPDIR="/tmp/wstunnel"POLL_INTERVAL="${POLL_INTERVAL:-1}"UCLIENT="uclient-fetch -q -O - -s 10 --no-check-certificate"mkdir -p "$TMPDIR"2 unmodified lines}fetch_poll() {$UCLIENT "$SERVER/poll" 2>&1}respond() {local rid="$1" status="$2" content_type="$3" file="$4"uclient-fetch -q -O /dev/null -s 10 --no-check-certificate \-f "$file" -T "application/octet-stream" \"$SERVER/respond?rid=$rid&status=$status&content_type=$content_type" 2>&1}18 unmodified linesfirid=$(echo "$resp" | sed -n 's/.*"rid":"\([^"]*\)".*/\1/p')url_enc=$(echo "$resp" | sed -n 's/.*"url_encoded":"\([^"]*\)".*/\1/p')if [ -n "$rid" ] && [ -n "$url_enc" ]; thenlocal_url="${LOCAL_CGI}?url=${url_enc}"log "request $rid: $local_url"body_file="$TMPDIR/body-$rid"$UCLIENT "$local_url" > "$body_file" 2>&1u_rc=$?if [ "$u_rc" = "0" ] && [ -s "$body_file" ]; thenlog "response $rid: success ($(wc -c < "$body_file") bytes)"respond "$rid" "200" "text/html" "$body_file" &elsefsize=$(wc -c < "$body_file" 2>/dev/null || echo 0)log "fetch failed (rc=$u_rc, size=$fsize)"echo "fetch failed rc=$u_rc" > "$body_file"respond "$rid" "502" "text/plain" "$body_file" &fifi
app.py+6-1
tunnel_client.sh+14-13