-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathessstat.cgi
81 lines (72 loc) · 1.85 KB
/
essstat.cgi
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
#
LOGGING_DIR="/var/log/essstat"
#
# Get the QUERY_STRING and arguments
#
OIFS="$IFS" # Save the old internal field separator.
IFS="${IFS}&" # Set the field separator to & and parse the QUERY_STRING at the ampersand.
set $QUERY_STRING
Args="$*"
IFS="$OIFS"
#
# Parse the individual "name=value" tokens from the CGI after we initialize local variables.
#
TPLhost=""
esFrom="`date +\%G`" #default From date as January 1st of this year - only need specify the year
esTo="`date +\%G`z" #default To date as now - only need specify the year and a letter s to make it 'big'
#
for i in $Args ;do
# Set the field separator to =
IFS="${OIFS}="
set $i
IFS="${OIFS}"
case $1 in
# Don't allow "/" changed to " ".
esTPLhost)
TPLhost="`echo $2 | sed 's|[\]||g' | sed 's|%20| |g'`"
;;
# Don't allow "/" changed to " ".
esFrom)
esFrom="`echo $2 | sed 's|[\]||g' | sed 's|%20| |g'`"
;;
esTo)
esTo="`echo $2 | sed 's|[\]||g' | sed 's|%20| |g'`"
;;
# *) echo "<hr>Warning:"\
# "<br>Unrecognized variable \'$1\' passed by FORM in QUERY_STRING.<hr>"
# ;;
esac
done
#
# We'll support a span of the From and To dates across a maximum of two years.
#
esFromY="${esFrom:0:4}"
esToY="${esTo:0:4}"
FilesToProcess="$LOGGING_DIR/essstat-$TPLhost-$esToY.csv"
if [ "$esFromY" != "$esToY" ]
then
f2="$LOGGING_DIR/essstat-$TPLhost-$esFromY.csv"
if test -f "$f2"
then
FilesToProcess="$f2 $FilesToProcess"
fi
fi
#
# Basic parameter check - return 400 status if a problem, otherwise try to return data
#
#logger -i $FilesToProcess
#logger -i "esFrom=$esFrom"
#logger -i "esTo=$esTo"
#
if [ "$TPLhost" == "" ]
then
echo "Status: 400 Bad Request"
echo ""
echo "Bad parameters"
echo ""
else
echo "Content-type: text/plain"
echo ""
awk -F "," -v esFrom="$esFrom" -v esTo="$esTo"-- "(\$1 >= esFrom) && (\$1 <= esTo) {print \$0}" $FilesToProcess
fi