Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / plugins / anet_epacks / front / plugin_anet_epacks.view_array_recap.php @ 2a106d8b

Historique | Voir | Annoter | Télécharger (14,3 ko)

1
<?php
2

    
3
  /*
4
    Creation de la vue ...
5
    CREATE  ALGORITHM = TEMPTABLE VIEW glpi_plugin_anet_epacks_ssh_max AS SELECT *
6
    FROM `glpi_plugin_anet_epacks_ssh` as s1
7
    WHERE sshdate=(SELECT MAX(sshdate) FROM `glpi_plugin_anet_epacks_ssh` as s2 WHERE s1.FK_serveur=s2.FK_serveur)
8

9
    Comme c'est super long et cause un lag monstrueux a l ouverture on remplace par une table "normale" qui est
10
    periodiquement remise a jour ...
11

12
    CREATE TABLE IF NOT EXISTS `glpi_plugin_anet_epacks_ssh_max` (
13
    `ID` int(11) NOT NULL auto_increment,
14
    `sshstatus` binary(1) NOT NULL,
15
    `FK_serveur` int(11) NOT NULL,
16
    `log` text collate utf8_unicode_ci NOT NULL,
17
    `sshdate` datetime NOT NULL,
18
    PRIMARY KEY  (`ID`),
19
    KEY `FK_serveur` (`FK_serveur`)
20
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ; 
21
    
22
    A lancer periodiquement (?)
23
    TRUNCATE TABLE `glpi_plugin_anet_epacks_ssh_max` ;
24
    INSERT INTO glpi_plugin_anet_epacks_ssh_max SELECT * FROM `glpi_plugin_anet_epacks_ssh` as s1  WHERE sshdate=(SELECT MAX(sshdate) FROM `glpi_plugin_anet_epacks_ssh` as s2 WHERE s1.FK_serveur=s2.FK_serveur) ;
25
    
26

27
    on utilise la meme astuce pour l autre view: glpi_plugin_anet_epacks_recencement_max
28

29
    CREATE TABLE IF NOT EXISTS `glpi_plugin_anet_epacks_recencement_max` (
30
    `id` int(11) NOT NULL auto_increment,
31
    `ladate` timestamp NOT NULL default CURRENT_TIMESTAMP,
32
    `site` text collate utf8_unicode_ci NOT NULL,
33
    `phone` varchar(20) collate utf8_unicode_ci NOT NULL,
34
    `rvd` varchar(100) collate utf8_unicode_ci NOT NULL,
35
    `adresse1` text collate utf8_unicode_ci NOT NULL,
36
    `adresse2` text collate utf8_unicode_ci NOT NULL,
37
    `ville` varchar(100) collate utf8_unicode_ci NOT NULL,
38
    `cpostal` varchar(10) collate utf8_unicode_ci NOT NULL,
39
    `pays` varchar(100) collate utf8_unicode_ci NOT NULL,
40
    `nom` varchar(100) collate utf8_unicode_ci NOT NULL,
41
    `prenom` varchar(100) collate utf8_unicode_ci NOT NULL,
42
    `email` varchar(100) collate utf8_unicode_ci NOT NULL,
43
    `mac0` varchar(15) collate utf8_unicode_ci NOT NULL,
44
    `mac1` varchar(15) collate utf8_unicode_ci NOT NULL,
45
    `proc` varchar(100) collate utf8_unicode_ci NOT NULL,
46
    `ram` varchar(100) collate utf8_unicode_ci NOT NULL,
47
    `hdd0` varchar(100) collate utf8_unicode_ci NOT NULL,
48
    `hdd1` varchar(100) collate utf8_unicode_ci NOT NULL,
49
    `anet` varchar(100) collate utf8_unicode_ci NOT NULL,
50
    `tel` varchar(20) collate utf8_unicode_ci NOT NULL,
51
    `contrat` varchar(100) collate utf8_unicode_ci NOT NULL,
52
    `nbprofs` int(11) NOT NULL,
53
    `nbeleves` int(11) NOT NULL,
54
    `nbpc` int(11) NOT NULL,
55
    `ip` varchar(16) collate utf8_unicode_ci NOT NULL,
56
    `FK_serveur` int(11) default NULL,
57
    PRIMARY KEY  (`id`),
58
    UNIQUE KEY `FK_serveur` (`FK_serveur`)
59
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
60
    
61
    Et lance periodiquement
62
    TRUNCATE TABLE `glpi_plugin_anet_epacks_recencement_max` ;
63
    INSERT INTO glpi_plugin_anet_epacks_recencement_max SELECT * FROM glpi_plugin_anet_epacks_recencement as s1
64
    WHERE ladate=(SELECT MAX(ladate) FROM `glpi_plugin_anet_epacks_recencement` as s2 WHERE s1.FK_serveur=s2.FK_serveur) ;
65

66
    En fait, ca se passe dans anet.ryxeo.com/statistiques.php
67

68
  */
