Advertisement
Guest User

Untitled

a guest
Dec 14th, 2013
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.30 KB | None | 0 0
  1. <?php
  2.  
  3. $screen_name = "senseo";
  4. $user = "root";
  5. $statusfile = realpath(dirname(__FILE__))."/status.txt";
  6.  
  7. $allowed = array("s", "c", "b", "r", "a");
  8. $list = shell_exec("sudo ls /var/run/screen/S-".$user);
  9. if (strpos($list, $screen_name) == FALSE) {
  10.     exec('sudo screen -dmS '.$screen_name.' /dev/ttyUSB0 115200');
  11.     sleep(1);
  12.     exec('sudo daemon screen -r '.$screen_name);
  13.     exec('sudo screen -S arduino -X eval "stuff i"');
  14.     sleep(5);
  15.     header('Location: '.$_SERVER['PHP_SELF']);
  16. }
  17. elseif (isset($_GET['data'])) {
  18.     while ($message[1] != "louis") {
  19.         exec('sudo screen -S '.$screen_name.' -X hardcopy '.$statusfile);
  20.         $serial = exec('sudo tail -1 '.$statusfile);
  21.         $message = explode("jean", $serial);
  22.     }
  23.     echo $message[0];
  24. }
  25. elseif (isset($_GET['send'])) {
  26.     if (in_array($_GET['send'], $allowed))
  27.         exec('sudo screen -S '.$screen_name.' -X eval "stuff '.$_GET['send'].'"');
  28. }
  29. else {
  30. ?>
  31. <!DOCTYPE html>
  32. <html><head>
  33. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  34.     <meta charset="UTF-8">
  35.     <title>Senseo</title>
  36.     <link type="text/css" rel="stylesheet" href="http://cdn.jsdelivr.net/animatecss/0.1/animate.min.css" />
  37.     <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
  38.     <style>
  39.     * {
  40.         padding: 0;
  41.         margin: 0;
  42.     }
  43.     body {
  44.         background-color: #eee;
  45.         padding-top: 80px;
  46.         font-family: "Arial" ;
  47.         width: 500px;
  48.         margin: auto;
  49.     }
  50.     #header {
  51.         text-align: center;
  52.         margin-bottom: 80px;
  53.     }
  54.     #state {
  55.         background-color: white;
  56.         height: 100px;
  57.         border-radius: 25px;
  58.         padding: 25px;
  59.     }
  60.     #state h3 {
  61.         color: grey;
  62.         font-style: italic;
  63.         margin-bottom: 25px;
  64.     }
  65.     #senseo {
  66.         text-align: center;
  67.     }
  68.     #smallbuttons {
  69.         margin-top: 10px;
  70.     }
  71.     #footer {
  72.         margin-top: 25px;
  73.         text-align: center;
  74.     }
  75.     .button {
  76.         -webkit-appearance: none;
  77.         background-color: #0079d7;
  78.         width: 120px;
  79.         color: white;
  80.         padding: 10px;
  81.         border-radius: 25px;
  82.         border:0;
  83.         transition-duration: 0.5s;
  84.     }
  85.     .button:hover {
  86.         background-color: #003965;
  87.     }
  88.     .firstbutton,.stop {
  89.         font-size: 1.5em;
  90.         background-color: #00d323;
  91.         width: 250px;
  92.         height: 50px;
  93.     }
  94.     .firstbutton:hover {
  95.         background-color: #006e12;
  96.     }
  97.     .stop {
  98.         background-color: #a40101;
  99.     }
  100.     .stop:hover {
  101.         background-color: #520000;
  102.     }
  103.     .hide {
  104.         display: none;
  105.     }
  106.     @media only screen
  107.     and (min-device-width : 320px)
  108.     and (max-device-width : 480px) {
  109.         body {
  110.             width: 95%;
  111.             font-size: 2em;
  112.         }
  113.         #state {
  114.             background-color: white;
  115.             border-radius: 50px;
  116.             height: 200px;
  117.         }
  118.         #footer,#state {
  119.             margin-top: 70px;
  120.         }
  121.         #smallbuttons {
  122.             margin-top: 40px;
  123.         }
  124.         .button {
  125.             width: 30%;
  126.             color: white;
  127.             padding: 30px;
  128.             border-radius: 100px;
  129.             font-size: 1em;
  130.             border:0;
  131.             transition-duration: 0.5s;
  132.         }
  133.         .firstbutton,.stop {
  134.             font-size: 2.5em;
  135.             width: 80%;
  136.             height: 150px;
  137.             border-radius: 100px;
  138.         }      
  139.     }
  140.     </style>
  141. </head>
  142. <body>
  143.     <div id="header" class="animated bounceInDown">
  144.         <h1>Senseo online</h1>
  145.     </div>
  146.     <div id="state" class="animated fadeIn">
  147.         <h3>Senseo says :</h3>
  148.         <h2 id="senseo">Coffee machine waiting for orders !</h2>
  149.     </div>
  150.     <div id="footer">
  151.         <div id="buttons" class="animated fadeInDown">
  152.             <input class="button firstbutton" type="button" onclick="data('s');" value="Make a coffee"/>
  153.             <br/>
  154.             <div id="smallbuttons">
  155.                 <input class="button" type="button" onclick="data('b');" value="Preheat"/>
  156.                 <input class="button" type="button" onclick="data('c');" value="Add some water"/>
  157.                 <input class="button" type="button" onclick="data('r');" value="Monitor sensors"/>
  158.             </div>
  159.             <br />
  160.         </div>
  161.         <div id="stop" class="hide">
  162.             <input class="button stop" type="button" onclick="data('a')" value="Return standby"/>
  163.         </div>
  164.     </div>
  165. <script>
  166. var senseotext='Coffee machine waiting for orders !';
  167. var i=0;
  168. function getserial() {
  169.     $("#senseo").load("?data");
  170.     var senseotext = ($("#senseo").text());
  171.     stopbutton(senseotext);
  172. }
  173. function data(cmd) {
  174.     $.get("?send="+cmd);
  175. }
  176. function stopbutton(text) {
  177.     if(text != 'Coffee machine waiting for orders !') {
  178.         $("#stop").fadeIn();
  179.     }
  180.     else {
  181.         if (i>1) {
  182.             $("#stop").removeClass("hide");
  183.             i++;
  184.         }
  185.         else $("#stop").fadeOut();
  186.     }
  187. }
  188. window.setInterval(function(){getserial()}, 100);
  189. getserial();
  190. </script>
  191. </body>
  192. </html>
  193. <?php
  194. }
  195. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement