-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ruptimed
executable file
·65 lines (59 loc) · 2.11 KB
/
ruptimed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
#source
if [ -f /etc/ruptime/ruptime.conf ]; then
. /etc/ruptime/ruptime.conf
else
defaults read ch.aiei.ruptime 2>/dev/null >/dev/null
if [ ! $? = 0 ]; then
echo "NO CONFIG FOUND in /etc/ruptime/ruptime.conf nor defaults"; exit 1
else
#echo "FOUND defaults";
SERVER=$(defaults read ch.aiei.ruptime SERVER)
PORT=$(defaults read ch.aiei.ruptime PORT)
HOSTNAMECMD=$(defaults read ch.aiei.ruptime HOSTNAMECMD)
SPOOL=$(defaults read ch.aiei.ruptime SPOOL)
fi
fi
if [ -f /etc/ruptime/ruptime.key ]; then
export KEY=$(cat /etc/ruptime/ruptime.key)
else
defaults read ch.aiei.ruptime 2>/dev/null >/dev/null
if [ ! $? = 0 ]; then
echo "NO KEY FOUND in /etc/ruptime/ruptime.key"; exit 1
else
#echo "FOUND defaults";
export KEY=$(defaults read ch.aiei.ruptime KEY)
fi
fi
f=$(getpeername)
if [ ! ${ACL}x = x ]; then
echo $f |grep ${ACL}$ >/dev/null
if [ ! $? = 0 ]; then
#echo Not allowed
echo "$f" >> $SPOOL/unauthorized
exit 0
fi
fi
#echo STARTED > $SPOOL/.started
read CMD ARG
h=$(echo $f| awk '{print $1}')
if [ "${ARG}x" = "x" ]; then
# only query command, deliver results asked for
if [ "$CMD" = "xz.ruptime" ]; then
(
find $SPOOL/ -type f -name "*.ruptime" -mmin +10 -exec cat {} \; |sed "s,up.*,down,g" |while read a b; do printf "%-28s %s %9s\n" $a $b $(TIME_STYLE=+%s ls -l $SPOOL/${a}.ruptime|awk -vNOW=$(date +%s) '{print ((NOW-$(6))/60) }'); done;
find $SPOOL/ -type f -name "*.ruptime" -mmin -10 -exec cat {} \; |sort) | xz -c | openssl enc -A -a -aes-192-cbc -pbkdf2 -pass env:KEY -in - -out -
fi
for a in runame rload rnet rsw rboot rbench rhw rdisk rac rwho; do
if [ "$CMD" = "xz.$a" ]; then
(find $SPOOL/ -name "*.$a" -exec cat {} \; |sort) | xz -c | openssl enc -A -a -aes-192-cbc -pbkdf2 -pass env:KEY -in - -out -
fi
done
else
# update/add entry
for a in ruptime runame rload rnet rsw rboot rbench rhw rdisk rac rwho; do
if [ "$CMD" = "$a" ]; then
echo "$ARG" | openssl enc -d -A -a -aes-192-cbc -pbkdf2 -pass env:KEY -in - -out - > "$SPOOL/${h}.${CMD}"
fi
done
fi