@@ -49,238 +49,238 @@ |
||
49 | 49 | * @package OCA\Files\Controller |
50 | 50 | */ |
51 | 51 | class ViewController extends Controller { |
52 | - /** @var string */ |
|
53 | - protected $appName; |
|
54 | - /** @var IRequest */ |
|
55 | - protected $request; |
|
56 | - /** @var IURLGenerator */ |
|
57 | - protected $urlGenerator; |
|
58 | - /** @var IL10N */ |
|
59 | - protected $l10n; |
|
60 | - /** @var IConfig */ |
|
61 | - protected $config; |
|
62 | - /** @var EventDispatcherInterface */ |
|
63 | - protected $eventDispatcher; |
|
64 | - /** @var IUserSession */ |
|
65 | - protected $userSession; |
|
66 | - /** @var IAppManager */ |
|
67 | - protected $appManager; |
|
68 | - /** @var IRootFolder */ |
|
69 | - protected $rootFolder; |
|
52 | + /** @var string */ |
|
53 | + protected $appName; |
|
54 | + /** @var IRequest */ |
|
55 | + protected $request; |
|
56 | + /** @var IURLGenerator */ |
|
57 | + protected $urlGenerator; |
|
58 | + /** @var IL10N */ |
|
59 | + protected $l10n; |
|
60 | + /** @var IConfig */ |
|
61 | + protected $config; |
|
62 | + /** @var EventDispatcherInterface */ |
|
63 | + protected $eventDispatcher; |
|
64 | + /** @var IUserSession */ |
|
65 | + protected $userSession; |
|
66 | + /** @var IAppManager */ |
|
67 | + protected $appManager; |
|
68 | + /** @var IRootFolder */ |
|
69 | + protected $rootFolder; |
|
70 | 70 | |
71 | - /** |
|
72 | - * @param string $appName |
|
73 | - * @param IRequest $request |
|
74 | - * @param IURLGenerator $urlGenerator |
|
75 | - * @param IL10N $l10n |
|
76 | - * @param IConfig $config |
|
77 | - * @param EventDispatcherInterface $eventDispatcherInterface |
|
78 | - * @param IUserSession $userSession |
|
79 | - * @param IAppManager $appManager |
|
80 | - * @param IRootFolder $rootFolder |
|
81 | - */ |
|
82 | - public function __construct($appName, |
|
83 | - IRequest $request, |
|
84 | - IURLGenerator $urlGenerator, |
|
85 | - IL10N $l10n, |
|
86 | - IConfig $config, |
|
87 | - EventDispatcherInterface $eventDispatcherInterface, |
|
88 | - IUserSession $userSession, |
|
89 | - IAppManager $appManager, |
|
90 | - IRootFolder $rootFolder |
|
91 | - ) { |
|
92 | - parent::__construct($appName, $request); |
|
93 | - $this->appName = $appName; |
|
94 | - $this->request = $request; |
|
95 | - $this->urlGenerator = $urlGenerator; |
|
96 | - $this->l10n = $l10n; |
|
97 | - $this->config = $config; |
|
98 | - $this->eventDispatcher = $eventDispatcherInterface; |
|
99 | - $this->userSession = $userSession; |
|
100 | - $this->appManager = $appManager; |
|
101 | - $this->rootFolder = $rootFolder; |
|
102 | - } |
|
71 | + /** |
|
72 | + * @param string $appName |
|
73 | + * @param IRequest $request |
|
74 | + * @param IURLGenerator $urlGenerator |
|
75 | + * @param IL10N $l10n |
|
76 | + * @param IConfig $config |
|
77 | + * @param EventDispatcherInterface $eventDispatcherInterface |
|
78 | + * @param IUserSession $userSession |
|
79 | + * @param IAppManager $appManager |
|
80 | + * @param IRootFolder $rootFolder |
|
81 | + */ |
|
82 | + public function __construct($appName, |
|
83 | + IRequest $request, |
|
84 | + IURLGenerator $urlGenerator, |
|
85 | + IL10N $l10n, |
|
86 | + IConfig $config, |
|
87 | + EventDispatcherInterface $eventDispatcherInterface, |
|
88 | + IUserSession $userSession, |
|
89 | + IAppManager $appManager, |
|
90 | + IRootFolder $rootFolder |
|
91 | + ) { |
|
92 | + parent::__construct($appName, $request); |
|
93 | + $this->appName = $appName; |
|
94 | + $this->request = $request; |
|
95 | + $this->urlGenerator = $urlGenerator; |
|
96 | + $this->l10n = $l10n; |
|
97 | + $this->config = $config; |
|
98 | + $this->eventDispatcher = $eventDispatcherInterface; |
|
99 | + $this->userSession = $userSession; |
|
100 | + $this->appManager = $appManager; |
|
101 | + $this->rootFolder = $rootFolder; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param string $appName |
|
106 | - * @param string $scriptName |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - protected function renderScript($appName, $scriptName) { |
|
110 | - $content = ''; |
|
111 | - $appPath = \OC_App::getAppPath($appName); |
|
112 | - $scriptPath = $appPath . '/' . $scriptName; |
|
113 | - if (file_exists($scriptPath)) { |
|
114 | - // TODO: sanitize path / script name ? |
|
115 | - ob_start(); |
|
116 | - include $scriptPath; |
|
117 | - $content = ob_get_contents(); |
|
118 | - @ob_end_clean(); |
|
119 | - } |
|
120 | - return $content; |
|
121 | - } |
|
104 | + /** |
|
105 | + * @param string $appName |
|
106 | + * @param string $scriptName |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + protected function renderScript($appName, $scriptName) { |
|
110 | + $content = ''; |
|
111 | + $appPath = \OC_App::getAppPath($appName); |
|
112 | + $scriptPath = $appPath . '/' . $scriptName; |
|
113 | + if (file_exists($scriptPath)) { |
|
114 | + // TODO: sanitize path / script name ? |
|
115 | + ob_start(); |
|
116 | + include $scriptPath; |
|
117 | + $content = ob_get_contents(); |
|
118 | + @ob_end_clean(); |
|
119 | + } |
|
120 | + return $content; |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * FIXME: Replace with non static code |
|
125 | - * |
|
126 | - * @return array |
|
127 | - * @throws \OCP\Files\NotFoundException |
|
128 | - */ |
|
129 | - protected function getStorageInfo() { |
|
130 | - $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
131 | - return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
132 | - } |
|
123 | + /** |
|
124 | + * FIXME: Replace with non static code |
|
125 | + * |
|
126 | + * @return array |
|
127 | + * @throws \OCP\Files\NotFoundException |
|
128 | + */ |
|
129 | + protected function getStorageInfo() { |
|
130 | + $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
131 | + return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @NoCSRFRequired |
|
136 | - * @NoAdminRequired |
|
137 | - * |
|
138 | - * @param string $dir |
|
139 | - * @param string $view |
|
140 | - * @param string $fileid |
|
141 | - * @return TemplateResponse|RedirectResponse |
|
142 | - */ |
|
143 | - public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
144 | - if ($fileid !== null) { |
|
145 | - try { |
|
146 | - return $this->showFile($fileid); |
|
147 | - } catch (NotFoundException $e) { |
|
148 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
149 | - } |
|
150 | - } |
|
134 | + /** |
|
135 | + * @NoCSRFRequired |
|
136 | + * @NoAdminRequired |
|
137 | + * |
|
138 | + * @param string $dir |
|
139 | + * @param string $view |
|
140 | + * @param string $fileid |
|
141 | + * @return TemplateResponse|RedirectResponse |
|
142 | + */ |
|
143 | + public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
144 | + if ($fileid !== null) { |
|
145 | + try { |
|
146 | + return $this->showFile($fileid); |
|
147 | + } catch (NotFoundException $e) { |
|
148 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
149 | + } |
|
150 | + } |
|
151 | 151 | |
152 | - $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
152 | + $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
153 | 153 | |
154 | - // Load the files we need |
|
155 | - \OCP\Util::addScript('files', 'app'); |
|
156 | - \OCP\Util::addScript('files', 'file-upload'); |
|
157 | - \OCP\Util::addScript('files', 'newfilemenu'); |
|
158 | - \OCP\Util::addScript('files', 'jquery.fileupload'); |
|
159 | - \OCP\Util::addScript('files', 'jquery-visibility'); |
|
160 | - \OCP\Util::addScript('files', 'fileinfomodel'); |
|
161 | - \OCP\Util::addScript('files', 'filesummary'); |
|
162 | - \OCP\Util::addScript('files', 'breadcrumb'); |
|
163 | - \OCP\Util::addScript('files', 'filelist'); |
|
164 | - \OCP\Util::addScript('files', 'search'); |
|
154 | + // Load the files we need |
|
155 | + \OCP\Util::addScript('files', 'app'); |
|
156 | + \OCP\Util::addScript('files', 'file-upload'); |
|
157 | + \OCP\Util::addScript('files', 'newfilemenu'); |
|
158 | + \OCP\Util::addScript('files', 'jquery.fileupload'); |
|
159 | + \OCP\Util::addScript('files', 'jquery-visibility'); |
|
160 | + \OCP\Util::addScript('files', 'fileinfomodel'); |
|
161 | + \OCP\Util::addScript('files', 'filesummary'); |
|
162 | + \OCP\Util::addScript('files', 'breadcrumb'); |
|
163 | + \OCP\Util::addScript('files', 'filelist'); |
|
164 | + \OCP\Util::addScript('files', 'search'); |
|
165 | 165 | |
166 | - \OCP\Util::addScript('files', 'favoritesfilelist'); |
|
167 | - \OCP\Util::addScript('files', 'recentfilelist'); |
|
168 | - \OCP\Util::addScript('files', 'tagsplugin'); |
|
169 | - \OCP\Util::addScript('files', 'gotoplugin'); |
|
170 | - \OCP\Util::addScript('files', 'favoritesplugin'); |
|
171 | - \OCP\Util::addScript('files', 'recentplugin'); |
|
166 | + \OCP\Util::addScript('files', 'favoritesfilelist'); |
|
167 | + \OCP\Util::addScript('files', 'recentfilelist'); |
|
168 | + \OCP\Util::addScript('files', 'tagsplugin'); |
|
169 | + \OCP\Util::addScript('files', 'gotoplugin'); |
|
170 | + \OCP\Util::addScript('files', 'favoritesplugin'); |
|
171 | + \OCP\Util::addScript('files', 'recentplugin'); |
|
172 | 172 | |
173 | - \OCP\Util::addScript('files', 'detailfileinfoview'); |
|
174 | - \OCP\Util::addScript('files', 'sidebarpreviewmanager'); |
|
175 | - \OCP\Util::addScript('files', 'sidebarpreviewtext'); |
|
176 | - \OCP\Util::addScript('files', 'detailtabview'); |
|
177 | - \OCP\Util::addScript('files', 'mainfileinfodetailview'); |
|
178 | - \OCP\Util::addScript('files', 'detailsview'); |
|
179 | - \OCP\Util::addStyle('files', 'merged'); |
|
173 | + \OCP\Util::addScript('files', 'detailfileinfoview'); |
|
174 | + \OCP\Util::addScript('files', 'sidebarpreviewmanager'); |
|
175 | + \OCP\Util::addScript('files', 'sidebarpreviewtext'); |
|
176 | + \OCP\Util::addScript('files', 'detailtabview'); |
|
177 | + \OCP\Util::addScript('files', 'mainfileinfodetailview'); |
|
178 | + \OCP\Util::addScript('files', 'detailsview'); |
|
179 | + \OCP\Util::addStyle('files', 'merged'); |
|
180 | 180 | |
181 | - \OC_Util::addVendorScript('core', 'handlebars/handlebars'); |
|
181 | + \OC_Util::addVendorScript('core', 'handlebars/handlebars'); |
|
182 | 182 | |
183 | - \OCP\Util::addScript('files', 'fileactions'); |
|
184 | - \OCP\Util::addScript('files', 'fileactionsmenu'); |
|
185 | - \OCP\Util::addScript('files', 'files'); |
|
186 | - \OCP\Util::addScript('files', 'keyboardshortcuts'); |
|
187 | - \OCP\Util::addScript('files', 'navigation'); |
|
183 | + \OCP\Util::addScript('files', 'fileactions'); |
|
184 | + \OCP\Util::addScript('files', 'fileactionsmenu'); |
|
185 | + \OCP\Util::addScript('files', 'files'); |
|
186 | + \OCP\Util::addScript('files', 'keyboardshortcuts'); |
|
187 | + \OCP\Util::addScript('files', 'navigation'); |
|
188 | 188 | |
189 | - // mostly for the home storage's free space |
|
190 | - // FIXME: Make non static |
|
191 | - $storageInfo = $this->getStorageInfo(); |
|
189 | + // mostly for the home storage's free space |
|
190 | + // FIXME: Make non static |
|
191 | + $storageInfo = $this->getStorageInfo(); |
|
192 | 192 | |
193 | - \OCA\Files\App::getNavigationManager()->add( |
|
194 | - [ |
|
195 | - 'id' => 'favorites', |
|
196 | - 'appname' => 'files', |
|
197 | - 'script' => 'simplelist.php', |
|
198 | - 'order' => 5, |
|
199 | - 'name' => $this->l10n->t('Favorites') |
|
200 | - ] |
|
201 | - ); |
|
193 | + \OCA\Files\App::getNavigationManager()->add( |
|
194 | + [ |
|
195 | + 'id' => 'favorites', |
|
196 | + 'appname' => 'files', |
|
197 | + 'script' => 'simplelist.php', |
|
198 | + 'order' => 5, |
|
199 | + 'name' => $this->l10n->t('Favorites') |
|
200 | + ] |
|
201 | + ); |
|
202 | 202 | |
203 | - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
204 | - usort($navItems, function($item1, $item2) { |
|
205 | - return $item1['order'] - $item2['order']; |
|
206 | - }); |
|
207 | - $nav->assign('navigationItems', $navItems); |
|
203 | + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
204 | + usort($navItems, function($item1, $item2) { |
|
205 | + return $item1['order'] - $item2['order']; |
|
206 | + }); |
|
207 | + $nav->assign('navigationItems', $navItems); |
|
208 | 208 | |
209 | - $contentItems = []; |
|
209 | + $contentItems = []; |
|
210 | 210 | |
211 | - // render the container content for every navigation item |
|
212 | - foreach ($navItems as $item) { |
|
213 | - $content = ''; |
|
214 | - if (isset($item['script'])) { |
|
215 | - $content = $this->renderScript($item['appname'], $item['script']); |
|
216 | - } |
|
217 | - $contentItem = []; |
|
218 | - $contentItem['id'] = $item['id']; |
|
219 | - $contentItem['content'] = $content; |
|
220 | - $contentItems[] = $contentItem; |
|
221 | - } |
|
211 | + // render the container content for every navigation item |
|
212 | + foreach ($navItems as $item) { |
|
213 | + $content = ''; |
|
214 | + if (isset($item['script'])) { |
|
215 | + $content = $this->renderScript($item['appname'], $item['script']); |
|
216 | + } |
|
217 | + $contentItem = []; |
|
218 | + $contentItem['id'] = $item['id']; |
|
219 | + $contentItem['content'] = $content; |
|
220 | + $contentItems[] = $contentItem; |
|
221 | + } |
|
222 | 222 | |
223 | - $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts'); |
|
223 | + $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts'); |
|
224 | 224 | |
225 | - $params = []; |
|
226 | - $params['usedSpacePercent'] = (int)$storageInfo['relative']; |
|
227 | - $params['owner'] = $storageInfo['owner']; |
|
228 | - $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
|
229 | - $params['isPublic'] = false; |
|
230 | - $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
231 | - $user = $this->userSession->getUser()->getUID(); |
|
232 | - $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
233 | - $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
234 | - $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
235 | - $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
236 | - $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
237 | - $params['appNavigation'] = $nav; |
|
238 | - $params['appContents'] = $contentItems; |
|
225 | + $params = []; |
|
226 | + $params['usedSpacePercent'] = (int)$storageInfo['relative']; |
|
227 | + $params['owner'] = $storageInfo['owner']; |
|
228 | + $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
|
229 | + $params['isPublic'] = false; |
|
230 | + $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
231 | + $user = $this->userSession->getUser()->getUID(); |
|
232 | + $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
233 | + $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
234 | + $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
235 | + $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
236 | + $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
237 | + $params['appNavigation'] = $nav; |
|
238 | + $params['appContents'] = $contentItems; |
|
239 | 239 | |
240 | - $response = new TemplateResponse( |
|
241 | - $this->appName, |
|
242 | - 'index', |
|
243 | - $params |
|
244 | - ); |
|
245 | - $policy = new ContentSecurityPolicy(); |
|
246 | - $policy->addAllowedFrameDomain('\'self\''); |
|
247 | - $response->setContentSecurityPolicy($policy); |
|
240 | + $response = new TemplateResponse( |
|
241 | + $this->appName, |
|
242 | + 'index', |
|
243 | + $params |
|
244 | + ); |
|
245 | + $policy = new ContentSecurityPolicy(); |
|
246 | + $policy->addAllowedFrameDomain('\'self\''); |
|
247 | + $response->setContentSecurityPolicy($policy); |
|
248 | 248 | |
249 | - return $response; |
|
250 | - } |
|
249 | + return $response; |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * Redirects to the file list and highlight the given file id |
|
254 | - * |
|
255 | - * @param string $fileId file id to show |
|
256 | - * @return RedirectResponse redirect response or not found response |
|
257 | - * @throws \OCP\Files\NotFoundException |
|
258 | - */ |
|
259 | - private function showFile($fileId) { |
|
260 | - $uid = $this->userSession->getUser()->getUID(); |
|
261 | - $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
262 | - $files = $baseFolder->getById($fileId); |
|
263 | - $params = []; |
|
252 | + /** |
|
253 | + * Redirects to the file list and highlight the given file id |
|
254 | + * |
|
255 | + * @param string $fileId file id to show |
|
256 | + * @return RedirectResponse redirect response or not found response |
|
257 | + * @throws \OCP\Files\NotFoundException |
|
258 | + */ |
|
259 | + private function showFile($fileId) { |
|
260 | + $uid = $this->userSession->getUser()->getUID(); |
|
261 | + $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
262 | + $files = $baseFolder->getById($fileId); |
|
263 | + $params = []; |
|
264 | 264 | |
265 | - if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
266 | - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
267 | - $files = $baseFolder->getById($fileId); |
|
268 | - $params['view'] = 'trashbin'; |
|
269 | - } |
|
265 | + if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
266 | + $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
267 | + $files = $baseFolder->getById($fileId); |
|
268 | + $params['view'] = 'trashbin'; |
|
269 | + } |
|
270 | 270 | |
271 | - if (!empty($files)) { |
|
272 | - $file = current($files); |
|
273 | - if ($file instanceof Folder) { |
|
274 | - // set the full path to enter the folder |
|
275 | - $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
276 | - } else { |
|
277 | - // set parent path as dir |
|
278 | - $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
279 | - // and scroll to the entry |
|
280 | - $params['scrollto'] = $file->getName(); |
|
281 | - } |
|
282 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
283 | - } |
|
284 | - throw new \OCP\Files\NotFoundException(); |
|
285 | - } |
|
271 | + if (!empty($files)) { |
|
272 | + $file = current($files); |
|
273 | + if ($file instanceof Folder) { |
|
274 | + // set the full path to enter the folder |
|
275 | + $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
276 | + } else { |
|
277 | + // set parent path as dir |
|
278 | + $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
279 | + // and scroll to the entry |
|
280 | + $params['scrollto'] = $file->getName(); |
|
281 | + } |
|
282 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
283 | + } |
|
284 | + throw new \OCP\Files\NotFoundException(); |
|
285 | + } |
|
286 | 286 | } |
@@ -36,52 +36,52 @@ |
||
36 | 36 | |
37 | 37 | $eventDispatcher = \OC::$server->getEventDispatcher(); |
38 | 38 | $eventDispatcher->addListener( |
39 | - 'OCA\Files::loadAdditionalScripts', |
|
40 | - function() { |
|
41 | - \OCP\Util::addScript('files_sharing', 'share'); |
|
42 | - \OCP\Util::addScript('files_sharing', 'sharetabview'); |
|
43 | - \OCP\Util::addScript('files_sharing', 'sharebreadcrumbview'); |
|
44 | - \OCP\Util::addStyle('files_sharing', 'mergedAdditionalScripts'); |
|
45 | - } |
|
39 | + 'OCA\Files::loadAdditionalScripts', |
|
40 | + function() { |
|
41 | + \OCP\Util::addScript('files_sharing', 'share'); |
|
42 | + \OCP\Util::addScript('files_sharing', 'sharetabview'); |
|
43 | + \OCP\Util::addScript('files_sharing', 'sharebreadcrumbview'); |
|
44 | + \OCP\Util::addStyle('files_sharing', 'mergedAdditionalScripts'); |
|
45 | + } |
|
46 | 46 | ); |
47 | 47 | |
48 | 48 | $config = \OC::$server->getConfig(); |
49 | 49 | if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { |
50 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
51 | - $l = \OC::$server->getL10N('files_sharing'); |
|
52 | - return [ |
|
53 | - 'id' => 'sharingin', |
|
54 | - 'appname' => 'files_sharing', |
|
55 | - 'script' => 'list.php', |
|
56 | - 'order' => 10, |
|
57 | - 'name' => $l->t('Shared with you'), |
|
58 | - ]; |
|
59 | - }); |
|
50 | + \OCA\Files\App::getNavigationManager()->add(function () { |
|
51 | + $l = \OC::$server->getL10N('files_sharing'); |
|
52 | + return [ |
|
53 | + 'id' => 'sharingin', |
|
54 | + 'appname' => 'files_sharing', |
|
55 | + 'script' => 'list.php', |
|
56 | + 'order' => 10, |
|
57 | + 'name' => $l->t('Shared with you'), |
|
58 | + ]; |
|
59 | + }); |
|
60 | 60 | |
61 | - if (\OCP\Util::isSharingDisabledForUser() === false) { |
|
62 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
63 | - $l = \OC::$server->getL10N('files_sharing'); |
|
64 | - return [ |
|
65 | - 'id' => 'sharingout', |
|
66 | - 'appname' => 'files_sharing', |
|
67 | - 'script' => 'list.php', |
|
68 | - 'order' => 15, |
|
69 | - 'name' => $l->t('Shared with others'), |
|
70 | - ]; |
|
71 | - }); |
|
61 | + if (\OCP\Util::isSharingDisabledForUser() === false) { |
|
62 | + \OCA\Files\App::getNavigationManager()->add(function () { |
|
63 | + $l = \OC::$server->getL10N('files_sharing'); |
|
64 | + return [ |
|
65 | + 'id' => 'sharingout', |
|
66 | + 'appname' => 'files_sharing', |
|
67 | + 'script' => 'list.php', |
|
68 | + 'order' => 15, |
|
69 | + 'name' => $l->t('Shared with others'), |
|
70 | + ]; |
|
71 | + }); |
|
72 | 72 | |
73 | - // Check if sharing by link is enabled |
|
74 | - if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { |
|
75 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
76 | - $l = \OC::$server->getL10N('files_sharing'); |
|
77 | - return [ |
|
78 | - 'id' => 'sharinglinks', |
|
79 | - 'appname' => 'files_sharing', |
|
80 | - 'script' => 'list.php', |
|
81 | - 'order' => 20, |
|
82 | - 'name' => $l->t('Shared by link'), |
|
83 | - ]; |
|
84 | - }); |
|
85 | - } |
|
86 | - } |
|
73 | + // Check if sharing by link is enabled |
|
74 | + if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { |
|
75 | + \OCA\Files\App::getNavigationManager()->add(function () { |
|
76 | + $l = \OC::$server->getL10N('files_sharing'); |
|
77 | + return [ |
|
78 | + 'id' => 'sharinglinks', |
|
79 | + 'appname' => 'files_sharing', |
|
80 | + 'script' => 'list.php', |
|
81 | + 'order' => 20, |
|
82 | + 'name' => $l->t('Shared by link'), |
|
83 | + ]; |
|
84 | + }); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | } |
@@ -64,556 +64,556 @@ |
||
64 | 64 | */ |
65 | 65 | class ShareController extends Controller { |
66 | 66 | |
67 | - /** @var IConfig */ |
|
68 | - protected $config; |
|
69 | - /** @var IURLGenerator */ |
|
70 | - protected $urlGenerator; |
|
71 | - /** @var IUserManager */ |
|
72 | - protected $userManager; |
|
73 | - /** @var ILogger */ |
|
74 | - protected $logger; |
|
75 | - /** @var \OCP\Activity\IManager */ |
|
76 | - protected $activityManager; |
|
77 | - /** @var \OCP\Share\IManager */ |
|
78 | - protected $shareManager; |
|
79 | - /** @var ISession */ |
|
80 | - protected $session; |
|
81 | - /** @var IPreview */ |
|
82 | - protected $previewManager; |
|
83 | - /** @var IRootFolder */ |
|
84 | - protected $rootFolder; |
|
85 | - /** @var FederatedShareProvider */ |
|
86 | - protected $federatedShareProvider; |
|
87 | - /** @var EventDispatcherInterface */ |
|
88 | - protected $eventDispatcher; |
|
89 | - /** @var IL10N */ |
|
90 | - protected $l10n; |
|
91 | - /** @var Defaults */ |
|
92 | - protected $defaults; |
|
93 | - |
|
94 | - /** |
|
95 | - * @param string $appName |
|
96 | - * @param IRequest $request |
|
97 | - * @param IConfig $config |
|
98 | - * @param IURLGenerator $urlGenerator |
|
99 | - * @param IUserManager $userManager |
|
100 | - * @param ILogger $logger |
|
101 | - * @param \OCP\Activity\IManager $activityManager |
|
102 | - * @param \OCP\Share\IManager $shareManager |
|
103 | - * @param ISession $session |
|
104 | - * @param IPreview $previewManager |
|
105 | - * @param IRootFolder $rootFolder |
|
106 | - * @param FederatedShareProvider $federatedShareProvider |
|
107 | - * @param EventDispatcherInterface $eventDispatcher |
|
108 | - * @param IL10N $l10n |
|
109 | - * @param \OC_Defaults $defaults |
|
110 | - */ |
|
111 | - public function __construct($appName, |
|
112 | - IRequest $request, |
|
113 | - IConfig $config, |
|
114 | - IURLGenerator $urlGenerator, |
|
115 | - IUserManager $userManager, |
|
116 | - ILogger $logger, |
|
117 | - \OCP\Activity\IManager $activityManager, |
|
118 | - \OCP\Share\IManager $shareManager, |
|
119 | - ISession $session, |
|
120 | - IPreview $previewManager, |
|
121 | - IRootFolder $rootFolder, |
|
122 | - FederatedShareProvider $federatedShareProvider, |
|
123 | - EventDispatcherInterface $eventDispatcher, |
|
124 | - IL10N $l10n, |
|
125 | - \OC_Defaults $defaults) { |
|
126 | - parent::__construct($appName, $request); |
|
127 | - |
|
128 | - $this->config = $config; |
|
129 | - $this->urlGenerator = $urlGenerator; |
|
130 | - $this->userManager = $userManager; |
|
131 | - $this->logger = $logger; |
|
132 | - $this->activityManager = $activityManager; |
|
133 | - $this->shareManager = $shareManager; |
|
134 | - $this->session = $session; |
|
135 | - $this->previewManager = $previewManager; |
|
136 | - $this->rootFolder = $rootFolder; |
|
137 | - $this->federatedShareProvider = $federatedShareProvider; |
|
138 | - $this->eventDispatcher = $eventDispatcher; |
|
139 | - $this->l10n = $l10n; |
|
140 | - $this->defaults = $defaults; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @PublicPage |
|
145 | - * @NoCSRFRequired |
|
146 | - * |
|
147 | - * @param string $token |
|
148 | - * @return TemplateResponse|RedirectResponse |
|
149 | - */ |
|
150 | - public function showAuthenticate($token) { |
|
151 | - $share = $this->shareManager->getShareByToken($token); |
|
152 | - |
|
153 | - if($this->linkShareAuth($share)) { |
|
154 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.showShare', array('token' => $token))); |
|
155 | - } |
|
156 | - |
|
157 | - return new TemplateResponse($this->appName, 'authenticate', array(), 'guest'); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @PublicPage |
|
162 | - * @UseSession |
|
163 | - * @BruteForceProtection publicLinkAuth |
|
164 | - * |
|
165 | - * Authenticates against password-protected shares |
|
166 | - * @param string $token |
|
167 | - * @param string $password |
|
168 | - * @return RedirectResponse|TemplateResponse|NotFoundResponse |
|
169 | - */ |
|
170 | - public function authenticate($token, $password = '') { |
|
171 | - |
|
172 | - // Check whether share exists |
|
173 | - try { |
|
174 | - $share = $this->shareManager->getShareByToken($token); |
|
175 | - } catch (ShareNotFound $e) { |
|
176 | - return new NotFoundResponse(); |
|
177 | - } |
|
178 | - |
|
179 | - $authenticate = $this->linkShareAuth($share, $password); |
|
180 | - |
|
181 | - if($authenticate === true) { |
|
182 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.showShare', array('token' => $token))); |
|
183 | - } |
|
184 | - |
|
185 | - return new TemplateResponse($this->appName, 'authenticate', array('wrongpw' => true), 'guest'); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Authenticate a link item with the given password. |
|
190 | - * Or use the session if no password is provided. |
|
191 | - * |
|
192 | - * This is a modified version of Helper::authenticate |
|
193 | - * TODO: Try to merge back eventually with Helper::authenticate |
|
194 | - * |
|
195 | - * @param \OCP\Share\IShare $share |
|
196 | - * @param string|null $password |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - private function linkShareAuth(\OCP\Share\IShare $share, $password = null) { |
|
200 | - if ($password !== null) { |
|
201 | - if ($this->shareManager->checkPassword($share, $password)) { |
|
202 | - $this->session->set('public_link_authenticated', (string)$share->getId()); |
|
203 | - } else { |
|
204 | - $this->emitAccessShareHook($share, 403, 'Wrong password'); |
|
205 | - return false; |
|
206 | - } |
|
207 | - } else { |
|
208 | - // not authenticated ? |
|
209 | - if ( ! $this->session->exists('public_link_authenticated') |
|
210 | - || $this->session->get('public_link_authenticated') !== (string)$share->getId()) { |
|
211 | - return false; |
|
212 | - } |
|
213 | - } |
|
214 | - return true; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * throws hooks when a share is attempted to be accessed |
|
219 | - * |
|
220 | - * @param \OCP\Share\IShare|string $share the Share instance if available, |
|
221 | - * otherwise token |
|
222 | - * @param int $errorCode |
|
223 | - * @param string $errorMessage |
|
224 | - * @throws \OC\HintException |
|
225 | - * @throws \OC\ServerNotAvailableException |
|
226 | - */ |
|
227 | - protected function emitAccessShareHook($share, $errorCode = 200, $errorMessage = '') { |
|
228 | - $itemType = $itemSource = $uidOwner = ''; |
|
229 | - $token = $share; |
|
230 | - $exception = null; |
|
231 | - if($share instanceof \OCP\Share\IShare) { |
|
232 | - try { |
|
233 | - $token = $share->getToken(); |
|
234 | - $uidOwner = $share->getSharedBy(); |
|
235 | - $itemType = $share->getNodeType(); |
|
236 | - $itemSource = $share->getNodeId(); |
|
237 | - } catch (\Exception $e) { |
|
238 | - // we log what we know and pass on the exception afterwards |
|
239 | - $exception = $e; |
|
240 | - } |
|
241 | - } |
|
242 | - \OC_Hook::emit('OCP\Share', 'share_link_access', [ |
|
243 | - 'itemType' => $itemType, |
|
244 | - 'itemSource' => $itemSource, |
|
245 | - 'uidOwner' => $uidOwner, |
|
246 | - 'token' => $token, |
|
247 | - 'errorCode' => $errorCode, |
|
248 | - 'errorMessage' => $errorMessage, |
|
249 | - ]); |
|
250 | - if(!is_null($exception)) { |
|
251 | - throw $exception; |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Validate the permissions of the share |
|
257 | - * |
|
258 | - * @param Share\IShare $share |
|
259 | - * @return bool |
|
260 | - */ |
|
261 | - private function validateShare(\OCP\Share\IShare $share) { |
|
262 | - return $share->getNode()->isReadable() && $share->getNode()->isShareable(); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * @PublicPage |
|
267 | - * @NoCSRFRequired |
|
268 | - * |
|
269 | - * @param string $token |
|
270 | - * @param string $path |
|
271 | - * @return TemplateResponse|RedirectResponse|NotFoundResponse |
|
272 | - * @throws NotFoundException |
|
273 | - * @throws \Exception |
|
274 | - */ |
|
275 | - public function showShare($token, $path = '') { |
|
276 | - \OC_User::setIncognitoMode(true); |
|
277 | - |
|
278 | - // Check whether share exists |
|
279 | - try { |
|
280 | - $share = $this->shareManager->getShareByToken($token); |
|
281 | - } catch (ShareNotFound $e) { |
|
282 | - $this->emitAccessShareHook($token, 404, 'Share not found'); |
|
283 | - return new NotFoundResponse(); |
|
284 | - } |
|
285 | - |
|
286 | - // Share is password protected - check whether the user is permitted to access the share |
|
287 | - if ($share->getPassword() !== null && !$this->linkShareAuth($share)) { |
|
288 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', |
|
289 | - array('token' => $token))); |
|
290 | - } |
|
291 | - |
|
292 | - if (!$this->validateShare($share)) { |
|
293 | - throw new NotFoundException(); |
|
294 | - } |
|
295 | - // We can't get the path of a file share |
|
296 | - try { |
|
297 | - if ($share->getNode() instanceof \OCP\Files\File && $path !== '') { |
|
298 | - $this->emitAccessShareHook($share, 404, 'Share not found'); |
|
299 | - throw new NotFoundException(); |
|
300 | - } |
|
301 | - } catch (\Exception $e) { |
|
302 | - $this->emitAccessShareHook($share, 404, 'Share not found'); |
|
303 | - throw $e; |
|
304 | - } |
|
305 | - |
|
306 | - $shareTmpl = []; |
|
307 | - $shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName(); |
|
308 | - $shareTmpl['owner'] = $share->getShareOwner(); |
|
309 | - $shareTmpl['filename'] = $share->getNode()->getName(); |
|
310 | - $shareTmpl['directory_path'] = $share->getTarget(); |
|
311 | - $shareTmpl['mimetype'] = $share->getNode()->getMimetype(); |
|
312 | - $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype()); |
|
313 | - $shareTmpl['dirToken'] = $token; |
|
314 | - $shareTmpl['sharingToken'] = $token; |
|
315 | - $shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
316 | - $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false'; |
|
317 | - $shareTmpl['dir'] = ''; |
|
318 | - $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize(); |
|
319 | - $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize()); |
|
320 | - |
|
321 | - // Show file list |
|
322 | - $hideFileList = false; |
|
323 | - if ($share->getNode() instanceof \OCP\Files\Folder) { |
|
324 | - /** @var \OCP\Files\Folder $rootFolder */ |
|
325 | - $rootFolder = $share->getNode(); |
|
326 | - |
|
327 | - try { |
|
328 | - $folderNode = $rootFolder->get($path); |
|
329 | - } catch (\OCP\Files\NotFoundException $e) { |
|
330 | - $this->emitAccessShareHook($share, 404, 'Share not found'); |
|
331 | - throw new NotFoundException(); |
|
332 | - } |
|
333 | - |
|
334 | - $shareTmpl['dir'] = $rootFolder->getRelativePath($folderNode->getPath()); |
|
335 | - |
|
336 | - /* |
|
67 | + /** @var IConfig */ |
|
68 | + protected $config; |
|
69 | + /** @var IURLGenerator */ |
|
70 | + protected $urlGenerator; |
|
71 | + /** @var IUserManager */ |
|
72 | + protected $userManager; |
|
73 | + /** @var ILogger */ |
|
74 | + protected $logger; |
|
75 | + /** @var \OCP\Activity\IManager */ |
|
76 | + protected $activityManager; |
|
77 | + /** @var \OCP\Share\IManager */ |
|
78 | + protected $shareManager; |
|
79 | + /** @var ISession */ |
|
80 | + protected $session; |
|
81 | + /** @var IPreview */ |
|
82 | + protected $previewManager; |
|
83 | + /** @var IRootFolder */ |
|
84 | + protected $rootFolder; |
|
85 | + /** @var FederatedShareProvider */ |
|
86 | + protected $federatedShareProvider; |
|
87 | + /** @var EventDispatcherInterface */ |
|
88 | + protected $eventDispatcher; |
|
89 | + /** @var IL10N */ |
|
90 | + protected $l10n; |
|
91 | + /** @var Defaults */ |
|
92 | + protected $defaults; |
|
93 | + |
|
94 | + /** |
|
95 | + * @param string $appName |
|
96 | + * @param IRequest $request |
|
97 | + * @param IConfig $config |
|
98 | + * @param IURLGenerator $urlGenerator |
|
99 | + * @param IUserManager $userManager |
|
100 | + * @param ILogger $logger |
|
101 | + * @param \OCP\Activity\IManager $activityManager |
|
102 | + * @param \OCP\Share\IManager $shareManager |
|
103 | + * @param ISession $session |
|
104 | + * @param IPreview $previewManager |
|
105 | + * @param IRootFolder $rootFolder |
|
106 | + * @param FederatedShareProvider $federatedShareProvider |
|
107 | + * @param EventDispatcherInterface $eventDispatcher |
|
108 | + * @param IL10N $l10n |
|
109 | + * @param \OC_Defaults $defaults |
|
110 | + */ |
|
111 | + public function __construct($appName, |
|
112 | + IRequest $request, |
|
113 | + IConfig $config, |
|
114 | + IURLGenerator $urlGenerator, |
|
115 | + IUserManager $userManager, |
|
116 | + ILogger $logger, |
|
117 | + \OCP\Activity\IManager $activityManager, |
|
118 | + \OCP\Share\IManager $shareManager, |
|
119 | + ISession $session, |
|
120 | + IPreview $previewManager, |
|
121 | + IRootFolder $rootFolder, |
|
122 | + FederatedShareProvider $federatedShareProvider, |
|
123 | + EventDispatcherInterface $eventDispatcher, |
|
124 | + IL10N $l10n, |
|
125 | + \OC_Defaults $defaults) { |
|
126 | + parent::__construct($appName, $request); |
|
127 | + |
|
128 | + $this->config = $config; |
|
129 | + $this->urlGenerator = $urlGenerator; |
|
130 | + $this->userManager = $userManager; |
|
131 | + $this->logger = $logger; |
|
132 | + $this->activityManager = $activityManager; |
|
133 | + $this->shareManager = $shareManager; |
|
134 | + $this->session = $session; |
|
135 | + $this->previewManager = $previewManager; |
|
136 | + $this->rootFolder = $rootFolder; |
|
137 | + $this->federatedShareProvider = $federatedShareProvider; |
|
138 | + $this->eventDispatcher = $eventDispatcher; |
|
139 | + $this->l10n = $l10n; |
|
140 | + $this->defaults = $defaults; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @PublicPage |
|
145 | + * @NoCSRFRequired |
|
146 | + * |
|
147 | + * @param string $token |
|
148 | + * @return TemplateResponse|RedirectResponse |
|
149 | + */ |
|
150 | + public function showAuthenticate($token) { |
|
151 | + $share = $this->shareManager->getShareByToken($token); |
|
152 | + |
|
153 | + if($this->linkShareAuth($share)) { |
|
154 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.showShare', array('token' => $token))); |
|
155 | + } |
|
156 | + |
|
157 | + return new TemplateResponse($this->appName, 'authenticate', array(), 'guest'); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @PublicPage |
|
162 | + * @UseSession |
|
163 | + * @BruteForceProtection publicLinkAuth |
|
164 | + * |
|
165 | + * Authenticates against password-protected shares |
|
166 | + * @param string $token |
|
167 | + * @param string $password |
|
168 | + * @return RedirectResponse|TemplateResponse|NotFoundResponse |
|
169 | + */ |
|
170 | + public function authenticate($token, $password = '') { |
|
171 | + |
|
172 | + // Check whether share exists |
|
173 | + try { |
|
174 | + $share = $this->shareManager->getShareByToken($token); |
|
175 | + } catch (ShareNotFound $e) { |
|
176 | + return new NotFoundResponse(); |
|
177 | + } |
|
178 | + |
|
179 | + $authenticate = $this->linkShareAuth($share, $password); |
|
180 | + |
|
181 | + if($authenticate === true) { |
|
182 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.showShare', array('token' => $token))); |
|
183 | + } |
|
184 | + |
|
185 | + return new TemplateResponse($this->appName, 'authenticate', array('wrongpw' => true), 'guest'); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Authenticate a link item with the given password. |
|
190 | + * Or use the session if no password is provided. |
|
191 | + * |
|
192 | + * This is a modified version of Helper::authenticate |
|
193 | + * TODO: Try to merge back eventually with Helper::authenticate |
|
194 | + * |
|
195 | + * @param \OCP\Share\IShare $share |
|
196 | + * @param string|null $password |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + private function linkShareAuth(\OCP\Share\IShare $share, $password = null) { |
|
200 | + if ($password !== null) { |
|
201 | + if ($this->shareManager->checkPassword($share, $password)) { |
|
202 | + $this->session->set('public_link_authenticated', (string)$share->getId()); |
|
203 | + } else { |
|
204 | + $this->emitAccessShareHook($share, 403, 'Wrong password'); |
|
205 | + return false; |
|
206 | + } |
|
207 | + } else { |
|
208 | + // not authenticated ? |
|
209 | + if ( ! $this->session->exists('public_link_authenticated') |
|
210 | + || $this->session->get('public_link_authenticated') !== (string)$share->getId()) { |
|
211 | + return false; |
|
212 | + } |
|
213 | + } |
|
214 | + return true; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * throws hooks when a share is attempted to be accessed |
|
219 | + * |
|
220 | + * @param \OCP\Share\IShare|string $share the Share instance if available, |
|
221 | + * otherwise token |
|
222 | + * @param int $errorCode |
|
223 | + * @param string $errorMessage |
|
224 | + * @throws \OC\HintException |
|
225 | + * @throws \OC\ServerNotAvailableException |
|
226 | + */ |
|
227 | + protected function emitAccessShareHook($share, $errorCode = 200, $errorMessage = '') { |
|
228 | + $itemType = $itemSource = $uidOwner = ''; |
|
229 | + $token = $share; |
|
230 | + $exception = null; |
|
231 | + if($share instanceof \OCP\Share\IShare) { |
|
232 | + try { |
|
233 | + $token = $share->getToken(); |
|
234 | + $uidOwner = $share->getSharedBy(); |
|
235 | + $itemType = $share->getNodeType(); |
|
236 | + $itemSource = $share->getNodeId(); |
|
237 | + } catch (\Exception $e) { |
|
238 | + // we log what we know and pass on the exception afterwards |
|
239 | + $exception = $e; |
|
240 | + } |
|
241 | + } |
|
242 | + \OC_Hook::emit('OCP\Share', 'share_link_access', [ |
|
243 | + 'itemType' => $itemType, |
|
244 | + 'itemSource' => $itemSource, |
|
245 | + 'uidOwner' => $uidOwner, |
|
246 | + 'token' => $token, |
|
247 | + 'errorCode' => $errorCode, |
|
248 | + 'errorMessage' => $errorMessage, |
|
249 | + ]); |
|
250 | + if(!is_null($exception)) { |
|
251 | + throw $exception; |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Validate the permissions of the share |
|
257 | + * |
|
258 | + * @param Share\IShare $share |
|
259 | + * @return bool |
|
260 | + */ |
|
261 | + private function validateShare(\OCP\Share\IShare $share) { |
|
262 | + return $share->getNode()->isReadable() && $share->getNode()->isShareable(); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * @PublicPage |
|
267 | + * @NoCSRFRequired |
|
268 | + * |
|
269 | + * @param string $token |
|
270 | + * @param string $path |
|
271 | + * @return TemplateResponse|RedirectResponse|NotFoundResponse |
|
272 | + * @throws NotFoundException |
|
273 | + * @throws \Exception |
|
274 | + */ |
|
275 | + public function showShare($token, $path = '') { |
|
276 | + \OC_User::setIncognitoMode(true); |
|
277 | + |
|
278 | + // Check whether share exists |
|
279 | + try { |
|
280 | + $share = $this->shareManager->getShareByToken($token); |
|
281 | + } catch (ShareNotFound $e) { |
|
282 | + $this->emitAccessShareHook($token, 404, 'Share not found'); |
|
283 | + return new NotFoundResponse(); |
|
284 | + } |
|
285 | + |
|
286 | + // Share is password protected - check whether the user is permitted to access the share |
|
287 | + if ($share->getPassword() !== null && !$this->linkShareAuth($share)) { |
|
288 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', |
|
289 | + array('token' => $token))); |
|
290 | + } |
|
291 | + |
|
292 | + if (!$this->validateShare($share)) { |
|
293 | + throw new NotFoundException(); |
|
294 | + } |
|
295 | + // We can't get the path of a file share |
|
296 | + try { |
|
297 | + if ($share->getNode() instanceof \OCP\Files\File && $path !== '') { |
|
298 | + $this->emitAccessShareHook($share, 404, 'Share not found'); |
|
299 | + throw new NotFoundException(); |
|
300 | + } |
|
301 | + } catch (\Exception $e) { |
|
302 | + $this->emitAccessShareHook($share, 404, 'Share not found'); |
|
303 | + throw $e; |
|
304 | + } |
|
305 | + |
|
306 | + $shareTmpl = []; |
|
307 | + $shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName(); |
|
308 | + $shareTmpl['owner'] = $share->getShareOwner(); |
|
309 | + $shareTmpl['filename'] = $share->getNode()->getName(); |
|
310 | + $shareTmpl['directory_path'] = $share->getTarget(); |
|
311 | + $shareTmpl['mimetype'] = $share->getNode()->getMimetype(); |
|
312 | + $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype()); |
|
313 | + $shareTmpl['dirToken'] = $token; |
|
314 | + $shareTmpl['sharingToken'] = $token; |
|
315 | + $shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
316 | + $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false'; |
|
317 | + $shareTmpl['dir'] = ''; |
|
318 | + $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize(); |
|
319 | + $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize()); |
|
320 | + |
|
321 | + // Show file list |
|
322 | + $hideFileList = false; |
|
323 | + if ($share->getNode() instanceof \OCP\Files\Folder) { |
|
324 | + /** @var \OCP\Files\Folder $rootFolder */ |
|
325 | + $rootFolder = $share->getNode(); |
|
326 | + |
|
327 | + try { |
|
328 | + $folderNode = $rootFolder->get($path); |
|
329 | + } catch (\OCP\Files\NotFoundException $e) { |
|
330 | + $this->emitAccessShareHook($share, 404, 'Share not found'); |
|
331 | + throw new NotFoundException(); |
|
332 | + } |
|
333 | + |
|
334 | + $shareTmpl['dir'] = $rootFolder->getRelativePath($folderNode->getPath()); |
|
335 | + |
|
336 | + /* |
|
337 | 337 | * The OC_Util methods require a view. This just uses the node API |
338 | 338 | */ |
339 | - $freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath()); |
|
340 | - if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
341 | - $freeSpace = max($freeSpace, 0); |
|
342 | - } else { |
|
343 | - $freeSpace = (INF > 0) ? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188 |
|
344 | - } |
|
345 | - |
|
346 | - $hideFileList = $share->getPermissions() & \OCP\Constants::PERMISSION_READ ? false : true; |
|
347 | - $maxUploadFilesize = $freeSpace; |
|
348 | - |
|
349 | - $folder = new Template('files', 'list', ''); |
|
350 | - $folder->assign('dir', $rootFolder->getRelativePath($folderNode->getPath())); |
|
351 | - $folder->assign('dirToken', $token); |
|
352 | - $folder->assign('permissions', \OCP\Constants::PERMISSION_READ); |
|
353 | - $folder->assign('isPublic', true); |
|
354 | - $folder->assign('hideFileList', $hideFileList); |
|
355 | - $folder->assign('publicUploadEnabled', 'no'); |
|
356 | - $folder->assign('uploadMaxFilesize', $maxUploadFilesize); |
|
357 | - $folder->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize)); |
|
358 | - $folder->assign('freeSpace', $freeSpace); |
|
359 | - $folder->assign('usedSpacePercent', 0); |
|
360 | - $folder->assign('trash', false); |
|
361 | - $shareTmpl['folder'] = $folder->fetchPage(); |
|
362 | - } |
|
363 | - |
|
364 | - $shareTmpl['hideFileList'] = $hideFileList; |
|
365 | - $shareTmpl['shareOwner'] = $this->userManager->get($share->getShareOwner())->getDisplayName(); |
|
366 | - $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', ['token' => $token]); |
|
367 | - $shareTmpl['shareUrl'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]); |
|
368 | - $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10); |
|
369 | - $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true); |
|
370 | - $shareTmpl['previewMaxX'] = $this->config->getSystemValue('preview_max_x', 1024); |
|
371 | - $shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024); |
|
372 | - $shareTmpl['disclaimer'] = $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null); |
|
373 | - if ($shareTmpl['previewSupported']) { |
|
374 | - $shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute( 'files_sharing.PublicPreview.getPreview', |
|
375 | - ['x' => 200, 'y' => 200, 'file' => $shareTmpl['directory_path'], 't' => $shareTmpl['dirToken']]); |
|
376 | - } else { |
|
377 | - $shareTmpl['previewImage'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-fb.png')); |
|
378 | - } |
|
379 | - |
|
380 | - // Load files we need |
|
381 | - \OCP\Util::addScript('files', 'file-upload'); |
|
382 | - \OCP\Util::addStyle('files_sharing', 'publicView'); |
|
383 | - \OCP\Util::addScript('files_sharing', 'public'); |
|
384 | - \OCP\Util::addScript('files', 'fileactions'); |
|
385 | - \OCP\Util::addScript('files', 'fileactionsmenu'); |
|
386 | - \OCP\Util::addScript('files', 'jquery.fileupload'); |
|
387 | - \OCP\Util::addScript('files_sharing', 'files_drop'); |
|
388 | - |
|
389 | - if (isset($shareTmpl['folder'])) { |
|
390 | - // JS required for folders |
|
391 | - \OCP\Util::addStyle('files', 'merged'); |
|
392 | - \OCP\Util::addScript('files', 'filesummary'); |
|
393 | - \OCP\Util::addScript('files', 'breadcrumb'); |
|
394 | - \OCP\Util::addScript('files', 'fileinfomodel'); |
|
395 | - \OCP\Util::addScript('files', 'newfilemenu'); |
|
396 | - \OCP\Util::addScript('files', 'files'); |
|
397 | - \OCP\Util::addScript('files', 'filelist'); |
|
398 | - \OCP\Util::addScript('files', 'keyboardshortcuts'); |
|
399 | - } |
|
400 | - |
|
401 | - // OpenGraph Support: http://ogp.me/ |
|
402 | - \OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $this->defaults->getName() . ' - ' . $this->defaults->getSlogan()]); |
|
403 | - \OCP\Util::addHeader('meta', ['property' => "og:description", 'content' => $this->l10n->t('%s is publicly shared', [$shareTmpl['filename']])]); |
|
404 | - \OCP\Util::addHeader('meta', ['property' => "og:site_name", 'content' => $this->defaults->getName()]); |
|
405 | - \OCP\Util::addHeader('meta', ['property' => "og:url", 'content' => $shareTmpl['shareUrl']]); |
|
406 | - \OCP\Util::addHeader('meta', ['property' => "og:type", 'content' => "object"]); |
|
407 | - \OCP\Util::addHeader('meta', ['property' => "og:image", 'content' => $shareTmpl['previewImage']]); |
|
408 | - |
|
409 | - $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts'); |
|
410 | - |
|
411 | - $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); |
|
412 | - $csp->addAllowedFrameDomain('\'self\''); |
|
413 | - $response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base'); |
|
414 | - $response->setContentSecurityPolicy($csp); |
|
415 | - |
|
416 | - $this->emitAccessShareHook($share); |
|
417 | - |
|
418 | - return $response; |
|
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * @PublicPage |
|
423 | - * @NoCSRFRequired |
|
424 | - * |
|
425 | - * @param string $token |
|
426 | - * @param string $files |
|
427 | - * @param string $path |
|
428 | - * @param string $downloadStartSecret |
|
429 | - * @return void|\OCP\AppFramework\Http\Response |
|
430 | - * @throws NotFoundException |
|
431 | - */ |
|
432 | - public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') { |
|
433 | - \OC_User::setIncognitoMode(true); |
|
434 | - |
|
435 | - $share = $this->shareManager->getShareByToken($token); |
|
436 | - |
|
437 | - if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) { |
|
438 | - return new \OCP\AppFramework\Http\DataResponse('Share is read-only'); |
|
439 | - } |
|
440 | - |
|
441 | - // Share is password protected - check whether the user is permitted to access the share |
|
442 | - if ($share->getPassword() !== null && !$this->linkShareAuth($share)) { |
|
443 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', |
|
444 | - ['token' => $token])); |
|
445 | - } |
|
446 | - |
|
447 | - $files_list = null; |
|
448 | - if (!is_null($files)) { // download selected files |
|
449 | - $files_list = json_decode($files); |
|
450 | - // in case we get only a single file |
|
451 | - if ($files_list === null) { |
|
452 | - $files_list = [$files]; |
|
453 | - } |
|
454 | - } |
|
455 | - |
|
456 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
457 | - $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath()); |
|
458 | - |
|
459 | - if (!$this->validateShare($share)) { |
|
460 | - throw new NotFoundException(); |
|
461 | - } |
|
462 | - |
|
463 | - // Single file share |
|
464 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
465 | - // Single file download |
|
466 | - $this->singleFileDownloaded($share, $share->getNode()); |
|
467 | - } |
|
468 | - // Directory share |
|
469 | - else { |
|
470 | - /** @var \OCP\Files\Folder $node */ |
|
471 | - $node = $share->getNode(); |
|
472 | - |
|
473 | - // Try to get the path |
|
474 | - if ($path !== '') { |
|
475 | - try { |
|
476 | - $node = $node->get($path); |
|
477 | - } catch (NotFoundException $e) { |
|
478 | - $this->emitAccessShareHook($share, 404, 'Share not found'); |
|
479 | - return new NotFoundResponse(); |
|
480 | - } |
|
481 | - } |
|
482 | - |
|
483 | - $originalSharePath = $userFolder->getRelativePath($node->getPath()); |
|
484 | - |
|
485 | - if ($node instanceof \OCP\Files\File) { |
|
486 | - // Single file download |
|
487 | - $this->singleFileDownloaded($share, $share->getNode()); |
|
488 | - } else if (!empty($files_list)) { |
|
489 | - $this->fileListDownloaded($share, $files_list, $node); |
|
490 | - } else { |
|
491 | - // The folder is downloaded |
|
492 | - $this->singleFileDownloaded($share, $share->getNode()); |
|
493 | - } |
|
494 | - } |
|
495 | - |
|
496 | - /* FIXME: We should do this all nicely in OCP */ |
|
497 | - OC_Util::tearDownFS(); |
|
498 | - OC_Util::setupFS($share->getShareOwner()); |
|
499 | - |
|
500 | - /** |
|
501 | - * this sets a cookie to be able to recognize the start of the download |
|
502 | - * the content must not be longer than 32 characters and must only contain |
|
503 | - * alphanumeric characters |
|
504 | - */ |
|
505 | - if (!empty($downloadStartSecret) |
|
506 | - && !isset($downloadStartSecret[32]) |
|
507 | - && preg_match('!^[a-zA-Z0-9]+$!', $downloadStartSecret) === 1) { |
|
508 | - |
|
509 | - // FIXME: set on the response once we use an actual app framework response |
|
510 | - setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/'); |
|
511 | - } |
|
512 | - |
|
513 | - $this->emitAccessShareHook($share); |
|
514 | - |
|
515 | - $server_params = array( 'head' => $this->request->getMethod() == 'HEAD' ); |
|
516 | - |
|
517 | - /** |
|
518 | - * Http range requests support |
|
519 | - */ |
|
520 | - if (isset($_SERVER['HTTP_RANGE'])) { |
|
521 | - $server_params['range'] = $this->request->getHeader('Range'); |
|
522 | - } |
|
523 | - |
|
524 | - // download selected files |
|
525 | - if (!is_null($files) && $files !== '') { |
|
526 | - // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well |
|
527 | - // after dispatching the request which results in a "Cannot modify header information" notice. |
|
528 | - OC_Files::get($originalSharePath, $files_list, $server_params); |
|
529 | - exit(); |
|
530 | - } else { |
|
531 | - // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well |
|
532 | - // after dispatching the request which results in a "Cannot modify header information" notice. |
|
533 | - OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $server_params); |
|
534 | - exit(); |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * create activity for every downloaded file |
|
540 | - * |
|
541 | - * @param Share\IShare $share |
|
542 | - * @param array $files_list |
|
543 | - * @param \OCP\Files\Folder $node |
|
544 | - */ |
|
545 | - protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) { |
|
546 | - foreach ($files_list as $file) { |
|
547 | - $subNode = $node->get($file); |
|
548 | - $this->singleFileDownloaded($share, $subNode); |
|
549 | - } |
|
550 | - |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * create activity if a single file was downloaded from a link share |
|
555 | - * |
|
556 | - * @param Share\IShare $share |
|
557 | - */ |
|
558 | - protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) { |
|
559 | - |
|
560 | - $fileId = $node->getId(); |
|
561 | - |
|
562 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
563 | - $userNodeList = $userFolder->getById($fileId); |
|
564 | - $userNode = $userNodeList[0]; |
|
565 | - $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
566 | - $userPath = $userFolder->getRelativePath($userNode->getPath()); |
|
567 | - $ownerPath = $ownerFolder->getRelativePath($node->getPath()); |
|
568 | - |
|
569 | - $parameters = [$userPath]; |
|
570 | - |
|
571 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
572 | - if ($node instanceof \OCP\Files\File) { |
|
573 | - $subject = Downloads::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED; |
|
574 | - } else { |
|
575 | - $subject = Downloads::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED; |
|
576 | - } |
|
577 | - $parameters[] = $share->getSharedWith(); |
|
578 | - } else { |
|
579 | - if ($node instanceof \OCP\Files\File) { |
|
580 | - $subject = Downloads::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED; |
|
581 | - } else { |
|
582 | - $subject = Downloads::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED; |
|
583 | - } |
|
584 | - } |
|
585 | - |
|
586 | - $this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath); |
|
587 | - |
|
588 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
589 | - $parameters[0] = $ownerPath; |
|
590 | - $this->publishActivity($subject, $parameters, $share->getShareOwner(), $fileId, $ownerPath); |
|
591 | - } |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * publish activity |
|
596 | - * |
|
597 | - * @param string $subject |
|
598 | - * @param array $parameters |
|
599 | - * @param string $affectedUser |
|
600 | - * @param int $fileId |
|
601 | - * @param string $filePath |
|
602 | - */ |
|
603 | - protected function publishActivity($subject, |
|
604 | - array $parameters, |
|
605 | - $affectedUser, |
|
606 | - $fileId, |
|
607 | - $filePath) { |
|
608 | - |
|
609 | - $event = $this->activityManager->generateEvent(); |
|
610 | - $event->setApp('files_sharing') |
|
611 | - ->setType('public_links') |
|
612 | - ->setSubject($subject, $parameters) |
|
613 | - ->setAffectedUser($affectedUser) |
|
614 | - ->setObject('files', $fileId, $filePath); |
|
615 | - $this->activityManager->publish($event); |
|
616 | - } |
|
339 | + $freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath()); |
|
340 | + if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
341 | + $freeSpace = max($freeSpace, 0); |
|
342 | + } else { |
|
343 | + $freeSpace = (INF > 0) ? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188 |
|
344 | + } |
|
345 | + |
|
346 | + $hideFileList = $share->getPermissions() & \OCP\Constants::PERMISSION_READ ? false : true; |
|
347 | + $maxUploadFilesize = $freeSpace; |
|
348 | + |
|
349 | + $folder = new Template('files', 'list', ''); |
|
350 | + $folder->assign('dir', $rootFolder->getRelativePath($folderNode->getPath())); |
|
351 | + $folder->assign('dirToken', $token); |
|
352 | + $folder->assign('permissions', \OCP\Constants::PERMISSION_READ); |
|
353 | + $folder->assign('isPublic', true); |
|
354 | + $folder->assign('hideFileList', $hideFileList); |
|
355 | + $folder->assign('publicUploadEnabled', 'no'); |
|
356 | + $folder->assign('uploadMaxFilesize', $maxUploadFilesize); |
|
357 | + $folder->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize)); |
|
358 | + $folder->assign('freeSpace', $freeSpace); |
|
359 | + $folder->assign('usedSpacePercent', 0); |
|
360 | + $folder->assign('trash', false); |
|
361 | + $shareTmpl['folder'] = $folder->fetchPage(); |
|
362 | + } |
|
363 | + |
|
364 | + $shareTmpl['hideFileList'] = $hideFileList; |
|
365 | + $shareTmpl['shareOwner'] = $this->userManager->get($share->getShareOwner())->getDisplayName(); |
|
366 | + $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', ['token' => $token]); |
|
367 | + $shareTmpl['shareUrl'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]); |
|
368 | + $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10); |
|
369 | + $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true); |
|
370 | + $shareTmpl['previewMaxX'] = $this->config->getSystemValue('preview_max_x', 1024); |
|
371 | + $shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024); |
|
372 | + $shareTmpl['disclaimer'] = $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null); |
|
373 | + if ($shareTmpl['previewSupported']) { |
|
374 | + $shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute( 'files_sharing.PublicPreview.getPreview', |
|
375 | + ['x' => 200, 'y' => 200, 'file' => $shareTmpl['directory_path'], 't' => $shareTmpl['dirToken']]); |
|
376 | + } else { |
|
377 | + $shareTmpl['previewImage'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-fb.png')); |
|
378 | + } |
|
379 | + |
|
380 | + // Load files we need |
|
381 | + \OCP\Util::addScript('files', 'file-upload'); |
|
382 | + \OCP\Util::addStyle('files_sharing', 'publicView'); |
|
383 | + \OCP\Util::addScript('files_sharing', 'public'); |
|
384 | + \OCP\Util::addScript('files', 'fileactions'); |
|
385 | + \OCP\Util::addScript('files', 'fileactionsmenu'); |
|
386 | + \OCP\Util::addScript('files', 'jquery.fileupload'); |
|
387 | + \OCP\Util::addScript('files_sharing', 'files_drop'); |
|
388 | + |
|
389 | + if (isset($shareTmpl['folder'])) { |
|
390 | + // JS required for folders |
|
391 | + \OCP\Util::addStyle('files', 'merged'); |
|
392 | + \OCP\Util::addScript('files', 'filesummary'); |
|
393 | + \OCP\Util::addScript('files', 'breadcrumb'); |
|
394 | + \OCP\Util::addScript('files', 'fileinfomodel'); |
|
395 | + \OCP\Util::addScript('files', 'newfilemenu'); |
|
396 | + \OCP\Util::addScript('files', 'files'); |
|
397 | + \OCP\Util::addScript('files', 'filelist'); |
|
398 | + \OCP\Util::addScript('files', 'keyboardshortcuts'); |
|
399 | + } |
|
400 | + |
|
401 | + // OpenGraph Support: http://ogp.me/ |
|
402 | + \OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $this->defaults->getName() . ' - ' . $this->defaults->getSlogan()]); |
|
403 | + \OCP\Util::addHeader('meta', ['property' => "og:description", 'content' => $this->l10n->t('%s is publicly shared', [$shareTmpl['filename']])]); |
|
404 | + \OCP\Util::addHeader('meta', ['property' => "og:site_name", 'content' => $this->defaults->getName()]); |
|
405 | + \OCP\Util::addHeader('meta', ['property' => "og:url", 'content' => $shareTmpl['shareUrl']]); |
|
406 | + \OCP\Util::addHeader('meta', ['property' => "og:type", 'content' => "object"]); |
|
407 | + \OCP\Util::addHeader('meta', ['property' => "og:image", 'content' => $shareTmpl['previewImage']]); |
|
408 | + |
|
409 | + $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts'); |
|
410 | + |
|
411 | + $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); |
|
412 | + $csp->addAllowedFrameDomain('\'self\''); |
|
413 | + $response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base'); |
|
414 | + $response->setContentSecurityPolicy($csp); |
|
415 | + |
|
416 | + $this->emitAccessShareHook($share); |
|
417 | + |
|
418 | + return $response; |
|
419 | + } |
|
420 | + |
|
421 | + /** |
|
422 | + * @PublicPage |
|
423 | + * @NoCSRFRequired |
|
424 | + * |
|
425 | + * @param string $token |
|
426 | + * @param string $files |
|
427 | + * @param string $path |
|
428 | + * @param string $downloadStartSecret |
|
429 | + * @return void|\OCP\AppFramework\Http\Response |
|
430 | + * @throws NotFoundException |
|
431 | + */ |
|
432 | + public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') { |
|
433 | + \OC_User::setIncognitoMode(true); |
|
434 | + |
|
435 | + $share = $this->shareManager->getShareByToken($token); |
|
436 | + |
|
437 | + if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) { |
|
438 | + return new \OCP\AppFramework\Http\DataResponse('Share is read-only'); |
|
439 | + } |
|
440 | + |
|
441 | + // Share is password protected - check whether the user is permitted to access the share |
|
442 | + if ($share->getPassword() !== null && !$this->linkShareAuth($share)) { |
|
443 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', |
|
444 | + ['token' => $token])); |
|
445 | + } |
|
446 | + |
|
447 | + $files_list = null; |
|
448 | + if (!is_null($files)) { // download selected files |
|
449 | + $files_list = json_decode($files); |
|
450 | + // in case we get only a single file |
|
451 | + if ($files_list === null) { |
|
452 | + $files_list = [$files]; |
|
453 | + } |
|
454 | + } |
|
455 | + |
|
456 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
457 | + $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath()); |
|
458 | + |
|
459 | + if (!$this->validateShare($share)) { |
|
460 | + throw new NotFoundException(); |
|
461 | + } |
|
462 | + |
|
463 | + // Single file share |
|
464 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
465 | + // Single file download |
|
466 | + $this->singleFileDownloaded($share, $share->getNode()); |
|
467 | + } |
|
468 | + // Directory share |
|
469 | + else { |
|
470 | + /** @var \OCP\Files\Folder $node */ |
|
471 | + $node = $share->getNode(); |
|
472 | + |
|
473 | + // Try to get the path |
|
474 | + if ($path !== '') { |
|
475 | + try { |
|
476 | + $node = $node->get($path); |
|
477 | + } catch (NotFoundException $e) { |
|
478 | + $this->emitAccessShareHook($share, 404, 'Share not found'); |
|
479 | + return new NotFoundResponse(); |
|
480 | + } |
|
481 | + } |
|
482 | + |
|
483 | + $originalSharePath = $userFolder->getRelativePath($node->getPath()); |
|
484 | + |
|
485 | + if ($node instanceof \OCP\Files\File) { |
|
486 | + // Single file download |
|
487 | + $this->singleFileDownloaded($share, $share->getNode()); |
|
488 | + } else if (!empty($files_list)) { |
|
489 | + $this->fileListDownloaded($share, $files_list, $node); |
|
490 | + } else { |
|
491 | + // The folder is downloaded |
|
492 | + $this->singleFileDownloaded($share, $share->getNode()); |
|
493 | + } |
|
494 | + } |
|
495 | + |
|
496 | + /* FIXME: We should do this all nicely in OCP */ |
|
497 | + OC_Util::tearDownFS(); |
|
498 | + OC_Util::setupFS($share->getShareOwner()); |
|
499 | + |
|
500 | + /** |
|
501 | + * this sets a cookie to be able to recognize the start of the download |
|
502 | + * the content must not be longer than 32 characters and must only contain |
|
503 | + * alphanumeric characters |
|
504 | + */ |
|
505 | + if (!empty($downloadStartSecret) |
|
506 | + && !isset($downloadStartSecret[32]) |
|
507 | + && preg_match('!^[a-zA-Z0-9]+$!', $downloadStartSecret) === 1) { |
|
508 | + |
|
509 | + // FIXME: set on the response once we use an actual app framework response |
|
510 | + setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/'); |
|
511 | + } |
|
512 | + |
|
513 | + $this->emitAccessShareHook($share); |
|
514 | + |
|
515 | + $server_params = array( 'head' => $this->request->getMethod() == 'HEAD' ); |
|
516 | + |
|
517 | + /** |
|
518 | + * Http range requests support |
|
519 | + */ |
|
520 | + if (isset($_SERVER['HTTP_RANGE'])) { |
|
521 | + $server_params['range'] = $this->request->getHeader('Range'); |
|
522 | + } |
|
523 | + |
|
524 | + // download selected files |
|
525 | + if (!is_null($files) && $files !== '') { |
|
526 | + // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well |
|
527 | + // after dispatching the request which results in a "Cannot modify header information" notice. |
|
528 | + OC_Files::get($originalSharePath, $files_list, $server_params); |
|
529 | + exit(); |
|
530 | + } else { |
|
531 | + // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well |
|
532 | + // after dispatching the request which results in a "Cannot modify header information" notice. |
|
533 | + OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $server_params); |
|
534 | + exit(); |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * create activity for every downloaded file |
|
540 | + * |
|
541 | + * @param Share\IShare $share |
|
542 | + * @param array $files_list |
|
543 | + * @param \OCP\Files\Folder $node |
|
544 | + */ |
|
545 | + protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) { |
|
546 | + foreach ($files_list as $file) { |
|
547 | + $subNode = $node->get($file); |
|
548 | + $this->singleFileDownloaded($share, $subNode); |
|
549 | + } |
|
550 | + |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * create activity if a single file was downloaded from a link share |
|
555 | + * |
|
556 | + * @param Share\IShare $share |
|
557 | + */ |
|
558 | + protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) { |
|
559 | + |
|
560 | + $fileId = $node->getId(); |
|
561 | + |
|
562 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
563 | + $userNodeList = $userFolder->getById($fileId); |
|
564 | + $userNode = $userNodeList[0]; |
|
565 | + $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
566 | + $userPath = $userFolder->getRelativePath($userNode->getPath()); |
|
567 | + $ownerPath = $ownerFolder->getRelativePath($node->getPath()); |
|
568 | + |
|
569 | + $parameters = [$userPath]; |
|
570 | + |
|
571 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
572 | + if ($node instanceof \OCP\Files\File) { |
|
573 | + $subject = Downloads::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED; |
|
574 | + } else { |
|
575 | + $subject = Downloads::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED; |
|
576 | + } |
|
577 | + $parameters[] = $share->getSharedWith(); |
|
578 | + } else { |
|
579 | + if ($node instanceof \OCP\Files\File) { |
|
580 | + $subject = Downloads::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED; |
|
581 | + } else { |
|
582 | + $subject = Downloads::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED; |
|
583 | + } |
|
584 | + } |
|
585 | + |
|
586 | + $this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath); |
|
587 | + |
|
588 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
589 | + $parameters[0] = $ownerPath; |
|
590 | + $this->publishActivity($subject, $parameters, $share->getShareOwner(), $fileId, $ownerPath); |
|
591 | + } |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * publish activity |
|
596 | + * |
|
597 | + * @param string $subject |
|
598 | + * @param array $parameters |
|
599 | + * @param string $affectedUser |
|
600 | + * @param int $fileId |
|
601 | + * @param string $filePath |
|
602 | + */ |
|
603 | + protected function publishActivity($subject, |
|
604 | + array $parameters, |
|
605 | + $affectedUser, |
|
606 | + $fileId, |
|
607 | + $filePath) { |
|
608 | + |
|
609 | + $event = $this->activityManager->generateEvent(); |
|
610 | + $event->setApp('files_sharing') |
|
611 | + ->setType('public_links') |
|
612 | + ->setSubject($subject, $parameters) |
|
613 | + ->setAffectedUser($affectedUser) |
|
614 | + ->setObject('files', $fileId, $filePath); |
|
615 | + $this->activityManager->publish($event); |
|
616 | + } |
|
617 | 617 | |
618 | 618 | |
619 | 619 | } |