| 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\TemplateManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use OCA\Richdocuments\TokenManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use OCP\AppFramework\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use OCP\AppFramework\Db\DoesNotExistException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | use OCP\AppFramework\Http; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | use OCP\AppFramework\Http\ContentSecurityPolicy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | use OCP\AppFramework\Http\JSONResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | use OCP\AppFramework\Http\TemplateResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use OCP\Files\IRootFolder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | use OCP\Files\Node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | use OCP\IConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | use OCP\IRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | class DirectViewController extends Controller { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	/** @var IRootFolder */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	private $rootFolder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	/** @var TokenManager */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	private $tokenManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	/** @var DirectMapper */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	private $directMapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	/** @var IConfig */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	private $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	/** @var AppConfig */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	private $appConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	/** @var TemplateManager */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	private $templateManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	public function __construct($appName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 								IRequest $request, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 								IRootFolder $rootFolder, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 								TokenManager $tokenManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 								DirectMapper $directMapper, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 								IConfig $config, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 								AppConfig $appConfig, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 								TemplateManager $templateManager) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		parent::__construct($appName, $request); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$this->rootFolder = $rootFolder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$this->tokenManager = $tokenManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		$this->directMapper = $directMapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		$this->config = $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		$this->appConfig = $appConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		$this->templateManager = $templateManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	 * @NoAdminRequired | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	 * @NoCSRFRequired | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	 * @PublicPage | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	 * @param string $token | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 83 |  |  | 	 */ | 
            
                                                        
            
                                    
            
            
                | 84 |  |  | 	public function show($token) { | 
            
                                                        
            
                                    
            
            
                | 85 |  |  | 		try { | 
            
                                                        
            
                                    
            
            
                | 86 |  |  | 			$direct = $this->directMapper->getByToken($token); | 
            
                                                        
            
                                    
            
            
                | 87 |  |  | 		} catch (DoesNotExistException $e) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 88 |  |  | 			//TODO show 404 | 
            
                                                        
            
                                    
            
            
                | 89 |  |  | 			return new JSONResponse([], Http::STATUS_NOT_FOUND); | 
            
                                                        
            
                                    
            
            
                | 90 |  |  | 		} | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 92 |  |  | 		// Delete the token. They are for 1 time use only | 
            
                                                        
            
                                    
            
            
                | 93 |  |  | 		$this->directMapper->delete($direct); | 
            
                                                        
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 95 |  |  | 		$folder = $this->rootFolder->getUserFolder($direct->getUid()); | 
            
                                                        
            
                                    
            
            
                | 96 |  |  | 		if ($this->templateManager->isTemplate($direct->getFileid())) { | 
            
                                                        
            
                                    
            
            
                | 97 |  |  | 			$item = $this->templateManager->get($direct->getFileid()); | 
            
                                                        
            
                                    
            
            
                | 98 |  |  | 			if ($direct->getTemplateDestination() === 0 || $direct->getTemplateDestination() === null) { | 
            
                                                        
            
                                    
            
            
                | 99 |  |  | 				return new JSONResponse([], Http::STATUS_BAD_REQUEST); | 
            
                                                        
            
                                    
            
            
                | 100 |  |  | 			} | 
            
                                                        
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 102 |  |  | 			try { | 
            
                                                        
            
                                    
            
            
                | 103 |  |  | 				list($urlSrc, $token) = $this->tokenManager->getTokenForTemplate($item, $direct->getUid(), $direct->getTemplateDestination()); | 
            
                                                        
            
                                    
            
            
                | 104 |  |  | 			} catch (\Exception $e) { | 
            
                                                        
            
                                    
            
            
                | 105 |  |  | 				return new JSONResponse([], Http::STATUS_BAD_REQUEST); | 
            
                                                        
            
                                    
            
            
                | 106 |  |  | 			} | 
            
                                                        
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 108 |  |  | 			$relativePath = '/new.odt'; | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 110 |  |  | 		} else { | 
            
                                                        
            
                                    
            
            
                | 111 |  |  | 			try { | 
            
                                                        
            
                                    
            
            
                | 112 |  |  | 				$item = $folder->getById($direct->getFileid())[0]; | 
            
                                                        
            
                                    
            
            
                | 113 |  |  | 				if(!($item instanceof Node)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 114 |  |  | 					throw new \Exception(); | 
            
                                                        
            
                                    
            
            
                | 115 |  |  | 				} | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 117 |  |  | 				list($urlSrc, $token) = $this->tokenManager->getToken($item->getId(), null, $direct->getUid()); | 
            
                                                        
            
                                    
            
            
                | 118 |  |  | 			} catch (\Exception $e) { | 
            
                                                        
            
                                    
            
            
                | 119 |  |  | 				return new JSONResponse([], Http::STATUS_BAD_REQUEST); | 
            
                                                        
            
                                    
            
            
                | 120 |  |  | 			} | 
            
                                                        
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 122 |  |  | 			$relativePath = $folder->getRelativePath($item->getPath()); | 
            
                                                        
            
                                    
            
            
                | 123 |  |  | 		} | 
            
                                                        
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 125 |  |  | 		try { | 
            
                                                        
            
                                    
            
            
                | 126 |  |  | 			$params = [ | 
            
                                                        
            
                                    
            
            
                | 127 |  |  | 				'permissions' => $item->getPermissions(), | 
            
                                                        
            
                                    
            
            
                | 128 |  |  | 				'title' => $item->getName(), | 
            
                                                        
            
                                    
            
            
                | 129 |  |  | 				'fileId' => $item->getId() . '_' . $this->config->getSystemValue('instanceid'), | 
            
                                                        
            
                                    
            
            
                | 130 |  |  | 				'token' => $token, | 
            
                                                        
            
                                    
            
            
                | 131 |  |  | 				'urlsrc' => $urlSrc, | 
            
                                                        
            
                                    
            
            
                | 132 |  |  | 				'path' => $relativePath, | 
            
                                                        
            
                                    
            
            
                | 133 |  |  | 				'instanceId' => $this->config->getSystemValue('instanceid'), | 
            
                                                        
            
                                    
            
            
                | 134 |  |  | 				'canonical_webroot' => $this->appConfig->getAppValue('canonical_webroot'), | 
            
                                                        
            
                                    
            
            
                | 135 |  |  | 				'direct' => true, | 
            
                                                        
            
                                    
            
            
                | 136 |  |  | 			]; | 
            
                                                        
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 138 |  |  | 			$response = new TemplateResponse('richdocuments', 'documents', $params, 'empty'); | 
            
                                                        
            
                                    
            
            
                | 139 |  |  | 			$policy = new ContentSecurityPolicy(); | 
            
                                                        
            
                                    
            
            
                | 140 |  |  | 			$policy->allowInlineScript(true); | 
            
                                                        
            
                                    
            
            
                | 141 |  |  | 			$policy->addAllowedFrameDomain($this->appConfig->getAppValue('wopi_url')); | 
            
                                                        
            
                                    
            
            
                | 142 |  |  | 			$response->setContentSecurityPolicy($policy); | 
            
                                                        
            
                                    
            
            
                | 143 |  |  | 			return $response; | 
            
                                                        
            
                                    
            
            
                | 144 |  |  | 		} catch (\Exception $e) { | 
            
                                                        
            
                                    
            
            
                | 145 |  |  | 			return new JSONResponse([], Http::STATUS_BAD_REQUEST); | 
            
                                                        
            
                                    
            
            
                | 146 |  |  | 		} | 
            
                                                        
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 148 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 149 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 150 |  |  |  | 
            
                        
Scrutinizer analyzes your
composer.json/composer.lockfile 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.