#!/usr/bin/perl use strict; use Getopt::Long; use HTTP::Request::Common; use LWP::UserAgent; use Pod::Usage; use JSON::XS; # Init my $browser = "gnome-open"; my $open_in_browser = 0; my $man = 0; my $help = 0; my $progress = 1; my $hidden = 0; my $password = ''; my $title = "Send to UP.lluga.net 0.3"; $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1; GetOptions( 'help|?' => \$help, 'man' => \$man, 'progress|p' => \$progress, 'open|o' => \$open_in_browser, 'hidden|h' => \$hidden, 'password=s' => \$password) or podusage(2); pod2usage(1) if $help; pod2usage(-exitstatus => 0, -verbose => 2) if $man; if( $progress ) { eval { require Term::ProgressBar; Term::ProgressBar->import(2.00); }; if ($@) { # Remove duplicate newline from error, and no need for two 'at line' messages chomp(my $err = $@); $err =~ s/\) at .*? line.*/)/; die "Term::ProgressBar needs to be installed for `--progress' to work\nIn Ubuntu: 'sudo apt-get install libterm-perl'\n\n"; } } pod2usage(1) unless @ARGV; main(); sub main( ) { if ($ARGV[0] eq '') { #print "$title\n"; #print "Usage: sendtoup [--progress] [--open] [--hidden] [--password=youpass] FILE..FILES\n\n"; #print "Upload FILES to UP.lluga.net\n\n"; #print "Copyright (c) 2008 Dimkalinux\n"; #print "Homepage: http://forum.lluga.net/viewtopic.php?id=8029\n\n"; #print "Send to UP comes with ABSOLUTELY NO WARRANTY.\n"; #print "This is free software and you are welcome to redistribute\n"; #print "it under certain conditions. See LICENSE for details.\n\n"; #exit; } # Begin uploading my $secretGroupCode = &generate_random_string(8); my $n = 0; my $total_files = $#ARGV+1; my $file_id; my $file_pass; my $group_id; foreach(@ARGV) { my $file = $_; die "Can't read file '$file'" unless $file and -f $file; print "Uploading: $file\n" if not $progress; ($file_id, $group_id, $file_pass) = upload ($file, $secretGroupCode, $hidden, $password); $n++; # make a pause beetwen uploads if ($n > 2) { sleep(3); } } # after all files uploaded if ($n > 0 && $open_in_browser) { if ($n == 1) { system("$browser http://up.lluga.net/$file_id/$file_pass/"); } else { system("$browser http://up.lluga.net/set/$group_id/$file_pass/"); } } } sub upload( ) { my ($file, $secretGroupCode, $hidden, $password) = @_; my $file_size = (stat($file))[7]; my $req = POST 'http://up.lluga.net/upload', 'Content_Type' => 'multipart/form-data', 'Content' => [ group_secret_code => $secretGroupCode, uploadHidden => $hidden, uploadPassword => $password, file => [$file]]; local $| = 1; if ($progress) { my $gen = $req->content(); die unless ref($gen) eq "CODE"; my $progress = Term::ProgressBar->new({ name => $file, count => $file_size, ETA => 'linear', }); $progress->max_update_rate(0.5); $progress->minor(0); my $state; my $size; my $next_update = 0; $req->content( sub { my $chunk = &$gen(); $size += file_length_in_encoded_chunk(\$chunk, \$state, $file_size); if ($size >= $next_update) { $next_update = $progress->update($size); } return $chunk; } ); } my $ua = LWP::UserAgent->new(); $ua->timeout(120); $ua->agent('SendToUP/0.3'); # # start here - go go go my $response = $ua->request($req); my $file_id = 0; my $r; my $id; my $err; my $err_message; my $pass; my $group; if ($response->{_rc} == 200 && $response->{_msg} eq 'OK') { $r = decode_json ($response->{_content}); $id = $r->{id}; $err = $r->{error}; $err_message = $r->{message}; $pass = $r->{pass}; $group = $r->{group}; if ($err != 0) { die "[FAIL] '$file' error: $err\tmessage: $err_message\n"; } print "[OK] '$file' link: http://up.lluga.net/$id/$pass/\n\n"; } else { die "[FAIL] '$file' message: $response->{_msg}\n"; } return($id, $group, $pass); } sub generate_random_string { my $length_of_randomstring=shift;# the length of # the random string to generate my @chars=('a'..'z','A'..'Z','0'..'9'); my $random_string; foreach (1..$length_of_randomstring) { # rand @chars will generate a random # number between 0 and scalar @chars $random_string.=$chars[rand @chars]; } return $random_string; } sub file_length_in_encoded_chunk { my ($chunk, $s, $img_size) = @_; $$s = {} unless ref $$s eq 'HASH'; # If we've run past the end of the image there's nothing to do but # report no image content in this sector. return 0 if $$s->{done}; unless ($$s->{in}) { # Since we haven't found the image yet append this chunk to # our internal data store, we do this because we have to do a # regex match on m[Content-Type...] which might be split # across multiple chunks $$s->{data} .= defined $$chunk ? $$chunk : ''; if ($$s->{data} =~ m[Content-Type: .*?\r\n\r\n]g) { # We've found the image inside the stream, record this, # delete ->{data} since we don't need it, and see how much # of the image this particular chunk gives us. $$s->{in} = 1; my $size = length substr($$s->{data}, pos($$s->{data}), -1); delete $$s->{data}; $$s->{size} = $size; if ($$s->{size} >= $img_size) { # The image could be so small that we've already run # through it in chunk it starts in, mark as done and # return the total image size $$s->{done} = 1; return $img_size; } else { return $$s->{size}; } } else { # Are we inside the image yet? No! return 0; } } else { my $size = length $$chunk; if (($$s->{size} + $size) >= $img_size) { # This chunk finishes the image $$s->{done} = 1; # Return what we had left return $img_size - $$s->{size}; } else { # This chunk isn't the last one $$s->{size} += $size; return $size; } } } __END__ =head1 NAME Send To UP - a UP.lluga.net file uploader for the Unix. Version 0.3. =head1 SYNOPSIS sendtoup [--progress] [--open] [--hidden] [--password=yourpass] FILENAME... where FILENAME is an file for upload to L. Multiple filenames can be separated by spaces or you can do stuff like "sendtoup *.*". =head1 OPTIONS =over 4 =item B<--progress> Display a progress bar for each upload with L. That optional module will have to be installed on the system. =item B<--open> Open browser after upload. =item B<--hidden> Set this option hide uploaded file from public view in top page. =item B<--password=yourpass> Set password for download file. =back 4 =head1 BUGS Please report bugs at dimkalinux@gmail.com =head1 AUTHORS B was written by Dimkalinux . This manual page was written by Dimkalinux . I`m use code from project. Thanks, guys. =head1 COPYRIGHT This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. On Debian GNU/Linux systems, the complete text of the GNU General Public License can be found in `/usr/share/common-licenses/GPL'. =head1 SEE ALSO Other Up.lluga.net uploaders: =over 4 =item B L =back 4 =cut