Roy@ENHost kindly pointed me to this script:
http://www.josheli.com/vox/view_sour...disk_usage.php
The only thing is is that it returns all of the users' diskspace that are in my WHM. I only need it to find the user who is logged in and return their disk space usage.
Here's the scrip (I've trimmed some of it to focus on the parts that actually handle the connecting):
PHP Code:
<?php
/*
Report looks like this:
Timestamp: September 14, 2003, 6:55 am
Reseller Total: 84.80
Domain: client1.com -- Space used: 19 Meg
Domain: client2.com -- Space used: 11 Meg
Domain: client3.com -- Space used: 104 Meg
Domain: client4.com -- Space used: 0 Meg
Domain: client5.com -- Space used: 14 Meg
Domain: client6.org -- Space used: 13 Meg
Domain: client7.com -- Space used: 8 Meg
Total space used: 253.8
Remaining space: 246.2
*/
/***********************************************************************
Start of configurable variables
************************************************************************/
$whmUser = 'username';
$whmPass = 'password';
$cpUser = 'username';
$cpPass = 'password';
$url = 'www.mydomain.com';//do not include 'https://'
$cpTheme = 'vertex';
$resellerQuota = 500;//in megabytes (e.g. 1.5 gigs would be '1500')
/***********************************************************************
End of configurable variables
************************************************************************/
$msg = 'Timestamp: '.date("F j, Y, g:i a")."\n\n";
//get the main reseller account usage from cpanel
//the other possible way to do this is to do a system call to 'du -ms'
$page = @file_get_contents("https://$cpUser:$cpPass@$url:2083/frontend/$cpTheme/main.html");
$int = preg_match("/>Disk.*?<\/b>/is",$page, $piece);
if($int) {
//$resellerTotal[1] will contain the value
preg_match('/<b>(.*)<\/b>/',$piece[0], $resellerTotal);
$msg .= 'Reseller Total: '.$resellerTotal[1]."\n";
}
//now get the WHM 'list accounts' page
$page2 = @file_get_contents("https://$whmUser:$whmPass@$url:2087/scripts2/listaccts?viewall=1");
//get each accounts table row
$int2 = preg_match_all("/<tr class=(?:tdshade2|tdshade1)>(.*?)<\/tr>/is", $page2, $matches);
if($int2 > 0 && is_array($matches[1])) {
foreach($matches[1] as $match) {
$account = explode('</td><td>',$match);
$msg .= 'Domain: '.strip_tags($account[0]).' -- Space used: '.$account[7]."\n";
$clientTotal += $account[7];
}
$total = ceil($clientTotal + $resellerTotal[1]);
$msg .= 'Total space used: '.$total." mb \n";
$remaining = ceil($resellerQuota - $total);
$msg .= 'Remaining space: '.$remaining." mb \n";
}
else {
$msg .= "No workee.\n";
}
echo nl2br($msg);//to browser
?>
I've been tearing my hair out over this for over 4 hours now. Hoping someone can help!
