@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | 29 | function generer_nom_fichier_cache($contexte, $page) { |
| 30 | - $u = md5(var_export(array($contexte, $page), true)); |
|
| 30 | + $u = md5(var_export(array($contexte, $page), true)); |
|
| 31 | 31 | |
| 32 | - return $u . ".cache"; |
|
| 32 | + return $u . ".cache"; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | * @return bool |
| 41 | 41 | */ |
| 42 | 42 | function ecrire_cache($nom_cache, $valeur) { |
| 43 | - $d = substr($nom_cache, 0, 2); |
|
| 44 | - $u = substr($nom_cache, 2, 2); |
|
| 45 | - $rep = _DIR_CACHE; |
|
| 46 | - $rep = sous_repertoire($rep, '', false, true); |
|
| 47 | - $rep = sous_repertoire($rep, $d, false, true); |
|
| 43 | + $d = substr($nom_cache, 0, 2); |
|
| 44 | + $u = substr($nom_cache, 2, 2); |
|
| 45 | + $rep = _DIR_CACHE; |
|
| 46 | + $rep = sous_repertoire($rep, '', false, true); |
|
| 47 | + $rep = sous_repertoire($rep, $d, false, true); |
|
| 48 | 48 | |
| 49 | - return ecrire_fichier($rep . $u . ".cache", serialize(array("nom_cache" => $nom_cache, "valeur" => $valeur))); |
|
| 49 | + return ecrire_fichier($rep . $u . ".cache", serialize(array("nom_cache" => $nom_cache, "valeur" => $valeur))); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -56,31 +56,31 @@ discard block |
||
| 56 | 56 | * @return mixed |
| 57 | 57 | */ |
| 58 | 58 | function lire_cache($nom_cache) { |
| 59 | - $d = substr($nom_cache, 0, 2); |
|
| 60 | - $u = substr($nom_cache, 2, 2); |
|
| 61 | - if (file_exists($f = _DIR_CACHE . "$d/$u.cache") |
|
| 62 | - and lire_fichier($f, $tmp) |
|
| 63 | - and $tmp = unserialize($tmp) |
|
| 64 | - and $tmp['nom_cache'] == $nom_cache |
|
| 65 | - and isset($tmp['valeur']) |
|
| 66 | - ) { |
|
| 67 | - return $tmp['valeur']; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return false; |
|
| 59 | + $d = substr($nom_cache, 0, 2); |
|
| 60 | + $u = substr($nom_cache, 2, 2); |
|
| 61 | + if (file_exists($f = _DIR_CACHE . "$d/$u.cache") |
|
| 62 | + and lire_fichier($f, $tmp) |
|
| 63 | + and $tmp = unserialize($tmp) |
|
| 64 | + and $tmp['nom_cache'] == $nom_cache |
|
| 65 | + and isset($tmp['valeur']) |
|
| 66 | + ) { |
|
| 67 | + return $tmp['valeur']; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return false; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // Parano : on signe le cache, afin d'interdire un hack d'injection |
| 74 | 74 | // dans notre memcache |
| 75 | 75 | function cache_signature(&$page) { |
| 76 | - if (!isset($GLOBALS['meta']['cache_signature'])) { |
|
| 77 | - include_spip('inc/acces'); |
|
| 78 | - include_spip('auth/sha256.inc'); |
|
| 79 | - ecrire_meta('cache_signature', |
|
| 80 | - spip_sha256($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SERVER_SIGNATURE"] . creer_uniqid()), 'non'); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 76 | + if (!isset($GLOBALS['meta']['cache_signature'])) { |
|
| 77 | + include_spip('inc/acces'); |
|
| 78 | + include_spip('auth/sha256.inc'); |
|
| 79 | + ecrire_meta('cache_signature', |
|
| 80 | + spip_sha256($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SERVER_SIGNATURE"] . creer_uniqid()), 'non'); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | 96 | function gzip_page($page) { |
| 97 | - if (function_exists('gzcompress') and strlen($page['texte']) > 16 * 1024) { |
|
| 98 | - $page['gz'] = true; |
|
| 99 | - $page['texte'] = gzcompress($page['texte']); |
|
| 100 | - } else { |
|
| 101 | - $page['gz'] = false; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return $page; |
|
| 97 | + if (function_exists('gzcompress') and strlen($page['texte']) > 16 * 1024) { |
|
| 98 | + $page['gz'] = true; |
|
| 99 | + $page['texte'] = gzcompress($page['texte']); |
|
| 100 | + } else { |
|
| 101 | + $page['gz'] = false; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return $page; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -116,10 +116,10 @@ discard block |
||
| 116 | 116 | * @return void |
| 117 | 117 | */ |
| 118 | 118 | function gunzip_page(&$page) { |
| 119 | - if ($page['gz']) { |
|
| 120 | - $page['texte'] = gzuncompress($page['texte']); |
|
| 121 | - $page['gz'] = false; // ne pas gzuncompress deux fois une meme page |
|
| 122 | - } |
|
| 119 | + if ($page['gz']) { |
|
| 120 | + $page['texte'] = gzuncompress($page['texte']); |
|
| 121 | + $page['gz'] = false; // ne pas gzuncompress deux fois une meme page |
|
| 122 | + } |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -135,72 +135,72 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | /// http://code.spip.net/@cache_valide |
| 137 | 137 | function cache_valide(&$page, $date) { |
| 138 | - $now = $_SERVER['REQUEST_TIME']; |
|
| 139 | - |
|
| 140 | - // Apparition d'un nouvel article post-date ? |
|
| 141 | - if (isset($GLOBALS['meta']['post_dates']) |
|
| 142 | - and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 143 | - and isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 144 | - and $now > $GLOBALS['meta']['date_prochain_postdate'] |
|
| 145 | - ) { |
|
| 146 | - spip_log('Un article post-date invalide le cache'); |
|
| 147 | - include_spip('inc/rubriques'); |
|
| 148 | - calculer_prochain_postdate(true); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (defined('_VAR_NOCACHE') and _VAR_NOCACHE) { |
|
| 152 | - return -1; |
|
| 153 | - } |
|
| 154 | - if (isset($GLOBALS['meta']['cache_inhib']) and $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) { |
|
| 155 | - return -1; |
|
| 156 | - } |
|
| 157 | - if (defined('_NO_CACHE')) { |
|
| 158 | - return (_NO_CACHE == 0 and !isset($page['texte'])) ? 1 : _NO_CACHE; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache) |
|
| 162 | - if (!$page or !isset($page['texte']) or !isset($page['entetes']['X-Spip-Cache'])) { |
|
| 163 | - return _IS_BOT ? -1 : 1; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // controle de la signature |
|
| 167 | - if ($page['sig'] !== cache_signature($page)) { |
|
| 168 | - return _IS_BOT ? -1 : 1; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // #CACHE{n,statique} => on n'invalide pas avec derniere_modif |
|
| 172 | - // cf. ecrire/public/balises.php, balise_CACHE_dist() |
|
| 173 | - if (!isset($page['entetes']['X-Spip-Statique']) or $page['entetes']['X-Spip-Statique'] !== 'oui') { |
|
| 174 | - |
|
| 175 | - // Cache invalide par la meta 'derniere_modif' |
|
| 176 | - // sauf pour les bots, qui utilisent toujours le cache |
|
| 177 | - if (!_IS_BOT |
|
| 178 | - and $GLOBALS['derniere_modif_invalide'] |
|
| 179 | - and isset($GLOBALS['meta']['derniere_modif']) |
|
| 180 | - and $date < $GLOBALS['meta']['derniere_modif'] |
|
| 181 | - ) { |
|
| 182 | - return 1; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - // Sinon comparer l'age du fichier a sa duree de cache |
|
| 188 | - $duree = intval($page['entetes']['X-Spip-Cache']); |
|
| 189 | - $cache_mark = (isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0); |
|
| 190 | - if ($duree == 0) #CACHE{0} |
|
| 191 | - { |
|
| 192 | - return -1; |
|
| 193 | - } // sauf pour les bots, qui utilisent toujours le cache |
|
| 194 | - else { |
|
| 195 | - if ((!_IS_BOT and $date + $duree < $now) |
|
| 196 | - # le cache est anterieur a la derniere purge : l'ignorer, meme pour les bots |
|
| 197 | - or $date < $cache_mark |
|
| 198 | - ) { |
|
| 199 | - return _IS_BOT ? -1 : 1; |
|
| 200 | - } else { |
|
| 201 | - return 0; |
|
| 202 | - } |
|
| 203 | - } |
|
| 138 | + $now = $_SERVER['REQUEST_TIME']; |
|
| 139 | + |
|
| 140 | + // Apparition d'un nouvel article post-date ? |
|
| 141 | + if (isset($GLOBALS['meta']['post_dates']) |
|
| 142 | + and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 143 | + and isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 144 | + and $now > $GLOBALS['meta']['date_prochain_postdate'] |
|
| 145 | + ) { |
|
| 146 | + spip_log('Un article post-date invalide le cache'); |
|
| 147 | + include_spip('inc/rubriques'); |
|
| 148 | + calculer_prochain_postdate(true); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if (defined('_VAR_NOCACHE') and _VAR_NOCACHE) { |
|
| 152 | + return -1; |
|
| 153 | + } |
|
| 154 | + if (isset($GLOBALS['meta']['cache_inhib']) and $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) { |
|
| 155 | + return -1; |
|
| 156 | + } |
|
| 157 | + if (defined('_NO_CACHE')) { |
|
| 158 | + return (_NO_CACHE == 0 and !isset($page['texte'])) ? 1 : _NO_CACHE; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache) |
|
| 162 | + if (!$page or !isset($page['texte']) or !isset($page['entetes']['X-Spip-Cache'])) { |
|
| 163 | + return _IS_BOT ? -1 : 1; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // controle de la signature |
|
| 167 | + if ($page['sig'] !== cache_signature($page)) { |
|
| 168 | + return _IS_BOT ? -1 : 1; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // #CACHE{n,statique} => on n'invalide pas avec derniere_modif |
|
| 172 | + // cf. ecrire/public/balises.php, balise_CACHE_dist() |
|
| 173 | + if (!isset($page['entetes']['X-Spip-Statique']) or $page['entetes']['X-Spip-Statique'] !== 'oui') { |
|
| 174 | + |
|
| 175 | + // Cache invalide par la meta 'derniere_modif' |
|
| 176 | + // sauf pour les bots, qui utilisent toujours le cache |
|
| 177 | + if (!_IS_BOT |
|
| 178 | + and $GLOBALS['derniere_modif_invalide'] |
|
| 179 | + and isset($GLOBALS['meta']['derniere_modif']) |
|
| 180 | + and $date < $GLOBALS['meta']['derniere_modif'] |
|
| 181 | + ) { |
|
| 182 | + return 1; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + // Sinon comparer l'age du fichier a sa duree de cache |
|
| 188 | + $duree = intval($page['entetes']['X-Spip-Cache']); |
|
| 189 | + $cache_mark = (isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0); |
|
| 190 | + if ($duree == 0) #CACHE{0} |
|
| 191 | + { |
|
| 192 | + return -1; |
|
| 193 | + } // sauf pour les bots, qui utilisent toujours le cache |
|
| 194 | + else { |
|
| 195 | + if ((!_IS_BOT and $date + $duree < $now) |
|
| 196 | + # le cache est anterieur a la derniere purge : l'ignorer, meme pour les bots |
|
| 197 | + or $date < $cache_mark |
|
| 198 | + ) { |
|
| 199 | + return _IS_BOT ? -1 : 1; |
|
| 200 | + } else { |
|
| 201 | + return 0; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -215,55 +215,55 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | function creer_cache(&$page, &$chemin_cache) { |
| 217 | 217 | |
| 218 | - // Ne rien faire si on est en preview, debug, ou si une erreur |
|
| 219 | - // grave s'est presentee (compilation du squelette, MySQL, etc) |
|
| 220 | - // le cas var_nocache ne devrait jamais arriver ici (securite) |
|
| 221 | - // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable |
|
| 222 | - if ((defined('_VAR_NOCACHE') and _VAR_NOCACHE) |
|
| 223 | - or defined('spip_interdire_cache') |
|
| 224 | - ) { |
|
| 225 | - return; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // Si la page c1234 a un invalideur de session 'zz', sauver dans |
|
| 229 | - // 'tmp/cache/MD5(chemin_cache)_zz' |
|
| 230 | - if (isset($page['invalideurs']) |
|
| 231 | - and isset($page['invalideurs']['session']) |
|
| 232 | - ) { |
|
| 233 | - // on verifie que le contenu du chemin cache indique seulement |
|
| 234 | - // "cache sessionne" ; sa date indique la date de validite |
|
| 235 | - // des caches sessionnes |
|
| 236 | - if (!$tmp = lire_cache($chemin_cache)) { |
|
| 237 | - spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 238 | - $tmp = array( |
|
| 239 | - 'invalideurs' => array('session' => ''), |
|
| 240 | - 'lastmodified' => $_SERVER['REQUEST_TIME'] |
|
| 241 | - ); |
|
| 242 | - ecrire_cache($chemin_cache, $tmp); |
|
| 243 | - } |
|
| 244 | - $chemin_cache = generer_nom_fichier_cache(array("chemin_cache" => $chemin_cache), |
|
| 245 | - array("session" => $page['invalideurs']['session'])); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // ajouter la date de production dans le cache lui meme |
|
| 249 | - // (qui contient deja sa duree de validite) |
|
| 250 | - $page['lastmodified'] = $_SERVER['REQUEST_TIME']; |
|
| 251 | - |
|
| 252 | - // compresser le contenu si besoin |
|
| 253 | - $pagez = gzip_page($page); |
|
| 254 | - |
|
| 255 | - // signer le contenu |
|
| 256 | - $pagez['sig'] = cache_signature($pagez); |
|
| 257 | - |
|
| 258 | - // l'enregistrer, compresse ou non... |
|
| 259 | - $ok = ecrire_cache($chemin_cache, $pagez); |
|
| 260 | - |
|
| 261 | - spip_log((_IS_BOT ? "Bot:" : "") . "Creation du cache $chemin_cache pour " |
|
| 262 | - . $page['entetes']['X-Spip-Cache'] . " secondes" . ($ok ? '' : ' (erreur!)'), _LOG_INFO_IMPORTANTE); |
|
| 263 | - |
|
| 264 | - // Inserer ses invalideurs |
|
| 265 | - include_spip('inc/invalideur'); |
|
| 266 | - maj_invalideurs($chemin_cache, $page); |
|
| 218 | + // Ne rien faire si on est en preview, debug, ou si une erreur |
|
| 219 | + // grave s'est presentee (compilation du squelette, MySQL, etc) |
|
| 220 | + // le cas var_nocache ne devrait jamais arriver ici (securite) |
|
| 221 | + // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable |
|
| 222 | + if ((defined('_VAR_NOCACHE') and _VAR_NOCACHE) |
|
| 223 | + or defined('spip_interdire_cache') |
|
| 224 | + ) { |
|
| 225 | + return; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // Si la page c1234 a un invalideur de session 'zz', sauver dans |
|
| 229 | + // 'tmp/cache/MD5(chemin_cache)_zz' |
|
| 230 | + if (isset($page['invalideurs']) |
|
| 231 | + and isset($page['invalideurs']['session']) |
|
| 232 | + ) { |
|
| 233 | + // on verifie que le contenu du chemin cache indique seulement |
|
| 234 | + // "cache sessionne" ; sa date indique la date de validite |
|
| 235 | + // des caches sessionnes |
|
| 236 | + if (!$tmp = lire_cache($chemin_cache)) { |
|
| 237 | + spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 238 | + $tmp = array( |
|
| 239 | + 'invalideurs' => array('session' => ''), |
|
| 240 | + 'lastmodified' => $_SERVER['REQUEST_TIME'] |
|
| 241 | + ); |
|
| 242 | + ecrire_cache($chemin_cache, $tmp); |
|
| 243 | + } |
|
| 244 | + $chemin_cache = generer_nom_fichier_cache(array("chemin_cache" => $chemin_cache), |
|
| 245 | + array("session" => $page['invalideurs']['session'])); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // ajouter la date de production dans le cache lui meme |
|
| 249 | + // (qui contient deja sa duree de validite) |
|
| 250 | + $page['lastmodified'] = $_SERVER['REQUEST_TIME']; |
|
| 251 | + |
|
| 252 | + // compresser le contenu si besoin |
|
| 253 | + $pagez = gzip_page($page); |
|
| 254 | + |
|
| 255 | + // signer le contenu |
|
| 256 | + $pagez['sig'] = cache_signature($pagez); |
|
| 257 | + |
|
| 258 | + // l'enregistrer, compresse ou non... |
|
| 259 | + $ok = ecrire_cache($chemin_cache, $pagez); |
|
| 260 | + |
|
| 261 | + spip_log((_IS_BOT ? "Bot:" : "") . "Creation du cache $chemin_cache pour " |
|
| 262 | + . $page['entetes']['X-Spip-Cache'] . " secondes" . ($ok ? '' : ' (erreur!)'), _LOG_INFO_IMPORTANTE); |
|
| 263 | + |
|
| 264 | + // Inserer ses invalideurs |
|
| 265 | + include_spip('inc/invalideur'); |
|
| 266 | + maj_invalideurs($chemin_cache, $page); |
|
| 267 | 267 | |
| 268 | 268 | } |
| 269 | 269 | |
@@ -279,15 +279,15 @@ discard block |
||
| 279 | 279 | * @return void |
| 280 | 280 | */ |
| 281 | 281 | function nettoyer_petit_cache($prefix, $duree = 300) { |
| 282 | - // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
|
| 283 | - $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
|
| 284 | - if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 285 | - foreach (preg_files($dircache, '[.]txt$') as $f) { |
|
| 286 | - if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
|
| 287 | - spip_unlink($f); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 282 | + // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
|
| 283 | + $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
|
| 284 | + if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 285 | + foreach (preg_files($dircache, '[.]txt$') as $f) { |
|
| 286 | + if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
|
| 287 | + spip_unlink($f); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | |
@@ -317,126 +317,126 @@ discard block |
||
| 317 | 317 | */ |
| 318 | 318 | function public_cacher_dist($contexte, &$use_cache, &$chemin_cache, &$page, &$lastmodified) { |
| 319 | 319 | |
| 320 | - # fonction de cache minimale : dire "non on ne met rien en cache" |
|
| 321 | - # $use_cache = -1; return; |
|
| 322 | - |
|
| 323 | - // Second appel, destine a l'enregistrement du cache sur le disque |
|
| 324 | - if (isset($chemin_cache)) { |
|
| 325 | - return creer_cache($page, $chemin_cache); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - // Toute la suite correspond au premier appel |
|
| 329 | - $contexte_implicite = $page['contexte_implicite']; |
|
| 330 | - |
|
| 331 | - // Cas ignorant le cache car completement dynamique |
|
| 332 | - if ($_SERVER['REQUEST_METHOD'] == 'POST' |
|
| 333 | - or _request('connect') |
|
| 334 | - ) { |
|
| 335 | - $use_cache = -1; |
|
| 336 | - $lastmodified = 0; |
|
| 337 | - $chemin_cache = ""; |
|
| 338 | - $page = array(); |
|
| 339 | - |
|
| 340 | - return; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // Controler l'existence d'un cache nous correspondant |
|
| 344 | - $chemin_cache = generer_nom_fichier_cache($contexte, $page); |
|
| 345 | - $lastmodified = 0; |
|
| 346 | - |
|
| 347 | - // charger le cache s'il existe (et si il a bien le bon hash = anticollision) |
|
| 348 | - if (!$page = lire_cache($chemin_cache)) { |
|
| 349 | - $page = array(); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - // s'il est sessionne, charger celui correspondant a notre session |
|
| 353 | - if (isset($page['invalideurs']) |
|
| 354 | - and isset($page['invalideurs']['session']) |
|
| 355 | - ) { |
|
| 356 | - $chemin_cache_session = generer_nom_fichier_cache(array("chemin_cache" => $chemin_cache), |
|
| 357 | - array("session" => spip_session())); |
|
| 358 | - if ($page_session = lire_cache($chemin_cache_session) |
|
| 359 | - and $page_session['lastmodified'] >= $page['lastmodified'] |
|
| 360 | - ) { |
|
| 361 | - $page = $page_session; |
|
| 362 | - } else { |
|
| 363 | - $page = array(); |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ? |
|
| 369 | - if (isset($GLOBALS['meta']['invalider'])) { |
|
| 370 | - // ne le faire que si la base est disponible |
|
| 371 | - if (spip_connect()) { |
|
| 372 | - include_spip('inc/invalideur'); |
|
| 373 | - retire_caches($chemin_cache); # API invalideur inutile |
|
| 374 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 375 | - if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 376 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande, |
|
| 382 | - // on supprime le cache |
|
| 383 | - if (defined('_VAR_MODE') && _VAR_MODE && |
|
| 384 | - (isset($_COOKIE['spip_session']) |
|
| 385 | - || isset($_COOKIE['spip_admin']) |
|
| 386 | - || @file_exists(_ACCESS_FILE_NAME)) |
|
| 387 | - ) { |
|
| 388 | - $page = array('contexte_implicite' => $contexte_implicite); // ignorer le cache deja lu |
|
| 389 | - include_spip('inc/invalideur'); |
|
| 390 | - retire_caches($chemin_cache); # API invalideur inutile |
|
| 391 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 392 | - if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 393 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - // $delais par defaut |
|
| 398 | - // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé |
|
| 399 | - // qui sont a cache nul par defaut |
|
| 400 | - if (!isset($GLOBALS['delais'])) { |
|
| 401 | - if (!defined('_DUREE_CACHE_DEFAUT')) { |
|
| 402 | - define('_DUREE_CACHE_DEFAUT', 24 * 3600); |
|
| 403 | - } |
|
| 404 | - $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - // determiner la validite de la page |
|
| 408 | - if ($page) { |
|
| 409 | - $use_cache = cache_valide($page, isset($page['lastmodified']) ? $page['lastmodified'] : 0); |
|
| 410 | - // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence |
|
| 411 | - // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul |
|
| 412 | - $page['contexte_implicite'] = $contexte_implicite; |
|
| 413 | - if (!$use_cache) { |
|
| 414 | - // $page est un cache utilisable |
|
| 415 | - gunzip_page($page); |
|
| 416 | - |
|
| 417 | - return; |
|
| 418 | - } |
|
| 419 | - } else { |
|
| 420 | - $page = array('contexte_implicite' => $contexte_implicite); |
|
| 421 | - $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - // Si pas valide mais pas de connexion a la base, le garder quand meme |
|
| 425 | - if (!spip_connect()) { |
|
| 426 | - if (isset($page['texte'])) { |
|
| 427 | - gunzip_page($page); |
|
| 428 | - $use_cache = 0; |
|
| 429 | - } else { |
|
| 430 | - spip_log("Erreur base de donnees, impossible utiliser $chemin_cache"); |
|
| 431 | - include_spip('inc/minipres'); |
|
| 432 | - |
|
| 433 | - return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503)); |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - if ($use_cache < 0) { |
|
| 438 | - $chemin_cache = ''; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - return; |
|
| 320 | + # fonction de cache minimale : dire "non on ne met rien en cache" |
|
| 321 | + # $use_cache = -1; return; |
|
| 322 | + |
|
| 323 | + // Second appel, destine a l'enregistrement du cache sur le disque |
|
| 324 | + if (isset($chemin_cache)) { |
|
| 325 | + return creer_cache($page, $chemin_cache); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + // Toute la suite correspond au premier appel |
|
| 329 | + $contexte_implicite = $page['contexte_implicite']; |
|
| 330 | + |
|
| 331 | + // Cas ignorant le cache car completement dynamique |
|
| 332 | + if ($_SERVER['REQUEST_METHOD'] == 'POST' |
|
| 333 | + or _request('connect') |
|
| 334 | + ) { |
|
| 335 | + $use_cache = -1; |
|
| 336 | + $lastmodified = 0; |
|
| 337 | + $chemin_cache = ""; |
|
| 338 | + $page = array(); |
|
| 339 | + |
|
| 340 | + return; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // Controler l'existence d'un cache nous correspondant |
|
| 344 | + $chemin_cache = generer_nom_fichier_cache($contexte, $page); |
|
| 345 | + $lastmodified = 0; |
|
| 346 | + |
|
| 347 | + // charger le cache s'il existe (et si il a bien le bon hash = anticollision) |
|
| 348 | + if (!$page = lire_cache($chemin_cache)) { |
|
| 349 | + $page = array(); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + // s'il est sessionne, charger celui correspondant a notre session |
|
| 353 | + if (isset($page['invalideurs']) |
|
| 354 | + and isset($page['invalideurs']['session']) |
|
| 355 | + ) { |
|
| 356 | + $chemin_cache_session = generer_nom_fichier_cache(array("chemin_cache" => $chemin_cache), |
|
| 357 | + array("session" => spip_session())); |
|
| 358 | + if ($page_session = lire_cache($chemin_cache_session) |
|
| 359 | + and $page_session['lastmodified'] >= $page['lastmodified'] |
|
| 360 | + ) { |
|
| 361 | + $page = $page_session; |
|
| 362 | + } else { |
|
| 363 | + $page = array(); |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ? |
|
| 369 | + if (isset($GLOBALS['meta']['invalider'])) { |
|
| 370 | + // ne le faire que si la base est disponible |
|
| 371 | + if (spip_connect()) { |
|
| 372 | + include_spip('inc/invalideur'); |
|
| 373 | + retire_caches($chemin_cache); # API invalideur inutile |
|
| 374 | + supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 375 | + if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 376 | + supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande, |
|
| 382 | + // on supprime le cache |
|
| 383 | + if (defined('_VAR_MODE') && _VAR_MODE && |
|
| 384 | + (isset($_COOKIE['spip_session']) |
|
| 385 | + || isset($_COOKIE['spip_admin']) |
|
| 386 | + || @file_exists(_ACCESS_FILE_NAME)) |
|
| 387 | + ) { |
|
| 388 | + $page = array('contexte_implicite' => $contexte_implicite); // ignorer le cache deja lu |
|
| 389 | + include_spip('inc/invalideur'); |
|
| 390 | + retire_caches($chemin_cache); # API invalideur inutile |
|
| 391 | + supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 392 | + if (isset($chemin_cache_session) and $chemin_cache_session) { |
|
| 393 | + supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + // $delais par defaut |
|
| 398 | + // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé |
|
| 399 | + // qui sont a cache nul par defaut |
|
| 400 | + if (!isset($GLOBALS['delais'])) { |
|
| 401 | + if (!defined('_DUREE_CACHE_DEFAUT')) { |
|
| 402 | + define('_DUREE_CACHE_DEFAUT', 24 * 3600); |
|
| 403 | + } |
|
| 404 | + $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + // determiner la validite de la page |
|
| 408 | + if ($page) { |
|
| 409 | + $use_cache = cache_valide($page, isset($page['lastmodified']) ? $page['lastmodified'] : 0); |
|
| 410 | + // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence |
|
| 411 | + // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul |
|
| 412 | + $page['contexte_implicite'] = $contexte_implicite; |
|
| 413 | + if (!$use_cache) { |
|
| 414 | + // $page est un cache utilisable |
|
| 415 | + gunzip_page($page); |
|
| 416 | + |
|
| 417 | + return; |
|
| 418 | + } |
|
| 419 | + } else { |
|
| 420 | + $page = array('contexte_implicite' => $contexte_implicite); |
|
| 421 | + $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + // Si pas valide mais pas de connexion a la base, le garder quand meme |
|
| 425 | + if (!spip_connect()) { |
|
| 426 | + if (isset($page['texte'])) { |
|
| 427 | + gunzip_page($page); |
|
| 428 | + $use_cache = 0; |
|
| 429 | + } else { |
|
| 430 | + spip_log("Erreur base de donnees, impossible utiliser $chemin_cache"); |
|
| 431 | + include_spip('inc/minipres'); |
|
| 432 | + |
|
| 433 | + return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503)); |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + if ($use_cache < 0) { |
|
| 438 | + $chemin_cache = ''; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + return; |
|
| 442 | 442 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | function generer_nom_fichier_cache($contexte, $page) { |
| 30 | 30 | $u = md5(var_export(array($contexte, $page), true)); |
| 31 | 31 | |
| 32 | - return $u . ".cache"; |
|
| 32 | + return $u.".cache"; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $rep = sous_repertoire($rep, '', false, true); |
| 47 | 47 | $rep = sous_repertoire($rep, $d, false, true); |
| 48 | 48 | |
| 49 | - return ecrire_fichier($rep . $u . ".cache", serialize(array("nom_cache" => $nom_cache, "valeur" => $valeur))); |
|
| 49 | + return ecrire_fichier($rep.$u.".cache", serialize(array("nom_cache" => $nom_cache, "valeur" => $valeur))); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | function lire_cache($nom_cache) { |
| 59 | 59 | $d = substr($nom_cache, 0, 2); |
| 60 | 60 | $u = substr($nom_cache, 2, 2); |
| 61 | - if (file_exists($f = _DIR_CACHE . "$d/$u.cache") |
|
| 61 | + if (file_exists($f = _DIR_CACHE."$d/$u.cache") |
|
| 62 | 62 | and lire_fichier($f, $tmp) |
| 63 | 63 | and $tmp = unserialize($tmp) |
| 64 | 64 | and $tmp['nom_cache'] == $nom_cache |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | include_spip('inc/acces'); |
| 78 | 78 | include_spip('auth/sha256.inc'); |
| 79 | 79 | ecrire_meta('cache_signature', |
| 80 | - spip_sha256($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SERVER_SIGNATURE"] . creer_uniqid()), 'non'); |
|
| 80 | + spip_sha256($_SERVER["DOCUMENT_ROOT"].$_SERVER["SERVER_SIGNATURE"].creer_uniqid()), 'non'); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 83 | + return crc32($GLOBALS['meta']['cache_signature'].$page['texte']); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | // "cache sessionne" ; sa date indique la date de validite |
| 235 | 235 | // des caches sessionnes |
| 236 | 236 | if (!$tmp = lire_cache($chemin_cache)) { |
| 237 | - spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 237 | + spip_log('Creation cache sessionne '.$chemin_cache); |
|
| 238 | 238 | $tmp = array( |
| 239 | 239 | 'invalideurs' => array('session' => ''), |
| 240 | 240 | 'lastmodified' => $_SERVER['REQUEST_TIME'] |
@@ -258,8 +258,8 @@ discard block |
||
| 258 | 258 | // l'enregistrer, compresse ou non... |
| 259 | 259 | $ok = ecrire_cache($chemin_cache, $pagez); |
| 260 | 260 | |
| 261 | - spip_log((_IS_BOT ? "Bot:" : "") . "Creation du cache $chemin_cache pour " |
|
| 262 | - . $page['entetes']['X-Spip-Cache'] . " secondes" . ($ok ? '' : ' (erreur!)'), _LOG_INFO_IMPORTANTE); |
|
| 261 | + spip_log((_IS_BOT ? "Bot:" : "")."Creation du cache $chemin_cache pour " |
|
| 262 | + . $page['entetes']['X-Spip-Cache']." secondes".($ok ? '' : ' (erreur!)'), _LOG_INFO_IMPORTANTE); |
|
| 263 | 263 | |
| 264 | 264 | // Inserer ses invalideurs |
| 265 | 265 | include_spip('inc/invalideur'); |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | function nettoyer_petit_cache($prefix, $duree = 300) { |
| 282 | 282 | // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
| 283 | 283 | $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
| 284 | - if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 284 | + if (spip_touch($dircache.'purger_'.$prefix, $duree, true)) { |
|
| 285 | 285 | foreach (preg_files($dircache, '[.]txt$') as $f) { |
| 286 | 286 | if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
| 287 | 287 | spip_unlink($f); |
@@ -371,9 +371,9 @@ discard block |
||
| 371 | 371 | if (spip_connect()) { |
| 372 | 372 | include_spip('inc/invalideur'); |
| 373 | 373 | retire_caches($chemin_cache); # API invalideur inutile |
| 374 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 374 | + supprimer_fichier(_DIR_CACHE.$chemin_cache); |
|
| 375 | 375 | if (isset($chemin_cache_session) and $chemin_cache_session) { |
| 376 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 376 | + supprimer_fichier(_DIR_CACHE.$chemin_cache_session); |
|
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | } |
@@ -388,9 +388,9 @@ discard block |
||
| 388 | 388 | $page = array('contexte_implicite' => $contexte_implicite); // ignorer le cache deja lu |
| 389 | 389 | include_spip('inc/invalideur'); |
| 390 | 390 | retire_caches($chemin_cache); # API invalideur inutile |
| 391 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 391 | + supprimer_fichier(_DIR_CACHE.$chemin_cache); |
|
| 392 | 392 | if (isset($chemin_cache_session) and $chemin_cache_session) { |
| 393 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 393 | + supprimer_fichier(_DIR_CACHE.$chemin_cache_session); |
|
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
@@ -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 | /** |
@@ -50,19 +50,19 @@ discard block |
||
| 50 | 50 | * @return array|string |
| 51 | 51 | */ |
| 52 | 52 | function inc_securiser_action_dist($action = '', $arg = '', $redirect = "", $mode = false, $att = '', $public = false) { |
| 53 | - if ($action) { |
|
| 54 | - return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public); |
|
| 55 | - } else { |
|
| 56 | - $arg = _request('arg'); |
|
| 57 | - $hash = _request('hash'); |
|
| 58 | - $action = _request('action') ? _request('action') : _request('formulaire_action'); |
|
| 59 | - if ($a = verifier_action_auteur("$action-$arg", $hash)) { |
|
| 60 | - return $arg; |
|
| 61 | - } |
|
| 62 | - include_spip('inc/minipres'); |
|
| 63 | - echo minipres(); |
|
| 64 | - exit; |
|
| 65 | - } |
|
| 53 | + if ($action) { |
|
| 54 | + return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public); |
|
| 55 | + } else { |
|
| 56 | + $arg = _request('arg'); |
|
| 57 | + $hash = _request('hash'); |
|
| 58 | + $action = _request('action') ? _request('action') : _request('formulaire_action'); |
|
| 59 | + if ($a = verifier_action_auteur("$action-$arg", $hash)) { |
|
| 60 | + return $arg; |
|
| 61 | + } |
|
| 62 | + include_spip('inc/minipres'); |
|
| 63 | + echo minipres(); |
|
| 64 | + exit; |
|
| 65 | + } |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -94,30 +94,30 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | function securiser_action_auteur($action, $arg, $redirect = "", $mode = false, $att = '', $public = false) { |
| 96 | 96 | |
| 97 | - // mode URL ou array |
|
| 98 | - if (!is_string($mode)) { |
|
| 99 | - $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null); |
|
| 100 | - |
|
| 101 | - $r = rawurlencode($redirect); |
|
| 102 | - if ($mode === -1) { |
|
| 103 | - return array('action' => $action, 'arg' => $arg, 'hash' => $hash); |
|
| 104 | - } else { |
|
| 105 | - return generer_url_action($action, "arg=" . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"), |
|
| 106 | - $mode, $public); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // mode formulaire |
|
| 111 | - $hash = calculer_action_auteur("$action-$arg"); |
|
| 112 | - $att .= " style='margin: 0px; border: 0px'"; |
|
| 113 | - if ($redirect) { |
|
| 114 | - $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", ''', $redirect) . "' />"; |
|
| 115 | - } |
|
| 116 | - $mode .= $redirect . " |
|
| 97 | + // mode URL ou array |
|
| 98 | + if (!is_string($mode)) { |
|
| 99 | + $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null); |
|
| 100 | + |
|
| 101 | + $r = rawurlencode($redirect); |
|
| 102 | + if ($mode === -1) { |
|
| 103 | + return array('action' => $action, 'arg' => $arg, 'hash' => $hash); |
|
| 104 | + } else { |
|
| 105 | + return generer_url_action($action, "arg=" . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"), |
|
| 106 | + $mode, $public); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // mode formulaire |
|
| 111 | + $hash = calculer_action_auteur("$action-$arg"); |
|
| 112 | + $att .= " style='margin: 0px; border: 0px'"; |
|
| 113 | + if ($redirect) { |
|
| 114 | + $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", ''', $redirect) . "' />"; |
|
| 115 | + } |
|
| 116 | + $mode .= $redirect . " |
|
| 117 | 117 | <input name='hash' type='hidden' value='$hash' /> |
| 118 | 118 | <input name='arg' type='hidden' value='$arg' />"; |
| 119 | 119 | |
| 120 | - return generer_form_action($action, $mode, $att, $public); |
|
| 120 | + return generer_form_action($action, $mode, $att, $public); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -127,47 +127,47 @@ discard block |
||
| 127 | 127 | * @return array |
| 128 | 128 | */ |
| 129 | 129 | function caracteriser_auteur($id_auteur = null) { |
| 130 | - static $caracterisation = array(); |
|
| 131 | - |
|
| 132 | - if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 133 | - // si l'auteur courant n'est pas connu alors qu'il peut demander une action |
|
| 134 | - // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie. |
|
| 135 | - // S'il n'avait pas le droit de realiser cette action, le hash sera faux. |
|
| 136 | - if (isset($_COOKIE['spip_session']) |
|
| 137 | - and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r)) |
|
| 138 | - ) { |
|
| 139 | - return array($r[1], ''); |
|
| 140 | - // Necessaire aux forums anonymes. |
|
| 141 | - // Pour le reste, ca echouera. |
|
| 142 | - } else { |
|
| 143 | - return array('0', ''); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - // Eviter l'acces SQL si le pass est connu de PHP |
|
| 147 | - if (is_null($id_auteur)) { |
|
| 148 | - $id_auteur = isset($GLOBALS['visiteur_session']['id_auteur']) ? $GLOBALS['visiteur_session']['id_auteur'] : 0; |
|
| 149 | - if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) { |
|
| 150 | - return $caracterisation[$id_auteur] = array($id_auteur, $GLOBALS['visiteur_session']['pass']); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if (isset($caracterisation[$id_auteur])) { |
|
| 155 | - return $caracterisation[$id_auteur]; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if ($id_auteur) { |
|
| 159 | - include_spip('base/abstract_sql'); |
|
| 160 | - $t = sql_fetsel("id_auteur, pass", "spip_auteurs", "id_auteur=$id_auteur"); |
|
| 161 | - if ($t) { |
|
| 162 | - return $caracterisation[$id_auteur] = array($t['id_auteur'], $t['pass']); |
|
| 163 | - } |
|
| 164 | - include_spip('inc/minipres'); |
|
| 165 | - echo minipres(); |
|
| 166 | - exit; |
|
| 167 | - } // Visiteur anonyme, pour ls forums par exemple |
|
| 168 | - else { |
|
| 169 | - return array('0', ''); |
|
| 170 | - } |
|
| 130 | + static $caracterisation = array(); |
|
| 131 | + |
|
| 132 | + if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 133 | + // si l'auteur courant n'est pas connu alors qu'il peut demander une action |
|
| 134 | + // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie. |
|
| 135 | + // S'il n'avait pas le droit de realiser cette action, le hash sera faux. |
|
| 136 | + if (isset($_COOKIE['spip_session']) |
|
| 137 | + and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r)) |
|
| 138 | + ) { |
|
| 139 | + return array($r[1], ''); |
|
| 140 | + // Necessaire aux forums anonymes. |
|
| 141 | + // Pour le reste, ca echouera. |
|
| 142 | + } else { |
|
| 143 | + return array('0', ''); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + // Eviter l'acces SQL si le pass est connu de PHP |
|
| 147 | + if (is_null($id_auteur)) { |
|
| 148 | + $id_auteur = isset($GLOBALS['visiteur_session']['id_auteur']) ? $GLOBALS['visiteur_session']['id_auteur'] : 0; |
|
| 149 | + if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) { |
|
| 150 | + return $caracterisation[$id_auteur] = array($id_auteur, $GLOBALS['visiteur_session']['pass']); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if (isset($caracterisation[$id_auteur])) { |
|
| 155 | + return $caracterisation[$id_auteur]; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if ($id_auteur) { |
|
| 159 | + include_spip('base/abstract_sql'); |
|
| 160 | + $t = sql_fetsel("id_auteur, pass", "spip_auteurs", "id_auteur=$id_auteur"); |
|
| 161 | + if ($t) { |
|
| 162 | + return $caracterisation[$id_auteur] = array($t['id_auteur'], $t['pass']); |
|
| 163 | + } |
|
| 164 | + include_spip('inc/minipres'); |
|
| 165 | + echo minipres(); |
|
| 166 | + exit; |
|
| 167 | + } // Visiteur anonyme, pour ls forums par exemple |
|
| 168 | + else { |
|
| 169 | + return array('0', ''); |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -182,26 +182,26 @@ discard block |
||
| 182 | 182 | * @return string |
| 183 | 183 | */ |
| 184 | 184 | function _action_auteur($action, $id_auteur, $pass, $alea) { |
| 185 | - static $sha = array(); |
|
| 186 | - if (!isset($sha[$id_auteur . $pass . $alea])) { |
|
| 187 | - if (!isset($GLOBALS['meta'][$alea]) and _request('exec') !== 'install') { |
|
| 188 | - include_spip('inc/acces'); |
|
| 189 | - charger_aleas(); |
|
| 190 | - if (empty($GLOBALS['meta'][$alea])) { |
|
| 191 | - include_spip('inc/minipres'); |
|
| 192 | - echo minipres(); |
|
| 193 | - spip_log("$alea indisponible"); |
|
| 194 | - exit; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - include_spip('auth/sha256.inc'); |
|
| 198 | - $sha[$id_auteur . $pass . $alea] = spip_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]); |
|
| 199 | - } |
|
| 200 | - if (function_exists('sha1')) { |
|
| 201 | - return sha1($action . $sha[$id_auteur . $pass . $alea]); |
|
| 202 | - } else { |
|
| 203 | - return md5($action . $sha[$id_auteur . $pass . $alea]); |
|
| 204 | - } |
|
| 185 | + static $sha = array(); |
|
| 186 | + if (!isset($sha[$id_auteur . $pass . $alea])) { |
|
| 187 | + if (!isset($GLOBALS['meta'][$alea]) and _request('exec') !== 'install') { |
|
| 188 | + include_spip('inc/acces'); |
|
| 189 | + charger_aleas(); |
|
| 190 | + if (empty($GLOBALS['meta'][$alea])) { |
|
| 191 | + include_spip('inc/minipres'); |
|
| 192 | + echo minipres(); |
|
| 193 | + spip_log("$alea indisponible"); |
|
| 194 | + exit; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + include_spip('auth/sha256.inc'); |
|
| 198 | + $sha[$id_auteur . $pass . $alea] = spip_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]); |
|
| 199 | + } |
|
| 200 | + if (function_exists('sha1')) { |
|
| 201 | + return sha1($action . $sha[$id_auteur . $pass . $alea]); |
|
| 202 | + } else { |
|
| 203 | + return md5($action . $sha[$id_auteur . $pass . $alea]); |
|
| 204 | + } |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | * @return string |
| 213 | 213 | */ |
| 214 | 214 | function calculer_action_auteur($action, $id_auteur = null) { |
| 215 | - list($id_auteur, $pass) = caracteriser_auteur($id_auteur); |
|
| 215 | + list($id_auteur, $pass) = caracteriser_auteur($id_auteur); |
|
| 216 | 216 | |
| 217 | - return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'); |
|
| 217 | + return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | |
@@ -227,15 +227,15 @@ discard block |
||
| 227 | 227 | * @return bool |
| 228 | 228 | */ |
| 229 | 229 | function verifier_action_auteur($action, $hash) { |
| 230 | - list($id_auteur, $pass) = caracteriser_auteur(); |
|
| 231 | - if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) { |
|
| 232 | - return true; |
|
| 233 | - } |
|
| 234 | - if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')) { |
|
| 235 | - return true; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - return false; |
|
| 230 | + list($id_auteur, $pass) = caracteriser_auteur(); |
|
| 231 | + if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) { |
|
| 232 | + return true; |
|
| 233 | + } |
|
| 234 | + if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')) { |
|
| 235 | + return true; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + return false; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | // |
@@ -251,21 +251,21 @@ discard block |
||
| 251 | 251 | * @return string |
| 252 | 252 | */ |
| 253 | 253 | function secret_du_site() { |
| 254 | - if (!isset($GLOBALS['meta']['secret_du_site'])) { |
|
| 255 | - include_spip('base/abstract_sql'); |
|
| 256 | - $GLOBALS['meta']['secret_du_site'] = sql_getfetsel('valeur', 'spip_meta', "nom='secret_du_site'"); |
|
| 257 | - } |
|
| 258 | - if (!isset($GLOBALS['meta']['secret_du_site']) |
|
| 259 | - or (strlen($GLOBALS['meta']['secret_du_site']) < 64) |
|
| 260 | - ) { |
|
| 261 | - include_spip('inc/acces'); |
|
| 262 | - include_spip('auth/sha256.inc'); |
|
| 263 | - ecrire_meta('secret_du_site', |
|
| 264 | - spip_sha256($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SERVER_SIGNATURE"] . creer_uniqid()), 'non'); |
|
| 265 | - lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - return $GLOBALS['meta']['secret_du_site']; |
|
| 254 | + if (!isset($GLOBALS['meta']['secret_du_site'])) { |
|
| 255 | + include_spip('base/abstract_sql'); |
|
| 256 | + $GLOBALS['meta']['secret_du_site'] = sql_getfetsel('valeur', 'spip_meta', "nom='secret_du_site'"); |
|
| 257 | + } |
|
| 258 | + if (!isset($GLOBALS['meta']['secret_du_site']) |
|
| 259 | + or (strlen($GLOBALS['meta']['secret_du_site']) < 64) |
|
| 260 | + ) { |
|
| 261 | + include_spip('inc/acces'); |
|
| 262 | + include_spip('auth/sha256.inc'); |
|
| 263 | + ecrire_meta('secret_du_site', |
|
| 264 | + spip_sha256($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SERVER_SIGNATURE"] . creer_uniqid()), 'non'); |
|
| 265 | + lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + return $GLOBALS['meta']['secret_du_site']; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -275,11 +275,11 @@ discard block |
||
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | 277 | function calculer_cle_action($action) { |
| 278 | - if (function_exists('sha1')) { |
|
| 279 | - return sha1($action . secret_du_site()); |
|
| 280 | - } else { |
|
| 281 | - return md5($action . secret_du_site()); |
|
| 282 | - } |
|
| 278 | + if (function_exists('sha1')) { |
|
| 279 | + return sha1($action . secret_du_site()); |
|
| 280 | + } else { |
|
| 281 | + return md5($action . secret_du_site()); |
|
| 282 | + } |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @return bool |
| 291 | 291 | */ |
| 292 | 292 | function verifier_cle_action($action, $cle) { |
| 293 | - return ($cle == calculer_cle_action($action)); |
|
| 293 | + return ($cle == calculer_cle_action($action)); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -307,19 +307,19 @@ discard block |
||
| 307 | 307 | * @return string Token, de la forme "{id}*{hash}" |
| 308 | 308 | */ |
| 309 | 309 | function calculer_token_previsu($url, $id_auteur = null, $alea = 'alea_ephemere') { |
| 310 | - if (is_null($id_auteur)) { |
|
| 311 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 312 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 316 | - return ""; |
|
| 317 | - } |
|
| 318 | - // On nettoie l’URL de tous les var_. |
|
| 319 | - $url = nettoyer_uri_var($url); |
|
| 320 | - |
|
| 321 | - $token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea); |
|
| 322 | - return "$id_auteur-$token"; |
|
| 310 | + if (is_null($id_auteur)) { |
|
| 311 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 312 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 316 | + return ""; |
|
| 317 | + } |
|
| 318 | + // On nettoie l’URL de tous les var_. |
|
| 319 | + $url = nettoyer_uri_var($url); |
|
| 320 | + |
|
| 321 | + $token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea); |
|
| 322 | + return "$id_auteur-$token"; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -337,31 +337,31 @@ discard block |
||
| 337 | 337 | * + Tableau (id auteur, type d’objet, id_objet) sinon. |
| 338 | 338 | */ |
| 339 | 339 | function verifier_token_previsu($token) { |
| 340 | - // retrouver auteur / hash |
|
| 341 | - $e = explode('-', $token, 2); |
|
| 342 | - if (count($e) == 2 and is_numeric(reset($e))) { |
|
| 343 | - $id_auteur = intval(reset($e)); |
|
| 344 | - } else { |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - // calculer le type et id de l’url actuelle |
|
| 349 | - include_spip('inc/urls'); |
|
| 350 | - include_spip('inc/filtres_mini'); |
|
| 351 | - $url = url_absolue(self()); |
|
| 352 | - |
|
| 353 | - // verifier le token |
|
| 354 | - $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere'); |
|
| 355 | - if (!$_token or $token !== $_token) { |
|
| 356 | - $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien'); |
|
| 357 | - if (!$_token or $token !== $_token) { |
|
| 358 | - return false; |
|
| 359 | - } |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return array( |
|
| 363 | - 'id_auteur' => $id_auteur, |
|
| 364 | - ); |
|
| 340 | + // retrouver auteur / hash |
|
| 341 | + $e = explode('-', $token, 2); |
|
| 342 | + if (count($e) == 2 and is_numeric(reset($e))) { |
|
| 343 | + $id_auteur = intval(reset($e)); |
|
| 344 | + } else { |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + // calculer le type et id de l’url actuelle |
|
| 349 | + include_spip('inc/urls'); |
|
| 350 | + include_spip('inc/filtres_mini'); |
|
| 351 | + $url = url_absolue(self()); |
|
| 352 | + |
|
| 353 | + // verifier le token |
|
| 354 | + $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere'); |
|
| 355 | + if (!$_token or $token !== $_token) { |
|
| 356 | + $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien'); |
|
| 357 | + if (!$_token or $token !== $_token) { |
|
| 358 | + return false; |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return array( |
|
| 363 | + 'id_auteur' => $id_auteur, |
|
| 364 | + ); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -370,13 +370,13 @@ discard block |
||
| 370 | 370 | * @return bool|array |
| 371 | 371 | */ |
| 372 | 372 | function decrire_token_previsu() { |
| 373 | - static $desc = null; |
|
| 374 | - if (is_null($desc)) { |
|
| 375 | - if ($token = _request('var_previewtoken')) { |
|
| 376 | - $desc = verifier_token_previsu($token); |
|
| 377 | - } else { |
|
| 378 | - $desc = false; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - return $desc; |
|
| 373 | + static $desc = null; |
|
| 374 | + if (is_null($desc)) { |
|
| 375 | + if ($token = _request('var_previewtoken')) { |
|
| 376 | + $desc = verifier_token_previsu($token); |
|
| 377 | + } else { |
|
| 378 | + $desc = false; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + return $desc; |
|
| 382 | 382 | } |
| 383 | 383 | \ No newline at end of file |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | if ($mode === -1) { |
| 103 | 103 | return array('action' => $action, 'arg' => $arg, 'hash' => $hash); |
| 104 | 104 | } else { |
| 105 | - return generer_url_action($action, "arg=" . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"), |
|
| 105 | + return generer_url_action($action, "arg=".rawurlencode($arg)."&hash=$hash".(!$r ? '' : "&redirect=$r"), |
|
| 106 | 106 | $mode, $public); |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | $hash = calculer_action_auteur("$action-$arg"); |
| 112 | 112 | $att .= " style='margin: 0px; border: 0px'"; |
| 113 | 113 | if ($redirect) { |
| 114 | - $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", ''', $redirect) . "' />"; |
|
| 114 | + $redirect = "\n\t\t<input name='redirect' type='hidden' value='".str_replace("'", ''', $redirect)."' />"; |
|
| 115 | 115 | } |
| 116 | - $mode .= $redirect . " |
|
| 116 | + $mode .= $redirect." |
|
| 117 | 117 | <input name='hash' type='hidden' value='$hash' /> |
| 118 | 118 | <input name='arg' type='hidden' value='$arg' />"; |
| 119 | 119 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | function _action_auteur($action, $id_auteur, $pass, $alea) { |
| 185 | 185 | static $sha = array(); |
| 186 | - if (!isset($sha[$id_auteur . $pass . $alea])) { |
|
| 186 | + if (!isset($sha[$id_auteur.$pass.$alea])) { |
|
| 187 | 187 | if (!isset($GLOBALS['meta'][$alea]) and _request('exec') !== 'install') { |
| 188 | 188 | include_spip('inc/acces'); |
| 189 | 189 | charger_aleas(); |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | include_spip('auth/sha256.inc'); |
| 198 | - $sha[$id_auteur . $pass . $alea] = spip_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]); |
|
| 198 | + $sha[$id_auteur.$pass.$alea] = spip_sha256($id_auteur.$pass.@$GLOBALS['meta'][$alea]); |
|
| 199 | 199 | } |
| 200 | 200 | if (function_exists('sha1')) { |
| 201 | - return sha1($action . $sha[$id_auteur . $pass . $alea]); |
|
| 201 | + return sha1($action.$sha[$id_auteur.$pass.$alea]); |
|
| 202 | 202 | } else { |
| 203 | - return md5($action . $sha[$id_auteur . $pass . $alea]); |
|
| 203 | + return md5($action.$sha[$id_auteur.$pass.$alea]); |
|
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | include_spip('inc/acces'); |
| 262 | 262 | include_spip('auth/sha256.inc'); |
| 263 | 263 | ecrire_meta('secret_du_site', |
| 264 | - spip_sha256($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SERVER_SIGNATURE"] . creer_uniqid()), 'non'); |
|
| 264 | + spip_sha256($_SERVER["DOCUMENT_ROOT"].$_SERVER["SERVER_SIGNATURE"].creer_uniqid()), 'non'); |
|
| 265 | 265 | lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
| 266 | 266 | } |
| 267 | 267 | |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | function calculer_cle_action($action) { |
| 278 | 278 | if (function_exists('sha1')) { |
| 279 | - return sha1($action . secret_du_site()); |
|
| 279 | + return sha1($action.secret_du_site()); |
|
| 280 | 280 | } else { |
| 281 | - return md5($action . secret_du_site()); |
|
| 281 | + return md5($action.secret_du_site()); |
|
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | // On nettoie l’URL de tous les var_. |
| 319 | 319 | $url = nettoyer_uri_var($url); |
| 320 | 320 | |
| 321 | - $token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea); |
|
| 321 | + $token = _action_auteur('previsualiser-'.$url, $id_auteur, null, $alea); |
|
| 322 | 322 | return "$id_auteur-$token"; |
| 323 | 323 | } |
| 324 | 324 | |
@@ -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 | /** |
@@ -32,78 +32,78 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function auth_spip_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 34 | 34 | |
| 35 | - // retrouver le login |
|
| 36 | - $login = auth_spip_retrouver_login($login); |
|
| 37 | - // login inconnu, n'allons pas plus loin |
|
| 38 | - if (!$login) { |
|
| 39 | - return array(); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $md5pass = ""; |
|
| 43 | - $shapass = $shanext = ""; |
|
| 44 | - |
|
| 45 | - if (preg_match(",^\{([0-9a-f]{64});([0-9a-f]{64})\}$,i", $pass, $regs)) { |
|
| 46 | - $shapass = $regs[1]; |
|
| 47 | - $shanext = $regs[2]; |
|
| 48 | - } // compat avec une base mixte md5/sha256 : le js a envoye les 2 hash |
|
| 49 | - elseif (preg_match(",^\{([0-9a-f]{64});([0-9a-f]{64});([0-9a-f]{32});([0-9a-f]{32})\}$,i", $pass, $regs)) { |
|
| 50 | - $shapass = $regs[1]; |
|
| 51 | - $shanext = $regs[2]; |
|
| 52 | - $md5pass = $regs[3]; |
|
| 53 | - //$md5next = $regs[4]; |
|
| 54 | - } // si envoi non crypte, crypter maintenant |
|
| 55 | - elseif ($pass) { |
|
| 56 | - $row = sql_fetsel("alea_actuel, alea_futur", "spip_auteurs", "login=" . sql_quote($login, $serveur, 'text'), '', '', |
|
| 57 | - '', '', $serveur); |
|
| 58 | - |
|
| 59 | - if ($row) { |
|
| 60 | - include_spip('auth/sha256.inc'); |
|
| 61 | - $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 62 | - $shanext = spip_sha256($row['alea_futur'] . $pass); |
|
| 63 | - $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // login inexistant ou mot de passe vide |
|
| 68 | - if (!$shapass and !$md5pass) { |
|
| 69 | - return array(); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $row = sql_fetsel("*", "spip_auteurs", |
|
| 73 | - "login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($shapass, $serveur, |
|
| 74 | - 'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur); |
|
| 75 | - |
|
| 76 | - // compat avec les anciennes bases en md5 |
|
| 77 | - if (!$row and $md5pass) { |
|
| 78 | - $row = sql_fetsel("*", "spip_auteurs", |
|
| 79 | - "login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($md5pass, $serveur, |
|
| 80 | - 'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // login/mot de passe incorrect |
|
| 84 | - if (!$row) { |
|
| 85 | - return array(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - // fait tourner le codage du pass dans la base |
|
| 89 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 90 | - if ($shanext and !$phpauth) { |
|
| 91 | - |
|
| 92 | - include_spip('inc/acces'); // pour creer_uniqid |
|
| 93 | - @sql_update('spip_auteurs', array( |
|
| 94 | - 'alea_actuel' => 'alea_futur', |
|
| 95 | - 'pass' => sql_quote($shanext, $serveur, 'text'), |
|
| 96 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text') |
|
| 97 | - ), "id_auteur=" . $row['id_auteur'] . ' AND pass IN (' . sql_quote($shapass, $serveur, |
|
| 98 | - 'text') . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur); |
|
| 99 | - // En profiter pour verifier la securite de tmp/ |
|
| 100 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 101 | - if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 102 | - return false; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $row; |
|
| 35 | + // retrouver le login |
|
| 36 | + $login = auth_spip_retrouver_login($login); |
|
| 37 | + // login inconnu, n'allons pas plus loin |
|
| 38 | + if (!$login) { |
|
| 39 | + return array(); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $md5pass = ""; |
|
| 43 | + $shapass = $shanext = ""; |
|
| 44 | + |
|
| 45 | + if (preg_match(",^\{([0-9a-f]{64});([0-9a-f]{64})\}$,i", $pass, $regs)) { |
|
| 46 | + $shapass = $regs[1]; |
|
| 47 | + $shanext = $regs[2]; |
|
| 48 | + } // compat avec une base mixte md5/sha256 : le js a envoye les 2 hash |
|
| 49 | + elseif (preg_match(",^\{([0-9a-f]{64});([0-9a-f]{64});([0-9a-f]{32});([0-9a-f]{32})\}$,i", $pass, $regs)) { |
|
| 50 | + $shapass = $regs[1]; |
|
| 51 | + $shanext = $regs[2]; |
|
| 52 | + $md5pass = $regs[3]; |
|
| 53 | + //$md5next = $regs[4]; |
|
| 54 | + } // si envoi non crypte, crypter maintenant |
|
| 55 | + elseif ($pass) { |
|
| 56 | + $row = sql_fetsel("alea_actuel, alea_futur", "spip_auteurs", "login=" . sql_quote($login, $serveur, 'text'), '', '', |
|
| 57 | + '', '', $serveur); |
|
| 58 | + |
|
| 59 | + if ($row) { |
|
| 60 | + include_spip('auth/sha256.inc'); |
|
| 61 | + $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 62 | + $shanext = spip_sha256($row['alea_futur'] . $pass); |
|
| 63 | + $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // login inexistant ou mot de passe vide |
|
| 68 | + if (!$shapass and !$md5pass) { |
|
| 69 | + return array(); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $row = sql_fetsel("*", "spip_auteurs", |
|
| 73 | + "login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($shapass, $serveur, |
|
| 74 | + 'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur); |
|
| 75 | + |
|
| 76 | + // compat avec les anciennes bases en md5 |
|
| 77 | + if (!$row and $md5pass) { |
|
| 78 | + $row = sql_fetsel("*", "spip_auteurs", |
|
| 79 | + "login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($md5pass, $serveur, |
|
| 80 | + 'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // login/mot de passe incorrect |
|
| 84 | + if (!$row) { |
|
| 85 | + return array(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + // fait tourner le codage du pass dans la base |
|
| 89 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 90 | + if ($shanext and !$phpauth) { |
|
| 91 | + |
|
| 92 | + include_spip('inc/acces'); // pour creer_uniqid |
|
| 93 | + @sql_update('spip_auteurs', array( |
|
| 94 | + 'alea_actuel' => 'alea_futur', |
|
| 95 | + 'pass' => sql_quote($shanext, $serveur, 'text'), |
|
| 96 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text') |
|
| 97 | + ), "id_auteur=" . $row['id_auteur'] . ' AND pass IN (' . sql_quote($shapass, $serveur, |
|
| 98 | + 'text') . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur); |
|
| 99 | + // En profiter pour verifier la securite de tmp/ |
|
| 100 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 101 | + if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $row; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -113,41 +113,41 @@ discard block |
||
| 113 | 113 | * @return array |
| 114 | 114 | */ |
| 115 | 115 | function auth_spip_formulaire_login($flux) { |
| 116 | - // faut il encore envoyer md5 ? |
|
| 117 | - // on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle |
|
| 118 | - // les hash md5 ont une longueur 32, les sha 64 |
|
| 119 | - // en evitant une requete sql a chaque affichage du formulaire login sans session |
|
| 120 | - // (perf issue pour les sites qui mettent le formulaire de login sur la home) |
|
| 121 | - $compat_md5 = false; |
|
| 122 | - if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) { |
|
| 123 | - $compat_md5 = sql_countsel("spip_auteurs", "length(pass)=32 AND statut<>'poubelle'"); |
|
| 124 | - if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) { |
|
| 125 | - effacer_meta('sha_256_only'); |
|
| 126 | - } |
|
| 127 | - if (!$compat_md5) { |
|
| 128 | - ecrire_meta('sha_256_only', 'oui'); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 133 | - $flux['data'] .= |
|
| 134 | - ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '') |
|
| 135 | - . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>' |
|
| 136 | - . '<script type="text/javascript">/*<![CDATA[*/' |
|
| 137 | - . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "'," |
|
| 138 | - . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "'," |
|
| 139 | - . "'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 140 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 141 | - . "'informe_auteur_en_cours':false," |
|
| 142 | - . "'attente_informe':0," |
|
| 143 | - . "'compat_md5':" . ($compat_md5 ? "true" : "false") . "};" |
|
| 144 | - . "jQuery(function(){ |
|
| 116 | + // faut il encore envoyer md5 ? |
|
| 117 | + // on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle |
|
| 118 | + // les hash md5 ont une longueur 32, les sha 64 |
|
| 119 | + // en evitant une requete sql a chaque affichage du formulaire login sans session |
|
| 120 | + // (perf issue pour les sites qui mettent le formulaire de login sur la home) |
|
| 121 | + $compat_md5 = false; |
|
| 122 | + if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) { |
|
| 123 | + $compat_md5 = sql_countsel("spip_auteurs", "length(pass)=32 AND statut<>'poubelle'"); |
|
| 124 | + if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) { |
|
| 125 | + effacer_meta('sha_256_only'); |
|
| 126 | + } |
|
| 127 | + if (!$compat_md5) { |
|
| 128 | + ecrire_meta('sha_256_only', 'oui'); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 133 | + $flux['data'] .= |
|
| 134 | + ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '') |
|
| 135 | + . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>' |
|
| 136 | + . '<script type="text/javascript">/*<![CDATA[*/' |
|
| 137 | + . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "'," |
|
| 138 | + . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "'," |
|
| 139 | + . "'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 140 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 141 | + . "'informe_auteur_en_cours':false," |
|
| 142 | + . "'attente_informe':0," |
|
| 143 | + . "'compat_md5':" . ($compat_md5 ? "true" : "false") . "};" |
|
| 144 | + . "jQuery(function(){ |
|
| 145 | 145 | jQuery('#var_login').change(actualise_auteur); |
| 146 | 146 | jQuery('form#formulaire_login').submit(login_submit); |
| 147 | 147 | });" |
| 148 | - . "/*]]>*/</script>"; |
|
| 148 | + . "/*]]>*/</script>"; |
|
| 149 | 149 | |
| 150 | - return $flux; |
|
| 150 | + return $flux; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | * toujours true pour un auteur cree dans SPIP |
| 160 | 160 | */ |
| 161 | 161 | function auth_spip_autoriser_modifier_login($serveur = '') { |
| 162 | - if (strlen($serveur)) { |
|
| 163 | - return false; |
|
| 164 | - } // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 165 | - return true; |
|
| 162 | + if (strlen($serveur)) { |
|
| 163 | + return false; |
|
| 164 | + } // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 165 | + return true; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | * message d'erreur si login non valide, chaine vide sinon |
| 177 | 177 | */ |
| 178 | 178 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 179 | - // login et mot de passe |
|
| 180 | - if (strlen($new_login)) { |
|
| 181 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 182 | - return _T('info_login_trop_court_car_pluriel', array('nb' => _LOGIN_TROP_COURT)); |
|
| 183 | - } else { |
|
| 184 | - $n = sql_countsel('spip_auteurs', |
|
| 185 | - "login=" . sql_quote($new_login) . " AND id_auteur!=" . intval($id_auteur) . " AND statut!='5poubelle'", '', '', |
|
| 186 | - $serveur); |
|
| 187 | - if ($n) { |
|
| 188 | - return _T('info_login_existant'); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - return ''; |
|
| 179 | + // login et mot de passe |
|
| 180 | + if (strlen($new_login)) { |
|
| 181 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 182 | + return _T('info_login_trop_court_car_pluriel', array('nb' => _LOGIN_TROP_COURT)); |
|
| 183 | + } else { |
|
| 184 | + $n = sql_countsel('spip_auteurs', |
|
| 185 | + "login=" . sql_quote($new_login) . " AND id_auteur!=" . intval($id_auteur) . " AND statut!='5poubelle'", '', '', |
|
| 186 | + $serveur); |
|
| 187 | + if ($n) { |
|
| 188 | + return _T('info_login_existant'); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + return ''; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -202,32 +202,32 @@ discard block |
||
| 202 | 202 | * @return bool |
| 203 | 203 | */ |
| 204 | 204 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 205 | - if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - if (!$id_auteur = intval($id_auteur) |
|
| 209 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 210 | - ) { |
|
| 211 | - return false; |
|
| 212 | - } |
|
| 213 | - if ($new_login == $auteur['login']) { |
|
| 214 | - return true; |
|
| 215 | - } // on a rien fait mais c'est bon ! |
|
| 216 | - |
|
| 217 | - include_spip('action/editer_auteur'); |
|
| 218 | - |
|
| 219 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 220 | - if (strlen($new_login)) { |
|
| 221 | - $anciens = sql_allfetsel('id_auteur', 'spip_auteurs', |
|
| 222 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", '', '', '', '', $serveur); |
|
| 223 | - while ($row = array_pop($anciens)) { |
|
| 224 | - auteur_modifier($row['id_auteur'], array('login' => ''), true); // manque la gestion de $serveur |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - auteur_modifier($id_auteur, array('login' => $new_login), true); // manque la gestion de $serveur |
|
| 229 | - |
|
| 230 | - return true; |
|
| 205 | + if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + if (!$id_auteur = intval($id_auteur) |
|
| 209 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 210 | + ) { |
|
| 211 | + return false; |
|
| 212 | + } |
|
| 213 | + if ($new_login == $auteur['login']) { |
|
| 214 | + return true; |
|
| 215 | + } // on a rien fait mais c'est bon ! |
|
| 216 | + |
|
| 217 | + include_spip('action/editer_auteur'); |
|
| 218 | + |
|
| 219 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 220 | + if (strlen($new_login)) { |
|
| 221 | + $anciens = sql_allfetsel('id_auteur', 'spip_auteurs', |
|
| 222 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", '', '', '', '', $serveur); |
|
| 223 | + while ($row = array_pop($anciens)) { |
|
| 224 | + auteur_modifier($row['id_auteur'], array('login' => ''), true); // manque la gestion de $serveur |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + auteur_modifier($id_auteur, array('login' => $new_login), true); // manque la gestion de $serveur |
|
| 229 | + |
|
| 230 | + return true; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -239,27 +239,27 @@ discard block |
||
| 239 | 239 | * @return string |
| 240 | 240 | */ |
| 241 | 241 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 242 | - if (!strlen($login)) { |
|
| 243 | - return null; |
|
| 244 | - } // pas la peine de requeter |
|
| 245 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 246 | - if ($r = sql_getfetsel('login', 'spip_auteurs', |
|
| 247 | - "statut<>'5poubelle'" . |
|
| 248 | - " AND (length(pass)>0)" . |
|
| 249 | - " AND (login=$l)", '', '', '', '', $serveur) |
|
| 250 | - ) { |
|
| 251 | - return $r; |
|
| 252 | - } |
|
| 253 | - // Si pas d'auteur avec ce login |
|
| 254 | - // regarder s'il a saisi son nom ou son mail. |
|
| 255 | - // Ne pas fusionner avec la requete precedente |
|
| 256 | - // car un nom peut etre homonyme d'un autre login |
|
| 257 | - else { |
|
| 258 | - return sql_getfetsel('login', 'spip_auteurs', |
|
| 259 | - "statut<>'5poubelle'" . |
|
| 260 | - " AND (length(pass)>0)" . |
|
| 261 | - " AND (login<>'' AND (nom=$l OR email=$l))", '', '', '', '', $serveur); |
|
| 262 | - } |
|
| 242 | + if (!strlen($login)) { |
|
| 243 | + return null; |
|
| 244 | + } // pas la peine de requeter |
|
| 245 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 246 | + if ($r = sql_getfetsel('login', 'spip_auteurs', |
|
| 247 | + "statut<>'5poubelle'" . |
|
| 248 | + " AND (length(pass)>0)" . |
|
| 249 | + " AND (login=$l)", '', '', '', '', $serveur) |
|
| 250 | + ) { |
|
| 251 | + return $r; |
|
| 252 | + } |
|
| 253 | + // Si pas d'auteur avec ce login |
|
| 254 | + // regarder s'il a saisi son nom ou son mail. |
|
| 255 | + // Ne pas fusionner avec la requete precedente |
|
| 256 | + // car un nom peut etre homonyme d'un autre login |
|
| 257 | + else { |
|
| 258 | + return sql_getfetsel('login', 'spip_auteurs', |
|
| 259 | + "statut<>'5poubelle'" . |
|
| 260 | + " AND (length(pass)>0)" . |
|
| 261 | + " AND (login<>'' AND (nom=$l OR email=$l))", '', '', '', '', $serveur); |
|
| 262 | + } |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -277,11 +277,11 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | function auth_spip_informer_login($infos, $row, $serveur = '') { |
| 279 | 279 | |
| 280 | - // pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec |
|
| 281 | - $infos['alea_actuel'] = $row['alea_actuel']; |
|
| 282 | - $infos['alea_futur'] = $row['alea_futur']; |
|
| 280 | + // pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec |
|
| 281 | + $infos['alea_actuel'] = $row['alea_actuel']; |
|
| 282 | + $infos['alea_futur'] = $row['alea_futur']; |
|
| 283 | 283 | |
| 284 | - return $infos; |
|
| 284 | + return $infos; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -292,10 +292,10 @@ discard block |
||
| 292 | 292 | * toujours true pour un auteur cree dans SPIP |
| 293 | 293 | */ |
| 294 | 294 | function auth_spip_autoriser_modifier_pass($serveur = '') { |
| 295 | - if (strlen($serveur)) { |
|
| 296 | - return false; |
|
| 297 | - } // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 298 | - return true; |
|
| 295 | + if (strlen($serveur)) { |
|
| 296 | + return false; |
|
| 297 | + } // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 298 | + return true; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | * message d'erreur si login non valide, chaine vide sinon |
| 317 | 317 | */ |
| 318 | 318 | function auth_spip_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 319 | - // login et mot de passe |
|
| 320 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 321 | - return _T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI)); |
|
| 322 | - } |
|
| 319 | + // login et mot de passe |
|
| 320 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 321 | + return _T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI)); |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - return ''; |
|
| 324 | + return ''; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -335,33 +335,33 @@ discard block |
||
| 335 | 335 | * @return bool |
| 336 | 336 | */ |
| 337 | 337 | function auth_spip_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 338 | - if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 339 | - return false; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - if (!$id_auteur = intval($id_auteur) |
|
| 343 | - or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 344 | - ) { |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $c = array(); |
|
| 349 | - include_spip('inc/acces'); |
|
| 350 | - include_spip('auth/sha256.inc'); |
|
| 351 | - $htpass = generer_htpass($new_pass); |
|
| 352 | - $alea_actuel = creer_uniqid(); |
|
| 353 | - $alea_futur = creer_uniqid(); |
|
| 354 | - $pass = spip_sha256($alea_actuel . $new_pass); |
|
| 355 | - $c['pass'] = $pass; |
|
| 356 | - $c['htpass'] = $htpass; |
|
| 357 | - $c['alea_actuel'] = $alea_actuel; |
|
| 358 | - $c['alea_futur'] = $alea_futur; |
|
| 359 | - $c['low_sec'] = ''; |
|
| 360 | - |
|
| 361 | - include_spip('action/editer_auteur'); |
|
| 362 | - auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur |
|
| 363 | - |
|
| 364 | - return true; // on a bien modifie le pass |
|
| 338 | + if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 339 | + return false; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + if (!$id_auteur = intval($id_auteur) |
|
| 343 | + or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 344 | + ) { |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $c = array(); |
|
| 349 | + include_spip('inc/acces'); |
|
| 350 | + include_spip('auth/sha256.inc'); |
|
| 351 | + $htpass = generer_htpass($new_pass); |
|
| 352 | + $alea_actuel = creer_uniqid(); |
|
| 353 | + $alea_futur = creer_uniqid(); |
|
| 354 | + $pass = spip_sha256($alea_actuel . $new_pass); |
|
| 355 | + $c['pass'] = $pass; |
|
| 356 | + $c['htpass'] = $htpass; |
|
| 357 | + $c['alea_actuel'] = $alea_actuel; |
|
| 358 | + $c['alea_futur'] = $alea_futur; |
|
| 359 | + $c['low_sec'] = ''; |
|
| 360 | + |
|
| 361 | + include_spip('action/editer_auteur'); |
|
| 362 | + auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur |
|
| 363 | + |
|
| 364 | + return true; // on a bien modifie le pass |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -375,54 +375,54 @@ discard block |
||
| 375 | 375 | * @return void |
| 376 | 376 | */ |
| 377 | 377 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = array(), $serveur = '') { |
| 378 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 379 | - if (strlen($serveur)) { |
|
| 380 | - return; |
|
| 381 | - } |
|
| 382 | - // si un login, pass ou statut a ete modifie |
|
| 383 | - // regenerer les fichier htpass |
|
| 384 | - if (isset($champs['login']) |
|
| 385 | - or isset($champs['pass']) |
|
| 386 | - or isset($champs['statut']) |
|
| 387 | - or (isset($options['all']) and $options['all']) |
|
| 388 | - ) { |
|
| 389 | - |
|
| 390 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 391 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 392 | - |
|
| 393 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 394 | - // par exemple acces_restreint ; |
|
| 395 | - // si .htaccess existe, outrepasser spip_meta |
|
| 396 | - if ((!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 397 | - and !@file_exists($htaccess) |
|
| 398 | - ) { |
|
| 399 | - spip_unlink($htpasswd); |
|
| 400 | - spip_unlink($htpasswd . "-admin"); |
|
| 401 | - |
|
| 402 | - return; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 406 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 407 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 408 | - |
|
| 409 | - $p1 = ''; // login:htpass pour tous |
|
| 410 | - $p2 = ''; // login:htpass pour les admins |
|
| 411 | - $s = sql_select("login, htpass, statut", "spip_auteurs", |
|
| 412 | - sql_in("statut", array('1comite', '0minirezo', 'nouveau'))); |
|
| 413 | - while ($t = sql_fetch($s)) { |
|
| 414 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 415 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 416 | - if ($t['statut'] == '0minirezo') { |
|
| 417 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - sql_free($s); |
|
| 422 | - if ($p1) { |
|
| 423 | - ecrire_fichier($htpasswd, $p1); |
|
| 424 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 425 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 426 | - } |
|
| 427 | - } |
|
| 378 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 379 | + if (strlen($serveur)) { |
|
| 380 | + return; |
|
| 381 | + } |
|
| 382 | + // si un login, pass ou statut a ete modifie |
|
| 383 | + // regenerer les fichier htpass |
|
| 384 | + if (isset($champs['login']) |
|
| 385 | + or isset($champs['pass']) |
|
| 386 | + or isset($champs['statut']) |
|
| 387 | + or (isset($options['all']) and $options['all']) |
|
| 388 | + ) { |
|
| 389 | + |
|
| 390 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 391 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 392 | + |
|
| 393 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 394 | + // par exemple acces_restreint ; |
|
| 395 | + // si .htaccess existe, outrepasser spip_meta |
|
| 396 | + if ((!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 397 | + and !@file_exists($htaccess) |
|
| 398 | + ) { |
|
| 399 | + spip_unlink($htpasswd); |
|
| 400 | + spip_unlink($htpasswd . "-admin"); |
|
| 401 | + |
|
| 402 | + return; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 406 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 407 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 408 | + |
|
| 409 | + $p1 = ''; // login:htpass pour tous |
|
| 410 | + $p2 = ''; // login:htpass pour les admins |
|
| 411 | + $s = sql_select("login, htpass, statut", "spip_auteurs", |
|
| 412 | + sql_in("statut", array('1comite', '0minirezo', 'nouveau'))); |
|
| 413 | + while ($t = sql_fetch($s)) { |
|
| 414 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 415 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 416 | + if ($t['statut'] == '0minirezo') { |
|
| 417 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + sql_free($s); |
|
| 422 | + if ($p1) { |
|
| 423 | + ecrire_fichier($htpasswd, $p1); |
|
| 424 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 425 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | 428 | } |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | //$md5next = $regs[4]; |
| 54 | 54 | } // si envoi non crypte, crypter maintenant |
| 55 | 55 | elseif ($pass) { |
| 56 | - $row = sql_fetsel("alea_actuel, alea_futur", "spip_auteurs", "login=" . sql_quote($login, $serveur, 'text'), '', '', |
|
| 56 | + $row = sql_fetsel("alea_actuel, alea_futur", "spip_auteurs", "login=".sql_quote($login, $serveur, 'text'), '', '', |
|
| 57 | 57 | '', '', $serveur); |
| 58 | 58 | |
| 59 | 59 | if ($row) { |
| 60 | 60 | include_spip('auth/sha256.inc'); |
| 61 | - $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 62 | - $shanext = spip_sha256($row['alea_futur'] . $pass); |
|
| 63 | - $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 61 | + $shapass = spip_sha256($row['alea_actuel'].$pass); |
|
| 62 | + $shanext = spip_sha256($row['alea_futur'].$pass); |
|
| 63 | + $md5pass = md5($row['alea_actuel'].$pass); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $row = sql_fetsel("*", "spip_auteurs", |
| 73 | - "login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($shapass, $serveur, |
|
| 74 | - 'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur); |
|
| 73 | + "login=".sql_quote($login, $serveur, 'text')." AND pass=".sql_quote($shapass, $serveur, |
|
| 74 | + 'text')." AND statut<>'5poubelle'", '', '', '', '', $serveur); |
|
| 75 | 75 | |
| 76 | 76 | // compat avec les anciennes bases en md5 |
| 77 | 77 | if (!$row and $md5pass) { |
| 78 | 78 | $row = sql_fetsel("*", "spip_auteurs", |
| 79 | - "login=" . sql_quote($login, $serveur, 'text') . " AND pass=" . sql_quote($md5pass, $serveur, |
|
| 80 | - 'text') . " AND statut<>'5poubelle'", '', '', '', '', $serveur); |
|
| 79 | + "login=".sql_quote($login, $serveur, 'text')." AND pass=".sql_quote($md5pass, $serveur, |
|
| 80 | + 'text')." AND statut<>'5poubelle'", '', '', '', '', $serveur); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // login/mot de passe incorrect |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | 'alea_actuel' => 'alea_futur', |
| 95 | 95 | 'pass' => sql_quote($shanext, $serveur, 'text'), |
| 96 | 96 | 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text') |
| 97 | - ), "id_auteur=" . $row['id_auteur'] . ' AND pass IN (' . sql_quote($shapass, $serveur, |
|
| 98 | - 'text') . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur); |
|
| 97 | + ), "id_auteur=".$row['id_auteur'].' AND pass IN ('.sql_quote($shapass, $serveur, |
|
| 98 | + 'text').', '.sql_quote($md5pass, $serveur, 'text').')', '', $serveur); |
|
| 99 | 99 | // En profiter pour verifier la securite de tmp/ |
| 100 | 100 | // Si elle ne fonctionne pas a l'installation, prevenir |
| 101 | 101 | if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
@@ -131,16 +131,16 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
| 133 | 133 | $flux['data'] .= |
| 134 | - ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '') |
|
| 135 | - . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>' |
|
| 134 | + ($compat_md5 ? '<script type="text/javascript" src="'._DIR_JAVASCRIPT.'md5.js"></script>' : '') |
|
| 135 | + . '<script type="text/javascript" src="'._DIR_JAVASCRIPT.'login-sha-min.js"></script>' |
|
| 136 | 136 | . '<script type="text/javascript">/*<![CDATA[*/' |
| 137 | - . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "'," |
|
| 138 | - . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "'," |
|
| 139 | - . "'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 140 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 137 | + . "var login_info={'alea_actuel':'".$flux['args']['contexte']['_alea_actuel']."'," |
|
| 138 | + . "'alea_futur':'".$flux['args']['contexte']['_alea_futur']."'," |
|
| 139 | + . "'login':'".$flux['args']['contexte']['var_login']."'," |
|
| 140 | + . "'page_auteur': '".generer_url_public('informer_auteur')."'," |
|
| 141 | 141 | . "'informe_auteur_en_cours':false," |
| 142 | 142 | . "'attente_informe':0," |
| 143 | - . "'compat_md5':" . ($compat_md5 ? "true" : "false") . "};" |
|
| 143 | + . "'compat_md5':".($compat_md5 ? "true" : "false")."};" |
|
| 144 | 144 | . "jQuery(function(){ |
| 145 | 145 | jQuery('#var_login').change(actualise_auteur); |
| 146 | 146 | jQuery('form#formulaire_login').submit(login_submit); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | return _T('info_login_trop_court_car_pluriel', array('nb' => _LOGIN_TROP_COURT)); |
| 183 | 183 | } else { |
| 184 | 184 | $n = sql_countsel('spip_auteurs', |
| 185 | - "login=" . sql_quote($new_login) . " AND id_auteur!=" . intval($id_auteur) . " AND statut!='5poubelle'", '', '', |
|
| 185 | + "login=".sql_quote($new_login)." AND id_auteur!=".intval($id_auteur)." AND statut!='5poubelle'", '', '', |
|
| 186 | 186 | $serveur); |
| 187 | 187 | if ($n) { |
| 188 | 188 | return _T('info_login_existant'); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | return false; |
| 207 | 207 | } |
| 208 | 208 | if (!$id_auteur = intval($id_auteur) |
| 209 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 209 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur) |
|
| 210 | 210 | ) { |
| 211 | 211 | return false; |
| 212 | 212 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | // vider le login des auteurs a la poubelle qui avaient ce meme login |
| 220 | 220 | if (strlen($new_login)) { |
| 221 | 221 | $anciens = sql_allfetsel('id_auteur', 'spip_auteurs', |
| 222 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", '', '', '', '', $serveur); |
|
| 222 | + 'login='.sql_quote($new_login, $serveur, 'text')." AND statut='5poubelle'", '', '', '', '', $serveur); |
|
| 223 | 223 | while ($row = array_pop($anciens)) { |
| 224 | 224 | auteur_modifier($row['id_auteur'], array('login' => ''), true); // manque la gestion de $serveur |
| 225 | 225 | } |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | } // pas la peine de requeter |
| 245 | 245 | $l = sql_quote($login, $serveur, 'text'); |
| 246 | 246 | if ($r = sql_getfetsel('login', 'spip_auteurs', |
| 247 | - "statut<>'5poubelle'" . |
|
| 248 | - " AND (length(pass)>0)" . |
|
| 247 | + "statut<>'5poubelle'". |
|
| 248 | + " AND (length(pass)>0)". |
|
| 249 | 249 | " AND (login=$l)", '', '', '', '', $serveur) |
| 250 | 250 | ) { |
| 251 | 251 | return $r; |
@@ -256,8 +256,8 @@ discard block |
||
| 256 | 256 | // car un nom peut etre homonyme d'un autre login |
| 257 | 257 | else { |
| 258 | 258 | return sql_getfetsel('login', 'spip_auteurs', |
| 259 | - "statut<>'5poubelle'" . |
|
| 260 | - " AND (length(pass)>0)" . |
|
| 259 | + "statut<>'5poubelle'". |
|
| 260 | + " AND (length(pass)>0)". |
|
| 261 | 261 | " AND (login<>'' AND (nom=$l OR email=$l))", '', '', '', '', $serveur); |
| 262 | 262 | } |
| 263 | 263 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | if (!$id_auteur = intval($id_auteur) |
| 343 | - or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 343 | + or !sql_fetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur) |
|
| 344 | 344 | ) { |
| 345 | 345 | return false; |
| 346 | 346 | } |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | $htpass = generer_htpass($new_pass); |
| 352 | 352 | $alea_actuel = creer_uniqid(); |
| 353 | 353 | $alea_futur = creer_uniqid(); |
| 354 | - $pass = spip_sha256($alea_actuel . $new_pass); |
|
| 354 | + $pass = spip_sha256($alea_actuel.$new_pass); |
|
| 355 | 355 | $c['pass'] = $pass; |
| 356 | 356 | $c['htpass'] = $htpass; |
| 357 | 357 | $c['alea_actuel'] = $alea_actuel; |
@@ -387,8 +387,8 @@ discard block |
||
| 387 | 387 | or (isset($options['all']) and $options['all']) |
| 388 | 388 | ) { |
| 389 | 389 | |
| 390 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 391 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 390 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 391 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 392 | 392 | |
| 393 | 393 | // Cette variable de configuration peut etre posee par un plugin |
| 394 | 394 | // par exemple acces_restreint ; |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | and !@file_exists($htaccess) |
| 398 | 398 | ) { |
| 399 | 399 | spip_unlink($htpasswd); |
| 400 | - spip_unlink($htpasswd . "-admin"); |
|
| 400 | + spip_unlink($htpasswd."-admin"); |
|
| 401 | 401 | |
| 402 | 402 | return; |
| 403 | 403 | } |
@@ -412,16 +412,16 @@ discard block |
||
| 412 | 412 | sql_in("statut", array('1comite', '0minirezo', 'nouveau'))); |
| 413 | 413 | while ($t = sql_fetch($s)) { |
| 414 | 414 | if (strlen($t['login']) and strlen($t['htpass'])) { |
| 415 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 415 | + $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 416 | 416 | if ($t['statut'] == '0minirezo') { |
| 417 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 417 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 418 | 418 | } |
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | 421 | sql_free($s); |
| 422 | 422 | if ($p1) { |
| 423 | 423 | ecrire_fichier($htpasswd, $p1); |
| 424 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 424 | + ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 425 | 425 | spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
| 426 | 426 | } |
| 427 | 427 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @return string Le SHA de la chaîne |
| 12 | 12 | */ |
| 13 | 13 | function spip_sha256($str) { |
| 14 | - return hash('sha256', $str); |
|
| 14 | + return hash('sha256', $str); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,18 +21,18 @@ discard block |
||
| 21 | 21 | * @deprecated |
| 22 | 22 | */ |
| 23 | 23 | function _nano_sha256($str, $ig_func = true) { |
| 24 | - return spip_sha256($str); |
|
| 24 | + return spip_sha256($str); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // 2009-07-23: Added check for function as the Suhosin plugin adds this routine. |
| 28 | 28 | if (!function_exists('sha256')) { |
| 29 | - /** |
|
| 30 | - * Calcul du SHA256 |
|
| 31 | - * |
|
| 32 | - * @param string $str Chaîne dont on veut calculer le SHA |
|
| 33 | - * @param bool $ig_func |
|
| 34 | - * @return string Le SHA de la chaîne |
|
| 35 | - * @deprecated |
|
| 36 | - */ |
|
| 37 | - function sha256($str, $ig_func = true) { return spip_sha256($str); } |
|
| 29 | + /** |
|
| 30 | + * Calcul du SHA256 |
|
| 31 | + * |
|
| 32 | + * @param string $str Chaîne dont on veut calculer le SHA |
|
| 33 | + * @param bool $ig_func |
|
| 34 | + * @return string Le SHA de la chaîne |
|
| 35 | + * @deprecated |
|
| 36 | + */ |
|
| 37 | + function sha256($str, $ig_func = true) { return spip_sha256($str); } |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -11,143 +11,143 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/headers'); |
| 18 | 18 | |
| 19 | 19 | function install_etape_3b_dist() { |
| 20 | - $login = _request('login'); |
|
| 21 | - $email = _request('email'); |
|
| 22 | - $nom = _request('nom'); |
|
| 23 | - $pass = _request('pass'); |
|
| 24 | - $pass_verif = _request('pass_verif'); |
|
| 25 | - |
|
| 26 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 27 | - ? _INSTALL_SERVER_DB |
|
| 28 | - : _request('server_db'); |
|
| 29 | - |
|
| 30 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 31 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 32 | - } |
|
| 33 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 34 | - define('_LOGIN_TROP_COURT', 4); |
|
| 35 | - } |
|
| 36 | - if ($login) { |
|
| 37 | - $echec = ($pass != $pass_verif) ? |
|
| 38 | - _T('info_passes_identiques') |
|
| 39 | - : ((strlen($pass) < _PASS_LONGUEUR_MINI) ? |
|
| 40 | - _T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI)) |
|
| 41 | - : ((strlen($login) < _LOGIN_TROP_COURT) ? |
|
| 42 | - _T('info_login_trop_court') |
|
| 43 | - : '')); |
|
| 44 | - include_spip('inc/filtres'); |
|
| 45 | - if (!$echec and $email and !email_valide($email)) { |
|
| 46 | - $echec = _T('form_email_non_valide'); |
|
| 47 | - } |
|
| 48 | - if ($echec) { |
|
| 49 | - echo minipres( |
|
| 50 | - 'AUTO', |
|
| 51 | - info_progression_etape(3, 'etape_', 'install/', true) . |
|
| 52 | - "<div class='error'><h3>$echec</h3>\n" . |
|
| 53 | - '<p>' . _T('avis_connexion_echec_2') . '</p>' . |
|
| 54 | - '</div>' |
|
| 55 | - ); |
|
| 56 | - exit; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (@file_exists(_FILE_CHMOD_TMP)) { |
|
| 61 | - include(_FILE_CHMOD_TMP); |
|
| 62 | - } else { |
|
| 63 | - redirige_url_ecrire('install'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - if (!@file_exists(_FILE_CONNECT_TMP)) { |
|
| 67 | - redirige_url_ecrire('install'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - # maintenant on connait le vrai charset du site s'il est deja configure |
|
| 71 | - # sinon par defaut lire_meta reglera _DEFAULT_CHARSET |
|
| 72 | - # (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET) |
|
| 73 | - |
|
| 74 | - lire_metas(); |
|
| 75 | - if ($login) { |
|
| 76 | - include_spip('inc/charsets'); |
|
| 77 | - |
|
| 78 | - $nom = (importer_charset($nom, _DEFAULT_CHARSET)); |
|
| 79 | - $login = (importer_charset($login, _DEFAULT_CHARSET)); |
|
| 80 | - $email = (importer_charset($email, _DEFAULT_CHARSET)); |
|
| 81 | - # pour le passwd, bizarrement il faut le convertir comme s'il avait |
|
| 82 | - # ete tape en iso-8859-1 ; car c'est en fait ce que voit md5.js |
|
| 83 | - $pass = unicode2charset(utf_8_to_unicode($pass), 'iso-8859-1'); |
|
| 84 | - include_spip('auth/sha256.inc'); |
|
| 85 | - include_spip('inc/acces'); |
|
| 86 | - $htpass = generer_htpass($pass); |
|
| 87 | - $alea_actuel = creer_uniqid(); |
|
| 88 | - $alea_futur = creer_uniqid(); |
|
| 89 | - $shapass = spip_sha256($alea_actuel . $pass); |
|
| 90 | - // prelablement, creer le champ webmestre si il n'existe pas (install neuve |
|
| 91 | - // sur une vieille base |
|
| 92 | - $t = sql_showtable('spip_auteurs', true); |
|
| 93 | - if (!isset($t['field']['webmestre'])) { |
|
| 94 | - @sql_alter("TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login)); |
|
| 98 | - if ($id_auteur !== null) { |
|
| 99 | - sql_updateq('spip_auteurs', array( |
|
| 100 | - 'nom' => $nom, |
|
| 101 | - 'email' => $email, |
|
| 102 | - 'login' => $login, |
|
| 103 | - 'pass' => $shapass, |
|
| 104 | - 'alea_actuel' => $alea_actuel, |
|
| 105 | - 'alea_futur' => $alea_futur, |
|
| 106 | - 'htpass' => $htpass, |
|
| 107 | - 'statut' => '0minirezo' |
|
| 108 | - ), "id_auteur=$id_auteur"); |
|
| 109 | - } else { |
|
| 110 | - $id_auteur = sql_insertq('spip_auteurs', array( |
|
| 111 | - 'nom' => $nom, |
|
| 112 | - 'email' => $email, |
|
| 113 | - 'login' => $login, |
|
| 114 | - 'pass' => $shapass, |
|
| 115 | - 'htpass' => $htpass, |
|
| 116 | - 'alea_actuel' => $alea_actuel, |
|
| 117 | - 'alea_futur' => $alea_futur, |
|
| 118 | - 'statut' => '0minirezo' |
|
| 119 | - )); |
|
| 120 | - } |
|
| 121 | - // le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 122 | - @sql_updateq('spip_auteurs', array('webmestre' => 'oui'), "id_auteur=$id_auteur"); |
|
| 123 | - |
|
| 124 | - // inserer email comme email webmaster principal |
|
| 125 | - // (sauf s'il est vide: cas de la re-installation) |
|
| 126 | - if ($email) { |
|
| 127 | - ecrire_meta('email_webmaster', $email); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // Connecter directement celui qui vient de (re)donner son login |
|
| 131 | - // mais sans cookie d'admin ni connexion longue |
|
| 132 | - include_spip('inc/auth'); |
|
| 133 | - if (!$auteur = auth_identifier_login($login, $pass) |
|
| 134 | - or !auth_loger($auteur, true) |
|
| 135 | - ) { |
|
| 136 | - spip_log("login automatique impossible $auth_spip $session" . count($row)); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // installer les metas |
|
| 141 | - $config = charger_fonction('config', 'inc'); |
|
| 142 | - $config(); |
|
| 143 | - |
|
| 144 | - // activer les plugins |
|
| 145 | - // leur installation ne peut pas se faire sur le meme hit, il faudra donc |
|
| 146 | - // poursuivre au hit suivant |
|
| 147 | - include_spip('inc/plugin'); |
|
| 148 | - actualise_plugins_actifs(); |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - include_spip('inc/distant'); |
|
| 152 | - redirige_par_entete(parametre_url(self(), 'etape', '4', '&')); |
|
| 20 | + $login = _request('login'); |
|
| 21 | + $email = _request('email'); |
|
| 22 | + $nom = _request('nom'); |
|
| 23 | + $pass = _request('pass'); |
|
| 24 | + $pass_verif = _request('pass_verif'); |
|
| 25 | + |
|
| 26 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 27 | + ? _INSTALL_SERVER_DB |
|
| 28 | + : _request('server_db'); |
|
| 29 | + |
|
| 30 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 31 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 32 | + } |
|
| 33 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 34 | + define('_LOGIN_TROP_COURT', 4); |
|
| 35 | + } |
|
| 36 | + if ($login) { |
|
| 37 | + $echec = ($pass != $pass_verif) ? |
|
| 38 | + _T('info_passes_identiques') |
|
| 39 | + : ((strlen($pass) < _PASS_LONGUEUR_MINI) ? |
|
| 40 | + _T('info_passe_trop_court_car_pluriel', array('nb' => _PASS_LONGUEUR_MINI)) |
|
| 41 | + : ((strlen($login) < _LOGIN_TROP_COURT) ? |
|
| 42 | + _T('info_login_trop_court') |
|
| 43 | + : '')); |
|
| 44 | + include_spip('inc/filtres'); |
|
| 45 | + if (!$echec and $email and !email_valide($email)) { |
|
| 46 | + $echec = _T('form_email_non_valide'); |
|
| 47 | + } |
|
| 48 | + if ($echec) { |
|
| 49 | + echo minipres( |
|
| 50 | + 'AUTO', |
|
| 51 | + info_progression_etape(3, 'etape_', 'install/', true) . |
|
| 52 | + "<div class='error'><h3>$echec</h3>\n" . |
|
| 53 | + '<p>' . _T('avis_connexion_echec_2') . '</p>' . |
|
| 54 | + '</div>' |
|
| 55 | + ); |
|
| 56 | + exit; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (@file_exists(_FILE_CHMOD_TMP)) { |
|
| 61 | + include(_FILE_CHMOD_TMP); |
|
| 62 | + } else { |
|
| 63 | + redirige_url_ecrire('install'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + if (!@file_exists(_FILE_CONNECT_TMP)) { |
|
| 67 | + redirige_url_ecrire('install'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + # maintenant on connait le vrai charset du site s'il est deja configure |
|
| 71 | + # sinon par defaut lire_meta reglera _DEFAULT_CHARSET |
|
| 72 | + # (les donnees arrivent de toute facon postees en _DEFAULT_CHARSET) |
|
| 73 | + |
|
| 74 | + lire_metas(); |
|
| 75 | + if ($login) { |
|
| 76 | + include_spip('inc/charsets'); |
|
| 77 | + |
|
| 78 | + $nom = (importer_charset($nom, _DEFAULT_CHARSET)); |
|
| 79 | + $login = (importer_charset($login, _DEFAULT_CHARSET)); |
|
| 80 | + $email = (importer_charset($email, _DEFAULT_CHARSET)); |
|
| 81 | + # pour le passwd, bizarrement il faut le convertir comme s'il avait |
|
| 82 | + # ete tape en iso-8859-1 ; car c'est en fait ce que voit md5.js |
|
| 83 | + $pass = unicode2charset(utf_8_to_unicode($pass), 'iso-8859-1'); |
|
| 84 | + include_spip('auth/sha256.inc'); |
|
| 85 | + include_spip('inc/acces'); |
|
| 86 | + $htpass = generer_htpass($pass); |
|
| 87 | + $alea_actuel = creer_uniqid(); |
|
| 88 | + $alea_futur = creer_uniqid(); |
|
| 89 | + $shapass = spip_sha256($alea_actuel . $pass); |
|
| 90 | + // prelablement, creer le champ webmestre si il n'existe pas (install neuve |
|
| 91 | + // sur une vieille base |
|
| 92 | + $t = sql_showtable('spip_auteurs', true); |
|
| 93 | + if (!isset($t['field']['webmestre'])) { |
|
| 94 | + @sql_alter("TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login)); |
|
| 98 | + if ($id_auteur !== null) { |
|
| 99 | + sql_updateq('spip_auteurs', array( |
|
| 100 | + 'nom' => $nom, |
|
| 101 | + 'email' => $email, |
|
| 102 | + 'login' => $login, |
|
| 103 | + 'pass' => $shapass, |
|
| 104 | + 'alea_actuel' => $alea_actuel, |
|
| 105 | + 'alea_futur' => $alea_futur, |
|
| 106 | + 'htpass' => $htpass, |
|
| 107 | + 'statut' => '0minirezo' |
|
| 108 | + ), "id_auteur=$id_auteur"); |
|
| 109 | + } else { |
|
| 110 | + $id_auteur = sql_insertq('spip_auteurs', array( |
|
| 111 | + 'nom' => $nom, |
|
| 112 | + 'email' => $email, |
|
| 113 | + 'login' => $login, |
|
| 114 | + 'pass' => $shapass, |
|
| 115 | + 'htpass' => $htpass, |
|
| 116 | + 'alea_actuel' => $alea_actuel, |
|
| 117 | + 'alea_futur' => $alea_futur, |
|
| 118 | + 'statut' => '0minirezo' |
|
| 119 | + )); |
|
| 120 | + } |
|
| 121 | + // le passer webmestre separrement du reste, au cas ou l'alter n'aurait pas fonctionne |
|
| 122 | + @sql_updateq('spip_auteurs', array('webmestre' => 'oui'), "id_auteur=$id_auteur"); |
|
| 123 | + |
|
| 124 | + // inserer email comme email webmaster principal |
|
| 125 | + // (sauf s'il est vide: cas de la re-installation) |
|
| 126 | + if ($email) { |
|
| 127 | + ecrire_meta('email_webmaster', $email); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // Connecter directement celui qui vient de (re)donner son login |
|
| 131 | + // mais sans cookie d'admin ni connexion longue |
|
| 132 | + include_spip('inc/auth'); |
|
| 133 | + if (!$auteur = auth_identifier_login($login, $pass) |
|
| 134 | + or !auth_loger($auteur, true) |
|
| 135 | + ) { |
|
| 136 | + spip_log("login automatique impossible $auth_spip $session" . count($row)); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // installer les metas |
|
| 141 | + $config = charger_fonction('config', 'inc'); |
|
| 142 | + $config(); |
|
| 143 | + |
|
| 144 | + // activer les plugins |
|
| 145 | + // leur installation ne peut pas se faire sur le meme hit, il faudra donc |
|
| 146 | + // poursuivre au hit suivant |
|
| 147 | + include_spip('inc/plugin'); |
|
| 148 | + actualise_plugins_actifs(); |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + include_spip('inc/distant'); |
|
| 152 | + redirige_par_entete(parametre_url(self(), 'etape', '4', '&')); |
|
| 153 | 153 | } |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | if ($echec) { |
| 49 | 49 | echo minipres( |
| 50 | 50 | 'AUTO', |
| 51 | - info_progression_etape(3, 'etape_', 'install/', true) . |
|
| 52 | - "<div class='error'><h3>$echec</h3>\n" . |
|
| 53 | - '<p>' . _T('avis_connexion_echec_2') . '</p>' . |
|
| 51 | + info_progression_etape(3, 'etape_', 'install/', true). |
|
| 52 | + "<div class='error'><h3>$echec</h3>\n". |
|
| 53 | + '<p>'._T('avis_connexion_echec_2').'</p>'. |
|
| 54 | 54 | '</div>' |
| 55 | 55 | ); |
| 56 | 56 | exit; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $htpass = generer_htpass($pass); |
| 87 | 87 | $alea_actuel = creer_uniqid(); |
| 88 | 88 | $alea_futur = creer_uniqid(); |
| 89 | - $shapass = spip_sha256($alea_actuel . $pass); |
|
| 89 | + $shapass = spip_sha256($alea_actuel.$pass); |
|
| 90 | 90 | // prelablement, creer le champ webmestre si il n'existe pas (install neuve |
| 91 | 91 | // sur une vieille base |
| 92 | 92 | $t = sql_showtable('spip_auteurs', true); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | @sql_alter("TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login=' . sql_quote($login)); |
|
| 97 | + $id_auteur = sql_getfetsel('id_auteur', 'spip_auteurs', 'login='.sql_quote($login)); |
|
| 98 | 98 | if ($id_auteur !== null) { |
| 99 | 99 | sql_updateq('spip_auteurs', array( |
| 100 | 100 | 'nom' => $nom, |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | if (!$auteur = auth_identifier_login($login, $pass) |
| 134 | 134 | or !auth_loger($auteur, true) |
| 135 | 135 | ) { |
| 136 | - spip_log("login automatique impossible $auth_spip $session" . count($row)); |
|
| 136 | + spip_log("login automatique impossible $auth_spip $session".count($row)); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |