Code Search for Developers
 
 
  

download.html from AlphaMail at Krugle


Show download.html syntax highlighted

% # vim:set syntax=mason:
<%args>
$file => ''
$password => ''
$download => ''
</%args>
<%init>
# look up file
my %control;
my $message;
my $cipher;
my $buffer;

$password =~ s/\"//g;

my $dir = $config->get('large_file_dir', '/tmp');
my $openssl = $config->get('openssl', '/usr/bin/openssl');
my $fn = $dir . "/" . $file;
eval {
   if(!open DATA, "<$fn.rec") {
      $message = "The file could not be found. This system only caches files for a limited time. The file may have expired, or the URL you used may have been corrupted.";
      die "Download failure";
   }

   while(<DATA>) {
      m/^(\w+):\s(.*)$/;
      $control{$1} = $2;
   }
   close DATA;
   $control{downloads}++;
   open DATA, ">$fn.rec";
   for my $k (sort keys %control) {
      print DATA "$k: $control{$k}\n";
   }
   close DATA;
   if($control{downloads} > $config->get('large_file_max_downloads', 21)) {
      $message = "The download count for this file has been exceeded. It has been removed.";
      unlink "$fn";
      # Leave the .rec file for timeout, so that the proper message will
      # still be generated.
   }

   # check the password
   my $password_hash = md5_hex($password);
   if($control{password} ne $password_hash) {
      $message = "Password incorrect.";
      die "Bad password";
   }

   # send the file
   $r->header_out('Content-Disposition' => qq(attachment; filename=$control{filename}));
   if($download =~ m/force/) { # Safari is broken...octet-stream goes to window
      $r->content_type("image/pnm");
   } else {
      $r->content_type("application/octet-stream");
   }
   $r->send_http_header;

   if(!open(DATA, "nice -20 $openssl enc -d -cast5-cbc -k '$password' -in $fn 2>/dev/null|")) {
      $message = "The file was unreadable. Contact support.";
      die "Unable to read file.";
   }
   while (read(DATA,$buffer,8192)) {
      $m->print($buffer);
      $m->flush_buffer;
   }

   # use Crypt::CBC to decrypt, then send
   #$cipher = Crypt::CBC->new( -key    => $password,
                              #-cipher => 'CAST5',
                              #-salt   => 1,
                            #);

   #$cipher->start('decrypt');
   #if(!open(DATA,"<$fn")) {
   #   $message = "The file was unreadable. Contact support.";
   #   die "Unable to read file.";
   #}

   # FIXME: More efficient! This SUCKS CPU
   #while (read(DATA,$buffer,1024)) {
   #   $m->print($cipher->crypt($buffer));
   #   $m->flush_buffer;
   #}
   #$m->print($cipher->finish);

   close DATA;
};
if($@) {
   $m->redirect(build_url('/filevault.html', {message => $message }));
}
</%init>
<%once>
use AlphaMail::HTMLHelper qw(build_url);
use Digest::MD5 qw(md5_hex);
use Crypt::CBC;
</%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

  images/
  mail/
    addressbook/
      autohandler
      edit.mhtml
      import.mhtml
      import_csv.html
      import_imho.html
      index.html
      process_edit.html
      take.html
    settings/
      altfolder_update.html
      autohandler
      edit_folders.html
      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
      word.html
      zip.html
    address_mail.html
    addresslist.mhtml
    check_spelling.html
    compose.html
    filevault.html
    first_login.html
    fix_spelling.html
    folderlist.mhtml
    footer.mhtml
    get_attachment.html
    header.mhtml
    index.html
    logout.html
    menu.mhtml
    other_folders.html
    print.html
    process_compose.html
    process_messages.html
    read.html
    renew_session.html
    share_options.html
    share_upload.html
    verify_password.html
    view_attachment.html
  static/
    amail_icon.jpg
    amail_large.jpg
    d.css
  download.html
  filevault.html
  index.html