owncloud /
gallery
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Gallery |
||
| 4 | * |
||
| 5 | * This file is licensed under the Affero General Public License version 3 or |
||
| 6 | * later. See the COPYING file. |
||
| 7 | * |
||
| 8 | * @author Robin Appelman <[email protected]> |
||
| 9 | * @author Olivier Paroz <[email protected]> |
||
| 10 | * |
||
| 11 | * @copyright Robin Appelman 2012-2015 |
||
| 12 | * @copyright Olivier Paroz 2014-2016 |
||
| 13 | */ |
||
| 14 | |||
| 15 | namespace OCA\Gallery\Controller; |
||
| 16 | |||
| 17 | use OCP\IURLGenerator; |
||
| 18 | use OCP\IRequest; |
||
| 19 | use OCP\IConfig; |
||
| 20 | |||
| 21 | use OCP\AppFramework\Controller; |
||
| 22 | use OCP\AppFramework\Http; |
||
| 23 | use OCP\AppFramework\Http\TemplateResponse; |
||
| 24 | use OCP\AppFramework\Http\RedirectResponse; |
||
| 25 | |||
| 26 | use OCA\Gallery\Environment\Environment; |
||
| 27 | use OCA\Gallery\Http\ImageResponse; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Generates templates for the landing page from within ownCloud, the public |
||
| 31 | * gallery and error pages |
||
| 32 | * |
||
| 33 | * @package OCA\Gallery\Controller |
||
| 34 | */ |
||
| 35 | class PageController extends Controller { |
||
| 36 | |||
| 37 | /** @var Environment */ |
||
| 38 | private $environment; |
||
| 39 | /** @var IURLGenerator */ |
||
| 40 | private $urlGenerator; |
||
| 41 | /** @var IConfig */ |
||
| 42 | private $appConfig; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Constructor |
||
| 46 | * |
||
| 47 | * @param string $appName |
||
| 48 | * @param IRequest $request |
||
| 49 | * @param Environment $environment |
||
| 50 | * @param IURLGenerator $urlGenerator |
||
| 51 | * @param IConfig $appConfig |
||
| 52 | */ |
||
| 53 | public function __construct( |
||
| 54 | $appName, |
||
| 55 | IRequest $request, |
||
| 56 | Environment $environment, |
||
| 57 | IURLGenerator $urlGenerator, |
||
| 58 | IConfig $appConfig |
||
| 59 | ) { |
||
| 60 | parent::__construct($appName, $request); |
||
| 61 | |||
| 62 | $this->environment = $environment; |
||
| 63 | $this->urlGenerator = $urlGenerator; |
||
| 64 | $this->appConfig = $appConfig; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @NoAdminRequired |
||
| 69 | * @NoCSRFRequired |
||
| 70 | * |
||
| 71 | * Shows the albums and pictures at the root folder or a message if |
||
| 72 | * there are no pictures. |
||
| 73 | * |
||
| 74 | * This is the entry page for logged-in users accessing the app from |
||
| 75 | * within ownCloud. |
||
| 76 | * A TemplateResponse response uses a template from the templates folder |
||
| 77 | * and parameters provided here to build the page users will see |
||
| 78 | * |
||
| 79 | * @return TemplateResponse |
||
| 80 | */ |
||
| 81 | public function index() { |
||
| 82 | $appName = $this->appName; |
||
| 83 | |||
| 84 | // Parameters sent to the template |
||
| 85 | $params = $this->getIndexParameters($appName); |
||
| 86 | |||
| 87 | // Will render the page using the template found in templates/index.php |
||
| 88 | $response = new TemplateResponse($appName, 'index', $params); |
||
| 89 | $this->addContentSecurityToResponse($response); |
||
| 90 | |||
| 91 | return $response; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @PublicPage |
||
| 96 | * @NoCSRFRequired |
||
| 97 | * |
||
| 98 | * Shows the albums and pictures or redirects to the download location the token gives access to |
||
| 99 | * |
||
| 100 | * @param string $token |
||
| 101 | * @param null|string $filename |
||
| 102 | * |
||
| 103 | * @return TemplateResponse|ImageResponse|RedirectResponse |
||
|
0 ignored issues
–
show
|
|||
| 104 | */ |
||
| 105 | public function publicIndex($token, $filename) { |
||
| 106 | $node = $this->environment->getSharedNode(); |
||
| 107 | if ($node->getType() === 'dir') { |
||
| 108 | return $this->showPublicPage($token); |
||
| 109 | } else { |
||
| 110 | $url = $this->urlGenerator->linkToRoute( |
||
| 111 | $this->appName . '.files_public.download', |
||
| 112 | [ |
||
| 113 | 'token' => $token, |
||
| 114 | 'fileId' => $node->getId(), |
||
| 115 | 'filename' => $filename |
||
| 116 | ] |
||
| 117 | ); |
||
| 118 | |||
| 119 | return new RedirectResponse($url); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @PublicPage |
||
| 125 | * @NoCSRFRequired |
||
| 126 | * @Guest |
||
| 127 | * |
||
| 128 | * Generates an error page based on the error code |
||
| 129 | * |
||
| 130 | * @param int $code |
||
| 131 | * |
||
| 132 | * @return TemplateResponse |
||
| 133 | */ |
||
| 134 | public function errorPage($code) { |
||
| 135 | $appName = $this->appName; |
||
| 136 | $message = $this->request->getCookie('galleryErrorMessage'); |
||
| 137 | $params = [ |
||
| 138 | 'appName' => $appName, |
||
| 139 | 'message' => $message, |
||
| 140 | 'code' => $code, |
||
| 141 | ]; |
||
| 142 | |||
| 143 | $errorTemplate = new TemplateResponse($appName, 'index', $params, 'guest'); |
||
| 144 | $errorTemplate->setStatus($code); |
||
| 145 | $errorTemplate->invalidateCookie('galleryErrorMessage'); |
||
| 146 | |||
| 147 | return $errorTemplate; |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Adds the domain "data:" to the allowed image domains |
||
| 152 | * this function is called by reference |
||
| 153 | * |
||
| 154 | * @param TemplateResponse $response |
||
| 155 | */ |
||
| 156 | private function addContentSecurityToResponse($response) { |
||
| 157 | $csp = new Http\ContentSecurityPolicy(); |
||
| 158 | $csp->addAllowedFontDomain("data:"); |
||
| 159 | $response->setContentSecurityPolicy($csp); |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @PublicPage |
||
| 164 | * @NoCSRFRequired |
||
| 165 | * @Guest |
||
| 166 | * |
||
| 167 | * Returns the slideshow template |
||
| 168 | * |
||
| 169 | * @return TemplateResponse |
||
| 170 | */ |
||
| 171 | public function slideshow() { |
||
| 172 | return new TemplateResponse($this->appName, 'slideshow', [], 'blank'); |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Returns the parameters to be used in the index function |
||
| 177 | * |
||
| 178 | * @param $appName |
||
| 179 | * |
||
| 180 | * @return array<string,string> |
||
| 181 | */ |
||
| 182 | private function getIndexParameters($appName) { |
||
| 183 | |||
| 184 | // Parameters sent to the index function |
||
| 185 | $params = [ |
||
| 186 | 'appName' => $appName, |
||
| 187 | 'uploadUrl' => $this->urlGenerator->linkTo( |
||
| 188 | 'files', 'ajax/upload.php' |
||
| 189 | ), |
||
| 190 | 'publicUploadEnabled' => $this->appConfig->getAppValue( |
||
| 191 | 'core', 'shareapi_allow_public_upload', 'yes' |
||
| 192 | ), |
||
| 193 | 'mailNotificationEnabled' => $this->appConfig->getAppValue( |
||
| 194 | 'core', 'shareapi_allow_mail_notification', 'no' |
||
| 195 | ), |
||
| 196 | 'mailPublicNotificationEnabled' => $this->appConfig->getAppValue( |
||
| 197 | 'core', 'shareapi_allow_public_notification', 'no' |
||
| 198 | ) |
||
| 199 | ]; |
||
| 200 | |||
| 201 | return $params; |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Shows the albums and pictures the token gives access to |
||
| 206 | * |
||
| 207 | * @param $token |
||
| 208 | * |
||
| 209 | * @return TemplateResponse |
||
| 210 | */ |
||
| 211 | private function showPublicPage($token) { |
||
| 212 | $albumName = $this->environment->getSharedFolderName(); |
||
| 213 | list($server2ServerSharing, $protected) = $this->getServer2ServerProperties(); |
||
| 214 | |||
| 215 | // Parameters sent to the template |
||
| 216 | $params = [ |
||
| 217 | 'appName' => $this->appName, |
||
| 218 | 'token' => $token, |
||
| 219 | 'displayName' => $this->environment->getDisplayName(), |
||
| 220 | 'albumName' => $albumName, |
||
| 221 | 'server2ServerSharing' => $server2ServerSharing, |
||
| 222 | 'protected' => $protected, |
||
| 223 | 'filename' => $albumName |
||
| 224 | ]; |
||
| 225 | |||
| 226 | // Will render the page using the template found in templates/public.php |
||
| 227 | $response = new TemplateResponse($this->appName, 'public', $params, 'public'); |
||
| 228 | $this->addContentSecurityToResponse($response); |
||
| 229 | |||
| 230 | return $response; |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Determines if we can add external shared to this instance |
||
| 235 | * |
||
| 236 | * @return array<bool,string> |
||
|
0 ignored issues
–
show
|
|||
| 237 | */ |
||
| 238 | private function getServer2ServerProperties() { |
||
| 239 | $server2ServerSharing = $this->appConfig->getAppValue( |
||
| 240 | 'files_sharing', 'outgoing_server2server_share_enabled', 'yes' |
||
| 241 | ); |
||
| 242 | $server2ServerSharing = ($server2ServerSharing === 'yes') ? true : false; |
||
| 243 | $password = $this->environment->getSharePassword(); |
||
| 244 | $passwordProtected = ($password) ? 'true' : 'false'; |
||
| 245 | |||
| 246 | return [$server2ServerSharing, $passwordProtected]; |
||
| 247 | } |
||
| 248 | } |
||
| 249 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.