rules.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. <button class="ui basic button" onclick="newProxyEndpoint();"><i class="blue add icon"></i> Create Endpoint</button>
  36. <br><br>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="six wide column">
  42. <div class="ui basic segment" style="height: 100%; background-color: var(--theme_grey); color: var(--theme_lgrey);">
  43. <br>
  44. <span style="font-size: 1.2em; font-weight: 300;">Subdomain</span><br>
  45. Example of subdomain matching keyword:<br>
  46. <code>s1.arozos.com</code> <br>(Any access starting with s1.arozos.com will be proxy to the IP address below)<br>
  47. <div class="ui divider"></div>
  48. <span style="font-size: 1.2em; font-weight: 300;">Virtual Directory</span><br>
  49. Example of virtual directory name: <br>
  50. <code>/s1/home/</code> <br>(Any access to {this_server}/s1/home/ will be proxy to the IP address below)<br>
  51. You can also ignore the tailing slash for wildcard like usage.<br>
  52. <code>/s1/room-</code> <br>Any access to {this_server}/s1/classroom_* will be proxied, for example: <br>
  53. <div class="ui list">
  54. <div class="item"><code>/s1/room-101</code></div>
  55. <div class="item"><code>/s1/room-102/</code></div>
  56. <div class="item"><code>/s1/room-103/map.txt</code></div>
  57. </div><br>
  58. <br>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. <script>
  64. //New Proxy Endpoint
  65. function newProxyEndpoint(){
  66. var type = $("#ptype").val();
  67. var rootname = $("#rootname").val();
  68. var proxyDomain = $("#proxyDomain").val();
  69. var useTLS = $("#reqTls")[0].checked;
  70. if (type === "vdir") {
  71. if (!rootname.startsWith("/")) {
  72. rootname = "/" + rootname
  73. $("#rootname").val(rootname);
  74. }
  75. }else{
  76. if (!isSubdomainDomain(rootname)){
  77. //This doesn't seems like a subdomain
  78. if (!confirm(rootname + " does not looks like a subdomain. Continue anyway?")){
  79. return;
  80. }
  81. }
  82. }
  83. if (rootname.trim() == ""){
  84. $("#rootname").parent().addClass("error");
  85. return
  86. }else{
  87. $("#rootname").parent().removeClass("error");
  88. }
  89. if (proxyDomain.trim() == ""){
  90. $("#proxyDomain").parent().addClass("error");
  91. return
  92. }else{
  93. $("#proxyDomain").parent().removeClass("error");
  94. }
  95. //Create the endpoint by calling add
  96. $.ajax({
  97. url: "/api/proxy/add",
  98. data: {type: type, rootname: rootname, tls: useTLS, ep: proxyDomain},
  99. success: function(data){
  100. if (data.error != undefined){
  101. msgbox(data.error, false, 5000);
  102. }else{
  103. //OK
  104. listVdirs();
  105. listSubd();
  106. msgbox("Proxy Endpoint Added");
  107. //Clear old data
  108. $("#rootname").val("");
  109. $("#proxyDomain").val("");
  110. }
  111. }
  112. });
  113. }
  114. //Generic functions for delete rp endpoints
  115. function deleteEndpoint(ptype, epoint){
  116. if (confirm("Confirm remove proxy for :" + epoint + " (type: " + ptype + ")?")){
  117. $.ajax({
  118. url: "/api/proxy/del",
  119. data: {ep: epoint, ptype: ptype},
  120. success: function(){
  121. listVdirs();
  122. listSubd();
  123. }
  124. })
  125. }
  126. }
  127. function autoCheckTls(targetDomain){
  128. $.ajax({
  129. url: "/api/proxy/tlscheck",
  130. data: {url: targetDomain},
  131. success: function(data){
  132. if (data.error != undefined){
  133. }else if (data == "https"){
  134. $("#reqTls").parent().checkbox("set checked");
  135. }else if (data == "http"){
  136. $("#reqTls").parent().checkbox("set unchecked");
  137. }
  138. }
  139. })
  140. }
  141. //Check if a string is a valid subdomain
  142. function isSubdomainDomain(str) {
  143. const regex = /^(localhost|[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,}|[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,}\.)$/i;
  144. return regex.test(str);
  145. }
  146. </script>