|
Posted by Stefan Bellon on 02/12/06 23:30
Stefan Bellon wrote:
> What I need to know is basically the information "which user can
> access which file?"
In the meantime I've come up with a solution. Just in case somebody
else needs something similar, here is my PHP code:
<?php
## Read in the .htgroups file and build array of groups of array of
## users.
$tmp=file('.htgroups');
$groups=array();
foreach($tmp as $line)
{
$exploded=explode(": ", $line);
$groups[$exploded[0]] = explode(" ", $exploded[1]);
}
## Read in the .htaccess file looking for group accesses for files.
$tmp=file('.htaccess');
$file="";
$files=array();
foreach($tmp as $line)
{
## htmlentities necessary in order to get at HTML-like tags at all,
## but then they're escaped, so < and > are necessary.
if (ereg("<Files .*>", htmlentities($line)))
{
## We have a file section starting, so remember the file name.
$file=trim(ereg_replace("<Files (.*)>", "\\1",
htmlentities($line)));
}
elseif (($file != "") &&
($file != "index.php") &&
(ereg("AuthName \".*\"", $line)))
{
## Get the authentication name of the file.
$files[$file]=array
('Name' => ereg_replace("AuthName \"(.*)\"", "\\1", $line),
'access' => 0);
}
elseif (($file != "") &&
($file != "index.php") &&
(ereg("Require user .*", $line)))
{
## We have a user permission.
$user=trim(ereg_replace("Require user (.*)", "\\1", $line));
if ($user == $_SERVER['REMOTE_USER'])
{
$files[$file]['access']=1;
}
}
elseif (($file != "") &&
($file != "index.php") &&
(ereg("Require group .*", $line)))
{
## We have a group permission, so get the group.
$group=trim(ereg_replace("Require group (.*)", "\\1", $line));
## Look in the users of the group whether REMOTE_USER is listed.
foreach($groups[$group] as $user)
{
if ($user == $_SERVER['REMOTE_USER'])
{
$files[$file]['access']=1;
break;
}
}
}
}
## Do whatever HTML stuff you want here, and later on:
## Now loop through the file permission data and built HTML code.
foreach($files as $file => $data)
{
if (($data['access'] == 1) && (file_exists($file)))
{
## Do something with $file and/or data['Name']
}
}
## Rest of HTML stuff.
?>
--
Stefan Bellon
[Back to original message]
|