Handle hostnames with upper-case letters
[webmin.git] / proftpd / save_aserv.cgi
1 #!/usr/local/bin/perl
2 # save_aserv.cgi
3 # Save anonymous section options
4
5 require './proftpd-lib.pl';
6 &ReadParse();
7 $conf = &get_config();
8 if ($in{'virt'}) {
9         $virt = $conf->[$in{'virt'}];
10         $vconf = $virt->{'members'};
11         }
12 else {
13         $vconf = $conf;
14         }
15 &error_setup($text{'aserv_err'});
16
17 # Validate inputs
18 -d $in{'root'} || $in{'root'} =~ /^~/ || &error($text{'aserv_eroot'});
19 $in{'User_def'} || scalar(getpwnam($in{'User'})) ||
20         &error($text{'aserv_euser'});
21 $in{'Group_def'} || scalar(getgrnam($in{'Group'})) ||
22         &error($text{'aserv_egroup'});
23
24 if ($in{'init'}) {
25         # Create a new <Anonymous> directive
26         $l = $vconf->[@$vconf - 1];
27         &lock_file($l->{'file'});
28         &before_changing();
29         $lref = &read_file_lines($l->{'file'});
30         local @l = ( "<Anonymous $in{'root'}>" );
31         push(@l, "User $in{'User'}") if (!$in{'User_def'});
32         push(@l, "UserAlias anonymous $in{'User'}") if (!$in{'User_def'});
33         push(@l, "Group $in{'Group'}") if (!$in{'Group_def'});
34         push(@l, "</Anonymous>");
35         splice(@$lref, $l->{'eline'}+1, 0, @l);
36         &after_changing();
37         &flush_file_lines();
38         &unlock_file($l->{'file'});
39         &webmin_log("anon", "create", $in{'root'}, \%in);
40         }
41 else {
42         # Update existing directive
43         $anon = &find_directive_struct("Anonymous", $vconf);
44         &lock_file($anon->{'file'});
45         &before_changing();
46         $lref = &read_file_lines($anon->{'file'});
47         $lref->[$anon->{'line'}] = "<Anonymous $in{'root'}>";
48         &save_directive("User", $in{'User_def'} ? [ ] : [ $in{'User'} ],
49                         $anon->{'members'}, $vconf);
50         &save_directive("Group", $in{'Group_def'} ? [ ] : [ $in{'Group'} ],
51                         $anon->{'members'}, $vconf);
52         &after_changing();
53         &flush_file_lines();
54         &unlock_file($anon->{'file'});
55         &webmin_log("anon", "save", $anon->{'value'}, \%in);
56         }
57 &redirect("anon_index.cgi?virt=$in{'virt'}");
58