@@ -38,139 +38,139 @@ |
||
38 | 38 | */ |
39 | 39 | interface IAppManager { |
40 | 40 | |
41 | - /** |
|
42 | - * Returns the app information from "appinfo/info.xml". |
|
43 | - * |
|
44 | - * @param string $appId |
|
45 | - * @return mixed |
|
46 | - * @since 14.0.0 |
|
47 | - */ |
|
48 | - public function getAppInfo(string $appId, bool $path = false, $lang = null); |
|
49 | - |
|
50 | - /** |
|
51 | - * Returns the app information from "appinfo/info.xml". |
|
52 | - * |
|
53 | - * @param string $appId |
|
54 | - * @param bool $useCache |
|
55 | - * @return string |
|
56 | - * @since 14.0.0 |
|
57 | - */ |
|
58 | - public function getAppVersion(string $appId, bool $useCache = true): string; |
|
59 | - |
|
60 | - /** |
|
61 | - * Check if an app is enabled for user |
|
62 | - * |
|
63 | - * @param string $appId |
|
64 | - * @param \OCP\IUser $user (optional) if not defined, the currently loggedin user will be used |
|
65 | - * @return bool |
|
66 | - * @since 8.0.0 |
|
67 | - */ |
|
68 | - public function isEnabledForUser($appId, $user = null); |
|
69 | - |
|
70 | - /** |
|
71 | - * Check if an app is enabled in the instance |
|
72 | - * |
|
73 | - * Notice: This actually checks if the app is enabled and not only if it is installed. |
|
74 | - * |
|
75 | - * @param string $appId |
|
76 | - * @return bool |
|
77 | - * @since 8.0.0 |
|
78 | - */ |
|
79 | - public function isInstalled($appId); |
|
80 | - |
|
81 | - /** |
|
82 | - * Enable an app for every user |
|
83 | - * |
|
84 | - * @param string $appId |
|
85 | - * @throws AppPathNotFoundException |
|
86 | - * @since 8.0.0 |
|
87 | - */ |
|
88 | - public function enableApp($appId); |
|
89 | - |
|
90 | - /** |
|
91 | - * Whether a list of types contains a protected app type |
|
92 | - * |
|
93 | - * @param string[] $types |
|
94 | - * @return bool |
|
95 | - * @since 12.0.0 |
|
96 | - */ |
|
97 | - public function hasProtectedAppType($types); |
|
98 | - |
|
99 | - /** |
|
100 | - * Enable an app only for specific groups |
|
101 | - * |
|
102 | - * @param string $appId |
|
103 | - * @param \OCP\IGroup[] $groups |
|
104 | - * @throws \Exception |
|
105 | - * @since 8.0.0 |
|
106 | - */ |
|
107 | - public function enableAppForGroups($appId, $groups); |
|
108 | - |
|
109 | - /** |
|
110 | - * Disable an app for every user |
|
111 | - * |
|
112 | - * @param string $appId |
|
113 | - * @since 8.0.0 |
|
114 | - */ |
|
115 | - public function disableApp($appId); |
|
116 | - |
|
117 | - /** |
|
118 | - * Get the directory for the given app. |
|
119 | - * |
|
120 | - * @param string $appId |
|
121 | - * @return string |
|
122 | - * @since 11.0.0 |
|
123 | - * @throws AppPathNotFoundException |
|
124 | - */ |
|
125 | - public function getAppPath($appId); |
|
126 | - |
|
127 | - /** |
|
128 | - * List all apps enabled for a user |
|
129 | - * |
|
130 | - * @param \OCP\IUser $user |
|
131 | - * @return string[] |
|
132 | - * @since 8.1.0 |
|
133 | - */ |
|
134 | - public function getEnabledAppsForUser(IUser $user); |
|
135 | - |
|
136 | - /** |
|
137 | - * List all installed apps |
|
138 | - * |
|
139 | - * @return string[] |
|
140 | - * @since 8.1.0 |
|
141 | - */ |
|
142 | - public function getInstalledApps(); |
|
143 | - |
|
144 | - /** |
|
145 | - * Clear the cached list of apps when enabling/disabling an app |
|
146 | - * @since 8.1.0 |
|
147 | - */ |
|
148 | - public function clearAppsCache(); |
|
149 | - |
|
150 | - /** |
|
151 | - * @param string $appId |
|
152 | - * @return boolean |
|
153 | - * @since 9.0.0 |
|
154 | - */ |
|
155 | - public function isShipped($appId); |
|
156 | - |
|
157 | - /** |
|
158 | - * @return string[] |
|
159 | - * @since 9.0.0 |
|
160 | - */ |
|
161 | - public function getAlwaysEnabledApps(); |
|
162 | - |
|
163 | - /** |
|
164 | - * @param \OCP\IGroup $group |
|
165 | - * @return String[] |
|
166 | - * @since 17.0.0 |
|
167 | - */ |
|
168 | - public function getEnabledAppsForGroup(IGroup $group): array; |
|
169 | - |
|
170 | - /** |
|
171 | - * @param String $appId |
|
172 | - * @return string[] |
|
173 | - * @since 17.0.0 |
|
174 | - */ |
|
175 | - public function getAppRestriction(string $appId): array; |
|
41 | + /** |
|
42 | + * Returns the app information from "appinfo/info.xml". |
|
43 | + * |
|
44 | + * @param string $appId |
|
45 | + * @return mixed |
|
46 | + * @since 14.0.0 |
|
47 | + */ |
|
48 | + public function getAppInfo(string $appId, bool $path = false, $lang = null); |
|
49 | + |
|
50 | + /** |
|
51 | + * Returns the app information from "appinfo/info.xml". |
|
52 | + * |
|
53 | + * @param string $appId |
|
54 | + * @param bool $useCache |
|
55 | + * @return string |
|
56 | + * @since 14.0.0 |
|
57 | + */ |
|
58 | + public function getAppVersion(string $appId, bool $useCache = true): string; |
|
59 | + |
|
60 | + /** |
|
61 | + * Check if an app is enabled for user |
|
62 | + * |
|
63 | + * @param string $appId |
|
64 | + * @param \OCP\IUser $user (optional) if not defined, the currently loggedin user will be used |
|
65 | + * @return bool |
|
66 | + * @since 8.0.0 |
|
67 | + */ |
|
68 | + public function isEnabledForUser($appId, $user = null); |
|
69 | + |
|
70 | + /** |
|
71 | + * Check if an app is enabled in the instance |
|
72 | + * |
|
73 | + * Notice: This actually checks if the app is enabled and not only if it is installed. |
|
74 | + * |
|
75 | + * @param string $appId |
|
76 | + * @return bool |
|
77 | + * @since 8.0.0 |
|
78 | + */ |
|
79 | + public function isInstalled($appId); |
|
80 | + |
|
81 | + /** |
|
82 | + * Enable an app for every user |
|
83 | + * |
|
84 | + * @param string $appId |
|
85 | + * @throws AppPathNotFoundException |
|
86 | + * @since 8.0.0 |
|
87 | + */ |
|
88 | + public function enableApp($appId); |
|
89 | + |
|
90 | + /** |
|
91 | + * Whether a list of types contains a protected app type |
|
92 | + * |
|
93 | + * @param string[] $types |
|
94 | + * @return bool |
|
95 | + * @since 12.0.0 |
|
96 | + */ |
|
97 | + public function hasProtectedAppType($types); |
|
98 | + |
|
99 | + /** |
|
100 | + * Enable an app only for specific groups |
|
101 | + * |
|
102 | + * @param string $appId |
|
103 | + * @param \OCP\IGroup[] $groups |
|
104 | + * @throws \Exception |
|
105 | + * @since 8.0.0 |
|
106 | + */ |
|
107 | + public function enableAppForGroups($appId, $groups); |
|
108 | + |
|
109 | + /** |
|
110 | + * Disable an app for every user |
|
111 | + * |
|
112 | + * @param string $appId |
|
113 | + * @since 8.0.0 |
|
114 | + */ |
|
115 | + public function disableApp($appId); |
|
116 | + |
|
117 | + /** |
|
118 | + * Get the directory for the given app. |
|
119 | + * |
|
120 | + * @param string $appId |
|
121 | + * @return string |
|
122 | + * @since 11.0.0 |
|
123 | + * @throws AppPathNotFoundException |
|
124 | + */ |
|
125 | + public function getAppPath($appId); |
|
126 | + |
|
127 | + /** |
|
128 | + * List all apps enabled for a user |
|
129 | + * |
|
130 | + * @param \OCP\IUser $user |
|
131 | + * @return string[] |
|
132 | + * @since 8.1.0 |
|
133 | + */ |
|
134 | + public function getEnabledAppsForUser(IUser $user); |
|
135 | + |
|
136 | + /** |
|
137 | + * List all installed apps |
|
138 | + * |
|
139 | + * @return string[] |
|
140 | + * @since 8.1.0 |
|
141 | + */ |
|
142 | + public function getInstalledApps(); |
|
143 | + |
|
144 | + /** |
|
145 | + * Clear the cached list of apps when enabling/disabling an app |
|
146 | + * @since 8.1.0 |
|
147 | + */ |
|
148 | + public function clearAppsCache(); |
|
149 | + |
|
150 | + /** |
|
151 | + * @param string $appId |
|
152 | + * @return boolean |
|
153 | + * @since 9.0.0 |
|
154 | + */ |
|
155 | + public function isShipped($appId); |
|
156 | + |
|
157 | + /** |
|
158 | + * @return string[] |
|
159 | + * @since 9.0.0 |
|
160 | + */ |
|
161 | + public function getAlwaysEnabledApps(); |
|
162 | + |
|
163 | + /** |
|
164 | + * @param \OCP\IGroup $group |
|
165 | + * @return String[] |
|
166 | + * @since 17.0.0 |
|
167 | + */ |
|
168 | + public function getEnabledAppsForGroup(IGroup $group): array; |
|
169 | + |
|
170 | + /** |
|
171 | + * @param String $appId |
|
172 | + * @return string[] |
|
173 | + * @since 17.0.0 |
|
174 | + */ |
|
175 | + public function getAppRestriction(string $appId): array; |
|
176 | 176 | } |
@@ -68,1014 +68,1014 @@ |
||
68 | 68 | * OC_autoload! |
69 | 69 | */ |
70 | 70 | class OC { |
71 | - /** |
|
72 | - * Associative array for autoloading. classname => filename |
|
73 | - */ |
|
74 | - public static $CLASSPATH = array(); |
|
75 | - /** |
|
76 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
77 | - */ |
|
78 | - public static $SERVERROOT = ''; |
|
79 | - /** |
|
80 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
81 | - */ |
|
82 | - private static $SUBURI = ''; |
|
83 | - /** |
|
84 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
85 | - */ |
|
86 | - public static $WEBROOT = ''; |
|
87 | - /** |
|
88 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
89 | - * web path in 'url' |
|
90 | - */ |
|
91 | - public static $APPSROOTS = array(); |
|
92 | - |
|
93 | - /** |
|
94 | - * @var string |
|
95 | - */ |
|
96 | - public static $configDir; |
|
97 | - |
|
98 | - /** |
|
99 | - * requested app |
|
100 | - */ |
|
101 | - public static $REQUESTEDAPP = ''; |
|
102 | - |
|
103 | - /** |
|
104 | - * check if Nextcloud runs in cli mode |
|
105 | - */ |
|
106 | - public static $CLI = false; |
|
107 | - |
|
108 | - /** |
|
109 | - * @var \OC\Autoloader $loader |
|
110 | - */ |
|
111 | - public static $loader = null; |
|
112 | - |
|
113 | - /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
114 | - public static $composerAutoloader = null; |
|
115 | - |
|
116 | - /** |
|
117 | - * @var \OC\Server |
|
118 | - */ |
|
119 | - public static $server = null; |
|
120 | - |
|
121 | - /** |
|
122 | - * @var \OC\Config |
|
123 | - */ |
|
124 | - private static $config = null; |
|
125 | - |
|
126 | - /** |
|
127 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
128 | - * the app path list is empty or contains an invalid path |
|
129 | - */ |
|
130 | - public static function initPaths() { |
|
131 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
132 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
133 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
134 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
135 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
136 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
137 | - } else { |
|
138 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
139 | - } |
|
140 | - self::$config = new \OC\Config(self::$configDir); |
|
141 | - |
|
142 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
143 | - /** |
|
144 | - * FIXME: The following lines are required because we can't yet instantiate |
|
145 | - * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
146 | - */ |
|
147 | - $params = [ |
|
148 | - 'server' => [ |
|
149 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
150 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
151 | - ], |
|
152 | - ]; |
|
153 | - $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
154 | - $scriptName = $fakeRequest->getScriptName(); |
|
155 | - if (substr($scriptName, -1) == '/') { |
|
156 | - $scriptName .= 'index.php'; |
|
157 | - //make sure suburi follows the same rules as scriptName |
|
158 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
159 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
160 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
161 | - } |
|
162 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - if (OC::$CLI) { |
|
168 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
169 | - } else { |
|
170 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
171 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
172 | - |
|
173 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
174 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
175 | - } |
|
176 | - } else { |
|
177 | - // The scriptName is not ending with OC::$SUBURI |
|
178 | - // This most likely means that we are calling from CLI. |
|
179 | - // However some cron jobs still need to generate |
|
180 | - // a web URL, so we use overwritewebroot as a fallback. |
|
181 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
182 | - } |
|
183 | - |
|
184 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
185 | - // slash which is required by URL generation. |
|
186 | - if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
187 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
188 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
189 | - exit(); |
|
190 | - } |
|
191 | - } |
|
192 | - |
|
193 | - // search the apps folder |
|
194 | - $config_paths = self::$config->getValue('apps_paths', array()); |
|
195 | - if (!empty($config_paths)) { |
|
196 | - foreach ($config_paths as $paths) { |
|
197 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
198 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
199 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
200 | - OC::$APPSROOTS[] = $paths; |
|
201 | - } |
|
202 | - } |
|
203 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
204 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
205 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
206 | - OC::$APPSROOTS[] = array( |
|
207 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
208 | - 'url' => '/apps', |
|
209 | - 'writable' => true |
|
210 | - ); |
|
211 | - } |
|
212 | - |
|
213 | - if (empty(OC::$APPSROOTS)) { |
|
214 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
215 | - . ' or the folder above. You can also configure the location in the config.php file.'); |
|
216 | - } |
|
217 | - $paths = array(); |
|
218 | - foreach (OC::$APPSROOTS as $path) { |
|
219 | - $paths[] = $path['path']; |
|
220 | - if (!is_dir($path['path'])) { |
|
221 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
222 | - . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
223 | - . ' config.php file.', $path['path'])); |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - // set the right include path |
|
228 | - set_include_path( |
|
229 | - implode(PATH_SEPARATOR, $paths) |
|
230 | - ); |
|
231 | - } |
|
232 | - |
|
233 | - public static function checkConfig() { |
|
234 | - $l = \OC::$server->getL10N('lib'); |
|
235 | - |
|
236 | - // Create config if it does not already exist |
|
237 | - $configFilePath = self::$configDir .'/config.php'; |
|
238 | - if(!file_exists($configFilePath)) { |
|
239 | - @touch($configFilePath); |
|
240 | - } |
|
241 | - |
|
242 | - // Check if config is writable |
|
243 | - $configFileWritable = is_writable($configFilePath); |
|
244 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
245 | - || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
246 | - |
|
247 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
248 | - |
|
249 | - if (self::$CLI) { |
|
250 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
251 | - echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
252 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
253 | - echo "\n"; |
|
254 | - echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
|
255 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
256 | - exit; |
|
257 | - } else { |
|
258 | - OC_Template::printErrorPage( |
|
259 | - $l->t('Cannot write into "config" directory!'), |
|
260 | - $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
261 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
262 | - . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
263 | - [ $urlGenerator->linkToDocs('admin-config') ] ), |
|
264 | - 503 |
|
265 | - ); |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - public static function checkInstalled() { |
|
271 | - if (defined('OC_CONSOLE')) { |
|
272 | - return; |
|
273 | - } |
|
274 | - // Redirect to installer if not installed |
|
275 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
276 | - if (OC::$CLI) { |
|
277 | - throw new Exception('Not installed'); |
|
278 | - } else { |
|
279 | - $url = OC::$WEBROOT . '/index.php'; |
|
280 | - header('Location: ' . $url); |
|
281 | - } |
|
282 | - exit(); |
|
283 | - } |
|
284 | - } |
|
285 | - |
|
286 | - public static function checkMaintenanceMode() { |
|
287 | - // Allow ajax update script to execute without being stopped |
|
288 | - if (((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { |
|
289 | - // send http status 503 |
|
290 | - http_response_code(503); |
|
291 | - header('Retry-After: 120'); |
|
292 | - |
|
293 | - // render error page |
|
294 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
295 | - OC_Util::addScript('dist/maintenance'); |
|
296 | - OC_Util::addStyle('core', 'guest'); |
|
297 | - $template->printPage(); |
|
298 | - die(); |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Prints the upgrade page |
|
304 | - * |
|
305 | - * @param \OC\SystemConfig $systemConfig |
|
306 | - */ |
|
307 | - private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
308 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
309 | - $tooBig = false; |
|
310 | - if (!$disableWebUpdater) { |
|
311 | - $apps = \OC::$server->getAppManager(); |
|
312 | - if ($apps->isInstalled('user_ldap')) { |
|
313 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
314 | - |
|
315 | - $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
316 | - ->from('ldap_user_mapping') |
|
317 | - ->execute(); |
|
318 | - $row = $result->fetch(); |
|
319 | - $result->closeCursor(); |
|
320 | - |
|
321 | - $tooBig = ($row['user_count'] > 50); |
|
322 | - } |
|
323 | - if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
324 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
325 | - |
|
326 | - $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
327 | - ->from('user_saml_users') |
|
328 | - ->execute(); |
|
329 | - $row = $result->fetch(); |
|
330 | - $result->closeCursor(); |
|
331 | - |
|
332 | - $tooBig = ($row['user_count'] > 50); |
|
333 | - } |
|
334 | - if (!$tooBig) { |
|
335 | - // count users |
|
336 | - $stats = \OC::$server->getUserManager()->countUsers(); |
|
337 | - $totalUsers = array_sum($stats); |
|
338 | - $tooBig = ($totalUsers > 50); |
|
339 | - } |
|
340 | - } |
|
341 | - $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
342 | - $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
343 | - |
|
344 | - if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
345 | - // send http status 503 |
|
346 | - http_response_code(503); |
|
347 | - header('Retry-After: 120'); |
|
348 | - |
|
349 | - // render error page |
|
350 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
351 | - $template->assign('productName', 'nextcloud'); // for now |
|
352 | - $template->assign('version', OC_Util::getVersionString()); |
|
353 | - $template->assign('tooBig', $tooBig); |
|
354 | - |
|
355 | - $template->printPage(); |
|
356 | - die(); |
|
357 | - } |
|
358 | - |
|
359 | - // check whether this is a core update or apps update |
|
360 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
361 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
362 | - |
|
363 | - // if not a core upgrade, then it's apps upgrade |
|
364 | - $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
365 | - |
|
366 | - $oldTheme = $systemConfig->getValue('theme'); |
|
367 | - $systemConfig->setValue('theme', ''); |
|
368 | - OC_Util::addScript('config'); // needed for web root |
|
369 | - OC_Util::addScript('update'); |
|
370 | - |
|
371 | - /** @var \OC\App\AppManager $appManager */ |
|
372 | - $appManager = \OC::$server->getAppManager(); |
|
373 | - |
|
374 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
375 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
376 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
377 | - |
|
378 | - // get third party apps |
|
379 | - $ocVersion = \OCP\Util::getVersion(); |
|
380 | - $ocVersion = implode('.', $ocVersion); |
|
381 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
382 | - $incompatibleShippedApps = []; |
|
383 | - foreach ($incompatibleApps as $appInfo) { |
|
384 | - if ($appManager->isShipped($appInfo['id'])) { |
|
385 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - if (!empty($incompatibleShippedApps)) { |
|
390 | - $l = \OC::$server->getL10N('core'); |
|
391 | - $hint = $l->t('The files of the app %1$s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
392 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
393 | - } |
|
394 | - |
|
395 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
396 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
397 | - $tmpl->assign('productName', 'Nextcloud'); // for now |
|
398 | - $tmpl->assign('oldTheme', $oldTheme); |
|
399 | - $tmpl->printPage(); |
|
400 | - } |
|
401 | - |
|
402 | - public static function initSession() { |
|
403 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
404 | - ini_set('session.cookie_secure', true); |
|
405 | - } |
|
406 | - |
|
407 | - // prevents javascript from accessing php session cookies |
|
408 | - ini_set('session.cookie_httponly', 'true'); |
|
409 | - |
|
410 | - // set the cookie path to the Nextcloud directory |
|
411 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
412 | - ini_set('session.cookie_path', $cookie_path); |
|
413 | - |
|
414 | - // Let the session name be changed in the initSession Hook |
|
415 | - $sessionName = OC_Util::getInstanceId(); |
|
416 | - |
|
417 | - try { |
|
418 | - // Allow session apps to create a custom session object |
|
419 | - $useCustomSession = false; |
|
420 | - $session = self::$server->getSession(); |
|
421 | - OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
422 | - if (!$useCustomSession) { |
|
423 | - // set the session name to the instance id - which is unique |
|
424 | - $session = new \OC\Session\Internal($sessionName); |
|
425 | - } |
|
426 | - |
|
427 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
428 | - $session = $cryptoWrapper->wrapSession($session); |
|
429 | - self::$server->setSession($session); |
|
430 | - |
|
431 | - // if session can't be started break with http 500 error |
|
432 | - } catch (Exception $e) { |
|
433 | - \OC::$server->getLogger()->logException($e, ['app' => 'base']); |
|
434 | - //show the user a detailed error page |
|
435 | - OC_Template::printExceptionErrorPage($e, 500); |
|
436 | - die(); |
|
437 | - } |
|
438 | - |
|
439 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
440 | - |
|
441 | - // session timeout |
|
442 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
443 | - if (isset($_COOKIE[session_name()])) { |
|
444 | - setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
445 | - } |
|
446 | - \OC::$server->getUserSession()->logout(); |
|
447 | - } |
|
448 | - |
|
449 | - $session->set('LAST_ACTIVITY', time()); |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * @return string |
|
454 | - */ |
|
455 | - private static function getSessionLifeTime() { |
|
456 | - return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Try to set some values to the required Nextcloud default |
|
461 | - */ |
|
462 | - public static function setRequiredIniValues() { |
|
463 | - @ini_set('default_charset', 'UTF-8'); |
|
464 | - @ini_set('gd.jpeg_ignore_warning', '1'); |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Send the same site cookies |
|
469 | - */ |
|
470 | - private static function sendSameSiteCookies() { |
|
471 | - $cookieParams = session_get_cookie_params(); |
|
472 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
473 | - $policies = [ |
|
474 | - 'lax', |
|
475 | - 'strict', |
|
476 | - ]; |
|
477 | - |
|
478 | - // Append __Host to the cookie if it meets the requirements |
|
479 | - $cookiePrefix = ''; |
|
480 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
481 | - $cookiePrefix = '__Host-'; |
|
482 | - } |
|
483 | - |
|
484 | - foreach($policies as $policy) { |
|
485 | - header( |
|
486 | - sprintf( |
|
487 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
488 | - $cookiePrefix, |
|
489 | - $policy, |
|
490 | - $cookieParams['path'], |
|
491 | - $policy |
|
492 | - ), |
|
493 | - false |
|
494 | - ); |
|
495 | - } |
|
496 | - } |
|
497 | - |
|
498 | - /** |
|
499 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
500 | - * be set in every request if cookies are sent to add a second level of |
|
501 | - * defense against CSRF. |
|
502 | - * |
|
503 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
504 | - * We use an additional cookie since we want to protect logout CSRF and |
|
505 | - * also we can't directly interfere with PHP's session mechanism. |
|
506 | - */ |
|
507 | - private static function performSameSiteCookieProtection() { |
|
508 | - $request = \OC::$server->getRequest(); |
|
509 | - |
|
510 | - // Some user agents are notorious and don't really properly follow HTTP |
|
511 | - // specifications. For those, have an automated opt-out. Since the protection |
|
512 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
513 | - // here. |
|
514 | - $incompatibleUserAgents = \OC::$server->getConfig()->getSystemValue('csrf.optout'); |
|
515 | - |
|
516 | - // Fallback, if csrf.optout is unset |
|
517 | - if (!is_array($incompatibleUserAgents)) { |
|
518 | - $incompatibleUserAgents = [ |
|
519 | - // OS X Finder |
|
520 | - '/^WebDAVFS/', |
|
521 | - // Windows webdav drive |
|
522 | - '/^Microsoft-WebDAV-MiniRedir/', |
|
523 | - ]; |
|
524 | - } |
|
525 | - |
|
526 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
527 | - return; |
|
528 | - } |
|
529 | - |
|
530 | - if(count($_COOKIE) > 0) { |
|
531 | - $requestUri = $request->getScriptName(); |
|
532 | - $processingScript = explode('/', $requestUri); |
|
533 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
534 | - |
|
535 | - // index.php routes are handled in the middleware |
|
536 | - if($processingScript === 'index.php') { |
|
537 | - return; |
|
538 | - } |
|
539 | - |
|
540 | - // All other endpoints require the lax and the strict cookie |
|
541 | - if(!$request->passesStrictCookieCheck()) { |
|
542 | - self::sendSameSiteCookies(); |
|
543 | - // Debug mode gets access to the resources without strict cookie |
|
544 | - // due to the fact that the SabreDAV browser also lives there. |
|
545 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
546 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
547 | - exit(); |
|
548 | - } |
|
549 | - } |
|
550 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
551 | - self::sendSameSiteCookies(); |
|
552 | - } |
|
553 | - } |
|
554 | - |
|
555 | - public static function init() { |
|
556 | - // calculate the root directories |
|
557 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
558 | - |
|
559 | - // register autoloader |
|
560 | - $loaderStart = microtime(true); |
|
561 | - require_once __DIR__ . '/autoloader.php'; |
|
562 | - self::$loader = new \OC\Autoloader([ |
|
563 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
564 | - ]); |
|
565 | - if (defined('PHPUNIT_RUN')) { |
|
566 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
567 | - } |
|
568 | - spl_autoload_register(array(self::$loader, 'load')); |
|
569 | - $loaderEnd = microtime(true); |
|
570 | - |
|
571 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
572 | - |
|
573 | - // Add default composer PSR-4 autoloader |
|
574 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
575 | - |
|
576 | - try { |
|
577 | - self::initPaths(); |
|
578 | - // setup 3rdparty autoloader |
|
579 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
580 | - if (!file_exists($vendorAutoLoad)) { |
|
581 | - throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
582 | - } |
|
583 | - require_once $vendorAutoLoad; |
|
584 | - |
|
585 | - } catch (\RuntimeException $e) { |
|
586 | - if (!self::$CLI) { |
|
587 | - http_response_code(503); |
|
588 | - } |
|
589 | - // we can't use the template error page here, because this needs the |
|
590 | - // DI container which isn't available yet |
|
591 | - print($e->getMessage()); |
|
592 | - exit(); |
|
593 | - } |
|
594 | - |
|
595 | - // setup the basic server |
|
596 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
597 | - \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
598 | - \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
599 | - |
|
600 | - // Don't display errors and log them |
|
601 | - error_reporting(E_ALL | E_STRICT); |
|
602 | - @ini_set('display_errors', '0'); |
|
603 | - @ini_set('log_errors', '1'); |
|
604 | - |
|
605 | - if(!date_default_timezone_set('UTC')) { |
|
606 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
607 | - } |
|
608 | - |
|
609 | - //try to configure php to enable big file uploads. |
|
610 | - //this doesn´t work always depending on the webserver and php configuration. |
|
611 | - //Let´s try to overwrite some defaults anyway |
|
612 | - |
|
613 | - //try to set the maximum execution time to 60min |
|
614 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
615 | - @set_time_limit(3600); |
|
616 | - } |
|
617 | - @ini_set('max_execution_time', '3600'); |
|
618 | - @ini_set('max_input_time', '3600'); |
|
619 | - |
|
620 | - //try to set the maximum filesize to 10G |
|
621 | - @ini_set('upload_max_filesize', '10G'); |
|
622 | - @ini_set('post_max_size', '10G'); |
|
623 | - @ini_set('file_uploads', '50'); |
|
624 | - |
|
625 | - self::setRequiredIniValues(); |
|
626 | - self::handleAuthHeaders(); |
|
627 | - self::registerAutoloaderCache(); |
|
628 | - |
|
629 | - // initialize intl fallback is necessary |
|
630 | - \Patchwork\Utf8\Bootup::initIntl(); |
|
631 | - OC_Util::isSetLocaleWorking(); |
|
632 | - |
|
633 | - if (!defined('PHPUNIT_RUN')) { |
|
634 | - OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
635 | - $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
636 | - OC\Log\ErrorHandler::register($debug); |
|
637 | - } |
|
638 | - |
|
639 | - \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
640 | - OC_App::loadApps(array('session')); |
|
641 | - if (!self::$CLI) { |
|
642 | - self::initSession(); |
|
643 | - } |
|
644 | - \OC::$server->getEventLogger()->end('init_session'); |
|
645 | - self::checkConfig(); |
|
646 | - self::checkInstalled(); |
|
647 | - |
|
648 | - OC_Response::addSecurityHeaders(); |
|
649 | - |
|
650 | - self::performSameSiteCookieProtection(); |
|
651 | - |
|
652 | - if (!defined('OC_CONSOLE')) { |
|
653 | - $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
654 | - if (count($errors) > 0) { |
|
655 | - if (self::$CLI) { |
|
656 | - // Convert l10n string into regular string for usage in database |
|
657 | - $staticErrors = []; |
|
658 | - foreach ($errors as $error) { |
|
659 | - echo $error['error'] . "\n"; |
|
660 | - echo $error['hint'] . "\n\n"; |
|
661 | - $staticErrors[] = [ |
|
662 | - 'error' => (string)$error['error'], |
|
663 | - 'hint' => (string)$error['hint'], |
|
664 | - ]; |
|
665 | - } |
|
666 | - |
|
667 | - try { |
|
668 | - \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
669 | - } catch (\Exception $e) { |
|
670 | - echo('Writing to database failed'); |
|
671 | - } |
|
672 | - exit(1); |
|
673 | - } else { |
|
674 | - http_response_code(503); |
|
675 | - OC_Util::addStyle('guest'); |
|
676 | - OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
677 | - exit; |
|
678 | - } |
|
679 | - } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
680 | - \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
681 | - } |
|
682 | - } |
|
683 | - //try to set the session lifetime |
|
684 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
685 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
686 | - |
|
687 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
688 | - |
|
689 | - // User and Groups |
|
690 | - if (!$systemConfig->getValue("installed", false)) { |
|
691 | - self::$server->getSession()->set('user_id', ''); |
|
692 | - } |
|
693 | - |
|
694 | - OC_User::useBackend(new \OC\User\Database()); |
|
695 | - \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
696 | - |
|
697 | - // Subscribe to the hook |
|
698 | - \OCP\Util::connectHook( |
|
699 | - '\OCA\Files_Sharing\API\Server2Server', |
|
700 | - 'preLoginNameUsedAsUserName', |
|
701 | - '\OC\User\Database', |
|
702 | - 'preLoginNameUsedAsUserName' |
|
703 | - ); |
|
704 | - |
|
705 | - //setup extra user backends |
|
706 | - if (!\OCP\Util::needUpgrade()) { |
|
707 | - OC_User::setupBackends(); |
|
708 | - } else { |
|
709 | - // Run upgrades in incognito mode |
|
710 | - OC_User::setIncognitoMode(true); |
|
711 | - } |
|
712 | - |
|
713 | - self::registerCleanupHooks(); |
|
714 | - self::registerFilesystemHooks(); |
|
715 | - self::registerShareHooks(); |
|
716 | - self::registerEncryptionWrapper(); |
|
717 | - self::registerEncryptionHooks(); |
|
718 | - self::registerAccountHooks(); |
|
719 | - self::registerResourceCollectionHooks(); |
|
720 | - self::registerAppRestrictionsHooks(); |
|
721 | - |
|
722 | - // Make sure that the application class is not loaded before the database is setup |
|
723 | - if ($systemConfig->getValue("installed", false)) { |
|
724 | - $settings = new \OC\Settings\Application(); |
|
725 | - $settings->register(); |
|
726 | - } |
|
727 | - |
|
728 | - //make sure temporary files are cleaned up |
|
729 | - $tmpManager = \OC::$server->getTempManager(); |
|
730 | - register_shutdown_function(array($tmpManager, 'clean')); |
|
731 | - $lockProvider = \OC::$server->getLockingProvider(); |
|
732 | - register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
733 | - |
|
734 | - // Check whether the sample configuration has been copied |
|
735 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
736 | - $l = \OC::$server->getL10N('lib'); |
|
737 | - OC_Template::printErrorPage( |
|
738 | - $l->t('Sample configuration detected'), |
|
739 | - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), |
|
740 | - 503 |
|
741 | - ); |
|
742 | - return; |
|
743 | - } |
|
744 | - |
|
745 | - $request = \OC::$server->getRequest(); |
|
746 | - $host = $request->getInsecureServerHost(); |
|
747 | - /** |
|
748 | - * if the host passed in headers isn't trusted |
|
749 | - * FIXME: Should not be in here at all :see_no_evil: |
|
750 | - */ |
|
751 | - if (!OC::$CLI |
|
752 | - // overwritehost is always trusted, workaround to not have to make |
|
753 | - // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
754 | - && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
755 | - && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
756 | - && self::$server->getConfig()->getSystemValue('installed', false) |
|
757 | - ) { |
|
758 | - // Allow access to CSS resources |
|
759 | - $isScssRequest = false; |
|
760 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
761 | - $isScssRequest = true; |
|
762 | - } |
|
763 | - |
|
764 | - if(substr($request->getRequestUri(), -11) === '/status.php') { |
|
765 | - http_response_code(400); |
|
766 | - header('Content-Type: application/json'); |
|
767 | - echo '{"error": "Trusted domain error.", "code": 15}'; |
|
768 | - exit(); |
|
769 | - } |
|
770 | - |
|
771 | - if (!$isScssRequest) { |
|
772 | - http_response_code(400); |
|
773 | - |
|
774 | - \OC::$server->getLogger()->info( |
|
775 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
776 | - [ |
|
777 | - 'app' => 'core', |
|
778 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
779 | - 'host' => $host, |
|
780 | - ] |
|
781 | - ); |
|
782 | - |
|
783 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
784 | - $tmpl->assign('docUrl', \OC::$server->getURLGenerator()->linkToDocs('admin-trusted-domains')); |
|
785 | - $tmpl->printPage(); |
|
786 | - |
|
787 | - exit(); |
|
788 | - } |
|
789 | - } |
|
790 | - \OC::$server->getEventLogger()->end('boot'); |
|
791 | - } |
|
792 | - |
|
793 | - /** |
|
794 | - * register hooks for the cleanup of cache and bruteforce protection |
|
795 | - */ |
|
796 | - public static function registerCleanupHooks() { |
|
797 | - //don't try to do this before we are properly setup |
|
798 | - if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
799 | - |
|
800 | - // NOTE: This will be replaced to use OCP |
|
801 | - $userSession = self::$server->getUserSession(); |
|
802 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
803 | - if (!defined('PHPUNIT_RUN')) { |
|
804 | - // reset brute force delay for this IP address and username |
|
805 | - $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
806 | - $request = \OC::$server->getRequest(); |
|
807 | - $throttler = \OC::$server->getBruteForceThrottler(); |
|
808 | - $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
809 | - } |
|
810 | - |
|
811 | - try { |
|
812 | - $cache = new \OC\Cache\File(); |
|
813 | - $cache->gc(); |
|
814 | - } catch (\OC\ServerNotAvailableException $e) { |
|
815 | - // not a GC exception, pass it on |
|
816 | - throw $e; |
|
817 | - } catch (\OC\ForbiddenException $e) { |
|
818 | - // filesystem blocked for this request, ignore |
|
819 | - } catch (\Exception $e) { |
|
820 | - // a GC exception should not prevent users from using OC, |
|
821 | - // so log the exception |
|
822 | - \OC::$server->getLogger()->logException($e, [ |
|
823 | - 'message' => 'Exception when running cache gc.', |
|
824 | - 'level' => ILogger::WARN, |
|
825 | - 'app' => 'core', |
|
826 | - ]); |
|
827 | - } |
|
828 | - }); |
|
829 | - } |
|
830 | - } |
|
831 | - |
|
832 | - private static function registerEncryptionWrapper() { |
|
833 | - $manager = self::$server->getEncryptionManager(); |
|
834 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
835 | - } |
|
836 | - |
|
837 | - private static function registerEncryptionHooks() { |
|
838 | - $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
839 | - if ($enabled) { |
|
840 | - \OCP\Util::connectHook(Share::class, 'post_shared', HookManager::class, 'postShared'); |
|
841 | - \OCP\Util::connectHook(Share::class, 'post_unshare', HookManager::class, 'postUnshared'); |
|
842 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', HookManager::class, 'postRename'); |
|
843 | - \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', HookManager::class, 'postRestore'); |
|
844 | - } |
|
845 | - } |
|
846 | - |
|
847 | - private static function registerAccountHooks() { |
|
848 | - $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
849 | - \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
850 | - } |
|
851 | - |
|
852 | - private static function registerAppRestrictionsHooks() { |
|
853 | - $groupManager = self::$server->query(\OCP\IGroupManager::class); |
|
854 | - $groupManager->listen ('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
855 | - $appManager = self::$server->getAppManager(); |
|
856 | - $apps = $appManager->getEnabledAppsForGroup($group); |
|
857 | - foreach ($apps as $appId) { |
|
858 | - $restrictions = $appManager->getAppRestriction($appId); |
|
859 | - if (empty($restrictions)) { |
|
860 | - continue; |
|
861 | - } |
|
862 | - $key = array_search($group->getGID(), $restrictions); |
|
863 | - unset($restrictions[$key]); |
|
864 | - $restrictions = array_values($restrictions); |
|
865 | - if (empty($restrictions)) { |
|
866 | - $appManager->disableApp($appId); |
|
867 | - } |
|
868 | - else{ |
|
869 | - $appManager->enableAppForGroups($appId, $restrictions); |
|
870 | - } |
|
871 | - |
|
872 | - } |
|
873 | - }); |
|
874 | - } |
|
875 | - |
|
876 | - private static function registerResourceCollectionHooks() { |
|
877 | - \OC\Collaboration\Resources\Listener::register(\OC::$server->getEventDispatcher()); |
|
878 | - } |
|
879 | - |
|
880 | - /** |
|
881 | - * register hooks for the filesystem |
|
882 | - */ |
|
883 | - public static function registerFilesystemHooks() { |
|
884 | - // Check for blacklisted files |
|
885 | - OC_Hook::connect('OC_Filesystem', 'write', Filesystem::class, 'isBlacklisted'); |
|
886 | - OC_Hook::connect('OC_Filesystem', 'rename', Filesystem::class, 'isBlacklisted'); |
|
887 | - } |
|
888 | - |
|
889 | - /** |
|
890 | - * register hooks for sharing |
|
891 | - */ |
|
892 | - public static function registerShareHooks() { |
|
893 | - if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
894 | - OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); |
|
895 | - OC_Hook::connect('OC_User', 'post_removeFromGroup', Hooks::class, 'post_removeFromGroup'); |
|
896 | - OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); |
|
897 | - } |
|
898 | - } |
|
899 | - |
|
900 | - protected static function registerAutoloaderCache() { |
|
901 | - // The class loader takes an optional low-latency cache, which MUST be |
|
902 | - // namespaced. The instanceid is used for namespacing, but might be |
|
903 | - // unavailable at this point. Furthermore, it might not be possible to |
|
904 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
905 | - // config file may not be writable. As such, we only register a class |
|
906 | - // loader cache if instanceid is available without trying to create one. |
|
907 | - $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
908 | - if ($instanceId) { |
|
909 | - try { |
|
910 | - $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
911 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
912 | - } catch (\Exception $ex) { |
|
913 | - } |
|
914 | - } |
|
915 | - } |
|
916 | - |
|
917 | - /** |
|
918 | - * Handle the request |
|
919 | - */ |
|
920 | - public static function handleRequest() { |
|
921 | - |
|
922 | - \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
923 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
924 | - |
|
925 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
926 | - if (!$systemConfig->getValue('installed', false)) { |
|
927 | - \OC::$server->getSession()->clear(); |
|
928 | - $setupHelper = new OC\Setup( |
|
929 | - $systemConfig, |
|
930 | - \OC::$server->getIniWrapper(), |
|
931 | - \OC::$server->getL10N('lib'), |
|
932 | - \OC::$server->query(\OCP\Defaults::class), |
|
933 | - \OC::$server->getLogger(), |
|
934 | - \OC::$server->getSecureRandom(), |
|
935 | - \OC::$server->query(\OC\Installer::class) |
|
936 | - ); |
|
937 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
938 | - $controller->run($_POST); |
|
939 | - exit(); |
|
940 | - } |
|
941 | - |
|
942 | - $request = \OC::$server->getRequest(); |
|
943 | - $requestPath = $request->getRawPathInfo(); |
|
944 | - if ($requestPath === '/heartbeat') { |
|
945 | - return; |
|
946 | - } |
|
947 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
948 | - self::checkMaintenanceMode(); |
|
949 | - |
|
950 | - if (\OCP\Util::needUpgrade()) { |
|
951 | - if (function_exists('opcache_reset')) { |
|
952 | - opcache_reset(); |
|
953 | - } |
|
954 | - if (!((bool) $systemConfig->getValue('maintenance', false))) { |
|
955 | - self::printUpgradePage($systemConfig); |
|
956 | - exit(); |
|
957 | - } |
|
958 | - } |
|
959 | - } |
|
960 | - |
|
961 | - // emergency app disabling |
|
962 | - if ($requestPath === '/disableapp' |
|
963 | - && $request->getMethod() === 'POST' |
|
964 | - && ((array)$request->getParam('appid')) !== '' |
|
965 | - ) { |
|
966 | - \OC_JSON::callCheck(); |
|
967 | - \OC_JSON::checkAdminUser(); |
|
968 | - $appIds = (array)$request->getParam('appid'); |
|
969 | - foreach($appIds as $appId) { |
|
970 | - $appId = \OC_App::cleanAppId($appId); |
|
971 | - \OC::$server->getAppManager()->disableApp($appId); |
|
972 | - } |
|
973 | - \OC_JSON::success(); |
|
974 | - exit(); |
|
975 | - } |
|
976 | - |
|
977 | - // Always load authentication apps |
|
978 | - OC_App::loadApps(['authentication']); |
|
979 | - |
|
980 | - // Load minimum set of apps |
|
981 | - if (!\OCP\Util::needUpgrade() |
|
982 | - && !((bool) $systemConfig->getValue('maintenance', false))) { |
|
983 | - // For logged-in users: Load everything |
|
984 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
985 | - OC_App::loadApps(); |
|
986 | - } else { |
|
987 | - // For guests: Load only filesystem and logging |
|
988 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
989 | - self::handleLogin($request); |
|
990 | - } |
|
991 | - } |
|
992 | - |
|
993 | - if (!self::$CLI) { |
|
994 | - try { |
|
995 | - if (!((bool) $systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) { |
|
996 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
997 | - OC_App::loadApps(); |
|
998 | - } |
|
999 | - OC_Util::setupFS(); |
|
1000 | - OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
1001 | - return; |
|
1002 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
1003 | - //header('HTTP/1.0 404 Not Found'); |
|
1004 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
1005 | - http_response_code(405); |
|
1006 | - return; |
|
1007 | - } |
|
1008 | - } |
|
1009 | - |
|
1010 | - // Handle WebDAV |
|
1011 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
1012 | - // not allowed any more to prevent people |
|
1013 | - // mounting this root directly. |
|
1014 | - // Users need to mount remote.php/webdav instead. |
|
1015 | - http_response_code(405); |
|
1016 | - return; |
|
1017 | - } |
|
1018 | - |
|
1019 | - // Someone is logged in |
|
1020 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1021 | - OC_App::loadApps(); |
|
1022 | - OC_User::setupBackends(); |
|
1023 | - OC_Util::setupFS(); |
|
1024 | - // FIXME |
|
1025 | - // Redirect to default application |
|
1026 | - OC_Util::redirectToDefaultPage(); |
|
1027 | - } else { |
|
1028 | - // Not handled and not logged in |
|
1029 | - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1030 | - } |
|
1031 | - } |
|
1032 | - |
|
1033 | - /** |
|
1034 | - * Check login: apache auth, auth token, basic auth |
|
1035 | - * |
|
1036 | - * @param OCP\IRequest $request |
|
1037 | - * @return boolean |
|
1038 | - */ |
|
1039 | - static function handleLogin(OCP\IRequest $request) { |
|
1040 | - $userSession = self::$server->getUserSession(); |
|
1041 | - if (OC_User::handleApacheAuth()) { |
|
1042 | - return true; |
|
1043 | - } |
|
1044 | - if ($userSession->tryTokenLogin($request)) { |
|
1045 | - return true; |
|
1046 | - } |
|
1047 | - if (isset($_COOKIE['nc_username']) |
|
1048 | - && isset($_COOKIE['nc_token']) |
|
1049 | - && isset($_COOKIE['nc_session_id']) |
|
1050 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1051 | - return true; |
|
1052 | - } |
|
1053 | - if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
1054 | - return true; |
|
1055 | - } |
|
1056 | - return false; |
|
1057 | - } |
|
1058 | - |
|
1059 | - protected static function handleAuthHeaders() { |
|
1060 | - //copy http auth headers for apache+php-fcgid work around |
|
1061 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1062 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1063 | - } |
|
1064 | - |
|
1065 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1066 | - $vars = array( |
|
1067 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1068 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1069 | - ); |
|
1070 | - foreach ($vars as $var) { |
|
1071 | - if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1072 | - list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
1073 | - $_SERVER['PHP_AUTH_USER'] = $name; |
|
1074 | - $_SERVER['PHP_AUTH_PW'] = $password; |
|
1075 | - break; |
|
1076 | - } |
|
1077 | - } |
|
1078 | - } |
|
71 | + /** |
|
72 | + * Associative array for autoloading. classname => filename |
|
73 | + */ |
|
74 | + public static $CLASSPATH = array(); |
|
75 | + /** |
|
76 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
77 | + */ |
|
78 | + public static $SERVERROOT = ''; |
|
79 | + /** |
|
80 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
81 | + */ |
|
82 | + private static $SUBURI = ''; |
|
83 | + /** |
|
84 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
85 | + */ |
|
86 | + public static $WEBROOT = ''; |
|
87 | + /** |
|
88 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
89 | + * web path in 'url' |
|
90 | + */ |
|
91 | + public static $APPSROOTS = array(); |
|
92 | + |
|
93 | + /** |
|
94 | + * @var string |
|
95 | + */ |
|
96 | + public static $configDir; |
|
97 | + |
|
98 | + /** |
|
99 | + * requested app |
|
100 | + */ |
|
101 | + public static $REQUESTEDAPP = ''; |
|
102 | + |
|
103 | + /** |
|
104 | + * check if Nextcloud runs in cli mode |
|
105 | + */ |
|
106 | + public static $CLI = false; |
|
107 | + |
|
108 | + /** |
|
109 | + * @var \OC\Autoloader $loader |
|
110 | + */ |
|
111 | + public static $loader = null; |
|
112 | + |
|
113 | + /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
114 | + public static $composerAutoloader = null; |
|
115 | + |
|
116 | + /** |
|
117 | + * @var \OC\Server |
|
118 | + */ |
|
119 | + public static $server = null; |
|
120 | + |
|
121 | + /** |
|
122 | + * @var \OC\Config |
|
123 | + */ |
|
124 | + private static $config = null; |
|
125 | + |
|
126 | + /** |
|
127 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
128 | + * the app path list is empty or contains an invalid path |
|
129 | + */ |
|
130 | + public static function initPaths() { |
|
131 | + if(defined('PHPUNIT_CONFIG_DIR')) { |
|
132 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
133 | + } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
134 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
135 | + } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
136 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
137 | + } else { |
|
138 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
139 | + } |
|
140 | + self::$config = new \OC\Config(self::$configDir); |
|
141 | + |
|
142 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
143 | + /** |
|
144 | + * FIXME: The following lines are required because we can't yet instantiate |
|
145 | + * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
146 | + */ |
|
147 | + $params = [ |
|
148 | + 'server' => [ |
|
149 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
150 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
151 | + ], |
|
152 | + ]; |
|
153 | + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
154 | + $scriptName = $fakeRequest->getScriptName(); |
|
155 | + if (substr($scriptName, -1) == '/') { |
|
156 | + $scriptName .= 'index.php'; |
|
157 | + //make sure suburi follows the same rules as scriptName |
|
158 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
159 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
160 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
161 | + } |
|
162 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + if (OC::$CLI) { |
|
168 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
169 | + } else { |
|
170 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
171 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
172 | + |
|
173 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
174 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
175 | + } |
|
176 | + } else { |
|
177 | + // The scriptName is not ending with OC::$SUBURI |
|
178 | + // This most likely means that we are calling from CLI. |
|
179 | + // However some cron jobs still need to generate |
|
180 | + // a web URL, so we use overwritewebroot as a fallback. |
|
181 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
182 | + } |
|
183 | + |
|
184 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
185 | + // slash which is required by URL generation. |
|
186 | + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
187 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
188 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
189 | + exit(); |
|
190 | + } |
|
191 | + } |
|
192 | + |
|
193 | + // search the apps folder |
|
194 | + $config_paths = self::$config->getValue('apps_paths', array()); |
|
195 | + if (!empty($config_paths)) { |
|
196 | + foreach ($config_paths as $paths) { |
|
197 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
198 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
199 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
200 | + OC::$APPSROOTS[] = $paths; |
|
201 | + } |
|
202 | + } |
|
203 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
204 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
205 | + } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
206 | + OC::$APPSROOTS[] = array( |
|
207 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
208 | + 'url' => '/apps', |
|
209 | + 'writable' => true |
|
210 | + ); |
|
211 | + } |
|
212 | + |
|
213 | + if (empty(OC::$APPSROOTS)) { |
|
214 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
215 | + . ' or the folder above. You can also configure the location in the config.php file.'); |
|
216 | + } |
|
217 | + $paths = array(); |
|
218 | + foreach (OC::$APPSROOTS as $path) { |
|
219 | + $paths[] = $path['path']; |
|
220 | + if (!is_dir($path['path'])) { |
|
221 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
222 | + . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
223 | + . ' config.php file.', $path['path'])); |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + // set the right include path |
|
228 | + set_include_path( |
|
229 | + implode(PATH_SEPARATOR, $paths) |
|
230 | + ); |
|
231 | + } |
|
232 | + |
|
233 | + public static function checkConfig() { |
|
234 | + $l = \OC::$server->getL10N('lib'); |
|
235 | + |
|
236 | + // Create config if it does not already exist |
|
237 | + $configFilePath = self::$configDir .'/config.php'; |
|
238 | + if(!file_exists($configFilePath)) { |
|
239 | + @touch($configFilePath); |
|
240 | + } |
|
241 | + |
|
242 | + // Check if config is writable |
|
243 | + $configFileWritable = is_writable($configFilePath); |
|
244 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
245 | + || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
246 | + |
|
247 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
248 | + |
|
249 | + if (self::$CLI) { |
|
250 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
251 | + echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
252 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
253 | + echo "\n"; |
|
254 | + echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
|
255 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
256 | + exit; |
|
257 | + } else { |
|
258 | + OC_Template::printErrorPage( |
|
259 | + $l->t('Cannot write into "config" directory!'), |
|
260 | + $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
261 | + [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
262 | + . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
263 | + [ $urlGenerator->linkToDocs('admin-config') ] ), |
|
264 | + 503 |
|
265 | + ); |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + public static function checkInstalled() { |
|
271 | + if (defined('OC_CONSOLE')) { |
|
272 | + return; |
|
273 | + } |
|
274 | + // Redirect to installer if not installed |
|
275 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
276 | + if (OC::$CLI) { |
|
277 | + throw new Exception('Not installed'); |
|
278 | + } else { |
|
279 | + $url = OC::$WEBROOT . '/index.php'; |
|
280 | + header('Location: ' . $url); |
|
281 | + } |
|
282 | + exit(); |
|
283 | + } |
|
284 | + } |
|
285 | + |
|
286 | + public static function checkMaintenanceMode() { |
|
287 | + // Allow ajax update script to execute without being stopped |
|
288 | + if (((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { |
|
289 | + // send http status 503 |
|
290 | + http_response_code(503); |
|
291 | + header('Retry-After: 120'); |
|
292 | + |
|
293 | + // render error page |
|
294 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
295 | + OC_Util::addScript('dist/maintenance'); |
|
296 | + OC_Util::addStyle('core', 'guest'); |
|
297 | + $template->printPage(); |
|
298 | + die(); |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Prints the upgrade page |
|
304 | + * |
|
305 | + * @param \OC\SystemConfig $systemConfig |
|
306 | + */ |
|
307 | + private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
308 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
309 | + $tooBig = false; |
|
310 | + if (!$disableWebUpdater) { |
|
311 | + $apps = \OC::$server->getAppManager(); |
|
312 | + if ($apps->isInstalled('user_ldap')) { |
|
313 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
314 | + |
|
315 | + $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
316 | + ->from('ldap_user_mapping') |
|
317 | + ->execute(); |
|
318 | + $row = $result->fetch(); |
|
319 | + $result->closeCursor(); |
|
320 | + |
|
321 | + $tooBig = ($row['user_count'] > 50); |
|
322 | + } |
|
323 | + if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
324 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
325 | + |
|
326 | + $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
327 | + ->from('user_saml_users') |
|
328 | + ->execute(); |
|
329 | + $row = $result->fetch(); |
|
330 | + $result->closeCursor(); |
|
331 | + |
|
332 | + $tooBig = ($row['user_count'] > 50); |
|
333 | + } |
|
334 | + if (!$tooBig) { |
|
335 | + // count users |
|
336 | + $stats = \OC::$server->getUserManager()->countUsers(); |
|
337 | + $totalUsers = array_sum($stats); |
|
338 | + $tooBig = ($totalUsers > 50); |
|
339 | + } |
|
340 | + } |
|
341 | + $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
342 | + $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
343 | + |
|
344 | + if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
345 | + // send http status 503 |
|
346 | + http_response_code(503); |
|
347 | + header('Retry-After: 120'); |
|
348 | + |
|
349 | + // render error page |
|
350 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
351 | + $template->assign('productName', 'nextcloud'); // for now |
|
352 | + $template->assign('version', OC_Util::getVersionString()); |
|
353 | + $template->assign('tooBig', $tooBig); |
|
354 | + |
|
355 | + $template->printPage(); |
|
356 | + die(); |
|
357 | + } |
|
358 | + |
|
359 | + // check whether this is a core update or apps update |
|
360 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
361 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
362 | + |
|
363 | + // if not a core upgrade, then it's apps upgrade |
|
364 | + $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
365 | + |
|
366 | + $oldTheme = $systemConfig->getValue('theme'); |
|
367 | + $systemConfig->setValue('theme', ''); |
|
368 | + OC_Util::addScript('config'); // needed for web root |
|
369 | + OC_Util::addScript('update'); |
|
370 | + |
|
371 | + /** @var \OC\App\AppManager $appManager */ |
|
372 | + $appManager = \OC::$server->getAppManager(); |
|
373 | + |
|
374 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
375 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
376 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
377 | + |
|
378 | + // get third party apps |
|
379 | + $ocVersion = \OCP\Util::getVersion(); |
|
380 | + $ocVersion = implode('.', $ocVersion); |
|
381 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
382 | + $incompatibleShippedApps = []; |
|
383 | + foreach ($incompatibleApps as $appInfo) { |
|
384 | + if ($appManager->isShipped($appInfo['id'])) { |
|
385 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + if (!empty($incompatibleShippedApps)) { |
|
390 | + $l = \OC::$server->getL10N('core'); |
|
391 | + $hint = $l->t('The files of the app %1$s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
392 | + throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
393 | + } |
|
394 | + |
|
395 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
396 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
397 | + $tmpl->assign('productName', 'Nextcloud'); // for now |
|
398 | + $tmpl->assign('oldTheme', $oldTheme); |
|
399 | + $tmpl->printPage(); |
|
400 | + } |
|
401 | + |
|
402 | + public static function initSession() { |
|
403 | + if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
404 | + ini_set('session.cookie_secure', true); |
|
405 | + } |
|
406 | + |
|
407 | + // prevents javascript from accessing php session cookies |
|
408 | + ini_set('session.cookie_httponly', 'true'); |
|
409 | + |
|
410 | + // set the cookie path to the Nextcloud directory |
|
411 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
412 | + ini_set('session.cookie_path', $cookie_path); |
|
413 | + |
|
414 | + // Let the session name be changed in the initSession Hook |
|
415 | + $sessionName = OC_Util::getInstanceId(); |
|
416 | + |
|
417 | + try { |
|
418 | + // Allow session apps to create a custom session object |
|
419 | + $useCustomSession = false; |
|
420 | + $session = self::$server->getSession(); |
|
421 | + OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
422 | + if (!$useCustomSession) { |
|
423 | + // set the session name to the instance id - which is unique |
|
424 | + $session = new \OC\Session\Internal($sessionName); |
|
425 | + } |
|
426 | + |
|
427 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
428 | + $session = $cryptoWrapper->wrapSession($session); |
|
429 | + self::$server->setSession($session); |
|
430 | + |
|
431 | + // if session can't be started break with http 500 error |
|
432 | + } catch (Exception $e) { |
|
433 | + \OC::$server->getLogger()->logException($e, ['app' => 'base']); |
|
434 | + //show the user a detailed error page |
|
435 | + OC_Template::printExceptionErrorPage($e, 500); |
|
436 | + die(); |
|
437 | + } |
|
438 | + |
|
439 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
440 | + |
|
441 | + // session timeout |
|
442 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
443 | + if (isset($_COOKIE[session_name()])) { |
|
444 | + setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
445 | + } |
|
446 | + \OC::$server->getUserSession()->logout(); |
|
447 | + } |
|
448 | + |
|
449 | + $session->set('LAST_ACTIVITY', time()); |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * @return string |
|
454 | + */ |
|
455 | + private static function getSessionLifeTime() { |
|
456 | + return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Try to set some values to the required Nextcloud default |
|
461 | + */ |
|
462 | + public static function setRequiredIniValues() { |
|
463 | + @ini_set('default_charset', 'UTF-8'); |
|
464 | + @ini_set('gd.jpeg_ignore_warning', '1'); |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Send the same site cookies |
|
469 | + */ |
|
470 | + private static function sendSameSiteCookies() { |
|
471 | + $cookieParams = session_get_cookie_params(); |
|
472 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
473 | + $policies = [ |
|
474 | + 'lax', |
|
475 | + 'strict', |
|
476 | + ]; |
|
477 | + |
|
478 | + // Append __Host to the cookie if it meets the requirements |
|
479 | + $cookiePrefix = ''; |
|
480 | + if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
481 | + $cookiePrefix = '__Host-'; |
|
482 | + } |
|
483 | + |
|
484 | + foreach($policies as $policy) { |
|
485 | + header( |
|
486 | + sprintf( |
|
487 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
488 | + $cookiePrefix, |
|
489 | + $policy, |
|
490 | + $cookieParams['path'], |
|
491 | + $policy |
|
492 | + ), |
|
493 | + false |
|
494 | + ); |
|
495 | + } |
|
496 | + } |
|
497 | + |
|
498 | + /** |
|
499 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
500 | + * be set in every request if cookies are sent to add a second level of |
|
501 | + * defense against CSRF. |
|
502 | + * |
|
503 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
504 | + * We use an additional cookie since we want to protect logout CSRF and |
|
505 | + * also we can't directly interfere with PHP's session mechanism. |
|
506 | + */ |
|
507 | + private static function performSameSiteCookieProtection() { |
|
508 | + $request = \OC::$server->getRequest(); |
|
509 | + |
|
510 | + // Some user agents are notorious and don't really properly follow HTTP |
|
511 | + // specifications. For those, have an automated opt-out. Since the protection |
|
512 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
513 | + // here. |
|
514 | + $incompatibleUserAgents = \OC::$server->getConfig()->getSystemValue('csrf.optout'); |
|
515 | + |
|
516 | + // Fallback, if csrf.optout is unset |
|
517 | + if (!is_array($incompatibleUserAgents)) { |
|
518 | + $incompatibleUserAgents = [ |
|
519 | + // OS X Finder |
|
520 | + '/^WebDAVFS/', |
|
521 | + // Windows webdav drive |
|
522 | + '/^Microsoft-WebDAV-MiniRedir/', |
|
523 | + ]; |
|
524 | + } |
|
525 | + |
|
526 | + if($request->isUserAgent($incompatibleUserAgents)) { |
|
527 | + return; |
|
528 | + } |
|
529 | + |
|
530 | + if(count($_COOKIE) > 0) { |
|
531 | + $requestUri = $request->getScriptName(); |
|
532 | + $processingScript = explode('/', $requestUri); |
|
533 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
534 | + |
|
535 | + // index.php routes are handled in the middleware |
|
536 | + if($processingScript === 'index.php') { |
|
537 | + return; |
|
538 | + } |
|
539 | + |
|
540 | + // All other endpoints require the lax and the strict cookie |
|
541 | + if(!$request->passesStrictCookieCheck()) { |
|
542 | + self::sendSameSiteCookies(); |
|
543 | + // Debug mode gets access to the resources without strict cookie |
|
544 | + // due to the fact that the SabreDAV browser also lives there. |
|
545 | + if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
546 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
547 | + exit(); |
|
548 | + } |
|
549 | + } |
|
550 | + } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
551 | + self::sendSameSiteCookies(); |
|
552 | + } |
|
553 | + } |
|
554 | + |
|
555 | + public static function init() { |
|
556 | + // calculate the root directories |
|
557 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
558 | + |
|
559 | + // register autoloader |
|
560 | + $loaderStart = microtime(true); |
|
561 | + require_once __DIR__ . '/autoloader.php'; |
|
562 | + self::$loader = new \OC\Autoloader([ |
|
563 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
564 | + ]); |
|
565 | + if (defined('PHPUNIT_RUN')) { |
|
566 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
567 | + } |
|
568 | + spl_autoload_register(array(self::$loader, 'load')); |
|
569 | + $loaderEnd = microtime(true); |
|
570 | + |
|
571 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
572 | + |
|
573 | + // Add default composer PSR-4 autoloader |
|
574 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
575 | + |
|
576 | + try { |
|
577 | + self::initPaths(); |
|
578 | + // setup 3rdparty autoloader |
|
579 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
580 | + if (!file_exists($vendorAutoLoad)) { |
|
581 | + throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
582 | + } |
|
583 | + require_once $vendorAutoLoad; |
|
584 | + |
|
585 | + } catch (\RuntimeException $e) { |
|
586 | + if (!self::$CLI) { |
|
587 | + http_response_code(503); |
|
588 | + } |
|
589 | + // we can't use the template error page here, because this needs the |
|
590 | + // DI container which isn't available yet |
|
591 | + print($e->getMessage()); |
|
592 | + exit(); |
|
593 | + } |
|
594 | + |
|
595 | + // setup the basic server |
|
596 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
597 | + \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
598 | + \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
599 | + |
|
600 | + // Don't display errors and log them |
|
601 | + error_reporting(E_ALL | E_STRICT); |
|
602 | + @ini_set('display_errors', '0'); |
|
603 | + @ini_set('log_errors', '1'); |
|
604 | + |
|
605 | + if(!date_default_timezone_set('UTC')) { |
|
606 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
607 | + } |
|
608 | + |
|
609 | + //try to configure php to enable big file uploads. |
|
610 | + //this doesn´t work always depending on the webserver and php configuration. |
|
611 | + //Let´s try to overwrite some defaults anyway |
|
612 | + |
|
613 | + //try to set the maximum execution time to 60min |
|
614 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
615 | + @set_time_limit(3600); |
|
616 | + } |
|
617 | + @ini_set('max_execution_time', '3600'); |
|
618 | + @ini_set('max_input_time', '3600'); |
|
619 | + |
|
620 | + //try to set the maximum filesize to 10G |
|
621 | + @ini_set('upload_max_filesize', '10G'); |
|
622 | + @ini_set('post_max_size', '10G'); |
|
623 | + @ini_set('file_uploads', '50'); |
|
624 | + |
|
625 | + self::setRequiredIniValues(); |
|
626 | + self::handleAuthHeaders(); |
|
627 | + self::registerAutoloaderCache(); |
|
628 | + |
|
629 | + // initialize intl fallback is necessary |
|
630 | + \Patchwork\Utf8\Bootup::initIntl(); |
|
631 | + OC_Util::isSetLocaleWorking(); |
|
632 | + |
|
633 | + if (!defined('PHPUNIT_RUN')) { |
|
634 | + OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
635 | + $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
636 | + OC\Log\ErrorHandler::register($debug); |
|
637 | + } |
|
638 | + |
|
639 | + \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
640 | + OC_App::loadApps(array('session')); |
|
641 | + if (!self::$CLI) { |
|
642 | + self::initSession(); |
|
643 | + } |
|
644 | + \OC::$server->getEventLogger()->end('init_session'); |
|
645 | + self::checkConfig(); |
|
646 | + self::checkInstalled(); |
|
647 | + |
|
648 | + OC_Response::addSecurityHeaders(); |
|
649 | + |
|
650 | + self::performSameSiteCookieProtection(); |
|
651 | + |
|
652 | + if (!defined('OC_CONSOLE')) { |
|
653 | + $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
654 | + if (count($errors) > 0) { |
|
655 | + if (self::$CLI) { |
|
656 | + // Convert l10n string into regular string for usage in database |
|
657 | + $staticErrors = []; |
|
658 | + foreach ($errors as $error) { |
|
659 | + echo $error['error'] . "\n"; |
|
660 | + echo $error['hint'] . "\n\n"; |
|
661 | + $staticErrors[] = [ |
|
662 | + 'error' => (string)$error['error'], |
|
663 | + 'hint' => (string)$error['hint'], |
|
664 | + ]; |
|
665 | + } |
|
666 | + |
|
667 | + try { |
|
668 | + \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
669 | + } catch (\Exception $e) { |
|
670 | + echo('Writing to database failed'); |
|
671 | + } |
|
672 | + exit(1); |
|
673 | + } else { |
|
674 | + http_response_code(503); |
|
675 | + OC_Util::addStyle('guest'); |
|
676 | + OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
677 | + exit; |
|
678 | + } |
|
679 | + } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
680 | + \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
681 | + } |
|
682 | + } |
|
683 | + //try to set the session lifetime |
|
684 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
685 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
686 | + |
|
687 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
688 | + |
|
689 | + // User and Groups |
|
690 | + if (!$systemConfig->getValue("installed", false)) { |
|
691 | + self::$server->getSession()->set('user_id', ''); |
|
692 | + } |
|
693 | + |
|
694 | + OC_User::useBackend(new \OC\User\Database()); |
|
695 | + \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
696 | + |
|
697 | + // Subscribe to the hook |
|
698 | + \OCP\Util::connectHook( |
|
699 | + '\OCA\Files_Sharing\API\Server2Server', |
|
700 | + 'preLoginNameUsedAsUserName', |
|
701 | + '\OC\User\Database', |
|
702 | + 'preLoginNameUsedAsUserName' |
|
703 | + ); |
|
704 | + |
|
705 | + //setup extra user backends |
|
706 | + if (!\OCP\Util::needUpgrade()) { |
|
707 | + OC_User::setupBackends(); |
|
708 | + } else { |
|
709 | + // Run upgrades in incognito mode |
|
710 | + OC_User::setIncognitoMode(true); |
|
711 | + } |
|
712 | + |
|
713 | + self::registerCleanupHooks(); |
|
714 | + self::registerFilesystemHooks(); |
|
715 | + self::registerShareHooks(); |
|
716 | + self::registerEncryptionWrapper(); |
|
717 | + self::registerEncryptionHooks(); |
|
718 | + self::registerAccountHooks(); |
|
719 | + self::registerResourceCollectionHooks(); |
|
720 | + self::registerAppRestrictionsHooks(); |
|
721 | + |
|
722 | + // Make sure that the application class is not loaded before the database is setup |
|
723 | + if ($systemConfig->getValue("installed", false)) { |
|
724 | + $settings = new \OC\Settings\Application(); |
|
725 | + $settings->register(); |
|
726 | + } |
|
727 | + |
|
728 | + //make sure temporary files are cleaned up |
|
729 | + $tmpManager = \OC::$server->getTempManager(); |
|
730 | + register_shutdown_function(array($tmpManager, 'clean')); |
|
731 | + $lockProvider = \OC::$server->getLockingProvider(); |
|
732 | + register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
733 | + |
|
734 | + // Check whether the sample configuration has been copied |
|
735 | + if($systemConfig->getValue('copied_sample_config', false)) { |
|
736 | + $l = \OC::$server->getL10N('lib'); |
|
737 | + OC_Template::printErrorPage( |
|
738 | + $l->t('Sample configuration detected'), |
|
739 | + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), |
|
740 | + 503 |
|
741 | + ); |
|
742 | + return; |
|
743 | + } |
|
744 | + |
|
745 | + $request = \OC::$server->getRequest(); |
|
746 | + $host = $request->getInsecureServerHost(); |
|
747 | + /** |
|
748 | + * if the host passed in headers isn't trusted |
|
749 | + * FIXME: Should not be in here at all :see_no_evil: |
|
750 | + */ |
|
751 | + if (!OC::$CLI |
|
752 | + // overwritehost is always trusted, workaround to not have to make |
|
753 | + // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
754 | + && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
755 | + && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
756 | + && self::$server->getConfig()->getSystemValue('installed', false) |
|
757 | + ) { |
|
758 | + // Allow access to CSS resources |
|
759 | + $isScssRequest = false; |
|
760 | + if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
761 | + $isScssRequest = true; |
|
762 | + } |
|
763 | + |
|
764 | + if(substr($request->getRequestUri(), -11) === '/status.php') { |
|
765 | + http_response_code(400); |
|
766 | + header('Content-Type: application/json'); |
|
767 | + echo '{"error": "Trusted domain error.", "code": 15}'; |
|
768 | + exit(); |
|
769 | + } |
|
770 | + |
|
771 | + if (!$isScssRequest) { |
|
772 | + http_response_code(400); |
|
773 | + |
|
774 | + \OC::$server->getLogger()->info( |
|
775 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
776 | + [ |
|
777 | + 'app' => 'core', |
|
778 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
779 | + 'host' => $host, |
|
780 | + ] |
|
781 | + ); |
|
782 | + |
|
783 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
784 | + $tmpl->assign('docUrl', \OC::$server->getURLGenerator()->linkToDocs('admin-trusted-domains')); |
|
785 | + $tmpl->printPage(); |
|
786 | + |
|
787 | + exit(); |
|
788 | + } |
|
789 | + } |
|
790 | + \OC::$server->getEventLogger()->end('boot'); |
|
791 | + } |
|
792 | + |
|
793 | + /** |
|
794 | + * register hooks for the cleanup of cache and bruteforce protection |
|
795 | + */ |
|
796 | + public static function registerCleanupHooks() { |
|
797 | + //don't try to do this before we are properly setup |
|
798 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
799 | + |
|
800 | + // NOTE: This will be replaced to use OCP |
|
801 | + $userSession = self::$server->getUserSession(); |
|
802 | + $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
803 | + if (!defined('PHPUNIT_RUN')) { |
|
804 | + // reset brute force delay for this IP address and username |
|
805 | + $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
806 | + $request = \OC::$server->getRequest(); |
|
807 | + $throttler = \OC::$server->getBruteForceThrottler(); |
|
808 | + $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
809 | + } |
|
810 | + |
|
811 | + try { |
|
812 | + $cache = new \OC\Cache\File(); |
|
813 | + $cache->gc(); |
|
814 | + } catch (\OC\ServerNotAvailableException $e) { |
|
815 | + // not a GC exception, pass it on |
|
816 | + throw $e; |
|
817 | + } catch (\OC\ForbiddenException $e) { |
|
818 | + // filesystem blocked for this request, ignore |
|
819 | + } catch (\Exception $e) { |
|
820 | + // a GC exception should not prevent users from using OC, |
|
821 | + // so log the exception |
|
822 | + \OC::$server->getLogger()->logException($e, [ |
|
823 | + 'message' => 'Exception when running cache gc.', |
|
824 | + 'level' => ILogger::WARN, |
|
825 | + 'app' => 'core', |
|
826 | + ]); |
|
827 | + } |
|
828 | + }); |
|
829 | + } |
|
830 | + } |
|
831 | + |
|
832 | + private static function registerEncryptionWrapper() { |
|
833 | + $manager = self::$server->getEncryptionManager(); |
|
834 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
835 | + } |
|
836 | + |
|
837 | + private static function registerEncryptionHooks() { |
|
838 | + $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
839 | + if ($enabled) { |
|
840 | + \OCP\Util::connectHook(Share::class, 'post_shared', HookManager::class, 'postShared'); |
|
841 | + \OCP\Util::connectHook(Share::class, 'post_unshare', HookManager::class, 'postUnshared'); |
|
842 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', HookManager::class, 'postRename'); |
|
843 | + \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', HookManager::class, 'postRestore'); |
|
844 | + } |
|
845 | + } |
|
846 | + |
|
847 | + private static function registerAccountHooks() { |
|
848 | + $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
849 | + \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
850 | + } |
|
851 | + |
|
852 | + private static function registerAppRestrictionsHooks() { |
|
853 | + $groupManager = self::$server->query(\OCP\IGroupManager::class); |
|
854 | + $groupManager->listen ('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
855 | + $appManager = self::$server->getAppManager(); |
|
856 | + $apps = $appManager->getEnabledAppsForGroup($group); |
|
857 | + foreach ($apps as $appId) { |
|
858 | + $restrictions = $appManager->getAppRestriction($appId); |
|
859 | + if (empty($restrictions)) { |
|
860 | + continue; |
|
861 | + } |
|
862 | + $key = array_search($group->getGID(), $restrictions); |
|
863 | + unset($restrictions[$key]); |
|
864 | + $restrictions = array_values($restrictions); |
|
865 | + if (empty($restrictions)) { |
|
866 | + $appManager->disableApp($appId); |
|
867 | + } |
|
868 | + else{ |
|
869 | + $appManager->enableAppForGroups($appId, $restrictions); |
|
870 | + } |
|
871 | + |
|
872 | + } |
|
873 | + }); |
|
874 | + } |
|
875 | + |
|
876 | + private static function registerResourceCollectionHooks() { |
|
877 | + \OC\Collaboration\Resources\Listener::register(\OC::$server->getEventDispatcher()); |
|
878 | + } |
|
879 | + |
|
880 | + /** |
|
881 | + * register hooks for the filesystem |
|
882 | + */ |
|
883 | + public static function registerFilesystemHooks() { |
|
884 | + // Check for blacklisted files |
|
885 | + OC_Hook::connect('OC_Filesystem', 'write', Filesystem::class, 'isBlacklisted'); |
|
886 | + OC_Hook::connect('OC_Filesystem', 'rename', Filesystem::class, 'isBlacklisted'); |
|
887 | + } |
|
888 | + |
|
889 | + /** |
|
890 | + * register hooks for sharing |
|
891 | + */ |
|
892 | + public static function registerShareHooks() { |
|
893 | + if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
894 | + OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); |
|
895 | + OC_Hook::connect('OC_User', 'post_removeFromGroup', Hooks::class, 'post_removeFromGroup'); |
|
896 | + OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); |
|
897 | + } |
|
898 | + } |
|
899 | + |
|
900 | + protected static function registerAutoloaderCache() { |
|
901 | + // The class loader takes an optional low-latency cache, which MUST be |
|
902 | + // namespaced. The instanceid is used for namespacing, but might be |
|
903 | + // unavailable at this point. Furthermore, it might not be possible to |
|
904 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
905 | + // config file may not be writable. As such, we only register a class |
|
906 | + // loader cache if instanceid is available without trying to create one. |
|
907 | + $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
908 | + if ($instanceId) { |
|
909 | + try { |
|
910 | + $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
911 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
912 | + } catch (\Exception $ex) { |
|
913 | + } |
|
914 | + } |
|
915 | + } |
|
916 | + |
|
917 | + /** |
|
918 | + * Handle the request |
|
919 | + */ |
|
920 | + public static function handleRequest() { |
|
921 | + |
|
922 | + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
923 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
924 | + |
|
925 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
926 | + if (!$systemConfig->getValue('installed', false)) { |
|
927 | + \OC::$server->getSession()->clear(); |
|
928 | + $setupHelper = new OC\Setup( |
|
929 | + $systemConfig, |
|
930 | + \OC::$server->getIniWrapper(), |
|
931 | + \OC::$server->getL10N('lib'), |
|
932 | + \OC::$server->query(\OCP\Defaults::class), |
|
933 | + \OC::$server->getLogger(), |
|
934 | + \OC::$server->getSecureRandom(), |
|
935 | + \OC::$server->query(\OC\Installer::class) |
|
936 | + ); |
|
937 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
938 | + $controller->run($_POST); |
|
939 | + exit(); |
|
940 | + } |
|
941 | + |
|
942 | + $request = \OC::$server->getRequest(); |
|
943 | + $requestPath = $request->getRawPathInfo(); |
|
944 | + if ($requestPath === '/heartbeat') { |
|
945 | + return; |
|
946 | + } |
|
947 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
948 | + self::checkMaintenanceMode(); |
|
949 | + |
|
950 | + if (\OCP\Util::needUpgrade()) { |
|
951 | + if (function_exists('opcache_reset')) { |
|
952 | + opcache_reset(); |
|
953 | + } |
|
954 | + if (!((bool) $systemConfig->getValue('maintenance', false))) { |
|
955 | + self::printUpgradePage($systemConfig); |
|
956 | + exit(); |
|
957 | + } |
|
958 | + } |
|
959 | + } |
|
960 | + |
|
961 | + // emergency app disabling |
|
962 | + if ($requestPath === '/disableapp' |
|
963 | + && $request->getMethod() === 'POST' |
|
964 | + && ((array)$request->getParam('appid')) !== '' |
|
965 | + ) { |
|
966 | + \OC_JSON::callCheck(); |
|
967 | + \OC_JSON::checkAdminUser(); |
|
968 | + $appIds = (array)$request->getParam('appid'); |
|
969 | + foreach($appIds as $appId) { |
|
970 | + $appId = \OC_App::cleanAppId($appId); |
|
971 | + \OC::$server->getAppManager()->disableApp($appId); |
|
972 | + } |
|
973 | + \OC_JSON::success(); |
|
974 | + exit(); |
|
975 | + } |
|
976 | + |
|
977 | + // Always load authentication apps |
|
978 | + OC_App::loadApps(['authentication']); |
|
979 | + |
|
980 | + // Load minimum set of apps |
|
981 | + if (!\OCP\Util::needUpgrade() |
|
982 | + && !((bool) $systemConfig->getValue('maintenance', false))) { |
|
983 | + // For logged-in users: Load everything |
|
984 | + if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
985 | + OC_App::loadApps(); |
|
986 | + } else { |
|
987 | + // For guests: Load only filesystem and logging |
|
988 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
989 | + self::handleLogin($request); |
|
990 | + } |
|
991 | + } |
|
992 | + |
|
993 | + if (!self::$CLI) { |
|
994 | + try { |
|
995 | + if (!((bool) $systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) { |
|
996 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
997 | + OC_App::loadApps(); |
|
998 | + } |
|
999 | + OC_Util::setupFS(); |
|
1000 | + OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
1001 | + return; |
|
1002 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
1003 | + //header('HTTP/1.0 404 Not Found'); |
|
1004 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
1005 | + http_response_code(405); |
|
1006 | + return; |
|
1007 | + } |
|
1008 | + } |
|
1009 | + |
|
1010 | + // Handle WebDAV |
|
1011 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
1012 | + // not allowed any more to prevent people |
|
1013 | + // mounting this root directly. |
|
1014 | + // Users need to mount remote.php/webdav instead. |
|
1015 | + http_response_code(405); |
|
1016 | + return; |
|
1017 | + } |
|
1018 | + |
|
1019 | + // Someone is logged in |
|
1020 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1021 | + OC_App::loadApps(); |
|
1022 | + OC_User::setupBackends(); |
|
1023 | + OC_Util::setupFS(); |
|
1024 | + // FIXME |
|
1025 | + // Redirect to default application |
|
1026 | + OC_Util::redirectToDefaultPage(); |
|
1027 | + } else { |
|
1028 | + // Not handled and not logged in |
|
1029 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1030 | + } |
|
1031 | + } |
|
1032 | + |
|
1033 | + /** |
|
1034 | + * Check login: apache auth, auth token, basic auth |
|
1035 | + * |
|
1036 | + * @param OCP\IRequest $request |
|
1037 | + * @return boolean |
|
1038 | + */ |
|
1039 | + static function handleLogin(OCP\IRequest $request) { |
|
1040 | + $userSession = self::$server->getUserSession(); |
|
1041 | + if (OC_User::handleApacheAuth()) { |
|
1042 | + return true; |
|
1043 | + } |
|
1044 | + if ($userSession->tryTokenLogin($request)) { |
|
1045 | + return true; |
|
1046 | + } |
|
1047 | + if (isset($_COOKIE['nc_username']) |
|
1048 | + && isset($_COOKIE['nc_token']) |
|
1049 | + && isset($_COOKIE['nc_session_id']) |
|
1050 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1051 | + return true; |
|
1052 | + } |
|
1053 | + if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
1054 | + return true; |
|
1055 | + } |
|
1056 | + return false; |
|
1057 | + } |
|
1058 | + |
|
1059 | + protected static function handleAuthHeaders() { |
|
1060 | + //copy http auth headers for apache+php-fcgid work around |
|
1061 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1062 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1063 | + } |
|
1064 | + |
|
1065 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1066 | + $vars = array( |
|
1067 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1068 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1069 | + ); |
|
1070 | + foreach ($vars as $var) { |
|
1071 | + if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1072 | + list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
1073 | + $_SERVER['PHP_AUTH_USER'] = $name; |
|
1074 | + $_SERVER['PHP_AUTH_PW'] = $password; |
|
1075 | + break; |
|
1076 | + } |
|
1077 | + } |
|
1078 | + } |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | OC::init(); |
@@ -128,14 +128,14 @@ discard block |
||
128 | 128 | * the app path list is empty or contains an invalid path |
129 | 129 | */ |
130 | 130 | public static function initPaths() { |
131 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
132 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
133 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
134 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
135 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
136 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
131 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
132 | + self::$configDir = OC::$SERVERROOT.'/'.PHPUNIT_CONFIG_DIR.'/'; |
|
133 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT.'/tests/config/')) { |
|
134 | + self::$configDir = OC::$SERVERROOT.'/tests/config/'; |
|
135 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
136 | + self::$configDir = rtrim($dir, '/').'/'; |
|
137 | 137 | } else { |
138 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
138 | + self::$configDir = OC::$SERVERROOT.'/config/'; |
|
139 | 139 | } |
140 | 140 | self::$config = new \OC\Config(self::$configDir); |
141 | 141 | |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | //make sure suburi follows the same rules as scriptName |
158 | 158 | if (substr(OC::$SUBURI, -9) != 'index.php') { |
159 | 159 | if (substr(OC::$SUBURI, -1) != '/') { |
160 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
160 | + OC::$SUBURI = OC::$SUBURI.'/'; |
|
161 | 161 | } |
162 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
162 | + OC::$SUBURI = OC::$SUBURI.'index.php'; |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
172 | 172 | |
173 | 173 | if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
174 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
174 | + OC::$WEBROOT = '/'.OC::$WEBROOT; |
|
175 | 175 | } |
176 | 176 | } else { |
177 | 177 | // The scriptName is not ending with OC::$SUBURI |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | OC::$APPSROOTS[] = $paths; |
201 | 201 | } |
202 | 202 | } |
203 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
204 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
205 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
203 | + } elseif (file_exists(OC::$SERVERROOT.'/apps')) { |
|
204 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT.'/apps', 'url' => '/apps', 'writable' => true); |
|
205 | + } elseif (file_exists(OC::$SERVERROOT.'/../apps')) { |
|
206 | 206 | OC::$APPSROOTS[] = array( |
207 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
207 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/').'/apps', |
|
208 | 208 | 'url' => '/apps', |
209 | 209 | 'writable' => true |
210 | 210 | ); |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | $l = \OC::$server->getL10N('lib'); |
235 | 235 | |
236 | 236 | // Create config if it does not already exist |
237 | - $configFilePath = self::$configDir .'/config.php'; |
|
238 | - if(!file_exists($configFilePath)) { |
|
237 | + $configFilePath = self::$configDir.'/config.php'; |
|
238 | + if (!file_exists($configFilePath)) { |
|
239 | 239 | @touch($configFilePath); |
240 | 240 | } |
241 | 241 | |
@@ -249,18 +249,18 @@ discard block |
||
249 | 249 | if (self::$CLI) { |
250 | 250 | echo $l->t('Cannot write into "config" directory!')."\n"; |
251 | 251 | echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
252 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
252 | + echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-dir_permissions')])."\n"; |
|
253 | 253 | echo "\n"; |
254 | 254 | echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
255 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
255 | + echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-config')])."\n"; |
|
256 | 256 | exit; |
257 | 257 | } else { |
258 | 258 | OC_Template::printErrorPage( |
259 | 259 | $l->t('Cannot write into "config" directory!'), |
260 | 260 | $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
261 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
261 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]).'. ' |
|
262 | 262 | . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
263 | - [ $urlGenerator->linkToDocs('admin-config') ] ), |
|
263 | + [$urlGenerator->linkToDocs('admin-config')]), |
|
264 | 264 | 503 |
265 | 265 | ); |
266 | 266 | } |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | if (OC::$CLI) { |
277 | 277 | throw new Exception('Not installed'); |
278 | 278 | } else { |
279 | - $url = OC::$WEBROOT . '/index.php'; |
|
280 | - header('Location: ' . $url); |
|
279 | + $url = OC::$WEBROOT.'/index.php'; |
|
280 | + header('Location: '.$url); |
|
281 | 281 | } |
282 | 282 | exit(); |
283 | 283 | } |
@@ -382,14 +382,14 @@ discard block |
||
382 | 382 | $incompatibleShippedApps = []; |
383 | 383 | foreach ($incompatibleApps as $appInfo) { |
384 | 384 | if ($appManager->isShipped($appInfo['id'])) { |
385 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
385 | + $incompatibleShippedApps[] = $appInfo['name'].' ('.$appInfo['id'].')'; |
|
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
389 | 389 | if (!empty($incompatibleShippedApps)) { |
390 | 390 | $l = \OC::$server->getL10N('core'); |
391 | 391 | $hint = $l->t('The files of the app %1$s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
392 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
392 | + throw new \OC\HintException('The files of the app '.implode(', ', $incompatibleShippedApps).' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | } |
401 | 401 | |
402 | 402 | public static function initSession() { |
403 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
403 | + if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
404 | 404 | ini_set('session.cookie_secure', true); |
405 | 405 | } |
406 | 406 | |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | ini_set('session.cookie_httponly', 'true'); |
409 | 409 | |
410 | 410 | // set the cookie path to the Nextcloud directory |
411 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
411 | + $cookie_path = OC::$WEBROOT ?: '/'; |
|
412 | 412 | ini_set('session.cookie_path', $cookie_path); |
413 | 413 | |
414 | 414 | // Let the session name be changed in the initSession Hook |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | // session timeout |
442 | 442 | if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
443 | 443 | if (isset($_COOKIE[session_name()])) { |
444 | - setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
444 | + setcookie(session_name(), '', -1, self::$WEBROOT ?: '/'); |
|
445 | 445 | } |
446 | 446 | \OC::$server->getUserSession()->logout(); |
447 | 447 | } |
@@ -477,14 +477,14 @@ discard block |
||
477 | 477 | |
478 | 478 | // Append __Host to the cookie if it meets the requirements |
479 | 479 | $cookiePrefix = ''; |
480 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
480 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
481 | 481 | $cookiePrefix = '__Host-'; |
482 | 482 | } |
483 | 483 | |
484 | - foreach($policies as $policy) { |
|
484 | + foreach ($policies as $policy) { |
|
485 | 485 | header( |
486 | 486 | sprintf( |
487 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
487 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
488 | 488 | $cookiePrefix, |
489 | 489 | $policy, |
490 | 490 | $cookieParams['path'], |
@@ -523,31 +523,31 @@ discard block |
||
523 | 523 | ]; |
524 | 524 | } |
525 | 525 | |
526 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
526 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
527 | 527 | return; |
528 | 528 | } |
529 | 529 | |
530 | - if(count($_COOKIE) > 0) { |
|
530 | + if (count($_COOKIE) > 0) { |
|
531 | 531 | $requestUri = $request->getScriptName(); |
532 | 532 | $processingScript = explode('/', $requestUri); |
533 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
533 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
534 | 534 | |
535 | 535 | // index.php routes are handled in the middleware |
536 | - if($processingScript === 'index.php') { |
|
536 | + if ($processingScript === 'index.php') { |
|
537 | 537 | return; |
538 | 538 | } |
539 | 539 | |
540 | 540 | // All other endpoints require the lax and the strict cookie |
541 | - if(!$request->passesStrictCookieCheck()) { |
|
541 | + if (!$request->passesStrictCookieCheck()) { |
|
542 | 542 | self::sendSameSiteCookies(); |
543 | 543 | // Debug mode gets access to the resources without strict cookie |
544 | 544 | // due to the fact that the SabreDAV browser also lives there. |
545 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
545 | + if (!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
546 | 546 | http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
547 | 547 | exit(); |
548 | 548 | } |
549 | 549 | } |
550 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
550 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
551 | 551 | self::sendSameSiteCookies(); |
552 | 552 | } |
553 | 553 | } |
@@ -558,12 +558,12 @@ discard block |
||
558 | 558 | |
559 | 559 | // register autoloader |
560 | 560 | $loaderStart = microtime(true); |
561 | - require_once __DIR__ . '/autoloader.php'; |
|
561 | + require_once __DIR__.'/autoloader.php'; |
|
562 | 562 | self::$loader = new \OC\Autoloader([ |
563 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
563 | + OC::$SERVERROOT.'/lib/private/legacy', |
|
564 | 564 | ]); |
565 | 565 | if (defined('PHPUNIT_RUN')) { |
566 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
566 | + self::$loader->addValidRoot(OC::$SERVERROOT.'/tests'); |
|
567 | 567 | } |
568 | 568 | spl_autoload_register(array(self::$loader, 'load')); |
569 | 569 | $loaderEnd = microtime(true); |
@@ -571,12 +571,12 @@ discard block |
||
571 | 571 | self::$CLI = (php_sapi_name() == 'cli'); |
572 | 572 | |
573 | 573 | // Add default composer PSR-4 autoloader |
574 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
574 | + self::$composerAutoloader = require_once OC::$SERVERROOT.'/lib/composer/autoload.php'; |
|
575 | 575 | |
576 | 576 | try { |
577 | 577 | self::initPaths(); |
578 | 578 | // setup 3rdparty autoloader |
579 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
579 | + $vendorAutoLoad = OC::$SERVERROOT.'/3rdparty/autoload.php'; |
|
580 | 580 | if (!file_exists($vendorAutoLoad)) { |
581 | 581 | throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
582 | 582 | } |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | @ini_set('display_errors', '0'); |
603 | 603 | @ini_set('log_errors', '1'); |
604 | 604 | |
605 | - if(!date_default_timezone_set('UTC')) { |
|
605 | + if (!date_default_timezone_set('UTC')) { |
|
606 | 606 | throw new \RuntimeException('Could not set timezone to UTC'); |
607 | 607 | } |
608 | 608 | |
@@ -656,11 +656,11 @@ discard block |
||
656 | 656 | // Convert l10n string into regular string for usage in database |
657 | 657 | $staticErrors = []; |
658 | 658 | foreach ($errors as $error) { |
659 | - echo $error['error'] . "\n"; |
|
660 | - echo $error['hint'] . "\n\n"; |
|
659 | + echo $error['error']."\n"; |
|
660 | + echo $error['hint']."\n\n"; |
|
661 | 661 | $staticErrors[] = [ |
662 | - 'error' => (string)$error['error'], |
|
663 | - 'hint' => (string)$error['hint'], |
|
662 | + 'error' => (string) $error['error'], |
|
663 | + 'hint' => (string) $error['hint'], |
|
664 | 664 | ]; |
665 | 665 | } |
666 | 666 | |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | } |
683 | 683 | //try to set the session lifetime |
684 | 684 | $sessionLifeTime = self::getSessionLifeTime(); |
685 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
685 | + @ini_set('gc_maxlifetime', (string) $sessionLifeTime); |
|
686 | 686 | |
687 | 687 | $systemConfig = \OC::$server->getSystemConfig(); |
688 | 688 | |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | register_shutdown_function(array($lockProvider, 'releaseAll')); |
733 | 733 | |
734 | 734 | // Check whether the sample configuration has been copied |
735 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
735 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
736 | 736 | $l = \OC::$server->getL10N('lib'); |
737 | 737 | OC_Template::printErrorPage( |
738 | 738 | $l->t('Sample configuration detected'), |
@@ -757,11 +757,11 @@ discard block |
||
757 | 757 | ) { |
758 | 758 | // Allow access to CSS resources |
759 | 759 | $isScssRequest = false; |
760 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
760 | + if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
761 | 761 | $isScssRequest = true; |
762 | 762 | } |
763 | 763 | |
764 | - if(substr($request->getRequestUri(), -11) === '/status.php') { |
|
764 | + if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
765 | 765 | http_response_code(400); |
766 | 766 | header('Content-Type: application/json'); |
767 | 767 | echo '{"error": "Trusted domain error.", "code": 15}'; |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | |
800 | 800 | // NOTE: This will be replaced to use OCP |
801 | 801 | $userSession = self::$server->getUserSession(); |
802 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
802 | + $userSession->listen('\OC\User', 'postLogin', function() use ($userSession) { |
|
803 | 803 | if (!defined('PHPUNIT_RUN')) { |
804 | 804 | // reset brute force delay for this IP address and username |
805 | 805 | $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | |
852 | 852 | private static function registerAppRestrictionsHooks() { |
853 | 853 | $groupManager = self::$server->query(\OCP\IGroupManager::class); |
854 | - $groupManager->listen ('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
854 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OCP\IGroup $group) { |
|
855 | 855 | $appManager = self::$server->getAppManager(); |
856 | 856 | $apps = $appManager->getEnabledAppsForGroup($group); |
857 | 857 | foreach ($apps as $appId) { |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | if (empty($restrictions)) { |
866 | 866 | $appManager->disableApp($appId); |
867 | 867 | } |
868 | - else{ |
|
868 | + else { |
|
869 | 869 | $appManager->enableAppForGroups($appId, $restrictions); |
870 | 870 | } |
871 | 871 | |
@@ -961,12 +961,12 @@ discard block |
||
961 | 961 | // emergency app disabling |
962 | 962 | if ($requestPath === '/disableapp' |
963 | 963 | && $request->getMethod() === 'POST' |
964 | - && ((array)$request->getParam('appid')) !== '' |
|
964 | + && ((array) $request->getParam('appid')) !== '' |
|
965 | 965 | ) { |
966 | 966 | \OC_JSON::callCheck(); |
967 | 967 | \OC_JSON::checkAdminUser(); |
968 | - $appIds = (array)$request->getParam('appid'); |
|
969 | - foreach($appIds as $appId) { |
|
968 | + $appIds = (array) $request->getParam('appid'); |
|
969 | + foreach ($appIds as $appId) { |
|
970 | 970 | $appId = \OC_App::cleanAppId($appId); |
971 | 971 | \OC::$server->getAppManager()->disableApp($appId); |
972 | 972 | } |
@@ -981,7 +981,7 @@ discard block |
||
981 | 981 | if (!\OCP\Util::needUpgrade() |
982 | 982 | && !((bool) $systemConfig->getValue('maintenance', false))) { |
983 | 983 | // For logged-in users: Load everything |
984 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
984 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
985 | 985 | OC_App::loadApps(); |
986 | 986 | } else { |
987 | 987 | // For guests: Load only filesystem and logging |
@@ -864,8 +864,7 @@ |
||
864 | 864 | $restrictions = array_values($restrictions); |
865 | 865 | if (empty($restrictions)) { |
866 | 866 | $appManager->disableApp($appId); |
867 | - } |
|
868 | - else{ |
|
867 | + } else{ |
|
869 | 868 | $appManager->enableAppForGroups($appId, $restrictions); |
870 | 869 | } |
871 | 870 |
@@ -46,486 +46,486 @@ |
||
46 | 46 | |
47 | 47 | class AppManager implements IAppManager { |
48 | 48 | |
49 | - /** |
|
50 | - * Apps with these types can not be enabled for certain groups only |
|
51 | - * @var string[] |
|
52 | - */ |
|
53 | - protected $protectedAppTypes = [ |
|
54 | - 'filesystem', |
|
55 | - 'prelogin', |
|
56 | - 'authentication', |
|
57 | - 'logging', |
|
58 | - 'prevent_group_restriction', |
|
59 | - ]; |
|
60 | - |
|
61 | - /** @var IUserSession */ |
|
62 | - private $userSession; |
|
63 | - |
|
64 | - /** @var AppConfig */ |
|
65 | - private $appConfig; |
|
66 | - |
|
67 | - /** @var IGroupManager */ |
|
68 | - private $groupManager; |
|
69 | - |
|
70 | - /** @var ICacheFactory */ |
|
71 | - private $memCacheFactory; |
|
72 | - |
|
73 | - /** @var EventDispatcherInterface */ |
|
74 | - private $dispatcher; |
|
75 | - |
|
76 | - /** @var ILogger */ |
|
77 | - private $logger; |
|
78 | - |
|
79 | - /** @var string[] $appId => $enabled */ |
|
80 | - private $installedAppsCache; |
|
81 | - |
|
82 | - /** @var string[] */ |
|
83 | - private $shippedApps; |
|
84 | - |
|
85 | - /** @var string[] */ |
|
86 | - private $alwaysEnabled; |
|
87 | - |
|
88 | - /** @var array */ |
|
89 | - private $appInfos = []; |
|
90 | - |
|
91 | - /** @var array */ |
|
92 | - private $appVersions = []; |
|
93 | - |
|
94 | - /** |
|
95 | - * @param IUserSession $userSession |
|
96 | - * @param AppConfig $appConfig |
|
97 | - * @param IGroupManager $groupManager |
|
98 | - * @param ICacheFactory $memCacheFactory |
|
99 | - * @param EventDispatcherInterface $dispatcher |
|
100 | - */ |
|
101 | - public function __construct(IUserSession $userSession, |
|
102 | - AppConfig $appConfig, |
|
103 | - IGroupManager $groupManager, |
|
104 | - ICacheFactory $memCacheFactory, |
|
105 | - EventDispatcherInterface $dispatcher, |
|
106 | - ILogger $logger) { |
|
107 | - $this->userSession = $userSession; |
|
108 | - $this->appConfig = $appConfig; |
|
109 | - $this->groupManager = $groupManager; |
|
110 | - $this->memCacheFactory = $memCacheFactory; |
|
111 | - $this->dispatcher = $dispatcher; |
|
112 | - $this->logger = $logger; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @return string[] $appId => $enabled |
|
117 | - */ |
|
118 | - private function getInstalledAppsValues() { |
|
119 | - if (!$this->installedAppsCache) { |
|
120 | - $values = $this->appConfig->getValues(false, 'enabled'); |
|
121 | - |
|
122 | - $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
|
123 | - foreach($alwaysEnabledApps as $appId) { |
|
124 | - $values[$appId] = 'yes'; |
|
125 | - } |
|
126 | - |
|
127 | - $this->installedAppsCache = array_filter($values, function ($value) { |
|
128 | - return $value !== 'no'; |
|
129 | - }); |
|
130 | - ksort($this->installedAppsCache); |
|
131 | - } |
|
132 | - return $this->installedAppsCache; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * List all installed apps |
|
137 | - * |
|
138 | - * @return string[] |
|
139 | - */ |
|
140 | - public function getInstalledApps() { |
|
141 | - return array_keys($this->getInstalledAppsValues()); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * List all apps enabled for a user |
|
146 | - * |
|
147 | - * @param \OCP\IUser $user |
|
148 | - * @return string[] |
|
149 | - */ |
|
150 | - public function getEnabledAppsForUser(IUser $user) { |
|
151 | - $apps = $this->getInstalledAppsValues(); |
|
152 | - $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
153 | - return $this->checkAppForUser($enabled, $user); |
|
154 | - }); |
|
155 | - return array_keys($appsForUser); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param \OCP\IGroup $group |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - public function getEnabledAppsForGroup(IGroup $group): array { |
|
163 | - $apps = $this->getInstalledAppsValues(); |
|
164 | - $appsForGroups = array_filter($apps, function ($enabled) use ($group) { |
|
165 | - return $this->checkAppForGroups($enabled, $group); |
|
166 | - }); |
|
167 | - return array_keys($appsForGroups); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $appId |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - public function getAppRestriction(string $appId): array { |
|
175 | - $values = $this->getInstalledAppsValues(); |
|
176 | - |
|
177 | - if (!isset($values[$appId])) { |
|
178 | - return []; |
|
179 | - } |
|
180 | - |
|
181 | - if ($values[$appId] === 'yes' || $values[$appId] === 'no') { |
|
182 | - return []; |
|
183 | - } |
|
184 | - return json_decode($values[$appId]); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Check if an app is enabled for user |
|
190 | - * |
|
191 | - * @param string $appId |
|
192 | - * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used |
|
193 | - * @return bool |
|
194 | - */ |
|
195 | - public function isEnabledForUser($appId, $user = null) { |
|
196 | - if ($this->isAlwaysEnabled($appId)) { |
|
197 | - return true; |
|
198 | - } |
|
199 | - if ($user === null) { |
|
200 | - $user = $this->userSession->getUser(); |
|
201 | - } |
|
202 | - $installedApps = $this->getInstalledAppsValues(); |
|
203 | - if (isset($installedApps[$appId])) { |
|
204 | - return $this->checkAppForUser($installedApps[$appId], $user); |
|
205 | - } else { |
|
206 | - return false; |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $enabled |
|
212 | - * @param IUser $user |
|
213 | - * @return bool |
|
214 | - */ |
|
215 | - private function checkAppForUser($enabled, $user) { |
|
216 | - if ($enabled === 'yes') { |
|
217 | - return true; |
|
218 | - } elseif ($user === null) { |
|
219 | - return false; |
|
220 | - } else { |
|
221 | - if(empty($enabled)){ |
|
222 | - return false; |
|
223 | - } |
|
224 | - |
|
225 | - $groupIds = json_decode($enabled); |
|
226 | - |
|
227 | - if (!is_array($groupIds)) { |
|
228 | - $jsonError = json_last_error(); |
|
229 | - $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
230 | - return false; |
|
231 | - } |
|
232 | - |
|
233 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
234 | - foreach ($userGroups as $groupId) { |
|
235 | - if (in_array($groupId, $groupIds, true)) { |
|
236 | - return true; |
|
237 | - } |
|
238 | - } |
|
239 | - return false; |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @param string $enabled |
|
245 | - * @param IGroup $group |
|
246 | - * @return bool |
|
247 | - */ |
|
248 | - private function checkAppForGroups(string $enabled, IGroup $group): bool { |
|
249 | - if ($enabled === 'yes') { |
|
250 | - return true; |
|
251 | - } elseif ($group === null) { |
|
252 | - return false; |
|
253 | - } else { |
|
254 | - if (empty($enabled)) { |
|
255 | - return false; |
|
256 | - } |
|
257 | - |
|
258 | - $groupIds = json_decode($enabled); |
|
259 | - |
|
260 | - if (!is_array($groupIds)) { |
|
261 | - $jsonError = json_last_error(); |
|
262 | - $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
263 | - return false; |
|
264 | - } |
|
265 | - |
|
266 | - return in_array($group->getGID(), $groupIds); |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Check if an app is enabled in the instance |
|
272 | - * |
|
273 | - * Notice: This actually checks if the app is enabled and not only if it is installed. |
|
274 | - * |
|
275 | - * @param string $appId |
|
276 | - * @param \OCP\IGroup[]|String[] $groups |
|
277 | - * @return bool |
|
278 | - */ |
|
279 | - public function isInstalled($appId) { |
|
280 | - $installedApps = $this->getInstalledAppsValues(); |
|
281 | - return isset($installedApps[$appId]); |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Enable an app for every user |
|
286 | - * |
|
287 | - * @param string $appId |
|
288 | - * @throws AppPathNotFoundException |
|
289 | - */ |
|
290 | - public function enableApp($appId) { |
|
291 | - // Check if app exists |
|
292 | - $this->getAppPath($appId); |
|
293 | - |
|
294 | - $this->installedAppsCache[$appId] = 'yes'; |
|
295 | - $this->appConfig->setValue($appId, 'enabled', 'yes'); |
|
296 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( |
|
297 | - ManagerEvent::EVENT_APP_ENABLE, $appId |
|
298 | - )); |
|
299 | - $this->clearAppsCache(); |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Whether a list of types contains a protected app type |
|
304 | - * |
|
305 | - * @param string[] $types |
|
306 | - * @return bool |
|
307 | - */ |
|
308 | - public function hasProtectedAppType($types) { |
|
309 | - if (empty($types)) { |
|
310 | - return false; |
|
311 | - } |
|
312 | - |
|
313 | - $protectedTypes = array_intersect($this->protectedAppTypes, $types); |
|
314 | - return !empty($protectedTypes); |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Enable an app only for specific groups |
|
319 | - * |
|
320 | - * @param string $appId |
|
321 | - * @param \OCP\IGroup[] $groups |
|
322 | - * @throws \InvalidArgumentException if app can't be enabled for groups |
|
323 | - * @throws AppPathNotFoundException |
|
324 | - */ |
|
325 | - public function enableAppForGroups($appId, $groups) { |
|
326 | - // Check if app exists |
|
327 | - $this->getAppPath($appId); |
|
328 | - |
|
329 | - $info = $this->getAppInfo($appId); |
|
330 | - if (!empty($info['types']) && $this->hasProtectedAppType($info['types'])) { |
|
331 | - throw new \InvalidArgumentException("$appId can't be enabled for groups."); |
|
332 | - } |
|
333 | - |
|
334 | - $groupIds = array_map(function ($group) { |
|
335 | - /** @var \OCP\IGroup $group */ |
|
336 | - return ($group instanceof IGroup) |
|
337 | - ? $group->getGID() |
|
338 | - : $group; |
|
339 | - }, $groups); |
|
340 | - |
|
341 | - $this->installedAppsCache[$appId] = json_encode($groupIds); |
|
342 | - $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); |
|
343 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( |
|
344 | - ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups |
|
345 | - )); |
|
346 | - $this->clearAppsCache(); |
|
347 | - |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Disable an app for every user |
|
352 | - * |
|
353 | - * @param string $appId |
|
354 | - * @throws \Exception if app can't be disabled |
|
355 | - */ |
|
356 | - public function disableApp($appId) { |
|
357 | - if ($this->isAlwaysEnabled($appId)) { |
|
358 | - throw new \Exception("$appId can't be disabled."); |
|
359 | - } |
|
360 | - unset($this->installedAppsCache[$appId]); |
|
361 | - $this->appConfig->setValue($appId, 'enabled', 'no'); |
|
362 | - |
|
363 | - // run uninstall steps |
|
364 | - $appData = $this->getAppInfo($appId); |
|
365 | - if (!is_null($appData)) { |
|
366 | - \OC_App::executeRepairSteps($appId, $appData['repair-steps']['uninstall']); |
|
367 | - } |
|
368 | - |
|
369 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( |
|
370 | - ManagerEvent::EVENT_APP_DISABLE, $appId |
|
371 | - )); |
|
372 | - $this->clearAppsCache(); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Get the directory for the given app. |
|
377 | - * |
|
378 | - * @param string $appId |
|
379 | - * @return string |
|
380 | - * @throws AppPathNotFoundException if app folder can't be found |
|
381 | - */ |
|
382 | - public function getAppPath($appId) { |
|
383 | - $appPath = \OC_App::getAppPath($appId); |
|
384 | - if($appPath === false) { |
|
385 | - throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
386 | - } |
|
387 | - return $appPath; |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Clear the cached list of apps when enabling/disabling an app |
|
392 | - */ |
|
393 | - public function clearAppsCache() { |
|
394 | - $settingsMemCache = $this->memCacheFactory->createDistributed('settings'); |
|
395 | - $settingsMemCache->clear('listApps'); |
|
396 | - $this->appInfos = []; |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Returns a list of apps that need upgrade |
|
401 | - * |
|
402 | - * @param string $version Nextcloud version as array of version components |
|
403 | - * @return array list of app info from apps that need an upgrade |
|
404 | - * |
|
405 | - * @internal |
|
406 | - */ |
|
407 | - public function getAppsNeedingUpgrade($version) { |
|
408 | - $appsToUpgrade = []; |
|
409 | - $apps = $this->getInstalledApps(); |
|
410 | - foreach ($apps as $appId) { |
|
411 | - $appInfo = $this->getAppInfo($appId); |
|
412 | - $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); |
|
413 | - if ($appDbVersion |
|
414 | - && isset($appInfo['version']) |
|
415 | - && version_compare($appInfo['version'], $appDbVersion, '>') |
|
416 | - && \OC_App::isAppCompatible($version, $appInfo) |
|
417 | - ) { |
|
418 | - $appsToUpgrade[] = $appInfo; |
|
419 | - } |
|
420 | - } |
|
421 | - |
|
422 | - return $appsToUpgrade; |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Returns the app information from "appinfo/info.xml". |
|
427 | - * |
|
428 | - * @param string $appId app id |
|
429 | - * |
|
430 | - * @param bool $path |
|
431 | - * @param null $lang |
|
432 | - * @return array|null app info |
|
433 | - */ |
|
434 | - public function getAppInfo(string $appId, bool $path = false, $lang = null) { |
|
435 | - if ($path) { |
|
436 | - $file = $appId; |
|
437 | - } else { |
|
438 | - if ($lang === null && isset($this->appInfos[$appId])) { |
|
439 | - return $this->appInfos[$appId]; |
|
440 | - } |
|
441 | - try { |
|
442 | - $appPath = $this->getAppPath($appId); |
|
443 | - } catch (AppPathNotFoundException $e) { |
|
444 | - return null; |
|
445 | - } |
|
446 | - $file = $appPath . '/appinfo/info.xml'; |
|
447 | - } |
|
448 | - |
|
449 | - $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
|
450 | - $data = $parser->parse($file); |
|
451 | - |
|
452 | - if (is_array($data)) { |
|
453 | - $data = \OC_App::parseAppInfo($data, $lang); |
|
454 | - } |
|
455 | - |
|
456 | - if ($lang === null) { |
|
457 | - $this->appInfos[$appId] = $data; |
|
458 | - } |
|
459 | - |
|
460 | - return $data; |
|
461 | - } |
|
462 | - |
|
463 | - public function getAppVersion(string $appId, bool $useCache = true): string { |
|
464 | - if(!$useCache || !isset($this->appVersions[$appId])) { |
|
465 | - $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
|
466 | - $this->appVersions[$appId] = ($appInfo !== null && isset($appInfo['version'])) ? $appInfo['version'] : '0'; |
|
467 | - } |
|
468 | - return $this->appVersions[$appId]; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Returns a list of apps incompatible with the given version |
|
473 | - * |
|
474 | - * @param string $version Nextcloud version as array of version components |
|
475 | - * |
|
476 | - * @return array list of app info from incompatible apps |
|
477 | - * |
|
478 | - * @internal |
|
479 | - */ |
|
480 | - public function getIncompatibleApps(string $version): array { |
|
481 | - $apps = $this->getInstalledApps(); |
|
482 | - $incompatibleApps = array(); |
|
483 | - foreach ($apps as $appId) { |
|
484 | - $info = $this->getAppInfo($appId); |
|
485 | - if ($info === null) { |
|
486 | - $incompatibleApps[] = ['id' => $appId]; |
|
487 | - } else if (!\OC_App::isAppCompatible($version, $info)) { |
|
488 | - $incompatibleApps[] = $info; |
|
489 | - } |
|
490 | - } |
|
491 | - return $incompatibleApps; |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * @inheritdoc |
|
496 | - * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::isShipped() |
|
497 | - */ |
|
498 | - public function isShipped($appId) { |
|
499 | - $this->loadShippedJson(); |
|
500 | - return in_array($appId, $this->shippedApps, true); |
|
501 | - } |
|
502 | - |
|
503 | - private function isAlwaysEnabled($appId) { |
|
504 | - $alwaysEnabled = $this->getAlwaysEnabledApps(); |
|
505 | - return in_array($appId, $alwaysEnabled, true); |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::loadShippedJson() |
|
510 | - * @throws \Exception |
|
511 | - */ |
|
512 | - private function loadShippedJson() { |
|
513 | - if ($this->shippedApps === null) { |
|
514 | - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
515 | - if (!file_exists($shippedJson)) { |
|
516 | - throw new \Exception("File not found: $shippedJson"); |
|
517 | - } |
|
518 | - $content = json_decode(file_get_contents($shippedJson), true); |
|
519 | - $this->shippedApps = $content['shippedApps']; |
|
520 | - $this->alwaysEnabled = $content['alwaysEnabled']; |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * @inheritdoc |
|
526 | - */ |
|
527 | - public function getAlwaysEnabledApps() { |
|
528 | - $this->loadShippedJson(); |
|
529 | - return $this->alwaysEnabled; |
|
530 | - } |
|
49 | + /** |
|
50 | + * Apps with these types can not be enabled for certain groups only |
|
51 | + * @var string[] |
|
52 | + */ |
|
53 | + protected $protectedAppTypes = [ |
|
54 | + 'filesystem', |
|
55 | + 'prelogin', |
|
56 | + 'authentication', |
|
57 | + 'logging', |
|
58 | + 'prevent_group_restriction', |
|
59 | + ]; |
|
60 | + |
|
61 | + /** @var IUserSession */ |
|
62 | + private $userSession; |
|
63 | + |
|
64 | + /** @var AppConfig */ |
|
65 | + private $appConfig; |
|
66 | + |
|
67 | + /** @var IGroupManager */ |
|
68 | + private $groupManager; |
|
69 | + |
|
70 | + /** @var ICacheFactory */ |
|
71 | + private $memCacheFactory; |
|
72 | + |
|
73 | + /** @var EventDispatcherInterface */ |
|
74 | + private $dispatcher; |
|
75 | + |
|
76 | + /** @var ILogger */ |
|
77 | + private $logger; |
|
78 | + |
|
79 | + /** @var string[] $appId => $enabled */ |
|
80 | + private $installedAppsCache; |
|
81 | + |
|
82 | + /** @var string[] */ |
|
83 | + private $shippedApps; |
|
84 | + |
|
85 | + /** @var string[] */ |
|
86 | + private $alwaysEnabled; |
|
87 | + |
|
88 | + /** @var array */ |
|
89 | + private $appInfos = []; |
|
90 | + |
|
91 | + /** @var array */ |
|
92 | + private $appVersions = []; |
|
93 | + |
|
94 | + /** |
|
95 | + * @param IUserSession $userSession |
|
96 | + * @param AppConfig $appConfig |
|
97 | + * @param IGroupManager $groupManager |
|
98 | + * @param ICacheFactory $memCacheFactory |
|
99 | + * @param EventDispatcherInterface $dispatcher |
|
100 | + */ |
|
101 | + public function __construct(IUserSession $userSession, |
|
102 | + AppConfig $appConfig, |
|
103 | + IGroupManager $groupManager, |
|
104 | + ICacheFactory $memCacheFactory, |
|
105 | + EventDispatcherInterface $dispatcher, |
|
106 | + ILogger $logger) { |
|
107 | + $this->userSession = $userSession; |
|
108 | + $this->appConfig = $appConfig; |
|
109 | + $this->groupManager = $groupManager; |
|
110 | + $this->memCacheFactory = $memCacheFactory; |
|
111 | + $this->dispatcher = $dispatcher; |
|
112 | + $this->logger = $logger; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @return string[] $appId => $enabled |
|
117 | + */ |
|
118 | + private function getInstalledAppsValues() { |
|
119 | + if (!$this->installedAppsCache) { |
|
120 | + $values = $this->appConfig->getValues(false, 'enabled'); |
|
121 | + |
|
122 | + $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
|
123 | + foreach($alwaysEnabledApps as $appId) { |
|
124 | + $values[$appId] = 'yes'; |
|
125 | + } |
|
126 | + |
|
127 | + $this->installedAppsCache = array_filter($values, function ($value) { |
|
128 | + return $value !== 'no'; |
|
129 | + }); |
|
130 | + ksort($this->installedAppsCache); |
|
131 | + } |
|
132 | + return $this->installedAppsCache; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * List all installed apps |
|
137 | + * |
|
138 | + * @return string[] |
|
139 | + */ |
|
140 | + public function getInstalledApps() { |
|
141 | + return array_keys($this->getInstalledAppsValues()); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * List all apps enabled for a user |
|
146 | + * |
|
147 | + * @param \OCP\IUser $user |
|
148 | + * @return string[] |
|
149 | + */ |
|
150 | + public function getEnabledAppsForUser(IUser $user) { |
|
151 | + $apps = $this->getInstalledAppsValues(); |
|
152 | + $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
153 | + return $this->checkAppForUser($enabled, $user); |
|
154 | + }); |
|
155 | + return array_keys($appsForUser); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param \OCP\IGroup $group |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + public function getEnabledAppsForGroup(IGroup $group): array { |
|
163 | + $apps = $this->getInstalledAppsValues(); |
|
164 | + $appsForGroups = array_filter($apps, function ($enabled) use ($group) { |
|
165 | + return $this->checkAppForGroups($enabled, $group); |
|
166 | + }); |
|
167 | + return array_keys($appsForGroups); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $appId |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + public function getAppRestriction(string $appId): array { |
|
175 | + $values = $this->getInstalledAppsValues(); |
|
176 | + |
|
177 | + if (!isset($values[$appId])) { |
|
178 | + return []; |
|
179 | + } |
|
180 | + |
|
181 | + if ($values[$appId] === 'yes' || $values[$appId] === 'no') { |
|
182 | + return []; |
|
183 | + } |
|
184 | + return json_decode($values[$appId]); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Check if an app is enabled for user |
|
190 | + * |
|
191 | + * @param string $appId |
|
192 | + * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used |
|
193 | + * @return bool |
|
194 | + */ |
|
195 | + public function isEnabledForUser($appId, $user = null) { |
|
196 | + if ($this->isAlwaysEnabled($appId)) { |
|
197 | + return true; |
|
198 | + } |
|
199 | + if ($user === null) { |
|
200 | + $user = $this->userSession->getUser(); |
|
201 | + } |
|
202 | + $installedApps = $this->getInstalledAppsValues(); |
|
203 | + if (isset($installedApps[$appId])) { |
|
204 | + return $this->checkAppForUser($installedApps[$appId], $user); |
|
205 | + } else { |
|
206 | + return false; |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $enabled |
|
212 | + * @param IUser $user |
|
213 | + * @return bool |
|
214 | + */ |
|
215 | + private function checkAppForUser($enabled, $user) { |
|
216 | + if ($enabled === 'yes') { |
|
217 | + return true; |
|
218 | + } elseif ($user === null) { |
|
219 | + return false; |
|
220 | + } else { |
|
221 | + if(empty($enabled)){ |
|
222 | + return false; |
|
223 | + } |
|
224 | + |
|
225 | + $groupIds = json_decode($enabled); |
|
226 | + |
|
227 | + if (!is_array($groupIds)) { |
|
228 | + $jsonError = json_last_error(); |
|
229 | + $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
230 | + return false; |
|
231 | + } |
|
232 | + |
|
233 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
234 | + foreach ($userGroups as $groupId) { |
|
235 | + if (in_array($groupId, $groupIds, true)) { |
|
236 | + return true; |
|
237 | + } |
|
238 | + } |
|
239 | + return false; |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @param string $enabled |
|
245 | + * @param IGroup $group |
|
246 | + * @return bool |
|
247 | + */ |
|
248 | + private function checkAppForGroups(string $enabled, IGroup $group): bool { |
|
249 | + if ($enabled === 'yes') { |
|
250 | + return true; |
|
251 | + } elseif ($group === null) { |
|
252 | + return false; |
|
253 | + } else { |
|
254 | + if (empty($enabled)) { |
|
255 | + return false; |
|
256 | + } |
|
257 | + |
|
258 | + $groupIds = json_decode($enabled); |
|
259 | + |
|
260 | + if (!is_array($groupIds)) { |
|
261 | + $jsonError = json_last_error(); |
|
262 | + $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
263 | + return false; |
|
264 | + } |
|
265 | + |
|
266 | + return in_array($group->getGID(), $groupIds); |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Check if an app is enabled in the instance |
|
272 | + * |
|
273 | + * Notice: This actually checks if the app is enabled and not only if it is installed. |
|
274 | + * |
|
275 | + * @param string $appId |
|
276 | + * @param \OCP\IGroup[]|String[] $groups |
|
277 | + * @return bool |
|
278 | + */ |
|
279 | + public function isInstalled($appId) { |
|
280 | + $installedApps = $this->getInstalledAppsValues(); |
|
281 | + return isset($installedApps[$appId]); |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Enable an app for every user |
|
286 | + * |
|
287 | + * @param string $appId |
|
288 | + * @throws AppPathNotFoundException |
|
289 | + */ |
|
290 | + public function enableApp($appId) { |
|
291 | + // Check if app exists |
|
292 | + $this->getAppPath($appId); |
|
293 | + |
|
294 | + $this->installedAppsCache[$appId] = 'yes'; |
|
295 | + $this->appConfig->setValue($appId, 'enabled', 'yes'); |
|
296 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( |
|
297 | + ManagerEvent::EVENT_APP_ENABLE, $appId |
|
298 | + )); |
|
299 | + $this->clearAppsCache(); |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Whether a list of types contains a protected app type |
|
304 | + * |
|
305 | + * @param string[] $types |
|
306 | + * @return bool |
|
307 | + */ |
|
308 | + public function hasProtectedAppType($types) { |
|
309 | + if (empty($types)) { |
|
310 | + return false; |
|
311 | + } |
|
312 | + |
|
313 | + $protectedTypes = array_intersect($this->protectedAppTypes, $types); |
|
314 | + return !empty($protectedTypes); |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Enable an app only for specific groups |
|
319 | + * |
|
320 | + * @param string $appId |
|
321 | + * @param \OCP\IGroup[] $groups |
|
322 | + * @throws \InvalidArgumentException if app can't be enabled for groups |
|
323 | + * @throws AppPathNotFoundException |
|
324 | + */ |
|
325 | + public function enableAppForGroups($appId, $groups) { |
|
326 | + // Check if app exists |
|
327 | + $this->getAppPath($appId); |
|
328 | + |
|
329 | + $info = $this->getAppInfo($appId); |
|
330 | + if (!empty($info['types']) && $this->hasProtectedAppType($info['types'])) { |
|
331 | + throw new \InvalidArgumentException("$appId can't be enabled for groups."); |
|
332 | + } |
|
333 | + |
|
334 | + $groupIds = array_map(function ($group) { |
|
335 | + /** @var \OCP\IGroup $group */ |
|
336 | + return ($group instanceof IGroup) |
|
337 | + ? $group->getGID() |
|
338 | + : $group; |
|
339 | + }, $groups); |
|
340 | + |
|
341 | + $this->installedAppsCache[$appId] = json_encode($groupIds); |
|
342 | + $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); |
|
343 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( |
|
344 | + ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups |
|
345 | + )); |
|
346 | + $this->clearAppsCache(); |
|
347 | + |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Disable an app for every user |
|
352 | + * |
|
353 | + * @param string $appId |
|
354 | + * @throws \Exception if app can't be disabled |
|
355 | + */ |
|
356 | + public function disableApp($appId) { |
|
357 | + if ($this->isAlwaysEnabled($appId)) { |
|
358 | + throw new \Exception("$appId can't be disabled."); |
|
359 | + } |
|
360 | + unset($this->installedAppsCache[$appId]); |
|
361 | + $this->appConfig->setValue($appId, 'enabled', 'no'); |
|
362 | + |
|
363 | + // run uninstall steps |
|
364 | + $appData = $this->getAppInfo($appId); |
|
365 | + if (!is_null($appData)) { |
|
366 | + \OC_App::executeRepairSteps($appId, $appData['repair-steps']['uninstall']); |
|
367 | + } |
|
368 | + |
|
369 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( |
|
370 | + ManagerEvent::EVENT_APP_DISABLE, $appId |
|
371 | + )); |
|
372 | + $this->clearAppsCache(); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Get the directory for the given app. |
|
377 | + * |
|
378 | + * @param string $appId |
|
379 | + * @return string |
|
380 | + * @throws AppPathNotFoundException if app folder can't be found |
|
381 | + */ |
|
382 | + public function getAppPath($appId) { |
|
383 | + $appPath = \OC_App::getAppPath($appId); |
|
384 | + if($appPath === false) { |
|
385 | + throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
386 | + } |
|
387 | + return $appPath; |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Clear the cached list of apps when enabling/disabling an app |
|
392 | + */ |
|
393 | + public function clearAppsCache() { |
|
394 | + $settingsMemCache = $this->memCacheFactory->createDistributed('settings'); |
|
395 | + $settingsMemCache->clear('listApps'); |
|
396 | + $this->appInfos = []; |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Returns a list of apps that need upgrade |
|
401 | + * |
|
402 | + * @param string $version Nextcloud version as array of version components |
|
403 | + * @return array list of app info from apps that need an upgrade |
|
404 | + * |
|
405 | + * @internal |
|
406 | + */ |
|
407 | + public function getAppsNeedingUpgrade($version) { |
|
408 | + $appsToUpgrade = []; |
|
409 | + $apps = $this->getInstalledApps(); |
|
410 | + foreach ($apps as $appId) { |
|
411 | + $appInfo = $this->getAppInfo($appId); |
|
412 | + $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); |
|
413 | + if ($appDbVersion |
|
414 | + && isset($appInfo['version']) |
|
415 | + && version_compare($appInfo['version'], $appDbVersion, '>') |
|
416 | + && \OC_App::isAppCompatible($version, $appInfo) |
|
417 | + ) { |
|
418 | + $appsToUpgrade[] = $appInfo; |
|
419 | + } |
|
420 | + } |
|
421 | + |
|
422 | + return $appsToUpgrade; |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Returns the app information from "appinfo/info.xml". |
|
427 | + * |
|
428 | + * @param string $appId app id |
|
429 | + * |
|
430 | + * @param bool $path |
|
431 | + * @param null $lang |
|
432 | + * @return array|null app info |
|
433 | + */ |
|
434 | + public function getAppInfo(string $appId, bool $path = false, $lang = null) { |
|
435 | + if ($path) { |
|
436 | + $file = $appId; |
|
437 | + } else { |
|
438 | + if ($lang === null && isset($this->appInfos[$appId])) { |
|
439 | + return $this->appInfos[$appId]; |
|
440 | + } |
|
441 | + try { |
|
442 | + $appPath = $this->getAppPath($appId); |
|
443 | + } catch (AppPathNotFoundException $e) { |
|
444 | + return null; |
|
445 | + } |
|
446 | + $file = $appPath . '/appinfo/info.xml'; |
|
447 | + } |
|
448 | + |
|
449 | + $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
|
450 | + $data = $parser->parse($file); |
|
451 | + |
|
452 | + if (is_array($data)) { |
|
453 | + $data = \OC_App::parseAppInfo($data, $lang); |
|
454 | + } |
|
455 | + |
|
456 | + if ($lang === null) { |
|
457 | + $this->appInfos[$appId] = $data; |
|
458 | + } |
|
459 | + |
|
460 | + return $data; |
|
461 | + } |
|
462 | + |
|
463 | + public function getAppVersion(string $appId, bool $useCache = true): string { |
|
464 | + if(!$useCache || !isset($this->appVersions[$appId])) { |
|
465 | + $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
|
466 | + $this->appVersions[$appId] = ($appInfo !== null && isset($appInfo['version'])) ? $appInfo['version'] : '0'; |
|
467 | + } |
|
468 | + return $this->appVersions[$appId]; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Returns a list of apps incompatible with the given version |
|
473 | + * |
|
474 | + * @param string $version Nextcloud version as array of version components |
|
475 | + * |
|
476 | + * @return array list of app info from incompatible apps |
|
477 | + * |
|
478 | + * @internal |
|
479 | + */ |
|
480 | + public function getIncompatibleApps(string $version): array { |
|
481 | + $apps = $this->getInstalledApps(); |
|
482 | + $incompatibleApps = array(); |
|
483 | + foreach ($apps as $appId) { |
|
484 | + $info = $this->getAppInfo($appId); |
|
485 | + if ($info === null) { |
|
486 | + $incompatibleApps[] = ['id' => $appId]; |
|
487 | + } else if (!\OC_App::isAppCompatible($version, $info)) { |
|
488 | + $incompatibleApps[] = $info; |
|
489 | + } |
|
490 | + } |
|
491 | + return $incompatibleApps; |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * @inheritdoc |
|
496 | + * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::isShipped() |
|
497 | + */ |
|
498 | + public function isShipped($appId) { |
|
499 | + $this->loadShippedJson(); |
|
500 | + return in_array($appId, $this->shippedApps, true); |
|
501 | + } |
|
502 | + |
|
503 | + private function isAlwaysEnabled($appId) { |
|
504 | + $alwaysEnabled = $this->getAlwaysEnabledApps(); |
|
505 | + return in_array($appId, $alwaysEnabled, true); |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * In case you change this method, also change \OC\App\CodeChecker\InfoChecker::loadShippedJson() |
|
510 | + * @throws \Exception |
|
511 | + */ |
|
512 | + private function loadShippedJson() { |
|
513 | + if ($this->shippedApps === null) { |
|
514 | + $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
515 | + if (!file_exists($shippedJson)) { |
|
516 | + throw new \Exception("File not found: $shippedJson"); |
|
517 | + } |
|
518 | + $content = json_decode(file_get_contents($shippedJson), true); |
|
519 | + $this->shippedApps = $content['shippedApps']; |
|
520 | + $this->alwaysEnabled = $content['alwaysEnabled']; |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * @inheritdoc |
|
526 | + */ |
|
527 | + public function getAlwaysEnabledApps() { |
|
528 | + $this->loadShippedJson(); |
|
529 | + return $this->alwaysEnabled; |
|
530 | + } |
|
531 | 531 | } |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | $values = $this->appConfig->getValues(false, 'enabled'); |
121 | 121 | |
122 | 122 | $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
123 | - foreach($alwaysEnabledApps as $appId) { |
|
123 | + foreach ($alwaysEnabledApps as $appId) { |
|
124 | 124 | $values[$appId] = 'yes'; |
125 | 125 | } |
126 | 126 | |
127 | - $this->installedAppsCache = array_filter($values, function ($value) { |
|
127 | + $this->installedAppsCache = array_filter($values, function($value) { |
|
128 | 128 | return $value !== 'no'; |
129 | 129 | }); |
130 | 130 | ksort($this->installedAppsCache); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function getEnabledAppsForUser(IUser $user) { |
151 | 151 | $apps = $this->getInstalledAppsValues(); |
152 | - $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
152 | + $appsForUser = array_filter($apps, function($enabled) use ($user) { |
|
153 | 153 | return $this->checkAppForUser($enabled, $user); |
154 | 154 | }); |
155 | 155 | return array_keys($appsForUser); |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function getEnabledAppsForGroup(IGroup $group): array { |
163 | 163 | $apps = $this->getInstalledAppsValues(); |
164 | - $appsForGroups = array_filter($apps, function ($enabled) use ($group) { |
|
164 | + $appsForGroups = array_filter($apps, function($enabled) use ($group) { |
|
165 | 165 | return $this->checkAppForGroups($enabled, $group); |
166 | 166 | }); |
167 | 167 | return array_keys($appsForGroups); |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } elseif ($user === null) { |
219 | 219 | return false; |
220 | 220 | } else { |
221 | - if(empty($enabled)){ |
|
221 | + if (empty($enabled)) { |
|
222 | 222 | return false; |
223 | 223 | } |
224 | 224 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | |
227 | 227 | if (!is_array($groupIds)) { |
228 | 228 | $jsonError = json_last_error(); |
229 | - $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
229 | + $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: '.print_r($enabled, true).' - json error code: '.$jsonError, ['app' => 'lib']); |
|
230 | 230 | return false; |
231 | 231 | } |
232 | 232 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | |
260 | 260 | if (!is_array($groupIds)) { |
261 | 261 | $jsonError = json_last_error(); |
262 | - $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
262 | + $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: '.print_r($enabled, true).' - json error code: '.$jsonError, ['app' => 'lib']); |
|
263 | 263 | return false; |
264 | 264 | } |
265 | 265 | |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | throw new \InvalidArgumentException("$appId can't be enabled for groups."); |
332 | 332 | } |
333 | 333 | |
334 | - $groupIds = array_map(function ($group) { |
|
334 | + $groupIds = array_map(function($group) { |
|
335 | 335 | /** @var \OCP\IGroup $group */ |
336 | 336 | return ($group instanceof IGroup) |
337 | 337 | ? $group->getGID() |
@@ -381,8 +381,8 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public function getAppPath($appId) { |
383 | 383 | $appPath = \OC_App::getAppPath($appId); |
384 | - if($appPath === false) { |
|
385 | - throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
384 | + if ($appPath === false) { |
|
385 | + throw new AppPathNotFoundException('Could not find path for '.$appId); |
|
386 | 386 | } |
387 | 387 | return $appPath; |
388 | 388 | } |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | } catch (AppPathNotFoundException $e) { |
444 | 444 | return null; |
445 | 445 | } |
446 | - $file = $appPath . '/appinfo/info.xml'; |
|
446 | + $file = $appPath.'/appinfo/info.xml'; |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | } |
462 | 462 | |
463 | 463 | public function getAppVersion(string $appId, bool $useCache = true): string { |
464 | - if(!$useCache || !isset($this->appVersions[$appId])) { |
|
464 | + if (!$useCache || !isset($this->appVersions[$appId])) { |
|
465 | 465 | $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
466 | 466 | $this->appVersions[$appId] = ($appInfo !== null && isset($appInfo['version'])) ? $appInfo['version'] : '0'; |
467 | 467 | } |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | */ |
512 | 512 | private function loadShippedJson() { |
513 | 513 | if ($this->shippedApps === null) { |
514 | - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
514 | + $shippedJson = \OC::$SERVERROOT.'/core/shipped.json'; |
|
515 | 515 | if (!file_exists($shippedJson)) { |
516 | 516 | throw new \Exception("File not found: $shippedJson"); |
517 | 517 | } |
@@ -168,1908 +168,1908 @@ |
||
168 | 168 | * TODO: hookup all manager classes |
169 | 169 | */ |
170 | 170 | class Server extends ServerContainer implements IServerContainer { |
171 | - /** @var string */ |
|
172 | - private $webRoot; |
|
173 | - |
|
174 | - /** |
|
175 | - * @param string $webRoot |
|
176 | - * @param \OC\Config $config |
|
177 | - */ |
|
178 | - public function __construct($webRoot, \OC\Config $config) { |
|
179 | - parent::__construct(); |
|
180 | - $this->webRoot = $webRoot; |
|
181 | - |
|
182 | - // To find out if we are running from CLI or not |
|
183 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
184 | - |
|
185 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
186 | - return $c; |
|
187 | - }); |
|
188 | - |
|
189 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
190 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
191 | - |
|
192 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
193 | - $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
194 | - |
|
195 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
196 | - $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
197 | - |
|
198 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
199 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
200 | - |
|
201 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
202 | - |
|
203 | - |
|
204 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
205 | - return new PreviewManager( |
|
206 | - $c->getConfig(), |
|
207 | - $c->getRootFolder(), |
|
208 | - $c->getAppDataDir('preview'), |
|
209 | - $c->getEventDispatcher(), |
|
210 | - $c->getGeneratorHelper(), |
|
211 | - $c->getSession()->get('user_id') |
|
212 | - ); |
|
213 | - }); |
|
214 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
215 | - |
|
216 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
217 | - return new \OC\Preview\Watcher( |
|
218 | - $c->getAppDataDir('preview') |
|
219 | - ); |
|
220 | - }); |
|
221 | - |
|
222 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
223 | - $view = new View(); |
|
224 | - $util = new Encryption\Util( |
|
225 | - $view, |
|
226 | - $c->getUserManager(), |
|
227 | - $c->getGroupManager(), |
|
228 | - $c->getConfig() |
|
229 | - ); |
|
230 | - return new Encryption\Manager( |
|
231 | - $c->getConfig(), |
|
232 | - $c->getLogger(), |
|
233 | - $c->getL10N('core'), |
|
234 | - new View(), |
|
235 | - $util, |
|
236 | - new ArrayCache() |
|
237 | - ); |
|
238 | - }); |
|
239 | - $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
240 | - |
|
241 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
242 | - $util = new Encryption\Util( |
|
243 | - new View(), |
|
244 | - $c->getUserManager(), |
|
245 | - $c->getGroupManager(), |
|
246 | - $c->getConfig() |
|
247 | - ); |
|
248 | - return new Encryption\File( |
|
249 | - $util, |
|
250 | - $c->getRootFolder(), |
|
251 | - $c->getShareManager() |
|
252 | - ); |
|
253 | - }); |
|
254 | - |
|
255 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
256 | - $view = new View(); |
|
257 | - $util = new Encryption\Util( |
|
258 | - $view, |
|
259 | - $c->getUserManager(), |
|
260 | - $c->getGroupManager(), |
|
261 | - $c->getConfig() |
|
262 | - ); |
|
263 | - |
|
264 | - return new Encryption\Keys\Storage($view, $util); |
|
265 | - }); |
|
266 | - $this->registerService('TagMapper', function (Server $c) { |
|
267 | - return new TagMapper($c->getDatabaseConnection()); |
|
268 | - }); |
|
269 | - |
|
270 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
271 | - $tagMapper = $c->query('TagMapper'); |
|
272 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
273 | - }); |
|
274 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
275 | - |
|
276 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
277 | - $config = $c->getConfig(); |
|
278 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
279 | - return new $factoryClass($this); |
|
280 | - }); |
|
281 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
282 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
283 | - }); |
|
284 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
285 | - |
|
286 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
287 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
288 | - }); |
|
289 | - $this->registerService('RootFolder', function (Server $c) { |
|
290 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
291 | - $view = new View(); |
|
292 | - $root = new Root( |
|
293 | - $manager, |
|
294 | - $view, |
|
295 | - null, |
|
296 | - $c->getUserMountCache(), |
|
297 | - $this->getLogger(), |
|
298 | - $this->getUserManager() |
|
299 | - ); |
|
300 | - $connector = new HookConnector($root, $view); |
|
301 | - $connector->viewToNode(); |
|
302 | - |
|
303 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
304 | - $previewConnector->connectWatcher(); |
|
305 | - |
|
306 | - return $root; |
|
307 | - }); |
|
308 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
309 | - |
|
310 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
311 | - return new LazyRoot(function () use ($c) { |
|
312 | - return $c->query('RootFolder'); |
|
313 | - }); |
|
314 | - }); |
|
315 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
316 | - |
|
317 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
318 | - return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher()); |
|
319 | - }); |
|
320 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
321 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
322 | - |
|
323 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
324 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
325 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
326 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
327 | - }); |
|
328 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
329 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
330 | - }); |
|
331 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
332 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
333 | - }); |
|
334 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
335 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
336 | - }); |
|
337 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
338 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
339 | - }); |
|
340 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
341 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
342 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
343 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
344 | - }); |
|
345 | - return $groupManager; |
|
346 | - }); |
|
347 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
348 | - |
|
349 | - $this->registerService(Store::class, function (Server $c) { |
|
350 | - $session = $c->getSession(); |
|
351 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
352 | - $tokenProvider = $c->query(IProvider::class); |
|
353 | - } else { |
|
354 | - $tokenProvider = null; |
|
355 | - } |
|
356 | - $logger = $c->getLogger(); |
|
357 | - return new Store($session, $logger, $tokenProvider); |
|
358 | - }); |
|
359 | - $this->registerAlias(IStore::class, Store::class); |
|
360 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
361 | - $dbConnection = $c->getDatabaseConnection(); |
|
362 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
363 | - }); |
|
364 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
365 | - |
|
366 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
367 | - $manager = $c->getUserManager(); |
|
368 | - $session = new \OC\Session\Memory(''); |
|
369 | - $timeFactory = new TimeFactory(); |
|
370 | - // Token providers might require a working database. This code |
|
371 | - // might however be called when ownCloud is not yet setup. |
|
372 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
373 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
374 | - } else { |
|
375 | - $defaultTokenProvider = null; |
|
376 | - } |
|
377 | - |
|
378 | - $dispatcher = $c->getEventDispatcher(); |
|
379 | - |
|
380 | - $userSession = new \OC\User\Session( |
|
381 | - $manager, |
|
382 | - $session, |
|
383 | - $timeFactory, |
|
384 | - $defaultTokenProvider, |
|
385 | - $c->getConfig(), |
|
386 | - $c->getSecureRandom(), |
|
387 | - $c->getLockdownManager(), |
|
388 | - $c->getLogger() |
|
389 | - ); |
|
390 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
391 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
392 | - }); |
|
393 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
394 | - /** @var $user \OC\User\User */ |
|
395 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
396 | - }); |
|
397 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
398 | - /** @var $user \OC\User\User */ |
|
399 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
400 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
401 | - }); |
|
402 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
403 | - /** @var $user \OC\User\User */ |
|
404 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
405 | - }); |
|
406 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
407 | - /** @var $user \OC\User\User */ |
|
408 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
409 | - }); |
|
410 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
411 | - /** @var $user \OC\User\User */ |
|
412 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
413 | - }); |
|
414 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
415 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
416 | - }); |
|
417 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
418 | - /** @var $user \OC\User\User */ |
|
419 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
|
420 | - }); |
|
421 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
422 | - /** @var $user \OC\User\User */ |
|
423 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
424 | - }); |
|
425 | - $userSession->listen('\OC\User', 'logout', function () { |
|
426 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
427 | - }); |
|
428 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
429 | - /** @var $user \OC\User\User */ |
|
430 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
431 | - }); |
|
432 | - return $userSession; |
|
433 | - }); |
|
434 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
435 | - $this->registerAlias('UserSession', \OC\User\Session::class); |
|
436 | - |
|
437 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
438 | - |
|
439 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
440 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
441 | - |
|
442 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
443 | - return new \OC\AllConfig( |
|
444 | - $c->getSystemConfig() |
|
445 | - ); |
|
446 | - }); |
|
447 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
448 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
449 | - |
|
450 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
451 | - return new \OC\SystemConfig($config); |
|
452 | - }); |
|
453 | - |
|
454 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
455 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
456 | - }); |
|
457 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
458 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
459 | - |
|
460 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
461 | - return new \OC\L10N\Factory( |
|
462 | - $c->getConfig(), |
|
463 | - $c->getRequest(), |
|
464 | - $c->getUserSession(), |
|
465 | - \OC::$SERVERROOT |
|
466 | - ); |
|
467 | - }); |
|
468 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
469 | - |
|
470 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
471 | - $config = $c->getConfig(); |
|
472 | - $cacheFactory = $c->getMemCacheFactory(); |
|
473 | - $request = $c->getRequest(); |
|
474 | - return new \OC\URLGenerator( |
|
475 | - $config, |
|
476 | - $cacheFactory, |
|
477 | - $request |
|
478 | - ); |
|
479 | - }); |
|
480 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
481 | - |
|
482 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
483 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
484 | - |
|
485 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
486 | - return new Cache\File(); |
|
487 | - }); |
|
488 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
489 | - |
|
490 | - $this->registerService(Factory::class, function (Server $c) { |
|
491 | - |
|
492 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
493 | - ArrayCache::class, |
|
494 | - ArrayCache::class, |
|
495 | - ArrayCache::class |
|
496 | - ); |
|
497 | - $config = $c->getConfig(); |
|
498 | - |
|
499 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
500 | - $v = \OC_App::getAppVersions(); |
|
501 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
502 | - $version = implode(',', $v); |
|
503 | - $instanceId = \OC_Util::getInstanceId(); |
|
504 | - $path = \OC::$SERVERROOT; |
|
505 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
506 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
507 | - $config->getSystemValue('memcache.local', null), |
|
508 | - $config->getSystemValue('memcache.distributed', null), |
|
509 | - $config->getSystemValue('memcache.locking', null) |
|
510 | - ); |
|
511 | - } |
|
512 | - return $arrayCacheFactory; |
|
513 | - |
|
514 | - }); |
|
515 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
516 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
517 | - |
|
518 | - $this->registerService('RedisFactory', function (Server $c) { |
|
519 | - $systemConfig = $c->getSystemConfig(); |
|
520 | - return new RedisFactory($systemConfig); |
|
521 | - }); |
|
522 | - |
|
523 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
524 | - return new \OC\Activity\Manager( |
|
525 | - $c->getRequest(), |
|
526 | - $c->getUserSession(), |
|
527 | - $c->getConfig(), |
|
528 | - $c->query(IValidator::class) |
|
529 | - ); |
|
530 | - }); |
|
531 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
532 | - |
|
533 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
534 | - return new \OC\Activity\EventMerger( |
|
535 | - $c->getL10N('lib') |
|
536 | - ); |
|
537 | - }); |
|
538 | - $this->registerAlias(IValidator::class, Validator::class); |
|
539 | - |
|
540 | - $this->registerService(AvatarManager::class, function(Server $c) { |
|
541 | - return new AvatarManager( |
|
542 | - $c->query(\OC\User\Manager::class), |
|
543 | - $c->getAppDataDir('avatar'), |
|
544 | - $c->getL10N('lib'), |
|
545 | - $c->getLogger(), |
|
546 | - $c->getConfig() |
|
547 | - ); |
|
548 | - }); |
|
549 | - $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class); |
|
550 | - $this->registerAlias('AvatarManager', AvatarManager::class); |
|
551 | - |
|
552 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
553 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
554 | - |
|
555 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
556 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
557 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
558 | - $logger = $factory->get($logType); |
|
559 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
560 | - |
|
561 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
562 | - }); |
|
563 | - $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
|
564 | - $this->registerAlias('Logger', \OC\Log::class); |
|
565 | - |
|
566 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
567 | - return new LogFactory($c, $this->getSystemConfig()); |
|
568 | - }); |
|
569 | - |
|
570 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
571 | - $config = $c->getConfig(); |
|
572 | - return new \OC\BackgroundJob\JobList( |
|
573 | - $c->getDatabaseConnection(), |
|
574 | - $config, |
|
575 | - new TimeFactory() |
|
576 | - ); |
|
577 | - }); |
|
578 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
579 | - |
|
580 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
581 | - $cacheFactory = $c->getMemCacheFactory(); |
|
582 | - $logger = $c->getLogger(); |
|
583 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
584 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
585 | - } else { |
|
586 | - $router = new \OC\Route\Router($logger); |
|
587 | - } |
|
588 | - return $router; |
|
589 | - }); |
|
590 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
591 | - |
|
592 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
593 | - return new Search(); |
|
594 | - }); |
|
595 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
596 | - |
|
597 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
598 | - return new \OC\Security\RateLimiting\Limiter( |
|
599 | - $this->getUserSession(), |
|
600 | - $this->getRequest(), |
|
601 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
602 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
603 | - ); |
|
604 | - }); |
|
605 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
606 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
607 | - $this->getMemCacheFactory(), |
|
608 | - new \OC\AppFramework\Utility\TimeFactory() |
|
609 | - ); |
|
610 | - }); |
|
611 | - |
|
612 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
613 | - return new SecureRandom(); |
|
614 | - }); |
|
615 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
616 | - |
|
617 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
618 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
619 | - }); |
|
620 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
621 | - |
|
622 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
623 | - return new Hasher($c->getConfig()); |
|
624 | - }); |
|
625 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
626 | - |
|
627 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
628 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
629 | - }); |
|
630 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
631 | - |
|
632 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
633 | - $systemConfig = $c->getSystemConfig(); |
|
634 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
635 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
636 | - if (!$factory->isValidType($type)) { |
|
637 | - throw new \OC\DatabaseException('Invalid database type'); |
|
638 | - } |
|
639 | - $connectionParams = $factory->createConnectionParams(); |
|
640 | - $connection = $factory->getConnection($type, $connectionParams); |
|
641 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
642 | - return $connection; |
|
643 | - }); |
|
644 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
645 | - |
|
646 | - |
|
647 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
648 | - $user = \OC_User::getUser(); |
|
649 | - $uid = $user ? $user : null; |
|
650 | - return new ClientService( |
|
651 | - $c->getConfig(), |
|
652 | - new \OC\Security\CertificateManager( |
|
653 | - $uid, |
|
654 | - new View(), |
|
655 | - $c->getConfig(), |
|
656 | - $c->getLogger(), |
|
657 | - $c->getSecureRandom() |
|
658 | - ) |
|
659 | - ); |
|
660 | - }); |
|
661 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
662 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
663 | - $eventLogger = new EventLogger(); |
|
664 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
665 | - // In debug mode, module is being activated by default |
|
666 | - $eventLogger->activate(); |
|
667 | - } |
|
668 | - return $eventLogger; |
|
669 | - }); |
|
670 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
671 | - |
|
672 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
673 | - $queryLogger = new QueryLogger(); |
|
674 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
675 | - // In debug mode, module is being activated by default |
|
676 | - $queryLogger->activate(); |
|
677 | - } |
|
678 | - return $queryLogger; |
|
679 | - }); |
|
680 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
681 | - |
|
682 | - $this->registerService(TempManager::class, function (Server $c) { |
|
683 | - return new TempManager( |
|
684 | - $c->getLogger(), |
|
685 | - $c->getConfig() |
|
686 | - ); |
|
687 | - }); |
|
688 | - $this->registerAlias('TempManager', TempManager::class); |
|
689 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
690 | - |
|
691 | - $this->registerService(AppManager::class, function (Server $c) { |
|
692 | - return new \OC\App\AppManager( |
|
693 | - $c->getUserSession(), |
|
694 | - $c->query(\OC\AppConfig::class), |
|
695 | - $c->getGroupManager(), |
|
696 | - $c->getMemCacheFactory(), |
|
697 | - $c->getEventDispatcher(), |
|
698 | - $c->getLogger() |
|
699 | - ); |
|
700 | - }); |
|
701 | - $this->registerAlias('AppManager', AppManager::class); |
|
702 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
703 | - |
|
704 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
705 | - return new DateTimeZone( |
|
706 | - $c->getConfig(), |
|
707 | - $c->getSession() |
|
708 | - ); |
|
709 | - }); |
|
710 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
711 | - |
|
712 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
713 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
714 | - |
|
715 | - return new DateTimeFormatter( |
|
716 | - $c->getDateTimeZone()->getTimeZone(), |
|
717 | - $c->getL10N('lib', $language) |
|
718 | - ); |
|
719 | - }); |
|
720 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
721 | - |
|
722 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
723 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
724 | - $listener = new UserMountCacheListener($mountCache); |
|
725 | - $listener->listen($c->getUserManager()); |
|
726 | - return $mountCache; |
|
727 | - }); |
|
728 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
729 | - |
|
730 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
731 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
732 | - $mountCache = $c->query('UserMountCache'); |
|
733 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
734 | - |
|
735 | - // builtin providers |
|
736 | - |
|
737 | - $config = $c->getConfig(); |
|
738 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
739 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
740 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
741 | - |
|
742 | - return $manager; |
|
743 | - }); |
|
744 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
745 | - |
|
746 | - $this->registerService('IniWrapper', function ($c) { |
|
747 | - return new IniGetWrapper(); |
|
748 | - }); |
|
749 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
750 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
751 | - if ($busClass) { |
|
752 | - list($app, $class) = explode('::', $busClass, 2); |
|
753 | - if ($c->getAppManager()->isInstalled($app)) { |
|
754 | - \OC_App::loadApp($app); |
|
755 | - return $c->query($class); |
|
756 | - } else { |
|
757 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
758 | - } |
|
759 | - } else { |
|
760 | - $jobList = $c->getJobList(); |
|
761 | - return new CronBus($jobList); |
|
762 | - } |
|
763 | - }); |
|
764 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
765 | - return new TrustedDomainHelper($this->getConfig()); |
|
766 | - }); |
|
767 | - $this->registerService(Throttler::class, function (Server $c) { |
|
768 | - return new Throttler( |
|
769 | - $c->getDatabaseConnection(), |
|
770 | - new TimeFactory(), |
|
771 | - $c->getLogger(), |
|
772 | - $c->getConfig() |
|
773 | - ); |
|
774 | - }); |
|
775 | - $this->registerAlias('Throttler', Throttler::class); |
|
776 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
777 | - // IConfig and IAppManager requires a working database. This code |
|
778 | - // might however be called when ownCloud is not yet setup. |
|
779 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
780 | - $config = $c->getConfig(); |
|
781 | - $appManager = $c->getAppManager(); |
|
782 | - } else { |
|
783 | - $config = null; |
|
784 | - $appManager = null; |
|
785 | - } |
|
786 | - |
|
787 | - return new Checker( |
|
788 | - new EnvironmentHelper(), |
|
789 | - new FileAccessHelper(), |
|
790 | - new AppLocator(), |
|
791 | - $config, |
|
792 | - $c->getMemCacheFactory(), |
|
793 | - $appManager, |
|
794 | - $c->getTempManager(), |
|
795 | - $c->getMimeTypeDetector() |
|
796 | - ); |
|
797 | - }); |
|
798 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
799 | - if (isset($this['urlParams'])) { |
|
800 | - $urlParams = $this['urlParams']; |
|
801 | - } else { |
|
802 | - $urlParams = []; |
|
803 | - } |
|
804 | - |
|
805 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
806 | - && in_array('fakeinput', stream_get_wrappers()) |
|
807 | - ) { |
|
808 | - $stream = 'fakeinput://data'; |
|
809 | - } else { |
|
810 | - $stream = 'php://input'; |
|
811 | - } |
|
812 | - |
|
813 | - return new Request( |
|
814 | - [ |
|
815 | - 'get' => $_GET, |
|
816 | - 'post' => $_POST, |
|
817 | - 'files' => $_FILES, |
|
818 | - 'server' => $_SERVER, |
|
819 | - 'env' => $_ENV, |
|
820 | - 'cookies' => $_COOKIE, |
|
821 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
822 | - ? $_SERVER['REQUEST_METHOD'] |
|
823 | - : '', |
|
824 | - 'urlParams' => $urlParams, |
|
825 | - ], |
|
826 | - $this->getSecureRandom(), |
|
827 | - $this->getConfig(), |
|
828 | - $this->getCsrfTokenManager(), |
|
829 | - $stream |
|
830 | - ); |
|
831 | - }); |
|
832 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
833 | - |
|
834 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
835 | - return new Mailer( |
|
836 | - $c->getConfig(), |
|
837 | - $c->getLogger(), |
|
838 | - $c->query(Defaults::class), |
|
839 | - $c->getURLGenerator(), |
|
840 | - $c->getL10N('lib') |
|
841 | - ); |
|
842 | - }); |
|
843 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
844 | - |
|
845 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
846 | - $config = $c->getConfig(); |
|
847 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
848 | - if (is_null($factoryClass)) { |
|
849 | - throw new \Exception('ldapProviderFactory not set'); |
|
850 | - } |
|
851 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
852 | - $factory = new $factoryClass($this); |
|
853 | - return $factory->getLDAPProvider(); |
|
854 | - }); |
|
855 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
856 | - $ini = $c->getIniWrapper(); |
|
857 | - $config = $c->getConfig(); |
|
858 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
859 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
860 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
861 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
862 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
863 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
864 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
865 | - } |
|
866 | - return new DBLockingProvider( |
|
867 | - $c->getDatabaseConnection(), |
|
868 | - $c->getLogger(), |
|
869 | - new TimeFactory(), |
|
870 | - $ttl, |
|
871 | - !\OC::$CLI |
|
872 | - ); |
|
873 | - } |
|
874 | - return new NoopLockingProvider(); |
|
875 | - }); |
|
876 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
877 | - |
|
878 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
879 | - return new \OC\Files\Mount\Manager(); |
|
880 | - }); |
|
881 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
882 | - |
|
883 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
884 | - return new \OC\Files\Type\Detection( |
|
885 | - $c->getURLGenerator(), |
|
886 | - \OC::$configDir, |
|
887 | - \OC::$SERVERROOT . '/resources/config/' |
|
888 | - ); |
|
889 | - }); |
|
890 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
891 | - |
|
892 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
893 | - return new \OC\Files\Type\Loader( |
|
894 | - $c->getDatabaseConnection() |
|
895 | - ); |
|
896 | - }); |
|
897 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
898 | - $this->registerService(BundleFetcher::class, function () { |
|
899 | - return new BundleFetcher($this->getL10N('lib')); |
|
900 | - }); |
|
901 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
902 | - return new Manager( |
|
903 | - $c->query(IValidator::class) |
|
904 | - ); |
|
905 | - }); |
|
906 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
907 | - |
|
908 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
909 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
910 | - $manager->registerCapability(function () use ($c) { |
|
911 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
912 | - }); |
|
913 | - $manager->registerCapability(function () use ($c) { |
|
914 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
915 | - }); |
|
916 | - return $manager; |
|
917 | - }); |
|
918 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
919 | - |
|
920 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
921 | - $config = $c->getConfig(); |
|
922 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
923 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
924 | - $factory = new $factoryClass($this); |
|
925 | - $manager = $factory->getManager(); |
|
926 | - |
|
927 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
928 | - $manager = $c->getUserManager(); |
|
929 | - $user = $manager->get($id); |
|
930 | - if(is_null($user)) { |
|
931 | - $l = $c->getL10N('core'); |
|
932 | - $displayName = $l->t('Unknown user'); |
|
933 | - } else { |
|
934 | - $displayName = $user->getDisplayName(); |
|
935 | - } |
|
936 | - return $displayName; |
|
937 | - }); |
|
938 | - |
|
939 | - return $manager; |
|
940 | - }); |
|
941 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
942 | - |
|
943 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
944 | - /* |
|
171 | + /** @var string */ |
|
172 | + private $webRoot; |
|
173 | + |
|
174 | + /** |
|
175 | + * @param string $webRoot |
|
176 | + * @param \OC\Config $config |
|
177 | + */ |
|
178 | + public function __construct($webRoot, \OC\Config $config) { |
|
179 | + parent::__construct(); |
|
180 | + $this->webRoot = $webRoot; |
|
181 | + |
|
182 | + // To find out if we are running from CLI or not |
|
183 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
184 | + |
|
185 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
186 | + return $c; |
|
187 | + }); |
|
188 | + |
|
189 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
190 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
191 | + |
|
192 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
193 | + $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
194 | + |
|
195 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
196 | + $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
197 | + |
|
198 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
199 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
200 | + |
|
201 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
202 | + |
|
203 | + |
|
204 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
205 | + return new PreviewManager( |
|
206 | + $c->getConfig(), |
|
207 | + $c->getRootFolder(), |
|
208 | + $c->getAppDataDir('preview'), |
|
209 | + $c->getEventDispatcher(), |
|
210 | + $c->getGeneratorHelper(), |
|
211 | + $c->getSession()->get('user_id') |
|
212 | + ); |
|
213 | + }); |
|
214 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
215 | + |
|
216 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
217 | + return new \OC\Preview\Watcher( |
|
218 | + $c->getAppDataDir('preview') |
|
219 | + ); |
|
220 | + }); |
|
221 | + |
|
222 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
223 | + $view = new View(); |
|
224 | + $util = new Encryption\Util( |
|
225 | + $view, |
|
226 | + $c->getUserManager(), |
|
227 | + $c->getGroupManager(), |
|
228 | + $c->getConfig() |
|
229 | + ); |
|
230 | + return new Encryption\Manager( |
|
231 | + $c->getConfig(), |
|
232 | + $c->getLogger(), |
|
233 | + $c->getL10N('core'), |
|
234 | + new View(), |
|
235 | + $util, |
|
236 | + new ArrayCache() |
|
237 | + ); |
|
238 | + }); |
|
239 | + $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
240 | + |
|
241 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
242 | + $util = new Encryption\Util( |
|
243 | + new View(), |
|
244 | + $c->getUserManager(), |
|
245 | + $c->getGroupManager(), |
|
246 | + $c->getConfig() |
|
247 | + ); |
|
248 | + return new Encryption\File( |
|
249 | + $util, |
|
250 | + $c->getRootFolder(), |
|
251 | + $c->getShareManager() |
|
252 | + ); |
|
253 | + }); |
|
254 | + |
|
255 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
256 | + $view = new View(); |
|
257 | + $util = new Encryption\Util( |
|
258 | + $view, |
|
259 | + $c->getUserManager(), |
|
260 | + $c->getGroupManager(), |
|
261 | + $c->getConfig() |
|
262 | + ); |
|
263 | + |
|
264 | + return new Encryption\Keys\Storage($view, $util); |
|
265 | + }); |
|
266 | + $this->registerService('TagMapper', function (Server $c) { |
|
267 | + return new TagMapper($c->getDatabaseConnection()); |
|
268 | + }); |
|
269 | + |
|
270 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
271 | + $tagMapper = $c->query('TagMapper'); |
|
272 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
273 | + }); |
|
274 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
275 | + |
|
276 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
277 | + $config = $c->getConfig(); |
|
278 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
279 | + return new $factoryClass($this); |
|
280 | + }); |
|
281 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
282 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
283 | + }); |
|
284 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
285 | + |
|
286 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
287 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
288 | + }); |
|
289 | + $this->registerService('RootFolder', function (Server $c) { |
|
290 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
291 | + $view = new View(); |
|
292 | + $root = new Root( |
|
293 | + $manager, |
|
294 | + $view, |
|
295 | + null, |
|
296 | + $c->getUserMountCache(), |
|
297 | + $this->getLogger(), |
|
298 | + $this->getUserManager() |
|
299 | + ); |
|
300 | + $connector = new HookConnector($root, $view); |
|
301 | + $connector->viewToNode(); |
|
302 | + |
|
303 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
304 | + $previewConnector->connectWatcher(); |
|
305 | + |
|
306 | + return $root; |
|
307 | + }); |
|
308 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
309 | + |
|
310 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
311 | + return new LazyRoot(function () use ($c) { |
|
312 | + return $c->query('RootFolder'); |
|
313 | + }); |
|
314 | + }); |
|
315 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
316 | + |
|
317 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
318 | + return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher()); |
|
319 | + }); |
|
320 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
321 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
322 | + |
|
323 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
324 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
325 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
326 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
327 | + }); |
|
328 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
329 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
330 | + }); |
|
331 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
332 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
333 | + }); |
|
334 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
335 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
336 | + }); |
|
337 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
338 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
339 | + }); |
|
340 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
341 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
342 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
343 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
344 | + }); |
|
345 | + return $groupManager; |
|
346 | + }); |
|
347 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
348 | + |
|
349 | + $this->registerService(Store::class, function (Server $c) { |
|
350 | + $session = $c->getSession(); |
|
351 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
352 | + $tokenProvider = $c->query(IProvider::class); |
|
353 | + } else { |
|
354 | + $tokenProvider = null; |
|
355 | + } |
|
356 | + $logger = $c->getLogger(); |
|
357 | + return new Store($session, $logger, $tokenProvider); |
|
358 | + }); |
|
359 | + $this->registerAlias(IStore::class, Store::class); |
|
360 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
361 | + $dbConnection = $c->getDatabaseConnection(); |
|
362 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
363 | + }); |
|
364 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
365 | + |
|
366 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
367 | + $manager = $c->getUserManager(); |
|
368 | + $session = new \OC\Session\Memory(''); |
|
369 | + $timeFactory = new TimeFactory(); |
|
370 | + // Token providers might require a working database. This code |
|
371 | + // might however be called when ownCloud is not yet setup. |
|
372 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
373 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
374 | + } else { |
|
375 | + $defaultTokenProvider = null; |
|
376 | + } |
|
377 | + |
|
378 | + $dispatcher = $c->getEventDispatcher(); |
|
379 | + |
|
380 | + $userSession = new \OC\User\Session( |
|
381 | + $manager, |
|
382 | + $session, |
|
383 | + $timeFactory, |
|
384 | + $defaultTokenProvider, |
|
385 | + $c->getConfig(), |
|
386 | + $c->getSecureRandom(), |
|
387 | + $c->getLockdownManager(), |
|
388 | + $c->getLogger() |
|
389 | + ); |
|
390 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
391 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
392 | + }); |
|
393 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
394 | + /** @var $user \OC\User\User */ |
|
395 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
396 | + }); |
|
397 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
398 | + /** @var $user \OC\User\User */ |
|
399 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
400 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
401 | + }); |
|
402 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
403 | + /** @var $user \OC\User\User */ |
|
404 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
405 | + }); |
|
406 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
407 | + /** @var $user \OC\User\User */ |
|
408 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
409 | + }); |
|
410 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
411 | + /** @var $user \OC\User\User */ |
|
412 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
413 | + }); |
|
414 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
415 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
416 | + }); |
|
417 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
418 | + /** @var $user \OC\User\User */ |
|
419 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
|
420 | + }); |
|
421 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
422 | + /** @var $user \OC\User\User */ |
|
423 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
424 | + }); |
|
425 | + $userSession->listen('\OC\User', 'logout', function () { |
|
426 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
427 | + }); |
|
428 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
429 | + /** @var $user \OC\User\User */ |
|
430 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
431 | + }); |
|
432 | + return $userSession; |
|
433 | + }); |
|
434 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
435 | + $this->registerAlias('UserSession', \OC\User\Session::class); |
|
436 | + |
|
437 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
438 | + |
|
439 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
440 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
441 | + |
|
442 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
443 | + return new \OC\AllConfig( |
|
444 | + $c->getSystemConfig() |
|
445 | + ); |
|
446 | + }); |
|
447 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
448 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
449 | + |
|
450 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
451 | + return new \OC\SystemConfig($config); |
|
452 | + }); |
|
453 | + |
|
454 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
455 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
456 | + }); |
|
457 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
458 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
459 | + |
|
460 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
461 | + return new \OC\L10N\Factory( |
|
462 | + $c->getConfig(), |
|
463 | + $c->getRequest(), |
|
464 | + $c->getUserSession(), |
|
465 | + \OC::$SERVERROOT |
|
466 | + ); |
|
467 | + }); |
|
468 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
469 | + |
|
470 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
471 | + $config = $c->getConfig(); |
|
472 | + $cacheFactory = $c->getMemCacheFactory(); |
|
473 | + $request = $c->getRequest(); |
|
474 | + return new \OC\URLGenerator( |
|
475 | + $config, |
|
476 | + $cacheFactory, |
|
477 | + $request |
|
478 | + ); |
|
479 | + }); |
|
480 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
481 | + |
|
482 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
483 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
484 | + |
|
485 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
486 | + return new Cache\File(); |
|
487 | + }); |
|
488 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
489 | + |
|
490 | + $this->registerService(Factory::class, function (Server $c) { |
|
491 | + |
|
492 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
493 | + ArrayCache::class, |
|
494 | + ArrayCache::class, |
|
495 | + ArrayCache::class |
|
496 | + ); |
|
497 | + $config = $c->getConfig(); |
|
498 | + |
|
499 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
500 | + $v = \OC_App::getAppVersions(); |
|
501 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
502 | + $version = implode(',', $v); |
|
503 | + $instanceId = \OC_Util::getInstanceId(); |
|
504 | + $path = \OC::$SERVERROOT; |
|
505 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
506 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
507 | + $config->getSystemValue('memcache.local', null), |
|
508 | + $config->getSystemValue('memcache.distributed', null), |
|
509 | + $config->getSystemValue('memcache.locking', null) |
|
510 | + ); |
|
511 | + } |
|
512 | + return $arrayCacheFactory; |
|
513 | + |
|
514 | + }); |
|
515 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
516 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
517 | + |
|
518 | + $this->registerService('RedisFactory', function (Server $c) { |
|
519 | + $systemConfig = $c->getSystemConfig(); |
|
520 | + return new RedisFactory($systemConfig); |
|
521 | + }); |
|
522 | + |
|
523 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
524 | + return new \OC\Activity\Manager( |
|
525 | + $c->getRequest(), |
|
526 | + $c->getUserSession(), |
|
527 | + $c->getConfig(), |
|
528 | + $c->query(IValidator::class) |
|
529 | + ); |
|
530 | + }); |
|
531 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
532 | + |
|
533 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
534 | + return new \OC\Activity\EventMerger( |
|
535 | + $c->getL10N('lib') |
|
536 | + ); |
|
537 | + }); |
|
538 | + $this->registerAlias(IValidator::class, Validator::class); |
|
539 | + |
|
540 | + $this->registerService(AvatarManager::class, function(Server $c) { |
|
541 | + return new AvatarManager( |
|
542 | + $c->query(\OC\User\Manager::class), |
|
543 | + $c->getAppDataDir('avatar'), |
|
544 | + $c->getL10N('lib'), |
|
545 | + $c->getLogger(), |
|
546 | + $c->getConfig() |
|
547 | + ); |
|
548 | + }); |
|
549 | + $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class); |
|
550 | + $this->registerAlias('AvatarManager', AvatarManager::class); |
|
551 | + |
|
552 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
553 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
554 | + |
|
555 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
556 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
557 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
558 | + $logger = $factory->get($logType); |
|
559 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
560 | + |
|
561 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
562 | + }); |
|
563 | + $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
|
564 | + $this->registerAlias('Logger', \OC\Log::class); |
|
565 | + |
|
566 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
567 | + return new LogFactory($c, $this->getSystemConfig()); |
|
568 | + }); |
|
569 | + |
|
570 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
571 | + $config = $c->getConfig(); |
|
572 | + return new \OC\BackgroundJob\JobList( |
|
573 | + $c->getDatabaseConnection(), |
|
574 | + $config, |
|
575 | + new TimeFactory() |
|
576 | + ); |
|
577 | + }); |
|
578 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
579 | + |
|
580 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
581 | + $cacheFactory = $c->getMemCacheFactory(); |
|
582 | + $logger = $c->getLogger(); |
|
583 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
584 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
585 | + } else { |
|
586 | + $router = new \OC\Route\Router($logger); |
|
587 | + } |
|
588 | + return $router; |
|
589 | + }); |
|
590 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
591 | + |
|
592 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
593 | + return new Search(); |
|
594 | + }); |
|
595 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
596 | + |
|
597 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
598 | + return new \OC\Security\RateLimiting\Limiter( |
|
599 | + $this->getUserSession(), |
|
600 | + $this->getRequest(), |
|
601 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
602 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
603 | + ); |
|
604 | + }); |
|
605 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
606 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
607 | + $this->getMemCacheFactory(), |
|
608 | + new \OC\AppFramework\Utility\TimeFactory() |
|
609 | + ); |
|
610 | + }); |
|
611 | + |
|
612 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
613 | + return new SecureRandom(); |
|
614 | + }); |
|
615 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
616 | + |
|
617 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
618 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
619 | + }); |
|
620 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
621 | + |
|
622 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
623 | + return new Hasher($c->getConfig()); |
|
624 | + }); |
|
625 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
626 | + |
|
627 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
628 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
629 | + }); |
|
630 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
631 | + |
|
632 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
633 | + $systemConfig = $c->getSystemConfig(); |
|
634 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
635 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
636 | + if (!$factory->isValidType($type)) { |
|
637 | + throw new \OC\DatabaseException('Invalid database type'); |
|
638 | + } |
|
639 | + $connectionParams = $factory->createConnectionParams(); |
|
640 | + $connection = $factory->getConnection($type, $connectionParams); |
|
641 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
642 | + return $connection; |
|
643 | + }); |
|
644 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
645 | + |
|
646 | + |
|
647 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
648 | + $user = \OC_User::getUser(); |
|
649 | + $uid = $user ? $user : null; |
|
650 | + return new ClientService( |
|
651 | + $c->getConfig(), |
|
652 | + new \OC\Security\CertificateManager( |
|
653 | + $uid, |
|
654 | + new View(), |
|
655 | + $c->getConfig(), |
|
656 | + $c->getLogger(), |
|
657 | + $c->getSecureRandom() |
|
658 | + ) |
|
659 | + ); |
|
660 | + }); |
|
661 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
662 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
663 | + $eventLogger = new EventLogger(); |
|
664 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
665 | + // In debug mode, module is being activated by default |
|
666 | + $eventLogger->activate(); |
|
667 | + } |
|
668 | + return $eventLogger; |
|
669 | + }); |
|
670 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
671 | + |
|
672 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
673 | + $queryLogger = new QueryLogger(); |
|
674 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
675 | + // In debug mode, module is being activated by default |
|
676 | + $queryLogger->activate(); |
|
677 | + } |
|
678 | + return $queryLogger; |
|
679 | + }); |
|
680 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
681 | + |
|
682 | + $this->registerService(TempManager::class, function (Server $c) { |
|
683 | + return new TempManager( |
|
684 | + $c->getLogger(), |
|
685 | + $c->getConfig() |
|
686 | + ); |
|
687 | + }); |
|
688 | + $this->registerAlias('TempManager', TempManager::class); |
|
689 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
690 | + |
|
691 | + $this->registerService(AppManager::class, function (Server $c) { |
|
692 | + return new \OC\App\AppManager( |
|
693 | + $c->getUserSession(), |
|
694 | + $c->query(\OC\AppConfig::class), |
|
695 | + $c->getGroupManager(), |
|
696 | + $c->getMemCacheFactory(), |
|
697 | + $c->getEventDispatcher(), |
|
698 | + $c->getLogger() |
|
699 | + ); |
|
700 | + }); |
|
701 | + $this->registerAlias('AppManager', AppManager::class); |
|
702 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
703 | + |
|
704 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
705 | + return new DateTimeZone( |
|
706 | + $c->getConfig(), |
|
707 | + $c->getSession() |
|
708 | + ); |
|
709 | + }); |
|
710 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
711 | + |
|
712 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
713 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
714 | + |
|
715 | + return new DateTimeFormatter( |
|
716 | + $c->getDateTimeZone()->getTimeZone(), |
|
717 | + $c->getL10N('lib', $language) |
|
718 | + ); |
|
719 | + }); |
|
720 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
721 | + |
|
722 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
723 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
724 | + $listener = new UserMountCacheListener($mountCache); |
|
725 | + $listener->listen($c->getUserManager()); |
|
726 | + return $mountCache; |
|
727 | + }); |
|
728 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
729 | + |
|
730 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
731 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
732 | + $mountCache = $c->query('UserMountCache'); |
|
733 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
734 | + |
|
735 | + // builtin providers |
|
736 | + |
|
737 | + $config = $c->getConfig(); |
|
738 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
739 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
740 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
741 | + |
|
742 | + return $manager; |
|
743 | + }); |
|
744 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
745 | + |
|
746 | + $this->registerService('IniWrapper', function ($c) { |
|
747 | + return new IniGetWrapper(); |
|
748 | + }); |
|
749 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
750 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
751 | + if ($busClass) { |
|
752 | + list($app, $class) = explode('::', $busClass, 2); |
|
753 | + if ($c->getAppManager()->isInstalled($app)) { |
|
754 | + \OC_App::loadApp($app); |
|
755 | + return $c->query($class); |
|
756 | + } else { |
|
757 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
758 | + } |
|
759 | + } else { |
|
760 | + $jobList = $c->getJobList(); |
|
761 | + return new CronBus($jobList); |
|
762 | + } |
|
763 | + }); |
|
764 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
765 | + return new TrustedDomainHelper($this->getConfig()); |
|
766 | + }); |
|
767 | + $this->registerService(Throttler::class, function (Server $c) { |
|
768 | + return new Throttler( |
|
769 | + $c->getDatabaseConnection(), |
|
770 | + new TimeFactory(), |
|
771 | + $c->getLogger(), |
|
772 | + $c->getConfig() |
|
773 | + ); |
|
774 | + }); |
|
775 | + $this->registerAlias('Throttler', Throttler::class); |
|
776 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
777 | + // IConfig and IAppManager requires a working database. This code |
|
778 | + // might however be called when ownCloud is not yet setup. |
|
779 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
780 | + $config = $c->getConfig(); |
|
781 | + $appManager = $c->getAppManager(); |
|
782 | + } else { |
|
783 | + $config = null; |
|
784 | + $appManager = null; |
|
785 | + } |
|
786 | + |
|
787 | + return new Checker( |
|
788 | + new EnvironmentHelper(), |
|
789 | + new FileAccessHelper(), |
|
790 | + new AppLocator(), |
|
791 | + $config, |
|
792 | + $c->getMemCacheFactory(), |
|
793 | + $appManager, |
|
794 | + $c->getTempManager(), |
|
795 | + $c->getMimeTypeDetector() |
|
796 | + ); |
|
797 | + }); |
|
798 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
799 | + if (isset($this['urlParams'])) { |
|
800 | + $urlParams = $this['urlParams']; |
|
801 | + } else { |
|
802 | + $urlParams = []; |
|
803 | + } |
|
804 | + |
|
805 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
806 | + && in_array('fakeinput', stream_get_wrappers()) |
|
807 | + ) { |
|
808 | + $stream = 'fakeinput://data'; |
|
809 | + } else { |
|
810 | + $stream = 'php://input'; |
|
811 | + } |
|
812 | + |
|
813 | + return new Request( |
|
814 | + [ |
|
815 | + 'get' => $_GET, |
|
816 | + 'post' => $_POST, |
|
817 | + 'files' => $_FILES, |
|
818 | + 'server' => $_SERVER, |
|
819 | + 'env' => $_ENV, |
|
820 | + 'cookies' => $_COOKIE, |
|
821 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
822 | + ? $_SERVER['REQUEST_METHOD'] |
|
823 | + : '', |
|
824 | + 'urlParams' => $urlParams, |
|
825 | + ], |
|
826 | + $this->getSecureRandom(), |
|
827 | + $this->getConfig(), |
|
828 | + $this->getCsrfTokenManager(), |
|
829 | + $stream |
|
830 | + ); |
|
831 | + }); |
|
832 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
833 | + |
|
834 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
835 | + return new Mailer( |
|
836 | + $c->getConfig(), |
|
837 | + $c->getLogger(), |
|
838 | + $c->query(Defaults::class), |
|
839 | + $c->getURLGenerator(), |
|
840 | + $c->getL10N('lib') |
|
841 | + ); |
|
842 | + }); |
|
843 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
844 | + |
|
845 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
846 | + $config = $c->getConfig(); |
|
847 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
848 | + if (is_null($factoryClass)) { |
|
849 | + throw new \Exception('ldapProviderFactory not set'); |
|
850 | + } |
|
851 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
852 | + $factory = new $factoryClass($this); |
|
853 | + return $factory->getLDAPProvider(); |
|
854 | + }); |
|
855 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
856 | + $ini = $c->getIniWrapper(); |
|
857 | + $config = $c->getConfig(); |
|
858 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
859 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
860 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
861 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
862 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
863 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
864 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
865 | + } |
|
866 | + return new DBLockingProvider( |
|
867 | + $c->getDatabaseConnection(), |
|
868 | + $c->getLogger(), |
|
869 | + new TimeFactory(), |
|
870 | + $ttl, |
|
871 | + !\OC::$CLI |
|
872 | + ); |
|
873 | + } |
|
874 | + return new NoopLockingProvider(); |
|
875 | + }); |
|
876 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
877 | + |
|
878 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
879 | + return new \OC\Files\Mount\Manager(); |
|
880 | + }); |
|
881 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
882 | + |
|
883 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
884 | + return new \OC\Files\Type\Detection( |
|
885 | + $c->getURLGenerator(), |
|
886 | + \OC::$configDir, |
|
887 | + \OC::$SERVERROOT . '/resources/config/' |
|
888 | + ); |
|
889 | + }); |
|
890 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
891 | + |
|
892 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
893 | + return new \OC\Files\Type\Loader( |
|
894 | + $c->getDatabaseConnection() |
|
895 | + ); |
|
896 | + }); |
|
897 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
898 | + $this->registerService(BundleFetcher::class, function () { |
|
899 | + return new BundleFetcher($this->getL10N('lib')); |
|
900 | + }); |
|
901 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
902 | + return new Manager( |
|
903 | + $c->query(IValidator::class) |
|
904 | + ); |
|
905 | + }); |
|
906 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
907 | + |
|
908 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
909 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
910 | + $manager->registerCapability(function () use ($c) { |
|
911 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
912 | + }); |
|
913 | + $manager->registerCapability(function () use ($c) { |
|
914 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
915 | + }); |
|
916 | + return $manager; |
|
917 | + }); |
|
918 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
919 | + |
|
920 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
921 | + $config = $c->getConfig(); |
|
922 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
923 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
924 | + $factory = new $factoryClass($this); |
|
925 | + $manager = $factory->getManager(); |
|
926 | + |
|
927 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
928 | + $manager = $c->getUserManager(); |
|
929 | + $user = $manager->get($id); |
|
930 | + if(is_null($user)) { |
|
931 | + $l = $c->getL10N('core'); |
|
932 | + $displayName = $l->t('Unknown user'); |
|
933 | + } else { |
|
934 | + $displayName = $user->getDisplayName(); |
|
935 | + } |
|
936 | + return $displayName; |
|
937 | + }); |
|
938 | + |
|
939 | + return $manager; |
|
940 | + }); |
|
941 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
942 | + |
|
943 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
944 | + /* |
|
945 | 945 | * Dark magic for autoloader. |
946 | 946 | * If we do a class_exists it will try to load the class which will |
947 | 947 | * make composer cache the result. Resulting in errors when enabling |
948 | 948 | * the theming app. |
949 | 949 | */ |
950 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
951 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
952 | - $classExists = true; |
|
953 | - } else { |
|
954 | - $classExists = false; |
|
955 | - } |
|
956 | - |
|
957 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
958 | - return new ThemingDefaults( |
|
959 | - $c->getConfig(), |
|
960 | - $c->getL10N('theming'), |
|
961 | - $c->getURLGenerator(), |
|
962 | - $c->getMemCacheFactory(), |
|
963 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
964 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
965 | - $c->getAppManager(), |
|
966 | - $c->getNavigationManager() |
|
967 | - ); |
|
968 | - } |
|
969 | - return new \OC_Defaults(); |
|
970 | - }); |
|
971 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
972 | - return new SCSSCacher( |
|
973 | - $c->getLogger(), |
|
974 | - $c->query(\OC\Files\AppData\Factory::class), |
|
975 | - $c->getURLGenerator(), |
|
976 | - $c->getConfig(), |
|
977 | - $c->getThemingDefaults(), |
|
978 | - \OC::$SERVERROOT, |
|
979 | - $this->getMemCacheFactory(), |
|
980 | - $c->query(IconsCacher::class), |
|
981 | - new TimeFactory() |
|
982 | - ); |
|
983 | - }); |
|
984 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
985 | - return new JSCombiner( |
|
986 | - $c->getAppDataDir('js'), |
|
987 | - $c->getURLGenerator(), |
|
988 | - $this->getMemCacheFactory(), |
|
989 | - $c->getSystemConfig(), |
|
990 | - $c->getLogger() |
|
991 | - ); |
|
992 | - }); |
|
993 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
994 | - $this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
995 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
996 | - |
|
997 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
998 | - // FIXME: Instantiiated here due to cyclic dependency |
|
999 | - $request = new Request( |
|
1000 | - [ |
|
1001 | - 'get' => $_GET, |
|
1002 | - 'post' => $_POST, |
|
1003 | - 'files' => $_FILES, |
|
1004 | - 'server' => $_SERVER, |
|
1005 | - 'env' => $_ENV, |
|
1006 | - 'cookies' => $_COOKIE, |
|
1007 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1008 | - ? $_SERVER['REQUEST_METHOD'] |
|
1009 | - : null, |
|
1010 | - ], |
|
1011 | - $c->getSecureRandom(), |
|
1012 | - $c->getConfig() |
|
1013 | - ); |
|
1014 | - |
|
1015 | - return new CryptoWrapper( |
|
1016 | - $c->getConfig(), |
|
1017 | - $c->getCrypto(), |
|
1018 | - $c->getSecureRandom(), |
|
1019 | - $request |
|
1020 | - ); |
|
1021 | - }); |
|
1022 | - $this->registerService(CsrfTokenManager::class, function (Server $c) { |
|
1023 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1024 | - |
|
1025 | - return new CsrfTokenManager( |
|
1026 | - $tokenGenerator, |
|
1027 | - $c->query(SessionStorage::class) |
|
1028 | - ); |
|
1029 | - }); |
|
1030 | - $this->registerAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1031 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1032 | - return new SessionStorage($c->getSession()); |
|
1033 | - }); |
|
1034 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, \OC\Security\CSP\ContentSecurityPolicyManager::class); |
|
1035 | - $this->registerAlias('ContentSecurityPolicyManager', \OC\Security\CSP\ContentSecurityPolicyManager::class); |
|
1036 | - |
|
1037 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1038 | - return new ContentSecurityPolicyNonceManager( |
|
1039 | - $c->getCsrfTokenManager(), |
|
1040 | - $c->getRequest() |
|
1041 | - ); |
|
1042 | - }); |
|
1043 | - |
|
1044 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1045 | - $config = $c->getConfig(); |
|
1046 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1047 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1048 | - $factory = new $factoryClass($this); |
|
1049 | - |
|
1050 | - $manager = new \OC\Share20\Manager( |
|
1051 | - $c->getLogger(), |
|
1052 | - $c->getConfig(), |
|
1053 | - $c->getSecureRandom(), |
|
1054 | - $c->getHasher(), |
|
1055 | - $c->getMountManager(), |
|
1056 | - $c->getGroupManager(), |
|
1057 | - $c->getL10N('lib'), |
|
1058 | - $c->getL10NFactory(), |
|
1059 | - $factory, |
|
1060 | - $c->getUserManager(), |
|
1061 | - $c->getLazyRootFolder(), |
|
1062 | - $c->getEventDispatcher(), |
|
1063 | - $c->getMailer(), |
|
1064 | - $c->getURLGenerator(), |
|
1065 | - $c->getThemingDefaults() |
|
1066 | - ); |
|
1067 | - |
|
1068 | - return $manager; |
|
1069 | - }); |
|
1070 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1071 | - |
|
1072 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1073 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1074 | - |
|
1075 | - // register default plugins |
|
1076 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1077 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1078 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1079 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1080 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1081 | - |
|
1082 | - return $instance; |
|
1083 | - }); |
|
1084 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1085 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1086 | - |
|
1087 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1088 | - |
|
1089 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1090 | - |
|
1091 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1092 | - $manager = new \OC\Settings\Manager( |
|
1093 | - $c->getLogger(), |
|
1094 | - $c->getL10NFactory(), |
|
1095 | - $c->getURLGenerator(), |
|
1096 | - $c |
|
1097 | - ); |
|
1098 | - return $manager; |
|
1099 | - }); |
|
1100 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1101 | - return new \OC\Files\AppData\Factory( |
|
1102 | - $c->getRootFolder(), |
|
1103 | - $c->getSystemConfig() |
|
1104 | - ); |
|
1105 | - }); |
|
1106 | - |
|
1107 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1108 | - return new LockdownManager(function () use ($c) { |
|
1109 | - return $c->getSession(); |
|
1110 | - }); |
|
1111 | - }); |
|
1112 | - |
|
1113 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1114 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1115 | - }); |
|
1116 | - |
|
1117 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1118 | - return new CloudIdManager(); |
|
1119 | - }); |
|
1120 | - |
|
1121 | - $this->registerService(IConfig::class, function (Server $c) { |
|
1122 | - return new GlobalScale\Config($c->getConfig()); |
|
1123 | - }); |
|
1124 | - |
|
1125 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1126 | - return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1127 | - }); |
|
1128 | - |
|
1129 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1130 | - return new CloudFederationFactory(); |
|
1131 | - }); |
|
1132 | - |
|
1133 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1134 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1135 | - |
|
1136 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1137 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1138 | - |
|
1139 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1140 | - return new Defaults( |
|
1141 | - $c->getThemingDefaults() |
|
1142 | - ); |
|
1143 | - }); |
|
1144 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1145 | - |
|
1146 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1147 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1148 | - }); |
|
1149 | - |
|
1150 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1151 | - return new ShareHelper( |
|
1152 | - $c->query(\OCP\Share\IManager::class) |
|
1153 | - ); |
|
1154 | - }); |
|
1155 | - |
|
1156 | - $this->registerService(Installer::class, function(Server $c) { |
|
1157 | - return new Installer( |
|
1158 | - $c->getAppFetcher(), |
|
1159 | - $c->getHTTPClientService(), |
|
1160 | - $c->getTempManager(), |
|
1161 | - $c->getLogger(), |
|
1162 | - $c->getConfig() |
|
1163 | - ); |
|
1164 | - }); |
|
1165 | - |
|
1166 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
1167 | - return new ApiFactory($c->getHTTPClientService()); |
|
1168 | - }); |
|
1169 | - |
|
1170 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1171 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1172 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1173 | - }); |
|
1174 | - |
|
1175 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
1176 | - return new ContactsStore( |
|
1177 | - $c->getContactsManager(), |
|
1178 | - $c->getConfig(), |
|
1179 | - $c->getUserManager(), |
|
1180 | - $c->getGroupManager() |
|
1181 | - ); |
|
1182 | - }); |
|
1183 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1184 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1185 | - |
|
1186 | - $this->registerService(IStorageFactory::class, function() { |
|
1187 | - return new StorageFactory(); |
|
1188 | - }); |
|
1189 | - |
|
1190 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1191 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1192 | - |
|
1193 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) { |
|
1194 | - return new \OC\Security\IdentityProof\Manager( |
|
1195 | - $c->query(\OC\Files\AppData\Factory::class), |
|
1196 | - $c->getCrypto(), |
|
1197 | - $c->getConfig() |
|
1198 | - ); |
|
1199 | - }); |
|
1200 | - |
|
1201 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1202 | - |
|
1203 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1204 | - |
|
1205 | - $this->connectDispatcher(); |
|
1206 | - } |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * @return \OCP\Calendar\IManager |
|
1210 | - */ |
|
1211 | - public function getCalendarManager() { |
|
1212 | - return $this->query('CalendarManager'); |
|
1213 | - } |
|
1214 | - |
|
1215 | - /** |
|
1216 | - * @return \OCP\Calendar\Resource\IManager |
|
1217 | - */ |
|
1218 | - public function getCalendarResourceBackendManager() { |
|
1219 | - return $this->query('CalendarResourceBackendManager'); |
|
1220 | - } |
|
1221 | - |
|
1222 | - /** |
|
1223 | - * @return \OCP\Calendar\Room\IManager |
|
1224 | - */ |
|
1225 | - public function getCalendarRoomBackendManager() { |
|
1226 | - return $this->query('CalendarRoomBackendManager'); |
|
1227 | - } |
|
1228 | - |
|
1229 | - private function connectDispatcher() { |
|
1230 | - $dispatcher = $this->getEventDispatcher(); |
|
1231 | - |
|
1232 | - // Delete avatar on user deletion |
|
1233 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1234 | - $logger = $this->getLogger(); |
|
1235 | - $manager = $this->getAvatarManager(); |
|
1236 | - /** @var IUser $user */ |
|
1237 | - $user = $e->getSubject(); |
|
1238 | - |
|
1239 | - try { |
|
1240 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1241 | - $avatar->remove(); |
|
1242 | - } catch (NotFoundException $e) { |
|
1243 | - // no avatar to remove |
|
1244 | - } catch (\Exception $e) { |
|
1245 | - // Ignore exceptions |
|
1246 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1247 | - } |
|
1248 | - }); |
|
1249 | - |
|
1250 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1251 | - $manager = $this->getAvatarManager(); |
|
1252 | - /** @var IUser $user */ |
|
1253 | - $user = $e->getSubject(); |
|
1254 | - $feature = $e->getArgument('feature'); |
|
1255 | - $oldValue = $e->getArgument('oldValue'); |
|
1256 | - $value = $e->getArgument('value'); |
|
1257 | - |
|
1258 | - // We only change the avatar on display name changes |
|
1259 | - if ($feature !== 'displayName') { |
|
1260 | - return; |
|
1261 | - } |
|
1262 | - |
|
1263 | - try { |
|
1264 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1265 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1266 | - } catch (NotFoundException $e) { |
|
1267 | - // no avatar to remove |
|
1268 | - } |
|
1269 | - }); |
|
1270 | - } |
|
1271 | - |
|
1272 | - /** |
|
1273 | - * @return \OCP\Contacts\IManager |
|
1274 | - */ |
|
1275 | - public function getContactsManager() { |
|
1276 | - return $this->query('ContactsManager'); |
|
1277 | - } |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * @return \OC\Encryption\Manager |
|
1281 | - */ |
|
1282 | - public function getEncryptionManager() { |
|
1283 | - return $this->query('EncryptionManager'); |
|
1284 | - } |
|
1285 | - |
|
1286 | - /** |
|
1287 | - * @return \OC\Encryption\File |
|
1288 | - */ |
|
1289 | - public function getEncryptionFilesHelper() { |
|
1290 | - return $this->query('EncryptionFileHelper'); |
|
1291 | - } |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * @return \OCP\Encryption\Keys\IStorage |
|
1295 | - */ |
|
1296 | - public function getEncryptionKeyStorage() { |
|
1297 | - return $this->query('EncryptionKeyStorage'); |
|
1298 | - } |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * The current request object holding all information about the request |
|
1302 | - * currently being processed is returned from this method. |
|
1303 | - * In case the current execution was not initiated by a web request null is returned |
|
1304 | - * |
|
1305 | - * @return \OCP\IRequest |
|
1306 | - */ |
|
1307 | - public function getRequest() { |
|
1308 | - return $this->query('Request'); |
|
1309 | - } |
|
1310 | - |
|
1311 | - /** |
|
1312 | - * Returns the preview manager which can create preview images for a given file |
|
1313 | - * |
|
1314 | - * @return \OCP\IPreview |
|
1315 | - */ |
|
1316 | - public function getPreviewManager() { |
|
1317 | - return $this->query('PreviewManager'); |
|
1318 | - } |
|
1319 | - |
|
1320 | - /** |
|
1321 | - * Returns the tag manager which can get and set tags for different object types |
|
1322 | - * |
|
1323 | - * @see \OCP\ITagManager::load() |
|
1324 | - * @return \OCP\ITagManager |
|
1325 | - */ |
|
1326 | - public function getTagManager() { |
|
1327 | - return $this->query('TagManager'); |
|
1328 | - } |
|
1329 | - |
|
1330 | - /** |
|
1331 | - * Returns the system-tag manager |
|
1332 | - * |
|
1333 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1334 | - * |
|
1335 | - * @since 9.0.0 |
|
1336 | - */ |
|
1337 | - public function getSystemTagManager() { |
|
1338 | - return $this->query('SystemTagManager'); |
|
1339 | - } |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * Returns the system-tag object mapper |
|
1343 | - * |
|
1344 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1345 | - * |
|
1346 | - * @since 9.0.0 |
|
1347 | - */ |
|
1348 | - public function getSystemTagObjectMapper() { |
|
1349 | - return $this->query('SystemTagObjectMapper'); |
|
1350 | - } |
|
1351 | - |
|
1352 | - /** |
|
1353 | - * Returns the avatar manager, used for avatar functionality |
|
1354 | - * |
|
1355 | - * @return \OCP\IAvatarManager |
|
1356 | - */ |
|
1357 | - public function getAvatarManager() { |
|
1358 | - return $this->query('AvatarManager'); |
|
1359 | - } |
|
1360 | - |
|
1361 | - /** |
|
1362 | - * Returns the root folder of ownCloud's data directory |
|
1363 | - * |
|
1364 | - * @return \OCP\Files\IRootFolder |
|
1365 | - */ |
|
1366 | - public function getRootFolder() { |
|
1367 | - return $this->query('LazyRootFolder'); |
|
1368 | - } |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * Returns the root folder of ownCloud's data directory |
|
1372 | - * This is the lazy variant so this gets only initialized once it |
|
1373 | - * is actually used. |
|
1374 | - * |
|
1375 | - * @return \OCP\Files\IRootFolder |
|
1376 | - */ |
|
1377 | - public function getLazyRootFolder() { |
|
1378 | - return $this->query('LazyRootFolder'); |
|
1379 | - } |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * Returns a view to ownCloud's files folder |
|
1383 | - * |
|
1384 | - * @param string $userId user ID |
|
1385 | - * @return \OCP\Files\Folder|null |
|
1386 | - */ |
|
1387 | - public function getUserFolder($userId = null) { |
|
1388 | - if ($userId === null) { |
|
1389 | - $user = $this->getUserSession()->getUser(); |
|
1390 | - if (!$user) { |
|
1391 | - return null; |
|
1392 | - } |
|
1393 | - $userId = $user->getUID(); |
|
1394 | - } |
|
1395 | - $root = $this->getRootFolder(); |
|
1396 | - return $root->getUserFolder($userId); |
|
1397 | - } |
|
1398 | - |
|
1399 | - /** |
|
1400 | - * Returns an app-specific view in ownClouds data directory |
|
1401 | - * |
|
1402 | - * @return \OCP\Files\Folder |
|
1403 | - * @deprecated since 9.2.0 use IAppData |
|
1404 | - */ |
|
1405 | - public function getAppFolder() { |
|
1406 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1407 | - $root = $this->getRootFolder(); |
|
1408 | - if (!$root->nodeExists($dir)) { |
|
1409 | - $folder = $root->newFolder($dir); |
|
1410 | - } else { |
|
1411 | - $folder = $root->get($dir); |
|
1412 | - } |
|
1413 | - return $folder; |
|
1414 | - } |
|
1415 | - |
|
1416 | - /** |
|
1417 | - * @return \OC\User\Manager |
|
1418 | - */ |
|
1419 | - public function getUserManager() { |
|
1420 | - return $this->query('UserManager'); |
|
1421 | - } |
|
1422 | - |
|
1423 | - /** |
|
1424 | - * @return \OC\Group\Manager |
|
1425 | - */ |
|
1426 | - public function getGroupManager() { |
|
1427 | - return $this->query('GroupManager'); |
|
1428 | - } |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * @return \OC\User\Session |
|
1432 | - */ |
|
1433 | - public function getUserSession() { |
|
1434 | - return $this->query('UserSession'); |
|
1435 | - } |
|
1436 | - |
|
1437 | - /** |
|
1438 | - * @return \OCP\ISession |
|
1439 | - */ |
|
1440 | - public function getSession() { |
|
1441 | - return $this->query('UserSession')->getSession(); |
|
1442 | - } |
|
1443 | - |
|
1444 | - /** |
|
1445 | - * @param \OCP\ISession $session |
|
1446 | - */ |
|
1447 | - public function setSession(\OCP\ISession $session) { |
|
1448 | - $this->query(SessionStorage::class)->setSession($session); |
|
1449 | - $this->query('UserSession')->setSession($session); |
|
1450 | - $this->query(Store::class)->setSession($session); |
|
1451 | - } |
|
1452 | - |
|
1453 | - /** |
|
1454 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1455 | - */ |
|
1456 | - public function getTwoFactorAuthManager() { |
|
1457 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1458 | - } |
|
1459 | - |
|
1460 | - /** |
|
1461 | - * @return \OC\NavigationManager |
|
1462 | - */ |
|
1463 | - public function getNavigationManager() { |
|
1464 | - return $this->query('NavigationManager'); |
|
1465 | - } |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * @return \OCP\IConfig |
|
1469 | - */ |
|
1470 | - public function getConfig() { |
|
1471 | - return $this->query('AllConfig'); |
|
1472 | - } |
|
1473 | - |
|
1474 | - /** |
|
1475 | - * @return \OC\SystemConfig |
|
1476 | - */ |
|
1477 | - public function getSystemConfig() { |
|
1478 | - return $this->query('SystemConfig'); |
|
1479 | - } |
|
1480 | - |
|
1481 | - /** |
|
1482 | - * Returns the app config manager |
|
1483 | - * |
|
1484 | - * @return \OCP\IAppConfig |
|
1485 | - */ |
|
1486 | - public function getAppConfig() { |
|
1487 | - return $this->query('AppConfig'); |
|
1488 | - } |
|
1489 | - |
|
1490 | - /** |
|
1491 | - * @return \OCP\L10N\IFactory |
|
1492 | - */ |
|
1493 | - public function getL10NFactory() { |
|
1494 | - return $this->query('L10NFactory'); |
|
1495 | - } |
|
1496 | - |
|
1497 | - /** |
|
1498 | - * get an L10N instance |
|
1499 | - * |
|
1500 | - * @param string $app appid |
|
1501 | - * @param string $lang |
|
1502 | - * @return IL10N |
|
1503 | - */ |
|
1504 | - public function getL10N($app, $lang = null) { |
|
1505 | - return $this->getL10NFactory()->get($app, $lang); |
|
1506 | - } |
|
1507 | - |
|
1508 | - /** |
|
1509 | - * @return \OCP\IURLGenerator |
|
1510 | - */ |
|
1511 | - public function getURLGenerator() { |
|
1512 | - return $this->query('URLGenerator'); |
|
1513 | - } |
|
1514 | - |
|
1515 | - /** |
|
1516 | - * @return AppFetcher |
|
1517 | - */ |
|
1518 | - public function getAppFetcher() { |
|
1519 | - return $this->query(AppFetcher::class); |
|
1520 | - } |
|
1521 | - |
|
1522 | - /** |
|
1523 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1524 | - * getMemCacheFactory() instead. |
|
1525 | - * |
|
1526 | - * @return \OCP\ICache |
|
1527 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1528 | - */ |
|
1529 | - public function getCache() { |
|
1530 | - return $this->query('UserCache'); |
|
1531 | - } |
|
1532 | - |
|
1533 | - /** |
|
1534 | - * Returns an \OCP\CacheFactory instance |
|
1535 | - * |
|
1536 | - * @return \OCP\ICacheFactory |
|
1537 | - */ |
|
1538 | - public function getMemCacheFactory() { |
|
1539 | - return $this->query('MemCacheFactory'); |
|
1540 | - } |
|
1541 | - |
|
1542 | - /** |
|
1543 | - * Returns an \OC\RedisFactory instance |
|
1544 | - * |
|
1545 | - * @return \OC\RedisFactory |
|
1546 | - */ |
|
1547 | - public function getGetRedisFactory() { |
|
1548 | - return $this->query('RedisFactory'); |
|
1549 | - } |
|
1550 | - |
|
1551 | - |
|
1552 | - /** |
|
1553 | - * Returns the current session |
|
1554 | - * |
|
1555 | - * @return \OCP\IDBConnection |
|
1556 | - */ |
|
1557 | - public function getDatabaseConnection() { |
|
1558 | - return $this->query('DatabaseConnection'); |
|
1559 | - } |
|
1560 | - |
|
1561 | - /** |
|
1562 | - * Returns the activity manager |
|
1563 | - * |
|
1564 | - * @return \OCP\Activity\IManager |
|
1565 | - */ |
|
1566 | - public function getActivityManager() { |
|
1567 | - return $this->query('ActivityManager'); |
|
1568 | - } |
|
1569 | - |
|
1570 | - /** |
|
1571 | - * Returns an job list for controlling background jobs |
|
1572 | - * |
|
1573 | - * @return \OCP\BackgroundJob\IJobList |
|
1574 | - */ |
|
1575 | - public function getJobList() { |
|
1576 | - return $this->query('JobList'); |
|
1577 | - } |
|
1578 | - |
|
1579 | - /** |
|
1580 | - * Returns a logger instance |
|
1581 | - * |
|
1582 | - * @return \OCP\ILogger |
|
1583 | - */ |
|
1584 | - public function getLogger() { |
|
1585 | - return $this->query('Logger'); |
|
1586 | - } |
|
1587 | - |
|
1588 | - /** |
|
1589 | - * @return ILogFactory |
|
1590 | - * @throws \OCP\AppFramework\QueryException |
|
1591 | - */ |
|
1592 | - public function getLogFactory() { |
|
1593 | - return $this->query(ILogFactory::class); |
|
1594 | - } |
|
1595 | - |
|
1596 | - /** |
|
1597 | - * Returns a router for generating and matching urls |
|
1598 | - * |
|
1599 | - * @return \OCP\Route\IRouter |
|
1600 | - */ |
|
1601 | - public function getRouter() { |
|
1602 | - return $this->query('Router'); |
|
1603 | - } |
|
1604 | - |
|
1605 | - /** |
|
1606 | - * Returns a search instance |
|
1607 | - * |
|
1608 | - * @return \OCP\ISearch |
|
1609 | - */ |
|
1610 | - public function getSearch() { |
|
1611 | - return $this->query('Search'); |
|
1612 | - } |
|
1613 | - |
|
1614 | - /** |
|
1615 | - * Returns a SecureRandom instance |
|
1616 | - * |
|
1617 | - * @return \OCP\Security\ISecureRandom |
|
1618 | - */ |
|
1619 | - public function getSecureRandom() { |
|
1620 | - return $this->query('SecureRandom'); |
|
1621 | - } |
|
1622 | - |
|
1623 | - /** |
|
1624 | - * Returns a Crypto instance |
|
1625 | - * |
|
1626 | - * @return \OCP\Security\ICrypto |
|
1627 | - */ |
|
1628 | - public function getCrypto() { |
|
1629 | - return $this->query('Crypto'); |
|
1630 | - } |
|
1631 | - |
|
1632 | - /** |
|
1633 | - * Returns a Hasher instance |
|
1634 | - * |
|
1635 | - * @return \OCP\Security\IHasher |
|
1636 | - */ |
|
1637 | - public function getHasher() { |
|
1638 | - return $this->query('Hasher'); |
|
1639 | - } |
|
1640 | - |
|
1641 | - /** |
|
1642 | - * Returns a CredentialsManager instance |
|
1643 | - * |
|
1644 | - * @return \OCP\Security\ICredentialsManager |
|
1645 | - */ |
|
1646 | - public function getCredentialsManager() { |
|
1647 | - return $this->query('CredentialsManager'); |
|
1648 | - } |
|
1649 | - |
|
1650 | - /** |
|
1651 | - * Get the certificate manager for the user |
|
1652 | - * |
|
1653 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1654 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1655 | - */ |
|
1656 | - public function getCertificateManager($userId = '') { |
|
1657 | - if ($userId === '') { |
|
1658 | - $userSession = $this->getUserSession(); |
|
1659 | - $user = $userSession->getUser(); |
|
1660 | - if (is_null($user)) { |
|
1661 | - return null; |
|
1662 | - } |
|
1663 | - $userId = $user->getUID(); |
|
1664 | - } |
|
1665 | - return new CertificateManager( |
|
1666 | - $userId, |
|
1667 | - new View(), |
|
1668 | - $this->getConfig(), |
|
1669 | - $this->getLogger(), |
|
1670 | - $this->getSecureRandom() |
|
1671 | - ); |
|
1672 | - } |
|
1673 | - |
|
1674 | - /** |
|
1675 | - * Returns an instance of the HTTP client service |
|
1676 | - * |
|
1677 | - * @return \OCP\Http\Client\IClientService |
|
1678 | - */ |
|
1679 | - public function getHTTPClientService() { |
|
1680 | - return $this->query('HttpClientService'); |
|
1681 | - } |
|
1682 | - |
|
1683 | - /** |
|
1684 | - * Create a new event source |
|
1685 | - * |
|
1686 | - * @return \OCP\IEventSource |
|
1687 | - */ |
|
1688 | - public function createEventSource() { |
|
1689 | - return new \OC_EventSource(); |
|
1690 | - } |
|
1691 | - |
|
1692 | - /** |
|
1693 | - * Get the active event logger |
|
1694 | - * |
|
1695 | - * The returned logger only logs data when debug mode is enabled |
|
1696 | - * |
|
1697 | - * @return \OCP\Diagnostics\IEventLogger |
|
1698 | - */ |
|
1699 | - public function getEventLogger() { |
|
1700 | - return $this->query('EventLogger'); |
|
1701 | - } |
|
1702 | - |
|
1703 | - /** |
|
1704 | - * Get the active query logger |
|
1705 | - * |
|
1706 | - * The returned logger only logs data when debug mode is enabled |
|
1707 | - * |
|
1708 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1709 | - */ |
|
1710 | - public function getQueryLogger() { |
|
1711 | - return $this->query('QueryLogger'); |
|
1712 | - } |
|
1713 | - |
|
1714 | - /** |
|
1715 | - * Get the manager for temporary files and folders |
|
1716 | - * |
|
1717 | - * @return \OCP\ITempManager |
|
1718 | - */ |
|
1719 | - public function getTempManager() { |
|
1720 | - return $this->query('TempManager'); |
|
1721 | - } |
|
1722 | - |
|
1723 | - /** |
|
1724 | - * Get the app manager |
|
1725 | - * |
|
1726 | - * @return \OCP\App\IAppManager |
|
1727 | - */ |
|
1728 | - public function getAppManager() { |
|
1729 | - return $this->query('AppManager'); |
|
1730 | - } |
|
1731 | - |
|
1732 | - /** |
|
1733 | - * Creates a new mailer |
|
1734 | - * |
|
1735 | - * @return \OCP\Mail\IMailer |
|
1736 | - */ |
|
1737 | - public function getMailer() { |
|
1738 | - return $this->query('Mailer'); |
|
1739 | - } |
|
1740 | - |
|
1741 | - /** |
|
1742 | - * Get the webroot |
|
1743 | - * |
|
1744 | - * @return string |
|
1745 | - */ |
|
1746 | - public function getWebRoot() { |
|
1747 | - return $this->webRoot; |
|
1748 | - } |
|
1749 | - |
|
1750 | - /** |
|
1751 | - * @return \OC\OCSClient |
|
1752 | - */ |
|
1753 | - public function getOcsClient() { |
|
1754 | - return $this->query('OcsClient'); |
|
1755 | - } |
|
1756 | - |
|
1757 | - /** |
|
1758 | - * @return \OCP\IDateTimeZone |
|
1759 | - */ |
|
1760 | - public function getDateTimeZone() { |
|
1761 | - return $this->query('DateTimeZone'); |
|
1762 | - } |
|
1763 | - |
|
1764 | - /** |
|
1765 | - * @return \OCP\IDateTimeFormatter |
|
1766 | - */ |
|
1767 | - public function getDateTimeFormatter() { |
|
1768 | - return $this->query('DateTimeFormatter'); |
|
1769 | - } |
|
1770 | - |
|
1771 | - /** |
|
1772 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1773 | - */ |
|
1774 | - public function getMountProviderCollection() { |
|
1775 | - return $this->query('MountConfigManager'); |
|
1776 | - } |
|
1777 | - |
|
1778 | - /** |
|
1779 | - * Get the IniWrapper |
|
1780 | - * |
|
1781 | - * @return IniGetWrapper |
|
1782 | - */ |
|
1783 | - public function getIniWrapper() { |
|
1784 | - return $this->query('IniWrapper'); |
|
1785 | - } |
|
1786 | - |
|
1787 | - /** |
|
1788 | - * @return \OCP\Command\IBus |
|
1789 | - */ |
|
1790 | - public function getCommandBus() { |
|
1791 | - return $this->query('AsyncCommandBus'); |
|
1792 | - } |
|
1793 | - |
|
1794 | - /** |
|
1795 | - * Get the trusted domain helper |
|
1796 | - * |
|
1797 | - * @return TrustedDomainHelper |
|
1798 | - */ |
|
1799 | - public function getTrustedDomainHelper() { |
|
1800 | - return $this->query('TrustedDomainHelper'); |
|
1801 | - } |
|
1802 | - |
|
1803 | - /** |
|
1804 | - * Get the locking provider |
|
1805 | - * |
|
1806 | - * @return \OCP\Lock\ILockingProvider |
|
1807 | - * @since 8.1.0 |
|
1808 | - */ |
|
1809 | - public function getLockingProvider() { |
|
1810 | - return $this->query('LockingProvider'); |
|
1811 | - } |
|
1812 | - |
|
1813 | - /** |
|
1814 | - * @return \OCP\Files\Mount\IMountManager |
|
1815 | - **/ |
|
1816 | - function getMountManager() { |
|
1817 | - return $this->query('MountManager'); |
|
1818 | - } |
|
1819 | - |
|
1820 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1821 | - function getUserMountCache() { |
|
1822 | - return $this->query('UserMountCache'); |
|
1823 | - } |
|
1824 | - |
|
1825 | - /** |
|
1826 | - * Get the MimeTypeDetector |
|
1827 | - * |
|
1828 | - * @return \OCP\Files\IMimeTypeDetector |
|
1829 | - */ |
|
1830 | - public function getMimeTypeDetector() { |
|
1831 | - return $this->query('MimeTypeDetector'); |
|
1832 | - } |
|
1833 | - |
|
1834 | - /** |
|
1835 | - * Get the MimeTypeLoader |
|
1836 | - * |
|
1837 | - * @return \OCP\Files\IMimeTypeLoader |
|
1838 | - */ |
|
1839 | - public function getMimeTypeLoader() { |
|
1840 | - return $this->query('MimeTypeLoader'); |
|
1841 | - } |
|
1842 | - |
|
1843 | - /** |
|
1844 | - * Get the manager of all the capabilities |
|
1845 | - * |
|
1846 | - * @return \OC\CapabilitiesManager |
|
1847 | - */ |
|
1848 | - public function getCapabilitiesManager() { |
|
1849 | - return $this->query('CapabilitiesManager'); |
|
1850 | - } |
|
1851 | - |
|
1852 | - /** |
|
1853 | - * Get the EventDispatcher |
|
1854 | - * |
|
1855 | - * @return EventDispatcherInterface |
|
1856 | - * @since 8.2.0 |
|
1857 | - */ |
|
1858 | - public function getEventDispatcher() { |
|
1859 | - return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
1860 | - } |
|
1861 | - |
|
1862 | - /** |
|
1863 | - * Get the Notification Manager |
|
1864 | - * |
|
1865 | - * @return \OCP\Notification\IManager |
|
1866 | - * @since 8.2.0 |
|
1867 | - */ |
|
1868 | - public function getNotificationManager() { |
|
1869 | - return $this->query('NotificationManager'); |
|
1870 | - } |
|
1871 | - |
|
1872 | - /** |
|
1873 | - * @return \OCP\Comments\ICommentsManager |
|
1874 | - */ |
|
1875 | - public function getCommentsManager() { |
|
1876 | - return $this->query('CommentsManager'); |
|
1877 | - } |
|
1878 | - |
|
1879 | - /** |
|
1880 | - * @return \OCA\Theming\ThemingDefaults |
|
1881 | - */ |
|
1882 | - public function getThemingDefaults() { |
|
1883 | - return $this->query('ThemingDefaults'); |
|
1884 | - } |
|
1885 | - |
|
1886 | - /** |
|
1887 | - * @return \OC\IntegrityCheck\Checker |
|
1888 | - */ |
|
1889 | - public function getIntegrityCodeChecker() { |
|
1890 | - return $this->query('IntegrityCodeChecker'); |
|
1891 | - } |
|
1892 | - |
|
1893 | - /** |
|
1894 | - * @return \OC\Session\CryptoWrapper |
|
1895 | - */ |
|
1896 | - public function getSessionCryptoWrapper() { |
|
1897 | - return $this->query('CryptoWrapper'); |
|
1898 | - } |
|
1899 | - |
|
1900 | - /** |
|
1901 | - * @return CsrfTokenManager |
|
1902 | - */ |
|
1903 | - public function getCsrfTokenManager() { |
|
1904 | - return $this->query(CsrfTokenManager::class); |
|
1905 | - } |
|
1906 | - |
|
1907 | - /** |
|
1908 | - * @return Throttler |
|
1909 | - */ |
|
1910 | - public function getBruteForceThrottler() { |
|
1911 | - return $this->query('Throttler'); |
|
1912 | - } |
|
1913 | - |
|
1914 | - /** |
|
1915 | - * @return IContentSecurityPolicyManager |
|
1916 | - */ |
|
1917 | - public function getContentSecurityPolicyManager() { |
|
1918 | - return $this->query('ContentSecurityPolicyManager'); |
|
1919 | - } |
|
1920 | - |
|
1921 | - /** |
|
1922 | - * @return ContentSecurityPolicyNonceManager |
|
1923 | - */ |
|
1924 | - public function getContentSecurityPolicyNonceManager() { |
|
1925 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1926 | - } |
|
1927 | - |
|
1928 | - /** |
|
1929 | - * Not a public API as of 8.2, wait for 9.0 |
|
1930 | - * |
|
1931 | - * @return \OCA\Files_External\Service\BackendService |
|
1932 | - */ |
|
1933 | - public function getStoragesBackendService() { |
|
1934 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1935 | - } |
|
1936 | - |
|
1937 | - /** |
|
1938 | - * Not a public API as of 8.2, wait for 9.0 |
|
1939 | - * |
|
1940 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1941 | - */ |
|
1942 | - public function getGlobalStoragesService() { |
|
1943 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1944 | - } |
|
1945 | - |
|
1946 | - /** |
|
1947 | - * Not a public API as of 8.2, wait for 9.0 |
|
1948 | - * |
|
1949 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1950 | - */ |
|
1951 | - public function getUserGlobalStoragesService() { |
|
1952 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1953 | - } |
|
1954 | - |
|
1955 | - /** |
|
1956 | - * Not a public API as of 8.2, wait for 9.0 |
|
1957 | - * |
|
1958 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1959 | - */ |
|
1960 | - public function getUserStoragesService() { |
|
1961 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1962 | - } |
|
1963 | - |
|
1964 | - /** |
|
1965 | - * @return \OCP\Share\IManager |
|
1966 | - */ |
|
1967 | - public function getShareManager() { |
|
1968 | - return $this->query('ShareManager'); |
|
1969 | - } |
|
1970 | - |
|
1971 | - /** |
|
1972 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1973 | - */ |
|
1974 | - public function getCollaboratorSearch() { |
|
1975 | - return $this->query('CollaboratorSearch'); |
|
1976 | - } |
|
1977 | - |
|
1978 | - /** |
|
1979 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1980 | - */ |
|
1981 | - public function getAutoCompleteManager(){ |
|
1982 | - return $this->query(IManager::class); |
|
1983 | - } |
|
1984 | - |
|
1985 | - /** |
|
1986 | - * Returns the LDAP Provider |
|
1987 | - * |
|
1988 | - * @return \OCP\LDAP\ILDAPProvider |
|
1989 | - */ |
|
1990 | - public function getLDAPProvider() { |
|
1991 | - return $this->query('LDAPProvider'); |
|
1992 | - } |
|
1993 | - |
|
1994 | - /** |
|
1995 | - * @return \OCP\Settings\IManager |
|
1996 | - */ |
|
1997 | - public function getSettingsManager() { |
|
1998 | - return $this->query('SettingsManager'); |
|
1999 | - } |
|
2000 | - |
|
2001 | - /** |
|
2002 | - * @return \OCP\Files\IAppData |
|
2003 | - */ |
|
2004 | - public function getAppDataDir($app) { |
|
2005 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
2006 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
2007 | - return $factory->get($app); |
|
2008 | - } |
|
2009 | - |
|
2010 | - /** |
|
2011 | - * @return \OCP\Lockdown\ILockdownManager |
|
2012 | - */ |
|
2013 | - public function getLockdownManager() { |
|
2014 | - return $this->query('LockdownManager'); |
|
2015 | - } |
|
2016 | - |
|
2017 | - /** |
|
2018 | - * @return \OCP\Federation\ICloudIdManager |
|
2019 | - */ |
|
2020 | - public function getCloudIdManager() { |
|
2021 | - return $this->query(ICloudIdManager::class); |
|
2022 | - } |
|
2023 | - |
|
2024 | - /** |
|
2025 | - * @return \OCP\GlobalScale\IConfig |
|
2026 | - */ |
|
2027 | - public function getGlobalScaleConfig() { |
|
2028 | - return $this->query(IConfig::class); |
|
2029 | - } |
|
2030 | - |
|
2031 | - /** |
|
2032 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
2033 | - */ |
|
2034 | - public function getCloudFederationProviderManager() { |
|
2035 | - return $this->query(ICloudFederationProviderManager::class); |
|
2036 | - } |
|
2037 | - |
|
2038 | - /** |
|
2039 | - * @return \OCP\Remote\Api\IApiFactory |
|
2040 | - */ |
|
2041 | - public function getRemoteApiFactory() { |
|
2042 | - return $this->query(IApiFactory::class); |
|
2043 | - } |
|
2044 | - |
|
2045 | - /** |
|
2046 | - * @return \OCP\Federation\ICloudFederationFactory |
|
2047 | - */ |
|
2048 | - public function getCloudFederationFactory() { |
|
2049 | - return $this->query(ICloudFederationFactory::class); |
|
2050 | - } |
|
2051 | - |
|
2052 | - /** |
|
2053 | - * @return \OCP\Remote\IInstanceFactory |
|
2054 | - */ |
|
2055 | - public function getRemoteInstanceFactory() { |
|
2056 | - return $this->query(IInstanceFactory::class); |
|
2057 | - } |
|
2058 | - |
|
2059 | - /** |
|
2060 | - * @return IStorageFactory |
|
2061 | - */ |
|
2062 | - public function getStorageFactory() { |
|
2063 | - return $this->query(IStorageFactory::class); |
|
2064 | - } |
|
2065 | - |
|
2066 | - /** |
|
2067 | - * Get the Preview GeneratorHelper |
|
2068 | - * |
|
2069 | - * @return GeneratorHelper |
|
2070 | - * @since 17.0.0 |
|
2071 | - */ |
|
2072 | - public function getGeneratorHelper() { |
|
2073 | - return $this->query(\OC\Preview\GeneratorHelper::class); |
|
2074 | - } |
|
950 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
951 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
952 | + $classExists = true; |
|
953 | + } else { |
|
954 | + $classExists = false; |
|
955 | + } |
|
956 | + |
|
957 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
958 | + return new ThemingDefaults( |
|
959 | + $c->getConfig(), |
|
960 | + $c->getL10N('theming'), |
|
961 | + $c->getURLGenerator(), |
|
962 | + $c->getMemCacheFactory(), |
|
963 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
964 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
965 | + $c->getAppManager(), |
|
966 | + $c->getNavigationManager() |
|
967 | + ); |
|
968 | + } |
|
969 | + return new \OC_Defaults(); |
|
970 | + }); |
|
971 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
972 | + return new SCSSCacher( |
|
973 | + $c->getLogger(), |
|
974 | + $c->query(\OC\Files\AppData\Factory::class), |
|
975 | + $c->getURLGenerator(), |
|
976 | + $c->getConfig(), |
|
977 | + $c->getThemingDefaults(), |
|
978 | + \OC::$SERVERROOT, |
|
979 | + $this->getMemCacheFactory(), |
|
980 | + $c->query(IconsCacher::class), |
|
981 | + new TimeFactory() |
|
982 | + ); |
|
983 | + }); |
|
984 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
985 | + return new JSCombiner( |
|
986 | + $c->getAppDataDir('js'), |
|
987 | + $c->getURLGenerator(), |
|
988 | + $this->getMemCacheFactory(), |
|
989 | + $c->getSystemConfig(), |
|
990 | + $c->getLogger() |
|
991 | + ); |
|
992 | + }); |
|
993 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
994 | + $this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
995 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
996 | + |
|
997 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
998 | + // FIXME: Instantiiated here due to cyclic dependency |
|
999 | + $request = new Request( |
|
1000 | + [ |
|
1001 | + 'get' => $_GET, |
|
1002 | + 'post' => $_POST, |
|
1003 | + 'files' => $_FILES, |
|
1004 | + 'server' => $_SERVER, |
|
1005 | + 'env' => $_ENV, |
|
1006 | + 'cookies' => $_COOKIE, |
|
1007 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1008 | + ? $_SERVER['REQUEST_METHOD'] |
|
1009 | + : null, |
|
1010 | + ], |
|
1011 | + $c->getSecureRandom(), |
|
1012 | + $c->getConfig() |
|
1013 | + ); |
|
1014 | + |
|
1015 | + return new CryptoWrapper( |
|
1016 | + $c->getConfig(), |
|
1017 | + $c->getCrypto(), |
|
1018 | + $c->getSecureRandom(), |
|
1019 | + $request |
|
1020 | + ); |
|
1021 | + }); |
|
1022 | + $this->registerService(CsrfTokenManager::class, function (Server $c) { |
|
1023 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1024 | + |
|
1025 | + return new CsrfTokenManager( |
|
1026 | + $tokenGenerator, |
|
1027 | + $c->query(SessionStorage::class) |
|
1028 | + ); |
|
1029 | + }); |
|
1030 | + $this->registerAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1031 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1032 | + return new SessionStorage($c->getSession()); |
|
1033 | + }); |
|
1034 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, \OC\Security\CSP\ContentSecurityPolicyManager::class); |
|
1035 | + $this->registerAlias('ContentSecurityPolicyManager', \OC\Security\CSP\ContentSecurityPolicyManager::class); |
|
1036 | + |
|
1037 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1038 | + return new ContentSecurityPolicyNonceManager( |
|
1039 | + $c->getCsrfTokenManager(), |
|
1040 | + $c->getRequest() |
|
1041 | + ); |
|
1042 | + }); |
|
1043 | + |
|
1044 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1045 | + $config = $c->getConfig(); |
|
1046 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1047 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1048 | + $factory = new $factoryClass($this); |
|
1049 | + |
|
1050 | + $manager = new \OC\Share20\Manager( |
|
1051 | + $c->getLogger(), |
|
1052 | + $c->getConfig(), |
|
1053 | + $c->getSecureRandom(), |
|
1054 | + $c->getHasher(), |
|
1055 | + $c->getMountManager(), |
|
1056 | + $c->getGroupManager(), |
|
1057 | + $c->getL10N('lib'), |
|
1058 | + $c->getL10NFactory(), |
|
1059 | + $factory, |
|
1060 | + $c->getUserManager(), |
|
1061 | + $c->getLazyRootFolder(), |
|
1062 | + $c->getEventDispatcher(), |
|
1063 | + $c->getMailer(), |
|
1064 | + $c->getURLGenerator(), |
|
1065 | + $c->getThemingDefaults() |
|
1066 | + ); |
|
1067 | + |
|
1068 | + return $manager; |
|
1069 | + }); |
|
1070 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1071 | + |
|
1072 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1073 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1074 | + |
|
1075 | + // register default plugins |
|
1076 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1077 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1078 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1079 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1080 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1081 | + |
|
1082 | + return $instance; |
|
1083 | + }); |
|
1084 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1085 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1086 | + |
|
1087 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1088 | + |
|
1089 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1090 | + |
|
1091 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1092 | + $manager = new \OC\Settings\Manager( |
|
1093 | + $c->getLogger(), |
|
1094 | + $c->getL10NFactory(), |
|
1095 | + $c->getURLGenerator(), |
|
1096 | + $c |
|
1097 | + ); |
|
1098 | + return $manager; |
|
1099 | + }); |
|
1100 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1101 | + return new \OC\Files\AppData\Factory( |
|
1102 | + $c->getRootFolder(), |
|
1103 | + $c->getSystemConfig() |
|
1104 | + ); |
|
1105 | + }); |
|
1106 | + |
|
1107 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1108 | + return new LockdownManager(function () use ($c) { |
|
1109 | + return $c->getSession(); |
|
1110 | + }); |
|
1111 | + }); |
|
1112 | + |
|
1113 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1114 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1115 | + }); |
|
1116 | + |
|
1117 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1118 | + return new CloudIdManager(); |
|
1119 | + }); |
|
1120 | + |
|
1121 | + $this->registerService(IConfig::class, function (Server $c) { |
|
1122 | + return new GlobalScale\Config($c->getConfig()); |
|
1123 | + }); |
|
1124 | + |
|
1125 | + $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1126 | + return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1127 | + }); |
|
1128 | + |
|
1129 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1130 | + return new CloudFederationFactory(); |
|
1131 | + }); |
|
1132 | + |
|
1133 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1134 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1135 | + |
|
1136 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1137 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1138 | + |
|
1139 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1140 | + return new Defaults( |
|
1141 | + $c->getThemingDefaults() |
|
1142 | + ); |
|
1143 | + }); |
|
1144 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1145 | + |
|
1146 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1147 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1148 | + }); |
|
1149 | + |
|
1150 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1151 | + return new ShareHelper( |
|
1152 | + $c->query(\OCP\Share\IManager::class) |
|
1153 | + ); |
|
1154 | + }); |
|
1155 | + |
|
1156 | + $this->registerService(Installer::class, function(Server $c) { |
|
1157 | + return new Installer( |
|
1158 | + $c->getAppFetcher(), |
|
1159 | + $c->getHTTPClientService(), |
|
1160 | + $c->getTempManager(), |
|
1161 | + $c->getLogger(), |
|
1162 | + $c->getConfig() |
|
1163 | + ); |
|
1164 | + }); |
|
1165 | + |
|
1166 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
1167 | + return new ApiFactory($c->getHTTPClientService()); |
|
1168 | + }); |
|
1169 | + |
|
1170 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1171 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1172 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1173 | + }); |
|
1174 | + |
|
1175 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
1176 | + return new ContactsStore( |
|
1177 | + $c->getContactsManager(), |
|
1178 | + $c->getConfig(), |
|
1179 | + $c->getUserManager(), |
|
1180 | + $c->getGroupManager() |
|
1181 | + ); |
|
1182 | + }); |
|
1183 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1184 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1185 | + |
|
1186 | + $this->registerService(IStorageFactory::class, function() { |
|
1187 | + return new StorageFactory(); |
|
1188 | + }); |
|
1189 | + |
|
1190 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1191 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1192 | + |
|
1193 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) { |
|
1194 | + return new \OC\Security\IdentityProof\Manager( |
|
1195 | + $c->query(\OC\Files\AppData\Factory::class), |
|
1196 | + $c->getCrypto(), |
|
1197 | + $c->getConfig() |
|
1198 | + ); |
|
1199 | + }); |
|
1200 | + |
|
1201 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1202 | + |
|
1203 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1204 | + |
|
1205 | + $this->connectDispatcher(); |
|
1206 | + } |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * @return \OCP\Calendar\IManager |
|
1210 | + */ |
|
1211 | + public function getCalendarManager() { |
|
1212 | + return $this->query('CalendarManager'); |
|
1213 | + } |
|
1214 | + |
|
1215 | + /** |
|
1216 | + * @return \OCP\Calendar\Resource\IManager |
|
1217 | + */ |
|
1218 | + public function getCalendarResourceBackendManager() { |
|
1219 | + return $this->query('CalendarResourceBackendManager'); |
|
1220 | + } |
|
1221 | + |
|
1222 | + /** |
|
1223 | + * @return \OCP\Calendar\Room\IManager |
|
1224 | + */ |
|
1225 | + public function getCalendarRoomBackendManager() { |
|
1226 | + return $this->query('CalendarRoomBackendManager'); |
|
1227 | + } |
|
1228 | + |
|
1229 | + private function connectDispatcher() { |
|
1230 | + $dispatcher = $this->getEventDispatcher(); |
|
1231 | + |
|
1232 | + // Delete avatar on user deletion |
|
1233 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1234 | + $logger = $this->getLogger(); |
|
1235 | + $manager = $this->getAvatarManager(); |
|
1236 | + /** @var IUser $user */ |
|
1237 | + $user = $e->getSubject(); |
|
1238 | + |
|
1239 | + try { |
|
1240 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1241 | + $avatar->remove(); |
|
1242 | + } catch (NotFoundException $e) { |
|
1243 | + // no avatar to remove |
|
1244 | + } catch (\Exception $e) { |
|
1245 | + // Ignore exceptions |
|
1246 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1247 | + } |
|
1248 | + }); |
|
1249 | + |
|
1250 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1251 | + $manager = $this->getAvatarManager(); |
|
1252 | + /** @var IUser $user */ |
|
1253 | + $user = $e->getSubject(); |
|
1254 | + $feature = $e->getArgument('feature'); |
|
1255 | + $oldValue = $e->getArgument('oldValue'); |
|
1256 | + $value = $e->getArgument('value'); |
|
1257 | + |
|
1258 | + // We only change the avatar on display name changes |
|
1259 | + if ($feature !== 'displayName') { |
|
1260 | + return; |
|
1261 | + } |
|
1262 | + |
|
1263 | + try { |
|
1264 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1265 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1266 | + } catch (NotFoundException $e) { |
|
1267 | + // no avatar to remove |
|
1268 | + } |
|
1269 | + }); |
|
1270 | + } |
|
1271 | + |
|
1272 | + /** |
|
1273 | + * @return \OCP\Contacts\IManager |
|
1274 | + */ |
|
1275 | + public function getContactsManager() { |
|
1276 | + return $this->query('ContactsManager'); |
|
1277 | + } |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * @return \OC\Encryption\Manager |
|
1281 | + */ |
|
1282 | + public function getEncryptionManager() { |
|
1283 | + return $this->query('EncryptionManager'); |
|
1284 | + } |
|
1285 | + |
|
1286 | + /** |
|
1287 | + * @return \OC\Encryption\File |
|
1288 | + */ |
|
1289 | + public function getEncryptionFilesHelper() { |
|
1290 | + return $this->query('EncryptionFileHelper'); |
|
1291 | + } |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * @return \OCP\Encryption\Keys\IStorage |
|
1295 | + */ |
|
1296 | + public function getEncryptionKeyStorage() { |
|
1297 | + return $this->query('EncryptionKeyStorage'); |
|
1298 | + } |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * The current request object holding all information about the request |
|
1302 | + * currently being processed is returned from this method. |
|
1303 | + * In case the current execution was not initiated by a web request null is returned |
|
1304 | + * |
|
1305 | + * @return \OCP\IRequest |
|
1306 | + */ |
|
1307 | + public function getRequest() { |
|
1308 | + return $this->query('Request'); |
|
1309 | + } |
|
1310 | + |
|
1311 | + /** |
|
1312 | + * Returns the preview manager which can create preview images for a given file |
|
1313 | + * |
|
1314 | + * @return \OCP\IPreview |
|
1315 | + */ |
|
1316 | + public function getPreviewManager() { |
|
1317 | + return $this->query('PreviewManager'); |
|
1318 | + } |
|
1319 | + |
|
1320 | + /** |
|
1321 | + * Returns the tag manager which can get and set tags for different object types |
|
1322 | + * |
|
1323 | + * @see \OCP\ITagManager::load() |
|
1324 | + * @return \OCP\ITagManager |
|
1325 | + */ |
|
1326 | + public function getTagManager() { |
|
1327 | + return $this->query('TagManager'); |
|
1328 | + } |
|
1329 | + |
|
1330 | + /** |
|
1331 | + * Returns the system-tag manager |
|
1332 | + * |
|
1333 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1334 | + * |
|
1335 | + * @since 9.0.0 |
|
1336 | + */ |
|
1337 | + public function getSystemTagManager() { |
|
1338 | + return $this->query('SystemTagManager'); |
|
1339 | + } |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * Returns the system-tag object mapper |
|
1343 | + * |
|
1344 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1345 | + * |
|
1346 | + * @since 9.0.0 |
|
1347 | + */ |
|
1348 | + public function getSystemTagObjectMapper() { |
|
1349 | + return $this->query('SystemTagObjectMapper'); |
|
1350 | + } |
|
1351 | + |
|
1352 | + /** |
|
1353 | + * Returns the avatar manager, used for avatar functionality |
|
1354 | + * |
|
1355 | + * @return \OCP\IAvatarManager |
|
1356 | + */ |
|
1357 | + public function getAvatarManager() { |
|
1358 | + return $this->query('AvatarManager'); |
|
1359 | + } |
|
1360 | + |
|
1361 | + /** |
|
1362 | + * Returns the root folder of ownCloud's data directory |
|
1363 | + * |
|
1364 | + * @return \OCP\Files\IRootFolder |
|
1365 | + */ |
|
1366 | + public function getRootFolder() { |
|
1367 | + return $this->query('LazyRootFolder'); |
|
1368 | + } |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * Returns the root folder of ownCloud's data directory |
|
1372 | + * This is the lazy variant so this gets only initialized once it |
|
1373 | + * is actually used. |
|
1374 | + * |
|
1375 | + * @return \OCP\Files\IRootFolder |
|
1376 | + */ |
|
1377 | + public function getLazyRootFolder() { |
|
1378 | + return $this->query('LazyRootFolder'); |
|
1379 | + } |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * Returns a view to ownCloud's files folder |
|
1383 | + * |
|
1384 | + * @param string $userId user ID |
|
1385 | + * @return \OCP\Files\Folder|null |
|
1386 | + */ |
|
1387 | + public function getUserFolder($userId = null) { |
|
1388 | + if ($userId === null) { |
|
1389 | + $user = $this->getUserSession()->getUser(); |
|
1390 | + if (!$user) { |
|
1391 | + return null; |
|
1392 | + } |
|
1393 | + $userId = $user->getUID(); |
|
1394 | + } |
|
1395 | + $root = $this->getRootFolder(); |
|
1396 | + return $root->getUserFolder($userId); |
|
1397 | + } |
|
1398 | + |
|
1399 | + /** |
|
1400 | + * Returns an app-specific view in ownClouds data directory |
|
1401 | + * |
|
1402 | + * @return \OCP\Files\Folder |
|
1403 | + * @deprecated since 9.2.0 use IAppData |
|
1404 | + */ |
|
1405 | + public function getAppFolder() { |
|
1406 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1407 | + $root = $this->getRootFolder(); |
|
1408 | + if (!$root->nodeExists($dir)) { |
|
1409 | + $folder = $root->newFolder($dir); |
|
1410 | + } else { |
|
1411 | + $folder = $root->get($dir); |
|
1412 | + } |
|
1413 | + return $folder; |
|
1414 | + } |
|
1415 | + |
|
1416 | + /** |
|
1417 | + * @return \OC\User\Manager |
|
1418 | + */ |
|
1419 | + public function getUserManager() { |
|
1420 | + return $this->query('UserManager'); |
|
1421 | + } |
|
1422 | + |
|
1423 | + /** |
|
1424 | + * @return \OC\Group\Manager |
|
1425 | + */ |
|
1426 | + public function getGroupManager() { |
|
1427 | + return $this->query('GroupManager'); |
|
1428 | + } |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * @return \OC\User\Session |
|
1432 | + */ |
|
1433 | + public function getUserSession() { |
|
1434 | + return $this->query('UserSession'); |
|
1435 | + } |
|
1436 | + |
|
1437 | + /** |
|
1438 | + * @return \OCP\ISession |
|
1439 | + */ |
|
1440 | + public function getSession() { |
|
1441 | + return $this->query('UserSession')->getSession(); |
|
1442 | + } |
|
1443 | + |
|
1444 | + /** |
|
1445 | + * @param \OCP\ISession $session |
|
1446 | + */ |
|
1447 | + public function setSession(\OCP\ISession $session) { |
|
1448 | + $this->query(SessionStorage::class)->setSession($session); |
|
1449 | + $this->query('UserSession')->setSession($session); |
|
1450 | + $this->query(Store::class)->setSession($session); |
|
1451 | + } |
|
1452 | + |
|
1453 | + /** |
|
1454 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1455 | + */ |
|
1456 | + public function getTwoFactorAuthManager() { |
|
1457 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1458 | + } |
|
1459 | + |
|
1460 | + /** |
|
1461 | + * @return \OC\NavigationManager |
|
1462 | + */ |
|
1463 | + public function getNavigationManager() { |
|
1464 | + return $this->query('NavigationManager'); |
|
1465 | + } |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * @return \OCP\IConfig |
|
1469 | + */ |
|
1470 | + public function getConfig() { |
|
1471 | + return $this->query('AllConfig'); |
|
1472 | + } |
|
1473 | + |
|
1474 | + /** |
|
1475 | + * @return \OC\SystemConfig |
|
1476 | + */ |
|
1477 | + public function getSystemConfig() { |
|
1478 | + return $this->query('SystemConfig'); |
|
1479 | + } |
|
1480 | + |
|
1481 | + /** |
|
1482 | + * Returns the app config manager |
|
1483 | + * |
|
1484 | + * @return \OCP\IAppConfig |
|
1485 | + */ |
|
1486 | + public function getAppConfig() { |
|
1487 | + return $this->query('AppConfig'); |
|
1488 | + } |
|
1489 | + |
|
1490 | + /** |
|
1491 | + * @return \OCP\L10N\IFactory |
|
1492 | + */ |
|
1493 | + public function getL10NFactory() { |
|
1494 | + return $this->query('L10NFactory'); |
|
1495 | + } |
|
1496 | + |
|
1497 | + /** |
|
1498 | + * get an L10N instance |
|
1499 | + * |
|
1500 | + * @param string $app appid |
|
1501 | + * @param string $lang |
|
1502 | + * @return IL10N |
|
1503 | + */ |
|
1504 | + public function getL10N($app, $lang = null) { |
|
1505 | + return $this->getL10NFactory()->get($app, $lang); |
|
1506 | + } |
|
1507 | + |
|
1508 | + /** |
|
1509 | + * @return \OCP\IURLGenerator |
|
1510 | + */ |
|
1511 | + public function getURLGenerator() { |
|
1512 | + return $this->query('URLGenerator'); |
|
1513 | + } |
|
1514 | + |
|
1515 | + /** |
|
1516 | + * @return AppFetcher |
|
1517 | + */ |
|
1518 | + public function getAppFetcher() { |
|
1519 | + return $this->query(AppFetcher::class); |
|
1520 | + } |
|
1521 | + |
|
1522 | + /** |
|
1523 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1524 | + * getMemCacheFactory() instead. |
|
1525 | + * |
|
1526 | + * @return \OCP\ICache |
|
1527 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1528 | + */ |
|
1529 | + public function getCache() { |
|
1530 | + return $this->query('UserCache'); |
|
1531 | + } |
|
1532 | + |
|
1533 | + /** |
|
1534 | + * Returns an \OCP\CacheFactory instance |
|
1535 | + * |
|
1536 | + * @return \OCP\ICacheFactory |
|
1537 | + */ |
|
1538 | + public function getMemCacheFactory() { |
|
1539 | + return $this->query('MemCacheFactory'); |
|
1540 | + } |
|
1541 | + |
|
1542 | + /** |
|
1543 | + * Returns an \OC\RedisFactory instance |
|
1544 | + * |
|
1545 | + * @return \OC\RedisFactory |
|
1546 | + */ |
|
1547 | + public function getGetRedisFactory() { |
|
1548 | + return $this->query('RedisFactory'); |
|
1549 | + } |
|
1550 | + |
|
1551 | + |
|
1552 | + /** |
|
1553 | + * Returns the current session |
|
1554 | + * |
|
1555 | + * @return \OCP\IDBConnection |
|
1556 | + */ |
|
1557 | + public function getDatabaseConnection() { |
|
1558 | + return $this->query('DatabaseConnection'); |
|
1559 | + } |
|
1560 | + |
|
1561 | + /** |
|
1562 | + * Returns the activity manager |
|
1563 | + * |
|
1564 | + * @return \OCP\Activity\IManager |
|
1565 | + */ |
|
1566 | + public function getActivityManager() { |
|
1567 | + return $this->query('ActivityManager'); |
|
1568 | + } |
|
1569 | + |
|
1570 | + /** |
|
1571 | + * Returns an job list for controlling background jobs |
|
1572 | + * |
|
1573 | + * @return \OCP\BackgroundJob\IJobList |
|
1574 | + */ |
|
1575 | + public function getJobList() { |
|
1576 | + return $this->query('JobList'); |
|
1577 | + } |
|
1578 | + |
|
1579 | + /** |
|
1580 | + * Returns a logger instance |
|
1581 | + * |
|
1582 | + * @return \OCP\ILogger |
|
1583 | + */ |
|
1584 | + public function getLogger() { |
|
1585 | + return $this->query('Logger'); |
|
1586 | + } |
|
1587 | + |
|
1588 | + /** |
|
1589 | + * @return ILogFactory |
|
1590 | + * @throws \OCP\AppFramework\QueryException |
|
1591 | + */ |
|
1592 | + public function getLogFactory() { |
|
1593 | + return $this->query(ILogFactory::class); |
|
1594 | + } |
|
1595 | + |
|
1596 | + /** |
|
1597 | + * Returns a router for generating and matching urls |
|
1598 | + * |
|
1599 | + * @return \OCP\Route\IRouter |
|
1600 | + */ |
|
1601 | + public function getRouter() { |
|
1602 | + return $this->query('Router'); |
|
1603 | + } |
|
1604 | + |
|
1605 | + /** |
|
1606 | + * Returns a search instance |
|
1607 | + * |
|
1608 | + * @return \OCP\ISearch |
|
1609 | + */ |
|
1610 | + public function getSearch() { |
|
1611 | + return $this->query('Search'); |
|
1612 | + } |
|
1613 | + |
|
1614 | + /** |
|
1615 | + * Returns a SecureRandom instance |
|
1616 | + * |
|
1617 | + * @return \OCP\Security\ISecureRandom |
|
1618 | + */ |
|
1619 | + public function getSecureRandom() { |
|
1620 | + return $this->query('SecureRandom'); |
|
1621 | + } |
|
1622 | + |
|
1623 | + /** |
|
1624 | + * Returns a Crypto instance |
|
1625 | + * |
|
1626 | + * @return \OCP\Security\ICrypto |
|
1627 | + */ |
|
1628 | + public function getCrypto() { |
|
1629 | + return $this->query('Crypto'); |
|
1630 | + } |
|
1631 | + |
|
1632 | + /** |
|
1633 | + * Returns a Hasher instance |
|
1634 | + * |
|
1635 | + * @return \OCP\Security\IHasher |
|
1636 | + */ |
|
1637 | + public function getHasher() { |
|
1638 | + return $this->query('Hasher'); |
|
1639 | + } |
|
1640 | + |
|
1641 | + /** |
|
1642 | + * Returns a CredentialsManager instance |
|
1643 | + * |
|
1644 | + * @return \OCP\Security\ICredentialsManager |
|
1645 | + */ |
|
1646 | + public function getCredentialsManager() { |
|
1647 | + return $this->query('CredentialsManager'); |
|
1648 | + } |
|
1649 | + |
|
1650 | + /** |
|
1651 | + * Get the certificate manager for the user |
|
1652 | + * |
|
1653 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1654 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1655 | + */ |
|
1656 | + public function getCertificateManager($userId = '') { |
|
1657 | + if ($userId === '') { |
|
1658 | + $userSession = $this->getUserSession(); |
|
1659 | + $user = $userSession->getUser(); |
|
1660 | + if (is_null($user)) { |
|
1661 | + return null; |
|
1662 | + } |
|
1663 | + $userId = $user->getUID(); |
|
1664 | + } |
|
1665 | + return new CertificateManager( |
|
1666 | + $userId, |
|
1667 | + new View(), |
|
1668 | + $this->getConfig(), |
|
1669 | + $this->getLogger(), |
|
1670 | + $this->getSecureRandom() |
|
1671 | + ); |
|
1672 | + } |
|
1673 | + |
|
1674 | + /** |
|
1675 | + * Returns an instance of the HTTP client service |
|
1676 | + * |
|
1677 | + * @return \OCP\Http\Client\IClientService |
|
1678 | + */ |
|
1679 | + public function getHTTPClientService() { |
|
1680 | + return $this->query('HttpClientService'); |
|
1681 | + } |
|
1682 | + |
|
1683 | + /** |
|
1684 | + * Create a new event source |
|
1685 | + * |
|
1686 | + * @return \OCP\IEventSource |
|
1687 | + */ |
|
1688 | + public function createEventSource() { |
|
1689 | + return new \OC_EventSource(); |
|
1690 | + } |
|
1691 | + |
|
1692 | + /** |
|
1693 | + * Get the active event logger |
|
1694 | + * |
|
1695 | + * The returned logger only logs data when debug mode is enabled |
|
1696 | + * |
|
1697 | + * @return \OCP\Diagnostics\IEventLogger |
|
1698 | + */ |
|
1699 | + public function getEventLogger() { |
|
1700 | + return $this->query('EventLogger'); |
|
1701 | + } |
|
1702 | + |
|
1703 | + /** |
|
1704 | + * Get the active query logger |
|
1705 | + * |
|
1706 | + * The returned logger only logs data when debug mode is enabled |
|
1707 | + * |
|
1708 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1709 | + */ |
|
1710 | + public function getQueryLogger() { |
|
1711 | + return $this->query('QueryLogger'); |
|
1712 | + } |
|
1713 | + |
|
1714 | + /** |
|
1715 | + * Get the manager for temporary files and folders |
|
1716 | + * |
|
1717 | + * @return \OCP\ITempManager |
|
1718 | + */ |
|
1719 | + public function getTempManager() { |
|
1720 | + return $this->query('TempManager'); |
|
1721 | + } |
|
1722 | + |
|
1723 | + /** |
|
1724 | + * Get the app manager |
|
1725 | + * |
|
1726 | + * @return \OCP\App\IAppManager |
|
1727 | + */ |
|
1728 | + public function getAppManager() { |
|
1729 | + return $this->query('AppManager'); |
|
1730 | + } |
|
1731 | + |
|
1732 | + /** |
|
1733 | + * Creates a new mailer |
|
1734 | + * |
|
1735 | + * @return \OCP\Mail\IMailer |
|
1736 | + */ |
|
1737 | + public function getMailer() { |
|
1738 | + return $this->query('Mailer'); |
|
1739 | + } |
|
1740 | + |
|
1741 | + /** |
|
1742 | + * Get the webroot |
|
1743 | + * |
|
1744 | + * @return string |
|
1745 | + */ |
|
1746 | + public function getWebRoot() { |
|
1747 | + return $this->webRoot; |
|
1748 | + } |
|
1749 | + |
|
1750 | + /** |
|
1751 | + * @return \OC\OCSClient |
|
1752 | + */ |
|
1753 | + public function getOcsClient() { |
|
1754 | + return $this->query('OcsClient'); |
|
1755 | + } |
|
1756 | + |
|
1757 | + /** |
|
1758 | + * @return \OCP\IDateTimeZone |
|
1759 | + */ |
|
1760 | + public function getDateTimeZone() { |
|
1761 | + return $this->query('DateTimeZone'); |
|
1762 | + } |
|
1763 | + |
|
1764 | + /** |
|
1765 | + * @return \OCP\IDateTimeFormatter |
|
1766 | + */ |
|
1767 | + public function getDateTimeFormatter() { |
|
1768 | + return $this->query('DateTimeFormatter'); |
|
1769 | + } |
|
1770 | + |
|
1771 | + /** |
|
1772 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1773 | + */ |
|
1774 | + public function getMountProviderCollection() { |
|
1775 | + return $this->query('MountConfigManager'); |
|
1776 | + } |
|
1777 | + |
|
1778 | + /** |
|
1779 | + * Get the IniWrapper |
|
1780 | + * |
|
1781 | + * @return IniGetWrapper |
|
1782 | + */ |
|
1783 | + public function getIniWrapper() { |
|
1784 | + return $this->query('IniWrapper'); |
|
1785 | + } |
|
1786 | + |
|
1787 | + /** |
|
1788 | + * @return \OCP\Command\IBus |
|
1789 | + */ |
|
1790 | + public function getCommandBus() { |
|
1791 | + return $this->query('AsyncCommandBus'); |
|
1792 | + } |
|
1793 | + |
|
1794 | + /** |
|
1795 | + * Get the trusted domain helper |
|
1796 | + * |
|
1797 | + * @return TrustedDomainHelper |
|
1798 | + */ |
|
1799 | + public function getTrustedDomainHelper() { |
|
1800 | + return $this->query('TrustedDomainHelper'); |
|
1801 | + } |
|
1802 | + |
|
1803 | + /** |
|
1804 | + * Get the locking provider |
|
1805 | + * |
|
1806 | + * @return \OCP\Lock\ILockingProvider |
|
1807 | + * @since 8.1.0 |
|
1808 | + */ |
|
1809 | + public function getLockingProvider() { |
|
1810 | + return $this->query('LockingProvider'); |
|
1811 | + } |
|
1812 | + |
|
1813 | + /** |
|
1814 | + * @return \OCP\Files\Mount\IMountManager |
|
1815 | + **/ |
|
1816 | + function getMountManager() { |
|
1817 | + return $this->query('MountManager'); |
|
1818 | + } |
|
1819 | + |
|
1820 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1821 | + function getUserMountCache() { |
|
1822 | + return $this->query('UserMountCache'); |
|
1823 | + } |
|
1824 | + |
|
1825 | + /** |
|
1826 | + * Get the MimeTypeDetector |
|
1827 | + * |
|
1828 | + * @return \OCP\Files\IMimeTypeDetector |
|
1829 | + */ |
|
1830 | + public function getMimeTypeDetector() { |
|
1831 | + return $this->query('MimeTypeDetector'); |
|
1832 | + } |
|
1833 | + |
|
1834 | + /** |
|
1835 | + * Get the MimeTypeLoader |
|
1836 | + * |
|
1837 | + * @return \OCP\Files\IMimeTypeLoader |
|
1838 | + */ |
|
1839 | + public function getMimeTypeLoader() { |
|
1840 | + return $this->query('MimeTypeLoader'); |
|
1841 | + } |
|
1842 | + |
|
1843 | + /** |
|
1844 | + * Get the manager of all the capabilities |
|
1845 | + * |
|
1846 | + * @return \OC\CapabilitiesManager |
|
1847 | + */ |
|
1848 | + public function getCapabilitiesManager() { |
|
1849 | + return $this->query('CapabilitiesManager'); |
|
1850 | + } |
|
1851 | + |
|
1852 | + /** |
|
1853 | + * Get the EventDispatcher |
|
1854 | + * |
|
1855 | + * @return EventDispatcherInterface |
|
1856 | + * @since 8.2.0 |
|
1857 | + */ |
|
1858 | + public function getEventDispatcher() { |
|
1859 | + return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
1860 | + } |
|
1861 | + |
|
1862 | + /** |
|
1863 | + * Get the Notification Manager |
|
1864 | + * |
|
1865 | + * @return \OCP\Notification\IManager |
|
1866 | + * @since 8.2.0 |
|
1867 | + */ |
|
1868 | + public function getNotificationManager() { |
|
1869 | + return $this->query('NotificationManager'); |
|
1870 | + } |
|
1871 | + |
|
1872 | + /** |
|
1873 | + * @return \OCP\Comments\ICommentsManager |
|
1874 | + */ |
|
1875 | + public function getCommentsManager() { |
|
1876 | + return $this->query('CommentsManager'); |
|
1877 | + } |
|
1878 | + |
|
1879 | + /** |
|
1880 | + * @return \OCA\Theming\ThemingDefaults |
|
1881 | + */ |
|
1882 | + public function getThemingDefaults() { |
|
1883 | + return $this->query('ThemingDefaults'); |
|
1884 | + } |
|
1885 | + |
|
1886 | + /** |
|
1887 | + * @return \OC\IntegrityCheck\Checker |
|
1888 | + */ |
|
1889 | + public function getIntegrityCodeChecker() { |
|
1890 | + return $this->query('IntegrityCodeChecker'); |
|
1891 | + } |
|
1892 | + |
|
1893 | + /** |
|
1894 | + * @return \OC\Session\CryptoWrapper |
|
1895 | + */ |
|
1896 | + public function getSessionCryptoWrapper() { |
|
1897 | + return $this->query('CryptoWrapper'); |
|
1898 | + } |
|
1899 | + |
|
1900 | + /** |
|
1901 | + * @return CsrfTokenManager |
|
1902 | + */ |
|
1903 | + public function getCsrfTokenManager() { |
|
1904 | + return $this->query(CsrfTokenManager::class); |
|
1905 | + } |
|
1906 | + |
|
1907 | + /** |
|
1908 | + * @return Throttler |
|
1909 | + */ |
|
1910 | + public function getBruteForceThrottler() { |
|
1911 | + return $this->query('Throttler'); |
|
1912 | + } |
|
1913 | + |
|
1914 | + /** |
|
1915 | + * @return IContentSecurityPolicyManager |
|
1916 | + */ |
|
1917 | + public function getContentSecurityPolicyManager() { |
|
1918 | + return $this->query('ContentSecurityPolicyManager'); |
|
1919 | + } |
|
1920 | + |
|
1921 | + /** |
|
1922 | + * @return ContentSecurityPolicyNonceManager |
|
1923 | + */ |
|
1924 | + public function getContentSecurityPolicyNonceManager() { |
|
1925 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1926 | + } |
|
1927 | + |
|
1928 | + /** |
|
1929 | + * Not a public API as of 8.2, wait for 9.0 |
|
1930 | + * |
|
1931 | + * @return \OCA\Files_External\Service\BackendService |
|
1932 | + */ |
|
1933 | + public function getStoragesBackendService() { |
|
1934 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1935 | + } |
|
1936 | + |
|
1937 | + /** |
|
1938 | + * Not a public API as of 8.2, wait for 9.0 |
|
1939 | + * |
|
1940 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1941 | + */ |
|
1942 | + public function getGlobalStoragesService() { |
|
1943 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1944 | + } |
|
1945 | + |
|
1946 | + /** |
|
1947 | + * Not a public API as of 8.2, wait for 9.0 |
|
1948 | + * |
|
1949 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1950 | + */ |
|
1951 | + public function getUserGlobalStoragesService() { |
|
1952 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1953 | + } |
|
1954 | + |
|
1955 | + /** |
|
1956 | + * Not a public API as of 8.2, wait for 9.0 |
|
1957 | + * |
|
1958 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1959 | + */ |
|
1960 | + public function getUserStoragesService() { |
|
1961 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1962 | + } |
|
1963 | + |
|
1964 | + /** |
|
1965 | + * @return \OCP\Share\IManager |
|
1966 | + */ |
|
1967 | + public function getShareManager() { |
|
1968 | + return $this->query('ShareManager'); |
|
1969 | + } |
|
1970 | + |
|
1971 | + /** |
|
1972 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1973 | + */ |
|
1974 | + public function getCollaboratorSearch() { |
|
1975 | + return $this->query('CollaboratorSearch'); |
|
1976 | + } |
|
1977 | + |
|
1978 | + /** |
|
1979 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1980 | + */ |
|
1981 | + public function getAutoCompleteManager(){ |
|
1982 | + return $this->query(IManager::class); |
|
1983 | + } |
|
1984 | + |
|
1985 | + /** |
|
1986 | + * Returns the LDAP Provider |
|
1987 | + * |
|
1988 | + * @return \OCP\LDAP\ILDAPProvider |
|
1989 | + */ |
|
1990 | + public function getLDAPProvider() { |
|
1991 | + return $this->query('LDAPProvider'); |
|
1992 | + } |
|
1993 | + |
|
1994 | + /** |
|
1995 | + * @return \OCP\Settings\IManager |
|
1996 | + */ |
|
1997 | + public function getSettingsManager() { |
|
1998 | + return $this->query('SettingsManager'); |
|
1999 | + } |
|
2000 | + |
|
2001 | + /** |
|
2002 | + * @return \OCP\Files\IAppData |
|
2003 | + */ |
|
2004 | + public function getAppDataDir($app) { |
|
2005 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
2006 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
2007 | + return $factory->get($app); |
|
2008 | + } |
|
2009 | + |
|
2010 | + /** |
|
2011 | + * @return \OCP\Lockdown\ILockdownManager |
|
2012 | + */ |
|
2013 | + public function getLockdownManager() { |
|
2014 | + return $this->query('LockdownManager'); |
|
2015 | + } |
|
2016 | + |
|
2017 | + /** |
|
2018 | + * @return \OCP\Federation\ICloudIdManager |
|
2019 | + */ |
|
2020 | + public function getCloudIdManager() { |
|
2021 | + return $this->query(ICloudIdManager::class); |
|
2022 | + } |
|
2023 | + |
|
2024 | + /** |
|
2025 | + * @return \OCP\GlobalScale\IConfig |
|
2026 | + */ |
|
2027 | + public function getGlobalScaleConfig() { |
|
2028 | + return $this->query(IConfig::class); |
|
2029 | + } |
|
2030 | + |
|
2031 | + /** |
|
2032 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
2033 | + */ |
|
2034 | + public function getCloudFederationProviderManager() { |
|
2035 | + return $this->query(ICloudFederationProviderManager::class); |
|
2036 | + } |
|
2037 | + |
|
2038 | + /** |
|
2039 | + * @return \OCP\Remote\Api\IApiFactory |
|
2040 | + */ |
|
2041 | + public function getRemoteApiFactory() { |
|
2042 | + return $this->query(IApiFactory::class); |
|
2043 | + } |
|
2044 | + |
|
2045 | + /** |
|
2046 | + * @return \OCP\Federation\ICloudFederationFactory |
|
2047 | + */ |
|
2048 | + public function getCloudFederationFactory() { |
|
2049 | + return $this->query(ICloudFederationFactory::class); |
|
2050 | + } |
|
2051 | + |
|
2052 | + /** |
|
2053 | + * @return \OCP\Remote\IInstanceFactory |
|
2054 | + */ |
|
2055 | + public function getRemoteInstanceFactory() { |
|
2056 | + return $this->query(IInstanceFactory::class); |
|
2057 | + } |
|
2058 | + |
|
2059 | + /** |
|
2060 | + * @return IStorageFactory |
|
2061 | + */ |
|
2062 | + public function getStorageFactory() { |
|
2063 | + return $this->query(IStorageFactory::class); |
|
2064 | + } |
|
2065 | + |
|
2066 | + /** |
|
2067 | + * Get the Preview GeneratorHelper |
|
2068 | + * |
|
2069 | + * @return GeneratorHelper |
|
2070 | + * @since 17.0.0 |
|
2071 | + */ |
|
2072 | + public function getGeneratorHelper() { |
|
2073 | + return $this->query(\OC\Preview\GeneratorHelper::class); |
|
2074 | + } |
|
2075 | 2075 | } |