Guest User

Untitled

a guest
Apr 22nd, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5. </head>
  6. <body>
  7. <?php
  8. $user = "user";
  9. $password = "pass";
  10. if (array_key_exists("port", $_GET) and is_numeric($_GET["port"] )) {
  11. $port = $_GET["port"];
  12. }
  13. if (array_key_exists("state", $_GET) and $_GET["state"] == "on" or $_GET["state"] == "off") {
  14. $state = $_GET["state"];
  15. }
  16. $url = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
  17. $output = shell_exec("expect /var/tmp/power.expect 192.168.5.3 ".$user." ".$password." ".$port." ".$state." | tail -n 10 | head -n 8 | cut -c 7,34-39");
  18. #foreach(preg_split("/((\r?\n)|(\r\n?))/", $output) as $line){
  19. # $stat = explode(" ", $line, 2);
  20. # if ($stat[0]) {echo $stat[0]." currently ".$stat[1]." <a href='".$url."?port=".$stat[0]."&state=on'>ON</a> <a href='".$url."?port=".$stat[0]."&state=off'>OFF</a><br>";}
  21. #}
  22. $outletstats = preg_split("/((\r?\n)|(\r\n?))/", $output);
  23. ?>
  24. <table style="width:100%;border: 1px solid black;">
  25. <tr>
  26. <th>Function</th>
  27. <th>Port</th>
  28. <th>Status</th>
  29. <th>Control</th>
  30. </tr>
  31. <tr>
  32. <td>Downstairs Exhaust Fan</td>
  33. <td>1</td>
  34. <td><?php echo explode(" ",$outletstats[0])[1];?></td>
  35. <td><?php echo "<a href='".$url."?state=on&port=1'>Turn On</a></br><a href='".$url."?state=off&port=1'>Turn Off</a>";?></td>
  36. </tr>
  37. <tr>
  38. <td>Deck Floodlight</td>
  39. <td>2</td>
  40. <td><?php echo explode(" ",$outletstats[1])[1];?></td>
  41. <td><?php echo "<a href='".$url."?state=on&port=2'>Turn On</a></br><a href='".$url."?state=off&port=2'>Turn Off</a>";?></td>
  42. </tr>
  43. </table>
  44. </body>
  45. </html>
Add Comment
Please, Sign In to add comment