[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 /***************************************************** 3 * This file is part of Agora, web based content management system. 4 * 5 * Agora is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * 9 * Agora is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details (file "COPYING"). 13 * 14 * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière. 15 * List of authors detailed in "copyright_fr.html" file. 16 * E-mail : agora@sig.premier-ministre.gouv.fr 17 * Web site : http://www.agora.gouv.fr 18 *****************************************************/ 19 // Ce fichier ne sera execute qu'une fois 20 if (defined("_ECRIRE_INC_ACCES")) 21 return; 22 23 define("_ECRIRE_INC_ACCES", "1"); 24 25 $GLOBALS['htaccess'] = $GLOBALS['dir_ecrire']. '.htaccess'; 26 $GLOBALS['htpasswd'] = $GLOBALS['dir_ecrire']. 'data/.htpasswd'; 27 28 function creer_pass_aleatoire ($longueur = 8, $sel = "") { 29 $seed = (double)(microtime() + 1) * time(); 30 mt_srand($seed); 31 srand($seed); 32 33 for ($i = 0; $i < $longueur; $i++) { 34 if (!$s) { 35 $s = mt_rand(); 36 37 if (!$s) 38 $s = rand(); 39 $s = substr(md5(uniqid($s). $sel), 0, 16); 40 } 41 42 $r = unpack("Cr", pack("H2", $s . $s)); 43 $x = $r['r'] & 63; 44 45 if ($x < 10) 46 $x = chr($x + 48); 47 else if ($x < 36) 48 $x = chr($x + 55); 49 else if ($x < 62) 50 $x = chr($x + 61); 51 else if ($x == 63) 52 $x = '/'; 53 else 54 $x = '.'; 55 56 $pass .= $x; 57 $s = substr($s, 2); 58 } 59 60 $pass = ereg_replace("[./]", "a", $pass); 61 $pass = ereg_replace("[I1l]", "L", $pass); 62 $pass = ereg_replace("[0O]", "o", $pass); 63 return $pass; 64 } 65 66 // 67 // low-security : un ensemble de fonctions pour gerer de l'identification 68 // faible via les URLs (suivi RSS, iCal...) 69 // 70 function low_sec ($id_auteur) { 71 $id_auteur = intval($id_auteur); // jamais trop prudent ;) 72 /********** Modification elebescond@clever-age.com **************/ 73 $auteurMetier = &recuperer_instance_auteur(); 74 $loadOK = $auteurMetier->load($id_auteur); 75 76 if (!PEAR::isError($loadOK)) { 77 $low_sec = $auteurMetier->getLowSec(); 78 79 if (!$low_sec) { 80 $low_sec = creer_pass_aleatoire(); 81 $auteurMetier->setLowSec($low_sec); 82 $updateOK = $auteurMetier->update(); 83 if (PEAR::isError($updateOK)) { 84 die($updateOK->getMessage()); 85 } 86 } 87 return $low_sec; 88 } 89 } 90 91 function afficher_low_sec ($id_auteur, $action = '') { 92 return substr(md5($action . low_sec($id_auteur)), 0, 8); 93 } 94 95 function verifier_low_sec ($id_auteur, $cle, $action = '') { 96 return ($cle == afficher_low_sec($id_auteur, $action)); 97 } 98 99 function effacer_low_sec ($id_auteur) { 100 $auteurMetier = &recuperer_instance_auteur(); 101 $loadOK = $auteurMetier->load($id_auteur); 102 103 if (!PEAR::isError($loadOK)) { 104 $auteurMetier->setLowSec(''); 105 $updateOK = $auteurMetier->update(); 106 if (PEAR::isError($updateOK)) { 107 die($updateOK->getMessage()); 108 } 109 } 110 } 111 112 function initialiser_sel () { 113 global $htsalt; 114 $htsalt = '$1$' . creer_pass_aleatoire(); 115 } 116 117 function ecrire_logins ($fichier, $tableau_logins) { 118 reset($tableau_logins); 119 120 while (list($login, $htpass) = each($tableau_logins)) { 121 if ($login && $htpass) { 122 fputs($fichier, "$login:$htpass\n"); 123 } 124 } 125 } 126 127 function ecrire_acces () { 128 global $htaccess, $htpasswd; 129 130 // si .htaccess existe, outrepasser spip_meta 131 if ((lire_meta('creer_htpasswd') == 'non')AND !file_exists($htaccess)) { 132 @unlink($htpasswd); 133 @unlink($htpasswd . "-admin"); 134 return; 135 } 136 137 $auteurMetier = &recuperer_instance_auteur(); 138 $logins = array(); 139 $logins = $auteurMetier->getHtpassWithLoginExceptStatuts('5poubelle', 'forum'); 140 141 if (PEAR::isError($logins)) { 142 die($logins->getMessage()); 143 } 144 145 $fichier = @fopen($htpasswd, "w"); 146 147 if ($fichier) { 148 ecrire_logins($fichier, $logins); 149 fclose($fichier); 150 } 151 else { 152 @header("Location: ../spip_test_dirs.php"); 153 exit; 154 } 155 156 $auteurMetier = &recuperer_instance_auteur(); 157 $logins = array(); 158 $logins = $auteurMetier->getHtpassWithLoginForProfil('item_webmestre'); 159 160 if (PEAR::isError($logins)) { 161 die($logins->getMessage()); 162 } 163 164 $fichier = fopen("$htpasswd-admin", "w"); 165 ecrire_logins($fichier, $logins); 166 fclose($fichier); 167 } 168 169 function generer_htpass ($pass) { 170 global $htsalt, $flag_crypt; 171 172 if ($flag_crypt) 173 return crypt($pass, $htsalt); 174 else 175 return ''; 176 } 177 178 initialiser_sel(); 179 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |