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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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="basic/tocas.css">
  18. <script src="basic/jquery.min.js"></script>
  19. <style>
  20. #button{
  21. background-color:#262626;
  22. }
  23. .center{
  24. display: block;
  25. margin-left: auto;
  26. margin-right: auto;
  27. width: 40%;
  28. top:30%;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="infoPage" style="position:fixed;left:0px;top:0px;color:white;z-index:999;display:none;"><?php
  34. $content = strip_tags(file_get_contents("http://" . $_GET['ip'] . "/in"));
  35. if (strpos($content,"Sonoff-Tasmota") !== 0){
  36. //This is a correctly loaded driver
  37. echo $content;
  38. }else{
  39. die("ERROR. This is not a Sonoff-Tasmota driven device or your driver is outdated.");
  40. }
  41. ?></div>
  42. <div id="ipv4" style="position:fixed;top:3px;left:3px;z-index:10;color:white;"><?php echo $_GET['ip'];?></div>
  43. <div id="button" style="width:100%;height:100%;position:fixed;left:0px;top:0px;" onClick="toggleSwitch();">
  44. <img id="icon" class="center" src=""></img>
  45. </div>
  46. <div id="uuid" style="position:fixed;bottom:3px;left:3px;color:white;"></div>
  47. <script>
  48. uuid();
  49. status();
  50. function status(){
  51. $.ajax({url: "s26.sonoff.ext.com.imuslab.php?status=" + $("#ipv4").text().trim(),
  52. success: function(result){
  53. console.log(result);
  54. $("#status").html(result);
  55. if (result == "ON"){
  56. $("#button").css("background-color","#00cccc");
  57. currentStatus = "ON";
  58. }else{
  59. $("#button").css("background-color","#262626");
  60. currentStatus = "OFF";
  61. }
  62. }});
  63. }
  64. function toggleSwitch(){
  65. $.ajax({url: "s26.sonoff.ext.com.imuslab.php?toggle=" + $("#ipv4").text().trim(),
  66. success: function(result){
  67. console.log(result);
  68. $("#status").html(result);
  69. if (result == "ON"){
  70. $("#button").css("background-color","#00cccc");
  71. currentStatus = "ON";
  72. }else{
  73. $("#button").css("background-color","#262626");
  74. currentStatus = "OFF";
  75. }
  76. }});
  77. }
  78. function uuid(){
  79. var deviceInfo = $("#infoPage").text();
  80. var starting = deviceInfo.indexOf("MAC");
  81. var MACADDR = deviceInfo.substring(starting);
  82. var ending = MACADDR.indexOf("MQTT");
  83. //Just a bunch of scripts to filter out the MAC address
  84. MACADDR = MACADDR.substring(0,ending - 7);
  85. starting = MACADDR.indexOf("}");
  86. MACADDR = MACADDR.substring(starting + 2);
  87. MACADDR = MACADDR.split(":").join("-");
  88. $("#uuid").text(MACADDR);
  89. getNickName();
  90. }
  91. function getNickName(){
  92. $.ajax({url: "../nicknameman.php?uuid=" + $("#uuid").text().trim(), success: function(result){
  93. if (result.includes("ERROR") == false){
  94. $("#uuid").text(result);
  95. getIcon();
  96. }else{
  97. }
  98. }});
  99. }
  100. function getIcon(){
  101. $.ajax({url: "../nicknameman.php?nickname=" + $("#uuid").text().trim(), success: function(result){
  102. if (result.includes("true") == true){
  103. $("#icon").attr('src','../img/icons/'+ $("#uuid").text().trim() +'.png');
  104. }
  105. }});
  106. }
  107. </script>
  108. </body>
  109. </html>