X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=cgi.sh;h=e994daa99d2ff50d68eeaab5703c2ec8a01d611d;hb=c5358ed1fda98b17ed9ebda01de44847659fb7ec;hp=3ad0e8b3a9f7c5301122f577bf9e0fc413b55074;hpb=9b62da2cc5552e018fe8c48360c770446a9a6b55;p=shcgi diff --git a/cgi.sh b/cgi.sh index 3ad0e8b..e994daa 100755 --- a/cgi.sh +++ b/cgi.sh @@ -73,10 +73,10 @@ cgi_cookie() { # Parse GET data from referer urlsave(){ printf %s "$*" \ - | sed 's; ;%20;g; + | sed 's;%;%25;g; + s; ;%20;g; s;!;%21;g; s;";%22;g; - s;%;%25;g; s;&;%26;g; s;(;%28;g; s;);%29;g; @@ -86,3 +86,22 @@ urlsave(){ s;'\'';%27;g; s;\?;%3f;g;' } + +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' +}