Possibility to generate and delete the root CA in the admin panel
This commit is contained in:
parent
38f1886972
commit
c5c54f3b1a
5 changed files with 111 additions and 7 deletions
|
@ -43,8 +43,13 @@ if ($n && $p[0] == SALT_ADMIN)
|
|||
|
||||
switch($cmpstr)
|
||||
{
|
||||
case "exercices/import/":
|
||||
case "certificate":
|
||||
case "certificate/":
|
||||
$page = require("admin/certificate.php");
|
||||
break;
|
||||
|
||||
case "exercices/import":
|
||||
case "exercices/import/":
|
||||
$page = require("admin/import_exercices.php");
|
||||
break;
|
||||
|
||||
|
|
42
onyx/include/admin/certificate.php
Normal file
42
onyx/include/admin/certificate.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
if (!defined('ONYX')) exit;
|
||||
|
||||
if (isset($_GET['generate']))
|
||||
{
|
||||
//TODO handle if already exist
|
||||
putenv("OPENSSL_CONF=".ONYX. '../misc/openssl.cnf');
|
||||
putenv("TOP_DIR=".ONYX. '../misc/fic_pki');
|
||||
$output = shell_exec(ONYX . '../misc/CA.sh -newca 2> toto');
|
||||
$template->assign("output", $output);
|
||||
}
|
||||
|
||||
function remove_directory($dir)
|
||||
{
|
||||
if (is_dir($dir))
|
||||
{
|
||||
$objects = scandir($dir);
|
||||
foreach ($objects as $object)
|
||||
{
|
||||
if ($object != "." && $object != "..")
|
||||
{
|
||||
if (filetype($dir."/".$object) == "dir")
|
||||
remove_directory($dir."/".$object);
|
||||
else
|
||||
unlink($dir."/".$object);
|
||||
}
|
||||
}
|
||||
reset($objects);
|
||||
rmdir($dir);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['delete']))
|
||||
{
|
||||
//TODO handle var path
|
||||
$dir = ONYX . '../misc/fic_pki';
|
||||
|
||||
remove_directory($dir);
|
||||
}
|
||||
|
||||
return "admin/home";
|
|
@ -2,4 +2,16 @@
|
|||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
return "admin/home";
|
||||
//TODO handle the path ?
|
||||
$ca_file = ONYX . '../misc/fic_pki/cacert.crt';
|
||||
|
||||
//TODO check permission ?
|
||||
if (!file_exists($ca_file))
|
||||
erreur("Can not to find the root certificate");
|
||||
else
|
||||
{
|
||||
$data = openssl_x509_parse(file_get_contents(ONYX . '../misc/fic_pki/cacert.crt'));
|
||||
$template->assign("cert", $data);
|
||||
}
|
||||
|
||||
return "admin/home";
|
||||
|
|
|
@ -4,11 +4,18 @@ if(!defined('ONYX')) exit;
|
|||
|
||||
if (!empty($_FILES["inputFile"]['tmp_name']))
|
||||
{
|
||||
//TODO use a variable to define the path
|
||||
if (!file_exists(ONYX . "../misc/fic_pki/cacert.crt"))
|
||||
{
|
||||
erreur("The root certificate file not found, please create this first");
|
||||
return "admin/import_users";
|
||||
}
|
||||
|
||||
$doc = new DOMDocument();
|
||||
if (@!$doc->load($_FILES["inputFile"]['tmp_name']))
|
||||
{
|
||||
erreur("Unable to parse given file. A XML file was expected.");
|
||||
return;
|
||||
return "admin/import_users";
|
||||
}
|
||||
|
||||
$xpath = new DOMXpath($doc);
|
||||
|
|
|
@ -1,7 +1,45 @@
|
|||
{extends file="admin/layout.tpl"}
|
||||
|
||||
{block name=content}
|
||||
<h1>
|
||||
Zone d'administration
|
||||
</h1>
|
||||
{block name=head}
|
||||
<link href="/css/common.css" rel="stylesheet">
|
||||
{/block}
|
||||
|
||||
{block name=content}
|
||||
|
||||
<div class="panel panel-info">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Certificat racine FIC 2014</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{if isset($cert)}
|
||||
<ul>
|
||||
<li><strong>[C] :</strong> {$cert['subject']['C']}</li>
|
||||
<li><strong>[ST] :</strong> {$cert['subject']['ST']}</li>
|
||||
<li><strong>[O] :</strong> {$cert['subject']['O']}</li>
|
||||
<li><strong>[OU] :</strong> {$cert['subject']['OU']}</li>
|
||||
<li><strong>[CN] :</strong> {$cert['subject']['CN']}</li>
|
||||
<li><strong>[emailAddress] :</strong> {$cert['subject']['emailAddress']}</li>
|
||||
</ul>
|
||||
<a href="/{$SALT_ADMIN}/certificate?delete" class="btn btn-danger">Supprimer</a>
|
||||
{else}
|
||||
<a href="/{$SALT_ADMIN}/certificate?generate" class="btn btn-primary">Nouveau</a>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{if isset($output)}
|
||||
<div class="panel panel-info">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Output</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<pre>
|
||||
{$output}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
|
||||
{/block}
|
||||
|
|
Reference in a new issue