-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.cgi
128 lines (88 loc) · 3.2 KB
/
action.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/sh
LOGFILE=/www/modules/schoolbell/log.txt
# Âåäåíèå æóðíàëà.
loginfo () {
lcnt=$(wc -l $LOGFILE | cut -f1 -d' ')
# Îãðàíè÷èâàåì ðàçìåð ôàéëà æóðíàëà ïî êîëè÷åñòâó ñòðîê.
if [ $lcnt -gt 100 ] ; then
start=`expr $lcnt - 50`
tail +$start $LOGFILE > /tmp/log.txt
mv /tmp/log.txt $LOGFILE
fi
echo "`date +"%Y.%m.%d %H:%M:%S [INFO]"` $1" >> $LOGFILE
}
echo "Content-type: text/html; charset=utf-8"
echo
if [ "$REQUEST_METHOD" = POST ]; then
read -n $CONTENT_LENGTH query
loginfo "POST $query"
elif [ "$REQUEST_METHOD" = GET ]; then
query=$(echo "$QUERY_STRING")
loginfo "GET $query"
else
exit 0
fi
# Ðàçáîð çàïðîñà.
if [ -n "$query" ]; then
# Äåêîäèðîâàíèå çàïðîñà.
query=$(echo "$query" | echo -e $(sed 's/+/ /g; s/%/\\x/g'))
# Ïðîâåðêà òèïà äåéñòâèÿ.
action=$(echo "$query" | sed -n 's/^.*action=\([^&]*\).*$/\1/p')
case "$action" in
# Ñîñòîÿíèå.
"state")
if ps | grep -v grep | grep cron &> /dev/null ; then
echo "1"
else
echo "0"
fi
;;
# Îñòàíîâêà ïëàíèðîâùèêà.
"stop")
/etc/init.d/cron stop
sleep 1
;;
# Çàïóñê ïëàíèðîâùèêà.
"start") `/www/cgi-bin/modules/schoolbell/scheduler.cgi` ;;
# Çàïðîñ äàòû.
# `date +\"%d.%m.%Y\"` Âðåìÿ: `date +\"%H:%M:%S\"`
"getdate") echo "`date`" ;;
# Ñèíõðîíèçàöèÿ âðåìåíè.
"setdate")
value=$(echo "$query" | sed -n 's/^.*value=\([^&]*\).*$/\1/p')
`date $value`
;;
# Òåñòèðîâàíèå çâóêîâîãî êàíàëà.
"test") `madplay /www/modules/schoolbell/test.mp3` ;;
# ×òåíèå ñïèñêà ìåëîäèé.
"loadmelodies") echo `cat /www/modules/schoolbell/melodies.json`;;
# Ñîõðàíåíèå íàñòðîåê.
"savesettings")
data=$(echo "$query" | sed -n 's/^.*data=\([^&]*\).*$/\1/p')
echo "$data" > /www/modules/schoolbell/settings.json
loginfo $data
;;
# ×òåíèå íàñòðîåê.
"loadsettings") echo `cat /www/modules/schoolbell/settings.json`;;
# Ñîõðàíåíèå ïëàíà.
"saveplan")
data=$(echo "$query" | sed -n 's/^.*data=\([^&]*\).*$/\1/p')
echo "$data" > /www/modules/schoolbell/plan.json
loginfo $data
;;
# ×òåíèå ïëàíà.
"loadplan") echo `cat /www/modules/schoolbell/plan.json`;;
# Ñîõðàíåíèå òåêóùåãî ðàñïèñàíèÿ.
"saveschedules")
data=$(echo "$query" | sed -n 's/^.*data=\([^&]*\).*$/\1/p')
echo "$data" > /www/modules/schoolbell/schedules.json
loginfo $data
;;
# ×òåíèå ðàñïèñàíèé.
"loadschedules") echo `cat /www/modules/schoolbell/schedules.json`;;
# Ñèñòåìíûé æóðíàë.
"logread") echo `logread | sed ':a;N;$!ba;s/\n/\r/g'` ;;
# Îòëàäêà.
"debuglog") echo `cat $LOGFILE | sed ':a;N;$!ba;s/\n/\r/g'` ;;
esac
fi