Code Search for Developers
 
 
  

quota.html from AlphaMail at Krugle


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

AlphaMail

AlphaMail is an accelerated web mail interface with a C++ middleware layer that is more effective than an IMAP proxy which is a highly scalable (10k+ users). The interface includes modern features, Section 508 compliance, and universal browser support.

Project homepage: http://sourceforge.net/projects/alphamail
Programming language(s): C++,Java,JavaScript,Perl
License: other

  addressbook/
    edit.mhtml
    import.mhtml
    import_complete.html
    import_csv.html
    import_csv_save.html
    import_fname.html
    import_imho.html
    import_lname.html
    index.html
    lists.mhtml
    process_edit.html
    process_lists.html
    process_take.html
    take.html
  admin/
    autohandler
    index.html
    show_stats.mhtml
    test.mhtml
  docs/
    faq/
      colors.gif
      dates1.gif
      drafts.gif
      filter.gif
      general.html
      index.html
      notrash1.gif
      notrash2.gif
      notrash3.gif
      other.html
      sort.gif
      timeout.gif
    new_features.html
  settings/
    add_filter.html
    altfolder_update.html
    altprefix_update.html
    edit_folders.html
    filters.mhtml
    folders.mhtml
    general.mhtml
    index.html
    share.mhtml
    sharing_agree.html
    signatures.mhtml
    update_folderlist.html
    update_general.html
    update_signatures.html
  viewers/
    excel.html
    html.html
    targz.html
    text.html
    word.html
    zip.html
  address_mail.html
  addresslist.html
  autohandler
  check_spelling.html
  compose.html
  error.html
  feedback.html
  first_login.html
  fix_spelling.html
  folderlist.mhtml
  footer.mhtml
  get_attachment.html
  header.mhtml
  help.html
  index.html
  logout.html
  menu.mhtml
  other_folders.html
  process_compose.html
  process_first_login.html
  process_messages.html
  process_read_message.html
  process_search.html
  quota.html
  quota_graph.html
  raw.html
  read.html
  remove_attachment.html
  renew_session.html
  resume_compose.html
  sanitized.html
  share_options.html
  share_upload.html
  verify_password.html
  view_attachment.html