Last active
December 20, 2015 20:49
-
-
Save danmilleruk/6193236 to your computer and use it in GitHub Desktop.
Checks for accounts with Unlimited Quota on cPanel servers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php -q | |
<?php | |
# Unlimited Quota Check Script | |
# Dan Miller <dm@sub6.com | |
$email = 'dm@sub6.com'; # Email address to send to | |
$hostn = gethostname(); # Machine hostname without a line break | |
$count = 0; # Ignore | |
$logfile = "/root/quota-check-log.txt"; # Log to write out to. | |
function megabyteConvert($kb) { | |
$result = $kb * 1000 / 1024 / 1000; | |
return "{$result} MB"; | |
} | |
function serverType($type) { | |
$hostname = `/bin/hostname`; | |
if (strpos($hostname,'uk-noc.com')) { | |
$result = 'reseller'; | |
} | |
elseif (strpos($hostname,'clook.net')) { | |
$result = 'shared'; | |
} | |
else { | |
$result = 'other'; | |
} | |
if ( $type != $result ) { | |
die("Server is not $type! Exiting."); | |
} | |
} | |
# Make sure we only allow this to run on shared servers | |
serverType(shared); | |
$quota = `repquota /home | grep '\--' | grep -v -E '(\#|nagios|root|nobody)'`; | |
$quota = preg_replace('/\h+/', '|', $quota); | |
$split = explode("\n", $quota); | |
foreach($split as $users) { | |
$valuesplit = explode("|", $users); | |
$valuesplit = str_replace("----------------------------------------------------------------------", "", $valuesplit); | |
if(!$valuesplit[0] == "") { | |
echo "Doing {$valuesplit[0]}...\n"; | |
if($valuesplit[4] == "0") { | |
echo "****** The user [{$valuesplit[0]}] appears to have unlimited quota set ({$valuesplit[4]} KB)"; | |
$count++; | |
} | |
echo "\n"; | |
} | |
} | |
# Email the results if we've found an account! | |
if($count > "0") { | |
echo "DEBUG: Count is {$count}"; | |
mail($email,"[$hostn] Quota Check"," Found {$count} accounts on {$hostn} with UNLIMITED quota.\n\nPlease see logfile ({$logfile}) for a full report."); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment