Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
m_ftp Class Reference

Classe de gestion des comptes FTP de l'hébergé. More...

Public Member Functions

 m_ftp ()
 Constructeur.
 alternc_password_policy ()
 Password kind used in this class (hook for admin class)
 hook_menu ()
 authip_class ()
 switch_enabled ($id, $status=null)
 get_list ()
 Retourne la liste des comptes FTP du compte hébergé Retourne la liste des comptes FTP sous forme de tableau indexé de tableaus associatifs comme suit : $a["id"]= ID du compte ftp $a["login"]= Nom de login du compte $a["dir"]= Dossier relatif à la racine du compte de l'utilisateur.
 get_ftp_details ($id)
 Retourne les détails d'un compte FTP (voir get_list) Le tableau est celui du compte d'id spécifié
 prefix_list ()
 Retourne la liste des prefixes utilisables par le compte courant.
 check_login ($l)
 select_prefix_list ($current)
 Affiche (ECHO) la liste des prefixes disponibles sous forme de champs d'option Les champs sont affichés sous la forme <option>prefixe</option>...
 put_ftp_details ($id, $prefixe, $login, $pass, $dir)
 Modifie les paramètres du comptes FTP $id.
 delete_ftp ($id)
 Efface le compte ftp spécifié.
 add_ftp ($prefixe, $login, $pass, $dir)
 Crée un nouveau compte FTP.
 is_ftp ($dir)
 Retourne TRUE si $dir possède un compte FTP.
 alternc_del_domain ($dom)
 Fonction appellée par domains quand un domaine est supprimé pour le membre.
 alternc_del_member ()
 Fonction appellée par membres quand un membre est effacé.
 hook_quota_get ()
 Returns the used quota for the $name service for the current user.
 alternc_export_conf ()
 Exporte toutes les informations ftp du compte AlternC private EXPERIMENTAL 'sid' function ;)
 hook_upnp_list ()
 hook function called by AlternC-upnp to know which open tcp or udp ports this class requires or suggests

Data Fields

 $srv_name

Detailed Description

Classe de gestion des comptes FTP de l'hébergé.

Definition at line 29 of file m_ftp.php.

Member Function Documentation

add_ftp (   $prefixe,
  $login,
  $pass,
  $dir 
)

Crée un nouveau compte FTP.

Parameters
string$prefixePrefixe au login
string$loginLogin ftp (login=prefixe_login)
string$passMot de passe FTP
string$dirRépertoire racine du compte relatif à la racine du membre
Returns
boolean TRUE si le compte a été créé, FALSE sinon.

Definition at line 338 of file m_ftp.php.

References $cuid, $db, $err, $mem, $r, _md5cr(), check_login(), getuserpath(), and prefix_list().

{
global $mem,$db,$err,$quota,$bro,$cuid,$admin;
$err->log("ftp","add_ftp",$prefixe."_".$login);
$dir=$bro->convertabsolute($dir);
if (substr($dir,0,1)=="/") {
$dir=substr($dir,1);
}
$r=$this->prefix_list();
if (empty($pass)) {
$err->raise("ftp",_("Password can't be empty"));
return false;
}
if (!in_array($prefixe,$r) || $prefixe=="") {
$err->raise("ftp",_("The chosen prefix is not allowed"));
return false;
}
$full_login=$prefixe;
if ($login) $full_login.="_".$login;
if ( !$this->check_login($full_login) ) return false;
$db->query("SELECT count(*) AS cnt FROM ftpusers WHERE name='".$full_login."'");
$db->next_record();
if ($db->f("cnt")) {
$err->raise("ftp",_("This FTP account already exists"));
return false;
}
$db->query("SELECT login FROM membres WHERE uid='$cuid';");
$db->next_record();
$lo=$db->f("login");
$l=substr($lo,0,1);
$absolute=getuserpath()."/$dir";
if (!file_exists($absolute)) {
system("/bin/mkdir -p $absolute");
}
if (!is_dir($absolute)) {
$err->raise("ftp",_("The directory cannot be created"));
return false;
}
// Check this password against the password policy using common API :
if (is_callable(array($admin,"checkPolicy"))) {
if (!$admin->checkPolicy("ftp",$full_login,$pass)) {
return false; // The error has been raised by checkPolicy()
}
}
if ($quota->cancreate("ftp")) {
$encrypted_password = _md5cr($pass,strrev(microtime(true)));
$db->query("INSERT INTO ftpusers (name,password, encrypted_password,homedir,uid) VALUES ('".$full_login."', '', '$encrypted_password', '$absolute', '$cuid')");
return true;
} else {
$err->raise("ftp",_("Your FTP account quota is over. You cannot create more ftp accounts"));
return false;
}
}
alternc_del_domain (   $dom)

