Php script that will show the size of each directory I have.

Ronen AmitY amity at mainsoft.com
Wed Feb 4 06:35:08 EST 2004


They do.
But, it is not enough.

My people wanted to know how much space they use in each folder (as wi have
people with over 4 gig of emails).

So I did something nice :

Here it is:


!/usr/bin/perl


# Things we use in this script.
use strict;
use warnings;

use CGI qw/:standard/;
use IMAP::Admin;

my $version        = 1.2;

# Those lines are defining some values for the CGI-frontend.
my $passlen        = 12;
my $userlen        = 30;
my $overridefields = 1;

# Define some values for connection to the local imap-server.
my $imap_port      = 143;
my $imap_seperator = ".";
my $imap           = undef;

# Print some basic html-stuff.
    print header;
    print start_html(-title  =>'Email Quota report ',
                     -author =>'o.pitzeier at uptime.at',
                     -BGCOLOR=>'white'),"\n";
                     ##RR -BGCOLOR=>'#C3CACE'),"\n";


# Create a table and a form.
if (!param('login')) {
    print "<table border=0>\n";
    print start_form,"\n",
        "<tr><td>username: </td><td>",    textfield(     -name
=>'login',
                                                         -override
=>$overridefields,
                                                         -size
=>$userlen,
                                                         -maxlength
=>$userlen),"</td></tr>\n",
        "<tr><td>password: </td><td>",    password_field(-name
=>'password',
                                                         -override
=>$overridefields,
                                                         -size
=>$passlen,
                                                         -maxlength
=>$passlen),"</td></tr>\n";
    print "</table>\n";
    print submit(-value=>'send'),"\n";
    print end_form,"\n";
}
    print hr;
# End of the table and the form.

# Check the parameters and do some error-catching.
# The stuff down here should be self-explaining.
# Don't forget to change the password for cyrus at line 72.
    if(param()) {
        if(param('login'))
        {
            if(param('password')) {
                $imap = IMAP::Admin->new('Server'    => 'localhost',
                                         'Login'     => param('login'),
                                         'Password'  => param('password'),
                                         'Port'      => $imap_port,
                                         'Separator' => $imap_seperator);
                if($imap->error eq 'No Errors') {
                    $imap->close;
                    $imap = IMAP::Admin->new('Server'    => 'localhost',
                                             'Login'     => "cyrus",
                                             'Password'  => "C0nnect!",
                                             'Port'      => $imap_port,
                                             'Separator' =>
$imap_seperator);
        my @chars = split(//, param('login'));
        my $letter = $chars[0];
        my $uu = '/usr/local/etc/du -h
/var/spool/imap/'.$letter.'/user/'.param('login');
        my $color = 'green';
                    my @quota = $imap->get_quota("user.".param('login'));
                    if(@quota) {
                    my $precent = $quota[1] / $quota[2];
                        if ($precent ge .8){ $color = 'brown';}
                        if ($precent ge .9) {$color = 'red';}
                           print "<table border=0>\n",
                              "<tr><td>Quota
for:</td><td><b>".param('login')."</b></td></tr>\n",
                              "<tr><td>Used :</td><td><font
color=\"$color\">".$quota[1]."</font> MB</td></tr>\n",
                              "<tr><td>Total :</td><td><font
color=\"Blue\">".$quota[2]."</font> MB</td></tr>\n",
                              "</table><br><hr><br>\n";
        print "<pre>";
        system "$uu  | sort -k 2 |sed
\"s#/var/spool/imap/$letter/user/##g\"";
        print "</pre>";

                    } else {
                        print "Could not retrieve quota information";
                        print $imap->error;
                    }
                $imap->close;
                } else {
                    if($imap->error =~ /Login failed/) {
                        if($imap->error =~ /: authentication/) {
                            print "Wrong password! Could not log in.", br;
                        }
                        if($imap->error =~ /: user not found/) {
                            print "User not found! Could not log in.", br;
                        }
                    }
                }
            } else {
                print "No password given. Please enter your password!";
            }
        } else {
            print "No username given. Please enter your username!";
        }
    } else {
        print "Please enter the above informations!";
    }
    print hr,"\n",end_html;

------------------------------------
Mainsoft Corp
amity at mainsoft.com
unix and ClearCase admin
amity at mainsoft.com
Ofek 1 center, 2nd Bldg.
North Industrial Area,
Lod, 71293
Israel
tel: +972-8-978-1300
mobile: +978-58-214707
------------------------------------


-----Original Message-----
From: Andrew Morgan [mailto:morgan at orst.edu] 
Sent: Tuesday, February 03, 2004 7:14 PM
To: Ronen AmitY
Cc: info-cyrus at lists.andrew.cmu.edu
Subject: Re: Php script that will show the size of each directory I have.




On Tue, 3 Feb 2004, Ronen AmitY wrote:

> Hi all,
>
> Im looking for a php script that will show me the size of my 
> directories. (after adding username and passwd).
>
> If it works with horde system, even better.

Doesn't Horde/IMP already include example code for displaying the user's
quota and usage?  Have a look at imp/config/conf.php...

	Andy






More information about the Info-cyrus mailing list