Use a variable to handle the misc_dir

This commit is contained in:
Li Chen 2013-11-25 18:24:46 +01:00
parent e137e755c0
commit a9fdcaf9f2
3 changed files with 58 additions and 26 deletions

View File

@ -24,39 +24,53 @@ function remove_directory($dir)
function new_client($name)
{
//TODO handle if already exist
putenv("OPENSSL_CONF=".ONYX. '../misc/openssl.cnf');
putenv("TOP_DIR=".ONYX. '../misc/pki');
$output = shell_exec(ONYX . "../misc/CA.sh -newclient $name");
if (isset($VAR['misc_dir']))
$misc_dir = $VAR['misc_dir'];
else
{
erreur("Merci d'ajouter la variable misc_dir dans root.xml");
return "admin/home";
}
//TODO handle if already exist
putenv("OPENSSL_CONF=$misc_dir/openssl.cnf");
putenv("TOP_DIR=$misc_dir/pki");
$output = shell_exec("$misc_dir/CA.sh -newclient $name");
}
if (!empty($p[2]))
{
if (isset($VAR['misc_dir']))
$misc_dir = $VAR['misc_dir'];
else
{
erreur("Merci d'ajouter la variable misc_dir dans root.xml");
return "admin/home";
}
$misc_dir = $VAR['misc_dir'];
if ($p[2] == "newca")
{
//TODO handle if already exist
putenv("OPENSSL_CONF=".ONYX. '../misc/openssl.cnf');
putenv("TOP_DIR=".ONYX. '../misc/pki');
$output = shell_exec(ONYX . '../misc/CA.sh -newca');
putenv("OPENSSL_CONF=$misc_dir/openssl.cnf");
putenv("TOP_DIR=$misc_dir/pki");
$output = shell_exec("$misc_dir/CA.sh -newca");
//TODO handle the path ?
$ca_file = ONYX . '../misc/pki/cacert.crt';
$ca_file = "$misc_dir/pki/cacert.crt";
//TODO check permission ?
if (file_exists($ca_file))
{
$data = openssl_x509_parse(file_get_contents(ONYX . '../misc/pki/cacert.crt'));
$data = openssl_x509_parse(file_get_contents("$misc_dir/pki/cacert.crt"));
$template->assign("cert", $data);
}
}
elseif ($p[2] == "deleteca")
{
//TODO handle var path
$dir = ONYX . '../misc/pki';
$dir = "$misc_dir/pki";
remove_directory($dir);
}
}
//header("Location: /admin/");
//exit;
header("Location: /admin/");
exit;

View File

@ -2,20 +2,31 @@
if(!defined('ONYX')) exit;
if (is_writable(ONYX."../misc/") && !is_dir(ONYX."../misc/pki/"))
mkdir(ONYX."../misc/pki/");
if (isset($VAR['misc_dir']))
$misc_dir = $VAR['misc_dir'];
else
{
erreur("Merci d'ajouter la variable misc_dir dans root.xml");
return "admin/home";
}
$wright = is_writable(ONYX."../misc/pki/");
if (is_writable($misc_dir) && !is_dir("$misc_dir/pki/"))
mkdir("$misc_dir/pki/");
$wright = is_writable("$misc_dir/pki/");
$template->assign("cert_writable", $wright);
//TODO handle the path ?
$ca_file = ONYX . '../misc/pki/cacert.crt';
$ca_file = "$misc_dir/pki/cacert.crt";
//TODO check permission ?
if (file_exists($ca_file))
{
$data = openssl_x509_parse(file_get_contents(ONYX . '../misc/pki/cacert.crt'));
$template->assign("cert", $data);
if (!is_readable($ca_file))
erreur("Impossible de lire le fichier");
else
{
$data = openssl_x509_parse(file_get_contents(ONYX . '../misc/pki/cacert.crt'));
$template->assign("cert", $data);
}
}
return "admin/home";

View File

@ -6,8 +6,15 @@ include 'certificate.php';
if (!empty($_FILES["inputFile"]['tmp_name']))
{
//TODO use a variable to define the path
if (!file_exists(ONYX . "../misc/fic_pki/cacert.crt"))
if (isset($VAR['misc_dir']))
$misc_dir = $VAR['misc_dir'];
else
{
erreur("Please add the misc_dir variable into root.xml");
return "admin/import_users";
}
if (!file_exists("$misc_dir/pki/cacert.crt"))
{
erreur("The root certificate file not found, please create this first");
return "admin/import_users";