Fix public client IP extraction and hide duplicate footer creation date

- Enhance RequestLogger::getClientIp() with 2-pass detection prioritizing public IPs over proxy/internal IPs
- Hide footer creation date when identical to modification date to prevent duplicate date display
- Improve AdminAuth log helper and footer template tooltips
This commit is contained in:
2026-07-28 17:11:00 +02:00
parent 0626e8c6cc
commit e2d9ddd516
4 changed files with 47 additions and 21 deletions
+6
View File
@@ -478,9 +478,13 @@ class CodePressCMS {
$created = date('d-m-Y H:i', $createdTimestamp);
}
// Show created date only if it is distinctly different from modified date
$showCreated = ($created !== $modified);
return [
'created' => $created,
'modified' => $modified,
'show_created' => $showCreated,
'size' => $this->formatFileSize($stats['size'])
];
}
@@ -1151,10 +1155,12 @@ class CodePressCMS {
if (isset($page['file_info'])) {
$templateData['created'] = htmlspecialchars($page['file_info']['created']);
$templateData['modified'] = htmlspecialchars($page['file_info']['modified']);
$templateData['show_created'] = !empty($page['file_info']['show_created']);
$templateData['file_info_block'] = true;
} else {
$templateData['created'] = '';
$templateData['modified'] = '';
$templateData['show_created'] = false;
$templateData['file_info_block'] = false;
}
+31 -12
View File
@@ -25,29 +25,48 @@ class RequestLogger
public static function getClientIp(): string
{
$headers = [
$headerKeys = [
'HTTP_CF_CONNECTING_IP',
'HTTP_X_REAL_IP',
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR',
];
foreach ($headers as $header) {
if (!empty($_SERVER[$header])) {
$rawIp = $_SERVER[$header];
if (str_contains($rawIp, ',')) {
$ips = explode(',', $rawIp);
$rawIp = trim($ips[0]);
}
$rawIp = trim($rawIp);
if (filter_var($rawIp, FILTER_VALIDATE_IP) !== false) {
return $rawIp;
// Pass 1: Prioritize valid PUBLIC IP addresses (skips 127.0.0.1, 10.x, 172.x, 192.168.x proxy/internal IPs)
foreach ($headerKeys as $key) {
if (empty($_SERVER[$key])) continue;
$value = $_SERVER[$key];
$ips = str_contains($value, ',') ? explode(',', $value) : [$value];
foreach ($ips as $rawIp) {
$ip = trim($rawIp);
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
return $ip;
}
}
}
return $_SERVER['REMOTE_ADDR'] ?? 'cli';
// Pass 2: Fallback for local development environments
foreach ($headerKeys as $key) {
if (empty($_SERVER[$key])) continue;
$value = $_SERVER[$key];
$ips = str_contains($value, ',') ? explode(',', $value) : [$value];
foreach ($ips as $rawIp) {
$ip = trim($rawIp);
if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
return $ip;
}
}
}
return $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
}
public static function detectVisitorInfo(string $ua, string $user = ''): array
+5 -3
View File
@@ -9,10 +9,12 @@
<span class="page-title d-none d-lg-inline" title="{{page_title}}">{{page_title}}</span>
{{#file_info_block}}
<span class="ms-2">
{{#show_created}}
<i class="bi bi-calendar-plus footer-icon" title="{{t_created}}: {{created}}"></i>
<span class="file-created">{{created}}</span>
<i class="bi bi-calendar-check ms-1 footer-icon" title="{{t_modified}}: {{modified}}"></i>
<span class="file-modified">{{modified}}</span>
<span class="file-created me-1" title="{{t_created}}: {{created}}">{{created}}</span>
{{/show_created}}
<i class="bi bi-calendar-check footer-icon" title="{{t_modified}}: {{modified}}"></i>
<span class="file-modified" title="{{t_modified}}: {{modified}}">{{modified}}</span>
</span>
{{/file_info_block}}
</small>