Files
scm/api/frontend/js/create_cert.js
T

48 lines
1.5 KiB
JavaScript

const domain = document.querySelector("#domain");
const commonname = document.querySelector("#commonname");
const organizationname = document.querySelector("#organizationname");
const password = document.querySelector("#password");
const organizationunit = document.querySelector("#organizationunit");
const create_certificate_form = document.querySelector(
"#create_certificate_form",
);
create_certificate_form.addEventListener("submit", (event) => {
event.preventDefault();
const domainValue = domain.value;
const commonnameValue = commonname.value;
const organizationnameValue = organizationname.value;
const passwordValue = password.value;
const organizationunitValue = organizationunit.value;
fetch(window.location.origin + "/api/certs", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
dns: [domainValue],
commonname: commonnameValue,
organizationname: [organizationnameValue],
organizationunit: [organizationunitValue],
password: passwordValue,
}),
})
.then((data) => data.json())
.then((jsondata) => {
if (jsondata.status === "success") {
getCerts();
var createmodal = bootstrap.Modal.getOrCreateInstance(
document.getElementById("create_certificate"),
);
createmodal.hide();
alert("Certificate created successfully");
} else {
alert("Failed to create certificate:", jsondata.error);
}
})
.catch((error) => {
alert("An error occurred:", error);
});
});