v1.6.29 : chemins IP triés par date, un par ligne avec compteur
- Drill-down IP : articles/livres affichés un par ligne (compteur entre parenthèses), triés par date de dernier accès desc
- AccessLogParser : ipPathTs trace le dernier timestamp par chemin/IP
- ip_top_paths : structure {n, ts} au lieu de count simple
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,14 @@ Format : [Keep a Changelog](https://keepachangelog.com/fr/1.0.0/) — versionnag
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [1.6.29] - 2026-05-19
|
||||||
|
|
||||||
|
### Modifié
|
||||||
|
- Admin stats / drill-down IP : chemins affichés un par ligne avec compteur entre parenthèses, triés par date de dernier accès (plus récent en premier)
|
||||||
|
- AccessLogParser : suivi du dernier horodatage par chemin/IP (`ipPathTs`), `ip_top_paths` devient `{n: count, ts: timestamp}`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## [1.6.28] - 2026-05-19
|
## [1.6.28] - 2026-05-19
|
||||||
|
|
||||||
### Ajouté
|
### Ajouté
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ function esc(s) {
|
|||||||
function flag(code) {
|
function flag(code) {
|
||||||
if (!code || code.length !== 2) { return ''; }
|
if (!code || code.length !== 2) { return ''; }
|
||||||
var cp = Array.from(code.toUpperCase()).map(function (c) { return 0x1F1E6 + c.charCodeAt(0) - 65; });
|
var cp = Array.from(code.toUpperCase()).map(function (c) { return 0x1F1E6 + c.charCodeAt(0) - 65; });
|
||||||
return String.fromCodePoint(cp[0], cp[1]) + ' ';
|
return String.fromCodePoint(cp[0], cp[1]) + ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index IPs par ASN pour le drill-down
|
// Index IPs par ASN pour le drill-down
|
||||||
@@ -35,7 +35,7 @@ function esc(s) {
|
|||||||
ipsByAsn[k].sort(function (a, b) { return b.hits - a.hits; });
|
ipsByAsn[k].sort(function (a, b) { return b.hits - a.hits; });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mini sparkline (80×20px polyline) pour chaque IP
|
// Mini sparkline (80x20px polyline) pour chaque IP
|
||||||
function ipSparkline(daily) {
|
function ipSparkline(daily) {
|
||||||
if (!daily || !daily.length) { return ''; }
|
if (!daily || !daily.length) { return ''; }
|
||||||
var W = 80, H = 20, padX = 1, padY = 2;
|
var W = 80, H = 20, padX = 1, padY = 2;
|
||||||
@@ -85,44 +85,45 @@ function esc(s) {
|
|||||||
var asnKey = n.asn || '__unknown__';
|
var asnKey = n.asn || '__unknown__';
|
||||||
var ips = ipsByAsn[asnKey] || [];
|
var ips = ipsByAsn[asnKey] || [];
|
||||||
|
|
||||||
// Lignes IP avec mini sparkline + chemins
|
// Lignes IP avec mini sparkline + chemins triés par date desc
|
||||||
var ipRows = ips.slice(0, 20).map(function (ipInfo) {
|
var ipRows = ips.slice(0, 20).map(function (ipInfo) {
|
||||||
var articles = [], books = [];
|
var articles = [], books = [];
|
||||||
Object.keys(ipInfo.paths || {}).forEach(function (path) {
|
Object.keys(ipInfo.paths || {}).forEach(function (path) {
|
||||||
var cnt = ipInfo.paths[path];
|
var p = ipInfo.paths[path];
|
||||||
if (path.indexOf('/post/') === 0) { articles.push({ path: path, cnt: cnt }); }
|
var cnt = (p && typeof p === 'object') ? p.n : p;
|
||||||
else if (path.indexOf('/book/') === 0) { books.push({ path: path, cnt: cnt }); }
|
var ts = (p && typeof p === 'object') ? p.ts : 0;
|
||||||
|
if (path.indexOf('/post/') === 0) { articles.push({ path: path, cnt: cnt, ts: ts }); }
|
||||||
|
else if (path.indexOf('/book/') === 0) { books.push({ path: path, cnt: cnt, ts: ts }); }
|
||||||
});
|
});
|
||||||
articles.sort(function (a, b) { return b.cnt - a.cnt; });
|
articles.sort(function (a, b) { return b.ts - a.ts; });
|
||||||
books.sort(function (a, b) { return b.cnt - a.cnt; });
|
books.sort(function (a, b) { return b.ts - a.ts; });
|
||||||
|
|
||||||
|
function pathLine(p, prefix) {
|
||||||
|
var slug = decodeURIComponent(p.path.replace(prefix, ''));
|
||||||
|
var label = slug.length > 40 ? slug.slice(0, 40) + '…' : slug;
|
||||||
|
return '<div style="font-size:.75rem;line-height:1.5">'
|
||||||
|
+ '<a href="' + esc(p.path) + '" target="_blank" style="color:#495057">'
|
||||||
|
+ esc(label) + '</a>'
|
||||||
|
+ ' <span style="color:#adb5bd">(' + p.cnt + ')</span></div>';
|
||||||
|
}
|
||||||
|
|
||||||
var pathsHtml = '';
|
var pathsHtml = '';
|
||||||
if (articles.length) {
|
if (articles.length) {
|
||||||
pathsHtml += '<div style="font-size:.75rem;color:#6c757d">Articles : '
|
pathsHtml += '<div style="font-size:.7rem;color:#adb5bd;margin-top:2px">Articles</div>'
|
||||||
+ articles.slice(0, 3).map(function (p) {
|
+ articles.map(function (p) { return pathLine(p, '/post/'); }).join('');
|
||||||
var slug = decodeURIComponent(p.path.replace('/post/', ''));
|
|
||||||
return '<a href="' + esc(p.path) + '" target="_blank" style="color:inherit">'
|
|
||||||
+ esc(slug.length > 28 ? slug.slice(0, 28) + '…' : slug)
|
|
||||||
+ '</a> (' + p.cnt + ')';
|
|
||||||
}).join(', ') + '</div>';
|
|
||||||
}
|
}
|
||||||
if (books.length) {
|
if (books.length) {
|
||||||
pathsHtml += '<div style="font-size:.75rem;color:#6c757d">Livres : '
|
pathsHtml += '<div style="font-size:.7rem;color:#adb5bd;margin-top:2px">Livres</div>'
|
||||||
+ books.slice(0, 3).map(function (p) {
|
+ books.map(function (p) { return pathLine(p, '/book/'); }).join('');
|
||||||
var slug = decodeURIComponent(p.path.replace('/book/', ''));
|
|
||||||
return '<a href="' + esc(p.path) + '" target="_blank" style="color:inherit">'
|
|
||||||
+ esc(slug.length > 28 ? slug.slice(0, 28) + '…' : slug)
|
|
||||||
+ '</a> (' + p.cnt + ')';
|
|
||||||
}).join(', ') + '</div>';
|
|
||||||
}
|
}
|
||||||
if (!pathsHtml) { pathsHtml = '<span style="font-size:.75rem;color:#adb5bd">—</span>'; }
|
if (!pathsHtml) { pathsHtml = '<span style="font-size:.75rem;color:#adb5bd">—</span>'; }
|
||||||
|
|
||||||
return '<div class="d-flex align-items-center gap-2 py-1 border-bottom">'
|
return '<div class="d-flex gap-2 py-2 border-bottom align-items-start">'
|
||||||
+ '<code style="width:9rem;flex-shrink:0;font-size:.72rem;color:#6c757d">'
|
+ '<code style="width:9rem;flex-shrink:0;font-size:.72rem;color:#6c757d;padding-top:2px">'
|
||||||
+ esc(ipInfo.ip) + '</code>'
|
+ esc(ipInfo.ip) + '</code>'
|
||||||
+ ipSparkline(ipInfo.daily || [])
|
+ '<div style="flex-shrink:0;padding-top:2px">' + ipSparkline(ipInfo.daily || []) + '</div>'
|
||||||
+ '<div class="flex-grow-1">' + pathsHtml + '</div>'
|
+ '<div class="flex-grow-1">' + pathsHtml + '</div>'
|
||||||
+ '<div class="text-end text-muted small" style="width:4rem;flex-shrink:0">'
|
+ '<div class="text-end text-muted small" style="width:4rem;flex-shrink:0;padding-top:2px">'
|
||||||
+ (ipInfo.hits || 0).toLocaleString('fr-FR') + '</div>'
|
+ (ipInfo.hits || 0).toLocaleString('fr-FR') + '</div>'
|
||||||
+ '</div>';
|
+ '</div>';
|
||||||
}).join('');
|
}).join('');
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
1.6.28
|
1.6.29
|
||||||
|
|||||||
+28
-18
@@ -30,7 +30,7 @@ class AccessLogParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array{pages:array<string,int>,books:array<string,int>,ips:array<string,int>,pages_by_day:array<string,list<int>>,ips_by_day:array<string,list<int>>,ip_top_paths:array<string,array<string,int>>}
|
* @return array{pages:array<string,int>,books:array<string,int>,ips:array<string,int>,pages_by_day:array<string,list<int>>,ips_by_day:array<string,list<int>>,ip_top_paths:array<string,array<string,array{n:int,ts:int}>>}
|
||||||
*/
|
*/
|
||||||
public function stats(): array
|
public function stats(): array
|
||||||
{
|
{
|
||||||
@@ -44,16 +44,17 @@ class AccessLogParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$cutoff = strtotime("-{$this->days} days midnight") ?: (time() - $this->days * 86400);
|
$cutoff = strtotime("-{$this->days} days midnight") ?: (time() - $this->days * 86400);
|
||||||
$pages = [];
|
$pages = [];
|
||||||
$books = [];
|
$books = [];
|
||||||
$ips = [];
|
$ips = [];
|
||||||
$dayPages = [];
|
$dayPages = [];
|
||||||
$ipDays = []; // [ip => [dayOffset => count]]
|
$ipDays = []; // [ip => [dayOffset => count]]
|
||||||
$ipPaths = []; // [ip => [path => count]]
|
$ipPaths = []; // [ip => [path => count]]
|
||||||
|
$ipPathTs = []; // [ip => [path => last_timestamp]]
|
||||||
|
|
||||||
foreach ($this->logFiles() as $file) {
|
foreach ($this->logFiles() as $file) {
|
||||||
$this->parseFile($file, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
$this->parseFile($file, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths, $ipPathTs);
|
||||||
}
|
}
|
||||||
|
|
||||||
arsort($pages);
|
arsort($pages);
|
||||||
@@ -86,7 +87,10 @@ class AccessLogParser
|
|||||||
|
|
||||||
$paths = $ipPaths[$ip] ?? [];
|
$paths = $ipPaths[$ip] ?? [];
|
||||||
arsort($paths);
|
arsort($paths);
|
||||||
$ipTopPaths[$ip] = array_slice($paths, 0, 10, true);
|
$ipTopPaths[$ip] = [];
|
||||||
|
foreach (array_slice($paths, 0, 10, true) as $p => $cnt) {
|
||||||
|
$ipTopPaths[$ip][$p] = ['n' => $cnt, 'ts' => $ipPathTs[$ip][$p] ?? 0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = [
|
$result = [
|
||||||
@@ -152,7 +156,7 @@ class AccessLogParser
|
|||||||
return (int) strtotime("{$m[1]} {$m[2]} {$m[3]} {$m[4]} {$m[5]}");
|
return (int) strtotime("{$m[1]} {$m[2]} {$m[3]} {$m[4]} {$m[5]}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseLine(string $line, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages, array &$ipDays, array &$ipPaths): void
|
private function parseLine(string $line, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages, array &$ipDays, array &$ipPaths, array &$ipPathTs): void
|
||||||
{
|
{
|
||||||
if (!preg_match(self::RE, $line, $m)) {
|
if (!preg_match(self::RE, $line, $m)) {
|
||||||
return;
|
return;
|
||||||
@@ -175,9 +179,12 @@ class AccessLogParser
|
|||||||
if ($publicIp) {
|
if ($publicIp) {
|
||||||
$ips[$ip] = ($ips[$ip] ?? 0) + 1;
|
$ips[$ip] = ($ips[$ip] ?? 0) + 1;
|
||||||
}
|
}
|
||||||
$dayPages[$path][$dayOffset] = ($dayPages[$path][$dayOffset] ?? 0) + 1;
|
$dayPages[$path][$dayOffset] = ($dayPages[$path][$dayOffset] ?? 0) + 1;
|
||||||
$ipDays[$ip][$dayOffset] = ($ipDays[$ip][$dayOffset] ?? 0) + 1;
|
$ipDays[$ip][$dayOffset] = ($ipDays[$ip][$dayOffset] ?? 0) + 1;
|
||||||
$ipPaths[$ip][$path] = ($ipPaths[$ip][$path] ?? 0) + 1;
|
$ipPaths[$ip][$path] = ($ipPaths[$ip][$path] ?? 0) + 1;
|
||||||
|
if ($tsVal > ($ipPathTs[$ip][$path] ?? 0)) {
|
||||||
|
$ipPathTs[$ip][$path] = $tsVal;
|
||||||
|
}
|
||||||
} elseif (str_starts_with($path, '/book/') && strlen($path) > 6) {
|
} elseif (str_starts_with($path, '/book/') && strlen($path) > 6) {
|
||||||
$books[$path] = ($books[$path] ?? 0) + 1;
|
$books[$path] = ($books[$path] ?? 0) + 1;
|
||||||
if ($publicIp) {
|
if ($publicIp) {
|
||||||
@@ -185,10 +192,13 @@ class AccessLogParser
|
|||||||
}
|
}
|
||||||
$ipDays[$ip][$dayOffset] = ($ipDays[$ip][$dayOffset] ?? 0) + 1;
|
$ipDays[$ip][$dayOffset] = ($ipDays[$ip][$dayOffset] ?? 0) + 1;
|
||||||
$ipPaths[$ip][$path] = ($ipPaths[$ip][$path] ?? 0) + 1;
|
$ipPaths[$ip][$path] = ($ipPaths[$ip][$path] ?? 0) + 1;
|
||||||
|
if ($tsVal > ($ipPathTs[$ip][$path] ?? 0)) {
|
||||||
|
$ipPathTs[$ip][$path] = $tsVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseFile(array $file, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages, array &$ipDays, array &$ipPaths): void
|
private function parseFile(array $file, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages, array &$ipDays, array &$ipPaths, array &$ipPathTs): void
|
||||||
{
|
{
|
||||||
if ($file['type'] === 'tgz') {
|
if ($file['type'] === 'tgz') {
|
||||||
try {
|
try {
|
||||||
@@ -199,7 +209,7 @@ class AccessLogParser
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach (explode("\n", $content) as $line) {
|
foreach (explode("\n", $content) as $line) {
|
||||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths, $ipPathTs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -212,7 +222,7 @@ class AccessLogParser
|
|||||||
while (!gzeof($h)) {
|
while (!gzeof($h)) {
|
||||||
$line = gzgets($h, 8192);
|
$line = gzgets($h, 8192);
|
||||||
if ($line !== false) {
|
if ($line !== false) {
|
||||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths, $ipPathTs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gzclose($h);
|
gzclose($h);
|
||||||
@@ -222,7 +232,7 @@ class AccessLogParser
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (($line = fgets($h)) !== false) {
|
while (($line = fgets($h)) !== false) {
|
||||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths, $ipPathTs);
|
||||||
}
|
}
|
||||||
fclose($h);
|
fclose($h);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user