2016-09-24 00:17:47 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Nextcloud - passman
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Sander Brand <brantje@gmail.com>
|
|
|
|
* @copyright Sander Brand 2016
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Passman\Controller;
|
|
|
|
|
2021-03-15 01:24:02 +08:00
|
|
|
use OCA\Passman\Service\CredentialService;
|
|
|
|
use OCP\App\IAppManager;
|
|
|
|
use OCP\AppFramework\ApiController;
|
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2016-12-29 01:54:54 +08:00
|
|
|
use OCP\IConfig;
|
2016-09-24 00:17:47 +08:00
|
|
|
use OCP\IRequest;
|
2021-03-15 01:24:02 +08:00
|
|
|
use OCP\Notification\IManager;
|
2016-09-24 00:17:47 +08:00
|
|
|
|
|
|
|
class InternalController extends ApiController {
|
|
|
|
private $userId;
|
|
|
|
private $credentialService;
|
2016-12-29 01:54:54 +08:00
|
|
|
private $config;
|
2021-03-15 01:24:02 +08:00
|
|
|
private $manager;
|
|
|
|
private $appManager;
|
2016-09-25 02:47:47 +08:00
|
|
|
|
2016-09-24 00:17:47 +08:00
|
|
|
public function __construct($AppName,
|
2021-03-15 01:24:02 +08:00
|
|
|
IRequest $request,
|
|
|
|
$UserId,
|
|
|
|
CredentialService $credentialService,
|
|
|
|
IConfig $config,
|
|
|
|
IManager $IManager,
|
|
|
|
IAppManager $appManager
|
2016-12-29 01:54:54 +08:00
|
|
|
) {
|
2017-01-19 20:39:01 +08:00
|
|
|
parent::__construct(
|
|
|
|
$AppName,
|
|
|
|
$request,
|
|
|
|
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
|
|
|
'Authorization, Content-Type, Accept',
|
|
|
|
86400);
|
2016-09-24 00:17:47 +08:00
|
|
|
$this->userId = $UserId;
|
|
|
|
$this->credentialService = $credentialService;
|
2016-12-29 01:54:54 +08:00
|
|
|
$this->config = $config;
|
2021-03-15 01:24:02 +08:00
|
|
|
$this->manager = $IManager;
|
|
|
|
$this->appManager = $appManager;
|
2016-09-24 00:17:47 +08:00
|
|
|
}
|
|
|
|
|
2016-09-25 02:47:47 +08:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
|
|
|
public function remind($credential_id) {
|
2016-09-24 00:17:47 +08:00
|
|
|
$credential = $this->credentialService->getCredentialById($credential_id, $this->userId);
|
2021-03-15 01:24:02 +08:00
|
|
|
if ($credential) {
|
2017-01-04 18:55:48 +08:00
|
|
|
$credential->setExpireTime(time() + (24 * 60 * 60));
|
|
|
|
$this->credentialService->upd($credential);
|
2016-09-24 00:17:47 +08:00
|
|
|
|
2021-03-15 01:24:02 +08:00
|
|
|
$notification = $this->manager->createNotification();
|
2017-01-04 18:55:48 +08:00
|
|
|
$notification->setApp('passman')
|
|
|
|
->setObject('credential', $credential_id)
|
|
|
|
->setUser($this->userId);
|
2021-03-15 01:24:02 +08:00
|
|
|
$this->manager->markProcessed($notification);
|
2017-01-04 18:55:48 +08:00
|
|
|
}
|
2016-09-24 00:17:47 +08:00
|
|
|
}
|
|
|
|
|
2016-09-25 02:47:47 +08:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
|
|
|
public function read($credential_id) {
|
2016-09-24 00:17:47 +08:00
|
|
|
$credential = $this->credentialService->getCredentialById($credential_id, $this->userId);
|
2021-03-15 01:24:02 +08:00
|
|
|
if ($credential) {
|
2017-01-04 18:55:48 +08:00
|
|
|
$credential->setExpireTime(0);
|
|
|
|
$this->credentialService->upd($credential);
|
2016-09-24 00:17:47 +08:00
|
|
|
|
2021-03-15 01:24:02 +08:00
|
|
|
$notification = $this->manager->createNotification();
|
2017-01-04 18:55:48 +08:00
|
|
|
$notification->setApp('passman')
|
|
|
|
->setObject('credential', $credential_id)
|
|
|
|
->setUser($this->userId);
|
2021-03-15 01:24:02 +08:00
|
|
|
$this->manager->markProcessed($notification);
|
2017-01-04 18:55:48 +08:00
|
|
|
}
|
2016-09-24 00:17:47 +08:00
|
|
|
}
|
2016-09-25 02:47:47 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2016-12-27 19:39:13 +08:00
|
|
|
* @NoCSRFRequired
|
2016-09-25 02:47:47 +08:00
|
|
|
*/
|
|
|
|
public function getAppVersion() {
|
2021-03-15 01:24:02 +08:00
|
|
|
return new JSONResponse(array('version' => $this->appManager->getAppInfo('passman')["version"]));
|
2016-09-25 02:47:47 +08:00
|
|
|
}
|
|
|
|
|
2016-09-26 06:27:02 +08:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
|
|
|
public function generatePerson() {
|
2021-03-15 01:24:02 +08:00
|
|
|
$context = ['http' => ['method' => 'GET'], 'ssl' => ['verify_peer' => false, 'allow_self_signed' => true]];
|
2017-04-17 19:07:45 +08:00
|
|
|
$context = stream_context_create($context);
|
|
|
|
$random_person = json_decode(file_get_contents('http://api.namefake.com/', false, $context));
|
2016-09-26 06:27:02 +08:00
|
|
|
return new JSONResponse($random_person);
|
|
|
|
}
|
|
|
|
|
2016-12-29 01:54:54 +08:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function getSettings() {
|
|
|
|
$settings = array(
|
2016-12-29 07:04:37 +08:00
|
|
|
'link_sharing_enabled' => intval($this->config->getAppValue('passman', 'link_sharing_enabled', 1)),
|
|
|
|
'user_sharing_enabled' => intval($this->config->getAppValue('passman', 'user_sharing_enabled', 1)),
|
|
|
|
'vault_key_strength' => intval($this->config->getAppValue('passman', 'vault_key_strength', 3)),
|
|
|
|
'check_version' => intval($this->config->getAppValue('passman', 'check_version', 1)),
|
|
|
|
'https_check' => intval($this->config->getAppValue('passman', 'https_check', 1)),
|
|
|
|
'disable_contextmenu' => intval($this->config->getAppValue('passman', 'disable_contextmenu', 1)),
|
2016-12-29 01:54:54 +08:00
|
|
|
);
|
|
|
|
return new JSONResponse($settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function saveSettings($key, $value) {
|
|
|
|
if (is_numeric($value)) {
|
|
|
|
$value = intval($value);
|
|
|
|
}
|
|
|
|
$this->config->setAppValue('passman', $key, $value);
|
|
|
|
}
|
|
|
|
|
2021-03-15 01:24:02 +08:00
|
|
|
}
|