-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pirds_webcgi.script.obs
executable file
·93 lines (83 loc) · 2.14 KB
/
pirds_webcgi.script.obs
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
82
83
84
85
86
87
88
89
90
91
92
93
#! /bin/bash
#####################
# bash based cig script to generate json data for viewing
#
# Written by Geoff Mulligan @2020
#####################
if [[ $REQUEST_URI == / ]] ;then
echo "Content-type: text/html"
echo "Access-Control-Allow-Origin: *"
echo ""
ls 0Logfile.* | sed 's/0Logfile.//' | while read line ;do
echo "$line -- <a href=/$line>raw</a> / <a href=/$line/json>json</a> / <a href=/breath_plot?i=$line>Breath Plot</a><br>"
done
exit
fi
uri=${REQUEST_URI%\?*}
uri=${uri#*/}
ipaddr=${uri%/*}
json=${uri##*/}
if [[ $json != json && $json != $ipaddr ]] ;then
echo "Content-type: text/plain"
echo "Access-Control-Allow-Origin: *"
echo ""
echo "Bad Request"
fi
if test -s 0Logfile.$ipaddr ;then
:
else
echo "Content-type: text/plain"
echo "Access-Control-Allow-Origin: *"
echo ""
echo "No such record"
exit
fi
if [[ $json == json ]] ;then
echo "Content-type: application/json"
else
echo "Content-type: text/plain"
fi
echo "Access-Control-Allow-Origin: *"
echo ""
nlines=$(cat 0Logfile.$ipaddr | wc -l)
# This is now obsolete...it doesn't support the full PIRDS standard (such as E/M Event/Message types)
if [[ $QUERY_STRING ]] ;then
if [[ $QUERY_STRING =~ "n=" ]] ;then
num=${QUERY_STRING#*n=}
if [[ $json == json ]] ;then
[[ $num -gt 1 && $nlines -gt 1 ]] && echo "["
IFS=:
first=1
tail -n $num 0Logfile.$ipaddr | while read t a b c d e ;do
[[ $first ]] || echo ","
first=""
echo -n "{ \"event\": \"M\", \"type\": \"$a\", \"loc\": \"$b\", \"num\": $c, \"ms\": $d, \"val\": $e }"
done
echo ""
[[ $num -gt 1 && $nlines -gt 1 ]] && echo "]"
else
tail -n $num 0Logfile.$ipaddr | cut -d: -f2-
fi
else
echo bad query
fi
else
if [[ $json == json ]] ;then
[[ $nlines -gt 1 ]] && echo "["
IFS=:
first=1
cat 0Logfile.$ipaddr | while read t a b c d e ;do
[[ $first ]] || echo ","
first=""
echo -n "{ \"event\": \"M\", \"type\": \"$a\", \"loc\": \"$b\", \"num\": $c, \"ms\": $d, \"val\": $e }"
done
echo ""
[[ $nlines -gt 1 ]] && echo "]"
else
cat 0Logfile.$ipaddr | cut -d: -f2-
fi
fi
exit
printenv
echo ----
set