mirror of
https://github.com/webmin/webmin.git
synced 2025-08-16 14:51:18 +00:00
82 lines
2.3 KiB
Perl
Executable File
82 lines
2.3 KiB
Perl
Executable File
#!/usr/local/bin/perl
|
|
# Output Javascript in a loop to track an upload
|
|
# XXX add to more modules
|
|
|
|
require './web-lib.pl';
|
|
&init_config();
|
|
do './ui-lib.pl';
|
|
&ReadParse();
|
|
$id = $in{'id'};
|
|
$id || &error($text{'uptracker_eid'});
|
|
$id !~ /\.\./ && $id !~ /\0/ || &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'";
|
|
print "<form>\n";
|
|
print "<center><table>\n";
|
|
print "<tr> <td><b>$text{'uptracker_file'}</b></td>\n";
|
|
print "<td>",&ui_textbox("file", undef, 50, 1, undef, $ff),"</td> </tr>\n";
|
|
print "<tr> <td><b>$text{'uptracker_size'}</b></td>\n";
|
|
print "<td>",&ui_textbox("size", undef, 50, 1, undef, $ff),"</td> </tr>\n";
|
|
print "<tr> <td><b>$text{'uptracker_pc'}</b></td>\n";
|
|
print "<td>",&ui_textbox("pc", undef, 50, 1, undef, $ff),"</td> </tr>\n";
|
|
print "</table></center>\n";
|
|
print "</form>\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
|
|
print "<script>\n";
|
|
print "window.doneupload = 1;\n";
|
|
print "</script>\n";
|
|
while(1) {
|
|
sleep(1);
|
|
open(UPFILE, $upfile) || next;
|
|
@lines = <UPFILE>;
|
|
chop(@lines);
|
|
close(UPFILE);
|
|
($size, $totalsize, $filename) = @lines;
|
|
if ($size == -1) {
|
|
# Come to the end OK .. set percent bar to 100
|
|
print "<script>\n";
|
|
print "document.forms[0].pc.value = \"".("X" x 50)."\";\n";
|
|
print "window.doneupload = 1;\n";
|
|
print "</script>\n";
|
|
last;
|
|
}
|
|
$pc = int(100 * $size / $totalsize) / 2;
|
|
next if (defined($lastpc) && $pc == $lastpc);
|
|
print "<script>\n";
|
|
print "document.forms[0].file.value = \"".
|
|
"e_escape($filename)."\";\n";
|
|
print "document.forms[0].size.value = \"".
|
|
"e_escape(&text('uptracker_of',
|
|
&nice_size($size),
|
|
&nice_size($totalsize)))."\";\n";
|
|
print "document.forms[0].pc.value = \"".("|" x $pc)."\";\n";
|
|
print "</script>\n";
|
|
|
|
$lastpc = $pc;
|
|
last if ($size >= $totalsize);
|
|
}
|
|
|
|
# All done, so close the window and remove the file
|
|
print "<script>\n";
|
|
print "window.close();\n";
|
|
print "</script>\n";
|
|
unlink($upfile);
|
|
|
|
&popup_footer();
|
|
|