"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #!/usr/bin/perl
2
3 ### stat4proftpd v1.0.1
4
5 ### stat4proftpd is a Perl script (with console interface) that
6 ### shows some statistics (input/output traffic, the most
7 ### requested files, the most active users) taken from the
8 ### default TransferLog file(s) created by ProFTPD.
9 ### Homepage: http://www.nixp.ru/shurup/coding/
10
11 ### Copyright (C) 2004 Dmitry Shurupov
12 ### E-mail to contact: root (at) nixp (dot) ru
13
14 ### CHANGE THIS VARIABLES
15 ### paths to ProFTPD's TransferLog files
16 my @files=("/var/log/proftpd.log");
17 ### turn on/off showing of the most requested files
18 my $enable_topfiles=1;
19 ### a number of the most requested files to show
20 my $topfiles=5;
21 ### turn on/off showing of the most active users
22 my $enable_topusers=1;
23 ### a number of the most active users to show
24 my $topusers=5;
25 ### that's all
26
27 my ($file,$files);
28
29 my ($tday,$tmonth,$tyear); &get_time;
30 my ($day,$month,$year)=(0,0,0);
31
32 my $myear=1970;
33 my @months=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
34
35 sub get_time{
36 use Time::localtime; my $tm=localtime;
37 ($tday,$tmonth,$tyear)=($tm->mday,($tm->mon)+1,$tm->year+1900);
38 if ($tmonth<10) { $tmonth="0" . $tmonth; }
39 if ($tday<10) { $tday="0" . $tday; }
40 }
41
42 system("clear");
43
44 print "stat4proftpd v1.0.1 [http://www.nixp.ru/shurup/coding/]\n";
45 print "Copyright (C) 2004 Dmitry Shurupov\n\n";
46 print "Skip putting <Enter> for the current day/month/year [$tday/$tmonth/$tyear].\n";
47 print "Input * to take account of all the days/months/years\n\n";
48
49 do { print " Year ($myear-$tyear/*): "; chomp($year=<STDIN>); } until (!$year || $year eq "*" || ($year=~/^(\d{4})$/ && $1>=$myear && $1<=$tyear));
50 if (!$year){ $year=$tyear; }
51
52 do { print " Month (1-12/*): "; chomp($month=<STDIN>); } until (!$month || $month eq "*" || ($month=~/^(\d{1,2})$/ && $1>=1 && $1<=12));
53 if (!$month){ $month=$tmonth; $month=~s/^0//; }
54
55 do { print " Day (1-31/*): "; chomp($day=<STDIN>); } until (!$day || $day eq "*" || ($day=~/^(\d{1,2})$/ && $1>=1 && $1<=31));
56 if (!$day){ $day=$tday; $day=~s/^0//; }
57
58 $month=$months[$month-1] if ($month ne "*");
59
60 my ($sum_o,$sum_i)=(0,0);
61 my %popfile; my %popuser;
62
63 foreach $files(@files){
64 if (open(FILE,$files)){
65 while($file=<FILE>){
66 chomp($file); my @tmp=split(/\s+/,$file);
67 if (($year eq "*" || $tmp[4] eq $year) && ($month eq "*" || uc($tmp[1]) eq uc($month)) && ($day eq "*" || $tmp[2] eq $day)){
68 if ($tmp[11] eq "o"){ $sum_o+=$tmp[7]; $popfile{$tmp[8]}++ if ($enable_topfiles); }
69 elsif ($tmp[11] eq "i"){ $sum_i+=$tmp[7]; }
70 if ($enable_topusers){ $popuser{$tmp[6]}++; }
71 }
72 }
73 close(FILE);
74 } else { print "Notice: can't open `$files`.\n"; }
75 }
76
77 if ($sum_o>0){ $sum_o=sprintf("%.3f",$sum_o/1048576); $sum_o=~/\./; $sum_o=$`.".".substr($',0,3); }
78 if ($sum_i>0){ $sum_i=sprintf("%.3f",$sum_i/1048576); $sum_i=~/\./; $sum_i=$`.".".substr($',0,3); }
79
80 system("clear");
81 print qq~--------------------------------
82 Stats for $day $month $year:
83
84 Output traffic: $sum_o mb
85 Input traffic: $sum_i mb\n~;
86
87 if ($enable_topfiles){
88 print "\n The most requested files:\n";
89 my @popfile2=sort { $popfile{$b} <=> $popfile{$a} }(keys %popfile); my $zc=0;
90 while(++$zc<=$topfiles){
91 print " #$zc: ";
92 if ($popfile2[$zc-1]){ print "$popfile2[$zc-1] ($popfile{$popfile2[$zc-1]})\n"; }
93 else { print "---\n"; }
94 }
95 }
96
97 if ($enable_topusers){
98 print "\n The most active users:\n";
99 my @popuser2=sort { $popuser{$b} <=> $popuser{$a} }(keys %popuser); my $zc=0;
100 while(++$zc<=$topusers){
101 print " #$zc: ";
102 if ($popuser2[$zc-1]){ print "$popuser2[$zc-1] ($popuser{$popuser2[$zc-1]})\n"; }
103 else { print "---\n"; }
104 }
105 }
106
107 print qq~\n--------------------------------\n~;