gan.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <div id="ganetWindow" class="standardContainer">
  2. <div class="ui basic segment">
  3. <h2>Global Area Network</h2>
  4. <p>Virtual Network Hub that allows all networked devices to communicate as if they all reside in the same physical data center or cloud region</p>
  5. </div>
  6. <div class="gansnetworks">
  7. <div class="ganstats">
  8. <div class="ui list">
  9. <div class="item">
  10. <i class="exchange icon"></i>
  11. <div class="content">
  12. <div class="header" style="font-size: 1.2em;" id="ganetCount">0</div>
  13. <div class="description">Networks</div>
  14. </div>
  15. </div>
  16. <div class="item">
  17. <i class="desktop icon"></i>
  18. <div class="content">
  19. <div class="header" style="font-size: 1.2em;" id="ganodeCount">0</div>
  20. <div class="description">Connected Nodes</div>
  21. </div>
  22. </div>
  23. </div>
  24. <br>
  25. </div>
  26. <div class="ganlist">
  27. <button class="ui basic orange button" onclick="$('#newGanForm').fadeToggle('fast');">Create New Network</button>
  28. <div class="" id="newGanForm" style="display:none; position: relative;">
  29. <div class="ui divider"></div>
  30. <p>Enter a new network name to create new network</p>
  31. <div class="ui action fluid input">
  32. <input type="text" id="networkName" placeholder="Network Name">
  33. <button class="ui basic button" onclick="handleAddNetwork();">
  34. <i class="blue add icon"></i> Add Network
  35. </button>
  36. </div>
  37. <button onclick="$('#newGanForm').fadeOut('fast');" class="ui mini circular basic icon button" style="position: absolute; right: 0.4em; top: 1em;"><i class="remove icon"></i></button>
  38. </div>
  39. <div class="ui divider"></div>
  40. <div class="ui icon input" style="margin-bottom: 1em;">
  41. <input type="text" placeholder="Search a Network">
  42. <i class="circular search link icon"></i>
  43. </div>
  44. <div style="width: 100%; overflow-x: auto;">
  45. <table class="ui celled basic unstackable striped table">
  46. <thead>
  47. <tr>
  48. <th>Network ID</th>
  49. <th>Name</th>
  50. <th>Description</th>
  51. <th>Subnet</th>
  52. <th>Nodes</th>
  53. <th>Actions</th>
  54. </tr>
  55. </thead>
  56. <tbody id="GANetList">
  57. <tr>
  58. <td colspan="6"><i class="ui green circle check icon"></i> No Global Area Network Found on this host</td>
  59. </tr>
  60. </tbody>
  61. </table>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <script>
  67. /*
  68. Network Management Functions
  69. */
  70. function handleAddNetwork(){
  71. let networkName = $("#networkName").val().trim();
  72. if (networkName == ""){
  73. msgbox("Network name cannot be empty", false, 5000);
  74. return;
  75. }
  76. //Add network with default settings
  77. addGANet(networkName, "192.168.196.0/24");
  78. $("#networkName").val("");
  79. }
  80. function addGANet(name, subnetMask) {
  81. $.ajax({
  82. url: "/api/gan/network/add",
  83. type: "POST",
  84. dataType: "json",
  85. data: {
  86. name: name,
  87. subnetMask: subnetMask
  88. },
  89. success: function(response) {
  90. if (response.error != undefined){
  91. msgbox(response.error, false, 5000);
  92. }else{
  93. msgbox("Network added successfully");
  94. }
  95. console.log("Network added successfully:", response);
  96. listGANet();
  97. },
  98. error: function(xhr, status, error) {
  99. console.log("Error adding network:", error);
  100. }
  101. });
  102. }
  103. function listGANet(){
  104. $.get("/api/gan/network/list", function(data){
  105. $("#GANetList").empty();
  106. if (data.error != undefined){
  107. msgbox(data.error, false, 5000);
  108. }else{
  109. var nodeCount = 0;
  110. data.forEach(function(gan){
  111. $("#GANetList").append(`<tr>
  112. <td>${gan.UID}</td>
  113. <td>${gan.Name}</td>
  114. <td>${gan.Description}</td>
  115. <td>${gan.CIDR}</td>
  116. <td>${gan.Nodes.length}</td>
  117. <td>
  118. <button onclick="openGANetDetails('${gan.UID}');" class="ui tiny basic icon button" title="Edit Network"><i class="edit icon"></i></button>
  119. <button onclick="removeGANet('${gan.UID}');" class="ui tiny basic icon button" title="Remove Network"><i class="red remove icon"></i></button>
  120. </td>
  121. </tr>`);
  122. nodeCount += gan.Nodes.length;
  123. });
  124. if (data.length == 0){
  125. $("#GANetList").append(`<tr>
  126. <td colspan="6"><i class="ui green circle check icon"></i> No Global Area Network Found on this host</td>
  127. </tr>`);
  128. }
  129. $("#ganodeCount").text(nodeCount);
  130. $("#ganetCount").text(data.length);
  131. }
  132. })
  133. }
  134. //Remove the given GANet
  135. function removeGANet(netid){
  136. if (confirm("Confirm remove Network " + netid + " PERMANENTLY ?"))
  137. $.ajax({
  138. url: "/api/gan/network/remove",
  139. type: "POST",
  140. dataType: "json",
  141. data: {
  142. id: netid,
  143. },
  144. success: function(data){
  145. if (data.error != undefined){
  146. msgbox(data.error, false, 5000);
  147. }else{
  148. msgbox("Net " + netid + " removed");
  149. }
  150. listGANet();
  151. }
  152. });
  153. }
  154. function openGANetDetails(netid){
  155. $("#ganetWindow").load("./components/gandetails.html", function(){
  156. setTimeout(function(){
  157. initGanetDetails(netid);
  158. });
  159. });
  160. }
  161. //Bind event to tab switch
  162. tabSwitchEventBind["gan"] = function(){
  163. //On switch over to this page, load info
  164. listGANet();
  165. }
  166. </script>