schöner aber auch nicht funktioneller
[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" == "ajax" ]; then
14       AJAX='?'
15     elif [ "$AJAX" == "?" ]; then
16       AJAX=$VALUE
17     fi
18     i=$i+1
19   done
20 done
21
22 UNIXSOCK=/var/run/powersensordaemon/cmd.sock
23 VALID_ONOFF_IDS="decke ambientlights lichter all werkzeug labor dart logo spots1 deckehinten deckevorne boiler lichterkette"
24 VALID_SEND_IDS="ymhpoweron ymhpoweroff ymhpower ymhvolup ymhvoldown 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"
25 VALID_BANSHEE_IDS="playPause next prev"
26
27 [ "$POWER" == "send" ] && POWER=on
28 if [ "$POWER" == "on" -o "$POWER" == "off" ]; then
29   for CHECKID in $VALID_ONOFF_IDS $VALID_SEND_IDS; do 
30     if [ "$CHECKID" == "$ID" ]; then
31       echo "power $POWER $ID" | usocket $UNIXSOCK
32       echo "Content-type: text/html"
33       echo ""
34       echo "<html>"
35       echo "<head>"
36       echo "<title>Realraum rf433ctl</title>"
37       echo '<script type="text/javascript">window.location="http://slug.realraum.at/cgi-bin/switch.cgi";</script>'
38       echo "</head></html>"
39       exit 0
40     fi
41   done
42
43   for CHECKID in $VALID_BANSHEE_IDS; do 
44     if [ "$CHECKID" == "$ID" ]; then
45       echo "$ID/" | nc wuerfel.realraum.at 8484
46       echo "Content-type: text/html"
47       echo ""
48       echo "<html>"
49       echo "<head>"
50       echo "<title>Realraum rf433ctl</title>"
51       echo '<script type="text/javascript">window.location="http://slug.realraum.at/cgi-bin/switch.cgi";</script>'
52       echo "</head></html>"
53       exit 0
54     fi
55   done
56 fi
57
58 DESC_werkzeug="Werkzeug LEDs"
59 DESC_stereo="Receiver On/Off"
60 DESC_ambientlights="Ambient Lichter"
61 DESC_labor="Labor Licht"
62 DESC_boiler="Warmwasser WC"
63 DESC_dart="Dart Scheibe"
64 DESC_logo="Logo"
65 DESC_spots1="Spots"
66 DESC_deckehinten="Decke Hinten"
67 DESC_deckevorne="Decke Vorne"
68 DESC_lichterkette="Blaue Lichterkette"
69 DESC_decke="Deckenlichter"
70 DESC_lichter="Alle Lichter"
71 DESC_all="Alles"
72 DESC_ymhpoweron="Receiver On"
73 DESC_ymhpoweroff="Receiver Off"
74 DESC_ymhpower="Receiver On/Off"
75 DESC_ymhvolup="VolumeUp"
76 DESC_ymhvoldown="VolumeDown"
77 DESC_ymhcd="Input CD"
78 DESC_ymhwdtv="Input WDlxTV"
79 DESC_ymhtuner="Input Tuner"
80 DESC_ymhvolmute="Mute"
81 DESC_ymhmenu="Menu"
82 DESC_ymhplus="+"
83 DESC_ymhminus="-"
84 DESC_ymhtest="Test"
85 DESC_ymhtimelevel="Time/Levels"
86 DESC_ymheffect="DSP Effect Toggle"
87 DESC_ymhprgup="DSP Up"
88 DESC_ymhprgdown="DSP Down"
89 DESC_ymhtunplus="Tuner +"
90 DESC_ymhtunminus="Tuner -"
91 DESC_ymhtunabcde="Tuner ABCDE"
92 DESC_ymhtape="Tape"
93 DESC_ymhvcr="VCR"
94 DESC_ymhextdec="ExtDec Toggle"
95 DESC_seep="Sleep Modus"
96 DESC_panicled="HAL9000 says hi"
97 DESC_blueled="Blue Led"
98 DESC_moviemode="Movie Mode"
99 echo "Content-type: text/html"
100 echo ""
101 echo "<html>"
102 echo "<head>"
103 echo "<title>Realraum rf433ctl</title>"
104 echo '<script type="text/javascript">'
105 echo 'function sendButton( onoff, btn )'
106 echo '{'
107 echo ' var req = new XMLHttpRequest();'
108 echo ' url = "http://slug.realraum.at/cgi-bin/switch.cgi?power="+onoff+"&id="+btn;'
109 echo ' req.open("GET", url ,false);'
110 echo ' //google chrome workaround'
111 echo ' req.setRequestHeader("googlechromefix","");'
112 echo ' req.send(null);'
113 echo '}'
114 echo '</script>'
115 echo "</head>"
116 echo "<body>"
117 #echo "<h1>Realraum rf433ctl</h1>"
118 echo "<div style=\"float:left; border:1px solid black;\">"
119 for DISPID in $VALID_ONOFF_IDS; do
120   NAME="$(eval echo \$DESC_$DISPID)"
121   [ -z "$NAME" ] && NAME=$DISPID
122   if [ -z "$AJAX" ]; then
123
124   echo "<form action=\"/cgi-bin/switch.cgi\">"
125   echo "<input type=\"hidden\" name=\"id\" value=\"$DISPID\" />"
126   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;'>"
127   echo " <input type='submit' name='power' value='on' />"
128   echo " <input type='submit' name='power' value='off' />"
129   echo "</span></div>"
130   echo "</form>"
131   
132   else
133   
134   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;'>"
135   echo " <button onClick='sendButton(\"on\",\"$DISPID\");'>On</button>"
136   echo " <button onClick='sendButton(\"off\",\"$DISPID\");'>Off</button>"
137   echo "</span></div>"
138   
139   fi
140 done
141 echo "</div>"
142 echo "<div style=\"float:left; border:1px solid black;\">"
143 for DISPID in $VALID_SEND_IDS; do
144   NAME="$(eval echo \$DESC_$DISPID)"
145   [ -z "$NAME" ] && NAME=$DISPID
146   if [ -z "$AJAX" ]; then
147
148   echo "<form action=\"/cgi-bin/switch.cgi\">"
149   echo "<input type=\"hidden\" name=\"id\" value=\"$DISPID\" />"
150   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;'>"
151   echo " <input type='submit' name='power' value='send' />"
152   echo "</span></div>"
153   echo "</form>"
154
155   else
156   
157   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;'>"
158   echo " <button onClick='sendButton(\"on\",\"$DISPID\");'>Send</button>"
159   echo "</span></div>"
160   
161   fi
162 done
163 echo "</div>"
164 echo "<div style=\"float:left; border:1px solid black;\">"
165 for DISPID in $VALID_BANSHEE_IDS; do
166   NAME="$(eval echo \$DESC_$DISPID)"
167   [ -z "$NAME" ] && NAME=$DISPID
168   if [ -z "$AJAX" ]; then
169
170   echo "<form action=\"/cgi-bin/switch.cgi\">"
171   echo "<input type=\"hidden\" name=\"id\" value=\"$DISPID\" />"
172   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;'>"
173   echo " <input type='submit' name='power' value='on' />"
174   echo " <input type='submit' name='power' value='off' />"
175   echo "</span></div>"
176   echo "</form>"
177   
178   else
179   
180   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;'>"
181   echo " <button onClick='sendButton(\"on\",\"$DISPID\");'>Send</button>"
182   echo "</span></div>"
183   
184   fi
185 done
186 echo "</div>"
187 echo "</body>"
188 echo "</html>"