s26.sonoff.ext.com.imuslab.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. if (isset($_GET['status'])){
  3. $content = file_get_contents("http://" . $_GET['status'] . "/ay");
  4. header('Content-Type: application/json');
  5. echo json_encode(str_replace("{t}","",strip_tags($content)));
  6. exit(0);
  7. }else if (isset($_GET['toggle']) && $_GET['toggle'] !=""){
  8. $content = file_get_contents("http://" . $_GET['toggle'] . "/ay?o=1");
  9. header('Content-Type: application/json');
  10. echo json_encode(str_replace("{t}","",strip_tags($content)));
  11. exit(0);
  12. }
  13. ?>
  14. <html>
  15. <head>
  16. <title>s26_sonoff_driver</title>
  17. <link rel="stylesheet" href="tocas.css">
  18. <script src="jquery.min.js"></script>
  19. <style>
  20. #button{
  21. background-color:#262626;
  22. }
  23. .center{
  24. position: fixed;
  25. width: 40%;
  26. top:50%;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div id="infoPage" style="position:fixed;left:0px;top:0px;color:white;z-index:999;display:none;"><?php
  32. $content = strip_tags(file_get_contents("http://" . $_GET['ip'] . "/in"));
  33. if (strpos($content,"Sonoff-Tasmota") !== 0){
  34. //This is a correctly loaded driver
  35. echo $content;
  36. }else{
  37. die("ERROR. This is not a Sonoff-Tasmota driven device or your driver is outdated.");
  38. }
  39. ?></div>
  40. <div id="ipv4" style="position:fixed;top:3px;left:3px;z-index:10;color:white;"><?php echo $_GET['ip'];?></div>
  41. <div id="button" style="width:100%;height:100%;position:fixed;left:0px;top:0px;" onClick="toggleSwitch();">
  42. <img id="icon" class="center" src="img/default_transparent.png"></img>
  43. </div>
  44. <div id="uuid" style="position:fixed;bottom:3px;left:3px;color:white;"></div>
  45. <script>
  46. uuid();
  47. status();
  48. moveIcon();
  49. function status(){
  50. $.ajax({url: "s26.sonoff.ext.com.imuslab.php?status=" + $("#ipv4").text().trim(),
  51. success: function(result){
  52. console.log(result);
  53. $("#status").html(result);
  54. if (result == "ON"){
  55. $("#button").css("background-color","#00cccc");
  56. currentStatus = "ON";
  57. }else{
  58. $("#button").css("background-color","#262626");
  59. currentStatus = "OFF";
  60. }
  61. }});
  62. }
  63. function toggleSwitch(){
  64. $.ajax({url: "s26.sonoff.ext.com.imuslab.php?toggle=" + $("#ipv4").text().trim(),
  65. success: function(result){
  66. console.log(result);
  67. $("#status").html(result);
  68. if (result == "ON"){
  69. $("#button").css("background-color","#00cccc");
  70. currentStatus = "ON";
  71. }else{
  72. $("#button").css("background-color","#262626");
  73. currentStatus = "OFF";
  74. }
  75. }});
  76. }
  77. function uuid(){
  78. var deviceInfo = $("#infoPage").text();
  79. var starting = deviceInfo.indexOf("MAC");
  80. var MACADDR = deviceInfo.substring(starting);
  81. var ending = MACADDR.indexOf("MQTT");
  82. //Just a bunch of scripts to filter out the MAC address
  83. MACADDR = MACADDR.substring(0,ending - 7);
  84. starting = MACADDR.indexOf("}");
  85. MACADDR = MACADDR.substring(starting + 2);
  86. MACADDR = MACADDR.split(":").join("-");
  87. $("#uuid").text(MACADDR);
  88. }
  89. function moveIcon(){
  90. $("#icon").css("top",(window.innerHeight /2 - $("#icon").height() / 2) + "px");
  91. $("#icon").css("left",(window.innerWidth /2 - $("#icon").width() / 2) + "px");
  92. }
  93. </script>
  94. </body>
  95. </html>