|
Server : Apache/2.4.62 System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64 User : www ( 80) PHP Version : 8.3.8 Disable Function : NONE Directory : /config/ |
Upload File : |
#!/usr/bin/perl
use lib qw(/config);
use modDB qw(mysql hosting provision pr0v1s10n 192.168.25.115);
modDB::dbDebug(4);
my $base = '/var/log/httpd/';
opendir(DIR, "$base");
@dirs = readdir(DIR);
closedir(DIR);
my ($machine_id) = modDB::fetchRow(q[select id from machine_table where name = ?],'fbsdweb2');
foreach $username (@dirs)
{
my ($login_id) = modDB::fetchRow(q[select login_id from user_table where username=?],$username);
next unless $login_id;
$path = "$base/$username/logs/";
opendir(LOG, $path);
@logs = readdir(LOG);
closedir(LOG);
foreach $log (@logs)
{
next unless -f "$path$log";
next unless $log =~ m/\.log$/;
next unless $log =~ m/ex(\d\d\d\d)(\d\d)(\d\d).log/;
$date = "$1-$2-$3";
my ($size) = modDB::fetchRow(q[select filesize from bandwidth_table where logdate = ? and login_id = ? and machine_id = ?], $date, $login_id, $machine_id);
$new_size = -s "$path$log";
next if( $new_size == $size );
# print $new_size
# print " $path$log $size \n";
$total = get_total("$path$log");
modDB::dbDo(q[delete from bandwidth_table where logdate = ? and login_id = ? and machine_id = ?], $date, $login_id, $machine_id);
modDB::dbDo(q[insert into bandwidth_table set logdate = ? , login_id = ? ,machine_id = ?, filesize=?, data=? ], $date, $login_id, $machine_id, $new_size , $total);
#print " $username - $date - $total\n";
}
}
exit;
sub get_total
{
my $file = shift;
open (FILE, $file);
#my @data = <FILE>;
my $total = 0;
while(my $line = <FILE>)
{
$line =~ s/"(.*?)"/spaceless($1)/ge;
$line =~ s/[\[\]]//g;
my (@a) = split / /,$line;
# print "$a[7] $line";
$total += $a[7];
}
close (FILE);
return $total;
}
exit;
sub spaceless
{
my $item = shift;
$item =~ s/ /+/g;
return $item;
}