You could run this shell script by adding a line into your crontab something
like the following.
0 0,6,12,18 * * * /path/to/extract-anonftp.sh
#!/bin/sh
#
# extract anonymous-ftp downloads from wu-ftpd xferlog
#
# (c) 1997 Tadashi Kawaguchi <tk@kawaguchi.k-inet.com>
#
XFERLOG=/var/adm/ftpd/xferlog
ANONFTPLOG=/home/foo/some/dir/anonftp.log
CGI=/home/foo/some/dir/anonftp_stat.cgi
HTML=/home/foo/public_html/anonftp_stat.html
MKHTML=yes
/usr/bin/grep ' _ o a ' $XFERLOG \
| /usr/bin/grep -v '\* i$' \
| /usr/bin/sed -e 's/^[A-Z][a-z][a-z] //' \
-e 's/ / 0/' \
-e 's/ [0-9][0-9]:[0-9][0-9]:[0-9][0-9]//' \
-e 's/ b _ o a//' \
-e 's/ a _ o a//' \
-e 's/ [0-9]* \// \//' \
-e 's/ ftp 0 \*$//'\
-e 's/ ftp [01] \* c$//' > $ANONFTPLOG
if [ "$MKHTML" = "yes" ]; then
/usr/local/bin/perl $CGI > $HTML
fi
You could convert the extracted anon-ftp log into a HTML file with
this perl script.
You may extract the stats directly from the wu-ftpd xferlog by making
a small change to this script, though I don't think it would be a good
idea for the system load.
#!/usr/local/bin/perl
#
#################################################################
# #
# Anonymous ftp xferlog to HTML converter #
# #
# Written by Tadashi Kawaguchi <tk@kawaguchi.k-inet.com> #
# Created on: 03/28/97 #
# Last Modified on: 06/22/97 #
# #
#################################################################
######## Define file path ########
$log_file = "/home/foo/public_html/cgi-dir/anonftp.log";
$h_grf_img_1 = "/cgi-dir/images/h_silver.gif";
$h_grf_img_2 = "/cgi-dir/images/h_greenP.jpg";
$h_grf_img_3 = "/cgi-dir/images/h_violetP.jpg";
$h_grf_img_4 = "/cgi-dir/images/h_purpleP.jpg";
$h_grf_img_5 = "/cgi-dir/images/h_purgray.gif";
$h_grf_img_6 = "/cgi-dir/images/h_red.gif";
######## Define variables ########
@allowhost = ('www.your.dom.ain', 'your.dom.ain');
$mkhtmlfile = "1"; # Set "1" when print into a html file
# Set "0" when print out to STDOUT
$min_xfer = "5";
$min_remote = "5";
$min_email = "5";
$min_day = "5";
$title = "your.dom.ain";
$webmaster = "Your Name";
$mailto = "webmaster\@your.dom.ain";
$homeurl = "http://www.your.dom.ain/index.html";
#######################{ begin main }###########################
######## Check host ########
if ($mkhtmlfile == 0)
{
if ($ENV{'HTTP_REFERER'}) {
foreach $i (0 .. $#allowhost) {
if ($ENV{'HTTP_REFERER'} =~ /$allowhost[$i]/i) {
$goodhost = '1';
last;
}
}
}
else {
$goodhost = '1';
}
if ($goodhost != '1') {
print "Content-type: text/plain\n";
print "Status: 400 Bad Request\n\n";
print "$ENV{'HTTP_REFERER'} is not allowed to access this cgi script!\n";
exit 1;
}
}
#### Get current localtime ####
@month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($mday < 10) { $mday = "0$mday"; }
$year = $year + 1900;
$current_date = "$hour\:$min\:$sec $mday/$month[$mon]/$year";
#### Read data from the log file ####
open(DB,"$log_file") || die "can\'t open $log_file: $!\n";
@lines = <DB>;
close(DB);
$total_num = @lines;
# Skip broken lines
foreach $i (0 .. 15) {
if ($lines[$i] =~ /(.*) (.*) (.*) (.*) (.*) (.*) (.*)/) {
$first_mm = $1;
$first_dd = $2;
$first_yy = $3;
$first_date = "$first_dd/$first_mm/$first_yy";
last;
} else {
$first_date = "";
}
}
foreach $i (0 .. 15) {
if ($lines[($#lines - $i)] =~ /(.*) (.*) (.*) (.*) (.*) (.*) (.*)/) {
$last_mm = $1;
$last_dd = $2;
$last_yy = $3;
$last_date = "$last_dd/$last_mm/$last_yy";
last;
} else {
$last_date = "";
}
}
#### Split each element then put it into assosiative array ####
foreach $line (@lines) {
if ($line =~ /(.* \d{4}) (.*) (.*) (.*) (.*)/) {
$date = $1;
($mm,$dd,$yy) = split(/ /,$date);
if ($mm eq 'Jan') { $mm = '01'; }
if ($mm eq 'Feb') { $mm = '02'; }
if ($mm eq 'Mar') { $mm = '03'; }
if ($mm eq 'Apr') { $mm = '04'; }
if ($mm eq 'May') { $mm = '05'; }
if ($mm eq 'Jun') { $mm = '06'; }
if ($mm eq 'Jul') { $mm = '07'; }
if ($mm eq 'Aug') { $mm = '08'; }
if ($mm eq 'Sep') { $mm = '09'; }
if ($mm eq 'Oct') { $mm = '10'; }
if ($mm eq 'Nov') { $mm = '11'; }
if ($mm eq 'Dec') { $mm = '12'; }
$day = "$yy/$mm/$dd";
$xfer_fn = $4;
$remote_host = $3;
$email_addr = $5;
$xfer_fn =~ s/\/pub.*\///;
if ($day ne '' && $day ne ' ') {
push(@DAYS, $day);
}
if ($xfer_fn ne ' ' && $xfer_fn ne '') {
push(@XFERFN, $xfer_fn);
}
if ($remote_host ne ' ' && $remote_host ne '') {
push(@REMOTE_HOST, $remote_host);
}
if ($email_addr ne ' ' && $email_addr ne '') {
push(@EMAIL_ADDR, $email_addr);
}
}
}
foreach (@XFERFN) {
$xfer{($_)[0]}++;
$xfer_num++;
}
foreach (@REMOTE_HOST) {
$remote{($_)[0]}++;
$remote_num++;
}
foreach (@EMAIL_ADDR) {
$email{($_)[0]}++;
$email_num++;
}
foreach (@DAYS) {
$day{($_)[0]}++;
}
######## Print HTML ########
if ($mkhtmlfile == 0) {
print "Content-type: text/html\n\n";
}
&html_header;
&html_xfer;
&html_remote_host;
&html_email_addr;
&html_days;
&html_trailer;
exit 0;
########################{ end main }###########################
################
sub html_header
{
print qq(<html>
<head>
<META HTTP-EQUIV="Content-Typpe" CONTENT="text/html\; charset=us-ascii">
<title>Download stats for $title</title></head>
<body bgcolor=#faffe2 text=#190880 link=#0000ff vlink=#009148 alink=#ff0000>
<center><h2><font color=0558FF>
Download Stats for $title
</h2></font></center>
<center>Below are the download stats for $title anonymous ftp server.<p>
A total of $total_num were reviewed for this logging, which occurred at:
$current_date
<p>);
unless (($first_date eq "") || ($last_date eq "")) {
print "These statistics reflect downloads from: <i>$first_date</i> to
<i>$last_date</i><p>\n";
}
print qq(</center>
<p><hr size=3 width=75%>
<font size=-1><center>
[ <a href="#html_xfer">Downloaded Files</a> ]
[ <a href="#remote_host">Remote Hosts</a> ]
[ <a href="#html_days">Downloads by Day</a> ]
</center></font>
<hr size=3 width=75%><p>
<br>);
}
################
sub html_xfer
{
print qq(
<center><h2><a name="html_xfer">Downloaded Files</a></h2></center>
<b> Files Searched:</b> <i><u>$xfer_num</u></i><br>
<b>Minimum Downloads Required to Make List:</b> <i><u>$min_xfer</u></i><p>
<font size=-2>
<table border width=100%>
<tr>
<th bgcolor=#30f2ff>Number <br></th>
<th bgcolor=#30f2ff>Percent <br></th>
<th bgcolor=#30f2ff>File Name <br></th>
<th bgcolor=#30f2ff></th>
</tr>);
foreach (sort { $xfer{$b} <=> $xfer{$a} } keys %xfer)
{
if ($xfer{$_} >= $min_xfer)
{
print "<tr>\n";
$total_xfer += $xfer{$_};
$percent_xfer = (int(10000 * ($xfer{$_} / $xfer_num)) / 100);
$pixel_xfer = int(10 * $percent_xfer);
if ($pixel_xfer == 0) {
$pixel_xfer = 1;
}
$total_percent_xfer += $percent_xfer;
$percent_xfer = sprintf("%3.1f%%", $percent_xfer);
print "<th align=right>$xfer{$_} </th>\n";
print "<td align=right>$percent_xfer </td><td>$_</td>\n";
print "<td><img src=\"$h_grf_img_2\" width=$pixel_xfer height=15 border=0></td>\n";
print "</tr>\n";
}
}
$total_percent_xfer = sprintf("%3.1f%%", $total_percent_xfer);
print qq(<tr>
<th align=right><br>$total_xfer </th>
<td align=right><br>$total_percent_xfer </td>
<td align=center><br>\*\* Totals For Downloaded Files Shown \*\*</td>
<td></td>
</tr>
</table>
</font>
<p><hr size=7 width=75%>
<br>);
}
################
sub html_remote_host
{
print qq(
<center><h2><a name="remote_host">Remote Hosts</a></h2></center>
<b> Remote Hosts Searched:</b> <u><i>$remote_num</i></u><br>
<b>Minimum Hits Required to Make List:</b> <i><u>$min_remote</u></i><p>
<font size=-2>
<table border width=100%>
<tr>
<th bgcolor=#30f2ff>Number <br></th>
<th bgcolor=#30f2ff>Percent <br></th>
<th bgcolor=#30f2ff>Remote Hosts <br></th>
<th bgcolor=#30f2ff></th>
</tr>);
foreach (sort { $remote{$b} <=> $remote{$a} } keys %remote)
{
if ($remote{$_} >= $min_remote)
{
print "<tr>\n";
$total_remote += $remote{$_};
$percent_remote = (int(10000 * ($remote{$_} / $remote_num)) / 100);
$pixel_remote = int(80 * $percent_remote);
if ($pixel_remote == 0) {
$pixel_remote = 1;
}
$total_percent_remote += $percent_remote;
$percent_remote = sprintf("%3.1f%%", $percent_remote);
print "<th align=right>$remote{$_} </th>\n";
print "<td align=right>$percent_remote </td><td>$_</td>\n";
print "<td><img src=\"$h_grf_img_3\" width=$pixel_remote height=10 border=0></td>\n";
print "</tr>\n";
}
}
$total_percent_remote = sprintf("%3.1f%%", $total_percent_remote);
print qq(<tr>
<th align=right><br>$total_remote </th>
<td align=right><br>$total_percent_remote </td>
<td align=center><br>\*\* Totals For Remote Hosts Shown \*\*</td>
<td></td>
</tr>
</table>
</font>
<P><hr size=7 width=75%>
<br>);
}
################
sub html_email_addr
{
print qq(
<a name="html_email"><center><h2>Email Address</h2></center></a>
<b> Email Address Searched:</b> <u><i>$email_num</i></u><br>
<b>Minimum Hits Required to Make List:</b> <i><u>$min_email</u></i><p>
<font size=-2>
<table border width=100%>
<tr>
<th bgcolor=#30f2ff>Number <br></th>
<th bgcolor=#30f2ff>Percent <br></th>
<th bgcolor=#30f2ff>Address <br></th>
<th bgcolor=#30f2ff></th>
</tr>);
foreach (sort { $email{$b} <=> $email{$a} } keys %email)
{
if ($email{$_} >= $min_email)
{
print "<tr>\n";
$total_email += $email{$_};
$percent_email = (int(10000 * ($email{$_} / $email_num)) / 100);
$pixel_email = int(3 * $percent_email);
if ($pixel_email == 0) {
$pixel_email = 1;
}
$percent_email = sprintf("%3.1f%%", $percent_email);
$total_percent_email += $percent_email;
print "<th align=right>$email{$_} </th>\n";
print "<td align=right>$percent_email </td><td>$_</td>\n";
print "<td><img src=$h_grf_img_4 width=$pixel_email height=10 border=0></td>\n";
print "</tr>\n";
}
}
$total_percent_email = sprintf("%3.1f%%", $total_percent_email);
print qq(<tr>
<th align=right><br>$total_email </th>
<td align=right><br>$total_percent_email </td>
<td align=center><br>\*\* Totals For Email Address Shown \*\*</td>
<td></td>
</tr>
</table>
</font>
<P><hr size=7 width=75%>
<br>);
}
################
sub html_days
{
print qq(
<a name="html_days"><center><h2>Downloads By Day</h2></center></a>
<font size=-2>
<table border width=100%>
<tr>
<th bgcolor=#30f2ff>Day<br></th>
<th colspan=2 bgcolor=#30f2ff>Number of Downloads<br></th>
</tr>);
foreach (sort keys %day)
{
$pixel_day = int(5 * $day{$_});
if ($pixel_day == 0) {
$pixel_day = 1;
}
print "<tr>\n";
print "<th>$_</th><td align=right>$day{$_}</td><td>\n";
print "<img src=\"$h_grf_img_1\" width=$pixel_day height=10 border=0></td>\n";
print "</tr>\n";
}
print "</table></font><p><br>\n";
}
################
sub html_trailer
{
print qq(
<p><hr size=3 width=75%>
<font size=-1><center>
[ <a href="#html_xfer">Downloaded Files</a> ]
[ <a href="#remote_host">Remote Hosts</a> ]
[ <a href="#html_days">Downloads by Day</a> ]
</center></font>
<hr size=3 width=75%><p>
<hr size=5 width=100%>
<center>
<table border=0 width=90%>
<tr>
<td align=left><font size=2><a href="$homeurl">Back to Home</a></font></td>
<td align=right><font size=2><a href="mailto:$mailto">$webmaster <$mailto></a></font></td>
</tr>
</table>
</center>
<img src="/cgi-dir/anonftp-count-log.cgi" width=1 height=1>
</body></html>\n);
}
#################################################################
# (c) 1997 Tadashi Kawaguchi <tk@kawaguchi.k-inet.com> #
# http://www.k-inet.com/ #
# http://www.erehwon.org/ #
# http://macware.erehwon.org/ #
#################################################################
![]() |
Back to Home | ©1995-2001 Erehwon.org, All Rights Reserved. |