1
0

hostAccessEditor.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!-- Notes: This should be open in its original path-->
  5. <meta charset="utf-8">
  6. <meta name="zoraxy.csrf.Token" content="{{.csrfToken}}">
  7. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  8. <script src="../script/jquery-3.6.0.min.js"></script>
  9. <script src="../script/semantic/semantic.min.js"></script>
  10. <script src="../script/utils.js"></script>
  11. <style>
  12. .accessRule{
  13. cursor: pointer;
  14. border-radius: 0.4em !important;
  15. border: 1px solid rgb(233, 233, 233) !important;
  16. }
  17. .accessRule:hover{
  18. background-color: rgb(241, 241, 241) !important;
  19. }
  20. .accessRule.active{
  21. background-color: rgb(241, 241, 241) !important;
  22. }
  23. .accessRule .selected{
  24. position: absolute;
  25. top: 1em;
  26. right: 0.6em;
  27. }
  28. .accessRule:not(.active) .selected{
  29. display:none;
  30. }
  31. #accessRuleList{
  32. padding: 0.6em;
  33. border: 1px solid rgb(228, 228, 228);
  34. border-radius: 0.4em !important;
  35. max-height: calc(100vh - 15em);
  36. min-height: 300px;
  37. overflow-y: auto;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <br>
  43. <div class="ui container">
  44. <div class="ui header">
  45. <div class="content">
  46. Host Access Settings
  47. <div class="sub header" id="epname"></div>
  48. </div>
  49. </div>
  50. <div class="ui divider"></div>
  51. <p>Select an access rule to apply blacklist / whitelist filtering</p>
  52. <div id="accessRuleList">
  53. <div class="ui segment accessRule">
  54. <div class="ui header">
  55. <i class="filter icon"></i>
  56. <div class="content">
  57. Account Settings
  58. <div class="sub header">Manage your preferences</div>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. <br>
  64. <button class="ui basic button" onclick="applyChangeAndClose()"><i class="ui green check icon"></i> Apply Change</button>
  65. <button class="ui basic button" style="float: right;" onclick="parent.hideSideWrapper();"><i class="remove icon"></i> Close</button>
  66. <br><br><br>
  67. </div>
  68. <script>
  69. let editingEndpoint = {};
  70. if (window.location.hash.length > 1){
  71. let payloadHash = window.location.hash.substr(1);
  72. try{
  73. payloadHash = JSON.parse(decodeURIComponent(payloadHash));
  74. $("#epname").text(payloadHash.ep);
  75. editingEndpoint = payloadHash;
  76. }catch(ex){
  77. console.log("Unable to load endpoint data from hash")
  78. }
  79. }
  80. function initAccessRuleList(callback = undefined){
  81. $("#accessRuleList").html("<small>Loading</small>");
  82. $.get("/api/access/list", function(data){
  83. if (data.error == undefined){
  84. $("#accessRuleList").html("");
  85. data.forEach(function(rule){
  86. let icon = `<i class="ui grey filter icon"></i>`;
  87. if (rule.ID == "default"){
  88. icon = `<i class="ui yellow star icon"></i>`;
  89. }else if (rule.BlacklistEnabled && !rule.WhitelistEnabled){
  90. //This is a blacklist filter
  91. icon = `<i class="ui red filter icon"></i>`;
  92. }else if (rule.WhitelistEnabled && !rule.BlacklistEnabled){
  93. //This is a whitelist filter
  94. icon = `<i class="ui green filter icon"></i>`;
  95. }else if (rule.WhitelistEnabled && rule.BlacklistEnabled){
  96. //Whitelist and blacklist filter
  97. icon = `<i class="ui yellow filter icon"></i>`;
  98. }
  99. $("#accessRuleList").append(`<div class="ui basic segment accessRule" ruleid="${rule.ID}" onclick="selectThisRule(this);">
  100. <h5 class="ui header">
  101. ${icon}
  102. <div class="content">
  103. ${rule.Name}
  104. <div class="sub header">${rule.ID}</div>
  105. </div>
  106. </h5>
  107. <p>${rule.Desc}</p>
  108. ${rule.BlacklistEnabled?`<small><i class="ui red filter icon"></i> Blacklist Enabled</small>`:""}
  109. ${rule.WhitelistEnabled?`<small><i class="ui green filter icon"></i> Whitelist Enabled</small>`:""}
  110. <div class="selected"><i class="ui large green check icon"></i></div>
  111. </div>`);
  112. });
  113. accessRuleList = data;
  114. $(".dropdown").dropdown();
  115. if (callback != undefined){
  116. callback();
  117. }
  118. }
  119. });
  120. }
  121. initAccessRuleList(function(){
  122. $.cjax({
  123. url: "/api/proxy/detail",
  124. method: "POST",
  125. data: {"type":"host", "epname": editingEndpoint.ep },
  126. success: function(data){
  127. console.log(data);
  128. if (data.error != undefined){
  129. alert(data.error);
  130. }else{
  131. let currentAccessFilter = data.AccessFilterUUID;
  132. if (currentAccessFilter == ""){
  133. //Use default
  134. currentAccessFilter = "default";
  135. }
  136. $(`.accessRule[ruleid=${currentAccessFilter}]`).addClass("active");
  137. }
  138. }
  139. })
  140. });
  141. function selectThisRule(accessRuleObject){
  142. let accessRuleID = $(accessRuleObject).attr("ruleid");
  143. $(".accessRule").removeClass('active');
  144. $(accessRuleObject).addClass('active');
  145. }
  146. function applyChangeAndClose(){
  147. let newAccessRuleID = $(".accessRule.active").attr("ruleid");
  148. let targetEndpoint = editingEndpoint.ep;
  149. $.cjax({
  150. url: "/api/access/attach",
  151. method: "POST",
  152. data: {
  153. id: newAccessRuleID,
  154. host: targetEndpoint
  155. },
  156. success: function(data){
  157. if (data.error != undefined){
  158. parent.msgbox(data.error, false);
  159. }else{
  160. parent.msgbox("Access Rule Updated");
  161. //Modify the parent list if exists
  162. if (parent != undefined && parent.updateAccessRuleNameUnderHost){
  163. parent.updateAccessRuleNameUnderHost(targetEndpoint, newAccessRuleID);
  164. }
  165. parent.hideSideWrapper();
  166. }
  167. }
  168. })
  169. }
  170. </script>
  171. </body>
  172. </html>