mdns.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="apple-mobile-web-app-capable" content="yes" />
  5. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  6. <meta charset="UTF-8">
  7. <meta name="theme-color" content="#4b75ff">
  8. <link rel="icon" type="image/png" href="./favicon.png" />
  9. <title>mDNS Discovery | Zoraxy</title>
  10. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  11. <script src="../script/jquery-3.6.0.min.js"></script>
  12. <script src="../../script/ao_module.js"></script>
  13. <script src="../script/semantic/semantic.min.js"></script>
  14. <script src="../script/tablesort.js"></script>
  15. <link rel="stylesheet" href="../main.css">
  16. </head>
  17. <body>
  18. <div id="mdns-hosts">
  19. </div>
  20. <br>
  21. <div class="ui container">
  22. <h4>Scan with custom domain filter</h4>
  23. <div class="ui form">
  24. <div class="field">
  25. <label for="domain">Domain</label>
  26. <input type="text" id="domain" name="domain" placeholder="domain.example.com"/>
  27. </div>
  28. <button id="discover" class="ui basic button">Discover</button>
  29. <small><span id="countdownTimer"></span></small>
  30. </div>
  31. <br>
  32. </div>
  33. <div style="float: right;">
  34. <button class="ui green basic button" onclick="initMDNSScan()"><i class="ui refresh icon"></i> Refresh</button>
  35. <button class="ui basic button" style="margin-right: 1em;" onclick="window.open('', '_self', ''); window.close();"><i class="ui red remove icon"></i> Close</button>
  36. </div>
  37. <br><br><br>
  38. <script>
  39. function initMDNSScan(){
  40. $.get("/api/mdns/list", function(data){
  41. renderMDNSHosts(data);
  42. });
  43. }
  44. initMDNSScan();
  45. $("#discover").on("click", function() {
  46. var domain = $("#domain").val();
  47. $("#discover").addClass("loading").addClass('disabled');
  48. setCountdown();
  49. $.ajax({
  50. type: "POST",
  51. url: "/api/mdns/discover",
  52. data: { domain: domain },
  53. success: function(data) {
  54. $("#discover").removeClass("loading").removeClass('disabled');
  55. renderMDNSHosts(data);
  56. },
  57. error: function(xhr, status, error) {
  58. console.error(error);
  59. // Handle error response here
  60. }
  61. });
  62. });
  63. function setCountdown() {
  64. var timeLeft = 29;
  65. var countdownTimer = document.getElementById("countdownTimer");
  66. // Update the timer every second
  67. var countdownInterval = setInterval(function() {
  68. if (timeLeft <= 0) {
  69. clearInterval(countdownInterval);
  70. countdownTimer.innerHTML = "Scan Completed";
  71. } else {
  72. countdownTimer.innerHTML = "Estimated Remaining Time: " + timeLeft + " seconds";
  73. timeLeft--;
  74. }
  75. }, 1000);
  76. }
  77. function renderMDNSHosts(data) {
  78. // Create table header
  79. var tableHeader = $('<thead>').append(
  80. $('<tr>').append(
  81. $('<th>').text('Host Name'),
  82. $('<th>').text('IP Address'),
  83. $('<th>').text('MAC Address'),
  84. $('<th>').text('Model'),
  85. $('<th>').text('Vendor')
  86. )
  87. );
  88. // Create table body
  89. var tableBody = $('<tbody>');
  90. for (var i = 0; i < data.length; i++) {
  91. var host = data[i];
  92. var ipAddresses = host.IPv4.join('<br> ');
  93. var macAddresses = host.MacAddr.join('<br> ');
  94. if (macAddresses.trim() == ""){
  95. macAddresses = '<i class="ui red remove icon"></i> Not Supported'
  96. }
  97. var row = $('<tr>').append(
  98. $('<td>').text(host.HostName),
  99. $('<td>').html(ipAddresses),
  100. $('<td>').html(macAddresses),
  101. $('<td>').text(host.Model),
  102. $('<td>').text(host.Vendor)
  103. );
  104. tableBody.append(row);
  105. }
  106. // Create table with header and body
  107. var table = $('<table>').addClass('ui celled unstackable table').append(tableHeader, tableBody);
  108. // Render table in HTML element with ID 'mdns-hosts'
  109. $('#mdns-hosts').html(table);
  110. }
  111. </script>
  112. </body>
  113. </html>