From: paul Date: Wed, 24 Feb 2016 20:15:37 +0000 (+0000) Subject: parse get and post data automatically X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=2030c27378891fc2d26091303269f7b9c228611b;p=shcgi parse get and post data automatically svn path=/trunk/; revision=20 --- diff --git a/cgi.sh b/cgi.sh index 4f4cb50..124496e 100755 --- a/cgi.sh +++ b/cgi.sh @@ -24,17 +24,17 @@ declare -A _COOKIE [ -z "$HTTP_REFERER" ] && HTTP_REFERER="./" -cgi_get() { # parse HTTP GET string - debug "== CGI DATA: GET ==" - printf '%s\n' "$QUERY_STRING" |tr '&' '\n' |while read query; do - key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\1:')" - val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\2:')" - _GET[$key]="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")" - debug "_GET[$key] => $val" - done -} +# parse HTTP GET string +debug "== CGI DATA: GET ==" +printf '%s\n' "$QUERY_STRING" |tr '&' '\n' |while read query; do + key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\1:')" + val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\2:')" + _GET[$key]="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")" + debug "_GET[$key] => $val" +done -cgi_post() { # parse HTTP POST string +if [ "$REQUEST_METHOD" = POST ]; then + # parse HTTP POST string debug "== CGI DATA: POST ==" sed -u 1q |tr '&' '\n' |while read query; do key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\1:')" @@ -48,11 +48,11 @@ cgi_post() { # parse HTTP POST string _POST[$key$n]="$value" debug "_POST[$key$n] => $value" done -} +fi cgi_refdata() { # Parse GET data from referer debug "== CGI DATA: REFERER ==" - printf '%s\n' "$HTTP_REFERER" |cut -d'?' -f2- |tr '&' '\n' |while read query; do + printf '%s\n' "${HTTP_REFERER#*\?}" |tr '&' '\n' |while read query; do key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\1:')" val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\2:')" _REF[$key]="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")" diff --git a/index.cgi b/index.cgi index 6107345..b406bc9 100755 --- a/index.cgi +++ b/index.cgi @@ -34,7 +34,6 @@ _EXEC="${real%/shcgi/index.cgi}" #execution directory [ -r "$_DATA/local.opts" ] && . "$_DATA/local.opts" . "$_EXEC/shcgi/cgi.sh" -cgi_get [ -x "$_EXEC/globals.sh" ] && . "$_EXEC/globals.sh"