@@ -412,7 +412,7 @@ |
||
| 412 | 412 | $appDir = OC_App::getInstallPath() . '/' . $appId; |
| 413 | 413 | OC_Helper::rmdirr($appDir); |
| 414 | 414 | return true; |
| 415 | - }else{ |
|
| 415 | + } else{ |
|
| 416 | 416 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
| 417 | 417 | |
| 418 | 418 | return false; |
@@ -36,17 +36,12 @@ |
||
| 36 | 36 | namespace OC; |
| 37 | 37 | |
| 38 | 38 | use Doctrine\DBAL\Exception\TableExistsException; |
| 39 | -use OC\App\AppManager; |
|
| 40 | 39 | use OC\App\AppStore\Bundles\Bundle; |
| 41 | 40 | use OC\App\AppStore\Fetcher\AppFetcher; |
| 42 | -use OC\App\CodeChecker\CodeChecker; |
|
| 43 | -use OC\App\CodeChecker\EmptyCheck; |
|
| 44 | -use OC\App\CodeChecker\PrivateCheck; |
|
| 45 | 41 | use OC\Archive\TAR; |
| 46 | 42 | use OC_App; |
| 47 | 43 | use OC_DB; |
| 48 | 44 | use OC_Helper; |
| 49 | -use OCP\App\IAppManager; |
|
| 50 | 45 | use OCP\Http\Client\IClientService; |
| 51 | 46 | use OCP\IConfig; |
| 52 | 47 | use OCP\ILogger; |
@@ -420,7 +420,7 @@ |
||
| 420 | 420 | |
| 421 | 421 | /** |
| 422 | 422 | * Check if app has been installed from git |
| 423 | - * @param string $name name of the application to remove |
|
| 423 | + * @param string $appId |
|
| 424 | 424 | * @return boolean |
| 425 | 425 | * |
| 426 | 426 | * The function will check if the path contains a .git folder |
@@ -57,564 +57,564 @@ |
||
| 57 | 57 | * This class provides the functionality needed to install, update and remove apps |
| 58 | 58 | */ |
| 59 | 59 | class Installer { |
| 60 | - /** @var AppFetcher */ |
|
| 61 | - private $appFetcher; |
|
| 62 | - /** @var IClientService */ |
|
| 63 | - private $clientService; |
|
| 64 | - /** @var ITempManager */ |
|
| 65 | - private $tempManager; |
|
| 66 | - /** @var ILogger */ |
|
| 67 | - private $logger; |
|
| 68 | - /** @var IConfig */ |
|
| 69 | - private $config; |
|
| 70 | - /** @var array - for caching the result of app fetcher */ |
|
| 71 | - private $apps = null; |
|
| 72 | - /** @var bool|null - for caching the result of the ready status */ |
|
| 73 | - private $isInstanceReadyForUpdates = null; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param AppFetcher $appFetcher |
|
| 77 | - * @param IClientService $clientService |
|
| 78 | - * @param ITempManager $tempManager |
|
| 79 | - * @param ILogger $logger |
|
| 80 | - * @param IConfig $config |
|
| 81 | - */ |
|
| 82 | - public function __construct(AppFetcher $appFetcher, |
|
| 83 | - IClientService $clientService, |
|
| 84 | - ITempManager $tempManager, |
|
| 85 | - ILogger $logger, |
|
| 86 | - IConfig $config) { |
|
| 87 | - $this->appFetcher = $appFetcher; |
|
| 88 | - $this->clientService = $clientService; |
|
| 89 | - $this->tempManager = $tempManager; |
|
| 90 | - $this->logger = $logger; |
|
| 91 | - $this->config = $config; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Installs an app that is located in one of the app folders already |
|
| 96 | - * |
|
| 97 | - * @param string $appId App to install |
|
| 98 | - * @throws \Exception |
|
| 99 | - * @return string app ID |
|
| 100 | - */ |
|
| 101 | - public function installApp($appId) { |
|
| 102 | - $app = \OC_App::findAppInDirectories($appId); |
|
| 103 | - if($app === false) { |
|
| 104 | - throw new \Exception('App not found in any app directory'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $basedir = $app['path'].'/'.$appId; |
|
| 108 | - $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
| 109 | - |
|
| 110 | - $l = \OC::$server->getL10N('core'); |
|
| 111 | - |
|
| 112 | - if(!is_array($info)) { |
|
| 113 | - throw new \Exception( |
|
| 114 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 115 | - [$appId] |
|
| 116 | - ) |
|
| 117 | - ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $version = \OCP\Util::getVersion(); |
|
| 121 | - if (!\OC_App::isAppCompatible($version, $info)) { |
|
| 122 | - throw new \Exception( |
|
| 123 | - // TODO $l |
|
| 124 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 125 | - [$info['name']] |
|
| 126 | - ) |
|
| 127 | - ); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // check for required dependencies |
|
| 131 | - \OC_App::checkAppDependencies($this->config, $l, $info); |
|
| 132 | - \OC_App::registerAutoloading($appId, $basedir); |
|
| 133 | - |
|
| 134 | - //install the database |
|
| 135 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
| 136 | - if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
|
| 137 | - OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 138 | - } else { |
|
| 139 | - OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 140 | - } |
|
| 141 | - } else { |
|
| 142 | - $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
| 143 | - $ms->migrate(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 147 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 148 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - //run appinfo/install.php |
|
| 152 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 153 | - |
|
| 154 | - $appData = OC_App::getAppInfo($appId); |
|
| 155 | - OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
| 156 | - |
|
| 157 | - //set the installed version |
|
| 158 | - \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
| 159 | - \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
| 160 | - |
|
| 161 | - //set remote/public handlers |
|
| 162 | - foreach($info['remote'] as $name=>$path) { |
|
| 163 | - \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
| 164 | - } |
|
| 165 | - foreach($info['public'] as $name=>$path) { |
|
| 166 | - \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - OC_App::setAppTypes($info['id']); |
|
| 170 | - |
|
| 171 | - return $info['id']; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @brief checks whether or not an app is installed |
|
| 176 | - * @param string $app app |
|
| 177 | - * @returns bool |
|
| 178 | - * |
|
| 179 | - * Checks whether or not an app is installed, i.e. registered in apps table. |
|
| 180 | - */ |
|
| 181 | - public static function isInstalled( $app ) { |
|
| 182 | - return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Updates the specified app from the appstore |
|
| 187 | - * |
|
| 188 | - * @param string $appId |
|
| 189 | - * @return bool |
|
| 190 | - */ |
|
| 191 | - public function updateAppstoreApp($appId) { |
|
| 192 | - if($this->isUpdateAvailable($appId)) { |
|
| 193 | - try { |
|
| 194 | - $this->downloadApp($appId); |
|
| 195 | - } catch (\Exception $e) { |
|
| 196 | - $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
| 197 | - return false; |
|
| 198 | - } |
|
| 199 | - return OC_App::updateApp($appId); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Downloads an app and puts it into the app directory |
|
| 207 | - * |
|
| 208 | - * @param string $appId |
|
| 209 | - * |
|
| 210 | - * @throws \Exception If the installation was not successful |
|
| 211 | - */ |
|
| 212 | - public function downloadApp($appId) { |
|
| 213 | - $appId = strtolower($appId); |
|
| 214 | - |
|
| 215 | - $apps = $this->appFetcher->get(); |
|
| 216 | - foreach($apps as $app) { |
|
| 217 | - if($app['id'] === $appId) { |
|
| 218 | - // Load the certificate |
|
| 219 | - $certificate = new X509(); |
|
| 220 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 221 | - $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
| 222 | - |
|
| 223 | - // Verify if the certificate has been revoked |
|
| 224 | - $crl = new X509(); |
|
| 225 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 226 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 227 | - if($crl->validateSignature() !== true) { |
|
| 228 | - throw new \Exception('Could not validate CRL signature'); |
|
| 229 | - } |
|
| 230 | - $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
| 231 | - $revoked = $crl->getRevoked($csn); |
|
| 232 | - if ($revoked !== false) { |
|
| 233 | - throw new \Exception( |
|
| 234 | - sprintf( |
|
| 235 | - 'Certificate "%s" has been revoked', |
|
| 236 | - $csn |
|
| 237 | - ) |
|
| 238 | - ); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
| 242 | - if($certificate->validateSignature() !== true) { |
|
| 243 | - throw new \Exception( |
|
| 244 | - sprintf( |
|
| 245 | - 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
| 246 | - $appId |
|
| 247 | - ) |
|
| 248 | - ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // Verify if the certificate is issued for the requested app id |
|
| 252 | - $certInfo = openssl_x509_parse($app['certificate']); |
|
| 253 | - if(!isset($certInfo['subject']['CN'])) { |
|
| 254 | - throw new \Exception( |
|
| 255 | - sprintf( |
|
| 256 | - 'App with id %s has a cert with no CN', |
|
| 257 | - $appId |
|
| 258 | - ) |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - if($certInfo['subject']['CN'] !== $appId) { |
|
| 262 | - throw new \Exception( |
|
| 263 | - sprintf( |
|
| 264 | - 'App with id %s has a cert issued to %s', |
|
| 265 | - $appId, |
|
| 266 | - $certInfo['subject']['CN'] |
|
| 267 | - ) |
|
| 268 | - ); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Download the release |
|
| 272 | - $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
| 273 | - $client = $this->clientService->newClient(); |
|
| 274 | - $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
| 275 | - |
|
| 276 | - // Check if the signature actually matches the downloaded content |
|
| 277 | - $certificate = openssl_get_publickey($app['certificate']); |
|
| 278 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 279 | - openssl_free_key($certificate); |
|
| 280 | - |
|
| 281 | - if($verified === true) { |
|
| 282 | - // Seems to match, let's proceed |
|
| 283 | - $extractDir = $this->tempManager->getTemporaryFolder(); |
|
| 284 | - $archive = new TAR($tempFile); |
|
| 285 | - |
|
| 286 | - if($archive) { |
|
| 287 | - if (!$archive->extract($extractDir)) { |
|
| 288 | - throw new \Exception( |
|
| 289 | - sprintf( |
|
| 290 | - 'Could not extract app %s', |
|
| 291 | - $appId |
|
| 292 | - ) |
|
| 293 | - ); |
|
| 294 | - } |
|
| 295 | - $allFiles = scandir($extractDir); |
|
| 296 | - $folders = array_diff($allFiles, ['.', '..']); |
|
| 297 | - $folders = array_values($folders); |
|
| 298 | - |
|
| 299 | - if(count($folders) > 1) { |
|
| 300 | - throw new \Exception( |
|
| 301 | - sprintf( |
|
| 302 | - 'Extracted app %s has more than 1 folder', |
|
| 303 | - $appId |
|
| 304 | - ) |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - // Check if appinfo/info.xml has the same app ID as well |
|
| 309 | - $loadEntities = libxml_disable_entity_loader(false); |
|
| 310 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 311 | - libxml_disable_entity_loader($loadEntities); |
|
| 312 | - if((string)$xml->id !== $appId) { |
|
| 313 | - throw new \Exception( |
|
| 314 | - sprintf( |
|
| 315 | - 'App for id %s has a wrong app ID in info.xml: %s', |
|
| 316 | - $appId, |
|
| 317 | - (string)$xml->id |
|
| 318 | - ) |
|
| 319 | - ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // Check if the version is lower than before |
|
| 323 | - $currentVersion = OC_App::getAppVersion($appId); |
|
| 324 | - $newVersion = (string)$xml->version; |
|
| 325 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
| 326 | - throw new \Exception( |
|
| 327 | - sprintf( |
|
| 328 | - 'App for id %s has version %s and tried to update to lower version %s', |
|
| 329 | - $appId, |
|
| 330 | - $currentVersion, |
|
| 331 | - $newVersion |
|
| 332 | - ) |
|
| 333 | - ); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 337 | - // Remove old app with the ID if existent |
|
| 338 | - OC_Helper::rmdirr($baseDir); |
|
| 339 | - // Move to app folder |
|
| 340 | - if(@mkdir($baseDir)) { |
|
| 341 | - $extractDir .= '/' . $folders[0]; |
|
| 342 | - OC_Helper::copyr($extractDir, $baseDir); |
|
| 343 | - } |
|
| 344 | - OC_Helper::copyr($extractDir, $baseDir); |
|
| 345 | - OC_Helper::rmdirr($extractDir); |
|
| 346 | - return; |
|
| 347 | - } else { |
|
| 348 | - throw new \Exception( |
|
| 349 | - sprintf( |
|
| 350 | - 'Could not extract app with ID %s to %s', |
|
| 351 | - $appId, |
|
| 352 | - $extractDir |
|
| 353 | - ) |
|
| 354 | - ); |
|
| 355 | - } |
|
| 356 | - } else { |
|
| 357 | - // Signature does not match |
|
| 358 | - throw new \Exception( |
|
| 359 | - sprintf( |
|
| 360 | - 'App with id %s has invalid signature', |
|
| 361 | - $appId |
|
| 362 | - ) |
|
| 363 | - ); |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - throw new \Exception( |
|
| 369 | - sprintf( |
|
| 370 | - 'Could not download app %s', |
|
| 371 | - $appId |
|
| 372 | - ) |
|
| 373 | - ); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Check if an update for the app is available |
|
| 378 | - * |
|
| 379 | - * @param string $appId |
|
| 380 | - * @return string|false false or the version number of the update |
|
| 381 | - */ |
|
| 382 | - public function isUpdateAvailable($appId) { |
|
| 383 | - if ($this->isInstanceReadyForUpdates === null) { |
|
| 384 | - $installPath = OC_App::getInstallPath(); |
|
| 385 | - if ($installPath === false || $installPath === null) { |
|
| 386 | - $this->isInstanceReadyForUpdates = false; |
|
| 387 | - } else { |
|
| 388 | - $this->isInstanceReadyForUpdates = true; |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - if ($this->isInstanceReadyForUpdates === false) { |
|
| 393 | - return false; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if ($this->isInstalledFromGit($appId) === true) { |
|
| 397 | - return false; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - if ($this->apps === null) { |
|
| 401 | - $this->apps = $this->appFetcher->get(); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - foreach($this->apps as $app) { |
|
| 405 | - if($app['id'] === $appId) { |
|
| 406 | - $currentVersion = OC_App::getAppVersion($appId); |
|
| 407 | - $newestVersion = $app['releases'][0]['version']; |
|
| 408 | - if (version_compare($newestVersion, $currentVersion, '>')) { |
|
| 409 | - return $newestVersion; |
|
| 410 | - } else { |
|
| 411 | - return false; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - return false; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Check if app has been installed from git |
|
| 421 | - * @param string $name name of the application to remove |
|
| 422 | - * @return boolean |
|
| 423 | - * |
|
| 424 | - * The function will check if the path contains a .git folder |
|
| 425 | - */ |
|
| 426 | - private function isInstalledFromGit($appId) { |
|
| 427 | - $app = \OC_App::findAppInDirectories($appId); |
|
| 428 | - if($app === false) { |
|
| 429 | - return false; |
|
| 430 | - } |
|
| 431 | - $basedir = $app['path'].'/'.$appId; |
|
| 432 | - return file_exists($basedir.'/.git/'); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Check if app is already downloaded |
|
| 437 | - * @param string $name name of the application to remove |
|
| 438 | - * @return boolean |
|
| 439 | - * |
|
| 440 | - * The function will check if the app is already downloaded in the apps repository |
|
| 441 | - */ |
|
| 442 | - public function isDownloaded($name) { |
|
| 443 | - foreach(\OC::$APPSROOTS as $dir) { |
|
| 444 | - $dirToTest = $dir['path']; |
|
| 445 | - $dirToTest .= '/'; |
|
| 446 | - $dirToTest .= $name; |
|
| 447 | - $dirToTest .= '/'; |
|
| 448 | - |
|
| 449 | - if (is_dir($dirToTest)) { |
|
| 450 | - return true; |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - return false; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Removes an app |
|
| 459 | - * @param string $appId ID of the application to remove |
|
| 460 | - * @return boolean |
|
| 461 | - * |
|
| 462 | - * |
|
| 463 | - * This function works as follows |
|
| 464 | - * -# call uninstall repair steps |
|
| 465 | - * -# removing the files |
|
| 466 | - * |
|
| 467 | - * The function will not delete preferences, tables and the configuration, |
|
| 468 | - * this has to be done by the function oc_app_uninstall(). |
|
| 469 | - */ |
|
| 470 | - public function removeApp($appId) { |
|
| 471 | - if($this->isDownloaded( $appId )) { |
|
| 472 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 473 | - OC_Helper::rmdirr($appDir); |
|
| 474 | - return true; |
|
| 475 | - }else{ |
|
| 476 | - \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
| 477 | - |
|
| 478 | - return false; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Installs the app within the bundle and marks the bundle as installed |
|
| 485 | - * |
|
| 486 | - * @param Bundle $bundle |
|
| 487 | - * @throws \Exception If app could not get installed |
|
| 488 | - */ |
|
| 489 | - public function installAppBundle(Bundle $bundle) { |
|
| 490 | - $appIds = $bundle->getAppIdentifiers(); |
|
| 491 | - foreach($appIds as $appId) { |
|
| 492 | - if(!$this->isDownloaded($appId)) { |
|
| 493 | - $this->downloadApp($appId); |
|
| 494 | - } |
|
| 495 | - $this->installApp($appId); |
|
| 496 | - $app = new OC_App(); |
|
| 497 | - $app->enable($appId); |
|
| 498 | - } |
|
| 499 | - $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
| 500 | - $bundles[] = $bundle->getIdentifier(); |
|
| 501 | - $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * Installs shipped apps |
|
| 506 | - * |
|
| 507 | - * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
| 508 | - * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
| 509 | - * working ownCloud at the end instead of an aborted update. |
|
| 510 | - * @return array Array of error messages (appid => Exception) |
|
| 511 | - */ |
|
| 512 | - public static function installShippedApps($softErrors = false) { |
|
| 513 | - $errors = []; |
|
| 514 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
| 515 | - if($dir = opendir( $app_dir['path'] )) { |
|
| 516 | - while( false !== ( $filename = readdir( $dir ))) { |
|
| 517 | - if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
| 518 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
| 519 | - if(!Installer::isInstalled($filename)) { |
|
| 520 | - $info=OC_App::getAppInfo($filename); |
|
| 521 | - $enabled = isset($info['default_enable']); |
|
| 522 | - if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
| 523 | - && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
| 524 | - if ($softErrors) { |
|
| 525 | - try { |
|
| 526 | - Installer::installShippedApp($filename); |
|
| 527 | - } catch (HintException $e) { |
|
| 528 | - if ($e->getPrevious() instanceof TableExistsException) { |
|
| 529 | - $errors[$filename] = $e; |
|
| 530 | - continue; |
|
| 531 | - } |
|
| 532 | - throw $e; |
|
| 533 | - } |
|
| 534 | - } else { |
|
| 535 | - Installer::installShippedApp($filename); |
|
| 536 | - } |
|
| 537 | - \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - closedir( $dir ); |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - return $errors; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * install an app already placed in the app folder |
|
| 552 | - * @param string $app id of the app to install |
|
| 553 | - * @return integer |
|
| 554 | - */ |
|
| 555 | - public static function installShippedApp($app) { |
|
| 556 | - //install the database |
|
| 557 | - $appPath = OC_App::getAppPath($app); |
|
| 558 | - \OC_App::registerAutoloading($app, $appPath); |
|
| 559 | - |
|
| 560 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
| 561 | - try { |
|
| 562 | - OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
| 563 | - } catch (TableExistsException $e) { |
|
| 564 | - throw new HintException( |
|
| 565 | - 'Failed to enable app ' . $app, |
|
| 566 | - 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
| 567 | - 0, $e |
|
| 568 | - ); |
|
| 569 | - } |
|
| 570 | - } else { |
|
| 571 | - $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
| 572 | - $ms->migrate(); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - //run appinfo/install.php |
|
| 576 | - self::includeAppScript("$appPath/appinfo/install.php"); |
|
| 577 | - |
|
| 578 | - $info = OC_App::getAppInfo($app); |
|
| 579 | - if (is_null($info)) { |
|
| 580 | - return false; |
|
| 581 | - } |
|
| 582 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 583 | - |
|
| 584 | - OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
| 585 | - |
|
| 586 | - $config = \OC::$server->getConfig(); |
|
| 587 | - |
|
| 588 | - $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
| 589 | - if (array_key_exists('ocsid', $info)) { |
|
| 590 | - $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - //set remote/public handlers |
|
| 594 | - foreach($info['remote'] as $name=>$path) { |
|
| 595 | - $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
| 596 | - } |
|
| 597 | - foreach($info['public'] as $name=>$path) { |
|
| 598 | - $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - OC_App::setAppTypes($info['id']); |
|
| 602 | - |
|
| 603 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 604 | - // requires that autoloading was registered for the app, |
|
| 605 | - // as happens before running the install.php some lines above |
|
| 606 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - return $info['id']; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * @param string $script |
|
| 614 | - */ |
|
| 615 | - private static function includeAppScript($script) { |
|
| 616 | - if ( file_exists($script) ){ |
|
| 617 | - include $script; |
|
| 618 | - } |
|
| 619 | - } |
|
| 60 | + /** @var AppFetcher */ |
|
| 61 | + private $appFetcher; |
|
| 62 | + /** @var IClientService */ |
|
| 63 | + private $clientService; |
|
| 64 | + /** @var ITempManager */ |
|
| 65 | + private $tempManager; |
|
| 66 | + /** @var ILogger */ |
|
| 67 | + private $logger; |
|
| 68 | + /** @var IConfig */ |
|
| 69 | + private $config; |
|
| 70 | + /** @var array - for caching the result of app fetcher */ |
|
| 71 | + private $apps = null; |
|
| 72 | + /** @var bool|null - for caching the result of the ready status */ |
|
| 73 | + private $isInstanceReadyForUpdates = null; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param AppFetcher $appFetcher |
|
| 77 | + * @param IClientService $clientService |
|
| 78 | + * @param ITempManager $tempManager |
|
| 79 | + * @param ILogger $logger |
|
| 80 | + * @param IConfig $config |
|
| 81 | + */ |
|
| 82 | + public function __construct(AppFetcher $appFetcher, |
|
| 83 | + IClientService $clientService, |
|
| 84 | + ITempManager $tempManager, |
|
| 85 | + ILogger $logger, |
|
| 86 | + IConfig $config) { |
|
| 87 | + $this->appFetcher = $appFetcher; |
|
| 88 | + $this->clientService = $clientService; |
|
| 89 | + $this->tempManager = $tempManager; |
|
| 90 | + $this->logger = $logger; |
|
| 91 | + $this->config = $config; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Installs an app that is located in one of the app folders already |
|
| 96 | + * |
|
| 97 | + * @param string $appId App to install |
|
| 98 | + * @throws \Exception |
|
| 99 | + * @return string app ID |
|
| 100 | + */ |
|
| 101 | + public function installApp($appId) { |
|
| 102 | + $app = \OC_App::findAppInDirectories($appId); |
|
| 103 | + if($app === false) { |
|
| 104 | + throw new \Exception('App not found in any app directory'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $basedir = $app['path'].'/'.$appId; |
|
| 108 | + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
| 109 | + |
|
| 110 | + $l = \OC::$server->getL10N('core'); |
|
| 111 | + |
|
| 112 | + if(!is_array($info)) { |
|
| 113 | + throw new \Exception( |
|
| 114 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 115 | + [$appId] |
|
| 116 | + ) |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $version = \OCP\Util::getVersion(); |
|
| 121 | + if (!\OC_App::isAppCompatible($version, $info)) { |
|
| 122 | + throw new \Exception( |
|
| 123 | + // TODO $l |
|
| 124 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 125 | + [$info['name']] |
|
| 126 | + ) |
|
| 127 | + ); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // check for required dependencies |
|
| 131 | + \OC_App::checkAppDependencies($this->config, $l, $info); |
|
| 132 | + \OC_App::registerAutoloading($appId, $basedir); |
|
| 133 | + |
|
| 134 | + //install the database |
|
| 135 | + if(is_file($basedir.'/appinfo/database.xml')) { |
|
| 136 | + if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
|
| 137 | + OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 138 | + } else { |
|
| 139 | + OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 140 | + } |
|
| 141 | + } else { |
|
| 142 | + $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
| 143 | + $ms->migrate(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 147 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 148 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + //run appinfo/install.php |
|
| 152 | + self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 153 | + |
|
| 154 | + $appData = OC_App::getAppInfo($appId); |
|
| 155 | + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
| 156 | + |
|
| 157 | + //set the installed version |
|
| 158 | + \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
| 159 | + \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
| 160 | + |
|
| 161 | + //set remote/public handlers |
|
| 162 | + foreach($info['remote'] as $name=>$path) { |
|
| 163 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
| 164 | + } |
|
| 165 | + foreach($info['public'] as $name=>$path) { |
|
| 166 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + OC_App::setAppTypes($info['id']); |
|
| 170 | + |
|
| 171 | + return $info['id']; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @brief checks whether or not an app is installed |
|
| 176 | + * @param string $app app |
|
| 177 | + * @returns bool |
|
| 178 | + * |
|
| 179 | + * Checks whether or not an app is installed, i.e. registered in apps table. |
|
| 180 | + */ |
|
| 181 | + public static function isInstalled( $app ) { |
|
| 182 | + return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Updates the specified app from the appstore |
|
| 187 | + * |
|
| 188 | + * @param string $appId |
|
| 189 | + * @return bool |
|
| 190 | + */ |
|
| 191 | + public function updateAppstoreApp($appId) { |
|
| 192 | + if($this->isUpdateAvailable($appId)) { |
|
| 193 | + try { |
|
| 194 | + $this->downloadApp($appId); |
|
| 195 | + } catch (\Exception $e) { |
|
| 196 | + $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
| 197 | + return false; |
|
| 198 | + } |
|
| 199 | + return OC_App::updateApp($appId); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Downloads an app and puts it into the app directory |
|
| 207 | + * |
|
| 208 | + * @param string $appId |
|
| 209 | + * |
|
| 210 | + * @throws \Exception If the installation was not successful |
|
| 211 | + */ |
|
| 212 | + public function downloadApp($appId) { |
|
| 213 | + $appId = strtolower($appId); |
|
| 214 | + |
|
| 215 | + $apps = $this->appFetcher->get(); |
|
| 216 | + foreach($apps as $app) { |
|
| 217 | + if($app['id'] === $appId) { |
|
| 218 | + // Load the certificate |
|
| 219 | + $certificate = new X509(); |
|
| 220 | + $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 221 | + $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
| 222 | + |
|
| 223 | + // Verify if the certificate has been revoked |
|
| 224 | + $crl = new X509(); |
|
| 225 | + $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 226 | + $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 227 | + if($crl->validateSignature() !== true) { |
|
| 228 | + throw new \Exception('Could not validate CRL signature'); |
|
| 229 | + } |
|
| 230 | + $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
| 231 | + $revoked = $crl->getRevoked($csn); |
|
| 232 | + if ($revoked !== false) { |
|
| 233 | + throw new \Exception( |
|
| 234 | + sprintf( |
|
| 235 | + 'Certificate "%s" has been revoked', |
|
| 236 | + $csn |
|
| 237 | + ) |
|
| 238 | + ); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
| 242 | + if($certificate->validateSignature() !== true) { |
|
| 243 | + throw new \Exception( |
|
| 244 | + sprintf( |
|
| 245 | + 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
| 246 | + $appId |
|
| 247 | + ) |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // Verify if the certificate is issued for the requested app id |
|
| 252 | + $certInfo = openssl_x509_parse($app['certificate']); |
|
| 253 | + if(!isset($certInfo['subject']['CN'])) { |
|
| 254 | + throw new \Exception( |
|
| 255 | + sprintf( |
|
| 256 | + 'App with id %s has a cert with no CN', |
|
| 257 | + $appId |
|
| 258 | + ) |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + if($certInfo['subject']['CN'] !== $appId) { |
|
| 262 | + throw new \Exception( |
|
| 263 | + sprintf( |
|
| 264 | + 'App with id %s has a cert issued to %s', |
|
| 265 | + $appId, |
|
| 266 | + $certInfo['subject']['CN'] |
|
| 267 | + ) |
|
| 268 | + ); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Download the release |
|
| 272 | + $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
| 273 | + $client = $this->clientService->newClient(); |
|
| 274 | + $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
| 275 | + |
|
| 276 | + // Check if the signature actually matches the downloaded content |
|
| 277 | + $certificate = openssl_get_publickey($app['certificate']); |
|
| 278 | + $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 279 | + openssl_free_key($certificate); |
|
| 280 | + |
|
| 281 | + if($verified === true) { |
|
| 282 | + // Seems to match, let's proceed |
|
| 283 | + $extractDir = $this->tempManager->getTemporaryFolder(); |
|
| 284 | + $archive = new TAR($tempFile); |
|
| 285 | + |
|
| 286 | + if($archive) { |
|
| 287 | + if (!$archive->extract($extractDir)) { |
|
| 288 | + throw new \Exception( |
|
| 289 | + sprintf( |
|
| 290 | + 'Could not extract app %s', |
|
| 291 | + $appId |
|
| 292 | + ) |
|
| 293 | + ); |
|
| 294 | + } |
|
| 295 | + $allFiles = scandir($extractDir); |
|
| 296 | + $folders = array_diff($allFiles, ['.', '..']); |
|
| 297 | + $folders = array_values($folders); |
|
| 298 | + |
|
| 299 | + if(count($folders) > 1) { |
|
| 300 | + throw new \Exception( |
|
| 301 | + sprintf( |
|
| 302 | + 'Extracted app %s has more than 1 folder', |
|
| 303 | + $appId |
|
| 304 | + ) |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + // Check if appinfo/info.xml has the same app ID as well |
|
| 309 | + $loadEntities = libxml_disable_entity_loader(false); |
|
| 310 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 311 | + libxml_disable_entity_loader($loadEntities); |
|
| 312 | + if((string)$xml->id !== $appId) { |
|
| 313 | + throw new \Exception( |
|
| 314 | + sprintf( |
|
| 315 | + 'App for id %s has a wrong app ID in info.xml: %s', |
|
| 316 | + $appId, |
|
| 317 | + (string)$xml->id |
|
| 318 | + ) |
|
| 319 | + ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // Check if the version is lower than before |
|
| 323 | + $currentVersion = OC_App::getAppVersion($appId); |
|
| 324 | + $newVersion = (string)$xml->version; |
|
| 325 | + if(version_compare($currentVersion, $newVersion) === 1) { |
|
| 326 | + throw new \Exception( |
|
| 327 | + sprintf( |
|
| 328 | + 'App for id %s has version %s and tried to update to lower version %s', |
|
| 329 | + $appId, |
|
| 330 | + $currentVersion, |
|
| 331 | + $newVersion |
|
| 332 | + ) |
|
| 333 | + ); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 337 | + // Remove old app with the ID if existent |
|
| 338 | + OC_Helper::rmdirr($baseDir); |
|
| 339 | + // Move to app folder |
|
| 340 | + if(@mkdir($baseDir)) { |
|
| 341 | + $extractDir .= '/' . $folders[0]; |
|
| 342 | + OC_Helper::copyr($extractDir, $baseDir); |
|
| 343 | + } |
|
| 344 | + OC_Helper::copyr($extractDir, $baseDir); |
|
| 345 | + OC_Helper::rmdirr($extractDir); |
|
| 346 | + return; |
|
| 347 | + } else { |
|
| 348 | + throw new \Exception( |
|
| 349 | + sprintf( |
|
| 350 | + 'Could not extract app with ID %s to %s', |
|
| 351 | + $appId, |
|
| 352 | + $extractDir |
|
| 353 | + ) |
|
| 354 | + ); |
|
| 355 | + } |
|
| 356 | + } else { |
|
| 357 | + // Signature does not match |
|
| 358 | + throw new \Exception( |
|
| 359 | + sprintf( |
|
| 360 | + 'App with id %s has invalid signature', |
|
| 361 | + $appId |
|
| 362 | + ) |
|
| 363 | + ); |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + throw new \Exception( |
|
| 369 | + sprintf( |
|
| 370 | + 'Could not download app %s', |
|
| 371 | + $appId |
|
| 372 | + ) |
|
| 373 | + ); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Check if an update for the app is available |
|
| 378 | + * |
|
| 379 | + * @param string $appId |
|
| 380 | + * @return string|false false or the version number of the update |
|
| 381 | + */ |
|
| 382 | + public function isUpdateAvailable($appId) { |
|
| 383 | + if ($this->isInstanceReadyForUpdates === null) { |
|
| 384 | + $installPath = OC_App::getInstallPath(); |
|
| 385 | + if ($installPath === false || $installPath === null) { |
|
| 386 | + $this->isInstanceReadyForUpdates = false; |
|
| 387 | + } else { |
|
| 388 | + $this->isInstanceReadyForUpdates = true; |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + if ($this->isInstanceReadyForUpdates === false) { |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if ($this->isInstalledFromGit($appId) === true) { |
|
| 397 | + return false; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + if ($this->apps === null) { |
|
| 401 | + $this->apps = $this->appFetcher->get(); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + foreach($this->apps as $app) { |
|
| 405 | + if($app['id'] === $appId) { |
|
| 406 | + $currentVersion = OC_App::getAppVersion($appId); |
|
| 407 | + $newestVersion = $app['releases'][0]['version']; |
|
| 408 | + if (version_compare($newestVersion, $currentVersion, '>')) { |
|
| 409 | + return $newestVersion; |
|
| 410 | + } else { |
|
| 411 | + return false; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + return false; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Check if app has been installed from git |
|
| 421 | + * @param string $name name of the application to remove |
|
| 422 | + * @return boolean |
|
| 423 | + * |
|
| 424 | + * The function will check if the path contains a .git folder |
|
| 425 | + */ |
|
| 426 | + private function isInstalledFromGit($appId) { |
|
| 427 | + $app = \OC_App::findAppInDirectories($appId); |
|
| 428 | + if($app === false) { |
|
| 429 | + return false; |
|
| 430 | + } |
|
| 431 | + $basedir = $app['path'].'/'.$appId; |
|
| 432 | + return file_exists($basedir.'/.git/'); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Check if app is already downloaded |
|
| 437 | + * @param string $name name of the application to remove |
|
| 438 | + * @return boolean |
|
| 439 | + * |
|
| 440 | + * The function will check if the app is already downloaded in the apps repository |
|
| 441 | + */ |
|
| 442 | + public function isDownloaded($name) { |
|
| 443 | + foreach(\OC::$APPSROOTS as $dir) { |
|
| 444 | + $dirToTest = $dir['path']; |
|
| 445 | + $dirToTest .= '/'; |
|
| 446 | + $dirToTest .= $name; |
|
| 447 | + $dirToTest .= '/'; |
|
| 448 | + |
|
| 449 | + if (is_dir($dirToTest)) { |
|
| 450 | + return true; |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + return false; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Removes an app |
|
| 459 | + * @param string $appId ID of the application to remove |
|
| 460 | + * @return boolean |
|
| 461 | + * |
|
| 462 | + * |
|
| 463 | + * This function works as follows |
|
| 464 | + * -# call uninstall repair steps |
|
| 465 | + * -# removing the files |
|
| 466 | + * |
|
| 467 | + * The function will not delete preferences, tables and the configuration, |
|
| 468 | + * this has to be done by the function oc_app_uninstall(). |
|
| 469 | + */ |
|
| 470 | + public function removeApp($appId) { |
|
| 471 | + if($this->isDownloaded( $appId )) { |
|
| 472 | + $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 473 | + OC_Helper::rmdirr($appDir); |
|
| 474 | + return true; |
|
| 475 | + }else{ |
|
| 476 | + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
| 477 | + |
|
| 478 | + return false; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Installs the app within the bundle and marks the bundle as installed |
|
| 485 | + * |
|
| 486 | + * @param Bundle $bundle |
|
| 487 | + * @throws \Exception If app could not get installed |
|
| 488 | + */ |
|
| 489 | + public function installAppBundle(Bundle $bundle) { |
|
| 490 | + $appIds = $bundle->getAppIdentifiers(); |
|
| 491 | + foreach($appIds as $appId) { |
|
| 492 | + if(!$this->isDownloaded($appId)) { |
|
| 493 | + $this->downloadApp($appId); |
|
| 494 | + } |
|
| 495 | + $this->installApp($appId); |
|
| 496 | + $app = new OC_App(); |
|
| 497 | + $app->enable($appId); |
|
| 498 | + } |
|
| 499 | + $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
| 500 | + $bundles[] = $bundle->getIdentifier(); |
|
| 501 | + $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * Installs shipped apps |
|
| 506 | + * |
|
| 507 | + * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
| 508 | + * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
| 509 | + * working ownCloud at the end instead of an aborted update. |
|
| 510 | + * @return array Array of error messages (appid => Exception) |
|
| 511 | + */ |
|
| 512 | + public static function installShippedApps($softErrors = false) { |
|
| 513 | + $errors = []; |
|
| 514 | + foreach(\OC::$APPSROOTS as $app_dir) { |
|
| 515 | + if($dir = opendir( $app_dir['path'] )) { |
|
| 516 | + while( false !== ( $filename = readdir( $dir ))) { |
|
| 517 | + if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
| 518 | + if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
| 519 | + if(!Installer::isInstalled($filename)) { |
|
| 520 | + $info=OC_App::getAppInfo($filename); |
|
| 521 | + $enabled = isset($info['default_enable']); |
|
| 522 | + if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
| 523 | + && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
| 524 | + if ($softErrors) { |
|
| 525 | + try { |
|
| 526 | + Installer::installShippedApp($filename); |
|
| 527 | + } catch (HintException $e) { |
|
| 528 | + if ($e->getPrevious() instanceof TableExistsException) { |
|
| 529 | + $errors[$filename] = $e; |
|
| 530 | + continue; |
|
| 531 | + } |
|
| 532 | + throw $e; |
|
| 533 | + } |
|
| 534 | + } else { |
|
| 535 | + Installer::installShippedApp($filename); |
|
| 536 | + } |
|
| 537 | + \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + closedir( $dir ); |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + return $errors; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * install an app already placed in the app folder |
|
| 552 | + * @param string $app id of the app to install |
|
| 553 | + * @return integer |
|
| 554 | + */ |
|
| 555 | + public static function installShippedApp($app) { |
|
| 556 | + //install the database |
|
| 557 | + $appPath = OC_App::getAppPath($app); |
|
| 558 | + \OC_App::registerAutoloading($app, $appPath); |
|
| 559 | + |
|
| 560 | + if(is_file("$appPath/appinfo/database.xml")) { |
|
| 561 | + try { |
|
| 562 | + OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
| 563 | + } catch (TableExistsException $e) { |
|
| 564 | + throw new HintException( |
|
| 565 | + 'Failed to enable app ' . $app, |
|
| 566 | + 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
| 567 | + 0, $e |
|
| 568 | + ); |
|
| 569 | + } |
|
| 570 | + } else { |
|
| 571 | + $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
| 572 | + $ms->migrate(); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + //run appinfo/install.php |
|
| 576 | + self::includeAppScript("$appPath/appinfo/install.php"); |
|
| 577 | + |
|
| 578 | + $info = OC_App::getAppInfo($app); |
|
| 579 | + if (is_null($info)) { |
|
| 580 | + return false; |
|
| 581 | + } |
|
| 582 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 583 | + |
|
| 584 | + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
| 585 | + |
|
| 586 | + $config = \OC::$server->getConfig(); |
|
| 587 | + |
|
| 588 | + $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
| 589 | + if (array_key_exists('ocsid', $info)) { |
|
| 590 | + $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + //set remote/public handlers |
|
| 594 | + foreach($info['remote'] as $name=>$path) { |
|
| 595 | + $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
| 596 | + } |
|
| 597 | + foreach($info['public'] as $name=>$path) { |
|
| 598 | + $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + OC_App::setAppTypes($info['id']); |
|
| 602 | + |
|
| 603 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 604 | + // requires that autoloading was registered for the app, |
|
| 605 | + // as happens before running the install.php some lines above |
|
| 606 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + return $info['id']; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * @param string $script |
|
| 614 | + */ |
|
| 615 | + private static function includeAppScript($script) { |
|
| 616 | + if ( file_exists($script) ){ |
|
| 617 | + include $script; |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | 620 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function installApp($appId) { |
| 102 | 102 | $app = \OC_App::findAppInDirectories($appId); |
| 103 | - if($app === false) { |
|
| 103 | + if ($app === false) { |
|
| 104 | 104 | throw new \Exception('App not found in any app directory'); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | $l = \OC::$server->getL10N('core'); |
| 111 | 111 | |
| 112 | - if(!is_array($info)) { |
|
| 112 | + if (!is_array($info)) { |
|
| 113 | 113 | throw new \Exception( |
| 114 | 114 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
| 115 | 115 | [$appId] |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | \OC_App::registerAutoloading($appId, $basedir); |
| 133 | 133 | |
| 134 | 134 | //install the database |
| 135 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
| 135 | + if (is_file($basedir.'/appinfo/database.xml')) { |
|
| 136 | 136 | if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
| 137 | 137 | OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
| 138 | 138 | } else { |
@@ -144,12 +144,12 @@ discard block |
||
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | \OC_App::setupBackgroundJobs($info['background-jobs']); |
| 147 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 147 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
| 148 | 148 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | //run appinfo/install.php |
| 152 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 152 | + self::includeAppScript($basedir.'/appinfo/install.php'); |
|
| 153 | 153 | |
| 154 | 154 | $appData = OC_App::getAppInfo($appId); |
| 155 | 155 | OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
| 160 | 160 | |
| 161 | 161 | //set remote/public handlers |
| 162 | - foreach($info['remote'] as $name=>$path) { |
|
| 162 | + foreach ($info['remote'] as $name=>$path) { |
|
| 163 | 163 | \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
| 164 | 164 | } |
| 165 | - foreach($info['public'] as $name=>$path) { |
|
| 165 | + foreach ($info['public'] as $name=>$path) { |
|
| 166 | 166 | \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
| 167 | 167 | } |
| 168 | 168 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * Checks whether or not an app is installed, i.e. registered in apps table. |
| 180 | 180 | */ |
| 181 | - public static function isInstalled( $app ) { |
|
| 181 | + public static function isInstalled($app) { |
|
| 182 | 182 | return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * @return bool |
| 190 | 190 | */ |
| 191 | 191 | public function updateAppstoreApp($appId) { |
| 192 | - if($this->isUpdateAvailable($appId)) { |
|
| 192 | + if ($this->isUpdateAvailable($appId)) { |
|
| 193 | 193 | try { |
| 194 | 194 | $this->downloadApp($appId); |
| 195 | 195 | } catch (\Exception $e) { |
@@ -213,18 +213,18 @@ discard block |
||
| 213 | 213 | $appId = strtolower($appId); |
| 214 | 214 | |
| 215 | 215 | $apps = $this->appFetcher->get(); |
| 216 | - foreach($apps as $app) { |
|
| 217 | - if($app['id'] === $appId) { |
|
| 216 | + foreach ($apps as $app) { |
|
| 217 | + if ($app['id'] === $appId) { |
|
| 218 | 218 | // Load the certificate |
| 219 | 219 | $certificate = new X509(); |
| 220 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 220 | + $certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
| 221 | 221 | $loadedCertificate = $certificate->loadX509($app['certificate']); |
| 222 | 222 | |
| 223 | 223 | // Verify if the certificate has been revoked |
| 224 | 224 | $crl = new X509(); |
| 225 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 226 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 227 | - if($crl->validateSignature() !== true) { |
|
| 225 | + $crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
| 226 | + $crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl')); |
|
| 227 | + if ($crl->validateSignature() !== true) { |
|
| 228 | 228 | throw new \Exception('Could not validate CRL signature'); |
| 229 | 229 | } |
| 230 | 230 | $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
| 242 | - if($certificate->validateSignature() !== true) { |
|
| 242 | + if ($certificate->validateSignature() !== true) { |
|
| 243 | 243 | throw new \Exception( |
| 244 | 244 | sprintf( |
| 245 | 245 | 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | |
| 251 | 251 | // Verify if the certificate is issued for the requested app id |
| 252 | 252 | $certInfo = openssl_x509_parse($app['certificate']); |
| 253 | - if(!isset($certInfo['subject']['CN'])) { |
|
| 253 | + if (!isset($certInfo['subject']['CN'])) { |
|
| 254 | 254 | throw new \Exception( |
| 255 | 255 | sprintf( |
| 256 | 256 | 'App with id %s has a cert with no CN', |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | ) |
| 259 | 259 | ); |
| 260 | 260 | } |
| 261 | - if($certInfo['subject']['CN'] !== $appId) { |
|
| 261 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
| 262 | 262 | throw new \Exception( |
| 263 | 263 | sprintf( |
| 264 | 264 | 'App with id %s has a cert issued to %s', |
@@ -275,15 +275,15 @@ discard block |
||
| 275 | 275 | |
| 276 | 276 | // Check if the signature actually matches the downloaded content |
| 277 | 277 | $certificate = openssl_get_publickey($app['certificate']); |
| 278 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 278 | + $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 279 | 279 | openssl_free_key($certificate); |
| 280 | 280 | |
| 281 | - if($verified === true) { |
|
| 281 | + if ($verified === true) { |
|
| 282 | 282 | // Seems to match, let's proceed |
| 283 | 283 | $extractDir = $this->tempManager->getTemporaryFolder(); |
| 284 | 284 | $archive = new TAR($tempFile); |
| 285 | 285 | |
| 286 | - if($archive) { |
|
| 286 | + if ($archive) { |
|
| 287 | 287 | if (!$archive->extract($extractDir)) { |
| 288 | 288 | throw new \Exception( |
| 289 | 289 | sprintf( |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | $folders = array_diff($allFiles, ['.', '..']); |
| 297 | 297 | $folders = array_values($folders); |
| 298 | 298 | |
| 299 | - if(count($folders) > 1) { |
|
| 299 | + if (count($folders) > 1) { |
|
| 300 | 300 | throw new \Exception( |
| 301 | 301 | sprintf( |
| 302 | 302 | 'Extracted app %s has more than 1 folder', |
@@ -307,22 +307,22 @@ discard block |
||
| 307 | 307 | |
| 308 | 308 | // Check if appinfo/info.xml has the same app ID as well |
| 309 | 309 | $loadEntities = libxml_disable_entity_loader(false); |
| 310 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 310 | + $xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml'); |
|
| 311 | 311 | libxml_disable_entity_loader($loadEntities); |
| 312 | - if((string)$xml->id !== $appId) { |
|
| 312 | + if ((string) $xml->id !== $appId) { |
|
| 313 | 313 | throw new \Exception( |
| 314 | 314 | sprintf( |
| 315 | 315 | 'App for id %s has a wrong app ID in info.xml: %s', |
| 316 | 316 | $appId, |
| 317 | - (string)$xml->id |
|
| 317 | + (string) $xml->id |
|
| 318 | 318 | ) |
| 319 | 319 | ); |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // Check if the version is lower than before |
| 323 | 323 | $currentVersion = OC_App::getAppVersion($appId); |
| 324 | - $newVersion = (string)$xml->version; |
|
| 325 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
| 324 | + $newVersion = (string) $xml->version; |
|
| 325 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
| 326 | 326 | throw new \Exception( |
| 327 | 327 | sprintf( |
| 328 | 328 | 'App for id %s has version %s and tried to update to lower version %s', |
@@ -333,12 +333,12 @@ discard block |
||
| 333 | 333 | ); |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 336 | + $baseDir = OC_App::getInstallPath().'/'.$appId; |
|
| 337 | 337 | // Remove old app with the ID if existent |
| 338 | 338 | OC_Helper::rmdirr($baseDir); |
| 339 | 339 | // Move to app folder |
| 340 | - if(@mkdir($baseDir)) { |
|
| 341 | - $extractDir .= '/' . $folders[0]; |
|
| 340 | + if (@mkdir($baseDir)) { |
|
| 341 | + $extractDir .= '/'.$folders[0]; |
|
| 342 | 342 | OC_Helper::copyr($extractDir, $baseDir); |
| 343 | 343 | } |
| 344 | 344 | OC_Helper::copyr($extractDir, $baseDir); |
@@ -401,8 +401,8 @@ discard block |
||
| 401 | 401 | $this->apps = $this->appFetcher->get(); |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - foreach($this->apps as $app) { |
|
| 405 | - if($app['id'] === $appId) { |
|
| 404 | + foreach ($this->apps as $app) { |
|
| 405 | + if ($app['id'] === $appId) { |
|
| 406 | 406 | $currentVersion = OC_App::getAppVersion($appId); |
| 407 | 407 | $newestVersion = $app['releases'][0]['version']; |
| 408 | 408 | if (version_compare($newestVersion, $currentVersion, '>')) { |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | */ |
| 426 | 426 | private function isInstalledFromGit($appId) { |
| 427 | 427 | $app = \OC_App::findAppInDirectories($appId); |
| 428 | - if($app === false) { |
|
| 428 | + if ($app === false) { |
|
| 429 | 429 | return false; |
| 430 | 430 | } |
| 431 | 431 | $basedir = $app['path'].'/'.$appId; |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | * The function will check if the app is already downloaded in the apps repository |
| 441 | 441 | */ |
| 442 | 442 | public function isDownloaded($name) { |
| 443 | - foreach(\OC::$APPSROOTS as $dir) { |
|
| 443 | + foreach (\OC::$APPSROOTS as $dir) { |
|
| 444 | 444 | $dirToTest = $dir['path']; |
| 445 | 445 | $dirToTest .= '/'; |
| 446 | 446 | $dirToTest .= $name; |
@@ -468,11 +468,11 @@ discard block |
||
| 468 | 468 | * this has to be done by the function oc_app_uninstall(). |
| 469 | 469 | */ |
| 470 | 470 | public function removeApp($appId) { |
| 471 | - if($this->isDownloaded( $appId )) { |
|
| 472 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 471 | + if ($this->isDownloaded($appId)) { |
|
| 472 | + $appDir = OC_App::getInstallPath().'/'.$appId; |
|
| 473 | 473 | OC_Helper::rmdirr($appDir); |
| 474 | 474 | return true; |
| 475 | - }else{ |
|
| 475 | + } else { |
|
| 476 | 476 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
| 477 | 477 | |
| 478 | 478 | return false; |
@@ -488,8 +488,8 @@ discard block |
||
| 488 | 488 | */ |
| 489 | 489 | public function installAppBundle(Bundle $bundle) { |
| 490 | 490 | $appIds = $bundle->getAppIdentifiers(); |
| 491 | - foreach($appIds as $appId) { |
|
| 492 | - if(!$this->isDownloaded($appId)) { |
|
| 491 | + foreach ($appIds as $appId) { |
|
| 492 | + if (!$this->isDownloaded($appId)) { |
|
| 493 | 493 | $this->downloadApp($appId); |
| 494 | 494 | } |
| 495 | 495 | $this->installApp($appId); |
@@ -511,13 +511,13 @@ discard block |
||
| 511 | 511 | */ |
| 512 | 512 | public static function installShippedApps($softErrors = false) { |
| 513 | 513 | $errors = []; |
| 514 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
| 515 | - if($dir = opendir( $app_dir['path'] )) { |
|
| 516 | - while( false !== ( $filename = readdir( $dir ))) { |
|
| 517 | - if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
| 518 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
| 519 | - if(!Installer::isInstalled($filename)) { |
|
| 520 | - $info=OC_App::getAppInfo($filename); |
|
| 514 | + foreach (\OC::$APPSROOTS as $app_dir) { |
|
| 515 | + if ($dir = opendir($app_dir['path'])) { |
|
| 516 | + while (false !== ($filename = readdir($dir))) { |
|
| 517 | + if (substr($filename, 0, 1) != '.' and is_dir($app_dir['path']."/$filename")) { |
|
| 518 | + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
| 519 | + if (!Installer::isInstalled($filename)) { |
|
| 520 | + $info = OC_App::getAppInfo($filename); |
|
| 521 | 521 | $enabled = isset($info['default_enable']); |
| 522 | 522 | if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
| 523 | 523 | && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | - closedir( $dir ); |
|
| 543 | + closedir($dir); |
|
| 544 | 544 | } |
| 545 | 545 | } |
| 546 | 546 | |
@@ -557,12 +557,12 @@ discard block |
||
| 557 | 557 | $appPath = OC_App::getAppPath($app); |
| 558 | 558 | \OC_App::registerAutoloading($app, $appPath); |
| 559 | 559 | |
| 560 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
| 560 | + if (is_file("$appPath/appinfo/database.xml")) { |
|
| 561 | 561 | try { |
| 562 | 562 | OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
| 563 | 563 | } catch (TableExistsException $e) { |
| 564 | 564 | throw new HintException( |
| 565 | - 'Failed to enable app ' . $app, |
|
| 565 | + 'Failed to enable app '.$app, |
|
| 566 | 566 | 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
| 567 | 567 | 0, $e |
| 568 | 568 | ); |
@@ -591,16 +591,16 @@ discard block |
||
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | //set remote/public handlers |
| 594 | - foreach($info['remote'] as $name=>$path) { |
|
| 594 | + foreach ($info['remote'] as $name=>$path) { |
|
| 595 | 595 | $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
| 596 | 596 | } |
| 597 | - foreach($info['public'] as $name=>$path) { |
|
| 597 | + foreach ($info['public'] as $name=>$path) { |
|
| 598 | 598 | $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | OC_App::setAppTypes($info['id']); |
| 602 | 602 | |
| 603 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 603 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
| 604 | 604 | // requires that autoloading was registered for the app, |
| 605 | 605 | // as happens before running the install.php some lines above |
| 606 | 606 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | * @param string $script |
| 614 | 614 | */ |
| 615 | 615 | private static function includeAppScript($script) { |
| 616 | - if ( file_exists($script) ){ |
|
| 616 | + if (file_exists($script)) { |
|
| 617 | 617 | include $script; |
| 618 | 618 | } |
| 619 | 619 | } |
@@ -134,7 +134,7 @@ |
||
| 134 | 134 | } |
| 135 | 135 | if(is_dir($source.'/'.$file)) { |
| 136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
| 137 | - }else{ |
|
| 137 | + } else{ |
|
| 138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -33,111 +33,111 @@ |
||
| 33 | 33 | namespace OC\Archive; |
| 34 | 34 | |
| 35 | 35 | abstract class Archive { |
| 36 | - /** |
|
| 37 | - * @param $source |
|
| 38 | - */ |
|
| 39 | - public abstract function __construct($source); |
|
| 40 | - /** |
|
| 41 | - * add an empty folder to the archive |
|
| 42 | - * @param string $path |
|
| 43 | - * @return bool |
|
| 44 | - */ |
|
| 45 | - public abstract function addFolder($path); |
|
| 46 | - /** |
|
| 47 | - * add a file to the archive |
|
| 48 | - * @param string $path |
|
| 49 | - * @param string $source either a local file or string data |
|
| 50 | - * @return bool |
|
| 51 | - */ |
|
| 52 | - public abstract function addFile($path, $source=''); |
|
| 53 | - /** |
|
| 54 | - * rename a file or folder in the archive |
|
| 55 | - * @param string $source |
|
| 56 | - * @param string $dest |
|
| 57 | - * @return bool |
|
| 58 | - */ |
|
| 59 | - public abstract function rename($source, $dest); |
|
| 60 | - /** |
|
| 61 | - * get the uncompressed size of a file in the archive |
|
| 62 | - * @param string $path |
|
| 63 | - * @return int |
|
| 64 | - */ |
|
| 65 | - public abstract function filesize($path); |
|
| 66 | - /** |
|
| 67 | - * get the last modified time of a file in the archive |
|
| 68 | - * @param string $path |
|
| 69 | - * @return int |
|
| 70 | - */ |
|
| 71 | - public abstract function mtime($path); |
|
| 72 | - /** |
|
| 73 | - * get the files in a folder |
|
| 74 | - * @param string $path |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 77 | - public abstract function getFolder($path); |
|
| 78 | - /** |
|
| 79 | - * get all files in the archive |
|
| 80 | - * @return array |
|
| 81 | - */ |
|
| 82 | - public abstract function getFiles(); |
|
| 83 | - /** |
|
| 84 | - * get the content of a file |
|
| 85 | - * @param string $path |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 88 | - public abstract function getFile($path); |
|
| 89 | - /** |
|
| 90 | - * extract a single file from the archive |
|
| 91 | - * @param string $path |
|
| 92 | - * @param string $dest |
|
| 93 | - * @return bool |
|
| 94 | - */ |
|
| 95 | - public abstract function extractFile($path, $dest); |
|
| 96 | - /** |
|
| 97 | - * extract the archive |
|
| 98 | - * @param string $dest |
|
| 99 | - * @return bool |
|
| 100 | - */ |
|
| 101 | - public abstract function extract($dest); |
|
| 102 | - /** |
|
| 103 | - * check if a file or folder exists in the archive |
|
| 104 | - * @param string $path |
|
| 105 | - * @return bool |
|
| 106 | - */ |
|
| 107 | - public abstract function fileExists($path); |
|
| 108 | - /** |
|
| 109 | - * remove a file or folder from the archive |
|
| 110 | - * @param string $path |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public abstract function remove($path); |
|
| 114 | - /** |
|
| 115 | - * get a file handler |
|
| 116 | - * @param string $path |
|
| 117 | - * @param string $mode |
|
| 118 | - * @return resource |
|
| 119 | - */ |
|
| 120 | - public abstract function getStream($path, $mode); |
|
| 121 | - /** |
|
| 122 | - * add a folder and all its content |
|
| 123 | - * @param string $path |
|
| 124 | - * @param string $source |
|
| 125 | - * @return boolean|null |
|
| 126 | - */ |
|
| 127 | - public function addRecursive($path, $source) { |
|
| 128 | - $dh = opendir($source); |
|
| 129 | - if(is_resource($dh)) { |
|
| 130 | - $this->addFolder($path); |
|
| 131 | - while (($file = readdir($dh)) !== false) { |
|
| 132 | - if($file === '.' || $file === '..') { |
|
| 133 | - continue; |
|
| 134 | - } |
|
| 135 | - if(is_dir($source.'/'.$file)) { |
|
| 136 | - $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
| 137 | - }else{ |
|
| 138 | - $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 36 | + /** |
|
| 37 | + * @param $source |
|
| 38 | + */ |
|
| 39 | + public abstract function __construct($source); |
|
| 40 | + /** |
|
| 41 | + * add an empty folder to the archive |
|
| 42 | + * @param string $path |
|
| 43 | + * @return bool |
|
| 44 | + */ |
|
| 45 | + public abstract function addFolder($path); |
|
| 46 | + /** |
|
| 47 | + * add a file to the archive |
|
| 48 | + * @param string $path |
|
| 49 | + * @param string $source either a local file or string data |
|
| 50 | + * @return bool |
|
| 51 | + */ |
|
| 52 | + public abstract function addFile($path, $source=''); |
|
| 53 | + /** |
|
| 54 | + * rename a file or folder in the archive |
|
| 55 | + * @param string $source |
|
| 56 | + * @param string $dest |
|
| 57 | + * @return bool |
|
| 58 | + */ |
|
| 59 | + public abstract function rename($source, $dest); |
|
| 60 | + /** |
|
| 61 | + * get the uncompressed size of a file in the archive |
|
| 62 | + * @param string $path |
|
| 63 | + * @return int |
|
| 64 | + */ |
|
| 65 | + public abstract function filesize($path); |
|
| 66 | + /** |
|
| 67 | + * get the last modified time of a file in the archive |
|
| 68 | + * @param string $path |
|
| 69 | + * @return int |
|
| 70 | + */ |
|
| 71 | + public abstract function mtime($path); |
|
| 72 | + /** |
|
| 73 | + * get the files in a folder |
|
| 74 | + * @param string $path |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | + public abstract function getFolder($path); |
|
| 78 | + /** |
|
| 79 | + * get all files in the archive |
|
| 80 | + * @return array |
|
| 81 | + */ |
|
| 82 | + public abstract function getFiles(); |
|
| 83 | + /** |
|
| 84 | + * get the content of a file |
|
| 85 | + * @param string $path |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | + public abstract function getFile($path); |
|
| 89 | + /** |
|
| 90 | + * extract a single file from the archive |
|
| 91 | + * @param string $path |
|
| 92 | + * @param string $dest |
|
| 93 | + * @return bool |
|
| 94 | + */ |
|
| 95 | + public abstract function extractFile($path, $dest); |
|
| 96 | + /** |
|
| 97 | + * extract the archive |
|
| 98 | + * @param string $dest |
|
| 99 | + * @return bool |
|
| 100 | + */ |
|
| 101 | + public abstract function extract($dest); |
|
| 102 | + /** |
|
| 103 | + * check if a file or folder exists in the archive |
|
| 104 | + * @param string $path |
|
| 105 | + * @return bool |
|
| 106 | + */ |
|
| 107 | + public abstract function fileExists($path); |
|
| 108 | + /** |
|
| 109 | + * remove a file or folder from the archive |
|
| 110 | + * @param string $path |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public abstract function remove($path); |
|
| 114 | + /** |
|
| 115 | + * get a file handler |
|
| 116 | + * @param string $path |
|
| 117 | + * @param string $mode |
|
| 118 | + * @return resource |
|
| 119 | + */ |
|
| 120 | + public abstract function getStream($path, $mode); |
|
| 121 | + /** |
|
| 122 | + * add a folder and all its content |
|
| 123 | + * @param string $path |
|
| 124 | + * @param string $source |
|
| 125 | + * @return boolean|null |
|
| 126 | + */ |
|
| 127 | + public function addRecursive($path, $source) { |
|
| 128 | + $dh = opendir($source); |
|
| 129 | + if(is_resource($dh)) { |
|
| 130 | + $this->addFolder($path); |
|
| 131 | + while (($file = readdir($dh)) !== false) { |
|
| 132 | + if($file === '.' || $file === '..') { |
|
| 133 | + continue; |
|
| 134 | + } |
|
| 135 | + if(is_dir($source.'/'.$file)) { |
|
| 136 | + $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
| 137 | + }else{ |
|
| 138 | + $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @param string $source either a local file or string data |
| 50 | 50 | * @return bool |
| 51 | 51 | */ |
| 52 | - public abstract function addFile($path, $source=''); |
|
| 52 | + public abstract function addFile($path, $source = ''); |
|
| 53 | 53 | /** |
| 54 | 54 | * rename a file or folder in the archive |
| 55 | 55 | * @param string $source |
@@ -126,15 +126,15 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function addRecursive($path, $source) { |
| 128 | 128 | $dh = opendir($source); |
| 129 | - if(is_resource($dh)) { |
|
| 129 | + if (is_resource($dh)) { |
|
| 130 | 130 | $this->addFolder($path); |
| 131 | 131 | while (($file = readdir($dh)) !== false) { |
| 132 | - if($file === '.' || $file === '..') { |
|
| 132 | + if ($file === '.' || $file === '..') { |
|
| 133 | 133 | continue; |
| 134 | 134 | } |
| 135 | - if(is_dir($source.'/'.$file)) { |
|
| 135 | + if (is_dir($source.'/'.$file)) { |
|
| 136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
| 137 | - }else{ |
|
| 137 | + } else { |
|
| 138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -25,14 +25,14 @@ |
||
| 25 | 25 | namespace OC; |
| 26 | 26 | |
| 27 | 27 | class NaturalSort_DefaultCollator { |
| 28 | - public function compare($a, $b) { |
|
| 29 | - $result = strcasecmp($a, $b); |
|
| 30 | - if ($result === 0) { |
|
| 31 | - if ($a === $b) { |
|
| 32 | - return 0; |
|
| 33 | - } |
|
| 34 | - return ($a > $b) ? -1 : 1; |
|
| 35 | - } |
|
| 36 | - return ($result < 0) ? -1 : 1; |
|
| 37 | - } |
|
| 28 | + public function compare($a, $b) { |
|
| 29 | + $result = strcasecmp($a, $b); |
|
| 30 | + if ($result === 0) { |
|
| 31 | + if ($a === $b) { |
|
| 32 | + return 0; |
|
| 33 | + } |
|
| 34 | + return ($a > $b) ? -1 : 1; |
|
| 35 | + } |
|
| 36 | + return ($result < 0) ? -1 : 1; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | parent::__construct( 'core', 'layout.user' ); |
| 62 | 62 | if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
| 63 | 63 | $this->assign('bodyid', 'body-settings'); |
| 64 | - }else{ |
|
| 64 | + } else{ |
|
| 65 | 65 | $this->assign('bodyid', 'body-user'); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -45,280 +45,280 @@ |
||
| 45 | 45 | |
| 46 | 46 | class TemplateLayout extends \OC_Template { |
| 47 | 47 | |
| 48 | - private static $versionHash = ''; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var \OCP\IConfig |
|
| 52 | - */ |
|
| 53 | - private $config; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param string $renderAs |
|
| 57 | - * @param string $appId application id |
|
| 58 | - */ |
|
| 59 | - public function __construct( $renderAs, $appId = '' ) { |
|
| 60 | - |
|
| 61 | - // yes - should be injected .... |
|
| 62 | - $this->config = \OC::$server->getConfig(); |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - // Decide which page we show |
|
| 66 | - if($renderAs == 'user') { |
|
| 67 | - parent::__construct( 'core', 'layout.user' ); |
|
| 68 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 69 | - $this->assign('bodyid', 'body-settings'); |
|
| 70 | - }else{ |
|
| 71 | - $this->assign('bodyid', 'body-user'); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // Code integrity notification |
|
| 75 | - $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
| 76 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
| 77 | - \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Add navigation entry |
|
| 81 | - $this->assign( 'application', ''); |
|
| 82 | - $this->assign( 'appid', $appId ); |
|
| 83 | - $navigation = \OC_App::getNavigation(); |
|
| 84 | - $this->assign( 'navigation', $navigation); |
|
| 85 | - $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
| 86 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 87 | - foreach($navigation as $entry) { |
|
| 88 | - if ($entry['active']) { |
|
| 89 | - $this->assign( 'application', $entry['name'] ); |
|
| 90 | - break; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - foreach($settingsNavigation as $entry) { |
|
| 95 | - if ($entry['active']) { |
|
| 96 | - $this->assign( 'application', $entry['name'] ); |
|
| 97 | - break; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - $userDisplayName = \OC_User::getDisplayName(); |
|
| 101 | - $this->assign('user_displayname', $userDisplayName); |
|
| 102 | - $this->assign('user_uid', \OC_User::getUser()); |
|
| 103 | - |
|
| 104 | - if (\OC_User::getUser() === false) { |
|
| 105 | - $this->assign('userAvatarSet', false); |
|
| 106 | - } else { |
|
| 107 | - $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
| 108 | - $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // check if app menu icons should be inverted |
|
| 112 | - try { |
|
| 113 | - /** @var \OCA\Theming\Util $util */ |
|
| 114 | - $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
| 115 | - $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
| 116 | - } catch (\OCP\AppFramework\QueryException $e) { |
|
| 117 | - $this->assign('themingInvertMenu', false); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - } else if ($renderAs == 'error') { |
|
| 121 | - parent::__construct('core', 'layout.guest', '', false); |
|
| 122 | - $this->assign('bodyid', 'body-login'); |
|
| 123 | - } else if ($renderAs == 'guest') { |
|
| 124 | - parent::__construct('core', 'layout.guest'); |
|
| 125 | - $this->assign('bodyid', 'body-login'); |
|
| 126 | - } else { |
|
| 127 | - parent::__construct('core', 'layout.base'); |
|
| 128 | - |
|
| 129 | - } |
|
| 130 | - // Send the language to our layouts |
|
| 131 | - $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
| 132 | - $lang = str_replace('_', '-', $lang); |
|
| 133 | - $this->assign('language', $lang); |
|
| 134 | - |
|
| 135 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 136 | - if (empty(self::$versionHash)) { |
|
| 137 | - $v = \OC_App::getAppVersions(); |
|
| 138 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
| 139 | - self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
| 140 | - } |
|
| 141 | - } else { |
|
| 142 | - self::$versionHash = md5('not installed'); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // Add the js files |
|
| 146 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
| 147 | - $this->assign('jsfiles', array()); |
|
| 148 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
| 149 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
| 150 | - $jsConfigHelper = new JSConfigHelper( |
|
| 151 | - \OC::$server->getL10N('lib'), |
|
| 152 | - \OC::$server->query(Defaults::class), |
|
| 153 | - \OC::$server->getAppManager(), |
|
| 154 | - \OC::$server->getSession(), |
|
| 155 | - \OC::$server->getUserSession()->getUser(), |
|
| 156 | - $this->config, |
|
| 157 | - \OC::$server->getGroupManager(), |
|
| 158 | - \OC::$server->getIniWrapper(), |
|
| 159 | - \OC::$server->getURLGenerator() |
|
| 160 | - ); |
|
| 161 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
| 162 | - } else { |
|
| 163 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - foreach($jsFiles as $info) { |
|
| 167 | - $web = $info[1]; |
|
| 168 | - $file = $info[2]; |
|
| 169 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - try { |
|
| 173 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
| 174 | - } catch (\Exception $e) { |
|
| 175 | - $pathInfo = ''; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Do not initialise scss appdata until we have a fully installed instance |
|
| 179 | - // Do not load scss for update, errors, installation or login page |
|
| 180 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 181 | - && !\OCP\Util::needUpgrade() |
|
| 182 | - && $pathInfo !== '' |
|
| 183 | - && !preg_match('/^\/login/', $pathInfo) |
|
| 184 | - && $renderAs !== 'error' && $renderAs !== 'guest' |
|
| 185 | - ) { |
|
| 186 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
| 187 | - } else { |
|
| 188 | - // If we ignore the scss compiler, |
|
| 189 | - // we need to load the guest css fallback |
|
| 190 | - \OC_Util::addStyle('guest'); |
|
| 191 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $this->assign('cssfiles', array()); |
|
| 195 | - $this->assign('printcssfiles', []); |
|
| 196 | - $this->assign('versionHash', self::$versionHash); |
|
| 197 | - foreach($cssFiles as $info) { |
|
| 198 | - $web = $info[1]; |
|
| 199 | - $file = $info[2]; |
|
| 200 | - |
|
| 201 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
| 202 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 203 | - } else { |
|
| 204 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * @param string $path |
|
| 211 | - * @param string $file |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - protected function getVersionHashSuffix($path = false, $file = false) { |
|
| 215 | - if ($this->config->getSystemValue('debug', false)) { |
|
| 216 | - // allows chrome workspace mapping in debug mode |
|
| 217 | - return ""; |
|
| 218 | - } |
|
| 219 | - $themingSuffix = ''; |
|
| 220 | - $v = []; |
|
| 221 | - |
|
| 222 | - if ($this->config->getSystemValue('installed', false)) { |
|
| 223 | - if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
| 224 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 225 | - } |
|
| 226 | - $v = \OC_App::getAppVersions(); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // Try the webroot path for a match |
|
| 230 | - if ($path !== false && $path !== '') { |
|
| 231 | - $appName = $this->getAppNamefromPath($path); |
|
| 232 | - if(array_key_exists($appName, $v)) { |
|
| 233 | - $appVersion = $v[$appName]; |
|
| 234 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - // fallback to the file path instead |
|
| 238 | - if ($file !== false && $file !== '') { |
|
| 239 | - $appName = $this->getAppNamefromPath($file); |
|
| 240 | - if(array_key_exists($appName, $v)) { |
|
| 241 | - $appVersion = $v[$appName]; |
|
| 242 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param array $styles |
|
| 251 | - * @return array |
|
| 252 | - */ |
|
| 253 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
| 254 | - // Read the selected theme from the config file |
|
| 255 | - $theme = \OC_Util::getTheme(); |
|
| 256 | - |
|
| 257 | - if($compileScss) { |
|
| 258 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
| 259 | - } else { |
|
| 260 | - $SCSSCacher = null; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - $locator = new \OC\Template\CSSResourceLocator( |
|
| 264 | - \OC::$server->getLogger(), |
|
| 265 | - $theme, |
|
| 266 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 267 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 268 | - $SCSSCacher |
|
| 269 | - ); |
|
| 270 | - $locator->find($styles); |
|
| 271 | - return $locator->getResources(); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * @param string $path |
|
| 276 | - * @return string|boolean |
|
| 277 | - */ |
|
| 278 | - public function getAppNamefromPath($path) { |
|
| 279 | - if ($path !== '' && is_string($path)) { |
|
| 280 | - $pathParts = explode('/', $path); |
|
| 281 | - if ($pathParts[0] === 'css') { |
|
| 282 | - // This is a scss request |
|
| 283 | - return $pathParts[1]; |
|
| 284 | - } |
|
| 285 | - return end($pathParts); |
|
| 286 | - } |
|
| 287 | - return false; |
|
| 288 | - |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * @param array $scripts |
|
| 293 | - * @return array |
|
| 294 | - */ |
|
| 295 | - static public function findJavascriptFiles($scripts) { |
|
| 296 | - // Read the selected theme from the config file |
|
| 297 | - $theme = \OC_Util::getTheme(); |
|
| 298 | - |
|
| 299 | - $locator = new \OC\Template\JSResourceLocator( |
|
| 300 | - \OC::$server->getLogger(), |
|
| 301 | - $theme, |
|
| 302 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 303 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 304 | - \OC::$server->query(JSCombiner::class) |
|
| 305 | - ); |
|
| 306 | - $locator->find($scripts); |
|
| 307 | - return $locator->getResources(); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
| 312 | - * @param string $filePath Absolute path |
|
| 313 | - * @return string Relative path |
|
| 314 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
| 315 | - */ |
|
| 316 | - public static function convertToRelativePath($filePath) { |
|
| 317 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
| 318 | - if(count($relativePath) !== 2) { |
|
| 319 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - return $relativePath[1]; |
|
| 323 | - } |
|
| 48 | + private static $versionHash = ''; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var \OCP\IConfig |
|
| 52 | + */ |
|
| 53 | + private $config; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param string $renderAs |
|
| 57 | + * @param string $appId application id |
|
| 58 | + */ |
|
| 59 | + public function __construct( $renderAs, $appId = '' ) { |
|
| 60 | + |
|
| 61 | + // yes - should be injected .... |
|
| 62 | + $this->config = \OC::$server->getConfig(); |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + // Decide which page we show |
|
| 66 | + if($renderAs == 'user') { |
|
| 67 | + parent::__construct( 'core', 'layout.user' ); |
|
| 68 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 69 | + $this->assign('bodyid', 'body-settings'); |
|
| 70 | + }else{ |
|
| 71 | + $this->assign('bodyid', 'body-user'); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // Code integrity notification |
|
| 75 | + $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
| 76 | + if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
| 77 | + \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Add navigation entry |
|
| 81 | + $this->assign( 'application', ''); |
|
| 82 | + $this->assign( 'appid', $appId ); |
|
| 83 | + $navigation = \OC_App::getNavigation(); |
|
| 84 | + $this->assign( 'navigation', $navigation); |
|
| 85 | + $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
| 86 | + $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 87 | + foreach($navigation as $entry) { |
|
| 88 | + if ($entry['active']) { |
|
| 89 | + $this->assign( 'application', $entry['name'] ); |
|
| 90 | + break; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + foreach($settingsNavigation as $entry) { |
|
| 95 | + if ($entry['active']) { |
|
| 96 | + $this->assign( 'application', $entry['name'] ); |
|
| 97 | + break; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + $userDisplayName = \OC_User::getDisplayName(); |
|
| 101 | + $this->assign('user_displayname', $userDisplayName); |
|
| 102 | + $this->assign('user_uid', \OC_User::getUser()); |
|
| 103 | + |
|
| 104 | + if (\OC_User::getUser() === false) { |
|
| 105 | + $this->assign('userAvatarSet', false); |
|
| 106 | + } else { |
|
| 107 | + $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
| 108 | + $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // check if app menu icons should be inverted |
|
| 112 | + try { |
|
| 113 | + /** @var \OCA\Theming\Util $util */ |
|
| 114 | + $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
| 115 | + $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
| 116 | + } catch (\OCP\AppFramework\QueryException $e) { |
|
| 117 | + $this->assign('themingInvertMenu', false); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + } else if ($renderAs == 'error') { |
|
| 121 | + parent::__construct('core', 'layout.guest', '', false); |
|
| 122 | + $this->assign('bodyid', 'body-login'); |
|
| 123 | + } else if ($renderAs == 'guest') { |
|
| 124 | + parent::__construct('core', 'layout.guest'); |
|
| 125 | + $this->assign('bodyid', 'body-login'); |
|
| 126 | + } else { |
|
| 127 | + parent::__construct('core', 'layout.base'); |
|
| 128 | + |
|
| 129 | + } |
|
| 130 | + // Send the language to our layouts |
|
| 131 | + $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
| 132 | + $lang = str_replace('_', '-', $lang); |
|
| 133 | + $this->assign('language', $lang); |
|
| 134 | + |
|
| 135 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 136 | + if (empty(self::$versionHash)) { |
|
| 137 | + $v = \OC_App::getAppVersions(); |
|
| 138 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
| 139 | + self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
| 140 | + } |
|
| 141 | + } else { |
|
| 142 | + self::$versionHash = md5('not installed'); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // Add the js files |
|
| 146 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
| 147 | + $this->assign('jsfiles', array()); |
|
| 148 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
| 149 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
| 150 | + $jsConfigHelper = new JSConfigHelper( |
|
| 151 | + \OC::$server->getL10N('lib'), |
|
| 152 | + \OC::$server->query(Defaults::class), |
|
| 153 | + \OC::$server->getAppManager(), |
|
| 154 | + \OC::$server->getSession(), |
|
| 155 | + \OC::$server->getUserSession()->getUser(), |
|
| 156 | + $this->config, |
|
| 157 | + \OC::$server->getGroupManager(), |
|
| 158 | + \OC::$server->getIniWrapper(), |
|
| 159 | + \OC::$server->getURLGenerator() |
|
| 160 | + ); |
|
| 161 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
| 162 | + } else { |
|
| 163 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + foreach($jsFiles as $info) { |
|
| 167 | + $web = $info[1]; |
|
| 168 | + $file = $info[2]; |
|
| 169 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + try { |
|
| 173 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
| 174 | + } catch (\Exception $e) { |
|
| 175 | + $pathInfo = ''; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Do not initialise scss appdata until we have a fully installed instance |
|
| 179 | + // Do not load scss for update, errors, installation or login page |
|
| 180 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 181 | + && !\OCP\Util::needUpgrade() |
|
| 182 | + && $pathInfo !== '' |
|
| 183 | + && !preg_match('/^\/login/', $pathInfo) |
|
| 184 | + && $renderAs !== 'error' && $renderAs !== 'guest' |
|
| 185 | + ) { |
|
| 186 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
| 187 | + } else { |
|
| 188 | + // If we ignore the scss compiler, |
|
| 189 | + // we need to load the guest css fallback |
|
| 190 | + \OC_Util::addStyle('guest'); |
|
| 191 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $this->assign('cssfiles', array()); |
|
| 195 | + $this->assign('printcssfiles', []); |
|
| 196 | + $this->assign('versionHash', self::$versionHash); |
|
| 197 | + foreach($cssFiles as $info) { |
|
| 198 | + $web = $info[1]; |
|
| 199 | + $file = $info[2]; |
|
| 200 | + |
|
| 201 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
| 202 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 203 | + } else { |
|
| 204 | + $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * @param string $path |
|
| 211 | + * @param string $file |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + protected function getVersionHashSuffix($path = false, $file = false) { |
|
| 215 | + if ($this->config->getSystemValue('debug', false)) { |
|
| 216 | + // allows chrome workspace mapping in debug mode |
|
| 217 | + return ""; |
|
| 218 | + } |
|
| 219 | + $themingSuffix = ''; |
|
| 220 | + $v = []; |
|
| 221 | + |
|
| 222 | + if ($this->config->getSystemValue('installed', false)) { |
|
| 223 | + if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
| 224 | + $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 225 | + } |
|
| 226 | + $v = \OC_App::getAppVersions(); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // Try the webroot path for a match |
|
| 230 | + if ($path !== false && $path !== '') { |
|
| 231 | + $appName = $this->getAppNamefromPath($path); |
|
| 232 | + if(array_key_exists($appName, $v)) { |
|
| 233 | + $appVersion = $v[$appName]; |
|
| 234 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + // fallback to the file path instead |
|
| 238 | + if ($file !== false && $file !== '') { |
|
| 239 | + $appName = $this->getAppNamefromPath($file); |
|
| 240 | + if(array_key_exists($appName, $v)) { |
|
| 241 | + $appVersion = $v[$appName]; |
|
| 242 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + return '?v=' . self::$versionHash . $themingSuffix; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param array $styles |
|
| 251 | + * @return array |
|
| 252 | + */ |
|
| 253 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
| 254 | + // Read the selected theme from the config file |
|
| 255 | + $theme = \OC_Util::getTheme(); |
|
| 256 | + |
|
| 257 | + if($compileScss) { |
|
| 258 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
| 259 | + } else { |
|
| 260 | + $SCSSCacher = null; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + $locator = new \OC\Template\CSSResourceLocator( |
|
| 264 | + \OC::$server->getLogger(), |
|
| 265 | + $theme, |
|
| 266 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 267 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 268 | + $SCSSCacher |
|
| 269 | + ); |
|
| 270 | + $locator->find($styles); |
|
| 271 | + return $locator->getResources(); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @param string $path |
|
| 276 | + * @return string|boolean |
|
| 277 | + */ |
|
| 278 | + public function getAppNamefromPath($path) { |
|
| 279 | + if ($path !== '' && is_string($path)) { |
|
| 280 | + $pathParts = explode('/', $path); |
|
| 281 | + if ($pathParts[0] === 'css') { |
|
| 282 | + // This is a scss request |
|
| 283 | + return $pathParts[1]; |
|
| 284 | + } |
|
| 285 | + return end($pathParts); |
|
| 286 | + } |
|
| 287 | + return false; |
|
| 288 | + |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * @param array $scripts |
|
| 293 | + * @return array |
|
| 294 | + */ |
|
| 295 | + static public function findJavascriptFiles($scripts) { |
|
| 296 | + // Read the selected theme from the config file |
|
| 297 | + $theme = \OC_Util::getTheme(); |
|
| 298 | + |
|
| 299 | + $locator = new \OC\Template\JSResourceLocator( |
|
| 300 | + \OC::$server->getLogger(), |
|
| 301 | + $theme, |
|
| 302 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 303 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 304 | + \OC::$server->query(JSCombiner::class) |
|
| 305 | + ); |
|
| 306 | + $locator->find($scripts); |
|
| 307 | + return $locator->getResources(); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
| 312 | + * @param string $filePath Absolute path |
|
| 313 | + * @return string Relative path |
|
| 314 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
| 315 | + */ |
|
| 316 | + public static function convertToRelativePath($filePath) { |
|
| 317 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
| 318 | + if(count($relativePath) !== 2) { |
|
| 319 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + return $relativePath[1]; |
|
| 323 | + } |
|
| 324 | 324 | } |
@@ -56,44 +56,44 @@ discard block |
||
| 56 | 56 | * @param string $renderAs |
| 57 | 57 | * @param string $appId application id |
| 58 | 58 | */ |
| 59 | - public function __construct( $renderAs, $appId = '' ) { |
|
| 59 | + public function __construct($renderAs, $appId = '') { |
|
| 60 | 60 | |
| 61 | 61 | // yes - should be injected .... |
| 62 | 62 | $this->config = \OC::$server->getConfig(); |
| 63 | 63 | |
| 64 | 64 | |
| 65 | 65 | // Decide which page we show |
| 66 | - if($renderAs == 'user') { |
|
| 67 | - parent::__construct( 'core', 'layout.user' ); |
|
| 68 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 66 | + if ($renderAs == 'user') { |
|
| 67 | + parent::__construct('core', 'layout.user'); |
|
| 68 | + if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) { |
|
| 69 | 69 | $this->assign('bodyid', 'body-settings'); |
| 70 | - }else{ |
|
| 70 | + } else { |
|
| 71 | 71 | $this->assign('bodyid', 'body-user'); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // Code integrity notification |
| 75 | 75 | $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
| 76 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
| 76 | + if (\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
| 77 | 77 | \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Add navigation entry |
| 81 | - $this->assign( 'application', ''); |
|
| 82 | - $this->assign( 'appid', $appId ); |
|
| 81 | + $this->assign('application', ''); |
|
| 82 | + $this->assign('appid', $appId); |
|
| 83 | 83 | $navigation = \OC_App::getNavigation(); |
| 84 | - $this->assign( 'navigation', $navigation); |
|
| 84 | + $this->assign('navigation', $navigation); |
|
| 85 | 85 | $settingsNavigation = \OC_App::getSettingsNavigation(); |
| 86 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 87 | - foreach($navigation as $entry) { |
|
| 86 | + $this->assign('settingsnavigation', $settingsNavigation); |
|
| 87 | + foreach ($navigation as $entry) { |
|
| 88 | 88 | if ($entry['active']) { |
| 89 | - $this->assign( 'application', $entry['name'] ); |
|
| 89 | + $this->assign('application', $entry['name']); |
|
| 90 | 90 | break; |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - foreach($settingsNavigation as $entry) { |
|
| 94 | + foreach ($settingsNavigation as $entry) { |
|
| 95 | 95 | if ($entry['active']) { |
| 96 | - $this->assign( 'application', $entry['name'] ); |
|
| 96 | + $this->assign('application', $entry['name']); |
|
| 97 | 97 | break; |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $lang = str_replace('_', '-', $lang); |
| 133 | 133 | $this->assign('language', $lang); |
| 134 | 134 | |
| 135 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 135 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 136 | 136 | if (empty(self::$versionHash)) { |
| 137 | 137 | $v = \OC_App::getAppVersions(); |
| 138 | 138 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | - foreach($jsFiles as $info) { |
|
| 166 | + foreach ($jsFiles as $info) { |
|
| 167 | 167 | $web = $info[1]; |
| 168 | 168 | $file = $info[2]; |
| 169 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 169 | + $this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | try { |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | // Do not initialise scss appdata until we have a fully installed instance |
| 179 | 179 | // Do not load scss for update, errors, installation or login page |
| 180 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 180 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 181 | 181 | && !\OCP\Util::needUpgrade() |
| 182 | 182 | && $pathInfo !== '' |
| 183 | 183 | && !preg_match('/^\/login/', $pathInfo) |
@@ -194,14 +194,14 @@ discard block |
||
| 194 | 194 | $this->assign('cssfiles', array()); |
| 195 | 195 | $this->assign('printcssfiles', []); |
| 196 | 196 | $this->assign('versionHash', self::$versionHash); |
| 197 | - foreach($cssFiles as $info) { |
|
| 197 | + foreach ($cssFiles as $info) { |
|
| 198 | 198 | $web = $info[1]; |
| 199 | 199 | $file = $info[2]; |
| 200 | 200 | |
| 201 | 201 | if (substr($file, -strlen('print.css')) === 'print.css') { |
| 202 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 202 | + $this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
| 203 | 203 | } else { |
| 204 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
|
| 204 | + $this->append('cssfiles', $web.'/'.$file.$this->getVersionHashSuffix($web, $file)); |
|
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | |
| 222 | 222 | if ($this->config->getSystemValue('installed', false)) { |
| 223 | 223 | if (\OC::$server->getAppManager()->isInstalled('theming')) { |
| 224 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 224 | + $themingSuffix = '-'.$this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 225 | 225 | } |
| 226 | 226 | $v = \OC_App::getAppVersions(); |
| 227 | 227 | } |
@@ -229,21 +229,21 @@ discard block |
||
| 229 | 229 | // Try the webroot path for a match |
| 230 | 230 | if ($path !== false && $path !== '') { |
| 231 | 231 | $appName = $this->getAppNamefromPath($path); |
| 232 | - if(array_key_exists($appName, $v)) { |
|
| 232 | + if (array_key_exists($appName, $v)) { |
|
| 233 | 233 | $appVersion = $v[$appName]; |
| 234 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 234 | + return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix; |
|
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | 237 | // fallback to the file path instead |
| 238 | 238 | if ($file !== false && $file !== '') { |
| 239 | 239 | $appName = $this->getAppNamefromPath($file); |
| 240 | - if(array_key_exists($appName, $v)) { |
|
| 240 | + if (array_key_exists($appName, $v)) { |
|
| 241 | 241 | $appVersion = $v[$appName]; |
| 242 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 242 | + return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix; |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
| 246 | + return '?v='.self::$versionHash.$themingSuffix; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | // Read the selected theme from the config file |
| 255 | 255 | $theme = \OC_Util::getTheme(); |
| 256 | 256 | |
| 257 | - if($compileScss) { |
|
| 257 | + if ($compileScss) { |
|
| 258 | 258 | $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
| 259 | 259 | } else { |
| 260 | 260 | $SCSSCacher = null; |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | $locator = new \OC\Template\CSSResourceLocator( |
| 264 | 264 | \OC::$server->getLogger(), |
| 265 | 265 | $theme, |
| 266 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 267 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 266 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 267 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 268 | 268 | $SCSSCacher |
| 269 | 269 | ); |
| 270 | 270 | $locator->find($styles); |
@@ -299,8 +299,8 @@ discard block |
||
| 299 | 299 | $locator = new \OC\Template\JSResourceLocator( |
| 300 | 300 | \OC::$server->getLogger(), |
| 301 | 301 | $theme, |
| 302 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 303 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 302 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 303 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 304 | 304 | \OC::$server->query(JSCombiner::class) |
| 305 | 305 | ); |
| 306 | 306 | $locator->find($scripts); |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | public static function convertToRelativePath($filePath) { |
| 317 | 317 | $relativePath = explode(\OC::$SERVERROOT, $filePath); |
| 318 | - if(count($relativePath) !== 2) { |
|
| 318 | + if (count($relativePath) !== 2) { |
|
| 319 | 319 | throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
| 320 | 320 | } |
| 321 | 321 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function execute($jobList, ILogger $logger = null) { |
| 59 | 59 | // add an interval of 15 mins |
| 60 | - $this->setInterval(15*60); |
|
| 60 | + $this->setInterval(15 * 60); |
|
| 61 | 61 | |
| 62 | 62 | $this->jobList = $jobList; |
| 63 | 63 | $this->logger = $logger; |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | try { |
| 91 | 91 | $repair->addStep($step); |
| 92 | 92 | } catch (\Exception $ex) { |
| 93 | - $this->logger->logException($ex,[ |
|
| 93 | + $this->logger->logException($ex, [ |
|
| 94 | 94 | 'app' => 'migration' |
| 95 | 95 | ]); |
| 96 | 96 | |
@@ -37,81 +37,81 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class BackgroundRepair extends TimedJob { |
| 39 | 39 | |
| 40 | - /** @var IJobList */ |
|
| 41 | - private $jobList; |
|
| 40 | + /** @var IJobList */ |
|
| 41 | + private $jobList; |
|
| 42 | 42 | |
| 43 | - /** @var ILogger */ |
|
| 44 | - private $logger; |
|
| 43 | + /** @var ILogger */ |
|
| 44 | + private $logger; |
|
| 45 | 45 | |
| 46 | - /** @var EventDispatcher */ |
|
| 47 | - private $dispatcher; |
|
| 46 | + /** @var EventDispatcher */ |
|
| 47 | + private $dispatcher; |
|
| 48 | 48 | |
| 49 | - public function setDispatcher(EventDispatcher $dispatcher) { |
|
| 50 | - $this->dispatcher = $dispatcher; |
|
| 51 | - } |
|
| 52 | - /** |
|
| 53 | - * run the job, then remove it from the job list |
|
| 54 | - * |
|
| 55 | - * @param JobList $jobList |
|
| 56 | - * @param ILogger|null $logger |
|
| 57 | - */ |
|
| 58 | - public function execute($jobList, ILogger $logger = null) { |
|
| 59 | - // add an interval of 15 mins |
|
| 60 | - $this->setInterval(15*60); |
|
| 49 | + public function setDispatcher(EventDispatcher $dispatcher) { |
|
| 50 | + $this->dispatcher = $dispatcher; |
|
| 51 | + } |
|
| 52 | + /** |
|
| 53 | + * run the job, then remove it from the job list |
|
| 54 | + * |
|
| 55 | + * @param JobList $jobList |
|
| 56 | + * @param ILogger|null $logger |
|
| 57 | + */ |
|
| 58 | + public function execute($jobList, ILogger $logger = null) { |
|
| 59 | + // add an interval of 15 mins |
|
| 60 | + $this->setInterval(15*60); |
|
| 61 | 61 | |
| 62 | - $this->jobList = $jobList; |
|
| 63 | - $this->logger = $logger; |
|
| 64 | - parent::execute($jobList, $logger); |
|
| 65 | - } |
|
| 62 | + $this->jobList = $jobList; |
|
| 63 | + $this->logger = $logger; |
|
| 64 | + parent::execute($jobList, $logger); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @param array $argument |
|
| 69 | - * @throws \Exception |
|
| 70 | - * @throws \OC\NeedsUpdateException |
|
| 71 | - */ |
|
| 72 | - protected function run($argument) { |
|
| 73 | - if (!isset($argument['app']) || !isset($argument['step'])) { |
|
| 74 | - // remove the job - we can never execute it |
|
| 75 | - $this->jobList->remove($this, $this->argument); |
|
| 76 | - return; |
|
| 77 | - } |
|
| 78 | - $app = $argument['app']; |
|
| 67 | + /** |
|
| 68 | + * @param array $argument |
|
| 69 | + * @throws \Exception |
|
| 70 | + * @throws \OC\NeedsUpdateException |
|
| 71 | + */ |
|
| 72 | + protected function run($argument) { |
|
| 73 | + if (!isset($argument['app']) || !isset($argument['step'])) { |
|
| 74 | + // remove the job - we can never execute it |
|
| 75 | + $this->jobList->remove($this, $this->argument); |
|
| 76 | + return; |
|
| 77 | + } |
|
| 78 | + $app = $argument['app']; |
|
| 79 | 79 | |
| 80 | - try { |
|
| 81 | - $this->loadApp($app); |
|
| 82 | - } catch (NeedsUpdateException $ex) { |
|
| 83 | - // as long as the app is not yet done with it's offline migration |
|
| 84 | - // we better not start with the live migration |
|
| 85 | - return; |
|
| 86 | - } |
|
| 80 | + try { |
|
| 81 | + $this->loadApp($app); |
|
| 82 | + } catch (NeedsUpdateException $ex) { |
|
| 83 | + // as long as the app is not yet done with it's offline migration |
|
| 84 | + // we better not start with the live migration |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - $step = $argument['step']; |
|
| 89 | - $repair = new Repair([], $this->dispatcher); |
|
| 90 | - try { |
|
| 91 | - $repair->addStep($step); |
|
| 92 | - } catch (\Exception $ex) { |
|
| 93 | - $this->logger->logException($ex,[ |
|
| 94 | - 'app' => 'migration' |
|
| 95 | - ]); |
|
| 88 | + $step = $argument['step']; |
|
| 89 | + $repair = new Repair([], $this->dispatcher); |
|
| 90 | + try { |
|
| 91 | + $repair->addStep($step); |
|
| 92 | + } catch (\Exception $ex) { |
|
| 93 | + $this->logger->logException($ex,[ |
|
| 94 | + 'app' => 'migration' |
|
| 95 | + ]); |
|
| 96 | 96 | |
| 97 | - // remove the job - we can never execute it |
|
| 98 | - $this->jobList->remove($this, $this->argument); |
|
| 99 | - return; |
|
| 100 | - } |
|
| 97 | + // remove the job - we can never execute it |
|
| 98 | + $this->jobList->remove($this, $this->argument); |
|
| 99 | + return; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - // execute the repair step |
|
| 103 | - $repair->run(); |
|
| 102 | + // execute the repair step |
|
| 103 | + $repair->run(); |
|
| 104 | 104 | |
| 105 | - // remove the job once executed successfully |
|
| 106 | - $this->jobList->remove($this, $this->argument); |
|
| 107 | - } |
|
| 105 | + // remove the job once executed successfully |
|
| 106 | + $this->jobList->remove($this, $this->argument); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * @codeCoverageIgnore |
|
| 111 | - * @param $app |
|
| 112 | - * @throws NeedsUpdateException |
|
| 113 | - */ |
|
| 114 | - protected function loadApp($app) { |
|
| 115 | - OC_App::loadApp($app); |
|
| 116 | - } |
|
| 109 | + /** |
|
| 110 | + * @codeCoverageIgnore |
|
| 111 | + * @param $app |
|
| 112 | + * @throws NeedsUpdateException |
|
| 113 | + */ |
|
| 114 | + protected function loadApp($app) { |
|
| 115 | + OC_App::loadApp($app); |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | if ($command instanceof ICommand) { |
| 56 | 56 | // ensure the command can be serialized |
| 57 | 57 | $serialized = serialize($command); |
| 58 | - if(strlen($serialized) > 4000) { |
|
| 58 | + if (strlen($serialized) > 4000) { |
|
| 59 | 59 | throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
| 60 | 60 | } |
| 61 | 61 | $unserialized = unserialize($serialized); |
@@ -26,48 +26,48 @@ |
||
| 26 | 26 | use OCP\Command\ICommand; |
| 27 | 27 | |
| 28 | 28 | class QueueBus implements IBus { |
| 29 | - /** |
|
| 30 | - * @var ICommand[]|callable[] |
|
| 31 | - */ |
|
| 32 | - private $queue = []; |
|
| 29 | + /** |
|
| 30 | + * @var ICommand[]|callable[] |
|
| 31 | + */ |
|
| 32 | + private $queue = []; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Schedule a command to be fired |
|
| 36 | - * |
|
| 37 | - * @param \OCP\Command\ICommand | callable $command |
|
| 38 | - */ |
|
| 39 | - public function push($command) { |
|
| 40 | - $this->queue[] = $command; |
|
| 41 | - } |
|
| 34 | + /** |
|
| 35 | + * Schedule a command to be fired |
|
| 36 | + * |
|
| 37 | + * @param \OCP\Command\ICommand | callable $command |
|
| 38 | + */ |
|
| 39 | + public function push($command) { |
|
| 40 | + $this->queue[] = $command; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Require all commands using a trait to be run synchronous |
|
| 45 | - * |
|
| 46 | - * @param string $trait |
|
| 47 | - */ |
|
| 48 | - public function requireSync($trait) { |
|
| 49 | - } |
|
| 43 | + /** |
|
| 44 | + * Require all commands using a trait to be run synchronous |
|
| 45 | + * |
|
| 46 | + * @param string $trait |
|
| 47 | + */ |
|
| 48 | + public function requireSync($trait) { |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param \OCP\Command\ICommand | callable $command |
|
| 53 | - */ |
|
| 54 | - private function runCommand($command) { |
|
| 55 | - if ($command instanceof ICommand) { |
|
| 56 | - // ensure the command can be serialized |
|
| 57 | - $serialized = serialize($command); |
|
| 58 | - if(strlen($serialized) > 4000) { |
|
| 59 | - throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
|
| 60 | - } |
|
| 61 | - $unserialized = unserialize($serialized); |
|
| 62 | - $unserialized->handle(); |
|
| 63 | - } else { |
|
| 64 | - $command(); |
|
| 65 | - } |
|
| 66 | - } |
|
| 51 | + /** |
|
| 52 | + * @param \OCP\Command\ICommand | callable $command |
|
| 53 | + */ |
|
| 54 | + private function runCommand($command) { |
|
| 55 | + if ($command instanceof ICommand) { |
|
| 56 | + // ensure the command can be serialized |
|
| 57 | + $serialized = serialize($command); |
|
| 58 | + if(strlen($serialized) > 4000) { |
|
| 59 | + throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
|
| 60 | + } |
|
| 61 | + $unserialized = unserialize($serialized); |
|
| 62 | + $unserialized->handle(); |
|
| 63 | + } else { |
|
| 64 | + $command(); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function run() { |
|
| 69 | - while ($command = array_shift($this->queue)) { |
|
| 70 | - $this->runCommand($command); |
|
| 71 | - } |
|
| 72 | - } |
|
| 68 | + public function run() { |
|
| 69 | + while ($command = array_shift($this->queue)) { |
|
| 70 | + $this->runCommand($command); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -25,12 +25,12 @@ |
||
| 25 | 25 | use OC\BackgroundJob\QueuedJob; |
| 26 | 26 | |
| 27 | 27 | class CallableJob extends QueuedJob { |
| 28 | - protected function run($serializedCallable) { |
|
| 29 | - $callable = unserialize($serializedCallable); |
|
| 30 | - if (is_callable($callable)) { |
|
| 31 | - $callable(); |
|
| 32 | - } else { |
|
| 33 | - throw new \InvalidArgumentException('Invalid serialized callable'); |
|
| 34 | - } |
|
| 35 | - } |
|
| 28 | + protected function run($serializedCallable) { |
|
| 29 | + $callable = unserialize($serializedCallable); |
|
| 30 | + if (is_callable($callable)) { |
|
| 31 | + $callable(); |
|
| 32 | + } else { |
|
| 33 | + throw new \InvalidArgumentException('Invalid serialized callable'); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -26,13 +26,13 @@ |
||
| 26 | 26 | use SuperClosure\Serializer; |
| 27 | 27 | |
| 28 | 28 | class ClosureJob extends QueuedJob { |
| 29 | - protected function run($serializedCallable) { |
|
| 30 | - $serializer = new Serializer(); |
|
| 31 | - $callable = $serializer->unserialize($serializedCallable); |
|
| 32 | - if (is_callable($callable)) { |
|
| 33 | - $callable(); |
|
| 34 | - } else { |
|
| 35 | - throw new \InvalidArgumentException('Invalid serialized callable'); |
|
| 36 | - } |
|
| 37 | - } |
|
| 29 | + protected function run($serializedCallable) { |
|
| 30 | + $serializer = new Serializer(); |
|
| 31 | + $callable = $serializer->unserialize($serializedCallable); |
|
| 32 | + if (is_callable($callable)) { |
|
| 33 | + $callable(); |
|
| 34 | + } else { |
|
| 35 | + throw new \InvalidArgumentException('Invalid serialized callable'); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -25,12 +25,12 @@ |
||
| 25 | 25 | use OCP\IUser; |
| 26 | 26 | |
| 27 | 27 | trait FileAccess { |
| 28 | - protected function setupFS(IUser $user){ |
|
| 29 | - \OC_Util::setupFS($user->getUID()); |
|
| 30 | - } |
|
| 28 | + protected function setupFS(IUser $user){ |
|
| 29 | + \OC_Util::setupFS($user->getUID()); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - protected function getUserFolder(IUser $user) { |
|
| 33 | - $this->setupFS($user); |
|
| 34 | - return \OC::$server->getUserFolder($user->getUID()); |
|
| 35 | - } |
|
| 32 | + protected function getUserFolder(IUser $user) { |
|
| 33 | + $this->setupFS($user); |
|
| 34 | + return \OC::$server->getUserFolder($user->getUID()); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | use OCP\IUser; |
| 26 | 26 | |
| 27 | 27 | trait FileAccess { |
| 28 | - protected function setupFS(IUser $user){ |
|
| 28 | + protected function setupFS(IUser $user) { |
|
| 29 | 29 | \OC_Util::setupFS($user->getUID()); |
| 30 | 30 | } |
| 31 | 31 | |