From 3f386cf5f3cfa703464cdb8b3eca823ed1f2acc6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 26 Nov 2013 19:08:35 +0100 Subject: [rfs-stage32] Add 'slxlog', a utility for remote logging --- .../rootfs-stage32/data/opt/openslx/bin/slxlog | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog (limited to 'remote') diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog new file mode 100755 index 00000000..4df68cc0 --- /dev/null +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog @@ -0,0 +1,53 @@ +#!/opt/openslx/bin/ash + +################## +# Remote logging # +################## + +. /opt/openslx/config +[ -z "$SLX_REMOTE_LOG" ] && exit 3 + +LOGCHECK="/tmp/remote_log_check" +NOW=$(date +%s) + +[ $# -eq 0 ] && exit 0 + +TYPE="$1" + +# Simple spamcheck. Not very tamper-proof, but if you'd want to spam the server +# you could do it anyways. This is to protect from accidental loops calling this. +if [ -r "$LOGCHECK" ]; then + # Allow max 500 messages in total + LINES=$(cat "$LOGCHECK" | wc -l) + [ "$LINES" -gt 500 ] && exit 1 + # Allow max 5 of same type messages in 30 seconds + LAST=$(grep "$TYPE" "$LOGCHECK" | tail -n 5 | head -n 1 | awk '{print $1}') + if [ -n "$LAST" ]; then + DIFF="$[ $NOW - $LAST ]" + [ "$DIFF" -lt "30" ] && exit 2 + fi +fi +echo "$NOW $TYPE" >> "$LOGCHECK" +chmod 0666 "$LOGCHECK" + +if [ $# -lt 2 ]; then + MSG="Missing text for $@" +else + MSG="$2" +fi +MSG="[$(whoami)] $MSG" + +if [ $# -gt 2 ]; then + EXTRA="$3" +fi + +if [ -r "$EXTRA" ]; then + curl --data-urlencode "type=$TYPE" --data-urlencode "description=$MSG" --data-urlencode "longdesc@$EXTRA" "$SLX_REMOTE_LOG" > /dev/null 2>&1 +elif [ -n "$EXTRA" ]; then + curl --data-urlencode "type=$TYPE" --data-urlencode "description=$MSG" --data-urlencode "longdesc=Missing $EXTRA" "$SLX_REMOTE_LOG" > /dev/null 2>&1 +else + curl --data-urlencode "type=$TYPE" --data-urlencode "description=$MSG" "$SLX_REMOTE_LOG" > /dev/null 2>&1 +fi + +exit 0 + -- cgit v1.2.3-55-g7522