Default values for parameters

This commit is contained in:
Jamie Cameron
2011-06-23 20:52:49 -07:00
parent afcb242485
commit 44a7e23e87
5 changed files with 30 additions and 7 deletions

View File

@@ -32,3 +32,5 @@ Fixed a bug that broke remote command execution with parameters.
Added a new parameter type for selecting multiple items from a menu.
---- Changes since 1.530 ----
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.

View File

@@ -1,2 +1,4 @@
display_mode=0
columns=2
params_file=0
params_cmd=0

View File

@@ -1,2 +1,4 @@
display_mode=0
columns=2
params_file=0
params_cmd=0

View File

@@ -5,3 +5,5 @@ height=Height of file editor window,3,Default (20 chars)
wrap=File editor wrap mode,1,-Default (Soft),hard-Hard,off-Off
columns=Columns to display commands in,1,2-2,1-1
sort=Sort commands by,1,desc-Command name,html-Description,-Command ordering
params_file=Treat default values starting with / as file to read?,1,1-Yes,0-No
params_cmd=Treat default values ending with | as command to run?,1,1-Yes,0-No

View File

@@ -537,24 +537,39 @@ sub show_parameter_input
{
local ($a, $form) = @_;
local $n = $a->{'name'};
local $v = $a->{'opts'};
if ($a->{'type'} != 9 && $a->{'type'} != 12) {
if ($v =~ /^"(.*)"$/ || $v =~ /^'(.*)'$/) {
# Quoted default
$v = $1;
}
elsif ($v =~ /^\// && $config{'params_file'}) {
# File to read
$v = &read_file_contents($v);
}
elsif ($v =~ /^(.*)\s*\|$/ && $config{'params_cmd'}) {
# Command to run
$v = &backquote_command("$1 2>/dev/null </dev/null");
}
}
if ($a->{'type'} == 0) {
return &ui_textbox($n, undef, 30);
return &ui_textbox($n, $v, 30);
}
elsif ($a->{'type'} == 1 || $a->{'type'} == 2) {
return &ui_user_textbox($n, undef, $form);
return &ui_user_textbox($n, $v, $form);
}
elsif ($a->{'type'} == 3 || $a->{'type'} == 4) {
return &ui_group_textbox($n, undef, $form);
return &ui_group_textbox($n, $v, $form);
}
elsif ($a->{'type'} == 5 || $a->{'type'} == 6) {
return &ui_textbox($n, $a->{'opts'}, 30)." ".
return &ui_textbox($n, $v, 30)." ".
&file_chooser_button($n, $a->{'type'}-5, $form);
}
elsif ($a->{'type'} == 7) {
return &ui_yesno_radio($n, 0);
return &ui_yesno_radio($n, $v =~ /true|yes|1/ ? 1 : 0);
}
elsif ($a->{'type'} == 8) {
return &ui_password($n, undef, 30);
return &ui_password($n, $v, 30);
}
elsif ($a->{'type'} == 9) {
return &ui_select($n, undef, [ &read_opts_file($a->{'opts'}) ]);
@@ -563,7 +578,7 @@ elsif ($a->{'type'} == 10) {
return &ui_upload($n, 30);
}
elsif ($a->{'type'} == 11) {
return &ui_textarea($n, undef, 4, 30);
return &ui_textarea($n, $v, 4, 30);
}
elsif ($a->{'type'} == 12) {
return &ui_select($n, undef, [ &read_opts_file($a->{'opts'}) ],