Commit 380c9c1c authored by root's avatar root

Ajout gestion des logs

parent 156a1ec1
......@@ -7,6 +7,8 @@ class Controller extends MY_Controller {
protected $topicMQTT_Changes; // Topic utilisé pour prévenir des changements dans la table capteur en BDD
protected $topicMQTT_Notif; // Topic utilisé pour informer le client de l'arrivée d'une nouvelle notification
protected $consigneMonitoring; // Localisation du fichier de consigne utiliser pour la maintenance
public function __construct() {
parent::__construct();
$this->serveur_mqtt = 'icaging.com';
......@@ -14,11 +16,16 @@ class Controller extends MY_Controller {
$this->topicMQTT_Status = "/system/mqtt";
$this->topicMQTT_Changes = "/system/changeCapteur";
$this->topicMQTT_Notif = "/system/notification/".$this->session->userdata('id');
$this->consigneMonitoring = python('ConsigneMonitoring.txt');
//$this->load->library('form_validation');
// charge les helpers pour les assets
$this->load->helper('url');
$this->load->helper('assets');
// Helpers utilisee pour la gestion des logs
$this->load->helper('download');
$this->load->helper('directory');
}
public function dash() {
......@@ -119,8 +126,6 @@ class Controller extends MY_Controller {
$result .= ', "idGroupes" : '.$resultGroupe ;
$result .= '}';
//$result = implode($unites)." !=?=! ".$listeCapteur[0]->unite. " == ".(!in_array($listeCapteur[0]->unite, $unites));
echo json_encode($result);
}
......@@ -507,7 +512,7 @@ class Controller extends MY_Controller {
$this->load->view('fragment/footer');
}
/* Tratement : Supprime l'image et le fichier texte generee par le script python */
/* Traitement : Supprime l'image et le fichier texte generee par le script python */
public function purgeGraphique($uuid){
if(file_exists(python('log_'.$uuid.'.txt'))){
unlink(python('log_'.$uuid.'.txt'));
......@@ -517,5 +522,98 @@ class Controller extends MY_Controller {
unlink(python($uuid.'.png'));
}
}
/* Page : Consultation des logs et pilotage du systeme a distance */
public function monitoring(){
$logs = directory_map(python('logs/'));
asort($logs);
$data["logs"] = $logs ;
$fileConsigne = $this->consigneMonitoring;
$data["consigne"] = file_get_contents($fileConsigne);
$this->header();
$this->load->view('pages/monitoring', $data);
$this->load->view('fragment/footer');
}
/* Traitement : Force le telechargement du fichier de consigne pour le Monitoring.
Attention: ce fichier et ce lien ne sont pas protegee par l'authentification (voir MY_Controller dans core), il ne doit pas contenir d'information sensible */
public function consigneMonitoringDownload(){
$file = $this->consigneMonitoring;
force_download($file, NULL);
}
/* Traitement : Supprime un log */
public function removeLog() {
$name = $this->input->post('name') ;
if(file_exists(python('logs/').$name)){
unlink(python('logs/').$name);
}
redirect('controller/monitoring');
}
/* Traitement : Supprime tous les logs */
public function purgeLogs() {
$logs = scandir(python('logs/'));
foreach($logs as $log){
if(is_file(python('logs/').$log)) {
unlink(python('logs/').$log);
}
}
redirect('controller/monitoring');
}
/* AJAX : Renvoie le contenu du fichier */
public function displayLog() {
$name = $this->input->post('name') ;
$data = file_get_contents(python('logs/').$name);
echo $data;
}
/* Traitement : Ajout d'une consigne dans le fichier de log */
public function ajoutConsigne($consigne, $param = "") {
$consigneTexte = "";
$checkDouble = "";
if($consigne == 0) { // Effacer le fichier
$f = fopen($this->consigneMonitoring, 'w');
fclose($f);
} else if($consigne == 1) { // Rappatriement des logs
$consigneTexte="logs";
$checkDouble=$consigneTexte;
} else if($consigne == 2) { // Information Hardware
$consigneTexte="hard";
$checkDouble=$consigneTexte;
} else if($consigne == 3) { // Changement frequence
$consigneTexte="freq=".$param;
$checkDouble="freq=";
}
if ($consigneTexte != "") {
$f = fopen($this->consigneMonitoring, 'a');
clearstatcache();
$contenuFichier = file_get_contents($this->consigneMonitoring) ;
if( strpos($contenuFichier, $checkDouble) === false) { # Pas de consigne en double
if(filesize($this->consigneMonitoring) !== 0) {
fwrite($f, ";");
}
fwrite($f, $consigneTexte);
}
fclose($f);
}
redirect('controller/monitoring');
}
}
?>
......@@ -3,7 +3,8 @@
// S'occupe de la sécurité de l'application
class MY_Controller extends CI_Controller {
protected $_no_access_control = array (
'controller/connexion'
'controller/connexion',
'controller/consigneMonitoringDownload'
);
public function __construct() {
......
......@@ -3,7 +3,7 @@
<div class="navbar-header">
<a class="navbar-minimalize minimalize-styl-2" href="#" style="background-color:#22427c;"><div class="barMenu"></div></a>
</div>
<div class="navbar-header minimalize-styl-2" style="width:20%;">
<div class="hidden-xs navbar-header minimalize-styl-2" style="width:20%;">
<select id="filtreGroupe" data-placeholder="Filtre par groupe..." multiple class="chosen-select">
<?php foreach ($listeGroupe as $groupe) {
echo "<option value=\"".$groupe->id."\"";
......@@ -11,7 +11,7 @@
}?>
</select>
</div>
<div class="navbar-header minimalize-styl-2" style="width:10%;">
<div class="hidden-xs navbar-header minimalize-styl-2" style="width:10%;">
<select id="filtreUnite" data-placeholder="Filtre par unité..." multiple class="chosen-select">
<?php foreach ($listeUnite as $unite) {
echo "<option value=\"".$unite->unite."\"";
......@@ -19,7 +19,7 @@
}?>
</select>
</div>
<div class="navbar-header minimalize-styl-2" style="width:10%;">
<div class="hidden-xs navbar-header minimalize-styl-2" style="width:10%;">
<select id="filtreTag" data-placeholder="Filtre par tags..." multiple class="chosen-select">
<?php foreach ($listeTag as $tag) {
echo "<option value=\"".$tag->tag."\"";
......@@ -27,10 +27,10 @@
}?>
</select>
</div>
<div class="navbar-header minimalize-styl-2 checkMin" style="width:10%;">
<div class="hidden-xs navbar-header minimalize-styl-2 checkMin" style="width:10%;">
<input type="number" id="filtreMin" name="filtreMin" value="" placeholder="Min..." class="form-control">
</div>
<div class="navbar-header minimalize-styl-2 checkMax" style="width:10%;">
<div class="hidden-xs navbar-header minimalize-styl-2 checkMax" style="width:10%;">
<input type="number" id="filtreMax" name="filtreMax" value="" placeholder="Max..." class="form-control">
</div>
<ul class="nav navbar-top-links navbar-right row">
......
......@@ -36,7 +36,7 @@
</div>
<div class="col-lg-6 animated fadeInDown" style="margin-bottom:10px;">
<a href= "<?php echo base_url() ?>index.php/controller/visu">
<a href= "<?php echo base_url() ?>index.php/controller/monitoring">
<div id="menuPrinc4">
<div class="p-m">
<h1 class="m-xs">Maintenance</h1>
......@@ -71,7 +71,7 @@
</div>
</a>
</div>
<div class="col-lg-6 animated fadeInDown" style="margin-bottom:10px;">
<a href= "<?php echo base_url() ?>index.php/controller/settings">
<div id="menuPrinc3">
......
<!-- Page : Visualisation du graphe generee par le script python -->
<h1 id="titre">Visualisation complexe</h1>
<div id="zone" class="progress">
<div id="progress" class="progress-bar progress-bar-striped progress-bar-animated progress-bar-success" style="width: 0%" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">hy</div>
<div id="progress" class="progress-bar progress-bar-striped progress-bar-animated progress-bar-warning" style="width: 0%" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">hy</div>
</div>
<script>
......
<div class="panel panel-primary">
<div class="panel panel-heading">
<h3>Consigne Monitoring</h3> Les consignes sont appliquées lors de la mise à jour des données
</div>
<div class="panel panel-body">
<ul>
<?php
$listConsignes = explode(";", $consigne);
foreach ($listConsignes as $c) {
if (strpos($c, "freq") !== false) {
$paramFreq = explode("=", $c)[1];
$c = "Changement de frequence à ".$paramFreq;
}
else if ($c === "logs") {
$c = "Rappatriement des Logs";
}
else if ($c === "hard") {
$c = "Rappatriement de l'état de la connexion du matériel";
}
if ($c !== "") {
echo "<li class=\"list-group-item active\"><h3><b>".$c."</b></h3></li>\n";
}
}
?>
</ul>
</div>
</div>
<div class="panel panel-default">
<div class="panel panel-heading">
<h4>Ajout de consignes</h4>
</div>
<div class="panel panel-body">
<button onclick="ajoutConsigne(1);" class="btn btn-info btn-rounded">Rapatriement Logs</button>
<button onclick="ajoutConsigne(2);" class="btn btn-info btn-rounded">Information Hardware</button>
<button onclick="ajoutConsigne(3);" class="btn btn-info btn-rounded">Changement de Frequence d'envoi</button>
<button onclick="ajoutConsigne(0);" class="btn btn-danger btn-rounded">Effacer les consignes</button>
</div>
</div>
<div class="row accordionDisplay" id="accordionDisplay">
<div class="col-lg-12">
<div class="panel-body">
<div class="panel-group" id="accordion" style="border-style:solid; border-color:#f3f3f4;">
<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse">
<div class="row">
<div class="col-xs-11">
<h5 class="panel-title">Logs disponibles</h5>
</div>
<div class="col-xs-1">
<?php echo form_open('controller/purgeLogs', ''); ?>
<input type="submit" value="Purge" class="btnPurge btn btn-danger" style="margin-bottom: -20px;margin-top: -7px;" />
</form>
</div>
</div>
</a>
</div>
<div id="collapse" class="panel-collapse collapse in">
<div class="panel-body gray-bg">
<table class="table table-hover table-bordered">
<tbody>
<?php foreach ($logs as $log) { ?>
<tr>
<td class="col-md-11"><a onclick="displayLog('<?php echo $log; ?>');"><?php echo $log; ?></a></td>
<td class="col-md-1">
<?php $hidden = array('name' => $log) ; ?>
<?php echo form_open('controller/removeLog', '', $hidden); ?>
<input type="submit" value="Supprimer" class="everySubmit btn btn-danger btn-rounded" />
</form>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
function ajoutConsigne(consigne) {
switch (consigne) {
case 0: // Effacer consignes
window.location.replace("<?php echo base_url();?>index.php/controller/ajoutConsigne/0");
break;
case 1: // Rapatriement Logs
window.location.replace("<?php echo base_url();?>index.php/controller/ajoutConsigne/1");
break;
case 2: // Information Hardware
window.location.replace("<?php echo base_url();?>index.php/controller/ajoutConsigne/2");
break;
case 3: // Changement de frequence d'envoi
swal("", {
title: "Delai de Rappatriement",
text: "Delai en secondes, valeur par defaut:10800 (3h)",
content: {
element: "input",
attributes: {
placeholder: "Veuillez mettre la nouvelle frequence d'envoi",
type: "text"
}
}
})
.then((inputValue) => {
if (inputValue === false || inputValue === null) {
return false;
}
if (inputValue === "") {
swal("Erreur", "Vous devez mettre un delai !", "error");
return false;
}
if(isNaN(inputValue)) {
swal("Erreur", "Vous devez mettre un nombre positif !", "error");
return false;
}
if(inputValue < 60 || inputValue > 86400) {
swal("Erreur", "Vous devez mettre un nombre compris entre 60 et 86400 !", "error");
return false;
}
var freq = inputValue.trim();
window.location.replace("<?php echo base_url();?>index.php/controller/ajoutConsigne/3/"+freq);
});
break;
default:
}
}
function displayLog(log) {
var url = "<?php echo base_url() ?>index.php/controller/displayLog";
$.ajax({
url: url,
type: 'POST',
dataType: 'text',
data: {"name": log},
success : function(response){
swal({
title: "Log "+log,
text: response,
className: 'grosSwal',
});
},
failure : function(response){
alert("Error! Please Contact technical support");
}
});
}
$(".everySubmit").on("click", function(e) {
e.preventDefault();
var form = $(this).parents('form');
swal({
title: "Êtes-vous sûr de vouloir supprimer ce log ?",
icon: "warning",
buttons: true,
dangerMode: true
})
.then((willDelete) => {
if (willDelete) {
console.log("True");
form.submit();
}
});
});
$(".btnPurge").on("click", function(e) {
e.preventDefault();
var form = $(this).parents('form');
swal({
title: "Êtes-vous sûr de vouloir supprimer tout les logs ?",
icon: "warning",
buttons: true,
dangerMode: true
})
.then((willDelete) => {
if (willDelete) {
console.log("True");
form.submit();
}
});
});
</script>
......@@ -259,8 +259,6 @@ function creationFormulaire(titre, nomUser){
});
}
//** --------- Traitement des groupes ----------- **/
function ajouterGroupe(){
var idGroupe = $("#groupes").val();
......
......@@ -39,6 +39,10 @@ h5 {
font-weight: 600;
}
.grosSwal{
width:850px !important;
}
#menuPrinc1 {
background-color: #EB7039;
color: #ffffff;
......
logs
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment