Handle hostnames with upper-case letters
[webmin.git] / sendmail / save_feature.cgi
1 #!/usr/local/bin/perl
2 # save_feature.cgi
3 # Add a new line to the M4 file
4
5 require './sendmail-lib.pl';
6 require './features-lib.pl';
7 &ReadParse();
8 $features_access || &error($text{'features_ecannot'});
9 &error_setup($text{'feature_err'});
10
11 @features = &list_features();
12 if ($in{'new'}) {
13         $feature = { 'type' => $in{'type'} };
14         }
15 else {
16         $feature = $features[$in{'idx'}];
17         }
18
19 &lock_file($config{'sendmail_mc'});
20 if ($in{'delete'}) {
21         # Just delete this entry
22         &delete_feature($feature);
23         }
24 else {
25         # Validate and store inputs
26         if ($feature->{'type'} == 0) {
27                 $feature->{'text'} = $in{'text'};
28                 }
29         elsif ($feature->{'type'} == 1) {
30                 #local ($same) = grep { $_->{'type'} == 1 &&
31                 #                      $_->{'name'} eq $in{'name'} } @features;
32                 #$same && ($in{'new'} || $feature->{'name'} ne $in{'name'}) &&
33                 #       &error(&text('feature_efeat', "<tt>$in{'name'}</tt>"));
34                 $feature->{'name'} = $in{'name'};
35                 local @v;
36                 for($i=0; defined($in{"value_$i"}); $i++) {
37                         push(@v, $in{"value_$i"});
38                         }
39                 while($v[$#v] eq '' && @v) { pop(@v); }
40                 $feature->{'values'} = \@v;
41                 }
42         elsif ($feature->{'type'} == 2 || $feature->{'type'} == 3) {
43                 local ($same) = grep { ($_->{'type'} == 2 || $_->{'type'} == 3) &&
44                                        $_->{'name'} eq $in{'name'} } @features;
45                 $same && ($in{'new'} || $feature->{'name'} ne $in{'name'}) &&
46                         &error(&text('feature_edef', "<tt>$in{'name'}</tt>"));
47                 $feature->{'name'} = $in{'name'};
48                 if ($in{'undef'}) {
49                         $feature->{'type'} = 3;
50                         }
51                 else {
52                         $feature->{'type'} = 2;
53                         $feature->{'value'} = $in{'value'};
54                         }
55                 }
56         elsif ($feature->{'type'} == 4) {
57                 local ($same) = grep { $_->{'type'} == 4 &&
58                                        $_->{'mailer'} eq $in{'mailer'} } @features;
59                 $same && ($in{'new'} || $feature->{'mailer'} ne $in{'mailer'}) &&
60                         &error(&text('feature_emailer', "<tt>$in{'mailer'}</tt>"));
61                 $feature->{'mailer'} = $in{'mailer'};
62                 }
63         elsif ($feature->{'type'} == 5) {
64                 local ($same) = grep { $_->{'type'} == 5 } @features;
65                 $same && $in{'new'} &&
66                         &error(&text('feature_eostype', "<tt>$in{'ostype'}</tt>"));
67                 $feature->{'ostype'} = $in{'ostype'};
68                 }
69
70         # Save or create the entry
71         if ($in{'new'}) {
72                 &create_feature($feature);
73                 }
74         else {
75                 &modify_feature($feature);
76                 }
77         }
78
79 &unlock_file($config{'sendmail_mc'});
80 &webmin_log($in{'new'} ? 'create' : $in{'delete'} ? 'delete' : 'modify',
81             "feature", undef, $feature);
82 &redirect("list_features.cgi");
83