httprp.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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; min-width: 400px;">
  7. <table class="ui celled sortable unstackable basic 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: 7.2em;">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="4"><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="4"><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 = `<i class="ui green circle check icon"></i> No Virtual Directory Rule`;
  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="basicauth">${subd.RequireBasicAuth?`<i class="ui green check icon"></i>`:`<i class="ui grey remove icon"></i>`}</td>
  68. <td class="center aligned" editable="true" datatype="action" data-label="">
  69. <button class="ui circular mini basic icon button editBtn inlineEditActionBtn" onclick='editEndpoint("${(subd.RootOrMatchingDomain).hexEncode()}")'><i class="edit icon"></i></button>
  70. <button class="ui circular mini red basic icon button inlineEditActionBtn" onclick='deleteEndpoint("${(subd.RootOrMatchingDomain).hexEncode()}")'><i class="trash icon"></i></button>
  71. </td>
  72. </tr>`);
  73. });
  74. }
  75. });
  76. }
  77. /*
  78. Inline editor for httprp.html
  79. */
  80. function editEndpoint(uuid) {
  81. uuid = uuid.hexDecode();
  82. var row = $('tr[eptuuid="' + uuid + '"]');
  83. var columns = row.find('td[data-label]');
  84. var payload = $(row).attr("payload");
  85. payload = JSON.parse(decodeURIComponent(payload));
  86. console.log(payload);
  87. //console.log(payload);
  88. columns.each(function(index) {
  89. var column = $(this);
  90. var oldValue = column.text().trim();
  91. if ($(this).attr("editable") == "false"){
  92. //This col do not allow edit. Skip
  93. return;
  94. }
  95. // Create an input element based on the column content
  96. var input;
  97. var datatype = $(this).attr("datatype");
  98. if (datatype == "domain"){
  99. let domain = payload.Domain;
  100. //Target require TLS for proxying
  101. let tls = payload.RequireTLS;
  102. if (tls){
  103. tls = "checked";
  104. }else{
  105. tls = "";
  106. }
  107. //Require TLS validation
  108. let skipTLSValidation = payload.SkipCertValidations;
  109. let checkstate = "";
  110. if (skipTLSValidation){
  111. checkstate = "checked";
  112. }
  113. input = `
  114. <div class="ui mini fluid input">
  115. <input type="text" class="Domain" value="${domain}">
  116. </div>
  117. <div class="ui checkbox" style="margin-top: 0.4em;">
  118. <input type="checkbox" class="RequireTLS" ${tls}>
  119. <label>Require TLS<br>
  120. <small>Proxy target require HTTPS connection</small></label>
  121. </div><br>
  122. <div class="ui checkbox" style="margin-top: 0.4em;">
  123. <input type="checkbox" class="SkipCertValidations" ${checkstate}>
  124. <label>Skip Verification<br>
  125. <small>Check this if proxy target is using self signed certificates</small></label>
  126. </div>
  127. `;
  128. column.empty().append(input);
  129. }else if (datatype == "basicauth"){
  130. let requireBasicAuth = payload.RequireBasicAuth;
  131. let checkstate = "";
  132. if (requireBasicAuth){
  133. checkstate = "checked";
  134. }
  135. column.empty().append(`<div class="ui checkbox" style="margin-top: 0.4em;">
  136. <input type="checkbox" class="RequireBasicAuth" ${checkstate}>
  137. <label>Require Basic Auth</label>
  138. </div>
  139. <button class="ui basic tiny button" style="margin-left: 0.4em; margin-top: 0.4em;" onclick="editBasicAuthCredentials('${uuid}');">Edit Credentials</button>`);
  140. }else if (datatype == 'action'){
  141. column.empty().append(`
  142. <button title="Save" onclick="saveProxyInlineEdit('${uuid.hexEncode()}');" class="ui basic small icon circular button inlineEditActionBtn"><i class="ui green save icon"></i></button>
  143. <button title="Cancel" onclick="exitProxyInlineEdit();" class="ui basic small icon circular button inlineEditActionBtn"><i class="ui remove icon"></i></button>
  144. `);
  145. }else if (datatype == "inbound"){
  146. let originalContent = $(column).html();
  147. column.empty().append(`${originalContent}
  148. <div class="ui divider"></div>
  149. <div class="ui checkbox" style="margin-top: 0.4em;">
  150. <input type="checkbox" class="BypassGlobalTLS" ${payload.BypassGlobalTLS?"checked":""}>
  151. <label>Allow plain HTTP access<br>
  152. <small>Allow inbound connections without TLS/SSL</small></label>
  153. </div><br>
  154. `);
  155. }else{
  156. //Unknown field. Leave it untouched
  157. }
  158. });
  159. $("#httpProxyList").find(".editBtn").addClass("disabled");
  160. }
  161. function exitProxyInlineEdit(){
  162. listProxyEndpoints();
  163. $("#httpProxyList").find(".editBtn").removeClass("disabled");
  164. }
  165. function saveProxyInlineEdit(uuid){
  166. uuid = uuid.hexDecode();
  167. var row = $('tr[eptuuid="' + uuid + '"]');
  168. if (row.length == 0){
  169. return;
  170. }
  171. var epttype = "host";
  172. let newDomain = $(row).find(".Domain").val();
  173. let requireTLS = $(row).find(".RequireTLS")[0].checked;
  174. let skipCertValidations = $(row).find(".SkipCertValidations")[0].checked;
  175. let requireBasicAuth = $(row).find(".RequireBasicAuth")[0].checked;
  176. let bypassGlobalTLS = $(row).find(".BypassGlobalTLS")[0].checked;
  177. console.log(newDomain, requireTLS, skipCertValidations, requireBasicAuth)
  178. $.ajax({
  179. url: "/api/proxy/edit",
  180. method: "POST",
  181. data: {
  182. "type": epttype,
  183. "rootname": uuid,
  184. "ep":newDomain,
  185. "bpgtls": bypassGlobalTLS,
  186. "tls" :requireTLS,
  187. "tlsval": skipCertValidations,
  188. "bauth" :requireBasicAuth,
  189. },
  190. success: function(data){
  191. if (data.error !== undefined){
  192. msgbox(data.error, false, 6000);
  193. }else{
  194. msgbox("Proxy endpoint updated");
  195. listProxyEndpoints();
  196. }
  197. }
  198. })
  199. }
  200. function editBasicAuthCredentials(uuid){
  201. let payload = encodeURIComponent(JSON.stringify({
  202. ept: "host",
  203. ep: uuid
  204. }));
  205. showSideWrapper("snippet/basicAuthEditor.html?t=" + Date.now() + "#" + payload);
  206. }
  207. //Bind on tab switch events
  208. tabSwitchEventBind["httprp"] = function(){
  209. listProxyEndpoints();
  210. }
  211. </script>