Commit 44a02f94 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) add cert info action in system_certmanager.php

parent 45a82edb
...@@ -150,61 +150,55 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -150,61 +150,55 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} }
} elseif ($act == "exp") { } elseif ($act == "exp") {
if (!isset($id)) { // export cert
header("Location: system_certmanager.php"); if (isset($id)) {
exit; $exp_name = urlencode("{$a_cert[$id]['descr']}.crt");
$exp_data = base64_decode($a_cert[$id]['crt']);
$exp_size = strlen($exp_data);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$exp_name}");
header("Content-Length: $exp_size");
echo $exp_data;
} }
$exp_name = urlencode("{$a_cert[$id]['descr']}.crt");
$exp_data = base64_decode($a_cert[$id]['crt']);
$exp_size = strlen($exp_data);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$exp_name}");
header("Content-Length: $exp_size");
echo $exp_data;
exit; exit;
} elseif ($act == "key") { } elseif ($act == "key") {
if (!isset($id)) { // export key
header("Location: system_certmanager.php"); if (isset($id)) {
exit; $exp_name = urlencode("{$a_cert[$id]['descr']}.key");
$exp_data = base64_decode($a_cert[$id]['prv']);
$exp_size = strlen($exp_data);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$exp_name}");
header("Content-Length: $exp_size");
echo $exp_data;
} }
$exp_name = urlencode("{$a_cert[$id]['descr']}.key");
$exp_data = base64_decode($a_cert[$id]['prv']);
$exp_size = strlen($exp_data);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$exp_name}");
header("Content-Length: $exp_size");
echo $exp_data;
exit; exit;
} elseif ($act == "p12") { } elseif ($act == "p12") {
if (!isset($id)) { // export cert+key in p12 format
header("Location: system_certmanager.php"); if (isset($id)) {
exit; $exp_name = urlencode("{$a_cert[$id]['descr']}.p12");
} $args = array();
$args['friendly_name'] = $a_cert[$id]['descr'];
$exp_name = urlencode("{$a_cert[$id]['descr']}.p12");
$args = array();
$args['friendly_name'] = $a_cert[$id]['descr'];
$ca = lookup_ca($a_cert[$id]['caref']); $ca = lookup_ca($a_cert[$id]['caref']);
if ($ca) { if ($ca) {
$args['extracerts'] = openssl_x509_read(base64_decode($ca['crt'])); $args['extracerts'] = openssl_x509_read(base64_decode($ca['crt']));
} }
$res_crt = openssl_x509_read(base64_decode($a_cert[$id]['crt'])); $res_crt = openssl_x509_read(base64_decode($a_cert[$id]['crt']));
$res_key = openssl_pkey_get_private(array(0 => base64_decode($a_cert[$id]['prv']) , 1 => "")); $res_key = openssl_pkey_get_private(array(0 => base64_decode($a_cert[$id]['prv']) , 1 => ""));
$exp_data = ""; $exp_data = "";
openssl_pkcs12_export($res_crt, $exp_data, $res_key, null, $args); openssl_pkcs12_export($res_crt, $exp_data, $res_key, null, $args);
$exp_size = strlen($exp_data); $exp_size = strlen($exp_data);
header("Content-Type: application/octet-stream"); header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$exp_name}"); header("Content-Disposition: attachment; filename={$exp_name}");
header("Content-Length: $exp_size"); header("Content-Length: $exp_size");
echo $exp_data; echo $exp_data;
}
exit; exit;
} elseif ($act == "csr") { } elseif ($act == "csr") {
if (!isset($id)) { if (!isset($id)) {
...@@ -214,6 +208,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -214,6 +208,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig['descr'] = $a_cert[$id]['descr']; $pconfig['descr'] = $a_cert[$id]['descr'];
$pconfig['csr'] = base64_decode($a_cert[$id]['csr']); $pconfig['csr'] = base64_decode($a_cert[$id]['csr']);
$pconfig['cert'] = null; $pconfig['cert'] = null;
} elseif ($act == "info") {
if (isset($id)) {
// use openssl to dump cert in readable format
$process = proc_open('/usr/bin/openssl x509 -text', array(array("pipe", "r"), array("pipe", "w")), $pipes);
if (is_resource($process)) {
fwrite($pipes[0], base64_decode($a_cert[$id]['crt']));
fclose($pipes[0]);
$result = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
echo $result;
}
}
exit;
} }
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
...@@ -504,6 +513,21 @@ if (empty($act)) { ...@@ -504,6 +513,21 @@ if (empty($act)) {
?> ?>
<body> <body>
<style>
.monospace-dialog {
font-family: monospace;;
white-space: pre;
}
.monospace-dialog > .modal-dialog {
width:70% !important;
}
.modal-body {
max-height: calc(100vh - 210px);
overflow-y: auto;
}
</style>
<script type="text/javascript"> <script type="text/javascript">
$( document ).ready(function() { $( document ).ready(function() {
// delete entry // delete entry
...@@ -529,6 +553,25 @@ if (empty($act)) { ...@@ -529,6 +553,25 @@ if (empty($act)) {
}); });
}); });
$(".act_info").click(function(event){
event.preventDefault();
var id = $(this).data('id');
$.ajax({
url:"system_certmanager.php",
type: 'get',
data: {'act' : 'info', 'id' :id},
success: function(data){
BootstrapDialog.show({
title: '<?=gettext("Certificate");?>',
type:BootstrapDialog.TYPE_INFO,
message: data,
cssClass: 'monospace-dialog',
});
}
});
});
/** /**
* remove row from altNametable * remove row from altNametable
*/ */
...@@ -1217,6 +1260,9 @@ $( document ).ready(function() { ...@@ -1217,6 +1260,9 @@ $( document ).ready(function() {
<?php <?php
endif; ?> endif; ?>
<a href="#" class="btn btn-default btn-xs act_info" data-id="<?=$i;?>" data-toggle="tooltip" data-placement="left" title="<?=gettext("show certificate info");?>">
<span class="glyphicon glyphicon-info-sign"></span>
</a>
<a href="system_certmanager.php?act=exp&amp;id=<?=$i;?>" class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="left" title="<?=gettext("export ca");?>"> <a href="system_certmanager.php?act=exp&amp;id=<?=$i;?>" class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="left" title="<?=gettext("export ca");?>">
<span class="glyphicon glyphicon-download"></span> <span class="glyphicon glyphicon-download"></span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment