httprp.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <div class="standardContainer">
  2. <div class="ui basic segment">
  3. <h2>HTTP Proxy</h2>
  4. <p>Proxy HTTP server with HTTP or HTTPS for multiple hosts. If you are only proxying for one host / domain, use Default Site instead.</p>
  5. </div>
  6. <div style="width: 100%; overflow-x: auto; margin-bottom: 1em;">
  7. <table class="ui celled sortable unstackable compact table">
  8. <thead>
  9. <tr>
  10. <th>Host</th>
  11. <th>Destination</th>
  12. <th>Virtual Directory</th>
  13. <th>Basic Auth</th>
  14. <th class="no-sort" style="min-width:100px;">Actions</th>
  15. </tr>
  16. </thead>
  17. <tbody id="httpProxyList">
  18. </tbody>
  19. </table>
  20. </div>
  21. <button class="ui icon right floated basic button" onclick="listProxyEndpoints();"><i class="green refresh icon"></i> Refresh</button>
  22. <br><br>
  23. </div>
  24. <script>
  25. function listProxyEndpoints(){
  26. $.get("/api/proxy/list?type=host", function(data){
  27. $("#httpProxyList").html(``);
  28. if (data.error !== undefined){
  29. $("#httpProxyList").append(`<tr>
  30. <td data-label="" colspan="5"><i class="remove icon"></i> ${data.error}</td>
  31. </tr>`);
  32. }else if (data.length == 0){
  33. $("#httpProxyList").append(`<tr>
  34. <td data-label="" colspan="5"><i class="green check circle icon"></i> No HTTP Proxy Record</td>
  35. </tr>`);
  36. }else{
  37. data.forEach(subd => {
  38. let tlsIcon = "";
  39. let subdData = encodeURIComponent(JSON.stringify(subd));
  40. if (subd.RequireTLS){
  41. tlsIcon = `<i class="green lock icon" title="TLS Mode"></i>`;
  42. if (subd.SkipCertValidations){
  43. tlsIcon = `<i class="yellow lock icon" title="TLS/SSL mode without verification"></i>`
  44. }
  45. }
  46. let inboundTlsIcon = "";
  47. if ($("#tls").checkbox("is checked")){
  48. inboundTlsIcon = `<i class="green lock icon" title="TLS Mode"></i>`;
  49. if (subd.BypassGlobalTLS){
  50. inboundTlsIcon = `<i class="grey lock icon" title="TLS Bypass Enabled"></i>`;
  51. }
  52. }else{
  53. inboundTlsIcon = `<i class="yellow lock open icon" title="Plain Text Mode"></i>`;
  54. }
  55. //Build the virtual directory list
  56. var vdList = `<div class="ui list">`;
  57. subd.VirtualDirectories.forEach(vdir => {
  58. vdList += `<div class="item">${vdir.MatchingPath} <i class="green angle double right icon"></i> ${vdir.Domain}</div>`;
  59. });
  60. vdList += `</div>`;
  61. if (subd.VirtualDirectories.length == 0){
  62. vdList = `<small style="opacity: 0.3; pointer-events: none; user-select: none;"><i class="check icon"></i> No Virtual Directory</small>`;
  63. }
  64. $("#httpProxyList").append(`<tr eptuuid="${subd.RootOrMatchingDomain}" payload="${subdData}" class="subdEntry">
  65. <td data-label="" editable="true" datatype="inbound"><a href="//${subd.RootOrMatchingDomain}" target="_blank">${subd.RootOrMatchingDomain}</a> ${inboundTlsIcon}</td>
  66. <td data-label="" editable="true" datatype="domain">${subd.Domain} ${tlsIcon}</td>
  67. <td data-label="" editable="true" datatype="vdir">${vdList}</td>
  68. <td data-label="" editable="true" datatype="basicauth">${subd.RequireBasicAuth?`<i class="ui green check icon"></i>`:`<i class="ui grey remove icon"></i>`}</td>
  69. <td class="center aligned" editable="true" datatype="action" data-label="">
  70. <button class="ui circular mini basic icon button editBtn inlineEditActionBtn" onclick='editEndpoint("${(subd.RootOrMatchingDomain).hexEncode()}")'><i class="edit icon"></i></button>
  71. <button class="ui circular mini red basic icon button inlineEditActionBtn" onclick='deleteEndpoint("${(subd.RootOrMatchingDomain).hexEncode()}")'><i class="trash icon"></i></button>
  72. </td>
  73. </tr>`);
  74. });
  75. }
  76. });
  77. }
  78. /*
  79. Inline editor for httprp.html
  80. */
  81. function editEndpoint(uuid) {
  82. uuid = uuid.hexDecode();
  83. var row = $('tr[eptuuid="' + uuid + '"]');
  84. var columns = row.find('td[data-label]');
  85. var payload = $(row).attr("payload");
  86. payload = JSON.parse(decodeURIComponent(payload));
  87. console.log(payload);
  88. //console.log(payload);
  89. columns.each(function(index) {
  90. var column = $(this);
  91. var oldValue = column.text().trim();
  92. if ($(this).attr("editable") == "false"){
  93. //This col do not allow edit. Skip
  94. return;
  95. }
  96. // Create an input element based on the column content
  97. var input;
  98. var datatype = $(this).attr("datatype");
  99. if (datatype == "domain"){
  100. let domain = payload.Domain;
  101. //Target require TLS for proxying
  102. let tls = payload.RequireTLS;
  103. if (tls){
  104. tls = "checked";
  105. }else{
  106. tls = "";
  107. }
  108. //Require TLS validation
  109. let skipTLSValidation = payload.SkipCertValidations;
  110. let checkstate = "";
  111. if (skipTLSValidation){
  112. checkstate = "checked";
  113. }
  114. input = `
  115. <div class="ui mini fluid input">
  116. <input type="text" class="Domain" value="${domain}">
  117. </div>
  118. <div class="ui checkbox" style="margin-top: 0.4em;">
  119. <input type="checkbox" class="RequireTLS" ${tls}>
  120. <label>Require TLS<br>
  121. <small>Proxy target require HTTPS connection</small></label>
  122. </div><br>
  123. <div class="ui checkbox" style="margin-top: 0.4em;">
  124. <input type="checkbox" class="SkipCertValidations" ${checkstate}>
  125. <label>Skip Verification<br>
  126. <small>Check this if proxy target is using self signed certificates</small></label>
  127. </div>
  128. `;
  129. column.empty().append(input);
  130. }else if (datatype == "vdir"){
  131. //Append a quick access button for vdir page
  132. column.append(`<button class="ui basic tiny button" style="margin-left: 0.4em; margin-top: 0.4em;" onclick="quickEditVdir('${uuid}');">
  133. <i class="ui yellow folder icon"></i> Edit Virtual Directories
  134. </button>`);
  135. }else if (datatype == "basicauth"){
  136. let requireBasicAuth = payload.RequireBasicAuth;
  137. let checkstate = "";
  138. if (requireBasicAuth){
  139. checkstate = "checked";
  140. }
  141. let skipWebSocketOriginCheck = payload.SkipWebSocketOriginCheck;
  142. let wsCheckstate = "";
  143. if (skipWebSocketOriginCheck){
  144. wsCheckstate = "checked";
  145. }
  146. column.empty().append(`<div class="ui checkbox" style="margin-top: 0.4em;">
  147. <input type="checkbox" class="RequireBasicAuth" ${checkstate}>
  148. <label>Require Basic Auth</label>
  149. </div>
  150. <button class="ui basic tiny button" style="margin-left: 0.4em; margin-top: 0.4em;" onclick="editBasicAuthCredentials('${uuid}');"><i class="ui blue user circle icon"></i> Edit Credentials</button>
  151. <div class="ui basic advance segment" style="padding: 0.4em !important; border-radius: 0.4em;">
  152. <div class="ui endpointAdvanceConfig accordion" style="padding-right: 0.6em;">
  153. <div class="title">
  154. <i class="dropdown icon"></i>
  155. Advance Configs
  156. </div>
  157. <div class="content">
  158. <div class="ui checkbox" style="margin-top: 0.4em;">
  159. <input type="checkbox" class="SkipWebSocketOriginCheck" ${wsCheckstate}>
  160. <label>Skip WebSocket Origin Check<br>
  161. <small>Check this to allow cross-origin websocket requests</small></label>
  162. </div>
  163. <button class="ui basic compact tiny button" style="margin-left: 0.4em; margin-top: 0.4em;" onclick="editCustomHeaders('${uuid}');"><i class="heading icon"></i> Custom Headers</button>
  164. <!-- <button class="ui basic compact tiny button" style="margin-left: 0.4em; margin-top: 0.4em;" onclick="editLoadBalanceOptions('${uuid}');"><i class="blue server icon"></i> Load Balance</button> -->
  165. </div>
  166. </div>
  167. <div>
  168. `);
  169. }else if (datatype == 'action'){
  170. column.empty().append(`
  171. <button title="Save" onclick="saveProxyInlineEdit('${uuid.hexEncode()}');" class="ui basic small icon circular button inlineEditActionBtn"><i class="ui green save icon"></i></button>
  172. <button title="Cancel" onclick="exitProxyInlineEdit();" class="ui basic small icon circular button inlineEditActionBtn"><i class="ui remove icon"></i></button>
  173. `);
  174. }else if (datatype == "inbound"){
  175. let originalContent = $(column).html();
  176. column.empty().append(`${originalContent}
  177. <div class="ui divider"></div>
  178. <div class="ui checkbox" style="margin-top: 0.4em;">
  179. <input type="checkbox" class="BypassGlobalTLS" ${payload.BypassGlobalTLS?"checked":""}>
  180. <label>Allow plain HTTP access<br>
  181. <small>Allow inbound connections without TLS/SSL</small></label>
  182. </div><br>
  183. `);
  184. }else{
  185. //Unknown field. Leave it untouched
  186. }
  187. });
  188. $(".endpointAdvanceConfig").accordion();
  189. $("#httpProxyList").find(".editBtn").addClass("disabled");
  190. }
  191. function exitProxyInlineEdit(){
  192. listProxyEndpoints();
  193. $("#httpProxyList").find(".editBtn").removeClass("disabled");
  194. }
  195. function saveProxyInlineEdit(uuid){
  196. uuid = uuid.hexDecode();
  197. var row = $('tr[eptuuid="' + uuid + '"]');
  198. if (row.length == 0){
  199. return;
  200. }
  201. var epttype = "host";
  202. let newDomain = $(row).find(".Domain").val();
  203. let requireTLS = $(row).find(".RequireTLS")[0].checked;
  204. let skipCertValidations = $(row).find(".SkipCertValidations")[0].checked;
  205. let requireBasicAuth = $(row).find(".RequireBasicAuth")[0].checked;
  206. let bypassGlobalTLS = $(row).find(".BypassGlobalTLS")[0].checked;
  207. let bypassWebsocketOrigin = $(row).find(".SkipWebSocketOriginCheck")[0].checked;
  208. console.log(newDomain, requireTLS, skipCertValidations, requireBasicAuth)
  209. $.ajax({
  210. url: "/api/proxy/edit",
  211. method: "POST",
  212. data: {
  213. "type": epttype,
  214. "rootname": uuid,
  215. "ep":newDomain,
  216. "bpgtls": bypassGlobalTLS,
  217. "tls" :requireTLS,
  218. "tlsval": skipCertValidations,
  219. "bpwsorg" : bypassWebsocketOrigin,
  220. "bauth" :requireBasicAuth,
  221. },
  222. success: function(data){
  223. if (data.error !== undefined){
  224. msgbox(data.error, false, 6000);
  225. }else{
  226. msgbox("Proxy endpoint updated");
  227. listProxyEndpoints();
  228. }
  229. }
  230. })
  231. }
  232. /* button events */
  233. function editBasicAuthCredentials(uuid){
  234. let payload = encodeURIComponent(JSON.stringify({
  235. ept: "host",
  236. ep: uuid
  237. }));
  238. showSideWrapper("snippet/basicAuthEditor.html?t=" + Date.now() + "#" + payload);
  239. }
  240. function quickEditVdir(uuid){
  241. openTabById("vdir");
  242. $("#vdirBaseRoutingRule").parent().dropdown("set selected", uuid);
  243. }
  244. function editCustomHeaders(uuid){
  245. let payload = encodeURIComponent(JSON.stringify({
  246. ept: "host",
  247. ep: uuid
  248. }));
  249. showSideWrapper("snippet/customHeaders.html?t=" + Date.now() + "#" + payload);
  250. }
  251. function editLoadBalanceOptions(uuid){
  252. alert(uuid);
  253. }
  254. //Bind on tab switch events
  255. tabSwitchEventBind["httprp"] = function(){
  256. listProxyEndpoints();
  257. }
  258. </script>