Subversion Repositories Sites.tela-botanica.org

Rev

Rev 609 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 david 1
<?php
2
 
3
/***************************************************************************\
4
 *  SPIP, Systeme de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright (c) 2001-2005                                                *
7
 *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
8
 *                                                                         *
9
 *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
10
 *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11
\***************************************************************************/
12
 
13
 
14
if (defined("_ECRIRE_INSTALL")) return;
15
define("_ECRIRE_INSTALL", "1");
16
 
17
include ("inc_version.php3");
18
include_ecrire ("inc_presentation.php3");
19
 
20
 
21
//
22
// Verifier que l'hebergement est compatible SPIP ... ou l'inverse :-)
23
// (sert a l'etape 1 de l'installation)
24
function tester_compatibilite_hebergement() {
25
	$err = array();
26
 
27
	$p = phpversion();
28
	if (ereg('^([0-9]+)\.([0-9]+)\.([0-9]+)', $p, $regs)) {
29
		$php = array($regs[1], $regs[2], $regs[3]);
30
		$m = '4.0.8';
31
		$min = explode('.', $m);
32
		if ($php[0]<$min[0]
33
		OR ($php[0]==$min[0] AND $php[1]<$min[1])
34
		OR ($php[0]==$min[0] AND $php[1]==$min[1] AND $php[2]<$min[2]))
35
			$err[] = _L("PHP version $p insuffisant (minimum = $m)");
36
	}
37
 
38
	if (!function_exists('mysql_query'))
39
		$err[] = _T('install_extension_php_obligatoire')
40
		. " <a href='http://se.php.net/mysql'>MYSQL</a>";
41
 
42
	if (!function_exists('preg_match_all'))
43
		$err[] = _T('install_extension_php_obligatoire')
44
		. " <a href='http://se.php.net/pcre'>PCRE</a>";
45
 
46
	if ($a = @ini_get('mbstring.func_overload'))
47
		$err[] = _T('install_extension_mbstring')
48
		. "mbstring.func_overload=$a - <a href='http://se.php.net/mb_string'>mb_string</a>.<br /><small>";
49
 
50
	if ($err) {
51
			echo "<P><FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=4><b>"._T('avis_attention').'</b> <p>'._T('install_echec_annonce')."</p></FONT>";
52
		while (list(,$e) = each ($err))
53
			echo "<li>$e</li>\n";
54
 
55
		# a priori ici on pourrait die(), mais il faut laisser la possibilite
56
		# de forcer malgre tout (pour tester, ou si bug de detection)
57
		echo "<p /><hr />\n";
58
	}
59
}
60
 
61
 
62
// Une fonction pour faciliter la recherche du login (superflu ?)
63
function login_hebergeur() {
64
	global $HTTP_X_HOST, $REQUEST_URI, $SERVER_NAME, $HTTP_HOST;
65
 
66
	$base_hebergeur = 'localhost'; # par defaut
67
 
68
	// Lycos (ex-Multimachin)
69
	if ($HTTP_X_HOST == 'membres.lycos.fr') {
70
		ereg('^/([^/]*)', $REQUEST_URI, $regs);
71
		$login_hebergeur = $regs[1];
72
	}
73
	// Altern
74
	else if (ereg('altern\.com$', $SERVER_NAME)) {
75
		ereg('([^.]*\.[^.]*)$', $HTTP_HOST, $regs);
76
		$login_hebergeur = ereg_replace('[^a-zA-Z0-9]', '_', $regs[1]);
77
	}
78
	// Free
79
	else if (ereg('(.*)\.free\.fr$', $SERVER_NAME, $regs)) {
80
		$base_hebergeur = 'sql.free.fr';
81
		$login_hebergeur = $regs[1];
82
	}
83
 
84
	return array($base_hebergeur, $login_hebergeur);
85
}
86
 
87
 
88
 
89
if (_FILE_CONNECT) {
90
	install_debut_html();
91
	echo "<P><FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=4>"._T('avis_espace_interdit')."</FONT>";
92
 
93
	install_fin_html();
94
	exit;
95
}
96
 
97
include_ecrire ("inc_base.php3");
98
define('_FILE_TMP', '_install');
99
 
100
 
