WE::Util::Htaccess - create apache .htaccess files
use WE::Util::Htaccess; WE::Util::Htaccess::create("/var/www/htdocs/.htaccess", $obj_db -authname => "sample", -authuserfile => "/var/www/.htpasswd", -authgroupfile => "/var/www/.htgroup", -inherit => 1, -add => "ErrorDocument 401 /index.html", );
This module is used to create Apache .htaccess files from a WE::DB::Obj database. All objects in the database are traversed (or restricted by a filter) and if the object contains a WWWAuth attribute, an entry for the .htaccess file is created.
.htaccess
WE::DB::Obj
WWWAuth
The WWWAuth attribute should be a string with the following syntax:
"[user=|group=]id1,[user=|group=]id2..."
If netither "user=" nor "group=" is specified, then a user id is assumed. Example:
"bla,group=foo,user=bar"
means: the users bla and bar and the group foo.
bla
bar
foo
The files .htpasswd, .htgroup and .htaccess are always protected from WWW access, so you can use these names for the user/group files, if you have to store these files in a WWW readable directory.
.htpasswd
.htgroup
The create function expects the following arguments:
create
The name of the authorization realm. By default it is "WE Authentication".
The type of user authentication. By default it is "Basic".
The path to the .htpasswd file (see WE::Util::Htpasswd). This is required unless set by an entry in the global httpd.conf.
httpd.conf
The path to the groups file (see WE::Util::Htgroup). This is required if there are any group authentifications in the object database and no entry from the global httpd.conf can be used.
If set to true (default) then inherit folder rights to their children and subfolders.
A filter callback for restricting an object or sub-tree. The callback will get the current object as parameter and should return a boolean value. If the returned value is false, then the object is not processed; if it is a folder then the descendants of the folder are not processed either.
A $string to be added to the .htaccess file. An example would be to add an ErrorDocument directive (see http://httpd.apache.org/docs/mod/core.html#errordocument).
$string
ErrorDocument
Like -add, but read the contents from the named file. It is possible to use -add and -addfile together.
-add
-addfile
Alternative restriction scheme. If set, then no access to the WE::DB::Obj database is done. -inherit and -filter are ignored. The $restrict string should be of the form:
-inherit
-filter
$restrict
type1 value1 value2 value3; type2 value4 value5 ...
where type is either group or user and value a group or user name.
group
user
This should be a code reference which receives the object id as parameter and returns a list of alias names for this page (excluding the supplied id).
Please check the setting of AllowOverride in the global httpd.conf. This directive should be set to All or at least AuthConfig Limit for the web.editor-controlled directories. See also the AllowOverride entry in the Apache documentation: http://httpd.apache.org/docs/mod/core.html#allowoverride.
AllowOverride
All
AuthConfig Limit
For a perl-based httpd.conf use something like:
$Directory{$document_root}{AllowOverride} = "All";
Slaven Rezic - slaven@rezic.de
WE::Util::Htgroup, WE::Util::Htpasswd, WE::DB::Obj, httpd(8).
To install WE::DB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WE::DB
CPAN shell
perl -MCPAN -e shell install WE::DB
For more information on module installation, please visit the detailed CPAN module installation guide.