@@ -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 = 8, $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,11 +264,11 @@ discard block |
||
| 264 | 264 | * @return void|bool |
| 265 | 265 | */ |
| 266 | 266 | function initialiser_sel() { |
| 267 | - if (CRYPT_MD5) { |
|
| 268 | - $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 269 | - } else { |
|
| 270 | - return ''; |
|
| 271 | - } |
|
| 267 | + if (CRYPT_MD5) { |
|
| 268 | + $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 269 | + } else { |
|
| 270 | + return ''; |
|
| 271 | + } |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -285,45 +285,45 @@ discard block |
||
| 285 | 285 | * - void sinon. |
| 286 | 286 | **/ |
| 287 | 287 | function ecrire_acces() { |
| 288 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 289 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 290 | - |
|
| 291 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 292 | - // par exemple acces_restreint ; |
|
| 293 | - // si .htaccess existe, outrepasser spip_meta |
|
| 294 | - if ((!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 295 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 296 | - and !@file_exists($htaccess) |
|
| 297 | - ) { |
|
| 298 | - spip_unlink($htpasswd); |
|
| 299 | - spip_unlink($htpasswd . '-admin'); |
|
| 300 | - return; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 304 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 305 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 306 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 307 | - |
|
| 308 | - if (spip_connect_ldap()) { |
|
| 309 | - return; |
|
| 310 | - } |
|
| 311 | - $p1 = ''; // login:htpass pour tous |
|
| 312 | - $p2 = ''; // login:htpass pour les admins |
|
| 313 | - $s = sql_select('login, htpass, statut', 'spip_auteurs', sql_in('statut', array('1comite', '0minirezo', 'nouveau'))); |
|
| 314 | - while ($t = sql_fetch($s)) { |
|
| 315 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 316 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 317 | - if ($t['statut'] == '0minirezo') { |
|
| 318 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - if ($p1) { |
|
| 323 | - ecrire_fichier($htpasswd, $p1); |
|
| 324 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 325 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 326 | - } |
|
| 288 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 289 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 290 | + |
|
| 291 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 292 | + // par exemple acces_restreint ; |
|
| 293 | + // si .htaccess existe, outrepasser spip_meta |
|
| 294 | + if ((!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 295 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 296 | + and !@file_exists($htaccess) |
|
| 297 | + ) { |
|
| 298 | + spip_unlink($htpasswd); |
|
| 299 | + spip_unlink($htpasswd . '-admin'); |
|
| 300 | + return; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 304 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 305 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 306 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 307 | + |
|
| 308 | + if (spip_connect_ldap()) { |
|
| 309 | + return; |
|
| 310 | + } |
|
| 311 | + $p1 = ''; // login:htpass pour tous |
|
| 312 | + $p2 = ''; // login:htpass pour les admins |
|
| 313 | + $s = sql_select('login, htpass, statut', 'spip_auteurs', sql_in('statut', array('1comite', '0minirezo', 'nouveau'))); |
|
| 314 | + while ($t = sql_fetch($s)) { |
|
| 315 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 316 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 317 | + if ($t['statut'] == '0minirezo') { |
|
| 318 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + if ($p1) { |
|
| 323 | + ecrire_fichier($htpasswd, $p1); |
|
| 324 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 325 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 326 | + } |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -339,9 +339,9 @@ discard block |
||
| 339 | 339 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 340 | 340 | */ |
| 341 | 341 | function generer_htpass($pass) { |
| 342 | - if (function_exists('crypt')) { |
|
| 343 | - return crypt($pass, $GLOBALS['htsalt']); |
|
| 344 | - } |
|
| 342 | + if (function_exists('crypt')) { |
|
| 343 | + return crypt($pass, $GLOBALS['htsalt']); |
|
| 344 | + } |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -354,14 +354,14 @@ discard block |
||
| 354 | 354 | * @return boolean |
| 355 | 355 | */ |
| 356 | 356 | function verifier_htaccess($rep, $force = false) { |
| 357 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 358 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 359 | - return true; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - // directive deny compatible Apache 2.0+ |
|
| 363 | - $deny = |
|
| 364 | - '# Deny all requests from Apache 2.4+. |
|
| 357 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 358 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 359 | + return true; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + // directive deny compatible Apache 2.0+ |
|
| 363 | + $deny = |
|
| 364 | + '# Deny all requests from Apache 2.4+. |
|
| 365 | 365 | <IfModule mod_authz_core.c> |
| 366 | 366 | Require all denied |
| 367 | 367 | </IfModule> |
@@ -370,32 +370,32 @@ discard block |
||
| 370 | 370 | Deny from all |
| 371 | 371 | </IfModule> |
| 372 | 372 | '; |
| 373 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 374 | - if (function_exists('apache_get_version') |
|
| 375 | - and $v = apache_get_version() |
|
| 376 | - and strncmp($v, 'Apache/1.', 9) == 0) { |
|
| 377 | - $deny = "deny from all\n"; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 381 | - fputs($ht, $deny); |
|
| 382 | - fclose($ht); |
|
| 383 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 384 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 385 | - if ($ht = @fopen($t, 'w')) { |
|
| 386 | - @fclose($ht); |
|
| 387 | - include_spip('inc/distant'); |
|
| 388 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 389 | - $t = url_de_base() . $t; |
|
| 390 | - $ht = recuperer_lapage($t, false, 'HEAD', 0); |
|
| 391 | - // htaccess inoperant si on a recupere des entetes HTTP |
|
| 392 | - // (ignorer la reussite si connexion par fopen) |
|
| 393 | - $ht = !(isset($ht[0]) and $ht[0]); |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 397 | - |
|
| 398 | - return $ht; |
|
| 373 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 374 | + if (function_exists('apache_get_version') |
|
| 375 | + and $v = apache_get_version() |
|
| 376 | + and strncmp($v, 'Apache/1.', 9) == 0) { |
|
| 377 | + $deny = "deny from all\n"; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 381 | + fputs($ht, $deny); |
|
| 382 | + fclose($ht); |
|
| 383 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 384 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 385 | + if ($ht = @fopen($t, 'w')) { |
|
| 386 | + @fclose($ht); |
|
| 387 | + include_spip('inc/distant'); |
|
| 388 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 389 | + $t = url_de_base() . $t; |
|
| 390 | + $ht = recuperer_lapage($t, false, 'HEAD', 0); |
|
| 391 | + // htaccess inoperant si on a recupere des entetes HTTP |
|
| 392 | + // (ignorer la reussite si connexion par fopen) |
|
| 393 | + $ht = !(isset($ht[0]) and $ht[0]); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 397 | + |
|
| 398 | + return $ht; |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | /** |
@@ -413,22 +413,22 @@ discard block |
||
| 413 | 413 | * Valeur de la configuration `creer_htaccess` |
| 414 | 414 | */ |
| 415 | 415 | function gerer_htaccess() { |
| 416 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 417 | - // par exemple acces_restreint |
|
| 418 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 419 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 420 | - $dirs[] = array('extension' => 'distant'); |
|
| 421 | - foreach ($dirs as $e) { |
|
| 422 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 423 | - if ($f) { |
|
| 424 | - verifier_htaccess($dir); |
|
| 425 | - } else { |
|
| 426 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - return isset($GLOBALS['meta']['creer_htaccess']) ? $GLOBALS['meta']['creer_htaccess'] : ''; |
|
| 416 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 417 | + // par exemple acces_restreint |
|
| 418 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 419 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 420 | + $dirs[] = array('extension' => 'distant'); |
|
| 421 | + foreach ($dirs as $e) { |
|
| 422 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 423 | + if ($f) { |
|
| 424 | + verifier_htaccess($dir); |
|
| 425 | + } else { |
|
| 426 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return isset($GLOBALS['meta']['creer_htaccess']) ? $GLOBALS['meta']['creer_htaccess'] : ''; |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | initialiser_sel(); |