3 # Copyright 2016 Paul Hänsch
5 # This file is part of shcgi.
7 # shcgi is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # shcgi is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with shcgi. If not, see <http://www.gnu.org/licenses/>.
20 if [ "$1" = '--server' ]; then
22 ncat -klc "$call --ncat" $@
26 export REMOTE_ADDR="${NCAT_REMOTE_ADDR}"
27 export SERVER_NAME="${NCAT_LOCAL_ADDR}"
28 export SERVER_PORT="${NCAT_LOCAL_PORT}"
33 /^(GET|HEAD|POST) ([^\?]*)\??(.+)? (HTTP\/[0-9]\.[0-9])\r?$/{
35 s;^(GET|HEAD|POST) ([^\?]*)\??(.+)? (HTTP\/[0-9]\.[0-9])\r?$;export REQUEST_METHOD='\''\1'\'';p
37 s;^(GET|HEAD|POST) ([^\?]*\??.*) (HTTP\/[0-9]\.[0-9])\r?$;\2;
38 s;'\'';'\''\\'\'''\'';g
39 s;^.*$;export REQUEST_URI='\''&'\'';p
41 s;^(GET|HEAD|POST) ([^\?]*)\??(.+)? (HTTP\/[0-9]\.[0-9])\r?$;\2;
42 s;'\'';'\''\\'\'''\'';g
43 s;^.*$;export PATH_INFO='\''&'\'';p
45 s;^(GET|HEAD|POST) ([^\?]*)\??(.+)? (HTTP\/[0-9]\.[0-9])\r?$;\3;
46 s;'\'';'\''\\'\'''\'';g
47 s;^.*$;export QUERY_STRING='\''&'\'';p
49 s;^(GET|HEAD|POST) ([^\?]*)\??(.+)? (HTTP\/[0-9]\.[0-9])\r?$;export SERVER_PROTOCOL='\''\4'\'';p
53 /^[Pp][Rr][Oo][Xx][Yy]: /d
58 s;'\'';'\''\\'\'''\'';g
62 y;abcdefghijklmnopqrstuvwxyz-;ABCDEFGHIJKLMNOPQRSTUVWXYZ_;
63 s;^.+$;export HTTP_&=;
80 aConnection: close\r\n\r
81 /^Status: *[1-5][0-9][0-9] .*/{s;^Status: *;HTTP/1.1 ;; bX}
82 s;^(.+\n)?Location: .*$;HTTP/1.1 302 Found\r\n&;
83 s;^(.+\n)?Content-Type: .*$;HTTP/1.1 200 OK\r\n&;
94 if [ -z "$QUERY_STRING" ]; then
95 PATH_INFO="$(printf "$(printf %s "$PATH_INFO" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")"
96 PATH_INFO="$(invalidate "${PATH_INFO}" '(^|.*/)\.\./.*' '')"
97 [ -f "$_DATA/$PATH_INFO" ] && . "$_EXEC/shcgi/static.sh" "$_DATA/$PATH_INFO"