cgi-get.sh 779 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. cd "$(dirname "$0")" || exit
  3. [ "$1" = "" ] && {
  4. cat <<EOF
  5. Run a CGI outside the webserver straight from the terminal.
  6. Example:
  7. \$ sh $0 "apchk.cgi/actor?id=https://example.com/users/alice"
  8. Better would be:
  9. # \$ sh $0 "https://example.com/apchk.cgi/actor?id=https://example.com/users/alice"
  10. EOF
  11. exit
  12. }
  13. pre="$(echo "$1" | cut -d '?' -f 1)"
  14. QUERY_STRING="$(echo "$1" | cut -d '?' -f 2)"
  15. PATH_INFO="/$(echo "$pre" | cut -d '/' -f 2)"
  16. cgi="$(echo "$pre" | cut -d '/' -f 1)"
  17. SCRIPT_NAME="/$cgi"
  18. [ -x "$cgi" ] || {
  19. echo "not executable: $1" 1>&2 ; exit 1
  20. }
  21. export HTTPS="on"
  22. export PATH_INFO
  23. export QUERY_STRING
  24. export REMOTE_ADDR="127.0.0.1"
  25. export REQUEST_METHOD="GET"
  26. export SCRIPT_NAME
  27. export SERVER_NAME="127.0.0.1"
  28. export SERVER_PORT="443"
  29. ./"$cgi"