Alternc  latest
Alternc logiel libre pour l'hébergement
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 @access 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 @access private EXPERIMENTAL 'sid' function ;) More...
 

Public Attributes

 $srv_proftpd
 

Detailed Description

FTP account management class.

Definition at line 26 of file m_ftp.php.

Member Function Documentation

◆ add_ftp()

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 359 of file m_ftp.php.

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

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

◆ alternc_del_domain()

m_ftp::alternc_del_domain (   $dom)

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

Parameters
string$domDomaine à detruire. @access private

Definition at line 443 of file m_ftp.php.

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

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

◆ alternc_del_member()

m_ftp::alternc_del_member ( )

Fonction appellee par membres quand un membre est efface @access private.

Definition at line 455 of file m_ftp.php.

455  {
456  global $db, $msg, $cuid;
457  $msg->log("ftp", "alternc_del_member");
458  $db->query("DELETE FROM ftpusers WHERE uid= ?", array($cuid));
459  return true;
460  }

References $cuid, $db, and $msg.

◆ alternc_export_conf()

m_ftp::alternc_export_conf ( )

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

Definition at line 486 of file m_ftp.php.

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

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

◆ alternc_password_policy()

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  }

◆ authip_class()

m_ftp::authip_class ( )

Return the values needed to activate security access.

See get_auth_class() in authip for more informations

Definition at line 86 of file m_ftp.php.

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  }
$c
Definition: bootstrap.php:47

References $c, and get_list().

◆ check_login()

m_ftp::check_login (   $l)

Check if the login is fine (syntax)

Parameters
string$l

Definition at line 223 of file m_ftp.php.

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

References $msg.

Referenced by add_ftp(), and put_ftp_details().

◆ delete_ftp()

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.

336  {
337  global $db, $msg, $cuid;
338  $msg->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  $msg->raise("ERROR", "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  }
if(!isset($is_include)) if(! $key &&! $crt) $id

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

◆ get_ftp_details()

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 170 of file m_ftp.php.

170  {
171  global $db, $msg, $cuid;
172  $msg->debug("ftp", "get_ftp_details", $id);
173  $r = array();
174  $db->query("SELECT id, name, homedir, enabled FROM ftpusers WHERE uid= ? AND id= ?;", array($cuid, $id));
175  if ($db->num_rows()) {
176  $db->next_record();
177 
178  $regexp = "/^" . preg_quote(getuserpath(), "/") . "\/(.*)$/";
179  $match = array();
180  preg_match($regexp, $db->f("homedir"), $match);
181 
182  $lg = explode("_", $db->f("name"));
183  if ((!is_array($lg)) || (count($lg) != 2)) {
184  $lg[0] = $db->f("name");
185  $lg[1] = "";
186  }
187  $r[] = array(
188  "id" => $db->f("id"),
189  "prefixe" => $lg[0],
190  "login" => $lg[1],
191  "dir" => $match[1],
192  "enabled" => $db->f("enabled")
193  );
194  return $r;
195  } else {
196  $msg->raise("ERROR", "ftp", _("This FTP account does not exist"));
197  return false;
198  }
199  }

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

Referenced by switch_enabled().

◆ get_list()

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 141 of file m_ftp.php.

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

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

Referenced by alternc_export_conf(), and authip_class().

◆ hook_menu()

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.

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

References $q.

◆ hook_quota_get()

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

Definition at line 469 of file m_ftp.php.

469  {
470  global $db, $msg, $cuid;
471  $msg->debug("ftp", "getquota");
472  $q = Array("name" => "ftp", "description" => _("FTP accounts"), "used" => 0);
473  $db->query("SELECT COUNT(*) AS cnt FROM ftpusers WHERE uid= ? ", array($cuid));
474  if ($db->next_record()) {
475  $q['used'] = $db->f("cnt");
476  }
477  return $q;
478  }

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

◆ is_ftp()

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 422 of file m_ftp.php.

422  {
423  global $db, $msg;
424  $msg->debug("ftp", "is_ftp", $dir);
425  if (substr($dir, 0, 1) == "/") {
426  $dir = substr($dir, 1);
427  }
428  $db->query("SELECT id FROM ftpusers WHERE homedir= ? ;", array( getuserpath() . "/" .$dir ));
429  if ($db->num_rows()) {
430  $db->next_record();
431  return $db->f("id");
432  } else {
433  return false;
434  }
435  }

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

◆ m_ftp()

m_ftp::m_ftp ( )

Constructor.

Definition at line 34 of file m_ftp.php.

34  {
35  global $L_FQDN;
36  $this->srv_proftpd = variable_get('fqdn_proftpd', $L_FQDN, 'Human name for FTP server. If you change it, launch reload-certs', array('desc' => 'Name', 'type' => 'string'));
37  }
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:85

References variable_get().

◆ prefix_list()

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 207 of file m_ftp.php.

207  {
208  global $db, $mem, $cuid;
209  $r = array();
210  $r[] = $mem->user["login"];
211  $db->query("SELECT domaine FROM domaines WHERE compte= ? ORDER BY domaine;", array($cuid));
212  while ($db->next_record()) {
213  $r[] = $db->f("domaine");
214  }
215  return $r;
216  }
$mem
Definition: bootstrap.php:71

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

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

◆ put_ftp_details()

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.

274  {
275  global $db, $msg, $bro, $cuid, $admin;
276  $msg->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  $msg->raise("ERROR", "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  $msg->raise("ERROR", "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  $msg->raise("ERROR", "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  $msg->raise("ERROR", "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 = _sha512cr($pass);
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  }

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

◆ select_prefix_list()

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.

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
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14

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

◆ switch_enabled()

m_ftp::switch_enabled (   $id,
  $status = null 
)

Switch enabled status of an account.

Definition at line 107 of file m_ftp.php.

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

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

Member Data Documentation

◆ $srv_proftpd

m_ftp::$srv_proftpd

Definition at line 28 of file m_ftp.php.


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