Subversion Repositories Sites.tela-botanica.org

Rev

Go to most recent revision | Details | 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
//
15
// Ce fichier ne sera execute qu'une fois
16
if (defined("_ECRIRE_INC_ACCES")) return;
17
define("_ECRIRE_INC_ACCES", "1");
18
 
19
 
20
function creer_pass_aleatoire($longueur = 8, $sel = "") {
21
	$seed = (double) (microtime() + 1) * time();
22
	mt_srand($seed);
23
	srand($seed);
24
	$s = '';
25
	$pass = '';
26
	for ($i = 0; $i < $longueur; $i++) {
27
		if (!$s) {
28
			$s = mt_rand();
29
			if (!$s) $s = rand();
30
			$s = substr(md5(uniqid($s).$sel), 0, 16);
31
		}
32
		$r = unpack("Cr", pack("H2", $s.$s));
33
		$x = $r['r'] & 63;
34
		if ($x < 10) $x = chr($x + 48);
35
		else if ($x < 36) $x = chr($x + 55);
36
		else if ($x < 62) $x = chr($x + 61);
37
		else if ($x == 63) $x = '/';
38
		else $x = '.';
39
		$pass .= $x;
40
		$s = substr($s, 2);
41
	}
42
	$pass = ereg_replace("[./]", "a", $pass);
43
	$pass = ereg_replace("[I1l]", "L", $pass);
44
	$pass = ereg_replace("[0O]", "o", $pass);
45
	return $pass;
46
}
47
 
48
 
49
//
50
// low-security : un ensemble de fonctions pour gerer de l'identification
51
// faible via les URLs (suivi RSS, iCal...)
52
//
53
function low_sec($id_auteur) {
54
	// Pas d'id_auteur : low_sec
55
	if (!$id_auteur = intval($id_auteur)) {
56
		if (!$low_sec = lire_meta('low_sec')) {
57
			include_ecrire('inc_meta.php3');
58
			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
59
			ecrire_metas();
60
		}
61
	}
62
	else {
63
		$query = "SELECT * FROM spip_auteurs WHERE id_auteur = $id_auteur";
64
		$result = spip_query($query);
65
 
66
		if ($row = spip_fetch_array($result)) {
67
			$low_sec = $row["low_sec"];
68
			if (!$low_sec) {
69
				$low_sec = creer_pass_aleatoire();
70
				spip_query("UPDATE spip_auteurs SET low_sec = '$low_sec' WHERE id_auteur = $id_auteur");
71
			}
72
		}
73
	}
74
	return $low_sec;
75
}
76
 
77
function afficher_low_sec ($id_auteur, $action='') {
78
	return substr(md5($action.low_sec($id_auteur)),0,8);
79
}
80
 
81
function verifier_low_sec ($id_auteur, $cle, $action='') {
82
	return ($cle == afficher_low_sec($id_auteur, $action));
83
}
84
 
85
function effacer_low_sec($id_auteur) {
86
	if (!$id_auteur = intval($id_auteur)) return; // jamais trop prudent ;)
87
	spip_query("UPDATE spip_auteurs SET low_sec = '' WHERE id_auteur = $id_auteur");
88
}
89
 
90
 
