' . $_log . '';
} elseif (stripos($_log, 'fatal') !== false) {
echo '
' . $_log . '
';
} elseif (stripos($_log, 'warn') !== false OR stripos($_log, 'alert') !== false) {
echo '' . $_log . '
';
} elseif (stripos($_log, 'notice') !== false) {
echo '' . $_log . '
';
} else {
echo '' . $_log . '
';
}
}
public static function filtreLog(string $_log){
$log = self::hidePassword($_log);
$log = self::hideEmail($log);
self::printLog($log);
}
private static function startsWithIpDate(string $str): bool {
return preg_match(
'/^\d{1,3}(\.\d{1,3}){3},\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},/',
$str
) === 1;
}
public static function printLogAttempts(string $_log){
if (self::startsWithIpDate($_log)) {
$parts = explode(',', $_log, 4);
if (count($parts) === 4) {
echo ''
. '' . htmlspecialchars($parts[0]) . ', '
. '' . htmlspecialchars($parts[1]) . ', '
. '' . htmlspecialchars($parts[2]) . ', '
. '' . htmlspecialchars($parts[3]) . ''
. '
';
return;
}
}
elseif (stripos($_log, 'error') !== false) {
echo '' . $_log . '
';
} elseif (stripos($_log, 'fatal') !== false) {
echo '' . $_log . '
';
} elseif (stripos($_log, 'warn') !== false OR stripos($_log, 'alert') !== false) {
echo '' . $_log . '
';
} elseif (stripos($_log, 'notice') !== false) {
echo '' . $_log . '
';
} else {
echo '' . $_log . '
';
}
}
private static function ifFolderWww(string $_log){
return (stripos($_log, DOCUMENT_ROOT) !== false) ? TRUE : FALSE;
}
private static function ifFolderDomain(string $_log){
return (stripos($_log, DOMAIN_CMS) !== false) ? TRUE : FALSE;
}
private static function ifGeneral(string $_log){
return (stripos($_log, "/var/www/") == FALSE AND stripos($_log, "https://") == FALSE) ? TRUE : FALSE;
}
private static function hidePassword($input) {
return preg_replace("/('password'\s*=>\s*)'[^']*'/", "$1'##PASSWORD##'", $input);
}
private static function hideEmail($input) {
return preg_replace("/('email'\s*=>\s*)'[^']*'/", "$1'##EMAIL##'", $input);
}
public static function consoleApache(){
if (!is_readable(SERVER_LOGS_APACHE)) {
echo "Le fichier n'est pas accessible en lecture.";
exit();
}
$lines = file(SERVER_LOGS_APACHE);
$search = strtolower($_GET['search'] ?? '');
$limit = strtolower($_GET['limit'] ?? 50); // A défaut les 50 derniers logs
if ($search) {
$lines = array_filter($lines, fn($line) => stripos($line, $search) !== false);
}
$lines = array_reverse($lines);
echo '
';
foreach (array_slice($lines, 0, $limit) as $line) {
serverLog::filtreLog($line);
}
echo '
';
}
public static function consoleAttempts(){ echo SERVER_LOGS_BLACKLIST . "/ip_attempts.log";
if (!is_readable(SERVER_LOGS_BLACKLIST . "/ip_attempts.log")) {
echo "Le fichier n'est pas accessible en lecture.";
exit();
}
$lines = file(SERVER_LOGS_BLACKLIST . "/ip_attempts.log");
$search = strtolower($_GET['search'] ?? '');
$limit = strtolower($_GET['limit'] ?? 50); // A défaut les 50 derniers logs
if ($search) {
$lines = array_filter($lines, fn($line) => stripos($line, $search) !== false);
}
$lines = array_reverse($lines);
echo '
';
foreach (array_slice($lines, 0, $limit) as $line) {
serverLog::filtreLog($line);
}
echo '
';
}
public static function consoleIpBlacklist(){
if (!is_readable(SERVER_LOGS_BLACKLIST . "/ip.txt")) {
echo "Le fichier n'est pas accessible en lecture.";
exit();
}
$lines = file(SERVER_LOGS_BLACKLIST . "/ip.txt");
$search = strtolower($_GET['search'] ?? '');
$limit = strtolower($_GET['limit'] ?? 50); // A défaut les 50 derniers logs
if ($search) {
$lines = array_filter($lines, fn($line) => stripos($line, $search) !== false);
}
$lines = array_reverse($lines);
echo '
';
foreach (array_slice($lines, 0, $limit) as $line) {
serverLog::filtreLog($line);
}
echo '
';
}
}