rproot.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. <div class="field">
  18. <div class="ui checkbox">
  19. <input type="checkbox" id="unsetRedirect">
  20. <label>Enable redirect for unset subdomains <br><small>Redirect subdomain that is not found to custom domain</small></label>
  21. </div>
  22. </div>
  23. <div class="ui basic segment" id="unsetRedirectDomain" style="background-color: #f7f7f7; border-radius: 1em; margin-left: 2em; padding-left: 2em; display:none;">
  24. <div style="
  25. position: absolute;
  26. top:0;
  27. left: 1em;
  28. width: 0px;
  29. height: 0px;
  30. margin-top: -10px;
  31. border-left: 10px solid transparent;
  32. border-right: 10px solid transparent;
  33. border-bottom: 10px solid #f7f7f7;">
  34. </div>
  35. <div class="field">
  36. <label>Redirect target domain</label>
  37. <div class="ui input">
  38. <input type="text" placeholder="http://example.com">
  39. </div>
  40. <p>Unset subdomain will be redirected to the link above. Remember to include the protocol (e.g. http:// or https://)</p>
  41. </div>
  42. </div>
  43. <div class="field">
  44. <div class="ui checkbox">
  45. <input type="checkbox" id="disableRootTLS">
  46. <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>
  47. </div>
  48. </div>
  49. <br>
  50. <button class="ui basic button" onclick="setProxyRoot()"><i class="teal home icon" ></i> Update Proxy Root</button>
  51. </div>
  52. <br>
  53. </div>
  54. </div>
  55. <script>
  56. $("#advanceRootSettings").accordion();
  57. function initRootInfo(){
  58. $.get("/api/proxy/list?type=root", function(data){
  59. if (data == null){
  60. }else{
  61. $("#proxyRoot").val(data.Domain);
  62. checkRootRequireTLS(data.Domain);
  63. }
  64. });
  65. }
  66. initRootInfo();
  67. function updateRootSettingStates(){
  68. $.get("/api/cert/tls", function(data){
  69. if (data == true){
  70. $("#disableRootTLS").parent().removeClass('disabled').attr("title", "");
  71. }else{
  72. $("#disableRootTLS").parent().addClass('disabled').attr("title", "TLS listener is not enabled");
  73. }
  74. });
  75. }
  76. //Bind event to tab switch
  77. tabSwitchEventBind["setroot"] = function(){
  78. //On switch over to this page, update root info
  79. updateRootSettingStates();
  80. }
  81. //Toggle the display status of the input box for domain setting
  82. function updateRedirectionDomainSettingInputBox(useRedirect){
  83. if(useRedirect){
  84. $("#unsetRedirectDomain").stop().finish().slideDown("fast");
  85. }else{
  86. $("#unsetRedirectDomain").stop().finish().slideUp("fast");
  87. }
  88. }
  89. function checkCustomRedirectForUnsetSubd(){
  90. $("#unsetRedirect").on("change", function(){
  91. let useRedirect = $(this)[0].checked;
  92. updateRedirectionDomainSettingInputBox(useRedirect);
  93. })
  94. }
  95. checkCustomRedirectForUnsetSubd();
  96. function checkRootRequireTLS(targetDomain){
  97. //Trim off the http or https from the origin
  98. if (targetDomain.startsWith("http://")){
  99. targetDomain = targetDomain.substring(7);
  100. $("#proxyRoot").val(targetDomain);
  101. }else if (targetDomain.startsWith("https://")){
  102. targetDomain = targetDomain.substring(8);
  103. $("#proxyRoot").val(targetDomain);
  104. }
  105. $.ajax({
  106. url: "/api/proxy/tlscheck",
  107. data: {url: targetDomain},
  108. success: function(data){
  109. if (data.error != undefined){
  110. }else if (data == "https"){
  111. $("#rootReqTLS").parent().checkbox("set checked");
  112. }else if (data == "http"){
  113. $("#rootReqTLS").parent().checkbox("set unchecked");
  114. }
  115. }
  116. })
  117. }
  118. function setProxyRoot(){
  119. var newpr = $("#proxyRoot").val();
  120. if (newpr.trim() == ""){
  121. $("#proxyRoot").parent().addClass('error');
  122. return
  123. }else{
  124. $("#proxyRoot").parent().removeClass('error');
  125. }
  126. var rootReqTls = $("#rootReqTLS")[0].checked;
  127. //Create the endpoint by calling add
  128. $.ajax({
  129. url: "/api/proxy/add",
  130. data: {"type": "root", tls: rootReqTls, ep: newpr},
  131. success: function(data){
  132. if (data.error != undefined){
  133. alert(data.error);
  134. }else{
  135. //OK
  136. initRootInfo();
  137. msgbox("Proxy Root Updated")
  138. }
  139. }
  140. });
  141. }
  142. </script>