@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function installApp($appId) { |
| 97 | 97 | $app = \OC_App::findAppInDirectories($appId); |
| 98 | - if($app === false) { |
|
| 98 | + if ($app === false) { |
|
| 99 | 99 | throw new \Exception('App not found in any app directory'); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $l = \OC::$server->getL10N('core'); |
| 106 | 106 | |
| 107 | - if(!is_array($info)) { |
|
| 107 | + if (!is_array($info)) { |
|
| 108 | 108 | throw new \Exception( |
| 109 | 109 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
| 110 | 110 | [$appId] |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | \OC_App::registerAutoloading($appId, $basedir); |
| 128 | 128 | |
| 129 | 129 | //install the database |
| 130 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
| 130 | + if (is_file($basedir.'/appinfo/database.xml')) { |
|
| 131 | 131 | if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
| 132 | 132 | OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
| 133 | 133 | } else { |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | \OC_App::setupBackgroundJobs($info['background-jobs']); |
| 142 | 142 | |
| 143 | 143 | //run appinfo/install.php |
| 144 | - if(!isset($data['noinstall']) or $data['noinstall']==false) { |
|
| 145 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 144 | + if (!isset($data['noinstall']) or $data['noinstall'] == false) { |
|
| 145 | + self::includeAppScript($basedir.'/appinfo/install.php'); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | $appData = OC_App::getAppInfo($appId); |
@@ -153,10 +153,10 @@ discard block |
||
| 153 | 153 | \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
| 154 | 154 | |
| 155 | 155 | //set remote/public handlers |
| 156 | - foreach($info['remote'] as $name=>$path) { |
|
| 156 | + foreach ($info['remote'] as $name=>$path) { |
|
| 157 | 157 | \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
| 158 | 158 | } |
| 159 | - foreach($info['public'] as $name=>$path) { |
|
| 159 | + foreach ($info['public'] as $name=>$path) { |
|
| 160 | 160 | \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
| 161 | 161 | } |
| 162 | 162 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * |
| 173 | 173 | * Checks whether or not an app is installed, i.e. registered in apps table. |
| 174 | 174 | */ |
| 175 | - public static function isInstalled( $app ) { |
|
| 175 | + public static function isInstalled($app) { |
|
| 176 | 176 | return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @return bool |
| 184 | 184 | */ |
| 185 | 185 | public function updateAppstoreApp($appId) { |
| 186 | - if($this->isUpdateAvailable($appId)) { |
|
| 186 | + if ($this->isUpdateAvailable($appId)) { |
|
| 187 | 187 | try { |
| 188 | 188 | $this->downloadApp($appId); |
| 189 | 189 | } catch (\Exception $e) { |
@@ -210,18 +210,18 @@ discard block |
||
| 210 | 210 | $appId = strtolower($appId); |
| 211 | 211 | |
| 212 | 212 | $apps = $this->appFetcher->get(); |
| 213 | - foreach($apps as $app) { |
|
| 214 | - if($app['id'] === $appId) { |
|
| 213 | + foreach ($apps as $app) { |
|
| 214 | + if ($app['id'] === $appId) { |
|
| 215 | 215 | // Load the certificate |
| 216 | 216 | $certificate = new X509(); |
| 217 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 217 | + $certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
| 218 | 218 | $loadedCertificate = $certificate->loadX509($app['certificate']); |
| 219 | 219 | |
| 220 | 220 | // Verify if the certificate has been revoked |
| 221 | 221 | $crl = new X509(); |
| 222 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 223 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 224 | - if($crl->validateSignature() !== true) { |
|
| 222 | + $crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
| 223 | + $crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl')); |
|
| 224 | + if ($crl->validateSignature() !== true) { |
|
| 225 | 225 | throw new \Exception('Could not validate CRL signature'); |
| 226 | 226 | } |
| 227 | 227 | $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
| 239 | - if($certificate->validateSignature() !== true) { |
|
| 239 | + if ($certificate->validateSignature() !== true) { |
|
| 240 | 240 | throw new \Exception( |
| 241 | 241 | sprintf( |
| 242 | 242 | 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | // Verify if the certificate is issued for the requested app id |
| 249 | 249 | $certInfo = openssl_x509_parse($app['certificate']); |
| 250 | - if(!isset($certInfo['subject']['CN'])) { |
|
| 250 | + if (!isset($certInfo['subject']['CN'])) { |
|
| 251 | 251 | throw new \Exception( |
| 252 | 252 | sprintf( |
| 253 | 253 | 'App with id %s has a cert with no CN', |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | ) |
| 256 | 256 | ); |
| 257 | 257 | } |
| 258 | - if($certInfo['subject']['CN'] !== $appId) { |
|
| 258 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
| 259 | 259 | throw new \Exception( |
| 260 | 260 | sprintf( |
| 261 | 261 | 'App with id %s has a cert issued to %s', |
@@ -272,15 +272,15 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | // Check if the signature actually matches the downloaded content |
| 274 | 274 | $certificate = openssl_get_publickey($app['certificate']); |
| 275 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 275 | + $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 276 | 276 | openssl_free_key($certificate); |
| 277 | 277 | |
| 278 | - if($verified === true) { |
|
| 278 | + if ($verified === true) { |
|
| 279 | 279 | // Seems to match, let's proceed |
| 280 | 280 | $extractDir = $this->tempManager->getTemporaryFolder(); |
| 281 | 281 | $archive = new TAR($tempFile); |
| 282 | 282 | |
| 283 | - if($archive) { |
|
| 283 | + if ($archive) { |
|
| 284 | 284 | if (!$archive->extract($extractDir)) { |
| 285 | 285 | throw new \Exception( |
| 286 | 286 | sprintf( |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | $folders = array_diff($allFiles, ['.', '..']); |
| 294 | 294 | $folders = array_values($folders); |
| 295 | 295 | |
| 296 | - if(count($folders) > 1) { |
|
| 296 | + if (count($folders) > 1) { |
|
| 297 | 297 | throw new \Exception( |
| 298 | 298 | sprintf( |
| 299 | 299 | 'Extracted app %s has more than 1 folder', |
@@ -304,22 +304,22 @@ discard block |
||
| 304 | 304 | |
| 305 | 305 | // Check if appinfo/info.xml has the same app ID as well |
| 306 | 306 | $loadEntities = libxml_disable_entity_loader(false); |
| 307 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 307 | + $xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml'); |
|
| 308 | 308 | libxml_disable_entity_loader($loadEntities); |
| 309 | - if((string)$xml->id !== $appId) { |
|
| 309 | + if ((string) $xml->id !== $appId) { |
|
| 310 | 310 | throw new \Exception( |
| 311 | 311 | sprintf( |
| 312 | 312 | 'App for id %s has a wrong app ID in info.xml: %s', |
| 313 | 313 | $appId, |
| 314 | - (string)$xml->id |
|
| 314 | + (string) $xml->id |
|
| 315 | 315 | ) |
| 316 | 316 | ); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // Check if the version is lower than before |
| 320 | 320 | $currentVersion = OC_App::getAppVersion($appId); |
| 321 | - $newVersion = (string)$xml->version; |
|
| 322 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
| 321 | + $newVersion = (string) $xml->version; |
|
| 322 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
| 323 | 323 | throw new \Exception( |
| 324 | 324 | sprintf( |
| 325 | 325 | 'App for id %s has version %s and tried to update to lower version %s', |
@@ -330,12 +330,12 @@ discard block |
||
| 330 | 330 | ); |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 333 | + $baseDir = OC_App::getInstallPath().'/'.$appId; |
|
| 334 | 334 | // Remove old app with the ID if existent |
| 335 | 335 | OC_Helper::rmdirr($baseDir); |
| 336 | 336 | // Move to app folder |
| 337 | - if(@mkdir($baseDir)) { |
|
| 338 | - $extractDir .= '/' . $folders[0]; |
|
| 337 | + if (@mkdir($baseDir)) { |
|
| 338 | + $extractDir .= '/'.$folders[0]; |
|
| 339 | 339 | OC_Helper::copyr($extractDir, $baseDir); |
| 340 | 340 | } |
| 341 | 341 | OC_Helper::copyr($extractDir, $baseDir); |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | $this->apps = $this->appFetcher->get(); |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - foreach($this->apps as $app) { |
|
| 402 | - if($app['id'] === $appId) { |
|
| 401 | + foreach ($this->apps as $app) { |
|
| 402 | + if ($app['id'] === $appId) { |
|
| 403 | 403 | $currentVersion = OC_App::getAppVersion($appId); |
| 404 | 404 | $newestVersion = $app['releases'][0]['version']; |
| 405 | 405 | if (version_compare($newestVersion, $currentVersion, '>')) { |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | */ |
| 423 | 423 | private function isInstalledFromGit($appId) { |
| 424 | 424 | $app = \OC_App::findAppInDirectories($appId); |
| 425 | - if($app === false) { |
|
| 425 | + if ($app === false) { |
|
| 426 | 426 | return false; |
| 427 | 427 | } |
| 428 | 428 | $basedir = $app['path'].'/'.$appId; |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | * The function will check if the app is already downloaded in the apps repository |
| 438 | 438 | */ |
| 439 | 439 | public function isDownloaded($name) { |
| 440 | - foreach(\OC::$APPSROOTS as $dir) { |
|
| 440 | + foreach (\OC::$APPSROOTS as $dir) { |
|
| 441 | 441 | $dirToTest = $dir['path']; |
| 442 | 442 | $dirToTest .= '/'; |
| 443 | 443 | $dirToTest .= $name; |
@@ -465,14 +465,14 @@ discard block |
||
| 465 | 465 | * this has to be done by the function oc_app_uninstall(). |
| 466 | 466 | */ |
| 467 | 467 | public function removeApp($appId) { |
| 468 | - if($this->isDownloaded( $appId )) { |
|
| 468 | + if ($this->isDownloaded($appId)) { |
|
| 469 | 469 | if (\OC::$server->getAppManager()->isShipped($appId)) { |
| 470 | 470 | return false; |
| 471 | 471 | } |
| 472 | - $appDir = OC_App::getInstallPath() . '/' . $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( $filename[0] !== '.' 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 ($filename[0] !== '.' 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,10 +591,10 @@ 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 | |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | * @param string $script |
| 608 | 608 | */ |
| 609 | 609 | private static function includeAppScript($script) { |
| 610 | - if ( file_exists($script) ){ |
|
| 610 | + if (file_exists($script)) { |
|
| 611 | 611 | include $script; |
| 612 | 612 | } |
| 613 | 613 | } |