hds_scan.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. include_once '../auth.php';
  3. ?>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  8. <meta name="apple-mobile-web-app-capable" content="yes" />
  9. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  10. <meta charset="utf-8">
  11. <title>HDS Scanner (Experimental)</title>
  12. <script src="../script/jquery.min.js"></script>
  13. <link rel="stylesheet" href="script/tocas/tocas.css">
  14. <style>
  15. .founddev{
  16. color:#41a345;
  17. }
  18. </style>
  19. </head>
  20. <body style="background-color:#f5f5f5;color:#3b3b3b;">
  21. <br><br>
  22. <p id="list" class="ts text container">Loading</p>
  23. <p id="debug" class="ts text container"></p>
  24. <div class="ts active inverted dimmer">
  25. <div class="ts text loader">Scanning in Progress<br>Do not close this page</div>
  26. </div>
  27. <script>
  28. var HDSIPList = [];
  29. var startedConnections = 0;
  30. $(document).ready(function(){
  31. GrapIP();
  32. setTimeout(function() {
  33. StartWebWorker();
  34. }, 2000);
  35. });
  36. function StartWebWorker(){
  37. var ip = $("#list").html();
  38. var webWorkers = [];
  39. if (ip.includes("ifconfig")){
  40. $("#debug").append("This browser is not supported.<br>");
  41. return;
  42. }
  43. if (typeof(Worker) !== "undefined") {
  44. $("#debug").append("Web Worker Exists. IP Scanning Started.<br>");
  45. //The browser support everything and ready to start scanning
  46. var ipg = ip.split(".");
  47. var header = ipg[0] + "." + ipg[1] + "." + ipg[2] + "."; //a.b.c.
  48. for (var i=1; i < 255;i++){
  49. startedConnections++;
  50. GetWorkingOrNot(header + i)
  51. }
  52. WaitAllFinish();
  53. } else {
  54. $("#debug").html("Error. Web Worker not supported.");
  55. }
  56. }
  57. function WaitAllFinish(){
  58. $("html, body").animate({ scrollTop: $(document).height() }, 200);
  59. if (startedConnections <= 1){
  60. $("#debug").append("<br>DONE<br><br>");
  61. GenerateTable();
  62. }else{
  63. setTimeout(WaitAllFinish, 1000);
  64. }
  65. }
  66. function GetWorkingOrNot(ip){
  67. $.ajax({url: "http://" + ip + "/uuid",
  68. type: "HEAD",
  69. timeout:5000,
  70. statusCode: {
  71. 200: function (response) {
  72. $("#debug").append("<span class='founddev'><i class='checkmark icon'></i>" +ip + " <i class='triangle right icon'></i> " + startedConnections + "</span><br>");
  73. //$("#debug").append("<a href='http://" +ip + "/' target='_blank'>Click here to redirect</a><br>");
  74. HDSIPList.push(ip);
  75. startedConnections--;
  76. },
  77. 400: function (response) {
  78. $("#debug").append("<i class='remove icon'></i>" +ip + " <i class='triangle right icon'></i> " + startedConnections + "<br>");
  79. startedConnections--;
  80. },
  81. 0: function (response) {
  82. $("#debug").append("<i class='question icon'></i>" +ip + " <i class='triangle right icon'></i> " + startedConnections + "<br>");
  83. startedConnections--;
  84. },
  85. 401: function (response) {
  86. $("#debug").append("<i class='remove icon'></i>" +ip + " <i class='triangle right icon'></i> " + startedConnections + "<br>");
  87. startedConnections--;
  88. },
  89. 404: function (response) {
  90. $("#debug").append("<i class='remove icon'></i>" +ip + " <i class='triangle right icon'></i> " + startedConnections + "<br>");
  91. startedConnections--;
  92. }
  93. }
  94. });
  95. }
  96. function GrapIP(){
  97. // NOTE: window.RTCPeerConnection is "not a constructor" in FF22/23
  98. var RTCPeerConnection = /*window.RTCPeerConnection ||*/ window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
  99. if (RTCPeerConnection) (function () {
  100. var rtc = new RTCPeerConnection({iceServers:[]});
  101. if (1 || window.mozRTCPeerConnection) { // FF [and now Chrome!] needs a channel/stream to proceed
  102. rtc.createDataChannel('', {reliable:false});
  103. };
  104. rtc.onicecandidate = function (evt) {
  105. // convert the candidate to SDP so we can run it through our general parser
  106. // see https://twitter.com/lancestout/status/525796175425720320 for details
  107. if (evt.candidate) grepSDP("a="+evt.candidate.candidate);
  108. };
  109. rtc.createOffer(function (offerDesc) {
  110. grepSDP(offerDesc.sdp);
  111. rtc.setLocalDescription(offerDesc);
  112. }, function (e) { console.warn("offer failed", e); });
  113. var addrs = Object.create(null);
  114. addrs["0.0.0.0"] = false;
  115. function updateDisplay(newAddr) {
  116. if (newAddr in addrs) return;
  117. else addrs[newAddr] = true;
  118. var displayAddrs = Object.keys(addrs).filter(function (k) { return addrs[k]; });
  119. document.getElementById('list').textContent = displayAddrs.join(" or perhaps ") || "n/a";
  120. }
  121. function grepSDP(sdp) {
  122. var hosts = [];
  123. sdp.split('\r\n').forEach(function (line) { // c.f. http://tools.ietf.org/html/rfc4566#page-39
  124. if (~line.indexOf("a=candidate")) { // http://tools.ietf.org/html/rfc4566#section-5.13
  125. var parts = line.split(' '), // http://tools.ietf.org/html/rfc5245#section-15.1
  126. addr = parts[4],
  127. type = parts[7];
  128. if (type === 'host') updateDisplay(addr);
  129. } else if (~line.indexOf("c=")) { // http://tools.ietf.org/html/rfc4566#section-5.7
  130. var parts = line.split(' '),
  131. addr = parts[2];
  132. updateDisplay(addr);
  133. }
  134. });
  135. }
  136. })(); else {
  137. document.getElementById('list').innerHTML = "<code>ifconfig | grep inet | grep -v inet6 | cut -d\" \" -f2 | tail -n1</code>";
  138. document.getElementById('list').nextSibling.textContent = "If you see this line, that means your browser is not supported. Please use Chrome / Firefox or other WebRTC supported browsers.";
  139. //Callback to next function
  140. }
  141. }
  142. function GenerateTable(){
  143. //Request the HDS Host to generate the ip table for all in range HDS unit
  144. console.log(HDSIPList);
  145. $.post( "HDS_iptable.php", {ipTable: HDSIPList})
  146. .done(function( data ) {
  147. window.location = "index.php";
  148. });
  149. }
  150. </script>
  151. </body></html>