who
[svn42.git] / router_gpio_relay_licht / mswitch.cgi
1 #!/bin/sh
2
3 VALID_ONOFF_IDS="7 18 20"
4 GPIOPATH=/sys/class/gpio/gpio
5
6 for QUERY in `echo $QUERY_STRING | tr '&' ' '`; do
7   for VALIDID in $VALID_ONOFF_IDS; do
8     if [ "$QUERY" == "$VALIDID=1" ]; then
9       eval "GPIO_$VALIDID"=1
10     elif [ "$QUERY" == "$VALIDID=0" ]; then
11       eval "GPIO_$VALIDID=0"
12     elif [ "$QUERY" == "$VALIDID=q" ]; then
13       eval "GPIO_$VALIDID=q"
14     fi
15   done
16   if [ "$QUERY" == "mobile=1" ]; then
17     MOBILE='1'
18     NOFLOAT='1'
19   elif [ "$QUERY" == "nofloat=1" ]; then
20     NOFLOAT='1'
21   fi
22 done
23
24
25 print_gpio_state() {
26   GPIOVALUE=$(cat "${GPIOPATH}${1}/value")
27   if [ "$GPIOVALUE" = "1" ]; then
28     echo -n "true"
29   else
30     echo -n "false"
31   fi
32 }
33
34 gpio_is_on() {
35   GPIOVALUE=$(cat "${GPIOPATH}${1}/value")
36   [ "$GPIOVALUE" = "1" ]
37 }
38
39 echo "Content-type: text/html"
40 echo ""
41
42 echo "{"
43 for CHECKID in $VALID_ONOFF_IDS; do
44   VAL=""
45   VAL="$(eval echo \$GPIO_$CHECKID)"
46   if [ $VAL == 1 -o $VAL == 0 ]; then
47     echo "$VAL" > "${GPIOPATH}${CHECKID}/value"
48   fi
49   echo -n "\"$CHECKID\":"
50   print_gpio_state $CHECKID
51   echo ","
52 done
53 echo "\"-1\":false}"
54 #      echo "<html>"
55 #      echo "<head>"
56 #      echo "<title>Realraum Relay Switch</title>"
57 #      echo '<script type="text/javascript">window.location="/cgi-bin/switch.cgi";</script>'
58 #      echo "</head></html>"
59 #      exit 0
60