forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_alias.cgi
executable file
·114 lines (102 loc) · 3.07 KB
/
save_alias.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/local/bin/perl
#
# postfix-module by Guillaume Cottenceau <[email protected]>,
# for webmin by Jamie Cameron
#
# Copyright (c) 2000 by Mandrakesoft
#
# Permission to use, copy, modify, and distribute this software and its
# documentation under the terms of the GNU General Public License is hereby
# granted. No representations are made about the suitability of this software
# for any purpose. It is provided "as is" without express or implied warranty.
# See the GNU General Public License for more details.
#
#
# Save, modify, delete an alias for Postfix
require './postfix-lib.pl';
&ReadParse();
$access{'aliases'} || &error($text{'aliases_ecannot'});
&error_setup($text{'alias_save_err'});
# Get the alias (if editing or deleting)
@afiles = &get_aliases_files(&get_current_value("alias_maps"));
@aliases = &list_postfix_aliases();
if (!$in{'new'}) {
$a = $aliases[$in{'num'}];
}
&lock_alias_files(\@afiles);
if ($in{'delete'}) {
# delete some alias
&delete_postfix_alias($a);
$loga = $a;
}
else {
# saving or creating .. check inputs
$in{'name'} =~ /^[^:@ ]+$/ ||
&error(&text('asave_eaddr', $in{'name'}));
if ($in{'new'} || uc($a->{'name'}) ne uc($in{'name'})) {
# is this name taken?
for($i=0; $i<@aliases; $i++) {
if (uc($in{'name'}) eq uc($aliases[$i]->{'name'})) {
&error(&text('asave_ealready', $in{'name'}));
}
}
}
for($i=0; defined($t = $in{"type_$i"}); $i++) {
$v = $in{"val_$i"};
$v =~ s/^\s+//;
$v =~ s/\s+$//;
if ($t == 1 && $v !~ /^(\S+)$/) {
&error(&text('asave_etype1', $v));
}
elsif ($t == 3 && $v !~ /^\/(\S+)$/) {
&error(&text('asave_etype3', $v));
}
elsif ($t == 4) {
$v =~ /^(\S+)/ || &error($text{'asave_etype4none'});
-x $1 || &error(&text('asave_etype4', $1));
}
elsif ($t == 5 && $v !~ /^\/(\S+)$/) {
&error(&text('asave_etype5', $v));
}
elsif ($t == 6 && $v !~ /^\/(\S+)$/) {
&error(&text('asave_etype6', $v));
}
if ($t == 1 || $t == 3) { push(@values, $v); }
elsif ($t == 2) { push(@values, ":include:$v"); }
elsif ($t == 4) { push(@values, "|$v"); }
elsif ($t == 5) {
# Setup autoreply script
push(@values, "|$module_config_directory/autoreply.pl ".
"$v $in{'name'}");
&system_logged("cp autoreply.pl $module_config_directory");
&system_logged("chmod 755 $module_config_directory/config");
}
elsif ($t == 6) {
# Setup filter script
push(@values, "|$module_config_directory/filter.pl ".
"$v $in{'name'}");
&system_logged("cp filter.pl $module_config_directory");
&system_logged("chmod 755 $module_config_directory/config");
}
}
$newa{'name'} = $in{'name'};
$newa{'values'} = \@values;
if (defined($in{'cmt'})) {
$newa{'cmt'} = $in{'cmt'};
}
$newa{'enabled'} = $in{'enabled'};
if ($in{'new'}) {
&create_postfix_alias(\%newa);
}
else {
&modify_postfix_alias($a, \%newa);
}
$loga = \%newa;
}
&unlock_alias_files(\@afiles);
# re-creates aliases database
®enerate_aliases();
&reload_postfix();
&webmin_log($in{'new'} ? 'create' : $in{'delete'} ? 'delete' : 'modify',
'alias', $loga->{'name'}, $loga);
&redirect("aliases.cgi");