관리-도구
편집 파일: upload_status.cgi
#!/usr/bin/perl ### SibSoft.net, XUpload Pro 3.1, May 2009 ### use strict; use CGI::Carp qw(fatalsToBrowser); use lib '.'; use XUploadConfig; use Fcntl ':flock'; my $nbars=30; # number of bars my $f; for(split(/&/,$ENV{QUERY_STRING})) { my ($name,$value) = split(/=/,$_); $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $f->{$name} = $value; } my $sid=$f->{uid}; my $flength_file = "$c->{temp_dir}/$sid/flength"; my $fmsg_file = "$c->{temp_dir}/$sid/fmsg"; my $temp_dir = "$c->{temp_dir}/$sid"; #print"Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"; #print"Cache-Control: no-store, no-cache, must-revalidate\n"; #print"Cache-Control: post-check=0, pre-check=0\n"; #print"Pragma: no-cache\n"; print"Content-type: text/html\n\n"; for(1..5){ last if -e $flength_file; sleep 1; } &DisplayMessage($c->{msg}->{transfer_complete},'nostop') unless (-e $flength_file); # No flength file => Upload already finished my ($str,$msgs,$num,$uploaded) = &getSizeInfo( $f->{num} ); my ($total,$current,$time,$speed,$files) = split(/:/,$str); my $percent = sprintf("%.1f",100*$current/$total) if $total>0; my $estimate = sprintf("%.0f", ($total-$current)/$speed ) if $speed; my ($totalKB,$currentKB,$total_metrics); my $speedKB = sprintf("%.0f",$speed/1024); if($total>1048576) #>1Mb - convert to Mb { $totalKB = sprintf("%.2f",$total/1048576); $currentKB = sprintf("%.2f",$current/1048576); $total_metrics = " Mbytes"; } else { $totalKB = sprintf("%.0f",$total/1024); $currentKB = sprintf("%.0f",$current/1024); $total_metrics = " Kbytes"; } unless($f->{ajax2}) { &DisplayMessage($str) if $str =~ /^ERROR/; my $i=1; my @file_list = map{ {num=>$i++,name=>$_} } grep{$_} split(':', $f->{files} ); my $files_total = scalar @file_list; my $tmpl_file = ($f->{tmpl}=~/^\w+$/ && -f "Templates/$f->{tmpl}.html") ? "$f->{tmpl}.html" : "default.html"; my $bars_arr = [map{{'num'=>$_}}(1..$nbars)]; require HTML::Template; my $t = HTML::Template->new( filename => "Templates/$tmpl_file", die_on_bad_params => 0, ); $t->param(( 'percent_completed' => '<font id="percent">0%</font>', 'files_uploaded' => '<font id="files">0</font>', 'files_total' => '<font id="files_total">0</font>', 'data_uploaded' => '<font id="current">0</font>', 'data_total' => '<font id="data_total">0</font>', 'time_spent' => '<font id="time">0</font>', 'speed' => '<font id="speed">0</font>', 'time_left' => '<font id="left">0</font>', 'inline' => $f->{inline}||'', 'data_total_dgt' => $totalKB, 'bars' => $bars_arr, 'nbars' => $nbars, 'file_list' => \@file_list, )); print $t->output; print"<Script>inline_pro=1;var doc=parent.document;</Script>" if $f->{inline_pro}; print qq[<Script>uid='$sid';num='$num';changeValue('files_total','$files_total');changeValue('data_total','$totalKB $total_metrics');S('$percent','$currentKB','$time',0,'$files',0);interval = window.setInterval(function (){jah();},1000);</Script>]; exit; } if(grep{/^uploaded$/i}@$msgs) #finished upload { $files++; print"S('100','$totalKB','$time','$speedKB','$files',0);"; print"if(document.getElementById('stop_btn')){document.getElementById('stop_btn').style.display='none';}"; } else { print qq{S('$percent','$currentKB','$time','$speedKB','$files','$estimate');} unless $uploaded; } for my $str (@$msgs) { if($str=~/^file_uploaded:(\d+):(\d+)/) { my $fsize = $2 < 1048576 ? sprintf("%.0f Kb",$2/1024) : sprintf("%.1f Mb",$2/1048576); print"updateFileStatus('$1','done','DONE','$fsize');"; print"updateFileStatus('".($1+1)."','load','Uploading','');"; } my ($msg) = $str=~/^MSG:(.+)$/; next unless $msg; $msg=~s/"/"e;/g; print qq{Message("$msg");num='$num';} if $msg; } ####### sub getSizeInfo { my ($num_old) = @_; open F,$flength_file || die"Flength open error!"; flock F, LOCK_EX; my @msgs = <F>; close F; chomp(@msgs); my $str = shift(@msgs); my $num = scalar @msgs; $num=0 if $num_old eq ''; my $uploaded=1 if grep{/^uploaded$/i}@msgs; shift @msgs for 1..$num_old; return ($str,\@msgs,$num,$uploaded); } sub DisplayMessage { my ($MSG,$nostop) = @_; my $MSG2 = $MSG; $MSG2=~s/<br>/\\n/gs; require HTML::Template; my $t = HTML::Template->new( filename => "Templates/default.html", die_on_bad_params => 0 ); $t->param('data_total_dgt' => 0, 'js_bars' => 0, 'nbars' => 0, 'message' => $MSG, 'message2' => $MSG2, 'nostop' => $nostop, 'inline_pro' => $f->{inline_pro}||'', ); print $t->output; exit; }