Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
PureFTPd .ftpquota report script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
eromang
n00b
n00b


Joined: 25 Mar 2003
Posts: 8

PostPosted: Wed Jul 02, 2003 7:32 am    Post subject: PureFTPd .ftpquota report script Reply with quote

Hello,

I have write a small script for the report off FTP Virtual Quota on PureFTPd.

What we have :

* Structure of the storage off the websites :

/www/vhosts/reseller1/www.domainalpha.xxx
/www/vhosts/reseller1/webalizer/
/www/vhosts/reseller2/www.domainbeta.xxx
/www/vhosts/reseller2/webalizer/

We also use PureFTPd with MySQL.

Example for the crontab

5 1 * * 5 /usr/local/scripts/customers-report.sh reseller1 /www/vhosts/reseller1/ > /dev/null 2>&1

The script
-----------------------------------------------------------------------
#!/bin/sh

#
# OPTIONS & VARIABLES
#

OUT=/tmp/vhost_per_resoller_tmp_report
APACHEOUT=/tmp/apache_out

APACHE_PATH=/usr/local/apache
MYSQL_PATH=/usr/local/mysql

# Preparation of the tmp report

echo "" > $OUT
echo "Reseller $1 Hosting report" >> $OUT
echo "" >> $OUT
echo "##############################################################################" >> $OUT
echo "General report for reseller $i" >> $OUT
echo "" >> $OUT

getapacheconf=`$APACHE_PATH/bin/httpd -S 2>$APACHEOUT`
numberofapachevhosts=`grep $1 $APACHEOUT | wc -l`

echo "Number of vhosts configured : $numberofapachevhosts" >> $OUT

getnumberftpaccountquery=$(echo "SELECT count(*) from users where Dir like '%$2%';" | $MYSQL_PATH/bin/mysql -u customerreport --password='passwd' pureftpd)

getnumberftpaccount=`echo $getnumberftpaccountquery | cut -d " " -f2`

getnumberofstatsconf=`ls $2webalizer | wc -l`

echo "Numer of FTP account configured : $getnumberftpaccount" >> $OUT

diskspacecheck=`du -hcs $2 | grep total`
diskspace=`echo $diskspacecheck | cut -d " " -f1`

echo "Used disk space : $diskspace" >> $OUT

echo "" >> $OUT
echo "##############################################################################" >> $OUT
echo "" >> $OUT

echo "##############################################################################" >> $OUT
echo "Report on the FTP account how are on the limit of their quota :" >> $OUT
echo "" >> $OUT

for i in `ls $2 | grep www`;
do
userquota=$(echo "SELECT POW(2,20) * QuotaSize AS quota from users where Dir='$2$i';" | $MYSQL_PATH/bin/mysql -u customerreport --password='passwd' pureftpd)
if [ "$userquota" != "" ] || [ "$userquota" != "0" ]
then
userquotavalue=`echo $userquota | cut -d " " -f2`
if [ -e $2$i/.ftpquota ]
then
actualquota=`cat $2$i/.ftpquota | cut -d " " -f2`
alertuserquotavalue=`echo $userquotavalue / 100 \* 90 | bc`
if [ $actualquota -gt $alertuserquotavalue ]
then
echo "----------------------------------------------------------------------------" >> $OUT
echo "Domain $i : Attention quota limit soon exceeded (90%)" >> $OUT
echo " -> $actualquota for $userquotavalue max. used" >> $OUT
echo "----------------------------------------------------------------------------" >> $OUT
else
b=0
b=$(expr $b + 1)
fi
fi
else
a=0
a=$(expr $a + 1)
echo "" >> $OUT
echo "$a sur $a domain doesn't have quota alert" >> $OUT
echo "" > $OUT
fi
done

echo "#################################################################################" >> $OUT
echo "" >> $OUT
echo "#################################################################################" >> $OUT
echo "General space disk used for reseller $1 vhosts report" >> $OUT
echo "" >> $OUT
for i in `ls $2 | grep www`;
do
userquota=$(echo "SELECT POW(2,20) * QuotaSize AS quota from users where Dir='$2$i';" | $MYSQL_PATH/bin/mysql -u customerreport --password='passwd' pureftpd)

echo "----------------------------------------------------------------------------" >> $OUT
echo "" >> $OUT
echo "Domain $i :" >> $OUT

if [ "$userquota" = "" ]
then
echo "Website $i not in the PureFTPd database" >> $OUT
echo "No quota's" >> $OUT
grep $i $APACHEOUT 2>&1
if [ "$?" != "0" ]
then
echo "Website $i not configured in Apache" >> $OUT
files=`ls $2$i | wc -l`
if [ "$files" != "0" ]
then
echo "They're is no files in the $i folder" >> $OUT
else
echo "They're are files in the $i folder" >> $OUT
echo "Verify if you should not clean the account" >> $OUT
fi

else
echo "Website $i configured in apache" >> $OUT
echo "Website without FTP access" >> $OUT
fi
else
grep $i $APACHEOUT 2>&1
if [ "$?" != "0" ]
then
echo "Website $i not configured in apache" >> $OUT
echo "FTP account only ??" >> $OUT
fi
userquotavalue=`echo $userquota | cut -d " " -f2`
if [ -e $2$i/.ftpquota ]
then
actualquota=`cat $2$i/.ftpquota | cut -d " " -f2`
echo "quota : $userquotavalue octets, actual quota : $actualquota octets" >> $OUT
else
echo "The website $i never connect on his FTP account." >> $OUT
echo "quota : $userquotavalue octets" >> $OUT
fi
fi

echo "" >> $OUT
echo "----------------------------------------------------------------------------" >> $OUT

done

echo "#################################################################################" >> $OUT

mail -s "Report for the $1 reseller" $1 < $OUT
---------------------------------------------------------------------

Feel free to contribute on this script.

Regards.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum