2015-04-16 07:47:27 -04:00
|
|
|
<?php
|
2024-05-28 10:42:42 -04:00
|
|
|
|
2015-04-16 07:47:27 -04:00
|
|
|
/**
|
2024-05-28 10:42:42 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-04-16 07:47:27 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Encryption\Controller;
|
|
|
|
|
|
|
|
|
|
use OCA\Encryption\Session;
|
|
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2017-05-30 07:22:27 -04:00
|
|
|
use OCP\Encryption\IManager;
|
2015-04-16 07:47:27 -04:00
|
|
|
use OCP\IL10N;
|
|
|
|
|
use OCP\IRequest;
|
|
|
|
|
|
|
|
|
|
class StatusController extends Controller {
|
|
|
|
|
|
|
|
|
|
/** @var IL10N */
|
|
|
|
|
private $l;
|
|
|
|
|
|
|
|
|
|
/** @var Session */
|
|
|
|
|
private $session;
|
|
|
|
|
|
2017-05-30 07:22:27 -04:00
|
|
|
/** @var IManager */
|
|
|
|
|
private $encryptionManager;
|
|
|
|
|
|
2015-04-16 07:47:27 -04:00
|
|
|
/**
|
|
|
|
|
* @param string $AppName
|
|
|
|
|
* @param IRequest $request
|
|
|
|
|
* @param IL10N $l10n
|
|
|
|
|
* @param Session $session
|
2017-05-30 07:22:27 -04:00
|
|
|
* @param IManager $encryptionManager
|
2015-04-16 07:47:27 -04:00
|
|
|
*/
|
|
|
|
|
public function __construct($AppName,
|
2023-11-23 04:22:34 -05:00
|
|
|
IRequest $request,
|
|
|
|
|
IL10N $l10n,
|
|
|
|
|
Session $session,
|
|
|
|
|
IManager $encryptionManager
|
|
|
|
|
) {
|
2015-04-16 07:47:27 -04:00
|
|
|
parent::__construct($AppName, $request);
|
|
|
|
|
$this->l = $l10n;
|
|
|
|
|
$this->session = $session;
|
2017-05-30 07:22:27 -04:00
|
|
|
$this->encryptionManager = $encryptionManager;
|
2015-04-16 07:47:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @NoAdminRequired
|
|
|
|
|
* @return DataResponse
|
|
|
|
|
*/
|
|
|
|
|
public function getStatus() {
|
2015-04-17 08:25:57 -04:00
|
|
|
$status = 'error';
|
2015-05-27 05:10:06 -04:00
|
|
|
$message = 'no valid init status';
|
2020-04-10 08:19:56 -04:00
|
|
|
switch ($this->session->getStatus()) {
|
2015-04-16 07:47:27 -04:00
|
|
|
case Session::INIT_EXECUTED:
|
2015-05-27 05:10:06 -04:00
|
|
|
$status = 'interactionNeeded';
|
2021-01-11 06:57:03 -05:00
|
|
|
$message = $this->l->t(
|
2016-08-05 09:50:17 -04:00
|
|
|
'Invalid private key for encryption app. Please update your private key password in your personal settings to recover access to your encrypted files.'
|
2015-04-17 08:26:58 -04:00
|
|
|
);
|
2015-04-16 07:47:27 -04:00
|
|
|
break;
|
|
|
|
|
case Session::NOT_INITIALIZED:
|
2015-05-27 05:10:06 -04:00
|
|
|
$status = 'interactionNeeded';
|
2017-05-30 07:22:27 -04:00
|
|
|
if ($this->encryptionManager->isEnabled()) {
|
2021-01-11 06:57:03 -05:00
|
|
|
$message = $this->l->t(
|
2017-05-30 07:22:27 -04:00
|
|
|
'Encryption App is enabled, but your keys are not initialized. Please log-out and log-in again.'
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2021-01-11 06:57:03 -05:00
|
|
|
$message = $this->l->t(
|
2017-05-30 07:22:27 -04:00
|
|
|
'Please enable server side encryption in the admin settings in order to use the encryption module.'
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-04-16 07:47:27 -04:00
|
|
|
break;
|
2015-05-27 05:10:06 -04:00
|
|
|
case Session::INIT_SUCCESSFUL:
|
|
|
|
|
$status = 'success';
|
2021-01-11 06:57:03 -05:00
|
|
|
$message = $this->l->t('Encryption app is enabled and ready');
|
2015-04-16 07:47:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new DataResponse(
|
2015-04-17 08:25:57 -04:00
|
|
|
[
|
2015-04-16 07:47:27 -04:00
|
|
|
'status' => $status,
|
2015-04-17 08:25:57 -04:00
|
|
|
'data' => [
|
|
|
|
|
'message' => $message]
|
|
|
|
|
]
|
2015-04-16 07:47:27 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|