Skip to content

Commit

Permalink
Prevent posting empty data from manage CRL (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
hakwerk committed Jun 11, 2023
1 parent f0601ff commit 66b5121
Showing 1 changed file with 61 additions and 55 deletions.
116 changes: 61 additions & 55 deletions gui/templates/views/manage.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,7 @@
<label for="modal-rootpassphrase">Passphrase (optional):</label>
<input class="form-control" type="password" id="modal-rootpassphrase" value="">
</div>
{{ with .CertificateInfo.Errors.Modal }}
<span class="error">{{ . }}</span><br/>
{{ end }}
<span class="error" id="modal-root-key-error" style="display: none;"></span><br/>
<input class="btn btn-default btn-reg" value="Upload" id="modal-root-key-upload"/>
<button type="button" class="btn btn-default" data-dismiss="modal" id="cancel-rootkey">Cancel</button>
</div>
Expand All @@ -395,9 +393,7 @@
<h4>CRL</h4>
<p>Please provide the CRL for the Root CA.</p>
<textarea class="form-control" id="modal-crl-val" rows="10" cols="80" required>{{ .CRL }}</textarea>
{{ with .CertificateInfo.Errors.Modal }}
<span class="error">{{ . }}</span><br/>
{{ end }}
<span class="error" id="modal-crl-error" style="display: none;"></span><br/>
<input class="btn btn-default btn-reg" value="OK" id="modal-crl-done"/>
<button type="button" class="btn btn-default" data-dismiss="modal" id="cancel-crl">Cancel</button>
</div>
Expand Down Expand Up @@ -864,7 +860,6 @@
$("#issuer-crl-result").removeClass("hidden").removeClass("error").show().html(msg).addClass("success");

} else {
console.log("***DEBUG*** 1 ", data);
$("#issuer-crl-result").removeClass("hidden").removeClass("success").show().text(data.Errors["CRL"]).addClass("error");
}
})
Expand Down Expand Up @@ -893,7 +888,6 @@
return false;

} else {
console.log("***DEBUG*** 2 ", data);
$("#root-crl-result").removeClass("hidden").removeClass("success").show().text(data.Errors["CRL"]).addClass("error");
}
})
Expand All @@ -903,67 +897,79 @@
});

} else if ( $(evt.target).attr("id") == "modal-root-key-upload") {
$('#modal-root-key').modal('hide');
$.ajax(window.location.href, {
method: "POST",
data: {
action: 'gen-root-crl',
rootkey: $("#modal-rootkey").val(),
rootpassphrase: $("#modal-rootpassphrase").val(),
},
})
.done(function(data) {
if ($("#modal-rootkey").val() == "") {
$('#modal-spinner').modal('hide');
$('.modal-backdrop').remove();
$("#modal-root-key-error").show().text("Please provide the root key");
return false;
} else {
$('#modal-root-key').modal('hide');
$("#modal-root-key-error").hide();
$.ajax(window.location.href, {
method: "POST",
data: {
action: 'gen-root-crl',
rootkey: $("#modal-rootkey").val(),
rootpassphrase: $("#modal-rootpassphrase").val(),
},
})
.done(function(data) {
$('#modal-spinner').modal('hide');
$('.modal-backdrop').remove();

if (data.Success) {
var msg = "Successfully generated Root CRL.<br/>";
$("#root-crl-result").removeClass("hidden").removeClass("error").show().html(msg).addClass("success");
if (data.Success) {
var msg = "Successfully generated Root CRL.<br/>";
$("#root-crl-result").removeClass("hidden").removeClass("error").show().html(msg).addClass("success");

} else if (data.Errors["CRL"] == "NO_ROOT_KEY") {
$('#modal-root-key').modal('show');
return false;
} else if (data.Errors["CRL"] == "NO_ROOT_KEY") {
$('#modal-root-key').modal('show');
return false;

} else {
console.log("***DEBUG*** 3 ", data);
$("#root-crl-result").removeClass("hidden").removeClass("success").show().text(data.Errors["CRL"]).addClass("error");
}
})
.fail(function(xhr, status, err) {
$('#modal-spinner').modal('hide');
$("#root-crl-result").removeClass("hidden").removeClass("success").show().html(err + "<br/>").addClass("error");
});
} else {
$("#root-crl-result").removeClass("hidden").removeClass("success").show().text(data.Errors["CRL"]).addClass("error");
}
})
.fail(function(xhr, status, err) {
$('#modal-spinner').modal('hide');
$("#root-crl-result").removeClass("hidden").removeClass("success").show().html(err + "<br/>").addClass("error");
});
}

} else if ( $(evt.target).attr("id") == "upload-root-crl") {
$('#modal-spinner').modal('hide');
$('#modal-crl').modal('show');
return false;

} else if ( $(evt.target).attr("id") == "modal-crl-done") {
$('#modal-crl').modal('hide');
$.ajax(window.location.href, {
method: "POST",
data: {
action: 'upload-root-crl',
crl: $("#modal-crl-val").val(),
},
})
.done(function(data) {
if ($("#modal-crl-val").val() == "") {
$('#modal-spinner').modal('hide');
$("#modal-crl-error").show().text("Please provide CRL content");
return false;
} else {
$('#modal-crl').modal('hide');
$("#modal-crl-error").hide();
$.ajax(window.location.href, {
method: "POST",
data: {
action: 'upload-root-crl',
crl: $("#modal-crl-val").val(),
},
})
.done(function(data) {
$('#modal-spinner').modal('hide');

if (data.Success) {
var msg = "Successfully uploaded Root CRL.<br/>";
$("#root-crl-result").removeClass("hidden").removeClass("error").show().html(msg).addClass("success");
if (data.Success) {
var msg = "Successfully uploaded Root CRL.<br/>";
$("#root-crl-result").removeClass("hidden").removeClass("error").show().html(msg).addClass("success");

} else {
console.log("***DEBUG*** 4 ", data);
$("#root-crl-result").removeClass("hidden").removeClass("success").show().text(data.Errors["CRL"]).addClass("error");
}
})
.fail(function(xhr, status, err) {
$('#modal-spinner').modal('hide');
$("#root-crl-result").removeClass("hidden").removeClass("success").show().html(err + "<br/>").addClass("error");
});
} else {
$("#root-crl-result").removeClass("hidden").removeClass("success").show().text(data.Errors["CRL"]).addClass("error");
}
})
.fail(function(xhr, status, err) {
$('#modal-spinner').modal('hide');
$("#root-crl-result").removeClass("hidden").removeClass("success").show().html(err + "<br/>").addClass("error");
});
}

} else if ( $(evt.target).attr("id") == "cancel-rootkey" || $(evt.target).attr("id") == "cancel-crl") {
$('#modal-spinner').modal('hide');
Expand Down

0 comments on commit 66b5121

Please sign in to comment.