Add some checks on directories

This commit is contained in:
Némunaire 2013-11-25 15:38:06 +01:00
commit 861b644b9e
7 changed files with 83 additions and 40 deletions

View file

@ -26,33 +26,37 @@ function new_client($name)
{
//TODO handle if already exist
putenv("OPENSSL_CONF=".ONYX. '../misc/openssl.cnf');
putenv("TOP_DIR=".ONYX. '../misc/fic_pki');
putenv("TOP_DIR=".ONYX. '../misc/pki');
$output = shell_exec(ONYX . "../misc/CA.sh -newclient $name");
}
if (isset($_GET['newca']))
if (!empty($p[2]))
{
if ($p[2] == "newca")
{
//TODO handle if already exist
putenv("OPENSSL_CONF=".ONYX. '../misc/openssl.cnf');
putenv("TOP_DIR=".ONYX. '../misc/fic_pki');
putenv("TOP_DIR=".ONYX. '../misc/pki');
$output = shell_exec(ONYX . '../misc/CA.sh -newca');
//TODO handle the path ?
$ca_file = ONYX . '../misc/fic_pki/cacert.crt';
$ca_file = ONYX . '../misc/pki/cacert.crt';
//TODO check permission ?
if (file_exists($ca_file))
{
$data = openssl_x509_parse(file_get_contents(ONYX . '../misc/fic_pki/cacert.crt'));
$template->assign("cert", $data);
$data = openssl_x509_parse(file_get_contents(ONYX . '../misc/pki/cacert.crt'));
$template->assign("cert", $data);
}
}
}
if (isset($_GET['deleteca']))
{
elseif ($p[2] == "deleteca")
{
//TODO handle var path
$dir = ONYX . '../misc/fic_pki';
$dir = ONYX . '../misc/pki';
remove_directory($dir);
}
}
return "admin/home";
//header("Location: /admin/");
//exit;

View file

@ -2,13 +2,19 @@
if(!defined('ONYX')) exit;
if (is_writable(ONYX."../misc/") && !is_dir(ONYX."../misc/pki/"))
mkdir(ONYX."../misc/pki/");
$wright = is_writable(ONYX."../misc/pki/");
$template->assign("cert_writable", $wright);
//TODO handle the path ?
$ca_file = ONYX . '../misc/fic_pki/cacert.crt';
$ca_file = ONYX . '../misc/pki/cacert.crt';
//TODO check permission ?
if (file_exists($ca_file))
{
$data = openssl_x509_parse(file_get_contents(ONYX . '../misc/fic_pki/cacert.crt'));
$data = openssl_x509_parse(file_get_contents(ONYX . '../misc/pki/cacert.crt'));
$template->assign("cert", $data);
}

View file

@ -4,19 +4,38 @@ if(!defined('ONYX')) exit;
$solved = count($EXERCICE->get_solved());
if ($n == 5 && $p[4] == "submission")
if ($n >= 5 && $p[4] == "submission")
{
$template->assign("ERRcolor", "success");
$template->assign("ERRmessage", "Votre réponse a bien été prise en compte et sera évaluée dans quelques instants...");
if ($n >= 6 && $p[5] == "werr")
{
$template->assign("ERRcolor", "danger");
if (DEBUG)
$template->assign("ERRmessage", "DEBUG ERROR: le répertoire submission n'est pas accessible en écriture.");
else
$template->assign("ERRmessage", "Une erreur s'est produite durant la soumission. Veuillez réessayer dans quelques instants.");
}
else
{
$template->assign("ERRcolor", "success");
$template->assign("ERRmessage", "Votre réponse a bien été prise en compte et sera évaluée dans quelques instants...");
}
if (!empty($_POST["solution"]))
{
$file = ONYX . "../submission/".$p[1]."-".$p[2]."-".$p[3];
if (is_writable(ONYX . "../submission/"))
{
$file = ONYX . "../submission/".$p[1]."-".$p[2]."-".$p[3];
file_put_contents($file, $_POST['solution'], LOCK_EX);
file_put_contents($file, $_POST['solution'], LOCK_EX);
header("Location: /".implode("/", $p));
exit;
header("Location: /".implode("/", $p));
exit;
}
else
{
header("Location: /".implode("/", $p)."/werr");
exit;
}
}
}