# along with CGIlite. If not, see <http://www.gnu.org/licenses/>.
# 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(){
)"
}
-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 "$(
)"
}
-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
done
}
-urlsafe(){
+URL(){
# Code every character in URL escape hex format
# except alphanumeric ascii
| 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"
[ $# -ge 3 ] && shift 2 && printf '; %s' "$@"
printf '\r\n'
}
+
+REDIRECT(){
+ printf 'Location: %s\r\n\r\n' "$*"
+ exit 0
+}