101
// Sur tous les formulaires on peut cliquer "return" pour passer a la suite
102
define ('_VALIDE_CLAVIER', '');
103
/*
104
define ('_VALIDE_CLAVIER', "<script><!--
105
	window.onkeypress = enterSubmit;
106
	function enterSubmit(){
107
		// si on appuie sur enter ou return
108
		if ((event.keyCode==13) || (event.keyCode==3)) {
109
			// a l'etape 1 ne pas valider formulaire var_lang
110
			a = 0;
111
			if ((document.forms(0).action != 'install.php3')
112
			&& (document.forms(0).action != 'index.php3'))
113
				a = 1;
114
			document.forms(a).submit();
115
		}
116
	}
117
// --></script>\n");
118
*/
119
 
120
//
121
// Etapes de l'installation standard
122
//
123
 
124
if ($etape == 6) {
125
	install_debut_html();
126
	echo _VALIDE_CLAVIER;
127
 
128
	echo "<BR><FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('info_derniere_etape')."</B></FONT>";
129
	echo "<P>";
130
	echo "<B>"._T('info_code_acces')."</B>";
131
	echo "<P>"._T('info_utilisation_spip');
132
 
133
	include(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP);
134
	include_ecrire ("inc_meta.php3");
135
 
136
	if ($login) {
137
		$nom = addslashes($nom);
138
		$login = addslashes($login);
139
		$query = "SELECT id_auteur FROM spip_auteurs WHERE login='$login'";
140
		$result = spip_query($query);
141
		unset($id_auteur);
142
		while ($row = spip_fetch_array($result)) $id_auteur = $row['id_auteur'];
143
 
144
		$mdpass = md5($pass);
145
		$htpass = generer_htpass($pass);
146
 
147
		if ($id_auteur) {
148
			$query = "UPDATE spip_auteurs SET nom='$nom', email='$email', login='$login', pass='$mdpass', alea_actuel='', alea_futur=FLOOR(32000*RAND()), htpass='$htpass', statut='0minirezo' WHERE id_auteur=$id_auteur";
149
		}
150
		else {
151
			$query = "INSERT INTO spip_auteurs (nom, email, login, pass, htpass, alea_futur, statut) VALUES('$nom','$email','$login','$mdpass','$htpass',FLOOR(32000*RAND()),'0minirezo')";
152
		}
153
		spip_query($query);
154
 
155
		// inserer email comme email webmaster principal
156
		spip_query("REPLACE spip_meta (nom, valeur)
157
			VALUES ('email_webmaster', '".addslashes($email)."')");
158
	}
159
 
160
	include_ecrire("inc_config.php3");
161
	init_config();
162
	init_langues();
163
 
164
	include_ecrire ("inc_acces.php3");
165
	ecrire_acces();
166
 
167
	@unlink(_DIR_SESSIONS . 'inc_meta_cache.php3');
168
	@unlink(_DIR_SESSIONS . 'meta_cache.php3');
169
	if (!@rename(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP,
170
		    _FILE_CONNECT_INS . _EXTENSION_PHP)) {
171
		copy(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP,
172
		     _FILE_CONNECT_INS . _EXTENSION_PHP);
173
		@unlink(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP);
174
	}
175
 
176
	echo "<FORM ACTION='index.php3' METHOD='post'>";
177
	echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
178
	echo "</FORM>";
179
 
180
	ecrire_metas();
181
 
182
	install_fin_html();
183
}
184
 
185
else if ($etape == 5) {
186
	install_debut_html();
187
	echo _VALIDE_CLAVIER;
188
 
189
	include(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP);
190
 
191
	echo "<BR />\n<FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('info_informations_personnelles')."</FONT>";
192
	echo "<P>\n";
193
 
194
	echo "<b>"._T('texte_informations_personnelles_1')."</b>";
195
	echo aide ("install5");
196
	echo "<p>\n"._T('texte_informations_personnelles_2')." ";
197
	echo _T('info_laisser_champs_vides');
198
 
199
	echo "<FORM ACTION='install.php3' METHOD='post'>";
200
	echo "<INPUT TYPE='hidden' NAME='etape' VALUE='6'>";
201
 
202
	echo "<fieldset><label><B>"._T('info_identification_publique')."</B><BR />\n</label>";
203
	echo "<B>"._T('entree_signature')."</B><BR />\n";
204
	echo _T('entree_nom_pseudo_1')."<BR />\n";
205
	echo "<INPUT TYPE='text' NAME='nom' CLASS='formo' VALUE=\"$nom\" SIZE='40'><P>\n";
206
 
207
	echo "<B>"._T('entree_adresse_email')."</B><BR />\n";
208
	echo "<INPUT TYPE='text' NAME='email' CLASS='formo' VALUE=\"$email\" SIZE='40'></fieldset><P>\n";
209
 
210
	echo "<fieldset><label><B>"._T('entree_identifiants_connexion')."</B><BR />\n</label>";
211
	echo "<B>"._T('entree_login')."</B><BR />\n";
212
	echo _T('info_plus_trois_car')."<BR />\n";
213
	echo "<INPUT TYPE='text' NAME='login' CLASS='formo' VALUE=\"$login\" SIZE='40'><P>\n";
214
 
215
	echo "<B>"._T('entree_mot_passe')."</B> <BR />\n";
216
	echo _T('info_plus_cinq_car_2')."<BR />\n";
217
	echo "<INPUT TYPE='password' NAME='pass' CLASS='formo' VALUE=\"$pass\" SIZE='40'></fieldset><P>\n";
218
 
219
	echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
220
	echo "</FORM>";
221
	echo "<p>\n";
222
 
223
	if ($flag_ldap AND !$ldap_present) {
224
		echo "<div style='border: 1px solid #404040; padding: 10px; text-align: left;'>";
225
		echo "<b>"._T('info_authentification_externe')."</b>";
226
		echo "<p>\n"._T('texte_annuaire_ldap_1');
227
		echo "<FORM ACTION='install.php3' METHOD='post'>";
228
		echo "<INPUT TYPE='hidden' NAME='etape' VALUE='ldap1'>";
229
		echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE=\""._T('bouton_acces_ldap')."\">";
230
		echo "</FORM>";
231
	}
232
 
233
	install_fin_html();
234
 
235
}
236
 
237
else if ($etape == 4) {
238
 
239
	install_debut_html();
240
	echo _VALIDE_CLAVIER;
241
 
242
	// Necessaire pour appeler les fonctions SQL wrappees
243
	include_ecrire("inc_db_mysql.php3");
244
 
245
	echo "<BR />\n<FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('info_creation_tables')."</FONT>";
246
	echo "<P>\n";
247
 
248
	$link = mysql_connect("$adresse_db", "$login_db", "$pass_db");
249
 
250
	echo "<"."!-- $link ";
251
 
252
	if ($choix_db == "new_spip") {
253
		$sel_db = $table_new;
254
		mysql_query("CREATE DATABASE $sel_db");
255
	}
256
	else {
257
		$sel_db = $choix_db;
258
	}
259
	echo "$sel_db ";
260
	mysql_select_db($sel_db);
261
 
262
	// Message pour spip_query : tout va bien !
263
	$GLOBALS['db_ok'] = true;
264
	$GLOBALS['spip_connect_version'] = 0.2; # cf. inc_version
265
 
266
	// Test si SPIP deja installe
267
	spip_query("SELECT COUNT(*) FROM spip_meta");
268
	$nouvelle = spip_sql_errno();
269
	creer_base();
270
 
271
	$maj_ok = maj_base();
272
 
273
	// Tester $mysql_rappel_nom_base
274
	$GLOBALS['mysql_rappel_nom_base'] = true;
275
	$GLOBALS['spip_mysql_db'] = $sel_db;
276
	$ok_rappel_nom = spip_query("INSERT spip_meta (nom,valeur)
277
		VALUES ('mysql_rappel_nom_base', 'test')");
278
	if ($ok_rappel_nom) {
279
		echo " (ok rappel nom base `$sel_db`.spip_meta) ";
280
		$ligne_rappel = '';
281
		spip_query("DELETE FROM spip_meta WHERE nom='mysql_rappel_nom_base'");
282
	} else {
283
		echo " (erreur rappel nom base `$sel_db`.spip_meta) ";
284
		$GLOBALS['mysql_rappel_nom_base'] = false;
285
		$ligne_rappel = "\$GLOBALS['mysql_rappel_nom_base'] = false; ".
286
		"/* echec du test sur `$sel_db`.spip_meta lors de l'installation. */\n";
287
	}
288
 
289
	if ($nouvelle) {
290
		spip_query("INSERT spip_meta (nom, valeur) VALUES ('nouvelle_install', 'oui')");
291
		$result_ok = !spip_sql_errno();
292
	} else {
293
		$result = spip_query("SELECT COUNT(*) FROM spip_articles");
294
		$result_ok = (spip_num_rows($result) > 0);
295
	}
296
	echo "($result_ok && $maj_ok) -->";
297
 
298
 
299
	if ($result_ok && $maj_ok) {
300
		$conn = "<"."?php\n";
301
		$conn .= "if (defined(\"_ECRIRE_INC_CONNECT\")) return;\n";
302
		$conn .= "define(\"_ECRIRE_INC_CONNECT\", \"1\");\n";
303
		$conn .= "\$GLOBALS['spip_connect_version'] = 0.2;\n";
304
		$conn .= "include_ecrire('inc_db_mysql.php3');\n";
305
		$conn .= $ligne_rappel;
306
		$conn .= "spip_connect_db('$adresse_db','','$login_db','$pass_db','$sel_db');\n";
307
#		$conn .= "\$GLOBALS['db_ok'] = !!@spip_num_rows(@spip_query_db('SELECT COUNT(*) FROM spip_meta'));\n";
308
		$conn .= "?".">";
309
		$myFile = fopen(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP, "wb");
310
		fputs($myFile, $conn);
311
		fclose($myFile);
312
 
313
		echo "<B>"._T('info_base_installee')."</B><P>\n"._T('info_etape_suivante_1');
314
 
315
		echo "<FORM ACTION='install.php3' METHOD='post'>";
316
		echo "<INPUT TYPE='hidden' NAME='etape' VALUE='5'>";
317
 
318
		echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
319
 
320
		echo "</FORM>";
321
	}
322
	else if ($result_ok) {
323
		echo _T('alerte_maj_impossible', array('version' => $spip_version));
324
	}
325
	else {
326
		echo "<B>"._T('avis_operation_echec')."</B> "._T('texte_operation_echec');
327
	}
328
 
329
	install_fin_html();
330
 
331
}
332
 
333
else if ($etape == 3) {
334
 
335
	install_debut_html();
336
	echo _VALIDE_CLAVIER;
337
 
338
	echo "<BR />\n<FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('info_choix_base')." <B>"._T('menu_aide_installation_choix_base')."</B></FONT>";
339
 
340
	echo aide ("install2");
341
	echo "<P>\n";
342
 
343
	echo "<FORM ACTION='install.php3' METHOD='post'>";
344
	echo "<INPUT TYPE='hidden' NAME='etape' VALUE='4'>";
345
	echo "<INPUT TYPE='hidden' NAME='adresse_db'  VALUE=\"$adresse_db\" SIZE='40'>";
346
	echo "<INPUT TYPE='hidden' NAME='login_db' VALUE=\"$login_db\">";
347
	echo "<INPUT TYPE='hidden' NAME='pass_db' VALUE=\"$pass_db\"><P>\n";
348
 
349
	$link = mysql_connect("$adresse_db","$login_db","$pass_db");
350
	$result = @mysql_list_dbs();
351
 
352
	echo "<fieldset><label><B>"._T('texte_choix_base_1')."</B><BR />\n</label>";
353
 
354
	if ($result AND (($n = @mysql_num_rows($result)) > 0)) {
355
		echo "<B>"._T('texte_choix_base_2')."</B><P> "._T('texte_choix_base_3');
356
		echo "<UL>";
357
		$bases = "";
358
		for ($i = 0; $i < $n; $i++) {
359
			$table_nom = mysql_dbname($result, $i);
360
			$base = "<INPUT NAME=\"choix_db\" VALUE=\"".$table_nom."\" TYPE=Radio id='tab$i'";
361
			$base_fin = "><label for='tab$i'>".$table_nom."</label><BR />\n\n";
362
			if ($table_nom == $login_db) {
363
				$bases = "$base CHECKED$base_fin".$bases;
364
				$checked = true;
365
			}
366
			else {
367
				$bases .= "$base$base_fin\n";
368
			}
369
		}
370
		echo $bases."</UL>";
371
		echo _T('info_ou')." ";
372
	}
373
	else {
374
		echo "<B>"._T('avis_lecture_noms_bases_1')."</B>
375
		"._T('avis_lecture_noms_bases_2')."<P>";
376
		if ($login_db) {
377
			// Si un login comporte un point, le nom de la base est plus
378
			// probablement le login sans le point -- testons pour savoir
379
			$test_base = $login_db;
380
			$ok = @mysql_select_db($test_base);
381
			$test_base2 = str_replace('.', '_', $test_base);
382
			if (@mysql_select_db($test_base2)) {
383
				$test_base = $test_base2;
384
				$ok = true;
385
			}
386
 
387
			if ($ok) {
388
				echo _T('avis_lecture_noms_bases_3');
389
				echo "<UL>";
390
				echo "<INPUT NAME=\"choix_db\" VALUE=\"".$test_base."\" TYPE=Radio id='stand' CHECKED>";
391
				echo "<label for='stand'>".$test_base."</label><BR />\n";
392
				echo "</UL>";
393
				echo _T('info_ou')." ";
394
				$checked = true;
395
			}
396
		}
397
	}
398
	echo "<INPUT NAME=\"choix_db\" VALUE=\"new_spip\" TYPE=Radio id='nou'";
399
	if (!$checked) echo " CHECKED";
400
	echo "> <label for='nou'>"._T('info_creer_base')."</label> ";
401
	echo "<INPUT TYPE='text' NAME='table_new' CLASS='fondo' VALUE=\"spip\" SIZE='20'></fieldset><P>";
402
 
403
	echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
404
 
405
 
406
	echo "</FORM>";
407
 
408
	install_fin_html();
409
 
410
}
411
 
412
else if ($etape == 2) {
413
 
414
	install_debut_html();
415
	echo _VALIDE_CLAVIER;
416
 
417
 
418
 
419
	echo "<BR />\n<FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('info_connexion_base')."</FONT>";
420
 
421
	echo "<!--";
422
	$link = mysql_connect("$adresse_db","$login_db","$pass_db");
423
	$db_connect = mysql_errno();
424
	echo "-->";
425
 
426
	echo "<P>";
427
 
428
	if (($db_connect=="0") && $link){
429
		echo "<B>"._T('info_connexion_ok')."</B><P> "._T('info_etape_suivante_2');
430
 
431
		echo "<FORM ACTION='install.php3' METHOD='post'>";
432
		echo "<INPUT TYPE='hidden' NAME='etape' VALUE='3'>";
433
		echo "<INPUT TYPE='hidden' NAME='adresse_db'  VALUE=\"$adresse_db\" SIZE='40'>";
434
		echo "<INPUT TYPE='hidden' NAME='login_db' VALUE=\"$login_db\">";
435
		echo "<INPUT TYPE='hidden' NAME='pass_db' VALUE=\"$pass_db\"><P>";
436
 
437
		echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
438
		echo "</FORM>";
439
	}
440
	else {
441
		echo "<B>"._T('avis_connexion_echec_1')."</B>";
442
		echo "<P>"._T('avis_connexion_echec_2');
443
		echo "<P><FONT SIZE=2>"._T('avis_connexion_echec_3')."</FONT>";
444
	}
445
 
446
	install_fin_html();
447
 
448
}
449
else if ($etape == 1) {
450
	install_debut_html();
451
	echo _VALIDE_CLAVIER;
452
 
453
	// stopper en cas de grosse incompatibilite de l'hebergement
454
	tester_compatibilite_hebergement();
455
 
456
	echo "<BR />\n<FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('info_connexion_mysql')."</FONT>";
457
 
458
	echo "<P>"._T('texte_connexion_mysql');
459
 
460
	echo aide ("install1");
461
 
462
	list($adresse_db, $login_db) = login_hebergeur();
463
	$pass_db = '';
464
 
465
	// Recuperer les anciennes donnees pour plus de facilite (si presentes)
466
	if (@file_exists(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP)) {
467
		$s = @join('', @file(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP));
468
		if (ereg("mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)", $s, $regs)) {
469
			$adresse_db = $regs[1];
470
			$login_db = $regs[2];
471
		}
472
		else if (ereg("spip_connect_db\('(.*)','(.*)','(.*)','(.*)','(.*)'\)", $s, $regs)) {
473
			$adresse_db = $regs[1];
474
			if ($port_db = $regs[2]) $adresse_db .= ':'.$port_db;
475
			$login_db = $regs[3];
476
		}
477
	}
478
 
479
	echo "<p><FORM ACTION='install.php3' METHOD='post'>";
480
	echo "<INPUT TYPE='hidden' NAME='etape' VALUE='2'>";
481
	echo "<fieldset><label><B>"._T('entree_base_donnee_1')."</B><BR />\n</label>";
482
	echo _T('entree_base_donnee_2')."<BR />\n";
483
	echo "<INPUT TYPE='text' NAME='adresse_db' CLASS='formo' VALUE=\"$adresse_db\" SIZE='40'></fieldset><P>";
484
 
485
	echo "<fieldset><label><B>"._T('entree_login_connexion_1')."</B><BR />\n</label>";
486
	echo _T('entree_login_connexion_2')."<BR />\n";
487
	echo "<INPUT TYPE='text' NAME='login_db' CLASS='formo' VALUE=\"$login_db\" SIZE='40'></fieldset><P>";
488
 
489
	echo "<fieldset><label><B>"._T('entree_mot_passe_1')."</B><BR />\n</label>";
490
	echo _T('entree_mot_passe_2')."<BR />\n";
491
	echo "<INPUT TYPE='password' NAME='pass_db' CLASS='formo' VALUE=\"$pass_db\" SIZE='40'></fieldset><P>";
492
 
493
	echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
494
 
495
 
496
	echo "</FORM>";
497
 
498
	install_fin_html();
499
 
500
}
501
else if ($etape == 'dirs') {
502
	header("Location: ../spip_test_dirs.php3");
503
}
504
else if (!$etape) {
505
	$menu_langues = menu_langues('var_lang_ecrire');
506
 
507
	if (!$menu_langues)
508
		header("Location: ../spip_test_dirs.php3");
509
	else {
510
		install_debut_html();
511
		echo _VALIDE_CLAVIER;
512
 
513
		echo "<p align='center'><img src='" . _DIR_IMG_PACK . "logo-spip.gif'></p>";
514
 
515
		echo "<p style='text-align: center; font-family: Verdana,Arial,Sans,sans-serif; font-size: 10px;'>";
516
		echo info_copyright();
517
		echo "</p>";
518
 
519
		echo "<p>" . _T('install_select_langue');
520
 
521
		echo "<p><div align='center'>".$menu_langues."</div>";
522
 
523
		echo "<p><FORM ACTION='install.php3' METHOD='get'>";
524
		echo "<INPUT TYPE='hidden' NAME='etape' VALUE='dirs'>";
525
		echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
526
		echo "</FORM>";
527
		install_fin_html();
528
	}
529
}
530
 
531
 
532
//
533
// Etapes de l'installation LDAP
534
//
535
 
536
else if ($etape == 'ldap5') {
537
	install_debut_html();
538
	echo _VALIDE_CLAVIER;
539
 
540
	include_local(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP);
541
	include_ecrire('inc_meta.php3');
542
	ecrire_meta("ldap_statut_import", $statut_ldap);
543
	ecrire_metas();
544
 
545
	echo "<B>"._T('info_ldap_ok')."</B>";
546
	echo "<P>"._T('info_terminer_installation');
547
 
548
	echo "<FORM ACTION='install.php3' METHOD='post'>";
549
	echo "<INPUT TYPE='hidden' NAME='etape' VALUE='5'>";
550
 
551
	echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
552
 
553
	echo "</FORM>";
554
}
555
 
556
else if ($etape == 'ldap4') {
557
	install_debut_html();
558
	echo _VALIDE_CLAVIER;
559
 
560
	if (!$base_ldap) $base_ldap = $base_ldap_text;
561
 
562
	$ldap_link = @ldap_connect("$adresse_ldap", "$port_ldap");
563
	@ldap_bind($ldap_link, "$login_ldap", "$pass_ldap");
564
 
565
	// Essayer de verifier le chemin fourni
566
	$r = @ldap_compare($ldap_link, $base_ldap, "objectClass", "");
567
	$fail = (ldap_errno($ldap_link) == 32);
568
 
569
	if ($fail) {
570
		echo "<BR />\n<FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('info_chemin_acces_annuaire')."</B></FONT>";
571
		echo "<P>";
572
 
573
		echo "<B>"._T('avis_operation_echec')."</B> "._T('avis_chemin_invalide_1')." (<tt>".htmlspecialchars($base_ldap);
574
		echo "</tt>) "._T('avis_chemin_invalide_2');
575
	}
576
	else {
577
		echo "<BR />\n<FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('info_reglage_ldap')."</FONT>";
578
		echo "<P>";
579
 
580
		$conn = join('', file(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP));
581
		if ($p = strpos($conn, '?'.'>'))
582
			$conn = substr($conn, 0, $p);
583
		if (!strpos($conn, 'spip_connect_ldap')) {
584
			$conn .= "function spip_connect_ldap() {\n";
585
			$conn .= "\t\$GLOBALS['ldap_link'] = @ldap_connect(\"$adresse_ldap\",\"$port_ldap\");\n";
586
			$conn .= "\t@ldap_bind(\$GLOBALS['ldap_link'],\"$login_ldap\",\"$pass_ldap\");\n";
587
			$conn .= "\treturn \$GLOBALS['ldap_link'];\n";
588
			$conn .= "}\n";
589
			$conn .= "\$GLOBALS['ldap_base'] = \"$base_ldap\";\n";
590
			$conn .= "\$GLOBALS['ldap_present'] = true;\n";
591
		}
592
		$conn .= "?".">";
593
		$myFile = fopen(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP, "wb");
594
		fputs($myFile, $conn);
595
		fclose($myFile);
596
 
597
		echo "<p><FORM ACTION='install.php3' METHOD='post'>";
598
		echo "<INPUT TYPE='hidden' NAME='etape' VALUE='ldap5'>";
599
		echo "<fieldset><label><B>"._T('info_statut_utilisateurs_1')."</B></label><BR />\n";
600
		echo _T('info_statut_utilisateurs_2')." ";
601
		echo "<p>";
602
		echo "<INPUT TYPE='Radio' NAME='statut_ldap' VALUE=\"6forum\" id='visit'>";
603
		echo "<label for='visit'><b>"._T('info_visiteur_1')."</b></label> "._T('info_visiteur_2')."<br />\n";
604
		echo "<INPUT TYPE='Radio' NAME='statut_ldap' VALUE=\"1comite\" id='redac' CHECKED>";
605
		echo "<label for='redac'><b>"._T('info_redacteur_1')."</b></label> "._T('info_redacteur_2')."<br />\n";
606
		echo "<INPUT TYPE='Radio' NAME='statut_ldap' VALUE=\"0minirezo\" id='admin'>";
607
		echo "<label for='admin'><b>"._T('info_administrateur_1')."</b></label> "._T('info_administrateur_2')."<br />\n";
608
 
609
		echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
610
 
611
		echo "</FORM>";
612
	}
613
 
614
	install_fin_html();
615
}
616
 
617
else if ($etape == 'ldap3') {
618
	install_debut_html();
619
	echo _VALIDE_CLAVIER;
620
 
621
	echo "<BR />\n<FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('info_chemin_acces_1')."</FONT>";
622
 
623
	echo "<P>"._T('info_chemin_acces_2');
624
 
625
	$ldap_link = @ldap_connect("$adresse_ldap", "$port_ldap");
626
	@ldap_bind($ldap_link, "$login_ldap", "$pass_ldap");
627
 
628
	$result = @ldap_read($ldap_link, "", "objectclass=*", array("namingContexts"));
629
	$info = @ldap_get_entries($ldap_link, $result);
630
 
631
	echo "<FORM ACTION='install.php3' METHOD='post'>";
632
	echo "<INPUT TYPE='hidden' NAME='etape' VALUE='ldap4'>";
633
	echo "<INPUT TYPE='hidden' NAME='adresse_ldap' VALUE=\"$adresse_ldap\">";
634
	echo "<INPUT TYPE='hidden' NAME='port_ldap' VALUE=\"$port_ldap\">";
635
	echo "<INPUT TYPE='hidden' NAME='login_ldap' VALUE=\"$login_ldap\">";
636
	echo "<INPUT TYPE='hidden' NAME='pass_ldap' VALUE=\"$pass_ldap\">";
637
 
638
	echo "<fieldset>";
639
 
640
	$checked = false;
641
 
642
	if (is_array($info) AND $info["count"] > 0) {
643
		echo "<P>"._T('info_selection_chemin_acces');
644
		echo "<UL>";
645
		$n = 0;
646
		for ($i = 0; $i < $info["count"]; $i++) {
647
			$names = $info[$i]["namingcontexts"];
648
			if (is_array($names)) {
649
				for ($j = 0; $j < $names["count"]; $j++) {
650
					$n++;
651
					echo "<INPUT NAME=\"base_ldap\" VALUE=\"".htmlspecialchars($names[$j])."\" TYPE='Radio' id='tab$n'";
652
					if (!$checked) {
653
						echo " CHECKED";
654
						$checked = true;
655
					}
656
					echo ">";
657
					echo "<label for='tab$n'>".htmlspecialchars($names[$j])."</label><BR />\n\n";
658
				}
659
			}
660
		}
661
		echo "</UL>";
662
		echo _T('info_ou')." ";
663
	}
664
	echo "<INPUT NAME=\"base_ldap\" VALUE=\"\" TYPE='Radio' id='manuel'";
665
	if (!$checked) {
666
		echo " CHECKED";
667
		$checked = true;
668
	}
669
	echo ">";
670
	echo "<label for='manuel'>"._T('entree_chemin_acces')."</label> ";
671
	echo "<INPUT TYPE='text' NAME='base_ldap_text' CLASS='formo' VALUE=\"ou=users, dc=mon-domaine, dc=com\" SIZE='40'></fieldset><P>";
672
 
673
	echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
674
	echo "</FORM>";
675
 
676
	install_fin_html();
677
 
678
}
679
 
680
else if ($etape == 'ldap2') {
681
	install_debut_html();
682
	echo _VALIDE_CLAVIER;
683
 
684
	echo "<BR />\n<FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('titre_connexion_ldap')."</FONT>";
685
 
686
	echo "<P>";
687
 
688
	$ldap_link = @ldap_connect("$adresse_ldap", "$port_ldap");
689
	$r = @ldap_bind($ldap_link, "$login_ldap", "$pass_ldap");
690
 
691
	if ($ldap_link && ($r || !$login_ldap)) {
692
		echo "<B>"._T('info_connexion_ldap_ok');
693
 
694
		echo "<FORM ACTION='install.php3' METHOD='post'>";
695
		echo "<INPUT TYPE='hidden' NAME='etape' VALUE='ldap3'>";
696
		echo "<INPUT TYPE='hidden' NAME='adresse_ldap' VALUE=\"$adresse_ldap\">";
697
		echo "<INPUT TYPE='hidden' NAME='port_ldap' VALUE=\"$port_ldap\">";
698
		echo "<INPUT TYPE='hidden' NAME='login_ldap' VALUE=\"$login_ldap\">";
699
		echo "<INPUT TYPE='hidden' NAME='pass_ldap' VALUE=\"$pass_ldap\">";
700
 
701
		echo "<DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
702
		echo "</FORM>";
703
	}
704
	else {
705
		echo "<B>"._T('avis_connexion_ldap_echec_1')."</B>";
706
		echo "<P>"._T('avis_connexion_ldap_echec_2');
707
		echo "<br />\n"._T('avis_connexion_ldap_echec_3');
708
	}
709
 
710
	install_fin_html();
711
 
712
}
713
 
714
else if ($etape == 'ldap1') {
715
	install_debut_html();
716
	echo _VALIDE_CLAVIER;
717
 
718
	echo "<BR />\n<FONT FACE='Verdana,Arial,Sans,sans-serif' SIZE=3>"._T('titre_connexion_ldap')."</FONT>";
719
 
720
	echo "<P>"._T('entree_informations_connexion_ldap');
721
 
722
	$adresse_ldap = 'localhost';
723
	$port_ldap = 389;
724
 
725
	// Recuperer les anciennes donnees (si presentes)
726
	if (@file_exists(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP)) {
727
		$s = @join('', @file(_FILE_CONNECT_INS . _FILE_TMP . _EXTENSION_PHP));
728
		if (ereg('ldap_connect\("(.*)","(.*)"\)', $s, $regs)) {
729
			$adresse_ldap = $regs[1];
730
			$port_ldap = $regs[2];
731
		}
732
	}
733
 
734
	echo "<p><FORM ACTION='install.php3' METHOD='post'>";
735
	echo "<INPUT TYPE='hidden' NAME='etape' VALUE='ldap2'>";
736
	echo "<fieldset><label><B>"._T('entree_adresse_annuaire')."</B><BR />\n</label>";
737
	echo _T('texte_adresse_annuaire_1')."<BR />\n";
738
	echo "<INPUT TYPE='text' NAME='adresse_ldap' CLASS='formo' VALUE=\"$adresse_ldap\" SIZE='20'><P>";
739
 
740
	echo "<label><B>"._T('entree_port_annuaire')."</B><BR />\n</label>";
741
	echo _T('texte_port_annuaire')."<BR />\n";
742
	echo "<INPUT TYPE='text' NAME='port_ldap' CLASS='formo' VALUE=\"$port_ldap\" SIZE='20'><P></fieldset>";
743
 
744
	echo "<p><fieldset>";
745
	echo _T('texte_acces_ldap_anonyme_1')." ";
746
	echo "<label><B>"._T('entree_login_ldap')."</B><BR />\n</label>";
747
	echo _T('texte_login_ldap_1')."<br />\n";
748
	echo "<INPUT TYPE='text' NAME='login_ldap' CLASS='formo' VALUE=\"\" SIZE='40'><P>";
749
 
750
	echo "<label><B>"._T('entree_passe_ldap')."</B><BR />\n</label>";
751
	echo "<INPUT TYPE='password' NAME='pass_ldap' CLASS='formo' VALUE=\"\" SIZE='40'></fieldset>";
752
 
753
	echo "<p><DIV align='$spip_lang_right'><INPUT TYPE='submit' CLASS='fondl'  VALUE='"._T('bouton_suivant')." >>'>";
754
 
755
	echo "</FORM>";
756
 
757
	install_fin_html();
758
 
759
}
760
 
761
 
762
?>