make it work with and without cgi
parent
dcaf1e7127
commit
8844d48611
|
@ -6,4 +6,6 @@ An example file outlining the format is provided.
|
|||
|
||||
# How to use:
|
||||
|
||||
Put `pyhi.sh` and `pyhp.py` somewhere where your web server can execute them, then configure said web server to execute `.pyh` files using `pyhi.sh`.
|
||||
Put `pyhi-cgi.sh` somewhere where the server will execute it as CGI script with the environment variable `PYHP` set to point to `pyhp.py`. If the environment variable is unset, `pyhi-cgi.sh` will try to find `pyhp.py` in the same directory as it itself is. Then configure the web server to run `.pyh` files using `pyhi-cgi.sh` as a cgi script.
|
||||
|
||||
Alternatively, put `pyhi.sh` and `pyhp.py` somewhere and run `pyhi.sh` with the `.pyh` file as the first argument. Any other command line arguments will be passed to the `.pyh` file. The same `PYHP` environment variable can be used as described above.
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ -z "$PYHP" ]; then
|
||||
PYHP=""$(dirname "$0")"/pyhp.py"
|
||||
fi
|
||||
|
||||
HYPERTEXT=$("$PYHP" "$PATH_TRANSLATED" | python3 -)
|
||||
|
||||
# check for headers, if present assume the pyh file is going to handle them
|
||||
if head -n1 <<< "$HYPERTEXT" | grep "[A-Za-z][A-Za-z0-9\-]*: " > /dev/null 2>&1; then
|
||||
true
|
||||
else
|
||||
echo -ne "Content-type: text/html\\n\\n"
|
||||
fi
|
||||
|
||||
echo "$HYPERTEXT"
|
|
@ -4,13 +4,7 @@ if [ -z "$PYHP" ]; then
|
|||
PYHP=""$(dirname "$0")"/pyhp.py"
|
||||
fi
|
||||
|
||||
HYPERTEXT=$("$PYHP" "$PYH" | python3 - "$PATH_TRANSLATED")
|
||||
PYH="$1"
|
||||
shift
|
||||
|
||||
# check for headers, if present assume the pyh file is going to handle them
|
||||
if head -n1 <<< "$HYPERTEXT" | grep "[A-Za-z][A-Za-z0-9\-]*: "; then
|
||||
true
|
||||
else
|
||||
echo -ne "Content-type: text/html\\n\\n"
|
||||
fi
|
||||
|
||||
echo "$HYPERTEXT"
|
||||
"$PYHP" "$PYH" | python3 - "$@"
|
||||
|
|
Loading…
Reference in New Issue