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
41 print "window.doneupload = 1;\n";
45 open(UPFILE, $upfile) || next;
49 ($size, $totalsize, $filename) = @lines;
51 # Come to the end OK .. set percent bar to 100
53 print "document.forms[0].pc.value = \"".("X" x 50)."\";\n";
54 print "window.doneupload = 1;\n";
58 $pc = int(100 * $size / $totalsize) / 2;
59 next if (defined($lastpc) && $pc == $lastpc);
61 print "document.forms[0].file.value = \"".
62 "e_escape($filename)."\";\n";
63 print "document.forms[0].size.value = \"".
64 "e_escape(&text('uptracker_of',
66 &nice_size($totalsize)))."\";\n";
67 print "document.forms[0].pc.value = \"".("|" x $pc)."\";\n";
71 last if ($size >= $totalsize);
74 # All done, so close the window and remove the file
76 print "window.close();\n";