2012-09-07 08:09:41 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2012-09-07 08:09:41 -04:00
|
|
|
/**
|
2024-06-06 03:55:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-02-26 05:37:37 -05:00
|
|
|
*/
|
2026-05-12 04:54:27 -04:00
|
|
|
|
2020-07-09 17:39:58 -04:00
|
|
|
namespace OCA\Files_External;
|
|
|
|
|
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\Files_External\Lib\Backend\Backend;
|
|
|
|
|
use OCA\Files_External\Service\BackendService;
|
2026-05-12 04:54:27 -04:00
|
|
|
use OCA\Files_External\Service\EncryptionService;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\Server;
|
2026-01-16 05:52:35 -05:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
2015-08-03 00:39:53 -04:00
|
|
|
|
2015-02-26 05:37:37 -05:00
|
|
|
/**
|
|
|
|
|
* Class to configure mount.json globally and for users
|
2014-03-18 16:15:11 -04:00
|
|
|
*/
|
2020-07-09 17:39:58 -04:00
|
|
|
class MountConfig {
|
2020-04-10 10:54:27 -04:00
|
|
|
public const MOUNT_TYPE_GLOBAL = 'global';
|
|
|
|
|
public const MOUNT_TYPE_GROUP = 'group';
|
|
|
|
|
public const MOUNT_TYPE_USER = 'user';
|
|
|
|
|
public const MOUNT_TYPE_PERSONAL = 'personal';
|
2012-09-07 08:09:41 -04:00
|
|
|
|
2019-02-11 17:18:08 -05:00
|
|
|
/**
|
|
|
|
|
* @param mixed $input
|
2019-07-25 11:57:22 -04:00
|
|
|
* @param string|null $userId
|
2019-02-11 17:18:08 -05:00
|
|
|
* @return mixed
|
2026-01-16 05:52:35 -05:00
|
|
|
* @throws ContainerExceptionInterface
|
2019-02-11 17:18:08 -05:00
|
|
|
* @since 16.0.0
|
2026-05-12 04:54:27 -04:00
|
|
|
* @deprecated 34.0.0 use BackendService instead
|
2019-02-11 17:18:08 -05:00
|
|
|
*/
|
2024-03-28 11:13:19 -04:00
|
|
|
public static function substitutePlaceholdersInConfig($input, ?string $userId = null) {
|
2026-05-12 04:54:27 -04:00
|
|
|
return Server::get(BackendService::class)->applyConfigHandlers($input, $userId);
|
2014-03-19 07:20:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test connecting using the given backend configuration
|
2014-12-11 11:35:11 -05:00
|
|
|
*
|
2014-03-19 07:20:48 -04:00
|
|
|
* @param string $class backend class name
|
|
|
|
|
* @param array $options backend configuration options
|
2015-11-30 05:29:06 -05:00
|
|
|
* @param boolean $isPersonal
|
2014-10-31 06:41:07 -04:00
|
|
|
* @return int see self::STATUS_*
|
2021-03-16 17:06:00 -04:00
|
|
|
* @throws \Exception
|
2026-05-12 04:54:27 -04:00
|
|
|
* @deprecated 34.0.0 use BackendService instead
|
2014-03-19 07:20:48 -04:00
|
|
|
*/
|
2025-07-15 06:56:51 -04:00
|
|
|
public static function getBackendStatus($class, $options) {
|
2026-05-12 04:54:27 -04:00
|
|
|
return Server::get(BackendService::class)->getBackendStatus($class, $options);
|
2012-12-24 13:45:52 -05:00
|
|
|
}
|
|
|
|
|
|
2014-03-18 16:15:11 -04:00
|
|
|
/**
|
|
|
|
|
* Encrypt passwords in the given config options
|
2014-12-11 11:35:11 -05:00
|
|
|
*
|
2014-03-18 16:15:11 -04:00
|
|
|
* @param array $options mount options
|
|
|
|
|
* @return array updated options
|
2026-05-12 04:54:27 -04:00
|
|
|
* @deprecated 34.0.0 use EncryptionService instead
|
2014-03-18 16:15:11 -04:00
|
|
|
*/
|
2014-10-31 06:41:07 -04:00
|
|
|
public static function encryptPasswords($options) {
|
2026-05-12 04:54:27 -04:00
|
|
|
return Server::get(EncryptionService::class)->encryptPasswords($options);
|
2014-03-18 16:15:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decrypt passwords in the given config options
|
2014-12-11 11:35:11 -05:00
|
|
|
*
|
2014-03-18 16:15:11 -04:00
|
|
|
* @param array $options mount options
|
|
|
|
|
* @return array updated options
|
2026-05-12 04:54:27 -04:00
|
|
|
* @deprecated 34.0.0 use EncryptionService instead
|
2014-03-18 16:15:11 -04:00
|
|
|
*/
|
2014-10-31 06:41:07 -04:00
|
|
|
public static function decryptPasswords($options) {
|
2026-05-12 04:54:27 -04:00
|
|
|
return Server::get(EncryptionService::class)->decryptPasswords($options);
|
2014-03-18 16:15:11 -04:00
|
|
|
}
|
2014-03-26 07:10:17 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Computes a hash based on the given configuration.
|
|
|
|
|
* This is mostly used to find out whether configurations
|
|
|
|
|
* are the same.
|
2026-05-12 04:54:27 -04:00
|
|
|
* @throws \JsonException
|
2014-03-26 07:10:17 -04:00
|
|
|
*/
|
2026-05-12 04:54:27 -04:00
|
|
|
public static function makeConfigHash(array $config): string {
|
2014-03-26 07:10:17 -04:00
|
|
|
$data = json_encode(
|
2020-03-26 04:30:18 -04:00
|
|
|
[
|
2015-08-12 15:03:11 -04:00
|
|
|
'c' => $config['backend'],
|
|
|
|
|
'a' => $config['authMechanism'],
|
2014-03-26 07:10:17 -04:00
|
|
|
'm' => $config['mountpoint'],
|
2015-03-16 07:18:01 -04:00
|
|
|
'o' => $config['options'],
|
2023-07-07 06:20:21 -04:00
|
|
|
'p' => $config['priority'] ?? -1,
|
|
|
|
|
'mo' => $config['mountOptions'] ?? [],
|
2026-05-12 04:54:27 -04:00
|
|
|
],
|
|
|
|
|
JSON_THROW_ON_ERROR
|
2014-03-26 07:10:17 -04:00
|
|
|
);
|
|
|
|
|
return hash('md5', $data);
|
|
|
|
|
}
|
2012-09-07 08:09:41 -04:00
|
|
|
}
|