====== Lecture des Logs ======
====== PHP ======
Exemple d'expression régulière : [[https://www.regexpal.com/95830]]
Description du format : [[https://httpd.apache.org/docs/2.4/fr/logs.html#accesslog]]
Tester sur [[https://regex101.com/]]
/^(\S+) (\S+) (\S+) \[([\w:\/]+\s[+\-]\d{4})\] "(\S+)\s?(\S+)?\s?(\S+)?" (\d{3}|-) (\d+|-)\s?"?([^"]*)"?\s?"?([^"]*)?"?$/m
Exemple :
$re = '/^(\S+) (\S+) (\S+) \[([\w:\/]+\s[+\-]\d{4})\] "(\S+)\s?(\S+)?\s?(\S+)?" (\d{3}|-) (\d+|-)\s?"?([^"]*)"?\s?"?([^"]*)?"?$/m';
$str = '91.178.82.190 - - [24/May/2020:11:07:25 +0200] "GET / HTTP/1.1" 302 4049 "https://www.marclebrun.be/pages" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0"';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
print_r($matches);
$host = $matches[ 1][0]; // 91.178.82.190
$datetime = $matches[ 4][0]; // 24/May/2020:11:07:25 +0200
$method = $matches[ 5][0]; // GET
$request = $matches[ 6][0]; // /
$protocol = $matches[ 7][0]; // HTTP/1.1
$status = $matches[ 8][0]; // 302
$size = $matches[ 9][0]; // 4049
$referer = $matches[10][0]; // https://www.marclebrun.be/pages
$userAgent = $matches[11][0]; // Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0
===== GoAccess =====
Site web: [[https://goaccess.io/]]
==== Installation ====
Disponible dans les dépôts Ubuntu :
sudo apt install goaccess
==== Lecture en ligne de commandes ====
Se connecter au serveur par SSH.
sudo goaccess access.log
Appuyer sur **Escpace** afin de sélectionner **NCSA Combined Log format**.
Ensuite appuyer sur **Enter** pour accéder à l'interface en mode texte.
^ Touche ^ Action ^
| TAB / Shift+TAB | Naviguer entre les différents panels |
| ENTER | Déployer un panel pour afficher plus d'infos |
| J et K | Scroller (up/down) à l'intérieur d'un panel |
| Q | Quitter le panel déployé, ou quitter l'interface |
==== Générer un fichier HTML ====
sudo goaccess access.log -o report.html --log-format=COMBINED