@@ -18,16 +18,16 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_SPIP_SELECT_RUBRIQUES')) { |
| 25 | - /** |
|
| 26 | - * @var int Nombre de rubriques maximum du sélecteur de rubriques. |
|
| 27 | - * Au delà, on bascule sur un sélecteur ajax. |
|
| 28 | - * mettre 100000 pour desactiver ajax |
|
| 29 | - */ |
|
| 30 | - define('_SPIP_SELECT_RUBRIQUES', 20); |
|
| 25 | + /** |
|
| 26 | + * @var int Nombre de rubriques maximum du sélecteur de rubriques. |
|
| 27 | + * Au delà, on bascule sur un sélecteur ajax. |
|
| 28 | + * mettre 100000 pour desactiver ajax |
|
| 29 | + */ |
|
| 30 | + define('_SPIP_SELECT_RUBRIQUES', 20); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -55,22 +55,22 @@ discard block |
||
| 55 | 55 | * Code HTML du sélecteur |
| 56 | 56 | **/ |
| 57 | 57 | function inc_chercher_rubrique_dist($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 58 | - if (sql_countsel('spip_rubriques') < 1) { |
|
| 59 | - return ''; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Mode sans Ajax : |
|
| 63 | - // - soit parce que le cookie ajax n'est pas la |
|
| 64 | - // - soit parce qu'il y a peu de rubriques |
|
| 65 | - if ( |
|
| 66 | - _SPIP_AJAX < 1 |
|
| 67 | - or $type == 'breve' |
|
| 68 | - or sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES |
|
| 69 | - ) { |
|
| 70 | - return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem); |
|
| 71 | - } else { |
|
| 72 | - return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do); |
|
| 73 | - } |
|
| 58 | + if (sql_countsel('spip_rubriques') < 1) { |
|
| 59 | + return ''; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Mode sans Ajax : |
|
| 63 | + // - soit parce que le cookie ajax n'est pas la |
|
| 64 | + // - soit parce qu'il y a peu de rubriques |
|
| 65 | + if ( |
|
| 66 | + _SPIP_AJAX < 1 |
|
| 67 | + or $type == 'breve' |
|
| 68 | + or sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES |
|
| 69 | + ) { |
|
| 70 | + return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem); |
|
| 71 | + } else { |
|
| 72 | + return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do); |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // compatibilite pour extensions qui utilisaient l'ancien nom |
@@ -87,17 +87,17 @@ discard block |
||
| 87 | 87 | **/ |
| 88 | 88 | function style_menu_rubriques($i) { |
| 89 | 89 | |
| 90 | - $espace = ''; |
|
| 91 | - $style = ''; |
|
| 92 | - for ($count = 1; $count <= $i; $count++) { |
|
| 93 | - $espace .= ' '; |
|
| 94 | - } |
|
| 95 | - if ($i == 1) { |
|
| 96 | - $espace = ''; |
|
| 97 | - } |
|
| 98 | - $class = "niveau_$i"; |
|
| 99 | - |
|
| 100 | - return [$class, $style, $espace]; |
|
| 90 | + $espace = ''; |
|
| 91 | + $style = ''; |
|
| 92 | + for ($count = 1; $count <= $i; $count++) { |
|
| 93 | + $espace .= ' '; |
|
| 94 | + } |
|
| 95 | + if ($i == 1) { |
|
| 96 | + $espace = ''; |
|
| 97 | + } |
|
| 98 | + $class = "niveau_$i"; |
|
| 99 | + |
|
| 100 | + return [$class, $style, $espace]; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -121,60 +121,60 @@ discard block |
||
| 121 | 121 | * Code HTML du sélecteur |
| 122 | 122 | **/ |
| 123 | 123 | function sous_menu_rubriques($id_rubrique, $root, $niv, &$data, &$enfants, $exclus, $restreint, $type) { |
| 124 | - static $decalage_secteur; |
|
| 125 | - |
|
| 126 | - // Si on a demande l'exclusion ne pas descendre dans la rubrique courante |
|
| 127 | - if ( |
|
| 128 | - $exclus > 0 |
|
| 129 | - and $root == $exclus |
|
| 130 | - ) { |
|
| 131 | - return ''; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // en fonction du niveau faire un affichage plus ou moins kikoo |
|
| 135 | - |
|
| 136 | - // selected ? |
|
| 137 | - $selected = ($root == $id_rubrique) ? ' selected="selected"' : ''; |
|
| 138 | - |
|
| 139 | - // le style en fonction de la profondeur |
|
| 140 | - list($class, $style, $espace) = style_menu_rubriques($niv); |
|
| 141 | - |
|
| 142 | - $class .= ' selec_rub'; |
|
| 143 | - |
|
| 144 | - // creer l'<option> pour la rubrique $root |
|
| 145 | - |
|
| 146 | - if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
|
| 147 | - $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
|
| 148 | - . $data[$root] |
|
| 149 | - . '</option>' . "\n"; |
|
| 150 | - } else { |
|
| 151 | - $r = ''; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // et le sous-menu pour ses enfants |
|
| 155 | - $sous = ''; |
|
| 156 | - if (isset($enfants[$root])) { |
|
| 157 | - foreach ($enfants[$root] as $sousrub) { |
|
| 158 | - $sous .= sous_menu_rubriques( |
|
| 159 | - $id_rubrique, |
|
| 160 | - $sousrub, |
|
| 161 | - $niv + 1, |
|
| 162 | - $data, |
|
| 163 | - $enfants, |
|
| 164 | - $exclus, |
|
| 165 | - $restreint, |
|
| 166 | - $type |
|
| 167 | - ); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques |
|
| 172 | - if ($restreint and $root != $id_rubrique and !autoriser('publierdans', 'rubrique', $root)) { |
|
| 173 | - return $sous; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // et voila le travail |
|
| 177 | - return $r . $sous; |
|
| 124 | + static $decalage_secteur; |
|
| 125 | + |
|
| 126 | + // Si on a demande l'exclusion ne pas descendre dans la rubrique courante |
|
| 127 | + if ( |
|
| 128 | + $exclus > 0 |
|
| 129 | + and $root == $exclus |
|
| 130 | + ) { |
|
| 131 | + return ''; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // en fonction du niveau faire un affichage plus ou moins kikoo |
|
| 135 | + |
|
| 136 | + // selected ? |
|
| 137 | + $selected = ($root == $id_rubrique) ? ' selected="selected"' : ''; |
|
| 138 | + |
|
| 139 | + // le style en fonction de la profondeur |
|
| 140 | + list($class, $style, $espace) = style_menu_rubriques($niv); |
|
| 141 | + |
|
| 142 | + $class .= ' selec_rub'; |
|
| 143 | + |
|
| 144 | + // creer l'<option> pour la rubrique $root |
|
| 145 | + |
|
| 146 | + if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
|
| 147 | + $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
|
| 148 | + . $data[$root] |
|
| 149 | + . '</option>' . "\n"; |
|
| 150 | + } else { |
|
| 151 | + $r = ''; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // et le sous-menu pour ses enfants |
|
| 155 | + $sous = ''; |
|
| 156 | + if (isset($enfants[$root])) { |
|
| 157 | + foreach ($enfants[$root] as $sousrub) { |
|
| 158 | + $sous .= sous_menu_rubriques( |
|
| 159 | + $id_rubrique, |
|
| 160 | + $sousrub, |
|
| 161 | + $niv + 1, |
|
| 162 | + $data, |
|
| 163 | + $enfants, |
|
| 164 | + $exclus, |
|
| 165 | + $restreint, |
|
| 166 | + $type |
|
| 167 | + ); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques |
|
| 172 | + if ($restreint and $root != $id_rubrique and !autoriser('publierdans', 'rubrique', $root)) { |
|
| 173 | + return $sous; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // et voila le travail |
|
| 177 | + return $r . $sous; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -195,74 +195,74 @@ discard block |
||
| 195 | 195 | * Code HTML du sélecteur |
| 196 | 196 | **/ |
| 197 | 197 | function selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem = 0) { |
| 198 | - $data = []; |
|
| 199 | - if ($type == 'rubrique' and autoriser('publierdans', 'rubrique', 0)) { |
|
| 200 | - $data[0] = _T('info_racine_site'); |
|
| 201 | - } |
|
| 202 | - # premier choix = neant |
|
| 203 | - # si auteur (rubriques restreintes) |
|
| 204 | - # ou si creation avec id_rubrique=0 |
|
| 205 | - elseif ($type == 'auteur' or !$id_rubrique) { |
|
| 206 | - $data[0] = ' '; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // |
|
| 210 | - // creer une structure contenant toute l'arborescence |
|
| 211 | - // |
|
| 212 | - |
|
| 213 | - include_spip('base/abstract_sql'); |
|
| 214 | - $q = sql_select( |
|
| 215 | - 'id_rubrique, id_parent, titre, statut, lang, langue_choisie', |
|
| 216 | - 'spip_rubriques', |
|
| 217 | - ($type == 'breve' ? ' id_parent=0 ' : ''), |
|
| 218 | - '', |
|
| 219 | - '0+titre,titre' |
|
| 220 | - ); |
|
| 221 | - while ($r = sql_fetch($q)) { |
|
| 222 | - if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
|
| 223 | - // titre largeur maxi a 50 |
|
| 224 | - $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 225 | - if ( |
|
| 226 | - $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 227 | - and ($r['langue_choisie'] == 'oui' or $r['id_parent'] == 0) |
|
| 228 | - ) { |
|
| 229 | - $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 230 | - } |
|
| 231 | - $data[$r['id_rubrique']] = $titre; |
|
| 232 | - $enfants[$r['id_parent']][] = $r['id_rubrique']; |
|
| 233 | - if ($id_rubrique == $r['id_rubrique']) { |
|
| 234 | - $id_parent = $r['id_parent']; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - // si une seule rubrique comme choix possible, |
|
| 240 | - // inutile de mettre le selecteur sur un choix vide par defaut |
|
| 241 | - // sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas |
|
| 242 | - if ( |
|
| 243 | - count($data) == 2 |
|
| 244 | - and isset($data[0]) |
|
| 245 | - and !in_array($type, ['auteur', 'rubrique']) |
|
| 246 | - and !$id_rubrique |
|
| 247 | - ) { |
|
| 248 | - unset($data[0]); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - $opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type); |
|
| 253 | - $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
|
| 254 | - |
|
| 255 | - if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
|
| 256 | - $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 257 | - } else { |
|
| 258 | - $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - # message pour neuneus (a supprimer ?) |
|
| 198 | + $data = []; |
|
| 199 | + if ($type == 'rubrique' and autoriser('publierdans', 'rubrique', 0)) { |
|
| 200 | + $data[0] = _T('info_racine_site'); |
|
| 201 | + } |
|
| 202 | + # premier choix = neant |
|
| 203 | + # si auteur (rubriques restreintes) |
|
| 204 | + # ou si creation avec id_rubrique=0 |
|
| 205 | + elseif ($type == 'auteur' or !$id_rubrique) { |
|
| 206 | + $data[0] = ' '; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // |
|
| 210 | + // creer une structure contenant toute l'arborescence |
|
| 211 | + // |
|
| 212 | + |
|
| 213 | + include_spip('base/abstract_sql'); |
|
| 214 | + $q = sql_select( |
|
| 215 | + 'id_rubrique, id_parent, titre, statut, lang, langue_choisie', |
|
| 216 | + 'spip_rubriques', |
|
| 217 | + ($type == 'breve' ? ' id_parent=0 ' : ''), |
|
| 218 | + '', |
|
| 219 | + '0+titre,titre' |
|
| 220 | + ); |
|
| 221 | + while ($r = sql_fetch($q)) { |
|
| 222 | + if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
|
| 223 | + // titre largeur maxi a 50 |
|
| 224 | + $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 225 | + if ( |
|
| 226 | + $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 227 | + and ($r['langue_choisie'] == 'oui' or $r['id_parent'] == 0) |
|
| 228 | + ) { |
|
| 229 | + $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 230 | + } |
|
| 231 | + $data[$r['id_rubrique']] = $titre; |
|
| 232 | + $enfants[$r['id_parent']][] = $r['id_rubrique']; |
|
| 233 | + if ($id_rubrique == $r['id_rubrique']) { |
|
| 234 | + $id_parent = $r['id_parent']; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + // si une seule rubrique comme choix possible, |
|
| 240 | + // inutile de mettre le selecteur sur un choix vide par defaut |
|
| 241 | + // sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas |
|
| 242 | + if ( |
|
| 243 | + count($data) == 2 |
|
| 244 | + and isset($data[0]) |
|
| 245 | + and !in_array($type, ['auteur', 'rubrique']) |
|
| 246 | + and !$id_rubrique |
|
| 247 | + ) { |
|
| 248 | + unset($data[0]); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + $opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type); |
|
| 253 | + $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
|
| 254 | + |
|
| 255 | + if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
|
| 256 | + $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 257 | + } else { |
|
| 258 | + $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + # message pour neuneus (a supprimer ?) |
|
| 262 | 262 | # if ($type != 'auteur' AND $type != 'breve') |
| 263 | 263 | # $r .= "\n<br />"._T('texte_rappel_selection_champs'); |
| 264 | 264 | |
| 265 | - return $r; |
|
| 265 | + return $r; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -296,26 +296,26 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 298 | 298 | |
| 299 | - if ($id_rubrique) { |
|
| 300 | - $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 301 | - } else { |
|
| 302 | - if ($type == 'auteur') { |
|
| 303 | - $titre = ' '; |
|
| 304 | - } else { |
|
| 305 | - $titre = _T('info_racine_site'); |
|
| 306 | - } |
|
| 307 | - } |
|
| 299 | + if ($id_rubrique) { |
|
| 300 | + $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 301 | + } else { |
|
| 302 | + if ($type == 'auteur') { |
|
| 303 | + $titre = ' '; |
|
| 304 | + } else { |
|
| 305 | + $titre = _T('info_racine_site'); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - $titre = str_replace('&', '&', entites_html(textebrut(typo($titre)))); |
|
| 310 | - $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 309 | + $titre = str_replace('&', '&', entites_html(textebrut(typo($titre)))); |
|
| 310 | + $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 311 | 311 | |
| 312 | - $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
|
| 313 | - . (!$idem ? '' : "&exclus=$idem") |
|
| 314 | - . ($restreint ? '' : '&racine=oui') |
|
| 315 | - . (isset($GLOBALS['var_profile']) ? '&var_profile=1' : '')); |
|
| 312 | + $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
|
| 313 | + . (!$idem ? '' : "&exclus=$idem") |
|
| 314 | + . ($restreint ? '' : '&racine=oui') |
|
| 315 | + . (isset($GLOBALS['var_profile']) ? '&var_profile=1' : '')); |
|
| 316 | 316 | |
| 317 | 317 | |
| 318 | - return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique); |
|
| 318 | + return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -345,30 +345,30 @@ discard block |
||
| 345 | 345 | * Code HTML du sélecteur de rubrique AJAX |
| 346 | 346 | **/ |
| 347 | 347 | function construire_selecteur($url, $js, $idom, $name, $init = '', $id = 0) { |
| 348 | - $icone = (strpos($idom, 'auteur') !== false) ? 'auteur-24.png' : 'rechercher-20.png'; |
|
| 349 | - // si icone de recherche on embed le svg |
|
| 350 | - $balise = ($icone === 'rechercher-20.png' ? chercher_filtre('balise_svg') : chercher_filtre('balise_img')); |
|
| 351 | - $img_icone = $balise(chemin_image($icone, _T('titre_image_selecteur'))); |
|
| 352 | - |
|
| 353 | - return |
|
| 354 | - "<div class='rubrique_actuelle'><a href='#' class='rubrique-search' role='button' style='display:inline-flex;vertical-align:middle;' onclick=\"" |
|
| 355 | - . $js |
|
| 356 | - . " jQuery(this).toggleClass('toggled'); " |
|
| 357 | - . "return charger_node_url_si_vide('" |
|
| 358 | - . $url |
|
| 359 | - . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 360 | - . $img_icone |
|
| 361 | - . "</a><img src='" |
|
| 362 | - . chemin_image('loader.svg') |
|
| 363 | - . "' class='loader' id='img_" |
|
| 364 | - . $idom |
|
| 365 | - . "'\nstyle='visibility: hidden;' alt='*' />" |
|
| 366 | - . "<input id='titreparent' name='titreparent' class='text'" |
|
| 367 | - . $init |
|
| 368 | - . ' />' |
|
| 369 | - . "<input type='hidden' id='$name' name='$name' value='" |
|
| 370 | - . $id |
|
| 371 | - . "' /><div class='nettoyeur'></div></div><div id='" |
|
| 372 | - . $idom |
|
| 373 | - . "'\nstyle='display: none;'></div>"; |
|
| 348 | + $icone = (strpos($idom, 'auteur') !== false) ? 'auteur-24.png' : 'rechercher-20.png'; |
|
| 349 | + // si icone de recherche on embed le svg |
|
| 350 | + $balise = ($icone === 'rechercher-20.png' ? chercher_filtre('balise_svg') : chercher_filtre('balise_img')); |
|
| 351 | + $img_icone = $balise(chemin_image($icone, _T('titre_image_selecteur'))); |
|
| 352 | + |
|
| 353 | + return |
|
| 354 | + "<div class='rubrique_actuelle'><a href='#' class='rubrique-search' role='button' style='display:inline-flex;vertical-align:middle;' onclick=\"" |
|
| 355 | + . $js |
|
| 356 | + . " jQuery(this).toggleClass('toggled'); " |
|
| 357 | + . "return charger_node_url_si_vide('" |
|
| 358 | + . $url |
|
| 359 | + . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 360 | + . $img_icone |
|
| 361 | + . "</a><img src='" |
|
| 362 | + . chemin_image('loader.svg') |
|
| 363 | + . "' class='loader' id='img_" |
|
| 364 | + . $idom |
|
| 365 | + . "'\nstyle='visibility: hidden;' alt='*' />" |
|
| 366 | + . "<input id='titreparent' name='titreparent' class='text'" |
|
| 367 | + . $init |
|
| 368 | + . ' />' |
|
| 369 | + . "<input type='hidden' id='$name' name='$name' value='" |
|
| 370 | + . $id |
|
| 371 | + . "' /><div class='nettoyeur'></div></div><div id='" |
|
| 372 | + . $idom |
|
| 373 | + . "'\nstyle='display: none;'></div>"; |
|
| 374 | 374 | } |
@@ -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 | /** |
@@ -75,28 +75,28 @@ discard block |
||
| 75 | 75 | * @return |
| 76 | 76 | **/ |
| 77 | 77 | function inc_genie_dist($taches = []) { |
| 78 | - include_spip('inc/queue'); |
|
| 79 | - |
|
| 80 | - if (_request('exec') == 'job_queue') { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $force_jobs = []; |
|
| 85 | - // l'ancienne facon de lancer une tache cron immediatement |
|
| 86 | - // etait de la passer en parametre a ing_genie_dist |
|
| 87 | - // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 88 | - foreach ($taches as $function => $period) { |
|
| 89 | - $force_jobs[] = queue_add_job( |
|
| 90 | - $function, |
|
| 91 | - _T('tache_cron_asap', ['function' => $function]), |
|
| 92 | - [time() - abs($period)], |
|
| 93 | - 'genie/' |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // et on passe la main a la gestion de la queue ! |
|
| 98 | - // en forcant eventuellement les jobs ajoute a l'instant |
|
| 99 | - return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 78 | + include_spip('inc/queue'); |
|
| 79 | + |
|
| 80 | + if (_request('exec') == 'job_queue') { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $force_jobs = []; |
|
| 85 | + // l'ancienne facon de lancer une tache cron immediatement |
|
| 86 | + // etait de la passer en parametre a ing_genie_dist |
|
| 87 | + // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 88 | + foreach ($taches as $function => $period) { |
|
| 89 | + $force_jobs[] = queue_add_job( |
|
| 90 | + $function, |
|
| 91 | + _T('tache_cron_asap', ['function' => $function]), |
|
| 92 | + [time() - abs($period)], |
|
| 93 | + 'genie/' |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // et on passe la main a la gestion de la queue ! |
|
| 98 | + // en forcant eventuellement les jobs ajoute a l'instant |
|
| 99 | + return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | // |
@@ -110,33 +110,33 @@ discard block |
||
| 110 | 110 | // https://code.spip.net/@taches_generales |
| 111 | 111 | function taches_generales($taches_generales = []) { |
| 112 | 112 | |
| 113 | - // verifier que toutes les taches cron sont planifiees |
|
| 114 | - // c'est une tache cron ! |
|
| 115 | - $taches_generales['queue_watch'] = 3600 * 24; |
|
| 113 | + // verifier que toutes les taches cron sont planifiees |
|
| 114 | + // c'est une tache cron ! |
|
| 115 | + $taches_generales['queue_watch'] = 3600 * 24; |
|
| 116 | 116 | |
| 117 | - // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 118 | - // est fait au coup par coup a present |
|
| 119 | - // $taches_generales['rubriques'] = 3600; |
|
| 117 | + // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 118 | + // est fait au coup par coup a present |
|
| 119 | + // $taches_generales['rubriques'] = 3600; |
|
| 120 | 120 | |
| 121 | - // Optimisation de la base |
|
| 122 | - $taches_generales['optimiser'] = 3600 * 48; |
|
| 121 | + // Optimisation de la base |
|
| 122 | + $taches_generales['optimiser'] = 3600 * 48; |
|
| 123 | 123 | |
| 124 | - // nouveautes |
|
| 125 | - if ( |
|
| 126 | - isset($GLOBALS['meta']['adresse_neuf']) and $GLOBALS['meta']['adresse_neuf'] |
|
| 127 | - and $GLOBALS['meta']['jours_neuf'] |
|
| 128 | - and ($GLOBALS['meta']['quoi_de_neuf'] == 'oui') |
|
| 129 | - ) { |
|
| 130 | - $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 131 | - } |
|
| 124 | + // nouveautes |
|
| 125 | + if ( |
|
| 126 | + isset($GLOBALS['meta']['adresse_neuf']) and $GLOBALS['meta']['adresse_neuf'] |
|
| 127 | + and $GLOBALS['meta']['jours_neuf'] |
|
| 128 | + and ($GLOBALS['meta']['quoi_de_neuf'] == 'oui') |
|
| 129 | + ) { |
|
| 130 | + $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - // maintenance (ajax, verifications diverses) |
|
| 134 | - $taches_generales['maintenance'] = 3600 * 2; |
|
| 133 | + // maintenance (ajax, verifications diverses) |
|
| 134 | + $taches_generales['maintenance'] = 3600 * 2; |
|
| 135 | 135 | |
| 136 | - // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 137 | - $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 136 | + // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 137 | + $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 138 | 138 | |
| 139 | - return pipeline('taches_generales_cron', $taches_generales); |
|
| 139 | + return pipeline('taches_generales_cron', $taches_generales); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -152,22 +152,22 @@ discard block |
||
| 152 | 152 | * @return int |
| 153 | 153 | */ |
| 154 | 154 | function genie_queue_watch_dist() { |
| 155 | - static $deja_la = false; |
|
| 156 | - if ($deja_la) { |
|
| 157 | - return; |
|
| 158 | - } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 159 | - $deja_la = true; |
|
| 160 | - $taches = taches_generales(); |
|
| 161 | - $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 162 | - $programmees = array_column($programmees, 'fonction'); |
|
| 163 | - foreach ($taches as $tache => $periode) { |
|
| 164 | - if (!in_array($tache, $programmees)) { |
|
| 165 | - queue_genie_replan_job($tache, $periode, time() - round(rand(1, $periode)), 0); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - $deja_la = false; |
|
| 169 | - |
|
| 170 | - return 1; |
|
| 155 | + static $deja_la = false; |
|
| 156 | + if ($deja_la) { |
|
| 157 | + return; |
|
| 158 | + } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 159 | + $deja_la = true; |
|
| 160 | + $taches = taches_generales(); |
|
| 161 | + $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 162 | + $programmees = array_column($programmees, 'fonction'); |
|
| 163 | + foreach ($taches as $tache => $periode) { |
|
| 164 | + if (!in_array($tache, $programmees)) { |
|
| 165 | + queue_genie_replan_job($tache, $periode, time() - round(rand(1, $periode)), 0); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + $deja_la = false; |
|
| 169 | + |
|
| 170 | + return 1; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -188,32 +188,32 @@ discard block |
||
| 188 | 188 | * @return void |
| 189 | 189 | */ |
| 190 | 190 | function queue_genie_replan_job($function, $period, $last = 0, $time = null, $priority = 0) { |
| 191 | - static $done = []; |
|
| 192 | - if (isset($done[$function])) { |
|
| 193 | - return; |
|
| 194 | - } |
|
| 195 | - $done[$function] = true; |
|
| 196 | - if (is_null($time)) { |
|
| 197 | - $time = time(); |
|
| 198 | - if ($last) { |
|
| 199 | - $time = max($last + $period, $time); |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - if (!$last) { |
|
| 203 | - $last = $time - $period; |
|
| 204 | - } |
|
| 205 | - spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 206 | - include_spip('inc/queue'); |
|
| 207 | - // on replanifie un job cron |
|
| 208 | - // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 209 | - // independament de l'argument |
|
| 210 | - queue_add_job( |
|
| 211 | - $function, |
|
| 212 | - _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 213 | - [$last], |
|
| 214 | - 'genie/', |
|
| 215 | - 'function_only', |
|
| 216 | - $time, |
|
| 217 | - $priority |
|
| 218 | - ); |
|
| 191 | + static $done = []; |
|
| 192 | + if (isset($done[$function])) { |
|
| 193 | + return; |
|
| 194 | + } |
|
| 195 | + $done[$function] = true; |
|
| 196 | + if (is_null($time)) { |
|
| 197 | + $time = time(); |
|
| 198 | + if ($last) { |
|
| 199 | + $time = max($last + $period, $time); |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + if (!$last) { |
|
| 203 | + $last = $time - $period; |
|
| 204 | + } |
|
| 205 | + spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 206 | + include_spip('inc/queue'); |
|
| 207 | + // on replanifie un job cron |
|
| 208 | + // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 209 | + // independament de l'argument |
|
| 210 | + queue_add_job( |
|
| 211 | + $function, |
|
| 212 | + _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 213 | + [$last], |
|
| 214 | + 'genie/', |
|
| 215 | + 'function_only', |
|
| 216 | + $time, |
|
| 217 | + $priority |
|
| 218 | + ); |
|
| 219 | 219 | } |
@@ -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 | // Les parametres generaux du site sont dans une table SQL; |
@@ -28,50 +28,50 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | // https://code.spip.net/@inc_meta_dist |
| 30 | 30 | function inc_meta_dist($table = 'meta') { |
| 31 | - // Lire les meta, en cache si present, valide et lisible |
|
| 32 | - // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 33 | - $cache = cache_meta($table); |
|
| 31 | + // Lire les meta, en cache si present, valide et lisible |
|
| 32 | + // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 33 | + $cache = cache_meta($table); |
|
| 34 | 34 | |
| 35 | - if ( |
|
| 36 | - (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) |
|
| 37 | - and $new = jeune_fichier($cache, _META_CACHE_TIME) |
|
| 38 | - and lire_fichier_securise($cache, $meta) |
|
| 39 | - and $meta = @unserialize($meta) |
|
| 40 | - ) { |
|
| 41 | - $GLOBALS[$table] = $meta; |
|
| 42 | - } |
|
| 35 | + if ( |
|
| 36 | + (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) |
|
| 37 | + and $new = jeune_fichier($cache, _META_CACHE_TIME) |
|
| 38 | + and lire_fichier_securise($cache, $meta) |
|
| 39 | + and $meta = @unserialize($meta) |
|
| 40 | + ) { |
|
| 41 | + $GLOBALS[$table] = $meta; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - if ( |
|
| 45 | - isset($GLOBALS[$table]['touch']) |
|
| 46 | - and ($GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME) |
|
| 47 | - ) { |
|
| 48 | - $GLOBALS[$table] = []; |
|
| 49 | - } |
|
| 50 | - // sinon lire en base |
|
| 51 | - if (!$GLOBALS[$table]) { |
|
| 52 | - $new = !lire_metas($table); |
|
| 53 | - } |
|
| 44 | + if ( |
|
| 45 | + isset($GLOBALS[$table]['touch']) |
|
| 46 | + and ($GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME) |
|
| 47 | + ) { |
|
| 48 | + $GLOBALS[$table] = []; |
|
| 49 | + } |
|
| 50 | + // sinon lire en base |
|
| 51 | + if (!$GLOBALS[$table]) { |
|
| 52 | + $new = !lire_metas($table); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 56 | - if ( |
|
| 57 | - (test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 58 | - and $GLOBALS[$table] |
|
| 59 | - and (time() > _RENOUVELLE_ALEA + (isset($GLOBALS['meta']['alea_ephemere_date']) ? $GLOBALS['meta']['alea_ephemere_date'] : 0)) |
|
| 60 | - ) { |
|
| 61 | - // si on n'a pas l'acces en ecriture sur le cache, |
|
| 62 | - // ne pas renouveller l'alea sinon le cache devient faux |
|
| 63 | - if (supprimer_fichier($cache)) { |
|
| 64 | - include_spip('inc/acces'); |
|
| 65 | - renouvelle_alea(); |
|
| 66 | - $new = false; |
|
| 67 | - } else { |
|
| 68 | - spip_log("impossible d'ecrire dans " . $cache); |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - // et refaire le cache si on a du lire en base |
|
| 72 | - if (!$new) { |
|
| 73 | - touch_meta(false, $table); |
|
| 74 | - } |
|
| 55 | + // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 56 | + if ( |
|
| 57 | + (test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 58 | + and $GLOBALS[$table] |
|
| 59 | + and (time() > _RENOUVELLE_ALEA + (isset($GLOBALS['meta']['alea_ephemere_date']) ? $GLOBALS['meta']['alea_ephemere_date'] : 0)) |
|
| 60 | + ) { |
|
| 61 | + // si on n'a pas l'acces en ecriture sur le cache, |
|
| 62 | + // ne pas renouveller l'alea sinon le cache devient faux |
|
| 63 | + if (supprimer_fichier($cache)) { |
|
| 64 | + include_spip('inc/acces'); |
|
| 65 | + renouvelle_alea(); |
|
| 66 | + $new = false; |
|
| 67 | + } else { |
|
| 68 | + spip_log("impossible d'ecrire dans " . $cache); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + // et refaire le cache si on a du lire en base |
|
| 72 | + if (!$new) { |
|
| 73 | + touch_meta(false, $table); |
|
| 74 | + } |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // fonctions aussi appelees a l'install ==> spip_query en premiere requete |
@@ -80,39 +80,39 @@ discard block |
||
| 80 | 80 | // https://code.spip.net/@lire_metas |
| 81 | 81 | function lire_metas($table = 'meta') { |
| 82 | 82 | |
| 83 | - if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 84 | - include_spip('base/abstract_sql'); |
|
| 85 | - $GLOBALS[$table] = []; |
|
| 86 | - while ($row = sql_fetch($result)) { |
|
| 87 | - $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 88 | - } |
|
| 89 | - sql_free($result); |
|
| 83 | + if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 84 | + include_spip('base/abstract_sql'); |
|
| 85 | + $GLOBALS[$table] = []; |
|
| 86 | + while ($row = sql_fetch($result)) { |
|
| 87 | + $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 88 | + } |
|
| 89 | + sql_free($result); |
|
| 90 | 90 | |
| 91 | - if ( |
|
| 92 | - !isset($GLOBALS[$table]['charset']) |
|
| 93 | - or !$GLOBALS[$table]['charset'] |
|
| 94 | - or $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 95 | - ) { |
|
| 96 | - ecrire_meta('charset', _DEFAULT_CHARSET, null, $table); |
|
| 97 | - } |
|
| 91 | + if ( |
|
| 92 | + !isset($GLOBALS[$table]['charset']) |
|
| 93 | + or !$GLOBALS[$table]['charset'] |
|
| 94 | + or $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 95 | + ) { |
|
| 96 | + ecrire_meta('charset', _DEFAULT_CHARSET, null, $table); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - // noter cette table de configuration dans les meta de SPIP |
|
| 100 | - if ($table !== 'meta') { |
|
| 101 | - $liste = []; |
|
| 102 | - if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 103 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 104 | - } |
|
| 105 | - if (!$liste) { |
|
| 106 | - $liste = []; |
|
| 107 | - } |
|
| 108 | - if (!in_array($table, $liste)) { |
|
| 109 | - $liste[] = $table; |
|
| 110 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - } |
|
| 99 | + // noter cette table de configuration dans les meta de SPIP |
|
| 100 | + if ($table !== 'meta') { |
|
| 101 | + $liste = []; |
|
| 102 | + if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 103 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 104 | + } |
|
| 105 | + if (!$liste) { |
|
| 106 | + $liste = []; |
|
| 107 | + } |
|
| 108 | + if (!in_array($table, $liste)) { |
|
| 109 | + $liste[] = $table; |
|
| 110 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - return isset($GLOBALS[$table]) ? $GLOBALS[$table] : null; |
|
| 115 | + return isset($GLOBALS[$table]) ? $GLOBALS[$table] : null; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
@@ -126,22 +126,22 @@ discard block |
||
| 126 | 126 | * Table SQL d'enregistrement des meta. |
| 127 | 127 | **/ |
| 128 | 128 | function touch_meta($antidate = false, $table = 'meta') { |
| 129 | - $file = cache_meta($table); |
|
| 130 | - if (!$antidate or !@touch($file, $antidate)) { |
|
| 131 | - $r = isset($GLOBALS[$table]) ? $GLOBALS[$table] : []; |
|
| 132 | - if ($table == 'meta') { |
|
| 133 | - unset($r['alea_ephemere']); |
|
| 134 | - unset($r['alea_ephemere_ancien']); |
|
| 135 | - // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 136 | - // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 137 | - // meme si son squelette est en cache |
|
| 138 | - //unset($r['secret_du_site']); |
|
| 139 | - if ($antidate) { |
|
| 140 | - $r['touch'] = $antidate; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - ecrire_fichier_securise($file, serialize($r)); |
|
| 144 | - } |
|
| 129 | + $file = cache_meta($table); |
|
| 130 | + if (!$antidate or !@touch($file, $antidate)) { |
|
| 131 | + $r = isset($GLOBALS[$table]) ? $GLOBALS[$table] : []; |
|
| 132 | + if ($table == 'meta') { |
|
| 133 | + unset($r['alea_ephemere']); |
|
| 134 | + unset($r['alea_ephemere_ancien']); |
|
| 135 | + // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 136 | + // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 137 | + // meme si son squelette est en cache |
|
| 138 | + //unset($r['secret_du_site']); |
|
| 139 | + if ($antidate) { |
|
| 140 | + $r['touch'] = $antidate; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + ecrire_fichier_securise($file, serialize($r)); |
|
| 144 | + } |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -157,21 +157,21 @@ discard block |
||
| 157 | 157 | * Table SQL d'enregistrement de la meta. |
| 158 | 158 | **/ |
| 159 | 159 | function effacer_meta($nom, $table = 'meta') { |
| 160 | - // section critique sur le cache: |
|
| 161 | - // l'invalider avant et apres la MAJ de la BD |
|
| 162 | - // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 163 | - // et utiliser une statique pour eviter des acces disques a repetition |
|
| 164 | - static $touch = []; |
|
| 165 | - $antidate = time() - (_META_CACHE_TIME << 4); |
|
| 166 | - if (!isset($touch[$table])) { |
|
| 167 | - touch_meta($antidate, $table); |
|
| 168 | - } |
|
| 169 | - sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 170 | - unset($GLOBALS[$table][$nom]); |
|
| 171 | - if (!isset($touch[$table])) { |
|
| 172 | - touch_meta($antidate, $table); |
|
| 173 | - $touch[$table] = false; |
|
| 174 | - } |
|
| 160 | + // section critique sur le cache: |
|
| 161 | + // l'invalider avant et apres la MAJ de la BD |
|
| 162 | + // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 163 | + // et utiliser une statique pour eviter des acces disques a repetition |
|
| 164 | + static $touch = []; |
|
| 165 | + $antidate = time() - (_META_CACHE_TIME << 4); |
|
| 166 | + if (!isset($touch[$table])) { |
|
| 167 | + touch_meta($antidate, $table); |
|
| 168 | + } |
|
| 169 | + sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 170 | + unset($GLOBALS[$table][$nom]); |
|
| 171 | + if (!isset($touch[$table])) { |
|
| 172 | + touch_meta($antidate, $table); |
|
| 173 | + $touch[$table] = false; |
|
| 174 | + } |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -192,53 +192,53 @@ discard block |
||
| 192 | 192 | **/ |
| 193 | 193 | function ecrire_meta($nom, $valeur, $importable = null, $table = 'meta') { |
| 194 | 194 | |
| 195 | - static $touch = []; |
|
| 196 | - if (!$nom) { |
|
| 197 | - return; |
|
| 198 | - } |
|
| 199 | - include_spip('base/abstract_sql'); |
|
| 200 | - $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 201 | - // table pas encore installee, travailler en php seulement |
|
| 202 | - if (!$res) { |
|
| 203 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 195 | + static $touch = []; |
|
| 196 | + if (!$nom) { |
|
| 197 | + return; |
|
| 198 | + } |
|
| 199 | + include_spip('base/abstract_sql'); |
|
| 200 | + $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 201 | + // table pas encore installee, travailler en php seulement |
|
| 202 | + if (!$res) { |
|
| 203 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 204 | 204 | |
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - $row = sql_fetch($res); |
|
| 208 | - sql_free($res); |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + $row = sql_fetch($res); |
|
| 208 | + sql_free($res); |
|
| 209 | 209 | |
| 210 | - // ne pas invalider le cache si affectation a l'identique |
|
| 211 | - // (tant pis si impt aurait du changer) |
|
| 212 | - if ( |
|
| 213 | - $row and $valeur == $row['valeur'] |
|
| 214 | - and isset($GLOBALS[$table][$nom]) |
|
| 215 | - and $GLOBALS[$table][$nom] == $valeur |
|
| 216 | - ) { |
|
| 217 | - return; |
|
| 218 | - } |
|
| 210 | + // ne pas invalider le cache si affectation a l'identique |
|
| 211 | + // (tant pis si impt aurait du changer) |
|
| 212 | + if ( |
|
| 213 | + $row and $valeur == $row['valeur'] |
|
| 214 | + and isset($GLOBALS[$table][$nom]) |
|
| 215 | + and $GLOBALS[$table][$nom] == $valeur |
|
| 216 | + ) { |
|
| 217 | + return; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 221 | - // cf effacer pour comprendre le double touch |
|
| 222 | - $antidate = time() - (_META_CACHE_TIME << 1); |
|
| 223 | - if (!isset($touch[$table])) { |
|
| 224 | - touch_meta($antidate, $table); |
|
| 225 | - } |
|
| 226 | - $r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')]; |
|
| 227 | - // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 228 | - // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot |
|
| 229 | - // de lecture des descriptions des tables |
|
| 230 | - if ($importable and isset($row['impt'])) { |
|
| 231 | - $r['impt'] = sql_quote($importable, '', 'text'); |
|
| 232 | - } |
|
| 233 | - if ($row) { |
|
| 234 | - sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom)); |
|
| 235 | - } else { |
|
| 236 | - sql_insert('spip_' . $table, '(' . join(',', array_keys($r)) . ')', '(' . join(',', array_values($r)) . ')'); |
|
| 237 | - } |
|
| 238 | - if (!isset($touch[$table])) { |
|
| 239 | - touch_meta($antidate, $table); |
|
| 240 | - $touch[$table] = false; |
|
| 241 | - } |
|
| 220 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 221 | + // cf effacer pour comprendre le double touch |
|
| 222 | + $antidate = time() - (_META_CACHE_TIME << 1); |
|
| 223 | + if (!isset($touch[$table])) { |
|
| 224 | + touch_meta($antidate, $table); |
|
| 225 | + } |
|
| 226 | + $r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')]; |
|
| 227 | + // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 228 | + // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot |
|
| 229 | + // de lecture des descriptions des tables |
|
| 230 | + if ($importable and isset($row['impt'])) { |
|
| 231 | + $r['impt'] = sql_quote($importable, '', 'text'); |
|
| 232 | + } |
|
| 233 | + if ($row) { |
|
| 234 | + sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom)); |
|
| 235 | + } else { |
|
| 236 | + sql_insert('spip_' . $table, '(' . join(',', array_keys($r)) . ')', '(' . join(',', array_values($r)) . ')'); |
|
| 237 | + } |
|
| 238 | + if (!isset($touch[$table])) { |
|
| 239 | + touch_meta($antidate, $table); |
|
| 240 | + $touch[$table] = false; |
|
| 241 | + } |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * Nom du fichier cache |
| 251 | 251 | **/ |
| 252 | 252 | function cache_meta($table = 'meta') { |
| 253 | - return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 253 | + return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -259,14 +259,14 @@ discard block |
||
| 259 | 259 | * @param string $table |
| 260 | 260 | */ |
| 261 | 261 | function installer_table_meta($table) { |
| 262 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 263 | - if (!$trouver_table("spip_$table")) { |
|
| 264 | - include_spip('base/auxiliaires'); |
|
| 265 | - include_spip('base/create'); |
|
| 266 | - creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 267 | - $trouver_table(''); |
|
| 268 | - } |
|
| 269 | - lire_metas($table); |
|
| 262 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 263 | + if (!$trouver_table("spip_$table")) { |
|
| 264 | + include_spip('base/auxiliaires'); |
|
| 265 | + include_spip('base/create'); |
|
| 266 | + creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 267 | + $trouver_table(''); |
|
| 268 | + } |
|
| 269 | + lire_metas($table); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -278,47 +278,47 @@ discard block |
||
| 278 | 278 | * @param bool $force |
| 279 | 279 | */ |
| 280 | 280 | function supprimer_table_meta($table, $force = false) { |
| 281 | - if ($table !== 'meta') { |
|
| 282 | - // Vérifier le contenu restant de la table |
|
| 283 | - $nb_variables = sql_countsel("spip_$table"); |
|
| 281 | + if ($table !== 'meta') { |
|
| 282 | + // Vérifier le contenu restant de la table |
|
| 283 | + $nb_variables = sql_countsel("spip_$table"); |
|
| 284 | 284 | |
| 285 | - // Supprimer si : |
|
| 286 | - // - la table est vide |
|
| 287 | - // - ou limitée à la variable charset |
|
| 288 | - // - ou qu'on force la suppression |
|
| 289 | - if ( |
|
| 290 | - $force |
|
| 291 | - or !$nb_variables |
|
| 292 | - or ( |
|
| 293 | - ($nb_variables == 1) |
|
| 294 | - and isset($GLOBALS[$table]['charset']) |
|
| 295 | - ) |
|
| 296 | - ) { |
|
| 297 | - // Supprimer la table des globaleset de la base |
|
| 298 | - unset($GLOBALS[$table]); |
|
| 299 | - sql_drop_table("spip_$table"); |
|
| 300 | - // Supprimer le fichier cache |
|
| 301 | - include_spip('inc/flock'); |
|
| 302 | - $cache = cache_meta($table); |
|
| 303 | - supprimer_fichier($cache); |
|
| 285 | + // Supprimer si : |
|
| 286 | + // - la table est vide |
|
| 287 | + // - ou limitée à la variable charset |
|
| 288 | + // - ou qu'on force la suppression |
|
| 289 | + if ( |
|
| 290 | + $force |
|
| 291 | + or !$nb_variables |
|
| 292 | + or ( |
|
| 293 | + ($nb_variables == 1) |
|
| 294 | + and isset($GLOBALS[$table]['charset']) |
|
| 295 | + ) |
|
| 296 | + ) { |
|
| 297 | + // Supprimer la table des globaleset de la base |
|
| 298 | + unset($GLOBALS[$table]); |
|
| 299 | + sql_drop_table("spip_$table"); |
|
| 300 | + // Supprimer le fichier cache |
|
| 301 | + include_spip('inc/flock'); |
|
| 302 | + $cache = cache_meta($table); |
|
| 303 | + supprimer_fichier($cache); |
|
| 304 | 304 | |
| 305 | - // vider le cache des tables |
|
| 306 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 307 | - $trouver_table(''); |
|
| 305 | + // vider le cache des tables |
|
| 306 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 307 | + $trouver_table(''); |
|
| 308 | 308 | |
| 309 | - // Supprimer la table de la liste des tables de configuration autres que spip_meta |
|
| 310 | - if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 311 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 312 | - $cle = array_search($table, $liste); |
|
| 313 | - if ($cle !== false) { |
|
| 314 | - unset($liste[$cle]); |
|
| 315 | - if ($liste) { |
|
| 316 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 317 | - } else { |
|
| 318 | - effacer_meta('tables_config'); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - } |
|
| 309 | + // Supprimer la table de la liste des tables de configuration autres que spip_meta |
|
| 310 | + if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 311 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 312 | + $cle = array_search($table, $liste); |
|
| 313 | + if ($cle !== false) { |
|
| 314 | + unset($liste[$cle]); |
|
| 315 | + if ($liste) { |
|
| 316 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 317 | + } else { |
|
| 318 | + effacer_meta('tables_config'); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + } |
|
| 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 | // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 26 | 26 | // ne pas ecraser une definition perso dans mes_options |
| 27 | 27 | if (!isset($GLOBALS['ldap_attributes']) or !is_array($GLOBALS['ldap_attributes'])) { |
| 28 | - $GLOBALS['ldap_attributes'] = [ |
|
| 29 | - 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 30 | - 'nom' => 'cn', |
|
| 31 | - 'email' => 'mail', |
|
| 32 | - 'bio' => 'description' |
|
| 33 | - ]; |
|
| 28 | + $GLOBALS['ldap_attributes'] = [ |
|
| 29 | + 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 30 | + 'nom' => 'cn', |
|
| 31 | + 'email' => 'mail', |
|
| 32 | + 'bio' => 'description' |
|
| 33 | + ]; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -56,50 +56,50 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function auth_ldap_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 58 | 58 | |
| 59 | - #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 60 | - |
|
| 61 | - // Utilisateur connu ? |
|
| 62 | - // si http auth, inutile de reauthentifier: cela |
|
| 63 | - // ne marchera pas avec auth http autre que basic. |
|
| 64 | - $checkpass = isset($_SERVER['REMOTE_USER']) ? false : true; |
|
| 65 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 66 | - return []; |
|
| 67 | - } |
|
| 68 | - $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 69 | - |
|
| 70 | - // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 71 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | - |
|
| 73 | - if ($r) { |
|
| 74 | - return array_merge($r, $credentials_ldap); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // sinon importer les infos depuis LDAP, |
|
| 78 | - |
|
| 79 | - if ( |
|
| 80 | - $GLOBALS['meta']['ldap_statut_import'] |
|
| 81 | - and $desc = auth_ldap_retrouver($dn, [], $serveur) |
|
| 82 | - ) { |
|
| 83 | - // rajouter le statut indique a l'install |
|
| 84 | - $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 85 | - $desc['login'] = $login; |
|
| 86 | - $desc['source'] = 'ldap'; |
|
| 87 | - $desc['pass'] = ''; |
|
| 88 | - |
|
| 89 | - $r = sql_insertq('spip_auteurs', $desc, '', $serveur); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if ($r) { |
|
| 93 | - return array_merge( |
|
| 94 | - $credentials_ldap, |
|
| 95 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // sinon echec |
|
| 100 | - spip_log("Creation de l'auteur '$login' impossible"); |
|
| 101 | - |
|
| 102 | - return []; |
|
| 59 | + #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 60 | + |
|
| 61 | + // Utilisateur connu ? |
|
| 62 | + // si http auth, inutile de reauthentifier: cela |
|
| 63 | + // ne marchera pas avec auth http autre que basic. |
|
| 64 | + $checkpass = isset($_SERVER['REMOTE_USER']) ? false : true; |
|
| 65 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 66 | + return []; |
|
| 67 | + } |
|
| 68 | + $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 69 | + |
|
| 70 | + // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 71 | + $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | + |
|
| 73 | + if ($r) { |
|
| 74 | + return array_merge($r, $credentials_ldap); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // sinon importer les infos depuis LDAP, |
|
| 78 | + |
|
| 79 | + if ( |
|
| 80 | + $GLOBALS['meta']['ldap_statut_import'] |
|
| 81 | + and $desc = auth_ldap_retrouver($dn, [], $serveur) |
|
| 82 | + ) { |
|
| 83 | + // rajouter le statut indique a l'install |
|
| 84 | + $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 85 | + $desc['login'] = $login; |
|
| 86 | + $desc['source'] = 'ldap'; |
|
| 87 | + $desc['pass'] = ''; |
|
| 88 | + |
|
| 89 | + $r = sql_insertq('spip_auteurs', $desc, '', $serveur); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if ($r) { |
|
| 93 | + return array_merge( |
|
| 94 | + $credentials_ldap, |
|
| 95 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // sinon echec |
|
| 100 | + spip_log("Creation de l'auteur '$login' impossible"); |
|
| 101 | + |
|
| 102 | + return []; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -113,36 +113,36 @@ discard block |
||
| 113 | 113 | * @return array |
| 114 | 114 | */ |
| 115 | 115 | function auth_ldap_connect($serveur = '') { |
| 116 | - include_spip('base/connect_sql'); |
|
| 117 | - static $connexions_ldap = []; |
|
| 118 | - if (isset($connexions_ldap[$serveur])) { |
|
| 119 | - return $connexions_ldap[$serveur]; |
|
| 120 | - } |
|
| 121 | - $connexion = spip_connect($serveur); |
|
| 122 | - if (!is_array($connexion['ldap'])) { |
|
| 123 | - if ($connexion['authentification']['ldap']) { |
|
| 124 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 125 | - unset($GLOBALS['ldap_link']); |
|
| 126 | - if (is_readable($f)) { |
|
| 127 | - include_once($f); |
|
| 128 | - }; |
|
| 129 | - if (isset($GLOBALS['ldap_link'])) { |
|
| 130 | - $connexion['ldap'] = [ |
|
| 131 | - 'link' => $GLOBALS['ldap_link'], |
|
| 132 | - 'base' => $GLOBALS['ldap_base'] |
|
| 133 | - ]; |
|
| 134 | - } else { |
|
| 135 | - spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 136 | - } |
|
| 137 | - if (isset($GLOBALS['ldap_champs'])) { |
|
| 138 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 139 | - } |
|
| 140 | - } else { |
|
| 141 | - spip_log("connection LDAP $serveur inconnue"); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 116 | + include_spip('base/connect_sql'); |
|
| 117 | + static $connexions_ldap = []; |
|
| 118 | + if (isset($connexions_ldap[$serveur])) { |
|
| 119 | + return $connexions_ldap[$serveur]; |
|
| 120 | + } |
|
| 121 | + $connexion = spip_connect($serveur); |
|
| 122 | + if (!is_array($connexion['ldap'])) { |
|
| 123 | + if ($connexion['authentification']['ldap']) { |
|
| 124 | + $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 125 | + unset($GLOBALS['ldap_link']); |
|
| 126 | + if (is_readable($f)) { |
|
| 127 | + include_once($f); |
|
| 128 | + }; |
|
| 129 | + if (isset($GLOBALS['ldap_link'])) { |
|
| 130 | + $connexion['ldap'] = [ |
|
| 131 | + 'link' => $GLOBALS['ldap_link'], |
|
| 132 | + 'base' => $GLOBALS['ldap_base'] |
|
| 133 | + ]; |
|
| 134 | + } else { |
|
| 135 | + spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 136 | + } |
|
| 137 | + if (isset($GLOBALS['ldap_champs'])) { |
|
| 138 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + spip_log("connection LDAP $serveur inconnue"); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -156,52 +156,52 @@ discard block |
||
| 156 | 156 | * Le login trouvé ou chaine vide si non trouvé |
| 157 | 157 | */ |
| 158 | 158 | function auth_ldap_search($login, $pass, $checkpass = true, $serveur = '') { |
| 159 | - // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 160 | - $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 161 | - if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 162 | - return ''; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // verifier la connexion |
|
| 166 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 167 | - return ''; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $ldap_link = isset($ldap['link']) ? $ldap['link'] : null; |
|
| 171 | - $ldap_base = isset($ldap['base']) ? $ldap['base'] : null; |
|
| 172 | - $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 173 | - |
|
| 174 | - $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 175 | - |
|
| 176 | - // Tenter une recherche pour essayer de retrouver le DN |
|
| 177 | - foreach ($logins as $att) { |
|
| 178 | - $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 179 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 180 | - // Ne pas accepter les resultats si plus d'une entree |
|
| 181 | - // (on veut un attribut unique) |
|
| 182 | - |
|
| 183 | - if (is_array($info) and $info['count'] == 1) { |
|
| 184 | - $dn = $info[0]['dn']; |
|
| 185 | - if (!$checkpass) { |
|
| 186 | - return $dn; |
|
| 187 | - } |
|
| 188 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 189 | - return $dn; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ($checkpass and !isset($dn)) { |
|
| 195 | - // Si echec, essayer de deviner le DN |
|
| 196 | - foreach ($logins as $att) { |
|
| 197 | - $dn = "$att=$login_search, $ldap_base"; |
|
| 198 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 199 | - return "$att=$login_search, $ldap_base"; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return ''; |
|
| 159 | + // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 160 | + $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 161 | + if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 162 | + return ''; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // verifier la connexion |
|
| 166 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 167 | + return ''; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $ldap_link = isset($ldap['link']) ? $ldap['link'] : null; |
|
| 171 | + $ldap_base = isset($ldap['base']) ? $ldap['base'] : null; |
|
| 172 | + $desc = isset($ldap['attributes']) && $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes'] ; |
|
| 173 | + |
|
| 174 | + $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 175 | + |
|
| 176 | + // Tenter une recherche pour essayer de retrouver le DN |
|
| 177 | + foreach ($logins as $att) { |
|
| 178 | + $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 179 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 180 | + // Ne pas accepter les resultats si plus d'une entree |
|
| 181 | + // (on veut un attribut unique) |
|
| 182 | + |
|
| 183 | + if (is_array($info) and $info['count'] == 1) { |
|
| 184 | + $dn = $info[0]['dn']; |
|
| 185 | + if (!$checkpass) { |
|
| 186 | + return $dn; |
|
| 187 | + } |
|
| 188 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 189 | + return $dn; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ($checkpass and !isset($dn)) { |
|
| 195 | + // Si echec, essayer de deviner le DN |
|
| 196 | + foreach ($logins as $att) { |
|
| 197 | + $dn = "$att=$login_search, $ldap_base"; |
|
| 198 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 199 | + return "$att=$login_search, $ldap_base"; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return ''; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -213,40 +213,40 @@ discard block |
||
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | 215 | function auth_ldap_retrouver($dn, $desc = [], $serveur = '') { |
| 216 | - // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 216 | + // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 217 | 217 | |
| 218 | - if (!$ldap = spip_connect_ldap($serveur)) { |
|
| 219 | - spip_log("ldap $serveur injoignable"); |
|
| 218 | + if (!$ldap = spip_connect_ldap($serveur)) { |
|
| 219 | + spip_log("ldap $serveur injoignable"); |
|
| 220 | 220 | |
| 221 | - return []; |
|
| 222 | - } |
|
| 221 | + return []; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - $ldap_link = $ldap['link']; |
|
| 225 | - if (!$desc) { |
|
| 226 | - $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 227 | - unset($desc['login']); |
|
| 228 | - } |
|
| 229 | - $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 224 | + $ldap_link = $ldap['link']; |
|
| 225 | + if (!$desc) { |
|
| 226 | + $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 227 | + unset($desc['login']); |
|
| 228 | + } |
|
| 229 | + $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 230 | 230 | |
| 231 | - if (!$result) { |
|
| 232 | - return []; |
|
| 233 | - } |
|
| 231 | + if (!$result) { |
|
| 232 | + return []; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 236 | - $val = @ldap_get_entries($ldap_link, $result); |
|
| 237 | - if (!is_array($val) or !is_array($val[0])) { |
|
| 238 | - return []; |
|
| 239 | - } |
|
| 240 | - $val = $val[0]; |
|
| 235 | + // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 236 | + $val = @ldap_get_entries($ldap_link, $result); |
|
| 237 | + if (!is_array($val) or !is_array($val[0])) { |
|
| 238 | + return []; |
|
| 239 | + } |
|
| 240 | + $val = $val[0]; |
|
| 241 | 241 | |
| 242 | - // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 243 | - include_spip('inc/charsets'); |
|
| 242 | + // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 243 | + include_spip('inc/charsets'); |
|
| 244 | 244 | |
| 245 | - foreach ($desc as $k => $v) { |
|
| 246 | - $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 247 | - } |
|
| 245 | + foreach ($desc as $k => $v) { |
|
| 246 | + $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - return $desc; |
|
| 249 | + return $desc; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | 260 | function auth_ldap_retrouver_login($login, $serveur = '') { |
| 261 | - return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 261 | + return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -278,9 +278,9 @@ discard block |
||
| 278 | 278 | * Message d'erreur si login non valide, chaîne vide sinon |
| 279 | 279 | */ |
| 280 | 280 | function auth_ldap_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 281 | - include_spip('auth/spip'); |
|
| 281 | + include_spip('auth/spip'); |
|
| 282 | 282 | |
| 283 | - return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 283 | + return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * ``` |
| 302 | 302 | */ |
| 303 | 303 | function auth_ldap_autoriser_modifier_pass($serveur = '') { |
| 304 | - return true; |
|
| 304 | + return true; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -319,23 +319,23 @@ discard block |
||
| 319 | 319 | * Informe du succès ou de l'echec du changement du mot de passe |
| 320 | 320 | */ |
| 321 | 321 | function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 322 | - if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 323 | - return false; |
|
| 324 | - } |
|
| 325 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 326 | - return ''; |
|
| 327 | - } |
|
| 328 | - $link = $ldap['link']; |
|
| 329 | - include_spip('inc/session'); |
|
| 330 | - $dn = session_get('ldap_dn'); |
|
| 331 | - if ('' == $dn) { |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | - $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 339 | - |
|
| 340 | - return $success; |
|
| 322 | + if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 325 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 326 | + return ''; |
|
| 327 | + } |
|
| 328 | + $link = $ldap['link']; |
|
| 329 | + include_spip('inc/session'); |
|
| 330 | + $dn = session_get('ldap_dn'); |
|
| 331 | + if ('' == $dn) { |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | + $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 339 | + |
|
| 340 | + return $success; |
|
| 341 | 341 | } |
@@ -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,110 +32,110 @@ 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 []; |
|
| 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( |
|
| 57 | - 'alea_actuel, alea_futur', |
|
| 58 | - 'spip_auteurs', |
|
| 59 | - 'login=' . sql_quote($login, $serveur, 'text'), |
|
| 60 | - '', |
|
| 61 | - '', |
|
| 62 | - '', |
|
| 63 | - '', |
|
| 64 | - $serveur |
|
| 65 | - ); |
|
| 66 | - |
|
| 67 | - if ($row) { |
|
| 68 | - include_spip('auth/sha256.inc'); |
|
| 69 | - $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 70 | - $shanext = spip_sha256($row['alea_futur'] . $pass); |
|
| 71 | - $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // login inexistant ou mot de passe vide |
|
| 76 | - if (!$shapass and !$md5pass) { |
|
| 77 | - return []; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $row = sql_fetsel( |
|
| 81 | - '*', |
|
| 82 | - 'spip_auteurs', |
|
| 83 | - 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 84 | - $shapass, |
|
| 85 | - $serveur, |
|
| 86 | - 'text' |
|
| 87 | - ) . " AND statut<>'5poubelle'", |
|
| 88 | - '', |
|
| 89 | - '', |
|
| 90 | - '', |
|
| 91 | - '', |
|
| 92 | - $serveur |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - // compat avec les anciennes bases en md5 |
|
| 96 | - if (!$row and $md5pass) { |
|
| 97 | - $row = sql_fetsel( |
|
| 98 | - '*', |
|
| 99 | - 'spip_auteurs', |
|
| 100 | - 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 101 | - $md5pass, |
|
| 102 | - $serveur, |
|
| 103 | - 'text' |
|
| 104 | - ) . " AND statut<>'5poubelle'", |
|
| 105 | - '', |
|
| 106 | - '', |
|
| 107 | - '', |
|
| 108 | - '', |
|
| 109 | - $serveur |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // login/mot de passe incorrect |
|
| 114 | - if (!$row) { |
|
| 115 | - return []; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // fait tourner le codage du pass dans la base |
|
| 119 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 120 | - if ($shanext and !$phpauth) { |
|
| 121 | - include_spip('inc/acces'); // pour creer_uniqid |
|
| 122 | - @sql_update('spip_auteurs', [ |
|
| 123 | - 'alea_actuel' => 'alea_futur', |
|
| 124 | - 'pass' => sql_quote($shanext, $serveur, 'text'), |
|
| 125 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text') |
|
| 126 | - ], 'id_auteur=' . $row['id_auteur'] . ' AND pass IN (' . sql_quote( |
|
| 127 | - $shapass, |
|
| 128 | - $serveur, |
|
| 129 | - 'text' |
|
| 130 | - ) . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur); |
|
| 131 | - // En profiter pour verifier la securite de tmp/ |
|
| 132 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 133 | - if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - 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 []; |
|
| 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( |
|
| 57 | + 'alea_actuel, alea_futur', |
|
| 58 | + 'spip_auteurs', |
|
| 59 | + 'login=' . sql_quote($login, $serveur, 'text'), |
|
| 60 | + '', |
|
| 61 | + '', |
|
| 62 | + '', |
|
| 63 | + '', |
|
| 64 | + $serveur |
|
| 65 | + ); |
|
| 66 | + |
|
| 67 | + if ($row) { |
|
| 68 | + include_spip('auth/sha256.inc'); |
|
| 69 | + $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 70 | + $shanext = spip_sha256($row['alea_futur'] . $pass); |
|
| 71 | + $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // login inexistant ou mot de passe vide |
|
| 76 | + if (!$shapass and !$md5pass) { |
|
| 77 | + return []; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $row = sql_fetsel( |
|
| 81 | + '*', |
|
| 82 | + 'spip_auteurs', |
|
| 83 | + 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 84 | + $shapass, |
|
| 85 | + $serveur, |
|
| 86 | + 'text' |
|
| 87 | + ) . " AND statut<>'5poubelle'", |
|
| 88 | + '', |
|
| 89 | + '', |
|
| 90 | + '', |
|
| 91 | + '', |
|
| 92 | + $serveur |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + // compat avec les anciennes bases en md5 |
|
| 96 | + if (!$row and $md5pass) { |
|
| 97 | + $row = sql_fetsel( |
|
| 98 | + '*', |
|
| 99 | + 'spip_auteurs', |
|
| 100 | + 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 101 | + $md5pass, |
|
| 102 | + $serveur, |
|
| 103 | + 'text' |
|
| 104 | + ) . " AND statut<>'5poubelle'", |
|
| 105 | + '', |
|
| 106 | + '', |
|
| 107 | + '', |
|
| 108 | + '', |
|
| 109 | + $serveur |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // login/mot de passe incorrect |
|
| 114 | + if (!$row) { |
|
| 115 | + return []; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // fait tourner le codage du pass dans la base |
|
| 119 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 120 | + if ($shanext and !$phpauth) { |
|
| 121 | + include_spip('inc/acces'); // pour creer_uniqid |
|
| 122 | + @sql_update('spip_auteurs', [ |
|
| 123 | + 'alea_actuel' => 'alea_futur', |
|
| 124 | + 'pass' => sql_quote($shanext, $serveur, 'text'), |
|
| 125 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text') |
|
| 126 | + ], 'id_auteur=' . $row['id_auteur'] . ' AND pass IN (' . sql_quote( |
|
| 127 | + $shapass, |
|
| 128 | + $serveur, |
|
| 129 | + 'text' |
|
| 130 | + ) . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur); |
|
| 131 | + // En profiter pour verifier la securite de tmp/ |
|
| 132 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 133 | + if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $row; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -145,41 +145,41 @@ discard block |
||
| 145 | 145 | * @return array |
| 146 | 146 | */ |
| 147 | 147 | function auth_spip_formulaire_login($flux) { |
| 148 | - // faut il encore envoyer md5 ? |
|
| 149 | - // on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle |
|
| 150 | - // les hash md5 ont une longueur 32, les sha 64 |
|
| 151 | - // en evitant une requete sql a chaque affichage du formulaire login sans session |
|
| 152 | - // (perf issue pour les sites qui mettent le formulaire de login sur la home) |
|
| 153 | - $compat_md5 = false; |
|
| 154 | - if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) { |
|
| 155 | - $compat_md5 = sql_countsel('spip_auteurs', "length(pass)=32 AND statut<>'poubelle'"); |
|
| 156 | - if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) { |
|
| 157 | - effacer_meta('sha_256_only'); |
|
| 158 | - } |
|
| 159 | - if (!$compat_md5) { |
|
| 160 | - ecrire_meta('sha_256_only', 'oui'); |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 165 | - $flux['data'] .= |
|
| 166 | - ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '') |
|
| 167 | - . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>' |
|
| 168 | - . '<script type="text/javascript">/*<![CDATA[*/' |
|
| 169 | - . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "'," |
|
| 170 | - . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "'," |
|
| 171 | - . "'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 172 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 173 | - . "'informe_auteur_en_cours':false," |
|
| 174 | - . "'attente_informe':0," |
|
| 175 | - . "'compat_md5':" . ($compat_md5 ? 'true' : 'false') . '};' |
|
| 176 | - . "jQuery(function(){ |
|
| 148 | + // faut il encore envoyer md5 ? |
|
| 149 | + // on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle |
|
| 150 | + // les hash md5 ont une longueur 32, les sha 64 |
|
| 151 | + // en evitant une requete sql a chaque affichage du formulaire login sans session |
|
| 152 | + // (perf issue pour les sites qui mettent le formulaire de login sur la home) |
|
| 153 | + $compat_md5 = false; |
|
| 154 | + if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) { |
|
| 155 | + $compat_md5 = sql_countsel('spip_auteurs', "length(pass)=32 AND statut<>'poubelle'"); |
|
| 156 | + if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) { |
|
| 157 | + effacer_meta('sha_256_only'); |
|
| 158 | + } |
|
| 159 | + if (!$compat_md5) { |
|
| 160 | + ecrire_meta('sha_256_only', 'oui'); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 165 | + $flux['data'] .= |
|
| 166 | + ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '') |
|
| 167 | + . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>' |
|
| 168 | + . '<script type="text/javascript">/*<![CDATA[*/' |
|
| 169 | + . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "'," |
|
| 170 | + . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "'," |
|
| 171 | + . "'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 172 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 173 | + . "'informe_auteur_en_cours':false," |
|
| 174 | + . "'attente_informe':0," |
|
| 175 | + . "'compat_md5':" . ($compat_md5 ? 'true' : 'false') . '};' |
|
| 176 | + . "jQuery(function(){ |
|
| 177 | 177 | jQuery('#var_login').change(actualise_auteur); |
| 178 | 178 | jQuery('form#formulaire_login').submit(login_submit); |
| 179 | 179 | });" |
| 180 | - . '/*]]>*/</script>'; |
|
| 180 | + . '/*]]>*/</script>'; |
|
| 181 | 181 | |
| 182 | - return $flux; |
|
| 182 | + return $flux; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
@@ -191,10 +191,10 @@ discard block |
||
| 191 | 191 | * toujours true pour un auteur cree dans SPIP |
| 192 | 192 | */ |
| 193 | 193 | function auth_spip_autoriser_modifier_login($serveur = '') { |
| 194 | - if (strlen($serveur)) { |
|
| 195 | - return false; |
|
| 196 | - } // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 197 | - return true; |
|
| 194 | + if (strlen($serveur)) { |
|
| 195 | + return false; |
|
| 196 | + } // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 197 | + return true; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -208,25 +208,25 @@ discard block |
||
| 208 | 208 | * message d'erreur si login non valide, chaine vide sinon |
| 209 | 209 | */ |
| 210 | 210 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 211 | - // login et mot de passe |
|
| 212 | - if (strlen($new_login)) { |
|
| 213 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 214 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 215 | - } else { |
|
| 216 | - $n = sql_countsel( |
|
| 217 | - 'spip_auteurs', |
|
| 218 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 219 | - '', |
|
| 220 | - '', |
|
| 221 | - $serveur |
|
| 222 | - ); |
|
| 223 | - if ($n) { |
|
| 224 | - return _T('info_login_existant'); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return ''; |
|
| 211 | + // login et mot de passe |
|
| 212 | + if (strlen($new_login)) { |
|
| 213 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 214 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 215 | + } else { |
|
| 216 | + $n = sql_countsel( |
|
| 217 | + 'spip_auteurs', |
|
| 218 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 219 | + '', |
|
| 220 | + '', |
|
| 221 | + $serveur |
|
| 222 | + ); |
|
| 223 | + if ($n) { |
|
| 224 | + return _T('info_login_existant'); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return ''; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -238,41 +238,41 @@ discard block |
||
| 238 | 238 | * @return bool |
| 239 | 239 | */ |
| 240 | 240 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 241 | - if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 242 | - return false; |
|
| 243 | - } |
|
| 244 | - if ( |
|
| 245 | - !$id_auteur = intval($id_auteur) |
|
| 246 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 247 | - ) { |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 250 | - if ($new_login == $auteur['login']) { |
|
| 251 | - return true; |
|
| 252 | - } // on a rien fait mais c'est bon ! |
|
| 253 | - |
|
| 254 | - include_spip('action/editer_auteur'); |
|
| 255 | - |
|
| 256 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 257 | - if (strlen($new_login)) { |
|
| 258 | - $anciens = sql_allfetsel( |
|
| 259 | - 'id_auteur', |
|
| 260 | - 'spip_auteurs', |
|
| 261 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 262 | - '', |
|
| 263 | - '', |
|
| 264 | - '', |
|
| 265 | - '', |
|
| 266 | - $serveur |
|
| 267 | - ); |
|
| 268 | - while ($row = array_pop($anciens)) { |
|
| 269 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 274 | - |
|
| 275 | - return true; |
|
| 241 | + if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | + if ( |
|
| 245 | + !$id_auteur = intval($id_auteur) |
|
| 246 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 247 | + ) { |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | + if ($new_login == $auteur['login']) { |
|
| 251 | + return true; |
|
| 252 | + } // on a rien fait mais c'est bon ! |
|
| 253 | + |
|
| 254 | + include_spip('action/editer_auteur'); |
|
| 255 | + |
|
| 256 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 257 | + if (strlen($new_login)) { |
|
| 258 | + $anciens = sql_allfetsel( |
|
| 259 | + 'id_auteur', |
|
| 260 | + 'spip_auteurs', |
|
| 261 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 262 | + '', |
|
| 263 | + '', |
|
| 264 | + '', |
|
| 265 | + '', |
|
| 266 | + $serveur |
|
| 267 | + ); |
|
| 268 | + while ($row = array_pop($anciens)) { |
|
| 269 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 274 | + |
|
| 275 | + return true; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -284,44 +284,44 @@ discard block |
||
| 284 | 284 | * @return string |
| 285 | 285 | */ |
| 286 | 286 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 287 | - if (!strlen($login)) { |
|
| 288 | - return null; |
|
| 289 | - } // pas la peine de requeter |
|
| 290 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 291 | - if ( |
|
| 292 | - $r = sql_getfetsel( |
|
| 293 | - 'login', |
|
| 294 | - 'spip_auteurs', |
|
| 295 | - "statut<>'5poubelle'" . |
|
| 296 | - ' AND (length(pass)>0)' . |
|
| 297 | - " AND (login=$l)", |
|
| 298 | - '', |
|
| 299 | - '', |
|
| 300 | - '', |
|
| 301 | - '', |
|
| 302 | - $serveur |
|
| 303 | - ) |
|
| 304 | - ) { |
|
| 305 | - return $r; |
|
| 306 | - } |
|
| 307 | - // Si pas d'auteur avec ce login |
|
| 308 | - // regarder s'il a saisi son nom ou son mail. |
|
| 309 | - // Ne pas fusionner avec la requete precedente |
|
| 310 | - // car un nom peut etre homonyme d'un autre login |
|
| 311 | - else { |
|
| 312 | - return sql_getfetsel( |
|
| 313 | - 'login', |
|
| 314 | - 'spip_auteurs', |
|
| 315 | - "statut<>'5poubelle'" . |
|
| 316 | - ' AND (length(pass)>0)' . |
|
| 317 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 318 | - '', |
|
| 319 | - '', |
|
| 320 | - '', |
|
| 321 | - '', |
|
| 322 | - $serveur |
|
| 323 | - ); |
|
| 324 | - } |
|
| 287 | + if (!strlen($login)) { |
|
| 288 | + return null; |
|
| 289 | + } // pas la peine de requeter |
|
| 290 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 291 | + if ( |
|
| 292 | + $r = sql_getfetsel( |
|
| 293 | + 'login', |
|
| 294 | + 'spip_auteurs', |
|
| 295 | + "statut<>'5poubelle'" . |
|
| 296 | + ' AND (length(pass)>0)' . |
|
| 297 | + " AND (login=$l)", |
|
| 298 | + '', |
|
| 299 | + '', |
|
| 300 | + '', |
|
| 301 | + '', |
|
| 302 | + $serveur |
|
| 303 | + ) |
|
| 304 | + ) { |
|
| 305 | + return $r; |
|
| 306 | + } |
|
| 307 | + // Si pas d'auteur avec ce login |
|
| 308 | + // regarder s'il a saisi son nom ou son mail. |
|
| 309 | + // Ne pas fusionner avec la requete precedente |
|
| 310 | + // car un nom peut etre homonyme d'un autre login |
|
| 311 | + else { |
|
| 312 | + return sql_getfetsel( |
|
| 313 | + 'login', |
|
| 314 | + 'spip_auteurs', |
|
| 315 | + "statut<>'5poubelle'" . |
|
| 316 | + ' AND (length(pass)>0)' . |
|
| 317 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 318 | + '', |
|
| 319 | + '', |
|
| 320 | + '', |
|
| 321 | + '', |
|
| 322 | + $serveur |
|
| 323 | + ); |
|
| 324 | + } |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -339,11 +339,11 @@ discard block |
||
| 339 | 339 | */ |
| 340 | 340 | function auth_spip_informer_login($infos, $row, $serveur = '') { |
| 341 | 341 | |
| 342 | - // pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec |
|
| 343 | - $infos['alea_actuel'] = $row['alea_actuel']; |
|
| 344 | - $infos['alea_futur'] = $row['alea_futur']; |
|
| 342 | + // pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec |
|
| 343 | + $infos['alea_actuel'] = $row['alea_actuel']; |
|
| 344 | + $infos['alea_futur'] = $row['alea_futur']; |
|
| 345 | 345 | |
| 346 | - return $infos; |
|
| 346 | + return $infos; |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -354,10 +354,10 @@ discard block |
||
| 354 | 354 | * toujours true pour un auteur cree dans SPIP |
| 355 | 355 | */ |
| 356 | 356 | function auth_spip_autoriser_modifier_pass($serveur = '') { |
| 357 | - if (strlen($serveur)) { |
|
| 358 | - return false; |
|
| 359 | - } // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 360 | - return true; |
|
| 357 | + if (strlen($serveur)) { |
|
| 358 | + return false; |
|
| 359 | + } // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 360 | + return true; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | |
@@ -378,12 +378,12 @@ discard block |
||
| 378 | 378 | * message d'erreur si login non valide, chaine vide sinon |
| 379 | 379 | */ |
| 380 | 380 | function auth_spip_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 381 | - // login et mot de passe |
|
| 382 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 383 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 384 | - } |
|
| 381 | + // login et mot de passe |
|
| 382 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 383 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | - return ''; |
|
| 386 | + return ''; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -397,34 +397,34 @@ discard block |
||
| 397 | 397 | * @return bool |
| 398 | 398 | */ |
| 399 | 399 | function auth_spip_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 400 | - if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 401 | - return false; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if ( |
|
| 405 | - !$id_auteur = intval($id_auteur) |
|
| 406 | - or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 407 | - ) { |
|
| 408 | - return false; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - $c = []; |
|
| 412 | - include_spip('inc/acces'); |
|
| 413 | - include_spip('auth/sha256.inc'); |
|
| 414 | - $htpass = generer_htpass($new_pass); |
|
| 415 | - $alea_actuel = creer_uniqid(); |
|
| 416 | - $alea_futur = creer_uniqid(); |
|
| 417 | - $pass = spip_sha256($alea_actuel . $new_pass); |
|
| 418 | - $c['pass'] = $pass; |
|
| 419 | - $c['htpass'] = $htpass; |
|
| 420 | - $c['alea_actuel'] = $alea_actuel; |
|
| 421 | - $c['alea_futur'] = $alea_futur; |
|
| 422 | - $c['low_sec'] = ''; |
|
| 423 | - |
|
| 424 | - include_spip('action/editer_auteur'); |
|
| 425 | - auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur |
|
| 426 | - |
|
| 427 | - return true; // on a bien modifie le pass |
|
| 400 | + if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 401 | + return false; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if ( |
|
| 405 | + !$id_auteur = intval($id_auteur) |
|
| 406 | + or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 407 | + ) { |
|
| 408 | + return false; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + $c = []; |
|
| 412 | + include_spip('inc/acces'); |
|
| 413 | + include_spip('auth/sha256.inc'); |
|
| 414 | + $htpass = generer_htpass($new_pass); |
|
| 415 | + $alea_actuel = creer_uniqid(); |
|
| 416 | + $alea_futur = creer_uniqid(); |
|
| 417 | + $pass = spip_sha256($alea_actuel . $new_pass); |
|
| 418 | + $c['pass'] = $pass; |
|
| 419 | + $c['htpass'] = $htpass; |
|
| 420 | + $c['alea_actuel'] = $alea_actuel; |
|
| 421 | + $c['alea_futur'] = $alea_futur; |
|
| 422 | + $c['low_sec'] = ''; |
|
| 423 | + |
|
| 424 | + include_spip('action/editer_auteur'); |
|
| 425 | + auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur |
|
| 426 | + |
|
| 427 | + return true; // on a bien modifie le pass |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
@@ -438,58 +438,58 @@ discard block |
||
| 438 | 438 | * @return void |
| 439 | 439 | */ |
| 440 | 440 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], $serveur = '') { |
| 441 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 442 | - if (strlen($serveur)) { |
|
| 443 | - return; |
|
| 444 | - } |
|
| 445 | - // si un login, pass ou statut a ete modifie |
|
| 446 | - // regenerer les fichier htpass |
|
| 447 | - if ( |
|
| 448 | - isset($champs['login']) |
|
| 449 | - or isset($champs['pass']) |
|
| 450 | - or isset($champs['statut']) |
|
| 451 | - or (isset($options['all']) and $options['all']) |
|
| 452 | - ) { |
|
| 453 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 454 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 455 | - |
|
| 456 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 457 | - // par exemple acces_restreint ; |
|
| 458 | - // si .htaccess existe, outrepasser spip_meta |
|
| 459 | - if ( |
|
| 460 | - (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 461 | - and !@file_exists($htaccess) |
|
| 462 | - ) { |
|
| 463 | - spip_unlink($htpasswd); |
|
| 464 | - spip_unlink($htpasswd . '-admin'); |
|
| 465 | - |
|
| 466 | - return; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 470 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 471 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 472 | - |
|
| 473 | - $p1 = ''; // login:htpass pour tous |
|
| 474 | - $p2 = ''; // login:htpass pour les admins |
|
| 475 | - $s = sql_select( |
|
| 476 | - 'login, htpass, statut', |
|
| 477 | - 'spip_auteurs', |
|
| 478 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 479 | - ); |
|
| 480 | - while ($t = sql_fetch($s)) { |
|
| 481 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 482 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 483 | - if ($t['statut'] == '0minirezo') { |
|
| 484 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 485 | - } |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - sql_free($s); |
|
| 489 | - if ($p1) { |
|
| 490 | - ecrire_fichier($htpasswd, $p1); |
|
| 491 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 492 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 493 | - } |
|
| 494 | - } |
|
| 441 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 442 | + if (strlen($serveur)) { |
|
| 443 | + return; |
|
| 444 | + } |
|
| 445 | + // si un login, pass ou statut a ete modifie |
|
| 446 | + // regenerer les fichier htpass |
|
| 447 | + if ( |
|
| 448 | + isset($champs['login']) |
|
| 449 | + or isset($champs['pass']) |
|
| 450 | + or isset($champs['statut']) |
|
| 451 | + or (isset($options['all']) and $options['all']) |
|
| 452 | + ) { |
|
| 453 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 454 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 455 | + |
|
| 456 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 457 | + // par exemple acces_restreint ; |
|
| 458 | + // si .htaccess existe, outrepasser spip_meta |
|
| 459 | + if ( |
|
| 460 | + (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 461 | + and !@file_exists($htaccess) |
|
| 462 | + ) { |
|
| 463 | + spip_unlink($htpasswd); |
|
| 464 | + spip_unlink($htpasswd . '-admin'); |
|
| 465 | + |
|
| 466 | + return; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 470 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 471 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 472 | + |
|
| 473 | + $p1 = ''; // login:htpass pour tous |
|
| 474 | + $p2 = ''; // login:htpass pour les admins |
|
| 475 | + $s = sql_select( |
|
| 476 | + 'login, htpass, statut', |
|
| 477 | + 'spip_auteurs', |
|
| 478 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 479 | + ); |
|
| 480 | + while ($t = sql_fetch($s)) { |
|
| 481 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 482 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 483 | + if ($t['statut'] == '0minirezo') { |
|
| 484 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 485 | + } |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + sql_free($s); |
|
| 489 | + if ($p1) { |
|
| 490 | + ecrire_fichier($htpasswd, $p1); |
|
| 491 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 492 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | 495 | } |
@@ -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 | include_spip('base/abstract_sql'); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * Pile complétée du code compilé |
| 44 | 44 | **/ |
| 45 | 45 | function balise_FORMULAIRE_INSCRIPTION($p) { |
| 46 | - return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 46 | + return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * - chaîne vide sinon. |
| 73 | 73 | */ |
| 74 | 74 | function balise_FORMULAIRE_INSCRIPTION_stat($args, $context_compil) { |
| 75 | - list($mode, $id, $retour) = array_pad($args, 3, null); |
|
| 76 | - include_spip('action/inscrire_auteur'); |
|
| 77 | - $mode = tester_statut_inscription($mode, $id); |
|
| 75 | + list($mode, $id, $retour) = array_pad($args, 3, null); |
|
| 76 | + include_spip('action/inscrire_auteur'); |
|
| 77 | + $mode = tester_statut_inscription($mode, $id); |
|
| 78 | 78 | |
| 79 | - return $mode ? [$mode, $id, $retour] : ''; |
|
| 79 | + return $mode ? [$mode, $id, $retour] : ''; |
|
| 80 | 80 | } |
@@ -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 | |
@@ -54,84 +54,84 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function balise_LOGO__dist($p) { |
| 56 | 56 | |
| 57 | - preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 58 | - $type = strtolower($regs[1]); |
|
| 59 | - $suite_logo = $regs[2]; |
|
| 60 | - |
|
| 61 | - // cas de #LOGO_SITE_SPIP |
|
| 62 | - if ($type == 'site_spip') { |
|
| 63 | - $type = 'site'; |
|
| 64 | - $_id_objet = "\"'0'\""; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - $id_objet = id_table_objet($type); |
|
| 68 | - if (!isset($_id_objet)) { |
|
| 69 | - $_id_objet = champ_sql($id_objet, $p); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 73 | - $coord = []; |
|
| 74 | - $align = $lien = ''; |
|
| 75 | - $mode_logo = ''; |
|
| 76 | - |
|
| 77 | - if ($p->param and !$p->param[0][0]) { |
|
| 78 | - $params = $p->param[0]; |
|
| 79 | - array_shift($params); |
|
| 80 | - foreach ($params as $a) { |
|
| 81 | - if ($a[0]->type === 'texte') { |
|
| 82 | - $n = $a[0]->texte; |
|
| 83 | - if (is_numeric($n)) { |
|
| 84 | - $coord[] = $n; |
|
| 85 | - } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 86 | - $align = $n; |
|
| 87 | - } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 88 | - $mode_logo = $n; |
|
| 89 | - } |
|
| 90 | - } else { |
|
| 91 | - $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $coord_x = !$coord ? 0 : intval(array_shift($coord)); |
|
| 97 | - $coord_y = !$coord ? 0 : intval(array_shift($coord)); |
|
| 98 | - |
|
| 99 | - if ($p->etoile === '*') { |
|
| 100 | - include_spip('balise/url_'); |
|
| 101 | - $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 105 | - if ($type == 'document') { |
|
| 106 | - $qconnect = _q($connect); |
|
| 107 | - $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 108 | - if ($fichier) { |
|
| 109 | - $code = "quete_logo_file($doc, $qconnect)"; |
|
| 110 | - } else { |
|
| 111 | - $code = "quete_logo_document($doc, " . ($lien ? $lien : "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | - } |
|
| 113 | - // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 114 | - if ($p->descr['documents']) { |
|
| 115 | - $code = '(($doublons["documents"] .= ",". ' |
|
| 116 | - . $_id_objet |
|
| 117 | - . ") ? $code : '')"; |
|
| 118 | - } |
|
| 119 | - } elseif ($connect) { |
|
| 120 | - $code = "''"; |
|
| 121 | - spip_log('Les logos distants ne sont pas prevus'); |
|
| 122 | - } else { |
|
| 123 | - $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 127 | - if ($coord_x or $coord_y) { |
|
| 128 | - $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $p->code = $code; |
|
| 132 | - $p->interdire_scripts = false; |
|
| 133 | - |
|
| 134 | - return $p; |
|
| 57 | + preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 58 | + $type = strtolower($regs[1]); |
|
| 59 | + $suite_logo = $regs[2]; |
|
| 60 | + |
|
| 61 | + // cas de #LOGO_SITE_SPIP |
|
| 62 | + if ($type == 'site_spip') { |
|
| 63 | + $type = 'site'; |
|
| 64 | + $_id_objet = "\"'0'\""; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + $id_objet = id_table_objet($type); |
|
| 68 | + if (!isset($_id_objet)) { |
|
| 69 | + $_id_objet = champ_sql($id_objet, $p); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 73 | + $coord = []; |
|
| 74 | + $align = $lien = ''; |
|
| 75 | + $mode_logo = ''; |
|
| 76 | + |
|
| 77 | + if ($p->param and !$p->param[0][0]) { |
|
| 78 | + $params = $p->param[0]; |
|
| 79 | + array_shift($params); |
|
| 80 | + foreach ($params as $a) { |
|
| 81 | + if ($a[0]->type === 'texte') { |
|
| 82 | + $n = $a[0]->texte; |
|
| 83 | + if (is_numeric($n)) { |
|
| 84 | + $coord[] = $n; |
|
| 85 | + } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 86 | + $align = $n; |
|
| 87 | + } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 88 | + $mode_logo = $n; |
|
| 89 | + } |
|
| 90 | + } else { |
|
| 91 | + $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $coord_x = !$coord ? 0 : intval(array_shift($coord)); |
|
| 97 | + $coord_y = !$coord ? 0 : intval(array_shift($coord)); |
|
| 98 | + |
|
| 99 | + if ($p->etoile === '*') { |
|
| 100 | + include_spip('balise/url_'); |
|
| 101 | + $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 105 | + if ($type == 'document') { |
|
| 106 | + $qconnect = _q($connect); |
|
| 107 | + $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 108 | + if ($fichier) { |
|
| 109 | + $code = "quete_logo_file($doc, $qconnect)"; |
|
| 110 | + } else { |
|
| 111 | + $code = "quete_logo_document($doc, " . ($lien ? $lien : "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | + } |
|
| 113 | + // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 114 | + if ($p->descr['documents']) { |
|
| 115 | + $code = '(($doublons["documents"] .= ",". ' |
|
| 116 | + . $_id_objet |
|
| 117 | + . ") ? $code : '')"; |
|
| 118 | + } |
|
| 119 | + } elseif ($connect) { |
|
| 120 | + $code = "''"; |
|
| 121 | + spip_log('Les logos distants ne sont pas prevus'); |
|
| 122 | + } else { |
|
| 123 | + $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 127 | + if ($coord_x or $coord_y) { |
|
| 128 | + $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $p->code = $code; |
|
| 132 | + $p->interdire_scripts = false; |
|
| 133 | + |
|
| 134 | + return $p; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -158,20 +158,20 @@ discard block |
||
| 158 | 158 | * Code compilé retournant le chemin du logo ou le code HTML du logo. |
| 159 | 159 | **/ |
| 160 | 160 | function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) { |
| 161 | - $code = "quete_logo('$id_objet', '" . |
|
| 162 | - (($suite == '_SURVOL') ? 'off' : |
|
| 163 | - (($suite == '_NORMAL') ? 'on' : 'ON')) . |
|
| 164 | - "', $_id_objet," . |
|
| 165 | - (($suite == '_RUBRIQUE') ? |
|
| 166 | - champ_sql('id_rubrique', $p) : |
|
| 167 | - (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) . |
|
| 168 | - ', ' . intval($fichier) . ')'; |
|
| 169 | - |
|
| 170 | - if ($fichier) { |
|
| 171 | - return $code; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $align = preg_replace(',\W,', '', $align); |
|
| 175 | - |
|
| 176 | - return "quete_html_logo($code, '$align', " . ($_lien ? $_lien : "''") . ')'; |
|
| 161 | + $code = "quete_logo('$id_objet', '" . |
|
| 162 | + (($suite == '_SURVOL') ? 'off' : |
|
| 163 | + (($suite == '_NORMAL') ? 'on' : 'ON')) . |
|
| 164 | + "', $_id_objet," . |
|
| 165 | + (($suite == '_RUBRIQUE') ? |
|
| 166 | + champ_sql('id_rubrique', $p) : |
|
| 167 | + (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) . |
|
| 168 | + ', ' . intval($fichier) . ')'; |
|
| 169 | + |
|
| 170 | + if ($fichier) { |
|
| 171 | + return $code; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $align = preg_replace(',\W,', '', $align); |
|
| 175 | + |
|
| 176 | + return "quete_html_logo($code, '$align', " . ($_lien ? $_lien : "''") . ')'; |
|
| 177 | 177 | } |
@@ -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 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Pile complétée du code compilé |
| 37 | 37 | **/ |
| 38 | 38 | function balise_URL_LOGOUT($p) { |
| 39 | - return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 39 | + return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * Liste (url) des arguments collectés. |
| 53 | 53 | */ |
| 54 | 54 | function balise_URL_LOGOUT_stat($args, $context_compil) { |
| 55 | - $url = isset($args[0]) ? $args[0] : ''; |
|
| 55 | + $url = isset($args[0]) ? $args[0] : ''; |
|
| 56 | 56 | |
| 57 | - return [$url]; |
|
| 57 | + return [$url]; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function balise_URL_LOGOUT_dyn($cible) { |
| 71 | 71 | |
| 72 | - if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | - return ''; |
|
| 74 | - } |
|
| 72 | + if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | + return ''; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ? $cible : self('&'))); |
|
| 76 | + return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ? $cible : self('&'))); |
|
| 77 | 77 | } |
@@ -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 | /** |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * Pile complétée du code compilé |
| 38 | 38 | **/ |
| 39 | 39 | function balise_MENU_LANG_ECRIRE($p) { |
| 40 | - return calculer_balise_dynamique($p, 'MENU_LANG_ECRIRE', ['lang']); |
|
| 40 | + return calculer_balise_dynamique($p, 'MENU_LANG_ECRIRE', ['lang']); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | * Liste (lang) des arguments collectés et fournis. |
| 56 | 56 | */ |
| 57 | 57 | function balise_MENU_LANG_ECRIRE_stat($args, $context_compil) { |
| 58 | - include_spip('inc/lang'); |
|
| 59 | - if (strpos($GLOBALS['meta']['langues_proposees'], ',') === false) { |
|
| 60 | - return ''; |
|
| 61 | - } |
|
| 58 | + include_spip('inc/lang'); |
|
| 59 | + if (strpos($GLOBALS['meta']['langues_proposees'], ',') === false) { |
|
| 60 | + return ''; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return $args; |
|
| 63 | + return $args; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * Liste : Chemin du squelette, durée du cache, contexte |
| 77 | 77 | **/ |
| 78 | 78 | function balise_MENU_LANG_ECRIRE_dyn($opt) { |
| 79 | - return menu_lang_pour_tous('var_lang_ecrire', $opt); |
|
| 79 | + return menu_lang_pour_tous('var_lang_ecrire', $opt); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -96,30 +96,30 @@ discard block |
||
| 96 | 96 | * Liste : Chemin du squelette, durée du cache, contexte |
| 97 | 97 | **/ |
| 98 | 98 | function menu_lang_pour_tous($nom, $default) { |
| 99 | - include_spip('inc/lang'); |
|
| 99 | + include_spip('inc/lang'); |
|
| 100 | 100 | |
| 101 | - if ($GLOBALS['spip_lang'] <> $default) { |
|
| 102 | - $opt = lang_select($default); # et remplace |
|
| 103 | - if ($GLOBALS['spip_lang'] <> $default) { |
|
| 104 | - $default = ''; # annule tout choix par defaut |
|
| 105 | - if ($opt) { |
|
| 106 | - lang_select(); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 101 | + if ($GLOBALS['spip_lang'] <> $default) { |
|
| 102 | + $opt = lang_select($default); # et remplace |
|
| 103 | + if ($GLOBALS['spip_lang'] <> $default) { |
|
| 104 | + $default = ''; # annule tout choix par defaut |
|
| 105 | + if ($opt) { |
|
| 106 | + lang_select(); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - # lien a partir de / |
|
| 112 | - $cible = parametre_url(self(), 'lang', '', '&'); |
|
| 113 | - $post = generer_url_action('converser', 'redirect=' . rawurlencode($cible), '&'); |
|
| 111 | + # lien a partir de / |
|
| 112 | + $cible = parametre_url(self(), 'lang', '', '&'); |
|
| 113 | + $post = generer_url_action('converser', 'redirect=' . rawurlencode($cible), '&'); |
|
| 114 | 114 | |
| 115 | - return [ |
|
| 116 | - 'formulaires/menu_lang', |
|
| 117 | - 3600, |
|
| 118 | - [ |
|
| 119 | - 'nom' => $nom, |
|
| 120 | - 'url' => $post, |
|
| 121 | - 'name' => $nom, |
|
| 122 | - 'default' => $default, |
|
| 123 | - ] |
|
| 124 | - ]; |
|
| 115 | + return [ |
|
| 116 | + 'formulaires/menu_lang', |
|
| 117 | + 3600, |
|
| 118 | + [ |
|
| 119 | + 'nom' => $nom, |
|
| 120 | + 'url' => $post, |
|
| 121 | + 'name' => $nom, |
|
| 122 | + 'default' => $default, |
|
| 123 | + ] |
|
| 124 | + ]; |
|
| 125 | 125 | } |