Add option to redirect to index after running a command
authorJamie Cameron <jcameron@webmin.com>
Sat, 23 Jul 2011 22:18:03 +0000 (15:18 -0700)
committerJamie Cameron <jcameron@webmin.com>
Sat, 23 Jul 2011 22:18:03 +0000 (15:18 -0700)
custom/CHANGELOG
custom/custom-lib.pl
custom/edit_cmd.cgi
custom/lang/en
custom/run.cgi
custom/save_cmd.cgi

index 982b182..a96f7d3 100644 (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.
index 6008e30..90c1664 100755 (executable)
@@ -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'})));
index b7b42c0..66608e8 100755 (executable)
@@ -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();
index eda085a..20f4a09 100644 (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
index 0707fe2..639ef01 100755 (executable)
@@ -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
 {
index 5810366..ea7d1d9 100755 (executable)
@@ -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'});