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>
$m->redirect($base) if !$config->get('large_file_limit',0);
my $logger = Log::Log4perl->get_logger('alphamail');
# 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 $sandbox_dir = $config->get('sandbox_dir');
my $sandbox_user = $config->get('sandbox_user', 'sandbox');
my $sandbox = $config->get('sandbox_util');

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.
      die "Limit exceeded";
   }

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

   unlink "$sandbox_dir/tmp/$file" if(-f "$sandbox_dir/tmp/$file");
   link $fn, "$sandbox_dir/tmp/$file" or $logger->error("Could not create link from $fn to $sandbox_dir/tmp/$file");
   $logger->debug("Running: $sandbox '$sandbox_user' '$sandbox_dir' $openssl enc -d -cast5-cbc -k '$password' -in '/tmp/$file'");
   if(!open(DATA, "$sandbox '$sandbox_user' '$sandbox_dir' $openssl enc -d -cast5-cbc -k '$password' -in '/tmp/$file' |")) {
      $message = "The file was unreadable. Contact support.";
      $logger->error("Unable to read $file");
      die "Unable to read file.";
   }

   # send the file
   if($download =~ m/force/) { # Safari is broken...octet-stream goes to window
      $r->content_type("application/unknown");
   } else {
      $r->content_type("application/octet-stream");
   }
   $r->headers_out()->set('Content-Disposition' => qq(attachment; filename="$control{filename}"));
   while (read(DATA,$buffer,8192)) {
      $m->print($buffer);
      $m->flush_buffer;
   }

   close DATA;

   unlink "$sandbox_dir/tmp/$file";

   $logger->debug("Done sending $file");
};
if($@) {
   $m->redirect(build_url($base . '/filevault.html', {file => $file, message => $message }));
}
</%init>
<%once>
use AlphaMail::HTMLHelper qw(build_url);
use Digest::MD5 qw(md5_hex);
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

  images/
  mail/
    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
      guide.html
      index.html
      quotas.jpg
      show_stats.mhtml
      test.mhtml
    docs/
      faq/
        attach1.gif
        attach2.gif
        attach3.gif
        colors.gif
        dates1.gif
        drafts.gif
        filter.gif
        index.html
        notrash1.gif
        notrash2.gif
        notrash3.gif
        other.html
        sort.gif
        timeout.gif
      index.html
      new_features.html
    settings/
      add_filter.html
      altfolder_update.html
      altprefix_update.html
      edit_folders.html
      export.mhtml
      export_mail.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
    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
  static/
    rte/
    amail_icon.jpg
    amail_large.jpg
    default.css
    paperclip.png
    wick.css
    wick.js
    wz_tooltip.js
  download.html
  error.html
  filevault.html
  index.html