1 parent
bf50da525e
commit
39c27b0de3
9 files changed
+386
-115
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"scm/model"
|
||||
)
|
||||
|
||||
func RootCert(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
_, err := os.Stat(fmt.Sprintf("%s/%s", os.Getenv("CERTS_PATH"), "root/root.crt"))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, `{"status":"ok"}`)
|
||||
case "POST":
|
||||
var rootCertRequest model.CreateRootCertRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&rootCertRequest)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
fmt.Fprintf(w, `{"status":"ok"}`)
|
||||
default:
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
@@ -305,5 +305,87 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" tabindex="-1" id="create_certificate">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Create SSl Certificate</h5>
|
||||
<button
|
||||
type="button"
|
||||
data-bs-dismiss="modal"
|
||||
aria-label="Close"
|
||||
class="btn-close"
|
||||
></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="text"
|
||||
id="domain"
|
||||
class="form-control"
|
||||
placeholder="example.domain"
|
||||
/>
|
||||
<label for="domain">Domain</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="text"
|
||||
id="commonname"
|
||||
class="form-control"
|
||||
placeholder="commonname"
|
||||
/>
|
||||
<label for="commonname">Common Name</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="text"
|
||||
id="organizationname"
|
||||
class="form-control"
|
||||
placeholder="organizationname"
|
||||
/>
|
||||
<label for="organizationname"
|
||||
>Organization Name</label
|
||||
>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="text"
|
||||
id="organizationunit"
|
||||
class="form-control"
|
||||
placeholder="organizationunit"
|
||||
/>
|
||||
<label for="organizationunit"
|
||||
>Organization Unit</label
|
||||
>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
class="form-control"
|
||||
placeholder="example.domain"
|
||||
/>
|
||||
<label for="password">RootCA password</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button
|
||||
type="button"
|
||||
data-bs-dismiss="modal"
|
||||
class="btn btn-secondary"
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
<button
|
||||
id="createcert"
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
>
|
||||
Create
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
+109
-114
@@ -4,132 +4,127 @@ const preview = document.querySelector("#preview");
|
||||
var certificates = [];
|
||||
|
||||
const renderCards = () => {
|
||||
cards.innerHTML = "";
|
||||
cards.innerHTML = "";
|
||||
if (certificates !== null) {
|
||||
certificates.map((cert) => {
|
||||
cards.innerHTML += `<div class="card" style="width: 16rem">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title" style="text-align: center">
|
||||
<a href="${cert.href}">${cert.domain}</a>
|
||||
</h5>
|
||||
</div>
|
||||
<div
|
||||
class="card-footer d-flex flex-column align-items-center gap-2"
|
||||
>
|
||||
<button type="button"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#preview"
|
||||
data-bs-whatever="${cert.cert}"
|
||||
data-bs-dnsnames="${cert.certinfo.DNSNames}"
|
||||
data-bs-notafter="${cert.certinfo.NotAfter}"
|
||||
data-bs-notbefore="${cert.certinfo.NotBefore}"
|
||||
data-bs-issuer-commonname="${cert.certinfo.Issuer.CommonName}"
|
||||
data-bs-issuer-organization="${cert.certinfo.Issuer.Organization}"
|
||||
data-bs-issuer-organizationunit="${cert.certinfo.Issuer.OrganizationalUnit}"
|
||||
data-bs-subject-commonname="${cert.certinfo.Subject.CommonName}"
|
||||
data-bs-subject-organization="${cert.certinfo.Subject.Organization}"
|
||||
data-bs-subject-organizationunit="${cert.certinfo.Subject.OrganizationalUnit}"
|
||||
class="btn btn-primary"
|
||||
style="width: 100%"
|
||||
>
|
||||
Cert
|
||||
</button>
|
||||
<button class="btn btn-primary" style="width: 100%">
|
||||
Download
|
||||
</button>
|
||||
<button class="btn btn-danger delcert" id="${cert.id}" style="width: 100%">
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>`;
|
||||
cards.innerHTML += `<div class="card" style="width: 16rem">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title" style="text-align: center">
|
||||
<a href="${cert.href}">${cert.domain}</a>
|
||||
</h5>
|
||||
</div>
|
||||
<div
|
||||
class="card-footer d-flex flex-column align-items-center gap-2"
|
||||
>
|
||||
<button type="button"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#preview"
|
||||
data-bs-whatever="${cert.cert}"
|
||||
data-bs-dnsnames="${cert.certinfo.DNSNames}"
|
||||
data-bs-notafter="${cert.certinfo.NotAfter}"
|
||||
data-bs-notbefore="${cert.certinfo.NotBefore}"
|
||||
data-bs-issuer-commonname="${cert.certinfo.Issuer.CommonName}"
|
||||
data-bs-issuer-organization="${cert.certinfo.Issuer.Organization}"
|
||||
data-bs-issuer-organizationunit="${cert.certinfo.Issuer.OrganizationalUnit}"
|
||||
data-bs-subject-commonname="${cert.certinfo.Subject.CommonName}"
|
||||
data-bs-subject-organization="${cert.certinfo.Subject.Organization}"
|
||||
data-bs-subject-organizationunit="${cert.certinfo.Subject.OrganizationalUnit}"
|
||||
class="btn btn-primary"
|
||||
style="width: 100%"
|
||||
>
|
||||
Cert
|
||||
</button>
|
||||
<button class="btn btn-primary" style="width: 100%">
|
||||
Download
|
||||
</button>
|
||||
<button class="btn btn-danger delcert" id="${cert.id}" style="width: 100%">
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>`;
|
||||
});
|
||||
} else {
|
||||
cards.innerHTML = `<h1>No Certificates Found</h1>`;
|
||||
}
|
||||
};
|
||||
|
||||
const getCerts = () => {
|
||||
fetch(window.location.origin + "/api/certs")
|
||||
.then((data) => data.json())
|
||||
.then((data) => {
|
||||
certificates = data;
|
||||
renderCards();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching certificates:", error);
|
||||
alert("Failed to fetch certificates");
|
||||
});
|
||||
fetch(window.location.origin + "/api/certs")
|
||||
.then((data) => data.json())
|
||||
.then((data) => {
|
||||
certificates = data;
|
||||
renderCards();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching certificates:", error);
|
||||
alert("Failed to fetch certificates");
|
||||
});
|
||||
};
|
||||
|
||||
getCerts();
|
||||
|
||||
if (preview) {
|
||||
preview.addEventListener("show.bs.modal", (e) => {
|
||||
const button = e.relatedTarget;
|
||||
const recipient = button.getAttribute("data-bs-whatever");
|
||||
// const modalBodyTextarea = preview.querySelector(".modal-body textarea");
|
||||
const dnsnames = button.getAttribute("data-bs-dnsnames");
|
||||
const notafter = button.getAttribute("data-bs-notafter");
|
||||
const notbefore = button.getAttribute("data-bs-notbefore");
|
||||
const issuerorganizationunit = button.getAttribute(
|
||||
"data-bs-issuer-organizationunit",
|
||||
);
|
||||
const issuerorganization = button.getAttribute(
|
||||
"data-bs-issuer-organization",
|
||||
);
|
||||
const issuercommonname = button.getAttribute(
|
||||
"data-bs-issuer-commonname",
|
||||
);
|
||||
const subjectorganizationunit = button.getAttribute(
|
||||
"data-bs-subject-organizationunit",
|
||||
);
|
||||
const subjectorganization = button.getAttribute(
|
||||
"data-bs-subject-organization",
|
||||
);
|
||||
const subjectcommonname = button.getAttribute(
|
||||
"data-bs-subject-commonname",
|
||||
);
|
||||
preview.querySelector("#raw").innerHTML = recipient.replace(
|
||||
/\n/g,
|
||||
"<br>",
|
||||
);
|
||||
preview.querySelector("#dnsNames").value = dnsnames;
|
||||
preview.querySelector("#notAfter").value = notafter;
|
||||
preview.querySelector("#notBefore").value = notbefore;
|
||||
preview.querySelector("#issuerorganizationunit").value =
|
||||
issuerorganizationunit;
|
||||
preview.querySelector("#issuerorganization").value = issuerorganization;
|
||||
preview.querySelector("#issuercommonname").value = issuercommonname;
|
||||
preview.querySelector("#subjectorganizationunit").value =
|
||||
subjectorganizationunit;
|
||||
preview.querySelector("#subjectorganization").value =
|
||||
subjectorganization;
|
||||
preview.querySelector("#subjectcommonname").value = subjectcommonname;
|
||||
});
|
||||
preview.addEventListener("show.bs.modal", (e) => {
|
||||
const button = e.relatedTarget;
|
||||
const recipient = button.getAttribute("data-bs-whatever");
|
||||
// const modalBodyTextarea = preview.querySelector(".modal-body textarea");
|
||||
const dnsnames = button.getAttribute("data-bs-dnsnames");
|
||||
const notafter = button.getAttribute("data-bs-notafter");
|
||||
const notbefore = button.getAttribute("data-bs-notbefore");
|
||||
const issuerorganizationunit = button.getAttribute(
|
||||
"data-bs-issuer-organizationunit",
|
||||
);
|
||||
const issuerorganization = button.getAttribute(
|
||||
"data-bs-issuer-organization",
|
||||
);
|
||||
const issuercommonname = button.getAttribute("data-bs-issuer-commonname");
|
||||
const subjectorganizationunit = button.getAttribute(
|
||||
"data-bs-subject-organizationunit",
|
||||
);
|
||||
const subjectorganization = button.getAttribute(
|
||||
"data-bs-subject-organization",
|
||||
);
|
||||
const subjectcommonname = button.getAttribute("data-bs-subject-commonname");
|
||||
preview.querySelector("#raw").innerHTML = recipient.replace(/\n/g, "<br>");
|
||||
preview.querySelector("#dnsNames").value = dnsnames;
|
||||
preview.querySelector("#notAfter").value = notafter;
|
||||
preview.querySelector("#notBefore").value = notbefore;
|
||||
preview.querySelector("#issuerorganizationunit").value =
|
||||
issuerorganizationunit;
|
||||
preview.querySelector("#issuerorganization").value = issuerorganization;
|
||||
preview.querySelector("#issuercommonname").value = issuercommonname;
|
||||
preview.querySelector("#subjectorganizationunit").value =
|
||||
subjectorganizationunit;
|
||||
preview.querySelector("#subjectorganization").value = subjectorganization;
|
||||
preview.querySelector("#subjectcommonname").value = subjectcommonname;
|
||||
});
|
||||
}
|
||||
|
||||
cards.addEventListener("click", (e) => {
|
||||
if (e.target.classList.contains("delcert")) {
|
||||
if (confirm("Are you sure you want to delete this certificate?")) {
|
||||
fetch(window.location.origin + `/api/certs/delete`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
domain: certificates.find((item) => item.id === e.target.id)
|
||||
.domain,
|
||||
}),
|
||||
})
|
||||
.then((data) => data.json())
|
||||
.then((jsondata) => {
|
||||
if (jsondata.status === "success") {
|
||||
getCerts();
|
||||
alert("Certificate deleted successfully");
|
||||
} else {
|
||||
alert("Failed to delete certificate");
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
alert("An error occurred while deleting the certificate");
|
||||
});
|
||||
}
|
||||
if (e.target.classList.contains("delcert")) {
|
||||
if (confirm("Are you sure you want to delete this certificate?")) {
|
||||
fetch(window.location.origin + `/api/certs/delete`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
domain: certificates.find((item) => item.id === e.target.id).domain,
|
||||
}),
|
||||
})
|
||||
.then((data) => data.json())
|
||||
.then((jsondata) => {
|
||||
if (jsondata.status === "success") {
|
||||
getCerts();
|
||||
alert("Certificate deleted successfully");
|
||||
} else {
|
||||
alert("Failed to delete certificate");
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
alert("An error occurred while deleting the certificate");
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user