#!/usr/local/bin/perl # Output Javascript in a loop to track an upload BEGIN { push(@INC, ".."); }; use WebminCore; $trust_unknown_referers = 1; &init_config(); &ReadParse(); $id = $in{'id'}; $id || &error($text{'uptracker_eid'}); $id =~ /^[a-z0-9_]+$/i || &error($text{'uptracker_eid2'}); &popup_header($text{'uptracker_title'}, undef, "onunload='if (!window.doneupload) { opener.stop() }'"); $| = 1; # Output text boxes that get updated with filenames and progress $ff = "style='font-family: courier,monospace'"; print "
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$text{'uptracker_file'}",&ui_textbox("file", undef, 50, 1, undef, $ff),"
$text{'uptracker_size'}",&ui_textbox("size", undef, 50, 1, undef, $ff),"
$text{'uptracker_pc'}",&ui_textbox("pc", undef, 50, 1, undef, $ff),"
\n"; print "
\n"; # Find the location of the user's upload progess file if ($in{'uid'}) { @uinfo = getpwuid($in{'uid'}); $upfile = "$uinfo[7]/.tmp/upload.$id"; } else { $upfile = "$ENV{'WEBMIN_VAR'}/upload.$id"; } # Read the tracker file in a loop until done, or until 1 minute has passed # with no progress print "\n"; $start = time(); while(1) { sleep(1); $now = time(); if (!open(UPFILE, $upfile)) { # Doesn't exist yet if ($now - $start > 60) { # Give up after 60 seconds print "\n"; last; } next; } @lines = ; chop(@lines); close(UPFILE); ($size, $totalsize, $filename) = @lines; if ($size == -1) { # Come to the end OK .. set percent bar to 100 print "\n"; last; } # Check if there has been no activity for 60 seconds if ($size == $last_size) { if ($last_time && $last_time < $now-60) { # Too slow! Give up print "\n"; last; } } else { $last_size = $size; $last_time = $now; } $pc = int(100 * $size / $totalsize) / 2; next if (defined($lastpc) && $pc == $lastpc); print "\n"; $lastpc = $pc; last if ($size >= $totalsize); } # All done, so close the window and remove the file print "\n"; unlink($upfile); &popup_footer();