@@ -16,351 +16,351 @@ |
||
| 16 | 16 | |
| 17 | 17 | abstract class AbstractBackend |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var string This is a small description for the backend. It will be shown in the settings UI. |
|
| 21 | - */ |
|
| 22 | - public $backendDescription = "This is a generic file backend."; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var string This is the name of backend that is visible to the user. |
|
| 26 | - */ |
|
| 27 | - public $backendDisplayName = "AbstractBackend"; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var string Version code of the backend implementation. |
|
| 31 | - */ |
|
| 32 | - public $backendVersion = "1.0"; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var string AccountID of the account that is using this backend. |
|
| 36 | - */ |
|
| 37 | - protected $accountID = null; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * This function will initialize internal variables of the backend. It will receive the values in the |
|
| 41 | - * $backend_config array. |
|
| 42 | - * |
|
| 43 | - * Example for the $backend_config array: |
|
| 44 | - * $backend_config["server_address"] |
|
| 45 | - * $backend_config["user"] |
|
| 46 | - * ... |
|
| 47 | - * |
|
| 48 | - * @param array $backend_config |
|
| 49 | - * @return void |
|
| 50 | - */ |
|
| 51 | - abstract public function init_backend($backend_config); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * This function will set the backend internal debug flag. Each backend will handle debugging by itself. |
|
| 55 | - * |
|
| 56 | - * @param bool $debug |
|
| 57 | - * @return void |
|
| 58 | - */ |
|
| 59 | - abstract public function set_debug($debug); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * This function opens the backend connection. For instance it will open a new ftp connection. |
|
| 63 | - * |
|
| 64 | - * @throws \Files\Backend\Exception |
|
| 65 | - * @return bool |
|
| 66 | - */ |
|
| 67 | - abstract public function open(); |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * This function will read a list of files and folders from the server. |
|
| 71 | - * The return value must look like this: |
|
| 72 | - * Array => ( |
|
| 73 | - * "path 1" => array( |
|
| 74 | - * "resourcetype" => "collection" or "file", |
|
| 75 | - * "getcontentlength" => size in bytes, |
|
| 76 | - * "getlastmodified" => date/time string, |
|
| 77 | - * "getcontenttype" => mime type (optional), |
|
| 78 | - * "quota-used-bytes" => size in bytes (optional), |
|
| 79 | - * "quota-available-bytes" => size in bytes (optional), |
|
| 80 | - * ), |
|
| 81 | - * "path 2" => array( |
|
| 82 | - * ... |
|
| 83 | - * ), |
|
| 84 | - * ): |
|
| 85 | - * |
|
| 86 | - * @param string $dir |
|
| 87 | - * @param bool $hidefirst |
|
| 88 | - * @throws \Files\Backend\Exception |
|
| 89 | - * @return array |
|
| 90 | - */ |
|
| 91 | - abstract public function ls($dir, $hidefirst = true); |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Creates a new directory on the server. |
|
| 95 | - * |
|
| 96 | - * @param string $dir |
|
| 97 | - * @throws \Files\Backend\Exception |
|
| 98 | - * @return bool |
|
| 99 | - */ |
|
| 100 | - abstract public function mkcol($dir); |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Deletes a files or folder from the backend. |
|
| 104 | - * |
|
| 105 | - * @param string $path |
|
| 106 | - * @throws \Files\Backend\Exception |
|
| 107 | - * @return bool |
|
| 108 | - */ |
|
| 109 | - abstract public function delete($path); |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Move a file or collection on the backend server (serverside). |
|
| 113 | - * If you set param $overwrite as true, the target will be overwritten. |
|
| 114 | - * |
|
| 115 | - * @param string $src_path Source path |
|
| 116 | - * @param string $dest_path Destination path |
|
| 117 | - * @param bool $overwrite Overwrite file if exists in $dest_path |
|
| 118 | - * @throws \Files\Backend\Exception |
|
| 119 | - * @return bool |
|
| 120 | - */ |
|
| 121 | - abstract public function move($src_path, $dst_path, $overwrite = false); |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Uploads the given $data to a new file in the backend. |
|
| 125 | - * |
|
| 126 | - * @param string $path |
|
| 127 | - * @param string $data |
|
| 128 | - * @throws \Files\Backend\Exception |
|
| 129 | - * @return bool |
|
| 130 | - */ |
|
| 131 | - abstract public function put($path, $data); |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Uploads a local file ($filename) to a new file in the backend. |
|
| 135 | - * |
|
| 136 | - * @param string $path |
|
| 137 | - * @param string $filename |
|
| 138 | - * @throws \Files\Backend\Exception |
|
| 139 | - * @return bool |
|
| 140 | - */ |
|
| 141 | - abstract public function put_file($path, $filename); |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Download a remote file to a buffer variable. |
|
| 145 | - * |
|
| 146 | - * @param string $path |
|
| 147 | - * @param string $buffer |
|
| 148 | - * @throws \Files\Backend\Exception |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - abstract public function get($path, &$buffer); |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Download a remote file to a local file. |
|
| 155 | - * |
|
| 156 | - * @param string $srcpath |
|
| 157 | - * @param string $localpath |
|
| 158 | - * @throws \Files\Backend\Exception |
|
| 159 | - * @return void |
|
| 160 | - */ |
|
| 161 | - abstract public function get_file($srcpath, $localpath); |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Duplicates a file on the backend server. |
|
| 165 | - * If you set param overwrite as true, the target will be overwritten. |
|
| 166 | - * |
|
| 167 | - * @param string $src_path |
|
| 168 | - * @param string $dst_path |
|
| 169 | - * @param bool $overwrite |
|
| 170 | - * @throws \Files\Backend\Exception |
|
| 171 | - * @return bool |
|
| 172 | - */ |
|
| 173 | - abstract public function copy_file($src_path, $dst_path, $overwrite = false); |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Duplicates a folder on the backend server. |
|
| 177 | - * If you set param overwrite as true, the target will be overwritten. |
|
| 178 | - * |
|
| 179 | - * @param string $src_path |
|
| 180 | - * @param string $dst_path |
|
| 181 | - * @param bool $overwrite |
|
| 182 | - * @throws \Files\Backend\Exception |
|
| 183 | - * @return bool |
|
| 184 | - */ |
|
| 185 | - abstract public function copy_coll($src_path, $dst_path, $overwrite = false); |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Gets path information from backend server for the first element |
|
| 189 | - * in the given path. |
|
| 190 | - * |
|
| 191 | - * Returned value: |
|
| 192 | - * array( |
|
| 193 | - * "resourcetype" => "collection" or "file", |
|
| 194 | - * "getcontentlength" => size in bytes, |
|
| 195 | - * "getlastmodified" => date/time string, |
|
| 196 | - * "getcontenttype" => mime type (optional), |
|
| 197 | - * "quota-used-bytes" => size in bytes (optional), |
|
| 198 | - * "quota-available-bytes" => size in bytes (optional), |
|
| 199 | - * ) |
|
| 200 | - * |
|
| 201 | - * @param string $path |
|
| 202 | - * @throws \Files\Backend\Exception |
|
| 203 | - * @return mixed |
|
| 204 | - */ |
|
| 205 | - abstract public function gpi($path); |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Checks if the given $path is a file. If so, this function returns true, otherwise it will |
|
| 209 | - * return false. |
|
| 210 | - * |
|
| 211 | - * @param string $path |
|
| 212 | - * @throws \Files\Backend\Exception |
|
| 213 | - * @return bool |
|
| 214 | - */ |
|
| 215 | - abstract public function is_file($path); |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Checks if the given $path is a folder. If so, this function returns true, otherwise it will |
|
| 219 | - * return false. |
|
| 220 | - * |
|
| 221 | - * @param string $path |
|
| 222 | - * @throws \Files\Backend\Exception |
|
| 223 | - * @return bool |
|
| 224 | - */ |
|
| 225 | - abstract public function is_dir($path); |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Checks if the given $path exists on the remote server. If so, this function returns true, otherwise it will |
|
| 229 | - * return false. |
|
| 230 | - * |
|
| 231 | - * @param string $path |
|
| 232 | - * @throws \Files\Backend\Exception |
|
| 233 | - * @return bool |
|
| 234 | - */ |
|
| 235 | - abstract public function exists($path); |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * This function will return an array with configuration values for the settings form. |
|
| 239 | - * |
|
| 240 | - * Example return value: |
|
| 241 | - * array( |
|
| 242 | - * "success" => true, |
|
| 243 | - * "metaData" => array( |
|
| 244 | - * "fields" => $this->formFields, |
|
| 245 | - * "formConfig" => $this->formConfig |
|
| 246 | - * ), |
|
| 247 | - * "data" => array( // here we can specify the default values. |
|
| 248 | - * "server_address" => "files.demo.com", |
|
| 249 | - * "server_port" => "80", |
|
| 250 | - * "server_path" => "/remote.php/webdav" |
|
| 251 | - * ), |
|
| 252 | - * ) |
|
| 253 | - * |
|
| 254 | - * @return array |
|
| 255 | - */ |
|
| 256 | - abstract public function getFormConfig(); |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * This function will return an array with configuration values for the settings form. |
|
| 260 | - * The returned value will also contain the data values for each form field. |
|
| 261 | - * |
|
| 262 | - * Example return value: |
|
| 263 | - * array( |
|
| 264 | - * "success" => true, |
|
| 265 | - * "metaData" => array( |
|
| 266 | - * "fields" => $this->formFields, |
|
| 267 | - * "formConfig" => $this->formConfig |
|
| 268 | - * ), |
|
| 269 | - * "data" => array( // here we can specify the default values. |
|
| 270 | - * "server_address" => "files.demo.com", |
|
| 271 | - * "server_port" => "80", |
|
| 272 | - * "server_path" => "/remote.php/webdav" |
|
| 273 | - * ), |
|
| 274 | - * ) |
|
| 275 | - * |
|
| 276 | - * @return array |
|
| 277 | - */ |
|
| 278 | - abstract public function getFormConfigWithData(); |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Returns a brief the description of the backend. |
|
| 282 | - * |
|
| 283 | - * @return string |
|
| 284 | - */ |
|
| 285 | - public function getDescription() |
|
| 286 | - { |
|
| 287 | - return $this->backendDescription; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * @return string |
|
| 292 | - */ |
|
| 293 | - public function getDisplayName() |
|
| 294 | - { |
|
| 295 | - return $this->backendDisplayName; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Returns the version/revision of the backend. |
|
| 301 | - * |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - public function getBackendVersion() |
|
| 305 | - { |
|
| 306 | - return $this->backendVersion; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Check if the given feature is supported by this backend. |
|
| 311 | - * |
|
| 312 | - * @param string $feature feature name. e.g. Quota or VersionInfo |
|
| 313 | - * |
|
| 314 | - * @return bool |
|
| 315 | - */ |
|
| 316 | - public function supports($feature) |
|
| 317 | - { |
|
| 318 | - $features = $this->getAvailableFeatures(); |
|
| 319 | - |
|
| 320 | - return in_array($feature, $features); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Returns all available features and their values. |
|
| 325 | - * |
|
| 326 | - * @return array |
|
| 327 | - */ |
|
| 328 | - public function getAvailableFeatures() |
|
| 329 | - { |
|
| 330 | - $interfaces = class_implements(get_class($this)); |
|
| 331 | - $features = array(); |
|
| 332 | - |
|
| 333 | - // remove namespace and interface prefix |
|
| 334 | - foreach ($interfaces as $interface) { |
|
| 335 | - $features[] = str_replace("Files\\Backend\\iFeature", "", $interface); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - return $features; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * This function gets called before the backend-account is deleted. |
|
| 343 | - * |
|
| 344 | - * @param $account |
|
| 345 | - */ |
|
| 346 | - public function beforeDeleteAccount($account) |
|
| 347 | - { |
|
| 348 | - // do nothing by default |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * @return string |
|
| 353 | - */ |
|
| 354 | - public function getAccountID() |
|
| 355 | - { |
|
| 356 | - return $this->accountID; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * @param string $accountID |
|
| 361 | - */ |
|
| 362 | - public function setAccountID($accountID) |
|
| 363 | - { |
|
| 364 | - $this->accountID = $accountID; |
|
| 365 | - } |
|
| 19 | + /** |
|
| 20 | + * @var string This is a small description for the backend. It will be shown in the settings UI. |
|
| 21 | + */ |
|
| 22 | + public $backendDescription = "This is a generic file backend."; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var string This is the name of backend that is visible to the user. |
|
| 26 | + */ |
|
| 27 | + public $backendDisplayName = "AbstractBackend"; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var string Version code of the backend implementation. |
|
| 31 | + */ |
|
| 32 | + public $backendVersion = "1.0"; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var string AccountID of the account that is using this backend. |
|
| 36 | + */ |
|
| 37 | + protected $accountID = null; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * This function will initialize internal variables of the backend. It will receive the values in the |
|
| 41 | + * $backend_config array. |
|
| 42 | + * |
|
| 43 | + * Example for the $backend_config array: |
|
| 44 | + * $backend_config["server_address"] |
|
| 45 | + * $backend_config["user"] |
|
| 46 | + * ... |
|
| 47 | + * |
|
| 48 | + * @param array $backend_config |
|
| 49 | + * @return void |
|
| 50 | + */ |
|
| 51 | + abstract public function init_backend($backend_config); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * This function will set the backend internal debug flag. Each backend will handle debugging by itself. |
|
| 55 | + * |
|
| 56 | + * @param bool $debug |
|
| 57 | + * @return void |
|
| 58 | + */ |
|
| 59 | + abstract public function set_debug($debug); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * This function opens the backend connection. For instance it will open a new ftp connection. |
|
| 63 | + * |
|
| 64 | + * @throws \Files\Backend\Exception |
|
| 65 | + * @return bool |
|
| 66 | + */ |
|
| 67 | + abstract public function open(); |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * This function will read a list of files and folders from the server. |
|
| 71 | + * The return value must look like this: |
|
| 72 | + * Array => ( |
|
| 73 | + * "path 1" => array( |
|
| 74 | + * "resourcetype" => "collection" or "file", |
|
| 75 | + * "getcontentlength" => size in bytes, |
|
| 76 | + * "getlastmodified" => date/time string, |
|
| 77 | + * "getcontenttype" => mime type (optional), |
|
| 78 | + * "quota-used-bytes" => size in bytes (optional), |
|
| 79 | + * "quota-available-bytes" => size in bytes (optional), |
|
| 80 | + * ), |
|
| 81 | + * "path 2" => array( |
|
| 82 | + * ... |
|
| 83 | + * ), |
|
| 84 | + * ): |
|
| 85 | + * |
|
| 86 | + * @param string $dir |
|
| 87 | + * @param bool $hidefirst |
|
| 88 | + * @throws \Files\Backend\Exception |
|
| 89 | + * @return array |
|
| 90 | + */ |
|
| 91 | + abstract public function ls($dir, $hidefirst = true); |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Creates a new directory on the server. |
|
| 95 | + * |
|
| 96 | + * @param string $dir |
|
| 97 | + * @throws \Files\Backend\Exception |
|
| 98 | + * @return bool |
|
| 99 | + */ |
|
| 100 | + abstract public function mkcol($dir); |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Deletes a files or folder from the backend. |
|
| 104 | + * |
|
| 105 | + * @param string $path |
|
| 106 | + * @throws \Files\Backend\Exception |
|
| 107 | + * @return bool |
|
| 108 | + */ |
|
| 109 | + abstract public function delete($path); |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Move a file or collection on the backend server (serverside). |
|
| 113 | + * If you set param $overwrite as true, the target will be overwritten. |
|
| 114 | + * |
|
| 115 | + * @param string $src_path Source path |
|
| 116 | + * @param string $dest_path Destination path |
|
| 117 | + * @param bool $overwrite Overwrite file if exists in $dest_path |
|
| 118 | + * @throws \Files\Backend\Exception |
|
| 119 | + * @return bool |
|
| 120 | + */ |
|
| 121 | + abstract public function move($src_path, $dst_path, $overwrite = false); |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Uploads the given $data to a new file in the backend. |
|
| 125 | + * |
|
| 126 | + * @param string $path |
|
| 127 | + * @param string $data |
|
| 128 | + * @throws \Files\Backend\Exception |
|
| 129 | + * @return bool |
|
| 130 | + */ |
|
| 131 | + abstract public function put($path, $data); |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Uploads a local file ($filename) to a new file in the backend. |
|
| 135 | + * |
|
| 136 | + * @param string $path |
|
| 137 | + * @param string $filename |
|
| 138 | + * @throws \Files\Backend\Exception |
|
| 139 | + * @return bool |
|
| 140 | + */ |
|
| 141 | + abstract public function put_file($path, $filename); |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Download a remote file to a buffer variable. |
|
| 145 | + * |
|
| 146 | + * @param string $path |
|
| 147 | + * @param string $buffer |
|
| 148 | + * @throws \Files\Backend\Exception |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + abstract public function get($path, &$buffer); |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Download a remote file to a local file. |
|
| 155 | + * |
|
| 156 | + * @param string $srcpath |
|
| 157 | + * @param string $localpath |
|
| 158 | + * @throws \Files\Backend\Exception |
|
| 159 | + * @return void |
|
| 160 | + */ |
|
| 161 | + abstract public function get_file($srcpath, $localpath); |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Duplicates a file on the backend server. |
|
| 165 | + * If you set param overwrite as true, the target will be overwritten. |
|
| 166 | + * |
|
| 167 | + * @param string $src_path |
|
| 168 | + * @param string $dst_path |
|
| 169 | + * @param bool $overwrite |
|
| 170 | + * @throws \Files\Backend\Exception |
|
| 171 | + * @return bool |
|
| 172 | + */ |
|
| 173 | + abstract public function copy_file($src_path, $dst_path, $overwrite = false); |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Duplicates a folder on the backend server. |
|
| 177 | + * If you set param overwrite as true, the target will be overwritten. |
|
| 178 | + * |
|
| 179 | + * @param string $src_path |
|
| 180 | + * @param string $dst_path |
|
| 181 | + * @param bool $overwrite |
|
| 182 | + * @throws \Files\Backend\Exception |
|
| 183 | + * @return bool |
|
| 184 | + */ |
|
| 185 | + abstract public function copy_coll($src_path, $dst_path, $overwrite = false); |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Gets path information from backend server for the first element |
|
| 189 | + * in the given path. |
|
| 190 | + * |
|
| 191 | + * Returned value: |
|
| 192 | + * array( |
|
| 193 | + * "resourcetype" => "collection" or "file", |
|
| 194 | + * "getcontentlength" => size in bytes, |
|
| 195 | + * "getlastmodified" => date/time string, |
|
| 196 | + * "getcontenttype" => mime type (optional), |
|
| 197 | + * "quota-used-bytes" => size in bytes (optional), |
|
| 198 | + * "quota-available-bytes" => size in bytes (optional), |
|
| 199 | + * ) |
|
| 200 | + * |
|
| 201 | + * @param string $path |
|
| 202 | + * @throws \Files\Backend\Exception |
|
| 203 | + * @return mixed |
|
| 204 | + */ |
|
| 205 | + abstract public function gpi($path); |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Checks if the given $path is a file. If so, this function returns true, otherwise it will |
|
| 209 | + * return false. |
|
| 210 | + * |
|
| 211 | + * @param string $path |
|
| 212 | + * @throws \Files\Backend\Exception |
|
| 213 | + * @return bool |
|
| 214 | + */ |
|
| 215 | + abstract public function is_file($path); |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Checks if the given $path is a folder. If so, this function returns true, otherwise it will |
|
| 219 | + * return false. |
|
| 220 | + * |
|
| 221 | + * @param string $path |
|
| 222 | + * @throws \Files\Backend\Exception |
|
| 223 | + * @return bool |
|
| 224 | + */ |
|
| 225 | + abstract public function is_dir($path); |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Checks if the given $path exists on the remote server. If so, this function returns true, otherwise it will |
|
| 229 | + * return false. |
|
| 230 | + * |
|
| 231 | + * @param string $path |
|
| 232 | + * @throws \Files\Backend\Exception |
|
| 233 | + * @return bool |
|
| 234 | + */ |
|
| 235 | + abstract public function exists($path); |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * This function will return an array with configuration values for the settings form. |
|
| 239 | + * |
|
| 240 | + * Example return value: |
|
| 241 | + * array( |
|
| 242 | + * "success" => true, |
|
| 243 | + * "metaData" => array( |
|
| 244 | + * "fields" => $this->formFields, |
|
| 245 | + * "formConfig" => $this->formConfig |
|
| 246 | + * ), |
|
| 247 | + * "data" => array( // here we can specify the default values. |
|
| 248 | + * "server_address" => "files.demo.com", |
|
| 249 | + * "server_port" => "80", |
|
| 250 | + * "server_path" => "/remote.php/webdav" |
|
| 251 | + * ), |
|
| 252 | + * ) |
|
| 253 | + * |
|
| 254 | + * @return array |
|
| 255 | + */ |
|
| 256 | + abstract public function getFormConfig(); |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * This function will return an array with configuration values for the settings form. |
|
| 260 | + * The returned value will also contain the data values for each form field. |
|
| 261 | + * |
|
| 262 | + * Example return value: |
|
| 263 | + * array( |
|
| 264 | + * "success" => true, |
|
| 265 | + * "metaData" => array( |
|
| 266 | + * "fields" => $this->formFields, |
|
| 267 | + * "formConfig" => $this->formConfig |
|
| 268 | + * ), |
|
| 269 | + * "data" => array( // here we can specify the default values. |
|
| 270 | + * "server_address" => "files.demo.com", |
|
| 271 | + * "server_port" => "80", |
|
| 272 | + * "server_path" => "/remote.php/webdav" |
|
| 273 | + * ), |
|
| 274 | + * ) |
|
| 275 | + * |
|
| 276 | + * @return array |
|
| 277 | + */ |
|
| 278 | + abstract public function getFormConfigWithData(); |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Returns a brief the description of the backend. |
|
| 282 | + * |
|
| 283 | + * @return string |
|
| 284 | + */ |
|
| 285 | + public function getDescription() |
|
| 286 | + { |
|
| 287 | + return $this->backendDescription; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + public function getDisplayName() |
|
| 294 | + { |
|
| 295 | + return $this->backendDisplayName; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Returns the version/revision of the backend. |
|
| 301 | + * |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public function getBackendVersion() |
|
| 305 | + { |
|
| 306 | + return $this->backendVersion; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Check if the given feature is supported by this backend. |
|
| 311 | + * |
|
| 312 | + * @param string $feature feature name. e.g. Quota or VersionInfo |
|
| 313 | + * |
|
| 314 | + * @return bool |
|
| 315 | + */ |
|
| 316 | + public function supports($feature) |
|
| 317 | + { |
|
| 318 | + $features = $this->getAvailableFeatures(); |
|
| 319 | + |
|
| 320 | + return in_array($feature, $features); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Returns all available features and their values. |
|
| 325 | + * |
|
| 326 | + * @return array |
|
| 327 | + */ |
|
| 328 | + public function getAvailableFeatures() |
|
| 329 | + { |
|
| 330 | + $interfaces = class_implements(get_class($this)); |
|
| 331 | + $features = array(); |
|
| 332 | + |
|
| 333 | + // remove namespace and interface prefix |
|
| 334 | + foreach ($interfaces as $interface) { |
|
| 335 | + $features[] = str_replace("Files\\Backend\\iFeature", "", $interface); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + return $features; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * This function gets called before the backend-account is deleted. |
|
| 343 | + * |
|
| 344 | + * @param $account |
|
| 345 | + */ |
|
| 346 | + public function beforeDeleteAccount($account) |
|
| 347 | + { |
|
| 348 | + // do nothing by default |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * @return string |
|
| 353 | + */ |
|
| 354 | + public function getAccountID() |
|
| 355 | + { |
|
| 356 | + return $this->accountID; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * @param string $accountID |
|
| 361 | + */ |
|
| 362 | + public function setAccountID($accountID) |
|
| 363 | + { |
|
| 364 | + $this->accountID = $accountID; |
|
| 365 | + } |
|
| 366 | 366 | } |
@@ -3,7 +3,7 @@ |
||
| 3 | 3 | |
| 4 | 4 | interface iFeatureQuota |
| 5 | 5 | { |
| 6 | - public function getQuotaBytesUsed($dir); |
|
| 6 | + public function getQuotaBytesUsed($dir); |
|
| 7 | 7 | |
| 8 | - public function getQuotaBytesAvailable($dir); |
|
| 8 | + public function getQuotaBytesAvailable($dir); |
|
| 9 | 9 | } |
| 10 | 10 | \ No newline at end of file |
@@ -10,48 +10,48 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Exception extends \Exception |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * The exception title to show as a message box title at client side. |
|
| 15 | - */ |
|
| 16 | - public $title = null; |
|
| 13 | + /** |
|
| 14 | + * The exception title to show as a message box title at client side. |
|
| 15 | + */ |
|
| 16 | + public $title = null; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @constructor |
|
| 20 | - * |
|
| 21 | - * @param string $message The error message |
|
| 22 | - * @param int $code The error code |
|
| 23 | - */ |
|
| 24 | - public function __construct($message, $code = 0) |
|
| 25 | - { |
|
| 26 | - parent::__construct($message, $code); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * @constructor |
|
| 20 | + * |
|
| 21 | + * @param string $message The error message |
|
| 22 | + * @param int $code The error code |
|
| 23 | + */ |
|
| 24 | + public function __construct($message, $code = 0) |
|
| 25 | + { |
|
| 26 | + parent::__construct($message, $code); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Overrides the toString method. |
|
| 31 | - * |
|
| 32 | - * @return string Error code and message |
|
| 33 | - */ |
|
| 34 | - public function __toString() |
|
| 35 | - { |
|
| 36 | - return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * Overrides the toString method. |
|
| 31 | + * |
|
| 32 | + * @return string Error code and message |
|
| 33 | + */ |
|
| 34 | + public function __toString() |
|
| 35 | + { |
|
| 36 | + return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Function sets title of an exception that will be sent to the client side |
|
| 41 | - * to show it to user. |
|
| 42 | - * @param string $title title of an exception. |
|
| 43 | - */ |
|
| 44 | - public function setTitle($title) |
|
| 45 | - { |
|
| 46 | - $this->title = $title; |
|
| 47 | - } |
|
| 39 | + /** |
|
| 40 | + * Function sets title of an exception that will be sent to the client side |
|
| 41 | + * to show it to user. |
|
| 42 | + * @param string $title title of an exception. |
|
| 43 | + */ |
|
| 44 | + public function setTitle($title) |
|
| 45 | + { |
|
| 46 | + $this->title = $title; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return string returns title that should be sent to client to display as a message box |
|
| 51 | - * title. |
|
| 52 | - */ |
|
| 53 | - public function getTitle() |
|
| 54 | - { |
|
| 55 | - return $this->title; |
|
| 56 | - } |
|
| 49 | + /** |
|
| 50 | + * @return string returns title that should be sent to client to display as a message box |
|
| 51 | + * title. |
|
| 52 | + */ |
|
| 53 | + public function getTitle() |
|
| 54 | + { |
|
| 55 | + return $this->title; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -7,32 +7,32 @@ |
||
| 7 | 7 | |
| 8 | 8 | class BackendCSSLoader extends AbstractCSSLoader |
| 9 | 9 | { |
| 10 | - function __construct() |
|
| 11 | - { |
|
| 12 | - $this->CSS_PATH = __DIR__ . "/css/"; |
|
| 13 | - } |
|
| 10 | + function __construct() |
|
| 11 | + { |
|
| 12 | + $this->CSS_PATH = __DIR__ . "/css/"; |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Returns a combined CSS String |
|
| 17 | - * |
|
| 18 | - * @param bool $debug |
|
| 19 | - * @return string |
|
| 20 | - */ |
|
| 21 | - public function get_combined_css($debug = false) |
|
| 22 | - { |
|
| 23 | - // Populate the list of directories to check against |
|
| 24 | - if (($directoryHandle = opendir($this->CSS_PATH)) !== FALSE) { |
|
| 25 | - while (($file = readdir($directoryHandle)) !== false) { |
|
| 26 | - // Make sure we're not dealing with a folder or a link to the parent directory |
|
| 27 | - if (is_dir($this->CSS_PATH . $file) || ($file == '.' || $file == '..') === true) { |
|
| 28 | - continue; |
|
| 29 | - } |
|
| 15 | + /** |
|
| 16 | + * Returns a combined CSS String |
|
| 17 | + * |
|
| 18 | + * @param bool $debug |
|
| 19 | + * @return string |
|
| 20 | + */ |
|
| 21 | + public function get_combined_css($debug = false) |
|
| 22 | + { |
|
| 23 | + // Populate the list of directories to check against |
|
| 24 | + if (($directoryHandle = opendir($this->CSS_PATH)) !== FALSE) { |
|
| 25 | + while (($file = readdir($directoryHandle)) !== false) { |
|
| 26 | + // Make sure we're not dealing with a folder or a link to the parent directory |
|
| 27 | + if (is_dir($this->CSS_PATH . $file) || ($file == '.' || $file == '..') === true) { |
|
| 28 | + continue; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - // Add file content to our buffer |
|
| 32 | - $this->cssBuffer .= file_get_contents($this->CSS_PATH . $file); |
|
| 33 | - } |
|
| 34 | - } |
|
| 31 | + // Add file content to our buffer |
|
| 32 | + $this->cssBuffer .= file_get_contents($this->CSS_PATH . $file); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - return $this->cssBuffer; |
|
| 37 | - } |
|
| 36 | + return $this->cssBuffer; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -23,1083 +23,1083 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class Backend extends AbstractBackend implements iFeatureQuota, iFeatureVersionInfo |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * Error codes |
|
| 28 | - * see @parseErrorCodeToMessage for description |
|
| 29 | - */ |
|
| 30 | - const WD_ERR_UNAUTHORIZED = 401; |
|
| 31 | - const WD_ERR_FORBIDDEN = 403; |
|
| 32 | - const WD_ERR_NOTFOUND = 404; |
|
| 33 | - const WD_ERR_NOTALLOWED = 405; |
|
| 34 | - const WD_ERR_TIMEOUT = 408; |
|
| 35 | - const WD_ERR_LOCKED = 423; |
|
| 36 | - const WD_ERR_FAILED_DEPENDENCY = 423; |
|
| 37 | - const WD_ERR_INTERNAL = 500; |
|
| 38 | - const WD_ERR_UNREACHABLE = 800; |
|
| 39 | - const WD_ERR_TMP = 801; |
|
| 40 | - const WD_ERR_FEATURES = 802; |
|
| 41 | - const WD_ERR_NO_CURL = 803; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Configuration data for the extjs metaform. |
|
| 45 | - */ |
|
| 46 | - protected $formConfig; |
|
| 47 | - protected $formFields; |
|
| 48 | - protected $metaConfig; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var boolean debugging flag, if true, debugging is enabled |
|
| 52 | - */ |
|
| 53 | - var $debug = false; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var int webdav server port |
|
| 57 | - */ |
|
| 58 | - var $port = 80; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var string hostname or ip |
|
| 62 | - */ |
|
| 63 | - var $server = "localhost"; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var string global path prefix for all requests |
|
| 67 | - */ |
|
| 68 | - var $path = "/webdav.php"; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var boolean if true, ssl is used |
|
| 72 | - */ |
|
| 73 | - var $ssl = false; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var boolean allow self signed certificates |
|
| 77 | - */ |
|
| 78 | - var $allowselfsigned = true; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @var string the username |
|
| 82 | - */ |
|
| 83 | - var $user = ""; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @var string the password |
|
| 87 | - */ |
|
| 88 | - var $pass = ""; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @var FilesWebDavClient the SabreDAV client object. |
|
| 92 | - */ |
|
| 93 | - var $sabre_client; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @constructor |
|
| 97 | - */ |
|
| 98 | - function __construct() |
|
| 99 | - { |
|
| 100 | - |
|
| 101 | - // initialization |
|
| 102 | - $this->debug = PLUGIN_FILESBROWSER_LOGLEVEL === "DEBUG" ? true : false; |
|
| 103 | - |
|
| 104 | - $this->init_form(); |
|
| 105 | - |
|
| 106 | - // set backend description |
|
| 107 | - $this->backendDescription = _("With this backend, you can connect to any WebDAV server."); |
|
| 108 | - |
|
| 109 | - // set backend display name |
|
| 110 | - $this->backendDisplayName = "Webdav"; |
|
| 111 | - |
|
| 112 | - // set backend version |
|
| 113 | - // TODO: this should be changed on every release |
|
| 114 | - $this->backendVersion = "3.0"; |
|
| 115 | - |
|
| 116 | - // Backend name used in translations |
|
| 117 | - $this->backendTransName = _('Files WebDAV Backend: '); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Initialise form fields |
|
| 122 | - */ |
|
| 123 | - private function init_form() |
|
| 124 | - { |
|
| 125 | - $this->formConfig = array( |
|
| 126 | - "labelAlign" => "left", |
|
| 127 | - "columnCount" => 1, |
|
| 128 | - "labelWidth" => 80, |
|
| 129 | - "defaults" => array( |
|
| 130 | - "width" => 292 |
|
| 131 | - ) |
|
| 132 | - ); |
|
| 133 | - |
|
| 134 | - $this->formFields = array( |
|
| 135 | - array( |
|
| 136 | - "name" => "server_address", |
|
| 137 | - "fieldLabel" => _('Server address'), |
|
| 138 | - "editor" => array( |
|
| 139 | - "allowBlank" => false |
|
| 140 | - ) |
|
| 141 | - ), |
|
| 142 | - array( |
|
| 143 | - "name" => "server_port", |
|
| 144 | - "fieldLabel" => _('Server port'), |
|
| 145 | - "editor" => array( |
|
| 146 | - "ref" => "../../portField", |
|
| 147 | - "allowBlank" => false |
|
| 148 | - ) |
|
| 149 | - ), |
|
| 150 | - array( |
|
| 151 | - "name" => "server_ssl", |
|
| 152 | - "fieldLabel" => _('Use SSL'), |
|
| 153 | - "editor" => array( |
|
| 154 | - "xtype" => "checkbox", |
|
| 155 | - "listeners" => array( |
|
| 156 | - "check" => "Zarafa.plugins.files.data.Actions.onCheckSSL" // this javascript function will be called! |
|
| 157 | - ) |
|
| 158 | - ) |
|
| 159 | - ), |
|
| 160 | - array( |
|
| 161 | - "name" => "server_path", |
|
| 162 | - "fieldLabel" => _('Webdav base path'), |
|
| 163 | - "editor" => array( |
|
| 164 | - ) |
|
| 165 | - ), |
|
| 166 | - array( |
|
| 167 | - "name" => "user", |
|
| 168 | - "fieldLabel" => _('Username'), |
|
| 169 | - "editor" => array( |
|
| 170 | - "ref" => "../../usernameField" |
|
| 171 | - ) |
|
| 172 | - ), |
|
| 173 | - array( |
|
| 174 | - "name" => "password", |
|
| 175 | - "fieldLabel" => _('Password'), |
|
| 176 | - "editor" => array( |
|
| 177 | - "ref" => "../../passwordField", |
|
| 178 | - "inputType" => "password" |
|
| 179 | - ) |
|
| 180 | - ), |
|
| 181 | - array( |
|
| 182 | - "name" => "use_grommunio_credentials", |
|
| 183 | - "fieldLabel" => _('Use grommunio credentials'), |
|
| 184 | - "editor" => array( |
|
| 185 | - "xtype" => "checkbox", |
|
| 186 | - "listeners" => array( |
|
| 187 | - "check" => "Zarafa.plugins.files.data.Actions.onCheckCredentials" // this javascript function will be called! |
|
| 188 | - ) |
|
| 189 | - ) |
|
| 190 | - ), |
|
| 191 | - ); |
|
| 192 | - |
|
| 193 | - $this->metaConfig = array( |
|
| 194 | - "success" => true, |
|
| 195 | - "metaData" => array( |
|
| 196 | - "fields" => $this->formFields, |
|
| 197 | - "formConfig" => $this->formConfig |
|
| 198 | - ), |
|
| 199 | - "data" => array( // here we can specify the default values. |
|
| 200 | - "server_address" => "files.demo.com", |
|
| 201 | - "server_port" => "80", |
|
| 202 | - "server_path" => "/remote.php/webdav" |
|
| 203 | - ) |
|
| 204 | - ); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Initialize backend from $backend_config array |
|
| 209 | - * @param $backend_config |
|
| 210 | - */ |
|
| 211 | - public function init_backend($backend_config) |
|
| 212 | - { |
|
| 213 | - $this->set_server($backend_config["server_address"]); |
|
| 214 | - $this->set_port($backend_config["server_port"]); |
|
| 215 | - $this->set_base($backend_config["server_path"]); |
|
| 216 | - $this->set_ssl($backend_config["server_ssl"]); |
|
| 217 | - |
|
| 218 | - // set user and password |
|
| 219 | - if ($backend_config["use_grommunio_credentials"] === FALSE) { |
|
| 220 | - $this->set_user($backend_config["user"]); |
|
| 221 | - $this->set_pass($backend_config["password"]); |
|
| 222 | - } else { |
|
| 223 | - // For backward compatibility we will check if the Encryption store exists. If not, |
|
| 224 | - // we will fall back to the old way of retrieving the password from the session. |
|
| 225 | - if ( class_exists('EncryptionStore') ) { |
|
| 226 | - // Get the username and password from the Encryption store |
|
| 227 | - $encryptionStore = \EncryptionStore::getInstance(); |
|
| 228 | - $this->set_user($encryptionStore->get('username')); |
|
| 229 | - $this->set_pass($encryptionStore->get('password')); |
|
| 230 | - } else { |
|
| 231 | - $this->set_user($GLOBALS['mapisession']->getUserName()); |
|
| 232 | - $password = $_SESSION['password']; |
|
| 233 | - if(function_exists('openssl_decrypt')) { |
|
| 234 | - $this->set_pass(openssl_decrypt($password, "des-ede3-cbc", PASSWORD_KEY, 0, PASSWORD_IV)); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Set webdav server. FQN or IP address. |
|
| 242 | - * |
|
| 243 | - * @param string $server hostname or ip of the ftp server |
|
| 244 | - * |
|
| 245 | - * @return void |
|
| 246 | - */ |
|
| 247 | - public function set_server($server) |
|
| 248 | - { |
|
| 249 | - $this->server = $server; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Set base path |
|
| 254 | - * |
|
| 255 | - * @param string $pp the global path prefix |
|
| 256 | - * |
|
| 257 | - * @return void |
|
| 258 | - */ |
|
| 259 | - public function set_base($pp) |
|
| 260 | - { |
|
| 261 | - $this->path = $pp; |
|
| 262 | - $this->log('Base path set to ' . $this->path); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Set ssl |
|
| 267 | - * |
|
| 268 | - * @param int /bool $ssl (1 = true, 0 = false) |
|
| 269 | - * |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - public function set_ssl($ssl) |
|
| 273 | - { |
|
| 274 | - $this->ssl = $ssl ? true : false; |
|
| 275 | - $this->log('SSL extension was set to ' . $this->ssl); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Allow self signed certificates - unimplemented |
|
| 280 | - * |
|
| 281 | - * @param bool $allowselfsigned Allow self signed certificates. Not yet implemented. |
|
| 282 | - * |
|
| 283 | - * @return void |
|
| 284 | - */ |
|
| 285 | - public function set_selfsigned($allowselfsigned) |
|
| 286 | - { |
|
| 287 | - $this->allowselfsigned = $allowselfsigned; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Set tcp port of webdav server. Default is 80. |
|
| 292 | - * |
|
| 293 | - * @param int $port the port of the ftp server |
|
| 294 | - * |
|
| 295 | - * @return void |
|
| 296 | - */ |
|
| 297 | - public function set_port($port) |
|
| 298 | - { |
|
| 299 | - $this->port = $port; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * set user name for authentication |
|
| 304 | - * |
|
| 305 | - * @param string $user username |
|
| 306 | - * |
|
| 307 | - * @return void |
|
| 308 | - */ |
|
| 309 | - public function set_user($user) |
|
| 310 | - { |
|
| 311 | - $this->user = $user; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Set password for authentication |
|
| 316 | - * |
|
| 317 | - * @param string $pass password |
|
| 318 | - * |
|
| 319 | - * @return void |
|
| 320 | - */ |
|
| 321 | - public function set_pass($pass) |
|
| 322 | - { |
|
| 323 | - $this->pass = $pass; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * set debug on (1) or off (0). |
|
| 328 | - * produces a lot of debug messages in webservers error log if set to on (1). |
|
| 329 | - * |
|
| 330 | - * @param boolean $debug enable or disable debugging |
|
| 331 | - * |
|
| 332 | - * @return void |
|
| 333 | - */ |
|
| 334 | - public function set_debug($debug) |
|
| 335 | - { |
|
| 336 | - $this->debug = $debug; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Opens the connection to the webdav server. |
|
| 341 | - * |
|
| 342 | - * @throws BackendException if connection is not successful |
|
| 343 | - * @return boolean true if action succeeded |
|
| 344 | - */ |
|
| 345 | - public function open() |
|
| 346 | - { |
|
| 347 | - |
|
| 348 | - // check if curl is available |
|
| 349 | - $serverHasCurl = function_exists('curl_version'); |
|
| 350 | - if (!$serverHasCurl) { |
|
| 351 | - $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_NO_CURL), 500); |
|
| 352 | - $e->setTitle($this->backendTransName . _('PHP-CURL is not installed')); |
|
| 353 | - throw $e; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - $davsettings = array( |
|
| 357 | - 'baseUri' => $this->webdavUrl(), |
|
| 358 | - 'userName' => $this->user, |
|
| 359 | - 'password' => $this->pass, |
|
| 360 | - 'authType' => \Sabre\DAV\Client::AUTH_BASIC, |
|
| 361 | - ); |
|
| 362 | - |
|
| 363 | - try { |
|
| 364 | - $this->sabre_client = new FilesWebDavClient($davsettings); |
|
| 365 | - $this->sabre_client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, !$this->allowselfsigned); |
|
| 366 | - |
|
| 367 | - return true; |
|
| 368 | - } catch (Exception $e) { |
|
| 369 | - $this->log('Failed to open: ' . $e->getMessage()); |
|
| 370 | - if (intval($e->getHTTPCode()) == 401) { |
|
| 371 | - $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_UNAUTHORIZED), $e->getHTTPCode()); |
|
| 372 | - $e->setTitle($this->backendTransName . _('Access denied')); |
|
| 373 | - throw $e; |
|
| 374 | - } else { |
|
| 375 | - $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_UNREACHABLE), $e->getHTTPCode()); |
|
| 376 | - $e->setTitle($this->backendTransName . _('Connection failed')); |
|
| 377 | - throw $e; |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * show content of a directory |
|
| 384 | - * |
|
| 385 | - * @param string $path directory path |
|
| 386 | - * @param boolean $hidefirst Optional parameter to hide the root entry. Default true |
|
| 387 | - * |
|
| 388 | - * @throws BackendException if request is not successful |
|
| 389 | - * |
|
| 390 | - * @return mixed array with directory content |
|
| 391 | - */ |
|
| 392 | - public function ls($dir, $hidefirst = true) |
|
| 393 | - { |
|
| 394 | - $time_start = microtime(true); |
|
| 395 | - $dir = $this->removeSlash($dir); |
|
| 396 | - $lsdata = array(); |
|
| 397 | - $this->log("[LS] start for dir: $dir"); |
|
| 398 | - try { |
|
| 399 | - $response = $this->sabre_client->propFind($dir, array( |
|
| 400 | - '{http://owncloud.org/ns}fileid', |
|
| 401 | - '{DAV:}resourcetype', |
|
| 402 | - '{DAV:}getcontentlength', |
|
| 403 | - '{DAV:}getlastmodified', |
|
| 404 | - '{DAV:}getcontenttype', |
|
| 405 | - '{DAV:}quota-used-bytes', |
|
| 406 | - '{DAV:}quota-available-bytes', |
|
| 407 | - ), 1); |
|
| 408 | - $this->log("[LS] backend fetched in: " . (microtime(true) - $time_start) . " seconds."); |
|
| 409 | - |
|
| 410 | - foreach ($response as $name => $fields) { |
|
| 411 | - |
|
| 412 | - if ($hidefirst) { |
|
| 413 | - $hidefirst = false; // skip the first line - its the requested dir itself |
|
| 414 | - continue; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $name = substr($name, strlen($this->path)); // skip the webdav path |
|
| 418 | - $name = urldecode($name); |
|
| 419 | - |
|
| 420 | - // Always fallback to a file resourceType |
|
| 421 | - $type = "file"; |
|
| 422 | - if (isset($fields['{DAV:}resourcetype'])) { |
|
| 423 | - $value = $fields['{DAV:}resourcetype']->getValue(); |
|
| 424 | - if (!empty($value) && $value[0] === "{DAV:}collection") { |
|
| 425 | - $type = "collection"; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - $lsdata[$name] = array( |
|
| 430 | - "fileid" => isset($fields["{http://owncloud.org/ns}fileid"]) ? $fields["{http://owncloud.org/ns}fileid"] : '-1', |
|
| 431 | - "resourcetype" => $type, |
|
| 432 | - "getcontentlength" => isset($fields["{DAV:}getcontentlength"]) ? $fields["{DAV:}getcontentlength"] : null, |
|
| 433 | - "getlastmodified" => isset($fields["{DAV:}getlastmodified"]) ? $fields["{DAV:}getlastmodified"] : null, |
|
| 434 | - "getcontenttype" => isset($fields["{DAV:}getcontenttype"]) ? $fields["{DAV:}getcontenttype"] : null, |
|
| 435 | - "quota-used-bytes" => isset($fields["{DAV:}quota-used-bytes"]) ? $fields["{DAV:}quota-used-bytes"] : null, |
|
| 436 | - "quota-available-bytes" => isset($fields["{DAV:}quota-available-bytes"]) ? $fields["{DAV:}quota-available-bytes"] : null, |
|
| 437 | - ); |
|
| 438 | - } |
|
| 439 | - $time_end = microtime(true); |
|
| 440 | - $time = $time_end - $time_start; |
|
| 441 | - $this->log("[LS] done in $time seconds"); |
|
| 442 | - |
|
| 443 | - return $lsdata; |
|
| 444 | - |
|
| 445 | - } catch (ClientException $e) { |
|
| 446 | - $this->log('ls sabre ClientException: ' . $e->getMessage()); |
|
| 447 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 448 | - $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 449 | - throw $e; |
|
| 450 | - } catch (Exception $e) { |
|
| 451 | - $this->log('ls general exception: ' . $e->getMessage() . " [" . $e->getHTTPCode() . "]"); |
|
| 452 | - // THIS IS A FIX FOR OWNCLOUD - It does return 500 instead of 401... |
|
| 453 | - $err_code = $e->getHTTPCode(); |
|
| 454 | - // check if code is 500 - then we should try to parse the error message |
|
| 455 | - if($err_code === 500) { |
|
| 456 | - // message example: HTTP-Code: 401 |
|
| 457 | - $regx = '/[0-9]{3}/'; |
|
| 458 | - if(preg_match($regx, $e->getMessage(), $found)) { |
|
| 459 | - $err_code = $found[0]; |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - $e = new BackendException($this->parseErrorCodeToMessage($err_code), $err_code); |
|
| 463 | - $e->setTitle($this->backendTransName . _('Connection failed')); |
|
| 464 | - throw $e; |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * create a new directory |
|
| 470 | - * |
|
| 471 | - * @param string $dir directory path |
|
| 472 | - * |
|
| 473 | - * @throws BackendException if request is not successful |
|
| 474 | - * |
|
| 475 | - * @return boolean true if action succeeded |
|
| 476 | - */ |
|
| 477 | - public function mkcol($dir) |
|
| 478 | - { |
|
| 479 | - $time_start = microtime(true); |
|
| 480 | - $dir = $this->removeSlash($dir); |
|
| 481 | - $this->log("[MKCOL] start for dir: $dir"); |
|
| 482 | - try { |
|
| 483 | - $response = $this->sabre_client->request("MKCOL", $dir, null); |
|
| 484 | - $time_end = microtime(true); |
|
| 485 | - $time = $time_end - $time_start; |
|
| 486 | - $this->log("[MKCOL] done in $time seconds: " . $response['statusCode']); |
|
| 487 | - |
|
| 488 | - return true; |
|
| 489 | - } catch (ClientException $e) { |
|
| 490 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 491 | - $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 492 | - throw $e; |
|
| 493 | - } catch (Exception $e) { |
|
| 494 | - $this->log('[MKCOL] fatal: ' . $e->getMessage()); |
|
| 495 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 496 | - $e->setTitle($this->backendTransName . _('Directory creation failed')); |
|
| 497 | - throw $e; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * delete a file or directory |
|
| 503 | - * |
|
| 504 | - * @param string $path file/directory path |
|
| 505 | - * |
|
| 506 | - * @throws BackendException if request is not successful |
|
| 507 | - * |
|
| 508 | - * @return boolean true if action succeeded |
|
| 509 | - */ |
|
| 510 | - public function delete($path) |
|
| 511 | - { |
|
| 512 | - $time_start = microtime(true); |
|
| 513 | - $path = $this->removeSlash($path); |
|
| 514 | - $this->log("[DELETE] start for dir: $path"); |
|
| 515 | - try { |
|
| 516 | - $response = $this->sabre_client->request("DELETE", $path, null); |
|
| 517 | - $time_end = microtime(true); |
|
| 518 | - $time = $time_end - $time_start; |
|
| 519 | - $this->log("[DELETE] done in $time seconds: " . $response['statusCode']); |
|
| 520 | - |
|
| 521 | - return true; |
|
| 522 | - } catch (ClientException $e) { |
|
| 523 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 524 | - $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 525 | - throw $e; |
|
| 526 | - } catch (Exception $e) { |
|
| 527 | - $this->log('[DELETE] fatal: ' . $e->getMessage()); |
|
| 528 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 529 | - $e->setTitle($this->backendTransName . _('Deletion failed')); |
|
| 530 | - throw $e; |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * Move a file or collection on webdav server (serverside) |
|
| 536 | - * If you set param overwrite as true, the target will be overwritten. |
|
| 537 | - * |
|
| 538 | - * @param string $src_path Source path |
|
| 539 | - * @param string $dest_path Destination path |
|
| 540 | - * @param boolean $overwrite Overwrite file if exists in $dest_path |
|
| 541 | - * |
|
| 542 | - * @throws BackendException if request is not successful |
|
| 543 | - * |
|
| 544 | - * @return boolean true if action succeeded |
|
| 545 | - */ |
|
| 546 | - public function move($src_path, $dst_path, $overwrite = false) |
|
| 547 | - { |
|
| 548 | - $time_start = microtime(true); |
|
| 549 | - $src_path = $this->removeSlash($src_path); |
|
| 550 | - $dst_path = $this->webdavUrl() . $this->removeSlash($dst_path); |
|
| 551 | - $this->log("[MOVE] start for dir: $src_path -> $dst_path"); |
|
| 552 | - if ($overwrite) { |
|
| 553 | - $overwrite = 'T'; |
|
| 554 | - } else { |
|
| 555 | - $overwrite = 'F'; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - try { |
|
| 559 | - $response = $this->sabre_client->request("MOVE", $src_path, null, array("Destination" => $dst_path, 'Overwrite' => $overwrite)); |
|
| 560 | - $time_end = microtime(true); |
|
| 561 | - $time = $time_end - $time_start; |
|
| 562 | - $this->log("[MOVE] done in $time seconds: " . $response['statusCode']); |
|
| 563 | - return true; |
|
| 564 | - } catch (ClientException $e) { |
|
| 565 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 566 | - $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 567 | - throw $e; |
|
| 568 | - } catch (Exception $e) { |
|
| 569 | - $this->log('[MOVE] fatal: ' . $e->getMessage()); |
|
| 570 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 571 | - $e->setTitle($this->backendTransName . _('Moving failed')); |
|
| 572 | - throw $e; |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * Puts a file into a collection. |
|
| 578 | - * |
|
| 579 | - * @param string $path Destination path |
|
| 580 | - * |
|
| 581 | - * @string mixed $data Any kind of data |
|
| 582 | - * @throws BackendException if request is not successful |
|
| 583 | - * |
|
| 584 | - * @return boolean true if action succeeded |
|
| 585 | - */ |
|
| 586 | - public function put($path, $data) |
|
| 587 | - { |
|
| 588 | - $time_start = microtime(true); |
|
| 589 | - $path = $this->removeSlash($path); |
|
| 590 | - $this->log("[PUT] start for dir: $path strlen: " . strlen($data)); |
|
| 591 | - try { |
|
| 592 | - $response = $this->sabre_client->request("PUT", $path, $data); |
|
| 593 | - $time_end = microtime(true); |
|
| 594 | - $time = $time_end - $time_start; |
|
| 595 | - $this->log("[PUT] done in $time seconds: " . $response['statusCode']); |
|
| 596 | - return true; |
|
| 597 | - } catch (ClientException $e) { |
|
| 598 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 599 | - $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 600 | - throw $e; |
|
| 601 | - } catch (Exception $e) { |
|
| 602 | - $this->log('[PUT] fatal: ' . $e->getMessage()); |
|
| 603 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 604 | - $e->setTitle($this->backendTransName . _('Connection failed')); |
|
| 605 | - throw $e; |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * Upload a local file |
|
| 611 | - * |
|
| 612 | - * @param string $path Destination path on the server |
|
| 613 | - * @param string $filename Local filename for the file that should be uploaded |
|
| 614 | - * |
|
| 615 | - * @throws BackendException if request is not successful |
|
| 616 | - * |
|
| 617 | - * @return boolean true if action succeeded |
|
| 618 | - */ |
|
| 619 | - public function put_file($path, $filename) |
|
| 620 | - { |
|
| 621 | - $buffer = file_get_contents($filename); |
|
| 622 | - |
|
| 623 | - if ($buffer !== false) { |
|
| 624 | - return $this->put($path, $buffer); |
|
| 625 | - } else { |
|
| 626 | - $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_TMP), self::WD_ERR_TMP); |
|
| 627 | - $e->setTitle($this->backendTransName . _('Temporary directory problems')); |
|
| 628 | - throw $e; |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Gets a file from a webdav collection. |
|
| 634 | - * |
|
| 635 | - * @param string $path The source path on the server |
|
| 636 | - * @param mixed $buffer Buffer for the received data |
|
| 637 | - * |
|
| 638 | - * @throws BackendException if request is not successful |
|
| 639 | - * |
|
| 640 | - * @return boolean true if action succeeded |
|
| 641 | - */ |
|
| 642 | - public function get($path, &$buffer) |
|
| 643 | - { |
|
| 644 | - $tmpfile = tempnam(TMP_PATH, stripslashes(base64_encode($path))); |
|
| 645 | - |
|
| 646 | - $this->log("[GET] buffer path: $tmpfile"); |
|
| 647 | - $this->get_file($path, $tmpfile); |
|
| 648 | - |
|
| 649 | - $buffer = file_get_contents($tmpfile); |
|
| 650 | - unlink($tmpfile); |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Gets a file from a collection into local filesystem. |
|
| 655 | - * |
|
| 656 | - * @param string $srcpath Source path on server |
|
| 657 | - * @param string $localpath Destination path on local filesystem |
|
| 658 | - * |
|
| 659 | - * @throws BackendException if request is not successful |
|
| 660 | - * |
|
| 661 | - * @return boolean true if action succeeded |
|
| 662 | - */ |
|
| 663 | - public function get_file($srcpath, $localpath) |
|
| 664 | - { |
|
| 665 | - $time_start = microtime(true); |
|
| 666 | - $path = $this->removeSlash($srcpath); |
|
| 667 | - $this->log("[GET_FILE] start for dir: $path"); |
|
| 668 | - $this->log("[GET_FILE] local path (" . $localpath . ") writeable: " . is_writable($localpath)); |
|
| 669 | - try { |
|
| 670 | - $response = $this->sabre_client->getFile($path, $localpath); |
|
| 671 | - $time_end = microtime(true); |
|
| 672 | - $time = $time_end - $time_start; |
|
| 673 | - $this->log("[GET_FILE] done in $time seconds: " . $response['statusCode']); |
|
| 674 | - } catch (ClientException $e) { |
|
| 675 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 676 | - $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 677 | - throw $e; |
|
| 678 | - } catch (Exception $e) { |
|
| 679 | - $this->log('[GET_FILE] - FATAL -' . $e->getMessage()); |
|
| 680 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 681 | - $e->setTitle($this->backendTransName . _('File or folder not found')); |
|
| 682 | - throw $e; |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - /** |
|
| 687 | - * Public method copy_file |
|
| 688 | - * |
|
| 689 | - * Copy a file on webdav server |
|
| 690 | - * Duplicates a file on the webdav server (serverside). |
|
| 691 | - * All work is done on the webdav server. If you set param overwrite as true, |
|
| 692 | - * the target will be overwritten. |
|
| 693 | - * |
|
| 694 | - * @param string $src_path Source path |
|
| 695 | - * @param string $dest_path Destination path |
|
| 696 | - * @param bool $overwrite Overwrite if file exists in $dst_path |
|
| 697 | - * |
|
| 698 | - * @throws BackendException if request is not successful |
|
| 699 | - * |
|
| 700 | - * @return boolean true if action succeeded |
|
| 701 | - */ |
|
| 702 | - public function copy_file($src_path, $dst_path, $overwrite = false) |
|
| 703 | - { |
|
| 704 | - return $this->copy($src_path, $dst_path, $overwrite, false); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * Public method copy_coll |
|
| 709 | - * |
|
| 710 | - * Copy a collection on webdav server |
|
| 711 | - * Duplicates a collection on the webdav server (serverside). |
|
| 712 | - * All work is done on the webdav server. If you set param overwrite as true, |
|
| 713 | - * the target will be overwritten. |
|
| 714 | - * |
|
| 715 | - * @param string $src_path Source path |
|
| 716 | - * @param string $dest_path Destination path |
|
| 717 | - * @param bool $overwrite Overwrite if collection exists in $dst_path |
|
| 718 | - * |
|
| 719 | - * @throws BackendException if request is not successful |
|
| 720 | - * |
|
| 721 | - * @return boolean true if action succeeded |
|
| 722 | - */ |
|
| 723 | - public function copy_coll($src_path, $dst_path, $overwrite = false) |
|
| 724 | - { |
|
| 725 | - return $this->copy($src_path, $dst_path, $overwrite, true); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * Gets path information from webdav server for one element |
|
| 730 | - * |
|
| 731 | - * @param string $path Path to file or folder |
|
| 732 | - * |
|
| 733 | - * @throws BackendException if request is not successful |
|
| 734 | - * |
|
| 735 | - * @return array directory info |
|
| 736 | - */ |
|
| 737 | - public function gpi($path) |
|
| 738 | - { |
|
| 739 | - $path = $this->removeSlash($path); |
|
| 740 | - $response = $this->sabre_client->propFind($path, array( |
|
| 741 | - '{http://owncloud.org/ns}fileid', |
|
| 742 | - '{DAV:}resourcetype', |
|
| 743 | - '{DAV:}getcontentlength', |
|
| 744 | - '{DAV:}getlastmodified', |
|
| 745 | - '{DAV:}getcontenttype', |
|
| 746 | - '{DAV:}quota-used-bytes', |
|
| 747 | - '{DAV:}quota-available-bytes', |
|
| 748 | - )); |
|
| 749 | - |
|
| 750 | - $type = $response["{DAV:}resourcetype"]->resourceType; |
|
| 751 | - if (is_array($type) && !empty($type)) { |
|
| 752 | - $type = $type[0] == "{DAV:}collection" ? "collection" : "file"; |
|
| 753 | - } else { |
|
| 754 | - $type = "file"; // fall back to file if detection fails... less harmful |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - $gpi = array( |
|
| 758 | - "fileid" => isset($response["{http://owncloud.org/ns}fileid"]) ? $response["{http://owncloud.org/ns}fileid"] : '-1', |
|
| 759 | - "resourcetype" => $type, |
|
| 760 | - "getcontentlength" => isset($response["{DAV:}getcontentlength"]) ? $response["{DAV:}getcontentlength"] : null, |
|
| 761 | - "getlastmodified" => isset($response["{DAV:}getlastmodified"]) ? $response["{DAV:}getlastmodified"] : null, |
|
| 762 | - "getcontenttype" => isset($response["{DAV:}getcontenttype"]) ? $response["{DAV:}getcontenttype"] : null, |
|
| 763 | - "quota-used-bytes" => isset($response["{DAV:}quota-used-bytes"]) ? $response["{DAV:}quota-used-bytes"] : null, |
|
| 764 | - "quota-available-bytes" => isset($response["{DAV:}quota-available-bytes"]) ? $response["{DAV:}quota-available-bytes"] : null, |
|
| 765 | - ); |
|
| 766 | - |
|
| 767 | - return $gpi; |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * Gets server information |
|
| 772 | - * |
|
| 773 | - * @throws BackendException if request is not successful |
|
| 774 | - * @return array with all header fields returned from webdav server. |
|
| 775 | - */ |
|
| 776 | - public function options() |
|
| 777 | - { |
|
| 778 | - $features = $this->sabre_client->options(); |
|
| 779 | - |
|
| 780 | - // be sure it is an array |
|
| 781 | - if (is_array($features)) { |
|
| 782 | - return $features; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - $this->log('[OPTIONS] - ERROR - Error getting server features'); |
|
| 786 | - $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_FEATURES), self::WD_ERR_FEATURES); |
|
| 787 | - $e->setTitle($this->backendTransName . _('Not implemented')); |
|
| 788 | - throw $e; |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * Gather whether a path points to a file or not |
|
| 793 | - * |
|
| 794 | - * @param string $path Path to file or folder |
|
| 795 | - * |
|
| 796 | - * @return boolean true if path points to a file, false otherwise |
|
| 797 | - */ |
|
| 798 | - public function is_file($path) |
|
| 799 | - { |
|
| 800 | - $item = $this->gpi($path); |
|
| 801 | - |
|
| 802 | - return $item === false ? false : ($item['resourcetype'] != 'collection'); |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * Gather whether a path points to a directory |
|
| 807 | - * |
|
| 808 | - * @param string $path Path to file or folder |
|
| 809 | - * |
|
| 810 | - * @return boolean true if path points to a directory, false otherwise |
|
| 811 | - */ |
|
| 812 | - public function is_dir($path) |
|
| 813 | - { |
|
| 814 | - $item = $this->gpi($path); |
|
| 815 | - |
|
| 816 | - return $item === false ? false : ($item['resourcetype'] == 'collection'); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - /** |
|
| 820 | - * check if file/directory exists |
|
| 821 | - * |
|
| 822 | - * @param string $path Path to file or folder |
|
| 823 | - * |
|
| 824 | - * @return boolean true if path exists, false otherwise |
|
| 825 | - */ |
|
| 826 | - public function exists($path) |
|
| 827 | - { |
|
| 828 | - return ($this->is_dir($path) || $this->is_file($path)); |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - /** |
|
| 832 | - * Copy a collection on webdav server |
|
| 833 | - * Duplicates a collection on the webdav server (serverside). |
|
| 834 | - * All work is done on the webdav server. If you set param overwrite as true, |
|
| 835 | - * the target will be overwritten. |
|
| 836 | - * |
|
| 837 | - * @access private |
|
| 838 | - * |
|
| 839 | - * @param string $src_path Source path |
|
| 840 | - * @param string $dest_path Destination path |
|
| 841 | - * @param bool $overwrite Overwrite if collection exists in $dst_path |
|
| 842 | - * @param bool $coll Set this to true if you want to copy a folder. |
|
| 843 | - * |
|
| 844 | - * @throws BackendException if request is not successful |
|
| 845 | - * |
|
| 846 | - * @return boolean true if action succeeded |
|
| 847 | - */ |
|
| 848 | - private function copy($src_path, $dst_path, $overwrite, $coll) |
|
| 849 | - { |
|
| 850 | - $time_start = microtime(true); |
|
| 851 | - $src_path = $this->removeSlash($src_path); |
|
| 852 | - $dst_path = $this->webdavUrl() . $this->removeSlash($dst_path); |
|
| 853 | - $this->log("[COPY] start for dir: $src_path -> $dst_path"); |
|
| 854 | - if ($overwrite) { |
|
| 855 | - $overwrite = 'T'; |
|
| 856 | - } else { |
|
| 857 | - $overwrite = 'F'; |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - array("Destination" => $dst_path, 'Overwrite' => $overwrite); |
|
| 861 | - if ($coll) { |
|
| 862 | - $settings = array("Destination" => $dst_path, 'Depth' => 'Infinity'); |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - try { |
|
| 866 | - $response = $this->sabre_client->request("COPY", $src_path, null, $settings); |
|
| 867 | - $time_end = microtime(true); |
|
| 868 | - $time = $time_end - $time_start; |
|
| 869 | - $this->log("[COPY] done in $time seconds: " . $response['statusCode']); |
|
| 870 | - return true; |
|
| 871 | - } catch (ClientException $e) { |
|
| 872 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 873 | - $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 874 | - throw $e; |
|
| 875 | - } catch (Exception $e) { |
|
| 876 | - $this->log('[COPY] - FATAL - ' . $e->getMessage()); |
|
| 877 | - $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 878 | - $e->setTitle($this->backendTransName . _('Copying failed')); |
|
| 879 | - throw $e; |
|
| 880 | - } |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * Create the base webdav url |
|
| 885 | - * |
|
| 886 | - * @access protected |
|
| 887 | - * @return string baseURL |
|
| 888 | - */ |
|
| 889 | - protected function webdavUrl() |
|
| 890 | - { |
|
| 891 | - if ($this->ssl) { |
|
| 892 | - $url = "https://"; |
|
| 893 | - } else { |
|
| 894 | - $url = "http://"; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - // make sure that we do not have any trailing / in our url |
|
| 898 | - $server = rtrim($this->server, '/'); |
|
| 899 | - $path = rtrim($this->path, '/'); |
|
| 900 | - |
|
| 901 | - $url .= $server . ":" . $this->port . $path . "/"; |
|
| 902 | - |
|
| 903 | - return $url; |
|
| 904 | - } |
|
| 905 | - |
|
| 906 | - /** |
|
| 907 | - * Removes the leading slash from the folder path |
|
| 908 | - * |
|
| 909 | - * @access private |
|
| 910 | - * |
|
| 911 | - * @param string $dir directory path |
|
| 912 | - * |
|
| 913 | - * @return string trimmed directory path |
|
| 914 | - */ |
|
| 915 | - function removeSlash($dir) |
|
| 916 | - { |
|
| 917 | - if (strpos($dir, '/') === 0) { |
|
| 918 | - $dir = substr($dir, 1); |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - // remove all html entities and urlencode the path... |
|
| 922 | - $nohtml = html_entity_decode($dir); |
|
| 923 | - $dir = implode("/", array_map("rawurlencode", explode("/", $nohtml))); |
|
| 924 | - |
|
| 925 | - return $dir; |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * This function will return a user friendly error string. |
|
| 930 | - * |
|
| 931 | - * @param number $error_code A error code |
|
| 932 | - * |
|
| 933 | - * @return string userfriendly error message |
|
| 934 | - */ |
|
| 935 | - private function parseErrorCodeToMessage($error_code) |
|
| 936 | - { |
|
| 937 | - $error = intval($error_code); |
|
| 938 | - |
|
| 939 | - $msg = _('Unknown error'); |
|
| 940 | - $contactAdmin = _('Please contact your system administrator'); |
|
| 941 | - |
|
| 942 | - switch ($error) { |
|
| 943 | - case CURLE_BAD_PASSWORD_ENTERED: |
|
| 944 | - case self::WD_ERR_UNAUTHORIZED: |
|
| 945 | - $msg = _('Unauthorized. Wrong username or password.'); |
|
| 946 | - break; |
|
| 947 | - case CURLE_SSL_CONNECT_ERROR: |
|
| 948 | - case CURLE_COULDNT_RESOLVE_HOST: |
|
| 949 | - case CURLE_COULDNT_CONNECT: |
|
| 950 | - case CURLE_OPERATION_TIMEOUTED: |
|
| 951 | - case self::WD_ERR_UNREACHABLE: |
|
| 952 | - $msg = _('File server is not reachable. Please verify the connection.'); |
|
| 953 | - break; |
|
| 954 | - case self::WD_ERR_NOTALLOWED: |
|
| 955 | - $msg = _('File server is not reachable. Please verify the file server URL.'); |
|
| 956 | - break; |
|
| 957 | - case self::WD_ERR_FORBIDDEN: |
|
| 958 | - $msg = _('You don\'t have enough permissions to view this file or folder.'); |
|
| 959 | - break; |
|
| 960 | - case self::WD_ERR_NOTFOUND: |
|
| 961 | - $msg = _('The file or folder is not available anymore.'); |
|
| 962 | - break; |
|
| 963 | - case self::WD_ERR_TIMEOUT: |
|
| 964 | - $msg = _('Connection to the file server timed out. Please check again later.'); |
|
| 965 | - break; |
|
| 966 | - case self::WD_ERR_LOCKED: |
|
| 967 | - $msg = _('This file is locked by another user. Please try again later.'); |
|
| 968 | - break; |
|
| 969 | - case self::WD_ERR_FAILED_DEPENDENCY: |
|
| 970 | - $msg = _('The request failed.') . ' ' . $contactAdmin; |
|
| 971 | - break; |
|
| 972 | - case self::WD_ERR_INTERNAL: |
|
| 973 | - // This is a general error, might be thrown due to a wrong IP, but we don't know. |
|
| 974 | - $msg = _('The file server encountered an internal problem.') . ' ' . $contactAdmin; |
|
| 975 | - break; |
|
| 976 | - case self::WD_ERR_TMP: |
|
| 977 | - $msg = _('We could not write to temporary directory.') . ' ' . $contactAdmin; |
|
| 978 | - break; |
|
| 979 | - case self::WD_ERR_FEATURES: |
|
| 980 | - $msg = _('We could not retrieve list of server features.') . ' ' . $contactAdmin; |
|
| 981 | - break; |
|
| 982 | - case self::WD_ERR_NO_CURL: |
|
| 983 | - $msg = _('PHP-Curl is not available.') . ' ' . $contactAdmin; |
|
| 984 | - break; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - return $msg; |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - public function getFormConfig() |
|
| 991 | - { |
|
| 992 | - $json = json_encode($this->metaConfig); |
|
| 993 | - |
|
| 994 | - if ($json === FALSE) { |
|
| 995 | - error_log(json_last_error()); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - return $json; |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - public function getFormConfigWithData() |
|
| 1002 | - { |
|
| 1003 | - return json_encode($this->metaConfig); |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * a simple php error_log wrapper. |
|
| 1008 | - * |
|
| 1009 | - * @access private |
|
| 1010 | - * |
|
| 1011 | - * @param string $err_string error message |
|
| 1012 | - * |
|
| 1013 | - * @return void |
|
| 1014 | - */ |
|
| 1015 | - private function log($err_string) |
|
| 1016 | - { |
|
| 1017 | - if ($this->debug) { |
|
| 1018 | - error_log("[BACKEND_WEBDAV]: " . $err_string); |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - /** |
|
| 1023 | - * ============================ FEATURE FUNCTIONS ======================== |
|
| 1024 | - */ |
|
| 1025 | - |
|
| 1026 | - /** |
|
| 1027 | - * Returns the bytes that are currently used. |
|
| 1028 | - * |
|
| 1029 | - * @param string $dir directory to check |
|
| 1030 | - * |
|
| 1031 | - * @return int bytes that are used or -1 on error |
|
| 1032 | - */ |
|
| 1033 | - public function getQuotaBytesUsed($dir) |
|
| 1034 | - { |
|
| 1035 | - $lsdata = $this->ls($dir, false); |
|
| 1036 | - |
|
| 1037 | - if (isset($lsdata) && is_array($lsdata)) { |
|
| 1038 | - return $lsdata[$dir]["quota-used-bytes"]; |
|
| 1039 | - } else { |
|
| 1040 | - return -1; |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * Returns the bytes that are currently available. |
|
| 1046 | - * |
|
| 1047 | - * @param string $dir directory to check |
|
| 1048 | - * |
|
| 1049 | - * @return int bytes that are available or -1 on error |
|
| 1050 | - */ |
|
| 1051 | - public function getQuotaBytesAvailable($dir) |
|
| 1052 | - { |
|
| 1053 | - $lsdata = $this->ls($dir, false); |
|
| 1054 | - |
|
| 1055 | - if (isset($lsdata) && is_array($lsdata)) { |
|
| 1056 | - return $lsdata[$dir]["quota-available-bytes"]; |
|
| 1057 | - } else { |
|
| 1058 | - return -1; |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - /** |
|
| 1063 | - * Return the version string of the server backend. |
|
| 1064 | - * @return String |
|
| 1065 | - * @throws BackendException |
|
| 1066 | - */ |
|
| 1067 | - public function getServerVersion() |
|
| 1068 | - { |
|
| 1069 | - // check if curl is available |
|
| 1070 | - $serverHasCurl = function_exists('curl_version'); |
|
| 1071 | - if (!$serverHasCurl) { |
|
| 1072 | - $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_NO_CURL), 500); |
|
| 1073 | - $e->setTitle($this->backendTransName . _('PHP-CURL not installed')); |
|
| 1074 | - throw $e; |
|
| 1075 | - } |
|
| 1076 | - |
|
| 1077 | - $webdavurl = $this->webdavUrl(); |
|
| 1078 | - |
|
| 1079 | - $url = substr($webdavurl, 0, strlen($webdavurl) - strlen("remote.php/webdav/")) . "status.php"; |
|
| 1080 | - |
|
| 1081 | - // try to get the contents of the owncloud status page |
|
| 1082 | - $ch = curl_init(); |
|
| 1083 | - curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); |
|
| 1084 | - curl_setopt($ch, CURLOPT_TIMEOUT, 3); // timeout of 3 seconds |
|
| 1085 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 1086 | - curl_setopt($ch, CURLOPT_URL, $url); |
|
| 1087 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); |
|
| 1088 | - if ($this->allowselfsigned) { |
|
| 1089 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 1090 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 1091 | - } |
|
| 1092 | - $versiondata = curl_exec($ch); |
|
| 1093 | - $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 1094 | - curl_close($ch); |
|
| 1095 | - |
|
| 1096 | - if ($httpcode && $httpcode == "200" && $versiondata) { |
|
| 1097 | - $versions = json_decode($versiondata); |
|
| 1098 | - $version = $versions->versionstring; |
|
| 1099 | - } else { |
|
| 1100 | - $version = "Undetected (no Owncloud?)"; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - return $version; |
|
| 1104 | - } |
|
| 26 | + /** |
|
| 27 | + * Error codes |
|
| 28 | + * see @parseErrorCodeToMessage for description |
|
| 29 | + */ |
|
| 30 | + const WD_ERR_UNAUTHORIZED = 401; |
|
| 31 | + const WD_ERR_FORBIDDEN = 403; |
|
| 32 | + const WD_ERR_NOTFOUND = 404; |
|
| 33 | + const WD_ERR_NOTALLOWED = 405; |
|
| 34 | + const WD_ERR_TIMEOUT = 408; |
|
| 35 | + const WD_ERR_LOCKED = 423; |
|
| 36 | + const WD_ERR_FAILED_DEPENDENCY = 423; |
|
| 37 | + const WD_ERR_INTERNAL = 500; |
|
| 38 | + const WD_ERR_UNREACHABLE = 800; |
|
| 39 | + const WD_ERR_TMP = 801; |
|
| 40 | + const WD_ERR_FEATURES = 802; |
|
| 41 | + const WD_ERR_NO_CURL = 803; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Configuration data for the extjs metaform. |
|
| 45 | + */ |
|
| 46 | + protected $formConfig; |
|
| 47 | + protected $formFields; |
|
| 48 | + protected $metaConfig; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var boolean debugging flag, if true, debugging is enabled |
|
| 52 | + */ |
|
| 53 | + var $debug = false; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var int webdav server port |
|
| 57 | + */ |
|
| 58 | + var $port = 80; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var string hostname or ip |
|
| 62 | + */ |
|
| 63 | + var $server = "localhost"; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var string global path prefix for all requests |
|
| 67 | + */ |
|
| 68 | + var $path = "/webdav.php"; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var boolean if true, ssl is used |
|
| 72 | + */ |
|
| 73 | + var $ssl = false; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var boolean allow self signed certificates |
|
| 77 | + */ |
|
| 78 | + var $allowselfsigned = true; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @var string the username |
|
| 82 | + */ |
|
| 83 | + var $user = ""; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @var string the password |
|
| 87 | + */ |
|
| 88 | + var $pass = ""; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @var FilesWebDavClient the SabreDAV client object. |
|
| 92 | + */ |
|
| 93 | + var $sabre_client; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @constructor |
|
| 97 | + */ |
|
| 98 | + function __construct() |
|
| 99 | + { |
|
| 100 | + |
|
| 101 | + // initialization |
|
| 102 | + $this->debug = PLUGIN_FILESBROWSER_LOGLEVEL === "DEBUG" ? true : false; |
|
| 103 | + |
|
| 104 | + $this->init_form(); |
|
| 105 | + |
|
| 106 | + // set backend description |
|
| 107 | + $this->backendDescription = _("With this backend, you can connect to any WebDAV server."); |
|
| 108 | + |
|
| 109 | + // set backend display name |
|
| 110 | + $this->backendDisplayName = "Webdav"; |
|
| 111 | + |
|
| 112 | + // set backend version |
|
| 113 | + // TODO: this should be changed on every release |
|
| 114 | + $this->backendVersion = "3.0"; |
|
| 115 | + |
|
| 116 | + // Backend name used in translations |
|
| 117 | + $this->backendTransName = _('Files WebDAV Backend: '); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Initialise form fields |
|
| 122 | + */ |
|
| 123 | + private function init_form() |
|
| 124 | + { |
|
| 125 | + $this->formConfig = array( |
|
| 126 | + "labelAlign" => "left", |
|
| 127 | + "columnCount" => 1, |
|
| 128 | + "labelWidth" => 80, |
|
| 129 | + "defaults" => array( |
|
| 130 | + "width" => 292 |
|
| 131 | + ) |
|
| 132 | + ); |
|
| 133 | + |
|
| 134 | + $this->formFields = array( |
|
| 135 | + array( |
|
| 136 | + "name" => "server_address", |
|
| 137 | + "fieldLabel" => _('Server address'), |
|
| 138 | + "editor" => array( |
|
| 139 | + "allowBlank" => false |
|
| 140 | + ) |
|
| 141 | + ), |
|
| 142 | + array( |
|
| 143 | + "name" => "server_port", |
|
| 144 | + "fieldLabel" => _('Server port'), |
|
| 145 | + "editor" => array( |
|
| 146 | + "ref" => "../../portField", |
|
| 147 | + "allowBlank" => false |
|
| 148 | + ) |
|
| 149 | + ), |
|
| 150 | + array( |
|
| 151 | + "name" => "server_ssl", |
|
| 152 | + "fieldLabel" => _('Use SSL'), |
|
| 153 | + "editor" => array( |
|
| 154 | + "xtype" => "checkbox", |
|
| 155 | + "listeners" => array( |
|
| 156 | + "check" => "Zarafa.plugins.files.data.Actions.onCheckSSL" // this javascript function will be called! |
|
| 157 | + ) |
|
| 158 | + ) |
|
| 159 | + ), |
|
| 160 | + array( |
|
| 161 | + "name" => "server_path", |
|
| 162 | + "fieldLabel" => _('Webdav base path'), |
|
| 163 | + "editor" => array( |
|
| 164 | + ) |
|
| 165 | + ), |
|
| 166 | + array( |
|
| 167 | + "name" => "user", |
|
| 168 | + "fieldLabel" => _('Username'), |
|
| 169 | + "editor" => array( |
|
| 170 | + "ref" => "../../usernameField" |
|
| 171 | + ) |
|
| 172 | + ), |
|
| 173 | + array( |
|
| 174 | + "name" => "password", |
|
| 175 | + "fieldLabel" => _('Password'), |
|
| 176 | + "editor" => array( |
|
| 177 | + "ref" => "../../passwordField", |
|
| 178 | + "inputType" => "password" |
|
| 179 | + ) |
|
| 180 | + ), |
|
| 181 | + array( |
|
| 182 | + "name" => "use_grommunio_credentials", |
|
| 183 | + "fieldLabel" => _('Use grommunio credentials'), |
|
| 184 | + "editor" => array( |
|
| 185 | + "xtype" => "checkbox", |
|
| 186 | + "listeners" => array( |
|
| 187 | + "check" => "Zarafa.plugins.files.data.Actions.onCheckCredentials" // this javascript function will be called! |
|
| 188 | + ) |
|
| 189 | + ) |
|
| 190 | + ), |
|
| 191 | + ); |
|
| 192 | + |
|
| 193 | + $this->metaConfig = array( |
|
| 194 | + "success" => true, |
|
| 195 | + "metaData" => array( |
|
| 196 | + "fields" => $this->formFields, |
|
| 197 | + "formConfig" => $this->formConfig |
|
| 198 | + ), |
|
| 199 | + "data" => array( // here we can specify the default values. |
|
| 200 | + "server_address" => "files.demo.com", |
|
| 201 | + "server_port" => "80", |
|
| 202 | + "server_path" => "/remote.php/webdav" |
|
| 203 | + ) |
|
| 204 | + ); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Initialize backend from $backend_config array |
|
| 209 | + * @param $backend_config |
|
| 210 | + */ |
|
| 211 | + public function init_backend($backend_config) |
|
| 212 | + { |
|
| 213 | + $this->set_server($backend_config["server_address"]); |
|
| 214 | + $this->set_port($backend_config["server_port"]); |
|
| 215 | + $this->set_base($backend_config["server_path"]); |
|
| 216 | + $this->set_ssl($backend_config["server_ssl"]); |
|
| 217 | + |
|
| 218 | + // set user and password |
|
| 219 | + if ($backend_config["use_grommunio_credentials"] === FALSE) { |
|
| 220 | + $this->set_user($backend_config["user"]); |
|
| 221 | + $this->set_pass($backend_config["password"]); |
|
| 222 | + } else { |
|
| 223 | + // For backward compatibility we will check if the Encryption store exists. If not, |
|
| 224 | + // we will fall back to the old way of retrieving the password from the session. |
|
| 225 | + if ( class_exists('EncryptionStore') ) { |
|
| 226 | + // Get the username and password from the Encryption store |
|
| 227 | + $encryptionStore = \EncryptionStore::getInstance(); |
|
| 228 | + $this->set_user($encryptionStore->get('username')); |
|
| 229 | + $this->set_pass($encryptionStore->get('password')); |
|
| 230 | + } else { |
|
| 231 | + $this->set_user($GLOBALS['mapisession']->getUserName()); |
|
| 232 | + $password = $_SESSION['password']; |
|
| 233 | + if(function_exists('openssl_decrypt')) { |
|
| 234 | + $this->set_pass(openssl_decrypt($password, "des-ede3-cbc", PASSWORD_KEY, 0, PASSWORD_IV)); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Set webdav server. FQN or IP address. |
|
| 242 | + * |
|
| 243 | + * @param string $server hostname or ip of the ftp server |
|
| 244 | + * |
|
| 245 | + * @return void |
|
| 246 | + */ |
|
| 247 | + public function set_server($server) |
|
| 248 | + { |
|
| 249 | + $this->server = $server; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Set base path |
|
| 254 | + * |
|
| 255 | + * @param string $pp the global path prefix |
|
| 256 | + * |
|
| 257 | + * @return void |
|
| 258 | + */ |
|
| 259 | + public function set_base($pp) |
|
| 260 | + { |
|
| 261 | + $this->path = $pp; |
|
| 262 | + $this->log('Base path set to ' . $this->path); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Set ssl |
|
| 267 | + * |
|
| 268 | + * @param int /bool $ssl (1 = true, 0 = false) |
|
| 269 | + * |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + public function set_ssl($ssl) |
|
| 273 | + { |
|
| 274 | + $this->ssl = $ssl ? true : false; |
|
| 275 | + $this->log('SSL extension was set to ' . $this->ssl); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Allow self signed certificates - unimplemented |
|
| 280 | + * |
|
| 281 | + * @param bool $allowselfsigned Allow self signed certificates. Not yet implemented. |
|
| 282 | + * |
|
| 283 | + * @return void |
|
| 284 | + */ |
|
| 285 | + public function set_selfsigned($allowselfsigned) |
|
| 286 | + { |
|
| 287 | + $this->allowselfsigned = $allowselfsigned; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Set tcp port of webdav server. Default is 80. |
|
| 292 | + * |
|
| 293 | + * @param int $port the port of the ftp server |
|
| 294 | + * |
|
| 295 | + * @return void |
|
| 296 | + */ |
|
| 297 | + public function set_port($port) |
|
| 298 | + { |
|
| 299 | + $this->port = $port; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * set user name for authentication |
|
| 304 | + * |
|
| 305 | + * @param string $user username |
|
| 306 | + * |
|
| 307 | + * @return void |
|
| 308 | + */ |
|
| 309 | + public function set_user($user) |
|
| 310 | + { |
|
| 311 | + $this->user = $user; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Set password for authentication |
|
| 316 | + * |
|
| 317 | + * @param string $pass password |
|
| 318 | + * |
|
| 319 | + * @return void |
|
| 320 | + */ |
|
| 321 | + public function set_pass($pass) |
|
| 322 | + { |
|
| 323 | + $this->pass = $pass; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * set debug on (1) or off (0). |
|
| 328 | + * produces a lot of debug messages in webservers error log if set to on (1). |
|
| 329 | + * |
|
| 330 | + * @param boolean $debug enable or disable debugging |
|
| 331 | + * |
|
| 332 | + * @return void |
|
| 333 | + */ |
|
| 334 | + public function set_debug($debug) |
|
| 335 | + { |
|
| 336 | + $this->debug = $debug; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Opens the connection to the webdav server. |
|
| 341 | + * |
|
| 342 | + * @throws BackendException if connection is not successful |
|
| 343 | + * @return boolean true if action succeeded |
|
| 344 | + */ |
|
| 345 | + public function open() |
|
| 346 | + { |
|
| 347 | + |
|
| 348 | + // check if curl is available |
|
| 349 | + $serverHasCurl = function_exists('curl_version'); |
|
| 350 | + if (!$serverHasCurl) { |
|
| 351 | + $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_NO_CURL), 500); |
|
| 352 | + $e->setTitle($this->backendTransName . _('PHP-CURL is not installed')); |
|
| 353 | + throw $e; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + $davsettings = array( |
|
| 357 | + 'baseUri' => $this->webdavUrl(), |
|
| 358 | + 'userName' => $this->user, |
|
| 359 | + 'password' => $this->pass, |
|
| 360 | + 'authType' => \Sabre\DAV\Client::AUTH_BASIC, |
|
| 361 | + ); |
|
| 362 | + |
|
| 363 | + try { |
|
| 364 | + $this->sabre_client = new FilesWebDavClient($davsettings); |
|
| 365 | + $this->sabre_client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, !$this->allowselfsigned); |
|
| 366 | + |
|
| 367 | + return true; |
|
| 368 | + } catch (Exception $e) { |
|
| 369 | + $this->log('Failed to open: ' . $e->getMessage()); |
|
| 370 | + if (intval($e->getHTTPCode()) == 401) { |
|
| 371 | + $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_UNAUTHORIZED), $e->getHTTPCode()); |
|
| 372 | + $e->setTitle($this->backendTransName . _('Access denied')); |
|
| 373 | + throw $e; |
|
| 374 | + } else { |
|
| 375 | + $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_UNREACHABLE), $e->getHTTPCode()); |
|
| 376 | + $e->setTitle($this->backendTransName . _('Connection failed')); |
|
| 377 | + throw $e; |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * show content of a directory |
|
| 384 | + * |
|
| 385 | + * @param string $path directory path |
|
| 386 | + * @param boolean $hidefirst Optional parameter to hide the root entry. Default true |
|
| 387 | + * |
|
| 388 | + * @throws BackendException if request is not successful |
|
| 389 | + * |
|
| 390 | + * @return mixed array with directory content |
|
| 391 | + */ |
|
| 392 | + public function ls($dir, $hidefirst = true) |
|
| 393 | + { |
|
| 394 | + $time_start = microtime(true); |
|
| 395 | + $dir = $this->removeSlash($dir); |
|
| 396 | + $lsdata = array(); |
|
| 397 | + $this->log("[LS] start for dir: $dir"); |
|
| 398 | + try { |
|
| 399 | + $response = $this->sabre_client->propFind($dir, array( |
|
| 400 | + '{http://owncloud.org/ns}fileid', |
|
| 401 | + '{DAV:}resourcetype', |
|
| 402 | + '{DAV:}getcontentlength', |
|
| 403 | + '{DAV:}getlastmodified', |
|
| 404 | + '{DAV:}getcontenttype', |
|
| 405 | + '{DAV:}quota-used-bytes', |
|
| 406 | + '{DAV:}quota-available-bytes', |
|
| 407 | + ), 1); |
|
| 408 | + $this->log("[LS] backend fetched in: " . (microtime(true) - $time_start) . " seconds."); |
|
| 409 | + |
|
| 410 | + foreach ($response as $name => $fields) { |
|
| 411 | + |
|
| 412 | + if ($hidefirst) { |
|
| 413 | + $hidefirst = false; // skip the first line - its the requested dir itself |
|
| 414 | + continue; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $name = substr($name, strlen($this->path)); // skip the webdav path |
|
| 418 | + $name = urldecode($name); |
|
| 419 | + |
|
| 420 | + // Always fallback to a file resourceType |
|
| 421 | + $type = "file"; |
|
| 422 | + if (isset($fields['{DAV:}resourcetype'])) { |
|
| 423 | + $value = $fields['{DAV:}resourcetype']->getValue(); |
|
| 424 | + if (!empty($value) && $value[0] === "{DAV:}collection") { |
|
| 425 | + $type = "collection"; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + $lsdata[$name] = array( |
|
| 430 | + "fileid" => isset($fields["{http://owncloud.org/ns}fileid"]) ? $fields["{http://owncloud.org/ns}fileid"] : '-1', |
|
| 431 | + "resourcetype" => $type, |
|
| 432 | + "getcontentlength" => isset($fields["{DAV:}getcontentlength"]) ? $fields["{DAV:}getcontentlength"] : null, |
|
| 433 | + "getlastmodified" => isset($fields["{DAV:}getlastmodified"]) ? $fields["{DAV:}getlastmodified"] : null, |
|
| 434 | + "getcontenttype" => isset($fields["{DAV:}getcontenttype"]) ? $fields["{DAV:}getcontenttype"] : null, |
|
| 435 | + "quota-used-bytes" => isset($fields["{DAV:}quota-used-bytes"]) ? $fields["{DAV:}quota-used-bytes"] : null, |
|
| 436 | + "quota-available-bytes" => isset($fields["{DAV:}quota-available-bytes"]) ? $fields["{DAV:}quota-available-bytes"] : null, |
|
| 437 | + ); |
|
| 438 | + } |
|
| 439 | + $time_end = microtime(true); |
|
| 440 | + $time = $time_end - $time_start; |
|
| 441 | + $this->log("[LS] done in $time seconds"); |
|
| 442 | + |
|
| 443 | + return $lsdata; |
|
| 444 | + |
|
| 445 | + } catch (ClientException $e) { |
|
| 446 | + $this->log('ls sabre ClientException: ' . $e->getMessage()); |
|
| 447 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 448 | + $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 449 | + throw $e; |
|
| 450 | + } catch (Exception $e) { |
|
| 451 | + $this->log('ls general exception: ' . $e->getMessage() . " [" . $e->getHTTPCode() . "]"); |
|
| 452 | + // THIS IS A FIX FOR OWNCLOUD - It does return 500 instead of 401... |
|
| 453 | + $err_code = $e->getHTTPCode(); |
|
| 454 | + // check if code is 500 - then we should try to parse the error message |
|
| 455 | + if($err_code === 500) { |
|
| 456 | + // message example: HTTP-Code: 401 |
|
| 457 | + $regx = '/[0-9]{3}/'; |
|
| 458 | + if(preg_match($regx, $e->getMessage(), $found)) { |
|
| 459 | + $err_code = $found[0]; |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + $e = new BackendException($this->parseErrorCodeToMessage($err_code), $err_code); |
|
| 463 | + $e->setTitle($this->backendTransName . _('Connection failed')); |
|
| 464 | + throw $e; |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * create a new directory |
|
| 470 | + * |
|
| 471 | + * @param string $dir directory path |
|
| 472 | + * |
|
| 473 | + * @throws BackendException if request is not successful |
|
| 474 | + * |
|
| 475 | + * @return boolean true if action succeeded |
|
| 476 | + */ |
|
| 477 | + public function mkcol($dir) |
|
| 478 | + { |
|
| 479 | + $time_start = microtime(true); |
|
| 480 | + $dir = $this->removeSlash($dir); |
|
| 481 | + $this->log("[MKCOL] start for dir: $dir"); |
|
| 482 | + try { |
|
| 483 | + $response = $this->sabre_client->request("MKCOL", $dir, null); |
|
| 484 | + $time_end = microtime(true); |
|
| 485 | + $time = $time_end - $time_start; |
|
| 486 | + $this->log("[MKCOL] done in $time seconds: " . $response['statusCode']); |
|
| 487 | + |
|
| 488 | + return true; |
|
| 489 | + } catch (ClientException $e) { |
|
| 490 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 491 | + $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 492 | + throw $e; |
|
| 493 | + } catch (Exception $e) { |
|
| 494 | + $this->log('[MKCOL] fatal: ' . $e->getMessage()); |
|
| 495 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 496 | + $e->setTitle($this->backendTransName . _('Directory creation failed')); |
|
| 497 | + throw $e; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * delete a file or directory |
|
| 503 | + * |
|
| 504 | + * @param string $path file/directory path |
|
| 505 | + * |
|
| 506 | + * @throws BackendException if request is not successful |
|
| 507 | + * |
|
| 508 | + * @return boolean true if action succeeded |
|
| 509 | + */ |
|
| 510 | + public function delete($path) |
|
| 511 | + { |
|
| 512 | + $time_start = microtime(true); |
|
| 513 | + $path = $this->removeSlash($path); |
|
| 514 | + $this->log("[DELETE] start for dir: $path"); |
|
| 515 | + try { |
|
| 516 | + $response = $this->sabre_client->request("DELETE", $path, null); |
|
| 517 | + $time_end = microtime(true); |
|
| 518 | + $time = $time_end - $time_start; |
|
| 519 | + $this->log("[DELETE] done in $time seconds: " . $response['statusCode']); |
|
| 520 | + |
|
| 521 | + return true; |
|
| 522 | + } catch (ClientException $e) { |
|
| 523 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 524 | + $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 525 | + throw $e; |
|
| 526 | + } catch (Exception $e) { |
|
| 527 | + $this->log('[DELETE] fatal: ' . $e->getMessage()); |
|
| 528 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 529 | + $e->setTitle($this->backendTransName . _('Deletion failed')); |
|
| 530 | + throw $e; |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * Move a file or collection on webdav server (serverside) |
|
| 536 | + * If you set param overwrite as true, the target will be overwritten. |
|
| 537 | + * |
|
| 538 | + * @param string $src_path Source path |
|
| 539 | + * @param string $dest_path Destination path |
|
| 540 | + * @param boolean $overwrite Overwrite file if exists in $dest_path |
|
| 541 | + * |
|
| 542 | + * @throws BackendException if request is not successful |
|
| 543 | + * |
|
| 544 | + * @return boolean true if action succeeded |
|
| 545 | + */ |
|
| 546 | + public function move($src_path, $dst_path, $overwrite = false) |
|
| 547 | + { |
|
| 548 | + $time_start = microtime(true); |
|
| 549 | + $src_path = $this->removeSlash($src_path); |
|
| 550 | + $dst_path = $this->webdavUrl() . $this->removeSlash($dst_path); |
|
| 551 | + $this->log("[MOVE] start for dir: $src_path -> $dst_path"); |
|
| 552 | + if ($overwrite) { |
|
| 553 | + $overwrite = 'T'; |
|
| 554 | + } else { |
|
| 555 | + $overwrite = 'F'; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + try { |
|
| 559 | + $response = $this->sabre_client->request("MOVE", $src_path, null, array("Destination" => $dst_path, 'Overwrite' => $overwrite)); |
|
| 560 | + $time_end = microtime(true); |
|
| 561 | + $time = $time_end - $time_start; |
|
| 562 | + $this->log("[MOVE] done in $time seconds: " . $response['statusCode']); |
|
| 563 | + return true; |
|
| 564 | + } catch (ClientException $e) { |
|
| 565 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 566 | + $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 567 | + throw $e; |
|
| 568 | + } catch (Exception $e) { |
|
| 569 | + $this->log('[MOVE] fatal: ' . $e->getMessage()); |
|
| 570 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 571 | + $e->setTitle($this->backendTransName . _('Moving failed')); |
|
| 572 | + throw $e; |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * Puts a file into a collection. |
|
| 578 | + * |
|
| 579 | + * @param string $path Destination path |
|
| 580 | + * |
|
| 581 | + * @string mixed $data Any kind of data |
|
| 582 | + * @throws BackendException if request is not successful |
|
| 583 | + * |
|
| 584 | + * @return boolean true if action succeeded |
|
| 585 | + */ |
|
| 586 | + public function put($path, $data) |
|
| 587 | + { |
|
| 588 | + $time_start = microtime(true); |
|
| 589 | + $path = $this->removeSlash($path); |
|
| 590 | + $this->log("[PUT] start for dir: $path strlen: " . strlen($data)); |
|
| 591 | + try { |
|
| 592 | + $response = $this->sabre_client->request("PUT", $path, $data); |
|
| 593 | + $time_end = microtime(true); |
|
| 594 | + $time = $time_end - $time_start; |
|
| 595 | + $this->log("[PUT] done in $time seconds: " . $response['statusCode']); |
|
| 596 | + return true; |
|
| 597 | + } catch (ClientException $e) { |
|
| 598 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 599 | + $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 600 | + throw $e; |
|
| 601 | + } catch (Exception $e) { |
|
| 602 | + $this->log('[PUT] fatal: ' . $e->getMessage()); |
|
| 603 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 604 | + $e->setTitle($this->backendTransName . _('Connection failed')); |
|
| 605 | + throw $e; |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * Upload a local file |
|
| 611 | + * |
|
| 612 | + * @param string $path Destination path on the server |
|
| 613 | + * @param string $filename Local filename for the file that should be uploaded |
|
| 614 | + * |
|
| 615 | + * @throws BackendException if request is not successful |
|
| 616 | + * |
|
| 617 | + * @return boolean true if action succeeded |
|
| 618 | + */ |
|
| 619 | + public function put_file($path, $filename) |
|
| 620 | + { |
|
| 621 | + $buffer = file_get_contents($filename); |
|
| 622 | + |
|
| 623 | + if ($buffer !== false) { |
|
| 624 | + return $this->put($path, $buffer); |
|
| 625 | + } else { |
|
| 626 | + $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_TMP), self::WD_ERR_TMP); |
|
| 627 | + $e->setTitle($this->backendTransName . _('Temporary directory problems')); |
|
| 628 | + throw $e; |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Gets a file from a webdav collection. |
|
| 634 | + * |
|
| 635 | + * @param string $path The source path on the server |
|
| 636 | + * @param mixed $buffer Buffer for the received data |
|
| 637 | + * |
|
| 638 | + * @throws BackendException if request is not successful |
|
| 639 | + * |
|
| 640 | + * @return boolean true if action succeeded |
|
| 641 | + */ |
|
| 642 | + public function get($path, &$buffer) |
|
| 643 | + { |
|
| 644 | + $tmpfile = tempnam(TMP_PATH, stripslashes(base64_encode($path))); |
|
| 645 | + |
|
| 646 | + $this->log("[GET] buffer path: $tmpfile"); |
|
| 647 | + $this->get_file($path, $tmpfile); |
|
| 648 | + |
|
| 649 | + $buffer = file_get_contents($tmpfile); |
|
| 650 | + unlink($tmpfile); |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Gets a file from a collection into local filesystem. |
|
| 655 | + * |
|
| 656 | + * @param string $srcpath Source path on server |
|
| 657 | + * @param string $localpath Destination path on local filesystem |
|
| 658 | + * |
|
| 659 | + * @throws BackendException if request is not successful |
|
| 660 | + * |
|
| 661 | + * @return boolean true if action succeeded |
|
| 662 | + */ |
|
| 663 | + public function get_file($srcpath, $localpath) |
|
| 664 | + { |
|
| 665 | + $time_start = microtime(true); |
|
| 666 | + $path = $this->removeSlash($srcpath); |
|
| 667 | + $this->log("[GET_FILE] start for dir: $path"); |
|
| 668 | + $this->log("[GET_FILE] local path (" . $localpath . ") writeable: " . is_writable($localpath)); |
|
| 669 | + try { |
|
| 670 | + $response = $this->sabre_client->getFile($path, $localpath); |
|
| 671 | + $time_end = microtime(true); |
|
| 672 | + $time = $time_end - $time_start; |
|
| 673 | + $this->log("[GET_FILE] done in $time seconds: " . $response['statusCode']); |
|
| 674 | + } catch (ClientException $e) { |
|
| 675 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 676 | + $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 677 | + throw $e; |
|
| 678 | + } catch (Exception $e) { |
|
| 679 | + $this->log('[GET_FILE] - FATAL -' . $e->getMessage()); |
|
| 680 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 681 | + $e->setTitle($this->backendTransName . _('File or folder not found')); |
|
| 682 | + throw $e; |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * Public method copy_file |
|
| 688 | + * |
|
| 689 | + * Copy a file on webdav server |
|
| 690 | + * Duplicates a file on the webdav server (serverside). |
|
| 691 | + * All work is done on the webdav server. If you set param overwrite as true, |
|
| 692 | + * the target will be overwritten. |
|
| 693 | + * |
|
| 694 | + * @param string $src_path Source path |
|
| 695 | + * @param string $dest_path Destination path |
|
| 696 | + * @param bool $overwrite Overwrite if file exists in $dst_path |
|
| 697 | + * |
|
| 698 | + * @throws BackendException if request is not successful |
|
| 699 | + * |
|
| 700 | + * @return boolean true if action succeeded |
|
| 701 | + */ |
|
| 702 | + public function copy_file($src_path, $dst_path, $overwrite = false) |
|
| 703 | + { |
|
| 704 | + return $this->copy($src_path, $dst_path, $overwrite, false); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * Public method copy_coll |
|
| 709 | + * |
|
| 710 | + * Copy a collection on webdav server |
|
| 711 | + * Duplicates a collection on the webdav server (serverside). |
|
| 712 | + * All work is done on the webdav server. If you set param overwrite as true, |
|
| 713 | + * the target will be overwritten. |
|
| 714 | + * |
|
| 715 | + * @param string $src_path Source path |
|
| 716 | + * @param string $dest_path Destination path |
|
| 717 | + * @param bool $overwrite Overwrite if collection exists in $dst_path |
|
| 718 | + * |
|
| 719 | + * @throws BackendException if request is not successful |
|
| 720 | + * |
|
| 721 | + * @return boolean true if action succeeded |
|
| 722 | + */ |
|
| 723 | + public function copy_coll($src_path, $dst_path, $overwrite = false) |
|
| 724 | + { |
|
| 725 | + return $this->copy($src_path, $dst_path, $overwrite, true); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * Gets path information from webdav server for one element |
|
| 730 | + * |
|
| 731 | + * @param string $path Path to file or folder |
|
| 732 | + * |
|
| 733 | + * @throws BackendException if request is not successful |
|
| 734 | + * |
|
| 735 | + * @return array directory info |
|
| 736 | + */ |
|
| 737 | + public function gpi($path) |
|
| 738 | + { |
|
| 739 | + $path = $this->removeSlash($path); |
|
| 740 | + $response = $this->sabre_client->propFind($path, array( |
|
| 741 | + '{http://owncloud.org/ns}fileid', |
|
| 742 | + '{DAV:}resourcetype', |
|
| 743 | + '{DAV:}getcontentlength', |
|
| 744 | + '{DAV:}getlastmodified', |
|
| 745 | + '{DAV:}getcontenttype', |
|
| 746 | + '{DAV:}quota-used-bytes', |
|
| 747 | + '{DAV:}quota-available-bytes', |
|
| 748 | + )); |
|
| 749 | + |
|
| 750 | + $type = $response["{DAV:}resourcetype"]->resourceType; |
|
| 751 | + if (is_array($type) && !empty($type)) { |
|
| 752 | + $type = $type[0] == "{DAV:}collection" ? "collection" : "file"; |
|
| 753 | + } else { |
|
| 754 | + $type = "file"; // fall back to file if detection fails... less harmful |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + $gpi = array( |
|
| 758 | + "fileid" => isset($response["{http://owncloud.org/ns}fileid"]) ? $response["{http://owncloud.org/ns}fileid"] : '-1', |
|
| 759 | + "resourcetype" => $type, |
|
| 760 | + "getcontentlength" => isset($response["{DAV:}getcontentlength"]) ? $response["{DAV:}getcontentlength"] : null, |
|
| 761 | + "getlastmodified" => isset($response["{DAV:}getlastmodified"]) ? $response["{DAV:}getlastmodified"] : null, |
|
| 762 | + "getcontenttype" => isset($response["{DAV:}getcontenttype"]) ? $response["{DAV:}getcontenttype"] : null, |
|
| 763 | + "quota-used-bytes" => isset($response["{DAV:}quota-used-bytes"]) ? $response["{DAV:}quota-used-bytes"] : null, |
|
| 764 | + "quota-available-bytes" => isset($response["{DAV:}quota-available-bytes"]) ? $response["{DAV:}quota-available-bytes"] : null, |
|
| 765 | + ); |
|
| 766 | + |
|
| 767 | + return $gpi; |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * Gets server information |
|
| 772 | + * |
|
| 773 | + * @throws BackendException if request is not successful |
|
| 774 | + * @return array with all header fields returned from webdav server. |
|
| 775 | + */ |
|
| 776 | + public function options() |
|
| 777 | + { |
|
| 778 | + $features = $this->sabre_client->options(); |
|
| 779 | + |
|
| 780 | + // be sure it is an array |
|
| 781 | + if (is_array($features)) { |
|
| 782 | + return $features; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + $this->log('[OPTIONS] - ERROR - Error getting server features'); |
|
| 786 | + $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_FEATURES), self::WD_ERR_FEATURES); |
|
| 787 | + $e->setTitle($this->backendTransName . _('Not implemented')); |
|
| 788 | + throw $e; |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * Gather whether a path points to a file or not |
|
| 793 | + * |
|
| 794 | + * @param string $path Path to file or folder |
|
| 795 | + * |
|
| 796 | + * @return boolean true if path points to a file, false otherwise |
|
| 797 | + */ |
|
| 798 | + public function is_file($path) |
|
| 799 | + { |
|
| 800 | + $item = $this->gpi($path); |
|
| 801 | + |
|
| 802 | + return $item === false ? false : ($item['resourcetype'] != 'collection'); |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * Gather whether a path points to a directory |
|
| 807 | + * |
|
| 808 | + * @param string $path Path to file or folder |
|
| 809 | + * |
|
| 810 | + * @return boolean true if path points to a directory, false otherwise |
|
| 811 | + */ |
|
| 812 | + public function is_dir($path) |
|
| 813 | + { |
|
| 814 | + $item = $this->gpi($path); |
|
| 815 | + |
|
| 816 | + return $item === false ? false : ($item['resourcetype'] == 'collection'); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + /** |
|
| 820 | + * check if file/directory exists |
|
| 821 | + * |
|
| 822 | + * @param string $path Path to file or folder |
|
| 823 | + * |
|
| 824 | + * @return boolean true if path exists, false otherwise |
|
| 825 | + */ |
|
| 826 | + public function exists($path) |
|
| 827 | + { |
|
| 828 | + return ($this->is_dir($path) || $this->is_file($path)); |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + /** |
|
| 832 | + * Copy a collection on webdav server |
|
| 833 | + * Duplicates a collection on the webdav server (serverside). |
|
| 834 | + * All work is done on the webdav server. If you set param overwrite as true, |
|
| 835 | + * the target will be overwritten. |
|
| 836 | + * |
|
| 837 | + * @access private |
|
| 838 | + * |
|
| 839 | + * @param string $src_path Source path |
|
| 840 | + * @param string $dest_path Destination path |
|
| 841 | + * @param bool $overwrite Overwrite if collection exists in $dst_path |
|
| 842 | + * @param bool $coll Set this to true if you want to copy a folder. |
|
| 843 | + * |
|
| 844 | + * @throws BackendException if request is not successful |
|
| 845 | + * |
|
| 846 | + * @return boolean true if action succeeded |
|
| 847 | + */ |
|
| 848 | + private function copy($src_path, $dst_path, $overwrite, $coll) |
|
| 849 | + { |
|
| 850 | + $time_start = microtime(true); |
|
| 851 | + $src_path = $this->removeSlash($src_path); |
|
| 852 | + $dst_path = $this->webdavUrl() . $this->removeSlash($dst_path); |
|
| 853 | + $this->log("[COPY] start for dir: $src_path -> $dst_path"); |
|
| 854 | + if ($overwrite) { |
|
| 855 | + $overwrite = 'T'; |
|
| 856 | + } else { |
|
| 857 | + $overwrite = 'F'; |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + array("Destination" => $dst_path, 'Overwrite' => $overwrite); |
|
| 861 | + if ($coll) { |
|
| 862 | + $settings = array("Destination" => $dst_path, 'Depth' => 'Infinity'); |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + try { |
|
| 866 | + $response = $this->sabre_client->request("COPY", $src_path, null, $settings); |
|
| 867 | + $time_end = microtime(true); |
|
| 868 | + $time = $time_end - $time_start; |
|
| 869 | + $this->log("[COPY] done in $time seconds: " . $response['statusCode']); |
|
| 870 | + return true; |
|
| 871 | + } catch (ClientException $e) { |
|
| 872 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getCode()), $e->getCode()); |
|
| 873 | + $e->setTitle($this->backendTransName . _('Sabre error')); |
|
| 874 | + throw $e; |
|
| 875 | + } catch (Exception $e) { |
|
| 876 | + $this->log('[COPY] - FATAL - ' . $e->getMessage()); |
|
| 877 | + $e = new BackendException($this->parseErrorCodeToMessage($e->getHTTPCode()), $e->getHTTPCode()); |
|
| 878 | + $e->setTitle($this->backendTransName . _('Copying failed')); |
|
| 879 | + throw $e; |
|
| 880 | + } |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * Create the base webdav url |
|
| 885 | + * |
|
| 886 | + * @access protected |
|
| 887 | + * @return string baseURL |
|
| 888 | + */ |
|
| 889 | + protected function webdavUrl() |
|
| 890 | + { |
|
| 891 | + if ($this->ssl) { |
|
| 892 | + $url = "https://"; |
|
| 893 | + } else { |
|
| 894 | + $url = "http://"; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + // make sure that we do not have any trailing / in our url |
|
| 898 | + $server = rtrim($this->server, '/'); |
|
| 899 | + $path = rtrim($this->path, '/'); |
|
| 900 | + |
|
| 901 | + $url .= $server . ":" . $this->port . $path . "/"; |
|
| 902 | + |
|
| 903 | + return $url; |
|
| 904 | + } |
|
| 905 | + |
|
| 906 | + /** |
|
| 907 | + * Removes the leading slash from the folder path |
|
| 908 | + * |
|
| 909 | + * @access private |
|
| 910 | + * |
|
| 911 | + * @param string $dir directory path |
|
| 912 | + * |
|
| 913 | + * @return string trimmed directory path |
|
| 914 | + */ |
|
| 915 | + function removeSlash($dir) |
|
| 916 | + { |
|
| 917 | + if (strpos($dir, '/') === 0) { |
|
| 918 | + $dir = substr($dir, 1); |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + // remove all html entities and urlencode the path... |
|
| 922 | + $nohtml = html_entity_decode($dir); |
|
| 923 | + $dir = implode("/", array_map("rawurlencode", explode("/", $nohtml))); |
|
| 924 | + |
|
| 925 | + return $dir; |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * This function will return a user friendly error string. |
|
| 930 | + * |
|
| 931 | + * @param number $error_code A error code |
|
| 932 | + * |
|
| 933 | + * @return string userfriendly error message |
|
| 934 | + */ |
|
| 935 | + private function parseErrorCodeToMessage($error_code) |
|
| 936 | + { |
|
| 937 | + $error = intval($error_code); |
|
| 938 | + |
|
| 939 | + $msg = _('Unknown error'); |
|
| 940 | + $contactAdmin = _('Please contact your system administrator'); |
|
| 941 | + |
|
| 942 | + switch ($error) { |
|
| 943 | + case CURLE_BAD_PASSWORD_ENTERED: |
|
| 944 | + case self::WD_ERR_UNAUTHORIZED: |
|
| 945 | + $msg = _('Unauthorized. Wrong username or password.'); |
|
| 946 | + break; |
|
| 947 | + case CURLE_SSL_CONNECT_ERROR: |
|
| 948 | + case CURLE_COULDNT_RESOLVE_HOST: |
|
| 949 | + case CURLE_COULDNT_CONNECT: |
|
| 950 | + case CURLE_OPERATION_TIMEOUTED: |
|
| 951 | + case self::WD_ERR_UNREACHABLE: |
|
| 952 | + $msg = _('File server is not reachable. Please verify the connection.'); |
|
| 953 | + break; |
|
| 954 | + case self::WD_ERR_NOTALLOWED: |
|
| 955 | + $msg = _('File server is not reachable. Please verify the file server URL.'); |
|
| 956 | + break; |
|
| 957 | + case self::WD_ERR_FORBIDDEN: |
|
| 958 | + $msg = _('You don\'t have enough permissions to view this file or folder.'); |
|
| 959 | + break; |
|
| 960 | + case self::WD_ERR_NOTFOUND: |
|
| 961 | + $msg = _('The file or folder is not available anymore.'); |
|
| 962 | + break; |
|
| 963 | + case self::WD_ERR_TIMEOUT: |
|
| 964 | + $msg = _('Connection to the file server timed out. Please check again later.'); |
|
| 965 | + break; |
|
| 966 | + case self::WD_ERR_LOCKED: |
|
| 967 | + $msg = _('This file is locked by another user. Please try again later.'); |
|
| 968 | + break; |
|
| 969 | + case self::WD_ERR_FAILED_DEPENDENCY: |
|
| 970 | + $msg = _('The request failed.') . ' ' . $contactAdmin; |
|
| 971 | + break; |
|
| 972 | + case self::WD_ERR_INTERNAL: |
|
| 973 | + // This is a general error, might be thrown due to a wrong IP, but we don't know. |
|
| 974 | + $msg = _('The file server encountered an internal problem.') . ' ' . $contactAdmin; |
|
| 975 | + break; |
|
| 976 | + case self::WD_ERR_TMP: |
|
| 977 | + $msg = _('We could not write to temporary directory.') . ' ' . $contactAdmin; |
|
| 978 | + break; |
|
| 979 | + case self::WD_ERR_FEATURES: |
|
| 980 | + $msg = _('We could not retrieve list of server features.') . ' ' . $contactAdmin; |
|
| 981 | + break; |
|
| 982 | + case self::WD_ERR_NO_CURL: |
|
| 983 | + $msg = _('PHP-Curl is not available.') . ' ' . $contactAdmin; |
|
| 984 | + break; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + return $msg; |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + public function getFormConfig() |
|
| 991 | + { |
|
| 992 | + $json = json_encode($this->metaConfig); |
|
| 993 | + |
|
| 994 | + if ($json === FALSE) { |
|
| 995 | + error_log(json_last_error()); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + return $json; |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + public function getFormConfigWithData() |
|
| 1002 | + { |
|
| 1003 | + return json_encode($this->metaConfig); |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * a simple php error_log wrapper. |
|
| 1008 | + * |
|
| 1009 | + * @access private |
|
| 1010 | + * |
|
| 1011 | + * @param string $err_string error message |
|
| 1012 | + * |
|
| 1013 | + * @return void |
|
| 1014 | + */ |
|
| 1015 | + private function log($err_string) |
|
| 1016 | + { |
|
| 1017 | + if ($this->debug) { |
|
| 1018 | + error_log("[BACKEND_WEBDAV]: " . $err_string); |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + /** |
|
| 1023 | + * ============================ FEATURE FUNCTIONS ======================== |
|
| 1024 | + */ |
|
| 1025 | + |
|
| 1026 | + /** |
|
| 1027 | + * Returns the bytes that are currently used. |
|
| 1028 | + * |
|
| 1029 | + * @param string $dir directory to check |
|
| 1030 | + * |
|
| 1031 | + * @return int bytes that are used or -1 on error |
|
| 1032 | + */ |
|
| 1033 | + public function getQuotaBytesUsed($dir) |
|
| 1034 | + { |
|
| 1035 | + $lsdata = $this->ls($dir, false); |
|
| 1036 | + |
|
| 1037 | + if (isset($lsdata) && is_array($lsdata)) { |
|
| 1038 | + return $lsdata[$dir]["quota-used-bytes"]; |
|
| 1039 | + } else { |
|
| 1040 | + return -1; |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * Returns the bytes that are currently available. |
|
| 1046 | + * |
|
| 1047 | + * @param string $dir directory to check |
|
| 1048 | + * |
|
| 1049 | + * @return int bytes that are available or -1 on error |
|
| 1050 | + */ |
|
| 1051 | + public function getQuotaBytesAvailable($dir) |
|
| 1052 | + { |
|
| 1053 | + $lsdata = $this->ls($dir, false); |
|
| 1054 | + |
|
| 1055 | + if (isset($lsdata) && is_array($lsdata)) { |
|
| 1056 | + return $lsdata[$dir]["quota-available-bytes"]; |
|
| 1057 | + } else { |
|
| 1058 | + return -1; |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + /** |
|
| 1063 | + * Return the version string of the server backend. |
|
| 1064 | + * @return String |
|
| 1065 | + * @throws BackendException |
|
| 1066 | + */ |
|
| 1067 | + public function getServerVersion() |
|
| 1068 | + { |
|
| 1069 | + // check if curl is available |
|
| 1070 | + $serverHasCurl = function_exists('curl_version'); |
|
| 1071 | + if (!$serverHasCurl) { |
|
| 1072 | + $e = new BackendException($this->parseErrorCodeToMessage(self::WD_ERR_NO_CURL), 500); |
|
| 1073 | + $e->setTitle($this->backendTransName . _('PHP-CURL not installed')); |
|
| 1074 | + throw $e; |
|
| 1075 | + } |
|
| 1076 | + |
|
| 1077 | + $webdavurl = $this->webdavUrl(); |
|
| 1078 | + |
|
| 1079 | + $url = substr($webdavurl, 0, strlen($webdavurl) - strlen("remote.php/webdav/")) . "status.php"; |
|
| 1080 | + |
|
| 1081 | + // try to get the contents of the owncloud status page |
|
| 1082 | + $ch = curl_init(); |
|
| 1083 | + curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); |
|
| 1084 | + curl_setopt($ch, CURLOPT_TIMEOUT, 3); // timeout of 3 seconds |
|
| 1085 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 1086 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 1087 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); |
|
| 1088 | + if ($this->allowselfsigned) { |
|
| 1089 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 1090 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 1091 | + } |
|
| 1092 | + $versiondata = curl_exec($ch); |
|
| 1093 | + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 1094 | + curl_close($ch); |
|
| 1095 | + |
|
| 1096 | + if ($httpcode && $httpcode == "200" && $versiondata) { |
|
| 1097 | + $versions = json_decode($versiondata); |
|
| 1098 | + $version = $versions->versionstring; |
|
| 1099 | + } else { |
|
| 1100 | + $version = "Undetected (no Owncloud?)"; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + return $version; |
|
| 1104 | + } |
|
| 1105 | 1105 | } |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | } else { |
| 223 | 223 | // For backward compatibility we will check if the Encryption store exists. If not, |
| 224 | 224 | // we will fall back to the old way of retrieving the password from the session. |
| 225 | - if ( class_exists('EncryptionStore') ) { |
|
| 225 | + if (class_exists('EncryptionStore')) { |
|
| 226 | 226 | // Get the username and password from the Encryption store |
| 227 | 227 | $encryptionStore = \EncryptionStore::getInstance(); |
| 228 | 228 | $this->set_user($encryptionStore->get('username')); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | } else { |
| 231 | 231 | $this->set_user($GLOBALS['mapisession']->getUserName()); |
| 232 | 232 | $password = $_SESSION['password']; |
| 233 | - if(function_exists('openssl_decrypt')) { |
|
| 233 | + if (function_exists('openssl_decrypt')) { |
|
| 234 | 234 | $this->set_pass(openssl_decrypt($password, "des-ede3-cbc", PASSWORD_KEY, 0, PASSWORD_IV)); |
| 235 | 235 | } |
| 236 | 236 | } |
@@ -448,14 +448,14 @@ discard block |
||
| 448 | 448 | $e->setTitle($this->backendTransName . _('Sabre error')); |
| 449 | 449 | throw $e; |
| 450 | 450 | } catch (Exception $e) { |
| 451 | - $this->log('ls general exception: ' . $e->getMessage() . " [" . $e->getHTTPCode() . "]"); |
|
| 451 | + $this->log('ls general exception: ' . $e->getMessage() . " [" . $e->getHTTPCode() . "]"); |
|
| 452 | 452 | // THIS IS A FIX FOR OWNCLOUD - It does return 500 instead of 401... |
| 453 | 453 | $err_code = $e->getHTTPCode(); |
| 454 | 454 | // check if code is 500 - then we should try to parse the error message |
| 455 | - if($err_code === 500) { |
|
| 455 | + if ($err_code === 500) { |
|
| 456 | 456 | // message example: HTTP-Code: 401 |
| 457 | 457 | $regx = '/[0-9]{3}/'; |
| 458 | - if(preg_match($regx, $e->getMessage(), $found)) { |
|
| 458 | + if (preg_match($regx, $e->getMessage(), $found)) { |
|
| 459 | 459 | $err_code = $found[0]; |
| 460 | 460 | } |
| 461 | 461 | } |
@@ -10,103 +10,103 @@ |
||
| 10 | 10 | include(__DIR__ . "/vendor/autoload.php"); |
| 11 | 11 | |
| 12 | 12 | class FilesWebDavClient extends \Sabre\DAV\Client { |
| 13 | - public function __construct(array $settings) { |
|
| 14 | - if (isset($settings['userName'])) { |
|
| 15 | - $this->userName = $settings['userName']; |
|
| 16 | - } |
|
| 17 | - if (isset($settings['password'])) { |
|
| 18 | - $this->password = $settings['password']; |
|
| 19 | - } |
|
| 20 | - parent::__construct($settings); |
|
| 21 | - } |
|
| 22 | - /** |
|
| 23 | - * Performs an actual HTTP request, and returns the result. |
|
| 24 | - * |
|
| 25 | - * If the specified url is relative, it will be expanded based on the base |
|
| 26 | - * url. |
|
| 27 | - * |
|
| 28 | - * The returned array contains 3 keys: |
|
| 29 | - * * body - the response body |
|
| 30 | - * * httpCode - a HTTP code (200, 404, etc) |
|
| 31 | - * * headers - a list of response http headers. The header names have |
|
| 32 | - * been lowercased. |
|
| 33 | - * |
|
| 34 | - * @param string $url |
|
| 35 | - * @param string $dstpath |
|
| 36 | - * @param array $headers |
|
| 37 | - * |
|
| 38 | - * @return array |
|
| 39 | - */ |
|
| 40 | - public function getFile($url = '', $dstpath, $headers = array()) { |
|
| 41 | - |
|
| 42 | - $url = $this->getAbsoluteUrl($url); |
|
| 43 | - $file_handle = fopen($dstpath, "w"); |
|
| 44 | - |
|
| 45 | - if (!$file_handle) { |
|
| 46 | - throw new \Sabre\DAV\Exception('[CURL] Error writing to temporary file! (' . $dstpath . ')'); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - //straight up curl instead of sabredav here, sabredav put's the entire get result in memory |
|
| 50 | - $curl = curl_init($url); |
|
| 51 | - |
|
| 52 | - if ($this->verifyPeer !== null) { |
|
| 53 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifyPeer); |
|
| 54 | - } |
|
| 55 | - if ($this->trustedCertificates) { |
|
| 56 | - curl_setopt($curl, CURLOPT_CAINFO, $this->trustedCertificates); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - curl_setopt($curl, CURLOPT_USERPWD, $this->userName . ":" . $this->password); |
|
| 60 | - curl_setopt($curl, CURLOPT_FILE, $file_handle); |
|
| 61 | - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
| 62 | - curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 63 | - curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 64 | - |
|
| 65 | - curl_exec($curl); |
|
| 66 | - |
|
| 67 | - $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
| 68 | - |
|
| 69 | - curl_close($curl); |
|
| 70 | - |
|
| 71 | - $response = array( |
|
| 72 | - 'statusCode' => $statusCode |
|
| 73 | - ); |
|
| 74 | - |
|
| 75 | - if ($response['statusCode'] >= 400) { |
|
| 76 | - switch ($response['statusCode']) { |
|
| 77 | - case 400 : |
|
| 78 | - throw new \Sabre\DAV\Exception\BadRequest('Bad request'); |
|
| 79 | - case 401 : |
|
| 80 | - throw new \Sabre\DAV\Exception\NotAuthenticated('Not authenticated'); |
|
| 81 | - case 402 : |
|
| 82 | - throw new \Sabre\DAV\Exception\PaymentRequired('Payment required'); |
|
| 83 | - case 403 : |
|
| 84 | - throw new \Sabre\DAV\Exception\Forbidden('Forbidden'); |
|
| 85 | - case 404: |
|
| 86 | - throw new \Sabre\DAV\Exception\NotFound('Resource not found.'); |
|
| 87 | - case 405 : |
|
| 88 | - throw new \Sabre\DAV\Exception\MethodNotAllowed('Method not allowed'); |
|
| 89 | - case 409 : |
|
| 90 | - throw new \Sabre\DAV\Exception\Conflict('Conflict'); |
|
| 91 | - case 412 : |
|
| 92 | - throw new \Sabre\DAV\Exception\PreconditionFailed('Precondition failed'); |
|
| 93 | - case 416 : |
|
| 94 | - throw new \Sabre\DAV\Exception\RequestedRangeNotSatisfiable('Requested Range Not Satisfiable'); |
|
| 95 | - case 500 : |
|
| 96 | - throw new \Sabre\DAV\Exception('Internal server error'); |
|
| 97 | - case 501 : |
|
| 98 | - throw new \Sabre\DAV\Exception\NotImplemented('Not Implemented'); |
|
| 99 | - case 507 : |
|
| 100 | - throw new \Sabre\DAV\Exception\InsufficientStorage('Insufficient storage'); |
|
| 101 | - default: |
|
| 102 | - throw new \Sabre\DAV\Exception('HTTP error response. (errorcode ' . $response['statusCode'] . ')'); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $response; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - public function uploadChunkedFile($destination, $resource) { |
|
| 110 | - return $this->request("PUT", $destination, $resource); |
|
| 111 | - } |
|
| 13 | + public function __construct(array $settings) { |
|
| 14 | + if (isset($settings['userName'])) { |
|
| 15 | + $this->userName = $settings['userName']; |
|
| 16 | + } |
|
| 17 | + if (isset($settings['password'])) { |
|
| 18 | + $this->password = $settings['password']; |
|
| 19 | + } |
|
| 20 | + parent::__construct($settings); |
|
| 21 | + } |
|
| 22 | + /** |
|
| 23 | + * Performs an actual HTTP request, and returns the result. |
|
| 24 | + * |
|
| 25 | + * If the specified url is relative, it will be expanded based on the base |
|
| 26 | + * url. |
|
| 27 | + * |
|
| 28 | + * The returned array contains 3 keys: |
|
| 29 | + * * body - the response body |
|
| 30 | + * * httpCode - a HTTP code (200, 404, etc) |
|
| 31 | + * * headers - a list of response http headers. The header names have |
|
| 32 | + * been lowercased. |
|
| 33 | + * |
|
| 34 | + * @param string $url |
|
| 35 | + * @param string $dstpath |
|
| 36 | + * @param array $headers |
|
| 37 | + * |
|
| 38 | + * @return array |
|
| 39 | + */ |
|
| 40 | + public function getFile($url = '', $dstpath, $headers = array()) { |
|
| 41 | + |
|
| 42 | + $url = $this->getAbsoluteUrl($url); |
|
| 43 | + $file_handle = fopen($dstpath, "w"); |
|
| 44 | + |
|
| 45 | + if (!$file_handle) { |
|
| 46 | + throw new \Sabre\DAV\Exception('[CURL] Error writing to temporary file! (' . $dstpath . ')'); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + //straight up curl instead of sabredav here, sabredav put's the entire get result in memory |
|
| 50 | + $curl = curl_init($url); |
|
| 51 | + |
|
| 52 | + if ($this->verifyPeer !== null) { |
|
| 53 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifyPeer); |
|
| 54 | + } |
|
| 55 | + if ($this->trustedCertificates) { |
|
| 56 | + curl_setopt($curl, CURLOPT_CAINFO, $this->trustedCertificates); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + curl_setopt($curl, CURLOPT_USERPWD, $this->userName . ":" . $this->password); |
|
| 60 | + curl_setopt($curl, CURLOPT_FILE, $file_handle); |
|
| 61 | + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
| 62 | + curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 63 | + curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 64 | + |
|
| 65 | + curl_exec($curl); |
|
| 66 | + |
|
| 67 | + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
| 68 | + |
|
| 69 | + curl_close($curl); |
|
| 70 | + |
|
| 71 | + $response = array( |
|
| 72 | + 'statusCode' => $statusCode |
|
| 73 | + ); |
|
| 74 | + |
|
| 75 | + if ($response['statusCode'] >= 400) { |
|
| 76 | + switch ($response['statusCode']) { |
|
| 77 | + case 400 : |
|
| 78 | + throw new \Sabre\DAV\Exception\BadRequest('Bad request'); |
|
| 79 | + case 401 : |
|
| 80 | + throw new \Sabre\DAV\Exception\NotAuthenticated('Not authenticated'); |
|
| 81 | + case 402 : |
|
| 82 | + throw new \Sabre\DAV\Exception\PaymentRequired('Payment required'); |
|
| 83 | + case 403 : |
|
| 84 | + throw new \Sabre\DAV\Exception\Forbidden('Forbidden'); |
|
| 85 | + case 404: |
|
| 86 | + throw new \Sabre\DAV\Exception\NotFound('Resource not found.'); |
|
| 87 | + case 405 : |
|
| 88 | + throw new \Sabre\DAV\Exception\MethodNotAllowed('Method not allowed'); |
|
| 89 | + case 409 : |
|
| 90 | + throw new \Sabre\DAV\Exception\Conflict('Conflict'); |
|
| 91 | + case 412 : |
|
| 92 | + throw new \Sabre\DAV\Exception\PreconditionFailed('Precondition failed'); |
|
| 93 | + case 416 : |
|
| 94 | + throw new \Sabre\DAV\Exception\RequestedRangeNotSatisfiable('Requested Range Not Satisfiable'); |
|
| 95 | + case 500 : |
|
| 96 | + throw new \Sabre\DAV\Exception('Internal server error'); |
|
| 97 | + case 501 : |
|
| 98 | + throw new \Sabre\DAV\Exception\NotImplemented('Not Implemented'); |
|
| 99 | + case 507 : |
|
| 100 | + throw new \Sabre\DAV\Exception\InsufficientStorage('Insufficient storage'); |
|
| 101 | + default: |
|
| 102 | + throw new \Sabre\DAV\Exception('HTTP error response. (errorcode ' . $response['statusCode'] . ')'); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $response; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + public function uploadChunkedFile($destination, $resource) { |
|
| 110 | + return $this->request("PUT", $destination, $resource); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -59,8 +59,8 @@ |
||
| 59 | 59 | curl_setopt($curl, CURLOPT_USERPWD, $this->userName . ":" . $this->password); |
| 60 | 60 | curl_setopt($curl, CURLOPT_FILE, $file_handle); |
| 61 | 61 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
| 62 | - curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 63 | - curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 62 | + curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 63 | + curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 64 | 64 | |
| 65 | 65 | curl_exec($curl); |
| 66 | 66 | |
@@ -5,11 +5,11 @@ |
||
| 5 | 5 | abstract class AbstractCSSLoader |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - protected $cssBuffer = ""; |
|
| 8 | + protected $cssBuffer = ""; |
|
| 9 | 9 | |
| 10 | - // path to css folder |
|
| 11 | - protected $CSS_PATH; |
|
| 10 | + // path to css folder |
|
| 11 | + protected $CSS_PATH; |
|
| 12 | 12 | |
| 13 | - // get combined css string |
|
| 14 | - abstract public function get_combined_css($debug = false); |
|
| 13 | + // get combined css string |
|
| 14 | + abstract public function get_combined_css($debug = false); |
|
| 15 | 15 | } |
| 16 | 16 | \ No newline at end of file |
@@ -3,5 +3,5 @@ |
||
| 3 | 3 | |
| 4 | 4 | interface iFeatureVersionInfo |
| 5 | 5 | { |
| 6 | - public function getServerVersion(); |
|
| 6 | + public function getServerVersion(); |
|
| 7 | 7 | } |
| 8 | 8 | \ No newline at end of file |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | // For backward compatibility we must check if the file exists |
| 8 | 8 | if ( file_exists(BASE_PATH . 'server/includes/core/class.encryptionstore.php') ) { |
| 9 | - require_once(BASE_PATH . 'server/includes/core/class.encryptionstore.php'); |
|
| 9 | + require_once(BASE_PATH . 'server/includes/core/class.encryptionstore.php'); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | use \Files\Core\Util\Logger; |
@@ -14,174 +14,174 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | class BackendStore |
| 16 | 16 | { |
| 17 | - const EXTERNAL_BACKEND_PREFIX = "filesbackend"; // folder prefix for external backends |
|
| 18 | - private $EXTERNAL_BACKEND_DIR = ""; // path to search for external plugins (should be grommunio-web/plugins) |
|
| 19 | - const BACKEND_DIR = "/"; // path to search for core backends, relative to current path |
|
| 20 | - const LOG_CONTEXT = "BackendStore"; // Context for the Logger |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Feature variables |
|
| 25 | - */ |
|
| 26 | - const FEATURE_QUOTA = "Quota"; |
|
| 27 | - const FEATURE_VERSION = "VersionInfo"; |
|
| 28 | - const FEATURE_SHARING = "Sharing"; |
|
| 29 | - const FEATURE_STREAMING = "Streaming"; |
|
| 30 | - const FEATURE_OAUTH = "OAUTH"; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var AbstractBackend |
|
| 34 | - */ |
|
| 35 | - private $backends = array(); |
|
| 36 | - protected static $_instance = null; |
|
| 37 | - |
|
| 38 | - // Make it a singleton |
|
| 39 | - private function __construct() |
|
| 40 | - { |
|
| 41 | - $this->EXTERNAL_BACKEND_DIR = BASE_PATH . PATH_PLUGIN_DIR . "/"; |
|
| 42 | - |
|
| 43 | - Logger::debug(self::LOG_CONTEXT, "Searching for external backends in " . $this->EXTERNAL_BACKEND_DIR); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Call this method to get singleton |
|
| 48 | - * |
|
| 49 | - * @return BackendStore |
|
| 50 | - */ |
|
| 51 | - public static function getInstance() |
|
| 52 | - { |
|
| 53 | - if (null === self::$_instance) { |
|
| 54 | - self::$_instance = new self; |
|
| 55 | - self::$_instance->initialize(); |
|
| 56 | - self::$_instance->initializeExternal(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return self::$_instance; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Search the backend folder for backends and register them |
|
| 64 | - */ |
|
| 65 | - public function initialize() |
|
| 66 | - { |
|
| 67 | - $list = array(); // this hold our plugin folders |
|
| 68 | - $workdir = __DIR__ . self::BACKEND_DIR; |
|
| 69 | - |
|
| 70 | - // Populate the list of directories to check against |
|
| 71 | - if (($directoryHandle = opendir($workdir)) !== FALSE) { |
|
| 72 | - while (($file = readdir($directoryHandle)) !== false) { |
|
| 73 | - // Make sure we're not dealing with a file or a link to the parent directory |
|
| 74 | - if (is_dir($workdir . $file) && ($file == '.' || $file == '..') !== true) { |
|
| 75 | - array_push($list, $file); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - Logger::error(self::LOG_CONTEXT, "Error opening the backend directory: " . $workdir); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - // Register the backends |
|
| 83 | - foreach ($list as $backend) { |
|
| 84 | - Logger::debug(self::LOG_CONTEXT, "Registering backend: " . $backend); |
|
| 85 | - $this->register($backend); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Search the backend folder for external backends and register them |
|
| 91 | - */ |
|
| 92 | - public function initializeExternal() |
|
| 93 | - { |
|
| 94 | - $list = array(); // this hold our plugin folders |
|
| 95 | - $workdir = $this->EXTERNAL_BACKEND_DIR; |
|
| 96 | - |
|
| 97 | - // Populate the list of directories to check against |
|
| 98 | - if (($directoryHandle = opendir($workdir)) !== FALSE) { |
|
| 99 | - while (($file = readdir($directoryHandle)) !== false) { |
|
| 100 | - // Make sure we're not dealing with a file or a link to the parent directory |
|
| 101 | - if (is_dir($workdir . $file) && ($file == '.' || $file == '..') !== true && StringUtil::startsWith($file, self::EXTERNAL_BACKEND_PREFIX)) { |
|
| 102 | - $backendName = substr($file, strlen(self::EXTERNAL_BACKEND_PREFIX)); |
|
| 103 | - array_push($list, $backendName); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } else { |
|
| 107 | - Logger::error(self::LOG_CONTEXT, "Error opening the external backend directory: " . $workdir); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Register the backends |
|
| 111 | - foreach ($list as $backend) { |
|
| 112 | - Logger::debug(self::LOG_CONTEXT, "Registering external backend: " . $backend); |
|
| 113 | - $this->registerExternal($backend); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Registration adds the backend to the list of plugins, and also |
|
| 119 | - * includes it's code into our runtime. |
|
| 120 | - * |
|
| 121 | - * @param $backend |
|
| 122 | - */ |
|
| 123 | - private function register($backend) |
|
| 124 | - { |
|
| 125 | - require_once(__DIR__ . self::BACKEND_DIR . $backend . "/class.backend.php"); |
|
| 126 | - array_push($this->backends, $backend); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Registration adds the external backend to the list of plugins, and also |
|
| 131 | - * includes it's code into our runtime. |
|
| 132 | - * |
|
| 133 | - * @param $backend |
|
| 134 | - */ |
|
| 135 | - private function registerExternal($backend) |
|
| 136 | - { |
|
| 137 | - require_once($this->EXTERNAL_BACKEND_DIR . self::EXTERNAL_BACKEND_PREFIX . $backend . "/php/class.backend.php"); |
|
| 138 | - array_push($this->backends, $backend); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Check if a backend is registered. |
|
| 143 | - * |
|
| 144 | - * @param $backend |
|
| 145 | - * |
|
| 146 | - * @return bool |
|
| 147 | - */ |
|
| 148 | - public function backendExists($backend) |
|
| 149 | - { |
|
| 150 | - foreach ($this->backends as $registeredbackend) { |
|
| 151 | - if ($backend === $registeredbackend) { |
|
| 152 | - return true; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - Logger::log(self::LOG_CONTEXT, "Backend does not exist: " . $backend); |
|
| 157 | - |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Creates a new Instance of the given backendtype. |
|
| 163 | - * |
|
| 164 | - * @param $backend |
|
| 165 | - * |
|
| 166 | - * @return AbstractBackend |
|
| 167 | - */ |
|
| 168 | - public function getInstanceOfBackend($backend) |
|
| 169 | - { |
|
| 170 | - if ($this->backendExists($backend)) { |
|
| 171 | - $class = "\\Files\\Backend\\$backend\\Backend"; |
|
| 172 | - |
|
| 173 | - return new $class(); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - return FALSE; // return false if the backend does not exist |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Return all registered backend internal names. |
|
| 181 | - * @return array |
|
| 182 | - */ |
|
| 183 | - public function getRegisteredBackendNames() |
|
| 184 | - { |
|
| 185 | - return $this->backends; |
|
| 186 | - } |
|
| 17 | + const EXTERNAL_BACKEND_PREFIX = "filesbackend"; // folder prefix for external backends |
|
| 18 | + private $EXTERNAL_BACKEND_DIR = ""; // path to search for external plugins (should be grommunio-web/plugins) |
|
| 19 | + const BACKEND_DIR = "/"; // path to search for core backends, relative to current path |
|
| 20 | + const LOG_CONTEXT = "BackendStore"; // Context for the Logger |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Feature variables |
|
| 25 | + */ |
|
| 26 | + const FEATURE_QUOTA = "Quota"; |
|
| 27 | + const FEATURE_VERSION = "VersionInfo"; |
|
| 28 | + const FEATURE_SHARING = "Sharing"; |
|
| 29 | + const FEATURE_STREAMING = "Streaming"; |
|
| 30 | + const FEATURE_OAUTH = "OAUTH"; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var AbstractBackend |
|
| 34 | + */ |
|
| 35 | + private $backends = array(); |
|
| 36 | + protected static $_instance = null; |
|
| 37 | + |
|
| 38 | + // Make it a singleton |
|
| 39 | + private function __construct() |
|
| 40 | + { |
|
| 41 | + $this->EXTERNAL_BACKEND_DIR = BASE_PATH . PATH_PLUGIN_DIR . "/"; |
|
| 42 | + |
|
| 43 | + Logger::debug(self::LOG_CONTEXT, "Searching for external backends in " . $this->EXTERNAL_BACKEND_DIR); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Call this method to get singleton |
|
| 48 | + * |
|
| 49 | + * @return BackendStore |
|
| 50 | + */ |
|
| 51 | + public static function getInstance() |
|
| 52 | + { |
|
| 53 | + if (null === self::$_instance) { |
|
| 54 | + self::$_instance = new self; |
|
| 55 | + self::$_instance->initialize(); |
|
| 56 | + self::$_instance->initializeExternal(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return self::$_instance; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Search the backend folder for backends and register them |
|
| 64 | + */ |
|
| 65 | + public function initialize() |
|
| 66 | + { |
|
| 67 | + $list = array(); // this hold our plugin folders |
|
| 68 | + $workdir = __DIR__ . self::BACKEND_DIR; |
|
| 69 | + |
|
| 70 | + // Populate the list of directories to check against |
|
| 71 | + if (($directoryHandle = opendir($workdir)) !== FALSE) { |
|
| 72 | + while (($file = readdir($directoryHandle)) !== false) { |
|
| 73 | + // Make sure we're not dealing with a file or a link to the parent directory |
|
| 74 | + if (is_dir($workdir . $file) && ($file == '.' || $file == '..') !== true) { |
|
| 75 | + array_push($list, $file); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + Logger::error(self::LOG_CONTEXT, "Error opening the backend directory: " . $workdir); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + // Register the backends |
|
| 83 | + foreach ($list as $backend) { |
|
| 84 | + Logger::debug(self::LOG_CONTEXT, "Registering backend: " . $backend); |
|
| 85 | + $this->register($backend); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Search the backend folder for external backends and register them |
|
| 91 | + */ |
|
| 92 | + public function initializeExternal() |
|
| 93 | + { |
|
| 94 | + $list = array(); // this hold our plugin folders |
|
| 95 | + $workdir = $this->EXTERNAL_BACKEND_DIR; |
|
| 96 | + |
|
| 97 | + // Populate the list of directories to check against |
|
| 98 | + if (($directoryHandle = opendir($workdir)) !== FALSE) { |
|
| 99 | + while (($file = readdir($directoryHandle)) !== false) { |
|
| 100 | + // Make sure we're not dealing with a file or a link to the parent directory |
|
| 101 | + if (is_dir($workdir . $file) && ($file == '.' || $file == '..') !== true && StringUtil::startsWith($file, self::EXTERNAL_BACKEND_PREFIX)) { |
|
| 102 | + $backendName = substr($file, strlen(self::EXTERNAL_BACKEND_PREFIX)); |
|
| 103 | + array_push($list, $backendName); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } else { |
|
| 107 | + Logger::error(self::LOG_CONTEXT, "Error opening the external backend directory: " . $workdir); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Register the backends |
|
| 111 | + foreach ($list as $backend) { |
|
| 112 | + Logger::debug(self::LOG_CONTEXT, "Registering external backend: " . $backend); |
|
| 113 | + $this->registerExternal($backend); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Registration adds the backend to the list of plugins, and also |
|
| 119 | + * includes it's code into our runtime. |
|
| 120 | + * |
|
| 121 | + * @param $backend |
|
| 122 | + */ |
|
| 123 | + private function register($backend) |
|
| 124 | + { |
|
| 125 | + require_once(__DIR__ . self::BACKEND_DIR . $backend . "/class.backend.php"); |
|
| 126 | + array_push($this->backends, $backend); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Registration adds the external backend to the list of plugins, and also |
|
| 131 | + * includes it's code into our runtime. |
|
| 132 | + * |
|
| 133 | + * @param $backend |
|
| 134 | + */ |
|
| 135 | + private function registerExternal($backend) |
|
| 136 | + { |
|
| 137 | + require_once($this->EXTERNAL_BACKEND_DIR . self::EXTERNAL_BACKEND_PREFIX . $backend . "/php/class.backend.php"); |
|
| 138 | + array_push($this->backends, $backend); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Check if a backend is registered. |
|
| 143 | + * |
|
| 144 | + * @param $backend |
|
| 145 | + * |
|
| 146 | + * @return bool |
|
| 147 | + */ |
|
| 148 | + public function backendExists($backend) |
|
| 149 | + { |
|
| 150 | + foreach ($this->backends as $registeredbackend) { |
|
| 151 | + if ($backend === $registeredbackend) { |
|
| 152 | + return true; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + Logger::log(self::LOG_CONTEXT, "Backend does not exist: " . $backend); |
|
| 157 | + |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Creates a new Instance of the given backendtype. |
|
| 163 | + * |
|
| 164 | + * @param $backend |
|
| 165 | + * |
|
| 166 | + * @return AbstractBackend |
|
| 167 | + */ |
|
| 168 | + public function getInstanceOfBackend($backend) |
|
| 169 | + { |
|
| 170 | + if ($this->backendExists($backend)) { |
|
| 171 | + $class = "\\Files\\Backend\\$backend\\Backend"; |
|
| 172 | + |
|
| 173 | + return new $class(); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + return FALSE; // return false if the backend does not exist |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Return all registered backend internal names. |
|
| 181 | + * @return array |
|
| 182 | + */ |
|
| 183 | + public function getRegisteredBackendNames() |
|
| 184 | + { |
|
| 185 | + return $this->backends; |
|
| 186 | + } |
|
| 187 | 187 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | require_once __DIR__ . "/../Core/Util/class.stringutil.php"; |
| 6 | 6 | |
| 7 | 7 | // For backward compatibility we must check if the file exists |
| 8 | -if ( file_exists(BASE_PATH . 'server/includes/core/class.encryptionstore.php') ) { |
|
| 8 | +if (file_exists(BASE_PATH . 'server/includes/core/class.encryptionstore.php')) { |
|
| 9 | 9 | require_once(BASE_PATH . 'server/includes/core/class.encryptionstore.php'); |
| 10 | 10 | } |
| 11 | 11 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function initialize() |
| 66 | 66 | { |
| 67 | - $list = array(); // this hold our plugin folders |
|
| 67 | + $list = array(); // this hold our plugin folders |
|
| 68 | 68 | $workdir = __DIR__ . self::BACKEND_DIR; |
| 69 | 69 | |
| 70 | 70 | // Populate the list of directories to check against |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function initializeExternal() |
| 93 | 93 | { |
| 94 | - $list = array(); // this hold our plugin folders |
|
| 94 | + $list = array(); // this hold our plugin folders |
|
| 95 | 95 | $workdir = $this->EXTERNAL_BACKEND_DIR; |
| 96 | 96 | |
| 97 | 97 | // Populate the list of directories to check against |