ryxeo-glpi-git / scripts / net2dip.sendtohurlevent.php @ 4ce9f9ca
Historique | Voir | Annoter | Télécharger (6,78 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 |
if ( DB::isError($result2 = $dbglpi->query($query2)) ) { |
99 |
die ("***\n$query2\n" . DB::errorMessage($result2) . "\n***\n\n"); |
100 |
} |
101 |
|
102 |
$nb = $result2->NumRows(); |
103 |
for ( $i = 0; $i < $nb; $i++) { |
104 |
$row = $result2->fetchrow(); |
105 |
$text .= implode(";",$row) . "\n"; |
106 |
make_htpass($row[1],$row[0]); |
107 |
} |
108 |
|
109 |
//Et ensuite les comptes utilisateurs pour les espaces limites uniquement
|
110 |
//Seuls les revendeurs (profile=5) et les orga-upgrade (profile=7)
|
111 |
$query3 = "SELECT name, realname FROM glpi_users as gu |
112 |
LEFT JOIN glpi_users_profiles as gup ON gup.FK_users=gu.ID
|
113 |
WHERE gup.FK_profiles = '5' OR gup.FK_profiles = '7'
|
114 |
GROUP BY name";
|
115 |
if ( DB::isError($result3 = $dbglpi->query($query3)) ) { |
116 |
die ("***\n$query2\n" . DB::errorMessage($result3) . "\n***\n\n"); |
117 |
} |
118 |
|
119 |
$nb = $result3->NumRows(); |
120 |
for ( $i = 0; $i < $nb; $i++) { |
121 |
$row = $result3->fetchrow(); |
122 |
//le nom en minuscule, sans accents et sans espaces
|
123 |
$nom = anti_speciaux($row[1],2); |
124 |
$login = trim($row[0]); |
125 |
make_htpass($login,$nom); |
126 |
} |
127 |
|
128 |
/*
|
129 |
*
|
130 |
* EXPEDITION DES DONNEES POUR LE SERVEUR GNUDIP
|
131 |
*
|
132 |
*/
|
133 |
|
134 |
$gpg="/usr/bin/gpg"; |
135 |
//Reception en clair pour tests
|
136 |
$user_clear="Eric Seigne <eric.seigne@ryxeo.com>"; |
137 |
//Expediteur
|
138 |
$user_from="AbulEdu Monitoring Robot on Horizon-2 <abuledu-monitoring@Horizon-2.ryxeo.com>"; |
139 |
//Destinataire serveur dyndns
|
140 |
$user_dyndns="Hurlevent GnuDIP Server <abuledu.gnudip.hurlevent@ryxeo.com>"; |
141 |
//Destinataire serveur apt
|
142 |
$user_apt="APT Filtered server <ryxeo.apt@apt.ryxeo.com>"; |
143 |
|
144 |
$command = 'echo "'.$text.'" | '.$gpg.' -a --always-trust --batch --no-secmem-warning -s -e -u "'.$user_from.'" -r "'.$user_dyndns.'"'; |
145 |
$result = exec($command, $encrypted, $errorcode); |
146 |
$message = implode("\n", $encrypted); |
147 |
/*
|
148 |
if( ereg("-----BEGIN PGP MESSAGE-----.*-----END PGP MESSAGE-----",$message) ) {
|
149 |
echo "It Worked";
|
150 |
} else {
|
151 |
echo "It failed";
|
152 |
}
|
153 |
*/
|
154 |
$subject="Update \"gnudip\" database table on abuledu.net"; |
155 |
$header="From: $user_from"; |
156 |
|
157 |
mail($user_dyndns,$subject,$message,$header); |
158 |
mail($user_clear,$subject,$message,$header); |
159 |
// tests mail($user_clear,$subject,$text,$header);
|
160 |
mail($user_clear,$subject,$text,$header); |
161 |
|
162 |
//Ensuite on GPG Crypte le fichier de htpasswd avec la meme cle
|
163 |
$encrypted = ""; |
164 |
$message = ""; |
165 |
$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; |
166 |
//print $command;
|
167 |
$result = exec($command, $encrypted, $errorcode); |
168 |
|
169 |
//le fichier de checksum que les serveurs vont downloader pour verifier si y a une mise a jour
|
170 |
$result = exec("cd " . $dir_htpass_public . " && md5sum " . $fic_htpass_public . " > " . $fic_htpass_public . ".md5"); |
171 |
|
172 |
?>
|