55 return array(
"hta"=>
"Protected folders passwords");
60 'title' => _(
"Protected folders"),
61 'ico' =>
'images/password.png',
62 'link' =>
'hta_list.php',
78 $err->log(
"hta",
"createdir",$dir);
79 $absolute=$bro->convertabsolute($dir,0);
81 $err->raise(
"hta",printf(_(
"The folder '%s' does not exist"),$dir));
84 if (!file_exists($absolute)) {
85 @mkdir($absolute,00777);
87 if (!file_exists(
"$absolute/.htaccess")) {
88 if (!@touch(
"$absolute/.htaccess")) {
89 $err->raise(
"hta",_(
"File already exist"));
92 $file = @fopen(
"$absolute/.htaccess",
"r+");
94 $err->raise(
"hta",_(
"File already exist"));
98 $param=
"AuthUserFile \"$absolute/.htpasswd\"\nAuthName \""._(
"Restricted area").
"\"\nAuthType Basic\nrequire valid-user\n";
99 fwrite($file, $param);
102 if (!file_exists(
"$absolute/.htpasswd")) {
103 if (!touch(
"$absolute/.htpasswd")) {
104 $err->raise(
"hta",_(
"File already exist"));
121 $err->log(
"hta",
"listdir");
123 $absolute=
ALTERNC_HTML.
"/".substr($mem->user[
"login"],0,1).
"/".$mem->user[
"login"];
124 exec(
"find $absolute -name .htpasswd|sort",$sortie);
126 $err->raise(
"hta",_(
"No protected folder"));
129 $pattern=
"/^".preg_quote(
ALTERNC_HTML,
"/").
"\/.\/[^\/]*\/(.*)\/\.htpasswd/";
130 for(
$i=0;
$i<count($sortie);
$i++){
131 preg_match($pattern,$sortie[
$i],$matches);
132 $tmpm=
isset($matches[1])?
'/'.$matches[1]:
'';
146 $err->log(
"hta",
"is_protected",$dir);
147 $absolute=
ALTERNC_HTML.
"/".substr($mem->user[
"login"],0,1).
"/".$mem->user[
"login"].
"/$dir";
149 if (file_exists(
"$absolute/.htpasswd")){
166 $err->log(
"hta",
"get_hta_detail");
167 $absolute=
ALTERNC_HTML.
"/".substr($mem->user[
"login"],0,1).
"/".$mem->user[
"login"].
"/$dir";
168 if (file_exists(
"$absolute/.htaccess")) {
173 $file = @fopen(
"$absolute/.htpasswd",
"r");
180 while (!feof($file)) {
181 $s=fgets($file,1024);
201 $err->log(
"hta",
"deldir",$dir);
202 $dir=$bro->convertabsolute($dir,0);
204 $err->raise(
"hta",printf((
"The folder '%s' does not exist"),$dir));
207 if (!@unlink(
"$dir/.htaccess")) {
208 $err->raise(
"hta",printf(_(
"I cannot delete the file '%s/.htaccess'"),$dir));
211 if (!@unlink(
"$dir/.htpasswd")) {
212 $err->raise(
"hta",printf(_(
"I cannot delete the file '%s/.htpasswd'"),$dir));
228 global
$err, $bro, $admin;
229 $err->log(
"hta",
"add_user",
$user.
"/".$dir);
231 $err->raise(
'hta',_(
"Please enter a user"));
235 $err->raise(
'hta',_(
"Please enter a password"));
238 $absolute=$bro->convertabsolute($dir,0);
239 if (!file_exists($absolute)) {
240 $err->raise(
"hta",printf((
"The folder '%s' does not exist"),$dir));
245 if (is_callable(array($admin,
"checkPolicy"))) {
251 $file = @fopen(
"$absolute/.htpasswd",
"a+");
253 $err->raise(
"hta",_(
"File already exist"));
257 while (!feof($file)) {
258 $s=fgets($file,1024);
261 $err->raise(
"hta",_(
"The user '%s' already exist for this folder"),
$user);
265 fseek($file,SEEK_END);
266 if ( empty(
$t[1]) || substr(
$t[1],-1)!=
"\n") {
273 $err->raise(
"hta",_(
"Please enter a valid username"));
288 $err->log(
"hta",
"del_user",$lst.
"/".$dir);
289 $absolute=$bro->convertabsolute($dir,0);
290 if (!file_exists($absolute)) {
291 $err->raise(
"hta",printf(_(
"The folder '%s' does not exist"),$dir));
294 touch(
"$absolute/.htpasswd.new");
295 $file = fopen(
"$absolute/.htpasswd",
"r");
296 $newf = fopen(
"$absolute/.htpasswd.new",
"a");
297 if (!$file || !$newf) {
298 $err->raise(
"hta",_(
"File already exist"));
303 while (!feof($file)) {
304 $s=fgets($file,1024);
306 if (!in_array(
$t[0],$lst) && (
$t[0]!=
"\n")) {
313 unlink(
"$absolute/.htpasswd");
314 rename(
"$absolute/.htpasswd.new",
"$absolute/.htpasswd");
328 global $bro,
$err,$admin;
329 $err->log(
"hta",
"change_pass",
$user.
"/".$dir);
330 $absolute=$bro->convertabsolute($dir,0);
331 if (!file_exists($absolute)) {
332 $err->raise(
"hta",printf(_(
"The folder '%s' does not exist"),$dir));
337 if (is_callable(array($admin,
"checkPolicy"))) {
338 if (!$admin->checkPolicy(
"hta",
$user,$newpass)) {
343 touch(
"$absolute/.htpasswd.new");
344 $file = fopen(
"$absolute/.htpasswd",
"r");
345 $newf = fopen(
"$absolute/.htpasswd.new",
"a");
346 if (!$file || !$newf) {
347 $err->raise(
"hta",_(
"File already exist"));
350 while (!feof($file)) {
351 $s=fgets($file,1024);
357 fwrite($newf,
"$user:".
_md5cr($newpass).
"\n");
360 unlink(
"$absolute/.htpasswd");
361 rename(
"$absolute/.htpasswd.new",
"$absolute/.htpasswd");
375 $err->log(
"hta",
"_reading_htaccess",$absolute);
376 $file = fopen(
"$absolute/.htaccess",
"r+");
377 $lignes=array(1,1,1);
382 while (!feof($file) && !$errr) {
383 $s=fgets($file,1024);
384 if (substr($s,0,12)!=
"RewriteCond " && substr($s,0,14)!=
"ErrorDocument " && substr($s,0,12)!=
"RewriteRule " && substr($s,0,14)!=
"RewriteEngine " && trim($s)!=
"") {
387 if (strtolower(trim($s))==strtolower(
"authuserfile $absolute/.htpasswd")) {
391 if (strtolower(trim($s))==
"require valid-user") {
395 if (strtolower(trim($s))==
"authtype basic") {
401 if ($errr || in_array(0,$lignes)) {
402 $err->raise(
"hta",_(
"An incompatible .htaccess file exists in this folder"));