include("class.Htgroup.php3"); $htgroup = new Htgroup("/full/path/to/.htgroup");
$htgroup->addGroup("admins"); $htgroup->addUserToGroup("cdi","admins");
if($htgroup->isUserInGroup("cdi","admins")) { echo "User cdi is a member of the admins group\n"; } else { echo "User cdi is not a member of the admins group\n"; }
// Add multiple users to a group $NewUsers = array ("cdi","john","david","susan","tom"); $htgroup->addGroup("users",$NewUsers);
// Remove multiple users from a group $OldUsers = array("snoopy","daffy","bugs","tweety"); $htgroup->deleteUserFromGroup($OldUsers,"toons");
// Remove one user $htgroup->deleteUserFromGroup("dilbert","toons");
if(!$htgroup->isUserInGroup("dilbert","toons")) { echo "Yup - removed.\n"; }
groupname: user user user user groupname: user user user user user
A groupname, terminated by a colon, followed by one or more users seperated by spaces, and line terminated with a carriage return. Group files that do not conform to the httpd spec will cause strange things to happen.
new(),
the Htgroup()
method requires
the full path and filename of the htgroup file to work with. If no groupFile is specified when Htgroup()
is called, you must call the initialize()
method. See WIN32
initialize()
method is only needed if you omit the path
and filename from the new Htgroup()
method. This method does a
quick sanity check on the file to manage, then opens and reads the files
contents into memory.
*Nix
servers.
is_readable(),
is_writeable(),
is_directory(),
is_symlink()
If the first two fail, or the last two succeed, then the file is considered to be tainted and the class will bomb out with a fatal exit. See also ERRORS.
$die
==
1, will exit the program. The contents of the last error()
call can be retrieved from the ERROR
variable. See also DEBUG and ERROR.
addGroup()
will add an empty GroupID to the group file. If the
second argument Users contains data, it will create the new group and
populate it with the user(s)
specified. $Users
can either be a single user name, or an array of users. Returns true on
success, false on failure. Will fail if the GroupID already exists. NOTE: User IDs can not contain whitespace! httpd and Apache delimit users in the group file using
a space character. A user of ``John Doe'' will be considered to be two
users, ``John'' and ``Doe''.
getGroups(),
getUsers()
returns an
array of all users found in the group file. Users that appear in more than
one group will only be listed once in the returned array. The returned
array is similar to getGroups()
in that the keys and values of
the returned array will be set to the corresponding user name. Returns null
on failure.
addUser()
method despite the
massive warning above, hell I'll shoot you myself. Adds a specified user or
array of users to the specified group. If the groupID submitted does not exist, it will automatically create the
new group. This is a convenience. If you don't want it to create the new group, the
make sure to call isGroup()
before calling this method.
Returns true on success, false on failure. Users that already exist in the
specified group will generate a warning (via error()
) but are
not considered fatal. (They just get skipped).
addUserToGroup(),
they just get skipped)
*Nix
stuff.
new()
or initialize().
error().
$FILE
is empty.
new()
or
initialize()
actually exists.
sane()
method fails. Is set to
true if sane()
succeeds or the do_not_blame_cdi()
method is called prior to a sane()
call.
do_not_blame_cdi(),
then this variable is set to
true. It's left as an exercise for the reader to figure out why.
errors()
will generate entries in the
error_log via the error_log()
function. Set this to false to
prevent that. (Usefull if you don't have permission to write to the system
log files)
new()
or initialize()
method
is called, this variable contains the raw data from the group file in the
following format;
$GROUPS[$GroupID] = array ($Users)
If you want to write your own methods to manipulate this array directly, I'll ask again, why are you using this class? :) Oh - and since I don't plan on documenting htWriteFile, guess who gets to figure out how to save the changes made to the GROUPS array? < evil grin >
$htgroup->addGroup("fools"); if(!$htgroup->isGroup("fools")) { echo "Something barfed, $htgroup->ERROR \n"; }
The only error that causes Htgroup to actually exit are fatal file write errors. Fatal file write errors will also be echoed to
STDOUT. IF DEBUG is true, errors will be logged to the system log files via
error_log().
include()
it using the full path.
2. Get a DSL connection...
Changes or modifications must retain these Copyright statements. Changes or modifications must be submitted to the AUTHOR, cdi@thewebmasters.net.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Artistic License for more details. This software is distributed AS-IS.
http://www.thewebmasters.net/php/
Actually, this is the first public release, has not been heavily tested, and should be considered BETA, since I said it was up in the Version section didn't I?