rules.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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>
  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 type="text" placeholder="Username" autocomplete="off">
  74. </div>
  75. <div class="field">
  76. <input type="password" placeholder="Password" autocomplete="off">
  77. </div>
  78. <div class="field">
  79. <button class="ui basic button"><i class="blue add icon"></i> Add Credential</button>
  80. </div>
  81. </div>
  82. <div class="">
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. <br>
  89. <button class="ui basic button" onclick="newProxyEndpoint();"><i class="blue add icon"></i> Create Endpoint</button>
  90. <br><br>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. <div class="six wide column">
  96. <div class="ui basic segment" style="height: 100%; background-color: var(--theme_grey); color: var(--theme_lgrey);">
  97. <br>
  98. <span style="font-size: 1.2em; font-weight: 300;">Subdomain</span><br>
  99. Example of subdomain matching keyword:<br>
  100. <code>s1.arozos.com</code> <br>(Any access starting with s1.arozos.com will be proxy to the IP address below)<br>
  101. <div class="ui divider"></div>
  102. <span style="font-size: 1.2em; font-weight: 300;">Virtual Directory</span><br>
  103. Example of virtual directory name: <br>
  104. <code>/s1/home/</code> <br>(Any access to {this_server}/s1/home/ will be proxy to the IP address below)<br>
  105. You can also ignore the tailing slash for wildcard like usage.<br>
  106. <code>/s1/room-</code> <br>Any access to {this_server}/s1/classroom_* will be proxied, for example: <br>
  107. <div class="ui list">
  108. <div class="item"><code>/s1/room-101</code></div>
  109. <div class="item"><code>/s1/room-102/</code></div>
  110. <div class="item"><code>/s1/room-103/map.txt</code></div>
  111. </div><br>
  112. <br>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. <script>
  118. $("#advanceProxyRules").accordion();
  119. //New Proxy Endpoint
  120. function newProxyEndpoint(){
  121. var type = $("#ptype").val();
  122. var rootname = $("#rootname").val();
  123. var proxyDomain = $("#proxyDomain").val();
  124. var useTLS = $("#reqTls")[0].checked;
  125. if (type === "vdir") {
  126. if (!rootname.startsWith("/")) {
  127. rootname = "/" + rootname
  128. $("#rootname").val(rootname);
  129. }
  130. }else{
  131. if (!isSubdomainDomain(rootname)){
  132. //This doesn't seems like a subdomain
  133. if (!confirm(rootname + " does not looks like a subdomain. Continue anyway?")){
  134. return;
  135. }
  136. }
  137. }
  138. if (rootname.trim() == ""){
  139. $("#rootname").parent().addClass("error");
  140. return
  141. }else{
  142. $("#rootname").parent().removeClass("error");
  143. }
  144. if (proxyDomain.trim() == ""){
  145. $("#proxyDomain").parent().addClass("error");
  146. return
  147. }else{
  148. $("#proxyDomain").parent().removeClass("error");
  149. }
  150. //Create the endpoint by calling add
  151. $.ajax({
  152. url: "/api/proxy/add",
  153. data: {type: type, rootname: rootname, tls: useTLS, ep: proxyDomain},
  154. success: function(data){
  155. if (data.error != undefined){
  156. msgbox(data.error, false, 5000);
  157. }else{
  158. //OK
  159. listVdirs();
  160. listSubd();
  161. msgbox("Proxy Endpoint Added");
  162. //Clear old data
  163. $("#rootname").val("");
  164. $("#proxyDomain").val("");
  165. }
  166. }
  167. });
  168. }
  169. //Generic functions for delete rp endpoints
  170. function deleteEndpoint(ptype, epoint){
  171. if (confirm("Confirm remove proxy for :" + epoint + " (type: " + ptype + ")?")){
  172. $.ajax({
  173. url: "/api/proxy/del",
  174. data: {ep: epoint, ptype: ptype},
  175. success: function(){
  176. listVdirs();
  177. listSubd();
  178. }
  179. })
  180. }
  181. }
  182. function autoCheckTls(targetDomain){
  183. $.ajax({
  184. url: "/api/proxy/tlscheck",
  185. data: {url: targetDomain},
  186. success: function(data){
  187. if (data.error != undefined){
  188. }else if (data == "https"){
  189. $("#reqTls").parent().checkbox("set checked");
  190. }else if (data == "http"){
  191. $("#reqTls").parent().checkbox("set unchecked");
  192. }
  193. }
  194. })
  195. }
  196. function toggleBasicAuth() {
  197. var basicAuthDiv = document.getElementById('basicAuthOnly');
  198. if ($("#requireBasicAuth").parent().checkbox("is checked")) {
  199. $("#basicAuthCredentials").removeClass("disabled");
  200. } else {
  201. $("#basicAuthCredentials").addClass("disabled");
  202. }
  203. }
  204. $("#requireBasicAuth").on('change', toggleBasicAuth);
  205. toggleBasicAuth();
  206. //Check if a string is a valid subdomain
  207. function isSubdomainDomain(str) {
  208. const regex = /^(localhost|[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,}|[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,}\.)$/i;
  209. return regex.test(str);
  210. }
  211. </script>