Projects
Kolab:16:Testing
chwala
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 15
View file
chwala.spec
Changed
@@ -38,7 +38,7 @@ %global upstream_version 0.5.14 Name: chwala -Version: 0.5.14.3 +Version: 0.5.14.5 Release: 1%{?dist} Summary: Glorified WebDAV, done right
View file
chwala-0.5.14.tar.gz/lib/api/document.php
Changed
@@ -262,7 +262,12 @@ $result'owner' = $session'owner'; $result'owner_name' = $session'owner_name'; - $result'user' = $rcube->user->get_username(); + if ($rcube && $rcube->user) { + $result'user' = $rcube->user->get_username(); + } else { + //Fall back to the owner if we don't have the rcube user initialized (wopi with kolabfiles) + $result'user' = $session'owner'; + } $result'readonly' = !empty($session'readonly'); $result'origin' = $session'origin';
View file
chwala-0.5.14.tar.gz/lib/drivers/kolab/kolab_file_storage.php
Changed
@@ -54,6 +54,11 @@ */ protected $lock_db; + /** + * @var ?object + */ + protected $driver_list = null; + /** * Class constructor @@ -186,7 +191,8 @@ // parse $host $a_host = parse_url($host); $port = null; - if ($a_host'host') { + $ssl = null; + if (!empty($a_host'host')) { $host = $a_host'host'; $ssl = (isset($a_host'scheme') && in_array($a_host'scheme', array('ssl','imaps','tls'))) ? $a_host'scheme' : null; if (!empty($a_host'port')) {
View file
chwala-0.5.14.tar.gz/lib/drivers/kolabfiles
Added
+(directory)
View file
chwala-0.5.14.tar.gz/lib/drivers/kolabfiles/kolabfiles_file_storage.php
Added
@@ -0,0 +1,1173 @@ +<?php +/* + +--------------------------------------------------------------------------+ + | This file is part of the Kolab File API | + | | + | Copyright (C) 2024, Apheleia It | + | | + | 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: Christian Mollekopf <mollekopf@apheleia-it.ch> | + +--------------------------------------------------------------------------+ +*/ + +// FIXME +// * Support non-toplevel folders for collection creation/moves/... +// * Paging (we don't display beyond the first page (100 items)) +// * Searching is not implemented +class kolabfiles_file_storage implements file_storage +{ + /** + * @var rcube + */ + protected $rc; + + protected $client = null; + + /** + * @var array + */ + protected $config = array(); + + /** + * List of Kolabfiles collections + * + * @var array + */ + protected $collections; + + /** + * Instance title (mount point) + * + * @var string + */ + protected $title; + + + /** + * Class constructor + */ + public function __construct() + { + $this->rc = rcube::get_instance(); + $this->config = + 'baseuri' => $this->rc->config->get('fileapi_kolabfiles_baseuri', 'https://' . $_SERVER"HTTP_HOST" . '/api/'), + 'host' => $this->rc->config->get('fileapi_kolabfiles_host', $_SERVER"HTTP_HOST"), + ; + } + + + protected function init() + { + if ($this->client !== null) { + return true; + } + + $stack = new \GuzzleHttp\HandlerStack(); + $stack->setHandler(\GuzzleHttp\choose_handler()); + $stack->push(\GuzzleHttp\Middleware::retry( + function ( + $retries, + \GuzzleHttp\Psr7\Request $request, + \GuzzleHttp\Psr7\Response $response = null, + \GuzzleHttp\Exception\RequestException $exception = null + ) { + $maxRetries = 2; + + if ($retries >= $maxRetries) { + return false; + } + + if ($response && $response->getStatusCode() === 401) { + $this->refreshClientAccessToken(); + return true; + } + + return false; + } + )); + + $stack->push(\GuzzleHttp\Middleware::mapRequest(function (\GuzzleHttp\Psr7\Request $request) { + //TODO Just forward the bearer token, once we manage to make sure it get's sent to roundcube + // 'Authorization' => rcube_utils::request_header('Authorization') + if ($accessToken = $this->getClientAccessToken()) { + return $request->withHeader('Authorization', 'Bearer ' . $accessToken); + } + return $request; + })); + + $this->client = new \GuzzleHttp\Client( + + 'http_errors' => false, // No exceptions from Guzzle + 'base_uri' => rtrim($this->config'baseuri', '/') . '/', + 'handler' => $stack, + 'verify' => false, + 'connect_timeout' => 10, + 'timeout' => 10, + // 'on_stats' => function (\GuzzleHttp\TransferStats $stats) { + // $threshold = \config('logging.slow_log'); + // if ($threshold && ($sec = $stats->getTransferTime()) > $threshold) { + // $url = $stats->getEffectiveUri(); + // $method = $stats->getRequest()->getMethod(); + // \Log::warning(sprintf("STATS %s %s: %.4f sec.", $method, $url, $sec)); + // } + // }, + + ); + } + + private function getClientAccessToken() + { + if (!empty($_SESSION'access_token')) { + return $this->rc->decrypt($_SESSION'access_token'); + } + return null; + } + + private function refreshClientAccessToken() + { + //TODO use the refresh token if available instead of refreshing from scratch always. + rcube::write_log('kolabfiles', "Refreshing the access token"); + $username = $_SESSION'username'; + $password = $this->rc->decrypt($_SESSION'password'); + + $client = new \GuzzleHttp\Client( + 'http_errors' => false, // No exceptions from Guzzle + 'base_uri' => rtrim($this->config'baseuri', '/') . '/', + 'verify' => false, + 'connect_timeout' => 10, + 'timeout' => 10, + ); + + $response = $client->request('POST', "auth/login?email=$username&password=$password"); + if ($response->getStatusCode() != 200) { + throw new Exception("Failed to authenticate $username:$password"); + } + $json = json_decode($response->getBody(), true); + $accessToken = $json'access_token'; + $_SESSION'access_token' = $this->rc->encrypt($accessToken); + } + + protected function client() + { + $this->init(); + return $this->client; + } + + /** + * Authenticates a user + * + * @param string $username User name + * @param string $password User password + * + * @param bool True on success, False on failure + */ + public function authenticate($username, $password) + { + $_SESSION'username' = $username; + $_SESSION'password' = $this->rc->encrypt($password); + + + $this->init(); + + return true; + } + + /** + * Get password and name of authenticated user + * + * @return array Authenticated user data + */ + public function auth_info() + { + return array( + 'username' => $_SESSION'username', + 'password' => $this->rc->decrypt($_SESSION'password'), + ); + } +
View file
chwala-0.5.14.tar.gz/lib/drivers/seafile/seafile_api.php
Changed
@@ -59,11 +59,11 @@ protected $config = array(); /** - * HTTP request handle + * HTTP client * - * @var HTTP_Request + * @var GuzzleHttp\Client */ - protected $request; + protected $client = null; /** * Web API URI prefix @@ -107,39 +107,6 @@ } /** - * - * @param array Configuration for this Request instance, that will be merged - * with default configuration - * - * @return HTTP_Request2 Request object - */ - public static function http_request($config = array()) - { - // remove unknown config, otherwise HTTP_Request will throw an error - $config = array_intersect_key($config, array_flip(array( - 'connect_timeout', 'timeout', 'use_brackets', 'protocol_version', - 'buffer_size', 'store_body', 'follow_redirects', 'max_redirects', - 'strict_redirects', 'ssl_verify_peer', 'ssl_verify_host', - 'ssl_cafile', 'ssl_capath', 'ssl_local_cert', 'ssl_passphrase' - ))); - - // force CURL adapter, this allows to handle correctly - // compressed responses with simple SplObserver registered - $config'adapter' = 'HTTP_Request2_Adapter_Curl'; - - try { - $request = new HTTP_Request2(); - $request->setConfig($config); - } - catch (Exception $e) { - rcube::raise_error($e, true, false); - return; - } - - return $request; - } - - /** * Send HTTP request * * @param string $method Request method ('OPTIONS','GET','HEAD','POST','PUT','DELETE','TRACE','CONNECT') @@ -166,29 +133,15 @@ $url = str_replace('/api2/', "/api/v$version/", $url); } - if (!$this->request) { - $this->config'store_body' = true; - // some methods respond with 301 redirect, we'll not follow them - // also because of https://github.com/haiwen/seahub/issues/288 - $this->config'follow_redirects' = false; - - $this->request = self::http_request($this->config); - - if (!$this->request) { - $this->status = self::CONNECTION_ERROR; - return; - } - } - - // cleanup - try { - $this->request->setBody(''); - $this->request->setUrl($url); - } - catch (Exception $e) { - rcube::raise_error($e, true, false); - $this->status = self::CONNECTION_ERROR; - return; + if (!$this->client) { + $this->client = new \GuzzleHttp\Client( + + 'http_errors' => true, + 'verify' => false, + 'connect_timeout' => 10, + 'timeout' => 300, + + ); } if ($this->config'debug') { @@ -210,49 +163,73 @@ rcube::write_log('console', $log_line); } - $this->request->setMethod($method ?: HTTP_Request2::METHOD_GET); - - if (!empty($get)) { - $_url = $this->request->getUrl(); - $_url->setQueryVariables($get); - $this->request->setUrl($_url); - } + // send request to the SeaFile API server + try { + $headers = + 'Accept' => "application/json,text/javascript,*/*", + 'User-Agent' => $_SERVER'HTTP_USER_AGENT' + ; - // HTTP_Request2 does not support POST params on PUT requests - if (!empty($post) && $method == 'PUT') { - $body = http_build_query($post, '', '&'); - $body = str_replace('%7E', '~', $body); // support RFC 3986 by not encoding '~' symbol - $post = null; + if ($this->token) { + $headers'Authorization' = "Token " . $this->token; + } - $this->request->setBody($body); - $this->request->setHeader('content-type', 'application/x-www-form-urlencoded'); - } + $options = ; - if (!empty($post)) { - $this->request->addPostParameter($post); - } - if (!empty($upload)) { - foreach ($upload as $field_name => $file) { - $this->request->addUpload($field_name, $file'data', $file'name', $file'type'); + if (!empty($get)) { + $options'query' = $get; } - } - - if ($this->token) { - $this->request->setHeader('Authorization', "Token " . $this->token); - } - // some HTTP server configurations require this header - $this->request->setHeader('Accept', "application/json,text/javascript,*/*"); + if (!empty($upload)) { + if (!empty($post'target_file')) { + $filename = basename($post'target_file'); + } else { + $filename = $upload'file''name'; + } + $multipart = + + 'headers' => 'Content-Type' => 'application/octet-stream', + 'name' => 'file', + 'filename' => $filename, + 'contents' => $upload'file''data' + , + + 'name' => 'name', + 'contents' => $upload'file''name', + , + + 'name' => 'type', + 'contents' => $upload'file''type', + , + ; + + if (array_key_exists('parent_dir', $post)) { + $multipart = + 'name' => 'parent_dir', + 'contents' => $post'parent_dir' + ; + } + if (array_key_exists('target_file', $post)) { + $multipart = + 'name' => 'target_file', + 'contents' => $post'target_file' + ; + } + $options'multipart' = $multipart; + } else { + if (!empty($post)) { + $options'form_params' = $post; + } + } - // proxy User-Agent string - $this->request->setHeader('User-Agent', $_SERVER'HTTP_USER_AGENT'); + if (!empty($headers)) { + $options'headers' = $headers; + } + $response = $this->client->request($method ?: "GET", $url, $options); - // send request to the SeaFile API server - try { - $response = $this->request->send(); - $this->status = $response->getStatus(); - $body = $response->getBody(); + $this->status = $response->getStatusCode(); + $body = $response->getBody();
View file
chwala-0.5.14.tar.gz/lib/drivers/seafile/seafile_file_storage.php
Changed
@@ -379,9 +379,6 @@ $created = $this->api->file_upload($repo_id, $fn, $file); - if ($fp) { - fclose($fp); - } if (!$created) { rcube::raise_error(array( @@ -425,9 +422,6 @@ $saved = $this->api->file_update($repo_id, $fn, $file); - if ($fp) { - fclose($fp); - } if (!$saved) { rcube::raise_error(array( @@ -542,7 +536,6 @@ } else if ($fp = fopen('php://output', 'wb')) { $this->save_file_content($link, $fp); - fclose($fp); } } } @@ -1645,9 +1638,24 @@ } $config = array_merge($this->config, array('store_bodies' => true)); - $request = seafile_api::http_request($config); - if (!$request) { + $config = array_intersect_key($config, array_flip(array( + 'connect_timeout', 'timeout', 'use_brackets', 'protocol_version', + 'buffer_size', 'store_body', 'follow_redirects', 'max_redirects', + 'strict_redirects', 'ssl_verify_peer', 'ssl_verify_host', + 'ssl_cafile', 'ssl_capath', 'ssl_local_cert', 'ssl_passphrase' + ))); + + // force CURL adapter, this allows to handle correctly + // compressed responses with simple SplObserver registered + $config'adapter' = 'HTTP_Request2_Adapter_Curl'; + + try { + $request = new HTTP_Request2(); + $request->setConfig($config); + } + catch (Exception $e) { + rcube::raise_error($e, true, false); return false; }
View file
chwala-0.5.14.tar.gz/lib/drivers/webdav/webdav_file_storage.php
Changed
@@ -269,7 +269,7 @@ ); // these are returned when authentication on folders list fails - if ($this->config'username') { + if (!empty($this->config'username')) { $metadata'form_values' = array( 'baseuri' => $this->config'baseuri', 'username' => $this->config'username',
View file
chwala-0.5.14.tar.gz/lib/file_api.php
Changed
@@ -215,6 +215,7 @@ */ protected function authenticate() { + $username = null; if (isset($_POST'username')) { $username = $_POST'username'; $password = $_POST'password'; @@ -226,9 +227,9 @@ // when used with (f)cgi no PHP_AUTH* variables are available without defining a special rewrite rule else if (!isset($_SERVER'PHP_AUTH_USER')) { $tokens = array( - $_SERVER'REMOTE_USER', - $_SERVER'REDIRECT_REMOTE_USER', - $_SERVER'HTTP_AUTHORIZATION', + $_SERVER'REMOTE_USER' ?? null, + $_SERVER'REDIRECT_REMOTE_USER' ?? null, + $_SERVER'HTTP_AUTHORIZATION' ?? null, rcube_utils::request_header('Authorization'), ); @@ -369,7 +370,7 @@ */ public function file_url($file) { - return $this->api_url() . '?method=file_get' + return $this->api_url() . '/?method=file_get' . '&file=' . urlencode($file) . '&token=' . urlencode(session_id()); }
View file
chwala-0.5.14.tar.gz/lib/wopi/files.php
Changed
@@ -95,8 +95,7 @@ $info = parent::document_info($id); // Convert file metadata to Wopi format - // TODO: support more properties from - // https://wopirest.readthedocs.io/en/latest/files/CheckFileInfo.html + // TODO: support more properties from the WOPI and Collabora spec. $result = array( 'BaseFileName' => $info'name', @@ -113,6 +112,7 @@ 'HideSaveOption' => true, 'HideExportOption' => true, 'HidePrintOption' => true, + // 'HideRepairOption' => true, 'EnableOwnerTermination' => true, 'WatermarkText' => '', // ?? 'DisablePrint' => false, @@ -121,9 +121,18 @@ 'DisableInactiveMessages' => true, 'DisableChangeTrackingRecord' => true, 'DisableChangeTrackingShow' => true, + // 'DownloadAsPostMessage' + // 'EnableInsertRemoteImage' + // 'EnableRemoteLinkPicker' + // 'EnableShare' 'HideChangeTrackingControls' => true, + // 'HideUserList' => true, + 'SupportsRename' => false, + 'UserCanRename' => false, + // 'UserCanNotWriteRelative' // TODO: 'UserExtraInfo' => 'avatar' => 'http://url/to/user/avatar', 'mail' => $info'user' 'UserExtraInfo' => array(), + // 'UserPrivateInfo' ); if ($info'modified') {
View file
chwala.dsc
Changed
@@ -2,7 +2,7 @@ Source: chwala Binary: chwala Architecture: all -Version: 0.5.14.3-1~kolab1 +Version: 0.5.14.5-1~kolab1 Maintainer: Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> Uploaders: Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> Homepage: http://kolab.org/about/chwala/
View file
debian.changelog
Changed
@@ -1,4 +1,4 @@ -chwala (0.5.14.3-1~kolab1) unsable; urgency=low +chwala (0.5.14.5-1~kolab1) unsable; urgency=low * Release version 0.5.14
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.