[fix] cosmetic changes
This commit is contained in:
parent
590223878e
commit
0f48d94c04
|
@ -863,27 +863,6 @@ function display_browser($dir="", $caller="main.dir", $width=350, $height=450) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Insere un $wrap_string tous les $max caracteres dans $message
|
|
||||||
*
|
|
||||||
* @param string $message
|
|
||||||
* @param int $max
|
|
||||||
* @param string $wrap_string
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function auto_wrap($message="",$max=10,$wrap_string="<wbr/>") {
|
|
||||||
$cpt = 0;
|
|
||||||
$mot = split(" ",$message);
|
|
||||||
while (isset($mot[$cpt]) && ($mot[$cpt] != "")){
|
|
||||||
if(@strlen($mot[$cpt]) > $max){
|
|
||||||
$nvmot = chunk_split ($mot[$cpt], $max, $wrap_string );
|
|
||||||
$message = str_replace($mot[$cpt], $nvmot, $message);
|
|
||||||
}
|
|
||||||
$cpt++;
|
|
||||||
}
|
|
||||||
return $message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts HSV to RGB values
|
* Converts HSV to RGB values
|
||||||
* -----------------------------------------------------
|
* -----------------------------------------------------
|
||||||
|
|
|
@ -99,12 +99,12 @@ class m_bro {
|
||||||
* @param string $dir
|
* @param string $dir
|
||||||
* @global m_mem $mem
|
* @global m_mem $mem
|
||||||
* @param string $dir Dossier absolu que l'on souhaite vérifier
|
* @param string $dir Dossier absolu que l'on souhaite vérifier
|
||||||
* @param boolean $strip
|
* @param integer $strip
|
||||||
* @return false|string Retourne le nom du dossier vrifi, relatif au
|
* @return false|string Retourne le nom du dossier vérifié, relatif au
|
||||||
* dossier de l'utilisateur courant, ventuellement corrig.
|
* dossier de l'utilisateur courant, éventuellement corrigé.
|
||||||
* ou FALSE si le dossier n'est pas dans le dossier de l'utilisateur.
|
* ou FALSE si le dossier n'est pas dans le dossier de l'utilisateur.
|
||||||
*/
|
*/
|
||||||
function convertabsolute($dir,$strip=true) {
|
function convertabsolute($dir,$strip = 1) {
|
||||||
global $mem;
|
global $mem;
|
||||||
$root = $this->get_user_root($mem->user["login"]);
|
$root = $this->get_user_root($mem->user["login"]);
|
||||||
// Sauvegarde du chemin de base.
|
// Sauvegarde du chemin de base.
|
||||||
|
@ -200,7 +200,7 @@ class m_bro {
|
||||||
function filelist($dir = "", $showdirsize = false) {
|
function filelist($dir = "", $showdirsize = false) {
|
||||||
global $db,$cuid,$err;
|
global $db,$cuid,$err;
|
||||||
$db->query("UPDATE browser SET lastdir = '$dir' WHERE uid = '$cuid';");
|
$db->query("UPDATE browser SET lastdir = '$dir' WHERE uid = '$cuid';");
|
||||||
$absolute=$this->convertabsolute($dir,false);
|
$absolute = $this->convertabsolute($dir,0);
|
||||||
if (!$absolute || !file_exists($absolute)) {
|
if (!$absolute || !file_exists($absolute)) {
|
||||||
$err->raise('bro',_("This directory do not exist"));
|
$err->raise('bro',_("This directory do not exist"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -260,10 +260,14 @@ class m_bro {
|
||||||
*/
|
*/
|
||||||
function SetPrefs($editsizex, $editsizey, $listmode, $showicons, $downfmt, $createfile, $showtype, $editor_font, $editor_size, $golastdir) {
|
function SetPrefs($editsizex, $editsizey, $listmode, $showicons, $downfmt, $createfile, $showtype, $editor_font, $editor_size, $golastdir) {
|
||||||
global $db,$cuid;
|
global $db,$cuid;
|
||||||
$editsizex=intval($editsizex); $editsizey=intval($editsizey);
|
$editsizex = intval($editsizex);
|
||||||
$listmode=intval($listmode); $showicons=intval($showicons);
|
$editsizey = intval($editsizey);
|
||||||
$showtype=intval($showtype); $downfmt=intval($downfmt);
|
$listmode = intval($listmode);
|
||||||
$createfile=intval($createfile); $golastdir=intval($golastdir);
|
$showicons = intval($showicons);
|
||||||
|
$showtype = intval($showtype);
|
||||||
|
$downfmt = intval($downfmt);
|
||||||
|
$createfile = intval($createfile);
|
||||||
|
$golastdir = intval($golastdir);
|
||||||
$db->query("SELECT * FROM browser WHERE uid = '".intval($cuid)."';");
|
$db->query("SELECT * FROM browser WHERE uid = '".intval($cuid)."';");
|
||||||
if ($db->num_rows() == 0) {
|
if ($db->num_rows() == 0) {
|
||||||
$db->query("INSERT INTO browser (editsizex, editsizey, listmode, showicons, downfmt, createfile, showtype, uid, editor_font, editor_size, golastdir) VALUES (70, 21, 0, 0, 0, 0, 0, '".intval($cuid)."','Arial, Helvetica, Sans-serif','12px',1);");
|
$db->query("INSERT INTO browser (editsizex, editsizey, listmode, showicons, downfmt, createfile, showtype, uid, editor_font, editor_size, golastdir) VALUES (70, 21, 0, 0, 0, 0, 0, '".intval($cuid)."','Arial, Helvetica, Sans-serif','12px',1);");
|
||||||
|
@ -391,7 +395,7 @@ class m_bro {
|
||||||
function CreateDir($dir,$file) {
|
function CreateDir($dir,$file) {
|
||||||
global $db,$cuid,$err;
|
global $db,$cuid,$err;
|
||||||
$file = ssla($file);
|
$file = ssla($file);
|
||||||
$absolute=$this->convertabsolute($dir."/".$file,false);
|
$absolute = $this->convertabsolute($dir."/".$file,0);
|
||||||
#echo "$absolute";
|
#echo "$absolute";
|
||||||
if ($absolute && (!file_exists($absolute))) {
|
if ($absolute && (!file_exists($absolute))) {
|
||||||
if (!mkdir($absolute,00777,true)) {
|
if (!mkdir($absolute,00777,true)) {
|
||||||
|
@ -420,7 +424,7 @@ class m_bro {
|
||||||
function CreateFile($dir,$file) {
|
function CreateFile($dir,$file) {
|
||||||
global $db,$err,$cuid;
|
global $db,$err,$cuid;
|
||||||
$file = ssla($file);
|
$file = ssla($file);
|
||||||
$absolute=$this->convertabsolute($dir."/".$file,false);
|
$absolute = $this->convertabsolute($dir."/".$file,0);
|
||||||
if (!$absolute || file_exists($absolute)) {
|
if (!$absolute || file_exists($absolute)) {
|
||||||
$err->raise("bro",_("File or folder name is incorrect"));
|
$err->raise("bro",_("File or folder name is incorrect"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -448,7 +452,7 @@ class m_bro {
|
||||||
function DeleteFile($file_list,$R) {
|
function DeleteFile($file_list,$R) {
|
||||||
global $err, $mem;
|
global $err, $mem;
|
||||||
$root = realpath(getuserpath());
|
$root = realpath(getuserpath());
|
||||||
$absolute=$this->convertabsolute($R,false);
|
$absolute = $this->convertabsolute($R,0);
|
||||||
if (!$absolute && strpos($root,$absolute) === 0 && strlen($absolute) > (strlen($root)+1) ) {
|
if (!$absolute && strpos($root,$absolute) === 0 && strlen($absolute) > (strlen($root)+1) ) {
|
||||||
$err->raise("bro",_("File or folder name is incorrect"));
|
$err->raise("bro",_("File or folder name is incorrect"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -474,7 +478,7 @@ class m_bro {
|
||||||
*/
|
*/
|
||||||
function RenameFile($R,$old,$new) {
|
function RenameFile($R,$old,$new) {
|
||||||
global $err;
|
global $err;
|
||||||
$absolute=$this->convertabsolute($R,false);
|
$absolute = $this->convertabsolute($R,0);
|
||||||
if (!$absolute) {
|
if (!$absolute) {
|
||||||
$err->raise("bro",_("File or folder name is incorrect"));
|
$err->raise("bro",_("File or folder name is incorrect"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -508,7 +512,7 @@ class m_bro {
|
||||||
*/
|
*/
|
||||||
function MoveFile($d,$old,$new) {
|
function MoveFile($d,$old,$new) {
|
||||||
global $err;
|
global $err;
|
||||||
$old=$this->convertabsolute($old,false);
|
$old = $this->convertabsolute($old,0);
|
||||||
if (!$old) {
|
if (!$old) {
|
||||||
$err->raise("bro",_("File or folder name is incorrect"));
|
$err->raise("bro",_("File or folder name is incorrect"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -517,7 +521,7 @@ class m_bro {
|
||||||
if ($new[0] != '/') {
|
if ($new[0] != '/') {
|
||||||
$new = $old . '/' . $new;
|
$new = $old . '/' . $new;
|
||||||
}
|
}
|
||||||
$new = $this->convertabsolute($new,false);
|
$new = $this->convertabsolute($new,0);
|
||||||
|
|
||||||
if (!$new) {
|
if (!$new) {
|
||||||
$err->raise("bro",_("File or folder name is incorrect"));
|
$err->raise("bro",_("File or folder name is incorrect"));
|
||||||
|
@ -548,7 +552,7 @@ class m_bro {
|
||||||
*/
|
*/
|
||||||
function ChangePermissions($R,$d,$perm,$verbose = false) {
|
function ChangePermissions($R,$d,$perm,$verbose = false) {
|
||||||
global $err;
|
global $err;
|
||||||
$absolute=$this->convertabsolute($R,false);
|
$absolute = $this->convertabsolute($R,0);
|
||||||
if (!$absolute) {
|
if (!$absolute) {
|
||||||
$err->raise("bro",_("File or folder name is incorrect"));
|
$err->raise("bro",_("File or folder name is incorrect"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -591,7 +595,7 @@ class m_bro {
|
||||||
*/
|
*/
|
||||||
function UploadFile($R) {
|
function UploadFile($R) {
|
||||||
global $_FILES,$err,$cuid,$action;
|
global $_FILES,$err,$cuid,$action;
|
||||||
$absolute=$this->convertabsolute($R,false);
|
$absolute = $this->convertabsolute($R,0);
|
||||||
if (!$absolute) {
|
if (!$absolute) {
|
||||||
$err->raise("bro",_("File or folder name is incorrect"));
|
$err->raise("bro",_("File or folder name is incorrect"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -647,11 +651,11 @@ class m_bro {
|
||||||
*/
|
*/
|
||||||
function ExtractFile($file, $dest = null) {
|
function ExtractFile($file, $dest = null) {
|
||||||
global $err,$cuid,$mem,$action;
|
global $err,$cuid,$mem,$action;
|
||||||
$file = $this->convertabsolute($file,false);
|
$file = $this->convertabsolute($file,0);
|
||||||
if (is_null($dest)) {
|
if (is_null($dest)) {
|
||||||
$dest = dirname($file);
|
$dest = dirname($file);
|
||||||
} else {
|
} else {
|
||||||
$dest = $this->convertabsolute($dest,false);
|
$dest = $this->convertabsolute($dest,0);
|
||||||
}
|
}
|
||||||
if (!$file || !$dest) {
|
if (!$file || !$dest) {
|
||||||
$err->raise("bro",_("File or folder name is incorrect"));
|
$err->raise("bro",_("File or folder name is incorrect"));
|
||||||
|
@ -696,12 +700,12 @@ class m_bro {
|
||||||
*/
|
*/
|
||||||
function CopyFile($d,$old,$new) {
|
function CopyFile($d,$old,$new) {
|
||||||
global $err;
|
global $err;
|
||||||
$old=$this->convertabsolute($old,false);
|
$old = $this->convertabsolute($old,0);
|
||||||
if (!$old) {
|
if (!$old) {
|
||||||
$err->raise("bro",_("File or folder name is incorrect"));
|
$err->raise("bro",_("File or folder name is incorrect"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$new=$this->convertabsolute($new,false);
|
$new = $this->convertabsolute($new,0);
|
||||||
if (!$new) {
|
if (!$new) {
|
||||||
$err->raise("bro",_("File or folder name is incorrect"));
|
$err->raise("bro",_("File or folder name is incorrect"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -757,7 +761,7 @@ class m_bro {
|
||||||
* @return string Le code HTML ainsi obtenu.
|
* @return string Le code HTML ainsi obtenu.
|
||||||
*/
|
*/
|
||||||
function PathList($path,$action, $justparent = false) {
|
function PathList($path,$action, $justparent = false) {
|
||||||
$path=$this->convertabsolute($path,true);
|
$path = $this->convertabsolute($path,1);
|
||||||
$a = explode("/",$path);
|
$a = explode("/",$path);
|
||||||
if (!is_array($a)) $a = array($a);
|
if (!is_array($a)) $a = array($a);
|
||||||
$c = '';
|
$c = '';
|
||||||
|
@ -789,7 +793,7 @@ class m_bro {
|
||||||
*/
|
*/
|
||||||
function content($R,$file) {
|
function content($R,$file) {
|
||||||
global $err;
|
global $err;
|
||||||
$absolute=$this->convertabsolute($R,false);
|
$absolute = $this->convertabsolute($R,0);
|
||||||
if (!strpos($file,"/")) {
|
if (!strpos($file,"/")) {
|
||||||
$absolute .= "/".$file;
|
$absolute .= "/".$file;
|
||||||
if (file_exists($absolute)) {
|
if (file_exists($absolute)) {
|
||||||
|
@ -987,7 +991,7 @@ class m_bro {
|
||||||
*/
|
*/
|
||||||
function save($file,$R,$texte) {
|
function save($file,$R,$texte) {
|
||||||
global $err;
|
global $err;
|
||||||
$absolute=$this->convertabsolute($R,false);
|
$absolute = $this->convertabsolute($R,0);
|
||||||
if (!strpos($file,"/")) {
|
if (!strpos($file,"/")) {
|
||||||
$absolute .= "/".$file;
|
$absolute .= "/".$file;
|
||||||
if (file_exists($absolute)) {
|
if (file_exists($absolute)) {
|
||||||
|
@ -1015,7 +1019,7 @@ class m_bro {
|
||||||
header("Content-Disposition: attachment; filename = ".$mem->user["login"].".Z");
|
header("Content-Disposition: attachment; filename = ".$mem->user["login"].".Z");
|
||||||
header("Content-Type: application/x-Z");
|
header("Content-Type: application/x-Z");
|
||||||
header("Content-Transfer-Encoding: binary");
|
header("Content-Transfer-Encoding: binary");
|
||||||
$d=escapeshellarg(".".$this->convertabsolute($dir,true));
|
$d = escapeshellarg(".".$this->convertabsolute($dir,1));
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
passthru("/bin/tar -cZ -C ".getuserpath()."/".$mem->user["login"]."/ $d");
|
passthru("/bin/tar -cZ -C ".getuserpath()."/".$mem->user["login"]."/ $d");
|
||||||
}
|
}
|
||||||
|
@ -1033,7 +1037,7 @@ class m_bro {
|
||||||
header("Content-Disposition: attachment; filename = ".$mem->user["login"].".tgz");
|
header("Content-Disposition: attachment; filename = ".$mem->user["login"].".tgz");
|
||||||
header("Content-Type: application/x-tgz");
|
header("Content-Type: application/x-tgz");
|
||||||
header("Content-Transfer-Encoding: binary");
|
header("Content-Transfer-Encoding: binary");
|
||||||
$d=escapeshellarg(".".$this->convertabsolute($dir,true));
|
$d = escapeshellarg(".".$this->convertabsolute($dir,1));
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
passthru("/bin/tar -cz -C ".getuserpath()."/ $d");
|
passthru("/bin/tar -cz -C ".getuserpath()."/ $d");
|
||||||
}
|
}
|
||||||
|
@ -1051,7 +1055,7 @@ class m_bro {
|
||||||
header("Content-Disposition: attachment; filename = ".$mem->user["login"].".tar.bz2");
|
header("Content-Disposition: attachment; filename = ".$mem->user["login"].".tar.bz2");
|
||||||
header("Content-Type: application/x-bzip2");
|
header("Content-Type: application/x-bzip2");
|
||||||
header("Content-Transfer-Encoding: binary");
|
header("Content-Transfer-Encoding: binary");
|
||||||
$d=escapeshellarg(".".$this->convertabsolute($dir,true));
|
$d = escapeshellarg(".".$this->convertabsolute($dir,1));
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
passthru("/bin/tar -cj -C ".getuserpath()."/ $d");
|
passthru("/bin/tar -cj -C ".getuserpath()."/ $d");
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
class m_hta {
|
class m_hta {
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -50,11 +49,17 @@ class m_hta {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Password kind used in this class (hook for admin class)
|
* Password kind used in this class (hook for admin class)
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
function alternc_password_policy() {
|
function alternc_password_policy() {
|
||||||
return array("hta"=>"Protected folders passwords");
|
return array("hta"=>"Protected folders passwords");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
function hook_menu() {
|
function hook_menu() {
|
||||||
$obj = array(
|
$obj = array(
|
||||||
'title' => _("Protected folders"),
|
'title' => _("Protected folders"),
|
||||||
|
@ -67,11 +72,16 @@ class m_hta {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
/**
|
||||||
* Create a protected folder (.htaccess et .htpasswd)
|
* Create a protected folder (.htaccess et .htpasswd)
|
||||||
* @param string $dir Folder to protect (relative to user root)
|
* @param string $dir Folder to protect (relative to user root)
|
||||||
* @return boolean TRUE if the folder has been protected, or FALSE if an error occurred
|
* @return boolean TRUE if the folder has been protected, or FALSE if an error occurred
|
||||||
|
*
|
||||||
|
* @global m_mem $mem
|
||||||
|
* @global m_bro $bro
|
||||||
|
* @global m_err $err
|
||||||
|
* @param string $dir
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function CreateDir($dir) {
|
function CreateDir($dir) {
|
||||||
global $mem,$bro,$err;
|
global $mem,$bro,$err;
|
||||||
|
@ -110,12 +120,13 @@ 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_mem $mem
|
||||||
* @return array Array containing user folder list
|
* @return array Array containing user folder list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function ListDir(){
|
function ListDir(){
|
||||||
global$err,$mem;
|
global$err,$mem;
|
||||||
$err->log("hta","listdir");
|
$err->log("hta","listdir");
|
||||||
|
@ -137,11 +148,13 @@ class m_hta {
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
/**
|
||||||
* Tells if a folder is protected.
|
* Tells if a folder is protected.
|
||||||
|
*
|
||||||
|
* @global m_mem $mem
|
||||||
|
* @global m_err $err
|
||||||
* @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,$err;
|
||||||
|
@ -155,9 +168,11 @@ 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_err $err
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
|
@ -176,7 +191,7 @@ class m_hta {
|
||||||
if (!$file) {
|
if (!$file) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO: Tester la validit<EFBFBD> du .htpasswd
|
// TODO: Tester la validité du .htpasswd
|
||||||
while (!feof($file)) {
|
while (!feof($file)) {
|
||||||
$s = fgets($file,1024);
|
$s = fgets($file,1024);
|
||||||
$t = explode(":",$s);
|
$t = explode(":",$s);
|
||||||
|
@ -190,35 +205,79 @@ class m_hta {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
/**
|
||||||
* Unprotect a folder
|
* Unprotect a folder
|
||||||
|
*
|
||||||
|
* @global m_mem $mem
|
||||||
|
* @global m_bro $bro
|
||||||
|
* @global m_err $err
|
||||||
* @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
|
||||||
* @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) {
|
function DelDir($dir,$skip = 0) {
|
||||||
global $mem,$bro,$err;
|
global $mem,$bro,$err;
|
||||||
$err->log("hta","deldir",$dir);
|
$err->log("hta","deldir",$dir);
|
||||||
$dir=$bro->convertabsolute($dir,0);
|
$dir = $bro->convertabsolute($dir,$skip);
|
||||||
if (!$dir) {
|
if (!$dir) {
|
||||||
$err->raise("hta",printf(("The folder '%s' does not exist"),$dir));
|
$err->raise("hta",printf(("The folder '%s' does not exist"),$dir));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!@unlink("$dir/.htaccess")) {
|
$htaccess_file = "$dir/.htaccess";
|
||||||
$err->raise("hta",printf(_("I cannot delete the file '%s/.htaccess'"),$dir));
|
if( !is_readable($htaccess_file)){
|
||||||
return false;
|
$err->raise("hta",printf(_("I cannot read the file '%s'"),$htaccess_file));
|
||||||
}
|
}
|
||||||
if (!@unlink("$dir/.htpasswd")) {
|
$fileLines = file($htaccess_file);
|
||||||
|
$patternList = array(
|
||||||
|
"AuthUserFile.*$",
|
||||||
|
"AuthName.*$",
|
||||||
|
"AuthType Basic.*$",
|
||||||
|
"require valid-user.*$"
|
||||||
|
);
|
||||||
|
$count_lines = 0;
|
||||||
|
foreach($fileLines as $key => $line){
|
||||||
|
foreach ($patternList as $pattern) {
|
||||||
|
if(preg_match("/".$pattern."/", $line)){
|
||||||
|
$count_lines++;
|
||||||
|
unset($fileLines[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If no changes
|
||||||
|
if( ! $count_lines ){
|
||||||
|
$err->raise("hta",printf(_("Unexpected: No changes made to '%s'"),$htaccess_file));
|
||||||
|
}
|
||||||
|
// If file is empty, remove it
|
||||||
|
if( !count($fileLines)){
|
||||||
|
if( ! unlink( $htaccess_file)){
|
||||||
|
$err->raise("hta",printf(_("I could not delete the file '%s'"),$htaccess_file));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
file_put_contents($htaccess_file, implode("\n",$fileLines));
|
||||||
|
}
|
||||||
|
$htpasswd_file = "$dir/.htpasswd";
|
||||||
|
$perms = substr(sprintf('%o', fileperms($dir)), -4);
|
||||||
|
if( ! is_writable($htpasswd_file)){
|
||||||
|
$err->raise("hta",printf(_("I cannot read the file '%s'"),$htpasswd_file));
|
||||||
|
}
|
||||||
|
else if ( ! unlink($htpasswd_file)) {
|
||||||
$err->raise("hta",printf(_("I cannot delete the file '%s/.htpasswd'"),$dir));
|
$err->raise("hta",printf(_("I cannot delete the file '%s/.htpasswd'"),$dir));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
/**
|
||||||
* Add a user to a protected folder
|
* Add a user to a protected folder
|
||||||
|
*
|
||||||
|
* @global m_err $err
|
||||||
|
* @global m_bro $bro
|
||||||
|
* @global m_admin $admin
|
||||||
|
* @param string $user
|
||||||
|
* @param string $password
|
||||||
|
* @param string $dir
|
||||||
* @param string $password The password to add (cleartext)
|
* @param string $password The password to add (cleartext)
|
||||||
* @param string $dir The folder we add it to (relative to user root).
|
* @param string $dir The folder we add it to (relative to user root).
|
||||||
* @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
|
||||||
|
@ -276,9 +335,13 @@ class m_hta {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/**
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* Delete a user from a protected folder.
|
* Delete a user from a protected folder.
|
||||||
|
*
|
||||||
|
* @global m_bro $bro
|
||||||
|
* @global m_err $err
|
||||||
* @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.
|
||||||
|
@ -316,14 +379,23 @@ class m_hta {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
/**
|
||||||
* Change the password of a user in a protected folder
|
|
||||||
* @param string $user The users whose password should be changed
|
* @param string $user The users whose password should be changed
|
||||||
* @param string $newpass The new password of this user
|
* @param string $newpass The new password of this user
|
||||||
* @param string $dir The folder, relative to user root, in which we will change a password
|
* @param string $dir The folder, relative to user root, in which we will change a password
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* Change the password of a user in a protected folder
|
||||||
|
*
|
||||||
|
* @global m_bro $bro
|
||||||
|
* @global m_err $err
|
||||||
|
* @global m_admin $admin
|
||||||
|
* @param string $user
|
||||||
|
* @param string $newpass
|
||||||
|
* @param string $dir
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function change_pass($user,$newpass,$dir) {
|
function change_pass($user,$newpass,$dir) {
|
||||||
global $bro,$err,$admin;
|
global $bro,$err,$admin;
|
||||||
$err->log("hta","change_pass",$user."/".$dir);
|
$err->log("hta","change_pass",$user."/".$dir);
|
||||||
|
@ -363,14 +435,15 @@ 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
|
||||||
|
* @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
|
||||||
* @access private
|
|
||||||
*/
|
*/
|
||||||
function _reading_htaccess($absolute) {
|
private function _reading_htaccess($absolute) {
|
||||||
global $err;
|
global $err;
|
||||||
$err->log("hta","_reading_htaccess",$absolute);
|
$err->log("hta","_reading_htaccess",$absolute);
|
||||||
$file = fopen("$absolute/.htaccess","r+");
|
$file = fopen("$absolute/.htaccess","r+");
|
||||||
|
|
Loading…
Reference in New Issue