diff options
Diffstat (limited to 'lib/private/Installer.php')
-rw-r--r-- | lib/private/Installer.php | 73 |
1 files changed, 36 insertions, 37 deletions
diff --git a/lib/private/Installer.php b/lib/private/Installer.php index 78925a56a2e..d5c9d076eda 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -106,7 +106,7 @@ class Installer { */ public function installApp(string $appId, bool $forceEnable = false): string { $app = \OC_App::findAppInDirectories($appId); - if($app === false) { + if ($app === false) { throw new \Exception('App not found in any app directory'); } @@ -115,7 +115,7 @@ class Installer { $l = \OC::$server->getL10N('core'); - if(!is_array($info)) { + if (!is_array($info)) { throw new \Exception( $l->t('App "%s" cannot be installed because appinfo file cannot be read.', [$appId] @@ -146,7 +146,7 @@ class Installer { } //install the database - if(is_file($basedir.'/appinfo/database.xml')) { + if (is_file($basedir.'/appinfo/database.xml')) { if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); } else { @@ -173,10 +173,10 @@ class Installer { \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); //set remote/public handlers - foreach($info['remote'] as $name=>$path) { + foreach ($info['remote'] as $name=>$path) { \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); } - foreach($info['public'] as $name=>$path) { + foreach ($info['public'] as $name=>$path) { \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); } @@ -192,7 +192,7 @@ class Installer { * @return bool */ public function updateAppstoreApp($appId) { - if($this->isUpdateAvailable($appId)) { + if ($this->isUpdateAvailable($appId)) { try { $this->downloadApp($appId); } catch (\Exception $e) { @@ -219,8 +219,8 @@ class Installer { $appId = strtolower($appId); $apps = $this->appFetcher->get(); - foreach($apps as $app) { - if($app['id'] === $appId) { + foreach ($apps as $app) { + if ($app['id'] === $appId) { // Load the certificate $certificate = new X509(); $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); @@ -230,7 +230,7 @@ class Installer { $crl = new X509(); $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); - if($crl->validateSignature() !== true) { + if ($crl->validateSignature() !== true) { throw new \Exception('Could not validate CRL signature'); } $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); @@ -245,7 +245,7 @@ class Installer { } // Verify if the certificate has been issued by the Nextcloud Code Authority CA - if($certificate->validateSignature() !== true) { + if ($certificate->validateSignature() !== true) { throw new \Exception( sprintf( 'App with id %s has a certificate not issued by a trusted Code Signing Authority', @@ -256,7 +256,7 @@ class Installer { // Verify if the certificate is issued for the requested app id $certInfo = openssl_x509_parse($app['certificate']); - if(!isset($certInfo['subject']['CN'])) { + if (!isset($certInfo['subject']['CN'])) { throw new \Exception( sprintf( 'App with id %s has a cert with no CN', @@ -264,7 +264,7 @@ class Installer { ) ); } - if($certInfo['subject']['CN'] !== $appId) { + if ($certInfo['subject']['CN'] !== $appId) { throw new \Exception( sprintf( 'App with id %s has a cert issued to %s', @@ -285,12 +285,12 @@ class Installer { $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); openssl_free_key($certificate); - if($verified === true) { + if ($verified === true) { // Seems to match, let's proceed $extractDir = $this->tempManager->getTemporaryFolder(); $archive = new TAR($tempFile); - if($archive) { + if ($archive) { if (!$archive->extract($extractDir)) { throw new \Exception( sprintf( @@ -303,7 +303,7 @@ class Installer { $folders = array_diff($allFiles, ['.', '..']); $folders = array_values($folders); - if(count($folders) > 1) { + if (count($folders) > 1) { throw new \Exception( sprintf( 'Extracted app %s has more than 1 folder', @@ -316,7 +316,7 @@ class Installer { $loadEntities = libxml_disable_entity_loader(false); $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); libxml_disable_entity_loader($loadEntities); - if((string)$xml->id !== $appId) { + if ((string)$xml->id !== $appId) { throw new \Exception( sprintf( 'App for id %s has a wrong app ID in info.xml: %s', @@ -329,7 +329,7 @@ class Installer { // Check if the version is lower than before $currentVersion = OC_App::getAppVersion($appId); $newVersion = (string)$xml->version; - if(version_compare($currentVersion, $newVersion) === 1) { + if (version_compare($currentVersion, $newVersion) === 1) { throw new \Exception( sprintf( 'App for id %s has version %s and tried to update to lower version %s', @@ -344,7 +344,7 @@ class Installer { // Remove old app with the ID if existent OC_Helper::rmdirr($baseDir); // Move to app folder - if(@mkdir($baseDir)) { + if (@mkdir($baseDir)) { $extractDir .= '/' . $folders[0]; OC_Helper::copyr($extractDir, $baseDir); } @@ -408,8 +408,8 @@ class Installer { $this->apps = $this->appFetcher->get(); } - foreach($this->apps as $app) { - if($app['id'] === $appId) { + foreach ($this->apps as $app) { + if ($app['id'] === $appId) { $currentVersion = OC_App::getAppVersion($appId); if (!isset($app['releases'][0]['version'])) { @@ -436,7 +436,7 @@ class Installer { */ private function isInstalledFromGit($appId) { $app = \OC_App::findAppInDirectories($appId); - if($app === false) { + if ($app === false) { return false; } $basedir = $app['path'].'/'.$appId; @@ -451,7 +451,7 @@ class Installer { * The function will check if the app is already downloaded in the apps repository */ public function isDownloaded($name) { - foreach(\OC::$APPSROOTS as $dir) { + foreach (\OC::$APPSROOTS as $dir) { $dirToTest = $dir['path']; $dirToTest .= '/'; $dirToTest .= $name; @@ -479,19 +479,18 @@ class Installer { * this has to be done by the function oc_app_uninstall(). */ public function removeApp($appId) { - if($this->isDownloaded($appId)) { + if ($this->isDownloaded($appId)) { if (\OC::$server->getAppManager()->isShipped($appId)) { return false; } $appDir = OC_App::getInstallPath() . '/' . $appId; OC_Helper::rmdirr($appDir); return true; - }else{ + } else { \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR); return false; } - } /** @@ -502,8 +501,8 @@ class Installer { */ public function installAppBundle(Bundle $bundle) { $appIds = $bundle->getAppIdentifiers(); - foreach($appIds as $appId) { - if(!$this->isDownloaded($appId)) { + foreach ($appIds as $appId) { + if (!$this->isDownloaded($appId)) { $this->downloadApp($appId); } $this->installApp($appId); @@ -527,12 +526,12 @@ class Installer { $appManager = \OC::$server->getAppManager(); $config = \OC::$server->getConfig(); $errors = []; - foreach(\OC::$APPSROOTS as $app_dir) { - if($dir = opendir($app_dir['path'])) { - while(false !== ($filename = readdir($dir))) { - if($filename[0] !== '.' and is_dir($app_dir['path']."/$filename")) { - if(file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { - if($config->getAppValue($filename, "installed_version", null) === null) { + foreach (\OC::$APPSROOTS as $app_dir) { + if ($dir = opendir($app_dir['path'])) { + while (false !== ($filename = readdir($dir))) { + if ($filename[0] !== '.' and is_dir($app_dir['path']."/$filename")) { + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { + if ($config->getAppValue($filename, "installed_version", null) === null) { $info=OC_App::getAppInfo($filename); $enabled = isset($info['default_enable']); if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps())) @@ -573,7 +572,7 @@ class Installer { $appPath = OC_App::getAppPath($app); \OC_App::registerAutoloading($app, $appPath); - if(is_file("$appPath/appinfo/database.xml")) { + if (is_file("$appPath/appinfo/database.xml")) { try { OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); } catch (TableExistsException $e) { @@ -607,10 +606,10 @@ class Installer { } //set remote/public handlers - foreach($info['remote'] as $name=>$path) { + foreach ($info['remote'] as $name=>$path) { $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); } - foreach($info['public'] as $name=>$path) { + foreach ($info['public'] as $name=>$path) { $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); } @@ -623,7 +622,7 @@ class Installer { * @param string $script */ private static function includeAppScript($script) { - if (file_exists($script)){ + if (file_exists($script)) { include $script; } } |