mirror of https://github.com/itflow-org/itflow
commit
2b3dad9082
|
|
@ -29,7 +29,7 @@
|
|||
</div>
|
||||
<input type="text" class="form-control" name="domain" id="domain" placeholder="FQDN" required>
|
||||
<div class="input-group-append">
|
||||
<button type="button" class="btn btn-secondary" onclick="fetchSSL()"><i class="fas fa-fw fa-sync-alt"></i></button>
|
||||
<button type="button" class="btn btn-secondary" onclick="fetchSSL('new')"><i class="fas fa-fw fa-sync-alt"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-building"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="issued_by" id="issued_by" placeholder="Issued By">
|
||||
<input type="text" class="form-control" name="issued_by" id="issuedBy" placeholder="Issued By">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -60,7 +60,7 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-key"></i></span>
|
||||
</div>
|
||||
<textarea class="form-control" name="public_key" id="public_key" placeholder="-----BEGIN CERTIFICATE-----"></textarea>
|
||||
<textarea class="form-control" name="public_key" id="publicKey" placeholder="-----BEGIN CERTIFICATE-----"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
<div class="modal" id="editCertificateModal<?php echo $certificate_id; ?>" tabindex="-1">
|
||||
<div class="modal" id="editCertificateModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-lock"></i> <?php echo $certificate_name ?></h5>
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-lock"></i><span id="editHeader"></span></h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="certificate_id" value="<?php echo $certificate_id; ?>">
|
||||
<input type="hidden" name="certificate_id" value="" id="editCertificateId">
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
<div class="form-group">
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-lock"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="name" placeholder="Certificate name" value="<?php echo $certificate_name; ?>" required>
|
||||
<input type="text" class="form-control" id="editCertificateName" name="name" placeholder="Certificate name" value="" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -27,9 +27,9 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-globe"></i> https://</span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="domain" placeholder="Domain" id="domain" value="<?php echo $certificate_domain; ?>" required>
|
||||
<input type="text" class="form-control" id="editDomain" name="domain" placeholder="Domain" value="" required>
|
||||
<div class="input-group-append">
|
||||
<button type="button" class="btn btn-secondary" onclick="fetchSSL()"><i class="fas fa-fw fa-sync-alt"></i></button>
|
||||
<button type="button" class="btn btn-secondary" onclick="fetchSSL('edit')"><i class="fas fa-fw fa-sync-alt"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-building"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="issued_by" placeholder="Issued By" id="issued_by" value="<?php echo $certificate_issued_by; ?>">
|
||||
<input type="text" class="form-control" id="editIssuedBy" name="issued_by" placeholder="Issued By" value="">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control" name="expire" id="expire" value="<?php echo $certificate_expire; ?>">
|
||||
<input type="date" class="form-control" id="editExpire" name="expire" value="">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -60,7 +60,7 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-key"></i></span>
|
||||
</div>
|
||||
<textarea class="form-control" name="public_key" id="public_key"><?php echo $certificate_public_key; ?></textarea>
|
||||
<textarea class="form-control" id="editPublicKey" name="public_key"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -70,21 +70,7 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-globe"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="domain_id">
|
||||
<option value="">- Domain -</option>
|
||||
<?php
|
||||
$domains_sql = mysqli_query($mysqli, "SELECT * FROM domains WHERE domain_client_id = '$client_id'");
|
||||
while($domain_row = mysqli_fetch_array($domains_sql)){
|
||||
$domain_id = $domain_row['domain_id'];
|
||||
$domain_name = $domain_row['domain_name'];
|
||||
if($certificate_domain_id == $domain_id){
|
||||
echo "<option value=\"$domain_id\" selected>$domain_name</option>";
|
||||
}
|
||||
else{
|
||||
echo "<option value=\"$domain_id\">$domain_name</option>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<select class="form-control select2" id="editDomainId" name="domain_id">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -98,13 +98,10 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||
$certificate_domain = $row['certificate_domain'];
|
||||
$certificate_issued_by = $row['certificate_issued_by'];
|
||||
$certificate_expire = $row['certificate_expire'];
|
||||
$certificate_updated_at = $row['certificate_updated_at'];
|
||||
$certificate_public_key = $row['certificate_public_key'];
|
||||
$certificate_domain_id = $row['certificate_domain_id'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><a class="text-dark" href="#" data-toggle="modal" data-target="#editCertificateModal<?php echo $certificate_id; ?>"><?php echo $certificate_name; ?></a></td>
|
||||
<td><a class="text-dark" href="#" data-toggle="modal" onclick="populateCertificateEditModal(<?php echo $client_id, ",", $certificate_id ?>)" data-target="#editCertificateModal"><?php echo $certificate_name; ?></a></td>
|
||||
<td><?php echo $certificate_domain; ?></td>
|
||||
<td><?php echo $certificate_issued_by; ?></td>
|
||||
<td><?php echo $certificate_expire; ?></td>
|
||||
|
|
@ -114,7 +111,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editCertificateModal<?php echo $certificate_id; ?>">Edit</a>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" onclick="populateCertificateEditModal(<?php echo $client_id, ",", $certificate_id ?>)" data-target="#editCertificateModal">Edit</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger" href="post.php?delete_certificate=<?php echo $certificate_id; ?>">Delete</a>
|
||||
</div>
|
||||
|
|
@ -123,10 +120,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||
</tr>
|
||||
|
||||
<?php
|
||||
|
||||
include("client_certificate_edit_modal.php");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</tbody>
|
||||
|
|
@ -136,13 +130,78 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<?php include("client_certificate_add_modal.php"); ?>
|
||||
<?php
|
||||
include("client_certificate_edit_modal.php");
|
||||
include("client_certificate_add_modal.php");
|
||||
?>
|
||||
|
||||
<script>
|
||||
function populateCertificateEditModal(client_id, certificate_id) {
|
||||
|
||||
// Send a GET request to post.php as post.php?certificate_get_json_details=true&client_id=NUM&certificate_id=NUM
|
||||
jQuery.get(
|
||||
"post.php",
|
||||
{certificate_get_json_details: 'true', client_id: client_id, certificate_id: certificate_id},
|
||||
function(data){
|
||||
|
||||
// If we get a response from post.php, parse it as JSON
|
||||
const response = JSON.parse(data);
|
||||
|
||||
// Access the certificate (one) and domains (multiple)
|
||||
const certificate = response.certificate[0];
|
||||
const domains = response.domains;
|
||||
|
||||
// Populate the cert modal fields
|
||||
document.getElementById("editHeader").innerText = " " + certificate.certificate_name;
|
||||
document.getElementById("editCertificateId").value = certificate_id;
|
||||
document.getElementById("editCertificateName").value = certificate.certificate_name;
|
||||
document.getElementById("editDomain").value = certificate.certificate_domain;
|
||||
document.getElementById("editIssuedBy").value = certificate.certificate_issued_by;
|
||||
document.getElementById("editExpire").value = certificate.certificate_expire;
|
||||
document.getElementById("editPublicKey").value = certificate.certificate_public_key;
|
||||
|
||||
// Select the domain dropdown
|
||||
var domainDropdown = document.getElementById("editDomainId");
|
||||
|
||||
// Clear domain dropdown
|
||||
var i, L = domainDropdown.options.length -1;
|
||||
for(i = L; i >= 0; i--) {
|
||||
domainDropdown.remove(i);
|
||||
}
|
||||
domainDropdown[domainDropdown.length] = new Option('- Domain -', '0');
|
||||
|
||||
// Populate domain dropdown
|
||||
domains.forEach(domain => {
|
||||
if(parseInt(domain.domain_id) == parseInt(certificate.certificate_domain_id)){
|
||||
// Selected domain
|
||||
domainDropdown[domainDropdown.length] = new Option(domain.domain_name, domain.domain_id, true, true);
|
||||
}
|
||||
else{
|
||||
domainDropdown[domainDropdown.length] = new Option(domain.domain_name, domain.domain_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function fetchSSL()
|
||||
function fetchSSL(type)
|
||||
{
|
||||
// Get the domain name input
|
||||
var domain = document.getElementById("domain").value;
|
||||
// Get the domain name input & issued/expire/key fields, based on whether this is a new cert or updating an existing
|
||||
if(type == 'new'){
|
||||
var domain = document.getElementById("domain").value;
|
||||
var issuedBy = document.getElementById("issuedBy");
|
||||
var expire = document.getElementById("expire");
|
||||
var publicKey = document.getElementById("publicKey");
|
||||
|
||||
}
|
||||
if(type == 'edit'){
|
||||
var domain = document.getElementById("editDomain").value;
|
||||
var issuedBy = document.getElementById("editIssuedBy");
|
||||
var expire = document.getElementById("editExpire");
|
||||
var publicKey = document.getElementById("editPublicKey");
|
||||
}
|
||||
|
||||
//Send a GET request to post.php as post.php?fetch_certificate=TRUE&domain=DOMAIN
|
||||
jQuery.get(
|
||||
|
|
@ -154,9 +213,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||
|
||||
if(ssl_data.success == "TRUE"){
|
||||
// Fill the form fields with the cert data
|
||||
document.getElementById("issued_by").value = ssl_data.issued_by;
|
||||
document.getElementById("expire").value = ssl_data.expire;
|
||||
document.getElementById("public_key").value = ssl_data.public_key;
|
||||
issuedBy.value = ssl_data.issued_by;
|
||||
expire.value = ssl_data.expire;
|
||||
publicKey.value = ssl_data.public_key;
|
||||
}
|
||||
else{
|
||||
alert("Error whilst parsing/retrieving details for domain")
|
||||
|
|
|
|||
23
post.php
23
post.php
|
|
@ -5217,7 +5217,30 @@ if(isset($_POST['edit_certificate'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_GET['certificate_get_json_details'])){
|
||||
$certificate_id = intval($_GET['certificate_id']);
|
||||
$client_id = intval($_GET['client_id']);
|
||||
|
||||
$cert_sql = mysqli_query($mysqli,"SELECT * FROM certificates WHERE certificate_id = $certificate_id AND certificate_client_id = $client_id");
|
||||
while($row = mysqli_fetch_array($cert_sql)){
|
||||
$response['certificate'][] = $row;
|
||||
}
|
||||
|
||||
$domains_sql = mysqli_query($mysqli, "SELECT domain_id, domain_name FROM domains
|
||||
WHERE domain_client_id = '$client_id' AND company_id = '$session_company_id'"
|
||||
);
|
||||
while($row = mysqli_fetch_array($domains_sql)){
|
||||
$response['domains'][] = $row;
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
if(isset($_GET['fetch_certificate'])){
|
||||
// PHP doesn't appreciate attempting SSL sockets to non-existent domains
|
||||
if(empty($_GET['domain'])){
|
||||
exit();
|
||||
}
|
||||
$domain = $_GET['domain'];
|
||||
|
||||
// FQDNs in database shouldn't have a URL scheme, adding one
|
||||
|
|
|
|||
Loading…
Reference in New Issue