Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / scripts / net2dip.sendtohurlevent.php @ e213dd82

Historique | Voir | Annoter | Télécharger (9,73 ko)

1
#!/usr/bin/php -q
2
<?php
3
/** **************************************************************************
4
 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 * ***************************************************************************
19
 * File  : net2dip.sendtohurlevent
20
 * Author  : Eric SEIGNE
21
 *           mailto:eric.seigne@ryxeo.com
22
 *           http://www.ryxeo.com/
23
 * Date    : 12/06/2004
24
 * Licence : GNU/GPL Version 2
25
 *
26
 * Description:
27
 * ------------
28
 *
29
 * @version    $Id: net2dip.sendtohurlevent,v 1.5 2004/12/09 11:31:49 erics Exp $
30
 * @author     Eric Seigne
31
 * @project   
32
 * @copyright  Eric Seigne 12/06/2004
33
 *
34
 * Passe de .NET  GnuDIP les infos ncessaires pour que le serveur GnuDIP
35
 * puisse faire son travail
36
 *
37
 * Depose egalement un fichier /home/webs/www.abuledu.net/htdocs/epack/export/checksum
38
 * dans lequel se trouve tous les htpasswd des comptes autorises a faire des apt-get
39
 * et les serveurs apt.ryxeo.com recuperent et de-gpg ce fichier via un cron
40
 *
41
 * ************************************************************************* */
42

    
43
$base_dir = dirname(__FILE__);
44
$text = "";
45

    
46
require_once "$base_dir/config/config.php";
47
require_once "$base_dir/libraries/fonctions.php";
48

    
49
//Creation automatique du fichier de mots de passe pour les restrictions de connexion
50
//sur les depot apt and co
51
$fic_htpass        = "/tmp/htpasswd-anet";
52
$fic_htpass908     = "/tmp/htpasswd-anet908";
53
$fic_htpass1108    = "/tmp/htpasswd-anet1108";
54
//Avec un nom checksum pour ne pas eveiller l'attention
55
$dir_htpass_public = "/home/webs/www.abuledu.net/htdocs/epack/export/";
56
$fic_htpass_public     = "checksum";
57
$fic_htpass_public908  = "checksum-908";
58
$fic_htpass_public1108 = "checksum-1108";
59
$result = system("rm -f "
60
                 . " " . $fic_htpass
61
                 . " " . $fic_htpass908
62
                 . " " . $fic_htpass1108
63
                 . " " . $dir_htpass_public . $fic_htpass_public
64
                 . " " . $dir_htpass_public . $fic_htpass_public908
65
                 . " " . $dir_htpass_public . $fic_htpass_public1108
66
                 . "&& touch " . $fic_htpass
67
                 . "&& touch " . $fic_htpass908
68
                 . "&& touch " . $fic_htpass1108
69
                 );
70

    
71
function nettoyage($s) {
72
  $texte = str_replace(" ","",$s);
73
  $texte = str_replace("'","",$texte);
74
  $texte = str_replace('"',"",$texte);
75
  return $texte;
76
}
77

    
78
function make_htpass($fic, $login,$pass) {
79
  $l = $login;
80
  //debug
81
  //echo "login: $login / $pass\n";
82
  //Si $login est toujours sous forme de mac on vire les ":"
83
  if(strpos($login,":") > 0)
84
    $login = trim(str_replace(":","",$login));
85

    
86
  //Si $login est toujours sous forme xxx.dip.abuledu.net
87
  if(strpos($login,".dip.abuledu.net") > 0)
88
    $login = trim(str_replace(".dip.abuledu.net","",$login));
89

    
90
  //Et le login en MAG et MIN because a bug ou un truc a la con qqpart dans la chaine
91
  $result = shell_exec("htpasswd -mb " . $fic . " " . trim(strtolower($login)) . " " . trim(nettoyage($pass)) . " 2>&1");
92
  $result = shell_exec("htpasswd -mb " . $fic . " " . trim(strtoupper($login)) . " " . trim(nettoyage($pass)) . " 2>&1");
93
}
94

    
95
//Les serveurs avant 2009 ne sont pas des epacks et leur mot de passe est stocke en crypte
96
$query = "SELECT e.password as gnudip_pass,os_license_number as dns_alias0,os_license_id as dns_alias1 FROM glpi_computers AS c
97
LEFT JOIN glpi_plugin_anet_epacks AS e ON e.FK_serveur=c.ID
98
WHERE os_license_number!='' AND e.creation_date<'2009-07-07'";
99
if ( DB::isError($result = $dbglpi->query($query)) ) {
100
  die ("***\n$query\n" . DB::errorMessage($result) . "\n***\n\n");
101
 }
