v1.6.28 : drill-down IP par AS dans stats pays, suppression Répartition par réseau
- Admin stats : clic sur un réseau AS affiche les IPs avec mini sparkline 14 jours + articles/livres consultés - AccessLogParser : calcul ip_data (daily + top paths) inclus dans le cache stats - Suppression du tableau statique "Répartition par réseau" (fusionné dans accordéon pays) - PHP-CS-Fixer appliqué sur l'ensemble des fichiers modifiés Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+43
-14
@@ -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>>}
|
||||
* @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>>}
|
||||
*/
|
||||
public function stats(): array
|
||||
{
|
||||
@@ -48,19 +48,19 @@ class AccessLogParser
|
||||
$pages = [];
|
||||
$books = [];
|
||||
$ips = [];
|
||||
$dayPages = []; // [path => [dayOffset => count]], dayOffset 0=oldest
|
||||
$dayPages = [];
|
||||
$ipDays = []; // [ip => [dayOffset => count]]
|
||||
$ipPaths = []; // [ip => [path => count]]
|
||||
|
||||
foreach ($this->logFiles() as $file) {
|
||||
$this->parseFile($file, $cutoff, $pages, $books, $ips, $dayPages);
|
||||
$this->parseFile($file, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
||||
}
|
||||
|
||||
arsort($pages);
|
||||
arsort($books);
|
||||
arsort($ips);
|
||||
|
||||
// Normalise dayPages : pour chaque page, tableau de $this->days entiers (index 0 = le plus ancien)
|
||||
$pagesByDay = [];
|
||||
$today = (int) strtotime('today midnight');
|
||||
foreach ($dayPages as $path => $byOffset) {
|
||||
$arr = array_fill(0, $this->days, 0);
|
||||
foreach ($byOffset as $offset => $count) {
|
||||
@@ -71,7 +71,32 @@ class AccessLogParser
|
||||
$pagesByDay[$path] = $arr;
|
||||
}
|
||||
|
||||
$result = ['pages' => $pages, 'books' => $books, 'ips' => $ips, 'pages_by_day' => $pagesByDay];
|
||||
// Per-IP daily counts + top paths, limité aux 200 IPs les plus actives
|
||||
$topIpKeys = array_keys(array_slice($ips, 0, 200, true));
|
||||
$ipsByDay = [];
|
||||
$ipTopPaths = [];
|
||||
foreach ($topIpKeys as $ip) {
|
||||
$arr = array_fill(0, $this->days, 0);
|
||||
foreach ($ipDays[$ip] ?? [] as $offset => $count) {
|
||||
if ($offset >= 0 && $offset < $this->days) {
|
||||
$arr[$offset] = $count;
|
||||
}
|
||||
}
|
||||
$ipsByDay[$ip] = $arr;
|
||||
|
||||
$paths = $ipPaths[$ip] ?? [];
|
||||
arsort($paths);
|
||||
$ipTopPaths[$ip] = array_slice($paths, 0, 10, true);
|
||||
}
|
||||
|
||||
$result = [
|
||||
'pages' => $pages,
|
||||
'books' => $books,
|
||||
'ips' => $ips,
|
||||
'pages_by_day' => $pagesByDay,
|
||||
'ips_by_day' => $ipsByDay,
|
||||
'ip_top_paths' => $ipTopPaths,
|
||||
];
|
||||
@mkdir(dirname($this->cacheFile), 0755, true);
|
||||
@file_put_contents($this->cacheFile, json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
return self::$memo = $result;
|
||||
@@ -127,7 +152,7 @@ class AccessLogParser
|
||||
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): void
|
||||
private function parseLine(string $line, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages, array &$ipDays, array &$ipPaths): void
|
||||
{
|
||||
if (!preg_match(self::RE, $line, $m)) {
|
||||
return;
|
||||
@@ -142,24 +167,28 @@ class AccessLogParser
|
||||
return;
|
||||
}
|
||||
|
||||
$publicIp = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false;
|
||||
$publicIp = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false;
|
||||
$dayOffset = (int) floor(($tsVal - $cutoff) / 86400);
|
||||
|
||||
if (str_starts_with($path, '/post/') && strlen($path) > 6) {
|
||||
$pages[$path] = ($pages[$path] ?? 0) + 1;
|
||||
if ($publicIp) {
|
||||
$ips[$ip] = ($ips[$ip] ?? 0) + 1;
|
||||
}
|
||||
$dayOffset = (int) floor(($tsVal - $cutoff) / 86400);
|
||||
$dayPages[$path][$dayOffset] = ($dayPages[$path][$dayOffset] ?? 0) + 1;
|
||||
$dayPages[$path][$dayOffset] = ($dayPages[$path][$dayOffset] ?? 0) + 1;
|
||||
$ipDays[$ip][$dayOffset] = ($ipDays[$ip][$dayOffset] ?? 0) + 1;
|
||||
$ipPaths[$ip][$path] = ($ipPaths[$ip][$path] ?? 0) + 1;
|
||||
} elseif (str_starts_with($path, '/book/') && strlen($path) > 6) {
|
||||
$books[$path] = ($books[$path] ?? 0) + 1;
|
||||
if ($publicIp) {
|
||||
$ips[$ip] = ($ips[$ip] ?? 0) + 1;
|
||||
}
|
||||
$ipDays[$ip][$dayOffset] = ($ipDays[$ip][$dayOffset] ?? 0) + 1;
|
||||
$ipPaths[$ip][$path] = ($ipPaths[$ip][$path] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private function parseFile(array $file, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages): void
|
||||
private function parseFile(array $file, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages, array &$ipDays, array &$ipPaths): void
|
||||
{
|
||||
if ($file['type'] === 'tgz') {
|
||||
try {
|
||||
@@ -170,7 +199,7 @@ class AccessLogParser
|
||||
continue;
|
||||
}
|
||||
foreach (explode("\n", $content) as $line) {
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages);
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
@@ -183,7 +212,7 @@ class AccessLogParser
|
||||
while (!gzeof($h)) {
|
||||
$line = gzgets($h, 8192);
|
||||
if ($line !== false) {
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages);
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
||||
}
|
||||
}
|
||||
gzclose($h);
|
||||
@@ -193,7 +222,7 @@ class AccessLogParser
|
||||
return;
|
||||
}
|
||||
while (($line = fgets($h)) !== false) {
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages);
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
||||
}
|
||||
fclose($h);
|
||||
}
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ class BookManager
|
||||
$this->bookPath($slug),
|
||||
json_encode($book, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\n"
|
||||
);
|
||||
$this->git?->commit("book: " . ($book['title'] ?? $slug));
|
||||
$this->git?->commit('book: ' . ($book['title'] ?? $slug));
|
||||
}
|
||||
|
||||
public function delete(string $slug): void
|
||||
|
||||
+3
-1
@@ -4,7 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
class DataGit
|
||||
{
|
||||
public function __construct(private string $dataDir) {}
|
||||
public function __construct(private string $dataDir)
|
||||
{
|
||||
}
|
||||
|
||||
public function commit(string $message): void
|
||||
{
|
||||
|
||||
@@ -61,7 +61,9 @@ PROMPT;
|
||||
$raw = $this->provider === 'claude_code'
|
||||
? $this->queryClaudeCode(self::SYSTEM_ANALYZE, $userMsg)
|
||||
: $this->queryAnthropicRaw(self::SYSTEM_ANALYZE, $userMsg, 4096);
|
||||
if (!$raw['ok']) return $raw;
|
||||
if (!$raw['ok']) {
|
||||
return $raw;
|
||||
}
|
||||
return $this->parseAnalyzeResponse($raw['text'] ?? '');
|
||||
}
|
||||
|
||||
@@ -129,7 +131,9 @@ PROMPT;
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($err !== '') return ['ok' => false, 'error' => 'Erreur réseau : ' . $err];
|
||||
if ($err !== '') {
|
||||
return ['ok' => false, 'error' => 'Erreur réseau : ' . $err];
|
||||
}
|
||||
|
||||
$data = json_decode((string) $resp, true);
|
||||
if ($http !== 200) {
|
||||
|
||||
@@ -96,14 +96,18 @@ function asGroups(): array
|
||||
function aiProvider(): string
|
||||
{
|
||||
$v = siteSettings()['ai_provider'] ?? '';
|
||||
if ($v !== '') return $v;
|
||||
if ($v !== '') {
|
||||
return $v;
|
||||
}
|
||||
return $_ENV['AI_PROVIDER'] ?? getenv('AI_PROVIDER') ?: 'anthropic';
|
||||
}
|
||||
|
||||
function aiModel(): string
|
||||
{
|
||||
$v = siteSettings()['ai_model'] ?? '';
|
||||
if ($v !== '') return $v;
|
||||
if ($v !== '') {
|
||||
return $v;
|
||||
}
|
||||
return $_ENV['AI_MODEL'] ?? getenv('AI_MODEL') ?: 'claude-haiku-4-5-20251001';
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ class TrendingParser
|
||||
public function __construct(
|
||||
private string $logDir,
|
||||
private string $pattern,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne les $limit chemins les plus consultés depuis $cutoff,
|
||||
|
||||
+6
-2
@@ -66,8 +66,12 @@ function lineDiff(string $old, string $new): array
|
||||
|
||||
if ($n * $m > 2_000_000) {
|
||||
$diff = [['!', "Diff trop grand ({$n}×{$m} lignes) — affichage simplifié."]];
|
||||
foreach ($a as $line) { $diff[] = ['-', $line]; }
|
||||
foreach ($b as $line) { $diff[] = ['+', $line]; }
|
||||
foreach ($a as $line) {
|
||||
$diff[] = ['-', $line];
|
||||
}
|
||||
foreach ($b as $line) {
|
||||
$diff[] = ['+', $line];
|
||||
}
|
||||
return $diff;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user