123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <div class="standardContainer">
- <div class="ui basic segment">
- <h2>HTTP Proxy</h2>
- <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>
- </div>
- <div style="width: 100%; overflow-x: auto; margin-bottom: 1em; min-width: 400px;">
- <table class="ui celled sortable unstackable compact table">
- <thead>
- <tr>
- <th>Host</th>
- <th>Destination</th>
- <!-- <th>Virtual Directory</th> -->
- <th>Basic Auth</th>
- <th class="no-sort" style="min-width: 7.2em;">Actions</th>
- </tr>
- </thead>
- <tbody id="httpProxyList">
-
- </tbody>
- </table>
- </div>
- <button class="ui icon right floated basic button" onclick="listProxyEndpoints();"><i class="green refresh icon"></i> Refresh</button>
- <br><br>
- </div>
- <script>
- function listProxyEndpoints(){
- $.get("/api/proxy/list?type=host", function(data){
- $("#httpProxyList").html(``);
- if (data.error !== undefined){
- $("#httpProxyList").append(`<tr>
- <td data-label="" colspan="4"><i class="remove icon"></i> ${data.error}</td>
- </tr>`);
- }else if (data.length == 0){
- $("#httpProxyList").append(`<tr>
- <td data-label="" colspan="4"><i class="green check circle icon"></i> No HTTP Proxy Record</td>
- </tr>`);
- }else{
- data.forEach(subd => {
- let tlsIcon = "";
- let subdData = encodeURIComponent(JSON.stringify(subd));
- if (subd.RequireTLS){
- tlsIcon = `<i class="green lock icon" title="TLS Mode"></i>`;
- if (subd.SkipCertValidations){
- tlsIcon = `<i class="yellow lock icon" title="TLS/SSL mode without verification"></i>`
- }
- }
- let inboundTlsIcon = "";
- if ($("#tls").checkbox("is checked")){
- inboundTlsIcon = `<i class="green lock icon" title="TLS Mode"></i>`;
- if (subd.BypassGlobalTLS){
- inboundTlsIcon = `<i class="grey lock icon" title="TLS Bypass Enabled"></i>`;
- }
- }else{
- inboundTlsIcon = `<i class="yellow lock open icon" title="Plain Text Mode"></i>`;
- }
-
- //Build the virtual directory list
- var vdList = `<div class="ui list">`;
- subd.VirtualDirectories.forEach(vdir => {
- vdList += `<div class="item">${vdir.MatchingPath} <i class="green angle double right icon"></i> ${vdir.Domain}</div>`;
- });
- vdList += `</div>`;
- if (subd.VirtualDirectories.length == 0){
- vdList = `<i class="ui green circle check icon"></i> No Virtual Directory Rule`;
- }
- $("#httpProxyList").append(`<tr eptuuid="${subd.RootOrMatchingDomain}" payload="${subdData}" class="subdEntry">
- <td data-label="" editable="true" datatype="inbound"><a href="//${subd.RootOrMatchingDomain}" target="_blank">${subd.RootOrMatchingDomain}</a> ${inboundTlsIcon}</td>
- <td data-label="" editable="true" datatype="domain">${subd.Domain} ${tlsIcon}</td>
- <td data-label="" editable="true" datatype="basicauth">${subd.RequireBasicAuth?`<i class="ui green check icon"></i>`:`<i class="ui grey remove icon"></i>`}</td>
- <td class="center aligned" editable="true" datatype="action" data-label="">
- <button class="ui circular mini basic icon button editBtn inlineEditActionBtn" onclick='editEndpoint("${(subd.RootOrMatchingDomain).hexEncode()}")'><i class="edit icon"></i></button>
- <button class="ui circular mini red basic icon button inlineEditActionBtn" onclick='deleteEndpoint("${(subd.RootOrMatchingDomain).hexEncode()}")'><i class="trash icon"></i></button>
- </td>
- </tr>`);
- });
- }
- });
- }
-
- /*
- Inline editor for httprp.html
- */
- function editEndpoint(uuid) {
- uuid = uuid.hexDecode();
- var row = $('tr[eptuuid="' + uuid + '"]');
- var columns = row.find('td[data-label]');
- var payload = $(row).attr("payload");
- payload = JSON.parse(decodeURIComponent(payload));
- console.log(payload);
- //console.log(payload);
- columns.each(function(index) {
- var column = $(this);
- var oldValue = column.text().trim();
- if ($(this).attr("editable") == "false"){
- //This col do not allow edit. Skip
- return;
- }
- // Create an input element based on the column content
- var input;
- var datatype = $(this).attr("datatype");
- if (datatype == "domain"){
- let domain = payload.Domain;
- //Target require TLS for proxying
- let tls = payload.RequireTLS;
- if (tls){
- tls = "checked";
- }else{
- tls = "";
- }
- //Require TLS validation
- let skipTLSValidation = payload.SkipCertValidations;
- let checkstate = "";
- if (skipTLSValidation){
- checkstate = "checked";
- }
- input = `
- <div class="ui mini fluid input">
- <input type="text" class="Domain" value="${domain}">
- </div>
- <div class="ui checkbox" style="margin-top: 0.4em;">
- <input type="checkbox" class="RequireTLS" ${tls}>
- <label>Require TLS<br>
- <small>Proxy target require HTTPS connection</small></label>
- </div><br>
- <div class="ui checkbox" style="margin-top: 0.4em;">
- <input type="checkbox" class="SkipCertValidations" ${checkstate}>
- <label>Skip Verification<br>
- <small>Check this if proxy target is using self signed certificates</small></label>
- </div>
- `;
- column.empty().append(input);
- }else if (datatype == "basicauth"){
- let requireBasicAuth = payload.RequireBasicAuth;
- let checkstate = "";
- if (requireBasicAuth){
- checkstate = "checked";
- }
- column.empty().append(`<div class="ui checkbox" style="margin-top: 0.4em;">
- <input type="checkbox" class="RequireBasicAuth" ${checkstate}>
- <label>Require Basic Auth</label>
- </div>
- <button class="ui basic tiny button" style="margin-left: 0.4em; margin-top: 0.4em;" onclick="editBasicAuthCredentials('${uuid}');">Edit Credentials</button>`);
- }else if (datatype == 'action'){
- column.empty().append(`
- <button title="Save" onclick="saveProxyInlineEdit('${uuid.hexEncode()}');" class="ui basic small icon circular button inlineEditActionBtn"><i class="ui green save icon"></i></button>
- <button title="Cancel" onclick="exitProxyInlineEdit();" class="ui basic small icon circular button inlineEditActionBtn"><i class="ui remove icon"></i></button>
-
- `);
- }else if (datatype == "inbound"){
- let originalContent = $(column).html();
- column.empty().append(`${originalContent}
- <div class="ui divider"></div>
- <div class="ui checkbox" style="margin-top: 0.4em;">
- <input type="checkbox" class="BypassGlobalTLS" ${payload.BypassGlobalTLS?"checked":""}>
- <label>Allow plain HTTP access<br>
- <small>Allow inbound connections without TLS/SSL</small></label>
- </div><br>
- `);
- }else{
- //Unknown field. Leave it untouched
- }
- });
- $("#httpProxyList").find(".editBtn").addClass("disabled");
- }
- function exitProxyInlineEdit(){
- listProxyEndpoints();
- $("#httpProxyList").find(".editBtn").removeClass("disabled");
- }
- function saveProxyInlineEdit(uuid){
- uuid = uuid.hexDecode();
- var row = $('tr[eptuuid="' + uuid + '"]');
- if (row.length == 0){
- return;
- }
-
- var epttype = "host";
- let newDomain = $(row).find(".Domain").val();
- let requireTLS = $(row).find(".RequireTLS")[0].checked;
- let skipCertValidations = $(row).find(".SkipCertValidations")[0].checked;
- let requireBasicAuth = $(row).find(".RequireBasicAuth")[0].checked;
- let bypassGlobalTLS = $(row).find(".BypassGlobalTLS")[0].checked;
- console.log(newDomain, requireTLS, skipCertValidations, requireBasicAuth)
- $.ajax({
- url: "/api/proxy/edit",
- method: "POST",
- data: {
- "type": epttype,
- "rootname": uuid,
- "ep":newDomain,
- "bpgtls": bypassGlobalTLS,
- "tls" :requireTLS,
- "tlsval": skipCertValidations,
- "bauth" :requireBasicAuth,
- },
- success: function(data){
- if (data.error !== undefined){
- msgbox(data.error, false, 6000);
- }else{
- msgbox("Proxy endpoint updated");
- listProxyEndpoints();
- }
- }
- })
- }
-
- function editBasicAuthCredentials(uuid){
- let payload = encodeURIComponent(JSON.stringify({
- ept: "host",
- ep: uuid
- }));
- showSideWrapper("snippet/basicAuthEditor.html?t=" + Date.now() + "#" + payload);
- }
-
- //Bind on tab switch events
- tabSwitchEventBind["httprp"] = function(){
- listProxyEndpoints();
- }
- </script>
|