#!/usr/bin/perl -w # # # (C) Oct 2000, by Deniss (deniss at fuckoff.com) # # use Pg; $mailprog = '/usr/sbin/sendmail'; $recipient = 'boss@company.com'; $date = `/bin/date +"%A, %B %d, %Y at %T (%Z)"`; chop($date); $my_year=`/bin/date -d yesterday +%Y`; # for year ! $my_mon=`/bin/date -d yesterday +%m`; # for month ! $conn = Pg::setdbLogin("localhost","" , "", "", "accounting", "nobody",""); if ($conn->status == PGRES_CONNECTION_BAD) { print "Error Connect to Database\n";die;}; $query="SELECT ip FROM users"; $result = $conn->exec($query); if ($result->resultStatus == PGRES_BAD_RESPONSE ){ print "Oooppsss, Query Error\n";die;}; while (@usrow = $result->fetchrow) { $query="select sum(\"out\") as \"out\",sum(\"in\") as \"in\" from statistic WHERE date_part('month',date)=$my_mon AND date_part('year',date)=$my_year AND ip='$usrow[0]'"; $result2 = $conn->exec($query); if ($result2->resultStatus == PGRES_BAD_RESPONSE ){ print "Oooppsss, Query Error\n";die;}; my @row; @row = $result2->fetchrow; if (($row[0]>200000000) or ($row[1]>200000000)) {mailto($row[0],$row[1],$usrow[0]);}; } sub mailto { open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n"; print MAIL "To: $recipient\n"; print MAIL "From: Internet statistic counting program \n"; print MAIL "Date: $date\n"; print MAIL "Subject: 200Mb exceed\n\n"; $i_result = $conn->exec("select * from users where ip='$_[2]'"); if ($i_result->resultStatus == PGRES_BAD_RESPONSE ){ print "Oooppsss, Query Error\n";die;} @user = $i_result->fetchrow; print MAIL "User $user[2]($_[2]) has international incoming traffic $_[1] bytes\n"; print MAIL "User $user[2]($_[2]) has international outgoing traffic $_[0] bytes\n"; print MAIL "You can contact $user[2] via email $user[10] or via phone $user[3]\n"; print MAIL "Today: $date Statistic calculated till tonight\n"; print MAIL "\t\t\t\t\tCoded by Deniss\n"; close (MAIL); }