1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
| #!/usr/bin/perl
###############################################################################
# Copyright 2000, Way to the Web Limited
# URL: http://www.waytotheweb.com
# Email: sales@waytotheweb.com
# Note: Under NO circumstances may the above three lines be removed or altered
###############################################################################
# StatsNow
$version = "v2.0";
###############################################################################
# start variables
#
$combinedaccess = "/var/log/httpd/access";
$xferlog = "/var/log/xferlog";
$maillog = "/var/log/maillog";
$mailprog = "/usr/sbin/sendmail";
$from = $to = "serverbeheer\@domein.com";
$subject = "Statistics";
#
# end variables
###############################################################################
# Note: Under NO circumstances may the lines below be altered without prior
# permission from Way to the Web Limited
#
# start
opendir (DIR, "/home/sites");
while ($file = readdir (DIR)) {
$link = readlink ("/home/sites/$file");
if ($link ne "") {
@levels = split (/\//,$link);
$domains{$levels[-1]} = $file;
}
}
closedir (DIR);
&process_www;
&process_ftp;
&process_mail;
&process_output;
exit;
# end
###############################################################################
# start process_www
sub process_www {
open (WWW,"<$combinedaccess") or die "Unable to open $combinedaccess";
@www_data = <WWW>;
close (WWW);
chomp @www_data;
foreach $line (@www_data) {
$line =~ s/ / /g;
@array = split (/ /,$line);
$domain = $array[0];
@array = split (/\//,$array[4]);
$month = $array[1];
if ($month ne "") {
if ($www_first eq "") {
($bit,$day) = split (/\\[/,$array[0]);
($year,$bit) = split (/\:/,$array[2]);
$www_first = "$day-$month-$year";
}
@array = split (/\"/,$line);
@array = split (/ /,$array[2]);
$size = $array[2];
$all{"$domain:$month"} += $size;
$www{"$domain:$month"} += $size;
}
}
}
# end process_www
###############################################################################
# start process_ftp
sub process_ftp {
open (FTP,"<$xferlog") or die "Unable to open $xferlog";
@ftp_data = <FTP>;
close (FTP);
chomp @ftp_data;
foreach $line (@ftp_data) {
unless (($line =~ / ftp /) and ($line =~ /\/home\/sites\//)) {next;}
$line =~ s/ / /g;
@array = split (/ /,$line);
$month = $array[1];
if ($month ne "") {
if ($ftp_first eq "") {
$ftp_first = "$array[2]-$month-$array[4]";
}
$size = $array[7];
@array = split (/\//,$array[8]);
$domain = $domains{$array[3]};
if ($domain ne "") {$ftp{"$domain:$month"} += $size;}
$all{"$domain:$month"} += $size;
}
}
}
# end process_ftp
###############################################################################
# start process_mail
sub process_mail {
open (MAIL,"<$maillog") or die "Unable to open $maillog";
@mail_data = <MAIL>;
close (MAIL);
chomp @mail_data;
foreach $line (@mail_data) {
if ($line =~ /size=(\d+)/) {
$size = $1;
$line =~ s/ / /g;
@array = split (/ /,$line);
$month = $array[0];
if ($month ne "") {
if ($mail_first eq "") {
$mail_first = "$array[1]-$month-\?\?\?\?";
}
$mail{"$month"} += $size;
}
}
}
}
# end process_mail
###############################################################################
# start process_output
sub process_output {
$body = "First www date processed = $www_first\n";
$body .= "First ftp date processed = $www_first\n";
$body .= "First mail date processed = $www_first\n";
$body .= "\n\###########################################################################\n\n";
foreach $key (keys %all) {
($domain,$month) = split (/\:/,$key);
$size = ($all{$key} / 1024000);
($before,$after) = split (/\./,$size);
$after .= "00";
$after = substr($after,0,2);
$size = "$before.$after";
$oldsize = "00000000000000000000000000000000000000000000000000".$all{$key};
$oldsize = substr ($oldsize,(length $oldsize)-50,50);
push (@allline,"$month$oldsize\#\#[$month] all for http://$domain = $size(mb)");
$total{$month} += $all{$key};
}
@data = sort @allline;
@data = reverse @data;
foreach $line (@data) {
($start,$info) = split(/\#\#/,$line);
$body .= $info."\n";
}
$body .= "\n\###########################################################################\n\n";
foreach $key (keys %www) {
($domain,$month) = split (/\:/,$key);
$size = ($www{$key} / 1024000);
($before,$after) = split (/\./,$size);
$after .= "00";
$after = substr($after,0,2);
$size = "$before.$after";
$oldsize = "00000000000000000000000000000000000000000000000000".$www{$key};
$oldsize = substr ($oldsize,(length $oldsize)-50,50);
push (@wwwline,"$month$oldsize\#\#[$month] www for http://$domain = $size(mb)");
$total_www{$month} += $www{$key};
}
@data = sort @wwwline;
@data = reverse @data;
foreach $line (@data) {
($start,$info) = split(/\#\#/,$line);
$body .= $info."\n";
}
$body .= "\n\###########################################################################\n\n";
foreach $key (keys %ftp) {
($domain,$month) = split (/\:/,$key);
$size = ($ftp{$key} / 1024000);
($before,$after) = split (/\./,$size);
$after .= "00";
$after = substr($after,0,2);
$size = "$before.$after";
$oldsize = "00000000000000000000000000000000000000000000000000".$ftp{$key};
$oldsize = substr ($oldsize,(length $oldsize)-50,50);
push (@ftpline,"$month$oldsize\#\#[$month] ftp for http://$domain = $size(mb)");
$total_ftp{$month} += $ftp{$key};
}
@data = sort @ftpline;
@data = reverse @data;
foreach $line (@data) {
($start,$info) = split(/\#\#/,$line);
$body .= $info."\n";
}
$body .= "\n\###########################################################################\n\n";
foreach $key (keys %total_www) {
$size = ($total_www{$key} / 1024000);
($before,$after) = split (/\./,$size);
$after .= "00";
$after = substr($after,0,2);
$size = "$before.$after";
$body .= "[$key] www for all = $size(mb)\n";
}
foreach $key (keys %total_ftp) {
$size = ($total_ftp{$key} / 1024000);
($before,$after) = split (/\./,$size);
$after .= "00";
$after = substr($after,0,2);
$size = "$before.$after";
$body .= "[$key] ftp for all = $size(mb)\n";
}
foreach $key (keys %mail) {
$size = ($mail{$key} / 1024000);
($before,$after) = split (/\./,$size);
$after .= "00";
$after = substr($after,0,2);
$size = "$before.$after";
$body .= "[$key] mail for all = $size(mb)\n";
$total{$month} += $mail{$key};
}
$body .= "\n\###########################################################################\n\n";
foreach $key (keys %total) {
$size = ($total{$key} / 1024000);
($before,$after) = split (/\./,$size);
$after .= "00";
$after = substr($after,0,2);
$size = "$before.$after";
$body .= "[$key] Grand Total = $size(mb)\n";
}
$body .= "\n";
open (MAIL, "|$mailprog -t $to") || die ("Can't open $mailprog!");
print MAIL "From: $from\n";
print MAIL "To: $to\n";
print MAIL "Subject: $subject\n";
print MAIL "$body";
close (MAIL);
}
# end process_output
############################################################################### |