#!/usr/bin/perl
#The script is designed for Linux Red Hat operating system.
#Run it from a web browser to get web space and files quota report.
#WARNING: Anyone on the Internet can use this script!
#To prevent unauthorized access, place the file in its
#own password-protected directory. To use it just run
#the script from your web browser by typing the exact
#URL to the script.
#IMPORTANT: CHMOD the quota.cgi file to 755 (rwxr-xr-x).
#DISCLAIMER: Developer is not responsible for any damage or problem
#caused by using this script. Feel free to modify or distribute it.
#Originally designed by Vladimir Koryagin on 06/25/00, modified
#by Tintagel Net Solutions Group.
#Version 1.0.8
&system_check;
"a_execution;
&using_file;
&processing;
&html_output;
&html_final;
sub system_check{
print "Content-type: text/html\n\n";
open (FD, "> /tmp/.TEMPQUOTA.TXT~") || &error;
system ("chmod 666 /tmp/.TEMPQUOTA.TXT~");
}
sub quota_execution{
if (!($pid = fork())){
exec ('quota -gv > /tmp/.TEMPQUOTA.TXT~');
}
else{
wait();
}
$tempfile_size = -s "/tmp/.TEMPQUOTA.TXT~";
if ($tempfile_size == 0){
&error;
}
}
sub using_file{
$x = 0;
open (FD, "/tmp/.TEMPQUOTA.TXT~");
while ($line[$x] = ){
$x++;
}
if ($x < 2){
&error;
}
close(FD);
unlink ("/tmp/.TEMPQUOTA.TXT~");
}
sub processing{
$x = 0;
while ($line[$x] =~ " "){
$space_used = substr ($line[$x], 16, 7);
$files_used = substr ($line[$x], 48, 7);
if($space_used < 5 || $files_used < 5){
$x++;
}
else{
$goal_line = $line[$x];
$x++;
}
}
$space_used = substr ($goal_line, 16, 7);
$space_quota = substr ($goal_line, 24, 7);
$files_used = substr ($goal_line, 48, 7);
$files_quota = substr ($goal_line, 56, 7);
if ($space_quota == 0){
$space_available = 'Unknown';
}
if($space_quota != 0){
$space_available = $space_quota - $space_used;
}
if ($files_quota == 0){
$files_available = 'Unknown';
}
if($files_quota != 0){
$files_available = $files_quota - $files_used;
}
}
sub html_output{
print << "HTML code";
Quota Page
Web Space and File Quotas
| Version 1.0.8
| Space (in Kilobytes)
| Number of files
|
Used web space and number of files located on your domain
| $space_used
| $files_used
|
Available web space and number of files you can upload on your domain
| $space_available
| $files_available
|
Total web space and number of files limited by the system
| $space_quota
| $files_quota
|
HTML code
if ($space_quota != 0 && $files_quota != 0){
&evaluation;
}
else{
&zero_limits;
sub zero_limits{
print << "ZERO code";
Zero limits means different system limitation type has been used. It does not
prevent the
domain from functioning correctly.
ZERO code
}
}
}
sub evaluation{
#if ($space_available <= 0 && $files_available <= 0) {
# "a_exceeded;
#}
if ($space_available < 0 || $files_available < 0) {
"a_exceeded;
}
elsif ($space_quota == 0 && $files_available > 0){
&zero_limits;
}
elsif ($files_quota == 0 && $space_available > 0){
&zero_limits;
}
else{
&no_problem;
}
}
sub no_problem{
print << "OK code";
At this moment, the domain is within it's web space and file quota limits.
To make
sure the domain doesn't exceed them in future, please run this script frequently.
OK code
}
sub quota_exceeded{
print << "QUOTA code";
Your domain has exceeded assigned limits for web space usage or allowed number of files!
During
such condition different system errors and information losses may occur. To ensure
that the domain is functioning correctly, please contact support IMMEDIATELY
QUOTA code
}
sub error {
print << "ERROR code";
Quota Page
The script was unable to generate Web Space and File Quota Table because
of unexpected error,
which could be caused by incorrect permissions for the files or/and directories,
or by exceeding
hard limits of assigned web space or/and file quota.
To ensure that the domain is functioning
correctly, please contact support
IMMEDIATELY
ERROR code
unlink ("/tmp/.TEMPQUOTA.TXT~");
die;
}
sub html_final{
print ("\n\n\n");
}