This commit is contained in:
Jamie Cameron 2017-11-19 12:22:39 -08:00
parent ed3e34a6aa
commit 125b50d3de
2 changed files with 32 additions and 19 deletions

View File

@ -1,3 +1,5 @@
---- Changes since 1.650 ----
The output from commands is now limited to 100k by default, to reduce memory consumption in Webmin and in the browser if a large command is executed.
The run-time of a command is now limited to 24 hours by default, to prevent eternal commands like tail -f from continuing in the the background forever.
---- Changes since 1.860 ----
Output from long-running commands is now displayed progressively.

View File

@ -6,9 +6,10 @@ $unsafe_index_cgi = 1;
require './shell-lib.pl';
%access = &get_module_acl();
&ReadParseMime() if ($ENV{'REQUEST_METHOD'} ne 'GET');
&ui_print_header(undef, $text{'index_title'}, "", undef,
$module_info{'usermin'} ? 0 : 1, 1,
undef, undef, undef,
&ui_print_unbuffered_header(
undef, $text{'index_title'}, "", undef,
$module_info{'usermin'} ? 0 : 1, 1,
undef, undef, undef,
"onLoad='window.scroll(0, 10000); document.forms[0].cmd.focus()'");
$prevfile = "$module_config_directory/previous.$remote_user";
@ -22,6 +23,7 @@ else {
open(PREVFILE, $prevfile);
chop(@previous = <PREVFILE>);
close(PREVFILE);
@previous = &unique(@previous);
}
$cmd = $in{'doprev'} ? $in{'pcmd'} : $in{'cmd'};
@ -40,13 +42,21 @@ else {
}
}
if (!$in{'clear'}) {
# Show the prior history and command input
$history = &un_urlize($in{'history'});
print "<pre>";
if ($history) {
print $history;
}
if ($cmd) {
# Execute the latest command
$chroot = $access{'chroot'} eq '/' ? '' : $access{'chroot'};
$fullcmd = $cmd;
$ok = chdir($chroot.$pwd);
$history .= "<b>&gt; ".&html_escape($cmd, 1)."</b>\n";
$cmdmsg = "<b>&gt; ".&html_escape($cmd, 1)."</b>\n";
$history .= $cmdmsg;
print $cmdmsg;
if ($cmd =~ /^cd\s+"([^"]+)"\s*(;?\s*(.*))$/ ||
$cmd =~ /^cd\s+'([^']+)'\s*(;?\s*(.*))$/ ||
$cmd =~ /^cd\s+([^; ]*)\s*(;?\s*(.*))$/) {
@ -107,12 +117,13 @@ if (!$in{'clear'}) {
}
}
local $buf;
$got = sysread(OUTPUT, $buf, 1024);
$got = sysread(OUTPUT, $buf, 80);
last if ($got <= 0);
$total += length($buf);
if ($config{'max_output'} &&
length($out) < $config{'max_output'}) {
$out .= $buf;
print &html_escape($buf);
}
else {
$trunc = 1;
@ -124,21 +135,27 @@ if (!$in{'clear'}) {
close(OUTPUT);
&reset_environment() if ($config{'clear_envs'});
if ($out && $out !~ /\n$/) {
print "\n";
$out .= "\n";
}
$out = &html_escape($out, 1);
$out = &html_escape($out);
my $msg;
if ($trunc) {
$out .= "<i>".&text('index_trunced',
$msg = "<i>".&text('index_trunced',
&nice_size($config{'max_output'}),
&nice_size($total))."</i><p>\n";
&nice_size($total))."</i>\n";
print $msg;
$out .= $msg;
}
if ($timedout) {
$out .= "<i>".&text('index_timedout',
$config{'max_runtime'})."</i><p>\n";
$msg = "<i>".&text('index_timedout',
$config{'max_runtime'})."</i>\n";
print $msg;
$out .= $msg;
}
$history .= $out;
}
@previous = &unique($fullcmd, @previous);
@previous = ((grep { $_ ne $fullcmd } @previous), $fullcmd);
&lock_file($prevfile);
&open_tempfile(PREVFILE, ">>$prevfile");
&print_tempfile(PREVFILE, $fullcmd,"\n");
@ -146,14 +163,8 @@ if (!$in{'clear'}) {
&unlock_file($prevfile);
&webmin_log("run", undef, undef, { 'cmd' => $fullcmd });
}
}
# Show the history and command input
if ($history) {
print &ui_table_start($text{'shell_history'}, "width=100%", 2);
print &ui_table_row(undef, "<pre>$history</pre>", 2);
print &ui_table_end();
print &ui_hr();
print "</pre>";
print &ui_hr() if ($history);
}
print "$text{'index_desc'}<br>\n";