From: Paul Hänsch Date: Sun, 18 Nov 2018 20:59:01 +0000 (+0100) Subject: various refinements in new modules X-Git-Url: http://git.plutz.net/?p=cgilite;a=commitdiff_plain;h=3fe2a9ceb477adf245f6cc8f72fb61282e42c904 various refinements in new modules --- diff --git a/logging.sh b/logging.sh index f10ea4c..31bb24d 100755 --- a/logging.sh +++ b/logging.sh @@ -12,14 +12,17 @@ LOGLEVEL="${LOGLEVEL:-3}" LOGFILE="${LOGFILE:-/dev/stderr}" logmsg(){ - if [ "${1:-3}" -le "$LOGLEVEL" ]; then - [ "$#" -gt 1 ] \ - && printf %s\\n "$*" >>"${LOGFILE}" \ - || tee -a "${LOGFILE}" + local ll="${1:-3}" + shift 1 + if [ "$ll" -le "$LOGLEVEL" -a "$#" -gt 0 ]; then + printf %s\\n "$*" >>"${LOGFILE}" + elif [ "$ll" -le "$LOGLEVEL" ]; then + tee -a "${LOGFILE}" + elif [ ! "$#" -gt 0 ]; then + cat fi } - die(){ [ "$#" -gt 0 ] && logmsg 1 "$@" exit 1 diff --git a/session.sh b/session.sh index 3f3839a..60ae577 100755 --- a/session.sh +++ b/session.sh @@ -5,7 +5,7 @@ include_session="$0" server_key(){ IDFILE="${IDFILE:-${_DATA:-.}/serverkey}" - if ! grep -m1 -xE '.{512}' "$IDFILE"; then + if [ "$(stat -c %s "$IDFILE")" -ne 512 ] || ! cat "$IDFILE"; then dd count=1 bs=512 if=/dev/urandom \ | tee "$IDFILE" fi 2>&- @@ -22,8 +22,8 @@ slopecode(){ } randomid(){ - dd bs=12 count=1 if=/dev/urandom \ - | slopecode 2>&- + dd bs=12 count=1 if=/dev/urandom 2>&- \ + | slopecode } timeid(){ @@ -35,8 +35,8 @@ timeid(){ $((d / 256 % 256)) \ $((d % 256)) )" - dd bs=8 count=1 if=/dev/urandom - } | slopecode 2>&- + dd bs=8 count=1 if=/dev/urandom 2>&- + } | slopecode } checkid(){ grep -m 1 -xE '[0-9a-zA-Z:_]{16}'; } @@ -53,7 +53,11 @@ update_session(){ checksig="${checksig%% *}" d=$(date +%s) - if [ "$checksig" != "$sig" -o "$time" -lt "$d" ] 2>&-; then + if [ "$checksig" != "$sig" \ + -o "$time" -lt "$d" \ + -o ! "$(printf %s "$sid" |checkid)" ] 2>&- + then + debug Setting up new session sid="$(randomid)" fi @@ -64,5 +68,5 @@ update_session(){ } SESSION_ID="$(update_session)" -SET_COOKIE 0 "session=$SESSION_ID" HttpOnly +SET_COOKIE 0 session="$SESSION_ID" Path=/ SameSite=Strict HttpOnly SESSION_ID="${SESSION_ID%%-*}"