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 lines345678931 unmodified lines4142434344454647484950512 unmodified linesimport osimport sysimport uuidimport urllib.parsefrom aiohttp import web
PORT = int(os.environ.get("PORT", 7860))31 unmodified lines for rid, info in list(pending.items()): if not info["claimed"]: info["claimed"] = True return web.json_response({"rid": rid, "url": info["url"]}) return 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 lines456789102 unmodified lines1314151516171819202021212223242518 unmodified lines4445464647484849495051525353545455565657575859606061626162636465663 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() { wget -q -O - --timeout=10 "$SERVER/poll" 2>&1 $UCLIENT "$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" \ 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 lines fi
rid=$(echo "$resp" | sed -n 's/.*"rid":"\([^"]*\)".*/\1/p') url=$(echo "$resp" | sed -n 's/.*"url":"\([^"]*\)".*/\1/p') url_enc=$(echo "$resp" | sed -n 's/.*"url_encoded":"\([^"]*\)".*/\1/p')
if [ -n "$rid" ] && [ -n "$url" ]; then local_url=$(echo "$url" | sed "s|https://shabakaty\.com|$LOCAL_CGI|") if [ -n "$rid" ] && [ -n "$url_enc" ]; then local_url="${LOCAL_CGI}?url=${url_enc}" log "request $rid: $local_url"
body_file="$TMPDIR/body-$rid" wget -q -O "$body_file" --timeout=10 "$local_url" 2>&1 wget_rc=$? $UCLIENT "$local_url" > "$body_file" 2>&1 u_rc=$?
if [ "$wget_rc" = "0" ] && [ -s "$body_file" ]; then log "response $rid: success" if [ "$u_rc" = "0" ] && [ -s "$body_file" ]; then log "response $rid: success ($(wc -c < "$body_file") bytes)" 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" fsize=$(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" & fi fiapp.py+6-1
tunnel_client.sh+14-13