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