Handle hostnames with upper-case letters
[webmin.git] / wuftpd / save_acl.cgi
1 #!/usr/local/bin/perl
2 # save_acl.cgi
3 # Save access control options
4
5 require './wuftpd-lib.pl';
6 &error_setup($text{'acl_err'});
7 &ReadParse();
8 &lock_file($config{'ftpaccess'});
9 $conf = &get_ftpaccess();
10
11 # Save deny directives
12 for($i=0; defined($daddrs = $in{"daddrs_$i"}); $i++) {
13         $dmsg = $in{"dmsg_$i"};
14         next if (!$daddrs);
15         $daddrs =~ /^\S+$/ || &error(&text('acl_edaddr', $daddrs));
16         $daddrs !~ /^\|(\S+)$/ || -r $1 || &error(&text('acl_edfile', $1));
17         $dmsg =~ /^\S+$/ && -r $dmsg || &error(&text('acl_edmsg', $dmsg));
18         push(@deny, { 'name' => 'deny',
19                       'values' => [ $daddrs, $dmsg ] } );
20         }
21 &save_directive($conf, 'deny', \@deny);
22
23 # Save limit directives
24 for($i=0; defined($lclass = $in{"lclass_$i"}); $i++) {
25         next if (!$lclass);
26         $in{"ln_def_$i"} || $in{"ln_$i"} =~ /^\d+$/ ||
27                 &error(&text('acl_eln', $in{"ln_$i"}));
28         $in{"ltimes_def_$i"} || $in{"ltimes_$i"} =~ /^\S+$/ ||
29                 &error(&text('acl_etimes', $in{"ltimes_$i"}));
30         -r $in{"lmsg_$i"} || &error(&text('acl_elmsg', $in{"lmsg_$i"}));
31         push(@limit,
32              { 'name' => 'limit',
33                'values' => [ $lclass,
34                              $in{"ln_def_$i"} ? -1 : $in{"ln_$i"},
35                              $in{"ltimes_def_$i"} ? 'Any' : $in{"ltimes_$i"},
36                              $in{"lmsg_$i"} ] } );
37         }
38 &save_directive($conf, 'limit', \@limit);
39
40 # Save file-limt and data-limit directives
41 for($i=0; defined($fblimit = $in{"fblimit_$i"}); $i++) {
42         next if (!$fblimit);
43         $in{"fbcount_$i"} =~ /^\d+$/ ||
44                 &error(&text('acl_efbcount', $in{"fbcount_$i"}));
45         local @v = $in{"fbraw_$i"} ? ('raw') : ();
46         push(@v, $in{"fbinout_$i"}, $in{"fbcount_$i"}, $in{"fbclass_$i"});
47         if ($fblimit eq 'file-limit') {
48                 push(@file_limit, { 'name' => 'file-limit',
49                                     'values' => \@v } );
50                 }
51         else {
52                 push(@data_limit, { 'name' => 'data-limit',
53                                     'values' => \@v } );
54                 }
55         }
56 &save_directive($conf, 'file-limit', \@file_limit);
57 &save_directive($conf, 'data-limit', \@data_limit);
58
59 # Save noretrieve directives
60 @class = &find_value("class", $conf);
61 for($i=0; defined($nfiles = $in{"nfiles_$i"}); $i++) {
62         next if (!$nfiles);
63         local @v = $in{"nrel_$i"} ? ('relative') : ();
64         local @c = split(/\0/, $in{"nclass_$i"});
65         push(@v, map { "class=$_" } @c) if (@c != @class);
66         push(@v, split(/\s+/, $nfiles));
67         push(@noretrieve, { 'name' => 'noretrieve',
68                             'values' => \@v } );
69         }
70 &save_directive($conf, 'noretrieve', \@noretrieve);
71
72 # Save allow-retrieve directives
73 for($i=0; defined($afiles = $in{"afiles_$i"}); $i++) {
74         next if (!$afiles);
75         local @v = $in{"arel_$i"} ? ('relative') : ();
76         local @c = split(/\0/, $in{"aclass_$i"});
77         push(@v, map { "class=$_" } @c) if (@c != @class);
78         push(@v, split(/\s+/, $afiles));
79         push(@allow_retrieve, { 'name' => 'allow-retrieve',
80                                 'values' => \@v } );
81         }
82 &save_directive($conf, 'allow-retrieve', \@allow_retrieve);
83
84 # Save limit-time directives
85 if (!$in{'alimit_def'}) {
86         $alimit = $in{'alimit'};
87         $alimit =~ /^\d+$/ || &error(&text('acl_elimit', $alimit));
88         }
89 if (!$in{'glimit_def'}) {
90         $glimit = $in{'glimit'};
91         $glimit =~ /^\d+$/ || &error(&text('acl_elimit', $glimit));
92         }
93 if ($alimit && $alimit eq $glimit) {
94         @limit_time = ( { 'name' => 'limit-time',
95                           'values' => [ '*', $alimit ] } );
96         }
97 else {
98         if ($alimit) {
99                 push(@limit_time, ( { 'name' => 'limit-time',
100                                   'values' => [ 'anonymous', $alimit ] } ) );
101                 }
102         if ($glimit) {
103                 push(@limit_time, ( { 'name' => 'limit-time',
104                                   'values' => [ 'guest', $glimit ] } ));
105                 }
106         }
107 &save_directive($conf, 'limit-time', \@limit_time);
108
109 # Save loginfails and private directives
110 if ($in{'fails_def'}) {
111         &save_directive($conf, 'loginfails', [ ]);
112         }
113 else {
114         $in{'fails'} =~ /^\d+$/ || &error(&text('acl_efails', $in{'fails'}));
115         &save_directive($conf, 'loginfails',
116                         [ { 'name' => 'loginfails',
117                             'values' => [ $in{'fails'} ] } ] );
118         }
119 &save_directive($conf, 'private', 
120                         [ { 'name' => 'private',
121                             'values' => [ $in{'private'} ] } ] );
122
123 &flush_file_lines();
124 &unlock_file($config{'ftpaccess'});
125 &webmin_log("acl", undef, undef, \%in);
126 &redirect("");
127