Fonction appellée par domains quand un domaine est supprimé pour le membre.

Parameters
string$domDomaine à détruire. private

Definition at line 418 of file m_ftp.php.

References $cuid, $db, $dom, and $err.

{
global $db,$err,$cuid;
$err->log("ftp","alternc_del_domain",$dom);
$db->query("DELETE FROM ftpusers WHERE uid='$cuid' AND ( name LIKE '$dom\_%' OR name LIKE '$dom') ");
return true;
}
alternc_del_member ( )

Fonction appellée par membres quand un membre est effacé.

Parameters
integer$uidNuméro de membre effacé. private

Definition at line 430 of file m_ftp.php.

References $cuid, $db, and $err.

{
global $db,$err,$cuid;
$err->log("ftp","alternc_del_member");
$db->query("DELETE FROM ftpusers WHERE uid='$cuid'");
return true;
}
alternc_export_conf ( )

Exporte toutes les informations ftp du compte AlternC private EXPERIMENTAL 'sid' function ;)

Definition at line 462 of file m_ftp.php.

References $d, $db, $err, and get_list().

{
global $db,$err;
$err->log("ftp","export");
$f=$this->get_list();
$str=" <ftp>";
foreach ($f as $d=>$v) {
$str.=" <login>".($v["login"])."</login>\n";
$str.=" <password>".($v["encrypted_password"])."</password>\n";
$str.=" <directory>".($v["dir"])."<directory>\n";
}
$str.=" </ftp>\n";
return $str;
}
alternc_password_policy ( )

Password kind used in this class (hook for admin class)

Definition at line 47 of file m_ftp.php.

{
return array("ftp"=>"FTP accounts");
}
authip_class ( )

Definition at line 86 of file m_ftp.php.

References $c, and get_list().

{
$c = Array();
$c['name']="FTP";
$c['protocol']="ftp";
$c['values']=Array();
$tt = $this->get_list();
if (empty($tt) || !is_array($tt)) return $c;
foreach ($this->get_list() as $v ) {
$c['values'][$v['id']]=$v['login'];
}
return $c;
}
check_login (   $l)

Definition at line 209 of file m_ftp.php.

References $err.

Referenced by add_ftp(), and put_ftp_details().

{
global $err;
// special chars and the max numbers of them allowed
// to be able to give a specific error
$vv = array('_'=>'1', ' '=>0);
foreach ($vv as $k=>$n) {
if (substr_count($l, $k) > $n ) { // if there is more than $n $k
$err->raise('ftp', sprintf(_("FTP login is incorrect: too many '%s'"), $k));
return false;
}
}
// Explicitly look for only allowed chars
if ( ! preg_match("/^[A-Za-z0-9_\.\-]+$/", $l) ) {
$err->raise('ftp', _("FTP login is incorrect"));
return false;
}
return true;
}
delete_ftp (   $id)

Efface le compte ftp spécifié.

Parameters
integer$idNuméro du compte FTP à supprimer.
Returns
boolean TRUE si le compte a été effacé, FALSE sinon.

Definition at line 315 of file m_ftp.php.

References $cuid, $db, and $err.

{
global $db,$err,$cuid;
$err->log("ftp","delete_ftp",$id);
$db->query("SELECT name FROM ftpusers WHERE id='$id' and uid='$cuid';");
$db->next_record();
$name=$db->f("name");
if (!$name) {
$err->raise("ftp",_("This FTP account does not exist"));
return false;
}
$db->query("DELETE FROM ftpusers WHERE id='$id'");
return $name;
}
get_ftp_details (   $id)

Retourne les détails d'un compte FTP (voir get_list) Le tableau est celui du compte d'id spécifié

Parameters
integer$idNuméro du compte dont on souhaite obtenir les détails
Returns
array Tableau associatif contenant les infos du comptes ftp

Definition at line 162 of file m_ftp.php.

References $cuid, $db, $err, $r, and getuserpath().

Referenced by switch_enabled().

