accesscontrol.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Access Control</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  7. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  8. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  9. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  10. <style>
  11. a.pageFocus {
  12. background: #222222;
  13. color: white !important;
  14. border-radius: 50%;
  15. -moz-border-radius: 50%;
  16. -webkit-border-radius: 50%;
  17. display: inline-block;
  18. font-weight: bold;
  19. line-height: 30px;
  20. margin-right: 2px;
  21. text-align: center;
  22. width: 30px;
  23. }
  24. .noselect {
  25. -webkit-touch-callout: none; /* iOS Safari */
  26. -webkit-user-select: none; /* Safari */
  27. -khtml-user-select: none; /* Konqueror HTML */
  28. -moz-user-select: none; /* Old versions of Firefox */
  29. -ms-user-select: none; /* Internet Explorer/Edge */
  30. user-select: none; /* Non-prefixed version, currently
  31. supported by Chrome, Edge, Opera and Firefox */
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <br>
  37. <div class="ui container" style="height: 100% !important;">
  38. <div>
  39. <h3 class="ui header">
  40. Access Control
  41. <div class="sub header">Manage IPs from logging into this host</div>
  42. </h3>
  43. <div class="ui divider"></div>
  44. <h3><i class="ui green checkmark icon"></i> Whitelist</h3>
  45. <div class="ui toggle checkbox">
  46. <input type="checkbox" id="enableWhiteList" onchange="">
  47. <label>Enable Whitelist Filtering</label>
  48. </div>
  49. <div class="ui inverted green segment" id="whitelistUpdateFeedback" style="display:none;">
  50. <i class="ui checkmark icon"></i> Whitelist Status Updated
  51. </div>
  52. <div class="ui basic segment">
  53. <p>Add or Remove new whitelisted IP range</p>
  54. <div class="ui action fluid input">
  55. <input type="text" id="whitelistIpRange" placeholder="192.168.1.100 - 192.168.1.250">
  56. <button class="ui green button" onclick="whitelistIpRange();"><i class="ui checkmark icon"></i> Add</button>
  57. </div>
  58. <table class="ui celled table">
  59. <thead>
  60. <tr><th>IP Range</th>
  61. <th>Remove</th>
  62. </tr></thead>
  63. <tbody id="whitelistTable">
  64. </tbody>
  65. </table>
  66. </div>
  67. <div class="ui divider"></div>
  68. <h3><i class="ui red remove icon"></i> Blacklist</h3>
  69. <div class="ui toggle checkbox">
  70. <input type="checkbox" id="enableBlacklist" onchange="updateBlacklistEnableState(this.checked);">
  71. <label>Enable Blacklist Filtering</label>
  72. </div>
  73. <div class="ui inverted green segment" id="blacklistUpdateFeedback" style="display:none;">
  74. <i class="ui checkmark icon"></i> Blacklist Status Updated
  75. </div>
  76. <div class="ui basic segment">
  77. <p>Add or Remove new banned IP range</p>
  78. <div class="ui action fluid input">
  79. <input type="text" id="blacklistIpRange" placeholder="192.168.1.100 - 192.168.1.250">
  80. <button class="ui red button" onclick="blacklistIpRange();"><i class="ui lock icon"></i> Ban</button>
  81. </div>
  82. <table class="ui celled table">
  83. <thead>
  84. <tr><th>IP Range</th>
  85. <th>Unban</th>
  86. </tr></thead>
  87. <tbody id="blacklisttable">
  88. </tbody>
  89. </table>
  90. </div>
  91. <!--
  92. <div class="ui divider"></div>
  93. <h3>Regional Block</h3>
  94. -->
  95. <div class="ui divider"></div>
  96. <div class="ui grey message">
  97. <p><i class="ui info circle icon"></i> For Whitelist and Blacklist, you can enter either a single IP or an IP range. IP range syntax examples as follows.</p>
  98. <div class="ui bulleted list">
  99. <div class="item">192.168.1.100</div>
  100. <div class="item">123.36.53.100</div>
  101. <div class="item">192.168.0.100 - 192.168.0.250</div>
  102. </div>
  103. </div>
  104. <br><br>
  105. </div>
  106. <script>
  107. //Init
  108. var preloading = true;
  109. $(".checkbox").checkbox();
  110. initBlacklist();
  111. initWhiteList();
  112. /*
  113. Whitelist Related
  114. */
  115. function initWhiteList(){
  116. //Get the whitelist enable state
  117. $.get("../../system/auth/whitelist/enable", function(data){
  118. if (data == true){
  119. //Whitelist is enabled
  120. $("#enableWhiteList").parent().checkbox("set checked");
  121. }else{
  122. $("#enableWhiteList").parent().checkbox("set unchecked");
  123. }
  124. $("#enableWhiteList").on("change", function(){
  125. //Toggle enable
  126. $.ajax({
  127. url: "../../system/auth/whitelist/enable",
  128. method: "POST",
  129. data: {enable: this.checked},
  130. success: function(data){
  131. $("#whitelistUpdateFeedback").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  132. }
  133. })
  134. })
  135. });
  136. //Get the whitelist table
  137. $("#whitelistTable").html(`<tr>
  138. <td colspan="3"><i class="loading spinner icon"></i> Loading</td>
  139. </tr>`);
  140. $.get("../../system/auth/whitelist/list", function(data){
  141. $("#whitelistTable").html('');
  142. data.forEach(entry => {
  143. //Strip out all space from record
  144. displayEntry = entry.split(" ").join("");
  145. //Check if this is reserved ip range
  146. var enableRemove = true;
  147. if (entry == "127.0.0.1"){
  148. enableRemove = false;
  149. }
  150. var removeButtonClass = ""
  151. if (!enableRemove){
  152. removeButtonClass = "disabled";
  153. }
  154. $("#whitelistTable").append(`<tr>
  155. <td>${displayEntry}</td>
  156. <td><button class="ui basic red ${removeButtonClass} icon button" onclick="removeWhitelistforIpRange(this);" range="${entry}"><i class="ui white remove icon"></i></button></td>
  157. </tr>`);
  158. })
  159. if (data.length == 0){
  160. $("#whitelistTable").html(`<tr>
  161. <td colspan="3"><i class="remove icon"></i> No Whitelisted IPs</td>
  162. </tr>`);
  163. }
  164. });
  165. }
  166. function whitelistIpRange(){
  167. var targetIP = $("#whitelistIpRange").val();
  168. $.ajax({
  169. url: "../../system/auth/whitelist/set",
  170. method: "POST",
  171. data: {iprange: targetIP},
  172. success: function(data){
  173. if (data.error != undefined){
  174. alert(data.error);
  175. }else{
  176. $("#whitelistIpRange").val('')
  177. initWhiteList();
  178. }
  179. }
  180. });
  181. }
  182. function removeWhitelistforIpRange(object){
  183. var unbanIpRange = $(object).attr("range");
  184. $.ajax({
  185. url: "../../system/auth/whitelist/unset",
  186. method: "POST",
  187. data: {iprange: unbanIpRange},
  188. success: function(data){
  189. if (data.error != undefined){
  190. alert(data.error);
  191. }else{
  192. $("#whitelistIpRange").val('')
  193. initWhiteList();
  194. }
  195. }
  196. });
  197. }
  198. /*
  199. Blacklist Related
  200. */
  201. function initBlacklist(){
  202. //Get the Blacklist enable state
  203. $.get("../../system/auth/blacklist/enable", function(data){
  204. if (data == true){
  205. //Blacklist is enabled
  206. $("#enableBlacklist").parent().checkbox("set checked");
  207. }else{
  208. $("#enableBlacklist").parent().checkbox("set unchecked");
  209. }
  210. preloading = false;
  211. });
  212. //Get the Blacklist table
  213. $("#blacklisttable").html(`<tr>
  214. <td colspan="3"><i class="loading spinner icon"></i> Loading</td>
  215. </tr>`);
  216. $.get("../../system/auth/blacklist/list", function(data){
  217. $("#blacklisttable").html('');
  218. data.forEach(entry => {
  219. //Strip out all space from record
  220. displayEntry = entry.split(" ").join("");
  221. $("#blacklisttable").append(`<tr>
  222. <td>${displayEntry}</td>
  223. <td><button class="ui green icon button" onclick="removeBlacklistforIpRange(this);" range="${entry}"><i class="ui white lock open icon"></i></button></td>
  224. </tr>`);
  225. })
  226. if (data.length == 0){
  227. $("#blacklisttable").html(`<tr>
  228. <td colspan="3"><i class="remove icon"></i> No Banned IPs</td>
  229. </tr>`);
  230. }
  231. })
  232. }
  233. function updateBlacklistEnableState(enabled){
  234. if (preloading){
  235. //Do not update status during preload stage
  236. return;
  237. }
  238. $.ajax({
  239. url: "../../system/auth/blacklist/enable",
  240. method: "POST",
  241. data: {enable: enabled},
  242. success: function(data){
  243. $("#blacklistUpdateFeedback").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  244. }
  245. })
  246. }
  247. function blacklistIpRange(){
  248. var targetIP = $("#blacklistIpRange").val();
  249. $.ajax({
  250. url: "../../system/auth/blacklist/ban",
  251. method: "POST",
  252. data: {iprange: targetIP},
  253. success: function(data){
  254. if (data.error != undefined){
  255. alert(data.error);
  256. }else{
  257. $("#blacklistIpRange").val('')
  258. initBlacklist();
  259. }
  260. }
  261. });
  262. }
  263. function removeBlacklistforIpRange(object){
  264. var unbanIpRange = $(object).attr("range");
  265. $.ajax({
  266. url: "../../system/auth/blacklist/unban",
  267. method: "POST",
  268. data: {iprange: unbanIpRange},
  269. success: function(data){
  270. if (data.error != undefined){
  271. alert(data.error);
  272. }else{
  273. $("#blacklistIpRange").val('')
  274. initBlacklist();
  275. }
  276. }
  277. });
  278. }
  279. </script>
  280. </body>
  281. </html>