networktools.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <div class="standardContainer">
  2. <div class="ui basic segment">
  3. <h2>Network Tools</h2>
  4. <p>Network tools to help manage your cluster nodes</p>
  5. </div>
  6. <div class="ui top attached tabular menu">
  7. <a class="nettools item active bluefont" data-tab="tab1">Discovery</a>
  8. <a class="nettools item bluefont" data-tab="tab2">Connection</a>
  9. <a class="nettools item bluefont" data-tab="tab3">Interface</a>
  10. </div>
  11. <div class="ui bottom attached tab segment active" data-tab="tab1">
  12. <h2>Multicast DNS (mDNS) Scanner</h2>
  13. <p>Discover mDNS enabled service in this gateway forwarded network</p>
  14. <button class="ui basic larger circular button" onclick="launchToolWithSize('./tools/mdns.html',1000, 640);">View Discovery</button>
  15. <div class="ui divider"></div>
  16. <h2>IP Scanner</h2>
  17. <p>Discover local area network devices by pinging them one by one</p>
  18. <button class="ui basic larger circular button" onclick="launchToolWithSize('./tools/ipscan.html',1000, 640);">Start Scanner</button>
  19. </div>
  20. <div class="ui bottom attached tab segment" data-tab="tab2">
  21. <div style="position: relative;">
  22. <h2>Web SSH</h2>
  23. <p>Connect to a network node within the local area network of the gateway</p>
  24. <div class="ui small form">
  25. <div class="three fields">
  26. <div class="field">
  27. <label>Server Name or IP Address</label>
  28. <input type="text" id="ssh_server" placeholder="e.g. example.com or 192.168.1.1">
  29. </div>
  30. <div class="field">
  31. <label>Port Number</label>
  32. <input type="number" id="ssh_port" placeholder="e.g. 22 or 2022">
  33. </div>
  34. <div class="field">
  35. <label>Username</label>
  36. <input type="text" id="ssh_username" placeholder="root">
  37. </div>
  38. </div>
  39. </div>
  40. <button class="ui basic larger orange circular button" onclick="connectSSH();">Connect using SSH</button>
  41. <div class="ui inverted message" style="display: block;">
  42. Copy from Terminal <code style="float: right;">Ctrl + Insert</code><br>
  43. Paste to Terminal <code style="float: right;">Shift + Insert</code>
  44. </div>
  45. </div>
  46. <div class="ui divider"></div>
  47. </div>
  48. <div class="ui bottom attached tab segment" data-tab="tab3">
  49. <h2>Network Interfaces</h2>
  50. <p>Network Interface Card (NIC) currently installed on this host</p>
  51. <table id="network-interfaces-table" class="ui selectable inverted striped celled table">
  52. <thead>
  53. <tr>
  54. <th>Interface Name</th>
  55. <th>ID</th>
  56. <th>IP Address</th>
  57. </tr>
  58. </thead>
  59. <tbody></tbody>
  60. </table>
  61. </div>
  62. </div>
  63. <script>
  64. // Activate the default tab
  65. $('.menu .nettools.item').tab();
  66. $('.menu .nettools.item').addClass("activated");
  67. // Switch tabs when clicking on the menu items
  68. $('.menu .nettools.item').on('click', function() {
  69. $('.menu .item').removeClass('active');
  70. $(this).addClass('active');
  71. var tab = $(this).attr('data-tab');
  72. $('.tab.segment').removeClass('active');
  73. $('div[data-tab="' + tab + '"]').addClass('active');
  74. });
  75. function connectSSH(){
  76. function validateForm() {
  77. var serverInput = document.getElementById("ssh_server");
  78. var portInput = document.getElementById("ssh_port");
  79. var usernameInput = document.getElementById("ssh_username");
  80. var server = serverInput.value.trim();
  81. var port = parseInt(portInput.value.trim() || "22");
  82. var username = usernameInput.value.trim() || "root";
  83. var isValid = true;
  84. // Validate server input
  85. if (server === "") {
  86. msgbox("Server Name or IP Address is required", false, 5000);
  87. serverInput.focus();
  88. isValid = false;
  89. } else if (!isIpAddress(server) && !isDomainName(server)) {
  90. msgbox("Invalid Server Name or IP Address", false, 5000);
  91. serverInput.focus();
  92. isValid = false;
  93. }
  94. // Validate port input
  95. if (isNaN(port) || port < 2 || port > 65533) {
  96. msgbox("Port Number must be a number between 2 and 65533", false, 5000);
  97. portInput.focus();
  98. isValid = false;
  99. }
  100. if (isValid){
  101. //OK! Launch SSH terminal
  102. let settingPayload = {
  103. server: server,
  104. port: port,
  105. username: username
  106. }
  107. let settings = encodeURIComponent(JSON.stringify(settingPayload));
  108. launchToolWithSize('./tools/sshconn.html#' + settings,1000, 640);
  109. }else{
  110. }
  111. }
  112. // Returns true if the given string is a valid IP address
  113. function isIpAddress(str) {
  114. var pattern = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
  115. return pattern.test(str);
  116. }
  117. // Returns true if the given string is a valid domain name
  118. function isDomainName(str) {
  119. var pattern = /^[a-z\d\-]{1,63}(\.[a-z\d\-]{1,63})*$/i;
  120. return pattern.test(str);
  121. }
  122. validateForm();
  123. }
  124. </script>
  125. <script>
  126. function launchToolWithSize(url, width, height){
  127. let windowName = Date.now();
  128. window.open(url,'w'+windowName,
  129. `toolbar=no,
  130. location=no,
  131. status=no,
  132. menubar=no,
  133. scrollbars=yes,
  134. resizable=yes,
  135. width=${width},
  136. height=${height}`);
  137. }
  138. /*
  139. NIC Info
  140. */
  141. function renderNICInfo(){
  142. $.get("/api/stats/listnic",function(data){
  143. var tbody = document.querySelector("#network-interfaces-table tbody");
  144. data.forEach(function(item) {
  145. var tr = document.createElement("tr");
  146. var name = document.createElement("td");
  147. name.textContent = item.Name;
  148. var id = document.createElement("td");
  149. id.textContent = item.ID;
  150. var ips = document.createElement("td");
  151. ips.innerHTML = item.IPs.join("<br>");
  152. tr.appendChild(name);
  153. tr.appendChild(id);
  154. tr.appendChild(ips);
  155. tbody.appendChild(tr);
  156. });
  157. });
  158. }
  159. renderNICInfo();
  160. </script>