bd77e61089d827a0da9a1b026e9fc586b47e6dd6
[svn42.git] / powersensordaemon / switch.cgi
1 #!/bin/sh
2
3 for QUERY in `echo $QUERY_STRING | tr '&' ' '`; do
4   for VALUE in `echo $QUERY | tr '=' ' '`; do
5     if [ "$VALUE" == "id" ]; then
6       ID='?'
7     elif [ "$ID" == "?" ]; then
8       ID=$VALUE
9     elif [ "$VALUE" == "power" ]; then
10       POWER='?'
11     elif [ "$POWER" == "?" ]; then
12       POWER=$VALUE
13     elif [ "$VALUE" == "mobile" ]; then
14       MOBILE='1'
15     elif [ "$POWER" == "?" ]; then
16       POWER=$VALUE
17     elif [ "$VALUE" == "ajax" ]; then
18       AJAX='?'
19     elif [ "$AJAX" == "?" ]; then
20       AJAX=$VALUE
21     fi
22     i=$i+1
23   done
24 done
25
26 UNIXSOCK=/var/run/powersensordaemon/cmd.sock
27 VALID_ONOFF_IDS="decke ambientlights lichter all werkzeug labor dart logo spots1 deckehinten deckevorne boiler whiteboard pcblueleds bikewcblue"
28 VALID_SEND_IDS_CUSTOM_DISPLAY="ymhpoweroff ymhpower ymhvolup ymhvoldown"
29 VALID_SEND_IDS="ymhpoweron ymhcd ymhwdtv ymhtuner ymhaux ymhsattv ymhvolmute ymhmenu ymhplus ymhminus ymhtest ymhtimelevel ymheffect ymhprgup ymhprgdown ymhtunplus ymhtunminus ymhtunabcde ymhtape ymhvcr ymhextdec ymhsleep ymhp5 panicled blueled moviemode"
30 #VALID_BANSHEE_IDS="playPause next prev"
31 #VALID_CAM_MOTOR_IDS="c C w W"
32
33 [ "$POWER" == "Off" ] && POWER=off
34 [ "$POWER" != "off" ] && POWER=on
35 if [ "$POWER" == "on" -o "$POWER" == "off" ]; then
36   for CHECKID in $VALID_ONOFF_IDS $VALID_SEND_IDS; do 
37     if [ "$CHECKID" == "$ID" ]; then
38       echo "power $POWER $ID" | usocket $UNIXSOCK
39       echo "Content-type: text/html"
40       echo ""
41       echo "<html>"
42       echo "<head>"
43       echo "<title>Realraum rf433ctl</title>"
44       echo '<script type="text/javascript">window.location="http://slug.realraum.at/cgi-bin/switch.cgi";</script>'
45       echo "</head></html>"
46       exit 0
47     fi
48   done
49
50   for CHECKID in $VALID_BANSHEE_IDS; do
51     if [ "$CHECKID" == "$ID" ]; then
52       echo "$ID/" | nc wuerfel.realraum.at 8484
53       echo "Content-type: text/html"
54       echo ""
55       echo "<html>"
56       echo "<head>"
57       echo "<title>Realraum rf433ctl</title>"
58       echo '<script type="text/javascript">window.location="http://slug.realraum.at/cgi-bin/switch.cgi";</script>'
59       echo "</head></html>"
60       exit 0
61     fi
62   done
63
64   for CHECKID in $VALID_CAM_MOTOR_IDS; do
65     if [ "$CHECKID" == "$ID" ]; then
66       echo "$ID" > /dev/ttyACM0
67       echo "Content-type: text/html"
68       echo ""
69       echo "<html>"
70       echo "<head>"
71       echo "<title>Realraum rf433ctl</title>"
72       echo '<script type="text/javascript">window.location="http://slug.realraum.at/cgi-bin/switch.cgi";</script>'
73       echo "</head></html>"
74       exit 0
75     fi
76   done
77 fi
78
79 DESC_pcblueleds="Blaue Leds PC"
80 DESC_bikewcblue="Blaue Lichterkette WC"
81 DESC_weissB="WeissB"
82 DESC_werkzeug="Werkzeug LEDs"
83 DESC_stereo="Receiver On/Off"
84 DESC_ambientlights="Ambient Lichter"
85 DESC_labor="Labor Licht"
86 DESC_boiler="Warmwasser WC"
87 DESC_dart="Dart Scheibe"
88 DESC_logo="Logo"
89 DESC_spots1="Spots"
90 DESC_deckehinten="Decke Hinten"
91 DESC_deckevorne="Decke Vorne"
92 DESC_whiteboard="Whiteboard Vorne"
93 DESC_decke="Deckenlichter"
94 DESC_lichter="Alle Lichter"
95 DESC_all="Alles"
96 DESC_ymhpoweron="Receiver On (off+tgl)"
97 DESC_ymhpoweroff="Receiver Off"
98 DESC_ymhpower="Receiver On/Off"
99 DESC_ymhvolup="VolumeUp"
100 DESC_ymhvoldown="VolumeDown"
101 DESC_ymhcd="Input CD"
102 DESC_ymhwdtv="Input S/PDIF Wuerfel"
103 DESC_ymhtuner="Input Tuner"
104 DESC_ymhvolmute="Mute"
105 DESC_ymhmenu="Menu"
106 DESC_ymhplus="+"
107 DESC_ymhminus="-"
108 DESC_ymhtest="Test"
109 DESC_ymhtimelevel="Time/Levels"
110 DESC_ymheffect="DSP Effect Toggle"
111 DESC_ymhprgup="DSP Up"
112 DESC_ymhprgdown="DSP Down"
113 DESC_ymhtunplus="Tuner +"
114 DESC_ymhtunminus="Tuner -"
115 DESC_ymhtunabcde="Tuner ABCDE"
116 DESC_ymhtape="Tape"
117 DESC_ymhvcr="VCR"
118 DESC_ymhextdec="ExtDec Toggle"
119 DESC_seep="Sleep Modus"
120 DESC_panicled="HAL9000 says hi"
121 DESC_blueled="Blue Led"
122 DESC_moviemode="Movie Mode"
123 DESC_w="Cam >"
124 DESC_W="Cam >>"
125 DESC_c="Cam <"
126 DESC_C="Cam <<"
127
128 echo "Content-type: text/html"
129 echo ""
130 echo "<html>"
131 echo "<head>"
132 echo "<title>Realraum rf433ctl</title>"
133 echo '<script type="text/javascript">'
134 echo 'function sendButton( onoff, btn )'
135 echo '{'
136 echo ' var req = new XMLHttpRequest();'
137 echo ' url = "http://slug.realraum.at/cgi-bin/switch.cgi?power="+onoff+"&id="+btn;'
138 echo ' req.open("GET", url ,false);'
139 echo ' //google chrome workaround'
140 echo ' req.setRequestHeader("googlechromefix","");'
141 echo ' req.send(null);'
142 echo '}'
143 echo '</script>'
144 echo '<style>'
145 echo 'div.switchbox {'
146 echo '    float:left;'
147 echo '    margin:2px;'
148 #echo '    max-width:236px;'
149 echo '    max-width:300px;'
150 echo '    font-size:10pt;'
151 echo '    border:1px solid black;'
152 #echo '    height: 32px;'
153 echo '    padding:0;'
154 echo '}'
155   
156 echo 'div.switchnameleft {'
157 echo '    width:12em; display:inline-block; vertical-align:middle; margin-left:3px;'
158 echo '}'
159
160 echo 'span.alignbuttonsright {'
161 echo '    top:0px; float:right; display:inline-block; text-align:right; padding:0;'
162 echo '}'
163
164 echo 'div.switchnameright {'
165 echo '    width:12em; display:inline-block; vertical-align:middle; float:right; display:inline-block; margin-left:1ex; margin-right:3px; margin-top:3px; margin-bottom:3px;'
166 echo '}'
167
168 echo 'span.alignbuttonsleft {'
169 echo '    float:left; text-align:left; padding:0;'
170 echo '}'
171
172 echo '.onbutton {'
173 echo '    font-size:11pt;'
174 echo '    width: 40px;'
175 echo '    height: 32px;'
176 echo '    background-color: lime;'
177 echo '    margin: 0px;'
178 echo '}'
179
180 echo '.offbutton {'
181 echo '    font-size:11pt;'
182 echo '    width: 40px;'
183 echo '    height: 32px;'
184 echo '    background-color: red;'
185 echo '    margin: 0px;'
186 echo '}'
187
188 echo '.sendbutton {'
189 echo '    font-size:11pt;'
190 echo '    width: 40px;'
191 echo '    height: 32px;'
192 #echo '    background-color: grey;'
193 echo '    margin: 0px;'
194 echo '}'
195 echo '</style>'
196 echo "</head>"
197 echo "<body>"
198 #echo "<h1>Realraum rf433ctl</h1>"
199 echo "<div style=\"float:left; border:1px solid black;\">"
200 for DISPID in $VALID_ONOFF_IDS; do
201   NAME="$(eval echo \$DESC_$DISPID)"
202   [ -z "$NAME" ] && NAME=$DISPID
203   if [ -z "$AJAX" ]; then
204
205   echo "<form action=\"/cgi-bin/switch.cgi\">"
206   echo "<input type=\"hidden\" name=\"id\" value=\"$DISPID\" />"
207   echo "<div class=\"switchbox\"><div class=\"switchnameleft\">$NAME</div><span class=\"alignbuttonsright\">"
208   echo " <input class=\"onbutton\" type='submit' name='power' value='on' />"
209   echo " <input class=\"offbutton\" type='submit' name='power' value='off' />"
210   echo "</span>"
211   echo "</div>"
212   echo "</form>"
213   
214   else
215   
216   echo "<div class=\"switchbox\">"
217   echo "<span class=\"alignbuttonsleft\">"
218   echo " <button class=\"onbutton\" onClick='sendButton(\"on\",\"$DISPID\");'>On</button>"
219   echo " <button class=\"offbutton\" onClick='sendButton(\"off\",\"$DISPID\");'>Off</button>"
220   echo "</span>"
221   echo "<div class=\"switchnameright\">$NAME</div>"
222   echo "</div>"
223   
224   fi
225   if [ "$MOBILE" == "1" ]; then
226     echo "<br/>"
227   fi 
228 done
229 echo "</div>"
230 if [ "$MOBILE" != "1" ]; then                                                             
231 echo "<div style=\"float:left; border:1px solid black; margin-top:5px;\">"
232
233   if [ -z "$AJAX" ]; then
234
235   echo "<div class=\"switchbox\"><div class=\"switchnameleft\">Receiver Power</div><span class=\"alignbuttonsright\">"
236   echo "<form action=\"/cgi-bin/switch.cgi\"><input type=\"hidden\" name=\"id\" value=\"ymhpower\" /><input class=\"sendbutton\" type='submit' name='power' value='tgl' /></form>"
237   echo "<form action=\"/cgi-bin/switch.cgi\"><input type=\"hidden\" name=\"id\" value=\"ymhpower\" /><input class=\"offbutton\" type='submit' name='power' value='off' /></form>"
238   echo "</span></div>"
239
240   echo "<div class=\"switchbox\"><div class=\"switchnameleft\">Receiver Volume</div><span class=\"alignbuttonsright\">"
241   echo "<form action=\"/cgi-bin/switch.cgi\"><input type=\"hidden\" name=\"id\" value=\"ymhvolup\" /><input class=\"sendbutton\" type='submit' name='power' value='&uarr;' /></form>"
242   echo "<form action=\"/cgi-bin/switch.cgi\"><input type=\"hidden\" name=\"id\" value=\"ymhvoldown\" /><input class=\"sendbutton\" type='submit' name='power' value='&darr;' /></form>"
243   echo "</span></div>"
244
245   else
246   
247   echo "<div class=\"switchbox\">"
248   echo "<span class=\"alignbuttonsleft\">"
249   echo " <button class=\"sendbutton\" onClick='sendButton(\"on\",\"ymhpower\");'>Tgl</button>"
250   echo " <button class=\"offbutton\" onClick='sendButton(\"on\",\"ymhpoweroff\");'>Off</button>"
251   echo "</span>"
252   echo "<div class=\"switchnameright\">Receiver Power</div>"
253   echo "</div>"
254     
255   echo "<div class=\"switchbox\">"
256   echo "<span class=\"alignbuttonsleft\">"
257   echo " <button class=\"sendbutton\" onClick='sendButton(\"on\",\"ymhvolup\");'>&uarr;</button>"
258   echo " <button class=\"sendbutton\" onClick='sendButton(\"on\",\"ymhvoldown\");'>&darr;</button>"
259   echo "</span>"
260   echo "<div class=\"switchnameright\">Receiver Volume</div>"
261   echo "</div>"    
262     
263   fi
264
265 for DISPID in $VALID_SEND_IDS; do
266   NAME="$(eval echo \$DESC_$DISPID)"
267   [ -z "$NAME" ] && NAME=$DISPID
268   if [ -z "$AJAX" ]; then
269
270   echo "<form action=\"/cgi-bin/switch.cgi\">"
271   echo "<input type=\"hidden\" name=\"id\" value=\"$DISPID\" />"
272   echo "<div style=\"float:left; margin:2px; padding:1px; max-width:236px; font-size:10pt; border:1px solid black;\"><div style='width:10em; display:inline-block; vertical-align:middle;'>$NAME</div><span style='float:right; text-align:right;'>"
273   echo " <input class=\"sendbutton\" type='submit' name='power' value='  ' />"
274   echo "</span></div>"
275   echo "</form>"
276
277   else
278   
279   echo "<div class=\"switchbox\">"
280   echo "<span class=\"alignbuttonsleft\">"
281   echo " <button class=\"sendbutton\" onClick='sendButton(\"on\",\"$DISPID\");'> </button>"
282   echo "</span>"
283   echo "<div class=\"switchnameright\">$NAME</div>"
284   echo "</div>"
285     
286   fi
287 done
288 echo "</div>"
289 echo "<div style=\"float:left; border:1px solid black; margin-top:5px;\">"
290 for DISPID in $VALID_BANSHEE_IDS $VALID_CAM_MOTOR_IDS; do
291   NAME="$(eval echo \$DESC_$DISPID)"
292   [ -z "$NAME" ] && NAME=$DISPID
293   if [ -z "$AJAX" ]; then
294
295   echo "<form action=\"/cgi-bin/switch.cgi\">"
296   echo "<input type=\"hidden\" name=\"id\" value=\"$DISPID\" />"
297   echo "<div style=\"float:left; margin:2px; padding:1px; max-width:236px; font-size:10pt; border:1px solid black;\"><div style='width:10em; display:inline-block; vertical-align:middle;'>$NAME</div><span style='float:right; text-align:right;'>"
298   echo " <input class=\"sendbutton\" type='submit' name='power' value='  ' />"
299   echo "</span></div>"
300   echo "</form>"
301
302   else
303   
304   echo "<div class=\"switchbox\">"
305   echo "<span class=\"alignbuttonsleft\">"
306   echo " <button class=\"sendbutton\" onClick='sendButton(\"on\",\"$DISPID\");'> </button>"
307   echo "</span>"
308   echo "<div class=\"switchnameright\">$NAME</div>"
309   echo "</div>"
310     
311   fi
312 done
313 echo "</div>"
314 fi
315 echo "</body>"
316 echo "</html>"