102

    
103
$nb = $result->NumRows();
104
for ( $i = 0; $i < $nb; $i++) {
105
  $row = $result->fetchrow();
106
  // pb 2010 avec implode si on a une espace qui termine les champs dyndns ou dip ca fait planter le serveur
107
  // dns a l autre bout ...
108
  //  $text .= implode(";",$row) . "\n";
109
  $text .= trim($row[0]) . ";" . trim($row[1]) . ";" . trim($row[2]) . ";\n";
110
  make_htpass($fic_htpass, $row[1],$row[0]);
111
}
112

    
113
//les serveurs post ENR sont des epacks reels et leur mot de passe n'est pas crypte
114
$query2 = "SELECT MD5(e.password),os_license_number,os_license_id FROM glpi_computers AS c
115
LEFT JOIN glpi_plugin_anet_epacks AS e ON e.FK_serveur=c.ID
116
WHERE os_license_number!='' AND e.creation_date>'2009-07-06'";
117
//fix #596
118
//On supprime les epacks qu'on a marque comme n etant plus sous maintenance
119
//attention on a des serveurs pour lesquels on n'a pas de contrat encore ...
120
$query2 .= " AND e.FK_contract>'-1'";
121

    
122
//print $query2;
123
//print "\n";
124
//exit;
125

    
126
if ( DB::isError($result2 = $dbglpi->query($query2)) ) {
127
  die ("***\n$query2\n" . DB::errorMessage($result2) . "\n***\n\n");
128
 }
129

    
130
$nb = $result2->NumRows();
131
for ( $i = 0; $i < $nb; $i++) {
132
  $row = $result2->fetchrow();
133
  $text .= implode(";",$row) . "\n";
134
  make_htpass($fic_htpass, $row[1],$row[0]);
135
 }
136

    
137
//Et ensuite les comptes utilisateurs pour les espaces limites uniquement
138
//Seuls les revendeurs (profile=5) et les orga-upgrade (profile=7)
139
$query3 = "SELECT name, realname FROM glpi_users as gu
140
LEFT JOIN glpi_users_profiles as gup ON gup.FK_users=gu.ID
141
WHERE gup.FK_profiles = '5' OR gup.FK_profiles = '7'
142
GROUP BY name";
143
if ( DB::isError($result3 = $dbglpi->query($query3)) ) {
144
  die ("***\n$query3\n" . DB::errorMessage($result3) . "\n***\n\n");
145
 }
146

    
147
$nb = $result3->NumRows();
148
for ( $i = 0; $i < $nb; $i++) {
149
  $row = $result3->fetchrow();
150
  //le nom en minuscule, sans accents et sans espaces
151
  $nom = anti_speciaux($row[1],2);
152
  $login = trim($row[0]);
153
  make_htpass($fic_htpass, $login,$nom);
154
 }
155

    
156
//Maintenant, les personnes qui ont suivies la formation 9.08 clé "493" dans la table glpi_groups
157
$query4 = "SELECT name, realname FROM glpi_users as gu
158
LEFT JOIN glpi_users_groups as gug ON gug.FK_users=gu.ID
159
WHERE gug.FK_groups = '493' GROUP BY name";
160
if ( DB::isError($result4 = $dbglpi->query($query4)) ) {
161
  die ("***\n$query4\n" . DB::errorMessage($result4) . "\n***\n\n");
162
 }
163

    
164
$nb = $result4->NumRows();
165
for ( $i = 0; $i < $nb; $i++) {
166
  $row = $result4->fetchrow();
167
  //le nom en minuscule, sans accents et sans espaces
168
  $nom = anti_speciaux($row[1],2);
169
  $login = trim($row[0]);
170
  make_htpass($fic_htpass908, $login, $nom);
171
  //echo "$fic_htpass908 ... $login : $nom\n";
172
 }
