Files
scm/api/frontend/js/rootcrt.js
T
2025-07-24 15:01:04 +07:00

69 lines
2.3 KiB
JavaScript

const createRootCertificateModal = bootstrap.Modal.getOrCreateInstance(
document.querySelector("#createRootCertificate"),
);
const createRootCertificateForm = document.querySelector(
"#createRootCertificateForm",
);
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();
createRootCertificateForm.addEventListener("submit", (event) => {
event.preventDefault();
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);
}),
);
});