Show quota.html syntax highlighted
% # vim: set syntax=mason:
% my $pct = (($free/$total) * 100);
<& /mail/header.mhtml, title => "Quotas",
message => ($pct < 10 ? "Warning: You are almost out of space! Please delete old messages and files.": "") &>
<p class="freespace">Free Space: <% $free %>kB (<% sprintf("%2d", (($free/$total) * 100)) %>%)</p>
<div class="subheading">Breakdown of usage</div>
<div class="section">
<img class="usage" src="<% build_url("$base/mail/quota_graph.html", { free => $free, used => $used, other => $sizemap{other}{kb}, inbox => $sizemap{inbox}{kb}, folders => $sizemap{folders}{kb}, web => $sizemap{web}{kb} } ) |h %>">
<table class="usage">
<tr>
<th>
Inbox:
</th>
<td class="inboxspace">
<% $sizemap{inbox}{amt} %><% $sizemap{inbox}{units} %> (<% ($sizemap{inbox}{kb}/$total < 0.01) ? "<1":sprintf("%2d", (($sizemap{inbox}{kb}/$total) * 100)) %>%)
</td>
</tr>
<tr>
<th>
Mail Folders:
</th>
<td class="mailspace">
<% $sizemap{folders}{amt} %><% $sizemap{folders}{units} %> (<% ($sizemap{folders}{kb}/$total < 0.01) ? "<1":sprintf("%2d", (($sizemap{folders}{kb}/$total) * 100)) %>%)
</td>
</tr>
<tr>
<th>
Personal Web Site:
</th>
<td class="webspace">
<% $sizemap{web}{amt} %><% $sizemap{web}{units} %> (<% ($sizemap{web}{kb}/$total < 0.01) ? "<1":sprintf("%2d", (($sizemap{web}{kb}/$total) * 100)) %>%)
</td>
</tr>
<tr>
<th>
Your other files:
</th>
<td class="otherspace">
<% $sizemap{other}{amt} %><% $sizemap{other}{units} %> (<% ($sizemap{other}{kb}/$total < 0.01) ? "<1":sprintf("%2d", (($sizemap{other}{kb}/$total) * 100)) %>%)
</td>
</tr>
</table>
</div>
<div class="smallprint">Note: Quota information updates at 1 minute intervals</div>
<div class="subheading">Usage by Folder</div>
<div class="section">
<table class="usage">
% for my $k (sort { $usage{$b}{kb} <=> $usage{$a}{kb} } keys %usage) {
<tr>
<th>
<% decode('utf8', $tr->decode($k)) |h %>
</th>
<td>
<% $usage{$k}{amt} %><% $usage{$k}{units} %> (<% ($usage{$k}{kb}/$total < 0.01) ? "<1":sprintf("%2d", (($usage{$k}{kb}/$total) * 100)) %>%)
</td>
</tr>
% }
</table>
</div>
<& /mail/footer.mhtml &>
<%init>
my $user = Apache2::SiteControl->getCurrentUser($r);
if(!$user || !$user->isa('Apache2::SiteControl::User')) {
$logger->error("Unable to find a user for the given session key.");
$m->redirect("/");
}
my $username = $user->getUsername();
my $password = $user->getAttribute('password');
my $host = 'darkwing.uoregon.edu';
my $tr = Unicode::IMAPUtf7->new();
my $prefs = new AlphaMail::Preferences($user->getUsername(),
$user->getAttribute('mx'), $config);
my ($prefix, $separator) = $config->getFolderPrefix($user);
$prefix .= $separator;
my $ssh;
my ($quotaout, $duout, $stderr, $exit);
my @lines;
my $total = 0;
my $used = 0;
my $free = 0;
my %sizemap;
my %usage;
my $units;
my $div;
return if $m->cache_self(key => "quota_$username.$host", expires_in => "1 min");
eval {
$logger->debug("Making ssh object for $username...");
$ssh = new Net::SSH::Perl($host, debug => "1", protocol => "1",
options =>
[ "UserKnownHostsFile /usr/local/active/alphamail/etc/known_hosts",
"IdentityFile /usr/local/active/alphamail/etc/id_dsa" ]);
$logger->debug("Logging in $username...");
$ssh->login($username, $password);
$logger->debug("Running quotas for $username...");
($quotaout, $stderr, $exit) = $ssh->cmd(q(quota -v));
$logger->debug("Done running quotas for $username...");
my $folderlist;
$logger->debug("running find for $username...");
($folderlist, $stderr, $exit) = $ssh->cmd(qq(find $prefix -type f -print));
$logger->debug("Done running find for $username...");
my @folders = grep { !m/^>/ } split( /\n/, $folderlist);
push @folders, ".mail";
push @folders, "$prefix";
push @folders, "public_html";
map { s/^(.*)$/'$1'/; } @folders;
local $" = " ";
$logger->debug("running du for $username...");
($duout, $stderr, $exit) = $ssh->cmd("du -sk @folders");
$logger->debug("done running du for $username...");
$logger->debug("du out: $duout");
$logger->debug("logging out $username...");
$ssh->cmd(q(exit));
};
if($@) {
$logger->error("Unable to run quota: $@");
} else {
@lines = split /[\n\r]/, $quotaout;
for my $l (@lines) {
if($l =~ m/home\d+\s+(\d+)\s+(\d+)\s/) {
$total = $2 if($2 > $total);
$used = $1 if($1 > $used);
}
}
$free = $total - $used;
@lines = split /[\n\r]/, $duout;
$sizemap{other}{kb} = $used;
for my $l (@lines) {
if($l =~ m/^(\d+)\s+(\S+)$/) {
if($2 eq '.mail') {
$sizemap{inbox}{kb} = $1;
$sizemap{inbox}{units} = ($1 > 1000 ? "MB":"kB");
$sizemap{inbox}{amt} = ($1 > 1000 ? (sprintf("%.1f", $1/1024)):$1);
$sizemap{other}{kb} -= $1;
} elsif($2 eq 'mail') {
$sizemap{folders}{kb} = $1;
$sizemap{folders}{units} = ($1 > 1000 ? "MB":"kB");
$sizemap{folders}{amt} = ($1 > 1000 ? (sprintf("%.1f", $1/1024)):$1);
} elsif($2 eq 'public_html') {
$sizemap{web}{kb} = $1;
$sizemap{web}{units} = ($1 > 1000 ? "MB":"kB");
$sizemap{web}{amt} = ($1 > 1000 ? (sprintf("%.1f", $1/1024)):$1);
$sizemap{other}{kb} -= $1;
} else {
$usage{$2}{kb} = $1;
$usage{$2}{units} = ($1 > 1000 ? "MB":"kB");
$usage{$2}{amt} = ($1 > 1000 ? (sprintf("%.1f", $1/1024)):$1);
$sizemap{other}{kb} -= $1;
}
}
}
$sizemap{other}{units} = ($sizemap{other}{kb} > 1000 ? "MB":"kB");
$sizemap{other}{amt} = ($sizemap{other}{kb} > 1000 ?
(sprintf("%.1f", $sizemap{other}{kb}/1024)):$sizemap{other}{kb});
}
$total = 1 if !$total;
</%init>
<%once>
use Carp;
use Encode;
use Net::SSH::Perl;
use AlphaMail::HTMLHelper qw(build_url);
our $logger = Log::Log4perl->get_logger('alphamail');
our $base = $config->get('base_uri');
</%once>
See more files for this project here