2 # Output Javascript in a loop to track an upload
4 BEGIN { push(@INC, ".."); };
7 $trust_unknown_referers = 1;
11 $id || &error($text{'uptracker_eid'});
12 $id =~ /^[a-z0-9_]+$/i || &error($text{'uptracker_eid2'});
14 &popup_header($text{'uptracker_title'}, undef,
15 "onunload='if (!window.doneupload) { opener.stop() }'");
18 # Output text boxes that get updated with filenames and progress
19 $ff = "style='font-family: courier,monospace'";
21 print "<center><table>\n";
22 print "<tr> <td><b>$text{'uptracker_file'}</b></td>\n";
23 print "<td>",&ui_textbox("file", undef, 50, 1, undef, $ff),"</td> </tr>\n";
24 print "<tr> <td><b>$text{'uptracker_size'}</b></td>\n";
25 print "<td>",&ui_textbox("size", undef, 50, 1, undef, $ff),"</td> </tr>\n";
26 print "<tr> <td><b>$text{'uptracker_pc'}</b></td>\n";
27 print "<td>",&ui_textbox("pc", undef, 50, 1, undef, $ff),"</td> </tr>\n";
28 print "</table></center>\n";
31 # Find the location of the user's upload progess file
33 @uinfo = getpwuid($in{'uid'});
34 $upfile = "$uinfo[7]/.tmp/upload.$id";
37 $upfile = "$ENV{'WEBMIN_VAR'}/upload.$id";
40 # Read the tracker file in a loop until done, or until 1 minute has passed
43 print "window.doneupload = 1;\n";
49 if (!open(UPFILE, $upfile)) {
51 if ($now - $start > 60) {
52 # Give up after 60 seconds
54 print "document.forms[0].pc.value = \"Not started\";\n";
63 ($size, $totalsize, $filename) = @lines;
65 # Come to the end OK .. set percent bar to 100
67 print "document.forms[0].pc.value = \"".("X" x 50)."\";\n";
68 print "window.doneupload = 1;\n";
73 # Check if there has been no activity for 60 seconds
74 if ($size == $last_size) {
75 if ($last_time && $last_time < $now-60) {
78 print "document.forms[0].pc.value = \"Timeout\";\n";
88 $pc = int(100 * $size / $totalsize) / 2;
89 next if (defined($lastpc) && $pc == $lastpc);
91 print "document.forms[0].file.value = \"".
92 "e_escape($filename)."\";\n";
93 print "document.forms[0].size.value = \"".
94 "e_escape(&text('uptracker_of',
96 &nice_size($totalsize)))."\";\n";
97 print "document.forms[0].pc.value = \"".("|" x $pc)."\";\n";
101 last if ($size >= $totalsize);
104 # All done, so close the window and remove the file
106 print "window.close();\n";