Handle hostnames with upper-case letters
[webmin.git] / apache / find_htaccess.cgi
1 #!/usr/local/bin/perl
2 # find_htaccess.cgi
3 # Finds all per-directory options files under the all the document roots
4
5 require './apache-lib.pl';
6 &ReadParse();
7 $access{'global'} || &error($text{'htaccess_ecannot'});
8
9 $in{'from'}=1 if ($access{'dir'} ne '/');
10 if ($in{'from'} == 1 && !(-d $in{'dir'})) {
11         &error(&text('htaccess_edir', $in{'dir'}));
12         }
13 &read_file("$module_config_directory/site", \%site);
14 foreach $f (split(/\s+/, $site{'htaccess'})) {
15         if (-r $f) { push(@rv, $f); }
16         }
17
18 # Find the default document root and access file
19 $conf = &get_config();
20 $def_htaccess = &find_directive("AccessFileName", $conf);
21 if (!$def_htaccess) { $def_htaccess = ".htaccess"; }
22 $def_root = &find_directive("DocumentRoot", $conf);
23 if (!$def_root) { $def_root = "/"; }
24
25 # find virtual server doc roots and access files
26 push(@dirs, $def_root); push(@files, $def_htaccess);
27 foreach $v (&find_directive_struct("VirtualHost", $conf)) {
28         $root = &find_directive("DocumentRoot", $v->{'members'});
29         push(@dirs, $root ? $root : $def_root);
30         $htaccess = &find_directive("AccessFileName", $v->{'members'});
31         push(@files, $htaccess ? $htaccess : $def_htaccess);
32         }
33
34 if ($in{'from'} == 0) {
35         # search under all directories
36         for($i=0; $i<@dirs; $i++) {
37                 open(FIND, "find $dirs[$i] -name $files[$i] -print |");
38                 while(<FIND>) {
39                         s/\r|\n//g;
40                         push(@rv, $_);
41                         }
42                 close(FIND);
43                 }
44         }
45 else {
46         # search under the given directory only
47         foreach $f (&unique(@files)) { push(@args, "-name $f"); }
48         $args = join(' -o ', @args);
49         open(FIND, "find ".quotemeta($in{'dir'})." $args -print |");
50         while(<FIND>) {
51                 s/\r|\n//g;
52                 push(@rv, $_);
53                 }
54         close(FIND);
55         }
56
57 # save results
58 $site{'htaccess'} = join(' ', &unique(@rv));
59 &write_file("$module_config_directory/site", \%site);
60 &redirect("htaccess.cgi");
61