From 8f722bb00c5e85d132bf71151b8433ca6a914b5e Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Tue, 21 Aug 2012 17:04:24 +0000 Subject: [PATCH] =?UTF-8?q?Genericit=C3=A9=20sur=20l'user=20dir,=20reste?= =?UTF-8?q?=20surement=20des=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bureau/admin/browseforfolder.php | 2 +- bureau/admin/menu.php | 2 +- bureau/class/config.php | 12 +++++++++--- bureau/class/config_real.php | 6 +++--- bureau/class/functions.php | 10 +++++----- bureau/class/lang_env.php | 2 +- bureau/class/m_bro.php | 16 ++++++++-------- bureau/class/m_ftp.php | 14 ++++++++------ bureau/class/m_mysql.php | 2 +- bureau/class/m_sta2.php | 10 ++++------ 10 files changed, 41 insertions(+), 35 deletions(-) diff --git a/bureau/admin/browseforfolder.php b/bureau/admin/browseforfolder.php index d2a14e5d..cf147f7f 100644 --- a/bureau/admin/browseforfolder.php +++ b/bureau/admin/browseforfolder.php @@ -74,7 +74,7 @@ function browseforfolder($curdir) { return $brlist; } -$root="/var/alternc/html/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/"; +$root=getuserpath(); // pour utiliser 'la ou est browseforfolder', mettre dirname($HTTP_SERVER_VARS["PATH_TRANSLATED"]); if (substr($file,0,1)!="/") $file="/".$file; diff --git a/bureau/admin/menu.php b/bureau/admin/menu.php index 84a2af30..a8e4354f 100644 --- a/bureau/admin/menu.php +++ b/bureau/admin/menu.php @@ -37,7 +37,7 @@ require_once("../class/config.php"); \ No newline at end of file +?> diff --git a/bureau/class/functions.php b/bureau/class/functions.php index 63a9eb43..8bbb9c0b 100644 --- a/bureau/class/functions.php +++ b/bureau/class/functions.php @@ -209,13 +209,13 @@ function checkuserpath($path) { if (substr($path,0,1)=="/") $path="/".$path; - $rpath = realpath("/var/alternc/html/$usar/$user$path"); - $userpath = realpath("/var/alternc/html/$usar/$user"); + $rpath = realpath(ALTERNC_HTML."/$usar/$user$path"); + $userpath = getuserpath(); if(strpos($rpath,$userpath) === 0){ - if (is_dir("/var/alternc/html/$usar/$user$path")) { + if (is_dir(ALTERNC_HTML."/$usar/$user$path")) { return 1; } - if (is_file("/var/alternc/html/$usar/$user$path")) { + if (is_file(ALTERNC_HTML."/$usar/$user$path")) { return 2; } } @@ -236,7 +236,7 @@ function getuserpath($user = null) { global $mem; $user = $mem->user['login']; } - return $L_ALTERNC_LOC . "/html/".substr($user,0,1)."/".$user; + return ALTERNC_HTML."/".substr($user,0,1)."/".$user; } /* ECHOes checked="checked" only if the parameter is true diff --git a/bureau/class/lang_env.php b/bureau/class/lang_env.php index 4106236d..0e67e964 100644 --- a/bureau/class/lang_env.php +++ b/bureau/class/lang_env.php @@ -21,7 +21,7 @@ if (isset($_REQUEST["setlang"])) { $lang=$_REQUEST["setlang"]; } -$langpath = bindtextdomain("alternc", "/var/alternc/bureau/locales"); +$langpath = bindtextdomain("alternc", ALTERNC_LOCALES); // Create or update a locale.php file if it is outdated. $locales = update_locale($langpath); diff --git a/bureau/class/m_bro.php b/bureau/class/m_bro.php index 2ad1878f..be9ea4bb 100644 --- a/bureau/class/m_bro.php +++ b/bureau/class/m_bro.php @@ -122,7 +122,7 @@ class m_bro { * @return string Returns the complete path to the root of the user's directory. */ function get_user_root($login) { - return "/var/alternc/html/".substr($login,0,1)."/".$login; + return getuserpath(); } /** Retourne le chemin complet vers la racine du repertoire de l'utilisateur. @@ -377,7 +377,7 @@ class m_bro { */ function DeleteFile($file_list,$R) { global $err, $mem; - $root=realpath("/var/alternc/html/".substr($mem->user["login"],0,1)."/".$mem->user["login"]); + $root=realpath(getuserpath()); $absolute=$this->convertabsolute($R,0); if (!$absolute && strpos($root,$absolute) === 0 && strlen($absolute) > (strlen($root)+1) ) { $err->raise("bro",1); @@ -556,8 +556,8 @@ class m_bro { return 1; } $file = escapeshellarg($file); - $dest = escapeshellarg($dest); - $dest_to_fix=str_replace($L_ALTERNC_LOC."/html/".substr($mem->user["login"],0,1)."/".$mem->user["login"],'',$dest); + $dest = escapeshellarg($dest); + $dest_to_fix=str_replace(getuserpath(),'',$dest); // TODO new version of tar supports `tar xf ...` so there is no // need to specify the compression format @@ -839,7 +839,7 @@ class m_bro { header("Content-Transfer-Encoding: binary"); $d=escapeshellarg(".".$this->convertabsolute($dir,1)); set_time_limit(0); - passthru("/bin/tar -cZ -C ".$L_ALTERNC_LOC."/html/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/ $d"); + passthru("/bin/tar -cZ -C ".getuserpath()."/".$mem->user["login"]."/ $d"); } @@ -855,7 +855,7 @@ class m_bro { header("Content-Transfer-Encoding: binary"); $d=escapeshellarg(".".$this->convertabsolute($dir,1)); set_time_limit(0); - passthru("/bin/tar -cz -C ".$L_ALTERNC_LOC."/html/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/ $d"); + passthru("/bin/tar -cz -C ".getuserpath()."/ $d"); } @@ -871,7 +871,7 @@ class m_bro { header("Content-Transfer-Encoding: binary"); $d=escapeshellarg(".".$this->convertabsolute($dir,1)); set_time_limit(0); - passthru("/bin/tar -cj -C ".$L_ALTERNC_LOC."/html/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/ $d"); + passthru("/bin/tar -cj -C ".getuserpath()."/ $d"); } @@ -964,7 +964,7 @@ function alternc_export_data($dir){ } $timestamp=date("H:i:s"); - if(exec("/bin/tar cvf - ".$L_ALTERNC_LOC."/html/".substr($mem->user['login'],0,1)."/".$mem->user['login']."/ | gzip -9c > ".$dir."/".$mem->user['login']."_html_".$timestamp.".tar.gz")){ + if(exec("/bin/tar cvf - ".getuserpath()."/ | gzip -9c > ".$dir."/".$mem->user['login']."_html_".$timestamp.".tar.gz")){ $err->log("bro","export_data_succes"); }else{ $err->log("bro","export_data_failed"); diff --git a/bureau/class/m_ftp.php b/bureau/class/m_ftp.php index 190a9751..0d59cc48 100644 --- a/bureau/class/m_ftp.php +++ b/bureau/class/m_ftp.php @@ -91,6 +91,7 @@ class m_ftp { if ($db->num_rows()) { while ($db->next_record()) { // On passe /var/alternc/html/u/user + // FIXME: utiliser getuserpath() $tr=preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)$/", $db->f("homedir"),$match); /* " */ $r[]=array( "id"=>$db->f("id"), @@ -119,6 +120,7 @@ class m_ftp { $db->query("SELECT id, name, homedir FROM ftpusers WHERE uid='$cuid' AND id='$id';"); if ($db->num_rows()) { $db->next_record(); + // FIXME: utiliser getuserpath $tr=preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)$/", $db->f("homedir"),$match); $lg=explode("_",$db->f("name")); if ((!is_array($lg)) || (count($lg)!=2)) { @@ -207,7 +209,7 @@ class m_ftp { $err->raise("ftp",4); return false; } - $absolute="/var/alternc/html/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/$dir"; + $absolute=getuserpath()."/$dir"; if (!file_exists($absolute)) { system("/bin/mkdir -p $absolute"); } @@ -224,9 +226,9 @@ class m_ftp { } } $encrypted_password = crypt($pass,strrev(microtime(true))); - $db->query("UPDATE ftpusers SET name='".$prefixe.$login."', password='', encrypted_password='$encrypted_password', homedir='/var/alternc/html/$l/$lo/$dir', uid='$cuid' WHERE id='$id';"); + $db->query("UPDATE ftpusers SET name='".$prefixe.$login."', password='', encrypted_password='$encrypted_password', homedir='$absolute', uid='$cuid' WHERE id='$id';"); } else { - $db->query("UPDATE ftpusers SET name='".$prefixe.$login."', homedir='/var/alternc/html/$l/$lo/$dir', uid='$cuid' WHERE id='$id';"); + $db->query("UPDATE ftpusers SET name='".$prefixe.$login."', homedir='$absolute', uid='$cuid' WHERE id='$id';"); } return true; } @@ -283,7 +285,7 @@ class m_ftp { $db->next_record(); $lo=$db->f("login"); $l=substr($lo,0,1); - $absolute="/var/alternc/html/".substr($mem->user["login"],0,1)."/".$mem->user["login"]."/$dir"; + $absolute=getuserpath()."/$dir"; if (!file_exists($absolute)) { system("/bin/mkdir -p $absolute"); } @@ -301,7 +303,7 @@ class m_ftp { if ($quota->cancreate("ftp")) { $encrypted_password = crypt($pass,strrev(microtime(true))); - $db->query("INSERT INTO ftpusers (name,password, encrypted_password,homedir,uid) VALUES ('".$prefixe.$login."', '', '$encrypted_password', '/var/alternc/html/$l/$lo/$dir', '$cuid')"); + $db->query("INSERT INTO ftpusers (name,password, encrypted_password,homedir,uid) VALUES ('".$prefixe.$login."', '', '$encrypted_password', '$absolute', '$cuid')"); return true; } else { $err->raise("ftp",5); @@ -320,7 +322,7 @@ class m_ftp { $lo=$mem->user["login"]; $l=substr($lo,0,1); if (substr($dir,0,1)=="/") $dir=substr($dir,1); - $db->query("SELECT id FROM ftpusers WHERE homedir='/var/alternc/html/$l/$lo/$dir';"); + $db->query("SELECT id FROM ftpusers WHERE homedir='".getuserpath()."/$dir';"); if ($db->num_rows()) { $db->next_record(); return $db->f("id"); diff --git a/bureau/class/m_mysql.php b/bureau/class/m_mysql.php index be2138f8..5d5a8ab5 100644 --- a/bureau/class/m_mysql.php +++ b/bureau/class/m_mysql.php @@ -184,7 +184,7 @@ class m_mysql { */ function get_mysql_details($dbn) { global $db,$err,$bro,$mem,$cuid; - $root="/var/alternc/html/".substr($mem->user["login"],0,1)."/".$mem->user["login"]; + $root=getuserpath(); $err->log("mysql","get_mysql_details"); $dbname=$mem->user["login"].($dbn?"_":"").$dbn; $size=$this->get_db_size($dbname); diff --git a/bureau/class/m_sta2.php b/bureau/class/m_sta2.php index b4b7173f..b0da2d18 100644 --- a/bureau/class/m_sta2.php +++ b/bureau/class/m_sta2.php @@ -140,6 +140,7 @@ class m_sta2 { if ($db->num_rows()) { while ($db->next_record()) { // We skip /var/alternc/html/u/user + // FIXME: utiliser ALTERNC_HTML au lieu de /var/alternc/html/ preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)/", $db->f("folder"),$match); $r[]=array( "id"=>$db->f("id"), @@ -173,6 +174,7 @@ class m_sta2 { if ($db->num_rows()) { $db->next_record(); // We skip /var/alternc/html/u/user + // FIXME: utiliser ALTERNC_HTML au lieu de /var/alternc/html/ preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)/", $db->f("folder"),$match); return array( "id"=>$db->f("id"), @@ -209,9 +211,7 @@ class m_sta2 { if (substr($folder,0,1)=="/") { $folder=substr($folder,1); } - $lo=$mem->user["login"]; - $l=substr($lo,0,1); - $db->query("UPDATE stats2 SET folder='/var/alternc/html/$l/$lo/$folder', mid='$cuid' WHERE id='$id';"); + $db->query("UPDATE stats2 SET folder='".getuserpath()."/$folder', mid='$cuid' WHERE id='$id';"); return true; } @@ -254,10 +254,8 @@ class m_sta2 { if (substr($dir,0,1)=="/") { $dir=substr($dir,1); } - $lo=$mem->user["login"]; - $l=substr($lo,0,1); if ($quota->cancreate("sta2")) { - $db->query("INSERT INTO stats2 (hostname,folder,mid) VALUES ('$hostname','/var/alternc/html/$l/$lo/$dir','$cuid')"); + $db->query("INSERT INTO stats2 (hostname,folder,mid) VALUES ('$hostname','".getuserpath()."/$dir','$cuid')"); return true; } else { $err->raise("sta2",1);