rproot.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <div class="standardContainer">
  2. <div class="ui basic segment">
  3. <h2>Set Proxy Root</h2>
  4. <p>The default routing point for all incoming traffics. For all routing not found in the proxy rules, request will be redirected to the proxy root server.</p>
  5. <div class="ui form">
  6. <div class="field">
  7. <label>Proxy Root</label>
  8. <input type="text" id="proxyRoot" onchange="checkRootRequireTLS(this.value);">
  9. <small>E.g. localhost:8080</small>
  10. </div>
  11. <div class="field">
  12. <div class="ui checkbox">
  13. <input type="checkbox" id="rootReqTLS">
  14. <label>Root require TLS connection <br><small>Check this if your proxy root URL starts with https://</small></label>
  15. </div>
  16. </div>
  17. <br>
  18. <button class="ui basic button" onclick="setProxyRoot()"><i class="teal home icon" ></i> Update Proxy Root</button>
  19. <div class="ui divider"></div>
  20. <div class="field">
  21. <h4>Root Routing Options</h4>
  22. </div>
  23. <div class="field">
  24. <div class="ui checkbox">
  25. <input type="checkbox" id="unsetRedirect">
  26. <label>Enable redirect for unset subdomains <br><small>Redirect subdomain that is not found to custom domain</small></label>
  27. </div>
  28. </div>
  29. <div class="ui basic segment" id="unsetRedirectDomainWrapper" style="background-color: #f7f7f7; border-radius: 1em; margin-left: 2em; padding-left: 2em; display:none;">
  30. <div style="
  31. position: absolute;
  32. top:0;
  33. left: 1em;
  34. width: 0px;
  35. height: 0px;
  36. margin-top: -10px;
  37. border-left: 10px solid transparent;
  38. border-right: 10px solid transparent;
  39. border-bottom: 10px solid #f7f7f7;">
  40. </div>
  41. <div class="field">
  42. <label>Redirect target domain</label>
  43. <div class="ui input">
  44. <input id="unsetRedirectDomain" type="text" placeholder="http://example.com">
  45. </div>
  46. <small>Unset subdomain will be redirected to the link above. Remember to include the protocol (e.g. http:// or https://)<br>
  47. Leave empty for redirecting to upper level domain (e.g. notfound.example.com <i class="right arrow icon"></i> example.com)</small>
  48. </div>
  49. </div>
  50. <div class="field">
  51. <div class="ui checkbox">
  52. <input type="checkbox" id="disableRootTLS">
  53. <label>Disable https on proxy root <br><small>Check this if you want your proxy root to bypass global TLS setting (Not Recommend)</small></label>
  54. </div>
  55. </div>
  56. <br>
  57. <button class="ui basic button" onclick="updateRootOptions()"><i class="blue save icon" ></i> Save Root Options</button>
  58. </div>
  59. <br>
  60. </div>
  61. </div>
  62. <script>
  63. $("#advanceRootSettings").accordion();
  64. function initRootInfo(){
  65. $.get("/api/proxy/list?type=root", function(data){
  66. if (data == null){
  67. }else{
  68. $("#proxyRoot").val(data.Domain);
  69. checkRootRequireTLS(data.Domain);
  70. }
  71. });
  72. }
  73. initRootInfo();
  74. function updateRootSettingStates(){
  75. $.get("/api/cert/tls", function(data){
  76. if (data == true){
  77. $("#disableRootTLS").parent().removeClass('disabled').attr("title", "");
  78. }else{
  79. $("#disableRootTLS").parent().addClass('disabled').attr("title", "TLS listener is not enabled");
  80. }
  81. });
  82. }
  83. //Bind event to tab switch
  84. tabSwitchEventBind["setroot"] = function(){
  85. //On switch over to this page, update root info
  86. updateRootSettingStates();
  87. }
  88. //Toggle the display status of the input box for domain setting
  89. function updateRedirectionDomainSettingInputBox(useRedirect){
  90. if(useRedirect){
  91. $("#unsetRedirectDomainWrapper").stop().finish().slideDown("fast");
  92. }else{
  93. $("#unsetRedirectDomainWrapper").stop().finish().slideUp("fast");
  94. }
  95. }
  96. function checkCustomRedirectForUnsetSubd(){
  97. $.get("/api/proxy/root/listOptions", function(data){
  98. $("#unsetRedirect")[0].checked = data.EnableRedirectForUnsetRules || false;
  99. $("#disableRootTLS")[0].checked = data.DisableHTTPSOnProxyRoot || false;
  100. $("#unsetRedirectDomain").val(data.UnsetRuleRedirectTarget);
  101. updateRedirectionDomainSettingInputBox(data.EnableRedirectForUnsetRules);
  102. //Bind event to the checkbox
  103. $("#unsetRedirect").off("change").on("change", function(){
  104. let useRedirect = $("#unsetRedirect")[0].checked;
  105. updateRedirectionDomainSettingInputBox(useRedirect);
  106. });
  107. })
  108. }
  109. checkCustomRedirectForUnsetSubd();
  110. function checkRootRequireTLS(targetDomain){
  111. //Trim off the http or https from the origin
  112. if (targetDomain.startsWith("http://")){
  113. targetDomain = targetDomain.substring(7);
  114. $("#proxyRoot").val(targetDomain);
  115. }else if (targetDomain.startsWith("https://")){
  116. targetDomain = targetDomain.substring(8);
  117. $("#proxyRoot").val(targetDomain);
  118. }
  119. $.ajax({
  120. url: "/api/proxy/tlscheck",
  121. data: {url: targetDomain},
  122. success: function(data){
  123. if (data.error != undefined){
  124. }else if (data == "https"){
  125. $("#rootReqTLS").parent().checkbox("set checked");
  126. }else if (data == "http"){
  127. $("#rootReqTLS").parent().checkbox("set unchecked");
  128. }
  129. }
  130. })
  131. }
  132. function setProxyRoot(){
  133. var newpr = $("#proxyRoot").val();
  134. if (newpr.trim() == ""){
  135. $("#proxyRoot").parent().addClass('error');
  136. return
  137. }else{
  138. $("#proxyRoot").parent().removeClass('error');
  139. }
  140. var rootReqTls = $("#rootReqTLS")[0].checked;
  141. //Create the endpoint by calling add
  142. $.ajax({
  143. url: "/api/proxy/add",
  144. data: {"type": "root", tls: rootReqTls, ep: newpr},
  145. success: function(data){
  146. if (data.error != undefined){
  147. msgbox(data.error, false, 5000);
  148. }else{
  149. //OK
  150. initRootInfo();
  151. msgbox("Proxy Root Updated")
  152. }
  153. }
  154. });
  155. }
  156. function updateRootOptions(){
  157. $.ajax({
  158. type: "POST",
  159. url: "/api/proxy/root/updateOptions",
  160. data: {
  161. unsetRedirect: $("#unsetRedirect")[0].checked,
  162. unsetRedirectTarget: $("#unsetRedirectDomain").val().trim(),
  163. disableRootHttps: $("#disableRootTLS")[0].checked,
  164. },
  165. success: function(data) {
  166. if (data.error != undefined){
  167. msgbox(data.error, false);
  168. }else{
  169. msgbox("Root Routing Options updated");
  170. }
  171. },
  172. error: function(error) {
  173. console.log("Error:", error);
  174. }
  175. });
  176. }
  177. </script>