info.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Disk Info</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" >
  7. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  8. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" />
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
  10. <style>
  11. body{
  12. background-color: rgb(243, 243, 243);
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <br>
  18. <div class="ui container">
  19. <div class="ui segment">
  20. <h3 class="ui header">
  21. <img src="img/network.svg">
  22. <div class="content">
  23. Network Storage
  24. <div class="sub header">Total space used on SD card</div>
  25. </div>
  26. </h3>
  27. <div class="ui blue progress" style="margin-bottom: 0.3em;">
  28. <div id="spaceUsedBar" class="bar" style="width: 30%;">
  29. <div class="progress">Loading...</div>
  30. </div>
  31. </div>
  32. <p id="volText"></p>
  33. <button onclick="initSDCardInfo();" style="position: absolute; top: 0.6em; right: 0.6em;" class="ui circular icon right floated basic button"><i class="ui green refresh icon"></i></button>
  34. </div>
  35. <div class="ui segment">
  36. <h3 class="ui header">
  37. <img src="img/cluster.svg">
  38. <div class="content">
  39. Wake-On-Lan
  40. <div class="sub header">Power on a host in LAN by sending WoL magic packet</div>
  41. </div>
  42. </h3>
  43. <p>Target host MAC address (in XX:XX:XX:XX:XX:XX format)</p>
  44. <div class="ui action small fluid input">
  45. <input type="text" id="targetMacAddress" placeholder="MAC Address">
  46. <button class="ui basic button" onclick="sendWakeOnLan();"><i class="green power icon"></i> Power-On</button>
  47. </div>
  48. </div>
  49. <div class="ui segment">
  50. <h3 class="ui header">
  51. <img src="img/wifi.svg">
  52. <div class="content">
  53. Network Details
  54. <div class="sub header">WiFi information for the current connected AP</div>
  55. </div>
  56. </h3>
  57. <div class="ui text container">
  58. <table class="ui very basic celled small table">
  59. <tbody id="wifiInfoTable">
  60. <tr>
  61. <td colspan="2"><i class="ui loading spinner icon"></i> Loading</td>
  62. </tr>
  63. </tbody>
  64. </table>
  65. </div>
  66. </div>
  67. <div class="ui divider"></div>
  68. <p>WebStick Management Interface designed by <a href="https://imuslab.com" target="_blank">tobychui</a></p>
  69. <br>
  70. </div>
  71. <script>
  72. function initWiFiInfo(){
  73. $.get("/api/info/wifi", function(data){
  74. if (data.error == undefined){
  75. $("#wifiInfoTable").empty();
  76. $("#wifiInfoTable").append(`
  77. <tr>
  78. <td>SSID</td>
  79. <td>${data.SSID}</td>
  80. </tr>
  81. <tr>
  82. <td>Wifi Channel</td>
  83. <td>${data.WifiStatus}</td>
  84. </tr>
  85. <tr>
  86. <td>Wifi Strength</td>
  87. <td>${data.WifiStrength}</td>
  88. </tr>
  89. <tr>
  90. <td>MAC Address</td>
  91. <td>${data.MAC}</td>
  92. </tr>
  93. <tr>
  94. <td>IP Address</td>
  95. <td>${data.IP}</td>
  96. </tr>
  97. <tr>
  98. <td>Subnet Mask</td>
  99. <td>${data.Subnet}</td>
  100. </tr>
  101. <tr>
  102. <td>Gateway</td>
  103. <td>${data.Gateway}</td>
  104. </tr>
  105. <tr>
  106. <td>DNS1</td>
  107. <td>${data.DNS1}</td>
  108. </tr>
  109. <tr>
  110. <td>DNS2</td>
  111. <td>${data.DNS2}</td>
  112. </tr>
  113. <tr>
  114. <td>DNS3</td>
  115. <td>${data.DNS3}</td>
  116. </tr>
  117. `);
  118. }
  119. });
  120. }
  121. initWiFiInfo();
  122. function initSDCardInfo(){
  123. $("#spaceUsedBar").find(".progress").text("Loading...");
  124. $.get("/api/fs/disk", function(data){
  125. if (data.error != undefined){
  126. alert(data.error);
  127. return;
  128. }
  129. let usedPercentage = data.usedSpace / data.diskSpace * 100;
  130. $("#spaceUsedBar").css("width", usedPercentage + "%");
  131. $("#spaceUsedBar").find(".progress").text(Math.round(usedPercentage) + "%");
  132. $("#volText").text(`Used: ${humanFileSize(data.usedSpace)} / Total: ${humanFileSize(data.diskSpace)}`);
  133. });
  134. }
  135. initSDCardInfo();
  136. //Send wake on lan package
  137. function sendWakeOnLan(){
  138. var macAddr= $("#targetMacAddress").val().trim();
  139. var regex = /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/;
  140. if (!regex.test(macAddr)){
  141. alert(macAddr + " is not a valid MAC address");
  142. return;
  143. }
  144. $.get("/api/wol?mac=" + macAddr, function(data){
  145. if (data.error != undefined){
  146. alert(data.error);
  147. }else{
  148. alert("WoL magic packet sent!")
  149. }
  150. })
  151. }
  152. //Send ICMP Ping
  153. function pingTarget(){
  154. var ipaddress = $("#targetIpAddr").val().trim();
  155. if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) {
  156. $.get("/api/ping?ipaddr=" + ipaddress, function(data){
  157. alert(data);
  158. })
  159. }else{
  160. alert("Invalid ip address given");
  161. }
  162. }
  163. function humanFileSize(bytes, si=false, dp=1) {
  164. const thresh = si ? 1000 : 1024;
  165. if (Math.abs(bytes) < thresh) {
  166. return bytes + ' B';
  167. }
  168. const units = si
  169. ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
  170. : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
  171. let u = -1;
  172. const r = 10**dp;
  173. do {
  174. bytes /= thresh;
  175. ++u;
  176. } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
  177. return bytes.toFixed(dp) + ' ' + units[u];
  178. }
  179. //Check login status
  180. function initLoginCheck(){
  181. $.get("/api/auth/chk", function(data){
  182. if (data == false){
  183. window.location.href = "/login.html"
  184. }
  185. });
  186. }
  187. initLoginCheck();
  188. </script>
  189. </body>
  190. </html>