69

    
70
  // Affiche le tableau recap de tous les serveurs
71

    
72
if(!defined('GLPI_ROOT')){
73
  define('GLPI_ROOT', '../../..');
74
 }
75
include_once (GLPI_ROOT . "/inc/includes.php");
76
//include_once (GLPI_CONFIG_DIR . "/config_db_slave.php");
77

    
78
//On essaye d'utiliser le proxy/cache mysql
79
//$DBSlave = new DBSlave;
80

    
81
//Fabrique la requete en fonction des besoins de liste des serveurs sous maintenance ou non
82
//$maintenance = 1 -> ceux qui sons sous maintenance (sur)
83
//$maintenance = 0 -> ceux qu'on ne sais pas (ça sera a faire quand on aura saisi tous les contrats)
84
//$maintenance = -1 -> ceux qui ne veulent pas de maintenance
85
//le champ peut etre a deux -> on ne veut meme plus les afficher
86
//
87
//
88
function local_make_query($data, $entityid, $maintenance) {
89
  $query = "SELECT e.*, e.FK_enduser as entityid, g3.name as client, g4.name as serveur, g4.os_license_number, g4.os_license_id, g4.otherserial, ssh.*,
90
(g5.nbeleves+g5.nbprofs) as nbusers, g5.nbpc as nbpc
91
FROM glpi_plugin_anet_epacks AS e
92
LEFT JOIN glpi_plugin_anet_epacks_ssh_max AS ssh ON e.FK_serveur=ssh.FK_serveur
93
LEFT JOIN glpi_entities AS g3 ON e.FK_client=g3.ID OR e.FK_enduser=g3.ID
94
LEFT JOIN glpi_computers AS g4 ON e.FK_serveur=g4.ID
95
LEFT JOIN glpi_plugin_anet_epacks_recencement_max AS g5 ON e.FK_serveur=g5.FK_serveur\n";
96

    
97
  //WHERE e.Fk_Serveur > '0'\n";
98
  if($data['name'] == "revendeur" || $data['name'] == "dsi") {
99
    if($maintenance == 0 || $maintenance ==  1) {
100
      $query .= "WHERE e.FK_contract >= '0' AND e.FK_activation='" . $entityid . "'\n";
101
    }
102
    else if($maintenance == -1) {
103
      $query .= "WHERE e.FK_contract='-1' AND e.FK_activation='" . $entityid . "'\n";
104
    }
105
      //GROUP BY e.FK_serveur
106
    $query .= "GROUP BY e.FK_serveur
107
ORDER BY client ASC
108
LIMIT 500;";
109
  }
110
  else {
111
    //On n'affiche pas les serveurs qui ne sont pas "Zen"
112
    if($maintenance == 0 || $maintenance ==  1) {
113
      $query .= "WHERE e.FK_contract >= '0' AND e.FK_Serveur>'0'\n";
114
    }
115
    else if($maintenance == -1) {
116
      $query .= "WHERE e.FK_contract='-1' AND e.FK_Serveur>'0'\n";
117
    }
118
    //GROUP BY e.FK_serveur
119
    //On ne peut pas group by client a cause de l'historique ou on avait pas la meme structure
120
    //de base
121
    $query .= "GROUP BY e.FK_serveur
122
ORDER BY client ASC
123
LIMIT 500;";
124
  }
125

    
126
  //  if($maintenance == -1) {
127
  //print $query;
128
  //  }
129
  return $query;
130
}
131

    
132

    
133
function local_make_array($q,$maintenance) {
134
  global $DB;
135
  global $DB;
136
  global $glpiid;
137

    
138
  $result = $DB->query($q) or die($DB->error());
139
    
140
  print "<table style=\"width:100%; padding: 0 10px 0 10px;\">
141
<tr class='tab_bg_2'>
142
  <th>Nom</th>
143
  <th><img src=\"img/stock_channel.png\" alt=\"Télémaintenance (SSH)\" title=\"Télémaintenance (SSH)\"></th>
144
  <th>Date du test</th>
145
  <th>Adresse DynDNS</th>
146
  <th><img src=\"img/computer.png\" alt=\"Nombre de postes\" title=\"Nombre de postes clients\"></th>
147
  <th><img src=\"img/stock_people.png\" alt=\"Nombre d'utilisateurs\" title=\"Nombre d'utilisateurs\"></th>
148
  <th><img src=\"img/stock_hand-signed.png\" title=\"Contrat\"></th>
149
</tr>\n";
150
    
151
  $total_nbpc = 0;
152
  $total_nbusers = 0;
153
  //La liste des entites qu'on affiche
154
  $tab_deja_affiche = array();
155
  $num_debut_ligne = 0;
156

    
157
  for($i = 0; $i < $DB->numrows($result); $i++) {
158
    $num_debut_ligne++;
159
    $data=$DB->fetch_array($result);
160
    $tab_deja_affiche[] = $data['entityid'];
161
    $ssh_dateLastOK = "";
162
    if($data['sshstatus'] == 1)
163
      $ssh_status = "<font color=\"green\">OK</font>";
164
    else if($data['sshdate']) {
165
      $ssh_status = "<font color=\"red\">ERR</font>";
166
      //Es-ce qu'on a deja reussi a se connecter sur ce serveur ?
167
      $queryLastOK = "SELECT sshdate FROM glpi_plugin_anet_epacks_ssh WHERE FK_serveur='" . $data['FK_serveur'] . "' AND sshstatus=1 ORDER BY sshdate DESC LIMIT 1";
168
      if($resultLastOK = $DB->query($queryLastOK)) {
169
        $dataLastOK = $DB->fetch_array($resultLastOK);
170
        if($dataLastOK[0]) {
171
          //          print_r($dataLastOK);
172
          $ssh_status .= "<br /><font color=\"green\">LAST OK</font>";
173
          $ssh_dateLastOK = "<br />" . $dataLastOK[0];
174
        }
175
      }
176
      else {
177
        $ssh_dateLastOK = "";
178
      }
179
      //print $queryLastOK;
180
    }
181
    else
182
      $ssh_status = "<font color=\"orange\">???</font>";
183
    print "<tr class='tab_bg_2'>
184
  <td align=\"left\">\n";
185
    if($data['entityid'] > 0) {
186
      print "    " . $num_debut_ligne . ". <a href=\"../../manageentity/index.php?active_entity=" . $data['entityid'] . "\">" . $data['client'] . ": " . $data['serveur'] . "</a>\n";
187
    }
188
    else {
189
      print "    " . $num_debut_ligne . ". " . $data['client'] . ": " . $data['serveur'] . "(abonnement zen jamais activé)\n";
190
    }
191
    print "  </td>
192
  <td>" . $ssh_status . "</td>
193
  <td>" . $data['sshdate'] . $ssh_dateLastOK . "</td>
194
  <td align=\"left\">" . $data['os_license_id'] . " " . $data['otherserial'] . "<br />" . $data['os_license_number'] . " " . $data['otherserial'] ."</td>
195
  <td>" . $data['nbpc'] . "</td>
196
  <td>" . $data['nbusers'] . "</td>
197
  <td>
198
  </td>
199
</tr>\n";
200
    /*
201
     <a href=\"../../../front/contract.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_hand-signed.png\" title=\"Contrat\"></a>
202
     <a href=\"../../../front/tracking.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_web-support.png\" title=\"Tickets\"></a>
203
     <a href=\"../../../front/user.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_people.png\" title=\"Droits d'accès\"></a>
204
    */
205
    $total_nbpc += $data['nbpc'];
206
    $total_nbusers += $data['nbusers'];
207
  }
208
  
209
  //Maintenant toutes les entités sur lesquelles on a des droits recursifs
210
  $queryR = "SELECT glpi_users_profiles.FK_entities as entity FROM glpi_users_profiles WHERE glpi_users_profiles.FK_users='" . $glpiid . "' AND glpi_users_profiles.recursive=1 GROUP BY FK_entities";
211
  //print $queryR;
212
  $resultR = $DB->query($queryR);
213
  $listentity = "";
214
  for($r = 0; $r < $DB->numrows($resultR); $r++) {
215
    $dataR=$DB->fetch_array($resultR);
216
    $entityparent = $dataR['entity'];
217
    if($listentity != "")
218
      $listentity .= ", '" . $entityparent . "'";
219
    else
220
      $listentity = "'" . $entityparent . "'";
221
  }
222
  //$query = "SELECT ID FROM glpi_entities WHERE parentID='" . $entityparent . "'";
223
  
224
  $query = "SELECT e.*, e.FK_enduser as entityid, g3.name as client, g4.name as serveur, g4.os_license_number, g4.os_license_id, g4.otherserial, ssh.*,
225
(sum(g5.nbeleves)+sum(g5.nbprofs)) as nbusers, g5.nbpc as nbpc
226
FROM glpi_plugin_anet_epacks AS e
227
LEFT JOIN glpi_plugin_anet_epacks_ssh_max AS ssh ON e.FK_serveur=ssh.FK_serveur
228
LEFT JOIN glpi_entities AS g3 ON e.FK_client=g3.ID OR e.FK_enduser=g3.ID
229
LEFT JOIN glpi_computers AS g4 ON e.FK_serveur=g4.ID
230
LEFT JOIN glpi_plugin_anet_epacks_recencement_max AS g5 ON e.FK_serveur=g5.FK_serveur\n";
231
  //WHERE e.Fk_Serveur > '0'\n";
232

    
233

    
234
  if($maintenance == 0 || $maintenance ==  1) {
235
    $query .= "WHERE e.FK_contract >= '0'";
236
  }
237
  else if($maintenance == -1) {
238
    $query .= "WHERE e.FK_contract='-1'";
239
  }
240

    
241
  if(trim($listentity) != "")
242
    $query .= " AND g3.parentID IN (" . $listentity . ")\n";
243
  //GROUP BY e.FK_serveur
244
  $query .= "GROUP BY e.FK_client
245
ORDER BY client
246
LIMIT 500;";
247
  
248
  //print $query;
249
  
250
  $result = $DB->query($query) or die($DB->error());
251
  
252
  for($i = 0; $i < $DB->numrows($result); $i++) {
253
    $num_debut_ligne++;
254
    $data=$DB->fetch_array($result);
255
    $ssh_dateLastOK = "";
256
    if(! in_array($data['entityid'],$tab_deja_affiche)) {
257
      $tab_deja_affiche[] = $data['entityid'];
258
      if($data['sshstatus'] == 1)
259
        $ssh_status = "<font color=\"green\">OK</font>";
260
      else if($data['sshdate']) {
261
        $ssh_status = "<font color=\"red\">ERR</font>";
262
        //Es-ce qu'on a deja reussi a se connecter sur ce serveur ?
263
        $queryLastOK = "SELECT sshdate FROM glpi_plugin_anet_epacks_ssh WHERE FK_serveur='" . $data['FK_serveur'] . "' AND sshstatus=1 ORDER BY sshdate DESC LIMIT 1";
264
        if($resultLastOK = $DB->query($queryLastOK)) {
265
          $dataLastOK = $DB->fetch_array($resultLastOK);
266
          if($dataLastOK[0]) {
267
            //          print_r($dataLastOK);
268
            $ssh_status .= "<br /><font color=\"green\">LAST OK</font>";
269
            $ssh_dateLastOK = "<br />" . $dataLastOK[0];
270
          }
271
        }
272
        else {
273
          $ssh_dateLastOK = "";
274
        }
275
        //print $queryLastOK;
276
      }
277
      else
278
        $ssh_status = "<font color=\"orange\">???</font>";
279
      print "<tr class='tab_bg_2'>
280
  <td align=\"left\">\n";
281
      if($data['entityid'] > 0) {
282
        print "    " . $num_debut_ligne . ". <a href=\"../../manageentity/index.php?active_entity=" . $data['entityid'] . "\">" . $data['client'] . ": " . $data['serveur'] . "</a>\n";
283
      }
284
      else {
285
        print "    " . $num_debut_ligne . ". " . $data['client'] . ": " . $data['serveur'] . "(abonnement zen jamais activé)\n";
286
      }
287
      print "  </td>
288
  <td>" . $ssh_status . "</td>
289
  <td>" . $data['sshdate'] . $ssh_dateLastOK . "</td>
290
  <td align=\"left\">" . $data['os_license_id'] . " " . $data['otherserial'] . "<br />" . $data['os_license_number'] . " " . $data['otherserial'] . "</td>
291
  <td>" . $data['nbpc'] . "</td>
292
  <td>" . $data['nbusers'] . "</td>
293
  <td>
294
  </td>
295
</tr>\n";
296
      /*
297
          <a href=\"../../../front/contract.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_hand-signed.png\" title=\"Contrat\"></a>
298
          <a href=\"../../../front/tracking.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_web-support.png\" title=\"Tickets\"></a>
299
          <a href=\"../../../front/user.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_people.png\" title=\"Droits d'accès\"></a>
300
      */
301
      $total_nbpc += $data['nbpc'];
302
      $total_nbusers += $data['nbusers'];
303
    }
304
    else {
305
      //print "deja affiché :: " . $data['entityid'];
306
    }
307
  }
308
  
309
  
310
  
311
  /*
312
   <a href=\"../../../front/central.php?active_entity=" . $data['entityid'] . "\"><img src=\"img/stock_about.png\" title=\"Incarner le client " . $data['client'] . "\"></a>
313
   <a href=\"../../../front/computer.php?contains[0]=" . $data['client'] . "\"><img src=\"img/stock_form-add-field.png\" title=\"Inventaire\"></a>
314
  */
315
  
316
  print "<tr class='tab_bg_2'>
317
  <td colspan=\"4\">Totaux: </td>
318
  <td>" . $total_nbpc . "</td>
319
  <td>" . $total_nbusers . "</td>
320
  <td></td>
321
</tr>\n";
322
  
323
  print "</table>";
324
  
325
}
326

    
327
commonHeader("AbulEdu.NET -- Tableau récapitulatif -- Accueil RyXéo",$_SERVER['PHP_SELF'],"config","plugins");
328

    
329
$glpiid = $_SESSION['glpiID'];
330

    
331
global $DB;
332

    
333
$query = "SELECT glpi_profiles.name AS name,glpi_users_profiles.FK_entities as FK_entities FROM glpi_profiles,glpi_users_profiles,glpi_users WHERE glpi_users_profiles.FK_users='" . $glpiid . "' AND glpi_users_profiles.FK_profiles=glpi_profiles.ID GROUP BY FK_entities";
334

    
335
//print $query;
336
//exit;
337

    
338
$result = $DB->query($query);
339
if($result) {
340
  $data=$DB->fetch_array($result);
341
  $entityid = $data['FK_entities'];
342
  if($data['name'] == "revendeur" || $data['name'] == "dsi" || $data['name'] == "super-admin") {
343
    $entityid = $data['FK_entities'];
344
    
345
    //print $query;
346
    //exit;
347
      
348
    print "<h1>Tableau récapitulatif de vos serveurs sous maintenance</h1>";
349
    $maintenance = 0;
350
    $querySM = local_make_query($data, $entityid, $maintenance);
351
    local_make_array($querySM,$maintenance);
352

    
353
    print "<h1>Tableau récapitulatif de vos serveurs hors maintenance</h1>";
354
    $maintenance = -1;
355
    $queryHM = local_make_query($data, $entityid, $maintenance);
356
    local_make_array($queryHM,$maintenance);
357
    
358
    commonFooter();
359
    exit;
360
  }
361
 }
362

    
363
?>
Redmine Appliance - Powered by TurnKey Linux