91
// Une fonction service qui affiche le statut de l'auteur dans l'espace prive
92
function afficher_formulaire_statut_auteur ($id_auteur, $statut, $post='') {
93
	global $connect_statut, $connect_toutes_rubriques, $connect_id_auteur;
94
	global $spip_lang_right;
95
 
96
	if ($post) {
97
		$url_self = $post;
98
		echo "<p />";
99
		echo "<form action='$post' method='post'>\n";
100
	} else
101
		$url_self = "auteur_infos.php3?id_auteur=$id_auteur";
102
 
103
 
104
	// S'agit-il d'un admin restreint ?
105
	if ($statut == '0minirezo') {
106
		$query_admin = "SELECT lien.id_rubrique, titre FROM spip_auteurs_rubriques AS lien, spip_rubriques AS rubriques WHERE lien.id_auteur=$id_auteur AND lien.id_rubrique=rubriques.id_rubrique GROUP BY lien.id_rubrique";
107
		$result_admin = spip_query($query_admin);
108
		$admin_restreint = (spip_num_rows($result_admin) > 0);
109
	}
110
 
111
	// Seuls les admins voient le menu 'statut' ; les admins restreints
112
	// ne peuvent l'utiliser que pour mettre un auteur a la poubelle
113
	if ($connect_statut == "0minirezo"
114
	AND ($connect_toutes_rubriques OR $statut != "0minirezo")
115
	AND $connect_id_auteur != $id_auteur) {
116
		debut_cadre_relief();
117
 
118
		if ($statut == '0minirezo') {
119
			if ($admin_restreint)
120
				echo bouton_block_visible("statut$id_auteur");
121
			else
122
				echo bouton_block_invisible("statut$id_auteur");
123
		}
124
 
125
		echo "<b>"._T('info_statut_auteur')." </b> ";
126
		echo "<select name='statut' size=1 class='fondl'>";
127
 
128
		if ($connect_statut == "0minirezo" AND $connect_toutes_rubriques)
129
			echo "<OPTION".mySel("0minirezo",$statut).">"._T('item_administrateur_2');
130
 
131
		echo "<OPTION".mySel("1comite",$statut).">"._T('intem_redacteur');
132
 
133
		if (($statut == '6forum')
134
		OR (lire_meta('accepter_visiteurs') == 'oui')
135
		OR (lire_meta('forums_publics') == 'abo')
136
		OR spip_num_rows(spip_query("SELECT statut
137
		FROM spip_auteurs WHERE statut='6forum'")))
138
			echo "<OPTION".mySel("6forum",$statut).">"._T('item_visiteur');
139
		echo "<OPTION".mySel("5poubelle",$statut).
140
		  " style='background:url(" . _DIR_IMG_PACK . "rayures-sup.gif)'>&gt; "._T('texte_statut_poubelle');
141
 
142
		echo "</select>\n";
143
 
144
		//
145
		// Gestion restreinte des rubriques
146
		//
147
		if ($statut == '0minirezo') {
148
			if (!$admin_restreint) {
149
				echo debut_block_invisible("statut$id_auteur");
150
				echo "<p /><div style='arial2'>\n";
151
				echo _T('info_admin_gere_toutes_rubriques');
152
			} else {
153
				echo debut_block_visible("statut$id_auteur");
154
				echo "<p /><div style='arial2'>\n";
155
				echo _T('info_admin_gere_rubriques')."\n";
156
				echo "<ul style='list-style-image: url(" . _DIR_IMG_PACK . "rubrique-12.gif)'>";
157
				while ($row_admin = spip_fetch_array($result_admin)) {
158
					$id_rubrique = $row_admin["id_rubrique"];
159
					$titre = typo($row_admin["titre"]);
160
					echo "<li>$titre";
161
					if ($connect_toutes_rubriques
162
					AND $connect_id_auteur != $id_auteur) {
163
						echo " <font size=1>"
164
						. "[<a href='$url_self&supp_rub=$id_rubrique'>"
165
						._T('lien_supprimer_rubrique')
166
						."</a>]</font>";
167
					}
168
					$toutes_rubriques .= "$id_rubrique,";
169
				}
170
				echo "</ul>";
171
				$toutes_rubriques = ",$toutes_rubriques";
172
			}
173
 
174
			if ($connect_toutes_rubriques
175
			AND $connect_id_auteur != $id_auteur) {
176
				echo "</div><br /><div class='arial1'>";
177
				if (spip_num_rows($result_admin) == 0) {
178
					echo "<b>"._T('info_restreindre_rubrique')."</b><br />";
179
				} else {
180
					echo "<b>"._T('info_ajouter_rubrique')."</b><br />";
181
				}
182
				echo "<INPUT NAME='id_auteur' VALUE='$id_auteur' TYPE='hidden'>";
183
				echo "<SELECT NAME='add_rub' SIZE=1 CLASS='formo'>";
184
				echo "<OPTION VALUE='0'>\n";
185
				afficher_auteur_rubriques("0");
186
				echo "</SELECT>";
187
			}
188
 
189
			echo "</div>\n";
190
			echo fin_block();
191
		}
192
 
193
 
194
		if ($post) {
195
			echo "<div align='$spip_lang_right'><input type='submit'
196
			class='fondo' name='Valider'
197
			value=\""._T('bouton_valider')."\" /></div>";
198
			echo "</form>\n";
199
		}
200
 
201
		fin_cadre_relief();
202
	}
203
}
204
 
205
function modifier_statut_auteur (&$auteur, $statut, $add_rub='', $supp_rub='') {
206
	global $connect_statut, $connect_toutes_rubriques;
207
	// changer le statut ?
208
	if ($connect_statut == '0minirezo' AND $statut) {
209
		if (ereg("^(0minirezo|1comite|5poubelle|6forum)$",$statut)) {
210
			$auteur['statut'] = $statut;
211
			spip_query("UPDATE spip_auteurs SET statut='".$statut."'
212
			WHERE id_auteur=".$auteur['id_auteur']);
213
		}
214
	}
215
	// modif auteur restreint, seulement pour les admins
216
	if ($connect_toutes_rubriques) {
217
		if ($add_rub=intval($add_rub))
218
			spip_query("INSERT INTO spip_auteurs_rubriques
219
			(id_auteur,id_rubrique)
220
			VALUES(".$auteur['id_auteur'].", $add_rub)");
221
 
222
		if ($supp_rub=intval($supp_rub))
223
			spip_query("DELETE FROM spip_auteurs_rubriques
224
			WHERE id_auteur=".$auteur['id_auteur']."
225
			AND id_rubrique=$supp_rub");
226
	}
227
}
228
 
229
 
230
function initialiser_sel() {
231
	global $htsalt;
232
 
233
	$htsalt = '$1$'.creer_pass_aleatoire();
234
}
235
 
236
 
237
function ecrire_logins($fichier, $tableau_logins) {
238
	reset($tableau_logins);
239
 
240
	while(list($login, $htpass) = each($tableau_logins)) {
241
		if ($login && $htpass) {
242
			fputs($fichier, "$login:$htpass\n");
243
		}
244
	}
245
}
246
 
247
 
248
function ecrire_acces() {
249
	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
250
	$htpasswd = _DIR_SESSIONS . _AUTH_USER_FILE;
251
 
252
	// si .htaccess existe, outrepasser spip_meta
253
	if ((lire_meta('creer_htpasswd') == 'non') AND !@file_exists($htaccess)) {
254
		@unlink($htpasswd);
255
		@unlink($htpasswd."-admin");
256
		return;
257
	}
258
 
259
	# remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
260
	# de devenir "1comite" le cas echeant (auth http)... a nettoyer
261
	$query = "SELECT login, htpass FROM spip_auteurs WHERE statut != '5poubelle' AND statut!='6forum'";
262
	$result = spip_query_db($query);	// attention, il faut au prealable se connecter a la base (necessaire car utilise par install.php3)
263
	$logins = array();
264
	while($row = spip_fetch_array($result)) $logins[$row['login']] = $row['htpass'];
265
 
266
	$fichier = @fopen($htpasswd, "w");
267
	if ($fichier) {
268
		ecrire_logins($fichier, $logins);
269
		fclose($fichier);
270
	} else {
271
		redirige_par_entete("../spip_test_dirs.php3");
272
	}
273
 
274
	$query = "SELECT login, htpass FROM spip_auteurs WHERE statut = '0minirezo'";
275
	$result = spip_query_db($query);
276
 
277
	$logins = array();
278
	while($row = spip_fetch_array($result)) $logins[$row['login']] = $row['htpass'];
279
 
280
	$fichier = fopen("$htpasswd-admin", "w");
281
	ecrire_logins($fichier, $logins);
282
	fclose($fichier);
283
}
284
 
285
 
286
function generer_htpass($pass) {
287
	global $htsalt, $flag_crypt;
288
	if ($flag_crypt) return crypt($pass, $htsalt);
289
	else return '';
290
}
291
 
292
//
293
// Verifier la presence des .htaccess
294
//
295
function verifier_htaccess($rep) {
296
	$htaccess = "$rep/" . _ACCESS_FILE_NAME;
297
	if ((!@file_exists($htaccess)) AND
298
	    !defined('_ECRIRE_INSTALL') AND !defined('_TEST_DIRS')) {
299
		spip_log("demande de creation de $htaccess");
300
		if ($_SERVER['SERVER_ADMIN'] != 'www@nexenservices.com'){
301
			if (!$f = fopen($htaccess, "w"))
302
				echo "<b>" .
303
				  "ECHEC DE LA CREATION DE $htaccess" . # ne pas traduire
304
				  "</b>";
305
			else
306
			  {
307
				fputs($f, "deny from all\n");
308
				fclose($f);
309
			  }
310
		} else {
311
			echo "<font color=\"#FF0000\">IMPORTANT : </font>";
312
			echo "Votre h&eacute;bergeur est Nexen Services.<br />";
313
			echo "La protection du r&eacute;pertoire <i>$rep/</i> doit se faire
314
			par l'interm&eacute;diaire de ";
315
			echo "<a href=\"http://www.nexenservices.com/webmestres/htlocal.php\"
316
			target=\"_blank\">l'espace webmestres</a>.";
317
			echo "Veuillez cr&eacute;er manuellement la protection pour
318
			ce r&eacute;pertoire (un couple login/mot de passe est
319
			n&eacute;cessaire).<br />";
320
		}
321
	}
322
}
323
 
324
function gerer_htaccess() {
325
	$mode = lire_meta('creer_htaccess');
326
	$r = spip_query("SELECT extension FROM spip_types_documents");
327
	while ($e = spip_fetch_array($r)) {
328
		if (is_dir($dir = _DIR_DOC . $e['extension'])) {
329
			if ($mode == 'oui')
330
				verifier_htaccess($dir);
331
			else @unlink("$dir/" . _ACCESS_FILE_NAME);
332
		}
333
	}
334
	return $mode;
335
}
336
 
337
// En profiter pour verifier la securite de ecrire/data/
338
verifier_htaccess(_DIR_SESSIONS);
339
 
340
initialiser_sel();
341
 
342
?>