@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,46 +31,46 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | - |
|
| 36 | - mt_srand($seed); |
|
| 37 | - $s = ''; |
|
| 38 | - $pass = ''; |
|
| 39 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | - if (!$s) { |
|
| 41 | - $s = random_int(0, mt_getrandmax()); |
|
| 42 | - if (!$s) { |
|
| 43 | - $s = random_int(0, mt_getrandmax()); |
|
| 44 | - } |
|
| 45 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | - } |
|
| 47 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | - $x = $r['r'] & 63; |
|
| 49 | - if ($x < 10) { |
|
| 50 | - $x = chr($x + 48); |
|
| 51 | - } else { |
|
| 52 | - if ($x < 36) { |
|
| 53 | - $x = chr($x + 55); |
|
| 54 | - } else { |
|
| 55 | - if ($x < 62) { |
|
| 56 | - $x = chr($x + 61); |
|
| 57 | - } else { |
|
| 58 | - if ($x == 63) { |
|
| 59 | - $x = '/'; |
|
| 60 | - } else { |
|
| 61 | - $x = '.'; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $pass .= $x; |
|
| 67 | - $s = substr($s, 2); |
|
| 68 | - } |
|
| 69 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | - |
|
| 73 | - return $pass; |
|
| 34 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | + |
|
| 36 | + mt_srand($seed); |
|
| 37 | + $s = ''; |
|
| 38 | + $pass = ''; |
|
| 39 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | + if (!$s) { |
|
| 41 | + $s = random_int(0, mt_getrandmax()); |
|
| 42 | + if (!$s) { |
|
| 43 | + $s = random_int(0, mt_getrandmax()); |
|
| 44 | + } |
|
| 45 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | + } |
|
| 47 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | + $x = $r['r'] & 63; |
|
| 49 | + if ($x < 10) { |
|
| 50 | + $x = chr($x + 48); |
|
| 51 | + } else { |
|
| 52 | + if ($x < 36) { |
|
| 53 | + $x = chr($x + 55); |
|
| 54 | + } else { |
|
| 55 | + if ($x < 62) { |
|
| 56 | + $x = chr($x + 61); |
|
| 57 | + } else { |
|
| 58 | + if ($x == 63) { |
|
| 59 | + $x = '/'; |
|
| 60 | + } else { |
|
| 61 | + $x = '.'; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $pass .= $x; |
|
| 67 | + $s = substr($s, 2); |
|
| 68 | + } |
|
| 69 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | + |
|
| 73 | + return $pass; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,20 +79,20 @@ discard block |
||
| 79 | 79 | * @return string Identifiant |
| 80 | 80 | */ |
| 81 | 81 | function creer_uniqid() { |
| 82 | - static $seeded; |
|
| 82 | + static $seeded; |
|
| 83 | 83 | |
| 84 | - if (!$seeded) { |
|
| 85 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | - mt_srand($seed); |
|
| 87 | - $seeded = true; |
|
| 88 | - } |
|
| 84 | + if (!$seeded) { |
|
| 85 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | + mt_srand($seed); |
|
| 87 | + $seeded = true; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $s = random_int(0, mt_getrandmax()); |
|
| 91 | - if (!$s) { |
|
| 92 | - $s = random_int(0, mt_getrandmax()); |
|
| 93 | - } |
|
| 90 | + $s = random_int(0, mt_getrandmax()); |
|
| 91 | + if (!$s) { |
|
| 92 | + $s = random_int(0, mt_getrandmax()); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - return uniqid($s, 1); |
|
| 95 | + return uniqid($s, 1); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -106,42 +106,42 @@ discard block |
||
| 106 | 106 | * @return string Retourne l'alea éphemère actuel au passage |
| 107 | 107 | */ |
| 108 | 108 | function charger_aleas() { |
| 109 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | - include_spip('base/abstract_sql'); |
|
| 111 | - $aleas = sql_allfetsel( |
|
| 112 | - ['nom', 'valeur'], |
|
| 113 | - 'spip_meta', |
|
| 114 | - sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | - '', |
|
| 116 | - '', |
|
| 117 | - '', |
|
| 118 | - '', |
|
| 119 | - '', |
|
| 120 | - 'continue' |
|
| 121 | - ); |
|
| 122 | - if ($aleas) { |
|
| 123 | - foreach ($aleas as $a) { |
|
| 124 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | - } |
|
| 126 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | - } else { |
|
| 128 | - spip_log('aleas indisponibles', 'session'); |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 109 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | + include_spip('base/abstract_sql'); |
|
| 111 | + $aleas = sql_allfetsel( |
|
| 112 | + ['nom', 'valeur'], |
|
| 113 | + 'spip_meta', |
|
| 114 | + sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | + '', |
|
| 116 | + '', |
|
| 117 | + '', |
|
| 118 | + '', |
|
| 119 | + '', |
|
| 120 | + 'continue' |
|
| 121 | + ); |
|
| 122 | + if ($aleas) { |
|
| 123 | + foreach ($aleas as $a) { |
|
| 124 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | + } |
|
| 126 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | + } else { |
|
| 128 | + spip_log('aleas indisponibles', 'session'); |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | 136 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 137 | 137 | **/ |
| 138 | 138 | function renouvelle_alea() { |
| 139 | - charger_aleas(); |
|
| 140 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 139 | + charger_aleas(); |
|
| 140 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -161,21 +161,21 @@ discard block |
||
| 161 | 161 | * Clé de sécurité. |
| 162 | 162 | **/ |
| 163 | 163 | function low_sec($id_auteur) { |
| 164 | - // Pas d'id_auteur : low_sec |
|
| 165 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | - include_spip('inc/config'); |
|
| 167 | - if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | - } |
|
| 170 | - } else { |
|
| 171 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | - if (!$low_sec) { |
|
| 173 | - $low_sec = creer_pass_aleatoire(); |
|
| 174 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $low_sec; |
|
| 164 | + // Pas d'id_auteur : low_sec |
|
| 165 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | + include_spip('inc/config'); |
|
| 167 | + if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | + } |
|
| 170 | + } else { |
|
| 171 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | + if (!$low_sec) { |
|
| 173 | + $low_sec = creer_pass_aleatoire(); |
|
| 174 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $low_sec; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | * @filtre |
| 209 | 209 | */ |
| 210 | 210 | function securiser_acces_low_sec($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 211 | - if ($op) { |
|
| 212 | - $dir .= " $op $args"; |
|
| 213 | - } |
|
| 211 | + if ($op) { |
|
| 212 | + $dir .= " $op $args"; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 215 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | 229 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 230 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | - $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 230 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | + $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | + $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 233 | 233 | |
| 234 | - return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 234 | + return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -249,27 +249,27 @@ discard block |
||
| 249 | 249 | * @deprecated 4.1 |
| 250 | 250 | */ |
| 251 | 251 | function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') { |
| 252 | - $a = $b = ''; |
|
| 253 | - foreach ($args as $val => $var) { |
|
| 254 | - if ($var) { |
|
| 255 | - if ($val <> 'statut') { |
|
| 256 | - $a .= ':' . $val . '-' . $var; |
|
| 257 | - } |
|
| 258 | - $b .= $val . '=' . $var . '&'; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - $a = substr($a, 1); |
|
| 262 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | - |
|
| 264 | - return $b |
|
| 265 | - . 'op=' |
|
| 266 | - . $op |
|
| 267 | - . '&id=' |
|
| 268 | - . $id |
|
| 269 | - . '&cle=' |
|
| 270 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | - . (!$a ? '' : "&args=$a") |
|
| 272 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 252 | + $a = $b = ''; |
|
| 253 | + foreach ($args as $val => $var) { |
|
| 254 | + if ($var) { |
|
| 255 | + if ($val <> 'statut') { |
|
| 256 | + $a .= ':' . $val . '-' . $var; |
|
| 257 | + } |
|
| 258 | + $b .= $val . '=' . $var . '&'; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + $a = substr($a, 1); |
|
| 262 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | + |
|
| 264 | + return $b |
|
| 265 | + . 'op=' |
|
| 266 | + . $op |
|
| 267 | + . '&id=' |
|
| 268 | + . $id |
|
| 269 | + . '&cle=' |
|
| 270 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | + . (!$a ? '' : "&args=$a") |
|
| 272 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Clé |
| 286 | 286 | **/ |
| 287 | 287 | function afficher_low_sec($id_auteur, $action = '') { |
| 288 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * true si les clés corresponde, false sinon |
| 304 | 304 | **/ |
| 305 | 305 | function verifier_low_sec($id_auteur, $cle, $action = '') { |
| 306 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 306 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | * Identifiant de l'auteur |
| 314 | 314 | **/ |
| 315 | 315 | function effacer_low_sec($id_auteur) { |
| 316 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | - return; |
|
| 318 | - } // jamais trop prudent ;) |
|
| 319 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 316 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | + return; |
|
| 318 | + } // jamais trop prudent ;) |
|
| 319 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -334,31 +334,31 @@ discard block |
||
| 334 | 334 | * - void sinon. |
| 335 | 335 | **/ |
| 336 | 336 | function ecrire_acces() { |
| 337 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 338 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 339 | - |
|
| 340 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 341 | - // par exemple acces_restreint ; |
|
| 342 | - // si .htaccess existe, outrepasser spip_meta |
|
| 343 | - if ( |
|
| 344 | - (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 345 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 346 | - and !@file_exists($htaccess) |
|
| 347 | - ) { |
|
| 348 | - spip_unlink($htpasswd); |
|
| 349 | - spip_unlink($htpasswd . '-admin'); |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 354 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 355 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 356 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 357 | - if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 358 | - return; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 337 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 338 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 339 | + |
|
| 340 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 341 | + // par exemple acces_restreint ; |
|
| 342 | + // si .htaccess existe, outrepasser spip_meta |
|
| 343 | + if ( |
|
| 344 | + (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 345 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 346 | + and !@file_exists($htaccess) |
|
| 347 | + ) { |
|
| 348 | + spip_unlink($htpasswd); |
|
| 349 | + spip_unlink($htpasswd . '-admin'); |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 354 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 355 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 356 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 357 | + if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 358 | + return; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | /** |
@@ -367,29 +367,29 @@ discard block |
||
| 367 | 367 | * @param $htpasswd_admin |
| 368 | 368 | */ |
| 369 | 369 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 370 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 371 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $pwd_all = ''; // login:htpass pour tous |
|
| 375 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 376 | - |
|
| 377 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 378 | - while ($row = sql_fetch($res)) { |
|
| 379 | - if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 380 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 381 | - $pwd_all .= $ligne; |
|
| 382 | - if ($row['statut'] == '0minirezo') { |
|
| 383 | - $pwd_admin .= $ligne; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ($pwd_all) { |
|
| 389 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 390 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 391 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 392 | - } |
|
| 370 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 371 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $pwd_all = ''; // login:htpass pour tous |
|
| 375 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 376 | + |
|
| 377 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 378 | + while ($row = sql_fetch($res)) { |
|
| 379 | + if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 380 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 381 | + $pwd_all .= $ligne; |
|
| 382 | + if ($row['statut'] == '0minirezo') { |
|
| 383 | + $pwd_admin .= $ligne; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ($pwd_all) { |
|
| 389 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 390 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 391 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 392 | + } |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -403,11 +403,11 @@ discard block |
||
| 403 | 403 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 404 | 404 | */ |
| 405 | 405 | function generer_htpass($pass) { |
| 406 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 407 | - return $generer_htpass($pass); |
|
| 408 | - } |
|
| 406 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 407 | + return $generer_htpass($pass); |
|
| 408 | + } |
|
| 409 | 409 | |
| 410 | - return ''; |
|
| 410 | + return ''; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -420,14 +420,14 @@ discard block |
||
| 420 | 420 | * @return boolean |
| 421 | 421 | */ |
| 422 | 422 | function verifier_htaccess($rep, $force = false) { |
| 423 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 424 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 425 | - return true; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - // directive deny compatible Apache 2.0+ |
|
| 429 | - $deny = |
|
| 430 | - '# Deny all requests from Apache 2.4+. |
|
| 423 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 424 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 425 | + return true; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + // directive deny compatible Apache 2.0+ |
|
| 429 | + $deny = |
|
| 430 | + '# Deny all requests from Apache 2.4+. |
|
| 431 | 431 | <IfModule mod_authz_core.c> |
| 432 | 432 | Require all denied |
| 433 | 433 | </IfModule> |
@@ -436,32 +436,32 @@ discard block |
||
| 436 | 436 | Deny from all |
| 437 | 437 | </IfModule> |
| 438 | 438 | '; |
| 439 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 440 | - if ( |
|
| 441 | - function_exists('apache_get_version') |
|
| 442 | - and $v = apache_get_version() |
|
| 443 | - and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 444 | - ) { |
|
| 445 | - $deny = "deny from all\n"; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 449 | - fputs($ht, $deny); |
|
| 450 | - fclose($ht); |
|
| 451 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 452 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 453 | - if ($ht = @fopen($t, 'w')) { |
|
| 454 | - @fclose($ht); |
|
| 455 | - include_spip('inc/distant'); |
|
| 456 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 457 | - $t = url_de_base() . $t; |
|
| 458 | - $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 459 | - $ht = ($ht['status'] ?? null) === 403; |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 463 | - |
|
| 464 | - return $ht; |
|
| 439 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 440 | + if ( |
|
| 441 | + function_exists('apache_get_version') |
|
| 442 | + and $v = apache_get_version() |
|
| 443 | + and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 444 | + ) { |
|
| 445 | + $deny = "deny from all\n"; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 449 | + fputs($ht, $deny); |
|
| 450 | + fclose($ht); |
|
| 451 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 452 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 453 | + if ($ht = @fopen($t, 'w')) { |
|
| 454 | + @fclose($ht); |
|
| 455 | + include_spip('inc/distant'); |
|
| 456 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 457 | + $t = url_de_base() . $t; |
|
| 458 | + $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 459 | + $ht = ($ht['status'] ?? null) === 403; |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 463 | + |
|
| 464 | + return $ht; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -479,20 +479,20 @@ discard block |
||
| 479 | 479 | * Valeur de la configuration `creer_htaccess` |
| 480 | 480 | */ |
| 481 | 481 | function gerer_htaccess() { |
| 482 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 483 | - // par exemple acces_restreint |
|
| 484 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 485 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 486 | - $dirs[] = ['extension' => 'distant']; |
|
| 487 | - foreach ($dirs as $e) { |
|
| 488 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 489 | - if ($f) { |
|
| 490 | - verifier_htaccess($dir); |
|
| 491 | - } else { |
|
| 492 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 482 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 483 | + // par exemple acces_restreint |
|
| 484 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 485 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 486 | + $dirs[] = ['extension' => 'distant']; |
|
| 487 | + foreach ($dirs as $e) { |
|
| 488 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 489 | + if ($f) { |
|
| 490 | + verifier_htaccess($dir); |
|
| 491 | + } else { |
|
| 492 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 498 | 498 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | use Spip\Chiffrer\SpipCles; |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -34,151 +34,151 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function auth_spip_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 36 | 36 | |
| 37 | - // retrouver le login |
|
| 38 | - $login = auth_spip_retrouver_login($login); |
|
| 39 | - // login inconnu, n'allons pas plus loin |
|
| 40 | - if (!$login) { |
|
| 41 | - return []; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $md5pass = ''; |
|
| 45 | - $shapass = $shanext = ''; |
|
| 46 | - $auteur_peut_sauver_cles = false; |
|
| 47 | - |
|
| 48 | - if ($pass) { |
|
| 49 | - $row = sql_fetsel( |
|
| 50 | - '*', |
|
| 51 | - 'spip_auteurs', |
|
| 52 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 53 | - '', |
|
| 54 | - '', |
|
| 55 | - '', |
|
| 56 | - '', |
|
| 57 | - $serveur |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - // lever un flag si cet auteur peut sauver les cles |
|
| 61 | - if ($row['statut'] === '0minirezo' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) { |
|
| 62 | - $auteur_peut_sauver_cles = true; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // login inexistant ou mot de passe vide |
|
| 67 | - if (!$pass or !$row) { |
|
| 68 | - return []; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - include_spip('inc/chiffrer'); |
|
| 72 | - $cles = SpipCles::instance(); |
|
| 73 | - $secret = $cles->getSecretAuth(); |
|
| 74 | - |
|
| 75 | - switch (strlen($row['pass'])) { |
|
| 76 | - case 32: |
|
| 77 | - // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 78 | - $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 79 | - if ($row['pass'] !== $md5pass) { |
|
| 80 | - unset($row); |
|
| 81 | - } |
|
| 82 | - break; |
|
| 83 | - case 64: |
|
| 84 | - // anciens mots de passe encodes en sha256(alea.pass) |
|
| 85 | - include_spip('auth/sha256.inc'); |
|
| 86 | - $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 87 | - if ($row['pass'] !== $shapass) { |
|
| 88 | - unset($row); |
|
| 89 | - } |
|
| 90 | - break; |
|
| 91 | - |
|
| 92 | - case 60: |
|
| 93 | - case 98: |
|
| 94 | - default: |
|
| 95 | - // doit-on restaurer un backup des cles ? |
|
| 96 | - if ( |
|
| 97 | - !$secret |
|
| 98 | - and $auteur_peut_sauver_cles |
|
| 99 | - and !empty($row['backup_cles']) |
|
| 100 | - ) { |
|
| 101 | - if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 102 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 103 | - $cles->save(); |
|
| 104 | - } |
|
| 105 | - else { |
|
| 106 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 107 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 112 | - unset($row); |
|
| 113 | - } |
|
| 114 | - break; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // Migration depuis ancienne version : si on a pas encore de cle |
|
| 118 | - // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 119 | - // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 120 | - // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 121 | - if (!$secret and $auteur_peut_sauver_cles) { |
|
| 122 | - if (auth_spip_initialiser_secret()) { |
|
| 123 | - $secret = $cles->getSecretAuth(); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // login/mot de passe incorrect |
|
| 128 | - if (empty($row)) { |
|
| 129 | - return []; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // fait tourner le codage du pass dans la base |
|
| 133 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 134 | - if (!$phpauth and $secret) { |
|
| 135 | - include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 136 | - $pass_hash_next = Password::hacher($pass, $secret); |
|
| 137 | - if ($pass_hash_next) { |
|
| 138 | - $set = [ |
|
| 139 | - 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 140 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 141 | - 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 142 | - ]; |
|
| 143 | - |
|
| 144 | - // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 145 | - // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 146 | - $htpass = generer_htpass($pass); |
|
| 147 | - if (strlen($htpass) !== strlen($row['htpass'])) { |
|
| 148 | - $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 152 | - if ($auteur_peut_sauver_cles) { |
|
| 153 | - $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - @sql_update( |
|
| 157 | - 'spip_auteurs', |
|
| 158 | - $set, |
|
| 159 | - 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 160 | - $row['pass'], |
|
| 161 | - $serveur, |
|
| 162 | - 'text' |
|
| 163 | - ), |
|
| 164 | - [], |
|
| 165 | - $serveur |
|
| 166 | - ); |
|
| 167 | - |
|
| 168 | - // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 169 | - if (isset($set['htpass'])) { |
|
| 170 | - ecrire_acces(); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // En profiter pour verifier la securite de tmp/ |
|
| 175 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 176 | - if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return $row; |
|
| 37 | + // retrouver le login |
|
| 38 | + $login = auth_spip_retrouver_login($login); |
|
| 39 | + // login inconnu, n'allons pas plus loin |
|
| 40 | + if (!$login) { |
|
| 41 | + return []; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $md5pass = ''; |
|
| 45 | + $shapass = $shanext = ''; |
|
| 46 | + $auteur_peut_sauver_cles = false; |
|
| 47 | + |
|
| 48 | + if ($pass) { |
|
| 49 | + $row = sql_fetsel( |
|
| 50 | + '*', |
|
| 51 | + 'spip_auteurs', |
|
| 52 | + 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 53 | + '', |
|
| 54 | + '', |
|
| 55 | + '', |
|
| 56 | + '', |
|
| 57 | + $serveur |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + // lever un flag si cet auteur peut sauver les cles |
|
| 61 | + if ($row['statut'] === '0minirezo' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) { |
|
| 62 | + $auteur_peut_sauver_cles = true; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // login inexistant ou mot de passe vide |
|
| 67 | + if (!$pass or !$row) { |
|
| 68 | + return []; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + include_spip('inc/chiffrer'); |
|
| 72 | + $cles = SpipCles::instance(); |
|
| 73 | + $secret = $cles->getSecretAuth(); |
|
| 74 | + |
|
| 75 | + switch (strlen($row['pass'])) { |
|
| 76 | + case 32: |
|
| 77 | + // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 78 | + $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 79 | + if ($row['pass'] !== $md5pass) { |
|
| 80 | + unset($row); |
|
| 81 | + } |
|
| 82 | + break; |
|
| 83 | + case 64: |
|
| 84 | + // anciens mots de passe encodes en sha256(alea.pass) |
|
| 85 | + include_spip('auth/sha256.inc'); |
|
| 86 | + $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 87 | + if ($row['pass'] !== $shapass) { |
|
| 88 | + unset($row); |
|
| 89 | + } |
|
| 90 | + break; |
|
| 91 | + |
|
| 92 | + case 60: |
|
| 93 | + case 98: |
|
| 94 | + default: |
|
| 95 | + // doit-on restaurer un backup des cles ? |
|
| 96 | + if ( |
|
| 97 | + !$secret |
|
| 98 | + and $auteur_peut_sauver_cles |
|
| 99 | + and !empty($row['backup_cles']) |
|
| 100 | + ) { |
|
| 101 | + if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 102 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 103 | + $cles->save(); |
|
| 104 | + } |
|
| 105 | + else { |
|
| 106 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 107 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 112 | + unset($row); |
|
| 113 | + } |
|
| 114 | + break; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // Migration depuis ancienne version : si on a pas encore de cle |
|
| 118 | + // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 119 | + // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 120 | + // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 121 | + if (!$secret and $auteur_peut_sauver_cles) { |
|
| 122 | + if (auth_spip_initialiser_secret()) { |
|
| 123 | + $secret = $cles->getSecretAuth(); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // login/mot de passe incorrect |
|
| 128 | + if (empty($row)) { |
|
| 129 | + return []; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // fait tourner le codage du pass dans la base |
|
| 133 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 134 | + if (!$phpauth and $secret) { |
|
| 135 | + include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 136 | + $pass_hash_next = Password::hacher($pass, $secret); |
|
| 137 | + if ($pass_hash_next) { |
|
| 138 | + $set = [ |
|
| 139 | + 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 140 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 141 | + 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 142 | + ]; |
|
| 143 | + |
|
| 144 | + // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 145 | + // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 146 | + $htpass = generer_htpass($pass); |
|
| 147 | + if (strlen($htpass) !== strlen($row['htpass'])) { |
|
| 148 | + $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 152 | + if ($auteur_peut_sauver_cles) { |
|
| 153 | + $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + @sql_update( |
|
| 157 | + 'spip_auteurs', |
|
| 158 | + $set, |
|
| 159 | + 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 160 | + $row['pass'], |
|
| 161 | + $serveur, |
|
| 162 | + 'text' |
|
| 163 | + ), |
|
| 164 | + [], |
|
| 165 | + $serveur |
|
| 166 | + ); |
|
| 167 | + |
|
| 168 | + // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 169 | + if (isset($set['htpass'])) { |
|
| 170 | + ecrire_acces(); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // En profiter pour verifier la securite de tmp/ |
|
| 175 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 176 | + if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return $row; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -193,33 +193,33 @@ discard block |
||
| 193 | 193 | * @return bool |
| 194 | 194 | */ |
| 195 | 195 | function auth_spip_initialiser_secret(bool $force = false): bool { |
| 196 | - include_spip('inc/chiffrer'); |
|
| 197 | - $cles = SpipCles::instance(); |
|
| 198 | - $secret = $cles->getSecretAuth(); |
|
| 199 | - |
|
| 200 | - // on ne fait rien si on a un secret dispo |
|
| 201 | - if ($secret) { |
|
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 206 | - if ($force) { |
|
| 207 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 208 | - $secret = $cles->getSecretAuth(true); |
|
| 209 | - return true; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 213 | - $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 214 | - if (empty($has_backup)) { |
|
| 215 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 216 | - $secret = $cles->getSecretAuth(true); |
|
| 217 | - return true; |
|
| 218 | - } |
|
| 219 | - else { |
|
| 220 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 221 | - return false; |
|
| 222 | - } |
|
| 196 | + include_spip('inc/chiffrer'); |
|
| 197 | + $cles = SpipCles::instance(); |
|
| 198 | + $secret = $cles->getSecretAuth(); |
|
| 199 | + |
|
| 200 | + // on ne fait rien si on a un secret dispo |
|
| 201 | + if ($secret) { |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 206 | + if ($force) { |
|
| 207 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 208 | + $secret = $cles->getSecretAuth(true); |
|
| 209 | + return true; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 213 | + $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 214 | + if (empty($has_backup)) { |
|
| 215 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 216 | + $secret = $cles->getSecretAuth(true); |
|
| 217 | + return true; |
|
| 218 | + } |
|
| 219 | + else { |
|
| 220 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 221 | + return false; |
|
| 222 | + } |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | /** |
@@ -229,19 +229,19 @@ discard block |
||
| 229 | 229 | * @return array |
| 230 | 230 | */ |
| 231 | 231 | function auth_spip_formulaire_login($flux) { |
| 232 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 233 | - $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 234 | - $flux['data'] .= |
|
| 235 | - '<script type="text/javascript">/*<![CDATA[*/' |
|
| 236 | - . "$js\n" |
|
| 237 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 238 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 239 | - . "'informe_auteur_en_cours':false," |
|
| 240 | - . "'attente_informe':0};" |
|
| 241 | - . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 242 | - . '/*]]>*/</script>'; |
|
| 243 | - |
|
| 244 | - return $flux; |
|
| 232 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 233 | + $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 234 | + $flux['data'] .= |
|
| 235 | + '<script type="text/javascript">/*<![CDATA[*/' |
|
| 236 | + . "$js\n" |
|
| 237 | + . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 238 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 239 | + . "'informe_auteur_en_cours':false," |
|
| 240 | + . "'attente_informe':0};" |
|
| 241 | + . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 242 | + . '/*]]>*/</script>'; |
|
| 243 | + |
|
| 244 | + return $flux; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | * toujours true pour un auteur cree dans SPIP |
| 254 | 254 | */ |
| 255 | 255 | function auth_spip_autoriser_modifier_login(string $serveur = ''): bool { |
| 256 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 257 | - if (strlen($serveur)) { |
|
| 258 | - return false; |
|
| 259 | - } |
|
| 260 | - return true; |
|
| 256 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 257 | + if (strlen($serveur)) { |
|
| 258 | + return false; |
|
| 259 | + } |
|
| 260 | + return true; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -271,25 +271,25 @@ discard block |
||
| 271 | 271 | * message d'erreur si login non valide, chaine vide sinon |
| 272 | 272 | */ |
| 273 | 273 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 274 | - // login et mot de passe |
|
| 275 | - if (strlen($new_login)) { |
|
| 276 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 277 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 278 | - } else { |
|
| 279 | - $n = sql_countsel( |
|
| 280 | - 'spip_auteurs', |
|
| 281 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 282 | - '', |
|
| 283 | - '', |
|
| 284 | - $serveur |
|
| 285 | - ); |
|
| 286 | - if ($n) { |
|
| 287 | - return _T('info_login_existant'); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - return ''; |
|
| 274 | + // login et mot de passe |
|
| 275 | + if (strlen($new_login)) { |
|
| 276 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 277 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 278 | + } else { |
|
| 279 | + $n = sql_countsel( |
|
| 280 | + 'spip_auteurs', |
|
| 281 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 282 | + '', |
|
| 283 | + '', |
|
| 284 | + $serveur |
|
| 285 | + ); |
|
| 286 | + if ($n) { |
|
| 287 | + return _T('info_login_existant'); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + return ''; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -301,41 +301,41 @@ discard block |
||
| 301 | 301 | * @return bool |
| 302 | 302 | */ |
| 303 | 303 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 304 | - if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 305 | - return false; |
|
| 306 | - } |
|
| 307 | - if ( |
|
| 308 | - !$id_auteur = intval($id_auteur) |
|
| 309 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 310 | - ) { |
|
| 311 | - return false; |
|
| 312 | - } |
|
| 313 | - if ($new_login == $auteur['login']) { |
|
| 314 | - return true; |
|
| 315 | - } // on a rien fait mais c'est bon ! |
|
| 316 | - |
|
| 317 | - include_spip('action/editer_auteur'); |
|
| 318 | - |
|
| 319 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 320 | - if (strlen($new_login)) { |
|
| 321 | - $anciens = sql_allfetsel( |
|
| 322 | - 'id_auteur', |
|
| 323 | - 'spip_auteurs', |
|
| 324 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 325 | - '', |
|
| 326 | - '', |
|
| 327 | - '', |
|
| 328 | - '', |
|
| 329 | - $serveur |
|
| 330 | - ); |
|
| 331 | - while ($row = array_pop($anciens)) { |
|
| 332 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 337 | - |
|
| 338 | - return true; |
|
| 304 | + if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 305 | + return false; |
|
| 306 | + } |
|
| 307 | + if ( |
|
| 308 | + !$id_auteur = intval($id_auteur) |
|
| 309 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 310 | + ) { |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 313 | + if ($new_login == $auteur['login']) { |
|
| 314 | + return true; |
|
| 315 | + } // on a rien fait mais c'est bon ! |
|
| 316 | + |
|
| 317 | + include_spip('action/editer_auteur'); |
|
| 318 | + |
|
| 319 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 320 | + if (strlen($new_login)) { |
|
| 321 | + $anciens = sql_allfetsel( |
|
| 322 | + 'id_auteur', |
|
| 323 | + 'spip_auteurs', |
|
| 324 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 325 | + '', |
|
| 326 | + '', |
|
| 327 | + '', |
|
| 328 | + '', |
|
| 329 | + $serveur |
|
| 330 | + ); |
|
| 331 | + while ($row = array_pop($anciens)) { |
|
| 332 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 337 | + |
|
| 338 | + return true; |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -347,44 +347,44 @@ discard block |
||
| 347 | 347 | * @return string |
| 348 | 348 | */ |
| 349 | 349 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 350 | - if (!strlen($login)) { |
|
| 351 | - return null; |
|
| 352 | - } // pas la peine de requeter |
|
| 353 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 354 | - if ( |
|
| 355 | - $r = sql_getfetsel( |
|
| 356 | - 'login', |
|
| 357 | - 'spip_auteurs', |
|
| 358 | - "statut<>'5poubelle'" . |
|
| 359 | - ' AND (length(pass)>0)' . |
|
| 360 | - " AND (login=$l)", |
|
| 361 | - '', |
|
| 362 | - '', |
|
| 363 | - '', |
|
| 364 | - '', |
|
| 365 | - $serveur |
|
| 366 | - ) |
|
| 367 | - ) { |
|
| 368 | - return $r; |
|
| 369 | - } |
|
| 370 | - // Si pas d'auteur avec ce login |
|
| 371 | - // regarder s'il a saisi son nom ou son mail. |
|
| 372 | - // Ne pas fusionner avec la requete precedente |
|
| 373 | - // car un nom peut etre homonyme d'un autre login |
|
| 374 | - else { |
|
| 375 | - return sql_getfetsel( |
|
| 376 | - 'login', |
|
| 377 | - 'spip_auteurs', |
|
| 378 | - "statut<>'5poubelle'" . |
|
| 379 | - ' AND (length(pass)>0)' . |
|
| 380 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 381 | - '', |
|
| 382 | - '', |
|
| 383 | - '', |
|
| 384 | - '', |
|
| 385 | - $serveur |
|
| 386 | - ); |
|
| 387 | - } |
|
| 350 | + if (!strlen($login)) { |
|
| 351 | + return null; |
|
| 352 | + } // pas la peine de requeter |
|
| 353 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 354 | + if ( |
|
| 355 | + $r = sql_getfetsel( |
|
| 356 | + 'login', |
|
| 357 | + 'spip_auteurs', |
|
| 358 | + "statut<>'5poubelle'" . |
|
| 359 | + ' AND (length(pass)>0)' . |
|
| 360 | + " AND (login=$l)", |
|
| 361 | + '', |
|
| 362 | + '', |
|
| 363 | + '', |
|
| 364 | + '', |
|
| 365 | + $serveur |
|
| 366 | + ) |
|
| 367 | + ) { |
|
| 368 | + return $r; |
|
| 369 | + } |
|
| 370 | + // Si pas d'auteur avec ce login |
|
| 371 | + // regarder s'il a saisi son nom ou son mail. |
|
| 372 | + // Ne pas fusionner avec la requete precedente |
|
| 373 | + // car un nom peut etre homonyme d'un autre login |
|
| 374 | + else { |
|
| 375 | + return sql_getfetsel( |
|
| 376 | + 'login', |
|
| 377 | + 'spip_auteurs', |
|
| 378 | + "statut<>'5poubelle'" . |
|
| 379 | + ' AND (length(pass)>0)' . |
|
| 380 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 381 | + '', |
|
| 382 | + '', |
|
| 383 | + '', |
|
| 384 | + '', |
|
| 385 | + $serveur |
|
| 386 | + ); |
|
| 387 | + } |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | /** |
@@ -395,11 +395,11 @@ discard block |
||
| 395 | 395 | * toujours true pour un auteur cree dans SPIP |
| 396 | 396 | */ |
| 397 | 397 | function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool { |
| 398 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 399 | - if (strlen($serveur)) { |
|
| 400 | - return false; |
|
| 401 | - } |
|
| 402 | - return true; |
|
| 398 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 399 | + if (strlen($serveur)) { |
|
| 400 | + return false; |
|
| 401 | + } |
|
| 402 | + return true; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -420,12 +420,12 @@ discard block |
||
| 420 | 420 | * message d'erreur si login non valide, chaine vide sinon |
| 421 | 421 | */ |
| 422 | 422 | function auth_spip_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 423 | - // login et mot de passe |
|
| 424 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 425 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 426 | - } |
|
| 423 | + // login et mot de passe |
|
| 424 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 425 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | - return ''; |
|
| 428 | + return ''; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -439,48 +439,48 @@ discard block |
||
| 439 | 439 | * @return bool |
| 440 | 440 | */ |
| 441 | 441 | function auth_spip_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 442 | - if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 443 | - return false; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - if ( |
|
| 447 | - !$id_auteur = intval($id_auteur) |
|
| 448 | - or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 449 | - ) { |
|
| 450 | - return false; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - include_spip('inc/chiffrer'); |
|
| 454 | - $cles = SpipCles::instance(); |
|
| 455 | - $secret = $cles->getSecretAuth(); |
|
| 456 | - if (!$secret) { |
|
| 457 | - if (auth_spip_initialiser_secret()) { |
|
| 458 | - $secret = $cles->getSecretAuth(); |
|
| 459 | - } |
|
| 460 | - else { |
|
| 461 | - return false; |
|
| 462 | - } |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - include_spip('inc/acces'); |
|
| 467 | - $set = [ |
|
| 468 | - 'pass' => Password::hacher($new_pass, $secret), |
|
| 469 | - 'htpass' => generer_htpass($new_pass), |
|
| 470 | - 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 471 | - 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 472 | - 'low_sec' => '', |
|
| 473 | - ]; |
|
| 474 | - |
|
| 475 | - // si c'est un webmestre, on met a jour son backup des cles |
|
| 476 | - if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') { |
|
| 477 | - $set['backup_cles'] = $cles->backup($new_pass); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - include_spip('action/editer_auteur'); |
|
| 481 | - auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 482 | - |
|
| 483 | - return true; // on a bien modifie le pass |
|
| 442 | + if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 443 | + return false; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + if ( |
|
| 447 | + !$id_auteur = intval($id_auteur) |
|
| 448 | + or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 449 | + ) { |
|
| 450 | + return false; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + include_spip('inc/chiffrer'); |
|
| 454 | + $cles = SpipCles::instance(); |
|
| 455 | + $secret = $cles->getSecretAuth(); |
|
| 456 | + if (!$secret) { |
|
| 457 | + if (auth_spip_initialiser_secret()) { |
|
| 458 | + $secret = $cles->getSecretAuth(); |
|
| 459 | + } |
|
| 460 | + else { |
|
| 461 | + return false; |
|
| 462 | + } |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + include_spip('inc/acces'); |
|
| 467 | + $set = [ |
|
| 468 | + 'pass' => Password::hacher($new_pass, $secret), |
|
| 469 | + 'htpass' => generer_htpass($new_pass), |
|
| 470 | + 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 471 | + 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 472 | + 'low_sec' => '', |
|
| 473 | + ]; |
|
| 474 | + |
|
| 475 | + // si c'est un webmestre, on met a jour son backup des cles |
|
| 476 | + if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') { |
|
| 477 | + $set['backup_cles'] = $cles->backup($new_pass); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + include_spip('action/editer_auteur'); |
|
| 481 | + auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 482 | + |
|
| 483 | + return true; // on a bien modifie le pass |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -494,58 +494,58 @@ discard block |
||
| 494 | 494 | * @return void |
| 495 | 495 | */ |
| 496 | 496 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = ''): void { |
| 497 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 498 | - if (strlen($serveur)) { |
|
| 499 | - return; |
|
| 500 | - } |
|
| 501 | - // si un login, pass ou statut a ete modifie |
|
| 502 | - // regenerer les fichier htpass |
|
| 503 | - if ( |
|
| 504 | - isset($champs['login']) |
|
| 505 | - or isset($champs['pass']) |
|
| 506 | - or isset($champs['statut']) |
|
| 507 | - or (isset($options['all']) and $options['all']) |
|
| 508 | - ) { |
|
| 509 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 510 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 511 | - |
|
| 512 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 513 | - // par exemple acces_restreint ; |
|
| 514 | - // si .htaccess existe, outrepasser spip_meta |
|
| 515 | - if ( |
|
| 516 | - (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 517 | - and !@file_exists($htaccess) |
|
| 518 | - ) { |
|
| 519 | - spip_unlink($htpasswd); |
|
| 520 | - spip_unlink($htpasswd . '-admin'); |
|
| 521 | - |
|
| 522 | - return; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 526 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 527 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 528 | - |
|
| 529 | - $p1 = ''; // login:htpass pour tous |
|
| 530 | - $p2 = ''; // login:htpass pour les admins |
|
| 531 | - $s = sql_select( |
|
| 532 | - 'login, htpass, statut', |
|
| 533 | - 'spip_auteurs', |
|
| 534 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 535 | - ); |
|
| 536 | - while ($t = sql_fetch($s)) { |
|
| 537 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 538 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 539 | - if ($t['statut'] == '0minirezo') { |
|
| 540 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - sql_free($s); |
|
| 545 | - if ($p1) { |
|
| 546 | - ecrire_fichier($htpasswd, $p1); |
|
| 547 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 548 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 549 | - } |
|
| 550 | - } |
|
| 497 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 498 | + if (strlen($serveur)) { |
|
| 499 | + return; |
|
| 500 | + } |
|
| 501 | + // si un login, pass ou statut a ete modifie |
|
| 502 | + // regenerer les fichier htpass |
|
| 503 | + if ( |
|
| 504 | + isset($champs['login']) |
|
| 505 | + or isset($champs['pass']) |
|
| 506 | + or isset($champs['statut']) |
|
| 507 | + or (isset($options['all']) and $options['all']) |
|
| 508 | + ) { |
|
| 509 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 510 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 511 | + |
|
| 512 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 513 | + // par exemple acces_restreint ; |
|
| 514 | + // si .htaccess existe, outrepasser spip_meta |
|
| 515 | + if ( |
|
| 516 | + (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 517 | + and !@file_exists($htaccess) |
|
| 518 | + ) { |
|
| 519 | + spip_unlink($htpasswd); |
|
| 520 | + spip_unlink($htpasswd . '-admin'); |
|
| 521 | + |
|
| 522 | + return; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 526 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 527 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 528 | + |
|
| 529 | + $p1 = ''; // login:htpass pour tous |
|
| 530 | + $p2 = ''; // login:htpass pour les admins |
|
| 531 | + $s = sql_select( |
|
| 532 | + 'login, htpass, statut', |
|
| 533 | + 'spip_auteurs', |
|
| 534 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 535 | + ); |
|
| 536 | + while ($t = sql_fetch($s)) { |
|
| 537 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 538 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 539 | + if ($t['statut'] == '0minirezo') { |
|
| 540 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + sql_free($s); |
|
| 545 | + if ($p1) { |
|
| 546 | + ecrire_fichier($htpasswd, $p1); |
|
| 547 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 548 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | 551 | } |