2007-04-12 20:24:50 +00:00
|
|
|
#!/usr/local/bin/perl
|
|
|
|
# Output Javascript in a loop to track an upload
|
|
|
|
|
2018-07-04 12:24:02 -07:00
|
|
|
BEGIN { push(@INC, "."); };
|
2009-03-01 07:50:07 +00:00
|
|
|
use WebminCore;
|
|
|
|
|
2007-04-12 20:24:50 +00:00
|
|
|
&init_config();
|
|
|
|
&ReadParse();
|
|
|
|
$id = $in{'id'};
|
|
|
|
$id || &error($text{'uptracker_eid'});
|
2008-02-14 08:27:59 +00:00
|
|
|
$id =~ /^[a-z0-9_]+$/i || &error($text{'uptracker_eid2'});
|
2007-04-12 20:24:50 +00:00
|
|
|
|
|
|
|
&popup_header($text{'uptracker_title'}, undef,
|
|
|
|
"onunload='if (!window.doneupload) { opener.stop() }'");
|
|
|
|
$| = 1;
|
|
|
|
|
|
|
|
# Output text boxes that get updated with filenames and progress
|
2011-06-04 09:42:16 -07:00
|
|
|
$ff = "style='font-family: courier,monospace'";
|
2007-04-12 20:24:50 +00:00
|
|
|
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";
|
|
|
|
|
2022-06-29 07:17:11 -04:00
|
|
|
# Find the location of the user's upload progress file
|
2007-04-12 20:24:50 +00:00
|
|
|
if ($in{'uid'}) {
|
|
|
|
@uinfo = getpwuid($in{'uid'});
|
|
|
|
$upfile = "$uinfo[7]/.tmp/upload.$id";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$upfile = "$ENV{'WEBMIN_VAR'}/upload.$id";
|
|
|
|
}
|
|
|
|
|
2007-04-29 19:16:52 +00:00
|
|
|
# Read the tracker file in a loop until done, or until 1 minute has passed
|
|
|
|
# with no progress
|
2007-04-12 20:24:50 +00:00
|
|
|
print "<script>\n";
|
|
|
|
print "window.doneupload = 1;\n";
|
|
|
|
print "</script>\n";
|
2008-01-16 18:53:01 +00:00
|
|
|
$start = time();
|
2007-04-12 20:24:50 +00:00
|
|
|
while(1) {
|
|
|
|
sleep(1);
|
2008-01-16 18:53:01 +00:00
|
|
|
$now = time();
|
2020-03-14 09:33:28 -07:00
|
|
|
if (!open(UPFILE, "<$upfile")) {
|
2008-01-16 18:53:01 +00:00
|
|
|
# Doesn't exist yet
|
|
|
|
if ($now - $start > 60) {
|
|
|
|
# Give up after 60 seconds
|
|
|
|
print "<script>\n";
|
|
|
|
print "document.forms[0].pc.value = \"Not started\";\n";
|
|
|
|
print "</script>\n";
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2007-04-12 20:24:50 +00:00
|
|
|
@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;
|
|
|
|
}
|
2007-04-29 19:16:52 +00:00
|
|
|
|
|
|
|
# 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 "<script>\n";
|
|
|
|
print "document.forms[0].pc.value = \"Timeout\";\n";
|
|
|
|
print "</script>\n";
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$last_size = $size;
|
|
|
|
$last_time = $now;
|
|
|
|
}
|
|
|
|
|
2021-04-30 20:37:10 -07:00
|
|
|
$pc = $totalsize ? int(100 * $size / $totalsize) / 2 : 100;
|
2007-04-12 20:24:50 +00:00
|
|
|
next if (defined($lastpc) && $pc == $lastpc);
|
|
|
|
print "<script>\n";
|
|
|
|
print "document.forms[0].file.value = \"".
|
2014-07-03 16:01:25 -07:00
|
|
|
"e_javascript($filename)."\";\n";
|
2007-04-12 20:24:50 +00:00
|
|
|
print "document.forms[0].size.value = \"".
|
2014-07-03 16:01:25 -07:00
|
|
|
"e_javascript(&text('uptracker_of',
|
2014-05-14 16:32:19 -07:00
|
|
|
&nice_size($size),
|
|
|
|
&nice_size($totalsize)))."\";\n";
|
2007-04-12 20:24:50 +00:00
|
|
|
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();
|
|
|
|
|