rproot.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. <br>
  51. <button class="ui basic button" onclick="updateRootOptions()"><i class="blue save icon" ></i> Save Root Options</button>
  52. </div>
  53. <br>
  54. </div>
  55. </div>
  56. <script>
  57. $("#advanceRootSettings").accordion();
  58. function initRootInfo(){
  59. $.get("/api/proxy/list?type=root", function(data){
  60. if (data == null){
  61. }else{
  62. $("#proxyRoot").val(data.Domain);
  63. checkRootRequireTLS(data.Domain);
  64. }
  65. });
  66. }
  67. initRootInfo();
  68. function updateRootSettingStates(){
  69. $.get("/api/cert/tls", function(data){
  70. if (data == true){
  71. $("#disableRootTLS").parent().removeClass('disabled').attr("title", "");
  72. }else{
  73. $("#disableRootTLS").parent().addClass('disabled').attr("title", "TLS listener is not enabled");
  74. }
  75. });
  76. }
  77. //Bind event to tab switch
  78. tabSwitchEventBind["setroot"] = function(){
  79. //On switch over to this page, update root info
  80. updateRootSettingStates();
  81. }
  82. //Toggle the display status of the input box for domain setting
  83. function updateRedirectionDomainSettingInputBox(useRedirect){
  84. if(useRedirect){
  85. $("#unsetRedirectDomainWrapper").stop().finish().slideDown("fast");
  86. }else{
  87. $("#unsetRedirectDomainWrapper").stop().finish().slideUp("fast");
  88. }
  89. }
  90. function checkCustomRedirectForUnsetSubd(){
  91. $.get("/api/proxy/root/listOptions", function(data){
  92. $("#unsetRedirect")[0].checked = data.EnableRedirectForUnsetRules || false;
  93. $("#unsetRedirectDomain").val(data.UnsetRuleRedirectTarget);
  94. updateRedirectionDomainSettingInputBox(data.EnableRedirectForUnsetRules);
  95. //Bind event to the checkbox
  96. $("#unsetRedirect").off("change").on("change", function(){
  97. let useRedirect = $("#unsetRedirect")[0].checked;
  98. updateRedirectionDomainSettingInputBox(useRedirect);
  99. });
  100. })
  101. }
  102. checkCustomRedirectForUnsetSubd();
  103. function checkRootRequireTLS(targetDomain){
  104. //Trim off the http or https from the origin
  105. if (targetDomain.startsWith("http://")){
  106. targetDomain = targetDomain.substring(7);
  107. $("#proxyRoot").val(targetDomain);
  108. }else if (targetDomain.startsWith("https://")){
  109. targetDomain = targetDomain.substring(8);
  110. $("#proxyRoot").val(targetDomain);
  111. }
  112. $.ajax({
  113. url: "/api/proxy/tlscheck",
  114. data: {url: targetDomain},
  115. success: function(data){
  116. if (data.error != undefined){
  117. }else if (data == "https"){
  118. $("#rootReqTLS").parent().checkbox("set checked");
  119. }else if (data == "http"){
  120. $("#rootReqTLS").parent().checkbox("set unchecked");
  121. }
  122. }
  123. })
  124. }
  125. function setProxyRoot(){
  126. var newpr = $("#proxyRoot").val();
  127. if (newpr.trim() == ""){
  128. $("#proxyRoot").parent().addClass('error');
  129. return
  130. }else{
  131. $("#proxyRoot").parent().removeClass('error');
  132. }
  133. var rootReqTls = $("#rootReqTLS")[0].checked;
  134. //Create the endpoint by calling add
  135. $.ajax({
  136. url: "/api/proxy/add",
  137. data: {"type": "root", tls: rootReqTls, ep: newpr},
  138. success: function(data){
  139. if (data.error != undefined){
  140. msgbox(data.error, false, 5000);
  141. }else{
  142. //OK
  143. initRootInfo();
  144. msgbox("Proxy Root Updated")
  145. }
  146. }
  147. });
  148. }
  149. function updateRootOptions(){
  150. $.ajax({
  151. type: "POST",
  152. url: "/api/proxy/root/updateOptions",
  153. data: {
  154. unsetRedirect: $("#unsetRedirect")[0].checked,
  155. unsetRedirectTarget: $("#unsetRedirectDomain").val().trim(),
  156. },
  157. success: function(data) {
  158. if (data.error != undefined){
  159. msgbox(data.error, false);
  160. }else{
  161. msgbox("Root Routing Options updated");
  162. }
  163. },
  164. error: function(error) {
  165. console.log("Error:", error);
  166. }
  167. });
  168. }
  169. </script>