Handle hostnames with upper-case letters
[webmin.git] / postfix / save_client.cgi
1 #!/usr/local/bin/perl
2 # Save SMTP authentication options
3
4 require './postfix-lib.pl';
5
6 &ReadParse();
7
8 $access{'client'} || &error($text{'opts_ecannot'});
9
10 &error_setup($text{'client_err'});
11
12 &lock_postfix_files();
13
14 if ($in{'client_def'}) {
15         # Reset to default
16         &set_current_value("smtpd_client_restrictions",
17                            "__DEFAULT_VALUE_IE_NOT_IN_CONFIG_FILE__");
18         }
19 else {
20         # Save client options
21         @opts = split(/[\s,]+/,&get_current_value("smtpd_client_restrictions"));
22         %oldopts = map { $_, 1 } @opts;
23         %newopts = map { $_, 1 } split(/\0/, $in{'client'});
24
25         # Save boolean options
26         foreach $o (&list_client_restrictions()) {
27                 if ($newopts{$o} && !$oldopts{$o}) {
28                         push(@opts, $o);
29                         }
30                 elsif (!$newopts{$o} && $oldopts{$o}) {
31                         @opts = grep { $_ ne $o } @opts;
32                         }
33                 }
34
35         # Save options with values
36         foreach $o (&list_multi_client_restrictions()) {
37                 # Find all current positions
38                 local @pos;
39                 for(my $i=0; $i<@opts; $i++) {
40                         push(@pos, $i) if ($opts[$i] eq $o);
41                         }
42
43                 # Make sure something was entered
44                 if ($newopts{$o}) {
45                         $in{"value_$o"} =~ /\S/ ||
46                             &error(&text('client_evalue', $text{'sasl_'.$o}));
47                         }
48
49                 # Sync with values entered
50                 @v = split(/\s+/, $in{"value_$o"});
51                 for(my $i=0; $i<@pos || $i<@v; $i++) {
52                         if ($i<@pos && $i<@v) {
53                                 # Updating a value
54                                 $opts[$pos[$i]+1] = $v[$i];
55                                 }
56                         elsif ($i<@pos && $i>=@v) {
57                                 # Removing a value
58                                 splice(@opts, $pos[$i], 2);
59                                 }
60                         elsif ($i>=@pos && $i<@v) {
61                                 # Adding a value, at the end
62                                 push(@opts, $o, $v[$i]);
63                                 }
64                         }
65                 }
66
67         &set_current_value("smtpd_client_restrictions", join(" ", @opts));
68         }
69
70 &unlock_postfix_files();
71
72 &reload_postfix();
73
74 &webmin_log("client");
75 &redirect("");
76
77
78