From: paul Date: Tue, 16 May 2017 09:44:38 +0000 (+0000) Subject: posix collection of cgi functions, additional functions X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=498d677f03d075567beeba90707d5b9c3b5a61fc;p=clickslide posix collection of cgi functions, additional functions svn path=/trunk/; revision=55 --- diff --git a/cgilite.sh b/cgilite.sh index 8a2ee57..c00f9e7 100755 --- a/cgilite.sh +++ b/cgilite.sh @@ -19,22 +19,21 @@ # along with CGIlite. If not, see . # ksh and zsh workaround -set -o posix -o OCTAL_ZEROES 2>&- +# set -o posix # ksh, not portable +setopt -o OCTAL_ZEROES 2>&- if [ "$REQUEST_METHOD" = POST -a "${HTTP_CONTENT_LENGTH:=${CONTENT_LENGTH:=0}}" -gt 0 ]; then cgilite_post="$(head -c "$HTTP_CONTENT_LENGTH")" fi cgilite_count(){ - printf "$( - case $1 in - GET) printf %s "${QUERY_STRING}";; - POST) printf %s "?${cgilite_post}";; - REF) printf %s "?${HTTP_REFERER#*\?}";; - esac \ - | grep -Eo '[&?]'"$2"'=[^&]*' \ - | wc -l - )" + case $1 in + GET) printf %s "${QUERY_STRING}";; + POST) printf %s "?${cgilite_post}";; + REF) printf %s "?${HTTP_REFERER#*\?}";; + esac \ + | grep -Eo '[&?]'"$2"'=[^&]*' \ + | wc -l } cgilite_value(){ @@ -49,26 +48,14 @@ cgilite_value(){ )" } -GET(){ - cgilite_value GET $@ -} -GET_no(){ - cgilite_count GET $1 -} +GET(){ cgilite_value GET $@; } +GET_COUNT(){ cgilite_count GET $1; } -POST(){ - cgilite_value POST $@ -} -POST_no(){ - cgilite_count POST $1 -} +POST(){ cgilite_value POST $@; } +POST_COUNT(){ cgilite_count POST $1; } -REF(){ - cgilite_value REF $@ -} -REF_no(){ - cgilite_count REF $1 -} +REF(){ cgilite_value REF $@; } +REF_COUNT(){ cgilite_count REF $1; } COOKIE(){ printf "$( @@ -78,7 +65,7 @@ COOKIE(){ )" } -HTMLEC(){ +HTML(){ # HTML Entity Coding # Prints UTF-8 string as decimal Unicode Code Points # Useful for escaping user input for use in HTML text and attributes @@ -100,7 +87,7 @@ HTMLEC(){ done } -urlsafe(){ +URL(){ # Code every character in URL escape hex format # except alphanumeric ascii @@ -109,16 +96,11 @@ urlsafe(){ | tr , % } -redirect(){ - printf '%s\r\n\r\n' "Location: $(urlsafe $*)" - exit 0 -} - -set_cookie(){ +SET_COOKIE(){ case "$1" in - session|0) expire='';; - ''|default) expire="$(LANG=C date -d "+ 1 week" +'%a, %d %b %Y %T %Z')";; - *) expire="$(LANG=C date -d "$1" +'%a, %d %b %Y %T %Z' 2>&-)";; + ''|0|session) expire='';; + [+-][0-9]*) expire="$(date -R -d @$(($(date +%s) + $1)))";; + *) expire="$(date -R -d "$1")";; esac cookie="$2" @@ -127,3 +109,8 @@ set_cookie(){ [ $# -ge 3 ] && shift 2 && printf '; %s' "$@" printf '\r\n' } + +REDIRECT(){ + printf 'Location: %s\r\n\r\n' "$*" + exit 0 +}