Handle hostnames with upper-case letters
[webmin.git] / sendmail / save_file.cgi
1 #!/usr/local/bin/perl
2 # save_file.cgi
3 # Save a manually edited file
4
5 require './sendmail-lib.pl';
6 &error_setup($text{'file_err'});
7 $access{'manual'} || &error($text{'file_ecannot'});
8 &ReadParseMime();
9 $conf = &get_sendmailcf();
10 if ($in{'mode'} eq 'aliases') {
11         require './aliases-lib.pl';
12         $file = &aliases_file($conf)->[$in{'idx'}];
13         $return = "list_aliases.cgi";
14         $post = "newaliases";
15         $access{'amode'} == 1 && $access{'aedit_1'} && $access{'aedit_2'} &&
16             $access{'aedit_3'} && $access{'aedit_4'} && $access{'aedit_5'} &&
17             $access{'amax'} == 0 && $access{'apath'} eq '/' ||
18             &error($text{'file_ealiases'});
19         $log = "alias";
20         $fmt = "alias";
21         }
22 elsif ($in{'mode'} eq 'virtusers') {
23         require './virtusers-lib.pl';
24         $file = &virtusers_file($conf);
25         ($vdbm, $vdbmtype) = &virtusers_dbm($conf);
26         $return = "list_virtusers.cgi";
27         $post = "$config{'makemap_path'} $vdbmtype $vdbm <$file";
28         $access{'vmode'} == 1 && $access{'vedit_0'} && $access{'vedit_1'} &&
29             $access{'vedit_2'} && $access{'vmax'} == 0 ||
30             &error($text{'file_evirtusers'});
31         $log = "virtuser";
32         $fmt = "tab";
33         }
34 elsif ($in{'mode'} eq 'mailers') {
35         require './mailers-lib.pl';
36         $file = &mailers_file($conf);
37         ($mdbm, $mdbmtype) = &mailers_dbm($conf);
38         $return = "list_mailers.cgi";
39         $post = "$config{'makemap_path'} $mdbmtype $mdbm <$file";
40         $access{'mailers'} || &error($text{'file_emailers'});
41         $log = "mailer";
42         $fmt = "tab";
43         }
44 elsif ($in{'mode'} eq 'generics') {
45         require './generics-lib.pl';
46         $file = &generics_file($conf);
47         ($gdbm, $gdbmtype) = &generics_dbm($conf);
48         $return = "list_generics.cgi";
49         $post = "$config{'makemap_path'} $gdbmtype $gdbm <$file";
50         $access{'omode'} == 1 || &error($text{'file_egenerics'});
51         $log = "generic";
52         $fmt = "tab";
53         }
54 elsif ($in{'mode'} eq 'domains') {
55         require './domain-lib.pl';
56         $file = &domains_file($conf);
57         ($ddbm, $ddbmtype) = &domains_dbm($conf);
58         $return = "list_domains.cgi";
59         $post = "$config{'makemap_path'} $ddbmtype $ddbm <$file";
60         $access{'domains'} || &error($text{'file_edomains'});
61         $log = "domain";
62         $fmt = "tab";
63         }
64 elsif ($in{'mode'} eq 'access') {
65         require './access-lib.pl';
66         $file = &access_file($conf);
67         ($adbm, $adbmtype) = &access_dbm($conf);
68         $return = "list_access.cgi";
69         $post = "$config{'makemap_path'} $adbmtype $adbm <$file";
70         $access{'access'} || &error($text{'file_eaccess'});
71         $log = "access";
72         $fmt = "tab";
73         }
74 else { &error($text{'file_emode'}); }
75
76 # Validate format
77 $in{'text'} =~ s/\r//g;
78 @lines = split(/\n+/, $in{'text'});
79 foreach my $l (@lines) {
80         $l =~ s/#.*$//;
81         next if ($l !~ /\S/);
82         if ($fmt eq "alias") {
83                 $l =~ /^\s*(\S+):\s*(\S.*)$/ ||
84                         &error(&text('file_ealias',
85                                      "<tt>".&html_escape($l)."</tt>"));
86                 }
87         elsif ($fmt eq "tab") {
88                 $l =~ /^\s*(\S+)\s+(\S.*)$/ ||
89                         &error(&text('file_etab',
90                                      "<tt>".&html_escape($l)."</tt>"));
91                 }
92         }
93
94 # Write out the file
95 &open_lock_tempfile(FILE, ">$file");
96 &print_tempfile(FILE, $in{'text'});
97 &close_tempfile(FILE);
98 &webmin_log("manual", $log, $file);
99
100 if (!&rebuild_map_cmd($file)) {
101         &system_logged("$post >/dev/null 2>&1") if ($post);
102         }
103 &redirect($return);
104