@@ -40,13 +40,13 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | class Application extends App { |
| 42 | 42 | |
| 43 | - public function __construct() { |
|
| 44 | - parent::__construct('core'); |
|
| 43 | + public function __construct() { |
|
| 44 | + parent::__construct('core'); |
|
| 45 | 45 | |
| 46 | - $container = $this->getContainer(); |
|
| 46 | + $container = $this->getContainer(); |
|
| 47 | 47 | |
| 48 | - $container->registerService('defaultMailAddress', function () { |
|
| 49 | - return Util::getDefaultEmailAddress('lostpassword-noreply'); |
|
| 50 | - }); |
|
| 51 | - } |
|
| 48 | + $container->registerService('defaultMailAddress', function () { |
|
| 49 | + return Util::getDefaultEmailAddress('lostpassword-noreply'); |
|
| 50 | + }); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | |
| 46 | 46 | $container = $this->getContainer(); |
| 47 | 47 | |
| 48 | - $container->registerService('defaultMailAddress', function () { |
|
| 48 | + $container->registerService('defaultMailAddress', function() { |
|
| 49 | 49 | return Util::getDefaultEmailAddress('lostpassword-noreply'); |
| 50 | 50 | }); |
| 51 | 51 | } |
@@ -35,74 +35,74 @@ |
||
| 35 | 35 | |
| 36 | 36 | class CssController extends Controller { |
| 37 | 37 | |
| 38 | - /** @var IAppData */ |
|
| 39 | - protected $appData; |
|
| 38 | + /** @var IAppData */ |
|
| 39 | + protected $appData; |
|
| 40 | 40 | |
| 41 | - /** @var ITimeFactory */ |
|
| 42 | - protected $timeFactory; |
|
| 41 | + /** @var ITimeFactory */ |
|
| 42 | + protected $timeFactory; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param string $appName |
|
| 46 | - * @param IRequest $request |
|
| 47 | - * @param Factory $appDataFactory |
|
| 48 | - * @param ITimeFactory $timeFactory |
|
| 49 | - */ |
|
| 50 | - public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) { |
|
| 51 | - parent::__construct($appName, $request); |
|
| 44 | + /** |
|
| 45 | + * @param string $appName |
|
| 46 | + * @param IRequest $request |
|
| 47 | + * @param Factory $appDataFactory |
|
| 48 | + * @param ITimeFactory $timeFactory |
|
| 49 | + */ |
|
| 50 | + public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) { |
|
| 51 | + parent::__construct($appName, $request); |
|
| 52 | 52 | |
| 53 | - $this->appData = $appDataFactory->get('css'); |
|
| 54 | - $this->timeFactory = $timeFactory; |
|
| 55 | - } |
|
| 53 | + $this->appData = $appDataFactory->get('css'); |
|
| 54 | + $this->timeFactory = $timeFactory; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @PublicPage |
|
| 59 | - * @NoCSRFRequired |
|
| 60 | - * |
|
| 61 | - * @param string $fileName css filename with extension |
|
| 62 | - * @param string $appName css folder name |
|
| 63 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 64 | - */ |
|
| 65 | - public function getCss($fileName, $appName) { |
|
| 66 | - try { |
|
| 67 | - $folder = $this->appData->getFolder($appName); |
|
| 68 | - $gzip = false; |
|
| 69 | - $file = $this->getFile($folder, $fileName, $gzip); |
|
| 70 | - } catch(NotFoundException $e) { |
|
| 71 | - return new NotFoundResponse(); |
|
| 72 | - } |
|
| 57 | + /** |
|
| 58 | + * @PublicPage |
|
| 59 | + * @NoCSRFRequired |
|
| 60 | + * |
|
| 61 | + * @param string $fileName css filename with extension |
|
| 62 | + * @param string $appName css folder name |
|
| 63 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 64 | + */ |
|
| 65 | + public function getCss($fileName, $appName) { |
|
| 66 | + try { |
|
| 67 | + $folder = $this->appData->getFolder($appName); |
|
| 68 | + $gzip = false; |
|
| 69 | + $file = $this->getFile($folder, $fileName, $gzip); |
|
| 70 | + } catch(NotFoundException $e) { |
|
| 71 | + return new NotFoundResponse(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 75 | - if ($gzip) { |
|
| 76 | - $response->addHeader('Content-Encoding', 'gzip'); |
|
| 77 | - } |
|
| 78 | - $response->cacheFor(86400); |
|
| 79 | - $expires = new \DateTime(); |
|
| 80 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 81 | - $expires->add(new \DateInterval('PT24H')); |
|
| 82 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 83 | - $response->addHeader('Pragma', 'cache'); |
|
| 84 | - return $response; |
|
| 85 | - } |
|
| 74 | + $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 75 | + if ($gzip) { |
|
| 76 | + $response->addHeader('Content-Encoding', 'gzip'); |
|
| 77 | + } |
|
| 78 | + $response->cacheFor(86400); |
|
| 79 | + $expires = new \DateTime(); |
|
| 80 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 81 | + $expires->add(new \DateInterval('PT24H')); |
|
| 82 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 83 | + $response->addHeader('Pragma', 'cache'); |
|
| 84 | + return $response; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @param ISimpleFolder $folder |
|
| 89 | - * @param string $fileName |
|
| 90 | - * @param bool $gzip is set to true if we use the gzip file |
|
| 91 | - * @return ISimpleFile |
|
| 92 | - */ |
|
| 93 | - private function getFile(ISimpleFolder $folder, $fileName, &$gzip) { |
|
| 94 | - $encoding = $this->request->getHeader('Accept-Encoding'); |
|
| 87 | + /** |
|
| 88 | + * @param ISimpleFolder $folder |
|
| 89 | + * @param string $fileName |
|
| 90 | + * @param bool $gzip is set to true if we use the gzip file |
|
| 91 | + * @return ISimpleFile |
|
| 92 | + */ |
|
| 93 | + private function getFile(ISimpleFolder $folder, $fileName, &$gzip) { |
|
| 94 | + $encoding = $this->request->getHeader('Accept-Encoding'); |
|
| 95 | 95 | |
| 96 | - if ($encoding !== null && strpos($encoding, 'gzip') !== false) { |
|
| 97 | - try { |
|
| 98 | - $gzip = true; |
|
| 99 | - return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz |
|
| 100 | - } catch (NotFoundException $e) { |
|
| 101 | - // continue |
|
| 102 | - } |
|
| 103 | - } |
|
| 96 | + if ($encoding !== null && strpos($encoding, 'gzip') !== false) { |
|
| 97 | + try { |
|
| 98 | + $gzip = true; |
|
| 99 | + return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz |
|
| 100 | + } catch (NotFoundException $e) { |
|
| 101 | + // continue |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - $gzip = false; |
|
| 106 | - return $folder->getFile($fileName); |
|
| 107 | - } |
|
| 105 | + $gzip = false; |
|
| 106 | + return $folder->getFile($fileName); |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -36,74 +36,74 @@ |
||
| 36 | 36 | |
| 37 | 37 | class JsController extends Controller { |
| 38 | 38 | |
| 39 | - /** @var IAppData */ |
|
| 40 | - protected $appData; |
|
| 39 | + /** @var IAppData */ |
|
| 40 | + protected $appData; |
|
| 41 | 41 | |
| 42 | - /** @var ITimeFactory */ |
|
| 43 | - protected $timeFactory; |
|
| 42 | + /** @var ITimeFactory */ |
|
| 43 | + protected $timeFactory; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param string $appName |
|
| 47 | - * @param IRequest $request |
|
| 48 | - * @param Factory $appDataFactory |
|
| 49 | - * @param ITimeFactory $timeFactory |
|
| 50 | - */ |
|
| 51 | - public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) { |
|
| 52 | - parent::__construct($appName, $request); |
|
| 45 | + /** |
|
| 46 | + * @param string $appName |
|
| 47 | + * @param IRequest $request |
|
| 48 | + * @param Factory $appDataFactory |
|
| 49 | + * @param ITimeFactory $timeFactory |
|
| 50 | + */ |
|
| 51 | + public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) { |
|
| 52 | + parent::__construct($appName, $request); |
|
| 53 | 53 | |
| 54 | - $this->appData = $appDataFactory->get('js'); |
|
| 55 | - $this->timeFactory = $timeFactory; |
|
| 56 | - } |
|
| 54 | + $this->appData = $appDataFactory->get('js'); |
|
| 55 | + $this->timeFactory = $timeFactory; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @PublicPage |
|
| 60 | - * @NoCSRFRequired |
|
| 61 | - * |
|
| 62 | - * @param string $fileName css filename with extension |
|
| 63 | - * @param string $appName css folder name |
|
| 64 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 65 | - */ |
|
| 66 | - public function getJs($fileName, $appName) { |
|
| 67 | - try { |
|
| 68 | - $folder = $this->appData->getFolder($appName); |
|
| 69 | - $gzip = false; |
|
| 70 | - $file = $this->getFile($folder, $fileName, $gzip); |
|
| 71 | - } catch(NotFoundException $e) { |
|
| 72 | - return new NotFoundResponse(); |
|
| 73 | - } |
|
| 58 | + /** |
|
| 59 | + * @PublicPage |
|
| 60 | + * @NoCSRFRequired |
|
| 61 | + * |
|
| 62 | + * @param string $fileName css filename with extension |
|
| 63 | + * @param string $appName css folder name |
|
| 64 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 65 | + */ |
|
| 66 | + public function getJs($fileName, $appName) { |
|
| 67 | + try { |
|
| 68 | + $folder = $this->appData->getFolder($appName); |
|
| 69 | + $gzip = false; |
|
| 70 | + $file = $this->getFile($folder, $fileName, $gzip); |
|
| 71 | + } catch(NotFoundException $e) { |
|
| 72 | + return new NotFoundResponse(); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']); |
|
| 76 | - if ($gzip) { |
|
| 77 | - $response->addHeader('Content-Encoding', 'gzip'); |
|
| 78 | - } |
|
| 79 | - $response->cacheFor(86400); |
|
| 80 | - $expires = new \DateTime(); |
|
| 81 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 82 | - $expires->add(new \DateInterval('PT24H')); |
|
| 83 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 84 | - $response->addHeader('Pragma', 'cache'); |
|
| 85 | - return $response; |
|
| 86 | - } |
|
| 75 | + $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']); |
|
| 76 | + if ($gzip) { |
|
| 77 | + $response->addHeader('Content-Encoding', 'gzip'); |
|
| 78 | + } |
|
| 79 | + $response->cacheFor(86400); |
|
| 80 | + $expires = new \DateTime(); |
|
| 81 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 82 | + $expires->add(new \DateInterval('PT24H')); |
|
| 83 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 84 | + $response->addHeader('Pragma', 'cache'); |
|
| 85 | + return $response; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @param ISimpleFolder $folder |
|
| 90 | - * @param string $fileName |
|
| 91 | - * @param bool $gzip is set to true if we use the gzip file |
|
| 92 | - * @return ISimpleFile |
|
| 93 | - */ |
|
| 94 | - private function getFile(ISimpleFolder $folder, $fileName, &$gzip) { |
|
| 95 | - $encoding = $this->request->getHeader('Accept-Encoding'); |
|
| 88 | + /** |
|
| 89 | + * @param ISimpleFolder $folder |
|
| 90 | + * @param string $fileName |
|
| 91 | + * @param bool $gzip is set to true if we use the gzip file |
|
| 92 | + * @return ISimpleFile |
|
| 93 | + */ |
|
| 94 | + private function getFile(ISimpleFolder $folder, $fileName, &$gzip) { |
|
| 95 | + $encoding = $this->request->getHeader('Accept-Encoding'); |
|
| 96 | 96 | |
| 97 | - if ($encoding !== null && strpos($encoding, 'gzip') !== false) { |
|
| 98 | - try { |
|
| 99 | - $gzip = true; |
|
| 100 | - return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz |
|
| 101 | - } catch (NotFoundException $e) { |
|
| 102 | - // continue |
|
| 103 | - } |
|
| 104 | - } |
|
| 97 | + if ($encoding !== null && strpos($encoding, 'gzip') !== false) { |
|
| 98 | + try { |
|
| 99 | + $gzip = true; |
|
| 100 | + return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz |
|
| 101 | + } catch (NotFoundException $e) { |
|
| 102 | + // continue |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - $gzip = false; |
|
| 107 | - return $folder->getFile($fileName); |
|
| 108 | - } |
|
| 106 | + $gzip = false; |
|
| 107 | + return $folder->getFile($fileName); |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -62,376 +62,376 @@ |
||
| 62 | 62 | |
| 63 | 63 | class DIContainer extends SimpleContainer implements IAppContainer { |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var array |
|
| 67 | - */ |
|
| 68 | - private $middleWares = array(); |
|
| 69 | - |
|
| 70 | - /** @var ServerContainer */ |
|
| 71 | - private $server; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Put your class dependencies in here |
|
| 75 | - * @param string $appName the name of the app |
|
| 76 | - * @param array $urlParams |
|
| 77 | - * @param ServerContainer $server |
|
| 78 | - */ |
|
| 79 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 80 | - parent::__construct(); |
|
| 81 | - $this['AppName'] = $appName; |
|
| 82 | - $this['urlParams'] = $urlParams; |
|
| 83 | - |
|
| 84 | - /** @var \OC\ServerContainer $server */ |
|
| 85 | - if ($server === null) { |
|
| 86 | - $server = \OC::$server; |
|
| 87 | - } |
|
| 88 | - $this->server = $server; |
|
| 89 | - $this->server->registerAppContainer($appName, $this); |
|
| 90 | - |
|
| 91 | - // aliases |
|
| 92 | - $this->registerAlias('appName', 'AppName'); |
|
| 93 | - $this->registerAlias('webRoot', 'WebRoot'); |
|
| 94 | - $this->registerAlias('userId', 'UserId'); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Core services |
|
| 98 | - */ |
|
| 99 | - $this->registerService(IOutput::class, function($c){ |
|
| 100 | - return new Output($this->getServer()->getWebRoot()); |
|
| 101 | - }); |
|
| 102 | - |
|
| 103 | - $this->registerService(Folder::class, function() { |
|
| 104 | - return $this->getServer()->getUserFolder(); |
|
| 105 | - }); |
|
| 106 | - |
|
| 107 | - $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 108 | - return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 109 | - }); |
|
| 110 | - |
|
| 111 | - $this->registerService(IL10N::class, function($c) { |
|
| 112 | - return $this->getServer()->getL10N($c->query('AppName')); |
|
| 113 | - }); |
|
| 114 | - |
|
| 115 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 116 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 117 | - |
|
| 118 | - $this->registerService(IRequest::class, function() { |
|
| 119 | - return $this->getServer()->query(IRequest::class); |
|
| 120 | - }); |
|
| 121 | - $this->registerAlias('Request', IRequest::class); |
|
| 122 | - |
|
| 123 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 124 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 125 | - |
|
| 126 | - $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
|
| 127 | - |
|
| 128 | - $this->registerService(IServerContainer::class, function ($c) { |
|
| 129 | - return $this->getServer(); |
|
| 130 | - }); |
|
| 131 | - $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 132 | - |
|
| 133 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 134 | - return $c->query('OCA\WorkflowEngine\Manager'); |
|
| 135 | - }); |
|
| 136 | - |
|
| 137 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 138 | - return $c; |
|
| 139 | - }); |
|
| 140 | - |
|
| 141 | - // commonly used attributes |
|
| 142 | - $this->registerService('UserId', function ($c) { |
|
| 143 | - return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
|
| 144 | - }); |
|
| 145 | - |
|
| 146 | - $this->registerService('WebRoot', function ($c) { |
|
| 147 | - return $c->query('ServerContainer')->getWebRoot(); |
|
| 148 | - }); |
|
| 149 | - |
|
| 150 | - $this->registerService('fromMailAddress', function() { |
|
| 151 | - return Util::getDefaultEmailAddress('no-reply'); |
|
| 152 | - }); |
|
| 153 | - |
|
| 154 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 155 | - return $c->getServer()->getThemingDefaults(); |
|
| 156 | - }); |
|
| 157 | - |
|
| 158 | - $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 159 | - return $this->getServer()->getEncryptionManager(); |
|
| 160 | - }); |
|
| 161 | - |
|
| 162 | - $this->registerService(IValidator::class, function($c) { |
|
| 163 | - return $c->query(Validator::class); |
|
| 164 | - }); |
|
| 165 | - |
|
| 166 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 167 | - return new \OC\Security\IdentityProof\Manager( |
|
| 168 | - $this->getServer()->query(\OC\Files\AppData\Factory::class), |
|
| 169 | - $this->getServer()->getCrypto() |
|
| 170 | - ); |
|
| 171 | - }); |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * App Framework APIs |
|
| 175 | - */ |
|
| 176 | - $this->registerService('API', function($c){ |
|
| 177 | - $c->query('OCP\\ILogger')->debug( |
|
| 178 | - 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 179 | - 'services instead!' |
|
| 180 | - ); |
|
| 181 | - return new API($c['AppName']); |
|
| 182 | - }); |
|
| 183 | - |
|
| 184 | - $this->registerService('Protocol', function($c){ |
|
| 185 | - /** @var \OC\Server $server */ |
|
| 186 | - $server = $c->query('ServerContainer'); |
|
| 187 | - $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 188 | - return new Http($_SERVER, $protocol); |
|
| 189 | - }); |
|
| 190 | - |
|
| 191 | - $this->registerService('Dispatcher', function($c) { |
|
| 192 | - return new Dispatcher( |
|
| 193 | - $c['Protocol'], |
|
| 194 | - $c['MiddlewareDispatcher'], |
|
| 195 | - $c['ControllerMethodReflector'], |
|
| 196 | - $c['Request'] |
|
| 197 | - ); |
|
| 198 | - }); |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * App Framework default arguments |
|
| 202 | - */ |
|
| 203 | - $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 204 | - $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 205 | - $this->registerParameter('corsMaxAge', 1728000); |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Middleware |
|
| 209 | - */ |
|
| 210 | - $app = $this; |
|
| 211 | - $this->registerService('SecurityMiddleware', function($c) use ($app){ |
|
| 212 | - /** @var \OC\Server $server */ |
|
| 213 | - $server = $app->getServer(); |
|
| 214 | - |
|
| 215 | - return new SecurityMiddleware( |
|
| 216 | - $c['Request'], |
|
| 217 | - $c['ControllerMethodReflector'], |
|
| 218 | - $server->getNavigationManager(), |
|
| 219 | - $server->getURLGenerator(), |
|
| 220 | - $server->getLogger(), |
|
| 221 | - $server->getSession(), |
|
| 222 | - $c['AppName'], |
|
| 223 | - $app->isLoggedIn(), |
|
| 224 | - $app->isAdminUser(), |
|
| 225 | - $server->getContentSecurityPolicyManager(), |
|
| 226 | - $server->getCsrfTokenManager(), |
|
| 227 | - $server->getContentSecurityPolicyNonceManager() |
|
| 228 | - ); |
|
| 229 | - |
|
| 230 | - }); |
|
| 231 | - |
|
| 232 | - $this->registerService('BruteForceMiddleware', function($c) use ($app) { |
|
| 233 | - /** @var \OC\Server $server */ |
|
| 234 | - $server = $app->getServer(); |
|
| 235 | - |
|
| 236 | - return new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 237 | - $c['ControllerMethodReflector'], |
|
| 238 | - $server->getBruteForceThrottler(), |
|
| 239 | - $server->getRequest() |
|
| 240 | - ); |
|
| 241 | - }); |
|
| 242 | - |
|
| 243 | - $this->registerService('RateLimitingMiddleware', function($c) use ($app) { |
|
| 244 | - /** @var \OC\Server $server */ |
|
| 245 | - $server = $app->getServer(); |
|
| 246 | - |
|
| 247 | - return new RateLimitingMiddleware( |
|
| 248 | - $server->getRequest(), |
|
| 249 | - $server->getUserSession(), |
|
| 250 | - $c['ControllerMethodReflector'], |
|
| 251 | - $c->query(OC\Security\RateLimiting\Limiter::class) |
|
| 252 | - ); |
|
| 253 | - }); |
|
| 254 | - |
|
| 255 | - $this->registerService('CORSMiddleware', function($c) { |
|
| 256 | - return new CORSMiddleware( |
|
| 257 | - $c['Request'], |
|
| 258 | - $c['ControllerMethodReflector'], |
|
| 259 | - $c->query(IUserSession::class), |
|
| 260 | - $c->getServer()->getBruteForceThrottler() |
|
| 261 | - ); |
|
| 262 | - }); |
|
| 263 | - |
|
| 264 | - $this->registerService('SessionMiddleware', function($c) use ($app) { |
|
| 265 | - return new SessionMiddleware( |
|
| 266 | - $c['Request'], |
|
| 267 | - $c['ControllerMethodReflector'], |
|
| 268 | - $app->getServer()->getSession() |
|
| 269 | - ); |
|
| 270 | - }); |
|
| 271 | - |
|
| 272 | - $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 273 | - $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
|
| 274 | - $userSession = $app->getServer()->getUserSession(); |
|
| 275 | - $session = $app->getServer()->getSession(); |
|
| 276 | - $urlGenerator = $app->getServer()->getURLGenerator(); |
|
| 277 | - $reflector = $c['ControllerMethodReflector']; |
|
| 278 | - $request = $app->getServer()->getRequest(); |
|
| 279 | - return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
|
| 280 | - }); |
|
| 281 | - |
|
| 282 | - $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 283 | - return new OCSMiddleware( |
|
| 284 | - $c['Request'] |
|
| 285 | - ); |
|
| 286 | - }); |
|
| 287 | - |
|
| 288 | - $middleWares = &$this->middleWares; |
|
| 289 | - $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) { |
|
| 290 | - $dispatcher = new MiddlewareDispatcher(); |
|
| 291 | - $dispatcher->registerMiddleware($c['CORSMiddleware']); |
|
| 292 | - $dispatcher->registerMiddleware($c['OCSMiddleware']); |
|
| 293 | - $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
|
| 294 | - $dispatcher->registerMiddleware($c['TwoFactorMiddleware']); |
|
| 295 | - $dispatcher->registerMiddleware($c['BruteForceMiddleware']); |
|
| 296 | - $dispatcher->registerMiddleware($c['RateLimitingMiddleware']); |
|
| 297 | - |
|
| 298 | - foreach($middleWares as $middleWare) { |
|
| 299 | - $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $dispatcher->registerMiddleware($c['SessionMiddleware']); |
|
| 303 | - return $dispatcher; |
|
| 304 | - }); |
|
| 305 | - |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * @deprecated implements only deprecated methods |
|
| 311 | - * @return IApi |
|
| 312 | - */ |
|
| 313 | - function getCoreApi() |
|
| 314 | - { |
|
| 315 | - return $this->query('API'); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @return \OCP\IServerContainer |
|
| 320 | - */ |
|
| 321 | - function getServer() |
|
| 322 | - { |
|
| 323 | - return $this->server; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @param string $middleWare |
|
| 328 | - * @return boolean|null |
|
| 329 | - */ |
|
| 330 | - function registerMiddleWare($middleWare) { |
|
| 331 | - array_push($this->middleWares, $middleWare); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * used to return the appname of the set application |
|
| 336 | - * @return string the name of your application |
|
| 337 | - */ |
|
| 338 | - function getAppName() { |
|
| 339 | - return $this->query('AppName'); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * @deprecated use IUserSession->isLoggedIn() |
|
| 344 | - * @return boolean |
|
| 345 | - */ |
|
| 346 | - function isLoggedIn() { |
|
| 347 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @deprecated use IGroupManager->isAdmin($userId) |
|
| 352 | - * @return boolean |
|
| 353 | - */ |
|
| 354 | - function isAdminUser() { |
|
| 355 | - $uid = $this->getUserId(); |
|
| 356 | - return \OC_User::isAdminUser($uid); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - private function getUserId() { |
|
| 360 | - return $this->getServer()->getSession()->get('user_id'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * @deprecated use the ILogger instead |
|
| 365 | - * @param string $message |
|
| 366 | - * @param string $level |
|
| 367 | - * @return mixed |
|
| 368 | - */ |
|
| 369 | - function log($message, $level) { |
|
| 370 | - switch($level){ |
|
| 371 | - case 'debug': |
|
| 372 | - $level = \OCP\Util::DEBUG; |
|
| 373 | - break; |
|
| 374 | - case 'info': |
|
| 375 | - $level = \OCP\Util::INFO; |
|
| 376 | - break; |
|
| 377 | - case 'warn': |
|
| 378 | - $level = \OCP\Util::WARN; |
|
| 379 | - break; |
|
| 380 | - case 'fatal': |
|
| 381 | - $level = \OCP\Util::FATAL; |
|
| 382 | - break; |
|
| 383 | - default: |
|
| 384 | - $level = \OCP\Util::ERROR; |
|
| 385 | - break; |
|
| 386 | - } |
|
| 387 | - \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Register a capability |
|
| 392 | - * |
|
| 393 | - * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 394 | - */ |
|
| 395 | - public function registerCapability($serviceName) { |
|
| 396 | - $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 397 | - return $this->query($serviceName); |
|
| 398 | - }); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * @param string $name |
|
| 403 | - * @return mixed |
|
| 404 | - * @throws QueryException if the query could not be resolved |
|
| 405 | - */ |
|
| 406 | - public function query($name) { |
|
| 407 | - try { |
|
| 408 | - return $this->queryNoFallback($name); |
|
| 409 | - } catch (QueryException $e) { |
|
| 410 | - return $this->getServer()->query($name); |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @param string $name |
|
| 416 | - * @return mixed |
|
| 417 | - * @throws QueryException if the query could not be resolved |
|
| 418 | - */ |
|
| 419 | - public function queryNoFallback($name) { |
|
| 420 | - $name = $this->sanitizeName($name); |
|
| 421 | - |
|
| 422 | - if ($this->offsetExists($name)) { |
|
| 423 | - return parent::query($name); |
|
| 424 | - } else { |
|
| 425 | - if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 426 | - return parent::query($name); |
|
| 427 | - } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 428 | - return parent::query($name); |
|
| 429 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 430 | - return parent::query($name); |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 435 | - ' Class can not be instantiated'); |
|
| 436 | - } |
|
| 65 | + /** |
|
| 66 | + * @var array |
|
| 67 | + */ |
|
| 68 | + private $middleWares = array(); |
|
| 69 | + |
|
| 70 | + /** @var ServerContainer */ |
|
| 71 | + private $server; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Put your class dependencies in here |
|
| 75 | + * @param string $appName the name of the app |
|
| 76 | + * @param array $urlParams |
|
| 77 | + * @param ServerContainer $server |
|
| 78 | + */ |
|
| 79 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 80 | + parent::__construct(); |
|
| 81 | + $this['AppName'] = $appName; |
|
| 82 | + $this['urlParams'] = $urlParams; |
|
| 83 | + |
|
| 84 | + /** @var \OC\ServerContainer $server */ |
|
| 85 | + if ($server === null) { |
|
| 86 | + $server = \OC::$server; |
|
| 87 | + } |
|
| 88 | + $this->server = $server; |
|
| 89 | + $this->server->registerAppContainer($appName, $this); |
|
| 90 | + |
|
| 91 | + // aliases |
|
| 92 | + $this->registerAlias('appName', 'AppName'); |
|
| 93 | + $this->registerAlias('webRoot', 'WebRoot'); |
|
| 94 | + $this->registerAlias('userId', 'UserId'); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Core services |
|
| 98 | + */ |
|
| 99 | + $this->registerService(IOutput::class, function($c){ |
|
| 100 | + return new Output($this->getServer()->getWebRoot()); |
|
| 101 | + }); |
|
| 102 | + |
|
| 103 | + $this->registerService(Folder::class, function() { |
|
| 104 | + return $this->getServer()->getUserFolder(); |
|
| 105 | + }); |
|
| 106 | + |
|
| 107 | + $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 108 | + return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 109 | + }); |
|
| 110 | + |
|
| 111 | + $this->registerService(IL10N::class, function($c) { |
|
| 112 | + return $this->getServer()->getL10N($c->query('AppName')); |
|
| 113 | + }); |
|
| 114 | + |
|
| 115 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 116 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 117 | + |
|
| 118 | + $this->registerService(IRequest::class, function() { |
|
| 119 | + return $this->getServer()->query(IRequest::class); |
|
| 120 | + }); |
|
| 121 | + $this->registerAlias('Request', IRequest::class); |
|
| 122 | + |
|
| 123 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 124 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 125 | + |
|
| 126 | + $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
|
| 127 | + |
|
| 128 | + $this->registerService(IServerContainer::class, function ($c) { |
|
| 129 | + return $this->getServer(); |
|
| 130 | + }); |
|
| 131 | + $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 132 | + |
|
| 133 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 134 | + return $c->query('OCA\WorkflowEngine\Manager'); |
|
| 135 | + }); |
|
| 136 | + |
|
| 137 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 138 | + return $c; |
|
| 139 | + }); |
|
| 140 | + |
|
| 141 | + // commonly used attributes |
|
| 142 | + $this->registerService('UserId', function ($c) { |
|
| 143 | + return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
|
| 144 | + }); |
|
| 145 | + |
|
| 146 | + $this->registerService('WebRoot', function ($c) { |
|
| 147 | + return $c->query('ServerContainer')->getWebRoot(); |
|
| 148 | + }); |
|
| 149 | + |
|
| 150 | + $this->registerService('fromMailAddress', function() { |
|
| 151 | + return Util::getDefaultEmailAddress('no-reply'); |
|
| 152 | + }); |
|
| 153 | + |
|
| 154 | + $this->registerService('OC_Defaults', function ($c) { |
|
| 155 | + return $c->getServer()->getThemingDefaults(); |
|
| 156 | + }); |
|
| 157 | + |
|
| 158 | + $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 159 | + return $this->getServer()->getEncryptionManager(); |
|
| 160 | + }); |
|
| 161 | + |
|
| 162 | + $this->registerService(IValidator::class, function($c) { |
|
| 163 | + return $c->query(Validator::class); |
|
| 164 | + }); |
|
| 165 | + |
|
| 166 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 167 | + return new \OC\Security\IdentityProof\Manager( |
|
| 168 | + $this->getServer()->query(\OC\Files\AppData\Factory::class), |
|
| 169 | + $this->getServer()->getCrypto() |
|
| 170 | + ); |
|
| 171 | + }); |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * App Framework APIs |
|
| 175 | + */ |
|
| 176 | + $this->registerService('API', function($c){ |
|
| 177 | + $c->query('OCP\\ILogger')->debug( |
|
| 178 | + 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 179 | + 'services instead!' |
|
| 180 | + ); |
|
| 181 | + return new API($c['AppName']); |
|
| 182 | + }); |
|
| 183 | + |
|
| 184 | + $this->registerService('Protocol', function($c){ |
|
| 185 | + /** @var \OC\Server $server */ |
|
| 186 | + $server = $c->query('ServerContainer'); |
|
| 187 | + $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 188 | + return new Http($_SERVER, $protocol); |
|
| 189 | + }); |
|
| 190 | + |
|
| 191 | + $this->registerService('Dispatcher', function($c) { |
|
| 192 | + return new Dispatcher( |
|
| 193 | + $c['Protocol'], |
|
| 194 | + $c['MiddlewareDispatcher'], |
|
| 195 | + $c['ControllerMethodReflector'], |
|
| 196 | + $c['Request'] |
|
| 197 | + ); |
|
| 198 | + }); |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * App Framework default arguments |
|
| 202 | + */ |
|
| 203 | + $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 204 | + $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 205 | + $this->registerParameter('corsMaxAge', 1728000); |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Middleware |
|
| 209 | + */ |
|
| 210 | + $app = $this; |
|
| 211 | + $this->registerService('SecurityMiddleware', function($c) use ($app){ |
|
| 212 | + /** @var \OC\Server $server */ |
|
| 213 | + $server = $app->getServer(); |
|
| 214 | + |
|
| 215 | + return new SecurityMiddleware( |
|
| 216 | + $c['Request'], |
|
| 217 | + $c['ControllerMethodReflector'], |
|
| 218 | + $server->getNavigationManager(), |
|
| 219 | + $server->getURLGenerator(), |
|
| 220 | + $server->getLogger(), |
|
| 221 | + $server->getSession(), |
|
| 222 | + $c['AppName'], |
|
| 223 | + $app->isLoggedIn(), |
|
| 224 | + $app->isAdminUser(), |
|
| 225 | + $server->getContentSecurityPolicyManager(), |
|
| 226 | + $server->getCsrfTokenManager(), |
|
| 227 | + $server->getContentSecurityPolicyNonceManager() |
|
| 228 | + ); |
|
| 229 | + |
|
| 230 | + }); |
|
| 231 | + |
|
| 232 | + $this->registerService('BruteForceMiddleware', function($c) use ($app) { |
|
| 233 | + /** @var \OC\Server $server */ |
|
| 234 | + $server = $app->getServer(); |
|
| 235 | + |
|
| 236 | + return new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 237 | + $c['ControllerMethodReflector'], |
|
| 238 | + $server->getBruteForceThrottler(), |
|
| 239 | + $server->getRequest() |
|
| 240 | + ); |
|
| 241 | + }); |
|
| 242 | + |
|
| 243 | + $this->registerService('RateLimitingMiddleware', function($c) use ($app) { |
|
| 244 | + /** @var \OC\Server $server */ |
|
| 245 | + $server = $app->getServer(); |
|
| 246 | + |
|
| 247 | + return new RateLimitingMiddleware( |
|
| 248 | + $server->getRequest(), |
|
| 249 | + $server->getUserSession(), |
|
| 250 | + $c['ControllerMethodReflector'], |
|
| 251 | + $c->query(OC\Security\RateLimiting\Limiter::class) |
|
| 252 | + ); |
|
| 253 | + }); |
|
| 254 | + |
|
| 255 | + $this->registerService('CORSMiddleware', function($c) { |
|
| 256 | + return new CORSMiddleware( |
|
| 257 | + $c['Request'], |
|
| 258 | + $c['ControllerMethodReflector'], |
|
| 259 | + $c->query(IUserSession::class), |
|
| 260 | + $c->getServer()->getBruteForceThrottler() |
|
| 261 | + ); |
|
| 262 | + }); |
|
| 263 | + |
|
| 264 | + $this->registerService('SessionMiddleware', function($c) use ($app) { |
|
| 265 | + return new SessionMiddleware( |
|
| 266 | + $c['Request'], |
|
| 267 | + $c['ControllerMethodReflector'], |
|
| 268 | + $app->getServer()->getSession() |
|
| 269 | + ); |
|
| 270 | + }); |
|
| 271 | + |
|
| 272 | + $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 273 | + $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
|
| 274 | + $userSession = $app->getServer()->getUserSession(); |
|
| 275 | + $session = $app->getServer()->getSession(); |
|
| 276 | + $urlGenerator = $app->getServer()->getURLGenerator(); |
|
| 277 | + $reflector = $c['ControllerMethodReflector']; |
|
| 278 | + $request = $app->getServer()->getRequest(); |
|
| 279 | + return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
|
| 280 | + }); |
|
| 281 | + |
|
| 282 | + $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 283 | + return new OCSMiddleware( |
|
| 284 | + $c['Request'] |
|
| 285 | + ); |
|
| 286 | + }); |
|
| 287 | + |
|
| 288 | + $middleWares = &$this->middleWares; |
|
| 289 | + $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) { |
|
| 290 | + $dispatcher = new MiddlewareDispatcher(); |
|
| 291 | + $dispatcher->registerMiddleware($c['CORSMiddleware']); |
|
| 292 | + $dispatcher->registerMiddleware($c['OCSMiddleware']); |
|
| 293 | + $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
|
| 294 | + $dispatcher->registerMiddleware($c['TwoFactorMiddleware']); |
|
| 295 | + $dispatcher->registerMiddleware($c['BruteForceMiddleware']); |
|
| 296 | + $dispatcher->registerMiddleware($c['RateLimitingMiddleware']); |
|
| 297 | + |
|
| 298 | + foreach($middleWares as $middleWare) { |
|
| 299 | + $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $dispatcher->registerMiddleware($c['SessionMiddleware']); |
|
| 303 | + return $dispatcher; |
|
| 304 | + }); |
|
| 305 | + |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * @deprecated implements only deprecated methods |
|
| 311 | + * @return IApi |
|
| 312 | + */ |
|
| 313 | + function getCoreApi() |
|
| 314 | + { |
|
| 315 | + return $this->query('API'); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @return \OCP\IServerContainer |
|
| 320 | + */ |
|
| 321 | + function getServer() |
|
| 322 | + { |
|
| 323 | + return $this->server; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @param string $middleWare |
|
| 328 | + * @return boolean|null |
|
| 329 | + */ |
|
| 330 | + function registerMiddleWare($middleWare) { |
|
| 331 | + array_push($this->middleWares, $middleWare); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * used to return the appname of the set application |
|
| 336 | + * @return string the name of your application |
|
| 337 | + */ |
|
| 338 | + function getAppName() { |
|
| 339 | + return $this->query('AppName'); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * @deprecated use IUserSession->isLoggedIn() |
|
| 344 | + * @return boolean |
|
| 345 | + */ |
|
| 346 | + function isLoggedIn() { |
|
| 347 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @deprecated use IGroupManager->isAdmin($userId) |
|
| 352 | + * @return boolean |
|
| 353 | + */ |
|
| 354 | + function isAdminUser() { |
|
| 355 | + $uid = $this->getUserId(); |
|
| 356 | + return \OC_User::isAdminUser($uid); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + private function getUserId() { |
|
| 360 | + return $this->getServer()->getSession()->get('user_id'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * @deprecated use the ILogger instead |
|
| 365 | + * @param string $message |
|
| 366 | + * @param string $level |
|
| 367 | + * @return mixed |
|
| 368 | + */ |
|
| 369 | + function log($message, $level) { |
|
| 370 | + switch($level){ |
|
| 371 | + case 'debug': |
|
| 372 | + $level = \OCP\Util::DEBUG; |
|
| 373 | + break; |
|
| 374 | + case 'info': |
|
| 375 | + $level = \OCP\Util::INFO; |
|
| 376 | + break; |
|
| 377 | + case 'warn': |
|
| 378 | + $level = \OCP\Util::WARN; |
|
| 379 | + break; |
|
| 380 | + case 'fatal': |
|
| 381 | + $level = \OCP\Util::FATAL; |
|
| 382 | + break; |
|
| 383 | + default: |
|
| 384 | + $level = \OCP\Util::ERROR; |
|
| 385 | + break; |
|
| 386 | + } |
|
| 387 | + \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Register a capability |
|
| 392 | + * |
|
| 393 | + * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 394 | + */ |
|
| 395 | + public function registerCapability($serviceName) { |
|
| 396 | + $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 397 | + return $this->query($serviceName); |
|
| 398 | + }); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * @param string $name |
|
| 403 | + * @return mixed |
|
| 404 | + * @throws QueryException if the query could not be resolved |
|
| 405 | + */ |
|
| 406 | + public function query($name) { |
|
| 407 | + try { |
|
| 408 | + return $this->queryNoFallback($name); |
|
| 409 | + } catch (QueryException $e) { |
|
| 410 | + return $this->getServer()->query($name); |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @param string $name |
|
| 416 | + * @return mixed |
|
| 417 | + * @throws QueryException if the query could not be resolved |
|
| 418 | + */ |
|
| 419 | + public function queryNoFallback($name) { |
|
| 420 | + $name = $this->sanitizeName($name); |
|
| 421 | + |
|
| 422 | + if ($this->offsetExists($name)) { |
|
| 423 | + return parent::query($name); |
|
| 424 | + } else { |
|
| 425 | + if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 426 | + return parent::query($name); |
|
| 427 | + } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 428 | + return parent::query($name); |
|
| 429 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 430 | + return parent::query($name); |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 435 | + ' Class can not be instantiated'); |
|
| 436 | + } |
|
| 437 | 437 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param array $urlParams |
| 77 | 77 | * @param ServerContainer $server |
| 78 | 78 | */ |
| 79 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 79 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null) { |
|
| 80 | 80 | parent::__construct(); |
| 81 | 81 | $this['AppName'] = $appName; |
| 82 | 82 | $this['urlParams'] = $urlParams; |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | /** |
| 97 | 97 | * Core services |
| 98 | 98 | */ |
| 99 | - $this->registerService(IOutput::class, function($c){ |
|
| 99 | + $this->registerService(IOutput::class, function($c) { |
|
| 100 | 100 | return new Output($this->getServer()->getWebRoot()); |
| 101 | 101 | }); |
| 102 | 102 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | return $this->getServer()->getUserFolder(); |
| 105 | 105 | }); |
| 106 | 106 | |
| 107 | - $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 107 | + $this->registerService(IAppData::class, function(SimpleContainer $c) { |
|
| 108 | 108 | return $this->getServer()->getAppDataDir($c->query('AppName')); |
| 109 | 109 | }); |
| 110 | 110 | |
@@ -125,25 +125,25 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
| 127 | 127 | |
| 128 | - $this->registerService(IServerContainer::class, function ($c) { |
|
| 128 | + $this->registerService(IServerContainer::class, function($c) { |
|
| 129 | 129 | return $this->getServer(); |
| 130 | 130 | }); |
| 131 | 131 | $this->registerAlias('ServerContainer', IServerContainer::class); |
| 132 | 132 | |
| 133 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 133 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function($c) { |
|
| 134 | 134 | return $c->query('OCA\WorkflowEngine\Manager'); |
| 135 | 135 | }); |
| 136 | 136 | |
| 137 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 137 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function($c) { |
|
| 138 | 138 | return $c; |
| 139 | 139 | }); |
| 140 | 140 | |
| 141 | 141 | // commonly used attributes |
| 142 | - $this->registerService('UserId', function ($c) { |
|
| 142 | + $this->registerService('UserId', function($c) { |
|
| 143 | 143 | return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
| 144 | 144 | }); |
| 145 | 145 | |
| 146 | - $this->registerService('WebRoot', function ($c) { |
|
| 146 | + $this->registerService('WebRoot', function($c) { |
|
| 147 | 147 | return $c->query('ServerContainer')->getWebRoot(); |
| 148 | 148 | }); |
| 149 | 149 | |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | return Util::getDefaultEmailAddress('no-reply'); |
| 152 | 152 | }); |
| 153 | 153 | |
| 154 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 154 | + $this->registerService('OC_Defaults', function($c) { |
|
| 155 | 155 | return $c->getServer()->getThemingDefaults(); |
| 156 | 156 | }); |
| 157 | 157 | |
| 158 | - $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 158 | + $this->registerService('OCP\Encryption\IManager', function($c) { |
|
| 159 | 159 | return $this->getServer()->getEncryptionManager(); |
| 160 | 160 | }); |
| 161 | 161 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | return $c->query(Validator::class); |
| 164 | 164 | }); |
| 165 | 165 | |
| 166 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 166 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function($c) { |
|
| 167 | 167 | return new \OC\Security\IdentityProof\Manager( |
| 168 | 168 | $this->getServer()->query(\OC\Files\AppData\Factory::class), |
| 169 | 169 | $this->getServer()->getCrypto() |
@@ -173,15 +173,15 @@ discard block |
||
| 173 | 173 | /** |
| 174 | 174 | * App Framework APIs |
| 175 | 175 | */ |
| 176 | - $this->registerService('API', function($c){ |
|
| 176 | + $this->registerService('API', function($c) { |
|
| 177 | 177 | $c->query('OCP\\ILogger')->debug( |
| 178 | - 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 178 | + 'Accessing the API class is deprecated! Use the appropriate '. |
|
| 179 | 179 | 'services instead!' |
| 180 | 180 | ); |
| 181 | 181 | return new API($c['AppName']); |
| 182 | 182 | }); |
| 183 | 183 | |
| 184 | - $this->registerService('Protocol', function($c){ |
|
| 184 | + $this->registerService('Protocol', function($c) { |
|
| 185 | 185 | /** @var \OC\Server $server */ |
| 186 | 186 | $server = $c->query('ServerContainer'); |
| 187 | 187 | $protocol = $server->getRequest()->getHttpProtocol(); |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | ); |
| 270 | 270 | }); |
| 271 | 271 | |
| 272 | - $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 272 | + $this->registerService('TwoFactorMiddleware', function(SimpleContainer $c) use ($app) { |
|
| 273 | 273 | $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
| 274 | 274 | $userSession = $app->getServer()->getUserSession(); |
| 275 | 275 | $session = $app->getServer()->getSession(); |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
| 280 | 280 | }); |
| 281 | 281 | |
| 282 | - $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 282 | + $this->registerService('OCSMiddleware', function(SimpleContainer $c) { |
|
| 283 | 283 | return new OCSMiddleware( |
| 284 | 284 | $c['Request'] |
| 285 | 285 | ); |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | $dispatcher->registerMiddleware($c['BruteForceMiddleware']); |
| 296 | 296 | $dispatcher->registerMiddleware($c['RateLimitingMiddleware']); |
| 297 | 297 | |
| 298 | - foreach($middleWares as $middleWare) { |
|
| 298 | + foreach ($middleWares as $middleWare) { |
|
| 299 | 299 | $dispatcher->registerMiddleware($c[$middleWare]); |
| 300 | 300 | } |
| 301 | 301 | |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | * @return mixed |
| 368 | 368 | */ |
| 369 | 369 | function log($message, $level) { |
| 370 | - switch($level){ |
|
| 370 | + switch ($level) { |
|
| 371 | 371 | case 'debug': |
| 372 | 372 | $level = \OCP\Util::DEBUG; |
| 373 | 373 | break; |
@@ -426,12 +426,12 @@ discard block |
||
| 426 | 426 | return parent::query($name); |
| 427 | 427 | } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
| 428 | 428 | return parent::query($name); |
| 429 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 429 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']).'\\') === 0) { |
|
| 430 | 430 | return parent::query($name); |
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 434 | + throw new QueryException('Could not resolve '.$name.'!'. |
|
| 435 | 435 | ' Class can not be instantiated'); |
| 436 | 436 | } |
| 437 | 437 | } |
@@ -27,83 +27,83 @@ |
||
| 27 | 27 | use OCP\Security\ICrypto; |
| 28 | 28 | |
| 29 | 29 | class Manager { |
| 30 | - /** @var IAppData */ |
|
| 31 | - private $appData; |
|
| 32 | - /** @var ICrypto */ |
|
| 33 | - private $crypto; |
|
| 30 | + /** @var IAppData */ |
|
| 31 | + private $appData; |
|
| 32 | + /** @var ICrypto */ |
|
| 33 | + private $crypto; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param Factory $appDataFactory |
|
| 37 | - * @param ICrypto $crypto |
|
| 38 | - */ |
|
| 39 | - public function __construct(Factory $appDataFactory, |
|
| 40 | - ICrypto $crypto) { |
|
| 41 | - $this->appData = $appDataFactory->get('identityproof'); |
|
| 42 | - $this->crypto = $crypto; |
|
| 43 | - } |
|
| 35 | + /** |
|
| 36 | + * @param Factory $appDataFactory |
|
| 37 | + * @param ICrypto $crypto |
|
| 38 | + */ |
|
| 39 | + public function __construct(Factory $appDataFactory, |
|
| 40 | + ICrypto $crypto) { |
|
| 41 | + $this->appData = $appDataFactory->get('identityproof'); |
|
| 42 | + $this->crypto = $crypto; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Calls the openssl functions to generate a public and private key. |
|
| 47 | - * In a separate function for unit testing purposes. |
|
| 48 | - * |
|
| 49 | - * @return array [$publicKey, $privateKey] |
|
| 50 | - */ |
|
| 51 | - protected function generateKeyPair() { |
|
| 52 | - $config = [ |
|
| 53 | - 'digest_alg' => 'sha512', |
|
| 54 | - 'private_key_bits' => 2048, |
|
| 55 | - ]; |
|
| 45 | + /** |
|
| 46 | + * Calls the openssl functions to generate a public and private key. |
|
| 47 | + * In a separate function for unit testing purposes. |
|
| 48 | + * |
|
| 49 | + * @return array [$publicKey, $privateKey] |
|
| 50 | + */ |
|
| 51 | + protected function generateKeyPair() { |
|
| 52 | + $config = [ |
|
| 53 | + 'digest_alg' => 'sha512', |
|
| 54 | + 'private_key_bits' => 2048, |
|
| 55 | + ]; |
|
| 56 | 56 | |
| 57 | - // Generate new key |
|
| 58 | - $res = openssl_pkey_new($config); |
|
| 59 | - openssl_pkey_export($res, $privateKey); |
|
| 57 | + // Generate new key |
|
| 58 | + $res = openssl_pkey_new($config); |
|
| 59 | + openssl_pkey_export($res, $privateKey); |
|
| 60 | 60 | |
| 61 | - // Extract the public key from $res to $pubKey |
|
| 62 | - $publicKey = openssl_pkey_get_details($res); |
|
| 63 | - $publicKey = $publicKey['key']; |
|
| 61 | + // Extract the public key from $res to $pubKey |
|
| 62 | + $publicKey = openssl_pkey_get_details($res); |
|
| 63 | + $publicKey = $publicKey['key']; |
|
| 64 | 64 | |
| 65 | - return [$publicKey, $privateKey]; |
|
| 66 | - } |
|
| 65 | + return [$publicKey, $privateKey]; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Generate a key for $user |
|
| 70 | - * Note: If a key already exists it will be overwritten |
|
| 71 | - * |
|
| 72 | - * @param IUser $user |
|
| 73 | - * @return Key |
|
| 74 | - */ |
|
| 75 | - protected function generateKey(IUser $user) { |
|
| 76 | - list($publicKey, $privateKey) = $this->generateKeyPair(); |
|
| 68 | + /** |
|
| 69 | + * Generate a key for $user |
|
| 70 | + * Note: If a key already exists it will be overwritten |
|
| 71 | + * |
|
| 72 | + * @param IUser $user |
|
| 73 | + * @return Key |
|
| 74 | + */ |
|
| 75 | + protected function generateKey(IUser $user) { |
|
| 76 | + list($publicKey, $privateKey) = $this->generateKeyPair(); |
|
| 77 | 77 | |
| 78 | - // Write the private and public key to the disk |
|
| 79 | - try { |
|
| 80 | - $this->appData->newFolder($user->getUID()); |
|
| 81 | - } catch (\Exception $e) {} |
|
| 82 | - $folder = $this->appData->getFolder($user->getUID()); |
|
| 83 | - $folder->newFile('private') |
|
| 84 | - ->putContent($this->crypto->encrypt($privateKey)); |
|
| 85 | - $folder->newFile('public') |
|
| 86 | - ->putContent($publicKey); |
|
| 78 | + // Write the private and public key to the disk |
|
| 79 | + try { |
|
| 80 | + $this->appData->newFolder($user->getUID()); |
|
| 81 | + } catch (\Exception $e) {} |
|
| 82 | + $folder = $this->appData->getFolder($user->getUID()); |
|
| 83 | + $folder->newFile('private') |
|
| 84 | + ->putContent($this->crypto->encrypt($privateKey)); |
|
| 85 | + $folder->newFile('public') |
|
| 86 | + ->putContent($publicKey); |
|
| 87 | 87 | |
| 88 | - return new Key($publicKey, $privateKey); |
|
| 89 | - } |
|
| 88 | + return new Key($publicKey, $privateKey); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Get public and private key for $user |
|
| 93 | - * |
|
| 94 | - * @param IUser $user |
|
| 95 | - * @return Key |
|
| 96 | - */ |
|
| 97 | - public function getKey(IUser $user) { |
|
| 98 | - try { |
|
| 99 | - $folder = $this->appData->getFolder($user->getUID()); |
|
| 100 | - $privateKey = $this->crypto->decrypt( |
|
| 101 | - $folder->getFile('private')->getContent() |
|
| 102 | - ); |
|
| 103 | - $publicKey = $folder->getFile('public')->getContent(); |
|
| 104 | - return new Key($publicKey, $privateKey); |
|
| 105 | - } catch (\Exception $e) { |
|
| 106 | - return $this->generateKey($user); |
|
| 107 | - } |
|
| 108 | - } |
|
| 91 | + /** |
|
| 92 | + * Get public and private key for $user |
|
| 93 | + * |
|
| 94 | + * @param IUser $user |
|
| 95 | + * @return Key |
|
| 96 | + */ |
|
| 97 | + public function getKey(IUser $user) { |
|
| 98 | + try { |
|
| 99 | + $folder = $this->appData->getFolder($user->getUID()); |
|
| 100 | + $privateKey = $this->crypto->decrypt( |
|
| 101 | + $folder->getFile('private')->getContent() |
|
| 102 | + ); |
|
| 103 | + $publicKey = $folder->getFile('public')->getContent(); |
|
| 104 | + return new Key($publicKey, $privateKey); |
|
| 105 | + } catch (\Exception $e) { |
|
| 106 | + return $this->generateKey($user); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -28,105 +28,105 @@ |
||
| 28 | 28 | use OCP\IConfig; |
| 29 | 29 | |
| 30 | 30 | class AppFetcher extends Fetcher { |
| 31 | - /** |
|
| 32 | - * @param Factory $appDataFactory |
|
| 33 | - * @param IClientService $clientService |
|
| 34 | - * @param ITimeFactory $timeFactory |
|
| 35 | - * @param IConfig $config; |
|
| 36 | - */ |
|
| 37 | - public function __construct(Factory $appDataFactory, |
|
| 38 | - IClientService $clientService, |
|
| 39 | - ITimeFactory $timeFactory, |
|
| 40 | - IConfig $config) { |
|
| 41 | - parent::__construct( |
|
| 42 | - $appDataFactory, |
|
| 43 | - $clientService, |
|
| 44 | - $timeFactory, |
|
| 45 | - $config |
|
| 46 | - ); |
|
| 31 | + /** |
|
| 32 | + * @param Factory $appDataFactory |
|
| 33 | + * @param IClientService $clientService |
|
| 34 | + * @param ITimeFactory $timeFactory |
|
| 35 | + * @param IConfig $config; |
|
| 36 | + */ |
|
| 37 | + public function __construct(Factory $appDataFactory, |
|
| 38 | + IClientService $clientService, |
|
| 39 | + ITimeFactory $timeFactory, |
|
| 40 | + IConfig $config) { |
|
| 41 | + parent::__construct( |
|
| 42 | + $appDataFactory, |
|
| 43 | + $clientService, |
|
| 44 | + $timeFactory, |
|
| 45 | + $config |
|
| 46 | + ); |
|
| 47 | 47 | |
| 48 | - $this->fileName = 'apps.json'; |
|
| 49 | - $this->setEndpoint(); |
|
| 50 | - } |
|
| 48 | + $this->fileName = 'apps.json'; |
|
| 49 | + $this->setEndpoint(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Only returns the latest compatible app release in the releases array |
|
| 54 | - * |
|
| 55 | - * @param string $ETag |
|
| 56 | - * @param string $content |
|
| 57 | - * |
|
| 58 | - * @return array |
|
| 59 | - */ |
|
| 60 | - protected function fetch($ETag, $content) { |
|
| 61 | - /** @var mixed[] $response */ |
|
| 62 | - $response = parent::fetch($ETag, $content); |
|
| 52 | + /** |
|
| 53 | + * Only returns the latest compatible app release in the releases array |
|
| 54 | + * |
|
| 55 | + * @param string $ETag |
|
| 56 | + * @param string $content |
|
| 57 | + * |
|
| 58 | + * @return array |
|
| 59 | + */ |
|
| 60 | + protected function fetch($ETag, $content) { |
|
| 61 | + /** @var mixed[] $response */ |
|
| 62 | + $response = parent::fetch($ETag, $content); |
|
| 63 | 63 | |
| 64 | - $ncVersion = $this->getVersion(); |
|
| 65 | - $ncMajorVersion = explode('.', $ncVersion)[0]; |
|
| 66 | - foreach($response['data'] as $dataKey => $app) { |
|
| 67 | - $releases = []; |
|
| 64 | + $ncVersion = $this->getVersion(); |
|
| 65 | + $ncMajorVersion = explode('.', $ncVersion)[0]; |
|
| 66 | + foreach($response['data'] as $dataKey => $app) { |
|
| 67 | + $releases = []; |
|
| 68 | 68 | |
| 69 | - // Filter all compatible releases |
|
| 70 | - foreach($app['releases'] as $release) { |
|
| 71 | - // Exclude all nightly and pre-releases |
|
| 72 | - if($release['isNightly'] === false |
|
| 73 | - && strpos($release['version'], '-') === false) { |
|
| 74 | - // Exclude all versions not compatible with the current version |
|
| 75 | - $versionParser = new VersionParser(); |
|
| 76 | - $version = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
|
| 77 | - if ( |
|
| 78 | - // Major version is bigger or equals to the minimum version of the app |
|
| 79 | - version_compare($ncMajorVersion, $version->getMinimumVersion(), '>=') |
|
| 80 | - // Major version is smaller or equals to the maximum version of the app |
|
| 81 | - && version_compare($ncMajorVersion, $version->getMaximumVersion(), '<=') |
|
| 82 | - ) { |
|
| 83 | - $releases[] = $release; |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - } |
|
| 69 | + // Filter all compatible releases |
|
| 70 | + foreach($app['releases'] as $release) { |
|
| 71 | + // Exclude all nightly and pre-releases |
|
| 72 | + if($release['isNightly'] === false |
|
| 73 | + && strpos($release['version'], '-') === false) { |
|
| 74 | + // Exclude all versions not compatible with the current version |
|
| 75 | + $versionParser = new VersionParser(); |
|
| 76 | + $version = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
|
| 77 | + if ( |
|
| 78 | + // Major version is bigger or equals to the minimum version of the app |
|
| 79 | + version_compare($ncMajorVersion, $version->getMinimumVersion(), '>=') |
|
| 80 | + // Major version is smaller or equals to the maximum version of the app |
|
| 81 | + && version_compare($ncMajorVersion, $version->getMaximumVersion(), '<=') |
|
| 82 | + ) { |
|
| 83 | + $releases[] = $release; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - // Get the highest version |
|
| 89 | - $versions = []; |
|
| 90 | - foreach($releases as $release) { |
|
| 91 | - $versions[] = $release['version']; |
|
| 92 | - } |
|
| 93 | - usort($versions, 'version_compare'); |
|
| 94 | - $versions = array_reverse($versions); |
|
| 95 | - $compatible = false; |
|
| 96 | - if(isset($versions[0])) { |
|
| 97 | - $highestVersion = $versions[0]; |
|
| 98 | - foreach ($releases as $release) { |
|
| 99 | - if ((string)$release['version'] === (string)$highestVersion) { |
|
| 100 | - $compatible = true; |
|
| 101 | - $response['data'][$dataKey]['releases'] = [$release]; |
|
| 102 | - break; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - if(!$compatible) { |
|
| 107 | - unset($response['data'][$dataKey]); |
|
| 108 | - } |
|
| 109 | - } |
|
| 88 | + // Get the highest version |
|
| 89 | + $versions = []; |
|
| 90 | + foreach($releases as $release) { |
|
| 91 | + $versions[] = $release['version']; |
|
| 92 | + } |
|
| 93 | + usort($versions, 'version_compare'); |
|
| 94 | + $versions = array_reverse($versions); |
|
| 95 | + $compatible = false; |
|
| 96 | + if(isset($versions[0])) { |
|
| 97 | + $highestVersion = $versions[0]; |
|
| 98 | + foreach ($releases as $release) { |
|
| 99 | + if ((string)$release['version'] === (string)$highestVersion) { |
|
| 100 | + $compatible = true; |
|
| 101 | + $response['data'][$dataKey]['releases'] = [$release]; |
|
| 102 | + break; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + if(!$compatible) { |
|
| 107 | + unset($response['data'][$dataKey]); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - $response['data'] = array_values($response['data']); |
|
| 112 | - return $response; |
|
| 113 | - } |
|
| 111 | + $response['data'] = array_values($response['data']); |
|
| 112 | + return $response; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - private function setEndpoint() { |
|
| 116 | - $versionArray = explode('.', $this->getVersion()); |
|
| 117 | - $this->endpointUrl = sprintf( |
|
| 118 | - 'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json', |
|
| 119 | - $versionArray[0], |
|
| 120 | - $versionArray[1], |
|
| 121 | - $versionArray[2] |
|
| 122 | - ); |
|
| 123 | - } |
|
| 115 | + private function setEndpoint() { |
|
| 116 | + $versionArray = explode('.', $this->getVersion()); |
|
| 117 | + $this->endpointUrl = sprintf( |
|
| 118 | + 'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json', |
|
| 119 | + $versionArray[0], |
|
| 120 | + $versionArray[1], |
|
| 121 | + $versionArray[2] |
|
| 122 | + ); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * @param string $version |
|
| 127 | - */ |
|
| 128 | - public function setVersion($version) { |
|
| 129 | - parent::setVersion($version); |
|
| 130 | - $this->setEndpoint(); |
|
| 131 | - } |
|
| 125 | + /** |
|
| 126 | + * @param string $version |
|
| 127 | + */ |
|
| 128 | + public function setVersion($version) { |
|
| 129 | + parent::setVersion($version); |
|
| 130 | + $this->setEndpoint(); |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -27,23 +27,23 @@ |
||
| 27 | 27 | use OCP\IConfig; |
| 28 | 28 | |
| 29 | 29 | class CategoryFetcher extends Fetcher { |
| 30 | - /** |
|
| 31 | - * @param Factory $appDataFactory |
|
| 32 | - * @param IClientService $clientService |
|
| 33 | - * @param ITimeFactory $timeFactory |
|
| 34 | - * @param IConfig $config |
|
| 35 | - */ |
|
| 36 | - public function __construct(Factory $appDataFactory, |
|
| 37 | - IClientService $clientService, |
|
| 38 | - ITimeFactory $timeFactory, |
|
| 39 | - IConfig $config) { |
|
| 40 | - parent::__construct( |
|
| 41 | - $appDataFactory, |
|
| 42 | - $clientService, |
|
| 43 | - $timeFactory, |
|
| 44 | - $config |
|
| 45 | - ); |
|
| 46 | - $this->fileName = 'categories.json'; |
|
| 47 | - $this->endpointUrl = 'https://apps.nextcloud.com/api/v1/categories.json'; |
|
| 48 | - } |
|
| 30 | + /** |
|
| 31 | + * @param Factory $appDataFactory |
|
| 32 | + * @param IClientService $clientService |
|
| 33 | + * @param ITimeFactory $timeFactory |
|
| 34 | + * @param IConfig $config |
|
| 35 | + */ |
|
| 36 | + public function __construct(Factory $appDataFactory, |
|
| 37 | + IClientService $clientService, |
|
| 38 | + ITimeFactory $timeFactory, |
|
| 39 | + IConfig $config) { |
|
| 40 | + parent::__construct( |
|
| 41 | + $appDataFactory, |
|
| 42 | + $clientService, |
|
| 43 | + $timeFactory, |
|
| 44 | + $config |
|
| 45 | + ); |
|
| 46 | + $this->fileName = 'categories.json'; |
|
| 47 | + $this->endpointUrl = 'https://apps.nextcloud.com/api/v1/categories.json'; |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -30,150 +30,150 @@ |
||
| 30 | 30 | use OCP\IConfig; |
| 31 | 31 | |
| 32 | 32 | abstract class Fetcher { |
| 33 | - const INVALIDATE_AFTER_SECONDS = 300; |
|
| 34 | - |
|
| 35 | - /** @var IAppData */ |
|
| 36 | - protected $appData; |
|
| 37 | - /** @var IClientService */ |
|
| 38 | - protected $clientService; |
|
| 39 | - /** @var ITimeFactory */ |
|
| 40 | - protected $timeFactory; |
|
| 41 | - /** @var IConfig */ |
|
| 42 | - protected $config; |
|
| 43 | - /** @var string */ |
|
| 44 | - protected $fileName; |
|
| 45 | - /** @var string */ |
|
| 46 | - protected $endpointUrl; |
|
| 47 | - /** @var string */ |
|
| 48 | - protected $version; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @param Factory $appDataFactory |
|
| 52 | - * @param IClientService $clientService |
|
| 53 | - * @param ITimeFactory $timeFactory |
|
| 54 | - * @param IConfig $config |
|
| 55 | - */ |
|
| 56 | - public function __construct(Factory $appDataFactory, |
|
| 57 | - IClientService $clientService, |
|
| 58 | - ITimeFactory $timeFactory, |
|
| 59 | - IConfig $config) { |
|
| 60 | - $this->appData = $appDataFactory->get('appstore'); |
|
| 61 | - $this->clientService = $clientService; |
|
| 62 | - $this->timeFactory = $timeFactory; |
|
| 63 | - $this->config = $config; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Fetches the response from the server |
|
| 68 | - * |
|
| 69 | - * @param string $ETag |
|
| 70 | - * @param string $content |
|
| 71 | - * |
|
| 72 | - * @return array |
|
| 73 | - */ |
|
| 74 | - protected function fetch($ETag, $content) { |
|
| 75 | - $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
| 76 | - |
|
| 77 | - if (!$appstoreenabled) { |
|
| 78 | - return []; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $options = []; |
|
| 82 | - |
|
| 83 | - if ($ETag !== '') { |
|
| 84 | - $options['headers'] = [ |
|
| 85 | - 'If-None-Match' => $ETag, |
|
| 86 | - ]; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $client = $this->clientService->newClient(); |
|
| 90 | - $response = $client->get($this->endpointUrl, $options); |
|
| 91 | - |
|
| 92 | - $responseJson = []; |
|
| 93 | - if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) { |
|
| 94 | - $responseJson['data'] = json_decode($content, true); |
|
| 95 | - } else { |
|
| 96 | - $responseJson['data'] = json_decode($response->getBody(), true); |
|
| 97 | - $ETag = $response->getHeader('ETag'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $responseJson['timestamp'] = $this->timeFactory->getTime(); |
|
| 101 | - $responseJson['ncversion'] = $this->getVersion(); |
|
| 102 | - if ($ETag !== '') { |
|
| 103 | - $responseJson['ETag'] = $ETag; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $responseJson; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Returns the array with the categories on the appstore server |
|
| 111 | - * |
|
| 112 | - * @return array |
|
| 113 | - */ |
|
| 114 | - public function get() { |
|
| 115 | - $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
| 116 | - |
|
| 117 | - if (!$appstoreenabled) { |
|
| 118 | - return []; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $rootFolder = $this->appData->getFolder('/'); |
|
| 122 | - |
|
| 123 | - $ETag = ''; |
|
| 124 | - $content = ''; |
|
| 125 | - |
|
| 126 | - try { |
|
| 127 | - // File does already exists |
|
| 128 | - $file = $rootFolder->getFile($this->fileName); |
|
| 129 | - $jsonBlob = json_decode($file->getContent(), true); |
|
| 130 | - if (is_array($jsonBlob)) { |
|
| 131 | - |
|
| 132 | - // No caching when the version has been updated |
|
| 133 | - if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) { |
|
| 134 | - |
|
| 135 | - // If the timestamp is older than 300 seconds request the files new |
|
| 136 | - if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { |
|
| 137 | - return $jsonBlob['data']; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if (isset($jsonBlob['ETag'])) { |
|
| 141 | - $ETag = $jsonBlob['ETag']; |
|
| 142 | - $content = json_encode($jsonBlob['data']); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } catch (NotFoundException $e) { |
|
| 147 | - // File does not already exists |
|
| 148 | - $file = $rootFolder->newFile($this->fileName); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Refresh the file content |
|
| 152 | - try { |
|
| 153 | - $responseJson = $this->fetch($ETag, $content); |
|
| 154 | - $file->putContent(json_encode($responseJson)); |
|
| 155 | - return json_decode($file->getContent(), true)['data']; |
|
| 156 | - } catch (\Exception $e) { |
|
| 157 | - return []; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Get the currently Nextcloud version |
|
| 163 | - * @return string |
|
| 164 | - */ |
|
| 165 | - protected function getVersion() { |
|
| 166 | - if ($this->version === null) { |
|
| 167 | - $this->version = $this->config->getSystemValue('version', '0.0.0'); |
|
| 168 | - } |
|
| 169 | - return $this->version; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Set the current Nextcloud version |
|
| 174 | - * @param string $version |
|
| 175 | - */ |
|
| 176 | - public function setVersion($version) { |
|
| 177 | - $this->version = $version; |
|
| 178 | - } |
|
| 33 | + const INVALIDATE_AFTER_SECONDS = 300; |
|
| 34 | + |
|
| 35 | + /** @var IAppData */ |
|
| 36 | + protected $appData; |
|
| 37 | + /** @var IClientService */ |
|
| 38 | + protected $clientService; |
|
| 39 | + /** @var ITimeFactory */ |
|
| 40 | + protected $timeFactory; |
|
| 41 | + /** @var IConfig */ |
|
| 42 | + protected $config; |
|
| 43 | + /** @var string */ |
|
| 44 | + protected $fileName; |
|
| 45 | + /** @var string */ |
|
| 46 | + protected $endpointUrl; |
|
| 47 | + /** @var string */ |
|
| 48 | + protected $version; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param Factory $appDataFactory |
|
| 52 | + * @param IClientService $clientService |
|
| 53 | + * @param ITimeFactory $timeFactory |
|
| 54 | + * @param IConfig $config |
|
| 55 | + */ |
|
| 56 | + public function __construct(Factory $appDataFactory, |
|
| 57 | + IClientService $clientService, |
|
| 58 | + ITimeFactory $timeFactory, |
|
| 59 | + IConfig $config) { |
|
| 60 | + $this->appData = $appDataFactory->get('appstore'); |
|
| 61 | + $this->clientService = $clientService; |
|
| 62 | + $this->timeFactory = $timeFactory; |
|
| 63 | + $this->config = $config; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Fetches the response from the server |
|
| 68 | + * |
|
| 69 | + * @param string $ETag |
|
| 70 | + * @param string $content |
|
| 71 | + * |
|
| 72 | + * @return array |
|
| 73 | + */ |
|
| 74 | + protected function fetch($ETag, $content) { |
|
| 75 | + $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
| 76 | + |
|
| 77 | + if (!$appstoreenabled) { |
|
| 78 | + return []; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $options = []; |
|
| 82 | + |
|
| 83 | + if ($ETag !== '') { |
|
| 84 | + $options['headers'] = [ |
|
| 85 | + 'If-None-Match' => $ETag, |
|
| 86 | + ]; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $client = $this->clientService->newClient(); |
|
| 90 | + $response = $client->get($this->endpointUrl, $options); |
|
| 91 | + |
|
| 92 | + $responseJson = []; |
|
| 93 | + if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) { |
|
| 94 | + $responseJson['data'] = json_decode($content, true); |
|
| 95 | + } else { |
|
| 96 | + $responseJson['data'] = json_decode($response->getBody(), true); |
|
| 97 | + $ETag = $response->getHeader('ETag'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $responseJson['timestamp'] = $this->timeFactory->getTime(); |
|
| 101 | + $responseJson['ncversion'] = $this->getVersion(); |
|
| 102 | + if ($ETag !== '') { |
|
| 103 | + $responseJson['ETag'] = $ETag; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $responseJson; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Returns the array with the categories on the appstore server |
|
| 111 | + * |
|
| 112 | + * @return array |
|
| 113 | + */ |
|
| 114 | + public function get() { |
|
| 115 | + $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true); |
|
| 116 | + |
|
| 117 | + if (!$appstoreenabled) { |
|
| 118 | + return []; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + $rootFolder = $this->appData->getFolder('/'); |
|
| 122 | + |
|
| 123 | + $ETag = ''; |
|
| 124 | + $content = ''; |
|
| 125 | + |
|
| 126 | + try { |
|
| 127 | + // File does already exists |
|
| 128 | + $file = $rootFolder->getFile($this->fileName); |
|
| 129 | + $jsonBlob = json_decode($file->getContent(), true); |
|
| 130 | + if (is_array($jsonBlob)) { |
|
| 131 | + |
|
| 132 | + // No caching when the version has been updated |
|
| 133 | + if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) { |
|
| 134 | + |
|
| 135 | + // If the timestamp is older than 300 seconds request the files new |
|
| 136 | + if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { |
|
| 137 | + return $jsonBlob['data']; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if (isset($jsonBlob['ETag'])) { |
|
| 141 | + $ETag = $jsonBlob['ETag']; |
|
| 142 | + $content = json_encode($jsonBlob['data']); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } catch (NotFoundException $e) { |
|
| 147 | + // File does not already exists |
|
| 148 | + $file = $rootFolder->newFile($this->fileName); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Refresh the file content |
|
| 152 | + try { |
|
| 153 | + $responseJson = $this->fetch($ETag, $content); |
|
| 154 | + $file->putContent(json_encode($responseJson)); |
|
| 155 | + return json_decode($file->getContent(), true)['data']; |
|
| 156 | + } catch (\Exception $e) { |
|
| 157 | + return []; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Get the currently Nextcloud version |
|
| 163 | + * @return string |
|
| 164 | + */ |
|
| 165 | + protected function getVersion() { |
|
| 166 | + if ($this->version === null) { |
|
| 167 | + $this->version = $this->config->getSystemValue('version', '0.0.0'); |
|
| 168 | + } |
|
| 169 | + return $this->version; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Set the current Nextcloud version |
|
| 174 | + * @param string $version |
|
| 175 | + */ |
|
| 176 | + public function setVersion($version) { |
|
| 177 | + $this->version = $version; |
|
| 178 | + } |
|
| 179 | 179 | } |
@@ -49,103 +49,103 @@ |
||
| 49 | 49 | class Application extends App { |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param array $urlParams |
|
| 54 | - */ |
|
| 55 | - public function __construct(array $urlParams=[]){ |
|
| 56 | - parent::__construct('settings', $urlParams); |
|
| 52 | + /** |
|
| 53 | + * @param array $urlParams |
|
| 54 | + */ |
|
| 55 | + public function __construct(array $urlParams=[]){ |
|
| 56 | + parent::__construct('settings', $urlParams); |
|
| 57 | 57 | |
| 58 | - $container = $this->getContainer(); |
|
| 58 | + $container = $this->getContainer(); |
|
| 59 | 59 | |
| 60 | - // Register Middleware |
|
| 61 | - $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
|
| 62 | - $container->registerMiddleWare('SubadminMiddleware'); |
|
| 60 | + // Register Middleware |
|
| 61 | + $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
|
| 62 | + $container->registerMiddleWare('SubadminMiddleware'); |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Core class wrappers |
|
| 66 | - */ |
|
| 67 | - /** FIXME: Remove once OC_User is non-static and mockable */ |
|
| 68 | - $container->registerService('isAdmin', function() { |
|
| 69 | - return \OC_User::isAdminUser(\OC_User::getUser()); |
|
| 70 | - }); |
|
| 71 | - /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
|
| 72 | - $container->registerService('isSubAdmin', function(IContainer $c) { |
|
| 73 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 74 | - $isSubAdmin = false; |
|
| 75 | - if($userObject !== null) { |
|
| 76 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 77 | - } |
|
| 78 | - return $isSubAdmin; |
|
| 79 | - }); |
|
| 80 | - $container->registerService('userCertificateManager', function(IContainer $c) { |
|
| 81 | - return $c->query('ServerContainer')->getCertificateManager(); |
|
| 82 | - }, false); |
|
| 83 | - $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
| 84 | - return $c->query('ServerContainer')->getCertificateManager(null); |
|
| 85 | - }, false); |
|
| 86 | - $container->registerService(IProvider::class, function (IContainer $c) { |
|
| 87 | - return $c->query('ServerContainer')->query(IProvider::class); |
|
| 88 | - }); |
|
| 89 | - $container->registerService(IManager::class, function (IContainer $c) { |
|
| 90 | - return $c->query('ServerContainer')->getSettingsManager(); |
|
| 91 | - }); |
|
| 64 | + /** |
|
| 65 | + * Core class wrappers |
|
| 66 | + */ |
|
| 67 | + /** FIXME: Remove once OC_User is non-static and mockable */ |
|
| 68 | + $container->registerService('isAdmin', function() { |
|
| 69 | + return \OC_User::isAdminUser(\OC_User::getUser()); |
|
| 70 | + }); |
|
| 71 | + /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
|
| 72 | + $container->registerService('isSubAdmin', function(IContainer $c) { |
|
| 73 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 74 | + $isSubAdmin = false; |
|
| 75 | + if($userObject !== null) { |
|
| 76 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 77 | + } |
|
| 78 | + return $isSubAdmin; |
|
| 79 | + }); |
|
| 80 | + $container->registerService('userCertificateManager', function(IContainer $c) { |
|
| 81 | + return $c->query('ServerContainer')->getCertificateManager(); |
|
| 82 | + }, false); |
|
| 83 | + $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
| 84 | + return $c->query('ServerContainer')->getCertificateManager(null); |
|
| 85 | + }, false); |
|
| 86 | + $container->registerService(IProvider::class, function (IContainer $c) { |
|
| 87 | + return $c->query('ServerContainer')->query(IProvider::class); |
|
| 88 | + }); |
|
| 89 | + $container->registerService(IManager::class, function (IContainer $c) { |
|
| 90 | + return $c->query('ServerContainer')->getSettingsManager(); |
|
| 91 | + }); |
|
| 92 | 92 | |
| 93 | - $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
| 94 | - /** @var Server $server */ |
|
| 95 | - $server = $c->query('ServerContainer'); |
|
| 96 | - /** @var Defaults $defaults */ |
|
| 97 | - $defaults = $server->query(Defaults::class); |
|
| 93 | + $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
| 94 | + /** @var Server $server */ |
|
| 95 | + $server = $c->query('ServerContainer'); |
|
| 96 | + /** @var Defaults $defaults */ |
|
| 97 | + $defaults = $server->query(Defaults::class); |
|
| 98 | 98 | |
| 99 | - return new NewUserMailHelper( |
|
| 100 | - $defaults, |
|
| 101 | - $server->getURLGenerator(), |
|
| 102 | - $server->getL10N('settings'), |
|
| 103 | - $server->getMailer(), |
|
| 104 | - $server->getSecureRandom(), |
|
| 105 | - new TimeFactory(), |
|
| 106 | - $server->getConfig(), |
|
| 107 | - $server->getCrypto(), |
|
| 108 | - Util::getDefaultEmailAddress('no-reply') |
|
| 109 | - ); |
|
| 110 | - }); |
|
| 111 | - } |
|
| 99 | + return new NewUserMailHelper( |
|
| 100 | + $defaults, |
|
| 101 | + $server->getURLGenerator(), |
|
| 102 | + $server->getL10N('settings'), |
|
| 103 | + $server->getMailer(), |
|
| 104 | + $server->getSecureRandom(), |
|
| 105 | + new TimeFactory(), |
|
| 106 | + $server->getConfig(), |
|
| 107 | + $server->getCrypto(), |
|
| 108 | + Util::getDefaultEmailAddress('no-reply') |
|
| 109 | + ); |
|
| 110 | + }); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - public function register() { |
|
| 114 | - $activityManager = $this->getContainer()->getServer()->getActivityManager(); |
|
| 115 | - $activityManager->registerSetting(Setting::class); // FIXME move to info.xml |
|
| 116 | - $activityManager->registerProvider(Provider::class); // FIXME move to info.xml |
|
| 113 | + public function register() { |
|
| 114 | + $activityManager = $this->getContainer()->getServer()->getActivityManager(); |
|
| 115 | + $activityManager->registerSetting(Setting::class); // FIXME move to info.xml |
|
| 116 | + $activityManager->registerProvider(Provider::class); // FIXME move to info.xml |
|
| 117 | 117 | |
| 118 | - Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); |
|
| 119 | - Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); |
|
| 120 | - } |
|
| 118 | + Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); |
|
| 119 | + Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @param array $parameters |
|
| 124 | - * @throws \InvalidArgumentException |
|
| 125 | - * @throws \BadMethodCallException |
|
| 126 | - * @throws \Exception |
|
| 127 | - * @throws \OCP\AppFramework\QueryException |
|
| 128 | - */ |
|
| 129 | - public function onChangePassword(array $parameters) { |
|
| 130 | - /** @var Hooks $hooks */ |
|
| 131 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
| 132 | - $hooks->onChangePassword($parameters['uid']); |
|
| 133 | - } |
|
| 122 | + /** |
|
| 123 | + * @param array $parameters |
|
| 124 | + * @throws \InvalidArgumentException |
|
| 125 | + * @throws \BadMethodCallException |
|
| 126 | + * @throws \Exception |
|
| 127 | + * @throws \OCP\AppFramework\QueryException |
|
| 128 | + */ |
|
| 129 | + public function onChangePassword(array $parameters) { |
|
| 130 | + /** @var Hooks $hooks */ |
|
| 131 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
| 132 | + $hooks->onChangePassword($parameters['uid']); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * @param array $parameters |
|
| 137 | - * @throws \InvalidArgumentException |
|
| 138 | - * @throws \BadMethodCallException |
|
| 139 | - * @throws \Exception |
|
| 140 | - * @throws \OCP\AppFramework\QueryException |
|
| 141 | - */ |
|
| 142 | - public function onChangeInfo(array $parameters) { |
|
| 143 | - if ($parameters['feature'] !== 'eMailAddress') { |
|
| 144 | - return; |
|
| 145 | - } |
|
| 135 | + /** |
|
| 136 | + * @param array $parameters |
|
| 137 | + * @throws \InvalidArgumentException |
|
| 138 | + * @throws \BadMethodCallException |
|
| 139 | + * @throws \Exception |
|
| 140 | + * @throws \OCP\AppFramework\QueryException |
|
| 141 | + */ |
|
| 142 | + public function onChangeInfo(array $parameters) { |
|
| 143 | + if ($parameters['feature'] !== 'eMailAddress') { |
|
| 144 | + return; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** @var Hooks $hooks */ |
|
| 148 | - $hooks = $this->getContainer()->query(Hooks::class); |
|
| 149 | - $hooks->onChangeEmail($parameters['user'], $parameters['old_value']); |
|
| 150 | - } |
|
| 147 | + /** @var Hooks $hooks */ |
|
| 148 | + $hooks = $this->getContainer()->query(Hooks::class); |
|
| 149 | + $hooks->onChangeEmail($parameters['user'], $parameters['old_value']); |
|
| 150 | + } |
|
| 151 | 151 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * @param array $urlParams |
| 54 | 54 | */ |
| 55 | - public function __construct(array $urlParams=[]){ |
|
| 55 | + public function __construct(array $urlParams = []) { |
|
| 56 | 56 | parent::__construct('settings', $urlParams); |
| 57 | 57 | |
| 58 | 58 | $container = $this->getContainer(); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $container->registerService('isSubAdmin', function(IContainer $c) { |
| 73 | 73 | $userObject = \OC::$server->getUserSession()->getUser(); |
| 74 | 74 | $isSubAdmin = false; |
| 75 | - if($userObject !== null) { |
|
| 75 | + if ($userObject !== null) { |
|
| 76 | 76 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
| 77 | 77 | } |
| 78 | 78 | return $isSubAdmin; |
@@ -80,17 +80,17 @@ discard block |
||
| 80 | 80 | $container->registerService('userCertificateManager', function(IContainer $c) { |
| 81 | 81 | return $c->query('ServerContainer')->getCertificateManager(); |
| 82 | 82 | }, false); |
| 83 | - $container->registerService('systemCertificateManager', function (IContainer $c) { |
|
| 83 | + $container->registerService('systemCertificateManager', function(IContainer $c) { |
|
| 84 | 84 | return $c->query('ServerContainer')->getCertificateManager(null); |
| 85 | 85 | }, false); |
| 86 | - $container->registerService(IProvider::class, function (IContainer $c) { |
|
| 86 | + $container->registerService(IProvider::class, function(IContainer $c) { |
|
| 87 | 87 | return $c->query('ServerContainer')->query(IProvider::class); |
| 88 | 88 | }); |
| 89 | - $container->registerService(IManager::class, function (IContainer $c) { |
|
| 89 | + $container->registerService(IManager::class, function(IContainer $c) { |
|
| 90 | 90 | return $c->query('ServerContainer')->getSettingsManager(); |
| 91 | 91 | }); |
| 92 | 92 | |
| 93 | - $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
|
| 93 | + $container->registerService(NewUserMailHelper::class, function(IContainer $c) { |
|
| 94 | 94 | /** @var Server $server */ |
| 95 | 95 | $server = $c->query('ServerContainer'); |
| 96 | 96 | /** @var Defaults $defaults */ |