server/onyx/include/admin/certificate.php

62 lines
1.4 KiB
PHP
Raw Normal View History

<?php
if (!defined('ONYX')) exit;
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);
}
}
function new_client($name)
{
//TODO handle if already exist
putenv("OPENSSL_CONF=".ONYX. '../misc/openssl.cnf');
2013-11-25 14:38:06 +00:00
putenv("TOP_DIR=".ONYX. '../misc/pki');
$output = shell_exec(ONYX . "../misc/CA.sh -newclient $name");
}
2013-11-25 14:38:06 +00:00
if (!empty($p[2]))
{
2013-11-25 14:38:06 +00:00
if ($p[2] == "newca")
{
//TODO handle if already exist
putenv("OPENSSL_CONF=".ONYX. '../misc/openssl.cnf');
2013-11-25 14:38:06 +00:00
putenv("TOP_DIR=".ONYX. '../misc/pki');
$output = shell_exec(ONYX . '../misc/CA.sh -newca');
//TODO handle the path ?
2013-11-25 14:38:06 +00:00
$ca_file = ONYX . '../misc/pki/cacert.crt';
//TODO check permission ?
if (file_exists($ca_file))
{
2013-11-25 14:38:06 +00:00
$data = openssl_x509_parse(file_get_contents(ONYX . '../misc/pki/cacert.crt'));
$template->assign("cert", $data);
}
2013-11-25 14:38:06 +00:00
}
2013-11-25 14:38:06 +00:00
elseif ($p[2] == "deleteca")
{
//TODO handle var path
2013-11-25 14:38:06 +00:00
$dir = ONYX . '../misc/pki';
remove_directory($dir);
2013-11-25 14:38:06 +00:00
}
}
2013-11-25 14:38:06 +00:00
//header("Location: /admin/");
//exit;