networktools.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 id="websshTool" 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. <h2>Wake On LAN</h2>
  48. <p>Wake up a remote server by WOL Magic Packet or an IoT device</p>
  49. </div>
  50. <div class="ui bottom attached tab segment" data-tab="tab3">
  51. <h2>Network Interfaces</h2>
  52. <p>Network Interface Card (NIC) currently installed on this host</p>
  53. <table id="network-interfaces-table" class="ui selectable inverted striped celled table">
  54. <thead>
  55. <tr>
  56. <th>Interface Name</th>
  57. <th>ID</th>
  58. <th>IP Address</th>
  59. </tr>
  60. </thead>
  61. <tbody></tbody>
  62. </table>
  63. </div>
  64. </div>
  65. <script>
  66. // Activate the default tab
  67. $('.menu .nettools.item').tab();
  68. $('.menu .nettools.item').addClass("activated");
  69. // Switch tabs when clicking on the menu items
  70. $('.menu .nettools.item').on('click', function() {
  71. $('.menu .item').removeClass('active');
  72. $(this).addClass('active');
  73. var tab = $(this).attr('data-tab');
  74. $('.tab.segment').removeClass('active');
  75. $('div[data-tab="' + tab + '"]').addClass('active');
  76. });
  77. //Check if web.ssh is supported
  78. function checkWebSSHSupport(){
  79. $.get("/api/tools/websshSupported", function(data){
  80. if (data == false){
  81. $("#websshTool").css({
  82. "opacity": "0.6",
  83. "pointer-events": "none",
  84. "user-select": "none",
  85. });
  86. $("#websshTool").find("button").addClass("disabled");
  87. }
  88. })
  89. }
  90. checkWebSSHSupport();
  91. //Connect SSH using web.ssh tool
  92. function connectSSH(){
  93. function validateForm() {
  94. var serverInput = document.getElementById("ssh_server");
  95. var portInput = document.getElementById("ssh_port");
  96. var usernameInput = document.getElementById("ssh_username");
  97. var server = serverInput.value.trim();
  98. var port = parseInt(portInput.value.trim() || "22");
  99. var username = usernameInput.value.trim() || "root";
  100. var isValid = true;
  101. // Validate server input
  102. if (server === "") {
  103. msgbox("Server Name or IP Address is required", false, 5000);
  104. serverInput.focus();
  105. isValid = false;
  106. } else if (!isIpAddress(server) && !isDomainName(server)) {
  107. msgbox("Invalid Server Name or IP Address", false, 5000);
  108. serverInput.focus();
  109. isValid = false;
  110. }
  111. // Validate port input
  112. if (isNaN(port) || port < 2 || port > 65533) {
  113. msgbox("Port Number must be a number between 2 and 65533", false, 5000);
  114. portInput.focus();
  115. isValid = false;
  116. }
  117. if (isValid){
  118. //OK! Launch SSH terminal
  119. let settingPayload = {
  120. server: server,
  121. port: port,
  122. username: username
  123. }
  124. let settings = encodeURIComponent(JSON.stringify(settingPayload));
  125. launchToolWithSize('./tools/sshconn.html#' + settings,1000, 640);
  126. }else{
  127. }
  128. }
  129. // Returns true if the given string is a valid IP address
  130. function isIpAddress(str) {
  131. var pattern = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
  132. return pattern.test(str);
  133. }
  134. // Returns true if the given string is a valid domain name
  135. function isDomainName(str) {
  136. var pattern = /^[a-z\d\-]{1,63}(\.[a-z\d\-]{1,63})*$/i;
  137. return pattern.test(str);
  138. }
  139. validateForm();
  140. }
  141. </script>
  142. <script>
  143. function launchToolWithSize(url, width, height){
  144. let windowName = Date.now();
  145. window.open(url,'w'+windowName,
  146. `toolbar=no,
  147. location=no,
  148. status=no,
  149. menubar=no,
  150. scrollbars=yes,
  151. resizable=yes,
  152. width=${width},
  153. height=${height}`);
  154. }
  155. /*
  156. NIC Info
  157. */
  158. function renderNICInfo(){
  159. $.get("/api/stats/listnic",function(data){
  160. var tbody = document.querySelector("#network-interfaces-table tbody");
  161. data.forEach(function(item) {
  162. var tr = document.createElement("tr");
  163. var name = document.createElement("td");
  164. name.textContent = item.Name;
  165. var id = document.createElement("td");
  166. id.textContent = item.ID;
  167. var ips = document.createElement("td");
  168. ips.innerHTML = item.IPs.join("<br>");
  169. tr.appendChild(name);
  170. tr.appendChild(id);
  171. tr.appendChild(ips);
  172. tbody.appendChild(tr);
  173. });
  174. });
  175. }
  176. renderNICInfo();
  177. </script>