Genericité sur l'user dir, reste surement des bugs

This commit is contained in:
Alan Garcia 2012-08-21 17:04:24 +00:00
parent 0d04b6f719
commit 8f722bb00c
10 changed files with 41 additions and 35 deletions

View File

@ -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;

View File

@ -37,7 +37,7 @@ require_once("../class/config.php");
</div>
<?php
$MENUPATH="/var/alternc/bureau/admin/";
$MENUPATH=ALTERNC_PANEL."/admin/";
$file=file("/etc/alternc/menulist.txt", FILE_SKIP_EMPTY_LINES);
foreach($file as $v) {
$v=trim($v);

View File

@ -46,6 +46,12 @@ Merci de revenir plus tard.";
*/
ini_set('display_errors', true);
// Some constant
define('ALTERNC_HTML', "/var/alternc/html");
define('ALTERNC_PANEL', "/var/alternc/bureau");
define('ALTERNC_LOGS', "/var/alternc/logs");
define('ALTERNC_LOCALES', "/var/alternc/bureau/locales");
// 1. Get a semaphore id for the alternc magic number (18577)
$alternc_sem = sem_get ( 18577 );
// 2. Declare the shutdown function, that release the semaphore
@ -87,10 +93,10 @@ $host=getenv("HTTP_HOST");
/* Global variables (AlternC configuration) */
require_once(dirname(__FILE__)."/local.php");
/* PHPLIB inclusions : */
$root=$L_ALTERNC_LOC."/bureau/";
$root=ALTERNC_PANEL."/";
require_once($root."class/db_mysql.php");
require_once($root."class/functions.php");
require_once($root."/class/db_mysql.php");
require_once($root."/class/functions.php");
require_once($root."class/variables.php");
// Redirection si appel à https://(!fqdn)/

View File

@ -53,7 +53,7 @@ register_shutdown_function("alternc_shutdown");
sem_acquire( $alternc_sem );
/* PHPLIB inclusions : */
$root="/var/alternc/bureau/";
$root=ALTERNC_PANEL."/";
/* Server Domain Name */
$host=getenv("HTTP_HOST");
@ -98,7 +98,7 @@ closedir($c);
/* Language */
bindtextdomain("alternc", "/var/alternc/bureau/locales");
bindtextdomain("alternc", ALTERNC_LOCALES);
if (!$do_not_set_lang_env) {
// setlang is on the link at the login page

View File

@ -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

View File

@ -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);

View File

@ -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");

View File

@ -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");

View File

@ -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);

View File

@ -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);