[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cobalt-users] Transfer quota's, the ultimate script
- Subject: [cobalt-users] Transfer quota's, the ultimate script
- From: Marco Baurdoux <linux@xxxxxxxxxxxxx>
- Date: Tue Oct 16 05:43:01 2001
- List-id: Mailing list for users to share thoughts on Cobalt products. <cobalt-users.list.cobalt.com>
Hi there,
Now you host several websites on your RAQ, and you would like to be able to
know in one go which sites, have more traffic then you allow them to have.
Up to now there was MRTG, but it could only controll the overall traffic
from your machine. You could use very expensive switch, which could filter
out this kind of info, or go in manually to see whether or not your
customers exploded their traffic quota.
But how about getting the names of the websites, that are over quota mailed
to you ?? Hum, interested ??? Well here it is the only thing I would like
you to do is keep my name in the soft (same as with the MySQL, PostgreSQL
and /etc backup by the way), since I'm still very young so only good working
programs can upgrade my market value :-))
Requirements :
* A cobalt RaQ 3/4
* PHP installed a 4.* will do, maybe even a 3.*
* Webalizer 1.*/2.* as long as it puts its history files in
/home/sites/www.mydomain.com/stats/webalizer.hist
* an e-mail address ( dugh !! )
* an idea of what a reasonable quota would be
* some shell knowledge !!
1. copy this PHP script onto your machine, carefull it needs to be able to
accès all the files on the machine, so it shouldn't be put on a site that
has safe-mode or open_basedir activated.
<?
/************************************************************************
* *
* Traffic overload announcer *
* Marco Baurdoux *
* linux@xxxxxxxxxxxxx *
* 16.10.1977 *
* *
************************************************************************/
/************************************************************************
Main Configuration
************************************************************************/
$quota = "20"; //Put it in Gigabytes, ie 20 means
20 GB
$mail_address = "linux@xxxxxxxxxxxxx"; //Pretty straight forward
/************************************************************************
!!! DO NOT EDIT BELOW THIS LINE !!!
************************************************************************/
//Now lets convert the quota into bytes.
$limit = ($quota * 1000 * 1024);
//Now let us run throuh the websites that are hosted on my raq
//All I do is make a array out the webalizer.hist file and fetch
//the 5 entry from it, that correponds to the "kbytes" entry, because
//that's what I wanted to check.
header("Content-type: text/plain");
$body = "Traffic overload announcer\n";
$body .= "Written by : Marco Baurdoux\n";
$body .= "linux@xxxxxxxxxxxxx\n\n";
$body .= "********************************************\n";
$body .= "The transfer limit has been set to $quota GB\n";
$body .= "********************************************\n\n";
$body .= "Website\tLast month\tCurrent month\n\n";
if($handle = opendir("/home/sites"))
{
$dot = readdir($handle);
$dotdot = readdir($handle);
while($entry = readdir($handle))
{
if(is_link("/home/sites/$entry"))
{
//bande($entry);
if($webalizer =
@file("/home/sites/$entry/stats/webalizer.hist"))
{
$x = count($webalizer);
$y = $x -2;
$z = $x -1;
$line0 = explode(" ", $webalizer[$y]);
$line1 = explode(" ", $webalizer[$z]);
if($line0[5] > $limit || $line1[5] > $limit)
{
$body .= $entry;
$body .= "\t";
$body .= $line0[5];
$body .= "\t";
$body .= $line1[5];
$body .= "\n";
}
}
}
}
if(mail($mail_address, "Sites overload for $SERVER_NAME", $body))
{
print "Youpi";
}
else
{
print "Merde";
}
}
?>
2. Edit the script, put in your quota and your e-mail addres in.
3. su to root and perform :
chown root script.php4
That's it,
fi you wish to make a cron out of it use this
lynx -dump http://cobaltx.mydomain.com/script.php4
if you put your script.php4 in a directory that requires authentification
through an htaccs then use this line
lynx -dump -auth=username:password http://cobaltx.mydomain.com/script.php4
it's as simpel as that.
=======================================================================
Marco Baurdoux
Unix Administrator
Infomaniak Network SA
Avenue de la Praille 26
1227 Carouge
Switzerland
Tel: +41 (0)22 820 35 41
Fax: +41 (0)22 820 35 46
http://web.infomaniak.ch
Linux/Unix is very user friendly,
it's just very picky about who its friends are !!!
=======================================================================