How would I go about having apache pull some lines from log files to be displayed on a website. I want to pull the last 5 vistiors IPs (possiblly while censoring them slightly) and the last 3 IPs to be banned for trying to connect via SSH (which is currently blocked using fail2ban.) I really have no clue where to start with this other than I already have apache up and running and my website is hosted in what can be thought of as a "normal" configuration. The log files are in /var/log/ and I can control the access to them. |
I wasn't using apache httpd for a long time but if log line begins with IP, you can use
to extract 5 last IPs hiding last number or just
to extract 5 last IPs. This may be a cronscript, generating an HTML page can be included in your plain HTML document. Can't describe same process for fail2ban but I guess it's just the same, you'll just have to read the manuals for tools like sed and awk in order to parse logs with shell script. Just remember: if your logs may contain resolved rDNS hostnames instead of IPs this may be dangerous to display them on website, who knows what it could be set to? |
My first thought is that the logs in /var/log are probably owned by Root and thus your web applications won't be able to read them (You can confirm with You could use a (Perl/PHP/Shell) script (cron'd as root) to extract the last X IPs from /var/log/httpd/access_log and /var/log/Fail2Ban.log and write them to a file owned by Apache (or the site user if you're using SuPHP/SuExec) which could then be read by the sites pages and dynamically included. I can't speak much regarding php but if you use Shell or Perl Log Excerpt:
fix the shell commands, please
(08 May '10, 13:56)
Web31337
|
are you using plain apache httpd without any scripting language?