rproot.html 8.3 KB

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