Handle hostnames with upper-case letters
[webmin.git] / sendmail / save_access.cgi
1 #!/usr/local/bin/perl
2 # save_access.cgi
3 # Save, create or delete an access rule
4
5 require './sendmail-lib.pl';
6 require './access-lib.pl';
7 &ReadParse();
8 $access{'access'} || &error($text{'access_ecannot'});
9 $conf = &get_sendmailcf();
10 $afile = &access_file($conf);
11 &lock_file($afile);
12 ($adbm, $adbmtype) = &access_dbm($conf);
13 @accs = &list_access($afile);
14 if (!$in{'new'}) {
15         $a = $accs[$in{'num'}];
16         &can_edit_access($a) ||
17                 &error($text{'sform_ecannot'});
18         }
19
20 if ($in{'delete'}) {
21         # delete some rule
22         $loga = $a;
23         &delete_access($a, $afile, $adbm, $adbmtype);
24         }
25 else {
26         # Saving or creating.. check inputs
27         $whatfailed = "Failed to save spam control rule";
28         $from = $in{'from'};
29         $in{'from_type'} == 0 && $from !~ /^[^\@ ]+\@[A-z0-9\.\-]+$/ &&
30                 &error(&text('ssave_etype0', $from));
31         $in{'from_type'} == 1 && $from !~ /^[0-9\.]+$/ &&
32                 &error(&text('ssave_etype1', $from));
33         $in{'from_type'} == 2 && $from !~ /^[^\@ ]+$/ &&
34                 &error(&text('ssave_etype2', $from));
35         $in{'from_type'} == 3 && $from !~ /^[A-z0-9\.\-]+$/ &&
36                 &error(&text('ssave_etype3', $from));
37         $from .= '@' if ($in{'from_type'} == 2);
38
39         if ($in{'new'} || uc($from) ne uc($a->{'from'}) ||
40             $in{'tag'} ne $a->{'tag'}) {
41                 # Is this name taken?
42                 local ($same) = grep { uc($_->{'from'}) eq uc($from) &&
43                                        $_->{'tag'} eq $in{'tag'} } @accs;
44                 $same && &error(&text('ssave_ealready', $from));
45                 }
46
47         if ($in{'action'}) { $action = $in{'action'}; }
48         else {
49                 $in{'err'} =~ /^\d\d\d$/ ||
50                         &error(&text('ssave_ecode', $in{'err'}));
51                 $action = "$in{'err'} $in{'msg'}";
52                 }
53
54         %newa = ( 'from', $from,
55                   'action', $action,
56                   'tag', $in{'tag'},
57                   'cmt', $in{'cmt'} );
58         &can_edit_access(\%newa) ||
59                 &error($text{'ssave_ecannot2'});
60         if ($in{'new'}) { &create_access(\%newa, $afile, $adbm, $adbmtype); }
61         else { &modify_access($a, \%newa, $afile, $adbm, $adbmtype); }
62         $loga = \%newa;
63         }
64 &unlock_file($afile);
65 &webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
66             "access", $loga->{'from'}, $loga);
67 &redirect("list_access.cgi");
68