Files
scm/api/frontend/js/rootcrt.js
T
wt e6526fb780
Build / Build (push) Successful in 19s
added createrootcertificateifnotexists
2025-07-21 22:11:04 +07:00

66 lines
2.2 KiB
JavaScript

const createRootCertificateModal = bootstrap.Modal.getOrCreateInstance(
document.querySelector("#createRootCertificate"),
);
const createRootCrtButton = document.querySelector("#createRootCrt");
const rootcommonnameinput = document.querySelector("#rootcommonname");
const rootorganizationinput = document.querySelector("#rootorganizationname");
const rootorganizationalunitinput = document.querySelector(
"#rootorganizationalunit",
);
const rootcountryinput = document.querySelector("#rootCountry");
const rootlocalityinput = document.querySelector("#rootLocality");
const rootprovinceinput = document.querySelector("#rootProvince");
const rootstreetaddressinput = document.querySelector("#rootStreetAddress");
const rootpostalcodeinput = document.querySelector("#rootPostalCode");
const rootvalidityyearsinput = document.querySelector("#rootValidityYears");
const rootkeypasswordinput = document.querySelector("#rootkeypassword");
const getRootCrt = () => {
fetch(window.location.origin + "/api/certs/root")
.then((data) => data.json())
.then((jsondata) => {
console.log(jsondata);
})
.catch((error) => {
createRootCertificateModal.show();
});
};
getRootCrt();
createRootCrtButton.addEventListener("click", () => {
const newRootCertificate = {
CommonName: rootcommonnameinput.value,
Organization: [rootorganizationinput.value],
OrganizationalUnit: [rootorganizationalunitinput.value],
Country: [rootcountryinput.value],
Locality: [rootlocalityinput.value],
Province: [rootprovinceinput.value],
StreetAddress: [rootstreetaddressinput.value],
PostalCode: [rootpostalcodeinput.value],
ValidityYears: parseInt(rootvalidityyearsinput.value),
KeyPassword: rootkeypasswordinput.value,
};
fetch(window.location.origin + "/api/certs/root", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(newRootCertificate),
}).then((data) =>
data
.json()
.then((jsondata) => {
console.log(jsondata);
if (jsondata.status === "ok") {
alert("Root certificate created successfully");
createRootCertificateModal.hide();
}
})
.catch((error) => {
alert(error);
}),
);
});