ryxeo-glpi-git / scripts / net2dip.sendtohurlevent.php @ b4660b5a
Historique | Voir | Annoter | Télécharger (6,9 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 |
//Avec un nom checksum pour ne pas eveiller l'attention
|
53 |
$dir_htpass_public = "/home/webs/www.abuledu.net/htdocs/epack/export/"; |
54 |
$fic_htpass_public = "checksum"; |
55 |
$result = system("rm -f " . $fic_htpass . " " . $dir_htpass_public . $fic_htpass_public . "&& touch " . $fic_htpass); |
56 |
|
57 |
function make_htpass($login,$pass) { |
58 |
global $fic_htpass; |
59 |
$l = $login; |
60 |
//debug
|
61 |
//echo "login: $login / $pass\n";
|
62 |
//Si $login est toujours sous forme de mac on vire les ":"
|
63 |
if(strpos($login,":") > 0) |
64 |
$login = trim(str_replace(":","",$login)); |
65 |
|
66 |
//Si $login est toujours sous forme xxx.dip.abuledu.net
|
67 |
if(strpos($login,".dip.abuledu.net") > 0) |
68 |
$login = trim(str_replace(".dip.abuledu.net","",$login)); |
69 |
|
70 |
//Et le login en MAG et MIN because a bug ou un truc a la con qqpart dans la chaine
|
71 |
$result = shell_exec("htpasswd -mb " . $fic_htpass . " " . trim(strtolower($login)) . " " . trim($pass) . " 2>&1"); |
72 |
$result = shell_exec("htpasswd -mb " . $fic_htpass . " " . trim(strtoupper($login)) . " " . trim($pass) . " 2>&1"); |
73 |
} |
74 |
|
75 |
|
76 |
//Les serveurs avant 2009 ne sont pas des epacks et leur mot de passe est stocke en crypte
|
77 |
$query = "SELECT e.password as gnudip_pass,os_license_number as dns_alias0,os_license_id as dns_alias1 FROM glpi_computers AS c |
78 |
LEFT JOIN glpi_plugin_anet_epacks AS e ON e.FK_serveur=c.ID
|
79 |
WHERE os_license_number!='' AND e.creation_date<'2009-07-07'";
|
80 |
if ( DB::isError($result = $dbglpi->query($query)) ) { |
81 |
die ("***\n$query\n" . DB::errorMessage($result) . "\n***\n\n"); |
82 |
} |
83 |
|
84 |
$nb = $result->NumRows(); |
85 |
for ( $i = 0; $i < $nb; $i++) { |
86 |
$row = $result->fetchrow(); |
87 |
// pb 2010 avec implode si on a une espace qui termine les champs dyndns ou dip ca fait planter le serveur
|
88 |
// dns a l autre bout ...
|
89 |
// $text .= implode(";",$row) . "\n";
|
90 |
$text .= trim($row[0]) . ";" . trim($row[1]) . ";" . trim($row[2]) . ";\n"; |
91 |
make_htpass($row[1],$row[0]); |
92 |
} |
93 |
|
94 |
//les serveurs post ENR sont des epacks reels et leur mot de passe n'est pas crypte
|
95 |
$query2 = "SELECT MD5(e.password),os_license_number,os_license_id FROM glpi_computers AS c |
96 |
LEFT JOIN glpi_plugin_anet_epacks AS e ON e.FK_serveur=c.ID
|
97 |
WHERE os_license_number!='' AND e.creation_date>'2009-07-06'";
|
98 |
//fix #596
|
99 |
//On supprime les epacks qu'on a marque comme n etant plus sous maintenance
|
100 |
$query2 .= " AND e.FK_contract>'0'"; |
101 |
|
102 |
if ( DB::isError($result2 = $dbglpi->query($query2)) ) { |
103 |
die ("***\n$query2\n" . DB::errorMessage($result2) . "\n***\n\n"); |
104 |
} |
105 |
|
106 |
$nb = $result2->NumRows(); |
107 |
for ( $i = 0; $i < $nb; $i++) { |
108 |
$row = $result2->fetchrow(); |
109 |
$text .= implode(";",$row) . "\n"; |
110 |
make_htpass($row[1],$row[0]); |
111 |
} |
112 |
|
113 |
//Et ensuite les comptes utilisateurs pour les espaces limites uniquement
|
114 |
//Seuls les revendeurs (profile=5) et les orga-upgrade (profile=7)
|
115 |
$query3 = "SELECT name, realname FROM glpi_users as gu |
116 |
LEFT JOIN glpi_users_profiles as gup ON gup.FK_users=gu.ID
|
117 |
WHERE gup.FK_profiles = '5' OR gup.FK_profiles = '7'
|
118 |
GROUP BY name";
|
119 |
if ( DB::isError($result3 = $dbglpi->query($query3)) ) { |
120 |
die ("***\n$query2\n" . DB::errorMessage($result3) . "\n***\n\n"); |
121 |
} |
122 |
|
123 |
$nb = $result3->NumRows(); |
124 |
for ( $i = 0; $i < $nb; $i++) { |
125 |
$row = $result3->fetchrow(); |
126 |
//le nom en minuscule, sans accents et sans espaces
|
127 |
$nom = anti_speciaux($row[1],2); |
128 |
$login = trim($row[0]); |
129 |
make_htpass($login,$nom); |
130 |
} |
131 |
|
132 |
/*
|
133 |
*
|
134 |
* EXPEDITION DES DONNEES POUR LE SERVEUR GNUDIP
|
135 |
*
|
136 |
*/
|
137 |
|
138 |
$gpg="/usr/bin/gpg"; |
139 |
//Reception en clair pour tests
|
140 |
$user_clear="Eric Seigne <eric.seigne@ryxeo.com>"; |
141 |
//Expediteur
|
142 |
$user_from="AbulEdu Monitoring Robot on Horizon-2 <abuledu-monitoring@Horizon-2.ryxeo.com>"; |
143 |
//Destinataire serveur dyndns
|
144 |
$user_dyndns="Hurlevent GnuDIP Server <abuledu.gnudip.hurlevent@ryxeo.com>"; |
145 |
//Destinataire serveur apt
|
146 |
$user_apt="APT Filtered server <ryxeo.apt@apt.ryxeo.com>"; |
147 |
|
148 |
$command = 'echo "'.$text.'" | '.$gpg.' -a --always-trust --batch --no-secmem-warning -s -e -u "'.$user_from.'" -r "'.$user_dyndns.'"'; |
149 |
$result = exec($command, $encrypted, $errorcode); |
150 |
$message = implode("\n", $encrypted); |
151 |
/*
|
152 |
if( ereg("-----BEGIN PGP MESSAGE-----.*-----END PGP MESSAGE-----",$message) ) {
|
153 |
echo "It Worked";
|
154 |
} else {
|
155 |
echo "It failed";
|
156 |
}
|
157 |
*/
|
158 |
$subject="Update \"gnudip\" database table on abuledu.net"; |
159 |
$header="From: $user_from"; |
160 |
|
161 |
mail($user_dyndns,$subject,$message,$header); |
162 |
mail($user_clear,$subject,$message,$header); |
163 |
// tests mail($user_clear,$subject,$text,$header);
|
164 |
mail($user_clear,$subject,$text,$header); |
165 |
|
166 |
//Ensuite on GPG Crypte le fichier de htpasswd avec la meme cle
|
167 |
$encrypted = ""; |
168 |
$message = ""; |
169 |
$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; |
170 |
//print $command;
|
171 |
$result = exec($command, $encrypted, $errorcode); |
172 |
|
173 |
//le fichier de checksum que les serveurs vont downloader pour verifier si y a une mise a jour
|
174 |
$result = exec("cd " . $dir_htpass_public . " && md5sum " . $fic_htpass_public . " > " . $fic_htpass_public . ".md5"); |
175 |
|
176 |
?>
|