2 # Output Javascript in a loop to track an upload
3 # XXX add to more modules
5 require './web-lib.pl';
10 $id || &error($text{'uptracker_eid'});
11 $id !~ /\.\./ && $id !~ /\0/ || &error($text{'uptracker_eid2'});
13 &popup_header($text{'uptracker_title'}, undef,
14 "onunload='if (!window.doneupload) { opener.stop() }'");
17 # Output text boxes that get updated with filenames and progress
18 $ff = "style='font-family: courier'";
20 print "<center><table>\n";
21 print "<tr> <td><b>$text{'uptracker_file'}</b></td>\n";
22 print "<td>",&ui_textbox("file", undef, 50, 1, undef, $ff),"</td> </tr>\n";
23 print "<tr> <td><b>$text{'uptracker_size'}</b></td>\n";
24 print "<td>",&ui_textbox("size", undef, 50, 1, undef, $ff),"</td> </tr>\n";
25 print "<tr> <td><b>$text{'uptracker_pc'}</b></td>\n";
26 print "<td>",&ui_textbox("pc", undef, 50, 1, undef, $ff),"</td> </tr>\n";
27 print "</table></center>\n";
30 # Find the location of the user's upload progess file
32 @uinfo = getpwuid($in{'uid'});
33 $upfile = "$uinfo[7]/.tmp/upload.$id";
36 $upfile = "$ENV{'WEBMIN_VAR'}/upload.$id";
39 # Read the tracker file in a loop until done, or until 1 minute has passed
42 print "window.doneupload = 1;\n";
48 if (!open(UPFILE, $upfile)) {
50 if ($now - $start > 60) {
51 # Give up after 60 seconds
53 print "document.forms[0].pc.value = \"Not started\";\n";
62 ($size, $totalsize, $filename) = @lines;
64 # Come to the end OK .. set percent bar to 100
66 print "document.forms[0].pc.value = \"".("X" x 50)."\";\n";
67 print "window.doneupload = 1;\n";
72 # Check if there has been no activity for 60 seconds
73 if ($size == $last_size) {
74 if ($last_time && $last_time < $now-60) {
77 print "document.forms[0].pc.value = \"Timeout\";\n";
87 $pc = int(100 * $size / $totalsize) / 2;
88 next if (defined($lastpc) && $pc == $lastpc);
90 print "document.forms[0].file.value = \"".
91 "e_escape($filename)."\";\n";
92 print "document.forms[0].size.value = \"".
93 "e_escape(&text('uptracker_of',
95 &nice_size($totalsize)))."\";\n";
96 print "document.forms[0].pc.value = \"".("|" x $pc)."\";\n";
100 last if ($size >= $totalsize);
103 # All done, so close the window and remove the file
105 print "window.close();\n";