Révision 4ce9f9ca
htdocs/epack/export/checksum.md5 | ||
---|---|---|
1 |
9a40822019a56e0c001d469c9667ba3f checksum |
|
1 |
d71374194eb36a9e5713e85c75b40d8b checksum |
scripts/config/config.php | ||
---|---|---|
1 |
<?php |
|
2 |
require_once 'DB.php'; |
|
3 |
|
|
4 |
$mailto = "supportteam@ryxeo.com"; |
|
5 |
$database = "abuledu_prod"; |
|
6 |
$dbuser = "AENuser"; |
|
7 |
$dbpass = "vvS5P38YJh"; |
|
8 |
$dbhost = "192.168.100.1"; |
|
9 |
$dbh = DB::connect("mysql://$dbuser:$dbpass@$dbhost/$database"); |
|
10 |
if (DB::isError($dbh)) { |
|
11 |
die("error ".$dbh->toString()); |
|
12 |
} |
|
13 |
|
|
14 |
$dbglpi = DB::connect("mysql://glpiu:F2D6nxPRA6HC@$dbhost/glpi"); |
|
15 |
if (DB::isError($dbglpi)) { |
|
16 |
die("error ".$dbglpi->toString()); |
|
17 |
} |
|
18 |
|
|
19 |
|
|
20 |
putenv("LC_MESSAGES=C"); |
|
21 |
putenv("LC_ALL=C"); |
|
22 |
putenv("LANG=C"); |
|
23 |
putenv("LANGUAGE=C"); |
|
24 |
?> |
scripts/libraries/fonctions.php | ||
---|---|---|
1 |
<?php |
|
2 |
error_reporting(E_ALL); |
|
3 |
//debug: E_ALL |
|
4 |
// ------------------------------------ |
|
5 |
// On rebind la fonction sql_exec pasqu'elle est vraiment lourdingue ! |
|
6 |
// SELECT: retourne le résultat ou le tableau de résultat |
|
7 |
function sql_exec($req) { |
|
8 |
global $dbh; |
|
9 |
//sql debug mode |
|
10 |
//echo "req = $req\n"; |
|
11 |
|
|
12 |
if ( DB::isError($res = $dbh->query($req)) ) { |
|
13 |
die ("***\n" . DB::errorMessage($res) . "\n***\n\n"); |
|
14 |
} |
|
15 |
if ( $res === DB_OK ) { |
|
16 |
return; |
|
17 |
} |
|
18 |
|
|
19 |
if ( $row = $res->fetchRow() ) { |
|
20 |
if (DB::isError($row)) { |
|
21 |
print $row->toString() . "<br/>"; |
|
22 |
continue; |
|
23 |
} |
|
24 |
} |
|
25 |
|
|
26 |
if ( $res->numRows() > 1 ) { |
|
27 |
return $res; |
|
28 |
} else { |
|
29 |
return $row; |
|
30 |
} |
|
31 |
} |
|
32 |
|
|
33 |
// ------------------------------------ |
|
34 |
// Avant d'insérer le nouvel enregistrement on essaye de voir si il n'est |
|
35 |
// pas déjà présent |
|
36 |
function ajoute_ou_upgrade_package($packageid, $serverid, $version, $etat) { |
|
37 |
$vi = makeintversion($version); |
|
38 |
$reqt = "SELECT id " . |
|
39 |
"FROM packages_installed " . |
|
40 |
"WHERE `id_package`='$packageid' and `id_server`='$serverid';"; |
|
41 |
$rest = sql_exec($reqt); |
|
42 |
if ( is_array($rest) ) { |
|
43 |
$r = $rest[0]; |
|
44 |
} else { |
|
45 |
$r = $rest; |
|
46 |
} |
|
47 |
if ( $r ) { |
|
48 |
$req1 = "UPDATE packages_installed " . |
|
49 |
"SET `inst_version`='$version', `inst_version_int`='$vi' " . |
|
50 |
"WHERE `id`='$r';"; |
|
51 |
$row1 = sql_exec($req1); |
|
52 |
} else { |
|
53 |
$req1 = "INSERT INTO packages_installed (id_server, " . |
|
54 |
"id_package, " . |
|
55 |
"package_status, " . |
|
56 |
"inst_version, " . |
|
57 |
"inst_version_int ) " . |
|
58 |
"VALUES ('$serverid', '$packageid', '$etat', '$version', $vi);"; |
|
59 |
$row1 = sql_exec($req1); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
// ------------------------------------ |
|
64 |
// Vérification que ce serveur est bien enregistré dans la base |
|
65 |
// ... si jamais il n'est pas dans la base on expédie un rapport |
|
66 |
function get_serveruid ( $serveruid, $str="" ) { |
|
67 |
global $mailto, $mail_subject; |
|
68 |
|
|
69 |
// Détection du "format" de la chaîne SERVERUID contenue dans le mail |
|
70 |
// Les anciennes versions sont du style SERVERUID=AA:BB:CC:DD:EE:FF;AA:BB:CC:DD:EE:GG |
|
71 |
// Les nouvelles versions sont du style SERVERUID=AABBCCDDEEFF |
|
72 |
// ...donc recherche du caractère ";" |
|
73 |
if (strstr($serveruid,";")) { |
|
74 |
// On a une ancienne forme... |
|
75 |
$t = explode(";",$serveruid); |
|
76 |
if ( strstr($t[0],":") ) { |
|
77 |
$t[0] = str_replace(":","",$t[0]); |
|
78 |
} |
|
79 |
if ( strstr($t[1], ":") ) { |
|
80 |
$t[1] = str_replace(":", "", $t[1]); |
|
81 |
} |
|
82 |
|
|
83 |
$req = "SELECT id " . |
|
84 |
"FROM servers " . |
|
85 |
"WHERE (`mac_address_0`='" . $t[0] . "' " . |
|
86 |
" AND `mac_address_1`='" . $t[1] . "') " . |
|
87 |
"OR (`mac_address_0`='" . $t[1] . "' " . |
|
88 |
" AND `mac_address_1`='" . $t[0] . "') " . |
|
89 |
"OR (`mac_address_0`='" . strtolower($t[0]) . "' " . |
|
90 |
" AND `mac_address_1`='" . strtolower($t[1]) . "') " . |
|
91 |
"OR (`mac_address_0`='" . strtolower($t[1]) . "' " . |
|
92 |
" AND `mac_address_1`='" . strtolower($t[0]) . "');"; |
|
93 |
// print "R: $req\n"; |
|
94 |
} else { |
|
95 |
// Nouvelle forme ("horizon-system-tools") |
|
96 |
$req = "SELECT id " . |
|
97 |
"FROM servers " . |
|
98 |
"WHERE `mac_address_0` LIKE '" . $serveruid . "' ". |
|
99 |
"OR `mac_address_1` LIKE '" . $serveruid . "' ". |
|
100 |
"OR `mac_address_0` LIKE '" . strtoupper($serveruid) . "' ". |
|
101 |
"OR `mac_address_1` LIKE '" . strtoupper($serveruid) . "';"; |
|
102 |
} |
|
103 |
|
|
104 |
$res = sql_exec($req); |
|
105 |
|
|
106 |
if ( is_array($res) ) { |
|
107 |
$r = $res[0]; |
|
108 |
} |
|
109 |
|
|
110 |
if ( isset($r) ) { |
|
111 |
return $r; |
|
112 |
} else { |
|
113 |
$message = "Tentative de get_serveruid ($serveruid)\n" . |
|
114 |
"STR: $str"; |
|
115 |
mail($mailto,$mail_subject,$message); |
|
116 |
return -1; |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 |
// ------------------------------------ |
|
121 |
// Récupration du serveurname |
|
122 |
function get_servername($id,$str) { |
|
123 |
global $mailto, $mail_subject; |
|
124 |
$req = "SELECT name FROM servers WHERE id='" . addslashes($id) . "';"; |
|
125 |
$row = sql_exec($req); |
|
126 |
if (is_array($row)) { |
|
127 |
$r = $row[0]; |
|
128 |
} else { |
|
129 |
$r = $row; |
|
130 |
} |
|
131 |
|
|
132 |
if(isset($r)) |
|
133 |
return $r; |
|
134 |
else { |
|
135 |
$message = "tentative de get_servername $id |
|
136 |
STR:$str"; |
|
137 |
mail($mailto,$mail_subject,$message); |
|
138 |
return -1; |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
// ------------------------------ |
|
143 |
// transforme une date au format mysql en date "normale" |
|
144 |
// 2003-10-05 en 05/10/2003 ... |
|
145 |
function MysqlDateToFrDate($s,$h = 1) { |
|
146 |
$masque = "d/m/Y"; |
|
147 |
if($h == 1) |
|
148 |
$masque .= " G:i:s"; |
|
149 |
return date($masque,strtotime($s)); |
|
150 |
//implode('/',array_reverse(split('[-]',$s))); |
|
151 |
} |
|
152 |
|
|
153 |
// ------------------------------ |
|
154 |
// On a des versions de paquets qui sont en 1:1.2.3 |
|
155 |
// Il faut donc virer le 1: |
|
156 |
function cleanversion($s) { |
|
157 |
$masque = "/(.:)?(.*)/"; |
|
158 |
$r = preg_replace($masque, "\${2}", $s); |
|
159 |
// print "$s -> $r\n"; |
|
160 |
return preg_replace($masque, "\${2}", $s); |
|
161 |
} |
|
162 |
|
|
163 |
// ------------------------------ |
|
164 |
// transforme une version en un bigint qui permet la comparaison ! |
|
165 |
function makeintversion($s) { |
|
166 |
$max = 6; |
|
167 |
$masque = "/(.:)?([\d\.]*)[-+]?.*/"; |
|
168 |
$i = preg_replace($masque, "\${2}", $s); |
|
169 |
// print "$s -> $i\n"; |
|
170 |
$tab = @explode( ".", preg_replace("/\(\w\D\)/i", "", $i) ); |
|
171 |
|
|
172 |
/* |
|
173 |
* $masque = "/[-+[:alpha:]]/"; |
|
174 |
* $i = preg_split($masque,$s); |
|
175 |
* $tab = explode(".",preg_replace("/\(\w\D\)/i","",$i[0])); |
|
176 |
*/ |
|
177 |
for ( $i = 0; $i < count($tab) || $i < $max; $i++) { |
|
178 |
//Modifier le 03 par ce qu'on veut pour le masque de sortie |
|
179 |
$res .= @sprintf("%03d",$tab[$i]); |
|
180 |
} |
|
181 |
return $res; |
|
182 |
} |
|
183 |
|
|
184 |
//Update la date de dernière info sur la table servers |
|
185 |
function update_datederniereinfo($id) { |
|
186 |
$r = "UPDATE servers SET datederniereinfo=now() WHERE id='$id'"; |
|
187 |
// $s = sql_exec($r); |
|
188 |
} |
|
189 |
|
|
190 |
//Retourne le diff -u système des deux fichiers |
|
191 |
function systemdiff($f1,$f2,$filename) { |
|
192 |
$t = ''; |
|
193 |
$tf1 = tempnam("/tmp",basename("$filename") . "_1-"); |
|
194 |
$tf2 = tempnam("/tmp",basename("$filename") . "_2-"); |
|
195 |
|
|
196 |
$handle = fopen($tf1, "w"); |
|
197 |
fwrite($handle, $f1); |
|
198 |
fclose($handle); |
|
199 |
|
|
200 |
$handle = fopen($tf2, "w"); |
|
201 |
fwrite($handle, $f2); |
|
202 |
fclose($handle); |
|
203 |
|
|
204 |
exec("diff -u $tf1 $tf2",$t); |
|
205 |
$r = implode("\n",$t); |
|
206 |
unlink($tf1); |
|
207 |
unlink($tf2); |
|
208 |
return $r; |
|
209 |
} |
|
210 |
|
|
211 |
|
|
212 |
// --------------------------------------------- |
|
213 |
// On vire les espaces ponctuations etc. |
|
214 |
// agressif = 0 on est gentil - on ne fait rien |
|
215 |
// = 1 on vire les accents + tout en minuscules |
|
216 |
// = 2 on vire aussi les tirets et espaces (login / pass) |
|
217 |
function anti_speciaux($t, $agressif=0) { |
|
218 |
if(trim($t) == "") |
|
219 |
return ; |
|
220 |
if($agressif >= 1) { |
|
221 |
$texte = strtolower($t); |
|
222 |
$texte = remove_accents($texte); |
|
223 |
if($agressif == 2) { |
|
224 |
// On vire les espaces |
|
225 |
$texte = str_replace(" ","",$texte); |
|
226 |
$texte = str_replace("-","",$texte); |
|
227 |
$texte = str_replace("_","",$texte); |
|
228 |
//le python accepte - et _ dans le login apres une lettre |
|
229 |
} |
|
230 |
} |
|
231 |
else { |
|
232 |
$texte=$t; |
|
233 |
} |
|
234 |
return $texte; |
|
235 |
} |
|
236 |
|
|
237 |
/** |
|
238 |
* Code from wordpress - wordpress.org |
|
239 |
* Converts all accent characters to ASCII characters. |
|
240 |
* |
|
241 |
* If there are no accent characters, then the string given is just returned. |
|
242 |
* |
|
243 |
* @since 1.2.1 |
|
244 |
* |
|
245 |
* @param string $string Text that might have accent characters |
|
246 |
* @return string Filtered string with replaced "nice" characters. |
|
247 |
*/ |
|
248 |
function remove_accents($string) { |
|
249 |
if ( !preg_match('/[\x80-\xff]/', $string) ) |
|
250 |
return $string; |
|
251 |
|
|
252 |
if (seems_utf8($string)) { |
|
253 |
$chars = array( |
|
254 |
// Decompositions for Latin-1 Supplement |
|
255 |
chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
|
256 |
chr(195).chr(130) => 'A', chr(195).chr(131) => 'A', |
|
257 |
chr(195).chr(132) => 'A', chr(195).chr(133) => 'A', |
|
258 |
chr(195).chr(135) => 'C', chr(195).chr(136) => 'E', |
|
259 |
chr(195).chr(137) => 'E', chr(195).chr(138) => 'E', |
|
260 |
chr(195).chr(139) => 'E', chr(195).chr(140) => 'I', |
|
261 |
chr(195).chr(141) => 'I', chr(195).chr(142) => 'I', |
|
262 |
chr(195).chr(143) => 'I', chr(195).chr(145) => 'N', |
|
263 |
chr(195).chr(146) => 'O', chr(195).chr(147) => 'O', |
|
264 |
chr(195).chr(148) => 'O', chr(195).chr(149) => 'O', |
|
265 |
chr(195).chr(150) => 'O', chr(195).chr(153) => 'U', |
|
266 |
chr(195).chr(154) => 'U', chr(195).chr(155) => 'U', |
|
267 |
chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y', |
|
268 |
chr(195).chr(159) => 's', chr(195).chr(160) => 'a', |
|
269 |
chr(195).chr(161) => 'a', chr(195).chr(162) => 'a', |
|
270 |
chr(195).chr(163) => 'a', chr(195).chr(164) => 'a', |
|
271 |
chr(195).chr(165) => 'a', chr(195).chr(167) => 'c', |
|
272 |
chr(195).chr(168) => 'e', chr(195).chr(169) => 'e', |
|
273 |
chr(195).chr(170) => 'e', chr(195).chr(171) => 'e', |
|
274 |
chr(195).chr(172) => 'i', chr(195).chr(173) => 'i', |
|
275 |
chr(195).chr(174) => 'i', chr(195).chr(175) => 'i', |
|
276 |
chr(195).chr(177) => 'n', chr(195).chr(178) => 'o', |
|
277 |
chr(195).chr(179) => 'o', chr(195).chr(180) => 'o', |
|
278 |
chr(195).chr(181) => 'o', chr(195).chr(182) => 'o', |
|
279 |
chr(195).chr(182) => 'o', chr(195).chr(185) => 'u', |
|
280 |
chr(195).chr(186) => 'u', chr(195).chr(187) => 'u', |
|
281 |
chr(195).chr(188) => 'u', chr(195).chr(189) => 'y', |
|
282 |
chr(195).chr(191) => 'y', |
|
283 |
// Decompositions for Latin Extended-A |
|
284 |
chr(196).chr(128) => 'A', chr(196).chr(129) => 'a', |
|
285 |
chr(196).chr(130) => 'A', chr(196).chr(131) => 'a', |
|
286 |
chr(196).chr(132) => 'A', chr(196).chr(133) => 'a', |
|
287 |
chr(196).chr(134) => 'C', chr(196).chr(135) => 'c', |
|
288 |
chr(196).chr(136) => 'C', chr(196).chr(137) => 'c', |
|
289 |
chr(196).chr(138) => 'C', chr(196).chr(139) => 'c', |
|
290 |
chr(196).chr(140) => 'C', chr(196).chr(141) => 'c', |
|
291 |
chr(196).chr(142) => 'D', chr(196).chr(143) => 'd', |
|
292 |
chr(196).chr(144) => 'D', chr(196).chr(145) => 'd', |
|
293 |
chr(196).chr(146) => 'E', chr(196).chr(147) => 'e', |
|
294 |
chr(196).chr(148) => 'E', chr(196).chr(149) => 'e', |
|
295 |
chr(196).chr(150) => 'E', chr(196).chr(151) => 'e', |
|
296 |
chr(196).chr(152) => 'E', chr(196).chr(153) => 'e', |
|
297 |
chr(196).chr(154) => 'E', chr(196).chr(155) => 'e', |
|
298 |
chr(196).chr(156) => 'G', chr(196).chr(157) => 'g', |
|
299 |
chr(196).chr(158) => 'G', chr(196).chr(159) => 'g', |
|
300 |
chr(196).chr(160) => 'G', chr(196).chr(161) => 'g', |
|
301 |
chr(196).chr(162) => 'G', chr(196).chr(163) => 'g', |
|
302 |
chr(196).chr(164) => 'H', chr(196).chr(165) => 'h', |
|
303 |
chr(196).chr(166) => 'H', chr(196).chr(167) => 'h', |
|
304 |
chr(196).chr(168) => 'I', chr(196).chr(169) => 'i', |
|
305 |
chr(196).chr(170) => 'I', chr(196).chr(171) => 'i', |
|
306 |
chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', |
|
307 |
chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', |
|
308 |
chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', |
|
309 |
chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij', |
|
310 |
chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', |
|
311 |
chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', |
|
312 |
chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', |
|
313 |
chr(196).chr(186) => 'l', chr(196).chr(187) => 'L', |
|
314 |
chr(196).chr(188) => 'l', chr(196).chr(189) => 'L', |
|
315 |
chr(196).chr(190) => 'l', chr(196).chr(191) => 'L', |
|
316 |
chr(197).chr(128) => 'l', chr(197).chr(129) => 'L', |
|
317 |
chr(197).chr(130) => 'l', chr(197).chr(131) => 'N', |
|
318 |
chr(197).chr(132) => 'n', chr(197).chr(133) => 'N', |
|
319 |
chr(197).chr(134) => 'n', chr(197).chr(135) => 'N', |
|
320 |
chr(197).chr(136) => 'n', chr(197).chr(137) => 'N', |
|
321 |
chr(197).chr(138) => 'n', chr(197).chr(139) => 'N', |
|
322 |
chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', |
|
323 |
chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', |
|
324 |
chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', |
|
325 |
chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe', |
|
326 |
chr(197).chr(148) => 'R',chr(197).chr(149) => 'r', |
|
327 |
chr(197).chr(150) => 'R',chr(197).chr(151) => 'r', |
|
328 |
chr(197).chr(152) => 'R',chr(197).chr(153) => 'r', |
|
329 |
chr(197).chr(154) => 'S',chr(197).chr(155) => 's', |
|
330 |
chr(197).chr(156) => 'S',chr(197).chr(157) => 's', |
|
331 |
chr(197).chr(158) => 'S',chr(197).chr(159) => 's', |
|
332 |
chr(197).chr(160) => 'S', chr(197).chr(161) => 's', |
|
333 |
chr(197).chr(162) => 'T', chr(197).chr(163) => 't', |
|
334 |
chr(197).chr(164) => 'T', chr(197).chr(165) => 't', |
|
335 |
chr(197).chr(166) => 'T', chr(197).chr(167) => 't', |
|
336 |
chr(197).chr(168) => 'U', chr(197).chr(169) => 'u', |
|
337 |
chr(197).chr(170) => 'U', chr(197).chr(171) => 'u', |
|
338 |
chr(197).chr(172) => 'U', chr(197).chr(173) => 'u', |
|
339 |
chr(197).chr(174) => 'U', chr(197).chr(175) => 'u', |
|
340 |
chr(197).chr(176) => 'U', chr(197).chr(177) => 'u', |
|
341 |
chr(197).chr(178) => 'U', chr(197).chr(179) => 'u', |
|
342 |
chr(197).chr(180) => 'W', chr(197).chr(181) => 'w', |
|
343 |
chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y', |
|
344 |
chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z', |
|
345 |
chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z', |
|
346 |
chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z', |
|
347 |
chr(197).chr(190) => 'z', chr(197).chr(191) => 's', |
|
348 |
// Euro Sign |
|
349 |
chr(226).chr(130).chr(172) => 'E', |
|
350 |
// GBP (Pound) Sign |
|
351 |
chr(194).chr(163) => ''); |
|
352 |
|
|
353 |
$string = strtr($string, $chars); |
|
354 |
} else { |
|
355 |
// Assume ISO-8859-1 if not UTF-8 |
|
356 |
$chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158) |
|
357 |
.chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194) |
|
358 |
.chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202) |
|
359 |
.chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210) |
|
360 |
.chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218) |
|
361 |
.chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227) |
|
362 |
.chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235) |
|
363 |
.chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243) |
|
364 |
.chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251) |
|
365 |
.chr(252).chr(253).chr(255); |
|
366 |
|
|
367 |
$chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy"; |
|
368 |
|
|
369 |
$string = strtr($string, $chars['in'], $chars['out']); |
|
370 |
$double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254)); |
|
371 |
$double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th'); |
|
372 |
$string = str_replace($double_chars['in'], $double_chars['out'], $string); |
|
373 |
} |
|
374 |
|
|
375 |
return $string; |
|
376 |
} |
|
377 |
|
|
378 |
/** |
|
379 |
* Code from wordpress - wordpress.org |
|
380 |
* Checks to see if a string is utf8 encoded. |
|
381 |
* |
|
382 |
* NOTE: This function checks for 5-Byte sequences, UTF8 |
|
383 |
* has Bytes Sequences with a maximum length of 4. |
|
384 |
* |
|
385 |
* @author bmorel at ssi dot fr (modified) |
|
386 |
* @since 1.2.1 |
|
387 |
* |
|
388 |
* @param string $str The string to be checked |
|
389 |
* @return bool True if $str fits a UTF-8 model, false otherwise. |
|
390 |
*/ |
|
391 |
function seems_utf8($str) { |
|
392 |
$length = strlen($str); |
|
393 |
for ($i=0; $i < $length; $i++) { |
|
394 |
$c = ord($str[$i]); |
|
395 |
if ($c < 0x80) $n = 0; # 0bbbbbbb |
|
396 |
elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
397 |
elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
398 |
elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
399 |
elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb |
|
400 |
elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b |
|
401 |
else return false; # Does not match any model |
|
402 |
for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
403 |
if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) |
|
404 |
return false; |
|
405 |
} |
|
406 |
} |
|
407 |
return true; |
|
408 |
} |
|
409 |
|
|
410 |
|
|
411 |
?> |
scripts/migration_gnudip_anet_to_glpi.php | ||
---|---|---|
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 |
* ************************************************************************* */ |
|
38 |
|
|
39 |
$base_dir = dirname(__FILE__); |
|
40 |
$text = ""; |
|
41 |
|
|
42 |
require_once "$base_dir/config/config.php"; |
|
43 |
require_once "$base_dir/libraries/fonctions.php"; |
|
44 |
|
|
45 |
$req = "SELECT dns_alias0, gnudip_pass, dns_alias1 " . |
|
46 |
"FROM gnudip " . |
|
47 |
"WHERE 1;"; |
|
48 |
$res = sql_exec($req); |
|
49 |
|
|
50 |
//Migration anet -> glpi pour gnudip2 |
|
51 |
$nb = $res->NumRows(); |
|
52 |
for ( $i = 0; $i < $nb; $i++) { |
|
53 |
$row = $res->fetchrow( DB_FETCHMODE_ASSOC, $i ); |
|
54 |
//Il nous faut le FK_serveur et le FK_enduser |
|
55 |
$query = "SELECT ID,FK_entities FROM glpi_computers WHERE os_license_number='" . $row['dns_alias0'] . ".dip.abuledu.net';"; |
|
56 |
if ( DB::isError($result = $dbglpi->query($query)) ) { |
|
57 |
die ("***\n$query\n" . DB::errorMessage($result) . "\n***\n\n"); |
|
58 |
} |
|
59 |
$data = $result->fetchRow(DB_FETCHMODE_ASSOC); |
|
60 |
|
|
61 |
if($data['ID']) { |
|
62 |
|
|
63 |
$query2 = "INSERT INTO glpi_plugin_anet_epacks(creation_date,activation_date,expiration_date,code,password,FK_serveur,FK_enduser) |
|
64 |
VALUES( |
|
65 |
'2009-07-01', |
|
66 |
'2009-07-01', |
|
67 |
'2009-07-01', |
|
68 |
'ABE08-01-$i', |
|
69 |
'" . $row['gnudip_pass'] . "', |
|
70 |
'" . $data['ID'] . "', |
|
71 |
'" . $data['FK_entities'] . "' |
|
72 |
);"; |
|
73 |
//$res = $dbglpi->query($query2); |
|
74 |
if ( DB::isError($result2 = $dbglpi->query($query2)) ) { |
|
75 |
print ("***\n$query2\n" . DB::errorMessage($result2) . "\n***\n\n"); |
|
76 |
} |
|
77 |
} |
|
78 |
else |
|
79 |
print "impossible pour " . $row['dns_alias0'] . "\n"; |
|
80 |
|
|
81 |
} |
|
82 |
?> |
scripts/net2dip.sendtohurlevent.php | ||
---|---|---|
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 |
?> |
Formats disponibles : Unified diff