X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=cgi.sh;h=439773015f82e103c2459e32b5059faa8e401205;hb=daa2cb2e7deb218330a74e609642830de221bbf5;hp=d9ee5bd012ed8b3780a4ed78ae75c8f82dda0d0a;hpb=d7ba9fdbc590932d2f59be6534ca1c5738fe2085;p=shcgi diff --git a/cgi.sh b/cgi.sh index d9ee5bd..4397730 100755 --- a/cgi.sh +++ b/cgi.sh @@ -40,14 +40,13 @@ cgi_post() { # parse HTTP POST string key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\1:')" val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]+)=(.*)$:\2:')" value="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g;')")" - if [ -n "${_POST[$key]}" ]; then + n='' + if [ -n "${_POST[$key$n]}" ]; then n=0 while [ -n "${_POST[$key$n]}" ]; do n=$(($n + 1)); done - _POST[$key$n]="$value" - else - _POST[$key]="$value" fi - debug "_POST[$key] => $value" + _POST[$key$n]="$value" + debug "_POST[$key$n] => $value" done } @@ -91,3 +90,17 @@ redirect(){ printf '%s\n\n' "Location: $*" exit 0 } + +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>&-)";; + esac + cookie="$2" + + printf 'Set-Cookie: %s' "$cookie" + [ -n "$expire" ] && printf '; Expires=%s' "$expire" + [ $# -ge 3 ] && shift 2 && printf '; %s' "$@" + printf '\n' +}