Page MenuHomePhorge

No OneTemporary

diff --git a/lib/api/document.php b/lib/api/document.php
index 9e23a24..b740dea 100644
--- a/lib/api/document.php
+++ b/lib/api/document.php
@@ -1,345 +1,345 @@
<?php
/**
+--------------------------------------------------------------------------+
| This file is part of the Kolab File API |
| |
| Copyright (C) 2012-2015, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
class file_api_document extends file_api_common
{
/**
* Request handler
*/
public function handle()
{
$method = $_SERVER['REQUEST_METHOD'];
$this->args = $_GET;
if ($method == 'POST' && !empty($_SERVER['HTTP_X_HTTP_METHOD'])) {
$method = $_SERVER['HTTP_X_HTTP_METHOD'];
}
// Invitation notifications
if ($this->args['method'] == 'invitations') {
return $this->invitations();
}
// Sessions list
if ($this->args['method'] == 'sessions') {
return $this->sessions();
}
// Session and invitations management
if (strpos($this->args['method'], 'document_') === 0) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$post = file_get_contents('php://input');
$this->args += (array) json_decode($post, true);
unset($post);
}
if (empty($this->args['id'])) {
throw new Exception("Missing document ID.", file_api_core::ERROR_CODE);
}
switch ($this->args['method']) {
case 'document_delete':
case 'document_invite':
case 'document_request':
case 'document_decline':
case 'document_accept':
case 'document_cancel':
case 'document_info':
return $this->{$this->args['method']}($this->args['id']);
}
}
// Document content actions for Manticore
else if ($method == 'PUT' || $method == 'GET') {
if (empty($this->args['id'])) {
throw new Exception("Missing document ID.", file_api_core::ERROR_CODE);
}
return $this->{'document_' . strtolower($method)}($this->args['id']);
}
throw new Exception("Unknown method", file_api_core::ERROR_INVALID);
}
/**
* Get file path from manticore session identifier
*/
protected function get_file_path($id)
{
$document = new file_document($this->api);
$file = $document->session_file($id);
return $file['file'];
}
/**
* Get invitations list
*/
protected function invitations()
{
$timestamp = new DateTime('now', new DateTimeZone('UTC'));
$timestamp = $timestamp->format('U');
// Initial tracking request, return just the current timestamp
if ($this->args['timestamp'] == -1) {
return array('timestamp' => $timestamp);
// @TODO: in this mode we should likely return all invitations
// that require user action, otherwise we may skip some unintentionally
}
$document = new file_document($this->api);
$filter = array();
if ($this->args['timestamp']) {
$filter['timestamp'] = $this->args['timestamp'];
}
$list = $document->invitations_list($filter);
return array(
'list' => $list,
'timestamp' => $timestamp,
);
}
/**
* Get sessions list
*/
protected function sessions()
{
$document = new file_document($this->api);
$params = array(
- 'reverse' => rcube_utils::get_boolean((string) $this->args['reverse']),
+ 'reverse' => rcube_utils::get_boolean((string) ($this->args['reverse'] ?? '')),
);
if (!empty($this->args['sort'])) {
$params['sort'] = strtolower($this->args['sort']);
}
return $document->sessions_list($params);
}
/**
* Close (delete) manticore session
*/
protected function document_delete($id)
{
$document = file_document::get_handler($this->api, $id);
if (!$document->session_delete($id)) {
throw new Exception("Failed deleting the document session.", file_api_core::ERROR_CODE);
}
}
/**
* Invite/add a session participant(s)
*/
protected function document_invite($id)
{
$document = file_document::get_handler($this->api, $id);
$users = $this->args['users'];
$comment = $this->args['comment'];
if (empty($users)) {
throw new Exception("Invalid arguments.", file_api_core::ERROR_CODE);
}
foreach ((array) $users as $user) {
if (!empty($user['user'])) {
$document->invitation_create($id, $user['user'], file_document::STATUS_INVITED, $comment, $user['name']);
$result[] = array(
'session_id' => $id,
'user' => $user['user'],
'user_name' => $user['name'],
'status' => file_document::STATUS_INVITED,
);
}
}
return array(
'list' => $result,
);
}
/**
* Request an invitation to a session
*/
protected function document_request($id)
{
$document = file_document::get_handler($this->api, $id);
$document->invitation_create($id, null, file_document::STATUS_REQUESTED, $this->args['comment']);
}
/**
* Decline an invitation to a session
*/
protected function document_decline($id)
{
$document = file_document::get_handler($this->api, $id);
$document->invitation_update($id, $this->args['user'], file_document::STATUS_DECLINED, $this->args['comment']);
}
/**
* Accept an invitation to a session
*/
protected function document_accept($id)
{
$document = file_document::get_handler($this->api, $id);
$document->invitation_update($id, $this->args['user'], file_document::STATUS_ACCEPTED, $this->args['comment']);
}
/**
* Remove a session participant(s) - cancel invitations
*/
protected function document_cancel($id)
{
$document = file_document::get_handler($this->api, $id);
$users = $this->args['users'];
if (empty($users)) {
throw new Exception("Invalid arguments.", file_api_core::ERROR_CODE);
}
foreach ((array) $users as $user) {
$document->invitation_delete($id, $user);
$result[] = $user;
}
return array(
'list' => $result,
);
}
/**
* Return document informations
*/
protected function document_info($id, $extended = true)
{
$document = file_document::get_handler($this->api, $id);
$file = $document->session_file($id, true);
$rcube = rcube::get_instance();
try {
list($driver, $path) = $this->api->get_driver($file['file']);
$result = $driver->file_info($path);
}
catch (Exception $e) {
// invited users may have no permission,
// use file data from the session
$result = array(
'size' => $file['size'],
'name' => $file['name'],
'modified' => $file['modified'],
'type' => $file['type'],
);
}
if ($extended) {
$session = $document->session_info($id);
$result['owner'] = $session['owner'];
$result['owner_name'] = $session['owner_name'];
$result['user'] = $rcube->user->get_username();
$result['readonly'] = !empty($session['readonly']);
$result['origin'] = $session['origin'];
if ($result['owner'] == $result['user']) {
$result['user_name'] = $result['owner_name'];
}
else {
$result['user_name'] = $this->api->resolve_user($result['user']) ?: '';
}
}
return $result;
}
/**
* Update document file content
*/
protected function document_put($id)
{
$file = $this->get_file_path($id);
list($driver, $path) = $this->api->get_driver($file);
$length = rcube_utils::request_header('Content-Length');
$tmp_dir = unslashify($this->api->config->get('temp_dir'));
$tmp_path = tempnam($tmp_dir, 'chwalaUpload');
// Create stream to copy input into a temp file
$input = fopen('php://input', 'r');
$tmp_file = fopen($tmp_path, 'w');
if (!$input || !$tmp_file) {
throw new Exception("Failed opening input or temp file stream.", file_api_core::ERROR_CODE);
}
// Create temp file from the input
$copied = stream_copy_to_stream($input, $tmp_file);
fclose($input);
fclose($tmp_file);
if ($copied < $length) {
throw new Exception("Failed writing to temp file.", file_api_core::ERROR_CODE);
}
$file_data = array(
'path' => $tmp_path,
'type' => rcube_mime::file_content_type($tmp_path, $file),
);
$driver->file_update($path, $file_data);
// remove the temp file
unlink($tmp_path);
// Update the file metadata in session
$file_data = $driver->file_info($path);
$document = file_document::get_handler($this->api, $this->args['id']);
$document->session_update($this->args['id'], $file_data);
}
/**
* Return document file content
*/
protected function document_get($id)
{
$file = $this->get_file_path($id);
list($driver, $path) = $this->api->get_driver($file);
try {
$params = array('force-type' => 'application/vnd.oasis.opendocument.text');
$driver->file_get($path, $params);
}
catch (Exception $e) {
header("HTTP/1.0 " . file_api_core::ERROR_CODE . " " . $e->getMessage());
}
$this->api->output_send();
}
}
diff --git a/lib/api/file_create.php b/lib/api/file_create.php
index 12cc814..45a477b 100644
--- a/lib/api/file_create.php
+++ b/lib/api/file_create.php
@@ -1,110 +1,110 @@
<?php
/*
+--------------------------------------------------------------------------+
| This file is part of the Kolab File API |
| |
| Copyright (C) 2012-2014, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
class file_api_file_create extends file_api_common
{
/**
* Request handler
*/
public function handle()
{
parent::handle();
if (!isset($this->args['file']) || $this->args['file'] === '') {
throw new Exception("Missing file name", file_api_core::ERROR_CODE);
}
if (!isset($this->args['content'])) {
if (!($this->api instanceof file_api_lib) || empty($this->args['path'])) {
throw new Exception("Missing file content", file_api_core::ERROR_CODE);
}
}
$is_file = false;
if (is_resource($this->args['content'])) {
$chunk = stream_get_contents($this->args['content'], 1024000, 0);
}
else if ($this->args['path'] ?? null) {
$chunk = $this->args['path'];
$is_file = true;
}
else {
$chunk = $this->args['content'];
}
- $ctype = $this->args['content-type'];
+ $ctype = $this->args['content-type'] ?? '';
if ($ctype && !preg_match('/^[a-z_-]+\/[a-z._-]+$/', $ctype)) {
$ctype = '';
}
$request = $this instanceof file_api_file_update ? 'file_update' : 'file_create';
$file = array(
'content' => $this->args['content'],
'path' => $this->args['path'] ?? null,
'type' => rcube_mime::file_content_type($chunk, $this->args['file'] ?? null, $ctype, !$is_file),
);
if (strpos($file['type'], 'empty') !== false && $ctype) {
$file['type'] = $ctype;
}
else if (empty($file['type'])) {
$file['type'] = 'application/octet-stream';
}
// Get file content from a template
if ($request == 'file_create' && empty($file['path']) && empty($file['content'])) {
$this->use_file_template($file);
}
list($driver, $path) = $this->api->get_driver($this->args['file']);
$driver->$request($path, $file);
- if (rcube_utils::get_boolean((string) ($this->args['info'] ?? null))) {
+ if (rcube_utils::get_boolean((string) ($this->args['info'] ?? ''))) {
return $driver->file_info($path);
}
}
/**
* Use templates when creating empty files
*/
protected function use_file_template(&$file)
{
if ($ext = array_search($file['type'], file_utils::$ext_map)) {
// find the template
$ext = ".$ext";
if ($handle = opendir(__DIR__ . '/../templates')) {
while (false !== ($entry = readdir($handle))) {
if (substr($entry, -strlen($ext)) == $ext) {
// set path to the template file
$file['path'] = __DIR__ . '/../templates/' . $entry;
break;
}
}
closedir($handle);
}
}
}
}
diff --git a/lib/api/file_get.php b/lib/api/file_get.php
index 249584c..6d79e4f 100644
--- a/lib/api/file_get.php
+++ b/lib/api/file_get.php
@@ -1,103 +1,103 @@
<?php
/*
+--------------------------------------------------------------------------+
| This file is part of the Kolab File API |
| |
| Copyright (C) 2012-2014, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
class file_api_file_get extends file_api_common
{
protected $driver;
/**
* Request handler
*/
public function handle()
{
parent::handle();
$this->api->output_type = file_api_core::OUTPUT_HTML;
if (!isset($this->args['file']) || $this->args['file'] === '') {
header("HTTP/1.0 ".file_api_core::ERROR_CODE." Missing file name");
}
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST' && !empty($_SERVER['HTTP_X_HTTP_METHOD'])) {
$method = $_SERVER['HTTP_X_HTTP_METHOD'];
}
$params = array(
- 'force-download' => rcube_utils::get_boolean((string) $this->args['force-download'] ?? ""),
+ 'force-download' => rcube_utils::get_boolean((string) ($this->args['force-download'] ?? '')),
'force-type' => $this->args['force-type'] ?? null,
'head' => ($this->args['head'] ?? null) ?: $method == 'HEAD',
);
list($this->driver, $path) = $this->api->get_driver($this->args['file']);
if (!empty($this->args['viewer'])) {
$this->file_view($path, $this->args, $params);
}
try {
$this->driver->file_get($path, $params);
}
catch (Exception $e) {
header("HTTP/1.0 " . file_api_core::ERROR_CODE . " " . $e->getMessage());
}
exit;
}
/**
* File vieweing request handler
*/
protected function file_view($file, $args, $params)
{
$viewer = $args['viewer'];
$path = __DIR__ . "/../viewers/$viewer.php";
$class = "file_viewer_$viewer";
if (!file_exists($path)) {
return;
}
// get file info
try {
$info = $this->driver->file_info($file);
}
catch (Exception $e) {
header("HTTP/1.0 " . file_api_core::ERROR_CODE . " " . $e->getMessage());
exit;
}
include_once $path;
$viewer = new $class($this->api);
// check if specified viewer supports file type
// otherwise return (fallback to file_get action)
if (!$viewer->supports($info['type'])) {
return;
}
$viewer->output($args['file'], $info);
exit;
}
}
diff --git a/lib/api/file_info.php b/lib/api/file_info.php
index 6e62a3b..8d1caaf 100644
--- a/lib/api/file_info.php
+++ b/lib/api/file_info.php
@@ -1,180 +1,180 @@
<?php
/*
+--------------------------------------------------------------------------+
| This file is part of the Kolab File API |
| |
| Copyright (C) 2012-2015, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
class file_api_file_info extends file_api_common
{
/**
* Request handler
*/
public function handle()
{
parent::handle();
// check Manticore support. Note: we don't use config->get('fileapi_manticore')
// here as it may be not properly set if backend driver wasn't initialized yet
$capabilities = $this->api->capabilities(false);
$manticore = $capabilities['MANTICORE'] ?? null;
$wopi = $capabilities['WOPI'] ?? null;
// support file_info by session ID
if (!isset($this->args['file']) || $this->args['file'] === '') {
if (($manticore || $wopi) && !empty($this->args['session'])) {
if ($info = $this->file_document_file($this->args['session'])) {
$this->args['file'] = $info['file'];
}
}
else {
throw new Exception("Missing file name", file_api_core::ERROR_CODE);
}
}
if ($this->args['file'] !== null) {
try {
list($driver, $path) = $this->api->get_driver($this->args['file']);
$info = $driver->file_info($path);
$info['file'] = $this->args['file'];
}
catch (Exception $e) {
// Invited user may have no access to the file,
// ignore errors if session exists
if (!$this->args['viewer'] || !$this->args['session']) {
throw $e;
}
}
}
// Possible 'viewer' types are defined in files_api.js:file_type_supported()
// 1 - Native browser support
// 2 - Chwala viewer exists
// 4 - Editor exists (manticore/wopi)
- if (rcube_utils::get_boolean((string) $this->args['viewer'])) {
+ if (rcube_utils::get_boolean((string) ($this->args['viewer'] ?? ''))) {
if ($this->args['file'] !== null) {
$this->file_viewer_info($info);
}
if ((intval($this->args['viewer']) & 4)) {
// @TODO: Chwala client should have a possibility to select
// between wopi and manticore?
if (!$wopi || !$this->file_wopi_handler($info)) {
if ($manticore) {
$this->file_manticore_handler($info);
}
}
}
}
// check writable flag
if ($this->args['file'] !== null) {
$path = explode(file_storage::SEPARATOR, $path);
array_pop($path);
$path = implode(file_storage::SEPARATOR, $path);
$acl = $driver->folder_rights($path);
$info['writable'] = ($acl & file_storage::ACL_WRITE) != 0;
}
return $info;
}
/**
* Merge file viewer data into file info
*/
protected function file_viewer_info(&$info)
{
$file = $this->args['file'];
$viewer = $this->find_viewer($info['type']);
if ($viewer) {
$info['viewer'] = array();
if ($frame = $viewer->frame($file, $info['type'])) {
$info['viewer']['frame'] = $frame;
}
else if ($href = $viewer->href($file, $info['type'])) {
$info['viewer']['href'] = $href;
}
}
}
/**
* Get file from manticore/wopi session
*/
protected function file_document_file($session_id)
{
$document = file_document::get_handler($this->api, $session_id);
return $document->session_file($session_id, true);
}
/**
* Merge manticore session data into file info
*/
protected function file_manticore_handler(&$info)
{
$manticore = new file_manticore($this->api);
$file = $this->args['file'];
$session = $this->args['session'];
if (in_array_nocase($info['type'], $manticore->supported_filetypes(true))) {
$info['viewer']['manticore'] = true;
}
else {
return false;
}
if ($uri = $manticore->session_start($file, $info, $session)) {
$info['viewer']['href'] = $uri;
$info['viewer']['post'] = $manticore->editor_post_params($info);
$info['session'] = $manticore->session_info($session, true);
}
return true;
}
/**
* Merge WOPI session data into file info
*/
protected function file_wopi_handler(&$info)
{
$wopi = new file_wopi($this->api);
$file = $this->args['file'];
$session = $this->args['session'];
if (in_array_nocase($info['type'], $wopi->supported_filetypes(true))) {
$info['viewer']['wopi'] = true;
}
else {
return false;
}
if ($uri = $wopi->session_start($file, $info, $session)) {
$info['viewer']['href'] = $uri;
$info['viewer']['post'] = $wopi->editor_post_params($info);
$info['session'] = $wopi->session_info($session, true);
}
return true;
}
}
diff --git a/lib/api/file_list.php b/lib/api/file_list.php
index 7d7a416..82f2d4e 100644
--- a/lib/api/file_list.php
+++ b/lib/api/file_list.php
@@ -1,62 +1,62 @@
<?php
/*
+--------------------------------------------------------------------------+
| This file is part of the Kolab File API |
| |
| Copyright (C) 2012-2014, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
class file_api_file_list extends file_api_common
{
/**
* Request handler
*/
public function handle()
{
parent::handle();
if (!isset($this->args['folder']) || $this->args['folder'] === '') {
throw new Exception("Missing folder name", file_api_core::ERROR_CODE);
}
$params = array(
- 'reverse' => rcube_utils::get_boolean((string) ($this->args['reverse'] ?? "")),
+ 'reverse' => rcube_utils::get_boolean((string) ($this->args['reverse'] ?? '')),
);
if (!empty($this->args['sort'])) {
$params['sort'] = strtolower($this->args['sort']);
}
if (!empty($this->args['search'])) {
$params['search'] = $this->args['search'];
if (!is_array($params['search'])) {
$params['search'] = array('name' => $params['search']);
}
}
list($driver, $path) = $this->api->get_driver($this->args['folder']);
// add mount point prefix to file paths
if ($path != $this->args['folder']) {
$params['prefix'] = substr($this->args['folder'], 0, -strlen($path));
}
return $driver->file_list($path, $params);
}
}
diff --git a/lib/api/file_move.php b/lib/api/file_move.php
index ce2ba10..8ee4414 100644
--- a/lib/api/file_move.php
+++ b/lib/api/file_move.php
@@ -1,163 +1,163 @@
<?php
/*
+--------------------------------------------------------------------------+
| This file is part of the Kolab File API |
| |
| Copyright (C) 2012-2014, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
class file_api_file_move extends file_api_common
{
/**
* Request handler
*/
public function handle()
{
parent::handle();
if (!isset($this->args['file']) || $this->args['file'] === '') {
throw new Exception("Missing file name", file_api_core::ERROR_CODE);
}
if (is_array($this->args['file'])) {
if (empty($this->args['file'])) {
throw new Exception("Missing file name", file_api_core::ERROR_CODE);
}
}
else {
if (!isset($this->args['new']) || $this->args['new'] === '') {
throw new Exception("Missing new file name", file_api_core::ERROR_CODE);
}
$this->args['file'] = array($this->args['file'] => $this->args['new']);
}
- $overwrite = rcube_utils::get_boolean((string) $this->args['overwrite']);
+ $overwrite = rcube_utils::get_boolean((string) ($this->args['overwrite'] ?? ''));
$request = $this instanceof file_api_file_copy ? 'file_copy' : 'file_move';
$errors = array();
foreach ((array) $this->args['file'] as $file => $new_file) {
if ($new_file === '') {
throw new Exception("Missing new file name", file_api_core::ERROR_CODE);
}
if ($new_file === $file) {
throw new Exception("Old and new file name is the same", file_api_core::ERROR_CODE);
}
list($driver, $path) = $this->api->get_driver($file);
list($new_driver, $new_path) = $this->api->get_driver($new_file);
try {
// source and destination on the same driver...
if ($driver == $new_driver) {
$driver->{$request}($path, $new_path);
}
// cross-driver move/copy...
else {
// first check if destination file exists
$info = null;
try {
$info = $new_driver->file_info($new_path);
}
catch (Exception $e) { }
if (!empty($info)) {
throw new Exception("File exists", file_storage::ERROR_FILE_EXISTS);
}
// copy/move between backends
$this->file_copy($driver, $new_driver, $path, $new_path, $request == 'file_move');
}
}
catch (Exception $e) {
if ($e->getCode() == file_storage::ERROR_FILE_EXISTS) {
// delete existing file and do copy/move again
if ($overwrite) {
$new_driver->file_delete($new_path);
if ($driver == $new_driver) {
$driver->{$request}($path, $new_path);
}
else {
$this->file_copy($driver, $new_driver, $path, $new_path, $request == 'file_move');
}
}
// collect file-exists errors, so the client can ask a user
// what to do and skip or replace file(s)
else {
$errors[] = array(
'src' => $file,
'dst' => $new_file,
);
}
}
else {
throw $e;
}
}
// Update manticore sessions
if ($request == 'file_move') {
$this->session_uri_update($file, $new_file, false);
}
}
if (!empty($errors)) {
return array('already_exist' => $errors);
}
}
/**
* File copy/move between storage backends
*/
protected function file_copy($driver, $new_driver, $path, $new_path, $move = false)
{
// unable to put file on mount point
if (strpos($new_path, file_storage::SEPARATOR) === false) {
throw new Exception("Unable to copy/move file into specified location", file_api_core::ERROR_CODE);
}
// get the file from source location
$fp = fopen('php://temp', 'w+');
if (!$fp) {
throw new Exception("Internal server error", file_api_core::ERROR_CODE);
}
$driver->file_get($path, null, $fp);
rewind($fp);
$chunk = stream_get_contents($fp, 102400);
$type = rcube_mime::file_content_type($chunk, $new_path, 'application/octet-stream', true);
rewind($fp);
// upload the file to new location
$new_driver->file_create($new_path, array('content' => $fp, 'type' => $type));
fclose($fp);
// now we can remove the original file if it was a move action
if ($move) {
$driver->file_delete($path);
}
}
}
diff --git a/lib/api/folder_auth.php b/lib/api/folder_auth.php
index 9bbe42d..896b184 100644
--- a/lib/api/folder_auth.php
+++ b/lib/api/folder_auth.php
@@ -1,82 +1,82 @@
<?php
/*
+--------------------------------------------------------------------------+
| This file is part of the Kolab File API |
| |
| Copyright (C) 2012-2014, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
class file_api_folder_auth extends file_api_common
{
/**
* Request handler
*/
public function handle()
{
parent::handle();
if (!isset($this->args['folder']) || $this->args['folder'] === '') {
throw new Exception("Missing folder name", file_api_core::ERROR_CODE);
}
list($driver, $path, $driver_config) = $this->api->get_driver($this->args['folder']);
if (empty($driver) || $driver->title() === '') {
throw new Exception("Unknown folder", file_api_core::ERROR_CODE);
}
// check if authentication works
$meta = $driver->driver_metadata();
$data = array_fill_keys(array_keys($meta['form']), '');
$data = array_merge($data, $this->args);
$data = $driver->driver_validate($data);
// optionally store (encrypted) passwords
if (!empty($data['password']) && rcube_utils::get_boolean((string) $this->args['store_passwords'])) {
$data['password'] = $this->api->encrypt($data['password']);
}
else {
unset($data['password']);
unset($driver_config['password']);
}
// save changed data
foreach (array_keys($meta['form']) as $key) {
if ($meta['form_values'][$key] != $data[$key]) {
// update driver config
$driver_config = array_merge($driver_config, $data);
$backend = $this->api->get_backend();
$backend->driver_update($this->args['folder'], $driver_config);
break;
}
}
$result = array('folder' => $this->args['folder']);
// get list of folders if requested
- if (rcube_utils::get_boolean((string) $this->args['list'])) {
+ if (rcube_utils::get_boolean((string) ($this->args['list'] ?? ''))) {
$params = $this->folder_list_params();
$params['path'] = $path;
$result['list'] = $this->folder_list($driver, $params, true);
}
return $result;
}
}
diff --git a/lib/api/lock_list.php b/lib/api/lock_list.php
index 83f609d..27e654a 100644
--- a/lib/api/lock_list.php
+++ b/lib/api/lock_list.php
@@ -1,40 +1,40 @@
<?php
/*
+--------------------------------------------------------------------------+
| This file is part of the Kolab File API |
| |
| Copyright (C) 2012-2014, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
class file_api_lock_list extends file_api_common
{
/**
* Request handler
*/
public function handle()
{
parent::handle();
- $child_locks = rcube_utils::get_boolean($this->args['child_locks']);
+ $child_locks = rcube_utils::get_boolean($this->args['child_locks'] ?? '');
list($driver, $uri) = $this->api->get_driver($this->args['uri']);
return $driver->lock_list($uri, $child_locks);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 10, 12:46 AM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
196904
Default Alt Text
(42 KB)

Event Timeline