@@ -39,238 +39,238 @@ |
||
| 39 | 39 | |
| 40 | 40 | class JSConfigHelper { |
| 41 | 41 | |
| 42 | - /** @var IL10N */ |
|
| 43 | - private $l; |
|
| 42 | + /** @var IL10N */ |
|
| 43 | + private $l; |
|
| 44 | 44 | |
| 45 | - /** @var Defaults */ |
|
| 46 | - private $defaults; |
|
| 45 | + /** @var Defaults */ |
|
| 46 | + private $defaults; |
|
| 47 | 47 | |
| 48 | - /** @var IAppManager */ |
|
| 49 | - private $appManager; |
|
| 48 | + /** @var IAppManager */ |
|
| 49 | + private $appManager; |
|
| 50 | 50 | |
| 51 | - /** @var ISession */ |
|
| 52 | - private $session; |
|
| 51 | + /** @var ISession */ |
|
| 52 | + private $session; |
|
| 53 | 53 | |
| 54 | - /** @var IUser|null */ |
|
| 55 | - private $currentUser; |
|
| 54 | + /** @var IUser|null */ |
|
| 55 | + private $currentUser; |
|
| 56 | 56 | |
| 57 | - /** @var IConfig */ |
|
| 58 | - private $config; |
|
| 57 | + /** @var IConfig */ |
|
| 58 | + private $config; |
|
| 59 | 59 | |
| 60 | - /** @var IGroupManager */ |
|
| 61 | - private $groupManager; |
|
| 60 | + /** @var IGroupManager */ |
|
| 61 | + private $groupManager; |
|
| 62 | 62 | |
| 63 | - /** @var IniGetWrapper */ |
|
| 64 | - private $iniWrapper; |
|
| 63 | + /** @var IniGetWrapper */ |
|
| 64 | + private $iniWrapper; |
|
| 65 | 65 | |
| 66 | - /** @var IURLGenerator */ |
|
| 67 | - private $urlGenerator; |
|
| 66 | + /** @var IURLGenerator */ |
|
| 67 | + private $urlGenerator; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param IL10N $l |
|
| 71 | - * @param Defaults $defaults |
|
| 72 | - * @param IAppManager $appManager |
|
| 73 | - * @param ISession $session |
|
| 74 | - * @param IUser|null $currentUser |
|
| 75 | - * @param IConfig $config |
|
| 76 | - * @param IGroupManager $groupManager |
|
| 77 | - * @param IniGetWrapper $iniWrapper |
|
| 78 | - * @param IURLGenerator $urlGenerator |
|
| 79 | - */ |
|
| 80 | - public function __construct(IL10N $l, |
|
| 81 | - Defaults $defaults, |
|
| 82 | - IAppManager $appManager, |
|
| 83 | - ISession $session, |
|
| 84 | - $currentUser, |
|
| 85 | - IConfig $config, |
|
| 86 | - IGroupManager $groupManager, |
|
| 87 | - IniGetWrapper $iniWrapper, |
|
| 88 | - IURLGenerator $urlGenerator) { |
|
| 89 | - $this->l = $l; |
|
| 90 | - $this->defaults = $defaults; |
|
| 91 | - $this->appManager = $appManager; |
|
| 92 | - $this->session = $session; |
|
| 93 | - $this->currentUser = $currentUser; |
|
| 94 | - $this->config = $config; |
|
| 95 | - $this->groupManager = $groupManager; |
|
| 96 | - $this->iniWrapper = $iniWrapper; |
|
| 97 | - $this->urlGenerator = $urlGenerator; |
|
| 98 | - } |
|
| 69 | + /** |
|
| 70 | + * @param IL10N $l |
|
| 71 | + * @param Defaults $defaults |
|
| 72 | + * @param IAppManager $appManager |
|
| 73 | + * @param ISession $session |
|
| 74 | + * @param IUser|null $currentUser |
|
| 75 | + * @param IConfig $config |
|
| 76 | + * @param IGroupManager $groupManager |
|
| 77 | + * @param IniGetWrapper $iniWrapper |
|
| 78 | + * @param IURLGenerator $urlGenerator |
|
| 79 | + */ |
|
| 80 | + public function __construct(IL10N $l, |
|
| 81 | + Defaults $defaults, |
|
| 82 | + IAppManager $appManager, |
|
| 83 | + ISession $session, |
|
| 84 | + $currentUser, |
|
| 85 | + IConfig $config, |
|
| 86 | + IGroupManager $groupManager, |
|
| 87 | + IniGetWrapper $iniWrapper, |
|
| 88 | + IURLGenerator $urlGenerator) { |
|
| 89 | + $this->l = $l; |
|
| 90 | + $this->defaults = $defaults; |
|
| 91 | + $this->appManager = $appManager; |
|
| 92 | + $this->session = $session; |
|
| 93 | + $this->currentUser = $currentUser; |
|
| 94 | + $this->config = $config; |
|
| 95 | + $this->groupManager = $groupManager; |
|
| 96 | + $this->iniWrapper = $iniWrapper; |
|
| 97 | + $this->urlGenerator = $urlGenerator; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - public function getConfig() { |
|
| 100 | + public function getConfig() { |
|
| 101 | 101 | |
| 102 | - if ($this->currentUser !== null) { |
|
| 103 | - $uid = $this->currentUser->getUID(); |
|
| 104 | - $userBackend = $this->currentUser->getBackendClassName(); |
|
| 105 | - } else { |
|
| 106 | - $uid = null; |
|
| 107 | - $userBackend = ''; |
|
| 108 | - } |
|
| 102 | + if ($this->currentUser !== null) { |
|
| 103 | + $uid = $this->currentUser->getUID(); |
|
| 104 | + $userBackend = $this->currentUser->getBackendClassName(); |
|
| 105 | + } else { |
|
| 106 | + $uid = null; |
|
| 107 | + $userBackend = ''; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - // Get the config |
|
| 111 | - $apps_paths = []; |
|
| 110 | + // Get the config |
|
| 111 | + $apps_paths = []; |
|
| 112 | 112 | |
| 113 | - if ($this->currentUser === null) { |
|
| 114 | - $apps = $this->appManager->getInstalledApps(); |
|
| 115 | - } else { |
|
| 116 | - $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
|
| 117 | - } |
|
| 113 | + if ($this->currentUser === null) { |
|
| 114 | + $apps = $this->appManager->getInstalledApps(); |
|
| 115 | + } else { |
|
| 116 | + $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - foreach($apps as $app) { |
|
| 120 | - $apps_paths[$app] = \OC_App::getAppWebPath($app); |
|
| 121 | - } |
|
| 119 | + foreach($apps as $app) { |
|
| 120 | + $apps_paths[$app] = \OC_App::getAppWebPath($app); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | |
| 124 | - $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'); |
|
| 125 | - $enableLinkPasswordByDefault = ($enableLinkPasswordByDefault === 'yes') ? true : false; |
|
| 126 | - $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 127 | - $defaultExpireDate = $enforceDefaultExpireDate = null; |
|
| 128 | - if ($defaultExpireDateEnabled) { |
|
| 129 | - $defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 130 | - $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 131 | - } |
|
| 132 | - $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 124 | + $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'); |
|
| 125 | + $enableLinkPasswordByDefault = ($enableLinkPasswordByDefault === 'yes') ? true : false; |
|
| 126 | + $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 127 | + $defaultExpireDate = $enforceDefaultExpireDate = null; |
|
| 128 | + if ($defaultExpireDateEnabled) { |
|
| 129 | + $defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 130 | + $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 131 | + } |
|
| 132 | + $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 133 | 133 | |
| 134 | - $countOfDataLocation = 0; |
|
| 135 | - $dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
| 136 | - if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
| 137 | - $dataLocation = false; |
|
| 138 | - } |
|
| 134 | + $countOfDataLocation = 0; |
|
| 135 | + $dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
| 136 | + if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
| 137 | + $dataLocation = false; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - if ($this->currentUser instanceof IUser) { |
|
| 141 | - $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
|
| 142 | - if (!is_int($lastConfirmTimestamp)) { |
|
| 143 | - $lastConfirmTimestamp = 0; |
|
| 144 | - } |
|
| 145 | - } else { |
|
| 146 | - $lastConfirmTimestamp = 0; |
|
| 147 | - } |
|
| 140 | + if ($this->currentUser instanceof IUser) { |
|
| 141 | + $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
|
| 142 | + if (!is_int($lastConfirmTimestamp)) { |
|
| 143 | + $lastConfirmTimestamp = 0; |
|
| 144 | + } |
|
| 145 | + } else { |
|
| 146 | + $lastConfirmTimestamp = 0; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - $array = [ |
|
| 150 | - "oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
|
| 151 | - "oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
|
| 152 | - "backendAllowsPasswordConfirmation" => $userBackend === 'user_saml'? 'false' : 'true', |
|
| 153 | - "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', |
|
| 154 | - "oc_webroot" => "\"".\OC::$WEBROOT."\"", |
|
| 155 | - "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
|
| 156 | - "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
|
| 157 | - 'nc_lastLogin' => $lastConfirmTimestamp, |
|
| 158 | - "dayNames" => json_encode([ |
|
| 159 | - (string)$this->l->t('Sunday'), |
|
| 160 | - (string)$this->l->t('Monday'), |
|
| 161 | - (string)$this->l->t('Tuesday'), |
|
| 162 | - (string)$this->l->t('Wednesday'), |
|
| 163 | - (string)$this->l->t('Thursday'), |
|
| 164 | - (string)$this->l->t('Friday'), |
|
| 165 | - (string)$this->l->t('Saturday') |
|
| 166 | - ]), |
|
| 167 | - "dayNamesShort" => json_encode([ |
|
| 168 | - (string)$this->l->t('Sun.'), |
|
| 169 | - (string)$this->l->t('Mon.'), |
|
| 170 | - (string)$this->l->t('Tue.'), |
|
| 171 | - (string)$this->l->t('Wed.'), |
|
| 172 | - (string)$this->l->t('Thu.'), |
|
| 173 | - (string)$this->l->t('Fri.'), |
|
| 174 | - (string)$this->l->t('Sat.') |
|
| 175 | - ]), |
|
| 176 | - "dayNamesMin" => json_encode([ |
|
| 177 | - (string)$this->l->t('Su'), |
|
| 178 | - (string)$this->l->t('Mo'), |
|
| 179 | - (string)$this->l->t('Tu'), |
|
| 180 | - (string)$this->l->t('We'), |
|
| 181 | - (string)$this->l->t('Th'), |
|
| 182 | - (string)$this->l->t('Fr'), |
|
| 183 | - (string)$this->l->t('Sa') |
|
| 184 | - ]), |
|
| 185 | - "monthNames" => json_encode([ |
|
| 186 | - (string)$this->l->t('January'), |
|
| 187 | - (string)$this->l->t('February'), |
|
| 188 | - (string)$this->l->t('March'), |
|
| 189 | - (string)$this->l->t('April'), |
|
| 190 | - (string)$this->l->t('May'), |
|
| 191 | - (string)$this->l->t('June'), |
|
| 192 | - (string)$this->l->t('July'), |
|
| 193 | - (string)$this->l->t('August'), |
|
| 194 | - (string)$this->l->t('September'), |
|
| 195 | - (string)$this->l->t('October'), |
|
| 196 | - (string)$this->l->t('November'), |
|
| 197 | - (string)$this->l->t('December') |
|
| 198 | - ]), |
|
| 199 | - "monthNamesShort" => json_encode([ |
|
| 200 | - (string)$this->l->t('Jan.'), |
|
| 201 | - (string)$this->l->t('Feb.'), |
|
| 202 | - (string)$this->l->t('Mar.'), |
|
| 203 | - (string)$this->l->t('Apr.'), |
|
| 204 | - (string)$this->l->t('May.'), |
|
| 205 | - (string)$this->l->t('Jun.'), |
|
| 206 | - (string)$this->l->t('Jul.'), |
|
| 207 | - (string)$this->l->t('Aug.'), |
|
| 208 | - (string)$this->l->t('Sep.'), |
|
| 209 | - (string)$this->l->t('Oct.'), |
|
| 210 | - (string)$this->l->t('Nov.'), |
|
| 211 | - (string)$this->l->t('Dec.') |
|
| 212 | - ]), |
|
| 213 | - "firstDay" => json_encode($this->l->l('firstday', null)) , |
|
| 214 | - "oc_config" => json_encode([ |
|
| 215 | - 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
|
| 216 | - 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
|
| 217 | - 'version' => implode('.', \OCP\Util::getVersion()), |
|
| 218 | - 'versionstring' => \OC_Util::getVersionString(), |
|
| 219 | - 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value |
|
| 220 | - 'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null), |
|
| 221 | - 'modRewriteWorking' => ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'), |
|
| 222 | - 'sharing.maxAutocompleteResults' => intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)), |
|
| 223 | - 'sharing.minSearchStringLength' => intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)), |
|
| 224 | - 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, |
|
| 225 | - ]), |
|
| 226 | - "oc_appconfig" => json_encode([ |
|
| 227 | - 'core' => [ |
|
| 228 | - 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, |
|
| 229 | - 'defaultExpireDate' => $defaultExpireDate, |
|
| 230 | - 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, |
|
| 231 | - 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), |
|
| 232 | - 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, |
|
| 233 | - 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), |
|
| 234 | - 'resharingAllowed' => \OC\Share\Share::isResharingAllowed(), |
|
| 235 | - 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, |
|
| 236 | - 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), |
|
| 237 | - 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing() |
|
| 238 | - ] |
|
| 239 | - ]), |
|
| 240 | - "oc_defaults" => json_encode([ |
|
| 241 | - 'entity' => $this->defaults->getEntity(), |
|
| 242 | - 'name' => $this->defaults->getName(), |
|
| 243 | - 'title' => $this->defaults->getTitle(), |
|
| 244 | - 'baseUrl' => $this->defaults->getBaseUrl(), |
|
| 245 | - 'syncClientUrl' => $this->defaults->getSyncClientUrl(), |
|
| 246 | - 'docBaseUrl' => $this->defaults->getDocBaseUrl(), |
|
| 247 | - 'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'), |
|
| 248 | - 'slogan' => $this->defaults->getSlogan(), |
|
| 249 | - 'logoClaim' => '', |
|
| 250 | - 'shortFooter' => $this->defaults->getShortFooter(), |
|
| 251 | - 'longFooter' => $this->defaults->getLongFooter(), |
|
| 252 | - 'folder' => \OC_Util::getTheme(), |
|
| 253 | - ]), |
|
| 254 | - ]; |
|
| 149 | + $array = [ |
|
| 150 | + "oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
|
| 151 | + "oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
|
| 152 | + "backendAllowsPasswordConfirmation" => $userBackend === 'user_saml'? 'false' : 'true', |
|
| 153 | + "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', |
|
| 154 | + "oc_webroot" => "\"".\OC::$WEBROOT."\"", |
|
| 155 | + "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
|
| 156 | + "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
|
| 157 | + 'nc_lastLogin' => $lastConfirmTimestamp, |
|
| 158 | + "dayNames" => json_encode([ |
|
| 159 | + (string)$this->l->t('Sunday'), |
|
| 160 | + (string)$this->l->t('Monday'), |
|
| 161 | + (string)$this->l->t('Tuesday'), |
|
| 162 | + (string)$this->l->t('Wednesday'), |
|
| 163 | + (string)$this->l->t('Thursday'), |
|
| 164 | + (string)$this->l->t('Friday'), |
|
| 165 | + (string)$this->l->t('Saturday') |
|
| 166 | + ]), |
|
| 167 | + "dayNamesShort" => json_encode([ |
|
| 168 | + (string)$this->l->t('Sun.'), |
|
| 169 | + (string)$this->l->t('Mon.'), |
|
| 170 | + (string)$this->l->t('Tue.'), |
|
| 171 | + (string)$this->l->t('Wed.'), |
|
| 172 | + (string)$this->l->t('Thu.'), |
|
| 173 | + (string)$this->l->t('Fri.'), |
|
| 174 | + (string)$this->l->t('Sat.') |
|
| 175 | + ]), |
|
| 176 | + "dayNamesMin" => json_encode([ |
|
| 177 | + (string)$this->l->t('Su'), |
|
| 178 | + (string)$this->l->t('Mo'), |
|
| 179 | + (string)$this->l->t('Tu'), |
|
| 180 | + (string)$this->l->t('We'), |
|
| 181 | + (string)$this->l->t('Th'), |
|
| 182 | + (string)$this->l->t('Fr'), |
|
| 183 | + (string)$this->l->t('Sa') |
|
| 184 | + ]), |
|
| 185 | + "monthNames" => json_encode([ |
|
| 186 | + (string)$this->l->t('January'), |
|
| 187 | + (string)$this->l->t('February'), |
|
| 188 | + (string)$this->l->t('March'), |
|
| 189 | + (string)$this->l->t('April'), |
|
| 190 | + (string)$this->l->t('May'), |
|
| 191 | + (string)$this->l->t('June'), |
|
| 192 | + (string)$this->l->t('July'), |
|
| 193 | + (string)$this->l->t('August'), |
|
| 194 | + (string)$this->l->t('September'), |
|
| 195 | + (string)$this->l->t('October'), |
|
| 196 | + (string)$this->l->t('November'), |
|
| 197 | + (string)$this->l->t('December') |
|
| 198 | + ]), |
|
| 199 | + "monthNamesShort" => json_encode([ |
|
| 200 | + (string)$this->l->t('Jan.'), |
|
| 201 | + (string)$this->l->t('Feb.'), |
|
| 202 | + (string)$this->l->t('Mar.'), |
|
| 203 | + (string)$this->l->t('Apr.'), |
|
| 204 | + (string)$this->l->t('May.'), |
|
| 205 | + (string)$this->l->t('Jun.'), |
|
| 206 | + (string)$this->l->t('Jul.'), |
|
| 207 | + (string)$this->l->t('Aug.'), |
|
| 208 | + (string)$this->l->t('Sep.'), |
|
| 209 | + (string)$this->l->t('Oct.'), |
|
| 210 | + (string)$this->l->t('Nov.'), |
|
| 211 | + (string)$this->l->t('Dec.') |
|
| 212 | + ]), |
|
| 213 | + "firstDay" => json_encode($this->l->l('firstday', null)) , |
|
| 214 | + "oc_config" => json_encode([ |
|
| 215 | + 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
|
| 216 | + 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
|
| 217 | + 'version' => implode('.', \OCP\Util::getVersion()), |
|
| 218 | + 'versionstring' => \OC_Util::getVersionString(), |
|
| 219 | + 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value |
|
| 220 | + 'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null), |
|
| 221 | + 'modRewriteWorking' => ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'), |
|
| 222 | + 'sharing.maxAutocompleteResults' => intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)), |
|
| 223 | + 'sharing.minSearchStringLength' => intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)), |
|
| 224 | + 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, |
|
| 225 | + ]), |
|
| 226 | + "oc_appconfig" => json_encode([ |
|
| 227 | + 'core' => [ |
|
| 228 | + 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, |
|
| 229 | + 'defaultExpireDate' => $defaultExpireDate, |
|
| 230 | + 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, |
|
| 231 | + 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), |
|
| 232 | + 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, |
|
| 233 | + 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), |
|
| 234 | + 'resharingAllowed' => \OC\Share\Share::isResharingAllowed(), |
|
| 235 | + 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, |
|
| 236 | + 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), |
|
| 237 | + 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing() |
|
| 238 | + ] |
|
| 239 | + ]), |
|
| 240 | + "oc_defaults" => json_encode([ |
|
| 241 | + 'entity' => $this->defaults->getEntity(), |
|
| 242 | + 'name' => $this->defaults->getName(), |
|
| 243 | + 'title' => $this->defaults->getTitle(), |
|
| 244 | + 'baseUrl' => $this->defaults->getBaseUrl(), |
|
| 245 | + 'syncClientUrl' => $this->defaults->getSyncClientUrl(), |
|
| 246 | + 'docBaseUrl' => $this->defaults->getDocBaseUrl(), |
|
| 247 | + 'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'), |
|
| 248 | + 'slogan' => $this->defaults->getSlogan(), |
|
| 249 | + 'logoClaim' => '', |
|
| 250 | + 'shortFooter' => $this->defaults->getShortFooter(), |
|
| 251 | + 'longFooter' => $this->defaults->getLongFooter(), |
|
| 252 | + 'folder' => \OC_Util::getTheme(), |
|
| 253 | + ]), |
|
| 254 | + ]; |
|
| 255 | 255 | |
| 256 | - if ($this->currentUser !== null) { |
|
| 257 | - $array['oc_userconfig'] = json_encode([ |
|
| 258 | - 'avatar' => [ |
|
| 259 | - 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
| 260 | - ] |
|
| 261 | - ]); |
|
| 262 | - } |
|
| 256 | + if ($this->currentUser !== null) { |
|
| 257 | + $array['oc_userconfig'] = json_encode([ |
|
| 258 | + 'avatar' => [ |
|
| 259 | + 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
| 260 | + ] |
|
| 261 | + ]); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - // Allow hooks to modify the output values |
|
| 265 | - \OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array)); |
|
| 264 | + // Allow hooks to modify the output values |
|
| 265 | + \OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array)); |
|
| 266 | 266 | |
| 267 | - $result = ''; |
|
| 267 | + $result = ''; |
|
| 268 | 268 | |
| 269 | - // Echo it |
|
| 270 | - foreach ($array as $setting => $value) { |
|
| 271 | - $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
| 272 | - } |
|
| 269 | + // Echo it |
|
| 270 | + foreach ($array as $setting => $value) { |
|
| 271 | + $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - return $result; |
|
| 275 | - } |
|
| 274 | + return $result; |
|
| 275 | + } |
|
| 276 | 276 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - foreach($apps as $app) { |
|
| 119 | + foreach ($apps as $app) { |
|
| 120 | 120 | $apps_paths[$app] = \OC_App::getAppWebPath($app); |
| 121 | 121 | } |
| 122 | 122 | |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
| 133 | 133 | |
| 134 | 134 | $countOfDataLocation = 0; |
| 135 | - $dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
| 136 | - if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
| 135 | + $dataLocation = str_replace(\OC::$SERVERROOT.'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
| 136 | + if ($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
| 137 | 137 | $dataLocation = false; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -149,68 +149,68 @@ discard block |
||
| 149 | 149 | $array = [ |
| 150 | 150 | "oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
| 151 | 151 | "oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
| 152 | - "backendAllowsPasswordConfirmation" => $userBackend === 'user_saml'? 'false' : 'true', |
|
| 152 | + "backendAllowsPasswordConfirmation" => $userBackend === 'user_saml' ? 'false' : 'true', |
|
| 153 | 153 | "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', |
| 154 | 154 | "oc_webroot" => "\"".\OC::$WEBROOT."\"", |
| 155 | 155 | "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
| 156 | 156 | "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
| 157 | 157 | 'nc_lastLogin' => $lastConfirmTimestamp, |
| 158 | 158 | "dayNames" => json_encode([ |
| 159 | - (string)$this->l->t('Sunday'), |
|
| 160 | - (string)$this->l->t('Monday'), |
|
| 161 | - (string)$this->l->t('Tuesday'), |
|
| 162 | - (string)$this->l->t('Wednesday'), |
|
| 163 | - (string)$this->l->t('Thursday'), |
|
| 164 | - (string)$this->l->t('Friday'), |
|
| 165 | - (string)$this->l->t('Saturday') |
|
| 159 | + (string) $this->l->t('Sunday'), |
|
| 160 | + (string) $this->l->t('Monday'), |
|
| 161 | + (string) $this->l->t('Tuesday'), |
|
| 162 | + (string) $this->l->t('Wednesday'), |
|
| 163 | + (string) $this->l->t('Thursday'), |
|
| 164 | + (string) $this->l->t('Friday'), |
|
| 165 | + (string) $this->l->t('Saturday') |
|
| 166 | 166 | ]), |
| 167 | 167 | "dayNamesShort" => json_encode([ |
| 168 | - (string)$this->l->t('Sun.'), |
|
| 169 | - (string)$this->l->t('Mon.'), |
|
| 170 | - (string)$this->l->t('Tue.'), |
|
| 171 | - (string)$this->l->t('Wed.'), |
|
| 172 | - (string)$this->l->t('Thu.'), |
|
| 173 | - (string)$this->l->t('Fri.'), |
|
| 174 | - (string)$this->l->t('Sat.') |
|
| 168 | + (string) $this->l->t('Sun.'), |
|
| 169 | + (string) $this->l->t('Mon.'), |
|
| 170 | + (string) $this->l->t('Tue.'), |
|
| 171 | + (string) $this->l->t('Wed.'), |
|
| 172 | + (string) $this->l->t('Thu.'), |
|
| 173 | + (string) $this->l->t('Fri.'), |
|
| 174 | + (string) $this->l->t('Sat.') |
|
| 175 | 175 | ]), |
| 176 | 176 | "dayNamesMin" => json_encode([ |
| 177 | - (string)$this->l->t('Su'), |
|
| 178 | - (string)$this->l->t('Mo'), |
|
| 179 | - (string)$this->l->t('Tu'), |
|
| 180 | - (string)$this->l->t('We'), |
|
| 181 | - (string)$this->l->t('Th'), |
|
| 182 | - (string)$this->l->t('Fr'), |
|
| 183 | - (string)$this->l->t('Sa') |
|
| 177 | + (string) $this->l->t('Su'), |
|
| 178 | + (string) $this->l->t('Mo'), |
|
| 179 | + (string) $this->l->t('Tu'), |
|
| 180 | + (string) $this->l->t('We'), |
|
| 181 | + (string) $this->l->t('Th'), |
|
| 182 | + (string) $this->l->t('Fr'), |
|
| 183 | + (string) $this->l->t('Sa') |
|
| 184 | 184 | ]), |
| 185 | 185 | "monthNames" => json_encode([ |
| 186 | - (string)$this->l->t('January'), |
|
| 187 | - (string)$this->l->t('February'), |
|
| 188 | - (string)$this->l->t('March'), |
|
| 189 | - (string)$this->l->t('April'), |
|
| 190 | - (string)$this->l->t('May'), |
|
| 191 | - (string)$this->l->t('June'), |
|
| 192 | - (string)$this->l->t('July'), |
|
| 193 | - (string)$this->l->t('August'), |
|
| 194 | - (string)$this->l->t('September'), |
|
| 195 | - (string)$this->l->t('October'), |
|
| 196 | - (string)$this->l->t('November'), |
|
| 197 | - (string)$this->l->t('December') |
|
| 186 | + (string) $this->l->t('January'), |
|
| 187 | + (string) $this->l->t('February'), |
|
| 188 | + (string) $this->l->t('March'), |
|
| 189 | + (string) $this->l->t('April'), |
|
| 190 | + (string) $this->l->t('May'), |
|
| 191 | + (string) $this->l->t('June'), |
|
| 192 | + (string) $this->l->t('July'), |
|
| 193 | + (string) $this->l->t('August'), |
|
| 194 | + (string) $this->l->t('September'), |
|
| 195 | + (string) $this->l->t('October'), |
|
| 196 | + (string) $this->l->t('November'), |
|
| 197 | + (string) $this->l->t('December') |
|
| 198 | 198 | ]), |
| 199 | 199 | "monthNamesShort" => json_encode([ |
| 200 | - (string)$this->l->t('Jan.'), |
|
| 201 | - (string)$this->l->t('Feb.'), |
|
| 202 | - (string)$this->l->t('Mar.'), |
|
| 203 | - (string)$this->l->t('Apr.'), |
|
| 204 | - (string)$this->l->t('May.'), |
|
| 205 | - (string)$this->l->t('Jun.'), |
|
| 206 | - (string)$this->l->t('Jul.'), |
|
| 207 | - (string)$this->l->t('Aug.'), |
|
| 208 | - (string)$this->l->t('Sep.'), |
|
| 209 | - (string)$this->l->t('Oct.'), |
|
| 210 | - (string)$this->l->t('Nov.'), |
|
| 211 | - (string)$this->l->t('Dec.') |
|
| 200 | + (string) $this->l->t('Jan.'), |
|
| 201 | + (string) $this->l->t('Feb.'), |
|
| 202 | + (string) $this->l->t('Mar.'), |
|
| 203 | + (string) $this->l->t('Apr.'), |
|
| 204 | + (string) $this->l->t('May.'), |
|
| 205 | + (string) $this->l->t('Jun.'), |
|
| 206 | + (string) $this->l->t('Jul.'), |
|
| 207 | + (string) $this->l->t('Aug.'), |
|
| 208 | + (string) $this->l->t('Sep.'), |
|
| 209 | + (string) $this->l->t('Oct.'), |
|
| 210 | + (string) $this->l->t('Nov.'), |
|
| 211 | + (string) $this->l->t('Dec.') |
|
| 212 | 212 | ]), |
| 213 | - "firstDay" => json_encode($this->l->l('firstday', null)) , |
|
| 213 | + "firstDay" => json_encode($this->l->l('firstday', null)), |
|
| 214 | 214 | "oc_config" => json_encode([ |
| 215 | 215 | 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
| 216 | 216 | 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | if ($this->currentUser !== null) { |
| 257 | 257 | $array['oc_userconfig'] = json_encode([ |
| 258 | 258 | 'avatar' => [ |
| 259 | - 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
| 259 | + 'version' => (int) $this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
| 260 | 260 | ] |
| 261 | 261 | ]); |
| 262 | 262 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | |
| 269 | 269 | // Echo it |
| 270 | 270 | foreach ($array as $setting => $value) { |
| 271 | - $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
| 271 | + $result .= 'var '.$setting.'='.$value.';'.PHP_EOL; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | return $result; |
@@ -106,7 +106,7 @@ |
||
| 106 | 106 | * @param bool $isLoggedIn |
| 107 | 107 | * @param bool $isAdminUser |
| 108 | 108 | * @param ContentSecurityPolicyManager $contentSecurityPolicyManager |
| 109 | - * @param CSRFTokenManager $csrfTokenManager |
|
| 109 | + * @param CsrfTokenManager $csrfTokenManager |
|
| 110 | 110 | * @param ContentSecurityPolicyNonceManager $cspNonceManager |
| 111 | 111 | * @param IAppManager $appManager |
| 112 | 112 | * @param IUserSession $userSession |
@@ -66,224 +66,224 @@ |
||
| 66 | 66 | * check fails |
| 67 | 67 | */ |
| 68 | 68 | class SecurityMiddleware extends Middleware { |
| 69 | - /** @var INavigationManager */ |
|
| 70 | - private $navigationManager; |
|
| 71 | - /** @var IRequest */ |
|
| 72 | - private $request; |
|
| 73 | - /** @var ControllerMethodReflector */ |
|
| 74 | - private $reflector; |
|
| 75 | - /** @var string */ |
|
| 76 | - private $appName; |
|
| 77 | - /** @var IURLGenerator */ |
|
| 78 | - private $urlGenerator; |
|
| 79 | - /** @var ILogger */ |
|
| 80 | - private $logger; |
|
| 81 | - /** @var ISession */ |
|
| 82 | - private $session; |
|
| 83 | - /** @var bool */ |
|
| 84 | - private $isLoggedIn; |
|
| 85 | - /** @var bool */ |
|
| 86 | - private $isAdminUser; |
|
| 87 | - /** @var ContentSecurityPolicyManager */ |
|
| 88 | - private $contentSecurityPolicyManager; |
|
| 89 | - /** @var CsrfTokenManager */ |
|
| 90 | - private $csrfTokenManager; |
|
| 91 | - /** @var ContentSecurityPolicyNonceManager */ |
|
| 92 | - private $cspNonceManager; |
|
| 93 | - /** @var IAppManager */ |
|
| 94 | - private $appManager; |
|
| 95 | - /** @var IUserSession */ |
|
| 96 | - private $userSession; |
|
| 69 | + /** @var INavigationManager */ |
|
| 70 | + private $navigationManager; |
|
| 71 | + /** @var IRequest */ |
|
| 72 | + private $request; |
|
| 73 | + /** @var ControllerMethodReflector */ |
|
| 74 | + private $reflector; |
|
| 75 | + /** @var string */ |
|
| 76 | + private $appName; |
|
| 77 | + /** @var IURLGenerator */ |
|
| 78 | + private $urlGenerator; |
|
| 79 | + /** @var ILogger */ |
|
| 80 | + private $logger; |
|
| 81 | + /** @var ISession */ |
|
| 82 | + private $session; |
|
| 83 | + /** @var bool */ |
|
| 84 | + private $isLoggedIn; |
|
| 85 | + /** @var bool */ |
|
| 86 | + private $isAdminUser; |
|
| 87 | + /** @var ContentSecurityPolicyManager */ |
|
| 88 | + private $contentSecurityPolicyManager; |
|
| 89 | + /** @var CsrfTokenManager */ |
|
| 90 | + private $csrfTokenManager; |
|
| 91 | + /** @var ContentSecurityPolicyNonceManager */ |
|
| 92 | + private $cspNonceManager; |
|
| 93 | + /** @var IAppManager */ |
|
| 94 | + private $appManager; |
|
| 95 | + /** @var IUserSession */ |
|
| 96 | + private $userSession; |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @param IRequest $request |
|
| 100 | - * @param ControllerMethodReflector $reflector |
|
| 101 | - * @param INavigationManager $navigationManager |
|
| 102 | - * @param IURLGenerator $urlGenerator |
|
| 103 | - * @param ILogger $logger |
|
| 104 | - * @param ISession $session |
|
| 105 | - * @param string $appName |
|
| 106 | - * @param bool $isLoggedIn |
|
| 107 | - * @param bool $isAdminUser |
|
| 108 | - * @param ContentSecurityPolicyManager $contentSecurityPolicyManager |
|
| 109 | - * @param CSRFTokenManager $csrfTokenManager |
|
| 110 | - * @param ContentSecurityPolicyNonceManager $cspNonceManager |
|
| 111 | - * @param IAppManager $appManager |
|
| 112 | - * @param IUserSession $userSession |
|
| 113 | - */ |
|
| 114 | - public function __construct(IRequest $request, |
|
| 115 | - ControllerMethodReflector $reflector, |
|
| 116 | - INavigationManager $navigationManager, |
|
| 117 | - IURLGenerator $urlGenerator, |
|
| 118 | - ILogger $logger, |
|
| 119 | - ISession $session, |
|
| 120 | - $appName, |
|
| 121 | - $isLoggedIn, |
|
| 122 | - $isAdminUser, |
|
| 123 | - ContentSecurityPolicyManager $contentSecurityPolicyManager, |
|
| 124 | - CsrfTokenManager $csrfTokenManager, |
|
| 125 | - ContentSecurityPolicyNonceManager $cspNonceManager, |
|
| 126 | - IAppManager $appManager, |
|
| 127 | - IUserSession $userSession |
|
| 128 | - ) { |
|
| 129 | - $this->navigationManager = $navigationManager; |
|
| 130 | - $this->request = $request; |
|
| 131 | - $this->reflector = $reflector; |
|
| 132 | - $this->appName = $appName; |
|
| 133 | - $this->urlGenerator = $urlGenerator; |
|
| 134 | - $this->logger = $logger; |
|
| 135 | - $this->session = $session; |
|
| 136 | - $this->isLoggedIn = $isLoggedIn; |
|
| 137 | - $this->isAdminUser = $isAdminUser; |
|
| 138 | - $this->contentSecurityPolicyManager = $contentSecurityPolicyManager; |
|
| 139 | - $this->csrfTokenManager = $csrfTokenManager; |
|
| 140 | - $this->cspNonceManager = $cspNonceManager; |
|
| 141 | - $this->appManager = $appManager; |
|
| 142 | - $this->userSession = $userSession; |
|
| 143 | - } |
|
| 98 | + /** |
|
| 99 | + * @param IRequest $request |
|
| 100 | + * @param ControllerMethodReflector $reflector |
|
| 101 | + * @param INavigationManager $navigationManager |
|
| 102 | + * @param IURLGenerator $urlGenerator |
|
| 103 | + * @param ILogger $logger |
|
| 104 | + * @param ISession $session |
|
| 105 | + * @param string $appName |
|
| 106 | + * @param bool $isLoggedIn |
|
| 107 | + * @param bool $isAdminUser |
|
| 108 | + * @param ContentSecurityPolicyManager $contentSecurityPolicyManager |
|
| 109 | + * @param CSRFTokenManager $csrfTokenManager |
|
| 110 | + * @param ContentSecurityPolicyNonceManager $cspNonceManager |
|
| 111 | + * @param IAppManager $appManager |
|
| 112 | + * @param IUserSession $userSession |
|
| 113 | + */ |
|
| 114 | + public function __construct(IRequest $request, |
|
| 115 | + ControllerMethodReflector $reflector, |
|
| 116 | + INavigationManager $navigationManager, |
|
| 117 | + IURLGenerator $urlGenerator, |
|
| 118 | + ILogger $logger, |
|
| 119 | + ISession $session, |
|
| 120 | + $appName, |
|
| 121 | + $isLoggedIn, |
|
| 122 | + $isAdminUser, |
|
| 123 | + ContentSecurityPolicyManager $contentSecurityPolicyManager, |
|
| 124 | + CsrfTokenManager $csrfTokenManager, |
|
| 125 | + ContentSecurityPolicyNonceManager $cspNonceManager, |
|
| 126 | + IAppManager $appManager, |
|
| 127 | + IUserSession $userSession |
|
| 128 | + ) { |
|
| 129 | + $this->navigationManager = $navigationManager; |
|
| 130 | + $this->request = $request; |
|
| 131 | + $this->reflector = $reflector; |
|
| 132 | + $this->appName = $appName; |
|
| 133 | + $this->urlGenerator = $urlGenerator; |
|
| 134 | + $this->logger = $logger; |
|
| 135 | + $this->session = $session; |
|
| 136 | + $this->isLoggedIn = $isLoggedIn; |
|
| 137 | + $this->isAdminUser = $isAdminUser; |
|
| 138 | + $this->contentSecurityPolicyManager = $contentSecurityPolicyManager; |
|
| 139 | + $this->csrfTokenManager = $csrfTokenManager; |
|
| 140 | + $this->cspNonceManager = $cspNonceManager; |
|
| 141 | + $this->appManager = $appManager; |
|
| 142 | + $this->userSession = $userSession; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * This runs all the security checks before a method call. The |
|
| 147 | - * security checks are determined by inspecting the controller method |
|
| 148 | - * annotations |
|
| 149 | - * @param Controller $controller the controller |
|
| 150 | - * @param string $methodName the name of the method |
|
| 151 | - * @throws SecurityException when a security check fails |
|
| 152 | - */ |
|
| 153 | - public function beforeController($controller, $methodName) { |
|
| 145 | + /** |
|
| 146 | + * This runs all the security checks before a method call. The |
|
| 147 | + * security checks are determined by inspecting the controller method |
|
| 148 | + * annotations |
|
| 149 | + * @param Controller $controller the controller |
|
| 150 | + * @param string $methodName the name of the method |
|
| 151 | + * @throws SecurityException when a security check fails |
|
| 152 | + */ |
|
| 153 | + public function beforeController($controller, $methodName) { |
|
| 154 | 154 | |
| 155 | - // this will set the current navigation entry of the app, use this only |
|
| 156 | - // for normal HTML requests and not for AJAX requests |
|
| 157 | - $this->navigationManager->setActiveEntry($this->appName); |
|
| 155 | + // this will set the current navigation entry of the app, use this only |
|
| 156 | + // for normal HTML requests and not for AJAX requests |
|
| 157 | + $this->navigationManager->setActiveEntry($this->appName); |
|
| 158 | 158 | |
| 159 | - // security checks |
|
| 160 | - $isPublicPage = $this->reflector->hasAnnotation('PublicPage'); |
|
| 161 | - if(!$isPublicPage) { |
|
| 162 | - if(!$this->isLoggedIn) { |
|
| 163 | - throw new NotLoggedInException(); |
|
| 164 | - } |
|
| 159 | + // security checks |
|
| 160 | + $isPublicPage = $this->reflector->hasAnnotation('PublicPage'); |
|
| 161 | + if(!$isPublicPage) { |
|
| 162 | + if(!$this->isLoggedIn) { |
|
| 163 | + throw new NotLoggedInException(); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - if(!$this->reflector->hasAnnotation('NoAdminRequired')) { |
|
| 167 | - if(!$this->isAdminUser) { |
|
| 168 | - throw new NotAdminException(); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - } |
|
| 166 | + if(!$this->reflector->hasAnnotation('NoAdminRequired')) { |
|
| 167 | + if(!$this->isAdminUser) { |
|
| 168 | + throw new NotAdminException(); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) { |
|
| 174 | - $user = $this->userSession->getUser(); |
|
| 175 | - $backendClassName = ''; |
|
| 176 | - if ($user !== null) { |
|
| 177 | - $backendClassName = $user->getBackendClassName(); |
|
| 178 | - } |
|
| 173 | + if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) { |
|
| 174 | + $user = $this->userSession->getUser(); |
|
| 175 | + $backendClassName = ''; |
|
| 176 | + if ($user !== null) { |
|
| 177 | + $backendClassName = $user->getBackendClassName(); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - $lastConfirm = (int) $this->session->get('last-password-confirm'); |
|
| 181 | - // we can't check the password against a SAML backend, so skip password confirmation in this case |
|
| 182 | - if ($backendClassName !== 'user_saml' && $lastConfirm < (time() - (30 * 60 + 15))) { // allow 15 seconds delay |
|
| 183 | - throw new NotConfirmedException(); |
|
| 184 | - } |
|
| 185 | - } |
|
| 180 | + $lastConfirm = (int) $this->session->get('last-password-confirm'); |
|
| 181 | + // we can't check the password against a SAML backend, so skip password confirmation in this case |
|
| 182 | + if ($backendClassName !== 'user_saml' && $lastConfirm < (time() - (30 * 60 + 15))) { // allow 15 seconds delay |
|
| 183 | + throw new NotConfirmedException(); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - // Check for strict cookie requirement |
|
| 188 | - if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) { |
|
| 189 | - if(!$this->request->passesStrictCookieCheck()) { |
|
| 190 | - throw new StrictCookieMissingException(); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - // CSRF check - also registers the CSRF token since the session may be closed later |
|
| 194 | - Util::callRegister(); |
|
| 195 | - if(!$this->reflector->hasAnnotation('NoCSRFRequired')) { |
|
| 196 | - /* |
|
| 187 | + // Check for strict cookie requirement |
|
| 188 | + if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) { |
|
| 189 | + if(!$this->request->passesStrictCookieCheck()) { |
|
| 190 | + throw new StrictCookieMissingException(); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + // CSRF check - also registers the CSRF token since the session may be closed later |
|
| 194 | + Util::callRegister(); |
|
| 195 | + if(!$this->reflector->hasAnnotation('NoCSRFRequired')) { |
|
| 196 | + /* |
|
| 197 | 197 | * Only allow the CSRF check to fail on OCS Requests. This kind of |
| 198 | 198 | * hacks around that we have no full token auth in place yet and we |
| 199 | 199 | * do want to offer CSRF checks for web requests. |
| 200 | 200 | */ |
| 201 | - if(!$this->request->passesCSRFCheck() && !( |
|
| 202 | - $controller instanceof OCSController && |
|
| 203 | - $this->request->getHeader('OCS-APIREQUEST') === 'true')) { |
|
| 204 | - throw new CrossSiteRequestForgeryException(); |
|
| 205 | - } |
|
| 206 | - } |
|
| 201 | + if(!$this->request->passesCSRFCheck() && !( |
|
| 202 | + $controller instanceof OCSController && |
|
| 203 | + $this->request->getHeader('OCS-APIREQUEST') === 'true')) { |
|
| 204 | + throw new CrossSiteRequestForgeryException(); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * FIXME: Use DI once available |
|
| 210 | - * Checks if app is enabled (also includes a check whether user is allowed to access the resource) |
|
| 211 | - * The getAppPath() check is here since components such as settings also use the AppFramework and |
|
| 212 | - * therefore won't pass this check. |
|
| 213 | - */ |
|
| 214 | - if(\OC_App::getAppPath($this->appName) !== false && !$this->appManager->isEnabledForUser($this->appName)) { |
|
| 215 | - throw new AppNotEnabledException(); |
|
| 216 | - } |
|
| 208 | + /** |
|
| 209 | + * FIXME: Use DI once available |
|
| 210 | + * Checks if app is enabled (also includes a check whether user is allowed to access the resource) |
|
| 211 | + * The getAppPath() check is here since components such as settings also use the AppFramework and |
|
| 212 | + * therefore won't pass this check. |
|
| 213 | + */ |
|
| 214 | + if(\OC_App::getAppPath($this->appName) !== false && !$this->appManager->isEnabledForUser($this->appName)) { |
|
| 215 | + throw new AppNotEnabledException(); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Performs the default CSP modifications that may be injected by other |
|
| 222 | - * applications |
|
| 223 | - * |
|
| 224 | - * @param Controller $controller |
|
| 225 | - * @param string $methodName |
|
| 226 | - * @param Response $response |
|
| 227 | - * @return Response |
|
| 228 | - */ |
|
| 229 | - public function afterController($controller, $methodName, Response $response) { |
|
| 230 | - $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy(); |
|
| 220 | + /** |
|
| 221 | + * Performs the default CSP modifications that may be injected by other |
|
| 222 | + * applications |
|
| 223 | + * |
|
| 224 | + * @param Controller $controller |
|
| 225 | + * @param string $methodName |
|
| 226 | + * @param Response $response |
|
| 227 | + * @return Response |
|
| 228 | + */ |
|
| 229 | + public function afterController($controller, $methodName, Response $response) { |
|
| 230 | + $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy(); |
|
| 231 | 231 | |
| 232 | - if (get_class($policy) === EmptyContentSecurityPolicy::class) { |
|
| 233 | - return $response; |
|
| 234 | - } |
|
| 232 | + if (get_class($policy) === EmptyContentSecurityPolicy::class) { |
|
| 233 | + return $response; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - $defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy(); |
|
| 237 | - $defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy); |
|
| 236 | + $defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy(); |
|
| 237 | + $defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy); |
|
| 238 | 238 | |
| 239 | - if($this->cspNonceManager->browserSupportsCspV3()) { |
|
| 240 | - $defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue()); |
|
| 241 | - } |
|
| 239 | + if($this->cspNonceManager->browserSupportsCspV3()) { |
|
| 240 | + $defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue()); |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - $response->setContentSecurityPolicy($defaultPolicy); |
|
| 243 | + $response->setContentSecurityPolicy($defaultPolicy); |
|
| 244 | 244 | |
| 245 | - return $response; |
|
| 246 | - } |
|
| 245 | + return $response; |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * If an SecurityException is being caught, ajax requests return a JSON error |
|
| 250 | - * response and non ajax requests redirect to the index |
|
| 251 | - * @param Controller $controller the controller that is being called |
|
| 252 | - * @param string $methodName the name of the method that will be called on |
|
| 253 | - * the controller |
|
| 254 | - * @param \Exception $exception the thrown exception |
|
| 255 | - * @throws \Exception the passed in exception if it can't handle it |
|
| 256 | - * @return Response a Response object or null in case that the exception could not be handled |
|
| 257 | - */ |
|
| 258 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 259 | - if($exception instanceof SecurityException) { |
|
| 260 | - if($exception instanceof StrictCookieMissingException) { |
|
| 261 | - return new RedirectResponse(\OC::$WEBROOT); |
|
| 262 | - } |
|
| 263 | - if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
| 264 | - $response = new JSONResponse( |
|
| 265 | - array('message' => $exception->getMessage()), |
|
| 266 | - $exception->getCode() |
|
| 267 | - ); |
|
| 268 | - } else { |
|
| 269 | - if($exception instanceof NotLoggedInException) { |
|
| 270 | - $params = []; |
|
| 271 | - if (isset($this->request->server['REQUEST_URI'])) { |
|
| 272 | - $params['redirect_url'] = $this->request->server['REQUEST_URI']; |
|
| 273 | - } |
|
| 274 | - $url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params); |
|
| 275 | - $response = new RedirectResponse($url); |
|
| 276 | - } else { |
|
| 277 | - $response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest'); |
|
| 278 | - $response->setStatus($exception->getCode()); |
|
| 279 | - } |
|
| 280 | - } |
|
| 248 | + /** |
|
| 249 | + * If an SecurityException is being caught, ajax requests return a JSON error |
|
| 250 | + * response and non ajax requests redirect to the index |
|
| 251 | + * @param Controller $controller the controller that is being called |
|
| 252 | + * @param string $methodName the name of the method that will be called on |
|
| 253 | + * the controller |
|
| 254 | + * @param \Exception $exception the thrown exception |
|
| 255 | + * @throws \Exception the passed in exception if it can't handle it |
|
| 256 | + * @return Response a Response object or null in case that the exception could not be handled |
|
| 257 | + */ |
|
| 258 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 259 | + if($exception instanceof SecurityException) { |
|
| 260 | + if($exception instanceof StrictCookieMissingException) { |
|
| 261 | + return new RedirectResponse(\OC::$WEBROOT); |
|
| 262 | + } |
|
| 263 | + if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
| 264 | + $response = new JSONResponse( |
|
| 265 | + array('message' => $exception->getMessage()), |
|
| 266 | + $exception->getCode() |
|
| 267 | + ); |
|
| 268 | + } else { |
|
| 269 | + if($exception instanceof NotLoggedInException) { |
|
| 270 | + $params = []; |
|
| 271 | + if (isset($this->request->server['REQUEST_URI'])) { |
|
| 272 | + $params['redirect_url'] = $this->request->server['REQUEST_URI']; |
|
| 273 | + } |
|
| 274 | + $url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params); |
|
| 275 | + $response = new RedirectResponse($url); |
|
| 276 | + } else { |
|
| 277 | + $response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest'); |
|
| 278 | + $response->setStatus($exception->getCode()); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - $this->logger->debug($exception->getMessage()); |
|
| 283 | - return $response; |
|
| 284 | - } |
|
| 282 | + $this->logger->debug($exception->getMessage()); |
|
| 283 | + return $response; |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - throw $exception; |
|
| 287 | - } |
|
| 286 | + throw $exception; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | 289 | } |
@@ -66,398 +66,398 @@ |
||
| 66 | 66 | |
| 67 | 67 | class DIContainer extends SimpleContainer implements IAppContainer { |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - private $middleWares = array(); |
|
| 73 | - |
|
| 74 | - /** @var ServerContainer */ |
|
| 75 | - private $server; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Put your class dependencies in here |
|
| 79 | - * @param string $appName the name of the app |
|
| 80 | - * @param array $urlParams |
|
| 81 | - * @param ServerContainer|null $server |
|
| 82 | - */ |
|
| 83 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 84 | - parent::__construct(); |
|
| 85 | - $this['AppName'] = $appName; |
|
| 86 | - $this['urlParams'] = $urlParams; |
|
| 87 | - |
|
| 88 | - /** @var \OC\ServerContainer $server */ |
|
| 89 | - if ($server === null) { |
|
| 90 | - $server = \OC::$server; |
|
| 91 | - } |
|
| 92 | - $this->server = $server; |
|
| 93 | - $this->server->registerAppContainer($appName, $this); |
|
| 94 | - |
|
| 95 | - // aliases |
|
| 96 | - $this->registerAlias('appName', 'AppName'); |
|
| 97 | - $this->registerAlias('webRoot', 'WebRoot'); |
|
| 98 | - $this->registerAlias('userId', 'UserId'); |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Core services |
|
| 102 | - */ |
|
| 103 | - $this->registerService(IOutput::class, function($c){ |
|
| 104 | - return new Output($this->getServer()->getWebRoot()); |
|
| 105 | - }); |
|
| 106 | - |
|
| 107 | - $this->registerService(Folder::class, function() { |
|
| 108 | - return $this->getServer()->getUserFolder(); |
|
| 109 | - }); |
|
| 110 | - |
|
| 111 | - $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 112 | - return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 113 | - }); |
|
| 114 | - |
|
| 115 | - $this->registerService(IL10N::class, function($c) { |
|
| 116 | - return $this->getServer()->getL10N($c->query('AppName')); |
|
| 117 | - }); |
|
| 118 | - |
|
| 119 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 120 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 121 | - |
|
| 122 | - $this->registerService(IRequest::class, function() { |
|
| 123 | - return $this->getServer()->query(IRequest::class); |
|
| 124 | - }); |
|
| 125 | - $this->registerAlias('Request', IRequest::class); |
|
| 126 | - |
|
| 127 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 128 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 129 | - |
|
| 130 | - $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
|
| 131 | - |
|
| 132 | - $this->registerService(IServerContainer::class, function ($c) { |
|
| 133 | - return $this->getServer(); |
|
| 134 | - }); |
|
| 135 | - $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 136 | - |
|
| 137 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 138 | - return $c->query('OCA\WorkflowEngine\Manager'); |
|
| 139 | - }); |
|
| 140 | - |
|
| 141 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 142 | - return $c; |
|
| 143 | - }); |
|
| 144 | - |
|
| 145 | - // commonly used attributes |
|
| 146 | - $this->registerService('UserId', function ($c) { |
|
| 147 | - return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
|
| 148 | - }); |
|
| 149 | - |
|
| 150 | - $this->registerService('WebRoot', function ($c) { |
|
| 151 | - return $c->query('ServerContainer')->getWebRoot(); |
|
| 152 | - }); |
|
| 153 | - |
|
| 154 | - $this->registerService('fromMailAddress', function() { |
|
| 155 | - return Util::getDefaultEmailAddress('no-reply'); |
|
| 156 | - }); |
|
| 157 | - |
|
| 158 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 159 | - return $c->getServer()->getThemingDefaults(); |
|
| 160 | - }); |
|
| 161 | - |
|
| 162 | - $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 163 | - return $this->getServer()->getEncryptionManager(); |
|
| 164 | - }); |
|
| 165 | - |
|
| 166 | - $this->registerService(IConfig::class, function ($c) { |
|
| 167 | - return $c->query(OC\GlobalScale\Config::class); |
|
| 168 | - }); |
|
| 169 | - |
|
| 170 | - $this->registerService(IValidator::class, function($c) { |
|
| 171 | - return $c->query(Validator::class); |
|
| 172 | - }); |
|
| 173 | - |
|
| 174 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 175 | - return new \OC\Security\IdentityProof\Manager( |
|
| 176 | - $this->getServer()->query(\OC\Files\AppData\Factory::class), |
|
| 177 | - $this->getServer()->getCrypto(), |
|
| 178 | - $this->getServer()->getConfig() |
|
| 179 | - ); |
|
| 180 | - }); |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * App Framework APIs |
|
| 184 | - */ |
|
| 185 | - $this->registerService('API', function($c){ |
|
| 186 | - $c->query('OCP\\ILogger')->debug( |
|
| 187 | - 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 188 | - 'services instead!' |
|
| 189 | - ); |
|
| 190 | - return new API($c['AppName']); |
|
| 191 | - }); |
|
| 192 | - |
|
| 193 | - $this->registerService('Protocol', function($c){ |
|
| 194 | - /** @var \OC\Server $server */ |
|
| 195 | - $server = $c->query('ServerContainer'); |
|
| 196 | - $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 197 | - return new Http($_SERVER, $protocol); |
|
| 198 | - }); |
|
| 199 | - |
|
| 200 | - $this->registerService('Dispatcher', function($c) { |
|
| 201 | - return new Dispatcher( |
|
| 202 | - $c['Protocol'], |
|
| 203 | - $c['MiddlewareDispatcher'], |
|
| 204 | - $c['ControllerMethodReflector'], |
|
| 205 | - $c['Request'] |
|
| 206 | - ); |
|
| 207 | - }); |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * App Framework default arguments |
|
| 211 | - */ |
|
| 212 | - $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 213 | - $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 214 | - $this->registerParameter('corsMaxAge', 1728000); |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Middleware |
|
| 218 | - */ |
|
| 219 | - $app = $this; |
|
| 220 | - $this->registerService('SecurityMiddleware', function($c) use ($app){ |
|
| 221 | - /** @var \OC\Server $server */ |
|
| 222 | - $server = $app->getServer(); |
|
| 223 | - |
|
| 224 | - return new SecurityMiddleware( |
|
| 225 | - $c['Request'], |
|
| 226 | - $c['ControllerMethodReflector'], |
|
| 227 | - $server->getNavigationManager(), |
|
| 228 | - $server->getURLGenerator(), |
|
| 229 | - $server->getLogger(), |
|
| 230 | - $server->getSession(), |
|
| 231 | - $c['AppName'], |
|
| 232 | - $app->isLoggedIn(), |
|
| 233 | - $app->isAdminUser(), |
|
| 234 | - $server->getContentSecurityPolicyManager(), |
|
| 235 | - $server->getCsrfTokenManager(), |
|
| 236 | - $server->getContentSecurityPolicyNonceManager(), |
|
| 237 | - $server->getAppManager(), |
|
| 238 | - $server->getUserSession() |
|
| 239 | - ); |
|
| 240 | - |
|
| 241 | - }); |
|
| 242 | - |
|
| 243 | - $this->registerService('BruteForceMiddleware', function($c) use ($app) { |
|
| 244 | - /** @var \OC\Server $server */ |
|
| 245 | - $server = $app->getServer(); |
|
| 246 | - |
|
| 247 | - return new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 248 | - $c['ControllerMethodReflector'], |
|
| 249 | - $server->getBruteForceThrottler(), |
|
| 250 | - $server->getRequest() |
|
| 251 | - ); |
|
| 252 | - }); |
|
| 253 | - |
|
| 254 | - $this->registerService('RateLimitingMiddleware', function($c) use ($app) { |
|
| 255 | - /** @var \OC\Server $server */ |
|
| 256 | - $server = $app->getServer(); |
|
| 257 | - |
|
| 258 | - return new RateLimitingMiddleware( |
|
| 259 | - $server->getRequest(), |
|
| 260 | - $server->getUserSession(), |
|
| 261 | - $c['ControllerMethodReflector'], |
|
| 262 | - $c->query(OC\Security\RateLimiting\Limiter::class) |
|
| 263 | - ); |
|
| 264 | - }); |
|
| 265 | - |
|
| 266 | - $this->registerService('CORSMiddleware', function($c) { |
|
| 267 | - return new CORSMiddleware( |
|
| 268 | - $c['Request'], |
|
| 269 | - $c['ControllerMethodReflector'], |
|
| 270 | - $c->query(IUserSession::class), |
|
| 271 | - $c->getServer()->getBruteForceThrottler() |
|
| 272 | - ); |
|
| 273 | - }); |
|
| 274 | - |
|
| 275 | - $this->registerService('SessionMiddleware', function($c) use ($app) { |
|
| 276 | - return new SessionMiddleware( |
|
| 277 | - $c['Request'], |
|
| 278 | - $c['ControllerMethodReflector'], |
|
| 279 | - $app->getServer()->getSession() |
|
| 280 | - ); |
|
| 281 | - }); |
|
| 282 | - |
|
| 283 | - $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 284 | - $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
|
| 285 | - $userSession = $app->getServer()->getUserSession(); |
|
| 286 | - $session = $app->getServer()->getSession(); |
|
| 287 | - $urlGenerator = $app->getServer()->getURLGenerator(); |
|
| 288 | - $reflector = $c['ControllerMethodReflector']; |
|
| 289 | - $request = $app->getServer()->getRequest(); |
|
| 290 | - return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
|
| 291 | - }); |
|
| 292 | - |
|
| 293 | - $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 294 | - return new OCSMiddleware( |
|
| 295 | - $c['Request'] |
|
| 296 | - ); |
|
| 297 | - }); |
|
| 298 | - |
|
| 299 | - $this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) { |
|
| 300 | - return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
| 301 | - $c['Request'], |
|
| 302 | - $c['ControllerMethodReflector'] |
|
| 303 | - ); |
|
| 304 | - }); |
|
| 305 | - |
|
| 306 | - $middleWares = &$this->middleWares; |
|
| 307 | - $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) { |
|
| 308 | - $dispatcher = new MiddlewareDispatcher(); |
|
| 309 | - $dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class]); |
|
| 310 | - $dispatcher->registerMiddleware($c['CORSMiddleware']); |
|
| 311 | - $dispatcher->registerMiddleware($c['OCSMiddleware']); |
|
| 312 | - $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
|
| 313 | - $dispatcher->registerMiddleware($c['TwoFactorMiddleware']); |
|
| 314 | - $dispatcher->registerMiddleware($c['BruteForceMiddleware']); |
|
| 315 | - $dispatcher->registerMiddleware($c['RateLimitingMiddleware']); |
|
| 316 | - |
|
| 317 | - foreach($middleWares as $middleWare) { |
|
| 318 | - $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - $dispatcher->registerMiddleware($c['SessionMiddleware']); |
|
| 322 | - return $dispatcher; |
|
| 323 | - }); |
|
| 324 | - |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @deprecated implements only deprecated methods |
|
| 330 | - * @return IApi |
|
| 331 | - */ |
|
| 332 | - public function getCoreApi() |
|
| 333 | - { |
|
| 334 | - return $this->query('API'); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * @return \OCP\IServerContainer |
|
| 339 | - */ |
|
| 340 | - public function getServer() |
|
| 341 | - { |
|
| 342 | - return $this->server; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * @param string $middleWare |
|
| 347 | - * @return boolean|null |
|
| 348 | - */ |
|
| 349 | - public function registerMiddleWare($middleWare) { |
|
| 350 | - array_push($this->middleWares, $middleWare); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * used to return the appname of the set application |
|
| 355 | - * @return string the name of your application |
|
| 356 | - */ |
|
| 357 | - public function getAppName() { |
|
| 358 | - return $this->query('AppName'); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * @deprecated use IUserSession->isLoggedIn() |
|
| 363 | - * @return boolean |
|
| 364 | - */ |
|
| 365 | - public function isLoggedIn() { |
|
| 366 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @deprecated use IGroupManager->isAdmin($userId) |
|
| 371 | - * @return boolean |
|
| 372 | - */ |
|
| 373 | - public function isAdminUser() { |
|
| 374 | - $uid = $this->getUserId(); |
|
| 375 | - return \OC_User::isAdminUser($uid); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - private function getUserId() { |
|
| 379 | - return $this->getServer()->getSession()->get('user_id'); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * @deprecated use the ILogger instead |
|
| 384 | - * @param string $message |
|
| 385 | - * @param string $level |
|
| 386 | - * @return mixed |
|
| 387 | - */ |
|
| 388 | - public function log($message, $level) { |
|
| 389 | - switch($level){ |
|
| 390 | - case 'debug': |
|
| 391 | - $level = \OCP\Util::DEBUG; |
|
| 392 | - break; |
|
| 393 | - case 'info': |
|
| 394 | - $level = \OCP\Util::INFO; |
|
| 395 | - break; |
|
| 396 | - case 'warn': |
|
| 397 | - $level = \OCP\Util::WARN; |
|
| 398 | - break; |
|
| 399 | - case 'fatal': |
|
| 400 | - $level = \OCP\Util::FATAL; |
|
| 401 | - break; |
|
| 402 | - default: |
|
| 403 | - $level = \OCP\Util::ERROR; |
|
| 404 | - break; |
|
| 405 | - } |
|
| 406 | - \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Register a capability |
|
| 411 | - * |
|
| 412 | - * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 413 | - */ |
|
| 414 | - public function registerCapability($serviceName) { |
|
| 415 | - $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 416 | - return $this->query($serviceName); |
|
| 417 | - }); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * @param string $name |
|
| 422 | - * @return mixed |
|
| 423 | - * @throws QueryException if the query could not be resolved |
|
| 424 | - */ |
|
| 425 | - public function query($name) { |
|
| 426 | - try { |
|
| 427 | - return $this->queryNoFallback($name); |
|
| 428 | - } catch (QueryException $firstException) { |
|
| 429 | - try { |
|
| 430 | - return $this->getServer()->query($name); |
|
| 431 | - } catch (QueryException $secondException) { |
|
| 432 | - if ($firstException->getCode() === 1) { |
|
| 433 | - throw $secondException; |
|
| 434 | - } |
|
| 435 | - throw $firstException; |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * @param string $name |
|
| 442 | - * @return mixed |
|
| 443 | - * @throws QueryException if the query could not be resolved |
|
| 444 | - */ |
|
| 445 | - public function queryNoFallback($name) { |
|
| 446 | - $name = $this->sanitizeName($name); |
|
| 447 | - |
|
| 448 | - if ($this->offsetExists($name)) { |
|
| 449 | - return parent::query($name); |
|
| 450 | - } else { |
|
| 451 | - if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 452 | - return parent::query($name); |
|
| 453 | - } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 454 | - return parent::query($name); |
|
| 455 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 456 | - return parent::query($name); |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 461 | - ' Class can not be instantiated', 1); |
|
| 462 | - } |
|
| 69 | + /** |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + private $middleWares = array(); |
|
| 73 | + |
|
| 74 | + /** @var ServerContainer */ |
|
| 75 | + private $server; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Put your class dependencies in here |
|
| 79 | + * @param string $appName the name of the app |
|
| 80 | + * @param array $urlParams |
|
| 81 | + * @param ServerContainer|null $server |
|
| 82 | + */ |
|
| 83 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 84 | + parent::__construct(); |
|
| 85 | + $this['AppName'] = $appName; |
|
| 86 | + $this['urlParams'] = $urlParams; |
|
| 87 | + |
|
| 88 | + /** @var \OC\ServerContainer $server */ |
|
| 89 | + if ($server === null) { |
|
| 90 | + $server = \OC::$server; |
|
| 91 | + } |
|
| 92 | + $this->server = $server; |
|
| 93 | + $this->server->registerAppContainer($appName, $this); |
|
| 94 | + |
|
| 95 | + // aliases |
|
| 96 | + $this->registerAlias('appName', 'AppName'); |
|
| 97 | + $this->registerAlias('webRoot', 'WebRoot'); |
|
| 98 | + $this->registerAlias('userId', 'UserId'); |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Core services |
|
| 102 | + */ |
|
| 103 | + $this->registerService(IOutput::class, function($c){ |
|
| 104 | + return new Output($this->getServer()->getWebRoot()); |
|
| 105 | + }); |
|
| 106 | + |
|
| 107 | + $this->registerService(Folder::class, function() { |
|
| 108 | + return $this->getServer()->getUserFolder(); |
|
| 109 | + }); |
|
| 110 | + |
|
| 111 | + $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 112 | + return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 113 | + }); |
|
| 114 | + |
|
| 115 | + $this->registerService(IL10N::class, function($c) { |
|
| 116 | + return $this->getServer()->getL10N($c->query('AppName')); |
|
| 117 | + }); |
|
| 118 | + |
|
| 119 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 120 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 121 | + |
|
| 122 | + $this->registerService(IRequest::class, function() { |
|
| 123 | + return $this->getServer()->query(IRequest::class); |
|
| 124 | + }); |
|
| 125 | + $this->registerAlias('Request', IRequest::class); |
|
| 126 | + |
|
| 127 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 128 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 129 | + |
|
| 130 | + $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
|
| 131 | + |
|
| 132 | + $this->registerService(IServerContainer::class, function ($c) { |
|
| 133 | + return $this->getServer(); |
|
| 134 | + }); |
|
| 135 | + $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 136 | + |
|
| 137 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 138 | + return $c->query('OCA\WorkflowEngine\Manager'); |
|
| 139 | + }); |
|
| 140 | + |
|
| 141 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 142 | + return $c; |
|
| 143 | + }); |
|
| 144 | + |
|
| 145 | + // commonly used attributes |
|
| 146 | + $this->registerService('UserId', function ($c) { |
|
| 147 | + return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
|
| 148 | + }); |
|
| 149 | + |
|
| 150 | + $this->registerService('WebRoot', function ($c) { |
|
| 151 | + return $c->query('ServerContainer')->getWebRoot(); |
|
| 152 | + }); |
|
| 153 | + |
|
| 154 | + $this->registerService('fromMailAddress', function() { |
|
| 155 | + return Util::getDefaultEmailAddress('no-reply'); |
|
| 156 | + }); |
|
| 157 | + |
|
| 158 | + $this->registerService('OC_Defaults', function ($c) { |
|
| 159 | + return $c->getServer()->getThemingDefaults(); |
|
| 160 | + }); |
|
| 161 | + |
|
| 162 | + $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 163 | + return $this->getServer()->getEncryptionManager(); |
|
| 164 | + }); |
|
| 165 | + |
|
| 166 | + $this->registerService(IConfig::class, function ($c) { |
|
| 167 | + return $c->query(OC\GlobalScale\Config::class); |
|
| 168 | + }); |
|
| 169 | + |
|
| 170 | + $this->registerService(IValidator::class, function($c) { |
|
| 171 | + return $c->query(Validator::class); |
|
| 172 | + }); |
|
| 173 | + |
|
| 174 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 175 | + return new \OC\Security\IdentityProof\Manager( |
|
| 176 | + $this->getServer()->query(\OC\Files\AppData\Factory::class), |
|
| 177 | + $this->getServer()->getCrypto(), |
|
| 178 | + $this->getServer()->getConfig() |
|
| 179 | + ); |
|
| 180 | + }); |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * App Framework APIs |
|
| 184 | + */ |
|
| 185 | + $this->registerService('API', function($c){ |
|
| 186 | + $c->query('OCP\\ILogger')->debug( |
|
| 187 | + 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 188 | + 'services instead!' |
|
| 189 | + ); |
|
| 190 | + return new API($c['AppName']); |
|
| 191 | + }); |
|
| 192 | + |
|
| 193 | + $this->registerService('Protocol', function($c){ |
|
| 194 | + /** @var \OC\Server $server */ |
|
| 195 | + $server = $c->query('ServerContainer'); |
|
| 196 | + $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 197 | + return new Http($_SERVER, $protocol); |
|
| 198 | + }); |
|
| 199 | + |
|
| 200 | + $this->registerService('Dispatcher', function($c) { |
|
| 201 | + return new Dispatcher( |
|
| 202 | + $c['Protocol'], |
|
| 203 | + $c['MiddlewareDispatcher'], |
|
| 204 | + $c['ControllerMethodReflector'], |
|
| 205 | + $c['Request'] |
|
| 206 | + ); |
|
| 207 | + }); |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * App Framework default arguments |
|
| 211 | + */ |
|
| 212 | + $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 213 | + $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 214 | + $this->registerParameter('corsMaxAge', 1728000); |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Middleware |
|
| 218 | + */ |
|
| 219 | + $app = $this; |
|
| 220 | + $this->registerService('SecurityMiddleware', function($c) use ($app){ |
|
| 221 | + /** @var \OC\Server $server */ |
|
| 222 | + $server = $app->getServer(); |
|
| 223 | + |
|
| 224 | + return new SecurityMiddleware( |
|
| 225 | + $c['Request'], |
|
| 226 | + $c['ControllerMethodReflector'], |
|
| 227 | + $server->getNavigationManager(), |
|
| 228 | + $server->getURLGenerator(), |
|
| 229 | + $server->getLogger(), |
|
| 230 | + $server->getSession(), |
|
| 231 | + $c['AppName'], |
|
| 232 | + $app->isLoggedIn(), |
|
| 233 | + $app->isAdminUser(), |
|
| 234 | + $server->getContentSecurityPolicyManager(), |
|
| 235 | + $server->getCsrfTokenManager(), |
|
| 236 | + $server->getContentSecurityPolicyNonceManager(), |
|
| 237 | + $server->getAppManager(), |
|
| 238 | + $server->getUserSession() |
|
| 239 | + ); |
|
| 240 | + |
|
| 241 | + }); |
|
| 242 | + |
|
| 243 | + $this->registerService('BruteForceMiddleware', function($c) use ($app) { |
|
| 244 | + /** @var \OC\Server $server */ |
|
| 245 | + $server = $app->getServer(); |
|
| 246 | + |
|
| 247 | + return new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 248 | + $c['ControllerMethodReflector'], |
|
| 249 | + $server->getBruteForceThrottler(), |
|
| 250 | + $server->getRequest() |
|
| 251 | + ); |
|
| 252 | + }); |
|
| 253 | + |
|
| 254 | + $this->registerService('RateLimitingMiddleware', function($c) use ($app) { |
|
| 255 | + /** @var \OC\Server $server */ |
|
| 256 | + $server = $app->getServer(); |
|
| 257 | + |
|
| 258 | + return new RateLimitingMiddleware( |
|
| 259 | + $server->getRequest(), |
|
| 260 | + $server->getUserSession(), |
|
| 261 | + $c['ControllerMethodReflector'], |
|
| 262 | + $c->query(OC\Security\RateLimiting\Limiter::class) |
|
| 263 | + ); |
|
| 264 | + }); |
|
| 265 | + |
|
| 266 | + $this->registerService('CORSMiddleware', function($c) { |
|
| 267 | + return new CORSMiddleware( |
|
| 268 | + $c['Request'], |
|
| 269 | + $c['ControllerMethodReflector'], |
|
| 270 | + $c->query(IUserSession::class), |
|
| 271 | + $c->getServer()->getBruteForceThrottler() |
|
| 272 | + ); |
|
| 273 | + }); |
|
| 274 | + |
|
| 275 | + $this->registerService('SessionMiddleware', function($c) use ($app) { |
|
| 276 | + return new SessionMiddleware( |
|
| 277 | + $c['Request'], |
|
| 278 | + $c['ControllerMethodReflector'], |
|
| 279 | + $app->getServer()->getSession() |
|
| 280 | + ); |
|
| 281 | + }); |
|
| 282 | + |
|
| 283 | + $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 284 | + $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
|
| 285 | + $userSession = $app->getServer()->getUserSession(); |
|
| 286 | + $session = $app->getServer()->getSession(); |
|
| 287 | + $urlGenerator = $app->getServer()->getURLGenerator(); |
|
| 288 | + $reflector = $c['ControllerMethodReflector']; |
|
| 289 | + $request = $app->getServer()->getRequest(); |
|
| 290 | + return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
|
| 291 | + }); |
|
| 292 | + |
|
| 293 | + $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 294 | + return new OCSMiddleware( |
|
| 295 | + $c['Request'] |
|
| 296 | + ); |
|
| 297 | + }); |
|
| 298 | + |
|
| 299 | + $this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) { |
|
| 300 | + return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
| 301 | + $c['Request'], |
|
| 302 | + $c['ControllerMethodReflector'] |
|
| 303 | + ); |
|
| 304 | + }); |
|
| 305 | + |
|
| 306 | + $middleWares = &$this->middleWares; |
|
| 307 | + $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) { |
|
| 308 | + $dispatcher = new MiddlewareDispatcher(); |
|
| 309 | + $dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class]); |
|
| 310 | + $dispatcher->registerMiddleware($c['CORSMiddleware']); |
|
| 311 | + $dispatcher->registerMiddleware($c['OCSMiddleware']); |
|
| 312 | + $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
|
| 313 | + $dispatcher->registerMiddleware($c['TwoFactorMiddleware']); |
|
| 314 | + $dispatcher->registerMiddleware($c['BruteForceMiddleware']); |
|
| 315 | + $dispatcher->registerMiddleware($c['RateLimitingMiddleware']); |
|
| 316 | + |
|
| 317 | + foreach($middleWares as $middleWare) { |
|
| 318 | + $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + $dispatcher->registerMiddleware($c['SessionMiddleware']); |
|
| 322 | + return $dispatcher; |
|
| 323 | + }); |
|
| 324 | + |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @deprecated implements only deprecated methods |
|
| 330 | + * @return IApi |
|
| 331 | + */ |
|
| 332 | + public function getCoreApi() |
|
| 333 | + { |
|
| 334 | + return $this->query('API'); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * @return \OCP\IServerContainer |
|
| 339 | + */ |
|
| 340 | + public function getServer() |
|
| 341 | + { |
|
| 342 | + return $this->server; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * @param string $middleWare |
|
| 347 | + * @return boolean|null |
|
| 348 | + */ |
|
| 349 | + public function registerMiddleWare($middleWare) { |
|
| 350 | + array_push($this->middleWares, $middleWare); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * used to return the appname of the set application |
|
| 355 | + * @return string the name of your application |
|
| 356 | + */ |
|
| 357 | + public function getAppName() { |
|
| 358 | + return $this->query('AppName'); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * @deprecated use IUserSession->isLoggedIn() |
|
| 363 | + * @return boolean |
|
| 364 | + */ |
|
| 365 | + public function isLoggedIn() { |
|
| 366 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @deprecated use IGroupManager->isAdmin($userId) |
|
| 371 | + * @return boolean |
|
| 372 | + */ |
|
| 373 | + public function isAdminUser() { |
|
| 374 | + $uid = $this->getUserId(); |
|
| 375 | + return \OC_User::isAdminUser($uid); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + private function getUserId() { |
|
| 379 | + return $this->getServer()->getSession()->get('user_id'); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * @deprecated use the ILogger instead |
|
| 384 | + * @param string $message |
|
| 385 | + * @param string $level |
|
| 386 | + * @return mixed |
|
| 387 | + */ |
|
| 388 | + public function log($message, $level) { |
|
| 389 | + switch($level){ |
|
| 390 | + case 'debug': |
|
| 391 | + $level = \OCP\Util::DEBUG; |
|
| 392 | + break; |
|
| 393 | + case 'info': |
|
| 394 | + $level = \OCP\Util::INFO; |
|
| 395 | + break; |
|
| 396 | + case 'warn': |
|
| 397 | + $level = \OCP\Util::WARN; |
|
| 398 | + break; |
|
| 399 | + case 'fatal': |
|
| 400 | + $level = \OCP\Util::FATAL; |
|
| 401 | + break; |
|
| 402 | + default: |
|
| 403 | + $level = \OCP\Util::ERROR; |
|
| 404 | + break; |
|
| 405 | + } |
|
| 406 | + \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Register a capability |
|
| 411 | + * |
|
| 412 | + * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 413 | + */ |
|
| 414 | + public function registerCapability($serviceName) { |
|
| 415 | + $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 416 | + return $this->query($serviceName); |
|
| 417 | + }); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * @param string $name |
|
| 422 | + * @return mixed |
|
| 423 | + * @throws QueryException if the query could not be resolved |
|
| 424 | + */ |
|
| 425 | + public function query($name) { |
|
| 426 | + try { |
|
| 427 | + return $this->queryNoFallback($name); |
|
| 428 | + } catch (QueryException $firstException) { |
|
| 429 | + try { |
|
| 430 | + return $this->getServer()->query($name); |
|
| 431 | + } catch (QueryException $secondException) { |
|
| 432 | + if ($firstException->getCode() === 1) { |
|
| 433 | + throw $secondException; |
|
| 434 | + } |
|
| 435 | + throw $firstException; |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * @param string $name |
|
| 442 | + * @return mixed |
|
| 443 | + * @throws QueryException if the query could not be resolved |
|
| 444 | + */ |
|
| 445 | + public function queryNoFallback($name) { |
|
| 446 | + $name = $this->sanitizeName($name); |
|
| 447 | + |
|
| 448 | + if ($this->offsetExists($name)) { |
|
| 449 | + return parent::query($name); |
|
| 450 | + } else { |
|
| 451 | + if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 452 | + return parent::query($name); |
|
| 453 | + } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 454 | + return parent::query($name); |
|
| 455 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 456 | + return parent::query($name); |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 461 | + ' Class can not be instantiated', 1); |
|
| 462 | + } |
|
| 463 | 463 | } |