Page MenuHomePhorge

D5859.1775183164.diff
No OneTemporary

Authored By
Unknown
Size
11 KB
Referenced Files
None
Subscribers
None

D5859.1775183164.diff

diff --git a/composer.json-dist b/composer.json-dist
--- a/composer.json-dist
+++ b/composer.json-dist
@@ -10,9 +10,10 @@
],
"require": {
"php": ">=5.4.0",
+ "guzzlehttp/guzzle": "^7.10.0",
"pear/pear-core-minimal": "~1.10.1",
"pear/net_url2": "~2.2.1",
- "pear/http_request2": "~2.3.0",
+ "pear/http_request2": "~2.7.0",
"pear/net_socket": "~1.2.1",
"pear/auth_sasl": "~1.1.0",
"pear/net_idna2": "~0.2.0",
@@ -20,6 +21,7 @@
"pear/net_smtp": "~1.7.3",
"pear/net_ldap2": "~2.2.0",
"kolab/net_ldap3": "dev-master",
- "sabre/dav" : "~2.1.11"
+ "sabre/dav" : "~2.1.11",
+ "smarty/smarty": "~5.8.0"
}
}
diff --git a/lib/api/document.php b/lib/api/document.php
--- a/lib/api/document.php
+++ b/lib/api/document.php
@@ -324,8 +324,8 @@
// 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);
+ $document = file_document::get_handler($this->api, $this->args['id'] ?? null);
+ $document->session_update($this->args['id'] ?? null, $file_data);
}
/**
diff --git a/lib/drivers/kolab/kolab_file_storage.php b/lib/drivers/kolab/kolab_file_storage.php
--- a/lib/drivers/kolab/kolab_file_storage.php
+++ b/lib/drivers/kolab/kolab_file_storage.php
@@ -541,7 +541,7 @@
0 => array(
'name' => $file_name,
'path' => $file['path'],
- 'content' => $file['content'],
+ 'content' => $file['content'] ?? null,
'mimetype' => $file['type'],
),
$key => false,
@@ -975,8 +975,8 @@
*/
public function folder_list($params = array())
{
- $unsubscribed = $params['type'] & file_storage::FILTER_UNSUBSCRIBED;
- $rights = ($params['type'] & file_storage::FILTER_WRITABLE) ? 'w' : null;
+ $unsubscribed = isset($params['type']) && $params['type'] & file_storage::FILTER_UNSUBSCRIBED;
+ $rights = isset($params['type']) && ($params['type'] & file_storage::FILTER_WRITABLE) ? 'w' : null;
$imap = $this->rc->get_storage();
$separator = $imap->get_hierarchy_delimiter();
$root = isset($params['path']) && strlen($params['path']) ? $this->folder_in($params['path']) . '/' : '';
diff --git a/lib/drivers/kolabfiles/kolabfiles_file_storage.php b/lib/drivers/kolabfiles/kolabfiles_file_storage.php
--- a/lib/drivers/kolabfiles/kolabfiles_file_storage.php
+++ b/lib/drivers/kolabfiles/kolabfiles_file_storage.php
@@ -150,7 +150,7 @@
'timeout' => 10,
]);
- $response = $client->request('POST', 'auth/login', ['json' => ['email' => $username, 'password' => $password]]);
+ $response = $client->post('auth/login', ['json' => ['email' => $username, 'password' => $password, 'mode' => 'fast']]);
if ($response->getStatusCode() != 200) {
throw new Exception("Failed to authenticate $username");
}
@@ -178,11 +178,30 @@
{
$_SESSION['username'] = $username;
$_SESSION['password'] = $this->rc->encrypt($password);
+ $_SESSION['access_token'] = null;
+ // Here password can be:
+ // - a normal password (when not using SSO)
+ // - a special one-time password (when using SSO)
+ // We can't use any of them as a Cockpit API token, we have to authenticate the user.
- $this->init();
+ $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->post('auth/login', ['json' => ['email' => $username, 'password' => $password, 'mode' => 'fast']]);
+
+ if ($response->getStatusCode() == 200) {
+ $json = json_decode($response->getBody(), true);
+ $accessToken = $json['access_token'];
+ $_SESSION['access_token'] = $this->rc->encrypt($accessToken);
+ }
- return true;
+ return !empty($_SESSION['access_token']);
}
/**
@@ -422,7 +441,7 @@
$deleted = $response->getStatusCode() == 200;
}
- if (!$deleted) {
+ if (empty($deleted)) {
rcube::raise_error(array(
'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
@@ -453,8 +472,7 @@
// write to file pointer, send no headers
if ($fp) {
$response = $this->client->request("GET", "v4/fs/{$file_id}", ['query' => ['download' => 1]]);
- fwrite(fp, $request->getBody());
-
+ fwrite($fp, $response->getBody());
return;
}
@@ -1036,7 +1054,6 @@
if ($this->collections) {
return $this->collections;
}
- $folders = array();
//FIXME If we could just fetch all collections, we could assemble the tree after a single fetch.
if ($parent) {
@@ -1053,19 +1070,23 @@
rcube::write_log('kolabfiles', "Failed to fetch collections from api, request status: " . $response->getStatusCode());
throw new Exception("GET request was unsuccessful");
}
+
$json = json_decode($response->getBody(), true);
- // rcube::write_log('kolabfiles', var_export($json, true));
- $collections = $json['list'];
+ $collections = $json['list'] ?? null;
if (!$collections) {
return [];
}
+ // For now skip shared collections
+ $collections = array_filter($collections, fn ($c) => empty($c['owner']));
+
$collections = array_map(function ($entry) use ($path) {
- //FIXME: retrieve the actual owner from the api. (Do we need the owner though?), not sure it matters
- $entry['owner'] = $_SESSION[$this->title . 'user'];
+ if (empty($entry['owner'])) {
+ $entry['owner'] = $_SESSION[$this->title . 'user'];
+ }
if ($path) {
- $entry['name'] = $path . "/" . $entry['name'];
+ $entry['name'] = $path . '/' . $entry['name'];
}
return $entry;
}, $collections);
@@ -1078,20 +1099,21 @@
if (!$parent) {
$this->collections = $collections;
}
+
return $collections;
}
-
protected function find_file_id($file_name, $repo_id)
{
- $response = $this->client()->request('GET', 'v4/fs', ['query' => ['parent' => $repo_id, 'type' => 'file']]);
+ $query = ['parent' => $repo_id, 'type' => 'file', 'search' => $file_name];
+ $response = $this->client()->request('GET', 'v4/fs', ['query' => $query]);
$json = json_decode($response->getBody(), true);
foreach ($json['list'] as $idx => $file) {
if ($file['name'] == $file_name) {
return $file['id'];
}
}
- rcube::write_log('console', "Failed to find the file $file_name in $repo_id");
+
throw new Exception("Failed to find the file $file_name in $repo_id");
}
@@ -1116,7 +1138,7 @@
if (!$no_exception) {
throw new Exception("Storage error. Collection not found.", file_storage::ERROR);
}
- return array(null, null);
+ return array(null, null, null);
}
else {
$folder = substr($folder_name, strlen($collection['name']) + 1);
diff --git a/lib/file_api.php b/lib/file_api.php
--- a/lib/file_api.php
+++ b/lib/file_api.php
@@ -57,7 +57,7 @@
*/
public function run()
{
- $this->request = strtolower($_GET['method']);
+ $this->request = strtolower($_GET['method'] ?? '');
// Check the session, authenticate the user
if (!$this->session_validate($this->request == 'authenticate', $_REQUEST['token'] ?? null)) {
@@ -218,11 +218,11 @@
$username = null;
if (isset($_POST['username'])) {
$username = $_POST['username'];
- $password = $_POST['password'];
+ $password = $_POST['password'] ?? null;
}
else if (!empty($_SERVER['PHP_AUTH_USER'])) {
$username = $_SERVER['PHP_AUTH_USER'];
- $password = $_SERVER['PHP_AUTH_PW'];
+ $password = $_SERVER['PHP_AUTH_PW'] ?? null;
}
// when used with (f)cgi no PHP_AUTH* variables are available without defining a special rewrite rule
else if (!isset($_SERVER['PHP_AUTH_USER'])) {
diff --git a/lib/file_api_core.php b/lib/file_api_core.php
--- a/lib/file_api_core.php
+++ b/lib/file_api_core.php
@@ -177,7 +177,7 @@
throw new Exception("Failed to find a driver for specified folder/file.", self::ERROR_NOT_FOUND);
}
- return array($this->get_backend(), $path);
+ return array($this->get_backend(), $path, null);
}
$path = substr($path, strlen($selected['title']) + 1);
@@ -275,6 +275,9 @@
$caps['NOROOT'] = true;
}
+ $driver = $rcube->config->get('fileapi_backend', 'kolab');
+ $caps['BACKEND'] = $driver;
+
if (!$full) {
return $caps;
}
diff --git a/lib/file_ui.php b/lib/file_ui.php
--- a/lib/file_ui.php
+++ b/lib/file_ui.php
@@ -537,7 +537,7 @@
));
$username = html::label(array('for' => 'login_name'), $this->translate('login.username'))
- . $user_input->show($post['username']);
+ . $user_input->show($post['username'] ?? '');
$password = html::label(array('for' => 'login_pass'), $this->translate('login.password'))
. $pass_input->show('');
diff --git a/lib/file_ui_output.php b/lib/file_ui_output.php
--- a/lib/file_ui_output.php
+++ b/lib/file_ui_output.php
@@ -51,27 +51,12 @@
*/
private function init()
{
- $conf = rcube::get_instance()->config;
+ $SMARTY = new \Smarty\Smarty();
- $smarty_path = array('Smarty', 'smarty3', 'smarty');
-
- if ($path = $conf->get('smarty_path')) {
- array_unshift($smarty_path, $path);
- }
-
- foreach ($smarty_path as $path) {
- @include_once "$path/Smarty.class.php";
- if (class_exists('Smarty', false)) {
- break;
- }
- }
-
- $SMARTY = new Smarty;
-
- $SMARTY->template_dir = 'skins/' . $this->skin . '/templates';
- $SMARTY->compile_dir = RCUBE_INSTALL_PATH . '/cache';
- $SMARTY->plugins_dir = RCUBE_INSTALL_PATH . '/lib/ext/Smarty/plugins/';
- $SMARTY->debugging = false;
+ $SMARTY->setTemplateDir('skins/' . $this->skin . '/templates');
+ $SMARTY->setCompileDir(RCUBE_INSTALL_PATH . '/cache');
+ //$SMARTY->addPluginsDir(RCUBE_INSTALL_PATH . '/lib/ext/Smarty/plugins/');
+ $SMARTY->debugging = false;
$this->tpl = $SMARTY;
}

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 2:26 AM (19 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18822136
Default Alt Text
D5859.1775183164.diff (11 KB)

Event Timeline