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 ()
 Constructor. More...
 
 alternc_password_policy ()
 Password kind used in this class (hook for admin class) More...
 
 hook_menu ()
 hook function called by menu class to add menu to the left panel More...
 
 authip_class ()
 Return the values needed to activate security access. More...
 
 switch_enabled ($id, $status=null)
 Switch enabled status of an account. More...
 
 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...
 

Public Attributes

 $srv_name
 

Detailed Description

FTP account management class.

Definition at line 26 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 361 of file m_ftp.php.

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

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

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

445  {
446  global $db, $msg, $cuid;
447  $msg->log("ftp", "alternc_del_domain", $dom);
448  $db->query("DELETE FROM ftpusers WHERE uid= ? AND ( name LIKE ? OR name LIKE ?) ", array($cuid, $dom."\_%", $dom));
449  return true;
450  }
global $db
Definition: bootstrap.php:22
$msg
Definition: config.php:155
$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 457 of file m_ftp.php.

References $cuid, $db, and $msg.

457  {
458  global $db, $msg, $cuid;
459  $msg->log("ftp", "alternc_del_member");
460  $db->query("DELETE FROM ftpusers WHERE uid= ?", array($cuid));
461  return true;
462  }
global $db
Definition: bootstrap.php:22
$msg
Definition: config.php:155
$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 488 of file m_ftp.php.

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

488  {
489  global $db, $msg;
490  $msg->log("ftp", "export");
491  $f = $this->get_list();
492  $str = " <ftp>";
493  foreach ($f as $d => $v) {
494  $str.=" <login>" . ($v["login"]) . "</login>\n";
495  $str.=" <password>" . ($v["encrypted_password"]) . "</password>\n";
496  $str.=" <directory>" . ($v["dir"]) . "<directory>\n";
497  }
498  $str.=" </ftp>\n";
499  return $str;
500  }
global $db
Definition: bootstrap.php:22
$msg
Definition: config.php:155
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:143
$d
m_ftp::alternc_password_policy ( )

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

Definition at line 43 of file m_ftp.php.

43  {
44  return array("ftp" => "FTP accounts");
45  }
m_ftp::authip_class ( )

Return the values needed to activate security access.

See get_auth_class() in authip for more informations

Definition at line 88 of file m_ftp.php.

References $c, and get_list().

88  {
89  $c = Array();
90  $c['name'] = "FTP";
91  $c['protocol'] = "ftp";
92  $c['values'] = Array();
93 
94  $tt = $this->get_list();
95  if (empty($tt) || !is_array($tt)) {
96  return $c;
97  }
98  foreach ($this->get_list() as $v) {
99  $c['values'][$v['id']] = $v['login'];
100  }
101 
102  return $c;
103  }
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:143
$c
Definition: bootstrap.php:47
m_ftp::check_login (   $l)

Check if the login is fine (syntax)

Parameters
string$l

Definition at line 225 of file m_ftp.php.

References $msg.

Referenced by add_ftp(), and put_ftp_details().

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

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

338  {
339  global $db, $msg, $cuid;
340  $msg->log("ftp", "delete_ftp", $id);
341  $db->query("SELECT name FROM ftpusers WHERE id= ? and uid= ? ;", array($id, $cuid));
342  $db->next_record();
343  $name = $db->f("name");
344  if (!$name) {
345  $msg->raise("ERROR", "ftp", _("This FTP account does not exist"));
346  return false;
347  }
348  $db->query("DELETE FROM ftpusers WHERE id= ? ;", array($id));
349  return $name;
350  }
global $db
Definition: bootstrap.php:22
$msg
Definition: config.php:155
$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 172 of file m_ftp.php.

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

Referenced by switch_enabled().

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

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

Referenced by alternc_export_conf(), and authip_class().

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

hook function called by menu class to add menu to the left panel

Definition at line 52 of file m_ftp.php.

References $q.

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

471  {
472  global $db, $msg, $cuid;
473  $msg->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
$msg
Definition: config.php:155
$cuid
Definition: bootstrap.php:43
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 424 of file m_ftp.php.

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

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

Constructor.

Definition at line 34 of file m_ftp.php.

References variable_get().

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

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

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

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

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

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

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

252  {
253  $r = $this->prefix_list();
254  reset($r);
255  while (list($key, $val) = each($r)) {
256  if ($current == $val) {
257  $c = " selected=\"selected\"";
258  } else {
259  $c = "";
260  }
261  echo "<option$c>$val</option>";
262  }
263  return true;
264  }
$val
Definition: tempovars.php:15
$r
Definition: aws_add.php:75
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:209
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
$c
Definition: bootstrap.php:47
m_ftp::switch_enabled (   $id,
  $status = null 
)

Switch enabled status of an account.

Definition at line 109 of file m_ftp.php.

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

109  {
110  global $cuid, $db, $msg;
111  if (!$jj = $this->get_ftp_details($id)) {
112  $msg->raise("ERROR", 'ftp', _("This account do not exist or is not of this account"));
113  return false;
114  }
115  if ($status == null) {
116  if ($jj[0]['enabled'] == true) {
117  $status = 0;
118  } else {
119  $status = 1;
120  }
121  }
122  // Be sure what is in $status, in case of it was a parameter
123  $status = ($status ? 1 : 0);
124 
125  if (!$db->query("UPDATE ftpusers SET enabled = ? WHERE uid = ? AND id = ? ;", array($status, $cuid, $id))) {
126  $msg->raise("ERROR", 'ftp', _("Error during update"));
127  return false;
128  } else {
129  return true;
130  }
131  }
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:172
PR null
Definition: lang-css.js:1
$msg
Definition: config.php:155
$cuid
Definition: bootstrap.php:43
if(!isset($is_include)) if(!$key &&!$crt) $id

Member Data Documentation

m_ftp::$srv_name

Definition at line 28 of file m_ftp.php.


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