1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2018, Roeland Jago Douma <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Roeland Jago Douma <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
namespace OCA\Richdocuments\Controller; |
24
|
|
|
|
25
|
|
|
use OCA\Richdocuments\AppConfig; |
26
|
|
|
use OCA\Richdocuments\Db\DirectMapper; |
27
|
|
|
use OCA\Richdocuments\TokenManager; |
28
|
|
|
use OCP\AppFramework\Controller; |
29
|
|
|
use OCP\AppFramework\Db\DoesNotExistException; |
30
|
|
|
use OCP\AppFramework\Http; |
31
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy; |
32
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
33
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
34
|
|
|
use OCP\Files\IRootFolder; |
35
|
|
|
use OCP\Files\Node; |
36
|
|
|
use OCP\IConfig; |
37
|
|
|
use OCP\IRequest; |
38
|
|
|
|
39
|
|
|
class DirectViewController extends Controller { |
40
|
|
|
/** @var IRootFolder */ |
41
|
|
|
private $rootFolder; |
42
|
|
|
|
43
|
|
|
/** @var TokenManager */ |
44
|
|
|
private $tokenManager; |
45
|
|
|
|
46
|
|
|
/** @var DirectMapper */ |
47
|
|
|
private $directMapper; |
48
|
|
|
|
49
|
|
|
/** @var IConfig */ |
50
|
|
|
private $config; |
51
|
|
|
|
52
|
|
|
/** @var AppConfig */ |
53
|
|
|
private $appConfig; |
54
|
|
|
|
55
|
|
|
public function __construct($appName, |
56
|
|
|
IRequest $request, |
57
|
|
|
IRootFolder $rootFolder, |
58
|
|
|
TokenManager $tokenManager, |
59
|
|
|
DirectMapper $directMapper, |
60
|
|
|
IConfig $config, |
61
|
|
|
AppConfig $appConfig) { |
62
|
|
|
parent::__construct($appName, $request); |
63
|
|
|
|
64
|
|
|
$this->rootFolder = $rootFolder; |
65
|
|
|
$this->tokenManager = $tokenManager; |
66
|
|
|
$this->directMapper = $directMapper; |
67
|
|
|
$this->config = $config; |
68
|
|
|
$this->appConfig = $appConfig; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @NoAdminRequired |
73
|
|
|
* @NoCSRFRequired |
74
|
|
|
* @PublicPage |
75
|
|
|
* |
76
|
|
|
* @param string $token |
77
|
|
|
*/ |
78
|
|
|
public function show($token) { |
79
|
|
|
try { |
80
|
|
|
$direct = $this->directMapper->getByToken($token); |
81
|
|
|
} catch (DoesNotExistException $e) { |
|
|
|
|
82
|
|
|
//TODO show 404 |
83
|
|
|
return new JSONResponse([], Http::STATUS_NOT_FOUND); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// Delete the token. They are for 1 time use only |
87
|
|
|
$this->directMapper->delete($direct); |
88
|
|
|
|
89
|
|
|
try { |
90
|
|
|
$folder = $this->rootFolder->getUserFolder($direct->getUid()); |
91
|
|
|
$item = $folder->getById($direct->getFileid())[0]; |
92
|
|
|
if(!($item instanceof Node)) { |
|
|
|
|
93
|
|
|
throw new \Exception(); |
94
|
|
|
} |
95
|
|
|
list($urlSrc, $token) = $this->tokenManager->getToken($item->getId()); |
96
|
|
|
$params = [ |
97
|
|
|
'permissions' => $item->getPermissions(), |
98
|
|
|
'title' => $item->getName(), |
99
|
|
|
'fileId' => $item->getId() . '_' . $this->config->getSystemValue('instanceid'), |
100
|
|
|
'token' => $token, |
101
|
|
|
'urlsrc' => $urlSrc, |
102
|
|
|
'path' => $folder->getRelativePath($item->getPath()), |
103
|
|
|
'instanceId' => $this->config->getSystemValue('instanceid'), |
104
|
|
|
'canonical_webroot' => $this->appConfig->getAppValue('canonical_webroot'), |
105
|
|
|
'direct' => true, |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
$response = new TemplateResponse('richdocuments', 'documents', $params, 'empty'); |
109
|
|
|
$policy = new ContentSecurityPolicy(); |
110
|
|
|
$policy->allowInlineScript(true); |
111
|
|
|
$policy->addAllowedFrameDomain($this->appConfig->getAppValue('wopi_url')); |
112
|
|
|
$response->setContentSecurityPolicy($policy); |
113
|
|
|
return $response; |
114
|
|
|
} catch (\Exception $e) { |
115
|
|
|
return new JSONResponse([], Http::STATUS_BAD_REQUEST); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.