Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/webif-page
  2. <?
  3. . /usr/lib/webif/webif.sh
  4. ############################################################################
  5. #       Pagina comandi - centrala i2c
  6. #                  
  7. #############################################################################
  8.  
  9. header "Info" "System" "<img src=\"/images/telecomando.jpg\" alt=\"@TR<<>>\"/>@TR<< Comandi >>"
  10.  
  11. bus=1
  12. indirizzo=0x3b
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. grade="$(echo $(ds1621 -d /dev/i2c-0 -a 0x48))"
  22.  
  23. # Già provato con: gradi="$(ds1621 -d /dev/i2c-0 -a 0x48)"
  24. #              gradi="$(/usr/bin/ds1621 -d /dev/i2c-0 -a 0x48)"
  25. #              gradi=`ds1621 -d /dev/i2c-0 -a 0x48`
  26. #
  27. #
  28. # ma non funziona
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. for n in $(seq 1 8);do  
  42.         eval pin$n="$(cat /etc/centralina/device | sed -n '/Device'$n'/p'| awk '{ print $3 }')"
  43. done
  44.  
  45. gradi="$(echo $(ds1621 -d /dev/i2c-1 -a 0x48))"
  46. for n in $pin1 $pin2  $pin3  $pin4 $pin5 $pin6 $pin7 $pin8;do
  47.         eval stato$n="$(echo "$(pcf8574 -d /dev/i2c-$bus -a $indirizzo -r -v)" | sed -n '3p' | awk '{ print $('$n') }')"
  48. done
  49.     for n in $pin1 $pin2  $pin3  $pin4 $pin5 $pin6 $pin7 $pin8;do
  50.            pin=FORM_npin$n
  51.            eval pin=\$$pin
  52.            statozero="0000"
  53.                if equal $pin "ACCENDI" ; then
  54.                            eval stato$n="0"
  55.                    fi
  56.                    if equal $pin "SPEGNI" ; then
  57.                            eval stato$n="1"
  58.                    fi
  59.             stato="$stato8$stato7$stato6$stato5$stato4$stato3$stato2$stato1"       
  60.             statopin2="$stato4$stato3$stato2$stato1"
  61.             statopin1="$stato8$stato7$Stato6$stato5"
  62.            
  63.                    if ! equal $pin " " ;then
  64.                            if equal $statopin1 "0000" ;then
  65.                                    stato="$statopin2"
  66.                            fi
  67.                            if equal $statopin2 "0000" ;then
  68.                                    stato="$statopin1$statozero"
  69.                            fi
  70.                            codice="$(echo "ibase=2; $stato" | bc)"
  71.                            codiceesa="$(echo "obase=16; $codice" | bc)"
  72.                            echo "$(pcf8574 -d /dev/i2c-$bus -a $indirizzo -w 0x$codiceesa)"
  73.                    fi
  74.     done
  75. done
  76. if equal $FORM_pin1 "APRI" ; then
  77.     echo "<img src=\"../../../images/clessidra.gif\">"
  78.     echo "Attendi... sto aprendo la porta..."
  79.     stato1="0"
  80.     statochiudi="1"
  81.     statoa="$stato8$stato7$stato6$stato5$stato4$stato3$stato2$stato1"
  82.     statob="$stato8$stato7$stato6$stato5$stato4$stato3$stato2$statochiudi"
  83.     statopin2="$stato1$stato2$stato3$stato4"
  84.     statopin1="$stato5$stato6$Stato7$stato8"
  85.     if equal $statopin1 "0000" ;then
  86.         statoa="$stato4$stato3$stato2$stato1"
  87.         statob="$stato4$stato3$stato2$statochiudi"
  88.     fi
  89.     if equal $statopin2 "0000" ;then
  90.         statoa="$statopin8$stato7$stato6$stato$statozero"
  91.         statob="$statopin8$stato7$stato6$stato$Stato1$stato1$stato1$statochiudi"
  92.     fi
  93.     codicea="$(echo "ibase=2; $statoa" | bc)"
  94.     codiceesaa="$(echo "obase=16; $codicea" | bc)"
  95.     codiceb="$(echo "ibase=2; $statob" | bc)"
  96.     codiceesab="$(echo "obase=16; $codiceb" | bc)"
  97.     echo "$(pcf8574 -d /dev/i2c-$bus -a $indirizzo -w 0x$codiceesaa)"
  98.     sleep 2
  99.     echo "$(pcf8574 -d /dev/i2c-$bus -a $indirizzo -w 0x$codiceesab)"
  100. cat <<EOF
  101. <script language="JavaScript" type="text/javascript">
  102. setTimeout('top.location.href=\"/cgi-bin/webif/centralina/comandi.sh\"',"100")
  103. </script>
  104. EOF
  105. exit
  106. fi
  107. if equal $FORM_internet "ABILITA";then
  108.     echo "<img src=\"../../../images/clessidra.gif\">"
  109.     echo "Attendi... sto abilitando l'accesso a Internet"
  110.     uci set network.eth0.vlan0="0 1 2 3 5*"
  111.     /etc/init.d/network restart > /dev/null
  112. cat <<EOF
  113. <script language="JavaScript" type="text/javascript">
  114. setTimeout('top.location.href=\"/cgi-bin/webif/centralina/comandi.sh\"',"3")
  115. </script>
  116. EOF
  117. exit
  118. fi
  119. if equal $FORM_internet "DISABILITA";then
  120.     echo "<img src=\"../../../images/clessidra.gif\">"
  121.     echo "Attendi... sto disabilitando l'accesso a Internet"
  122.     uci set network.eth0.vlan0="2 3 5*"
  123.     /etc/init.d/network restart > /dev/null
  124. cat <<EOF
  125. <script language="JavaScript" type="text/javascript">
  126. setTimeout('top.location.href=\"/cgi-bin/webif/centralina/comandi.sh\"',"3")
  127. </script>
  128. EOF
  129. exit
  130. fi
  131. if equal $FORM_generale "SPEGNI_TUTTO" ; then
  132.     echo "Attendi... sto chiudendo tutto..."
  133.     echo "<img src=\"../../../images/clessidra.gif\">"
  134.     echo "$(pcf8574 -d /dev/i2c-$bus -a $indirizzo -w 0xff)"
  135. ocat <<EOF
  136. <script language="JavaScript" type="text/javascript">
  137. setTimeout('top.location.href=\"/cgi-bin/webif/centralina/comandi.sh\"',"300")
  138. </script>
  139. EOF
  140. exit
  141. fi
  142. cat <<EOF
  143.     <form method="get" action="comandi.sh">
  144.     <p><p><center>
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.     Temperatura interna: $gradi Gradi
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.     <table width="40%">
  170.     <tr><td><strong></td><td><strong><center>STATO</td>
  171.     <td><strong><center>COMANDO</strong></td></tr>
  172. EOF
  173. cat <<EOF
  174.     <tr><td>Apriporta :</td><td><center><center><img src="/images/chiave.jpg"></td>
  175.     <td><center><input type="submit" name="pin1" value=APRI
  176.     onClick="javascript:return confirm('Vuoi veramente aprire la porta?');"></td></tr>
  177. EOF
  178. for n in $pin2 $pin3 $pin4 $pin5 $pin6 $pin7 $pin8;do
  179.         stato="$(echo "$(pcf8574 -d /dev/i2c-$bus -a $indirizzo -r -v)" | sed -n '3p' | awk '{ print $('$n') }')"
  180.         per="$(cat /etc/centralina/device | sed -n '/ '$n'/p'| awk '{ print $2 }')"
  181.         per="$(echo "$per" | sed '/_/s// /g')"
  182.         if equal $stato "0" ; then
  183. cat <<EOF
  184.       <tr><td>$per:</td><td><center><img src="/images/lamp.jpg"></td>
  185.       <td><center><input type="submit" name="npin$n" value=SPEGNI ></td></tr>
  186. EOF
  187.         else
  188. cat <<EOF
  189.        <tr><td>$per :</td><td><center><img src="/images/lamp1.jpg"></td>
  190.        <td><center><input type="submit" name="npin$n" value=ACCENDI ></td></tr>
  191. EOF
  192.         fi
  193. done
  194.  
  195. accesso="$(echo "$(uci get network.eth0.vlan0)" |  awk '{ print $1 }' )"
  196. if equal $accesso "2";then
  197. cat <<EOF
  198.     <tr><td>Internet :</td><td><center><img src="/images/internet1.jpg"></td>
  199.     <td><center><input type="submit" name="internet" value="ABILITA"
  200.     onClick="javascript:return confirm('Vuoi veramente abilitare Internet?');"><td></tr>
  201. EOF
  202. else
  203. cat <<EOF
  204.     <tr><td>Internet :</td><td><center><img src="/images/internet.jpg"></td>
  205.     <td><center><input type="submit" name="internet" value="DISABILITA"
  206.     onClick="javascript:return confirm('Vuoi veramente dasabilitare Internet?');"></td></tr>
  207. EOF
  208. fi
  209. cat <<EOF
  210.     <tr><td>Generale :</td><td></td><td><center><input type="submit" name="generale" value="SPEGNI_TUTTO" ></td></tr>
  211.     </table></form>
  212.     &nbsp;<p>&nbsp;<p>
  213. EOF
  214.  
  215. display_form <<EOF
  216. start_form|@TR<<&nbsp;>>
  217. end_form
  218. EOF
  219.  
  220. presenza="$(cat /etc/centralina/presenza)"
  221. if ! equal $presenza "" ; then
  222.     echo "Il centro è attualmente utilizzato da:<strong> $presenza </strong>"
  223. fi
  224.  
  225. cat <<EOF
  226.     <script language="JavaScript" type="text/javascript">
  227.     setTimeout('top.location.href=\"/cgi-bin/webif/centralina/comandi.sh\"',"30000")
  228. </script>
  229. EOF
  230. footer
  231. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement