#!/usr/bin/perl #-----------------------------------------------------------------------------------# # Copyright Information # Code created by Liu Xuefeng, xfliu.math@gmail.com # You can use this code freely with this copyright information kept inside. # The author does not take any responsilibity for the result of using this code. # 2008/03/22 #-----------------------------------------------------------------------------------# # use strict; use CGI qw(:all); use CGI::Carp qw( fatalsToBrowser ); # ---------- Change parameters below ------------------------------ # Here is your server name, it can be anyone you like. my $server_name="YOUR_SERVER_NAME"; # The base address of this file # For example : # my $base_url="http://xfliu.sakura.ne.jp/o/shipit/"; my $base_url="http://xfliu.sakura.ne.jp/o/shipit/"; # This info will be showed when the uploading is finished. my $thanks_info="This is from xfliu's homepage."; # The max size of each file to be uploaded. Unit is Mega. my $max_size=45;#45M, The minimum value should be 45M # The max space you want supply, unit is by Mega. my $space_can_be_used=100;#90M # Here is the time that the thanks page will be shown before redirecting the user to Shipit-now.com. my $wait_time=2; #--------------- Stop your modification here -------------------------------------- my $cgi = new CGI; my $script= $ENV{"SCRIPT_NAME"}; my $back_url="http://shipit-now.com/index.cgi?"; my $file = $cgi->param('file'); my $user = $cgi->param('user'); my $g_title = $cgi->param('g_title'); my $user_email = $cgi->param('user_email'); my $g_id=$cgi->param("group_id"); my $file_link=$cgi->param("file_link"); my $note=$cgi->param("note"); my $admin=$cgi->param("admin"); $wait_time=$cgi->param("time") if $cgi->param("time"); $note=~s/\|//g; $note =~ s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg; $user=~s/\|//g; $user =~ s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg; $g_title =~ s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg; $file_link="" if $file_link eq 'http://'; $back_url.="child=${server_name}&user=${user}&g_title=${g_title}&user_email=${user_email}¬e=${note}"; $back_url.="&group_id=${g_id}" if $g_id; # the value of file_link can not be determined here. # ------------- used space -------------------------------------------------- my $can_upload=1; my $used_space=used_space()/1000000; $used_space=int($used_space*1000)/1000; # ---------- report ------------------------------------------------------------------- my $report; if($cgi->param("report")){ $report=< Max size : $max_size M Max space : $space_can_be_used M Used space: $used_space M Wait time : $wait_time Base Url : $base_url ServerName: $server_name Thank Info: $thanks_info EOF } if ( length($g_id) < 6 and $g_id) { $report="
  • No such group id: $g_id ."; $g_id="" ; } if(($space_can_be_used - $used_space)<$max_size) { $report.="
  • There are no enough space on the server. Please try to upload file on another day or only upload links.
  • "; $can_upload=0; } if($file and not $file_link and $can_upload){ #upload my $filesize = -s $file; if($filesize > $max_size*1000000 and not $admin){ $report.="
  • Upload failed! Your file is too big (Over $max_size M).\n"; unlink("$file"); } else{ $file=~/\.([^\.\s]{2,3})$/; my $ext=$1; my $t_f=$file; $t_f =~ s/\.${ext}$//; $t_f =~ /([a-zA-Z0-9\.]{0,9})$/; my $basename=create_name()."_".$1; my $file_name = $basename.".".$ext; my $file_html = $basename.".html"; $file_name = lc $file_name; my $size=$filesize; open(OUT, ">$file_name") or die(qq(Can not open "$file_name".)); binmode OUT; my $buffer; while (read($file, $buffer, 1024)) { print OUT $buffer; } close OUT; system("chmod 766 $file_name");#Import bug fixed. unlink("$file"); $file =~ s/\|//g; $file =~ s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg; $back_url.="&file_link=${base_url}${file_name}&filesize=${filesize}&file=${file}"; # creating group_id if(not $g_id){ $g_id = create_num(); create_group($g_id,$user,$g_title); $report.="
  • A new group $g_id created.\n"; $back_url.="&g_id=${g_id}&new_group=1"; }; # save files; my $mydate=get_date(); $file=~ /([^\\\/]*)$/; my $line = "$g_id\|$file_name\|$note|$filesize|$user|$mydate|$1|$user_email\n"; my @files=open_files(); push(@files ,$line); save_files(@files); # send email; my $link="http://shipit-now.com/?group_id=$g_id"; $report.="
  • A file $file_name uploaded.\n"; } } if($file_link) { $back_url.="&file_link=${file_link}"; # creating group_id if(not $g_id){ $g_id = create_num(); create_group($g_id,$user,$g_title); $report.="
  • A new group $g_id created.\n"; $back_url.="&g_id=${g_id}&new_group=1"; }; # save file link; my $mydate=get_date(); my $line = "$g_id\|$file_link\|$note|unkown|$user|$mydate\n"; my @files=open_files(); push(@files ,$line); save_files(@files); $report.="
  • A file link: $file_link uploaded.\n"; $back_url.="&file_link=${file_link}&filesize=0"; } #---------------------------- The code above is enough for saving ------------------# if($g_id and not $g_title){ my @files=open_groups($g_id); my $line=$files[0]; my @elements=split(/\|/,$line); $g_title=$elements[1]." by ".$elements[2]; } #--------------- html content *File list" ----------------- print "Content-Type: text/html\n\n"; print < Ship It

        方舟快递   

    ----分享大文件从此轻松简单!

    [English Version]

    System Report    Skip it

      $report

    Thanks Info

    $thanks_info
    EOF 1; #---------------------------------------------------- # subroutines #---------------------------------------------------- sub used_space() { my @files=open_files(); my @newfiles; my $dead_line=get_deadline(); foreach(@files){ my @elements = split (/\|/, $_); my $fday=$elements[5]; $fday=~/^(.+):/; $fday=$1; if($fday<$dead_line){ unlink($elements[1]); system("rm -fR ./swap/".$elements[0]); $report.="
  • File $elements[1] deleted.\n"; } else { push(@newfiles ,$_); } } save_files(@newfiles); my @files=group_files(""); my $total_size=0; foreach(@files){ my @elements = split (/\|/, $_); my $size=$elements[3]; $total_size=$total_size+$size; } return $total_size; } sub get_deadline() { my $days=7; my @c_d=localtime(time-$days*24*3600); my ($cdh,$cdmin,$cds)=(@c_d[2],@c_d[1],@c_d[0]); my ($cdy,$cdm,$cdd)=(@c_d[5],@c_d[4],@c_d[3]); $cdm=$cdm+1; $cdy=$cdy-100+2000; $cdh="0".$cdh if $cdh<10; $cdmin="0".$cdmin if $cdmin<10; $cds="0".$cds if $cds<10; $cdm="0".$cdm if $cdm<10; $cdd="0".$cdd if $cdd<10; return "$cdy$cdm$cdd"; } sub get_date() { my ($days)=@_; my $seconds=0; $seconds= my @c_d=localtime(time+$seconds); my ($cdh,$cdmin,$cds)=(@c_d[2],@c_d[1],@c_d[0]); my ($cdy,$cdm,$cdd)=(@c_d[5],@c_d[4],@c_d[3]); $cdm=$cdm+1; $cdy=$cdy-100+2000; $cdh="0".$cdh if $cdh<10; $cdmin="0".$cdmin if $cdmin<10; $cds="0".$cds if $cds<10; $cdm="0".$cdm if $cdm<10; $cdd="0".$cdd if $cdd<10; return "$cdy$cdm$cdd:$cdh$cdmin$cds"; } sub create_group() { my($g_id,$u_name,$g_title) = @_; open(FH,">>grouplist.log"); my $mydate=get_date(); print FH "$g_id\|$g_title\|$u_name\|$mydate\n"; close FH; return $g_id; } sub save_groups() { my @groups = @_; open(FH,">grouplist.log"); foreach(@groups) { print FH $_; } close FH; } sub save_files(){ my @files = @_; open(FH,">filelist.log"); foreach(@files) { print FH $_; } close FH; } sub open_groups() { my ($key)=@_; my @groups; my $i=0; open(FH, "grouplist.log"); while(){ $groups[$i++] = $_ if /$key/; } close FH; return @groups; } sub open_files() { my ($key)=@_; my @files; my $i=0; open(FH, "filelist.log"); while(){ $files[$i++]=$_ if /$key/; } close FH; return @files; } sub group_files() { my($g_id) = @_; my @files; my $i=0; open(FH, "filelist.log"); while(){ if(/$g_id/){ $files[$i]=$_; $i++; } } close FH; return @files; } sub create_name() { my $i; my $str; for($i=1;$i<=5;$i++){ $str.=chr(int(rand(26))+65); } return $str; } sub create_num() { my $i; my $str; for($i=1;$i<=6;$i++){ $str.=int(rand(9)); } return $str; } sub num_format() { my ($v,$f)=@_; if(not $f ) { $f="M" if $v>500000; $f="K" if $v<500000; } if($f eq "M"){ $v=$v/1000000; $v=int($v*1000)/1000; $v = $v. " Mega"; } if($f eq "K"){ $v= $v/1000; $v = $v. " Kbyte"; } return $v; } 1;