classe hta & fichiers section admin associés

This commit is contained in:
quenenni 2017-08-16 19:34:32 +02:00
parent 6f30c8bac4
commit 991b4b48e3
11 changed files with 117 additions and 131 deletions

View File

@ -30,10 +30,12 @@
require_once("../class/config.php"); require_once("../class/config.php");
include_once("head.php"); include_once("head.php");
$fields = array ( if (!isset($is_include)) {
"dir" => array ("request", "string", ""), $fields = array (
); "dir" => array ("request", "string", ""),
getFields($fields); );
getFields($fields);
}
?> ?>
<h3><?php __("Protect a folder"); ?></h3> <h3><?php __("Protect a folder"); ?></h3>
@ -43,11 +45,8 @@ getFields($fields);
<?php __("Enter the name of the folder you want to protect. It must already exists."); ?> <?php __("Enter the name of the folder you want to protect. It must already exists."); ?>
</p> </p>
<?php <?php
if (isset($error) && $error) { echo $msg->msg_html_all();
echo "<p class=\"alert alert-danger\">$error</p>"; ?>
include_once("foot.php");
exit;
} ?>
<form method="post" action="hta_doadd.php" name="main" id="main"> <form method="post" action="hta_doadd.php" name="main" id="main">
<?php csrf_get(); ?> <?php csrf_get(); ?>

View File

@ -39,9 +39,10 @@ getFields($fields);
?> ?>
<h3><?php printf(_("Adding a username in %s"),$dir); ?></h3> <h3><?php printf(_("Adding a username in %s"),$dir); ?></h3>
<?php <?php
if (isset($error) && $error) { echo $msg->msg_html_all();
echo "<p class=\"alert alert-danger\">$error</p>";
} $c=$admin->listPasswordPolicies();
$passwd_classcount = $c['hta']['classcount'];
?> ?>
<form method="post" action="hta_doadduser.php" name="main" id="main" autocomplete="off"> <form method="post" action="hta_doadduser.php" name="main" id="main" autocomplete="off">
@ -61,7 +62,7 @@ getFields($fields);
</tr> </tr>
<tr> <tr>
<th><label for="password"><?php __("Password"); ?></label></th> <th><label for="password"><?php __("Password"); ?></label></th>
<td><input type="password" class="int" name="password" autocomplete="off" id="password" value="" size="20" maxlength="64" /><?php display_div_generate_password(DEFAULT_PASS_SIZE,"#password","#passwordconf"); ?></td> <td><input type="password" class="int" name="password" autocomplete="off" id="password" value="" size="20" maxlength="64" /><?php display_div_generate_password(DEFAULT_PASS_SIZE,"#password","#passwordconf",$passwd_classcount); ?></td>
</tr> </tr>
<tr> <tr>
<th><label for="passwordconf"><?php __("Confirm password"); ?></label></th> <th><label for="passwordconf"><?php __("Confirm password"); ?></label></th>

View File

@ -29,18 +29,14 @@
*/ */
require_once("../class/config.php"); require_once("../class/config.php");
$error="";
// On parcours les POST_VARS et on repere les del_. // On parcours les POST_VARS et on repere les del_.
reset($_POST); reset($_POST);
while (list($key,$val)=each($_POST)) { while (list($key,$val)=each($_POST)) {
if (substr($key,0,4)=="del_") { if (substr($key,0,4)=="del_") {
// Effacement du dossier $val // Effacement du dossier $val
// $r=$hta->DelDir($val);
$return = $hta->DelDir($val); $return = $hta->DelDir($val);
if (!$return) { if ($return) {
$error.= $err->errstr()."<br />"; $msg->raise("Ok", "hta",_("The protected folder %s has been successfully unprotected"),$val);
} else {
$error.= sprintf(_("The protected folder %s has been successfully unprotected"),$val)."<br />";
} }
} }
} }

View File

