Move the function remove_team from list_users.php to Team.class

Revoke certificates after drop all teams
This commit is contained in:
Li Chen 2013-12-01 19:40:47 +01:00
parent 964d3b067f
commit 31eabf84b4
4 changed files with 43 additions and 18 deletions

View File

@ -31,6 +31,13 @@ function new_client($name, $misc_dir)
return $output;
}
function revoke_client($name, $misc_dir)
{
putenv("OPENSSL_CONF=$misc_dir/openssl.cnf");
putenv("TOP_DIR=$misc_dir/pki");
$output = shell_exec("$misc_dir/CA.sh -revoke $name");
}
if (!empty($p[2]))
{
if (isset($VAR['misc_dir']))
@ -60,11 +67,9 @@ if (!empty($p[2]))
$name = $_GET['name'];
if (isset($name))
{
putenv("OPENSSL_CONF=$misc_dir/openssl.cnf");
putenv("TOP_DIR=$misc_dir/pki");
$output = shell_exec("$misc_dir/CA.sh -revoke $name");
//TODO Check revocation failed
Team::set_revoked(TRUE, $name);
$output = revoke_client($name, $misc_dir);
//TODO Check revocation failed
Team::set_revoked(TRUE, $name);
}
}
// Is new team

View File

@ -2,29 +2,40 @@
if(!defined('ONYX')) exit;
function remove_team($id)
{
$db = new BDD();
$db->query("DELETE FROM team_members WHERE id_team = ".$id);
$db->query("DELETE FROM solved WHERE id_team = ".$id);
$db->query("DELETE FROM teams WHERE id = ".$id);
$db->deconnexion();
}
include 'certificate.php';
if (!empty($_GET["delete"]))
{
$id_team = intval($_GET["delete"]);
if (isset($VAR['misc_dir']))
$misc_dir = $VAR['misc_dir'];
else
{
erreur("Merci d'ajouter la variable misc_dir dans root.xml");
return SALT_ADMIN."/users";
}
remove_team($id_team);
$id_team = intval($_GET["delete"]);
revoke_client($_GET['name'], $misc_dir);
Team::remove_team($id_team);
header("Location: /".SALT_ADMIN."/teams");
exit;
}
else if (isset($_GET["drop"]))
{
if (isset($VAR['misc_dir']))
$misc_dir = $VAR['misc_dir'];
else
{
erreur("Merci d'ajouter la variable misc_dir dans root.xml");
return SALT_ADMIN."/users";
}
foreach(Team::get_teams() as $team)
{
remove_team($team->get_id());
//TODO check output
revoke_client($team->team_name, $misc_dir);
Team::remove_team($team->get_id());
}
header("Location: /".SALT_ADMIN."/teams");
@ -33,4 +44,4 @@ else if (isset($_GET["drop"]))
$template->assign("teams", Team::get_teams());
return "admin/users";
return SALT_ADMIN."/users";

View File

@ -246,6 +246,15 @@ class Team
return ($aff == 1);
}
public static function remove_team($id)
{
$db = new BDD();
$db->query("DELETE FROM team_members WHERE id_team = ".$id);
$db->query("DELETE FROM solved WHERE id_team = ".$id);
$db->query("DELETE FROM teams WHERE id = ".$id);
$db->deconnexion();
}
public static function get_teams()
{
$db = new BDD();

View File

@ -19,7 +19,7 @@
<tr>
<td>
{$t->id}<br>
<a href="?delete={$t->id}" onclick="return confirm('Êtes-vous sûr de vouloir supprimer cette équipe ?')">
<a href="?delete={$t->id}&name={$t->team_name}" onclick="return confirm('Êtes-vous sûr de vouloir supprimer cette équipe ?')">
<span class="glyphicon glyphicon-trash"></span></a>
<a href="/{$SALT_ADMIN}/certificate/get?name={$t->team_name}">
<span class="glyphicon glyphicon-download"></span></a>