1
0

mdns.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. <style>
  17. body{
  18. overflow-x: auto;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div id="mdns-hosts">
  24. </div>
  25. <br>
  26. <div class="ui container">
  27. <h4>Scan with custom domain filter</h4>
  28. <div class="ui form">
  29. <div class="field">
  30. <label for="domain">Domain</label>
  31. <input type="text" id="domain" name="domain" placeholder="domain.example.com"/>
  32. </div>
  33. <button id="discover" class="ui basic button">Discover</button>
  34. <small><span id="countdownTimer"></span></small>
  35. </div>
  36. <br>
  37. </div>
  38. <div style="float: right;">
  39. <button class="ui basic button" onclick="initMDNSScan()"><i class="ui green refresh icon"></i> Refresh</button>
  40. <button class="ui basic button" style="margin-right: 1em;" onclick="window.open('', '_self', ''); window.close();"><i class="ui red remove icon"></i> Close</button>
  41. </div>
  42. <br><br><br>
  43. <script>
  44. function initMDNSScan(){
  45. $.get("/api/mdns/list", function(data){
  46. renderMDNSHosts(data);
  47. });
  48. }
  49. initMDNSScan();
  50. $("#discover").on("click", function() {
  51. var domain = $("#domain").val();
  52. $("#discover").addClass("loading").addClass('disabled');
  53. setCountdown();
  54. $.ajax({
  55. type: "POST",
  56. url: "/api/mdns/discover",
  57. data: { domain: domain },
  58. success: function(data) {
  59. $("#discover").removeClass("loading").removeClass('disabled');
  60. renderMDNSHosts(data);
  61. },
  62. error: function(xhr, status, error) {
  63. console.error(error);
  64. // Handle error response here
  65. }
  66. });
  67. });
  68. function setCountdown() {
  69. var timeLeft = 29;
  70. var countdownTimer = document.getElementById("countdownTimer");
  71. // Update the timer every second
  72. var countdownInterval = setInterval(function() {
  73. if (timeLeft <= 0) {
  74. clearInterval(countdownInterval);
  75. countdownTimer.innerHTML = "Scan Completed";
  76. } else {
  77. countdownTimer.innerHTML = "Estimated Remaining Time: " + timeLeft + " seconds";
  78. timeLeft--;
  79. }
  80. }, 1000);
  81. }
  82. function renderMDNSHosts(data) {
  83. // Create table header
  84. var tableHeader = $('<thead>').append(
  85. $('<tr>').append(
  86. $('<th>').text('Host Name'),
  87. $('<th>').text('IP Address'),
  88. $('<th>').text('MAC Address'),
  89. $('<th>').text('Model'),
  90. $('<th>').text('Vendor')
  91. )
  92. );
  93. if (data.error != undefined){
  94. $('#mdns-hosts').html(`<table class="ui celled unstackable table"><tbody></tbody></table>`);
  95. $('#mdns-hosts').find("tbody").append(`<tr><td colspan="5"><i class="ui red circle times icon"></i> ${data.error}</td></tr>`);
  96. $("#discover").addClass("disabled");
  97. return;
  98. }
  99. // Create table body
  100. var tableBody = $('<tbody>');
  101. for (var i = 0; i < data.length; i++) {
  102. var host = data[i];
  103. var ipAddresses = host.IPv4.join('<br> ');
  104. var macAddresses = host.MacAddr.join('<br> ');
  105. if (macAddresses.trim() == ""){
  106. macAddresses = '<i class="ui red remove icon"></i> Not Supported'
  107. }
  108. var row = $('<tr>').append(
  109. $('<td>').html(`<a target="_blank" href="//${host.HostName}:${host.Port}">${host.HostName}</a>`),
  110. $('<td>').html(ipAddresses),
  111. $('<td>').html(macAddresses),
  112. $('<td>').text(host.Model),
  113. $('<td>').text(host.Vendor)
  114. );
  115. tableBody.append(row);
  116. }
  117. // Create table with header and body
  118. var table = $('<table>').addClass('ui celled unstackable table').append(tableHeader, tableBody);
  119. // Render table in HTML element with ID 'mdns-hosts'
  120. $('#mdns-hosts').html(table);
  121. if (data.length == 0){
  122. $('#mdns-hosts').find("tbody").append(`<tr><td colspan="5"><i class="ui green circle check icon"></i> No scan results</td></tr>`);
  123. }
  124. }
  125. </script>
  126. </body>
  127. </html>