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