Advertisement
Guest User

Untitled

a guest
Mar 18th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.04 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. use Bio::Graphics::Browser2;
  7. use Bio::Graphics::Browser2::Session;
  8. use Bio::Graphics::Browser2::UserDB;
  9. use Bio::Graphics::Browser2::Render;
  10. use Bio::Graphics::Browser2::UserTracks;
  11. use Data::Dumper;
  12. use CGI;
  13. use POSIX qw/setsid/;
  14.  
  15. my $q = new CGI;
  16. my $upload_target = $q->param('upload');
  17. my $upload_name = $q->param('name');
  18. my $upload_type = $q->param('type');
  19.  
  20. my $globals = Bio::Graphics::Browser2->open_globals;
  21. my $userdb = Bio::Graphics::Browser2::UserDB->new($globals);
  22. my $render = Bio::Graphics::Browser2::Render->new($globals);
  23. my $session = $render->session;
  24. my $data_source = $render->data_source;
  25. my $user_tracks = Bio::Graphics::Browser2::UserTracks->new($data_source,$session);
  26.  
  27. my $pid = fork();
  28. if($pid == 0) {
  29.     print STDERR "I'm the start of the parent: $pid\n";
  30.     print $q->header;
  31.     print $q->start_html( -title => 'Starting file upload',
  32.                 -style => ['http://fonts.googleapis.com/css?family=Lato','../../expression_ratios.css'],
  33.                 -script => {-type => 'JAVASCRIPT',
  34.                             -src => '../../expression_ratios.js'
  35.                             }
  36.                 );
  37.     print $q->b("Upload Started!");
  38.     print $q->end_html;
  39.     print STDERR "I'm the end of the parent\n";
  40. } else {
  41.     local $SIG{TERM} = sub {
  42.         open FILE,">","/home/guest/data_dump2.txt" or die "Unable to open data_dump2.txt";
  43.         print FILE "Cancelled by Apache timeout\n";
  44.         close FILE;
  45.         die "cancelled by Apache timeout";
  46.     };
  47.     open STDOUT, '>/dev/null' or die "Can't open /dev/null: $!";
  48.         open STDIN, '</dev/null' or die "Can't open /dev/null: $!";
  49.  
  50.     print STDERR "I'm the child, I'm starting the upload: $pid\n";
  51.  
  52.     setsid or die "Can't start a new session: $!";
  53.  
  54.     print STDERR "upload_target: $upload_target\n";
  55.  
  56.     open my $fh, "<", $upload_target or die "unable to open upload target: $!";
  57.     my @results = $user_tracks->upload_file($upload_name, $fh, $upload_type, 1);
  58.  
  59.     open FILE, ">", "/home/guest/data_dump.txt" or die "can't open file: $!";
  60.     print FILE "Dump: ",Dumper(\@results);
  61.     close FILE;
  62.  
  63.     print STDERR "Upload complete!\n";
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement