|
@@ -299,4 +299,136 @@
|
|
|
const regex = /^(localhost|[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,}|[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,}\.)$/i;
|
|
|
return regex.test(str);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ Inline editor for subd.html and vdir.html
|
|
|
+ */
|
|
|
+
|
|
|
+ function editEndpoint(endpointType, uuid) {
|
|
|
+ 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);
|
|
|
+ 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;
|
|
|
+ let tls = payload.RequireTLS;
|
|
|
+ if (tls){
|
|
|
+ tls = "checked";
|
|
|
+ }else{
|
|
|
+ tls = "";
|
|
|
+ }
|
|
|
+ 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</label>
|
|
|
+ </div>
|
|
|
+ `;
|
|
|
+ column.empty().append(input);
|
|
|
+
|
|
|
+ }else if (datatype == "skipver"){
|
|
|
+ let skipTLSValidation = payload.SkipCertValidations;
|
|
|
+ let checkstate = "";
|
|
|
+ if (skipTLSValidation){
|
|
|
+ checkstate = "checked";
|
|
|
+ }
|
|
|
+ column.empty().append(`<div class="ui checkbox" style="margin-top: 0.4em;">
|
|
|
+ <input type="checkbox" class="SkipCertValidations" ${checkstate}>
|
|
|
+ <label>Skip Verification</label>
|
|
|
+ <small>Check this if you are using self signed certificates</small>
|
|
|
+ </div>`);
|
|
|
+ }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 right floated button"><i class="ui blue lock icon"></i> Edit Credentials</button>`);
|
|
|
+
|
|
|
+ }else if (datatype == 'action'){
|
|
|
+ column.empty().append(`<button onclick="saveProxyInlineEdit('${uuid}');" class="ui tiny basic button"><i class="ui green save icon"></i> Save</button>`);
|
|
|
+ }else{
|
|
|
+ //Unknown field. Leave it untouched
|
|
|
+
|
|
|
+ }
|
|
|
+ if (column.find('i.green.check.icon').length > 0) {
|
|
|
+ // Create a checkbox input for boolean options
|
|
|
+ var checked = (oldValue === '✓'); // Assuming '✓' indicates a checked state
|
|
|
+ input = $('<input>').attr('type', 'checkbox').prop('checked', checked);
|
|
|
+ } else {
|
|
|
+ // Create a regular text input for other fields
|
|
|
+ input = $('<input>').attr('type', 'text').val(oldValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Set focus on the input element
|
|
|
+ input.focus();
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function saveProxyInlineEdit(uuid){
|
|
|
+ var row = $('tr[eptuuid="' + uuid + '"]');
|
|
|
+ if (row.length == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var epttype = $(row).attr("class");
|
|
|
+ if (epttype == "subdEntry"){
|
|
|
+ epttype = "subd";
|
|
|
+ }else if (epttype == "vdirEntry"){
|
|
|
+ epttype = "vdir";
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+
|
|
|
+ console.log(newDomain, requireTLS, skipCertValidations, requireBasicAuth)
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ url: "/api/proxy/edit",
|
|
|
+ method: "POST",
|
|
|
+ data: {
|
|
|
+ "type": epttype,
|
|
|
+ "rootname": uuid,
|
|
|
+ "ep":newDomain,
|
|
|
+ "tls" :requireTLS,
|
|
|
+ "tlsval": skipCertValidations,
|
|
|
+ "bauth" :requireBasicAuth,
|
|
|
+ },
|
|
|
+ success: function(data){
|
|
|
+ if (data.error !== undefined){
|
|
|
+ msgbox(data.error, false, 6000);
|
|
|
+ }else{
|
|
|
+ msgbox("Proxy endpoint updated");
|
|
|
+ if (epttype == "subd"){
|
|
|
+ listSubd();
|
|
|
+ }else if (epttype == "vdir"){
|
|
|
+ listVdirs();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
</script>
|