@ -36,18 +36,13 @@ $fields = array (
getFields($fields); getFields($fields);
if(empty($dir)) { if(empty($dir)) {
$error=_("No directory specified"); $msg->raise("Error", "hta", _("No directory specified"));
include("hta_list.php"); include("hta_list.php");
exit(); } else if(!$hta->CreateDir($dir)) {
} $is_include=true;
if(!$hta->CreateDir($dir)) {
$error=$err->errstr();
include("hta_add.php"); include("hta_add.php");
exit(); } else {
$msg->raise("Ok", "hta", _("Folder %s is protected"), $dir); // à traduire
include("hta_list.php");
} }
include("hta_list.php");
exit();
?> ?>

View File

@ -38,15 +38,15 @@ getFields($fields);
if ($password != $passwordconf) { if ($password != $passwordconf) {
$error = _("Passwords do not match"); $msg->raise("Error", "hta", _("Passwords do not match"));
include("hta_adduser.php"); include("hta_adduser.php");
exit(); exit();
} }
if (!$hta->add_user($user, $password, $dir)) { if (!$hta->add_user($user, $password, $dir)) {
$error=$err->errstr();
include ("hta_adduser.php"); include ("hta_adduser.php");
} else { } else {
$msg->raise("Ok", "hta", _("The user %s was added to th protected folder %s"), array($user, $dir)); // à traduire
include ("hta_edit.php"); include ("hta_edit.php");
} }
?> ?>

View File

@ -38,10 +38,13 @@ getFields($fields);
if (!empty($confirm_del)) { if (!empty($confirm_del)) {
reset($d); reset($d);
if (!$hta->del_user($d,$dir)) { if ($hta->del_user($d,$dir)) {
$error=$err->errstr(); foreach ($d as $v) {
$msg->raise("Ok", "hta", _("The user '%s' was successfully deleted"), $v); // à traduire
}
} }
header ('Location: /hta_edit.php?dir='.urlencode($dir)); $is_include=true;
include_once("hta_edit.php");
exit(); exit();
} }
include_once('head.php'); include_once('head.php');
@ -52,7 +55,7 @@ include_once('head.php');
<?php __("Do you really want to delete those users ?");?> <?php __("Do you really want to delete those users ?");?>
<ul> <ul>
<?php foreach($d as $t) { <?php foreach($d as $t) {
echo "<li>".ehe($t,false)."</li>\n"; echo "<li><b>".ehe($t,false)."</b></li>\n";
} ?> } ?>
</ul> </ul>

View File

@ -39,26 +39,16 @@ $fields = array (
getFields($fields); getFields($fields);
if ($newpass != $newpassconf) { if ($newpass != $newpassconf) {
$error = _("Passwords do not match"); $msg->raise("Error", "hta", _("Passwords do not match"));
include("hta_edituser.php"); include("hta_edituser.php");
exit(); exit();
} }
if (!$hta->change_pass($user,$newpass,$dir)) { if ($hta->change_pass($user,$newpass,$dir)) {
$error=$err->errstr(); $msg->raise("Ok", "hta", _("The password of the user %s has been successfully changed"), $user);
$is_include=true;
include_once("hta_edit.php");
} else {
include("hta_edituser.php");
} }
?> ?>
<h3><?php printf(_("Change the user %s in the protected folder %s"),$user,$dir); ?></h3>
<hr id="topbar"/>
<br />
<?php
if (isset($error) && $error) {
echo "<p class=\"alert alert-danger\">$error</p>";
}
else {
echo "<p>".sprintf(_("The password of the user %s has been successfully changed"),$user)."</p>";
}
echo "<p><span class=\"ina\"><a href=\"hta_edit.php?dir=$dir\">"._("Click here to continue")."</a></span></p>";
?>
<?php include_once("foot.php"); ?>

View File

@ -30,10 +30,12 @@
require_once("../class/config.php"); require_once("../class/config.php");
include_once("head.php"); include_once("head.php");
$fields = array ( if (!isset($is_include)) {
$fields = array (
"dir" => array ("request", "string", ""), "dir" => array ("request", "string", ""),
); );
getFields($fields); getFields($fields);
}
if (!$dir) { if (!$dir) {
echo "<p class=\"alert alert-warning\">"._("No folder selected!")."</p>"; echo "<p class=\"alert alert-warning\">"._("No folder selected!")."</p>";
@ -41,20 +43,22 @@ if (!$dir) {
die(); die();
} else { } else {
$r=$hta->get_hta_detail($dir); $r=$hta->get_hta_detail($dir);
if (!$r) {
$error=$err->errstr();
}
} // if !$dir } // if !$dir
$c=$admin->listPasswordPolicies();
$passwd_classcount = $c['hta']['classcount'];
?> ?>
<h3><?php printf(_("List of authorized user in folder %s"),$dir); ?></h3> <h3><?php printf(_("List of authorized user in folder %s"),$dir); ?></h3>
<hr id="topbar"/> <hr id="topbar"/>
<br /> <br />
<?php <?php
if (!count($r)) { if (!count($r)) {
echo "<p class=\"alert alert-warning\">".sprintf(_("No authorized user in %s"),$dir)."</p>"; $msg->raise("Info", "hta", _("No authorized user in %s"),$dir);
echo $msg->msg_html_all();
} else { } else {
reset($r); reset($r);
echo $msg->msg_html_all();
?> ?>
<form method="post" action="hta_dodeluser.php"> <form method="post" action="hta_dodeluser.php">
<?php csrf_get(); ?> <?php csrf_get(); ?>
@ -108,7 +112,7 @@ for($i=0;$i<count($r);$i++){ ?>
</tr> </tr>
<tr> <tr>
<th><label for="password"><?php __("Password"); ?></label></th> <th><label for="password"><?php __("Password"); ?></label></th>
<td><input type="password" class="int" name="password" autocomplete="off" id="password" value="" size="20" maxlength="64" /><?php display_div_generate_password(DEFAULT_PASS_SIZE,"#password","#passwordconf"); ?></td> <td><input type="password" class="int" name="password" autocomplete="off" id="password" value="" size="20" maxlength="64" /><?php display_div_generate_password(DEFAULT_PASS_SIZE,"#password","#passwordconf",$passwd_classcount); ?></td>
</tr> </tr>
<tr> <tr>
<th><label for="passwordconf"><?php __("Confirm password"); ?></label></th> <th><label for="passwordconf"><?php __("Confirm password"); ?></label></th>

View File

@ -36,12 +36,17 @@ $fields = array (
); );
getFields($fields); getFields($fields);
$c=$admin->listPasswordPolicies();
$passwd_classcount = $c['hta']['classcount'];
?> ?>
<h3><?php printf(_("Editing user %s in the protected folder %s"),$user,$dir); ?></h3> <h3><?php printf(_("Editing user %s in the protected folder %s"),$user,$dir); ?></h3>
<hr id="topbar"/> <hr id="topbar"/>
<br /> <br />
<?php if (!empty($error) ) { echo "<p class=\"alert alert-danger\">$error</p>"; } ?> <?php
echo $msg->msg_html_all();
?>
<form method="post" action="hta_doedituser.php" name="main" id="main" autocomplete="off"> <form method="post" action="hta_doedituser.php" name="main" id="main" autocomplete="off">
<?php csrf_get(); ?> <?php csrf_get(); ?>
@ -63,7 +68,7 @@ getFields($fields);
</tr> </tr>
<tr> <tr>
<th><label for="newpass"><?php __("New password"); ?></label></th> <th><label for="newpass"><?php __("New password"); ?></label></th>
<td><input type="password" class="int" name="newpass" autocomplete="off" id="newpass" value="" size="20" maxlength="64" /><?php display_div_generate_password(DEFAULT_PASS_SIZE,"#newpass","#newpassconf"); ?></td> <td><input type="password" class="int" name="newpass" autocomplete="off" id="newpass" value="" size="20" maxlength="64" /><?php display_div_generate_password(DEFAULT_PASS_SIZE,"#newpass","#newpassconf",$passwd_classcount); ?></td>
</tr> </tr>
<tr> <tr>
<th><label for="newpassconf"><?php __("Confirm password"); ?></label></th> <th><label for="newpassconf"><?php __("Confirm password"); ?></label></th>

View File

@ -30,10 +30,8 @@
require_once("../class/config.php"); require_once("../class/config.php");
include_once("head.php"); include_once("head.php");
if (!$r=$hta->ListDir()) { if ($r=$hta->ListDir()) {
$error=$err->errstr(); reset($r);
} else {
reset($r);
} }
?> ?>
@ -41,17 +39,15 @@ if (!$r=$hta->ListDir()) {
<hr id="topbar"/> <hr id="topbar"/>
<br /> <br />
<?php <?php
if (isset($error) && $error) { echo $msg->msg_html_all();
echo "<p class=\"alert alert-danger\">$error</p>";
}
if (!is_array($r)) { if (!is_array($r)) {
echo "<p><span class=\"ina\"><a href=\"hta_add.php\">"._("Protect a folder")."</a></span><br />"; echo "<p><span class=\"ina\"><a href=\"hta_add.php\">"._("Protect a folder")."</a></span><br />";
$mem->show_help("hta_list"); $mem->show_help("hta_list");
echo "</p>"; echo "</p>";
include_once("foot.php"); include_once("foot.php");
exit(); exit();
} }
?> ?>

View File

@ -78,29 +78,26 @@ class m_hta {
* *
* @global m_mem $mem * @global m_mem $mem
* @global m_bro $bro * @global m_bro $bro
* @global m_err $err * @global m_messages $msg
* @param string $dir * @param string $dir
* @return boolean * @return boolean
*/ */
function CreateDir($dir) { function CreateDir($dir) {
global $bro, $err; global $bro, $msg;
$err->log("hta", "createdir", $dir); $msg->log("hta", "createdir", $dir);
$absolute = $bro->convertabsolute($dir, 0); $absolute = $bro->convertabsolute($dir, 0);
if (!$absolute) { if (!is_dir($absolute)) {
$err->raise("hta", printf(_("The folder '%s' does not exist"), $dir)); $msg->raise('Error', "hta", _("The folder '%s' does not exist"), $dir);
return false; return false;
} }
if (!file_exists($absolute)) {
@mkdir($absolute, 00777);
}
if (!file_exists("$absolute/.htaccess")) { if (!file_exists("$absolute/.htaccess")) {
if (!@touch("$absolute/.htaccess")) { if (!@touch("$absolute/.htaccess")) {
$err->raise("hta", _("File already exist")); $msg->raise('Error', "hta", _("File already exist"));
return false; return false;
} }
$file = @fopen("$absolute/.htaccess", "r+"); $file = @fopen("$absolute/.htaccess", "r+");
if (!$file) { if (!$file) {
$err->raise("hta", _("File already exist")); $msg->raise('Error', "hta", _("File already exist"));
return false; return false;
} }
fseek($file, 0); fseek($file, 0);
@ -110,7 +107,7 @@ class m_hta {
} }
if (!file_exists("$absolute/.htpasswd")) { if (!file_exists("$absolute/.htpasswd")) {
if (!touch("$absolute/.htpasswd")) { if (!touch("$absolute/.htpasswd")) {
$err->raise("hta", _("File already exist")); $msg->raise('Error', "hta", _("File already exist"));
return false; return false;
} }
return true; return true;
@ -121,18 +118,18 @@ class m_hta {
/** /**
* Returns the list of all user folder currently protected by a .htpasswd file * Returns the list of all user folder currently protected by a .htpasswd file
* *
* @global m_err $err * @global m_messages $msg
* @global m_mem $mem * @global m_mem $mem
* @return array Array containing user folder list * @return array Array containing user folder list
*/ */
function ListDir() { function ListDir() {
global$err, $mem; global$msg, $mem;
$err->log("hta", "listdir"); $msg->log("hta", "listdir");
$sortie = array(); $sortie = array();
$absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"]; $absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"];
exec("find " . escapeshellarg($absolute) . " -name .htpasswd|sort", $sortie); exec("find " . escapeshellarg($absolute) . " -name .htpasswd|sort", $sortie);
if (!count($sortie)) { if (!count($sortie)) {
$err->raise("hta", _("No protected folder")); $msg->raise('Info', "hta", _("No protected folder"));
return false; return false;
} }
$pattern = "/^" . preg_quote(ALTERNC_HTML, "/") . "\/.\/[^\/]*\/(.*)\/\.htpasswd/"; $pattern = "/^" . preg_quote(ALTERNC_HTML, "/") . "\/.\/[^\/]*\/(.*)\/\.htpasswd/";
@ -151,13 +148,13 @@ class m_hta {
* Tells if a folder is protected. * Tells if a folder is protected.
* *
* @global m_mem $mem * @global m_mem $mem
* @global m_err $err * @global m_messages $msg
* @param string $dir Folder to check * @param string $dir Folder to check
* @return boolean If the folder is protected, or FALSE if it is not * @return boolean If the folder is protected, or FALSE if it is not
*/ */
function is_protected($dir) { function is_protected($dir) {
global $mem, $err; global $mem, $msg;
$err->log("hta", "is_protected", $dir); $msg->log("hta", "is_protected", $dir);
$absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"] . "/$dir"; $absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"] . "/$dir";
if (file_exists("$absolute/.htpasswd")) { if (file_exists("$absolute/.htpasswd")) {
return true; return true;
@ -170,13 +167,13 @@ class m_hta {
* Returns the list of login for a protected folder. * Returns the list of login for a protected folder.
* *
* @global m_mem $mem * @global m_mem $mem
* @global m_err $err * @global m_messages $msg
* @param string $dir The folder to lookup (relative to user root) * @param string $dir The folder to lookup (relative to user root)
* @return array An array containing the list of logins from the .htpasswd file, or FALSE * @return array An array containing the list of logins from the .htpasswd file, or FALSE
*/ */
function get_hta_detail($dir) { function get_hta_detail($dir) {
global $mem, $err; global $mem, $msg;
$err->log("hta", "get_hta_detail"); $msg->log("hta", "get_hta_detail");
$absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"] . "/$dir"; $absolute = ALTERNC_HTML . "/" . substr($mem->user["login"], 0, 1) . "/" . $mem->user["login"] . "/$dir";
if (file_exists("$absolute/.htaccess")) { if (file_exists("$absolute/.htaccess")) {
/* if (!_reading_htaccess($absolute)) { /* if (!_reading_htaccess($absolute)) {
@ -208,22 +205,22 @@ class m_hta {
* *
* @global m_mem $mem * @global m_mem $mem
* @global m_bro $bro * @global m_bro $bro
* @global m_err $err * @global m_messages $msg
* @param string $dir Folder to unprotect, relative to user root * @param string $dir Folder to unprotect, relative to user root
* @param boolean $skip For testing purpose mainly, skips the full user path search * @param boolean $skip For testing purpose mainly, skips the full user path search
* @return boolean TRUE if the folder has been unprotected, or FALSE if an error occurred * @return boolean TRUE if the folder has been unprotected, or FALSE if an error occurred
*/ */
function DelDir($dir, $skip = false) { function DelDir($dir, $skip = false) {
global $bro, $err; global $bro, $msg;
$err->log("hta", "deldir", $dir); $msg->log("hta", "deldir", $dir);
$dir = $bro->convertabsolute($dir, $skip); $dir = $bro->convertabsolute($dir, $skip);
if (!$dir) { if (!$dir) {
$err->raise("hta", printf(("The folder '%s' does not exist"), $dir)); $msg->raise('Error', "hta", ("The folder '%s' does not exist"), $dir);
return false; return false;
} }
$htaccess_file = "$dir/.htaccess"; $htaccess_file = "$dir/.htaccess";
if (!is_readable($htaccess_file)) { if (!is_readable($htaccess_file)) {
$err->raise("hta", printf(_("I cannot read the file '%s'"), $htaccess_file)); $msg->raise('Error', "hta", _("I cannot read the file '%s'"), $htaccess_file);
} }
$fileLines = file($htaccess_file); $fileLines = file($htaccess_file);
$patternList = array( $patternList = array(
@ -243,21 +240,21 @@ class m_hta {
} }
// If no changes // If no changes
if (!$count_lines) { if (!$count_lines) {
$err->raise("hta", printf(_("Unexpected: No changes made to '%s'"), $htaccess_file)); $msg->raise('Alert', "hta", _("Unexpected: No changes made to '%s'"), $htaccess_file);
} }
// If file is empty, remove it // If file is empty, remove it
if (!count($fileLines)) { if (!count($fileLines)) {
if (!unlink($htaccess_file)) { if (!unlink($htaccess_file)) {
$err->raise("hta", printf(_("I could not delete the file '%s'"), $htaccess_file)); $msg->raise('Error', "hta", _("I could not delete the file '%s'"), $htaccess_file);
} }
} else { } else {
file_put_contents($htaccess_file, implode("\n", $fileLines)); file_put_contents($htaccess_file, implode("\n", $fileLines));
} }
$htpasswd_file = "$dir/.htpasswd"; $htpasswd_file = "$dir/.htpasswd";
if (!is_writable($htpasswd_file)) { if (!is_writable($htpasswd_file)) {
$err->raise("hta", printf(_("I cannot read the file '%s'"), $htpasswd_file)); $msg->raise('Error', "hta", _("I cannot read the file '%s'"), $htpasswd_file);
} else if (!unlink($htpasswd_file)) { } else if (!unlink($htpasswd_file)) {
$err->raise("hta", printf(_("I cannot delete the file '%s/.htpasswd'"), $dir)); $msg->raise('Error', "hta", _("I cannot delete the file '%s/.htpasswd'"), $dir);
return false; return false;
} }
@ -267,7 +264,7 @@ class m_hta {
/** /**
* Add a user to a protected folder * Add a user to a protected folder
* *
* @global m_err $err * @global m_messages $msg
* @global m_bro $bro * @global m_bro $bro
* @global m_admin $admin * @global m_admin $admin
* @param string $user * @param string $user
@ -278,19 +275,19 @@ class m_hta {
* @return boolean TRUE if the user has been added, or FALSE if an error occurred * @return boolean TRUE if the user has been added, or FALSE if an error occurred
*/ */
function add_user($user, $password, $dir) { function add_user($user, $password, $dir) {
global $err, $bro, $admin; global $msg, $bro, $admin;
$err->log("hta", "add_user", $user . "/" . $dir); $msg->log("hta", "add_user", $user . "/" . $dir);
if (empty($user)) { if (empty($user)) {
$err->raise('hta', _("Please enter a user")); $msg->raise('Error', 'hta', _("Please enter a user"));
return false; return false;
} }
if (empty($password)) { if (empty($password)) {
$err->raise('hta', _("Please enter a password")); $msg->raise('Error', 'hta', _("Please enter a password"));
return false; return false;
} }
$absolute = $bro->convertabsolute($dir, 0); $absolute = $bro->convertabsolute($dir, 0);
if (!file_exists($absolute)) { if (!file_exists($absolute)) {
$err->raise("hta", printf(("The folder '%s' does not exist"), $dir)); $msg->raise('Error', "hta", _("The folder '%s' does not exist"), $dir);
return false; return false;
} }
// @todo delete cf!. functions.php checkloginemail definition // @todo delete cf!. functions.php checkloginemail definition
@ -304,7 +301,7 @@ class m_hta {
$file = @fopen("$absolute/.htpasswd", "a+"); $file = @fopen("$absolute/.htpasswd", "a+");
if (!$file) { if (!$file) {
$err->raise("hta", _("File already exist")); $msg->raise('Error', "hta", _("File already exist"));
return false; return false;
} }
fseek($file, 0); fseek($file, 0);
@ -312,7 +309,7 @@ class m_hta {
$s = fgets($file, 1024); $s = fgets($file, 1024);
$t = explode(":", $s); $t = explode(":", $s);
if ($t[0] == $user) { if ($t[0] == $user) {
$err->raise("hta", _("The user '%s' already exist for this folder"), $user); $msg->raise('Error', "hta", _("The user '%s' already exist for this folder"), $user);
return false; return false;
} }
} }
@ -324,7 +321,7 @@ class m_hta {
fclose($file); fclose($file);
return true; return true;
} else { } else {
$err->raise("hta", _("Please enter a valid username")); $msg->raise('Error', "hta", _("Please enter a valid username"));
return false; return false;
} }
} }
@ -333,24 +330,24 @@ class m_hta {
* Delete a user from a protected folder. * Delete a user from a protected folder.
* *
* @global m_bro $bro * @global m_bro $bro
* @global m_err $err * @global m_messages $msg
* @param array $lst An array with login to delete. * @param array $lst An array with login to delete.
* @param string $dir The folder, relative to user root, where we want to delete users. * @param string $dir The folder, relative to user root, where we want to delete users.
* @return boolean TRUE if users has been deleted, or FALSE if an error occurred. * @return boolean TRUE if users has been deleted, or FALSE if an error occurred.
*/ */
function del_user($lst, $dir) { function del_user($lst, $dir) {
global $bro, $err; global $bro, $msg;
$err->log("hta", "del_user", $lst . "/" . $dir); $msg->log("hta", "del_user", $lst . "/" . $dir);
$absolute = $bro->convertabsolute($dir, 0); $absolute = $bro->convertabsolute($dir, 0);
if (!file_exists($absolute)) { if (!file_exists($absolute)) {
$err->raise("hta", printf(_("The folder '%s' does not exist"), $dir)); $msg->raise('Error', "hta", _("The folder '%s' does not exist"), $dir);
return false; return false;
} }
touch("$absolute/.htpasswd.new"); touch("$absolute/.htpasswd.new");
$file = fopen("$absolute/.htpasswd", "r"); $file = fopen("$absolute/.htpasswd", "r");
$newf = fopen("$absolute/.htpasswd.new", "a"); $newf = fopen("$absolute/.htpasswd.new", "a");
if (!$file || !$newf) { if (!$file || !$newf) {
$err->raise("hta", _("File already exist")); $msg->raise('Error', "hta", _("File already exist"));
return false; return false;
} }
reset($lst); reset($lst);
@ -378,11 +375,11 @@ class m_hta {
* @return boolean TRUE if the password has been changed, or FALSE if an error occurred * @return boolean TRUE if the password has been changed, or FALSE if an error occurred
*/ */
function change_pass($user, $newpass, $dir) { function change_pass($user, $newpass, $dir) {
global $bro, $err, $admin; global $bro, $msg, $admin;
$err->log("hta", "change_pass", $user . "/" . $dir); $msg->log("hta", "change_pass", $user . "/" . $dir);
$absolute = $bro->convertabsolute($dir, 0); $absolute = $bro->convertabsolute($dir, 0);
if (!file_exists($absolute)) { if (!file_exists($absolute)) {
$err->raise("hta", printf(_("The folder '%s' does not exist"), $dir)); $msg->raise('Error', "hta", _("The folder '%s' does not exist"), $dir);
return false; return false;
} }
@ -397,7 +394,7 @@ class m_hta {
$file = fopen("$absolute/.htpasswd", "r"); $file = fopen("$absolute/.htpasswd", "r");
$newf = fopen("$absolute/.htpasswd.new", "a"); $newf = fopen("$absolute/.htpasswd.new", "a");
if (!$file || !$newf) { if (!$file || !$newf) {
$err->raise("hta", _("File already exist")); $msg->raise('Error', "hta", _("File already exist"));
return false; return false;
} }
while (!feof($file)) { while (!feof($file)) {
@ -418,14 +415,14 @@ class m_hta {
/** /**
* Check that a .htaccess file is valid (for authentication) * Check that a .htaccess file is valid (for authentication)
* *
* @global m_err $err * @global m_messages $msg
* @param type $absolute * @param type $absolute
* @param string $absolute Folder we want to check (relative to user root) * @param string $absolute Folder we want to check (relative to user root)
* @return boolean TRUE is the .htaccess is protecting this folder, or FALSE else * @return boolean TRUE is the .htaccess is protecting this folder, or FALSE else
*/ */
private function _reading_htaccess($absolute) { private function _reading_htaccess($absolute) {
global $err; global $msg;
$err->log("hta", "_reading_htaccess", $absolute); $msg->log("hta", "_reading_htaccess", $absolute);
$file = fopen("$absolute/.htaccess", "r+"); $file = fopen("$absolute/.htaccess", "r+");
$lignes = array(1, 1, 1); $lignes = array(1, 1, 1);
$errr = 0; $errr = 0;
@ -452,7 +449,7 @@ class m_hta {
} // Reading config file } // Reading config file
fclose($file); fclose($file);
if ($errr || in_array(0, $lignes)) { if ($errr || in_array(0, $lignes)) {
$err->raise("hta", _("An incompatible .htaccess file exists in this folder")); $msg->raise('Error', "hta", _("An incompatible .htaccess file exists in this folder"));
return false; return false;
} }
return true; return true;