Commit b3cfed72 authored by Denis Bonnenfant's avatar Denis Bonnenfant
Browse files

merge

parent 1ac99bf7
......@@ -31,6 +31,7 @@
* info_depot_id_appli($config, $id_depot_applications) : liste des infos d'une application d'un depot
* info_appli_version_depot($config, $id_depot,$id_nom_appli) : liste des infos d'une application donnee sur le depot id_depot
* info_categorie($config) : liste des categories des applications actives
*
* ----------------------------------------------------------------------------------------------------
*
* insert_poste_info_wpkg($config, $info) : insere un poste
......@@ -64,6 +65,15 @@
* desactive_depot_applis($config, $id_depot) : desactive toutes les applis d'un depot
* delete_depot_applis_inactives($config, $id_depot) : supprime toutes les applications inactives d'un depot
* update_hash_depot($config, $id_depot,$hash_xml) : met a jour le hash du xml source du depot
*
* ----------------------------------------------------------------------------------------------------
*
* maintenance_liste_poste($config,$flag,$uuid) : liste des postes avec info uuid + protection
* maintenance_poste_protection($config,$id_poste) passage du poste en mode protege
* maintenance_poste_deprotection($config,$id_poste) passage du poste en mode deprotege
* maintenance_poste_suppression($config,$id_poste) autorisation de la suppresion d un poste sans uuid
* maintenance_poste_reset_wpkg($config,$id_poste) changement hash du rapport pour forcer la relecture du rapport
*
* ----------------------------------------------------------------------------------------------------
*/
......@@ -1489,4 +1499,189 @@ function update_hash_depot($config, $id_depot, $hash_xml)
deconnexion_db_wpkg($wpkg_link);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function maintenance_liste_poste($config,$flag,$uuid)
{
$wpkg_link = connexion_db_wpkg($config);
if ($flag!=-1)
$query_flag="AND p.flag_poste=".($flag+0);
else
$query_flag="";
$query_uuid="";
switch($uuid)
{
case 0:
$query_uuid=" AND (p.uuid_poste is NULL OR p.uuid_poste like 'DELETE%')";
break;
case 1:
$query_uuid=" AND (p.uuid_poste is not NULL AND p.uuid_poste not like 'DELETE%')";
break;
}
$query = mysqli_prepare($wpkg_link, "SELECT p.id_poste, p.nom_poste, p.OS_poste, p.date_rapport_poste, p.ip_poste, p.mac_address_poste, p.file_log_poste, p.file_rapport_poste, p.date_modification_poste, p.flag_poste, p.uuid_poste, count(distinct pa.id_app) as nb_appli, sum(pa.statut_poste_app='Installed') as nb_appli_installed
FROM (`postes` p)
LEFT JOIN (`poste_app` pa) ON pa.id_poste=p.id_poste
WHERE 1=1 ".$query_flag.$query_uuid."
GROUP BY p.nom_poste ASC
ORDER BY p.date_modification_poste ASC");
mysqli_stmt_execute($query);
mysqli_stmt_bind_result($query, $res_id_poste, $res_nom_poste, $res_OS_poste, $res_date_rapport_poste, $res_ip_poste, $res_mac_address_poste, $res_file_log_poste, $res_file_rapport_poste, $res_date_modification_poste, $res_flag_poste, $res_uuid_poste, $res_nb_appli, $res_nb_appli_installed);
mysqli_stmt_store_result($query);
$num_rows = mysqli_stmt_num_rows($query);
$tab = array();
if ($num_rows != 0) {
while (mysqli_stmt_fetch($query))
{
$tab[strtolower($res_nom_poste)] = array(
"id" => $res_id_poste,
"nom_poste" => strtolower($res_nom_poste),
"OS_poste" => $res_OS_poste,
"date_rapport_poste" => $res_date_rapport_poste,
"IP_poste" => $res_ip_poste,
"mac_address_poste" => $res_mac_address_poste,
"file_log_poste" => $res_file_log_poste,
"file_rapport_poste" => $res_file_rapport_poste,
"date_modification_poste" => $res_date_modification_poste,
"uuid_poste" => $res_uuid_poste,
"flag_poste" => $res_flag_poste,
"nb_appli_installed" => $res_nb_appli_installed,
"nb_appli" => $res_nb_appli
);
}
}
mysqli_stmt_close($query);
deconnexion_db_wpkg($wpkg_link);
return $tab;
}
function maintenance_poste_protection($config,$id_poste)
{
$wpkg_link = connexion_db_wpkg($config);
$query = mysqli_prepare($wpkg_link, "SELECT nom_poste, flag_poste FROM `postes` WHERE id_poste=?");
mysqli_stmt_bind_param($query, "i", $id_poste);
mysqli_stmt_execute($query);
mysqli_stmt_bind_result($query, $res_nom_poste, $res_flag_poste);
mysqli_stmt_store_result($query);
$num_rows = mysqli_stmt_num_rows($query);
$nom_poste=0;
if ($num_rows == 1)
{
while (mysqli_stmt_fetch($query))
{
$nom_poste = $res_nom_poste;
$flag_poste = $res_flag_poste;
}
if ($flag_poste!=1)
{
$update_query = mysqli_prepare($wpkg_link, "UPDATE `postes` SET `flag_poste`=1, `date_modification_poste`=NOW() WHERE `id_poste`=?");
mysqli_stmt_bind_param($update_query, "i", $id_poste);
mysqli_stmt_execute($update_query);
mysqli_stmt_close($update_query);
}
else
$nom_poste=0;
}
mysqli_stmt_close($query);
deconnexion_db_wpkg($wpkg_link);
return $nom_poste;
}
function maintenance_poste_deprotection($config,$id_poste)
{
$wpkg_link = connexion_db_wpkg($config);
$query = mysqli_prepare($wpkg_link, "SELECT nom_poste, flag_poste, uuid_poste FROM `postes` WHERE id_poste=?");
mysqli_stmt_bind_param($query, "i", $id_poste);
mysqli_stmt_execute($query);
mysqli_stmt_bind_result($query, $res_nom_poste, $res_flag_poste, $res_uuid_poste);
mysqli_stmt_store_result($query);
$num_rows = mysqli_stmt_num_rows($query);
$nom_poste=0;
if ($num_rows == 1)
{
while (mysqli_stmt_fetch($query))
{
$nom_poste = $res_nom_poste;
$flag_poste = $res_flag_poste;
$uuid_poste = $res_uuid_poste;
}
if ($flag_poste!=0 and $uuid_poste!="")
{
$update_query = mysqli_prepare($wpkg_link, "UPDATE `postes` SET `flag_poste`=0, `date_modification_poste`=NOW() WHERE `id_poste`=?");
mysqli_stmt_bind_param($update_query, "i", $id_poste);
mysqli_stmt_execute($update_query);
mysqli_stmt_close($update_query);
}
else
$nom_poste=0;
}
mysqli_stmt_close($query);
deconnexion_db_wpkg($wpkg_link);
return $nom_poste;
}
function maintenance_poste_suppression($config,$id_poste)
{
$wpkg_link = connexion_db_wpkg($config);
$query = mysqli_prepare($wpkg_link, "SELECT nom_poste, flag_poste, uuid_poste FROM `postes` WHERE id_poste=?");
mysqli_stmt_bind_param($query, "i", $id_poste);
mysqli_stmt_execute($query);
mysqli_stmt_bind_result($query, $res_nom_poste, $res_flag_poste, $res_uuid_poste);
mysqli_stmt_store_result($query);
$num_rows = mysqli_stmt_num_rows($query);
$nom_poste=0;
if ($num_rows == 1)
{
while (mysqli_stmt_fetch($query))
{
$nom_poste = $res_nom_poste;
$flag_poste = $res_flag_poste;
$uuid_poste = $res_uuid_poste;
}
if ($uuid_poste=="")
{
$delete_uuid="DELETE".$id_poste;
$update_query = mysqli_prepare($wpkg_link, "UPDATE `postes` SET `flag_poste`=0, `uuid_poste`=?, `date_modification_poste`=NOW() WHERE `id_poste`=?");
mysqli_stmt_bind_param($update_query, "si", $delete_uuid, $id_poste);
mysqli_stmt_execute($update_query);
mysqli_stmt_close($update_query);
}
else
$nom_poste=0;
}
mysqli_stmt_close($query);
deconnexion_db_wpkg($wpkg_link);
return $nom_poste;
}
function maintenance_poste_reset_wpkg($config,$id_poste)
{
$wpkg_link = connexion_db_wpkg($config);
$query = mysqli_prepare($wpkg_link, "SELECT nom_poste, flag_poste FROM `postes` WHERE id_poste=?");
mysqli_stmt_bind_param($query, "i", $id_poste);
mysqli_stmt_execute($query);
mysqli_stmt_bind_result($query, $res_nom_poste, $res_flag_poste);
mysqli_stmt_store_result($query);
$num_rows = mysqli_stmt_num_rows($query);
$nom_poste=0;
if ($num_rows == 1)
{
while (mysqli_stmt_fetch($query))
{
$nom_poste = $res_nom_poste;
}
$update_query = mysqli_prepare($wpkg_link, "UPDATE `postes` SET `sha_rapport_poste`='miaou', `date_modification_poste`=NOW() WHERE `id_poste`=?");
mysqli_stmt_bind_param($update_query, "i", $id_poste);
mysqli_stmt_execute($update_query);
mysqli_stmt_close($update_query);
}
mysqli_stmt_close($query);
deconnexion_db_wpkg($wpkg_link);
return $nom_poste;
}
?>
<?php
/**
* Maintenance gestion des postes
* @Projet LCS / SambaEdu
* @auteurs Laurent Joly
* @note
* @Licence Distribue sous la licence GPL
*/
// loading libs and init
include "entete.inc.php";
include "ihm.inc.php";
include "wpkg_lib.php";
include "wpkg_libsql.php";
$login = isauth();
if (! $login) {
echo "<script language=\"JavaScript\" type=\"text/javascript\">\n<!--\n";
$request = '/wpkg/index.php';
echo "top.location.href = '/auth.php?request=" . rawurlencode($request) . "';\n";
echo "//-->\n</script>\n";
exit();
}
if (! have_right($config, "computer_is_admin"))
die(gettext("Vous n'avez pas les droits suffisants pour acc&#233;der &#224; cette fonction") . "</BODY></HTML>");
// HTMLpurifier
$conf = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($conf);
if (isset($_GET["tri"]))
$tri = $purifier->purify($_GET["tri"]) + 0;
else
$tri = 0;
if (isset($_GET['flag']))
$get_flag = $purifier->purify($_GET['flag']);
else
$get_flag = -1;
if (isset($_GET['uuid']))
$get_uuid = $purifier->purify($_GET['uuid']);
else
$get_uuid = -1;
if (isset($_POST["valider"]))
$post_valider = $purifier->purify($_POST["valider"]);
else
$post_valider = "";
$page_id=1;
include("maintenance_top.php");
if ($post_valider == "Valider les modifications")
{
if (isset($_POST["poste_id"]))
$post_poste_id = $_POST["poste_id"];
else
$post_poste_id = array();
if (isset($_POST["action"]))
$post_action = $purifier->purify($_POST["action"])+0;
else
$post_action = 0;
echo "<p align='left'>";
$count=0;
switch($post_action)
{
case 0:
echo "<b><i>Aucune action</i></b>";
break;
case 1:
echo "<b><i>Protection des machines :</i></b> ";
foreach ($post_poste_id as $tmp)
{
$result=maintenance_poste_protection($config,$tmp);
if ($result)
{
if ($count==0)
$count=1;
else
echo ", ";
echo $result;
}
}
break;
case 2:
echo "<b><i>D&#233;protection des machines :</i></b> ";
foreach ($post_poste_id as $tmp)
{
$result=maintenance_poste_deprotection($config,$tmp);
if ($result)
{
if ($count==0)
$count=1;
else
echo ", ";
echo $result;
}
}
break;
case 3:
echo "<b><i>Suppression des machines sans uuid :</i></b> ";
foreach ($post_poste_id as $tmp)
{
$result=maintenance_poste_suppression($config,$tmp);
if ($result)
{
if ($count==0)
$count=1;
else
echo ", ";
echo $result;
}
}
break;
case 4:
echo "<b><i>Recharger le dernier rapport wpkg des machines :</i></b> ";
foreach ($post_poste_id as $tmp)
{
$result=maintenance_poste_reset_wpkg($config,$tmp);
if ($result)
{
if ($count==0)
$count=1;
else
echo ", ";
echo $result;
}
}
break;
case 5:
echo "<b><i>Aucune action</i></b>";
break;
case 6:
echo "<b><i>Aucune action</i></b>";
break;
}
echo "</p></ br>";
}
echo "<script>\n";
echo "function checkAll()\n";
echo "{\n";
echo " var checkboxes = document.getElementsByTagName('input'), val = null; \n";
echo " for (var i = 0; i < checkboxes.length; i++)\n";
echo " {\n";
echo " if (checkboxes[i].type == 'checkbox')\n";
echo " {\n";
echo " if (val === null) val = checkboxes[i].checked;\n";
echo " checkboxes[i].checked = val;\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "</script>\n";
$liste_poste=maintenance_liste_poste($config,$get_flag,$get_uuid);
$tri_poste = array();
$tri_flag = array();
$tri_date = array();
$tri_ip = array();
$tri_mac = array();
$tri_nb_app = array();
foreach ($liste_poste as $key => $row) {
$tri_poste[] = $key;
$tri_flag[] = $row["flag_poste"];
$tri_date[] = $row["date_modification_poste"];
$tri_ip[] = ip2long($row["IP_poste"]);
$tri_mac[] = $row["mac_address_poste"];
$tri_nb_app[] = $row["nb_appli_installed"];
}
if ($liste_poste) {
switch ($tri) {
case 0:
array_multisort($tri_poste, SORT_ASC, $liste_poste);
break;
case 1:
array_multisort($tri_poste, SORT_DESC, $liste_poste);
break;
case 2:
array_multisort($tri_flag, SORT_ASC, $tri_poste, SORT_ASC, $liste_poste);
break;
case 3:
array_multisort($tri_flag, SORT_DESC, $tri_poste, SORT_ASC, $liste_poste);
break;
case 4:
array_multisort($tri_nb_app, SORT_DESC, $tri_poste, SORT_ASC, $liste_poste);
break;
case 5:
array_multisort($tri_nb_app, SORT_ASC, $tri_poste, SORT_ASC, $liste_poste);
break;
case 6:
array_multisort($tri_date, SORT_DESC, $tri_poste, SORT_ASC, $liste_poste);
break;
case 7:
array_multisort($tri_date, SORT_ASC, $tri_poste, SORT_ASC, $liste_poste);
break;
case 8:
array_multisort($tri_ip, SORT_ASC, $liste_poste);
break;
case 9:
array_multisort($tri_ip, SORT_DESC, $liste_poste);
break;
case 10:
array_multisort($tri_mac, SORT_ASC, $liste_poste);
break;
case 11:
array_multisort($tri_mac, SORT_DESC, $liste_poste);
break;
default:
array_multisort($tri_poste, SORT_ASC, $liste_poste);
break;
}
}
echo "<table cellspadding='2' cellspacing='1' border='0' align='center' bgcolor='black'>\n";
echo "<tr style='color:white'>\n";
echo "<th width='10' rowspan='2'></th>\n";
echo "<th width='120' rowspan='2'><a href='?flag=".$get_flag."&uuid=".$get_uuid."&tri=";
if ($tri == 0)
echo "1";
else
echo "0";
echo "' style='color:" . $regular_lnk . "'>Nom du poste</a></th>\n";
echo "<th width='50' rowspan='2'>OS</th>\n";
echo "<th width='120'><a href='?flag=".$get_flag."&uuid=".$get_uuid."&tri=";
if ($tri == 2)
echo "3";
else
echo "2";
echo "' style='color:" . $regular_lnk . "'>Statut</a></th>\n";
echo "<th width='180' colspan='2'>Nombre d'applications</th>\n";
echo "<th width='200' rowspan='2'><a href='?flag=".$get_flag."&uuid=".$get_uuid."&tri=";
if ($tri == 6)
echo "7";
else
echo "6";
echo "' style='color:" . $regular_lnk . "'>Date du dernier rapport</a></th>\n";
echo "<th width='120' rowspan='2'><a href='?flag=".$get_flag."&uuid=".$get_uuid."&tri=";
if ($tri == 8)
echo "9";
else
echo "8";
echo "' style='color:" . $regular_lnk . "'>Adresse IP</a></th>\n";
echo "<th width='160' rowspan='2'><a href='?flag=".$get_flag."&uuid=".$get_uuid."&tri=";
if ($tri == 10)
echo "11";
else
echo "10";
echo "' style='color:" . $regular_lnk . "'>Adresse mac</a></th>\n";
echo "<th width='160'>Uuid machine</a></th>\n";
echo "</tr>\n";
echo "<form method='get' action=''>\n";
echo "<tr style='color:white'>\n";
echo "<th>";
echo " <select name='flag' onchange='submit()'>";
echo " <option value='-1'";
if ($get_flag==-1)
echo " selected";
echo ">Tout</option>";
echo " <option value='0'";
if ($get_flag==0)
echo " selected";
echo ">Non prot&#233;g&#233;</option>";
echo " <option value='1'";
if ($get_flag==1)
echo " selected";
echo ">Prot&#233;g&#233;</option>";
echo " <option value='2'";
if ($get_flag==2)
echo " selected";
echo ">Autre</option>";
echo " </select>";
echo "</th>\n";
echo "<th width='90'>Total</th>\n";
echo "<th width='90'><a href='?flag=".$get_flag."&uuid=".$get_uuid."&tri=";
if ($tri == 4)
echo "5";
else
echo "4";
echo "' style='color:" . $regular_lnk . "'>Install&#233;es</a></th>\n";
echo "<th>";
echo " <select name='uuid' onchange='submit()'>";
echo " <option value='-1'";
if ($get_uuid==-1)
echo " selected";
echo ">Tout</option>";
echo " <option value='0'";
if ($get_uuid==0)
echo " selected";
echo ">Inconnu</option>";
echo " <option value='1'";
if ($get_uuid==1)
echo " selected";
echo ">Connu</option>";
echo " </select>";
echo "</th>\n";
echo "</tr>\n";
echo "<input type='hidden' name='tri' value='" . $tri . "'>\n";
echo "</form>\n";
echo "<tr>\n";
echo "<td colspan='10'>\n";
echo "<table cellspadding='2' cellspacing='1' border='0' align='center' bgcolor='white' width='100%'>\n";
echo "<form method='post' action='?tri=" . $tri . "&flag=" . $get_flag . "&uuid=" . $get_uuid . "'>\n";
echo "<tr>\n";
echo "<td width='33%' style='color:black' align='center'>";
echo "<select name='action' style='color:white;background-color:red'>";
echo "<option value='0'>-- Choisir une action --</option>";
echo "<option value='1'>Prot&#233;ger des machines</option>";
echo "<option value='2'>D&#233;prot&#233;ger des machines</option>";
echo "<option value='3'>Supprimer des machines sans uuid</option>";
echo "<option value='4'>Recharger le dernier rapport wpkg</option>";
echo "<option value='5'>Rien</option>";
echo "</select>";
echo "</td>\n";
echo "<td width='33%' style='color:black' align='center'>";
echo "<input type='checkbox' onchange='checkAll()' name='chk[]' /> Tous/Aucun";
echo "</td>\n";
echo "<td width='*' style='color:black' align='center'>";
echo "<input type='submit' name='valider' value='Valider les modifications' style='color:white;background-color:red'>";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</td>\n";
echo "</tr>\n";
foreach ($liste_poste as $nom_poste => $lp)
{
$affichage = 0;
switch ($lp["flag_poste"]) {
case 0:
$bg = $ok_bg;
$lnk = $ok_lnk;
$txt = $ok_txt;
$affichage = 1;
break;
case 1:
$bg = $error_bg;
$lnk = $error_lnk;
$txt = $error_txt;
$affichage = 1;
break;
case 2:
$bg = $warning_bg;
$lnk = $warning_lnk;
$txt = $warning_txt;
$affichage = 1;
break;
}
if ($affichage == 1)
{
echo "<tr bgcolor='" . $bg . "' style='color: " . $txt . "'>";
echo "<td align='center'>";
echo "<input type='checkbox' id='poste_id[]' name='poste_id[]' value='" . $lp["id"] . "' />";
echo "</td>";
echo "<td align='center'><a href='poste_statuts.php?id_host=" . $nom_poste . "' style='color: " . $lnk . "'>" . $nom_poste . "</a></td>";
echo "<td align='center' bgcolor='" . $wintype_txt . "'>";
echo '<img src="images/';
switch ($lp["OS_poste"]) {
case 'Windows XP':
echo "winxp.png";
break;
case 'Windows 7':
echo "win7.png";
break;
case 'Windows 10':
echo "win10.png";
break;