@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | /** |
| 262 | 262 | * Initialiser la globale htsalt si cela n'a pas déjà été fait. |
| 263 | 263 | * |
| 264 | - * @return void|bool |
|
| 264 | + * @return string |
|
| 265 | 265 | */ |
| 266 | 266 | function initialiser_sel() { |
| 267 | 267 | if (!isset($GLOBALS['htsalt'])) { |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | /** |
| 319 | 319 | * Generer le fichier de htpasswd contenant les htpass |
| 320 | - * @param $htpasswd |
|
| 320 | + * @param string $htpasswd |
|
| 321 | 321 | * @param $htpasswd_admin |
| 322 | 322 | */ |
| 323 | 323 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
@@ -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,47 +31,47 @@ 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 | - srand($seed); |
|
| 38 | - $s = ''; |
|
| 39 | - $pass = ''; |
|
| 40 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 41 | - if (!$s) { |
|
| 42 | - $s = mt_rand(); |
|
| 43 | - if (!$s) { |
|
| 44 | - $s = rand(); |
|
| 45 | - } |
|
| 46 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 47 | - } |
|
| 48 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 49 | - $x = $r['r'] & 63; |
|
| 50 | - if ($x < 10) { |
|
| 51 | - $x = chr($x + 48); |
|
| 52 | - } else { |
|
| 53 | - if ($x < 36) { |
|
| 54 | - $x = chr($x + 55); |
|
| 55 | - } else { |
|
| 56 | - if ($x < 62) { |
|
| 57 | - $x = chr($x + 61); |
|
| 58 | - } else { |
|
| 59 | - if ($x == 63) { |
|
| 60 | - $x = '/'; |
|
| 61 | - } else { |
|
| 62 | - $x = '.'; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $pass .= $x; |
|
| 68 | - $s = substr($s, 2); |
|
| 69 | - } |
|
| 70 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 71 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 72 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 73 | - |
|
| 74 | - return $pass; |
|
| 34 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | + |
|
| 36 | + mt_srand($seed); |
|
| 37 | + srand($seed); |
|
| 38 | + $s = ''; |
|
| 39 | + $pass = ''; |
|
| 40 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 41 | + if (!$s) { |
|
| 42 | + $s = mt_rand(); |
|
| 43 | + if (!$s) { |
|
| 44 | + $s = rand(); |
|
| 45 | + } |
|
| 46 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 47 | + } |
|
| 48 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 49 | + $x = $r['r'] & 63; |
|
| 50 | + if ($x < 10) { |
|
| 51 | + $x = chr($x + 48); |
|
| 52 | + } else { |
|
| 53 | + if ($x < 36) { |
|
| 54 | + $x = chr($x + 55); |
|
| 55 | + } else { |
|
| 56 | + if ($x < 62) { |
|
| 57 | + $x = chr($x + 61); |
|
| 58 | + } else { |
|
| 59 | + if ($x == 63) { |
|
| 60 | + $x = '/'; |
|
| 61 | + } else { |
|
| 62 | + $x = '.'; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + $pass .= $x; |
|
| 68 | + $s = substr($s, 2); |
|
| 69 | + } |
|
| 70 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 71 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 72 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 73 | + |
|
| 74 | + return $pass; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -80,21 +80,21 @@ discard block |
||
| 80 | 80 | * @return string Identifiant |
| 81 | 81 | */ |
| 82 | 82 | function creer_uniqid() { |
| 83 | - static $seeded; |
|
| 83 | + static $seeded; |
|
| 84 | 84 | |
| 85 | - if (!$seeded) { |
|
| 86 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 87 | - mt_srand($seed); |
|
| 88 | - srand($seed); |
|
| 89 | - $seeded = true; |
|
| 90 | - } |
|
| 85 | + if (!$seeded) { |
|
| 86 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 87 | + mt_srand($seed); |
|
| 88 | + srand($seed); |
|
| 89 | + $seeded = true; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - $s = mt_rand(); |
|
| 93 | - if (!$s) { |
|
| 94 | - $s = rand(); |
|
| 95 | - } |
|
| 92 | + $s = mt_rand(); |
|
| 93 | + if (!$s) { |
|
| 94 | + $s = rand(); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return uniqid($s, 1); |
|
| 97 | + return uniqid($s, 1); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -108,38 +108,38 @@ discard block |
||
| 108 | 108 | * @return string Retourne l'alea éphemère actuel au passage |
| 109 | 109 | */ |
| 110 | 110 | function charger_aleas() { |
| 111 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 112 | - include_spip('base/abstract_sql'); |
|
| 113 | - $aleas = sql_allfetsel( |
|
| 114 | - array('nom', 'valeur'), |
|
| 115 | - 'spip_meta', |
|
| 116 | - sql_in("nom", array('alea_ephemere', 'alea_ephemere_ancien')), |
|
| 117 | - '', '', '', '', '', |
|
| 118 | - 'continue' |
|
| 119 | - ); |
|
| 120 | - if ($aleas) { |
|
| 121 | - foreach ($aleas as $a) { |
|
| 122 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 123 | - } |
|
| 124 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 125 | - } else { |
|
| 126 | - spip_log("aleas indisponibles", "session"); |
|
| 127 | - return ""; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 111 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 112 | + include_spip('base/abstract_sql'); |
|
| 113 | + $aleas = sql_allfetsel( |
|
| 114 | + array('nom', 'valeur'), |
|
| 115 | + 'spip_meta', |
|
| 116 | + sql_in("nom", array('alea_ephemere', 'alea_ephemere_ancien')), |
|
| 117 | + '', '', '', '', '', |
|
| 118 | + 'continue' |
|
| 119 | + ); |
|
| 120 | + if ($aleas) { |
|
| 121 | + foreach ($aleas as $a) { |
|
| 122 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 123 | + } |
|
| 124 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 125 | + } else { |
|
| 126 | + spip_log("aleas indisponibles", "session"); |
|
| 127 | + return ""; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 135 | 135 | **/ |
| 136 | 136 | function renouvelle_alea() { |
| 137 | - charger_aleas(); |
|
| 138 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 139 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 140 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 142 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 137 | + charger_aleas(); |
|
| 138 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 139 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 140 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 142 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -159,20 +159,20 @@ discard block |
||
| 159 | 159 | * Clé de sécurité. |
| 160 | 160 | **/ |
| 161 | 161 | function low_sec($id_auteur) { |
| 162 | - // Pas d'id_auteur : low_sec |
|
| 163 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 164 | - if (!$low_sec = $GLOBALS['meta']['low_sec']) { |
|
| 165 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 166 | - } |
|
| 167 | - } else { |
|
| 168 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur)); |
|
| 169 | - if (!$low_sec) { |
|
| 170 | - $low_sec = creer_pass_aleatoire(); |
|
| 171 | - sql_updateq('spip_auteurs', array('low_sec' => $low_sec), 'id_auteur = '.intval($id_auteur)); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return $low_sec; |
|
| 162 | + // Pas d'id_auteur : low_sec |
|
| 163 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 164 | + if (!$low_sec = $GLOBALS['meta']['low_sec']) { |
|
| 165 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 166 | + } |
|
| 167 | + } else { |
|
| 168 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur)); |
|
| 169 | + if (!$low_sec) { |
|
| 170 | + $low_sec = creer_pass_aleatoire(); |
|
| 171 | + sql_updateq('spip_auteurs', array('low_sec' => $low_sec), 'id_auteur = '.intval($id_auteur)); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return $low_sec; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -188,27 +188,27 @@ discard block |
||
| 188 | 188 | * @return string |
| 189 | 189 | */ |
| 190 | 190 | function param_low_sec($op, $args = array(), $lang = '', $mime = 'rss') { |
| 191 | - $a = $b = ''; |
|
| 192 | - foreach ($args as $val => $var) { |
|
| 193 | - if ($var) { |
|
| 194 | - if ($val <> 'statut') { |
|
| 195 | - $a .= ':' . $val . '-' . $var; |
|
| 196 | - } |
|
| 197 | - $b .= $val . '=' . $var . '&'; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - $a = substr($a, 1); |
|
| 201 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 202 | - |
|
| 203 | - return $b |
|
| 204 | - . 'op=' |
|
| 205 | - . $op |
|
| 206 | - . '&id=' |
|
| 207 | - . $id |
|
| 208 | - . '&cle=' |
|
| 209 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 210 | - . (!$a ? '' : "&args=$a") |
|
| 211 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 191 | + $a = $b = ''; |
|
| 192 | + foreach ($args as $val => $var) { |
|
| 193 | + if ($var) { |
|
| 194 | + if ($val <> 'statut') { |
|
| 195 | + $a .= ':' . $val . '-' . $var; |
|
| 196 | + } |
|
| 197 | + $b .= $val . '=' . $var . '&'; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + $a = substr($a, 1); |
|
| 201 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 202 | + |
|
| 203 | + return $b |
|
| 204 | + . 'op=' |
|
| 205 | + . $op |
|
| 206 | + . '&id=' |
|
| 207 | + . $id |
|
| 208 | + . '&cle=' |
|
| 209 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 210 | + . (!$a ? '' : "&args=$a") |
|
| 211 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * Clé |
| 225 | 225 | **/ |
| 226 | 226 | function afficher_low_sec($id_auteur, $action = '') { |
| 227 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 227 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * true si les clés corresponde, false sinon |
| 243 | 243 | **/ |
| 244 | 244 | function verifier_low_sec($id_auteur, $cle, $action = '') { |
| 245 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 245 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -252,10 +252,10 @@ discard block |
||
| 252 | 252 | * Identifiant de l'auteur |
| 253 | 253 | **/ |
| 254 | 254 | function effacer_low_sec($id_auteur) { |
| 255 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 256 | - return; |
|
| 257 | - } // jamais trop prudent ;) |
|
| 258 | - sql_updateq('spip_auteurs', array('low_sec' => ''), 'id_auteur = '.intval($id_auteur)); |
|
| 255 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 256 | + return; |
|
| 257 | + } // jamais trop prudent ;) |
|
| 258 | + sql_updateq('spip_auteurs', array('low_sec' => ''), 'id_auteur = '.intval($id_auteur)); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | * @return void|bool |
| 265 | 265 | */ |
| 266 | 266 | function initialiser_sel() { |
| 267 | - if (!isset($GLOBALS['htsalt'])) { |
|
| 268 | - if (CRYPT_MD5) { |
|
| 269 | - $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 270 | - } else { |
|
| 271 | - $GLOBALS['htsalt'] = ''; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - return $GLOBALS['htsalt']; |
|
| 267 | + if (!isset($GLOBALS['htsalt'])) { |
|
| 268 | + if (CRYPT_MD5) { |
|
| 269 | + $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 270 | + } else { |
|
| 271 | + $GLOBALS['htsalt'] = ''; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + return $GLOBALS['htsalt']; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -288,31 +288,31 @@ discard block |
||
| 288 | 288 | * - void sinon. |
| 289 | 289 | **/ |
| 290 | 290 | function ecrire_acces() { |
| 291 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 292 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 293 | - |
|
| 294 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 295 | - // par exemple acces_restreint ; |
|
| 296 | - // si .htaccess existe, outrepasser spip_meta |
|
| 297 | - if ((!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 298 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 299 | - and !@file_exists($htaccess) |
|
| 300 | - ) { |
|
| 301 | - spip_unlink($htpasswd); |
|
| 302 | - spip_unlink($htpasswd . '-admin'); |
|
| 303 | - return; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 307 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 308 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 309 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 310 | - |
|
| 311 | - if (spip_connect_ldap()) { |
|
| 312 | - return; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 291 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 292 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 293 | + |
|
| 294 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 295 | + // par exemple acces_restreint ; |
|
| 296 | + // si .htaccess existe, outrepasser spip_meta |
|
| 297 | + if ((!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 298 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 299 | + and !@file_exists($htaccess) |
|
| 300 | + ) { |
|
| 301 | + spip_unlink($htpasswd); |
|
| 302 | + spip_unlink($htpasswd . '-admin'); |
|
| 303 | + return; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 307 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 308 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 309 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 310 | + |
|
| 311 | + if (spip_connect_ldap()) { |
|
| 312 | + return; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -321,29 +321,29 @@ discard block |
||
| 321 | 321 | * @param $htpasswd_admin |
| 322 | 322 | */ |
| 323 | 323 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 324 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 325 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - $pwd_all = ''; // login:htpass pour tous |
|
| 329 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 330 | - |
|
| 331 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 332 | - while ($row = sql_fetch($res)) { |
|
| 333 | - if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 334 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 335 | - $pwd_all .= $ligne; |
|
| 336 | - if ($row['statut'] == '0minirezo') { |
|
| 337 | - $pwd_admin .= $ligne; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - if ($pwd_all) { |
|
| 343 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 344 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 345 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 346 | - } |
|
| 324 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 325 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + $pwd_all = ''; // login:htpass pour tous |
|
| 329 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 330 | + |
|
| 331 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 332 | + while ($row = sql_fetch($res)) { |
|
| 333 | + if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 334 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 335 | + $pwd_all .= $ligne; |
|
| 336 | + if ($row['statut'] == '0minirezo') { |
|
| 337 | + $pwd_admin .= $ligne; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + if ($pwd_all) { |
|
| 343 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 344 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 345 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 346 | + } |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -357,13 +357,13 @@ discard block |
||
| 357 | 357 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 358 | 358 | */ |
| 359 | 359 | function generer_htpass($pass) { |
| 360 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 361 | - return $generer_htpass($pass); |
|
| 362 | - } |
|
| 363 | - elseif (function_exists('crypt')) { |
|
| 364 | - return crypt($pass, initialiser_sel()); |
|
| 365 | - } |
|
| 366 | - return ''; |
|
| 360 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 361 | + return $generer_htpass($pass); |
|
| 362 | + } |
|
| 363 | + elseif (function_exists('crypt')) { |
|
| 364 | + return crypt($pass, initialiser_sel()); |
|
| 365 | + } |
|
| 366 | + return ''; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -376,14 +376,14 @@ discard block |
||
| 376 | 376 | * @return boolean |
| 377 | 377 | */ |
| 378 | 378 | function verifier_htaccess($rep, $force = false) { |
| 379 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 380 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 381 | - return true; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - // directive deny compatible Apache 2.0+ |
|
| 385 | - $deny = |
|
| 386 | - '# Deny all requests from Apache 2.4+. |
|
| 379 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 380 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 381 | + return true; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + // directive deny compatible Apache 2.0+ |
|
| 385 | + $deny = |
|
| 386 | + '# Deny all requests from Apache 2.4+. |
|
| 387 | 387 | <IfModule mod_authz_core.c> |
| 388 | 388 | Require all denied |
| 389 | 389 | </IfModule> |
@@ -392,32 +392,32 @@ discard block |
||
| 392 | 392 | Deny from all |
| 393 | 393 | </IfModule> |
| 394 | 394 | '; |
| 395 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 396 | - if (function_exists('apache_get_version') |
|
| 397 | - and $v = apache_get_version() |
|
| 398 | - and strncmp($v, 'Apache/1.', 9) == 0) { |
|
| 399 | - $deny = "deny from all\n"; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 403 | - fputs($ht, $deny); |
|
| 404 | - fclose($ht); |
|
| 405 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 406 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 407 | - if ($ht = @fopen($t, 'w')) { |
|
| 408 | - @fclose($ht); |
|
| 409 | - include_spip('inc/distant'); |
|
| 410 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 411 | - $t = url_de_base() . $t; |
|
| 412 | - $ht = recuperer_lapage($t, false, 'HEAD', 0); |
|
| 413 | - // htaccess inoperant si on a recupere des entetes HTTP |
|
| 414 | - // (ignorer la reussite si connexion par fopen) |
|
| 415 | - $ht = !(isset($ht[0]) and $ht[0]); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 419 | - |
|
| 420 | - return $ht; |
|
| 395 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 396 | + if (function_exists('apache_get_version') |
|
| 397 | + and $v = apache_get_version() |
|
| 398 | + and strncmp($v, 'Apache/1.', 9) == 0) { |
|
| 399 | + $deny = "deny from all\n"; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 403 | + fputs($ht, $deny); |
|
| 404 | + fclose($ht); |
|
| 405 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 406 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 407 | + if ($ht = @fopen($t, 'w')) { |
|
| 408 | + @fclose($ht); |
|
| 409 | + include_spip('inc/distant'); |
|
| 410 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 411 | + $t = url_de_base() . $t; |
|
| 412 | + $ht = recuperer_lapage($t, false, 'HEAD', 0); |
|
| 413 | + // htaccess inoperant si on a recupere des entetes HTTP |
|
| 414 | + // (ignorer la reussite si connexion par fopen) |
|
| 415 | + $ht = !(isset($ht[0]) and $ht[0]); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 419 | + |
|
| 420 | + return $ht; |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -435,21 +435,21 @@ discard block |
||
| 435 | 435 | * Valeur de la configuration `creer_htaccess` |
| 436 | 436 | */ |
| 437 | 437 | function gerer_htaccess() { |
| 438 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 439 | - // par exemple acces_restreint |
|
| 440 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 441 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 442 | - $dirs[] = array('extension' => 'distant'); |
|
| 443 | - foreach ($dirs as $e) { |
|
| 444 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 445 | - if ($f) { |
|
| 446 | - verifier_htaccess($dir); |
|
| 447 | - } else { |
|
| 448 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - return isset($GLOBALS['meta']['creer_htaccess']) ? $GLOBALS['meta']['creer_htaccess'] : ''; |
|
| 438 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 439 | + // par exemple acces_restreint |
|
| 440 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 441 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 442 | + $dirs[] = array('extension' => 'distant'); |
|
| 443 | + foreach ($dirs as $e) { |
|
| 444 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 445 | + if ($f) { |
|
| 446 | + verifier_htaccess($dir); |
|
| 447 | + } else { |
|
| 448 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + return isset($GLOBALS['meta']['creer_htaccess']) ? $GLOBALS['meta']['creer_htaccess'] : ''; |
|
| 454 | 454 | } |
| 455 | 455 | |
@@ -31,7 +31,7 @@ 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()); |
|
| 34 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 35 | 35 | |
| 36 | 36 | mt_srand($seed); |
| 37 | 37 | srand($seed); |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | if (!$s) { |
| 44 | 44 | $s = rand(); |
| 45 | 45 | } |
| 46 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | + $s = substr(md5(uniqid($s).$sel), 0, 16); |
|
| 47 | 47 | } |
| 48 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | + $r = unpack('Cr', pack('H2', $s.$s)); |
|
| 49 | 49 | $x = $r['r'] & 63; |
| 50 | 50 | if ($x < 10) { |
| 51 | 51 | $x = chr($x + 48); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | static $seeded; |
| 84 | 84 | |
| 85 | 85 | if (!$seeded) { |
| 86 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 87 | 87 | mt_srand($seed); |
| 88 | 88 | srand($seed); |
| 89 | 89 | $seeded = true; |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | foreach ($args as $val => $var) { |
| 193 | 193 | if ($var) { |
| 194 | 194 | if ($val <> 'statut') { |
| 195 | - $a .= ':' . $val . '-' . $var; |
|
| 195 | + $a .= ':'.$val.'-'.$var; |
|
| 196 | 196 | } |
| 197 | - $b .= $val . '=' . $var . '&'; |
|
| 197 | + $b .= $val.'='.$var.'&'; |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | $a = substr($a, 1); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * Clé |
| 225 | 225 | **/ |
| 226 | 226 | function afficher_low_sec($id_auteur, $action = '') { |
| 227 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 227 | + return substr(md5($action.low_sec($id_auteur)), 0, 8); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | function initialiser_sel() { |
| 267 | 267 | if (!isset($GLOBALS['htsalt'])) { |
| 268 | 268 | if (CRYPT_MD5) { |
| 269 | - $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 269 | + $GLOBALS['htsalt'] = '$1$'.creer_pass_aleatoire(); |
|
| 270 | 270 | } else { |
| 271 | 271 | $GLOBALS['htsalt'] = ''; |
| 272 | 272 | } |
@@ -288,8 +288,8 @@ discard block |
||
| 288 | 288 | * - void sinon. |
| 289 | 289 | **/ |
| 290 | 290 | function ecrire_acces() { |
| 291 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 292 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 291 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 292 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 293 | 293 | |
| 294 | 294 | // Cette variable de configuration peut etre posee par un plugin |
| 295 | 295 | // par exemple acces_restreint ; |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | and !@file_exists($htaccess) |
| 300 | 300 | ) { |
| 301 | 301 | spip_unlink($htpasswd); |
| 302 | - spip_unlink($htpasswd . '-admin'); |
|
| 302 | + spip_unlink($htpasswd.'-admin'); |
|
| 303 | 303 | return; |
| 304 | 304 | } |
| 305 | 305 | |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
| 332 | 332 | while ($row = sql_fetch($res)) { |
| 333 | 333 | if (strlen($row['login']) and strlen($row['htpass'])) { |
| 334 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 334 | + $ligne = $row['login'].':'.$row['htpass']."\n"; |
|
| 335 | 335 | $pwd_all .= $ligne; |
| 336 | 336 | if ($row['statut'] == '0minirezo') { |
| 337 | 337 | $pwd_admin .= $ligne; |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | * @return boolean |
| 377 | 377 | */ |
| 378 | 378 | function verifier_htaccess($rep, $force = false) { |
| 379 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 379 | + $htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME; |
|
| 380 | 380 | if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
| 381 | 381 | return true; |
| 382 | 382 | } |
@@ -403,19 +403,19 @@ discard block |
||
| 403 | 403 | fputs($ht, $deny); |
| 404 | 404 | fclose($ht); |
| 405 | 405 | @chmod($htaccess, _SPIP_CHMOD & 0666); |
| 406 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 406 | + $t = rtrim($rep, '/').'/.ok'; |
|
| 407 | 407 | if ($ht = @fopen($t, 'w')) { |
| 408 | 408 | @fclose($ht); |
| 409 | 409 | include_spip('inc/distant'); |
| 410 | 410 | $t = substr($t, strlen(_DIR_RACINE)); |
| 411 | - $t = url_de_base() . $t; |
|
| 411 | + $t = url_de_base().$t; |
|
| 412 | 412 | $ht = recuperer_lapage($t, false, 'HEAD', 0); |
| 413 | 413 | // htaccess inoperant si on a recupere des entetes HTTP |
| 414 | 414 | // (ignorer la reussite si connexion par fopen) |
| 415 | 415 | $ht = !(isset($ht[0]) and $ht[0]); |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 418 | + spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee')); |
|
| 419 | 419 | |
| 420 | 420 | return $ht; |
| 421 | 421 | } |
@@ -441,11 +441,11 @@ discard block |
||
| 441 | 441 | $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
| 442 | 442 | $dirs[] = array('extension' => 'distant'); |
| 443 | 443 | foreach ($dirs as $e) { |
| 444 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 444 | + if (is_dir($dir = _DIR_IMG.$e['extension'])) { |
|
| 445 | 445 | if ($f) { |
| 446 | 446 | verifier_htaccess($dir); |
| 447 | 447 | } else { |
| 448 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 448 | + spip_unlink($dir.'/'._ACCESS_FILE_NAME); |
|
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | } |
@@ -359,8 +359,7 @@ |
||
| 359 | 359 | function generer_htpass($pass) { |
| 360 | 360 | if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
| 361 | 361 | return $generer_htpass($pass); |
| 362 | - } |
|
| 363 | - elseif (function_exists('crypt')) { |
|
| 362 | + } elseif (function_exists('crypt')) { |
|
| 364 | 363 | return crypt($pass, initialiser_sel()); |
| 365 | 364 | } |
| 366 | 365 | return ''; |