@@ -32,17 +32,17 @@ |
||
| 32 | 32 | |
| 33 | 33 | class CleanupLoginFlowV2 extends TimedJob { |
| 34 | 34 | |
| 35 | - /** @var LoginFlowV2Mapper */ |
|
| 36 | - private $loginFlowV2Mapper; |
|
| 35 | + /** @var LoginFlowV2Mapper */ |
|
| 36 | + private $loginFlowV2Mapper; |
|
| 37 | 37 | |
| 38 | - public function __construct(ITimeFactory $time, LoginFlowV2Mapper $loginFlowV2Mapper) { |
|
| 39 | - parent::__construct($time); |
|
| 40 | - $this->loginFlowV2Mapper = $loginFlowV2Mapper; |
|
| 38 | + public function __construct(ITimeFactory $time, LoginFlowV2Mapper $loginFlowV2Mapper) { |
|
| 39 | + parent::__construct($time); |
|
| 40 | + $this->loginFlowV2Mapper = $loginFlowV2Mapper; |
|
| 41 | 41 | |
| 42 | - $this->setInterval(3600); |
|
| 43 | - } |
|
| 42 | + $this->setInterval(3600); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - protected function run($argument): void { |
|
| 46 | - $this->loginFlowV2Mapper->cleanup(); |
|
| 47 | - } |
|
| 45 | + protected function run($argument): void { |
|
| 46 | + $this->loginFlowV2Mapper->cleanup(); |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -34,63 +34,63 @@ |
||
| 34 | 34 | |
| 35 | 35 | class BackgroundCleanupUpdaterBackupsJob extends QueuedJob { |
| 36 | 36 | |
| 37 | - /** @var IConfig */ |
|
| 38 | - protected $config; |
|
| 39 | - /** @var ILogger */ |
|
| 40 | - protected $log; |
|
| 41 | - |
|
| 42 | - public function __construct(IConfig $config, ILogger $log) { |
|
| 43 | - $this->config = $config; |
|
| 44 | - $this->log = $log; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * This job cleans up all backups except the latest 3 from the updaters backup directory |
|
| 49 | - * |
|
| 50 | - */ |
|
| 51 | - public function run($arguments) { |
|
| 52 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
| 53 | - $instanceId = $this->config->getSystemValue('instanceid', null); |
|
| 54 | - |
|
| 55 | - if (!is_string($instanceId) || empty($instanceId)) { |
|
| 56 | - return; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
| 60 | - $backupFolderPath = $updaterFolderPath . '/backups'; |
|
| 61 | - if (file_exists($backupFolderPath)) { |
|
| 62 | - $this->log->info("$backupFolderPath exists - start to clean it up"); |
|
| 63 | - |
|
| 64 | - $dirList = []; |
|
| 65 | - $dirs = new \DirectoryIterator($backupFolderPath); |
|
| 66 | - foreach ($dirs as $dir) { |
|
| 67 | - // skip files and dot dirs |
|
| 68 | - if ($dir->isFile() || $dir->isDot()) { |
|
| 69 | - continue; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $mtime = $dir->getMTime(); |
|
| 73 | - $realPath = $dir->getRealPath(); |
|
| 74 | - |
|
| 75 | - if ($realPath === false) { |
|
| 76 | - continue; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $dirList[$mtime] = $realPath; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - ksort($dirList); |
|
| 83 | - // drop the newest 3 directories |
|
| 84 | - $dirList = array_slice($dirList, 0, -3); |
|
| 85 | - $this->log->info("List of all directories that will be deleted: " . json_encode($dirList)); |
|
| 86 | - |
|
| 87 | - foreach ($dirList as $dir) { |
|
| 88 | - $this->log->info("Removing $dir ..."); |
|
| 89 | - \OC_Helper::rmdirr($dir); |
|
| 90 | - } |
|
| 91 | - $this->log->info("Cleanup finished"); |
|
| 92 | - } else { |
|
| 93 | - $this->log->info("Could not find updater directory $backupFolderPath - cleanup step not needed"); |
|
| 94 | - } |
|
| 95 | - } |
|
| 37 | + /** @var IConfig */ |
|
| 38 | + protected $config; |
|
| 39 | + /** @var ILogger */ |
|
| 40 | + protected $log; |
|
| 41 | + |
|
| 42 | + public function __construct(IConfig $config, ILogger $log) { |
|
| 43 | + $this->config = $config; |
|
| 44 | + $this->log = $log; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * This job cleans up all backups except the latest 3 from the updaters backup directory |
|
| 49 | + * |
|
| 50 | + */ |
|
| 51 | + public function run($arguments) { |
|
| 52 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
| 53 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
|
| 54 | + |
|
| 55 | + if (!is_string($instanceId) || empty($instanceId)) { |
|
| 56 | + return; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
| 60 | + $backupFolderPath = $updaterFolderPath . '/backups'; |
|
| 61 | + if (file_exists($backupFolderPath)) { |
|
| 62 | + $this->log->info("$backupFolderPath exists - start to clean it up"); |
|
| 63 | + |
|
| 64 | + $dirList = []; |
|
| 65 | + $dirs = new \DirectoryIterator($backupFolderPath); |
|
| 66 | + foreach ($dirs as $dir) { |
|
| 67 | + // skip files and dot dirs |
|
| 68 | + if ($dir->isFile() || $dir->isDot()) { |
|
| 69 | + continue; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $mtime = $dir->getMTime(); |
|
| 73 | + $realPath = $dir->getRealPath(); |
|
| 74 | + |
|
| 75 | + if ($realPath === false) { |
|
| 76 | + continue; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $dirList[$mtime] = $realPath; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + ksort($dirList); |
|
| 83 | + // drop the newest 3 directories |
|
| 84 | + $dirList = array_slice($dirList, 0, -3); |
|
| 85 | + $this->log->info("List of all directories that will be deleted: " . json_encode($dirList)); |
|
| 86 | + |
|
| 87 | + foreach ($dirList as $dir) { |
|
| 88 | + $this->log->info("Removing $dir ..."); |
|
| 89 | + \OC_Helper::rmdirr($dir); |
|
| 90 | + } |
|
| 91 | + $this->log->info("Cleanup finished"); |
|
| 92 | + } else { |
|
| 93 | + $this->log->info("Could not find updater directory $backupFolderPath - cleanup step not needed"); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -36,47 +36,47 @@ |
||
| 36 | 36 | |
| 37 | 37 | class CheckForUserCertificates extends QueuedJob { |
| 38 | 38 | |
| 39 | - /** @var IConfig */ |
|
| 40 | - protected $config; |
|
| 41 | - /** @var IUserManager */ |
|
| 42 | - private $userManager; |
|
| 43 | - /** @var IRootFolder */ |
|
| 44 | - private $rootFolder; |
|
| 39 | + /** @var IConfig */ |
|
| 40 | + protected $config; |
|
| 41 | + /** @var IUserManager */ |
|
| 42 | + private $userManager; |
|
| 43 | + /** @var IRootFolder */ |
|
| 44 | + private $rootFolder; |
|
| 45 | 45 | |
| 46 | - public function __construct(IConfig $config, IUserManager $userManager, IRootFolder $rootFolder) { |
|
| 47 | - $this->config = $config; |
|
| 48 | - $this->userManager = $userManager; |
|
| 49 | - $this->rootFolder = $rootFolder; |
|
| 50 | - } |
|
| 46 | + public function __construct(IConfig $config, IUserManager $userManager, IRootFolder $rootFolder) { |
|
| 47 | + $this->config = $config; |
|
| 48 | + $this->userManager = $userManager; |
|
| 49 | + $this->rootFolder = $rootFolder; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Checks all user directories for old user uploaded certificates |
|
| 54 | - */ |
|
| 55 | - public function run($arguments): void { |
|
| 56 | - $uploadList = []; |
|
| 57 | - $this->userManager->callForSeenUsers(function (IUser $user) use (&$uploadList) { |
|
| 58 | - $userId = $user->getUID(); |
|
| 59 | - try { |
|
| 60 | - \OC_Util::setupFS($userId); |
|
| 61 | - $filesExternalUploadsFolder = $this->rootFolder->get($userId . '/files_external/uploads'); |
|
| 62 | - } catch (NotFoundException $e) { |
|
| 63 | - \OC_Util::tearDownFS(); |
|
| 64 | - return; |
|
| 65 | - } |
|
| 66 | - if ($filesExternalUploadsFolder instanceof Folder) { |
|
| 67 | - $files = $filesExternalUploadsFolder->getDirectoryListing(); |
|
| 68 | - foreach ($files as $file) { |
|
| 69 | - $filename = $file->getName(); |
|
| 70 | - $uploadList[] = "$userId/files_external/uploads/$filename"; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - \OC_Util::tearDownFS(); |
|
| 74 | - }); |
|
| 52 | + /** |
|
| 53 | + * Checks all user directories for old user uploaded certificates |
|
| 54 | + */ |
|
| 55 | + public function run($arguments): void { |
|
| 56 | + $uploadList = []; |
|
| 57 | + $this->userManager->callForSeenUsers(function (IUser $user) use (&$uploadList) { |
|
| 58 | + $userId = $user->getUID(); |
|
| 59 | + try { |
|
| 60 | + \OC_Util::setupFS($userId); |
|
| 61 | + $filesExternalUploadsFolder = $this->rootFolder->get($userId . '/files_external/uploads'); |
|
| 62 | + } catch (NotFoundException $e) { |
|
| 63 | + \OC_Util::tearDownFS(); |
|
| 64 | + return; |
|
| 65 | + } |
|
| 66 | + if ($filesExternalUploadsFolder instanceof Folder) { |
|
| 67 | + $files = $filesExternalUploadsFolder->getDirectoryListing(); |
|
| 68 | + foreach ($files as $file) { |
|
| 69 | + $filename = $file->getName(); |
|
| 70 | + $uploadList[] = "$userId/files_external/uploads/$filename"; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + \OC_Util::tearDownFS(); |
|
| 74 | + }); |
|
| 75 | 75 | |
| 76 | - if (empty($uploadList)) { |
|
| 77 | - $this->config->deleteAppValue('files_external', 'user_certificate_scan'); |
|
| 78 | - } else { |
|
| 79 | - $this->config->setAppValue('files_external', 'user_certificate_scan', json_encode($uploadList)); |
|
| 80 | - } |
|
| 81 | - } |
|
| 76 | + if (empty($uploadList)) { |
|
| 77 | + $this->config->deleteAppValue('files_external', 'user_certificate_scan'); |
|
| 78 | + } else { |
|
| 79 | + $this->config->setAppValue('files_external', 'user_certificate_scan', json_encode($uploadList)); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -54,11 +54,11 @@ |
||
| 54 | 54 | */ |
| 55 | 55 | public function run($arguments): void { |
| 56 | 56 | $uploadList = []; |
| 57 | - $this->userManager->callForSeenUsers(function (IUser $user) use (&$uploadList) { |
|
| 57 | + $this->userManager->callForSeenUsers(function(IUser $user) use (&$uploadList) { |
|
| 58 | 58 | $userId = $user->getUID(); |
| 59 | 59 | try { |
| 60 | 60 | \OC_Util::setupFS($userId); |
| 61 | - $filesExternalUploadsFolder = $this->rootFolder->get($userId . '/files_external/uploads'); |
|
| 61 | + $filesExternalUploadsFolder = $this->rootFolder->get($userId.'/files_external/uploads'); |
|
| 62 | 62 | } catch (NotFoundException $e) { |
| 63 | 63 | \OC_Util::tearDownFS(); |
| 64 | 64 | return; |
@@ -45,177 +45,177 @@ |
||
| 45 | 45 | */ |
| 46 | 46 | class Defaults { |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * \OC_Defaults instance to retrieve the defaults |
|
| 50 | - * @since 6.0.0 |
|
| 51 | - */ |
|
| 52 | - private $defaults; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * creates a \OC_Defaults instance which is used in all methods to retrieve the |
|
| 56 | - * actual defaults |
|
| 57 | - * @since 6.0.0 |
|
| 58 | - */ |
|
| 59 | - public function __construct(\OC_Defaults $defaults = null) { |
|
| 60 | - if ($defaults === null) { |
|
| 61 | - $defaults = \OC::$server->getThemingDefaults(); |
|
| 62 | - } |
|
| 63 | - $this->defaults = $defaults; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * get base URL for the organisation behind your ownCloud instance |
|
| 68 | - * @return string |
|
| 69 | - * @since 6.0.0 |
|
| 70 | - */ |
|
| 71 | - public function getBaseUrl(): string { |
|
| 72 | - return $this->defaults->getBaseUrl(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * link to the desktop sync client |
|
| 77 | - * @return string |
|
| 78 | - * @since 6.0.0 |
|
| 79 | - */ |
|
| 80 | - public function getSyncClientUrl(): string { |
|
| 81 | - return $this->defaults->getSyncClientUrl(); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * link to the iOS client |
|
| 86 | - * @return string |
|
| 87 | - * @since 8.0.0 |
|
| 88 | - */ |
|
| 89 | - public function getiOSClientUrl(): string { |
|
| 90 | - return $this->defaults->getiOSClientUrl(); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * link to the Android client |
|
| 95 | - * @return string |
|
| 96 | - * @since 8.0.0 |
|
| 97 | - */ |
|
| 98 | - public function getAndroidClientUrl(): string { |
|
| 99 | - return $this->defaults->getAndroidClientUrl(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * base URL to the documentation of your ownCloud instance |
|
| 104 | - * @return string |
|
| 105 | - * @since 6.0.0 |
|
| 106 | - */ |
|
| 107 | - public function getDocBaseUrl(): string { |
|
| 108 | - return $this->defaults->getDocBaseUrl(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * name of your ownCloud instance |
|
| 113 | - * @return string |
|
| 114 | - * @since 6.0.0 |
|
| 115 | - */ |
|
| 116 | - public function getName(): string { |
|
| 117 | - return $this->defaults->getName(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * name of your ownCloud instance containing HTML styles |
|
| 122 | - * @return string |
|
| 123 | - * @since 8.0.0 |
|
| 124 | - * @depreacted 22.0.0 |
|
| 125 | - */ |
|
| 126 | - public function getHTMLName(): string { |
|
| 127 | - return $this->defaults->getHTMLName(); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Entity behind your onwCloud instance |
|
| 132 | - * @return string |
|
| 133 | - * @since 6.0.0 |
|
| 134 | - */ |
|
| 135 | - public function getEntity(): string { |
|
| 136 | - return $this->defaults->getEntity(); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * ownCloud slogan |
|
| 141 | - * @return string |
|
| 142 | - * @since 6.0.0 |
|
| 143 | - */ |
|
| 144 | - public function getSlogan(?string $lang = null): string { |
|
| 145 | - return $this->defaults->getSlogan($lang); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * footer, short version |
|
| 150 | - * @return string |
|
| 151 | - * @since 6.0.0 |
|
| 152 | - */ |
|
| 153 | - public function getShortFooter(): string { |
|
| 154 | - return $this->defaults->getShortFooter(); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * footer, long version |
|
| 159 | - * @return string |
|
| 160 | - * @since 6.0.0 |
|
| 161 | - */ |
|
| 162 | - public function getLongFooter(): string { |
|
| 163 | - return $this->defaults->getLongFooter(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Returns the AppId for the App Store for the iOS Client |
|
| 168 | - * @return string AppId |
|
| 169 | - * @since 8.0.0 |
|
| 170 | - */ |
|
| 171 | - public function getiTunesAppId(): string { |
|
| 172 | - return $this->defaults->getiTunesAppId(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Themed logo url |
|
| 177 | - * |
|
| 178 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 179 | - * @return string |
|
| 180 | - * @since 12.0.0 |
|
| 181 | - */ |
|
| 182 | - public function getLogo(bool $useSvg = true): string { |
|
| 183 | - return $this->defaults->getLogo($useSvg); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Returns primary color |
|
| 188 | - * @return string |
|
| 189 | - * @since 12.0.0 |
|
| 190 | - */ |
|
| 191 | - public function getColorPrimary(): string { |
|
| 192 | - return $this->defaults->getColorPrimary(); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param string $key |
|
| 197 | - * @return string URL to doc with key |
|
| 198 | - * @since 12.0.0 |
|
| 199 | - */ |
|
| 200 | - public function buildDocLinkToKey(string $key): string { |
|
| 201 | - return $this->defaults->buildDocLinkToKey($key); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Returns the title |
|
| 206 | - * @return string title |
|
| 207 | - * @since 12.0.0 |
|
| 208 | - */ |
|
| 209 | - public function getTitle(): string { |
|
| 210 | - return $this->defaults->getTitle(); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Returns primary color |
|
| 215 | - * @return string |
|
| 216 | - * @since 13.0.0 |
|
| 217 | - */ |
|
| 218 | - public function getTextColorPrimary(): string { |
|
| 219 | - return $this->defaults->getTextColorPrimary(); |
|
| 220 | - } |
|
| 48 | + /** |
|
| 49 | + * \OC_Defaults instance to retrieve the defaults |
|
| 50 | + * @since 6.0.0 |
|
| 51 | + */ |
|
| 52 | + private $defaults; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * creates a \OC_Defaults instance which is used in all methods to retrieve the |
|
| 56 | + * actual defaults |
|
| 57 | + * @since 6.0.0 |
|
| 58 | + */ |
|
| 59 | + public function __construct(\OC_Defaults $defaults = null) { |
|
| 60 | + if ($defaults === null) { |
|
| 61 | + $defaults = \OC::$server->getThemingDefaults(); |
|
| 62 | + } |
|
| 63 | + $this->defaults = $defaults; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * get base URL for the organisation behind your ownCloud instance |
|
| 68 | + * @return string |
|
| 69 | + * @since 6.0.0 |
|
| 70 | + */ |
|
| 71 | + public function getBaseUrl(): string { |
|
| 72 | + return $this->defaults->getBaseUrl(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * link to the desktop sync client |
|
| 77 | + * @return string |
|
| 78 | + * @since 6.0.0 |
|
| 79 | + */ |
|
| 80 | + public function getSyncClientUrl(): string { |
|
| 81 | + return $this->defaults->getSyncClientUrl(); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * link to the iOS client |
|
| 86 | + * @return string |
|
| 87 | + * @since 8.0.0 |
|
| 88 | + */ |
|
| 89 | + public function getiOSClientUrl(): string { |
|
| 90 | + return $this->defaults->getiOSClientUrl(); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * link to the Android client |
|
| 95 | + * @return string |
|
| 96 | + * @since 8.0.0 |
|
| 97 | + */ |
|
| 98 | + public function getAndroidClientUrl(): string { |
|
| 99 | + return $this->defaults->getAndroidClientUrl(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * base URL to the documentation of your ownCloud instance |
|
| 104 | + * @return string |
|
| 105 | + * @since 6.0.0 |
|
| 106 | + */ |
|
| 107 | + public function getDocBaseUrl(): string { |
|
| 108 | + return $this->defaults->getDocBaseUrl(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * name of your ownCloud instance |
|
| 113 | + * @return string |
|
| 114 | + * @since 6.0.0 |
|
| 115 | + */ |
|
| 116 | + public function getName(): string { |
|
| 117 | + return $this->defaults->getName(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * name of your ownCloud instance containing HTML styles |
|
| 122 | + * @return string |
|
| 123 | + * @since 8.0.0 |
|
| 124 | + * @depreacted 22.0.0 |
|
| 125 | + */ |
|
| 126 | + public function getHTMLName(): string { |
|
| 127 | + return $this->defaults->getHTMLName(); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Entity behind your onwCloud instance |
|
| 132 | + * @return string |
|
| 133 | + * @since 6.0.0 |
|
| 134 | + */ |
|
| 135 | + public function getEntity(): string { |
|
| 136 | + return $this->defaults->getEntity(); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * ownCloud slogan |
|
| 141 | + * @return string |
|
| 142 | + * @since 6.0.0 |
|
| 143 | + */ |
|
| 144 | + public function getSlogan(?string $lang = null): string { |
|
| 145 | + return $this->defaults->getSlogan($lang); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * footer, short version |
|
| 150 | + * @return string |
|
| 151 | + * @since 6.0.0 |
|
| 152 | + */ |
|
| 153 | + public function getShortFooter(): string { |
|
| 154 | + return $this->defaults->getShortFooter(); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * footer, long version |
|
| 159 | + * @return string |
|
| 160 | + * @since 6.0.0 |
|
| 161 | + */ |
|
| 162 | + public function getLongFooter(): string { |
|
| 163 | + return $this->defaults->getLongFooter(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Returns the AppId for the App Store for the iOS Client |
|
| 168 | + * @return string AppId |
|
| 169 | + * @since 8.0.0 |
|
| 170 | + */ |
|
| 171 | + public function getiTunesAppId(): string { |
|
| 172 | + return $this->defaults->getiTunesAppId(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Themed logo url |
|
| 177 | + * |
|
| 178 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 179 | + * @return string |
|
| 180 | + * @since 12.0.0 |
|
| 181 | + */ |
|
| 182 | + public function getLogo(bool $useSvg = true): string { |
|
| 183 | + return $this->defaults->getLogo($useSvg); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Returns primary color |
|
| 188 | + * @return string |
|
| 189 | + * @since 12.0.0 |
|
| 190 | + */ |
|
| 191 | + public function getColorPrimary(): string { |
|
| 192 | + return $this->defaults->getColorPrimary(); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param string $key |
|
| 197 | + * @return string URL to doc with key |
|
| 198 | + * @since 12.0.0 |
|
| 199 | + */ |
|
| 200 | + public function buildDocLinkToKey(string $key): string { |
|
| 201 | + return $this->defaults->buildDocLinkToKey($key); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Returns the title |
|
| 206 | + * @return string title |
|
| 207 | + * @since 12.0.0 |
|
| 208 | + */ |
|
| 209 | + public function getTitle(): string { |
|
| 210 | + return $this->defaults->getTitle(); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Returns primary color |
|
| 215 | + * @return string |
|
| 216 | + * @since 13.0.0 |
|
| 217 | + */ |
|
| 218 | + public function getTextColorPrimary(): string { |
|
| 219 | + return $this->defaults->getTextColorPrimary(); |
|
| 220 | + } |
|
| 221 | 221 | } |
@@ -40,151 +40,151 @@ |
||
| 40 | 40 | use OCP\ILogger; |
| 41 | 41 | |
| 42 | 42 | class Autoloader { |
| 43 | - /** @var bool */ |
|
| 44 | - private $useGlobalClassPath = true; |
|
| 45 | - /** @var array */ |
|
| 46 | - private $validRoots = []; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Optional low-latency memory cache for class to path mapping. |
|
| 50 | - * |
|
| 51 | - * @var \OC\Memcache\Cache |
|
| 52 | - */ |
|
| 53 | - protected $memoryCache; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Autoloader constructor. |
|
| 57 | - * |
|
| 58 | - * @param string[] $validRoots |
|
| 59 | - */ |
|
| 60 | - public function __construct(array $validRoots) { |
|
| 61 | - foreach ($validRoots as $root) { |
|
| 62 | - $this->validRoots[$root] = true; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Add a path to the list of valid php roots for auto loading |
|
| 68 | - * |
|
| 69 | - * @param string $root |
|
| 70 | - */ |
|
| 71 | - public function addValidRoot(string $root): void { |
|
| 72 | - $root = stream_resolve_include_path($root); |
|
| 73 | - $this->validRoots[$root] = true; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * disable the usage of the global classpath \OC::$CLASSPATH |
|
| 78 | - */ |
|
| 79 | - public function disableGlobalClassPath(): void { |
|
| 80 | - $this->useGlobalClassPath = false; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * enable the usage of the global classpath \OC::$CLASSPATH |
|
| 85 | - */ |
|
| 86 | - public function enableGlobalClassPath(): void { |
|
| 87 | - $this->useGlobalClassPath = true; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * get the possible paths for a class |
|
| 92 | - * |
|
| 93 | - * @param string $class |
|
| 94 | - * @return array an array of possible paths |
|
| 95 | - */ |
|
| 96 | - public function findClass(string $class): array { |
|
| 97 | - $class = trim($class, '\\'); |
|
| 98 | - |
|
| 99 | - $paths = []; |
|
| 100 | - if ($this->useGlobalClassPath && array_key_exists($class, \OC::$CLASSPATH)) { |
|
| 101 | - $paths[] = \OC::$CLASSPATH[$class]; |
|
| 102 | - /** |
|
| 103 | - * @TODO: Remove this when necessary |
|
| 104 | - * Remove "apps/" from inclusion path for smooth migration to multi app dir |
|
| 105 | - */ |
|
| 106 | - if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) { |
|
| 107 | - \OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', ILogger::DEBUG); |
|
| 108 | - $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]); |
|
| 109 | - } |
|
| 110 | - } elseif (strpos($class, 'OC_') === 0) { |
|
| 111 | - $paths[] = \OC::$SERVERROOT . '/lib/private/legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); |
|
| 112 | - } elseif (strpos($class, 'OCA\\') === 0) { |
|
| 113 | - [, $app, $rest] = explode('\\', $class, 3); |
|
| 114 | - $app = strtolower($app); |
|
| 115 | - $appPath = \OC_App::getAppPath($app); |
|
| 116 | - if ($appPath && stream_resolve_include_path($appPath)) { |
|
| 117 | - $paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
|
| 118 | - // If not found in the root of the app directory, insert '/lib' after app id and try again. |
|
| 119 | - $paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
|
| 120 | - } |
|
| 121 | - } elseif ($class === 'Test\\TestCase') { |
|
| 122 | - // This File is considered public API, so we make sure that the class |
|
| 123 | - // can still be loaded, although the PSR-4 paths have not been loaded. |
|
| 124 | - $paths[] = \OC::$SERVERROOT . '/tests/lib/TestCase.php'; |
|
| 125 | - } |
|
| 126 | - return $paths; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @param string $fullPath |
|
| 131 | - * @return bool |
|
| 132 | - * @throws AutoloadNotAllowedException |
|
| 133 | - */ |
|
| 134 | - protected function isValidPath(string $fullPath): bool { |
|
| 135 | - foreach ($this->validRoots as $root => $true) { |
|
| 136 | - if (substr($fullPath, 0, strlen($root) + 1) === $root . '/') { |
|
| 137 | - return true; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - throw new AutoloadNotAllowedException($fullPath); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Load the specified class |
|
| 145 | - * |
|
| 146 | - * @param string $class |
|
| 147 | - * @return bool |
|
| 148 | - * @throws AutoloadNotAllowedException |
|
| 149 | - */ |
|
| 150 | - public function load(string $class): bool { |
|
| 151 | - $pathsToRequire = null; |
|
| 152 | - if ($this->memoryCache) { |
|
| 153 | - $pathsToRequire = $this->memoryCache->get($class); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - if (class_exists($class, false)) { |
|
| 157 | - return false; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - if (!is_array($pathsToRequire)) { |
|
| 161 | - // No cache or cache miss |
|
| 162 | - $pathsToRequire = []; |
|
| 163 | - foreach ($this->findClass($class) as $path) { |
|
| 164 | - $fullPath = stream_resolve_include_path($path); |
|
| 165 | - if ($fullPath && $this->isValidPath($fullPath)) { |
|
| 166 | - $pathsToRequire[] = $fullPath; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if ($this->memoryCache) { |
|
| 171 | - $this->memoryCache->set($class, $pathsToRequire, 60); // cache 60 sec |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - foreach ($pathsToRequire as $fullPath) { |
|
| 176 | - require_once $fullPath; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return false; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Sets the optional low-latency cache for class to path mapping. |
|
| 184 | - * |
|
| 185 | - * @param \OC\Memcache\Cache $memoryCache Instance of memory cache. |
|
| 186 | - */ |
|
| 187 | - public function setMemoryCache(\OC\Memcache\Cache $memoryCache = null): void { |
|
| 188 | - $this->memoryCache = $memoryCache; |
|
| 189 | - } |
|
| 43 | + /** @var bool */ |
|
| 44 | + private $useGlobalClassPath = true; |
|
| 45 | + /** @var array */ |
|
| 46 | + private $validRoots = []; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Optional low-latency memory cache for class to path mapping. |
|
| 50 | + * |
|
| 51 | + * @var \OC\Memcache\Cache |
|
| 52 | + */ |
|
| 53 | + protected $memoryCache; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Autoloader constructor. |
|
| 57 | + * |
|
| 58 | + * @param string[] $validRoots |
|
| 59 | + */ |
|
| 60 | + public function __construct(array $validRoots) { |
|
| 61 | + foreach ($validRoots as $root) { |
|
| 62 | + $this->validRoots[$root] = true; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Add a path to the list of valid php roots for auto loading |
|
| 68 | + * |
|
| 69 | + * @param string $root |
|
| 70 | + */ |
|
| 71 | + public function addValidRoot(string $root): void { |
|
| 72 | + $root = stream_resolve_include_path($root); |
|
| 73 | + $this->validRoots[$root] = true; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * disable the usage of the global classpath \OC::$CLASSPATH |
|
| 78 | + */ |
|
| 79 | + public function disableGlobalClassPath(): void { |
|
| 80 | + $this->useGlobalClassPath = false; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * enable the usage of the global classpath \OC::$CLASSPATH |
|
| 85 | + */ |
|
| 86 | + public function enableGlobalClassPath(): void { |
|
| 87 | + $this->useGlobalClassPath = true; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * get the possible paths for a class |
|
| 92 | + * |
|
| 93 | + * @param string $class |
|
| 94 | + * @return array an array of possible paths |
|
| 95 | + */ |
|
| 96 | + public function findClass(string $class): array { |
|
| 97 | + $class = trim($class, '\\'); |
|
| 98 | + |
|
| 99 | + $paths = []; |
|
| 100 | + if ($this->useGlobalClassPath && array_key_exists($class, \OC::$CLASSPATH)) { |
|
| 101 | + $paths[] = \OC::$CLASSPATH[$class]; |
|
| 102 | + /** |
|
| 103 | + * @TODO: Remove this when necessary |
|
| 104 | + * Remove "apps/" from inclusion path for smooth migration to multi app dir |
|
| 105 | + */ |
|
| 106 | + if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) { |
|
| 107 | + \OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', ILogger::DEBUG); |
|
| 108 | + $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]); |
|
| 109 | + } |
|
| 110 | + } elseif (strpos($class, 'OC_') === 0) { |
|
| 111 | + $paths[] = \OC::$SERVERROOT . '/lib/private/legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); |
|
| 112 | + } elseif (strpos($class, 'OCA\\') === 0) { |
|
| 113 | + [, $app, $rest] = explode('\\', $class, 3); |
|
| 114 | + $app = strtolower($app); |
|
| 115 | + $appPath = \OC_App::getAppPath($app); |
|
| 116 | + if ($appPath && stream_resolve_include_path($appPath)) { |
|
| 117 | + $paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
|
| 118 | + // If not found in the root of the app directory, insert '/lib' after app id and try again. |
|
| 119 | + $paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
|
| 120 | + } |
|
| 121 | + } elseif ($class === 'Test\\TestCase') { |
|
| 122 | + // This File is considered public API, so we make sure that the class |
|
| 123 | + // can still be loaded, although the PSR-4 paths have not been loaded. |
|
| 124 | + $paths[] = \OC::$SERVERROOT . '/tests/lib/TestCase.php'; |
|
| 125 | + } |
|
| 126 | + return $paths; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param string $fullPath |
|
| 131 | + * @return bool |
|
| 132 | + * @throws AutoloadNotAllowedException |
|
| 133 | + */ |
|
| 134 | + protected function isValidPath(string $fullPath): bool { |
|
| 135 | + foreach ($this->validRoots as $root => $true) { |
|
| 136 | + if (substr($fullPath, 0, strlen($root) + 1) === $root . '/') { |
|
| 137 | + return true; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + throw new AutoloadNotAllowedException($fullPath); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Load the specified class |
|
| 145 | + * |
|
| 146 | + * @param string $class |
|
| 147 | + * @return bool |
|
| 148 | + * @throws AutoloadNotAllowedException |
|
| 149 | + */ |
|
| 150 | + public function load(string $class): bool { |
|
| 151 | + $pathsToRequire = null; |
|
| 152 | + if ($this->memoryCache) { |
|
| 153 | + $pathsToRequire = $this->memoryCache->get($class); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + if (class_exists($class, false)) { |
|
| 157 | + return false; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + if (!is_array($pathsToRequire)) { |
|
| 161 | + // No cache or cache miss |
|
| 162 | + $pathsToRequire = []; |
|
| 163 | + foreach ($this->findClass($class) as $path) { |
|
| 164 | + $fullPath = stream_resolve_include_path($path); |
|
| 165 | + if ($fullPath && $this->isValidPath($fullPath)) { |
|
| 166 | + $pathsToRequire[] = $fullPath; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if ($this->memoryCache) { |
|
| 171 | + $this->memoryCache->set($class, $pathsToRequire, 60); // cache 60 sec |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + foreach ($pathsToRequire as $fullPath) { |
|
| 176 | + require_once $fullPath; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Sets the optional low-latency cache for class to path mapping. |
|
| 184 | + * |
|
| 185 | + * @param \OC\Memcache\Cache $memoryCache Instance of memory cache. |
|
| 186 | + */ |
|
| 187 | + public function setMemoryCache(\OC\Memcache\Cache $memoryCache = null): void { |
|
| 188 | + $this->memoryCache = $memoryCache; |
|
| 189 | + } |
|
| 190 | 190 | } |
@@ -62,523 +62,523 @@ |
||
| 62 | 62 | */ |
| 63 | 63 | class Updater extends BasicEmitter { |
| 64 | 64 | |
| 65 | - /** @var LoggerInterface */ |
|
| 66 | - private $log; |
|
| 67 | - |
|
| 68 | - /** @var IConfig */ |
|
| 69 | - private $config; |
|
| 70 | - |
|
| 71 | - /** @var Checker */ |
|
| 72 | - private $checker; |
|
| 73 | - |
|
| 74 | - /** @var Installer */ |
|
| 75 | - private $installer; |
|
| 76 | - |
|
| 77 | - private $logLevelNames = [ |
|
| 78 | - 0 => 'Debug', |
|
| 79 | - 1 => 'Info', |
|
| 80 | - 2 => 'Warning', |
|
| 81 | - 3 => 'Error', |
|
| 82 | - 4 => 'Fatal', |
|
| 83 | - ]; |
|
| 84 | - |
|
| 85 | - public function __construct(IConfig $config, |
|
| 86 | - Checker $checker, |
|
| 87 | - ?LoggerInterface $log, |
|
| 88 | - Installer $installer) { |
|
| 89 | - $this->log = $log; |
|
| 90 | - $this->config = $config; |
|
| 91 | - $this->checker = $checker; |
|
| 92 | - $this->installer = $installer; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 97 | - * except the main .htaccess file |
|
| 98 | - * |
|
| 99 | - * @return bool true if the operation succeeded, false otherwise |
|
| 100 | - */ |
|
| 101 | - public function upgrade(): bool { |
|
| 102 | - $this->emitRepairEvents(); |
|
| 103 | - $this->logAllEvents(); |
|
| 104 | - |
|
| 105 | - $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
|
| 106 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 107 | - $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
|
| 108 | - |
|
| 109 | - $wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); |
|
| 110 | - |
|
| 111 | - if (!$wasMaintenanceModeEnabled) { |
|
| 112 | - $this->config->setSystemValue('maintenance', true); |
|
| 113 | - $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - // Clear CAN_INSTALL file if not on git |
|
| 117 | - if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 118 | - if (!unlink(\OC::$configDir . '/CAN_INSTALL')) { |
|
| 119 | - $this->log->error('Could not cleanup CAN_INSTALL from your config folder. Please remove this file manually.'); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 124 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 125 | - |
|
| 126 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, ['app' => 'core']); |
|
| 127 | - |
|
| 128 | - $success = true; |
|
| 129 | - try { |
|
| 130 | - $this->doUpgrade($currentVersion, $installedVersion); |
|
| 131 | - } catch (HintException $exception) { |
|
| 132 | - $this->log->error($exception->getMessage(), [ |
|
| 133 | - 'exception' => $exception, |
|
| 134 | - ]); |
|
| 135 | - $this->emit('\OC\Updater', 'failure', [$exception->getMessage() . ': ' .$exception->getHint()]); |
|
| 136 | - $success = false; |
|
| 137 | - } catch (\Exception $exception) { |
|
| 138 | - $this->log->error($exception->getMessage(), [ |
|
| 139 | - 'exception' => $exception, |
|
| 140 | - ]); |
|
| 141 | - $this->emit('\OC\Updater', 'failure', [get_class($exception) . ': ' .$exception->getMessage()]); |
|
| 142 | - $success = false; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $this->emit('\OC\Updater', 'updateEnd', [$success]); |
|
| 146 | - |
|
| 147 | - if (!$wasMaintenanceModeEnabled && $success) { |
|
| 148 | - $this->config->setSystemValue('maintenance', false); |
|
| 149 | - $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
| 150 | - } else { |
|
| 151 | - $this->emit('\OC\Updater', 'maintenanceActive'); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 155 | - $this->config->setSystemValue('loglevel', $logLevel); |
|
| 156 | - $this->config->setSystemValue('installed', true); |
|
| 157 | - |
|
| 158 | - return $success; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Return version from which this version is allowed to upgrade from |
|
| 163 | - * |
|
| 164 | - * @return array allowed previous versions per vendor |
|
| 165 | - */ |
|
| 166 | - private function getAllowedPreviousVersions(): array { |
|
| 167 | - // this should really be a JSON file |
|
| 168 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 169 | - /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
| 170 | - return $OC_VersionCanBeUpgradedFrom; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Return vendor from which this version was published |
|
| 175 | - * |
|
| 176 | - * @return string Get the vendor |
|
| 177 | - */ |
|
| 178 | - private function getVendor(): string { |
|
| 179 | - // this should really be a JSON file |
|
| 180 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 181 | - /** @var string $vendor */ |
|
| 182 | - return (string) $vendor; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Whether an upgrade to a specified version is possible |
|
| 187 | - * @param string $oldVersion |
|
| 188 | - * @param string $newVersion |
|
| 189 | - * @param array $allowedPreviousVersions |
|
| 190 | - * @return bool |
|
| 191 | - */ |
|
| 192 | - public function isUpgradePossible(string $oldVersion, string $newVersion, array $allowedPreviousVersions): bool { |
|
| 193 | - $version = explode('.', $oldVersion); |
|
| 194 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
| 195 | - |
|
| 196 | - $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
| 197 | - |
|
| 198 | - // Vendor was not set correctly on install, so we have to white-list known versions |
|
| 199 | - if ($currentVendor === '' && ( |
|
| 200 | - isset($allowedPreviousVersions['owncloud'][$oldVersion]) || |
|
| 201 | - isset($allowedPreviousVersions['owncloud'][$majorMinor]) |
|
| 202 | - )) { |
|
| 203 | - $currentVendor = 'owncloud'; |
|
| 204 | - $this->config->setAppValue('core', 'vendor', $currentVendor); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if ($currentVendor === 'nextcloud') { |
|
| 208 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
| 209 | - && (version_compare($oldVersion, $newVersion, '<=') || |
|
| 210 | - $this->config->getSystemValue('debug', false)); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - // Check if the instance can be migrated |
|
| 214 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
| 215 | - isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 220 | - * except the main .htaccess file |
|
| 221 | - * |
|
| 222 | - * @param string $currentVersion current version to upgrade to |
|
| 223 | - * @param string $installedVersion previous version from which to upgrade from |
|
| 224 | - * |
|
| 225 | - * @throws \Exception |
|
| 226 | - */ |
|
| 227 | - private function doUpgrade(string $currentVersion, string $installedVersion): void { |
|
| 228 | - // Stop update if the update is over several major versions |
|
| 229 | - $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
| 230 | - if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
| 231 | - throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // Update .htaccess files |
|
| 235 | - try { |
|
| 236 | - Setup::updateHtaccess(); |
|
| 237 | - Setup::protectDataDirectory(); |
|
| 238 | - } catch (\Exception $e) { |
|
| 239 | - throw new \Exception($e->getMessage()); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // create empty file in data dir, so we can later find |
|
| 243 | - // out that this is indeed an ownCloud data directory |
|
| 244 | - // (in case it didn't exist before) |
|
| 245 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 246 | - |
|
| 247 | - // pre-upgrade repairs |
|
| 248 | - $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)); |
|
| 249 | - $repair->run(); |
|
| 250 | - |
|
| 251 | - $this->doCoreUpgrade(); |
|
| 252 | - |
|
| 253 | - try { |
|
| 254 | - // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
| 255 | - Setup::installBackgroundJobs(); |
|
| 256 | - } catch (\Exception $e) { |
|
| 257 | - throw new \Exception($e->getMessage()); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - // update all shipped apps |
|
| 261 | - $this->checkAppsRequirements(); |
|
| 262 | - $this->doAppUpgrade(); |
|
| 263 | - |
|
| 264 | - // Update the appfetchers version so it downloads the correct list from the appstore |
|
| 265 | - \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
| 266 | - |
|
| 267 | - // upgrade appstore apps |
|
| 268 | - $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
| 269 | - $autoDisabledApps = \OC::$server->getAppManager()->getAutoDisabledApps(); |
|
| 270 | - $this->upgradeAppStoreApps($autoDisabledApps, true); |
|
| 271 | - |
|
| 272 | - // install new shipped apps on upgrade |
|
| 273 | - $errors = Installer::installShippedApps(true); |
|
| 274 | - foreach ($errors as $appId => $exception) { |
|
| 275 | - /** @var \Exception $exception */ |
|
| 276 | - $this->log->error($exception->getMessage(), [ |
|
| 277 | - 'exception' => $exception, |
|
| 278 | - 'app' => $appId, |
|
| 279 | - ]); |
|
| 280 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // post-upgrade repairs |
|
| 284 | - $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)); |
|
| 285 | - $repair->run(); |
|
| 286 | - |
|
| 287 | - //Invalidate update feed |
|
| 288 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 289 | - |
|
| 290 | - // Check for code integrity if not disabled |
|
| 291 | - if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 292 | - $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
| 293 | - $this->checker->runInstanceVerification(); |
|
| 294 | - $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // only set the final version if everything went well |
|
| 298 | - $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
| 299 | - $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - protected function doCoreUpgrade(): void { |
|
| 303 | - $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
| 304 | - |
|
| 305 | - // execute core migrations |
|
| 306 | - $ms = new MigrationService('core', \OC::$server->get(Connection::class)); |
|
| 307 | - $ms->migrate(); |
|
| 308 | - |
|
| 309 | - $this->emit('\OC\Updater', 'dbUpgrade'); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
| 314 | - * (types authentication, filesystem, logging, in that order) afterwards. |
|
| 315 | - * |
|
| 316 | - * @throws NeedsUpdateException |
|
| 317 | - */ |
|
| 318 | - protected function doAppUpgrade(): void { |
|
| 319 | - $apps = \OC_App::getEnabledApps(); |
|
| 320 | - $priorityTypes = ['authentication', 'filesystem', 'logging']; |
|
| 321 | - $pseudoOtherType = 'other'; |
|
| 322 | - $stacks = [$pseudoOtherType => []]; |
|
| 323 | - |
|
| 324 | - foreach ($apps as $appId) { |
|
| 325 | - $priorityType = false; |
|
| 326 | - foreach ($priorityTypes as $type) { |
|
| 327 | - if (!isset($stacks[$type])) { |
|
| 328 | - $stacks[$type] = []; |
|
| 329 | - } |
|
| 330 | - if (\OC_App::isType($appId, [$type])) { |
|
| 331 | - $stacks[$type][] = $appId; |
|
| 332 | - $priorityType = true; |
|
| 333 | - break; |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - if (!$priorityType) { |
|
| 337 | - $stacks[$pseudoOtherType][] = $appId; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - foreach (array_merge($priorityTypes, [$pseudoOtherType]) as $type) { |
|
| 341 | - $stack = $stacks[$type]; |
|
| 342 | - foreach ($stack as $appId) { |
|
| 343 | - if (\OC_App::shouldUpgrade($appId)) { |
|
| 344 | - $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 345 | - \OC_App::updateApp($appId); |
|
| 346 | - $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 347 | - } |
|
| 348 | - if ($type !== $pseudoOtherType) { |
|
| 349 | - // load authentication, filesystem and logging apps after |
|
| 350 | - // upgrading them. Other apps my need to rely on modifying |
|
| 351 | - // user and/or filesystem aspects. |
|
| 352 | - \OC_App::loadApp($appId); |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * check if the current enabled apps are compatible with the current |
|
| 360 | - * ownCloud version. disable them if not. |
|
| 361 | - * This is important if you upgrade ownCloud and have non ported 3rd |
|
| 362 | - * party apps installed. |
|
| 363 | - * |
|
| 364 | - * @return array |
|
| 365 | - * @throws \Exception |
|
| 366 | - */ |
|
| 367 | - private function checkAppsRequirements(): array { |
|
| 368 | - $isCoreUpgrade = $this->isCodeUpgrade(); |
|
| 369 | - $apps = OC_App::getEnabledApps(); |
|
| 370 | - $version = implode('.', Util::getVersion()); |
|
| 371 | - $disabledApps = []; |
|
| 372 | - $appManager = \OC::$server->getAppManager(); |
|
| 373 | - foreach ($apps as $app) { |
|
| 374 | - // check if the app is compatible with this version of Nextcloud |
|
| 375 | - $info = OC_App::getAppInfo($app); |
|
| 376 | - if ($info === null || !OC_App::isAppCompatible($version, $info)) { |
|
| 377 | - if ($appManager->isShipped($app)) { |
|
| 378 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 379 | - } |
|
| 380 | - \OC::$server->getAppManager()->disableApp($app, true); |
|
| 381 | - $this->emit('\OC\Updater', 'incompatibleAppDisabled', [$app]); |
|
| 382 | - } |
|
| 383 | - // no need to disable any app in case this is a non-core upgrade |
|
| 384 | - if (!$isCoreUpgrade) { |
|
| 385 | - continue; |
|
| 386 | - } |
|
| 387 | - // shipped apps will remain enabled |
|
| 388 | - if ($appManager->isShipped($app)) { |
|
| 389 | - continue; |
|
| 390 | - } |
|
| 391 | - // authentication and session apps will remain enabled as well |
|
| 392 | - if (OC_App::isType($app, ['session', 'authentication'])) { |
|
| 393 | - continue; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - return $disabledApps; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * @return bool |
|
| 401 | - */ |
|
| 402 | - private function isCodeUpgrade(): bool { |
|
| 403 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 404 | - $currentVersion = implode('.', Util::getVersion()); |
|
| 405 | - if (version_compare($currentVersion, $installedVersion, '>')) { |
|
| 406 | - return true; |
|
| 407 | - } |
|
| 408 | - return false; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * @param array $disabledApps |
|
| 413 | - * @param bool $reenable |
|
| 414 | - * @throws \Exception |
|
| 415 | - */ |
|
| 416 | - private function upgradeAppStoreApps(array $disabledApps, bool $reenable = false): void { |
|
| 417 | - foreach ($disabledApps as $app) { |
|
| 418 | - try { |
|
| 419 | - $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
| 420 | - if ($this->installer->isUpdateAvailable($app)) { |
|
| 421 | - $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
| 422 | - $this->installer->updateAppstoreApp($app); |
|
| 423 | - } |
|
| 424 | - $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
| 425 | - |
|
| 426 | - if ($reenable) { |
|
| 427 | - $ocApp = new \OC_App(); |
|
| 428 | - $ocApp->enable($app); |
|
| 429 | - } |
|
| 430 | - } catch (\Exception $ex) { |
|
| 431 | - $this->log->error($ex->getMessage(), [ |
|
| 432 | - 'exception' => $ex, |
|
| 433 | - ]); |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * Forward messages emitted by the repair routine |
|
| 440 | - */ |
|
| 441 | - private function emitRepairEvents(): void { |
|
| 442 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 443 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 444 | - if ($event instanceof GenericEvent) { |
|
| 445 | - $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
| 446 | - } |
|
| 447 | - }); |
|
| 448 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 449 | - if ($event instanceof GenericEvent) { |
|
| 450 | - $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
| 451 | - } |
|
| 452 | - }); |
|
| 453 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 454 | - if ($event instanceof GenericEvent) { |
|
| 455 | - $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
| 456 | - } |
|
| 457 | - }); |
|
| 458 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 459 | - if ($event instanceof GenericEvent) { |
|
| 460 | - $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
| 461 | - } |
|
| 462 | - }); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - private function logAllEvents(): void { |
|
| 466 | - $log = $this->log; |
|
| 467 | - |
|
| 468 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 469 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($log) { |
|
| 470 | - if (!$event instanceof GenericEvent) { |
|
| 471 | - return; |
|
| 472 | - } |
|
| 473 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 474 | - }); |
|
| 475 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($log) { |
|
| 476 | - if (!$event instanceof GenericEvent) { |
|
| 477 | - return; |
|
| 478 | - } |
|
| 479 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 480 | - }); |
|
| 481 | - |
|
| 482 | - $repairListener = function ($event) use ($log) { |
|
| 483 | - if (!$event instanceof GenericEvent) { |
|
| 484 | - return; |
|
| 485 | - } |
|
| 486 | - switch ($event->getSubject()) { |
|
| 487 | - case '\OC\Repair::startProgress': |
|
| 488 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 489 | - break; |
|
| 490 | - case '\OC\Repair::advance': |
|
| 491 | - $desc = $event->getArgument(1); |
|
| 492 | - if (empty($desc)) { |
|
| 493 | - $desc = ''; |
|
| 494 | - } |
|
| 495 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 496 | - |
|
| 497 | - break; |
|
| 498 | - case '\OC\Repair::finishProgress': |
|
| 499 | - $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
| 500 | - break; |
|
| 501 | - case '\OC\Repair::step': |
|
| 502 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 503 | - break; |
|
| 504 | - case '\OC\Repair::info': |
|
| 505 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 506 | - break; |
|
| 507 | - case '\OC\Repair::warning': |
|
| 508 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 509 | - break; |
|
| 510 | - case '\OC\Repair::error': |
|
| 511 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 512 | - break; |
|
| 513 | - } |
|
| 514 | - }; |
|
| 515 | - |
|
| 516 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 517 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 518 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 519 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 520 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 521 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 522 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use ($log) { |
|
| 526 | - $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
| 527 | - }); |
|
| 528 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use ($log) { |
|
| 529 | - $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
| 530 | - }); |
|
| 531 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use ($log) { |
|
| 532 | - $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
| 533 | - }); |
|
| 534 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use ($log) { |
|
| 535 | - if ($success) { |
|
| 536 | - $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
| 537 | - } else { |
|
| 538 | - $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
| 539 | - } |
|
| 540 | - }); |
|
| 541 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($log) { |
|
| 542 | - $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
| 543 | - }); |
|
| 544 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use ($log) { |
|
| 545 | - $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
| 546 | - }); |
|
| 547 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($log) { |
|
| 548 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 549 | - }); |
|
| 550 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($log) { |
|
| 551 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 552 | - }); |
|
| 553 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($log) { |
|
| 554 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 555 | - }); |
|
| 556 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($log) { |
|
| 557 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 558 | - }); |
|
| 559 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 560 | - $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 561 | - }); |
|
| 562 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 563 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 564 | - }); |
|
| 565 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 566 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 567 | - }); |
|
| 568 | - $this->listen('\OC\Updater', 'failure', function ($message) use ($log) { |
|
| 569 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 570 | - }); |
|
| 571 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use ($log) { |
|
| 572 | - $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
| 573 | - }); |
|
| 574 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($log) { |
|
| 575 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 576 | - }); |
|
| 577 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($log) { |
|
| 578 | - $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
| 579 | - }); |
|
| 580 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($log) { |
|
| 581 | - $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
| 582 | - }); |
|
| 583 | - } |
|
| 65 | + /** @var LoggerInterface */ |
|
| 66 | + private $log; |
|
| 67 | + |
|
| 68 | + /** @var IConfig */ |
|
| 69 | + private $config; |
|
| 70 | + |
|
| 71 | + /** @var Checker */ |
|
| 72 | + private $checker; |
|
| 73 | + |
|
| 74 | + /** @var Installer */ |
|
| 75 | + private $installer; |
|
| 76 | + |
|
| 77 | + private $logLevelNames = [ |
|
| 78 | + 0 => 'Debug', |
|
| 79 | + 1 => 'Info', |
|
| 80 | + 2 => 'Warning', |
|
| 81 | + 3 => 'Error', |
|
| 82 | + 4 => 'Fatal', |
|
| 83 | + ]; |
|
| 84 | + |
|
| 85 | + public function __construct(IConfig $config, |
|
| 86 | + Checker $checker, |
|
| 87 | + ?LoggerInterface $log, |
|
| 88 | + Installer $installer) { |
|
| 89 | + $this->log = $log; |
|
| 90 | + $this->config = $config; |
|
| 91 | + $this->checker = $checker; |
|
| 92 | + $this->installer = $installer; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 97 | + * except the main .htaccess file |
|
| 98 | + * |
|
| 99 | + * @return bool true if the operation succeeded, false otherwise |
|
| 100 | + */ |
|
| 101 | + public function upgrade(): bool { |
|
| 102 | + $this->emitRepairEvents(); |
|
| 103 | + $this->logAllEvents(); |
|
| 104 | + |
|
| 105 | + $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
|
| 106 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 107 | + $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
|
| 108 | + |
|
| 109 | + $wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); |
|
| 110 | + |
|
| 111 | + if (!$wasMaintenanceModeEnabled) { |
|
| 112 | + $this->config->setSystemValue('maintenance', true); |
|
| 113 | + $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + // Clear CAN_INSTALL file if not on git |
|
| 117 | + if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 118 | + if (!unlink(\OC::$configDir . '/CAN_INSTALL')) { |
|
| 119 | + $this->log->error('Could not cleanup CAN_INSTALL from your config folder. Please remove this file manually.'); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 124 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 125 | + |
|
| 126 | + $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, ['app' => 'core']); |
|
| 127 | + |
|
| 128 | + $success = true; |
|
| 129 | + try { |
|
| 130 | + $this->doUpgrade($currentVersion, $installedVersion); |
|
| 131 | + } catch (HintException $exception) { |
|
| 132 | + $this->log->error($exception->getMessage(), [ |
|
| 133 | + 'exception' => $exception, |
|
| 134 | + ]); |
|
| 135 | + $this->emit('\OC\Updater', 'failure', [$exception->getMessage() . ': ' .$exception->getHint()]); |
|
| 136 | + $success = false; |
|
| 137 | + } catch (\Exception $exception) { |
|
| 138 | + $this->log->error($exception->getMessage(), [ |
|
| 139 | + 'exception' => $exception, |
|
| 140 | + ]); |
|
| 141 | + $this->emit('\OC\Updater', 'failure', [get_class($exception) . ': ' .$exception->getMessage()]); |
|
| 142 | + $success = false; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $this->emit('\OC\Updater', 'updateEnd', [$success]); |
|
| 146 | + |
|
| 147 | + if (!$wasMaintenanceModeEnabled && $success) { |
|
| 148 | + $this->config->setSystemValue('maintenance', false); |
|
| 149 | + $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
| 150 | + } else { |
|
| 151 | + $this->emit('\OC\Updater', 'maintenanceActive'); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 155 | + $this->config->setSystemValue('loglevel', $logLevel); |
|
| 156 | + $this->config->setSystemValue('installed', true); |
|
| 157 | + |
|
| 158 | + return $success; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Return version from which this version is allowed to upgrade from |
|
| 163 | + * |
|
| 164 | + * @return array allowed previous versions per vendor |
|
| 165 | + */ |
|
| 166 | + private function getAllowedPreviousVersions(): array { |
|
| 167 | + // this should really be a JSON file |
|
| 168 | + require \OC::$SERVERROOT . '/version.php'; |
|
| 169 | + /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
| 170 | + return $OC_VersionCanBeUpgradedFrom; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Return vendor from which this version was published |
|
| 175 | + * |
|
| 176 | + * @return string Get the vendor |
|
| 177 | + */ |
|
| 178 | + private function getVendor(): string { |
|
| 179 | + // this should really be a JSON file |
|
| 180 | + require \OC::$SERVERROOT . '/version.php'; |
|
| 181 | + /** @var string $vendor */ |
|
| 182 | + return (string) $vendor; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Whether an upgrade to a specified version is possible |
|
| 187 | + * @param string $oldVersion |
|
| 188 | + * @param string $newVersion |
|
| 189 | + * @param array $allowedPreviousVersions |
|
| 190 | + * @return bool |
|
| 191 | + */ |
|
| 192 | + public function isUpgradePossible(string $oldVersion, string $newVersion, array $allowedPreviousVersions): bool { |
|
| 193 | + $version = explode('.', $oldVersion); |
|
| 194 | + $majorMinor = $version[0] . '.' . $version[1]; |
|
| 195 | + |
|
| 196 | + $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
| 197 | + |
|
| 198 | + // Vendor was not set correctly on install, so we have to white-list known versions |
|
| 199 | + if ($currentVendor === '' && ( |
|
| 200 | + isset($allowedPreviousVersions['owncloud'][$oldVersion]) || |
|
| 201 | + isset($allowedPreviousVersions['owncloud'][$majorMinor]) |
|
| 202 | + )) { |
|
| 203 | + $currentVendor = 'owncloud'; |
|
| 204 | + $this->config->setAppValue('core', 'vendor', $currentVendor); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if ($currentVendor === 'nextcloud') { |
|
| 208 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
| 209 | + && (version_compare($oldVersion, $newVersion, '<=') || |
|
| 210 | + $this->config->getSystemValue('debug', false)); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + // Check if the instance can be migrated |
|
| 214 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
| 215 | + isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 220 | + * except the main .htaccess file |
|
| 221 | + * |
|
| 222 | + * @param string $currentVersion current version to upgrade to |
|
| 223 | + * @param string $installedVersion previous version from which to upgrade from |
|
| 224 | + * |
|
| 225 | + * @throws \Exception |
|
| 226 | + */ |
|
| 227 | + private function doUpgrade(string $currentVersion, string $installedVersion): void { |
|
| 228 | + // Stop update if the update is over several major versions |
|
| 229 | + $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
| 230 | + if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
| 231 | + throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // Update .htaccess files |
|
| 235 | + try { |
|
| 236 | + Setup::updateHtaccess(); |
|
| 237 | + Setup::protectDataDirectory(); |
|
| 238 | + } catch (\Exception $e) { |
|
| 239 | + throw new \Exception($e->getMessage()); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // create empty file in data dir, so we can later find |
|
| 243 | + // out that this is indeed an ownCloud data directory |
|
| 244 | + // (in case it didn't exist before) |
|
| 245 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 246 | + |
|
| 247 | + // pre-upgrade repairs |
|
| 248 | + $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)); |
|
| 249 | + $repair->run(); |
|
| 250 | + |
|
| 251 | + $this->doCoreUpgrade(); |
|
| 252 | + |
|
| 253 | + try { |
|
| 254 | + // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
| 255 | + Setup::installBackgroundJobs(); |
|
| 256 | + } catch (\Exception $e) { |
|
| 257 | + throw new \Exception($e->getMessage()); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + // update all shipped apps |
|
| 261 | + $this->checkAppsRequirements(); |
|
| 262 | + $this->doAppUpgrade(); |
|
| 263 | + |
|
| 264 | + // Update the appfetchers version so it downloads the correct list from the appstore |
|
| 265 | + \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
| 266 | + |
|
| 267 | + // upgrade appstore apps |
|
| 268 | + $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
| 269 | + $autoDisabledApps = \OC::$server->getAppManager()->getAutoDisabledApps(); |
|
| 270 | + $this->upgradeAppStoreApps($autoDisabledApps, true); |
|
| 271 | + |
|
| 272 | + // install new shipped apps on upgrade |
|
| 273 | + $errors = Installer::installShippedApps(true); |
|
| 274 | + foreach ($errors as $appId => $exception) { |
|
| 275 | + /** @var \Exception $exception */ |
|
| 276 | + $this->log->error($exception->getMessage(), [ |
|
| 277 | + 'exception' => $exception, |
|
| 278 | + 'app' => $appId, |
|
| 279 | + ]); |
|
| 280 | + $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // post-upgrade repairs |
|
| 284 | + $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)); |
|
| 285 | + $repair->run(); |
|
| 286 | + |
|
| 287 | + //Invalidate update feed |
|
| 288 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 289 | + |
|
| 290 | + // Check for code integrity if not disabled |
|
| 291 | + if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 292 | + $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
| 293 | + $this->checker->runInstanceVerification(); |
|
| 294 | + $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // only set the final version if everything went well |
|
| 298 | + $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
| 299 | + $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + protected function doCoreUpgrade(): void { |
|
| 303 | + $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
| 304 | + |
|
| 305 | + // execute core migrations |
|
| 306 | + $ms = new MigrationService('core', \OC::$server->get(Connection::class)); |
|
| 307 | + $ms->migrate(); |
|
| 308 | + |
|
| 309 | + $this->emit('\OC\Updater', 'dbUpgrade'); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
| 314 | + * (types authentication, filesystem, logging, in that order) afterwards. |
|
| 315 | + * |
|
| 316 | + * @throws NeedsUpdateException |
|
| 317 | + */ |
|
| 318 | + protected function doAppUpgrade(): void { |
|
| 319 | + $apps = \OC_App::getEnabledApps(); |
|
| 320 | + $priorityTypes = ['authentication', 'filesystem', 'logging']; |
|
| 321 | + $pseudoOtherType = 'other'; |
|
| 322 | + $stacks = [$pseudoOtherType => []]; |
|
| 323 | + |
|
| 324 | + foreach ($apps as $appId) { |
|
| 325 | + $priorityType = false; |
|
| 326 | + foreach ($priorityTypes as $type) { |
|
| 327 | + if (!isset($stacks[$type])) { |
|
| 328 | + $stacks[$type] = []; |
|
| 329 | + } |
|
| 330 | + if (\OC_App::isType($appId, [$type])) { |
|
| 331 | + $stacks[$type][] = $appId; |
|
| 332 | + $priorityType = true; |
|
| 333 | + break; |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + if (!$priorityType) { |
|
| 337 | + $stacks[$pseudoOtherType][] = $appId; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + foreach (array_merge($priorityTypes, [$pseudoOtherType]) as $type) { |
|
| 341 | + $stack = $stacks[$type]; |
|
| 342 | + foreach ($stack as $appId) { |
|
| 343 | + if (\OC_App::shouldUpgrade($appId)) { |
|
| 344 | + $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 345 | + \OC_App::updateApp($appId); |
|
| 346 | + $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 347 | + } |
|
| 348 | + if ($type !== $pseudoOtherType) { |
|
| 349 | + // load authentication, filesystem and logging apps after |
|
| 350 | + // upgrading them. Other apps my need to rely on modifying |
|
| 351 | + // user and/or filesystem aspects. |
|
| 352 | + \OC_App::loadApp($appId); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * check if the current enabled apps are compatible with the current |
|
| 360 | + * ownCloud version. disable them if not. |
|
| 361 | + * This is important if you upgrade ownCloud and have non ported 3rd |
|
| 362 | + * party apps installed. |
|
| 363 | + * |
|
| 364 | + * @return array |
|
| 365 | + * @throws \Exception |
|
| 366 | + */ |
|
| 367 | + private function checkAppsRequirements(): array { |
|
| 368 | + $isCoreUpgrade = $this->isCodeUpgrade(); |
|
| 369 | + $apps = OC_App::getEnabledApps(); |
|
| 370 | + $version = implode('.', Util::getVersion()); |
|
| 371 | + $disabledApps = []; |
|
| 372 | + $appManager = \OC::$server->getAppManager(); |
|
| 373 | + foreach ($apps as $app) { |
|
| 374 | + // check if the app is compatible with this version of Nextcloud |
|
| 375 | + $info = OC_App::getAppInfo($app); |
|
| 376 | + if ($info === null || !OC_App::isAppCompatible($version, $info)) { |
|
| 377 | + if ($appManager->isShipped($app)) { |
|
| 378 | + throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 379 | + } |
|
| 380 | + \OC::$server->getAppManager()->disableApp($app, true); |
|
| 381 | + $this->emit('\OC\Updater', 'incompatibleAppDisabled', [$app]); |
|
| 382 | + } |
|
| 383 | + // no need to disable any app in case this is a non-core upgrade |
|
| 384 | + if (!$isCoreUpgrade) { |
|
| 385 | + continue; |
|
| 386 | + } |
|
| 387 | + // shipped apps will remain enabled |
|
| 388 | + if ($appManager->isShipped($app)) { |
|
| 389 | + continue; |
|
| 390 | + } |
|
| 391 | + // authentication and session apps will remain enabled as well |
|
| 392 | + if (OC_App::isType($app, ['session', 'authentication'])) { |
|
| 393 | + continue; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + return $disabledApps; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * @return bool |
|
| 401 | + */ |
|
| 402 | + private function isCodeUpgrade(): bool { |
|
| 403 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 404 | + $currentVersion = implode('.', Util::getVersion()); |
|
| 405 | + if (version_compare($currentVersion, $installedVersion, '>')) { |
|
| 406 | + return true; |
|
| 407 | + } |
|
| 408 | + return false; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * @param array $disabledApps |
|
| 413 | + * @param bool $reenable |
|
| 414 | + * @throws \Exception |
|
| 415 | + */ |
|
| 416 | + private function upgradeAppStoreApps(array $disabledApps, bool $reenable = false): void { |
|
| 417 | + foreach ($disabledApps as $app) { |
|
| 418 | + try { |
|
| 419 | + $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
| 420 | + if ($this->installer->isUpdateAvailable($app)) { |
|
| 421 | + $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
| 422 | + $this->installer->updateAppstoreApp($app); |
|
| 423 | + } |
|
| 424 | + $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
| 425 | + |
|
| 426 | + if ($reenable) { |
|
| 427 | + $ocApp = new \OC_App(); |
|
| 428 | + $ocApp->enable($app); |
|
| 429 | + } |
|
| 430 | + } catch (\Exception $ex) { |
|
| 431 | + $this->log->error($ex->getMessage(), [ |
|
| 432 | + 'exception' => $ex, |
|
| 433 | + ]); |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * Forward messages emitted by the repair routine |
|
| 440 | + */ |
|
| 441 | + private function emitRepairEvents(): void { |
|
| 442 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 443 | + $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 444 | + if ($event instanceof GenericEvent) { |
|
| 445 | + $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
| 446 | + } |
|
| 447 | + }); |
|
| 448 | + $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 449 | + if ($event instanceof GenericEvent) { |
|
| 450 | + $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
| 451 | + } |
|
| 452 | + }); |
|
| 453 | + $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 454 | + if ($event instanceof GenericEvent) { |
|
| 455 | + $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
| 456 | + } |
|
| 457 | + }); |
|
| 458 | + $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 459 | + if ($event instanceof GenericEvent) { |
|
| 460 | + $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
| 461 | + } |
|
| 462 | + }); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + private function logAllEvents(): void { |
|
| 466 | + $log = $this->log; |
|
| 467 | + |
|
| 468 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 469 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($log) { |
|
| 470 | + if (!$event instanceof GenericEvent) { |
|
| 471 | + return; |
|
| 472 | + } |
|
| 473 | + $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 474 | + }); |
|
| 475 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($log) { |
|
| 476 | + if (!$event instanceof GenericEvent) { |
|
| 477 | + return; |
|
| 478 | + } |
|
| 479 | + $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 480 | + }); |
|
| 481 | + |
|
| 482 | + $repairListener = function ($event) use ($log) { |
|
| 483 | + if (!$event instanceof GenericEvent) { |
|
| 484 | + return; |
|
| 485 | + } |
|
| 486 | + switch ($event->getSubject()) { |
|
| 487 | + case '\OC\Repair::startProgress': |
|
| 488 | + $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 489 | + break; |
|
| 490 | + case '\OC\Repair::advance': |
|
| 491 | + $desc = $event->getArgument(1); |
|
| 492 | + if (empty($desc)) { |
|
| 493 | + $desc = ''; |
|
| 494 | + } |
|
| 495 | + $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 496 | + |
|
| 497 | + break; |
|
| 498 | + case '\OC\Repair::finishProgress': |
|
| 499 | + $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
| 500 | + break; |
|
| 501 | + case '\OC\Repair::step': |
|
| 502 | + $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 503 | + break; |
|
| 504 | + case '\OC\Repair::info': |
|
| 505 | + $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 506 | + break; |
|
| 507 | + case '\OC\Repair::warning': |
|
| 508 | + $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 509 | + break; |
|
| 510 | + case '\OC\Repair::error': |
|
| 511 | + $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 512 | + break; |
|
| 513 | + } |
|
| 514 | + }; |
|
| 515 | + |
|
| 516 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 517 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 518 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 519 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 520 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 521 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 522 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function () use ($log) { |
|
| 526 | + $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
| 527 | + }); |
|
| 528 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function () use ($log) { |
|
| 529 | + $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
| 530 | + }); |
|
| 531 | + $this->listen('\OC\Updater', 'maintenanceActive', function () use ($log) { |
|
| 532 | + $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
| 533 | + }); |
|
| 534 | + $this->listen('\OC\Updater', 'updateEnd', function ($success) use ($log) { |
|
| 535 | + if ($success) { |
|
| 536 | + $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
| 537 | + } else { |
|
| 538 | + $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
| 539 | + } |
|
| 540 | + }); |
|
| 541 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($log) { |
|
| 542 | + $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
| 543 | + }); |
|
| 544 | + $this->listen('\OC\Updater', 'dbUpgrade', function () use ($log) { |
|
| 545 | + $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
| 546 | + }); |
|
| 547 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($log) { |
|
| 548 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 549 | + }); |
|
| 550 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($log) { |
|
| 551 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 552 | + }); |
|
| 553 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($log) { |
|
| 554 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 555 | + }); |
|
| 556 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($log) { |
|
| 557 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 558 | + }); |
|
| 559 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 560 | + $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 561 | + }); |
|
| 562 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 563 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 564 | + }); |
|
| 565 | + $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 566 | + $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 567 | + }); |
|
| 568 | + $this->listen('\OC\Updater', 'failure', function ($message) use ($log) { |
|
| 569 | + $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 570 | + }); |
|
| 571 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function () use ($log) { |
|
| 572 | + $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
| 573 | + }); |
|
| 574 | + $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($log) { |
|
| 575 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 576 | + }); |
|
| 577 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($log) { |
|
| 578 | + $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
| 579 | + }); |
|
| 580 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($log) { |
|
| 581 | + $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
| 582 | + }); |
|
| 583 | + } |
|
| 584 | 584 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $this->logAllEvents(); |
| 104 | 104 | |
| 105 | 105 | $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
| 106 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 106 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [$logLevel, $this->logLevelNames[$logLevel]]); |
|
| 107 | 107 | $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
| 108 | 108 | |
| 109 | 109 | $wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | // Clear CAN_INSTALL file if not on git |
| 117 | 117 | if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { |
| 118 | - if (!unlink(\OC::$configDir . '/CAN_INSTALL')) { |
|
| 118 | + if (!unlink(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 119 | 119 | $this->log->error('Could not cleanup CAN_INSTALL from your config folder. Please remove this file manually.'); |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
| 124 | 124 | $currentVersion = implode('.', \OCP\Util::getVersion()); |
| 125 | 125 | |
| 126 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, ['app' => 'core']); |
|
| 126 | + $this->log->debug('starting upgrade from '.$installedVersion.' to '.$currentVersion, ['app' => 'core']); |
|
| 127 | 127 | |
| 128 | 128 | $success = true; |
| 129 | 129 | try { |
@@ -132,13 +132,13 @@ discard block |
||
| 132 | 132 | $this->log->error($exception->getMessage(), [ |
| 133 | 133 | 'exception' => $exception, |
| 134 | 134 | ]); |
| 135 | - $this->emit('\OC\Updater', 'failure', [$exception->getMessage() . ': ' .$exception->getHint()]); |
|
| 135 | + $this->emit('\OC\Updater', 'failure', [$exception->getMessage().': '.$exception->getHint()]); |
|
| 136 | 136 | $success = false; |
| 137 | 137 | } catch (\Exception $exception) { |
| 138 | 138 | $this->log->error($exception->getMessage(), [ |
| 139 | 139 | 'exception' => $exception, |
| 140 | 140 | ]); |
| 141 | - $this->emit('\OC\Updater', 'failure', [get_class($exception) . ': ' .$exception->getMessage()]); |
|
| 141 | + $this->emit('\OC\Updater', 'failure', [get_class($exception).': '.$exception->getMessage()]); |
|
| 142 | 142 | $success = false; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | $this->emit('\OC\Updater', 'maintenanceActive'); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 154 | + $this->emit('\OC\Updater', 'resetLogLevel', [$logLevel, $this->logLevelNames[$logLevel]]); |
|
| 155 | 155 | $this->config->setSystemValue('loglevel', $logLevel); |
| 156 | 156 | $this->config->setSystemValue('installed', true); |
| 157 | 157 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | private function getAllowedPreviousVersions(): array { |
| 167 | 167 | // this should really be a JSON file |
| 168 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 168 | + require \OC::$SERVERROOT.'/version.php'; |
|
| 169 | 169 | /** @var array $OC_VersionCanBeUpgradedFrom */ |
| 170 | 170 | return $OC_VersionCanBeUpgradedFrom; |
| 171 | 171 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | private function getVendor(): string { |
| 179 | 179 | // this should really be a JSON file |
| 180 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 180 | + require \OC::$SERVERROOT.'/version.php'; |
|
| 181 | 181 | /** @var string $vendor */ |
| 182 | 182 | return (string) $vendor; |
| 183 | 183 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | public function isUpgradePossible(string $oldVersion, string $newVersion, array $allowedPreviousVersions): bool { |
| 193 | 193 | $version = explode('.', $oldVersion); |
| 194 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
| 194 | + $majorMinor = $version[0].'.'.$version[1]; |
|
| 195 | 195 | |
| 196 | 196 | $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
| 197 | 197 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | // create empty file in data dir, so we can later find |
| 243 | 243 | // out that this is indeed an ownCloud data directory |
| 244 | 244 | // (in case it didn't exist before) |
| 245 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 245 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', ''); |
|
| 246 | 246 | |
| 247 | 247 | // pre-upgrade repairs |
| 248 | 248 | $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)); |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | 'exception' => $exception, |
| 278 | 278 | 'app' => $appId, |
| 279 | 279 | ]); |
| 280 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 280 | + $this->emit('\OC\Updater', 'failure', [$appId.': '.$exception->getMessage()]); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // post-upgrade repairs |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | $info = OC_App::getAppInfo($app); |
| 376 | 376 | if ($info === null || !OC_App::isAppCompatible($version, $info)) { |
| 377 | 377 | if ($appManager->isShipped($app)) { |
| 378 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 378 | + throw new \UnexpectedValueException('The files of the app "'.$app.'" were not correctly replaced before running the update'); |
|
| 379 | 379 | } |
| 380 | 380 | \OC::$server->getAppManager()->disableApp($app, true); |
| 381 | 381 | $this->emit('\OC\Updater', 'incompatibleAppDisabled', [$app]); |
@@ -440,22 +440,22 @@ discard block |
||
| 440 | 440 | */ |
| 441 | 441 | private function emitRepairEvents(): void { |
| 442 | 442 | $dispatcher = \OC::$server->getEventDispatcher(); |
| 443 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 443 | + $dispatcher->addListener('\OC\Repair::warning', function($event) { |
|
| 444 | 444 | if ($event instanceof GenericEvent) { |
| 445 | 445 | $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
| 446 | 446 | } |
| 447 | 447 | }); |
| 448 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 448 | + $dispatcher->addListener('\OC\Repair::error', function($event) { |
|
| 449 | 449 | if ($event instanceof GenericEvent) { |
| 450 | 450 | $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
| 451 | 451 | } |
| 452 | 452 | }); |
| 453 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 453 | + $dispatcher->addListener('\OC\Repair::info', function($event) { |
|
| 454 | 454 | if ($event instanceof GenericEvent) { |
| 455 | 455 | $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
| 456 | 456 | } |
| 457 | 457 | }); |
| 458 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 458 | + $dispatcher->addListener('\OC\Repair::step', function($event) { |
|
| 459 | 459 | if ($event instanceof GenericEvent) { |
| 460 | 460 | $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
| 461 | 461 | } |
@@ -466,49 +466,49 @@ discard block |
||
| 466 | 466 | $log = $this->log; |
| 467 | 467 | |
| 468 | 468 | $dispatcher = \OC::$server->getEventDispatcher(); |
| 469 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($log) { |
|
| 469 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
| 470 | 470 | if (!$event instanceof GenericEvent) { |
| 471 | 471 | return; |
| 472 | 472 | } |
| 473 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 473 | + $log->info('\OC\DB\Migrator::executeSql: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']); |
|
| 474 | 474 | }); |
| 475 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($log) { |
|
| 475 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
| 476 | 476 | if (!$event instanceof GenericEvent) { |
| 477 | 477 | return; |
| 478 | 478 | } |
| 479 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 479 | + $log->info('\OC\DB\Migrator::checkTable: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']); |
|
| 480 | 480 | }); |
| 481 | 481 | |
| 482 | - $repairListener = function ($event) use ($log) { |
|
| 482 | + $repairListener = function($event) use ($log) { |
|
| 483 | 483 | if (!$event instanceof GenericEvent) { |
| 484 | 484 | return; |
| 485 | 485 | } |
| 486 | 486 | switch ($event->getSubject()) { |
| 487 | 487 | case '\OC\Repair::startProgress': |
| 488 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 488 | + $log->info('\OC\Repair::startProgress: Starting ... '.$event->getArgument(1).' ('.$event->getArgument(0).')', ['app' => 'updater']); |
|
| 489 | 489 | break; |
| 490 | 490 | case '\OC\Repair::advance': |
| 491 | 491 | $desc = $event->getArgument(1); |
| 492 | 492 | if (empty($desc)) { |
| 493 | 493 | $desc = ''; |
| 494 | 494 | } |
| 495 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 495 | + $log->info('\OC\Repair::advance: '.$desc.' ('.$event->getArgument(0).')', ['app' => 'updater']); |
|
| 496 | 496 | |
| 497 | 497 | break; |
| 498 | 498 | case '\OC\Repair::finishProgress': |
| 499 | 499 | $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
| 500 | 500 | break; |
| 501 | 501 | case '\OC\Repair::step': |
| 502 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 502 | + $log->info('\OC\Repair::step: Repair step: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 503 | 503 | break; |
| 504 | 504 | case '\OC\Repair::info': |
| 505 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 505 | + $log->info('\OC\Repair::info: Repair info: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 506 | 506 | break; |
| 507 | 507 | case '\OC\Repair::warning': |
| 508 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 508 | + $log->warning('\OC\Repair::warning: Repair warning: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 509 | 509 | break; |
| 510 | 510 | case '\OC\Repair::error': |
| 511 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 511 | + $log->error('\OC\Repair::error: Repair error: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 512 | 512 | break; |
| 513 | 513 | } |
| 514 | 514 | }; |
@@ -522,62 +522,62 @@ discard block |
||
| 522 | 522 | $dispatcher->addListener('\OC\Repair::error', $repairListener); |
| 523 | 523 | |
| 524 | 524 | |
| 525 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use ($log) { |
|
| 525 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function() use ($log) { |
|
| 526 | 526 | $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
| 527 | 527 | }); |
| 528 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use ($log) { |
|
| 528 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function() use ($log) { |
|
| 529 | 529 | $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
| 530 | 530 | }); |
| 531 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use ($log) { |
|
| 531 | + $this->listen('\OC\Updater', 'maintenanceActive', function() use ($log) { |
|
| 532 | 532 | $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
| 533 | 533 | }); |
| 534 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use ($log) { |
|
| 534 | + $this->listen('\OC\Updater', 'updateEnd', function($success) use ($log) { |
|
| 535 | 535 | if ($success) { |
| 536 | 536 | $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
| 537 | 537 | } else { |
| 538 | 538 | $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
| 539 | 539 | } |
| 540 | 540 | }); |
| 541 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($log) { |
|
| 541 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function() use ($log) { |
|
| 542 | 542 | $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
| 543 | 543 | }); |
| 544 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use ($log) { |
|
| 544 | + $this->listen('\OC\Updater', 'dbUpgrade', function() use ($log) { |
|
| 545 | 545 | $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
| 546 | 546 | }); |
| 547 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($log) { |
|
| 548 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 547 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use ($log) { |
|
| 548 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: '.$app, ['app' => 'updater']); |
|
| 549 | 549 | }); |
| 550 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($log) { |
|
| 551 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 550 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use ($log) { |
|
| 551 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "'.$app.'" in appstore', ['app' => 'updater']); |
|
| 552 | 552 | }); |
| 553 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($log) { |
|
| 554 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 553 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use ($log) { |
|
| 554 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "'.$app.'" from appstore', ['app' => 'updater']); |
|
| 555 | 555 | }); |
| 556 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($log) { |
|
| 557 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 556 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function($app) use ($log) { |
|
| 557 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "'.$app.'" in appstore', ['app' => 'updater']); |
|
| 558 | 558 | }); |
| 559 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 560 | - $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 559 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($log) { |
|
| 560 | + $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <'.$app.'> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 561 | 561 | }); |
| 562 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 563 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 562 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function($app) use ($log) { |
|
| 563 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <'.$app.'> ...', ['app' => 'updater']); |
|
| 564 | 564 | }); |
| 565 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 566 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 565 | + $this->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($log) { |
|
| 566 | + $log->info('\OC\Updater::appUpgrade: Updated <'.$app.'> to '.$version, ['app' => 'updater']); |
|
| 567 | 567 | }); |
| 568 | - $this->listen('\OC\Updater', 'failure', function ($message) use ($log) { |
|
| 569 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 568 | + $this->listen('\OC\Updater', 'failure', function($message) use ($log) { |
|
| 569 | + $log->error('\OC\Updater::failure: '.$message, ['app' => 'updater']); |
|
| 570 | 570 | }); |
| 571 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use ($log) { |
|
| 571 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function() use ($log) { |
|
| 572 | 572 | $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
| 573 | 573 | }); |
| 574 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($log) { |
|
| 575 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 574 | + $this->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use ($log) { |
|
| 575 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to '.$logLevelName.'('.$logLevel.')', ['app' => 'updater']); |
|
| 576 | 576 | }); |
| 577 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($log) { |
|
| 577 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use ($log) { |
|
| 578 | 578 | $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
| 579 | 579 | }); |
| 580 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($log) { |
|
| 580 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use ($log) { |
|
| 581 | 581 | $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
| 582 | 582 | }); |
| 583 | 583 | } |
@@ -77,1005 +77,1005 @@ |
||
| 77 | 77 | * OC_autoload! |
| 78 | 78 | */ |
| 79 | 79 | class OC { |
| 80 | - /** |
|
| 81 | - * Associative array for autoloading. classname => filename |
|
| 82 | - */ |
|
| 83 | - public static $CLASSPATH = []; |
|
| 84 | - /** |
|
| 85 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 86 | - */ |
|
| 87 | - public static $SERVERROOT = ''; |
|
| 88 | - /** |
|
| 89 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 90 | - */ |
|
| 91 | - private static $SUBURI = ''; |
|
| 92 | - /** |
|
| 93 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
| 94 | - */ |
|
| 95 | - public static $WEBROOT = ''; |
|
| 96 | - /** |
|
| 97 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 98 | - * web path in 'url' |
|
| 99 | - */ |
|
| 100 | - public static $APPSROOTS = []; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public static $configDir; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * requested app |
|
| 109 | - */ |
|
| 110 | - public static $REQUESTEDAPP = ''; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * check if Nextcloud runs in cli mode |
|
| 114 | - */ |
|
| 115 | - public static $CLI = false; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @var \OC\Autoloader $loader |
|
| 119 | - */ |
|
| 120 | - public static $loader = null; |
|
| 121 | - |
|
| 122 | - /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
| 123 | - public static $composerAutoloader = null; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @var \OC\Server |
|
| 127 | - */ |
|
| 128 | - public static $server = null; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @var \OC\Config |
|
| 132 | - */ |
|
| 133 | - private static $config = null; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 137 | - * the app path list is empty or contains an invalid path |
|
| 138 | - */ |
|
| 139 | - public static function initPaths() { |
|
| 140 | - if (defined('PHPUNIT_CONFIG_DIR')) { |
|
| 141 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 142 | - } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 143 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 144 | - } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 145 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
| 146 | - } else { |
|
| 147 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 148 | - } |
|
| 149 | - self::$config = new \OC\Config(self::$configDir); |
|
| 150 | - |
|
| 151 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
| 152 | - /** |
|
| 153 | - * FIXME: The following lines are required because we can't yet instantiate |
|
| 154 | - * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
| 155 | - */ |
|
| 156 | - $params = [ |
|
| 157 | - 'server' => [ |
|
| 158 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
| 159 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
| 160 | - ], |
|
| 161 | - ]; |
|
| 162 | - $fakeRequest = new \OC\AppFramework\Http\Request($params, new \OC\Security\SecureRandom(), new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
| 163 | - $scriptName = $fakeRequest->getScriptName(); |
|
| 164 | - if (substr($scriptName, -1) == '/') { |
|
| 165 | - $scriptName .= 'index.php'; |
|
| 166 | - //make sure suburi follows the same rules as scriptName |
|
| 167 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 168 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
| 169 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 170 | - } |
|
| 171 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - if (OC::$CLI) { |
|
| 177 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 178 | - } else { |
|
| 179 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 180 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 181 | - |
|
| 182 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 183 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 184 | - } |
|
| 185 | - } else { |
|
| 186 | - // The scriptName is not ending with OC::$SUBURI |
|
| 187 | - // This most likely means that we are calling from CLI. |
|
| 188 | - // However some cron jobs still need to generate |
|
| 189 | - // a web URL, so we use overwritewebroot as a fallback. |
|
| 190 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 194 | - // slash which is required by URL generation. |
|
| 195 | - if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 196 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 197 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
| 198 | - exit(); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // search the apps folder |
|
| 203 | - $config_paths = self::$config->getValue('apps_paths', []); |
|
| 204 | - if (!empty($config_paths)) { |
|
| 205 | - foreach ($config_paths as $paths) { |
|
| 206 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
| 207 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
| 208 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
| 209 | - OC::$APPSROOTS[] = $paths; |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 213 | - OC::$APPSROOTS[] = ['path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true]; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (empty(OC::$APPSROOTS)) { |
|
| 217 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 218 | - . '. You can also configure the location in the config.php file.'); |
|
| 219 | - } |
|
| 220 | - $paths = []; |
|
| 221 | - foreach (OC::$APPSROOTS as $path) { |
|
| 222 | - $paths[] = $path['path']; |
|
| 223 | - if (!is_dir($path['path'])) { |
|
| 224 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 225 | - . ' Nextcloud folder. You can also configure the location in the config.php file.', $path['path'])); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // set the right include path |
|
| 230 | - set_include_path( |
|
| 231 | - implode(PATH_SEPARATOR, $paths) |
|
| 232 | - ); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - public static function checkConfig() { |
|
| 236 | - $l = \OC::$server->getL10N('lib'); |
|
| 237 | - |
|
| 238 | - // Create config if it does not already exist |
|
| 239 | - $configFilePath = self::$configDir .'/config.php'; |
|
| 240 | - if (!file_exists($configFilePath)) { |
|
| 241 | - @touch($configFilePath); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Check if config is writable |
|
| 245 | - $configFileWritable = is_writable($configFilePath); |
|
| 246 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
| 247 | - || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
| 248 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 249 | - |
|
| 250 | - if (self::$CLI) { |
|
| 251 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
| 252 | - echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
| 253 | - echo "\n"; |
|
| 254 | - echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
|
| 255 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
| 256 | - exit; |
|
| 257 | - } else { |
|
| 258 | - OC_Template::printErrorPage( |
|
| 259 | - $l->t('Cannot write into "config" directory!'), |
|
| 260 | - $l->t('This can usually be fixed by giving the webserver write access to the config directory.') . '. ' |
|
| 261 | - . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
| 262 | - [ $urlGenerator->linkToDocs('admin-config') ]), |
|
| 263 | - 503 |
|
| 264 | - ); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - public static function checkInstalled(\OC\SystemConfig $systemConfig) { |
|
| 270 | - if (defined('OC_CONSOLE')) { |
|
| 271 | - return; |
|
| 272 | - } |
|
| 273 | - // Redirect to installer if not installed |
|
| 274 | - if (!$systemConfig->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 275 | - if (OC::$CLI) { |
|
| 276 | - throw new Exception('Not installed'); |
|
| 277 | - } else { |
|
| 278 | - $url = OC::$WEBROOT . '/index.php'; |
|
| 279 | - header('Location: ' . $url); |
|
| 280 | - } |
|
| 281 | - exit(); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - public static function checkMaintenanceMode(\OC\SystemConfig $systemConfig) { |
|
| 286 | - // Allow ajax update script to execute without being stopped |
|
| 287 | - if (((bool) $systemConfig->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 288 | - // send http status 503 |
|
| 289 | - http_response_code(503); |
|
| 290 | - header('Retry-After: 120'); |
|
| 291 | - |
|
| 292 | - // render error page |
|
| 293 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
| 294 | - OC_Util::addScript('dist/maintenance'); |
|
| 295 | - OC_Util::addStyle('core', 'guest'); |
|
| 296 | - $template->printPage(); |
|
| 297 | - die(); |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Prints the upgrade page |
|
| 303 | - * |
|
| 304 | - * @param \OC\SystemConfig $systemConfig |
|
| 305 | - */ |
|
| 306 | - private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
| 307 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 308 | - $tooBig = false; |
|
| 309 | - if (!$disableWebUpdater) { |
|
| 310 | - $apps = \OC::$server->getAppManager(); |
|
| 311 | - if ($apps->isInstalled('user_ldap')) { |
|
| 312 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 313 | - |
|
| 314 | - $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 315 | - ->from('ldap_user_mapping') |
|
| 316 | - ->execute(); |
|
| 317 | - $row = $result->fetch(); |
|
| 318 | - $result->closeCursor(); |
|
| 319 | - |
|
| 320 | - $tooBig = ($row['user_count'] > 50); |
|
| 321 | - } |
|
| 322 | - if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
| 323 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 324 | - |
|
| 325 | - $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 326 | - ->from('user_saml_users') |
|
| 327 | - ->execute(); |
|
| 328 | - $row = $result->fetch(); |
|
| 329 | - $result->closeCursor(); |
|
| 330 | - |
|
| 331 | - $tooBig = ($row['user_count'] > 50); |
|
| 332 | - } |
|
| 333 | - if (!$tooBig) { |
|
| 334 | - // count users |
|
| 335 | - $stats = \OC::$server->getUserManager()->countUsers(); |
|
| 336 | - $totalUsers = array_sum($stats); |
|
| 337 | - $tooBig = ($totalUsers > 50); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
| 341 | - $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
| 342 | - |
|
| 343 | - if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
| 344 | - // send http status 503 |
|
| 345 | - http_response_code(503); |
|
| 346 | - header('Retry-After: 120'); |
|
| 347 | - |
|
| 348 | - // render error page |
|
| 349 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
| 350 | - $template->assign('productName', 'nextcloud'); // for now |
|
| 351 | - $template->assign('version', OC_Util::getVersionString()); |
|
| 352 | - $template->assign('tooBig', $tooBig); |
|
| 353 | - |
|
| 354 | - $template->printPage(); |
|
| 355 | - die(); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // check whether this is a core update or apps update |
|
| 359 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 360 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 361 | - |
|
| 362 | - // if not a core upgrade, then it's apps upgrade |
|
| 363 | - $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
| 364 | - |
|
| 365 | - $oldTheme = $systemConfig->getValue('theme'); |
|
| 366 | - $systemConfig->setValue('theme', ''); |
|
| 367 | - OC_Util::addScript('update'); |
|
| 368 | - |
|
| 369 | - /** @var \OC\App\AppManager $appManager */ |
|
| 370 | - $appManager = \OC::$server->getAppManager(); |
|
| 371 | - |
|
| 372 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
| 373 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
| 374 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 375 | - |
|
| 376 | - // get third party apps |
|
| 377 | - $ocVersion = \OCP\Util::getVersion(); |
|
| 378 | - $ocVersion = implode('.', $ocVersion); |
|
| 379 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 380 | - $incompatibleShippedApps = []; |
|
| 381 | - foreach ($incompatibleApps as $appInfo) { |
|
| 382 | - if ($appManager->isShipped($appInfo['id'])) { |
|
| 383 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if (!empty($incompatibleShippedApps)) { |
|
| 388 | - $l = \OC::$server->getL10N('core'); |
|
| 389 | - $hint = $l->t('The files of the app %1$s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
| 390 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 394 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
| 395 | - try { |
|
| 396 | - $defaults = new \OC_Defaults(); |
|
| 397 | - $tmpl->assign('productName', $defaults->getName()); |
|
| 398 | - } catch (Throwable $error) { |
|
| 399 | - $tmpl->assign('productName', 'Nextcloud'); |
|
| 400 | - } |
|
| 401 | - $tmpl->assign('oldTheme', $oldTheme); |
|
| 402 | - $tmpl->printPage(); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - public static function initSession() { |
|
| 406 | - if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 407 | - ini_set('session.cookie_secure', 'true'); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - // prevents javascript from accessing php session cookies |
|
| 411 | - ini_set('session.cookie_httponly', 'true'); |
|
| 412 | - |
|
| 413 | - // set the cookie path to the Nextcloud directory |
|
| 414 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 415 | - ini_set('session.cookie_path', $cookie_path); |
|
| 416 | - |
|
| 417 | - // Let the session name be changed in the initSession Hook |
|
| 418 | - $sessionName = OC_Util::getInstanceId(); |
|
| 419 | - |
|
| 420 | - try { |
|
| 421 | - // set the session name to the instance id - which is unique |
|
| 422 | - $session = new \OC\Session\Internal($sessionName); |
|
| 423 | - |
|
| 424 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 425 | - $session = $cryptoWrapper->wrapSession($session); |
|
| 426 | - self::$server->setSession($session); |
|
| 427 | - |
|
| 428 | - // if session can't be started break with http 500 error |
|
| 429 | - } catch (Exception $e) { |
|
| 430 | - \OC::$server->getLogger()->logException($e, ['app' => 'base']); |
|
| 431 | - //show the user a detailed error page |
|
| 432 | - OC_Template::printExceptionErrorPage($e, 500); |
|
| 433 | - die(); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 437 | - |
|
| 438 | - // session timeout |
|
| 439 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 440 | - if (isset($_COOKIE[session_name()])) { |
|
| 441 | - setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
| 442 | - } |
|
| 443 | - \OC::$server->getUserSession()->logout(); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - $session->set('LAST_ACTIVITY', time()); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * @return string |
|
| 451 | - */ |
|
| 452 | - private static function getSessionLifeTime() { |
|
| 453 | - return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Try to set some values to the required Nextcloud default |
|
| 458 | - */ |
|
| 459 | - public static function setRequiredIniValues() { |
|
| 460 | - @ini_set('default_charset', 'UTF-8'); |
|
| 461 | - @ini_set('gd.jpeg_ignore_warning', '1'); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * Send the same site cookies |
|
| 466 | - */ |
|
| 467 | - private static function sendSameSiteCookies() { |
|
| 468 | - $cookieParams = session_get_cookie_params(); |
|
| 469 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 470 | - $policies = [ |
|
| 471 | - 'lax', |
|
| 472 | - 'strict', |
|
| 473 | - ]; |
|
| 474 | - |
|
| 475 | - // Append __Host to the cookie if it meets the requirements |
|
| 476 | - $cookiePrefix = ''; |
|
| 477 | - if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 478 | - $cookiePrefix = '__Host-'; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - foreach ($policies as $policy) { |
|
| 482 | - header( |
|
| 483 | - sprintf( |
|
| 484 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 485 | - $cookiePrefix, |
|
| 486 | - $policy, |
|
| 487 | - $cookieParams['path'], |
|
| 488 | - $policy |
|
| 489 | - ), |
|
| 490 | - false |
|
| 491 | - ); |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 497 | - * be set in every request if cookies are sent to add a second level of |
|
| 498 | - * defense against CSRF. |
|
| 499 | - * |
|
| 500 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
| 501 | - * We use an additional cookie since we want to protect logout CSRF and |
|
| 502 | - * also we can't directly interfere with PHP's session mechanism. |
|
| 503 | - */ |
|
| 504 | - private static function performSameSiteCookieProtection(\OCP\IConfig $config) { |
|
| 505 | - $request = \OC::$server->getRequest(); |
|
| 506 | - |
|
| 507 | - // Some user agents are notorious and don't really properly follow HTTP |
|
| 508 | - // specifications. For those, have an automated opt-out. Since the protection |
|
| 509 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
| 510 | - // here. |
|
| 511 | - $incompatibleUserAgents = $config->getSystemValue('csrf.optout'); |
|
| 512 | - |
|
| 513 | - // Fallback, if csrf.optout is unset |
|
| 514 | - if (!is_array($incompatibleUserAgents)) { |
|
| 515 | - $incompatibleUserAgents = [ |
|
| 516 | - // OS X Finder |
|
| 517 | - '/^WebDAVFS/', |
|
| 518 | - // Windows webdav drive |
|
| 519 | - '/^Microsoft-WebDAV-MiniRedir/', |
|
| 520 | - ]; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - if ($request->isUserAgent($incompatibleUserAgents)) { |
|
| 524 | - return; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - if (count($_COOKIE) > 0) { |
|
| 528 | - $requestUri = $request->getScriptName(); |
|
| 529 | - $processingScript = explode('/', $requestUri); |
|
| 530 | - $processingScript = $processingScript[count($processingScript) - 1]; |
|
| 531 | - |
|
| 532 | - // index.php routes are handled in the middleware |
|
| 533 | - if ($processingScript === 'index.php') { |
|
| 534 | - return; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - // All other endpoints require the lax and the strict cookie |
|
| 538 | - if (!$request->passesStrictCookieCheck()) { |
|
| 539 | - self::sendSameSiteCookies(); |
|
| 540 | - // Debug mode gets access to the resources without strict cookie |
|
| 541 | - // due to the fact that the SabreDAV browser also lives there. |
|
| 542 | - if (!$config->getSystemValue('debug', false)) { |
|
| 543 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 544 | - exit(); |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 548 | - self::sendSameSiteCookies(); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - public static function init() { |
|
| 553 | - // calculate the root directories |
|
| 554 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
| 555 | - |
|
| 556 | - // register autoloader |
|
| 557 | - $loaderStart = microtime(true); |
|
| 558 | - require_once __DIR__ . '/autoloader.php'; |
|
| 559 | - self::$loader = new \OC\Autoloader([ |
|
| 560 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
| 561 | - ]); |
|
| 562 | - if (defined('PHPUNIT_RUN')) { |
|
| 563 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 564 | - } |
|
| 565 | - spl_autoload_register([self::$loader, 'load']); |
|
| 566 | - $loaderEnd = microtime(true); |
|
| 567 | - |
|
| 568 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
| 569 | - |
|
| 570 | - // Add default composer PSR-4 autoloader |
|
| 571 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 572 | - |
|
| 573 | - try { |
|
| 574 | - self::initPaths(); |
|
| 575 | - // setup 3rdparty autoloader |
|
| 576 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 577 | - if (!file_exists($vendorAutoLoad)) { |
|
| 578 | - throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 579 | - } |
|
| 580 | - require_once $vendorAutoLoad; |
|
| 581 | - } catch (\RuntimeException $e) { |
|
| 582 | - if (!self::$CLI) { |
|
| 583 | - http_response_code(503); |
|
| 584 | - } |
|
| 585 | - // we can't use the template error page here, because this needs the |
|
| 586 | - // DI container which isn't available yet |
|
| 587 | - print($e->getMessage()); |
|
| 588 | - exit(); |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - // setup the basic server |
|
| 592 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 593 | - self::$server->boot(); |
|
| 594 | - $eventLogger = \OC::$server->getEventLogger(); |
|
| 595 | - $eventLogger->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 596 | - $eventLogger->start('boot', 'Initialize'); |
|
| 597 | - |
|
| 598 | - // Override php.ini and log everything if we're troubleshooting |
|
| 599 | - if (self::$config->getValue('loglevel') === ILogger::DEBUG) { |
|
| 600 | - error_reporting(E_ALL); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - // Don't display errors and log them |
|
| 604 | - @ini_set('display_errors', '0'); |
|
| 605 | - @ini_set('log_errors', '1'); |
|
| 606 | - |
|
| 607 | - if (!date_default_timezone_set('UTC')) { |
|
| 608 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - //try to configure php to enable big file uploads. |
|
| 612 | - //this doesn´t work always depending on the webserver and php configuration. |
|
| 613 | - //Let´s try to overwrite some defaults anyway |
|
| 614 | - |
|
| 615 | - //try to set the maximum execution time to 60min |
|
| 616 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 617 | - @set_time_limit(3600); |
|
| 618 | - } |
|
| 619 | - @ini_set('max_execution_time', '3600'); |
|
| 620 | - @ini_set('max_input_time', '3600'); |
|
| 621 | - |
|
| 622 | - self::setRequiredIniValues(); |
|
| 623 | - self::handleAuthHeaders(); |
|
| 624 | - $systemConfig = \OC::$server->get(\OC\SystemConfig::class); |
|
| 625 | - self::registerAutoloaderCache($systemConfig); |
|
| 626 | - |
|
| 627 | - // initialize intl fallback if necessary |
|
| 628 | - OC_Util::isSetLocaleWorking(); |
|
| 629 | - |
|
| 630 | - $config = \OC::$server->get(\OCP\IConfig::class); |
|
| 631 | - if (!defined('PHPUNIT_RUN')) { |
|
| 632 | - OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
| 633 | - $debug = $config->getSystemValue('debug', false); |
|
| 634 | - OC\Log\ErrorHandler::register($debug); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - /** @var \OC\AppFramework\Bootstrap\Coordinator $bootstrapCoordinator */ |
|
| 638 | - $bootstrapCoordinator = \OC::$server->query(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
| 639 | - $bootstrapCoordinator->runInitialRegistration(); |
|
| 640 | - |
|
| 641 | - $eventLogger->start('init_session', 'Initialize session'); |
|
| 642 | - OC_App::loadApps(['session']); |
|
| 643 | - if (!self::$CLI) { |
|
| 644 | - self::initSession(); |
|
| 645 | - } |
|
| 646 | - $eventLogger->end('init_session'); |
|
| 647 | - self::checkConfig(); |
|
| 648 | - self::checkInstalled($systemConfig); |
|
| 649 | - |
|
| 650 | - OC_Response::addSecurityHeaders(); |
|
| 651 | - |
|
| 652 | - self::performSameSiteCookieProtection($config); |
|
| 653 | - |
|
| 654 | - if (!defined('OC_CONSOLE')) { |
|
| 655 | - $errors = OC_Util::checkServer($systemConfig); |
|
| 656 | - if (count($errors) > 0) { |
|
| 657 | - if (!self::$CLI) { |
|
| 658 | - http_response_code(503); |
|
| 659 | - OC_Util::addStyle('guest'); |
|
| 660 | - try { |
|
| 661 | - OC_Template::printGuestPage('', 'error', ['errors' => $errors]); |
|
| 662 | - exit; |
|
| 663 | - } catch (\Exception $e) { |
|
| 664 | - // In case any error happens when showing the error page, we simply fall back to posting the text. |
|
| 665 | - // This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it. |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - // Convert l10n string into regular string for usage in database |
|
| 670 | - $staticErrors = []; |
|
| 671 | - foreach ($errors as $error) { |
|
| 672 | - echo $error['error'] . "\n"; |
|
| 673 | - echo $error['hint'] . "\n\n"; |
|
| 674 | - $staticErrors[] = [ |
|
| 675 | - 'error' => (string)$error['error'], |
|
| 676 | - 'hint' => (string)$error['hint'], |
|
| 677 | - ]; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - try { |
|
| 681 | - $config->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 682 | - } catch (\Exception $e) { |
|
| 683 | - echo('Writing to database failed'); |
|
| 684 | - } |
|
| 685 | - exit(1); |
|
| 686 | - } elseif (self::$CLI && $config->getSystemValue('installed', false)) { |
|
| 687 | - $config->deleteAppValue('core', 'cronErrors'); |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - //try to set the session lifetime |
|
| 691 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 692 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 693 | - |
|
| 694 | - // User and Groups |
|
| 695 | - if (!$systemConfig->getValue("installed", false)) { |
|
| 696 | - self::$server->getSession()->set('user_id', ''); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - OC_User::useBackend(new \OC\User\Database()); |
|
| 700 | - \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
| 701 | - |
|
| 702 | - // Subscribe to the hook |
|
| 703 | - \OCP\Util::connectHook( |
|
| 704 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 705 | - 'preLoginNameUsedAsUserName', |
|
| 706 | - '\OC\User\Database', |
|
| 707 | - 'preLoginNameUsedAsUserName' |
|
| 708 | - ); |
|
| 709 | - |
|
| 710 | - //setup extra user backends |
|
| 711 | - if (!\OCP\Util::needUpgrade()) { |
|
| 712 | - OC_User::setupBackends(); |
|
| 713 | - } else { |
|
| 714 | - // Run upgrades in incognito mode |
|
| 715 | - OC_User::setIncognitoMode(true); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - self::registerCleanupHooks($systemConfig); |
|
| 719 | - self::registerFilesystemHooks(); |
|
| 720 | - self::registerShareHooks($systemConfig); |
|
| 721 | - self::registerEncryptionWrapperAndHooks(); |
|
| 722 | - self::registerAccountHooks(); |
|
| 723 | - self::registerResourceCollectionHooks(); |
|
| 724 | - self::registerAppRestrictionsHooks(); |
|
| 725 | - |
|
| 726 | - // Make sure that the application class is not loaded before the database is setup |
|
| 727 | - if ($systemConfig->getValue("installed", false)) { |
|
| 728 | - OC_App::loadApp('settings'); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - //make sure temporary files are cleaned up |
|
| 732 | - $tmpManager = \OC::$server->getTempManager(); |
|
| 733 | - register_shutdown_function([$tmpManager, 'clean']); |
|
| 734 | - $lockProvider = \OC::$server->getLockingProvider(); |
|
| 735 | - register_shutdown_function([$lockProvider, 'releaseAll']); |
|
| 736 | - |
|
| 737 | - // Check whether the sample configuration has been copied |
|
| 738 | - if ($systemConfig->getValue('copied_sample_config', false)) { |
|
| 739 | - $l = \OC::$server->getL10N('lib'); |
|
| 740 | - OC_Template::printErrorPage( |
|
| 741 | - $l->t('Sample configuration detected'), |
|
| 742 | - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), |
|
| 743 | - 503 |
|
| 744 | - ); |
|
| 745 | - return; |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - $request = \OC::$server->getRequest(); |
|
| 749 | - $host = $request->getInsecureServerHost(); |
|
| 750 | - /** |
|
| 751 | - * if the host passed in headers isn't trusted |
|
| 752 | - * FIXME: Should not be in here at all :see_no_evil: |
|
| 753 | - */ |
|
| 754 | - if (!OC::$CLI |
|
| 755 | - && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
| 756 | - && $config->getSystemValue('installed', false) |
|
| 757 | - ) { |
|
| 758 | - // Allow access to CSS resources |
|
| 759 | - $isScssRequest = false; |
|
| 760 | - if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 761 | - $isScssRequest = true; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
| 765 | - http_response_code(400); |
|
| 766 | - header('Content-Type: application/json'); |
|
| 767 | - echo '{"error": "Trusted domain error.", "code": 15}'; |
|
| 768 | - exit(); |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - if (!$isScssRequest) { |
|
| 772 | - http_response_code(400); |
|
| 773 | - |
|
| 774 | - \OC::$server->getLogger()->info( |
|
| 775 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 776 | - [ |
|
| 777 | - 'app' => 'core', |
|
| 778 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
| 779 | - 'host' => $host, |
|
| 780 | - ] |
|
| 781 | - ); |
|
| 782 | - |
|
| 783 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
| 784 | - $tmpl->assign('docUrl', \OC::$server->getURLGenerator()->linkToDocs('admin-trusted-domains')); |
|
| 785 | - $tmpl->printPage(); |
|
| 786 | - |
|
| 787 | - exit(); |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - $eventLogger->end('boot'); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * register hooks for the cleanup of cache and bruteforce protection |
|
| 795 | - */ |
|
| 796 | - public static function registerCleanupHooks(\OC\SystemConfig $systemConfig) { |
|
| 797 | - //don't try to do this before we are properly setup |
|
| 798 | - if ($systemConfig->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
| 799 | - |
|
| 800 | - // NOTE: This will be replaced to use OCP |
|
| 801 | - $userSession = self::$server->getUserSession(); |
|
| 802 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 803 | - if (!defined('PHPUNIT_RUN') && $userSession->isLoggedIn()) { |
|
| 804 | - // reset brute force delay for this IP address and username |
|
| 805 | - $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
| 806 | - $request = \OC::$server->getRequest(); |
|
| 807 | - $throttler = \OC::$server->getBruteForceThrottler(); |
|
| 808 | - $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - try { |
|
| 812 | - $cache = new \OC\Cache\File(); |
|
| 813 | - $cache->gc(); |
|
| 814 | - } catch (\OC\ServerNotAvailableException $e) { |
|
| 815 | - // not a GC exception, pass it on |
|
| 816 | - throw $e; |
|
| 817 | - } catch (\OC\ForbiddenException $e) { |
|
| 818 | - // filesystem blocked for this request, ignore |
|
| 819 | - } catch (\Exception $e) { |
|
| 820 | - // a GC exception should not prevent users from using OC, |
|
| 821 | - // so log the exception |
|
| 822 | - \OC::$server->getLogger()->logException($e, [ |
|
| 823 | - 'message' => 'Exception when running cache gc.', |
|
| 824 | - 'level' => ILogger::WARN, |
|
| 825 | - 'app' => 'core', |
|
| 826 | - ]); |
|
| 827 | - } |
|
| 828 | - }); |
|
| 829 | - } |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - private static function registerEncryptionWrapperAndHooks() { |
|
| 833 | - $manager = self::$server->getEncryptionManager(); |
|
| 834 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
| 835 | - |
|
| 836 | - $enabled = $manager->isEnabled(); |
|
| 837 | - if ($enabled) { |
|
| 838 | - \OCP\Util::connectHook(Share::class, 'post_shared', HookManager::class, 'postShared'); |
|
| 839 | - \OCP\Util::connectHook(Share::class, 'post_unshare', HookManager::class, 'postUnshared'); |
|
| 840 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', HookManager::class, 'postRename'); |
|
| 841 | - \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', HookManager::class, 'postRestore'); |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - private static function registerAccountHooks() { |
|
| 846 | - $hookHandler = \OC::$server->get(\OC\Accounts\Hooks::class); |
|
| 847 | - \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - private static function registerAppRestrictionsHooks() { |
|
| 851 | - /** @var \OC\Group\Manager $groupManager */ |
|
| 852 | - $groupManager = self::$server->query(\OCP\IGroupManager::class); |
|
| 853 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
| 854 | - $appManager = self::$server->getAppManager(); |
|
| 855 | - $apps = $appManager->getEnabledAppsForGroup($group); |
|
| 856 | - foreach ($apps as $appId) { |
|
| 857 | - $restrictions = $appManager->getAppRestriction($appId); |
|
| 858 | - if (empty($restrictions)) { |
|
| 859 | - continue; |
|
| 860 | - } |
|
| 861 | - $key = array_search($group->getGID(), $restrictions); |
|
| 862 | - unset($restrictions[$key]); |
|
| 863 | - $restrictions = array_values($restrictions); |
|
| 864 | - if (empty($restrictions)) { |
|
| 865 | - $appManager->disableApp($appId); |
|
| 866 | - } else { |
|
| 867 | - $appManager->enableAppForGroups($appId, $restrictions); |
|
| 868 | - } |
|
| 869 | - } |
|
| 870 | - }); |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - private static function registerResourceCollectionHooks() { |
|
| 874 | - \OC\Collaboration\Resources\Listener::register(\OC::$server->getEventDispatcher()); |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - /** |
|
| 878 | - * register hooks for the filesystem |
|
| 879 | - */ |
|
| 880 | - public static function registerFilesystemHooks() { |
|
| 881 | - // Check for blacklisted files |
|
| 882 | - OC_Hook::connect('OC_Filesystem', 'write', Filesystem::class, 'isBlacklisted'); |
|
| 883 | - OC_Hook::connect('OC_Filesystem', 'rename', Filesystem::class, 'isBlacklisted'); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * register hooks for sharing |
|
| 888 | - */ |
|
| 889 | - public static function registerShareHooks(\OC\SystemConfig $systemConfig) { |
|
| 890 | - if ($systemConfig->getValue('installed')) { |
|
| 891 | - OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); |
|
| 892 | - OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); |
|
| 893 | - |
|
| 894 | - /** @var IEventDispatcher $dispatcher */ |
|
| 895 | - $dispatcher = \OC::$server->get(IEventDispatcher::class); |
|
| 896 | - $dispatcher->addServiceListener(UserRemovedEvent::class, \OC\Share20\UserRemovedListener::class); |
|
| 897 | - } |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - protected static function registerAutoloaderCache(\OC\SystemConfig $systemConfig) { |
|
| 901 | - // The class loader takes an optional low-latency cache, which MUST be |
|
| 902 | - // namespaced. The instanceid is used for namespacing, but might be |
|
| 903 | - // unavailable at this point. Furthermore, it might not be possible to |
|
| 904 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
| 905 | - // config file may not be writable. As such, we only register a class |
|
| 906 | - // loader cache if instanceid is available without trying to create one. |
|
| 907 | - $instanceId = $systemConfig->getValue('instanceid', null); |
|
| 908 | - if ($instanceId) { |
|
| 909 | - try { |
|
| 910 | - $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
| 911 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
| 912 | - } catch (\Exception $ex) { |
|
| 913 | - } |
|
| 914 | - } |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * Handle the request |
|
| 919 | - */ |
|
| 920 | - public static function handleRequest() { |
|
| 921 | - \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
| 922 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 923 | - |
|
| 924 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 925 | - if (!$systemConfig->getValue('installed', false)) { |
|
| 926 | - \OC::$server->getSession()->clear(); |
|
| 927 | - $setupHelper = new OC\Setup( |
|
| 928 | - $systemConfig, |
|
| 929 | - \OC::$server->get(\bantu\IniGetWrapper\IniGetWrapper::class), |
|
| 930 | - \OC::$server->getL10N('lib'), |
|
| 931 | - \OC::$server->query(\OCP\Defaults::class), |
|
| 932 | - \OC::$server->get(\Psr\Log\LoggerInterface::class), |
|
| 933 | - \OC::$server->getSecureRandom(), |
|
| 934 | - \OC::$server->query(\OC\Installer::class) |
|
| 935 | - ); |
|
| 936 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
| 937 | - $controller->run($_POST); |
|
| 938 | - exit(); |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - $request = \OC::$server->getRequest(); |
|
| 942 | - $requestPath = $request->getRawPathInfo(); |
|
| 943 | - if ($requestPath === '/heartbeat') { |
|
| 944 | - return; |
|
| 945 | - } |
|
| 946 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 947 | - self::checkMaintenanceMode($systemConfig); |
|
| 948 | - |
|
| 949 | - if (\OCP\Util::needUpgrade()) { |
|
| 950 | - if (function_exists('opcache_reset')) { |
|
| 951 | - opcache_reset(); |
|
| 952 | - } |
|
| 953 | - if (!((bool) $systemConfig->getValue('maintenance', false))) { |
|
| 954 | - self::printUpgradePage($systemConfig); |
|
| 955 | - exit(); |
|
| 956 | - } |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - // emergency app disabling |
|
| 961 | - if ($requestPath === '/disableapp' |
|
| 962 | - && $request->getMethod() === 'POST' |
|
| 963 | - && ((array)$request->getParam('appid')) !== '' |
|
| 964 | - ) { |
|
| 965 | - \OC_JSON::callCheck(); |
|
| 966 | - \OC_JSON::checkAdminUser(); |
|
| 967 | - $appIds = (array)$request->getParam('appid'); |
|
| 968 | - foreach ($appIds as $appId) { |
|
| 969 | - $appId = \OC_App::cleanAppId($appId); |
|
| 970 | - \OC::$server->getAppManager()->disableApp($appId); |
|
| 971 | - } |
|
| 972 | - \OC_JSON::success(); |
|
| 973 | - exit(); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - // Always load authentication apps |
|
| 977 | - OC_App::loadApps(['authentication']); |
|
| 978 | - |
|
| 979 | - // Load minimum set of apps |
|
| 980 | - if (!\OCP\Util::needUpgrade() |
|
| 981 | - && !((bool) $systemConfig->getValue('maintenance', false))) { |
|
| 982 | - // For logged-in users: Load everything |
|
| 983 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 984 | - OC_App::loadApps(); |
|
| 985 | - } else { |
|
| 986 | - // For guests: Load only filesystem and logging |
|
| 987 | - OC_App::loadApps(['filesystem', 'logging']); |
|
| 988 | - self::handleLogin($request); |
|
| 989 | - } |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - if (!self::$CLI) { |
|
| 993 | - try { |
|
| 994 | - if (!((bool) $systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) { |
|
| 995 | - OC_App::loadApps(['filesystem', 'logging']); |
|
| 996 | - OC_App::loadApps(); |
|
| 997 | - } |
|
| 998 | - OC::$server->get(\OC\Route\Router::class)->match($request->getRawPathInfo()); |
|
| 999 | - return; |
|
| 1000 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 1001 | - //header('HTTP/1.0 404 Not Found'); |
|
| 1002 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 1003 | - http_response_code(405); |
|
| 1004 | - return; |
|
| 1005 | - } |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - // Handle WebDAV |
|
| 1009 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 1010 | - // not allowed any more to prevent people |
|
| 1011 | - // mounting this root directly. |
|
| 1012 | - // Users need to mount remote.php/webdav instead. |
|
| 1013 | - http_response_code(405); |
|
| 1014 | - return; |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - // Someone is logged in |
|
| 1018 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1019 | - OC_App::loadApps(); |
|
| 1020 | - OC_User::setupBackends(); |
|
| 1021 | - OC_Util::setupFS(); |
|
| 1022 | - // FIXME |
|
| 1023 | - // Redirect to default application |
|
| 1024 | - OC_Util::redirectToDefaultPage(); |
|
| 1025 | - } else { |
|
| 1026 | - // Not handled and not logged in |
|
| 1027 | - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * Check login: apache auth, auth token, basic auth |
|
| 1033 | - * |
|
| 1034 | - * @param OCP\IRequest $request |
|
| 1035 | - * @return boolean |
|
| 1036 | - */ |
|
| 1037 | - public static function handleLogin(OCP\IRequest $request) { |
|
| 1038 | - $userSession = self::$server->getUserSession(); |
|
| 1039 | - if (OC_User::handleApacheAuth()) { |
|
| 1040 | - return true; |
|
| 1041 | - } |
|
| 1042 | - if ($userSession->tryTokenLogin($request)) { |
|
| 1043 | - return true; |
|
| 1044 | - } |
|
| 1045 | - if (isset($_COOKIE['nc_username']) |
|
| 1046 | - && isset($_COOKIE['nc_token']) |
|
| 1047 | - && isset($_COOKIE['nc_session_id']) |
|
| 1048 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1049 | - return true; |
|
| 1050 | - } |
|
| 1051 | - if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
| 1052 | - return true; |
|
| 1053 | - } |
|
| 1054 | - return false; |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - protected static function handleAuthHeaders() { |
|
| 1058 | - //copy http auth headers for apache+php-fcgid work around |
|
| 1059 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1060 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1064 | - $vars = [ |
|
| 1065 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1066 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1067 | - ]; |
|
| 1068 | - foreach ($vars as $var) { |
|
| 1069 | - if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1070 | - $credentials = explode(':', base64_decode($matches[1]), 2); |
|
| 1071 | - if (count($credentials) === 2) { |
|
| 1072 | - $_SERVER['PHP_AUTH_USER'] = $credentials[0]; |
|
| 1073 | - $_SERVER['PHP_AUTH_PW'] = $credentials[1]; |
|
| 1074 | - break; |
|
| 1075 | - } |
|
| 1076 | - } |
|
| 1077 | - } |
|
| 1078 | - } |
|
| 80 | + /** |
|
| 81 | + * Associative array for autoloading. classname => filename |
|
| 82 | + */ |
|
| 83 | + public static $CLASSPATH = []; |
|
| 84 | + /** |
|
| 85 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 86 | + */ |
|
| 87 | + public static $SERVERROOT = ''; |
|
| 88 | + /** |
|
| 89 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 90 | + */ |
|
| 91 | + private static $SUBURI = ''; |
|
| 92 | + /** |
|
| 93 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
| 94 | + */ |
|
| 95 | + public static $WEBROOT = ''; |
|
| 96 | + /** |
|
| 97 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 98 | + * web path in 'url' |
|
| 99 | + */ |
|
| 100 | + public static $APPSROOTS = []; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public static $configDir; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * requested app |
|
| 109 | + */ |
|
| 110 | + public static $REQUESTEDAPP = ''; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * check if Nextcloud runs in cli mode |
|
| 114 | + */ |
|
| 115 | + public static $CLI = false; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @var \OC\Autoloader $loader |
|
| 119 | + */ |
|
| 120 | + public static $loader = null; |
|
| 121 | + |
|
| 122 | + /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
| 123 | + public static $composerAutoloader = null; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @var \OC\Server |
|
| 127 | + */ |
|
| 128 | + public static $server = null; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @var \OC\Config |
|
| 132 | + */ |
|
| 133 | + private static $config = null; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 137 | + * the app path list is empty or contains an invalid path |
|
| 138 | + */ |
|
| 139 | + public static function initPaths() { |
|
| 140 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
| 141 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 142 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 143 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 144 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 145 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
| 146 | + } else { |
|
| 147 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 148 | + } |
|
| 149 | + self::$config = new \OC\Config(self::$configDir); |
|
| 150 | + |
|
| 151 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
| 152 | + /** |
|
| 153 | + * FIXME: The following lines are required because we can't yet instantiate |
|
| 154 | + * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
| 155 | + */ |
|
| 156 | + $params = [ |
|
| 157 | + 'server' => [ |
|
| 158 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
| 159 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
| 160 | + ], |
|
| 161 | + ]; |
|
| 162 | + $fakeRequest = new \OC\AppFramework\Http\Request($params, new \OC\Security\SecureRandom(), new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
| 163 | + $scriptName = $fakeRequest->getScriptName(); |
|
| 164 | + if (substr($scriptName, -1) == '/') { |
|
| 165 | + $scriptName .= 'index.php'; |
|
| 166 | + //make sure suburi follows the same rules as scriptName |
|
| 167 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 168 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
| 169 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 170 | + } |
|
| 171 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + if (OC::$CLI) { |
|
| 177 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 178 | + } else { |
|
| 179 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 180 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 181 | + |
|
| 182 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 183 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 184 | + } |
|
| 185 | + } else { |
|
| 186 | + // The scriptName is not ending with OC::$SUBURI |
|
| 187 | + // This most likely means that we are calling from CLI. |
|
| 188 | + // However some cron jobs still need to generate |
|
| 189 | + // a web URL, so we use overwritewebroot as a fallback. |
|
| 190 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 194 | + // slash which is required by URL generation. |
|
| 195 | + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 196 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 197 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
| 198 | + exit(); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // search the apps folder |
|
| 203 | + $config_paths = self::$config->getValue('apps_paths', []); |
|
| 204 | + if (!empty($config_paths)) { |
|
| 205 | + foreach ($config_paths as $paths) { |
|
| 206 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
| 207 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
| 208 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
| 209 | + OC::$APPSROOTS[] = $paths; |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 213 | + OC::$APPSROOTS[] = ['path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true]; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (empty(OC::$APPSROOTS)) { |
|
| 217 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 218 | + . '. You can also configure the location in the config.php file.'); |
|
| 219 | + } |
|
| 220 | + $paths = []; |
|
| 221 | + foreach (OC::$APPSROOTS as $path) { |
|
| 222 | + $paths[] = $path['path']; |
|
| 223 | + if (!is_dir($path['path'])) { |
|
| 224 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 225 | + . ' Nextcloud folder. You can also configure the location in the config.php file.', $path['path'])); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // set the right include path |
|
| 230 | + set_include_path( |
|
| 231 | + implode(PATH_SEPARATOR, $paths) |
|
| 232 | + ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + public static function checkConfig() { |
|
| 236 | + $l = \OC::$server->getL10N('lib'); |
|
| 237 | + |
|
| 238 | + // Create config if it does not already exist |
|
| 239 | + $configFilePath = self::$configDir .'/config.php'; |
|
| 240 | + if (!file_exists($configFilePath)) { |
|
| 241 | + @touch($configFilePath); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Check if config is writable |
|
| 245 | + $configFileWritable = is_writable($configFilePath); |
|
| 246 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
| 247 | + || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
| 248 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 249 | + |
|
| 250 | + if (self::$CLI) { |
|
| 251 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
| 252 | + echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
| 253 | + echo "\n"; |
|
| 254 | + echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
|
| 255 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
| 256 | + exit; |
|
| 257 | + } else { |
|
| 258 | + OC_Template::printErrorPage( |
|
| 259 | + $l->t('Cannot write into "config" directory!'), |
|
| 260 | + $l->t('This can usually be fixed by giving the webserver write access to the config directory.') . '. ' |
|
| 261 | + . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
| 262 | + [ $urlGenerator->linkToDocs('admin-config') ]), |
|
| 263 | + 503 |
|
| 264 | + ); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + public static function checkInstalled(\OC\SystemConfig $systemConfig) { |
|
| 270 | + if (defined('OC_CONSOLE')) { |
|
| 271 | + return; |
|
| 272 | + } |
|
| 273 | + // Redirect to installer if not installed |
|
| 274 | + if (!$systemConfig->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 275 | + if (OC::$CLI) { |
|
| 276 | + throw new Exception('Not installed'); |
|
| 277 | + } else { |
|
| 278 | + $url = OC::$WEBROOT . '/index.php'; |
|
| 279 | + header('Location: ' . $url); |
|
| 280 | + } |
|
| 281 | + exit(); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + public static function checkMaintenanceMode(\OC\SystemConfig $systemConfig) { |
|
| 286 | + // Allow ajax update script to execute without being stopped |
|
| 287 | + if (((bool) $systemConfig->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 288 | + // send http status 503 |
|
| 289 | + http_response_code(503); |
|
| 290 | + header('Retry-After: 120'); |
|
| 291 | + |
|
| 292 | + // render error page |
|
| 293 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
| 294 | + OC_Util::addScript('dist/maintenance'); |
|
| 295 | + OC_Util::addStyle('core', 'guest'); |
|
| 296 | + $template->printPage(); |
|
| 297 | + die(); |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Prints the upgrade page |
|
| 303 | + * |
|
| 304 | + * @param \OC\SystemConfig $systemConfig |
|
| 305 | + */ |
|
| 306 | + private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
| 307 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 308 | + $tooBig = false; |
|
| 309 | + if (!$disableWebUpdater) { |
|
| 310 | + $apps = \OC::$server->getAppManager(); |
|
| 311 | + if ($apps->isInstalled('user_ldap')) { |
|
| 312 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 313 | + |
|
| 314 | + $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 315 | + ->from('ldap_user_mapping') |
|
| 316 | + ->execute(); |
|
| 317 | + $row = $result->fetch(); |
|
| 318 | + $result->closeCursor(); |
|
| 319 | + |
|
| 320 | + $tooBig = ($row['user_count'] > 50); |
|
| 321 | + } |
|
| 322 | + if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
| 323 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 324 | + |
|
| 325 | + $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 326 | + ->from('user_saml_users') |
|
| 327 | + ->execute(); |
|
| 328 | + $row = $result->fetch(); |
|
| 329 | + $result->closeCursor(); |
|
| 330 | + |
|
| 331 | + $tooBig = ($row['user_count'] > 50); |
|
| 332 | + } |
|
| 333 | + if (!$tooBig) { |
|
| 334 | + // count users |
|
| 335 | + $stats = \OC::$server->getUserManager()->countUsers(); |
|
| 336 | + $totalUsers = array_sum($stats); |
|
| 337 | + $tooBig = ($totalUsers > 50); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
| 341 | + $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
| 342 | + |
|
| 343 | + if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
| 344 | + // send http status 503 |
|
| 345 | + http_response_code(503); |
|
| 346 | + header('Retry-After: 120'); |
|
| 347 | + |
|
| 348 | + // render error page |
|
| 349 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
| 350 | + $template->assign('productName', 'nextcloud'); // for now |
|
| 351 | + $template->assign('version', OC_Util::getVersionString()); |
|
| 352 | + $template->assign('tooBig', $tooBig); |
|
| 353 | + |
|
| 354 | + $template->printPage(); |
|
| 355 | + die(); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // check whether this is a core update or apps update |
|
| 359 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 360 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 361 | + |
|
| 362 | + // if not a core upgrade, then it's apps upgrade |
|
| 363 | + $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
| 364 | + |
|
| 365 | + $oldTheme = $systemConfig->getValue('theme'); |
|
| 366 | + $systemConfig->setValue('theme', ''); |
|
| 367 | + OC_Util::addScript('update'); |
|
| 368 | + |
|
| 369 | + /** @var \OC\App\AppManager $appManager */ |
|
| 370 | + $appManager = \OC::$server->getAppManager(); |
|
| 371 | + |
|
| 372 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
| 373 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
| 374 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 375 | + |
|
| 376 | + // get third party apps |
|
| 377 | + $ocVersion = \OCP\Util::getVersion(); |
|
| 378 | + $ocVersion = implode('.', $ocVersion); |
|
| 379 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 380 | + $incompatibleShippedApps = []; |
|
| 381 | + foreach ($incompatibleApps as $appInfo) { |
|
| 382 | + if ($appManager->isShipped($appInfo['id'])) { |
|
| 383 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if (!empty($incompatibleShippedApps)) { |
|
| 388 | + $l = \OC::$server->getL10N('core'); |
|
| 389 | + $hint = $l->t('The files of the app %1$s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
| 390 | + throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 394 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
| 395 | + try { |
|
| 396 | + $defaults = new \OC_Defaults(); |
|
| 397 | + $tmpl->assign('productName', $defaults->getName()); |
|
| 398 | + } catch (Throwable $error) { |
|
| 399 | + $tmpl->assign('productName', 'Nextcloud'); |
|
| 400 | + } |
|
| 401 | + $tmpl->assign('oldTheme', $oldTheme); |
|
| 402 | + $tmpl->printPage(); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + public static function initSession() { |
|
| 406 | + if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 407 | + ini_set('session.cookie_secure', 'true'); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + // prevents javascript from accessing php session cookies |
|
| 411 | + ini_set('session.cookie_httponly', 'true'); |
|
| 412 | + |
|
| 413 | + // set the cookie path to the Nextcloud directory |
|
| 414 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 415 | + ini_set('session.cookie_path', $cookie_path); |
|
| 416 | + |
|
| 417 | + // Let the session name be changed in the initSession Hook |
|
| 418 | + $sessionName = OC_Util::getInstanceId(); |
|
| 419 | + |
|
| 420 | + try { |
|
| 421 | + // set the session name to the instance id - which is unique |
|
| 422 | + $session = new \OC\Session\Internal($sessionName); |
|
| 423 | + |
|
| 424 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 425 | + $session = $cryptoWrapper->wrapSession($session); |
|
| 426 | + self::$server->setSession($session); |
|
| 427 | + |
|
| 428 | + // if session can't be started break with http 500 error |
|
| 429 | + } catch (Exception $e) { |
|
| 430 | + \OC::$server->getLogger()->logException($e, ['app' => 'base']); |
|
| 431 | + //show the user a detailed error page |
|
| 432 | + OC_Template::printExceptionErrorPage($e, 500); |
|
| 433 | + die(); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 437 | + |
|
| 438 | + // session timeout |
|
| 439 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 440 | + if (isset($_COOKIE[session_name()])) { |
|
| 441 | + setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
| 442 | + } |
|
| 443 | + \OC::$server->getUserSession()->logout(); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + $session->set('LAST_ACTIVITY', time()); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * @return string |
|
| 451 | + */ |
|
| 452 | + private static function getSessionLifeTime() { |
|
| 453 | + return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Try to set some values to the required Nextcloud default |
|
| 458 | + */ |
|
| 459 | + public static function setRequiredIniValues() { |
|
| 460 | + @ini_set('default_charset', 'UTF-8'); |
|
| 461 | + @ini_set('gd.jpeg_ignore_warning', '1'); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * Send the same site cookies |
|
| 466 | + */ |
|
| 467 | + private static function sendSameSiteCookies() { |
|
| 468 | + $cookieParams = session_get_cookie_params(); |
|
| 469 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 470 | + $policies = [ |
|
| 471 | + 'lax', |
|
| 472 | + 'strict', |
|
| 473 | + ]; |
|
| 474 | + |
|
| 475 | + // Append __Host to the cookie if it meets the requirements |
|
| 476 | + $cookiePrefix = ''; |
|
| 477 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 478 | + $cookiePrefix = '__Host-'; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + foreach ($policies as $policy) { |
|
| 482 | + header( |
|
| 483 | + sprintf( |
|
| 484 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 485 | + $cookiePrefix, |
|
| 486 | + $policy, |
|
| 487 | + $cookieParams['path'], |
|
| 488 | + $policy |
|
| 489 | + ), |
|
| 490 | + false |
|
| 491 | + ); |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 497 | + * be set in every request if cookies are sent to add a second level of |
|
| 498 | + * defense against CSRF. |
|
| 499 | + * |
|
| 500 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
| 501 | + * We use an additional cookie since we want to protect logout CSRF and |
|
| 502 | + * also we can't directly interfere with PHP's session mechanism. |
|
| 503 | + */ |
|
| 504 | + private static function performSameSiteCookieProtection(\OCP\IConfig $config) { |
|
| 505 | + $request = \OC::$server->getRequest(); |
|
| 506 | + |
|
| 507 | + // Some user agents are notorious and don't really properly follow HTTP |
|
| 508 | + // specifications. For those, have an automated opt-out. Since the protection |
|
| 509 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
| 510 | + // here. |
|
| 511 | + $incompatibleUserAgents = $config->getSystemValue('csrf.optout'); |
|
| 512 | + |
|
| 513 | + // Fallback, if csrf.optout is unset |
|
| 514 | + if (!is_array($incompatibleUserAgents)) { |
|
| 515 | + $incompatibleUserAgents = [ |
|
| 516 | + // OS X Finder |
|
| 517 | + '/^WebDAVFS/', |
|
| 518 | + // Windows webdav drive |
|
| 519 | + '/^Microsoft-WebDAV-MiniRedir/', |
|
| 520 | + ]; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
| 524 | + return; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + if (count($_COOKIE) > 0) { |
|
| 528 | + $requestUri = $request->getScriptName(); |
|
| 529 | + $processingScript = explode('/', $requestUri); |
|
| 530 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
| 531 | + |
|
| 532 | + // index.php routes are handled in the middleware |
|
| 533 | + if ($processingScript === 'index.php') { |
|
| 534 | + return; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + // All other endpoints require the lax and the strict cookie |
|
| 538 | + if (!$request->passesStrictCookieCheck()) { |
|
| 539 | + self::sendSameSiteCookies(); |
|
| 540 | + // Debug mode gets access to the resources without strict cookie |
|
| 541 | + // due to the fact that the SabreDAV browser also lives there. |
|
| 542 | + if (!$config->getSystemValue('debug', false)) { |
|
| 543 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 544 | + exit(); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 548 | + self::sendSameSiteCookies(); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + public static function init() { |
|
| 553 | + // calculate the root directories |
|
| 554 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
| 555 | + |
|
| 556 | + // register autoloader |
|
| 557 | + $loaderStart = microtime(true); |
|
| 558 | + require_once __DIR__ . '/autoloader.php'; |
|
| 559 | + self::$loader = new \OC\Autoloader([ |
|
| 560 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
| 561 | + ]); |
|
| 562 | + if (defined('PHPUNIT_RUN')) { |
|
| 563 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 564 | + } |
|
| 565 | + spl_autoload_register([self::$loader, 'load']); |
|
| 566 | + $loaderEnd = microtime(true); |
|
| 567 | + |
|
| 568 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
| 569 | + |
|
| 570 | + // Add default composer PSR-4 autoloader |
|
| 571 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 572 | + |
|
| 573 | + try { |
|
| 574 | + self::initPaths(); |
|
| 575 | + // setup 3rdparty autoloader |
|
| 576 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 577 | + if (!file_exists($vendorAutoLoad)) { |
|
| 578 | + throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 579 | + } |
|
| 580 | + require_once $vendorAutoLoad; |
|
| 581 | + } catch (\RuntimeException $e) { |
|
| 582 | + if (!self::$CLI) { |
|
| 583 | + http_response_code(503); |
|
| 584 | + } |
|
| 585 | + // we can't use the template error page here, because this needs the |
|
| 586 | + // DI container which isn't available yet |
|
| 587 | + print($e->getMessage()); |
|
| 588 | + exit(); |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + // setup the basic server |
|
| 592 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 593 | + self::$server->boot(); |
|
| 594 | + $eventLogger = \OC::$server->getEventLogger(); |
|
| 595 | + $eventLogger->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 596 | + $eventLogger->start('boot', 'Initialize'); |
|
| 597 | + |
|
| 598 | + // Override php.ini and log everything if we're troubleshooting |
|
| 599 | + if (self::$config->getValue('loglevel') === ILogger::DEBUG) { |
|
| 600 | + error_reporting(E_ALL); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + // Don't display errors and log them |
|
| 604 | + @ini_set('display_errors', '0'); |
|
| 605 | + @ini_set('log_errors', '1'); |
|
| 606 | + |
|
| 607 | + if (!date_default_timezone_set('UTC')) { |
|
| 608 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + //try to configure php to enable big file uploads. |
|
| 612 | + //this doesn´t work always depending on the webserver and php configuration. |
|
| 613 | + //Let´s try to overwrite some defaults anyway |
|
| 614 | + |
|
| 615 | + //try to set the maximum execution time to 60min |
|
| 616 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 617 | + @set_time_limit(3600); |
|
| 618 | + } |
|
| 619 | + @ini_set('max_execution_time', '3600'); |
|
| 620 | + @ini_set('max_input_time', '3600'); |
|
| 621 | + |
|
| 622 | + self::setRequiredIniValues(); |
|
| 623 | + self::handleAuthHeaders(); |
|
| 624 | + $systemConfig = \OC::$server->get(\OC\SystemConfig::class); |
|
| 625 | + self::registerAutoloaderCache($systemConfig); |
|
| 626 | + |
|
| 627 | + // initialize intl fallback if necessary |
|
| 628 | + OC_Util::isSetLocaleWorking(); |
|
| 629 | + |
|
| 630 | + $config = \OC::$server->get(\OCP\IConfig::class); |
|
| 631 | + if (!defined('PHPUNIT_RUN')) { |
|
| 632 | + OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
| 633 | + $debug = $config->getSystemValue('debug', false); |
|
| 634 | + OC\Log\ErrorHandler::register($debug); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + /** @var \OC\AppFramework\Bootstrap\Coordinator $bootstrapCoordinator */ |
|
| 638 | + $bootstrapCoordinator = \OC::$server->query(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
| 639 | + $bootstrapCoordinator->runInitialRegistration(); |
|
| 640 | + |
|
| 641 | + $eventLogger->start('init_session', 'Initialize session'); |
|
| 642 | + OC_App::loadApps(['session']); |
|
| 643 | + if (!self::$CLI) { |
|
| 644 | + self::initSession(); |
|
| 645 | + } |
|
| 646 | + $eventLogger->end('init_session'); |
|
| 647 | + self::checkConfig(); |
|
| 648 | + self::checkInstalled($systemConfig); |
|
| 649 | + |
|
| 650 | + OC_Response::addSecurityHeaders(); |
|
| 651 | + |
|
| 652 | + self::performSameSiteCookieProtection($config); |
|
| 653 | + |
|
| 654 | + if (!defined('OC_CONSOLE')) { |
|
| 655 | + $errors = OC_Util::checkServer($systemConfig); |
|
| 656 | + if (count($errors) > 0) { |
|
| 657 | + if (!self::$CLI) { |
|
| 658 | + http_response_code(503); |
|
| 659 | + OC_Util::addStyle('guest'); |
|
| 660 | + try { |
|
| 661 | + OC_Template::printGuestPage('', 'error', ['errors' => $errors]); |
|
| 662 | + exit; |
|
| 663 | + } catch (\Exception $e) { |
|
| 664 | + // In case any error happens when showing the error page, we simply fall back to posting the text. |
|
| 665 | + // This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it. |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + // Convert l10n string into regular string for usage in database |
|
| 670 | + $staticErrors = []; |
|
| 671 | + foreach ($errors as $error) { |
|
| 672 | + echo $error['error'] . "\n"; |
|
| 673 | + echo $error['hint'] . "\n\n"; |
|
| 674 | + $staticErrors[] = [ |
|
| 675 | + 'error' => (string)$error['error'], |
|
| 676 | + 'hint' => (string)$error['hint'], |
|
| 677 | + ]; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + try { |
|
| 681 | + $config->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 682 | + } catch (\Exception $e) { |
|
| 683 | + echo('Writing to database failed'); |
|
| 684 | + } |
|
| 685 | + exit(1); |
|
| 686 | + } elseif (self::$CLI && $config->getSystemValue('installed', false)) { |
|
| 687 | + $config->deleteAppValue('core', 'cronErrors'); |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + //try to set the session lifetime |
|
| 691 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 692 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 693 | + |
|
| 694 | + // User and Groups |
|
| 695 | + if (!$systemConfig->getValue("installed", false)) { |
|
| 696 | + self::$server->getSession()->set('user_id', ''); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + OC_User::useBackend(new \OC\User\Database()); |
|
| 700 | + \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
| 701 | + |
|
| 702 | + // Subscribe to the hook |
|
| 703 | + \OCP\Util::connectHook( |
|
| 704 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 705 | + 'preLoginNameUsedAsUserName', |
|
| 706 | + '\OC\User\Database', |
|
| 707 | + 'preLoginNameUsedAsUserName' |
|
| 708 | + ); |
|
| 709 | + |
|
| 710 | + //setup extra user backends |
|
| 711 | + if (!\OCP\Util::needUpgrade()) { |
|
| 712 | + OC_User::setupBackends(); |
|
| 713 | + } else { |
|
| 714 | + // Run upgrades in incognito mode |
|
| 715 | + OC_User::setIncognitoMode(true); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + self::registerCleanupHooks($systemConfig); |
|
| 719 | + self::registerFilesystemHooks(); |
|
| 720 | + self::registerShareHooks($systemConfig); |
|
| 721 | + self::registerEncryptionWrapperAndHooks(); |
|
| 722 | + self::registerAccountHooks(); |
|
| 723 | + self::registerResourceCollectionHooks(); |
|
| 724 | + self::registerAppRestrictionsHooks(); |
|
| 725 | + |
|
| 726 | + // Make sure that the application class is not loaded before the database is setup |
|
| 727 | + if ($systemConfig->getValue("installed", false)) { |
|
| 728 | + OC_App::loadApp('settings'); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + //make sure temporary files are cleaned up |
|
| 732 | + $tmpManager = \OC::$server->getTempManager(); |
|
| 733 | + register_shutdown_function([$tmpManager, 'clean']); |
|
| 734 | + $lockProvider = \OC::$server->getLockingProvider(); |
|
| 735 | + register_shutdown_function([$lockProvider, 'releaseAll']); |
|
| 736 | + |
|
| 737 | + // Check whether the sample configuration has been copied |
|
| 738 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
| 739 | + $l = \OC::$server->getL10N('lib'); |
|
| 740 | + OC_Template::printErrorPage( |
|
| 741 | + $l->t('Sample configuration detected'), |
|
| 742 | + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), |
|
| 743 | + 503 |
|
| 744 | + ); |
|
| 745 | + return; |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + $request = \OC::$server->getRequest(); |
|
| 749 | + $host = $request->getInsecureServerHost(); |
|
| 750 | + /** |
|
| 751 | + * if the host passed in headers isn't trusted |
|
| 752 | + * FIXME: Should not be in here at all :see_no_evil: |
|
| 753 | + */ |
|
| 754 | + if (!OC::$CLI |
|
| 755 | + && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
| 756 | + && $config->getSystemValue('installed', false) |
|
| 757 | + ) { |
|
| 758 | + // Allow access to CSS resources |
|
| 759 | + $isScssRequest = false; |
|
| 760 | + if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 761 | + $isScssRequest = true; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
| 765 | + http_response_code(400); |
|
| 766 | + header('Content-Type: application/json'); |
|
| 767 | + echo '{"error": "Trusted domain error.", "code": 15}'; |
|
| 768 | + exit(); |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + if (!$isScssRequest) { |
|
| 772 | + http_response_code(400); |
|
| 773 | + |
|
| 774 | + \OC::$server->getLogger()->info( |
|
| 775 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 776 | + [ |
|
| 777 | + 'app' => 'core', |
|
| 778 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
| 779 | + 'host' => $host, |
|
| 780 | + ] |
|
| 781 | + ); |
|
| 782 | + |
|
| 783 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
| 784 | + $tmpl->assign('docUrl', \OC::$server->getURLGenerator()->linkToDocs('admin-trusted-domains')); |
|
| 785 | + $tmpl->printPage(); |
|
| 786 | + |
|
| 787 | + exit(); |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + $eventLogger->end('boot'); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * register hooks for the cleanup of cache and bruteforce protection |
|
| 795 | + */ |
|
| 796 | + public static function registerCleanupHooks(\OC\SystemConfig $systemConfig) { |
|
| 797 | + //don't try to do this before we are properly setup |
|
| 798 | + if ($systemConfig->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
| 799 | + |
|
| 800 | + // NOTE: This will be replaced to use OCP |
|
| 801 | + $userSession = self::$server->getUserSession(); |
|
| 802 | + $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 803 | + if (!defined('PHPUNIT_RUN') && $userSession->isLoggedIn()) { |
|
| 804 | + // reset brute force delay for this IP address and username |
|
| 805 | + $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
| 806 | + $request = \OC::$server->getRequest(); |
|
| 807 | + $throttler = \OC::$server->getBruteForceThrottler(); |
|
| 808 | + $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + try { |
|
| 812 | + $cache = new \OC\Cache\File(); |
|
| 813 | + $cache->gc(); |
|
| 814 | + } catch (\OC\ServerNotAvailableException $e) { |
|
| 815 | + // not a GC exception, pass it on |
|
| 816 | + throw $e; |
|
| 817 | + } catch (\OC\ForbiddenException $e) { |
|
| 818 | + // filesystem blocked for this request, ignore |
|
| 819 | + } catch (\Exception $e) { |
|
| 820 | + // a GC exception should not prevent users from using OC, |
|
| 821 | + // so log the exception |
|
| 822 | + \OC::$server->getLogger()->logException($e, [ |
|
| 823 | + 'message' => 'Exception when running cache gc.', |
|
| 824 | + 'level' => ILogger::WARN, |
|
| 825 | + 'app' => 'core', |
|
| 826 | + ]); |
|
| 827 | + } |
|
| 828 | + }); |
|
| 829 | + } |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + private static function registerEncryptionWrapperAndHooks() { |
|
| 833 | + $manager = self::$server->getEncryptionManager(); |
|
| 834 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
| 835 | + |
|
| 836 | + $enabled = $manager->isEnabled(); |
|
| 837 | + if ($enabled) { |
|
| 838 | + \OCP\Util::connectHook(Share::class, 'post_shared', HookManager::class, 'postShared'); |
|
| 839 | + \OCP\Util::connectHook(Share::class, 'post_unshare', HookManager::class, 'postUnshared'); |
|
| 840 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', HookManager::class, 'postRename'); |
|
| 841 | + \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', HookManager::class, 'postRestore'); |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + private static function registerAccountHooks() { |
|
| 846 | + $hookHandler = \OC::$server->get(\OC\Accounts\Hooks::class); |
|
| 847 | + \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + private static function registerAppRestrictionsHooks() { |
|
| 851 | + /** @var \OC\Group\Manager $groupManager */ |
|
| 852 | + $groupManager = self::$server->query(\OCP\IGroupManager::class); |
|
| 853 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
| 854 | + $appManager = self::$server->getAppManager(); |
|
| 855 | + $apps = $appManager->getEnabledAppsForGroup($group); |
|
| 856 | + foreach ($apps as $appId) { |
|
| 857 | + $restrictions = $appManager->getAppRestriction($appId); |
|
| 858 | + if (empty($restrictions)) { |
|
| 859 | + continue; |
|
| 860 | + } |
|
| 861 | + $key = array_search($group->getGID(), $restrictions); |
|
| 862 | + unset($restrictions[$key]); |
|
| 863 | + $restrictions = array_values($restrictions); |
|
| 864 | + if (empty($restrictions)) { |
|
| 865 | + $appManager->disableApp($appId); |
|
| 866 | + } else { |
|
| 867 | + $appManager->enableAppForGroups($appId, $restrictions); |
|
| 868 | + } |
|
| 869 | + } |
|
| 870 | + }); |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + private static function registerResourceCollectionHooks() { |
|
| 874 | + \OC\Collaboration\Resources\Listener::register(\OC::$server->getEventDispatcher()); |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + /** |
|
| 878 | + * register hooks for the filesystem |
|
| 879 | + */ |
|
| 880 | + public static function registerFilesystemHooks() { |
|
| 881 | + // Check for blacklisted files |
|
| 882 | + OC_Hook::connect('OC_Filesystem', 'write', Filesystem::class, 'isBlacklisted'); |
|
| 883 | + OC_Hook::connect('OC_Filesystem', 'rename', Filesystem::class, 'isBlacklisted'); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * register hooks for sharing |
|
| 888 | + */ |
|
| 889 | + public static function registerShareHooks(\OC\SystemConfig $systemConfig) { |
|
| 890 | + if ($systemConfig->getValue('installed')) { |
|
| 891 | + OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); |
|
| 892 | + OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); |
|
| 893 | + |
|
| 894 | + /** @var IEventDispatcher $dispatcher */ |
|
| 895 | + $dispatcher = \OC::$server->get(IEventDispatcher::class); |
|
| 896 | + $dispatcher->addServiceListener(UserRemovedEvent::class, \OC\Share20\UserRemovedListener::class); |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + protected static function registerAutoloaderCache(\OC\SystemConfig $systemConfig) { |
|
| 901 | + // The class loader takes an optional low-latency cache, which MUST be |
|
| 902 | + // namespaced. The instanceid is used for namespacing, but might be |
|
| 903 | + // unavailable at this point. Furthermore, it might not be possible to |
|
| 904 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
| 905 | + // config file may not be writable. As such, we only register a class |
|
| 906 | + // loader cache if instanceid is available without trying to create one. |
|
| 907 | + $instanceId = $systemConfig->getValue('instanceid', null); |
|
| 908 | + if ($instanceId) { |
|
| 909 | + try { |
|
| 910 | + $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
| 911 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
| 912 | + } catch (\Exception $ex) { |
|
| 913 | + } |
|
| 914 | + } |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * Handle the request |
|
| 919 | + */ |
|
| 920 | + public static function handleRequest() { |
|
| 921 | + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
| 922 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 923 | + |
|
| 924 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 925 | + if (!$systemConfig->getValue('installed', false)) { |
|
| 926 | + \OC::$server->getSession()->clear(); |
|
| 927 | + $setupHelper = new OC\Setup( |
|
| 928 | + $systemConfig, |
|
| 929 | + \OC::$server->get(\bantu\IniGetWrapper\IniGetWrapper::class), |
|
| 930 | + \OC::$server->getL10N('lib'), |
|
| 931 | + \OC::$server->query(\OCP\Defaults::class), |
|
| 932 | + \OC::$server->get(\Psr\Log\LoggerInterface::class), |
|
| 933 | + \OC::$server->getSecureRandom(), |
|
| 934 | + \OC::$server->query(\OC\Installer::class) |
|
| 935 | + ); |
|
| 936 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
| 937 | + $controller->run($_POST); |
|
| 938 | + exit(); |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + $request = \OC::$server->getRequest(); |
|
| 942 | + $requestPath = $request->getRawPathInfo(); |
|
| 943 | + if ($requestPath === '/heartbeat') { |
|
| 944 | + return; |
|
| 945 | + } |
|
| 946 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 947 | + self::checkMaintenanceMode($systemConfig); |
|
| 948 | + |
|
| 949 | + if (\OCP\Util::needUpgrade()) { |
|
| 950 | + if (function_exists('opcache_reset')) { |
|
| 951 | + opcache_reset(); |
|
| 952 | + } |
|
| 953 | + if (!((bool) $systemConfig->getValue('maintenance', false))) { |
|
| 954 | + self::printUpgradePage($systemConfig); |
|
| 955 | + exit(); |
|
| 956 | + } |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + // emergency app disabling |
|
| 961 | + if ($requestPath === '/disableapp' |
|
| 962 | + && $request->getMethod() === 'POST' |
|
| 963 | + && ((array)$request->getParam('appid')) !== '' |
|
| 964 | + ) { |
|
| 965 | + \OC_JSON::callCheck(); |
|
| 966 | + \OC_JSON::checkAdminUser(); |
|
| 967 | + $appIds = (array)$request->getParam('appid'); |
|
| 968 | + foreach ($appIds as $appId) { |
|
| 969 | + $appId = \OC_App::cleanAppId($appId); |
|
| 970 | + \OC::$server->getAppManager()->disableApp($appId); |
|
| 971 | + } |
|
| 972 | + \OC_JSON::success(); |
|
| 973 | + exit(); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + // Always load authentication apps |
|
| 977 | + OC_App::loadApps(['authentication']); |
|
| 978 | + |
|
| 979 | + // Load minimum set of apps |
|
| 980 | + if (!\OCP\Util::needUpgrade() |
|
| 981 | + && !((bool) $systemConfig->getValue('maintenance', false))) { |
|
| 982 | + // For logged-in users: Load everything |
|
| 983 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 984 | + OC_App::loadApps(); |
|
| 985 | + } else { |
|
| 986 | + // For guests: Load only filesystem and logging |
|
| 987 | + OC_App::loadApps(['filesystem', 'logging']); |
|
| 988 | + self::handleLogin($request); |
|
| 989 | + } |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + if (!self::$CLI) { |
|
| 993 | + try { |
|
| 994 | + if (!((bool) $systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) { |
|
| 995 | + OC_App::loadApps(['filesystem', 'logging']); |
|
| 996 | + OC_App::loadApps(); |
|
| 997 | + } |
|
| 998 | + OC::$server->get(\OC\Route\Router::class)->match($request->getRawPathInfo()); |
|
| 999 | + return; |
|
| 1000 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 1001 | + //header('HTTP/1.0 404 Not Found'); |
|
| 1002 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 1003 | + http_response_code(405); |
|
| 1004 | + return; |
|
| 1005 | + } |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + // Handle WebDAV |
|
| 1009 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 1010 | + // not allowed any more to prevent people |
|
| 1011 | + // mounting this root directly. |
|
| 1012 | + // Users need to mount remote.php/webdav instead. |
|
| 1013 | + http_response_code(405); |
|
| 1014 | + return; |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + // Someone is logged in |
|
| 1018 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1019 | + OC_App::loadApps(); |
|
| 1020 | + OC_User::setupBackends(); |
|
| 1021 | + OC_Util::setupFS(); |
|
| 1022 | + // FIXME |
|
| 1023 | + // Redirect to default application |
|
| 1024 | + OC_Util::redirectToDefaultPage(); |
|
| 1025 | + } else { |
|
| 1026 | + // Not handled and not logged in |
|
| 1027 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * Check login: apache auth, auth token, basic auth |
|
| 1033 | + * |
|
| 1034 | + * @param OCP\IRequest $request |
|
| 1035 | + * @return boolean |
|
| 1036 | + */ |
|
| 1037 | + public static function handleLogin(OCP\IRequest $request) { |
|
| 1038 | + $userSession = self::$server->getUserSession(); |
|
| 1039 | + if (OC_User::handleApacheAuth()) { |
|
| 1040 | + return true; |
|
| 1041 | + } |
|
| 1042 | + if ($userSession->tryTokenLogin($request)) { |
|
| 1043 | + return true; |
|
| 1044 | + } |
|
| 1045 | + if (isset($_COOKIE['nc_username']) |
|
| 1046 | + && isset($_COOKIE['nc_token']) |
|
| 1047 | + && isset($_COOKIE['nc_session_id']) |
|
| 1048 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1049 | + return true; |
|
| 1050 | + } |
|
| 1051 | + if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
| 1052 | + return true; |
|
| 1053 | + } |
|
| 1054 | + return false; |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + protected static function handleAuthHeaders() { |
|
| 1058 | + //copy http auth headers for apache+php-fcgid work around |
|
| 1059 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1060 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1064 | + $vars = [ |
|
| 1065 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1066 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1067 | + ]; |
|
| 1068 | + foreach ($vars as $var) { |
|
| 1069 | + if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1070 | + $credentials = explode(':', base64_decode($matches[1]), 2); |
|
| 1071 | + if (count($credentials) === 2) { |
|
| 1072 | + $_SERVER['PHP_AUTH_USER'] = $credentials[0]; |
|
| 1073 | + $_SERVER['PHP_AUTH_PW'] = $credentials[1]; |
|
| 1074 | + break; |
|
| 1075 | + } |
|
| 1076 | + } |
|
| 1077 | + } |
|
| 1078 | + } |
|
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | OC::init(); |