3 # Save, create or delete an access rule
5 require './sendmail-lib.pl';
6 require './access-lib.pl';
8 $access{'access'} || &error($text{'access_ecannot'});
9 $conf = &get_sendmailcf();
10 $afile = &access_file($conf);
12 ($adbm, $adbmtype) = &access_dbm($conf);
13 @accs = &list_access($afile);
15 $a = $accs[$in{'num'}];
16 &can_edit_access($a) ||
17 &error($text{'sform_ecannot'});
23 &delete_access($a, $afile, $adbm, $adbmtype);
26 # Saving or creating.. check inputs
27 $whatfailed = "Failed to save spam control rule";
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);
39 if ($in{'new'} || uc($from) ne uc($a->{'from'}) ||
40 $in{'tag'} ne $a->{'tag'}) {
42 local ($same) = grep { uc($_->{'from'}) eq uc($from) &&
43 $_->{'tag'} eq $in{'tag'} } @accs;
44 $same && &error(&text('ssave_ealready', $from));
47 if ($in{'action'}) { $action = $in{'action'}; }
49 $in{'err'} =~ /^\d\d\d$/ ||
50 &error(&text('ssave_ecode', $in{'err'}));
51 $action = "$in{'err'} $in{'msg'}";
54 %newa = ( 'from', $from,
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); }
65 &webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
66 "access", $loga->{'from'}, $loga);
67 &redirect("list_access.cgi");