3 # Save, create or delete an address mapping
5 require './sendmail-lib.pl';
6 require './virtusers-lib.pl';
8 $access{'vmode'} > 0 || &error($text{'vsave_ecannot'});
9 $conf = &get_sendmailcf();
10 $vfile = &virtusers_file($conf);
12 ($vdbm, $vdbmtype) = &virtusers_dbm($conf);
13 @virts = &list_virtusers($vfile);
14 foreach $vu (@virts) { $already{$vu->{'from'}}++; }
16 $v = $virts[$in{'num'}];
17 &can_edit_virtuser($v) || &error($text{'vsave_ecannot2'});
19 elsif ($access{'vmax'}) {
21 grep { $access{"vedit_".&virt_type($_->{'to'})} } @virts;
22 if ($access{'vmode'} == 2) {
23 @cvirts = grep { $_->{'from'} =~ /$access{'vaddrs'}/ } @cvirts;
25 elsif ($access{'vmode'} == 3) {
26 @cvirts = grep { $_->{'from'} =~ /^$remote_user\@/ } @cvirts;
28 &error(&text('vsave_emax', $access{'vmax'}))
29 if (@cvirts >= $access{'vmax'});
35 &delete_virtuser($v, $vfile, $vdbm, $vdbmtype);
38 # Saving or creating.. check inputs
39 &error_setup($text{'vsave_err'});
40 if ($in{'from_type'} == 0 || !$access{'vcatchall'}) {
41 $in{'from_addr'} =~ /^(\S+)\@(\S+)$/ ||
42 &error(&text('vsave_efrom', $in{'from_addr'}));
43 $from = $in{'from_addr'};
44 if ($already{$from} && ($in{'new'} || $v->{'from'} ne $from)) {
45 &error(&text('vsave_efromdup', $in{'from_addr'}));
49 $in{'from_dom'} =~ /^([^\@ ]+)$/ ||
50 &error(&text('vsave_edom', $in{'from_dom'}));
51 $from = "\@$in{'from_dom'}";
52 if ($already{$from} && ($in{'new'} || $v->{'from'} ne $from)) {
53 &error(&text('vsave_edomdup', $in{'from_dom'}));
56 if ($access{'vmode'} == 2) {
57 $from =~ /$access{'vaddrs'}/ ||
58 &error(&text('vsave_ematch', $access{'vaddrs'}));
60 elsif ($access{'vmode'} == 3) {
61 $from =~ /^$remote_user\@/ || &error($text{'vsave_esame'});
63 if ($in{'to_type'} == 2) {
65 &error($text{'vsave_ecannot3'});
66 $in{'to_addr'} =~ /^([^\s,]+)$/ ||
67 &error(&text('vsave_eaddr', $in{'to_addr'}));
70 elsif ($in{'to_type'} == 1) {
72 &error($text{'vsave_ecannot4'});
73 $in{'to_dom'} =~ /^([^\@ ]+)$/ ||
74 &error(&text('vsave_edom', $in{'to_dom'}));
75 $in{'from_type'} == 1 ||
76 &error($text{'vsave_edomdom'});
77 $to = "\%1\@$in{'to_dom'}";
81 &error($text{'vsave_ecannot5'});
82 $to = "error:$in{'to_code'} $in{'to_error'}";
85 $newv{'from'} = $from;
87 $newv{'cmt'} = $in{'cmt'};
88 if ($in{'new'}) { &create_virtuser(\%newv, $vfile, $vdbm, $vdbmtype); }
89 else { &modify_virtuser($v, \%newv, $vfile, $vdbm, $vdbmtype); }
93 &webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
94 "virtuser", $logv->{'from'}, $logv);
95 &redirect("list_virtusers.cgi");