rproot.html 6.8 KB

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