@@ -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,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(); |
@@ -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 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | function initialiser_sel() { |
| 267 | 267 | if (CRYPT_MD5) { |
| 268 | - $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 268 | + $GLOBALS['htsalt'] = '$1$'.creer_pass_aleatoire(); |
|
| 269 | 269 | } else { |
| 270 | 270 | return ''; |
| 271 | 271 | } |
@@ -285,8 +285,8 @@ 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; |
|
| 288 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 289 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 290 | 290 | |
| 291 | 291 | // Cette variable de configuration peut etre posee par un plugin |
| 292 | 292 | // par exemple acces_restreint ; |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | and !@file_exists($htaccess) |
| 297 | 297 | ) { |
| 298 | 298 | spip_unlink($htpasswd); |
| 299 | - spip_unlink($htpasswd . '-admin'); |
|
| 299 | + spip_unlink($htpasswd.'-admin'); |
|
| 300 | 300 | return; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -313,15 +313,15 @@ discard block |
||
| 313 | 313 | $s = sql_select('login, htpass, statut', 'spip_auteurs', sql_in('statut', array('1comite', '0minirezo', 'nouveau'))); |
| 314 | 314 | while ($t = sql_fetch($s)) { |
| 315 | 315 | if (strlen($t['login']) and strlen($t['htpass'])) { |
| 316 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 316 | + $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 317 | 317 | if ($t['statut'] == '0minirezo') { |
| 318 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 318 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | } |
| 322 | 322 | if ($p1) { |
| 323 | 323 | ecrire_fichier($htpasswd, $p1); |
| 324 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 324 | + ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 325 | 325 | spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
| 326 | 326 | } |
| 327 | 327 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * @return boolean |
| 355 | 355 | */ |
| 356 | 356 | function verifier_htaccess($rep, $force = false) { |
| 357 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 357 | + $htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME; |
|
| 358 | 358 | if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
| 359 | 359 | return true; |
| 360 | 360 | } |
@@ -381,19 +381,19 @@ discard block |
||
| 381 | 381 | fputs($ht, $deny); |
| 382 | 382 | fclose($ht); |
| 383 | 383 | @chmod($htaccess, _SPIP_CHMOD & 0666); |
| 384 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 384 | + $t = rtrim($rep, '/').'/.ok'; |
|
| 385 | 385 | if ($ht = @fopen($t, 'w')) { |
| 386 | 386 | @fclose($ht); |
| 387 | 387 | include_spip('inc/distant'); |
| 388 | 388 | $t = substr($t, strlen(_DIR_RACINE)); |
| 389 | - $t = url_de_base() . $t; |
|
| 389 | + $t = url_de_base().$t; |
|
| 390 | 390 | $ht = recuperer_lapage($t, false, 'HEAD', 0); |
| 391 | 391 | // htaccess inoperant si on a recupere des entetes HTTP |
| 392 | 392 | // (ignorer la reussite si connexion par fopen) |
| 393 | 393 | $ht = !(isset($ht[0]) and $ht[0]); |
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 396 | + spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee')); |
|
| 397 | 397 | |
| 398 | 398 | return $ht; |
| 399 | 399 | } |
@@ -419,11 +419,11 @@ discard block |
||
| 419 | 419 | $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
| 420 | 420 | $dirs[] = array('extension' => 'distant'); |
| 421 | 421 | foreach ($dirs as $e) { |
| 422 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 422 | + if (is_dir($dir = _DIR_IMG.$e['extension'])) { |
|
| 423 | 423 | if ($f) { |
| 424 | 424 | verifier_htaccess($dir); |
| 425 | 425 | } else { |
| 426 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 426 | + spip_unlink($dir.'/'._ACCESS_FILE_NAME); |
|
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Inscription |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -38,68 +38,68 @@ discard block |
||
| 38 | 38 | * @return array|string |
| 39 | 39 | */ |
| 40 | 40 | function action_inscrire_auteur_dist($statut, $mail_complet, $nom, $options = array()) { |
| 41 | - if (!is_array($options)) { |
|
| 42 | - $options = array('id' => $options); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if (function_exists('test_inscription')) { |
|
| 46 | - $f = 'test_inscription'; |
|
| 47 | - } else { |
|
| 48 | - $f = 'test_inscription_dist'; |
|
| 49 | - } |
|
| 50 | - $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 51 | - |
|
| 52 | - // erreur ? |
|
| 53 | - if (!is_array($desc)) { |
|
| 54 | - return _T($desc); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - include_spip('base/abstract_sql'); |
|
| 58 | - $res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email'])); |
|
| 59 | - // erreur ? |
|
| 60 | - if (!$res) { |
|
| 61 | - return _T('titre_probleme_technique'); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $row = sql_fetch($res); |
|
| 65 | - sql_free($res); |
|
| 66 | - if ($row) { |
|
| 67 | - if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) { |
|
| 68 | - $desc['id_auteur'] = $row['id_auteur']; |
|
| 69 | - $desc = inscription_nouveau($desc); |
|
| 70 | - } else { |
|
| 71 | - $desc = $row; |
|
| 72 | - } |
|
| 73 | - } else // s'il n'existe pas deja, creer les identifiants |
|
| 74 | - { |
|
| 75 | - $desc = inscription_nouveau($desc); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // erreur ? |
|
| 79 | - if (!is_array($desc)) { |
|
| 80 | - return $desc; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 85 | - $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 86 | - |
|
| 87 | - // attribuer un jeton pour confirmation par clic sur un lien |
|
| 88 | - $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 89 | - |
|
| 90 | - // charger de suite cette fonction, pour ses utilitaires |
|
| 91 | - $envoyer_inscription = charger_fonction("envoyer_inscription", ""); |
|
| 92 | - list($sujet, $msg, $from, $head) = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 93 | - |
|
| 94 | - $notifications = charger_fonction('notifications', 'inc'); |
|
| 95 | - notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 96 | - |
|
| 97 | - // Notifications |
|
| 98 | - $notifications('inscription', $desc['id_auteur'], |
|
| 99 | - array('nom' => $desc['nom'], 'email' => $desc['email']) |
|
| 100 | - ); |
|
| 101 | - |
|
| 102 | - return $desc; |
|
| 41 | + if (!is_array($options)) { |
|
| 42 | + $options = array('id' => $options); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if (function_exists('test_inscription')) { |
|
| 46 | + $f = 'test_inscription'; |
|
| 47 | + } else { |
|
| 48 | + $f = 'test_inscription_dist'; |
|
| 49 | + } |
|
| 50 | + $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 51 | + |
|
| 52 | + // erreur ? |
|
| 53 | + if (!is_array($desc)) { |
|
| 54 | + return _T($desc); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + include_spip('base/abstract_sql'); |
|
| 58 | + $res = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . sql_quote($desc['email'])); |
|
| 59 | + // erreur ? |
|
| 60 | + if (!$res) { |
|
| 61 | + return _T('titre_probleme_technique'); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $row = sql_fetch($res); |
|
| 65 | + sql_free($res); |
|
| 66 | + if ($row) { |
|
| 67 | + if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) { |
|
| 68 | + $desc['id_auteur'] = $row['id_auteur']; |
|
| 69 | + $desc = inscription_nouveau($desc); |
|
| 70 | + } else { |
|
| 71 | + $desc = $row; |
|
| 72 | + } |
|
| 73 | + } else // s'il n'existe pas deja, creer les identifiants |
|
| 74 | + { |
|
| 75 | + $desc = inscription_nouveau($desc); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // erreur ? |
|
| 79 | + if (!is_array($desc)) { |
|
| 80 | + return $desc; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 85 | + $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 86 | + |
|
| 87 | + // attribuer un jeton pour confirmation par clic sur un lien |
|
| 88 | + $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 89 | + |
|
| 90 | + // charger de suite cette fonction, pour ses utilitaires |
|
| 91 | + $envoyer_inscription = charger_fonction("envoyer_inscription", ""); |
|
| 92 | + list($sujet, $msg, $from, $head) = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 93 | + |
|
| 94 | + $notifications = charger_fonction('notifications', 'inc'); |
|
| 95 | + notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 96 | + |
|
| 97 | + // Notifications |
|
| 98 | + $notifications('inscription', $desc['id_auteur'], |
|
| 99 | + array('nom' => $desc['nom'], 'email' => $desc['email']) |
|
| 100 | + ); |
|
| 101 | + |
|
| 102 | + return $desc; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -122,23 +122,23 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | */ |
| 124 | 124 | function test_inscription_dist($statut, $mail, $nom, $options) { |
| 125 | - include_spip('inc/filtres'); |
|
| 126 | - if (!$r = email_valide($mail)) { |
|
| 127 | - return 'info_email_invalide'; |
|
| 128 | - } |
|
| 129 | - $nom = trim(corriger_caracteres($nom)); |
|
| 130 | - $res = array('email' => $r, 'nom' => $nom, 'prefs' => $statut); |
|
| 131 | - if (isset($options['login'])) { |
|
| 132 | - $login = trim(corriger_caracteres($options['login'])); |
|
| 133 | - if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) { |
|
| 134 | - $res['login'] = $login; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) { |
|
| 138 | - return 'ecrire:info_login_trop_court'; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $res; |
|
| 125 | + include_spip('inc/filtres'); |
|
| 126 | + if (!$r = email_valide($mail)) { |
|
| 127 | + return 'info_email_invalide'; |
|
| 128 | + } |
|
| 129 | + $nom = trim(corriger_caracteres($nom)); |
|
| 130 | + $res = array('email' => $r, 'nom' => $nom, 'prefs' => $statut); |
|
| 131 | + if (isset($options['login'])) { |
|
| 132 | + $login = trim(corriger_caracteres($options['login'])); |
|
| 133 | + if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) { |
|
| 134 | + $res['login'] = $login; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) { |
|
| 138 | + return 'ecrire:info_login_trop_court'; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $res; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
@@ -151,33 +151,33 @@ discard block |
||
| 151 | 151 | * @return mixed|string |
| 152 | 152 | */ |
| 153 | 153 | function inscription_nouveau($desc) { |
| 154 | - if (!isset($desc['login']) or !strlen($desc['login'])) { |
|
| 155 | - $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 156 | - } |
|
| 154 | + if (!isset($desc['login']) or !strlen($desc['login'])) { |
|
| 155 | + $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - $desc['statut'] = 'nouveau'; |
|
| 159 | - include_spip('action/editer_auteur'); |
|
| 160 | - if (isset($desc['id_auteur'])) { |
|
| 161 | - $id_auteur = $desc['id_auteur']; |
|
| 162 | - } else { |
|
| 163 | - $id_auteur = auteur_inserer(); |
|
| 164 | - } |
|
| 158 | + $desc['statut'] = 'nouveau'; |
|
| 159 | + include_spip('action/editer_auteur'); |
|
| 160 | + if (isset($desc['id_auteur'])) { |
|
| 161 | + $id_auteur = $desc['id_auteur']; |
|
| 162 | + } else { |
|
| 163 | + $id_auteur = auteur_inserer(); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - if (!$id_auteur) { |
|
| 167 | - return _T('titre_probleme_technique'); |
|
| 168 | - } |
|
| 166 | + if (!$id_auteur) { |
|
| 167 | + return _T('titre_probleme_technique'); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - $desc['lang'] = $GLOBALS['spip_lang']; |
|
| 170 | + $desc['lang'] = $GLOBALS['spip_lang']; |
|
| 171 | 171 | |
| 172 | - include_spip('inc/autoriser'); |
|
| 173 | - // lever l'autorisation pour pouvoir modifier le statut |
|
| 174 | - autoriser_exception('modifier', 'auteur', $id_auteur); |
|
| 175 | - auteur_modifier($id_auteur, $desc); |
|
| 176 | - autoriser_exception('modifier', 'auteur', $id_auteur, false); |
|
| 172 | + include_spip('inc/autoriser'); |
|
| 173 | + // lever l'autorisation pour pouvoir modifier le statut |
|
| 174 | + autoriser_exception('modifier', 'auteur', $id_auteur); |
|
| 175 | + auteur_modifier($id_auteur, $desc); |
|
| 176 | + autoriser_exception('modifier', 'auteur', $id_auteur, false); |
|
| 177 | 177 | |
| 178 | - $desc['id_auteur'] = $id_auteur; |
|
| 178 | + $desc['id_auteur'] = $id_auteur; |
|
| 179 | 179 | |
| 180 | - return $desc; |
|
| 180 | + return $desc; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
@@ -189,29 +189,29 @@ discard block |
||
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | 191 | function test_login($nom, $mail) { |
| 192 | - include_spip('inc/charsets'); |
|
| 193 | - $nom = strtolower(translitteration($nom)); |
|
| 194 | - $login_base = preg_replace("/[^\w\d_]/", "_", $nom); |
|
| 195 | - |
|
| 196 | - // il faut eviter que le login soit vraiment trop court |
|
| 197 | - if (strlen($login_base) < 3) { |
|
| 198 | - $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 199 | - $login_base = preg_replace("/[^\w\d]/", "_", $mail); |
|
| 200 | - } |
|
| 201 | - if (strlen($login_base) < 3) { |
|
| 202 | - $login_base = 'user'; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $login = $login_base; |
|
| 206 | - |
|
| 207 | - for ($i = 1; ; $i++) { |
|
| 208 | - if (!sql_countsel('spip_auteurs', "login='$login'")) { |
|
| 209 | - return $login; |
|
| 210 | - } |
|
| 211 | - $login = $login_base . $i; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return $login; |
|
| 192 | + include_spip('inc/charsets'); |
|
| 193 | + $nom = strtolower(translitteration($nom)); |
|
| 194 | + $login_base = preg_replace("/[^\w\d_]/", "_", $nom); |
|
| 195 | + |
|
| 196 | + // il faut eviter que le login soit vraiment trop court |
|
| 197 | + if (strlen($login_base) < 3) { |
|
| 198 | + $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 199 | + $login_base = preg_replace("/[^\w\d]/", "_", $mail); |
|
| 200 | + } |
|
| 201 | + if (strlen($login_base) < 3) { |
|
| 202 | + $login_base = 'user'; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $login = $login_base; |
|
| 206 | + |
|
| 207 | + for ($i = 1; ; $i++) { |
|
| 208 | + if (!sql_countsel('spip_auteurs', "login='$login'")) { |
|
| 209 | + return $login; |
|
| 210 | + } |
|
| 211 | + $login = $login_base . $i; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return $login; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | |
@@ -229,22 +229,22 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | function envoyer_inscription_dist($desc, $nom, $mode, $options = array()) { |
| 231 | 231 | |
| 232 | - $contexte = array_merge($desc, $options); |
|
| 233 | - $contexte['nom'] = $nom; |
|
| 234 | - $contexte['mode'] = $mode; |
|
| 235 | - $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true); |
|
| 236 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']); |
|
| 237 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
|
| 238 | - |
|
| 239 | - $modele_mail = 'modeles/mail_inscription'; |
|
| 240 | - if (isset($options['modele_mail']) and $options['modele_mail']){ |
|
| 241 | - $modele_mail = $options['modele_mail']; |
|
| 242 | - } |
|
| 243 | - $message = recuperer_fond($modele_mail, $contexte); |
|
| 244 | - $from = (isset($options['from']) ? $options['from'] : null); |
|
| 245 | - $head = null; |
|
| 246 | - |
|
| 247 | - return array("", $message, $from, $head); |
|
| 232 | + $contexte = array_merge($desc, $options); |
|
| 233 | + $contexte['nom'] = $nom; |
|
| 234 | + $contexte['mode'] = $mode; |
|
| 235 | + $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true); |
|
| 236 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']); |
|
| 237 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
|
| 238 | + |
|
| 239 | + $modele_mail = 'modeles/mail_inscription'; |
|
| 240 | + if (isset($options['modele_mail']) and $options['modele_mail']){ |
|
| 241 | + $modele_mail = $options['modele_mail']; |
|
| 242 | + } |
|
| 243 | + $message = recuperer_fond($modele_mail, $contexte); |
|
| 244 | + $from = (isset($options['from']) ? $options['from'] : null); |
|
| 245 | + $head = null; |
|
| 246 | + |
|
| 247 | + return array("", $message, $from, $head); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -255,12 +255,12 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function creer_pass_pour_auteur($id_auteur) { |
| 258 | - include_spip('inc/acces'); |
|
| 259 | - $pass = creer_pass_aleatoire(16, $id_auteur); |
|
| 260 | - include_spip('action/editer_auteur'); |
|
| 261 | - auteur_instituer($id_auteur, array('pass' => $pass)); |
|
| 258 | + include_spip('inc/acces'); |
|
| 259 | + $pass = creer_pass_aleatoire(16, $id_auteur); |
|
| 260 | + include_spip('action/editer_auteur'); |
|
| 261 | + auteur_instituer($id_auteur, array('pass' => $pass)); |
|
| 262 | 262 | |
| 263 | - return $pass; |
|
| 263 | + return $pass; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -273,17 +273,17 @@ discard block |
||
| 273 | 273 | * @return string |
| 274 | 274 | */ |
| 275 | 275 | function tester_statut_inscription($statut_tmp, $id) { |
| 276 | - include_spip('inc/autoriser'); |
|
| 277 | - if ($statut_tmp) { |
|
| 278 | - return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 279 | - } elseif ( |
|
| 280 | - autoriser('inscrireauteur', $statut_tmp = "1comite", $id) |
|
| 281 | - or autoriser('inscrireauteur', $statut_tmp = "6forum", $id) |
|
| 282 | - ) { |
|
| 283 | - return $statut_tmp; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - return ''; |
|
| 276 | + include_spip('inc/autoriser'); |
|
| 277 | + if ($statut_tmp) { |
|
| 278 | + return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 279 | + } elseif ( |
|
| 280 | + autoriser('inscrireauteur', $statut_tmp = "1comite", $id) |
|
| 281 | + or autoriser('inscrireauteur', $statut_tmp = "6forum", $id) |
|
| 282 | + ) { |
|
| 283 | + return $statut_tmp; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + return ''; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | |
@@ -297,35 +297,35 @@ discard block |
||
| 297 | 297 | * @return array |
| 298 | 298 | */ |
| 299 | 299 | function confirmer_statut_inscription($auteur) { |
| 300 | - // securite |
|
| 301 | - if ($auteur['statut'] != 'nouveau') { |
|
| 302 | - return $auteur; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $s = $auteur['prefs']; |
|
| 306 | - // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize) |
|
| 307 | - if (!preg_match(',^\w+$,', $s)) { |
|
| 308 | - $s = '6forum'; |
|
| 309 | - } |
|
| 310 | - include_spip('inc/autoriser'); |
|
| 311 | - if (!autoriser('inscrireauteur', $s)) { |
|
| 312 | - return $auteur; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - include_spip('inc/autoriser'); |
|
| 316 | - // accorder l'autorisation de modif du statut auteur |
|
| 317 | - autoriser_exception('modifier', 'auteur', $auteur['id_auteur']); |
|
| 318 | - include_spip('action/editer_auteur'); |
|
| 319 | - // changer le statut |
|
| 320 | - auteur_modifier($auteur['id_auteur'], array('statut' => $s)); |
|
| 321 | - unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 322 | - // lever l'autorisation de modif du statut auteur |
|
| 323 | - autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false); |
|
| 324 | - |
|
| 325 | - // mettre a jour le statut |
|
| 326 | - $auteur['statut'] = $s; |
|
| 327 | - |
|
| 328 | - return $auteur; |
|
| 300 | + // securite |
|
| 301 | + if ($auteur['statut'] != 'nouveau') { |
|
| 302 | + return $auteur; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $s = $auteur['prefs']; |
|
| 306 | + // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize) |
|
| 307 | + if (!preg_match(',^\w+$,', $s)) { |
|
| 308 | + $s = '6forum'; |
|
| 309 | + } |
|
| 310 | + include_spip('inc/autoriser'); |
|
| 311 | + if (!autoriser('inscrireauteur', $s)) { |
|
| 312 | + return $auteur; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + include_spip('inc/autoriser'); |
|
| 316 | + // accorder l'autorisation de modif du statut auteur |
|
| 317 | + autoriser_exception('modifier', 'auteur', $auteur['id_auteur']); |
|
| 318 | + include_spip('action/editer_auteur'); |
|
| 319 | + // changer le statut |
|
| 320 | + auteur_modifier($auteur['id_auteur'], array('statut' => $s)); |
|
| 321 | + unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 322 | + // lever l'autorisation de modif du statut auteur |
|
| 323 | + autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false); |
|
| 324 | + |
|
| 325 | + // mettre a jour le statut |
|
| 326 | + $auteur['statut'] = $s; |
|
| 327 | + |
|
| 328 | + return $auteur; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -337,14 +337,14 @@ discard block |
||
| 337 | 337 | * @return string |
| 338 | 338 | */ |
| 339 | 339 | function auteur_attribuer_jeton($id_auteur) { |
| 340 | - include_spip('inc/acces'); |
|
| 341 | - // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 342 | - do { |
|
| 343 | - $jeton = creer_uniqid(); |
|
| 344 | - sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=" . intval($id_auteur)); |
|
| 345 | - } while (sql_countsel("spip_auteurs", "cookie_oubli=" . sql_quote($jeton)) > 1); |
|
| 346 | - |
|
| 347 | - return $jeton; |
|
| 340 | + include_spip('inc/acces'); |
|
| 341 | + // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 342 | + do { |
|
| 343 | + $jeton = creer_uniqid(); |
|
| 344 | + sql_updateq("spip_auteurs", array("cookie_oubli" => $jeton), "id_auteur=" . intval($id_auteur)); |
|
| 345 | + } while (sql_countsel("spip_auteurs", "cookie_oubli=" . sql_quote($jeton)) > 1); |
|
| 346 | + |
|
| 347 | + return $jeton; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -354,15 +354,15 @@ discard block |
||
| 354 | 354 | * @return array|bool |
| 355 | 355 | */ |
| 356 | 356 | function auteur_verifier_jeton($jeton) { |
| 357 | - // refuser un jeton corrompu |
|
| 358 | - if (preg_match(',[^0-9a-f.],i', $jeton)) { |
|
| 359 | - return false; |
|
| 360 | - } |
|
| 357 | + // refuser un jeton corrompu |
|
| 358 | + if (preg_match(',[^0-9a-f.],i', $jeton)) { |
|
| 359 | + return false; |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - // on peut tomber sur un jeton compose uniquement de chiffres, il faut forcer le $type pour sql_quote pour eviter de planter |
|
| 363 | - $desc = sql_fetsel('*', 'spip_auteurs', "cookie_oubli=" . sql_quote($jeton, '', 'string')); |
|
| 362 | + // on peut tomber sur un jeton compose uniquement de chiffres, il faut forcer le $type pour sql_quote pour eviter de planter |
|
| 363 | + $desc = sql_fetsel('*', 'spip_auteurs', "cookie_oubli=" . sql_quote($jeton, '', 'string')); |
|
| 364 | 364 | |
| 365 | - return $desc; |
|
| 365 | + return $desc; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | /** |
@@ -372,5 +372,5 @@ discard block |
||
| 372 | 372 | * @return bool |
| 373 | 373 | */ |
| 374 | 374 | function auteur_effacer_jeton($id_auteur) { |
| 375 | - return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur)); |
|
| 375 | + return sql_updateq("spip_auteurs", array("cookie_oubli" => ''), "id_auteur=" . intval($id_auteur)); |
|
| 376 | 376 | } |