rproot.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. //Toggle the display status of the input box for domain setting
  68. function updateRedirectionDomainSettingInputBox(useRedirect){
  69. if(useRedirect){
  70. $("#unsetRedirectDomain").stop().finish().slideDown("fast");
  71. }else{
  72. $("#unsetRedirectDomain").stop().finish().slideUp("fast");
  73. }
  74. }
  75. function checkCustomRedirectForUnsetSubd(){
  76. $("#unsetRedirect").on("change", function(){
  77. let useRedirect = $(this)[0].checked;
  78. updateRedirectionDomainSettingInputBox(useRedirect);
  79. })
  80. }
  81. checkCustomRedirectForUnsetSubd();
  82. function checkRootRequireTLS(targetDomain){
  83. //Trim off the http or https from the origin
  84. if (targetDomain.startsWith("http://")){
  85. targetDomain = targetDomain.substring(7);
  86. $("#proxyRoot").val(targetDomain);
  87. }else if (targetDomain.startsWith("https://")){
  88. targetDomain = targetDomain.substring(8);
  89. $("#proxyRoot").val(targetDomain);
  90. }
  91. $.ajax({
  92. url: "/api/proxy/tlscheck",
  93. data: {url: targetDomain},
  94. success: function(data){
  95. if (data.error != undefined){
  96. }else if (data == "https"){
  97. $("#rootReqTLS").parent().checkbox("set checked");
  98. }else if (data == "http"){
  99. $("#rootReqTLS").parent().checkbox("set unchecked");
  100. }
  101. }
  102. })
  103. }
  104. function setProxyRoot(){
  105. var newpr = $("#proxyRoot").val();
  106. if (newpr.trim() == ""){
  107. $("#proxyRoot").parent().addClass('error');
  108. return
  109. }else{
  110. $("#proxyRoot").parent().removeClass('error');
  111. }
  112. var rootReqTls = $("#rootReqTLS")[0].checked;
  113. //Create the endpoint by calling add
  114. $.ajax({
  115. url: "/api/proxy/add",
  116. data: {"type": "root", tls: rootReqTls, ep: newpr},
  117. success: function(data){
  118. if (data.error != undefined){
  119. alert(data.error);
  120. }else{
  121. //OK
  122. initRootInfo();
  123. msgbox("Proxy Root Updated")
  124. }
  125. }
  126. });
  127. }
  128. </script>