[ -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
}
timeid(){
- d=$(($(date +%s) % 4294967296))
+ d=$(($_DATE % 4294967296))
{ printf "$(
printf \\%o \
$((d / 16777216 % 256)) \
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}"