3 # Creates a new .htaccess file for some directory
5 require './apache-lib.pl';
6 &error_setup($text{'htaccess_err'});
8 $access{'global'} || &error($text{'htaccess_ecannot'});
10 $in{'file'} || &error($text{'htaccess_eempty'});
11 $in{'file'} =~ /^\// && $in{'file'} !~ /\.\./ ||
12 &error($text{'htaccess_eabsolute'});
15 # user entered a directory.. create a file in that directory
16 $accfile = &find_directive("AccessFile", $conf);
17 if (!$accfile) { $accfile = ".htaccess"; }
18 $file = "$in{'file'}/$accfile";
23 &allowed_auth_file($file) ||
24 &error($text{'htaccess_ecreate'});
26 # create the file (if needed), and add to the known list
29 &open_tempfile(HTACCESS, ">$file");
30 &close_tempfile(HTACCESS);
33 $u = &find_directive("User", $conf);
34 if ($u =~ /#(\d+)/) { $u = $1; }
35 elsif (defined($u)) { $u = getpwnam($u); }
37 $g = &find_directive("Group", $conf);
38 if ($g =~ /#(\d+)/) { $g = $1; }
39 elsif (defined($g)) { $g = getgrnam($g); }
41 chown(defined($u) ? $u : $< , defined($g) ? $g : $( , $file);
43 &read_file("$module_config_directory/site", \%site);
44 @ht = split(/\s+/, $site{'htaccess'});
45 $site{'htaccess'} = join(' ', &unique(@ht, $file));
46 &write_file("$module_config_directory/site", \%site);
48 &webmin_log("htaccess", "create", $file);
50 # redirect to editing index
51 &redirect("htaccess_index.cgi?file=".&urlize($file));