Add option to redirect to index after running a command

This commit is contained in:
Jamie Cameron
2011-07-23 15:18:03 -07:00
parent 47e9ae77a1
commit caf8b94f16
6 changed files with 30 additions and 13 deletions

View File

@ -34,3 +34,4 @@ Added a new parameter type for selecting multiple items from a menu.
Added an option for custom commands to have their output displayed without any Webmin UI, in a selectable MIME type.
---- Changes since 1.550 ----
A default value for each custom command parameter can now be entered on the Edit Command form. Defaults can also be read from a file or shell command, if this behavior is enabled on the Module Config page. Thanks to Sart Cole for suggesting this feature.
A command can now be configured to not display any output at all, and instead return to the module index after being run.

View File

@ -345,7 +345,7 @@ for(my $i=0; $i<@a; $i++) {
push(@opts, [ $j, $text{"edit_type$j"} ]);
}
push(@cols, &ui_select("type_$i", $a[$i]->{'type'}, \@opts)." ".
&ui_textbox("opts_$i", $a[$i]->{'opts'}, 20));
&ui_textbox("opts_$i", $a[$i]->{'opts'}, 40));
if (!$noquote) {
push(@cols, &ui_yesno_radio("quote_$i",
int($a[$i]->{'quote'})));

View File

@ -81,9 +81,15 @@ print &ui_table_row(&hlink($text{'edit_clear'},"clear"),
&ui_yesno_radio("clear", $cmd->{'clear'}));
# Output format
$fmode = $cmd->{'format'} eq 'redirect' ? 2 :
$cmd->{'format'} ? 1 : 0;
print &ui_table_row(&hlink($text{'edit_format'}, "format"),
&ui_opt_textbox("format", $cmd->{'format'}, 20, $text{'edit_format0'},
$text{'edit_format1'}));
&ui_radio("format_def", $fmode,
[ [ 0, $text{'edit_format0'} ],
[ 2, $text{'edit_format2'} ],
[ 1, $text{'edit_format1'}." ".
&ui_textbox("format",
$fmode == 1 ? $cmd->{'format'} : "", 20) ] ]));
# Show Webmin servers to run on
@servers = &list_servers();

View File

@ -56,6 +56,7 @@ edit_clear=Clear environment variables?
edit_format=Output style
edit_format0=Show in Webmin UI
edit_format1=Output with MIME type
edit_format2=Redirect to index
edit_servers=Run on Webmin servers
edit_this=this server
edit_clone=Clone

View File

@ -34,13 +34,15 @@ else {
@servers = &list_servers();
# Run and display output
if ($cmd->{'format'}) {
print "Content-type: ",$cmd->{'format'},"\n";
print "\n";
}
else {
&ui_print_unbuffered_header($cmd->{'desc'}, $text{'run_title'}, "",
-d "help" ? "run" : undef);
if ($cmd->{'format'} ne 'redirect') {
if ($cmd->{'format'}) {
print "Content-type: ",$cmd->{'format'},"\n";
print "\n";
}
else {
&ui_print_unbuffered_header($cmd->{'desc'}, $text{'run_title'},
"", -d "help" ? "run" : undef);
}
}
&remote_error_setup(\&remote_custom_handler);
@ -61,7 +63,8 @@ foreach $h (@hosts) {
if ($h == 0) {
# Run locally
($got, $out, $timeout) = &execute_custom_command(
$cmd, $env, $export, $str, 1);
$cmd, $env, $export, $str,
$cmd->{'format'} ne 'redirect');
}
else {
# Remote foreign call
@ -78,7 +81,7 @@ foreach $h (@hosts) {
&additional_log('exec', undef, $displaystr);
}
if (!$remote_custom_error) {
print $out if ($h != 0);
print $out if ($h != 0 && $cmd->{'format'} ne 'redirect');
if (!$got && !$cmd->{'format'}) {
print "<i>$text{'run_noout'}</i>\n";
}
@ -109,6 +112,9 @@ unlink(@unlink) if (@unlink);
if (!$cmd->{'format'}) {
&ui_print_footer("", $text{'index_return'});
}
elsif ($cmd->{'format'} eq 'redirect') {
&redirect("");
}
sub remote_custom_handler
{

View File

@ -56,9 +56,12 @@ else {
$cmd->{'order'} = $in{'order_def'} ? 0 : int($in{'order'});
$cmd->{'timeout'} = $in{'timeout_def'} ? 0 : int($in{'timeout'});
$cmd->{'clear'} = $in{'clear'};
if ($in{'format_def'}) {
if ($in{'format_def'} == 0) {
delete($cmd->{'format'});
}
elsif ($in{'format_def'} == 2) {
$cmd->{'format'} = 'redirect';
}
else {
$in{'format'} =~ /^[a-z0-9\.\_\-]+\/[a-z0-9\.\_\-]+/i ||
&error($text{'save_eformat'});