Browse Source

On met des liens vers la page de diagnostic IP, on améliore légèrement son affichage, et on passe

son calcul dans une fonction PHP dédiée.
pull/2/head
Matthieu Marcillaud 2 years ago
parent
commit
92f9aad43d
  1. 73
      inclure/ipset_diagnostic.html
  2. 56
      inclure/ipset_diagnostic_fonctions.php
  3. 3
      lang/ipset_fr.php
  4. 31
      prive/squelettes/contenu/ipset_diagnostic.html
  5. 1
      prive/squelettes/navigation/auteurs_access_ips.html
  6. 12
      prive/squelettes/navigation/ipset_diagnostic.html

73
inclure/ipset_diagnostic.html

@ -2,75 +2,20 @@
#CACHE{0}
<section>
<header class="cartouche">
<h1><:ipset:titre_page_ip_diagnostic:></h1>
<h1><:ipset:ipset_diagnostic:></h1>
</header>
<div class="main">
<?php
spip_log("Visite IP diagnostic", 'ipset');
function test_ip_cache_ipset() {
include_spip('inc/config');
include_spip('lib/IPSet/src/Wikimedia/IPSet');
$cache_ipset = lire_config("ipset");
if (
!$cache_ipset
or !($cache_ipset instanceof \Wikimedia\IPSet)
) {
return false;
}
return true;
}
$data = array();
$ip = $GLOBALS['ip'];
$data['Your IP'] = $ip;
$data['Cache IPset exists'] = test_ip_cache_ipset() ? 'yes' : 'no';
$data['Your Cache Session exists'] = isset($GLOBALS['visiteur_session']['ip_id_auteur']) ? 'yes' : 'no';
if (($data['Your Cache Session exists'] === 'yes') and empty($GLOBALS['visiteur_session']['ip_id_auteur'])) {
$data['Your Cache Session exists'] .= " (but empty!)";
}
$data['Your IP Session is accepted'] = ipset_access_author() ? 'yes' : 'no';
$data['Your name'] = !empty($GLOBALS['visiteur_session']['ip_id_auteur']) ? $GLOBALS['visiteur_session']['ip_id_auteur'] : 'unknown';
$ipset = ipset_get();
$data['IP matched the IPSet'] = $ipset->match($ip) ? 'yes' : 'no';
include_spip('inc/ipset');
$accessip = new AccessIP($ip);
$data['IP found in file cache'] = $accessip->read() ? 'yes' : 'no';
$data['IP found by full search'] = $accessip->search() ? 'yes' : 'no';
// maintenant, on tente de corriger si problème de cache…
if (!test_ip_cache_ipset()) {
$data['Error : Cache is missing'] = "We make it again...";
ipset_update_ips_cache();
if (!test_ip_cache_ipset()) {
$data['Error : Cache still missing'] = ":-(";
<?php
$data = ipset_diagnostic_collect();
if ($data) {
echo "<dl>\n";
foreach ($data as $dt => $dd) {
echo "<dt>$dt</dt>\n";
echo "<dd>$dd</dd>\n";
}
echo "</dl>\n";
}
$data['Thank you'] =
"Thank you for visiting this page. It will help us improve the reliability of your access."
. " <br />You can now return on the home page: <a href='#URL_SITE_SPIP'>#URL_SITE_SPIP</a>";
spip_log("Fin visite IP diagnostic", 'ipset');
?>
<dl><?php
foreach ($data as $dt => $dd) {
echo "<dt>$dt</dt>\n";
echo "<dd>$dd</dd>\n";
}
?><dl>
<?php
spip_log('IP DIAGNOSTIC', 'ip_diagnostic');
spip_log($data, 'ip_diagnostic');
?>
</div>
</section>

56
inclure/ipset_diagnostic_fonctions.php

@ -0,0 +1,56 @@
<?php
/**
* Génère et loggue différentes infos sur l’IP, les Caches IPSet pour ce visiteur...
* @return array
*/
function ipset_diagnostic_collect() {
spip_log("Visite IP diagnostic", 'ipset');
$data = array();
$ip = $GLOBALS['ip'];
$data['Your IP'] = $ip;
$data['Cache IPset exists'] = ipset_get_cache() ? 'yes' : 'no';
$data['Your Cache Session exists'] = isset($GLOBALS['visiteur_session']['ip_id_auteur']) ? 'yes' : 'no';
if (($data['Your Cache Session exists'] === 'yes') and empty($GLOBALS['visiteur_session']['ip_id_auteur'])) {
$data['Your Cache Session exists'] .= " (but empty!)";
}
$data['Your IP Session is accepted'] = ipset_access_author() ? 'yes' : 'no';
$data['Your name'] = !empty($GLOBALS['visiteur_session']['ip_name']) ? $GLOBALS['visiteur_session']['ip_name'] : 'unknown';
$ipset = ipset_get();
$data['IP matched the IPSet'] = $ipset->match($ip) ? 'yes' : 'no';
include_spip('inc/ipset');
$accessip = new AccessIP($ip);
$data['IP found in file cache'] = $accessip->read() ? 'yes' : 'no';
$data['IP found by full search'] = $accessip->search() ? 'yes' : 'no';
// maintenant, on tente de corriger si problème de cache…
if (!ipset_get_cache()) {
$data['Error : Cache is missing'] = "We make it again...";
ipset_update_ips_cache();
if (!ipset_get_cache()) {
$data['Error : Cache still missing'] = ":-(";
}
}
$url = spip_htmlspecialchars($GLOBALS['meta']['adresse_site']);
$data['Thank you'] =
"Thank you for visiting this page. It will help us improve the reliability of your access."
. " <br />You can now return on the home page: <a href='$url'>$url</a>";
spip_log("Fin visite IP diagnostic", 'ipset');
$data_public = $data;
// Not visible to humans ...
$data['Your ID Author'] = !empty($GLOBALS['visiteur_session']['ip_id_auteur']) ? $GLOBALS['visiteur_session']['ip_id_auteur'] : 'unknown';
spip_log('IP DIAGNOSTIC', 'ipset_diagnostic');
spip_log($data, 'ipset_diagnostic');
return $data_public;
}

3
lang/ipset_fr.php

@ -25,5 +25,6 @@ $GLOBALS[$GLOBALS['idx_lang']] = array(
'label_access_ips_explication' => 'Liste d’IPs ou de plages d’IPs (CIDR) séparés par des virgules.',
// T
'titre_page_ip_diagnostic' => 'Diagnostic IP',
'ipset_diagnostic' => 'Diagnostic IP',
'ipset_diagnostic_info' => 'Cette page affiche les @nb@ dernières visites sur la page : ',
);

31
prive/squelettes/contenu/ipset_diagnostic.html

@ -1,15 +1,8 @@
[(#AUTORISER{configurer}|sinon_interdire_acces)]
<h1 class="grostitre"><:ipset:titre_page_ip_diagnostic:></h1>
<h1 class="grostitre"><:ipset:ipset_diagnostic:></h1>
<?php $max = 15; ?>
<p class="info">
<multi>
[fr] Cette page affiche les <?php echo $max; ?> dernières visites sur la page
[en] This page show the <?php echo $max; ?> last visits on page
</multi>
<a href="#URL_PAGE{ip_diagnostic}">IP Diagnostic</a>
</p>
<style type="text/css">
textarea.log {
@ -32,14 +25,17 @@
$open = false;
$data = array();
$content = "";
if (file_exists(_DIR_LOG . 'ip_diagnostic.log')) {
$content = file_get_contents(_DIR_LOG . 'ip_diagnostic.log');
if (file_exists(_DIR_LOG . 'ipset_diagnostic.log')) {
$content = file_get_contents(_DIR_LOG . 'ipset_diagnostic.log');
}
foreach (explode("\n", $content) as $line) {
if ($line and false !== strpos($line, 'IP DIAGNOSTIC')) {
if (!$line or !$line = trim($line)) {
continue;
}
$pos = strpos($line, 'IP DIAGNOSTIC');
if (false !== $pos) {
$open = true;
list($date, $heure, $ip, $pid1, $pid2, $level, $text) = explode(" ", $line, 7);
$remove = implode(" ", array($date, $heure, $ip, $pid1, $pid2, $level, ""));
list($date, $heure, $ip, $text) = explode(" ", $line, 4);
$titre = "IP $ip à $heure";
if (empty($data[$date])) {
$data[$date] = array();
@ -50,7 +46,14 @@ foreach (explode("\n", $content) as $line) {
if (!$open) {
continue;
}
$data[$date][$titre][] = str_replace($remove, "", $line);
if (
false !== strpos($line, 'Array')
or $line === '('
or $line === ')'
) {
continue;
}
$data[$date][$titre][] = $line;
}
$data = array_reverse($data);

1
prive/squelettes/navigation/auteurs_access_ips.html

@ -5,4 +5,5 @@
[(#BOITE_OUVRIR{'','raccourcis'})]
[(#URL_ECRIRE{auteurs}|icone_horizontale{<:icone_afficher_auteurs:>,auteur})]
[(#URL_ECRIRE{ipset_diagnostic}|icone_horizontale{<:ipset:ipset_diagnostic:>,ipset})]
#BOITE_FERMER

12
prive/squelettes/navigation/ipset_diagnostic.html

@ -0,0 +1,12 @@
#BOITE_OUVRIR{'','info'}
<p>
<:ipset:ipset_diagnostic_info{nb=15}:>
<a href="#URL_PAGE{ipset_diagnostic}">IPSet Diagnostic</a>
</p>
#BOITE_FERMER
[(#BOITE_OUVRIR{'','raccourcis'})]
[(#URL_ECRIRE{auteurs}|icone_horizontale{<:icone_afficher_auteurs:>,auteur})]
[(#URL_ECRIRE{auteurs_access_ips}|icone_horizontale{<:ipset:auteurs_access_ips:>, #CHEMIN_IMAGE{ipset-24.png}})]
#BOITE_FERMER
Loading…
Cancel
Save