[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3master/var/www/se3/alertes/ -> alertes.php (source)

   1  <?php
   2  
   3     /**
   4     
   5     * Permet de definir des alertes de supervision 
   6     * @Version $Id: alertes.php 7591 2013-01-06 01:46:31Z keyser $ 
   7     
   8    
   9     * @Projet LCS / SambaEdu 
  10     
  11     * @auteurs  Philippe Chadefaux
  12     
  13     * @Licence Distribue selon les termes de la licence GPL
  14     
  15     * @note 
  16     
  17     */
  18  
  19     /**
  20  
  21     * @Repertoire: alertes 
  22     * file: alertes.php
  23  
  24    */    
  25  
  26  include  "entete.inc.php";
  27  include  "ldap.inc.php";
  28  include  "ihm.inc.php";
  29  //require "dbconfig.inc.php";
  30  if ($inventaire=="1") { // Si inventaire on on inclu le fichier de conf
  31      include_once "dbconfig.inc.php";  
  32  }
  33  
  34  $action=$_POST['action'];
  35  if (!$action) { $action=$_GET['action']; }
  36  
  37  foreach($_GET as $key => $valeur)
  38      $$key = $valeur;
  39  
  40  if (is_admin("computers_is_admin",$login)=="Y") {
  41  
  42    //aide 
  43    $_SESSION["pageaide"]="L\'interface_web_administrateur#Gestion_des_alertes";
  44  
  45    echo "<H1>".gettext("Cr&#233;ation d'alertes")."</H1>\n";
  46  
  47  
  48    // Supprime une alerte perso
  49    if ($action=="suppr") {
  50      $authlink = mysql_connect($dbhost,$dbuser,$dbpass);
  51      @mysql_select_db($dbname) or die("Impossible de se connecter &#224; la base $dbname.");
  52      $query_info="SELECT * FROM alertes WHERE ID='$ID';";
  53      $result_info=mysql_query($query_info,$authlink);
  54      $row = mysql_fetch_array($result_info);
  55  
  56      $query_suppr="DELETE FROM alertes WHERE ID='$ID'";
  57      $result_suppr=mysql_query($query_suppr,$authlink) or die("Erreur lors de la suppression de l'alerte");
  58      if ($result_suppr) {
  59          echo "<center>";
  60          echo gettext("L'alerte ").$row['NAME'].gettext(" a &#233;t&#233; supprim&#233;e.");
  61          echo "</center>";
  62      } else {
  63          echo "<center>";
  64          echo gettext("La suppression de l'alerte a &#233;hou&#233;e");
  65          echo "</center>";
  66      }
  67    }
  68  
  69  
  70    // Selectionne le type de alerte a ajouter (Systeme ou inventaire)
  71    if ($action == "new_perso_select") {
  72      echo "<BR><BR>";
  73      echo "<CENTER><TABLE border=1 width=\"60%\">";
  74      
  75      echo "<TR>\n";
  76        echo "<TD class=\"menuheader\" height=\"30\" align=center colspan=\"5\">".gettext("Type d'alertes")."</TD>\n";
  77      echo "</TR>\n";
  78      
  79      echo "<TR>\n";
  80        echo "<td align=\"center\">".aide('Pour d&#233;finir une nouvelle alerte',"<IMG border=\"0\" src=\"../elements/images/edit.png\" alt=\"Help\">")."</td>\n";
  81        echo "<TD>".gettext("Alerte syst&#232;me")."</TD>\n";
  82        echo "<TD align=center colspan=2>";
  83        
  84        echo "<FORM ACTION=\"config_alert_system.php\" method=\"get\" name=\"form_action\">\n";
  85        echo "<input type=\"hidden\" name=\"action\" value=\"new\">\n";
  86        echo "<input value=\"Ajouter\" name=\"action_image\" type=\"submit\"></FORM></TD>";
  87        echo "<TD align=\"center\"><u onmouseover=\"this.T_SHADOWWIDTH=5;this.T_STICKY=1;return escape".gettext("('<B>Les alertes syst&#232;mes</B> sont les alertes qui permettent de surveiller le serveur, &#233;ventuellement d\'autres machines.')")."\"><img name=\"action_image2\"  src=\"../elements/images/system-help.png\" alt=\"Help\"></u></TD>\n";  
  88      echo "</TR>\n";
  89  
  90      include_once("config.inc.php");
  91      if ($inventaire=="1") { // Si inventaire desactive plus d'alerte
  92      
  93          echo "<TR>\n";
  94          echo "<td align=\"center\">".aide('Pour d&#233;finir une nouvelle alerte',"<IMG border=\"0\" src=\"../elements/images/edit.png\" alt=\"Help\">")."</td>\n";
  95          echo "<TD>".gettext("Alerte sur l'inventaire")."</TD><TD align=center colspan=2>";
  96          
  97          echo "<FORM ACTION=\"config_alert.php\" method=\"get\" name=\"form_action_2\">\n";
  98          echo "<input type=\"hidden\" name=\"action_hidden\" value=\"new\">\n";
  99          echo "<input value=\"Ajouter\" name=\"action_image\" type=\"submit\"></FORM></TD>\n";
 100          echo "<TD align=\"center\"><u onmouseover=\"this.T_SHADOWWIDTH=5;this.T_STICKY=1;return escape".gettext("('<B>Les alertes inventaire</B> vous permettent de surveiller les clients &#224; partir de l\'inventaire remont&#233;, par exemple quel client ne dispose pas de l\'anti-virus ou bien quel client a msn d\'install&#233;.')")."\"><img name=\"action_image3\"  src=\"../elements/images/system-help.png\" alt=\"Help\"></u></TD>\n";
 101          echo "</TR>\n";
 102      }
 103      
 104      echo "</TABLE></CENTER>\n";    
 105      
 106      include ("pdp.inc.php");
 107      exit;
 108    }     
 109  
 110  
 111    // Ajout - modification
 112    if ($action=="mod2") {
 113      if(($name_alert=="") || ($text_alert=="") || ($script_alert=="")) {
 114          echo "<center>";
 115          echo gettext("Erreur une donn&#233;e est manquante");
 116          echo "</center>";
 117      } else    {
 118          // Verifie si le script existe dans /usr/share/se3/scripts-alertes
 119          list($script_alert_exist, $options)=explode(" ",$script_alert);
 120          if( ! file_exists("/usr/share/se3/scripts-alertes/$script_alert_exist")) {
 121              echo "<center>";
 122              echo gettext("Erreur le script ne semble pas exister dans /usr/share/se3/scripts-alertes");
 123              echo "</center>";
 124          } else {
 125              //tout est ok on peut accepter
 126              $authlink = mysql_connect($dbhost,$dbuser,$dbpass);
 127              @mysql_select_db($dbname) or die("Impossible de se connecter &#224; la base $dbname.");
 128      
 129      
 130              if ($ID !="") {
 131                  $query="UPDATE alertes SET NAME='$name_alert', TEXT='$text_alert', MAIL='$mail_alert' ,SCRIPT='$script_alert' ,ACTIVE='$active_alert',FREQUENCE='$frequence_alert',MAIL_FREQUENCE='$frequence_mail' WHERE ID='$ID';";
 132              } else {
 133                  $query="INSERT INTO alertes (`ID`,`NAME`,`MAIL`,`Q_ALERT`,`VALUE`,`CHOIX`,`TEXT`,`AFFICHAGE`,`VARIABLE`,`PREDEF`,`MENU`,`ACTIVE`,`SCRIPT`,`PARC`,`FREQUENCE`,`PERIODE_SCRIPT`,`MAIL_FREQUENCE`) VALUES ('NULL','$name_alert','$mail_alert','$q_alert_alert','$value_alert','$choix_alert','$text_alert','1','$variable_alert','0','','$active_alert','$script_alert','','$frequence_alert','',$frequence_mail)";
 134  
 135              }
 136              $result=mysql_query($query,$authlink) or die("Erreur lors de la modification de l'alerte");
 137  
 138              if ($result) {
 139                  echo "<center>";
 140                  echo gettext("L'alerte ")." $name_alert. ".gettext(" a &#233;t&#233; modifi&#233;e.");
 141                  echo "</center>";
 142              } else {
 143                  echo "<center>";
 144                  echo gettext("La modification de l'alerte a &#233;chou&#233;e");
 145                  echo "</center>";
 146              }
 147          }
 148      }    
 149    }
 150  
 151    // Modifie la table pour rendre une alerte active ou non
 152    if ($action == "conf_mail") {
 153      // connexion a la base
 154          include "config.inc.php";
 155          $auth = @mysql_connect($dbhost,$dbuser,$dbpass);
 156          @mysql_select_db($dbname) or die("Impossible de se connecter &#224; la base $dbname.");
 157          $query="select NAME,ID from alertes where PREDEF='1'";
 158          $resultat=mysql_query($query,$auth);
 159          $ligne=mysql_num_rows($resultat);
 160          if ($ligne > "0") {
 161          while($row = mysql_fetch_array($resultat)) {
 162                      $test = $$row[1];
 163                      if ($test == "on")   { $active="1"; } 
 164                      if ($test == "")  { $active="0"; }
 165                      $query1="UPDATE alertes SET ACTIVE='$active' WHERE ID='$row[1]' AND PREDEF='1'";
 166              $result=mysql_query($query1);
 167              }
 168          }
 169    }
 170  
 171  
 172    // Test si l'expedition de mail est configuree
 173    $fichier="/etc/ssmtp/ssmtp.conf";
 174  
 175    if ( ! file_exists($fichier)) {
 176      echo "<CENTER><font color=\"#FFA500\"><u>".gettext("Attention :")." </u>".gettext("Il n'est pas possible d'envoyer des messages via la messagerie.<BR> Vous devez");
 177          echo"<a href=../conf_smtp.php>"; 
 178          echo gettext(" configurer l'exp&#233;dition des mails,");
 179          echo "</a>"; 
 180          echo gettext(" pour pouvoir utiliser cette fonctionnalit&#233;")."</font><BR>";
 181      echo "</CENTER>";
 182    }  
 183  
 184  
 185  
 186  
 187  // Affichage sous forme de 2 tableaux (alertes predef et alertes perso 
 188  include "config.inc.php";
 189  $auth = @mysql_connect($dbhost,$dbuser,$dbpass);
 190  @mysql_select_db($dbname) or die("Impossible de se connecter &#224; la base $dbnameinvent.");
 191  echo "<BR><BR>";
 192  
 193  echo "<FORM ACTION=\"alertes.php\" method=\"get\" >";
 194  echo "<INPUT TYPE=\"hidden\" NAME=\"action\" VALUE=\"conf_mail\">";
 195  echo "<CENTER><TABLE border=1 width=\"60%\">";
 196  
 197  echo "<TR><TD class=\"menuheader\" height=\"30\" align=center colspan=\"4\">".gettext("Alertes pr&#233;d&#233;finies")."</TD></TR>\n";
 198  $query="select ID,TEXT,VARIABLE,ACTIVE,NAME  from alertes where PREDEF='1'";
 199  $resultat=mysql_query($query,$auth);
 200  $ligne=mysql_num_rows($resultat);
 201  if ($ligne > "0") {
 202      while($row = mysql_fetch_array($resultat)) {
 203              $ajout=""; $statut=""; 
 204              if ($row['ACTIVE'] == "1") {   
 205              $ajout=" CHECKED"; 
 206                      $statut=aide('D&#233;cocher la case de droite pour d&#233;sactiver cette alerte',"<IMG style=\"border: 0px solid ;\" SRC=\"../elements/images/recovery.png\" ALT=\"Alerte active\">");
 207                 }   else { 
 208                  $statut=aide('Cocher la case de droite pour activer cette alerte',"<IMG style=\"border: 0px solid ;\" SRC=\"../elements/images/disabled.png\" ALT=\"Alerte inactive\">");
 209                 }
 210                 echo "<TR><td>$statut</td><TD>$row[1]</TD><TD align=center><INPUT TYPE=CHECKBOX NAME=\"$row[0]\" $ajout></TD></TR>\n";
 211      }
 212  }   
 213  
 214  echo "<TR><TD colspan=\"4\" align=center><INPUT TYPE=\"submit\" value=\"".gettext("Valider")."\"></TD></TR>\n";
 215  echo "</TABLE></CENTER><BR><BR>\n"; 
 216  echo "</FORM>\n";
 217  
 218  /* Creation d'alertes */
 219  echo "<CENTER><TABLE border=1 width=\"60%\">";
 220  echo "<TR><TD class=\"menuheader\" height=\"30\" align=center colspan=\"4\">".gettext("Mes alertes")."</TD></TR>\n";
 221  echo "<TR><td align=\"center\">".aide('Pour d&#233;finir une nouvelle alerte',"<IMG border=\"0\" src=\"../elements/images/edit.png\" alt=\"Editer\">")."</td><TD>".gettext("Ajout d'une alerte")."</TD><TD align=center colspan=2>";
 222  
 223  echo "<FORM ACTION=\"alertes.php\" method=\"get\" name=\"form_action\">\n";
 224  echo "<input type=\"hidden\" name=\"action\" value=\"new_perso_select\">\n";
 225  echo "<input value=\"Ajouter\" name=\"action_image\" type=\"submit\">\n";
 226  echo "</FORM>\n";
 227  echo "</TD></TR>\n";
 228  
 229  // Les alertes existantes
 230  //mysql_close();
 231  // $authlink = mysql_connect($dbhost,$dbuser,$dbpass);
 232  // @mysql_select_db($dbname) or die("Impossible de se connecter &#224; la base $dbname.");
 233  $query_info="SELECT * FROM alertes where PREDEF='0';";
 234  $result_info=mysql_query($query_info,$authlink);
 235  while ($row = mysql_fetch_array($result_info)) {
 236         // Si l'alete est active ou non
 237         if ($row["ACTIVE"]=="1") {
 238                 $statut=aide('L\&#039;alerte est actuellement activ&#233;e.Pour d&#233;activer cette alerte, cliquer sur l\&#039;icone Modifier <IMG  style=\&#034;border: 0px solid ;\&#034; SRC=\&#034;../elements/images/zoom.png\&#034; ALT=\&#034;Modifier\&#034;> et choisissez Alerte active, Non',"<IMG style=\"border: 0px solid ;\" SRC=\"../elements/images/recovery.png\" ALT=\"Alerte active\"></a>");
 239         } else {
 240          $statut=aide('L\&#039;alerte est actuellement d&#233;sactiv&#233;e.Pour activer cette alerte, cliquer sur l\&#039;icone Modifier <IMG  style=\&#034;border: 0px solid ;\&#034; SRC=\&#034;../elements/images/zoom.png\&#034; ALT=\&#034;Modifier\&#034;> et choisissez Alerte active, Oui',"<IMG style=\"border: 0px solid ;\" SRC=\"../elements/images/disabled.png\" ALT=\"Alerte inactive\">");
 241         }
 242         
 243             echo "<tr><td align=\"center\">$statut&nbsp;</td><td>".$row["TEXT"]."</td>\n";
 244             echo "<TD align=\"center\"><a href=\"alertes.php?action=suppr&amp;ID=".$row["ID"]."\"><IMG style=\"border: 0px solid ;\" SRC=\"../elements/images/edittrash.png\" ALT=\"Supprimer\"></a></TD>\n";
 245  
 246      // Selectionne le type d'alertes systeme ou inventaire
 247      if ($row["MENU"]=="inventaire") {
 248          echo "<TD align=\"center\"><a href=\"config_alert.php?action_hidden=mod&amp;ID=".$row["ID"]."\"><IMG style=\"border: 0px solid ;\" SRC=\"../elements/images/zoom.png\" ALT=\"Modifier\"></a></TD>\n";
 249          } else {
 250          echo "<TD align=\"center\"><a href=\"config_alert_system.php?action=new&amp;ID=".$row["ID"]."\"><IMG style=\"border: 0px solid ;\" SRC=\"../elements/images/zoom.png\" ALT=\"Modifier\"></a></TD>\n";
 251      }    
 252      echo "</tr>\n";
 253    }
 254    echo "</table></center>";        
 255  
 256  
 257  }
 258  
 259  include ("pdp.inc.php");
 260  ?>


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1