rules.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <div class="ui stackable grid">
  2. <div class="ten wide column">
  3. <div class="standardContainer">
  4. <div class="ui basic segment" style="margin-top: 1em;">
  5. <h2>New Proxy Rule</h2>
  6. <p>You can create a proxy endpoing by subdomain or virtual directories</p>
  7. <div class="ui form">
  8. <div class="field">
  9. <label>Proxy Type</label>
  10. <div class="ui selection dropdown">
  11. <input type="hidden" id="ptype" value="subd">
  12. <i class="dropdown icon"></i>
  13. <div class="default text">Proxy Type</div>
  14. <div class="menu">
  15. <div class="item" data-value="subd">Sub-domain</div>
  16. <div class="item" data-value="vdir">Virtual Directory</div>
  17. </div>
  18. </div>
  19. </div>
  20. <div class="field">
  21. <label>Subdomain Matching Keyword / Virtual Directory Name</label>
  22. <input type="text" id="rootname" placeholder="s1.mydomain.com">
  23. </div>
  24. <div class="field">
  25. <label>IP Address or Domain Name with port</label>
  26. <input type="text" id="proxyDomain" onchange="autoCheckTls(this.value);">
  27. <small>E.g. 192.168.0.101:8000 or example.com</small>
  28. </div>
  29. <div class="field">
  30. <div class="ui checkbox">
  31. <input type="checkbox" id="reqTls">
  32. <label>Proxy Target require TLS Connection <br><small>(i.e. Your proxy target starts with https://)</small></label>
  33. </div>
  34. </div>
  35. <!-- Advance configs -->
  36. <div class="ui basic segment" style="background-color: #f7f7f7; border-radius: 1em;">
  37. <div id="advanceProxyRules" class="ui fluid accordion">
  38. <div class="title">
  39. <i class="dropdown icon"></i>
  40. Advance Settings
  41. </div>
  42. <div class="content">
  43. <p></p>
  44. <div class="field">
  45. <div class="ui checkbox">
  46. <input type="checkbox" id="skipTLSValidation">
  47. <label>Ignore TLS/SSL Verification Error<br><small>E.g. self-signed, expired certificate (Not Recommended)</small></label>
  48. </div>
  49. </div>
  50. <div class="field">
  51. <div class="ui checkbox">
  52. <input type="checkbox" id="requireBasicAuth">
  53. <label>Require Basic Auth<br><small>Require client to login in order to view the page</small></label>
  54. </div>
  55. </div>
  56. <div id="basicAuthCredentials" class="field">
  57. <p>Enter the username and password for allowing them to access this proxy endpoint</p>
  58. <table class="ui very basic celled table">
  59. <thead>
  60. <tr>
  61. <th>Username</th>
  62. <th>Password</th>
  63. <th>Remove</th>
  64. </tr></thead>
  65. <tbody id="basicAuthCredentialTable">
  66. <tr>
  67. <td colspan="3"><i class="ui green circle check icon"></i> No Entered Credential</td>
  68. </tr>
  69. </tbody>
  70. </table>
  71. <div class="three small fields credentialEntry">
  72. <div class="field">
  73. <input id="basicAuthCredUsername" type="text" placeholder="Username" autocomplete="off">
  74. </div>
  75. <div class="field">
  76. <input id="basicAuthCredPassword" type="password" placeholder="Password" autocomplete="off">
  77. </div>
  78. <div class="field">
  79. <button class="ui basic button" onclick="addCredentials();"><i class="blue add icon"></i> Add Credential</button>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. <br>
  87. <button class="ui basic button" onclick="newProxyEndpoint();"><i class="blue add icon"></i> Create Endpoint</button>
  88. <br><br>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <div class="six wide column">
  94. <div class="ui basic segment" style="height: 100%; background-color: var(--theme_grey); color: var(--theme_lgrey);">
  95. <br>
  96. <span style="font-size: 1.2em; font-weight: 300;">Subdomain</span><br>
  97. Example of subdomain matching keyword:<br>
  98. <code>s1.arozos.com</code> <br>(Any access starting with s1.arozos.com will be proxy to the IP address below)<br>
  99. <div class="ui divider"></div>
  100. <span style="font-size: 1.2em; font-weight: 300;">Virtual Directory</span><br>
  101. Example of virtual directory name: <br>
  102. <code>/s1/home/</code> <br>(Any access to {this_server}/s1/home/ will be proxy to the IP address below)<br>
  103. You can also ignore the tailing slash for wildcard like usage.<br>
  104. <code>/s1/room-</code> <br>Any access to {this_server}/s1/classroom_* will be proxied, for example: <br>
  105. <div class="ui list">
  106. <div class="item"><code>/s1/room-101</code></div>
  107. <div class="item"><code>/s1/room-102/</code></div>
  108. <div class="item"><code>/s1/room-103/map.txt</code></div>
  109. </div><br>
  110. <br>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. <script>
  116. $("#advanceProxyRules").accordion();
  117. //New Proxy Endpoint
  118. function newProxyEndpoint(){
  119. var type = $("#ptype").val();
  120. var rootname = $("#rootname").val();
  121. var proxyDomain = $("#proxyDomain").val();
  122. var useTLS = $("#reqTls")[0].checked;
  123. if (type === "vdir") {
  124. if (!rootname.startsWith("/")) {
  125. rootname = "/" + rootname
  126. $("#rootname").val(rootname);
  127. }
  128. }else{
  129. if (!isSubdomainDomain(rootname)){
  130. //This doesn't seems like a subdomain
  131. if (!confirm(rootname + " does not looks like a subdomain. Continue anyway?")){
  132. return;
  133. }
  134. }
  135. }
  136. if (rootname.trim() == ""){
  137. $("#rootname").parent().addClass("error");
  138. return
  139. }else{
  140. $("#rootname").parent().removeClass("error");
  141. }
  142. if (proxyDomain.trim() == ""){
  143. $("#proxyDomain").parent().addClass("error");
  144. return
  145. }else{
  146. $("#proxyDomain").parent().removeClass("error");
  147. }
  148. //Create the endpoint by calling add
  149. $.ajax({
  150. url: "/api/proxy/add",
  151. data: {type: type, rootname: rootname, tls: useTLS, ep: proxyDomain},
  152. success: function(data){
  153. if (data.error != undefined){
  154. msgbox(data.error, false, 5000);
  155. }else{
  156. //OK
  157. listVdirs();
  158. listSubd();
  159. msgbox("Proxy Endpoint Added");
  160. //Clear old data
  161. $("#rootname").val("");
  162. $("#proxyDomain").val("");
  163. }
  164. }
  165. });
  166. }
  167. //Generic functions for delete rp endpoints
  168. function deleteEndpoint(ptype, epoint){
  169. if (confirm("Confirm remove proxy for :" + epoint + " (type: " + ptype + ")?")){
  170. $.ajax({
  171. url: "/api/proxy/del",
  172. data: {ep: epoint, ptype: ptype},
  173. success: function(){
  174. listVdirs();
  175. listSubd();
  176. }
  177. })
  178. }
  179. }
  180. function autoCheckTls(targetDomain){
  181. $.ajax({
  182. url: "/api/proxy/tlscheck",
  183. data: {url: targetDomain},
  184. success: function(data){
  185. if (data.error != undefined){
  186. }else if (data == "https"){
  187. $("#reqTls").parent().checkbox("set checked");
  188. }else if (data == "http"){
  189. $("#reqTls").parent().checkbox("set unchecked");
  190. }
  191. }
  192. })
  193. }
  194. function toggleBasicAuth() {
  195. var basicAuthDiv = document.getElementById('basicAuthOnly');
  196. if ($("#requireBasicAuth").parent().checkbox("is checked")) {
  197. $("#basicAuthCredentials").removeClass("disabled");
  198. } else {
  199. $("#basicAuthCredentials").addClass("disabled");
  200. }
  201. }
  202. $("#requireBasicAuth").on('change', toggleBasicAuth);
  203. toggleBasicAuth();
  204. /*
  205. Credential Managements
  206. */
  207. let credentials = []; // Global variable to store credentials
  208. function addCredentials() {
  209. // Retrieve the username and password input values
  210. var username = $('#basicAuthCredUsername').val();
  211. var password = $('#basicAuthCredPassword').val();
  212. if(username == "" || password == ""){
  213. msgbox("Username or password cannot be empty", false, 5000);
  214. return;
  215. }
  216. // Create a new credential object
  217. var credential = {
  218. username: username,
  219. password: password
  220. };
  221. // Add the credential to the global credentials array
  222. credentials.push(credential);
  223. // Clear the input fields
  224. $('input[type="text"]').val('');
  225. $('input[type="password"]').val('');
  226. // Update the table body with the credentials
  227. updateTable();
  228. }
  229. function updateTable() {
  230. var tableBody = $('#basicAuthCredentialTable');
  231. tableBody.empty();
  232. if (credentials.length === 0) {
  233. tableBody.append('<tr><td colspan="3"><i class="ui green circle check icon"></i> No Entered Credential</td></tr>');
  234. } else {
  235. for (var i = 0; i < credentials.length; i++) {
  236. var credential = credentials[i];
  237. var username = credential.username;
  238. var password = credential.password.replace(/./g, '*'); // Replace each character with '*'
  239. var row = '<tr>' +
  240. '<td>' + username + '</td>' +
  241. '<td>' + password + '</td>' +
  242. '<td><button class="ui basic button" onclick="removeCredential(' + i + ');"><i class="red remove icon"></i> Remove</button></td>' +
  243. '</tr>';
  244. tableBody.append(row);
  245. }
  246. }
  247. }
  248. function removeCredential(index) {
  249. // Remove the credential from the credentials array
  250. credentials.splice(index, 1);
  251. // Update the table body
  252. updateTable();
  253. }
  254. //Check if a string is a valid subdomain
  255. function isSubdomainDomain(str) {
  256. const regex = /^(localhost|[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,}|[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,}\.)$/i;
  257. return regex.test(str);
  258. }
  259. </script>