Code Search for Developers
 
 
  

share_upload.html from AlphaMail at Krugle


Show share_upload.html syntax highlighted

% # vim:set syntax=mason:
<%args>
$cancel => 0
$key => 0
$password => ''
$message => ''
</%args>
<%init>
my $user = Apache::SiteControl->getCurrentUser($r);
my $logger = Log::Log4perl->get_logger('alphamail');
my $username = $user->getUsername;
my $mx = $user->getAttribute('mx');
my ($password_hash, $filename_hash);
my $prefs = new AlphaMail::Preferences($user->getUsername(), 
                                   $user->getAttribute('imap'), $config);
my $number = $prefs->get('sharing_number');
my $agree = $prefs->get('sharing_agree');
my $copyright = $prefs->get('sharing_copyright');
my $expire = $prefs->get('sharing_expire');
   
   $password =~ s/\"//g;

   if(!$number || !$copyright || !$agree || !$expire) {
      $m->redirect(build_url("/mail/index.html", {message => "SECURITY VIOLATION. Attempt to bypass Sharing Security!"}));
   }
   if(!$password || $password !~ m/^..*$/) {
      $m->redirect(build_url("/mail/share_options.html", { agree => $agree, copyright => $copyright,  number => $number, expire => $expire, message => "The password must be set to something!"}));
   }

   eval {
      my $upload = $r->upload;
      my $filename = $upload->filename;
      my $size = $upload->size;

      if($size > $config->get('large_file_limit')) {
         $message = "The file you uploaded is $size bytes, which exceeds the system limit.";
         die "File size limit exceeded.";
      }

      $filename =~ s!^.*[/\\]([^\\/]*)$!$1!;
      $filename =~ s/^\.+//g;
      $filename =~ s/[^a-z0-9.]/_/ig;

      if($filename =~ m/^\s*$/) {
         $message = "The file's name is incompatible with this system. Please rename the file to something alphanumeric and try again.";
         die "Bad filename.";
      }

      my $dir = $config->get('large_file_dir', '/tmp');
      my $openssl = $config->get('openssl', '/usr/bin/openssl');

      # Create the control file
      $password_hash = md5_hex($password);
      $filename_hash = md5_hex($filename);
      if(!open(DATA, ">$dir/$filename_hash.rec")) {
         $message = "I could not create a control file for you. Contact support.";
         die "Could not create control file: $dir/$filename_hash.rec";
      }
      print DATA "downloads: 0\nowner: $username\@$mx\nfilename: $filename\npassword: $password_hash\n";
      close DATA;

      my $infile = $upload->tempname;
      my $out = qx(nice -20 $openssl enc -cast5-cbc -k "$password" -in $infile -out $dir/$filename_hash 2>&1);
      $logger->debug("Openssl output: $out");
      if(!defined($out)) {
         $message = "I could not create an encrypted version of that file. It is possible that the file sharing space is full.";
         die "Could not create share file";
      }

      # Open the output file, and encrypt the file we got using $password
      #if(!open(DATA, ">$dir/$filename_hash")) {
      #   $message = "I could not create an encrypted version of that file. It is possible that the file sharing space is full.";
      #   die "Could not create share file";
      #}

      #my $fh = $upload->fh;
      #my $buffer;
      #my $cipher = Crypt::CBC->new( -key    => $password,
      #                              -cipher => 'CAST5',
      #                              -salt   => 1,
      #                            );

      #$cipher->start('encrypting');
      #while (read($fh,$buffer,1024)) {
      #  print DATA $cipher->crypt($buffer);
      #}
      #print DATA $cipher->finish;

      #close DATA;
   };
   if($@) {
      $logger->error("$message: $@");
      $m->redirect(build_url("/mail/share_options.html", { agree => $agree, copyright => $copyright,  number => $number, expire => $expire, message => $message}));
   }

   my $url = build_url($config->get('base_url') . "/filevault.html", 
      { file => $filename_hash });

   $message = <<EOM;
I have a large file I want to share with you, but it was too big to email.
Please copy the following URL (without the angle brackets around it) into a
browser in order to download it:

$url

EOM
   if($key) {
      $message .= "You will need to type in the following password to download the file: $password\n";
   } else {
      $message .= "You will need a password to download the file.\nFor security reasons, I will get that to you by some other means.\n";
   }

   $m->redirect(build_url('/mail/compose.html', { message => $message }));
</%init>
<%once>
use AlphaMail::HTMLHelper qw(build_url);
use Digest::MD5 qw(md5_hex);
</%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/
    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_first_login.html
  process_messages.html
  read.html
  renew_session.html
  share_options.html
  share_upload.html
  verify_password.html
  view_attachment.html