The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WE::Util::Htaccess - create apache .htaccess files

SYNOPSIS

    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",
                              );

DESCRIPTION

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.

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.

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.

The create function expects the following arguments:

-authname => $name

The name of the authorization realm. By default it is "WE Authentication".

-authtype => $type

The type of user authentication. By default it is "Basic".

-authuserfile => $file

The path to the .htpasswd file (see WE::Util::Htpasswd). This is required unless set by an entry in the global httpd.conf.

-authgroupfile => $file

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.

-inherit => $bool

If set to true (default) then inherit folder rights to their children and subfolders.

-filter => sub { my($obj) = @_; ... }

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.

-add => $string

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).

-addfile => $file

Like -add, but read the contents from the named file. It is possible to use -add and -addfile together.

-restrict => $restrict

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:

    type1 value1 value2 value3; type2 value4 value5 ...

where type is either group or user and value a group or user name.

-getaliases => sub { my($id) = @_; ... }

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).

NOTES

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.

For a perl-based httpd.conf use something like:

  $Directory{$document_root}{AllowOverride} = "All";

AUTHOR

Slaven Rezic - slaven@rezic.de

SEE ALSO

WE::Util::Htgroup, WE::Util::Htpasswd, WE::DB::Obj, httpd(8).