rules.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/ will be proxy to the IP address below)<br>
  51. <br>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. <script>
  57. //New Proxy Endpoint
  58. function newProxyEndpoint(){
  59. var type = $("#ptype").val();
  60. var rootname = $("#rootname").val();
  61. var proxyDomain = $("#proxyDomain").val();
  62. var useTLS = $("#reqTls")[0].checked;
  63. if (type === "vdir") {
  64. if (!rootname.startsWith("/")) {
  65. rootname = "/" + rootname
  66. $("#rootname").val(rootname);
  67. }
  68. }else{
  69. if (!isSubdomainDomain(rootname)){
  70. //This doesn't seems like a subdomain
  71. if (!confirm(rootname + " does not looks like a subdomain. Continue anyway?")){
  72. return;
  73. }
  74. }
  75. }
  76. if (rootname.trim() == ""){
  77. $("#rootname").parent().addClass("error");
  78. return
  79. }else{
  80. $("#rootname").parent().removeClass("error");
  81. }
  82. if (proxyDomain.trim() == ""){
  83. $("#proxyDomain").parent().addClass("error");
  84. return
  85. }else{
  86. $("#proxyDomain").parent().removeClass("error");
  87. }
  88. //Create the endpoint by calling add
  89. $.ajax({
  90. url: "/api/proxy/add",
  91. data: {type: type, rootname: rootname, tls: useTLS, ep: proxyDomain},
  92. success: function(data){
  93. if (data.error != undefined){
  94. msgbox(data.error, false, 5000);
  95. }else{
  96. //OK
  97. listVdirs();
  98. listSubd();
  99. msgbox("Proxy Endpoint Added");
  100. //Clear old data
  101. $("#rootname").val("");
  102. $("#proxyDomain").val("");
  103. }
  104. }
  105. });
  106. }
  107. //Generic functions for delete rp endpoints
  108. function deleteEndpoint(ptype, epoint){
  109. if (confirm("Confirm remove proxy for :" + epoint + " (type: " + ptype + ")?")){
  110. $.ajax({
  111. url: "/api/proxy/del",
  112. data: {ep: epoint, ptype: ptype},
  113. success: function(){
  114. listVdirs();
  115. listSubd();
  116. }
  117. })
  118. }
  119. }
  120. function autoCheckTls(targetDomain){
  121. $.ajax({
  122. url: "/api/proxy/tlscheck",
  123. data: {url: targetDomain},
  124. success: function(data){
  125. if (data.error != undefined){
  126. }else if (data == "https"){
  127. $("#reqTls").parent().checkbox("set checked");
  128. }else if (data == "http"){
  129. $("#reqTls").parent().checkbox("set unchecked");
  130. }
  131. }
  132. })
  133. }
  134. //Check if a string is a valid subdomain
  135. function isSubdomainDomain(str) {
  136. const regex = /^(localhost|[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,}|[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,}\.)$/i;
  137. return regex.test(str);
  138. }
  139. </script>