From: Paul Hänsch Date: Sat, 30 Nov 2019 12:30:49 +0000 (+0100) Subject: allow configuration of session timeout, make timestamp variable reusable X-Git-Url: http://git.plutz.net/?p=cgilite;a=commitdiff_plain;h=f0bc458f738e3171e60424d300b937fdbec2583f allow configuration of session timeout, make timestamp variable reusable --- diff --git a/session.sh b/session.sh index 8ed8d88..ee5c499 100755 --- a/session.sh +++ b/session.sh @@ -3,6 +3,9 @@ [ -n "$include_session" ] && return 0 include_session="$0" +_DATE="$(date +%s)" +SESSION_TIMEOUT="${SESSION_TIMEOUT:-7200}" + server_key(){ IDFILE="${IDFILE:-${_DATA:-.}/serverkey}" if [ "$(stat -c %s "$IDFILE")" -ne 512 ] || ! cat "$IDFILE"; then @@ -27,7 +30,7 @@ randomid(){ } timeid(){ - d=$(($(date +%s) % 4294967296)) + d=$(($_DATE % 4294967296)) { printf "$( printf \\%o \ $((d / 16777216 % 256)) \ @@ -60,17 +63,16 @@ update_session(){ checksig="$(printf %s "$sid" "$time" "$serverkey" | sha256sum)" checksig="${checksig%% *}" - d=$(date +%s) if ! [ "$checksig" = "$sig" \ - -a "$time" -ge "$d" \ + -a "$time" -ge "$_DATE" \ -a "$(printf %s "$sid" |checkid)" ] 2>&- then debug Setting up new session sid="$(randomid)" fi - time=$(( $(date +%s) + 7200 )) + time=$(( $_DATE + $SESSION_TIMEOUT )) sig="$(printf %s "$sid" "$time" "$serverkey" |sha256sum)" sig="${sig%% *}" printf %s\\n "${sid}-${time}-${sig}"