Alternc  latest
Alternc logiel libre pour l'hébergement
Ftp.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Ftp Api of AlternC, used by alternc-api package
5  */
7 
8  protected $ftp; // m_ftp instance
9 
10  function __construct($service) {
11  global $ftp;
12  parent::__construct($service);
13  $this->ftp = $ftp;
14  }
15 
16  /** API Method from legacy class method ftp->add_ftp()
17  * @param $options a hash with parameters transmitted to legacy call
18  * mandatory parameters: prefix, login, pass, dir
19  * @return Alternc_Api_Response whose content is the newly created UID
20  */
21  function add($options) {
22  $mandatory = array("prefix", "login", "pass", "dir");
23  $missing = "";
24  foreach ($mandatory as $key) {
25  if (!isset($options[$key])) {
26  $missing.=$key . " ";
27  }
28  }
29  if ($missing) {
30  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
31  }
32  $ftpid = $this->ftp->add_ftp($options["prefix"], $options["login"], $options["pass"], $options["dir"]);
33  if (!$ftpid) {
34  return $this->alterncLegacyErrorManager();
35  } else {
36  return new Alternc_Api_Response(array("content" => $ftpid));
37  }
38  }
39 
40  /** API Method from legacy class method ftp->put_ftp_details()
41  * @param $options a hash with parameters transmitted to legacy call
42  * mandatory parameters: id
43  * non-mandatory: prefix, login, pass, dir
44  * @return Alternc_Api_Response whose content is the updated UID
45  */
46  function update($options) {
47  $defaults = array("prefix", "login", "dir");
48  if (!isset($options["id"])) {
49  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: ID"));
50  }
51  $id = intval($options["id"]);
52  $old = $this->ftp->get_ftp_details($id);
53  if (!$old) {
54  return new Alternc_Api_Response(array("code" => self::ERR_NOT_FOUND, "message" => "FTP Account not found"));
55  }
56  foreach ($defaults as $key) {
57  if (!isset($options[$key])) {
58  $options[$key] = $old[$key];
59  }
60  }
61  if (!isset($options["pass"]))
62  $options["pass"] = "";
63  $result = $this->ftp->put_ftp_details($id, $options["prefix"], $options["login"], $options["pass"], $options["dir"]);
64  if (!$result) {
65  return $this->alterncLegacyErrorManager();
66  } else {
67  return new Alternc_Api_Response(array("content" => $result));
68  }
69  }
70 
71  /** API Method from legacy class method ftp->del_ftp()
72  * @param $options a hash with parameters transmitted to legacy call
73  * mandatory parameters: id
74  * @return Alternc_Api_Response TRUE if the FTP account has been deleted.
75  */
76  function del($options) {
77  if (!isset($options["id"])) {
78  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: ID"));
79  }
80  $result = $this->ftp->delete_ftp(intval($options["id"]));
81  if (!$result) {
82  return $this->alterncLegacyErrorManager();
83  } else {
84  return new Alternc_Api_Response(array("content" => true));
85  }
86  }
87 
88  /** API Method from legacy class method ftp->get_list()
89  * @param $options a hash with parameters transmitted to legacy call
90  * non-mandatory parameters:
91  * Any of: offset(int=0), count(int=+inf)
92  * @return Alternc_Api_Response An array with all matching FTP account informations as hashes
93  */
94  function find($options) {
95  $result = $this->ftp->get_list();
96  if (!$result) {
97  return $this->alterncLegacyErrorManager();
98  } else {
99  list($offset, $count) = $this->offsetAndCount($options, count($result));
100  if ($offset != -1 || $count != -1) {
101  $result = array_slice($result, $offset, $count);
102  }
103  return new Alternc_Api_Response(array("content" => $result));
104  }
105  }
106 
107  /** API Method from legacy class method ftp->is_ftp()
108  * @param $options a hash with parameters transmitted to legacy call
109  * mandatory parameters: DIR
110  * @return Alternc_Api_Response Integer the ID of the account in this folder, or FALSE
111  */
112  function isFtp($options) {
113  if (!isset($options["dir"])) {
114  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: DIR"));
115  }
116  $result = $this->ftp->is_ftp($options["dir"]);
117  if (!$result) {
118  return $this->alterncLegacyErrorManager();
119  } else {
120  return new Alternc_Api_Response(array("content" => $result));
121  }
122  }
123 
124 }
125 
126 // class Alternc_Api_Object_Ftp
Any Legacy AlternC Api should use this class as a parent to be able to handle properly the access rig...
Definition: Legacyobject.php:9
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class
offsetAndCount($options, $max)
ensure that offset & count are set properly from $options.
Ftp Api of AlternC, used by alternc-api package.
Definition: Ftp.php:6
add($options)
API Method from legacy class method ftp->add_ftp()
Definition: Ftp.php:21
isFtp($options)
API Method from legacy class method ftp->is_ftp()
Definition: Ftp.php:112
__construct($service)
Definition: Ftp.php:10
del($options)
API Method from legacy class method ftp->del_ftp()
Definition: Ftp.php:76
find($options)
API Method from legacy class method ftp->get_list()
Definition: Ftp.php:94
update($options)
API Method from legacy class method ftp->put_ftp_details()
Definition: Ftp.php:46
Standard Response object for the AlternC API.
Definition: Response.php:7
if(!isset($is_include)) if(! $key &&! $crt) $id
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14