@@ -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] |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | \OC_App::registerAutoloading($appId, $basedir); |
131 | 131 | |
132 | 132 | //install the database |
133 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
133 | + if (is_file($basedir.'/appinfo/database.xml')) { |
|
134 | 134 | if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
135 | 135 | OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
136 | 136 | } else { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | \OC_App::setupBackgroundJobs($info['background-jobs']); |
145 | 145 | |
146 | 146 | //run appinfo/install.php |
147 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
147 | + self::includeAppScript($basedir.'/appinfo/install.php'); |
|
148 | 148 | |
149 | 149 | $appData = OC_App::getAppInfo($appId); |
150 | 150 | OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
155 | 155 | |
156 | 156 | //set remote/public handlers |
157 | - foreach($info['remote'] as $name=>$path) { |
|
157 | + foreach ($info['remote'] as $name=>$path) { |
|
158 | 158 | \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
159 | 159 | } |
160 | - foreach($info['public'] as $name=>$path) { |
|
160 | + foreach ($info['public'] as $name=>$path) { |
|
161 | 161 | \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
162 | 162 | } |
163 | 163 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @return bool |
174 | 174 | */ |
175 | 175 | public function updateAppstoreApp($appId) { |
176 | - if($this->isUpdateAvailable($appId)) { |
|
176 | + if ($this->isUpdateAvailable($appId)) { |
|
177 | 177 | try { |
178 | 178 | $this->downloadApp($appId); |
179 | 179 | } catch (\Exception $e) { |
@@ -200,18 +200,18 @@ discard block |
||
200 | 200 | $appId = strtolower($appId); |
201 | 201 | |
202 | 202 | $apps = $this->appFetcher->get(); |
203 | - foreach($apps as $app) { |
|
204 | - if($app['id'] === $appId) { |
|
203 | + foreach ($apps as $app) { |
|
204 | + if ($app['id'] === $appId) { |
|
205 | 205 | // Load the certificate |
206 | 206 | $certificate = new X509(); |
207 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
207 | + $certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
208 | 208 | $loadedCertificate = $certificate->loadX509($app['certificate']); |
209 | 209 | |
210 | 210 | // Verify if the certificate has been revoked |
211 | 211 | $crl = new X509(); |
212 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
213 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
214 | - if($crl->validateSignature() !== true) { |
|
212 | + $crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
213 | + $crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl')); |
|
214 | + if ($crl->validateSignature() !== true) { |
|
215 | 215 | throw new \Exception('Could not validate CRL signature'); |
216 | 216 | } |
217 | 217 | $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
229 | - if($certificate->validateSignature() !== true) { |
|
229 | + if ($certificate->validateSignature() !== true) { |
|
230 | 230 | throw new \Exception( |
231 | 231 | sprintf( |
232 | 232 | 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | // Verify if the certificate is issued for the requested app id |
239 | 239 | $certInfo = openssl_x509_parse($app['certificate']); |
240 | - if(!isset($certInfo['subject']['CN'])) { |
|
240 | + if (!isset($certInfo['subject']['CN'])) { |
|
241 | 241 | throw new \Exception( |
242 | 242 | sprintf( |
243 | 243 | 'App with id %s has a cert with no CN', |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | ) |
246 | 246 | ); |
247 | 247 | } |
248 | - if($certInfo['subject']['CN'] !== $appId) { |
|
248 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
249 | 249 | throw new \Exception( |
250 | 250 | sprintf( |
251 | 251 | 'App with id %s has a cert issued to %s', |
@@ -262,15 +262,15 @@ discard block |
||
262 | 262 | |
263 | 263 | // Check if the signature actually matches the downloaded content |
264 | 264 | $certificate = openssl_get_publickey($app['certificate']); |
265 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
265 | + $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
266 | 266 | openssl_free_key($certificate); |
267 | 267 | |
268 | - if($verified === true) { |
|
268 | + if ($verified === true) { |
|
269 | 269 | // Seems to match, let's proceed |
270 | 270 | $extractDir = $this->tempManager->getTemporaryFolder(); |
271 | 271 | $archive = new TAR($tempFile); |
272 | 272 | |
273 | - if($archive) { |
|
273 | + if ($archive) { |
|
274 | 274 | if (!$archive->extract($extractDir)) { |
275 | 275 | throw new \Exception( |
276 | 276 | sprintf( |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | $folders = array_diff($allFiles, ['.', '..']); |
284 | 284 | $folders = array_values($folders); |
285 | 285 | |
286 | - if(count($folders) > 1) { |
|
286 | + if (count($folders) > 1) { |
|
287 | 287 | throw new \Exception( |
288 | 288 | sprintf( |
289 | 289 | 'Extracted app %s has more than 1 folder', |
@@ -294,22 +294,22 @@ discard block |
||
294 | 294 | |
295 | 295 | // Check if appinfo/info.xml has the same app ID as well |
296 | 296 | $loadEntities = libxml_disable_entity_loader(false); |
297 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
297 | + $xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml'); |
|
298 | 298 | libxml_disable_entity_loader($loadEntities); |
299 | - if((string)$xml->id !== $appId) { |
|
299 | + if ((string) $xml->id !== $appId) { |
|
300 | 300 | throw new \Exception( |
301 | 301 | sprintf( |
302 | 302 | 'App for id %s has a wrong app ID in info.xml: %s', |
303 | 303 | $appId, |
304 | - (string)$xml->id |
|
304 | + (string) $xml->id |
|
305 | 305 | ) |
306 | 306 | ); |
307 | 307 | } |
308 | 308 | |
309 | 309 | // Check if the version is lower than before |
310 | 310 | $currentVersion = OC_App::getAppVersion($appId); |
311 | - $newVersion = (string)$xml->version; |
|
312 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
311 | + $newVersion = (string) $xml->version; |
|
312 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
313 | 313 | throw new \Exception( |
314 | 314 | sprintf( |
315 | 315 | 'App for id %s has version %s and tried to update to lower version %s', |
@@ -320,12 +320,12 @@ discard block |
||
320 | 320 | ); |
321 | 321 | } |
322 | 322 | |
323 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
323 | + $baseDir = OC_App::getInstallPath().'/'.$appId; |
|
324 | 324 | // Remove old app with the ID if existent |
325 | 325 | OC_Helper::rmdirr($baseDir); |
326 | 326 | // Move to app folder |
327 | - if(@mkdir($baseDir)) { |
|
328 | - $extractDir .= '/' . $folders[0]; |
|
327 | + if (@mkdir($baseDir)) { |
|
328 | + $extractDir .= '/'.$folders[0]; |
|
329 | 329 | OC_Helper::copyr($extractDir, $baseDir); |
330 | 330 | } |
331 | 331 | OC_Helper::copyr($extractDir, $baseDir); |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | $this->apps = $this->appFetcher->get(); |
389 | 389 | } |
390 | 390 | |
391 | - foreach($this->apps as $app) { |
|
392 | - if($app['id'] === $appId) { |
|
391 | + foreach ($this->apps as $app) { |
|
392 | + if ($app['id'] === $appId) { |
|
393 | 393 | $currentVersion = OC_App::getAppVersion($appId); |
394 | 394 | |
395 | 395 | if (!isset($app['releases'][0]['version'])) { |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | */ |
417 | 417 | private function isInstalledFromGit($appId) { |
418 | 418 | $app = \OC_App::findAppInDirectories($appId); |
419 | - if($app === false) { |
|
419 | + if ($app === false) { |
|
420 | 420 | return false; |
421 | 421 | } |
422 | 422 | $basedir = $app['path'].'/'.$appId; |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | * The function will check if the app is already downloaded in the apps repository |
432 | 432 | */ |
433 | 433 | public function isDownloaded($name) { |
434 | - foreach(\OC::$APPSROOTS as $dir) { |
|
434 | + foreach (\OC::$APPSROOTS as $dir) { |
|
435 | 435 | $dirToTest = $dir['path']; |
436 | 436 | $dirToTest .= '/'; |
437 | 437 | $dirToTest .= $name; |
@@ -459,14 +459,14 @@ discard block |
||
459 | 459 | * this has to be done by the function oc_app_uninstall(). |
460 | 460 | */ |
461 | 461 | public function removeApp($appId) { |
462 | - if($this->isDownloaded( $appId )) { |
|
462 | + if ($this->isDownloaded($appId)) { |
|
463 | 463 | if (\OC::$server->getAppManager()->isShipped($appId)) { |
464 | 464 | return false; |
465 | 465 | } |
466 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
466 | + $appDir = OC_App::getInstallPath().'/'.$appId; |
|
467 | 467 | OC_Helper::rmdirr($appDir); |
468 | 468 | return true; |
469 | - }else{ |
|
469 | + } else { |
|
470 | 470 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR); |
471 | 471 | |
472 | 472 | return false; |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | */ |
483 | 483 | public function installAppBundle(Bundle $bundle) { |
484 | 484 | $appIds = $bundle->getAppIdentifiers(); |
485 | - foreach($appIds as $appId) { |
|
486 | - if(!$this->isDownloaded($appId)) { |
|
485 | + foreach ($appIds as $appId) { |
|
486 | + if (!$this->isDownloaded($appId)) { |
|
487 | 487 | $this->downloadApp($appId); |
488 | 488 | } |
489 | 489 | $this->installApp($appId); |
@@ -507,13 +507,13 @@ discard block |
||
507 | 507 | $appManager = \OC::$server->getAppManager(); |
508 | 508 | $config = \OC::$server->getConfig(); |
509 | 509 | $errors = []; |
510 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
511 | - if($dir = opendir( $app_dir['path'] )) { |
|
512 | - while( false !== ( $filename = readdir( $dir ))) { |
|
513 | - if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
514 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
515 | - if($config->getAppValue($filename, "installed_version", null) === null) { |
|
516 | - $info=OC_App::getAppInfo($filename); |
|
510 | + foreach (\OC::$APPSROOTS as $app_dir) { |
|
511 | + if ($dir = opendir($app_dir['path'])) { |
|
512 | + while (false !== ($filename = readdir($dir))) { |
|
513 | + if ($filename[0] !== '.' and is_dir($app_dir['path']."/$filename")) { |
|
514 | + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
515 | + if ($config->getAppValue($filename, "installed_version", null) === null) { |
|
516 | + $info = OC_App::getAppInfo($filename); |
|
517 | 517 | $enabled = isset($info['default_enable']); |
518 | 518 | if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps())) |
519 | 519 | && $config->getAppValue($filename, 'enabled') !== 'no') { |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | } |
537 | 537 | } |
538 | 538 | } |
539 | - closedir( $dir ); |
|
539 | + closedir($dir); |
|
540 | 540 | } |
541 | 541 | } |
542 | 542 | |
@@ -553,12 +553,12 @@ discard block |
||
553 | 553 | $appPath = OC_App::getAppPath($app); |
554 | 554 | \OC_App::registerAutoloading($app, $appPath); |
555 | 555 | |
556 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
556 | + if (is_file("$appPath/appinfo/database.xml")) { |
|
557 | 557 | try { |
558 | 558 | OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
559 | 559 | } catch (TableExistsException $e) { |
560 | 560 | throw new HintException( |
561 | - 'Failed to enable app ' . $app, |
|
561 | + 'Failed to enable app '.$app, |
|
562 | 562 | 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
563 | 563 | 0, $e |
564 | 564 | ); |
@@ -587,10 +587,10 @@ discard block |
||
587 | 587 | } |
588 | 588 | |
589 | 589 | //set remote/public handlers |
590 | - foreach($info['remote'] as $name=>$path) { |
|
590 | + foreach ($info['remote'] as $name=>$path) { |
|
591 | 591 | $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
592 | 592 | } |
593 | - foreach($info['public'] as $name=>$path) { |
|
593 | + foreach ($info['public'] as $name=>$path) { |
|
594 | 594 | $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
595 | 595 | } |
596 | 596 | |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @param string $script |
604 | 604 | */ |
605 | 605 | private static function includeAppScript($script) { |
606 | - if ( file_exists($script) ){ |
|
606 | + if (file_exists($script)) { |
|
607 | 607 | include $script; |
608 | 608 | } |
609 | 609 | } |