diff --git a/custom/CHANGELOG b/custom/CHANGELOG index c1c24313e..982b18257 100644 --- a/custom/CHANGELOG +++ b/custom/CHANGELOG @@ -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. diff --git a/custom/config b/custom/config index 0a6ade13e..e31a0a466 100644 --- a/custom/config +++ b/custom/config @@ -1,2 +1,4 @@ display_mode=0 columns=2 +params_file=0 +params_cmd=0 diff --git a/custom/config-*-linux b/custom/config-*-linux index 0a6ade13e..e31a0a466 100644 --- a/custom/config-*-linux +++ b/custom/config-*-linux @@ -1,2 +1,4 @@ display_mode=0 columns=2 +params_file=0 +params_cmd=0 diff --git a/custom/config.info b/custom/config.info index 53bd8aaea..cabdd0ab2 100644 --- a/custom/config.info +++ b/custom/config.info @@ -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 diff --git a/custom/custom-lib.pl b/custom/custom-lib.pl index 2b05d88a7..523969dd8 100755 --- a/custom/custom-lib.pl +++ b/custom/custom-lib.pl @@ -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 {'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'}) ],