Alternc  latest
Alternc logiel libre pour l'hébergement
 All Classes Namespaces Files Functions Variables Pages
m_ftp Class Reference

FTP account management class. More...

Public Member Functions

 m_ftp ()
 Constructeur. More...
 
 alternc_password_policy ()
 Password kind used in this class (hook for admin class) More...
 
 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. More...
 
 get_ftp_details ($id)
 Retourne les details d'un compte FTP (voir get_list) Le tableau est celui du compte d'id specifie. More...
 
 prefix_list ()
 Retourne la liste des prefixes utilisables par le compte courant. More...
 
 check_login ($l)
 Check if the login is fine (syntax) More...
 
 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>... More...
 
 put_ftp_details ($id, $prefixe, $login, $pass, $dir)
 Modifie les param�tres du comptes FTP $id. More...
 
 delete_ftp ($id)
 Efface le compte ftp specifie. More...
 
 add_ftp ($prefixe, $login, $pass, $dir)
 Cree un nouveau compte FTP. More...
 
 is_ftp ($dir)
 Retourne TRUE si $dir possee un compte FTP. More...
 
 alternc_del_domain ($dom)
 Fonction appellee par domains quand un domaine est supprime pour le membre. More...
 
 alternc_del_member ()
 Fonction appellee par membres quand un membre est efface private. More...
 
 hook_quota_get ()
 Returns the used quota for the $name service for the current user. More...
 
 alternc_export_conf ()
 Exporte toutes les informations ftp du compte AlternC private EXPERIMENTAL 'sid' function ;) More...
 
 hook_upnp_list ()
 hook function called by AlternC-upnp to know which open tcp or udp ports this class requires or suggests More...
 

Public Attributes

 $srv_name
 

Detailed Description

FTP account management class.

Definition at line 30 of file m_ftp.php.

Member Function Documentation

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

Cree un nouveau compte FTP.

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

Definition at line 360 of file m_ftp.php.

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

360  {
361  global $db, $err, $quota, $bro, $cuid, $admin;
362  $err->log("ftp", "add_ftp", $prefixe . "_" . $login);
363  $dir = $bro->convertabsolute($dir);
364  if (substr($dir, 0, 1) == "/") {
365  $dir = substr($dir, 1);
366  }
367  $r = $this->prefix_list();
368  if (empty($pass)) {
369  $err->raise("ftp", _("Password can't be empty"));
370  return false;
371  }
372  if (!in_array($prefixe, $r) || $prefixe == "") {
373  $err->raise("ftp", _("The chosen prefix is not allowed"));
374  return false;
375  }
376  $full_login = $prefixe;
377  if ($login) {
378  $full_login.="_" . $login;
379  }
380  if (!$this->check_login($full_login)) {
381  return false;
382  }
383  $db->query("SELECT count(*) AS cnt FROM ftpusers WHERE name= ? ;", array($full_login));
384  $db->next_record();
385  if ($db->f("cnt")) {
386  $err->raise("ftp", _("This FTP account already exists"));
387  return false;
388  }
389  $db->query("SELECT login FROM membres WHERE uid= ? ;", array($cuid));
390  $db->next_record();
391  $absolute = getuserpath() . "/$dir";
392  if (!file_exists($absolute)) {
393  system("/bin/mkdir -p $absolute"); // FIXME replace with action
394  }
395  if (!is_dir($absolute)) {
396  $err->raise("ftp", _("The directory cannot be created"));
397  return false;
398  }
399 
400  // Check this password against the password policy using common API :
401  if (is_callable(array($admin, "checkPolicy"))) {
402  if (!$admin->checkPolicy("ftp", $full_login, $pass)) {
403  return false; // The error has been raised by checkPolicy()
404  }
405  }
406 
407  if ($quota->cancreate("ftp")) {
408  $encrypted_password = _md5cr($pass, strrev(microtime(true)));
409  $db->query("INSERT INTO ftpusers (name,password, encrypted_password,homedir,uid) VALUES ( ?, '', ?, ?, ?)", array($full_login, $encrypted_password, $absolute, $cuid));
410  return true;
411  } else {
412  $err->raise("ftp", _("Your FTP account quota is over. You cannot create more ftp accounts"));
413  return false;
414  }
415  }
check_login($l)
Check if the login is fine (syntax)
Definition: m_ftp.php:221
$bro
Definition: bootstrap.php:151
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:77
_md5cr($pass, $salt="")
Hashe un mot de passe en clair en MD5 avec un salt al�atoire.
Definition: functions.php:513
$err
Definition: bootstrap.php:72
getuserpath($user=null)
get the home of the user
Definition: functions.php:318
$cuid
Definition: bootstrap.php:43
prefix_list()
Retourne la liste des prefixes utilisables par le compte courant.
Definition: m_ftp.php:205
m_ftp::alternc_del_domain (   $dom)