{
global $db,$err,$cuid;
$err->log("ftp","get_ftp_details",$id);
$r=array();
$db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid='$cuid' AND id='$id';");
if ($db->num_rows()) {
$db->next_record();
$regexp="/^".preg_quote(getuserpath(),"/")."\/(.*)$/";
$tr=preg_match($regexp, $db->f("homedir"),$match);
$lg=explode("_",$db->f("name"));
if ((!is_array($lg)) || (count($lg)!=2)) {
$lg[0]=$db->f("name");
$lg[1]="";
}
$r[]=array(
"id"=>$db->f("id"),
"prefixe"=> $lg[0],
"login"=>$lg[1],
"dir"=>$match[1],
"enabled"=>$db->f("enabled")
);
return $r;
} else {
$err->raise("ftp",_("This FTP account does not exist"));
return false;
}
}
get_list ( )

Retourne la liste des comptes FTP du compte hébergé Retourne la liste des comptes FTP sous forme de tableau indexé de tableaus associatifs comme suit : $a["id"]= ID du compte ftp $a["login"]= Nom de login du compte $a["dir"]= Dossier relatif à la racine du compte de l'utilisateur.

Returns
array Retourne le tableau des comptes ou FALSE si une erreur s'est produite.

Definition at line 134 of file m_ftp.php.

References $cuid, $db, $err, and $r.

Referenced by alternc_export_conf(), and authip_class().

{
global $db,$err,$cuid, $bro;
$err->log("ftp","get_list");
$r=array();
$db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid='$cuid' ORDER BY name;");
if ($db->num_rows()) {
while ($db->next_record()) {
$r[]=array(
"id"=>$db->f("id"),
"login"=>$db->f("name"),
"enabled"=>$db->f("enabled"),
//"dir"=>$match[1]
"dir"=>$db->f("homedir")
);
}
return $r;
} else {
$err->raise("ftp",_("No FTP account found"));
return false;
}
}
hook_menu ( )

Definition at line 51 of file m_ftp.php.

References $q.

{
global $quota;
$q = $quota->getquota("ftp");
$obj = array(
'title' => _("FTP accounts"),
'ico' => 'images/ftp.png',
'link' => 'toggle',
'pos' => 60,
'links' => array(),
) ;
if ( $quota->cancreate("ftp") ) {
$obj['links'][] =
array (
'ico' => 'images/new.png',
'txt' => _("Create a new ftp account"),
'url' => "ftp_edit.php?create=1",
'class' => '',
);
}
if ( $q['u'] > 0 ) { // if there are some FTP accounts
$obj['links'][] =
array (
'txt' => _("FTP accounts list"),
'url' => "ftp_list.php"
);
}
return $obj;
}
hook_quota_get ( )

Returns the used quota for the $name service for the current user.

Parameters
$namestring name of the quota
Returns
integer the number of service used or false if an error occured private

Definition at line 444 of file m_ftp.php.

References $cuid, $db, $err, and $q.

{
global $db,$err,$cuid;
$err->log("ftp","getquota");
$q=Array("name"=>"ftp", "description"=>_("FTP accounts"), "used"=>0);
$db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE uid='$cuid'");
if ($db->next_record()) {
$q['used']=$db->f("cnt");
}
return $q;
}
hook_upnp_list ( )

hook function called by AlternC-upnp to know which open tcp or udp ports this class requires or suggests

Returns
array a key => value list of port protocol name mandatory values private

Definition at line 483 of file m_ftp.php.

{
return array(
"ftp" => array("port" => 21, "protocol" => "tcp", "mandatory" => 1),
);
}
is_ftp (   $dir)

Retourne TRUE si $dir possède un compte FTP.

Parameters
string$dirDossier à tester, relatif à la racine du compte courant
Returns
boolean retourne TRUE si $dir à un compte FTP, FALSE sinon.

Definition at line 398 of file m_ftp.php.

References $db, $err, $mem, and getuserpath().

{
global $mem,$db,$err;
$err->log("ftp","is_ftp",$dir);
$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='".getuserpath()."/$dir';");
if ($db->num_rows()) {
$db->next_record();
return $db->f("id");
} else {
return false;
}
}
m_ftp ( )

Constructeur.

Definition at line 37 of file m_ftp.php.

References variable_get().

{
global $L_FQDN;
$this->srv_name = variable_get('ftp_human_name', '%%FQDN%%','Human name for FTP server', array(array('desc'=>'Name','type'=>'string')));
}
prefix_list ( )

Retourne la liste des prefixes utilisables par le compte courant.

Returns
array tableau contenant la liste des prefixes (domaines + login) du compte actuel.

Definition at line 197 of file m_ftp.php.

References $cuid, $db, $mem, and $r.

Referenced by add_ftp(), put_ftp_details(), and select_prefix_list().

