Handle hostnames with upper-case letters
[webmin.git] / proftpd / manual_save.cgi
1 #!/usr/local/bin/perl
2 # manual_save.cgi
3 # Save manually entered directives
4
5 require './proftpd-lib.pl';
6 &ReadParseMime();
7 if ($in{'global'}) {
8         $conf = &get_config();
9         $global = &find_directive_struct("Global", $conf);
10         $conf = $global->{'members'};
11         if (defined($in{'limit'})) {
12                 # limit within the global section
13                 if ($in{'idx'}) {
14                         $d = $conf->[$in{'idx'}];
15                         $l = $d->{'members'}->[$in{'limit'}];
16                         }
17                 else {
18                         $l = $conf->[$in{'limit'}];
19                         }
20                 $file = $l->{'file'};
21                 $return = "limit_index.cgi";
22                 $start = $l->{'line'}+1; $end = $l->{'eline'}-1;
23                 }
24         else {
25                 # directory in the global section
26                 $d = $conf->[$in{'idx'}];
27                 $file = $d->{'file'};
28                 $return = "dir_index.cgi";
29                 $start = $d->{'line'}+1; $end = $d->{'eline'}-1;
30                 $logtype = 'dir';
31                 $logname = $d->{'value'};
32                 }
33         }
34 elsif (defined($in{'virt'})) {
35         if (defined($in{'limit'})) {
36                 # limit, maybe within a directory
37                 ($conf, $v) = &get_virtual_config($in{'virt'});
38                 if ($in{'anon'}) {
39                         $anon = &find_directive_struct("Anonymous", $conf);
40                         $conf = $anon->{'members'};
41                         }
42                 if ($in{'idx'} ne '') {
43                         $conf = $conf->[$in{'idx'}]->{'members'};
44                         }
45                 $l = $conf->[$in{'limit'}];
46                 $file = $l->{'file'};
47                 $return = "limit_index.cgi";
48                 $start = $l->{'line'}+1; $end = $l->{'eline'}-1;
49                 $logtype = 'limit';
50                 $logname = $l->{'value'};
51                 }
52         elsif (defined($in{'idx'})) {
53                 # directory within virtual server
54                 ($vconf, $v) = &get_virtual_config($in{'virt'});
55                 if ($in{'anon'}) {
56                         $anon = &find_directive_struct("Anonymous", $vconf);
57                         $vconf = $anon->{'members'};
58                         }
59                 $d = $vconf->[$in{'idx'}];
60                 $file = $d->{'file'};
61                 $return = "dir_index.cgi";
62                 $start = $d->{'line'}+1; $end = $d->{'eline'}-1;
63                 $logtype = 'dir';
64                 $logname = "$v->{'value'}:$d->{'words'}->[0]";
65                 }
66         else {
67                 # virtual server
68                 ($conf, $v) = &get_virtual_config($in{'virt'});
69                 $return = "virt_index.cgi";
70                 $file = $v->{'file'};
71                 $start = $v->{'line'}+1; $end = $v->{'eline'}-1;
72                 $logtype = 'virt'; $logname = $v->{'words'}->[0];
73                 }
74         }
75 else {
76         if (defined($in{'limit'})) {
77                 # files within .htaccess file
78                 $hconf = &get_ftpaccess_config($in{'file'});
79                 $l = $hconf->[$in{'limit'}];
80                 $file = $in{'file'};
81                 $return = "limit_index.cgi";
82                 $start = $l->{'line'}+1; $end = $l->{'eline'}-1;
83                 $logtype = 'limit';
84                 $logname = $l->{'value'};
85                 }
86         else {
87                 # .htaccess file
88                 $file = $in{'file'};
89                 $return = "ftpaccess_index.cgi";
90                 $logtype = 'ftpaccess'; $logname = $in{'file'};
91                 }
92         }
93
94 &lock_file($file);
95 &lock_file($file);
96 $temp = &transname();
97 system("cp ".quotemeta($file)." $temp");
98 $in{'directives'} =~ s/\r//g;
99 $in{'directives'} =~ s/\s+$//;
100 @dirs = split(/\n/, $in{'directives'});
101 $lref = &read_file_lines($file);
102 if (!defined($start)) {
103         $start = 0;
104         $end = @$lref - 1;
105         }
106 splice(@$lref, $start, $end-$start+1, @dirs);
107 &flush_file_lines();
108 if ($config{'test_manual'}) {
109         $err = &test_config();
110         if ($err) {
111                 system("mv $temp ".quotemeta($file));
112                 &error(&text('manual_etest', "<pre>$err</pre>"));
113                 }
114         }
115 unlink($temp);
116 &unlock_file($file);
117 &webmin_log($logtype, "manual", $logname, \%in);
118
119 foreach $h ('virt', 'idx', 'file', 'limit', 'anon', 'global') {
120         push(@args, "$h=$in{$h}") if (defined($in{$h}));
121         }
122 &redirect("$return?".join("&", @args));
123