Fonction appellee par domains quand un domaine est supprime pour le membre.

Parameters
string$domDomaine à detruire. private

Definition at line 444 of file m_ftp.php.

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

444  {
445  global $db, $err, $cuid;
446  $err->log("ftp", "alternc_del_domain", $dom);
447  $db->query("DELETE FROM ftpusers WHERE uid= ? AND ( name LIKE ? OR name LIKE ?) ", array($cuid, $dom."\_%", $dom));
448  return true;
449  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$cuid
Definition: bootstrap.php:43
$dom
Definition: whois_test.php:10
m_ftp::alternc_del_member ( )

Fonction appellee par membres quand un membre est efface private.

Definition at line 456 of file m_ftp.php.

References $cuid, $db, and $err.

456  {
457  global $db, $err, $cuid;
458  $err->log("ftp", "alternc_del_member");
459  $db->query("DELETE FROM ftpusers WHERE uid= ?", array($cuid));
460  return true;
461  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$cuid
Definition: bootstrap.php:43
m_ftp::alternc_export_conf ( )

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

Definition at line 489 of file m_ftp.php.

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

489  {
490  global $db, $err;
491  $err->log("ftp", "export");
492  $f = $this->get_list();
493  $str = " <ftp>";
494  foreach ($f as $d => $v) {
495  $str.=" <login>" . ($v["login"]) . "</login>\n";
496  $str.=" <password>" . ($v["encrypted_password"]) . "</password>\n";
497  $str.=" <directory>" . ($v["dir"]) . "<directory>\n";
498  }
499  $str.=" </ftp>\n";
500  return $str;
501  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
get_list()
Retourne la liste des comptes FTP du compte h�berg� Retourne la liste des comptes FTP sous forme de...
Definition: m_ftp.php:139
$d
m_ftp::alternc_password_policy ( )

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

Definition at line 49 of file m_ftp.php.

49  {
50  return array("ftp" => "FTP accounts");
51  }
m_ftp::authip_class ( )

Definition at line 86 of file m_ftp.php.

References $c, and get_list().

86  {
87  $c = Array();
88  $c['name'] = "FTP";
89  $c['protocol'] = "ftp";
90  $c['values'] = Array();
91 
92  $tt = $this->get_list();
93  if (empty($tt) || !is_array($tt)) {
94  return $c;
95  }
96  foreach ($this->get_list() as $v) {
97  $c['values'][$v['id']] = $v['login'];
98  }
99 
100  return $c;
101  }
get_list()
Retourne la liste des comptes FTP du compte h�berg� Retourne la liste des comptes FTP sous forme de...
Definition: m_ftp.php:139
$c
Definition: bootstrap.php:47
m_ftp::check_login (   $l)

Check if the login is fine (syntax)

Parameters
string$l

Definition at line 221 of file m_ftp.php.

References $err.

Referenced by add_ftp(), and put_ftp_details().

221  {
222  global $err;
223 
224  // special chars and the max numbers of them allowed
225  // to be able to give a specific error
226  $vv = array('_' => '1', ' ' => 0);
227  foreach ($vv as $k => $n) {
228  if (substr_count($l, $k) > $n) { // if there is more than $n $k
229  $err->raise('ftp', sprintf(_("FTP login is incorrect: too many '%s'"), $k));
230  return false;
231  }
232  }
233 
234  // Explicitly look for only allowed chars
235  if (!preg_match("/^[A-Za-z0-9]+[A-Za-z0-9_\.\-]*$/", $l)) {
236  $err->raise('ftp', _("FTP login is incorrect"));
237  return false;
238  }
239  return true;
240  }
$err
Definition: bootstrap.php:72
m_ftp::delete_ftp (   $id)

Efface le compte ftp specifie.

Parameters
integer$idNumero du compte FTP a supprimer.
Returns
boolean TRUE si le compte a ete efface, FALSE sinon.

Definition at line 336 of file m_ftp.php.

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

336  {
337  global $db, $err, $cuid;
338  $err->log("ftp", "delete_ftp", $id);
339  $db->query("SELECT name FROM ftpusers WHERE id= ? and uid= ? ;", array($id, $cuid));
340  $db->next_record();
341  $name = $db->f("name");
342  if (!$name) {
343  $err->raise("ftp", _("This FTP account does not exist"));
344  return false;
345  }
346  $db->query("DELETE FROM ftpusers WHERE id= ? ;", array($id));
347  return $name;
348  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$cuid
Definition: bootstrap.php:43
if(!isset($is_include)) if(!$key &&!$crt) $id
m_ftp::get_ftp_details (   $id)

Retourne les details d'un compte FTP (voir get_list) Le tableau est celui du compte d'id specifie.

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

Definition at line 168 of file m_ftp.php.

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

Referenced by switch_enabled().

168  {
169  global $db, $err, $cuid;
170  $err->log("ftp", "get_ftp_details", $id);
171  $r = array();
172  $db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid= ? AND id= ?;", array($cuid, $id));
173  if ($db->num_rows()) {
174  $db->next_record();
175 
176  $regexp = "/^" . preg_quote(getuserpath(), "/") . "\/(.*)$/";
177  $match = array();
178  preg_match($regexp, $db->f("homedir"), $match);
179 
180  $lg = explode("_", $db->f("name"));
181  if ((!is_array($lg)) || (count($lg) != 2)) {
182  $lg[0] = $db->f("name");
183  $lg[1] = "";
184  }
185  $r[] = array(
186  "id" => $db->f("id"),
187  "prefixe" => $lg[0],
188  "login" => $lg[1],
189  "dir" => $match[1],
190  "enabled" => $db->f("enabled")
191  );
192  return $r;
193  } else {
194  $err->raise("ftp", _("This FTP account does not exist"));
195  return false;
196  }
197  }
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:77
$err
Definition: bootstrap.php:72
getuserpath($user=null)
get the home of the user
Definition: functions.php:318
$cuid
Definition: bootstrap.php:43
if(!isset($is_include)) if(!$key &&!$crt) $id
m_ftp::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

Definition at line 139 of file m_ftp.php.

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

Referenced by alternc_export_conf(), and authip_class().

139  {
140  global $db, $err, $cuid;
141  $err->log("ftp", "get_list");
142  $r = array();
143  $db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid= ? ORDER BY name;", array($cuid));
144  if ($db->num_rows()) {
145  while ($db->next_record()) {
146  $r[] = array(
147  "id" => $db->f("id"),
148  "login" => $db->f("name"),
149  "enabled" => $db->f("enabled"),
150  //"dir"=>$match[1]
151  "dir" => $db->f("homedir")
152  );
153  }
154  return $r;
155  } else {
156  $err->raise("ftp", _("No FTP account found"));
157  return array();
158  }
159  }
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:77
$err
Definition: bootstrap.php:72
$cuid
Definition: bootstrap.php:43
m_ftp::hook_menu ( )

Definition at line 53 of file m_ftp.php.

References $q.

53  {
54  global $quota;
55  $q = $quota->getquota("ftp");
56 
57  $obj = array(
58  'title' => _("FTP accounts"),
59  'ico' => 'images/ftp.png',
60  'link' => 'toggle',
61  'pos' => 60,
62  'links' => array(),
63  );
64 
65  if ($quota->cancreate("ftp")) {
66  $obj['links'][] = array(
67  'ico' => 'images/new.png',
68  'txt' => _("Create a new ftp account"),
69  'url' => "ftp_edit.php?create=1",
70  'class' => '',
71  );
72  }
73 
74  if ($q['u'] > 0) { // if there are some FTP accounts
75  $obj['links'][] = array(
76  'txt' => _("FTP accounts list"),
77  'url' => "ftp_list.php"
78  );
79  }
80 
81  return $obj;
82  }
m_ftp::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 471 of file m_ftp.php.

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

471  {
472  global $db, $err, $cuid;
473  $err->log("ftp", "getquota");
474  $q = Array("name" => "ftp", "description" => _("FTP accounts"), "used" => 0);
475  $db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE uid= ? ", array($cuid));
476  if ($db->next_record()) {
477  $q['used'] = $db->f("cnt");
478  }
479  return $q;
480  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$cuid
Definition: bootstrap.php:43
m_ftp::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 510 of file m_ftp.php.

510  {
511  return array(
512  "ftp" => array("port" => 21, "protocol" => "tcp", "mandatory" => 1),
513  );
514  }
m_ftp::is_ftp (   $dir)

Retourne TRUE si $dir possee un compte FTP.

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

Definition at line 423 of file m_ftp.php.

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

423  {
424  global $db, $err;
425  $err->log("ftp", "is_ftp", $dir);
426  if (substr($dir, 0, 1) == "/") {
427  $dir = substr($dir, 1);
428  }
429  $db->query("SELECT id FROM ftpusers WHERE homedir= ? ;", array( getuserpath() . "/" .$dir ));
430  if ($db->num_rows()) {
431  $db->next_record();
432  return $db->f("id");
433  } else {
434  return false;
435  }
436  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
getuserpath($user=null)
get the home of the user
Definition: functions.php:318
m_ftp::m_ftp ( )

Constructeur.

Definition at line 39 of file m_ftp.php.

References variable_get().

39  {
40  global $L_FQDN;
41  $this->srv_name = variable_get('ftp_human_name', $L_FQDN, 'Human name for FTP server', array('desc' => 'Name', 'type' => 'string'));
42  }
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:90
m_ftp::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 205 of file m_ftp.php.

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

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

205  {
206  global $db, $mem, $cuid;
207  $r = array();
208  $r[] = $mem->user["login"];
209  $db->query("SELECT domaine FROM domaines WHERE compte= ? ORDER BY domaine;", array($cuid));
210  while ($db->next_record()) {
211  $r[] = $db->f("domaine");
212  }
213  return $r;
214  }
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:77
$cuid
Definition: bootstrap.php:43
$mem
Definition: bootstrap.php:71
m_ftp::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 274 of file m_ftp.php.

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

274  {
275  global $db, $err, $bro, $cuid, $admin;
276  $err->log("ftp", "put_ftp_details", $id);
277  $db->query("SELECT count(*) AS cnt FROM ftpusers WHERE id= ? and uid= ?;", array($id, $cuid));
278  $db->next_record();
279  if (!$db->f("cnt")) {
280  $err->raise("ftp", _("This FTP account does not exist"));
281  return false;
282  }
283  $dir = $bro->convertabsolute($dir);
284  if (substr($dir, 0, 1) == "/") {
285  $dir = substr($dir, 1);
286  }
287  $r = $this->prefix_list();
288  if (!in_array($prefixe, $r)) {
289  $err->raise("ftp", _("The chosen prefix is not allowed"));
290  return false;
291  }
292 
293  $full_login = $prefixe;
294  if ($login) {
295  $full_login.="_" . $login;
296  }
297  if (!$this->check_login($full_login)) {
298  return false;
299  }
300  $db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE id!= ? AND name= ?;", array($id, $full_login));
301  $db->next_record();
302  if ($db->f("cnt")) {
303  $err->raise("ftp", _("This FTP account already exists"));
304  return false;
305  }
306  $absolute = getuserpath() . "/$dir";
307  if (!file_exists($absolute)) {
308  system("/bin/mkdir -p $absolute");
309  }
310  if (!is_dir($absolute)) {
311  $err->raise("ftp", _("The directory cannot be created"));
312  return false;
313  }
314  if (trim($pass)) {
315 
316  // Check this password against the password policy using common API :
317  if (is_callable(array($admin, "checkPolicy"))) {
318  if (!$admin->checkPolicy("ftp", $full_login, $pass)) {
319  return false; // The error has been raised by checkPolicy()
320  }
321  }
322  $encrypted_password = _md5cr($pass, strrev(microtime(true)));
323  $db->query("UPDATE ftpusers SET name= ? , password='', encrypted_password= ?, homedir= ?, uid= ? WHERE id= ?;", array($full_login, $encrypted_password, $absolute, $cuid, $id));
324  } else {
325  $db->query("UPDATE ftpusers SET name= ? , homedir= ? , uid= ? WHERE id= ? ;", array($full_login, $absolute, $cuid, $id));
326  }
327  return true;
328  }
check_login($l)
Check if the login is fine (syntax)
Definition: m_ftp.php:221
$bro
Definition: bootstrap.php:151
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:77
_md5cr($pass, $salt="")
Hashe un mot de passe en clair en MD5 avec un salt al�atoire.
Definition: functions.php:513
$err
Definition: bootstrap.php:72
getuserpath($user=null)
get the home of the user
Definition: functions.php:318
$cuid
Definition: bootstrap.php:43
prefix_list()
Retourne la liste des prefixes utilisables par le compte courant.
Definition: m_ftp.php:205
if(!isset($is_include)) if(!$key &&!$crt) $id
m_ftp::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 250 of file m_ftp.php.

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

250  {
251  $r = $this->prefix_list();
252  reset($r);
253  while (list($key, $val) = each($r)) {
254  if ($current == $val) {
255  $c = " selected=\"selected\"";
256  } else {
257  $c = "";
258  }
259  echo "<option$c>$val</option>";
260  }
261  return true;
262  }
$val
Definition: tempovars.php:15
$r
Definition: aws_add.php:77
x each(["height","width"], function(e, n){x.cssHooks[n]={get:function(e, r, i){return r?0===e.offsetWidth &&Xt.test(x.css(e,"display"))?x.swap(e, Qt, function(){return sn(e, n, i)}):sn(e, n, i):t}, set:function(e, t, r){var i=r &&Rt(e);return on(e, t, r?an(e, n, r, x.support.boxSizing &&"border-box"===x.css(e,"boxSizing",!1, i), i):0)}}})
prefix_list()
Retourne la liste des prefixes utilisables par le compte courant.
Definition: m_ftp.php:205
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
$c
Definition: bootstrap.php:47
m_ftp::switch_enabled (   $id,
  $status = null 
)

Definition at line 104 of file m_ftp.php.

References $cuid, $db, $err, $id, get_ftp_details(), and null.

104  {
105  global $cuid, $db, $err;
106  if (!$jj = $this->get_ftp_details($id)) {
107  $err->raise('ftp', _("This account do not exist or is not of this account"));
108  return false;
109  }
110  if ($status == null) {
111  if ($jj[0]['enabled'] == true) {
112  $status = 0;
113  } else {
114  $status = 1;
115  }
116  }
117 
118  // Be sure what is in $status, in case of it was a parameter
119  $status = ($status ? 'true' : 'false');
120 
121  if (!$db->query("UPDATE ftpusers SET enabled = ? WHERE uid = ? AND id = ? ;", array($status, $cuid, $id))) {
122  $err->raise('ftp', _("Error during update"));
123  return false;
124  } else {
125  return true;
126  }
127  }
global $db
Definition: bootstrap.php:22
get_ftp_details($id)
Retourne les details d'un compte FTP (voir get_list) Le tableau est celui du compte d'id specifie...
Definition: m_ftp.php:168
$err
Definition: bootstrap.php:72
PR null
Definition: lang-css.js:1
$cuid
Definition: bootstrap.php:43
if(!isset($is_include)) if(!$key &&!$crt) $id

Member Data Documentation

m_ftp::$srv_name

Definition at line 32 of file m_ftp.php.


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