{
global $db,$mem,$cuid;
$r=array();
$r[]=$mem->user["login"];
$db->query("SELECT domaine FROM domaines WHERE compte='$cuid' ORDER BY domaine;");
while ($db->next_record()) {
$r[]=$db->f("domaine");
}
return $r;
}
put_ftp_details (   $id,
  $prefixe,
  $login,
  $pass,
  $dir 
)

Modifie les paramètres du comptes FTP $id.

Parameters
integer$idNuméro du compte dont on veut modifier les paramètres
string$prefixePrefixe du compte FTP
string$loginlogin ajouté au préfixe ($prefixe_$login)
string$passmot de passe
string$dirRépertoire racine du compte
Returns
boolean TRUE si le compte a été modifié, FALSE si une erreur est survenue.

Definition at line 256 of file m_ftp.php.

References $cuid, $db, $err, $mem, $r, _md5cr(), check_login(), getuserpath(), and prefix_list().

{
global $mem,$db,$err,$bro,$cuid,$admin;
$err->log("ftp","put_ftp_details",$id);
$db->query("SELECT count(*) AS cnt FROM ftpusers WHERE id='$id' and uid='$cuid';");
$db->next_record();
if (!$db->f("cnt")) {
$err->raise("ftp",_("This FTP account does not exist"));
return false;
}
$dir=$bro->convertabsolute($dir);
if (substr($dir,0,1)=="/") {
$dir=substr($dir,1);
}
$r=$this->prefix_list();
if (!in_array($prefixe,$r)) {
$err->raise("ftp",_("The chosen prefix is not allowed"));
return false;
}
$lo=$mem->user["login"];
$l=substr($lo,0,1);
$full_login=$prefixe;
if ($login) $full_login.="_".$login;
if (! $this->check_login($full_login) ) return false;
$db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE id!='$id' AND name='$full_login';");
$db->next_record();
if ($db->f("cnt")) {
$err->raise("ftp",_("This FTP account already exists"));
return false;
}
$absolute=getuserpath()."/$dir";
if (!file_exists($absolute)) {
system("/bin/mkdir -p $absolute");
}
if (!is_dir($absolute)) {
$err->raise("ftp",_("The directory cannot be created"));
return false;
}
if (trim($pass)) {
// Check this password against the password policy using common API :
if (is_callable(array($admin,"checkPolicy"))) {
if (!$admin->checkPolicy("ftp",$prefixe.$login,$pass)) {
return false; // The error has been raised by checkPolicy()
}
}
$encrypted_password = _md5cr($pass,strrev(microtime(true)));
$db->query("UPDATE ftpusers SET name='".$full_login."', password='', encrypted_password='$encrypted_password', homedir='$absolute', uid='$cuid' WHERE id='$id';");
} else {
$db->query("UPDATE ftpusers SET name='".$full_login."', homedir='$absolute', uid='$cuid' WHERE id='$id';");
}
return true;
}
select_prefix_list (   $current)

Affiche (ECHO) la liste des prefixes disponibles sous forme de champs d'option Les champs sont affichés sous la forme <option>prefixe</option>...

La valeur $current se voit affublée de la balise SELECTED.

Parameters
string$currentPrefixe sélectionné par défaut
Returns
boolean TRUE.

Definition at line 237 of file m_ftp.php.

References $c, $key, $r, $val, and prefix_list().

{
$r=$this->prefix_list();
reset($r);
while (list($key,$val)=each($r)) {
if ($current==$val) $c=" selected=\"selected\""; else $c="";
echo "<option$c>$val</option>";
}
return true;
}
switch_enabled (   $id,
  $status = null 
)

Definition at line 102 of file m_ftp.php.

References $cuid, $db, $err, get_ftp_details(), and true.

{
global $cuid, $db, $err;
if (! $jj = $this->get_ftp_details($id)) {
$err->raise('ftp', _("This account do not exist or is not of this account"));
return false;
}
if ( $status == null ){
if ($jj[0]['enabled'] == true ) { $status=0;}
else { $status=1; }
}
// Be sure what is in $status, in case of it was a parameter
$status = ($status?'true':'false');
if ( ! $db->query("UPDATE ftpusers SET enabled = $status WHERE uid = '$cuid' AND id = '$id' ;") ) {
$err->raise('ftp', _("Error during update"));
return false;
} else {
return true ;
}
}

Field Documentation

$srv_name

Definition at line 32 of file m_ftp.php.


The documentation for this class was generated from the following file: