Mandatory parameter option
authorJamie Cameron <jcameron@webmin.com>
Thu, 5 Feb 2009 01:39:31 +0000 (01:39 +0000)
committerJamie Cameron <jcameron@webmin.com>
Thu, 5 Feb 2009 01:39:31 +0000 (01:39 +0000)
custom/CHANGELOG
custom/custom-lib.pl
custom/lang/en

index f1664a3..bfb831b 100644 (file)
@@ -22,3 +22,5 @@ When commands are shown in a table and no parameters are needed, the names now l
 Added a popup progress tracker to commands with file upload fields.
 ---- Changes since 1.410 ----
 All links to commands are via an ID number rather than an index, which makes them easier to link to from other web pages.
+---- Changes since 1.450 ----
+Added a parameter-level option to make the parameter mandatory.
index ef4496d..ca57830 100644 (file)
@@ -69,10 +69,12 @@ while($f = readdir(DIR)) {
                while(<FILE>) {
                        s/\r|\n//g;
                        local @a = split(/:/, $_, 5);
+                       local ($quote, $must) = split(/,/, $a[3]);
                        push(@{$cmd{'args'}}, { 'name' => $a[0],
                                                'type' => $a[1],
                                                'opts' => $a[2],
-                                               'quote' => $a[3],
+                                               'quote' => int($quote),
+                                               'must' => int($must),
                                                'desc' => $a[4] });
                        }
                close(FILE);
@@ -161,7 +163,8 @@ else {
 # Save parameters
 foreach $a (@{$c->{'args'}}) {
        &print_tempfile(FILE, $a->{'name'},":",$a->{'type'},":",
-          $a->{'opts'},":",$a->{'quote'},":",$a->{'desc'},"\n");
+          $a->{'opts'},":",int($a->{'quote'}),",",int($a->{'must'}),":",
+          $a->{'desc'},"\n");
        }
 &close_tempfile(FILE);
 
@@ -311,6 +314,7 @@ local ($cmd, $noquote, $editor) = @_;
 local $ptable = &ui_columns_start([
        $text{'edit_name'}, $text{'edit_desc'}, $text{'edit_type'},
        $noquote ? ( ) : ( $text{'edit_quote'} ),
+       $text{'edit_must'},
        ], 100, 0, undef, undef);
 local @a = (@{$cmd->{'args'}}, { });
 for(my $i=0; $i<@a; $i++) {
@@ -329,6 +333,8 @@ for(my $i=0; $i<@a; $i++) {
                push(@cols, &ui_yesno_radio("quote_$i",
                                            int($a[$i]->{'quote'})));
                }
+       push(@cols, &ui_yesno_radio("must_$i",
+                                    int($a[$i]->{'must'})));
        $ptable .= &ui_columns_row(\@cols);
        }
 
@@ -348,6 +354,7 @@ for($i=0; defined($name = $in{"name_$i"}); $i++) {
                                          'desc' => $in{"desc_$i"},
                                          'type' => $in{"type_$i"},
                                          'quote' => int($in{"quote_$i"}),
+                                         'must' => int($in{"must_$i"}),
                                          'opts' => $in{"opts_$i"} });
                }
        }
@@ -407,6 +414,9 @@ foreach my $a (@{$cmd->{'args'}}) {
                chown($uinfo->[2], $uinfo->[3], $rv);
                push(@unlink, $rv);
                }
+       if ($rv eq '' && $a->{'must'} && $a->{'type'} != 7) {
+               &error(&text('run_emust', $a->{'desc'}));
+               }
        $ENV{$n} = $rv;
        $env .= "$n='$rv'\n";
        $export .= " $n";
index bb642c8..e808c65 100644 (file)
@@ -33,6 +33,7 @@ edit_params=Command parameters
 edit_name=Parameter name
 edit_type=Type
 edit_quote=Quote?
+edit_must=Required?
 edit_type0=Text
 edit_type1=User
 edit_type2=UID
@@ -77,6 +78,7 @@ run_noout=No output generated
 run_ecmduser=User '$1' to run command as does not exist
 run_eopt=Invalid option selected
 run_eupload=No file to upload selected
+run_emust=Missing value for parameter '$1'
 run_timeout=Command terminated after $1 second timeout.
 
 log_modify=Modified command $1