173

    
174
//Maintenant, les personnes qui ont suivies la formation 11.08 clé "494" dans la table glpi_groups
175
$query5 = "SELECT name, realname FROM glpi_users as gu
176
LEFT JOIN glpi_users_groups as gug ON gug.FK_users=gu.ID
177
WHERE gug.FK_groups = '494' GROUP BY name";
178
if ( DB::isError($result5 = $dbglpi->query($query5)) ) {
179
  die ("***\n$query5\n" . DB::errorMessage($result5) . "\n***\n\n");
180
 }
181

    
182
$nb = $result5->NumRows();
183
for ( $i = 0; $i < $nb; $i++) {
184
  $row = $result5->fetchrow();
185
  //le nom en minuscule, sans accents et sans espaces
186
  $nom = anti_speciaux($row[1],2);
187
  $login = trim($row[0]);
188
  //echo "$fic_htpass1108 ... $login : $nom\n";
189
  make_htpass($fic_htpass1108, $login, $nom);
190
 }
191

    
192

    
193
/*
194
 *
195
 * EXPEDITION DES DONNEES POUR LE SERVEUR GNUDIP
196
 *
197
 */
198

    
199
$gpg="/usr/bin/gpg";
200
//Reception en clair pour tests
201
$user_clear="Eric Seigne <eric.seigne@ryxeo.com>";
202
//Expediteur
203
$user_from="AbulEdu Monitoring Robot on Horizon-2 <abuledu-monitoring@Horizon-2.ryxeo.com>";
204
//Destinataire serveur dyndns
205
$user_dyndns="Hurlevent GnuDIP Server <abuledu.gnudip.hurlevent@ryxeo.com>";
206
//Destinataire serveur apt
207
$user_apt="APT Filtered server <ryxeo.apt@apt.ryxeo.com>";
208

    
209
$command = 'echo "'.$text.'" | '.$gpg.' -a --always-trust --batch --no-secmem-warning -s -e -u "'.$user_from.'" -r "'.$user_dyndns.'"';
210
$result = exec($command, $encrypted, $errorcode);
211
//print $command . "\n";
212

    
213
$message = implode("\n", $encrypted);
214
/*
215
if( ereg("-----BEGIN PGP MESSAGE-----.*-----END PGP MESSAGE-----",$message) ) {
216
        echo "It Worked";
217
} else {
218
        echo "It failed";
219
}
220
*/
221
$subject="Update \"gnudip\" database table on abuledu.net";
222
$header="From: $user_from";
223

    
224
mail($user_dyndns,$subject,$message,$header);
225
mail($user_clear,$subject,$message,$header);
226
// tests mail($user_clear,$subject,$text,$header);
227
mail($user_clear,$subject,$text,$header);
228

    
229
//Ensuite on GPG Crypte le fichier de htpasswd avec la meme cle
230
$encrypted = "";
231
$message = "";
232
$command = 'rm -f "' . $dir_htpass_public . $fic_htpass_public      . '" && cat "' . $fic_htpass     . '" | ' . $gpg . ' --always-trust --batch --no-secmem-warning -s -e -u "' . $user_from . '" -r "' . $user_apt . '" > ' . $dir_htpass_public . $fic_htpass_public;
233
$result = exec($command, $encrypted, $errorcode);
234
//print $command . "\n";
235

    
236
$encrypted = "";
237
$message = "";
238
$command = 'rm -f "' . $dir_htpass_public . $fic_htpass_public908   . '" && cat "' . $fic_htpass908  . '" | ' . $gpg . ' --always-trust --batch --no-secmem-warning -s -e -u "' . $user_from . '" -r "' . $user_apt . '" > ' . $dir_htpass_public . $fic_htpass_public908;
239
$result = exec($command, $encrypted, $errorcode);
240
//print $command . "\n";
241

    
242
$encrypted = "";
243
$message = "";
244
$command = 'rm -f "' . $dir_htpass_public . $fic_htpass_public1108  . '" && cat "' . $fic_htpass1108 . '" | ' . $gpg . ' --always-trust --batch --no-secmem-warning -s -e -u "' . $user_from . '" -r "' . $user_apt . '" > ' . $dir_htpass_public . $fic_htpass_public1108;
245
$result = exec($command, $encrypted, $errorcode);
246
//print $command . "\n";
247

    
248
//le fichier de checksum que les serveurs vont downloader pour verifier si y a une mise a jour
249
$result = exec("cd " . $dir_htpass_public . " && md5sum " . $fic_htpass_public . " > " . $fic_htpass_public . ".md5");
250

    
251
?>
Redmine Appliance - Powered by TurnKey Linux