diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2022-09-02 23:18:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-02 23:18:32 +0300 |
commit | 121af7e14845a10093ba9e9fafea63cd01a67daf (patch) | |
tree | 7afa331592758d0ff7852754730bacbe710c5690 | |
parent | e7915bc197ea0896ffc9d31f0a86916d4eef6231 (diff) | |
parent | 6cf29c74746760bd5c4a88b1775934f640a01f05 (diff) |
Merge pull request #420 from nextcloud/updateDir
Introduce Update Directory
-rw-r--r-- | index.php | 43 | ||||
-rw-r--r-- | lib/Updater.php | 35 |
2 files changed, 38 insertions, 40 deletions
@@ -96,7 +96,7 @@ class Updater { return; } - $dataDir = $this->getDataDirectoryLocation(); + $dataDir = $this->getUpdateDirectoryLocation(); if (empty($dataDir) || !is_string($dataDir)) { throw new \Exception('Could not read data directory from config.php.'); } @@ -115,10 +115,7 @@ class Updater { $buildTime = $OC_Build; } - if ($version === null) { - return; - } - if ($buildTime === null) { + if ($version === null || $buildTime === null) { return; } @@ -216,8 +213,8 @@ class Updater { * * @return string */ - private function getDataDirectoryLocation() { - return $this->configValues['datadirectory']; + private function getUpdateDirectoryLocation() { + return $this->configValues['updatedirectory'] ?? $this->configValues['datadirectory']; } /** @@ -398,7 +395,7 @@ class Updater { ]; // Create new folder for the backup - $backupFolderLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid').'/backups/nextcloud-'.$this->getConfigOption('version') . '-' . time() . '/'; + $backupFolderLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid').'/backups/nextcloud-'.$this->getConfigOption('version') . '-' . time() . '/'; $this->silentLog('[info] backup folder location: ' . $backupFolderLocation); $state = mkdir($backupFolderLocation, 0750, true); @@ -550,7 +547,8 @@ class Updater { $this->silentLog('[info] downloadUpdate()'); $response = $this->getUpdateServerResponse(); - $storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/'; + + $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/'; if (file_exists($storageLocation)) { $this->silentLog('[info] storage location exists'); $this->recursiveDelete($storageLocation); @@ -618,7 +616,7 @@ class Updater { * @throws \Exception */ private function getDownloadedFilePath() { - $storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/'; + $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/'; $this->silentLog('[info] storage location: ' . $storageLocation); $filesInStorageLocation = scandir($storageLocation); @@ -839,7 +837,7 @@ EOF; throw new \Exception('core/shipped.json is not available'); } - $newShippedAppsFile = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/core/shipped.json'; + $newShippedAppsFile = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/core/shipped.json'; if (!file_exists($newShippedAppsFile)) { throw new \Exception('core/shipped.json is not available in the new release'); } @@ -997,7 +995,7 @@ EOF; 'ocs/v1.php', 'ocs/v2.php', ]; - $storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/'; + $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/'; $this->silentLog('[info] storage location: ' . $storageLocation); $this->moveWithExclusions($storageLocation, $excludedElements); @@ -1013,14 +1011,15 @@ EOF; public function finalize() { $this->silentLog('[info] finalize()'); - $storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/'; + $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/'; $this->silentLog('[info] storage location: ' . $storageLocation); $this->moveWithExclusions($storageLocation, []); $state = rmdir($storageLocation); if ($state === false) { throw new \Exception('Could not rmdir $storagelocation'); } - $state = unlink($this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/.step'); + + $state = unlink($this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/.step'); if ($state === false) { throw new \Exception('Could not rmdir .step'); } @@ -1039,7 +1038,7 @@ EOF; * @throws \Exception */ private function writeStep($state, $step) { - $updaterDir = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); + $updaterDir = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); if (!file_exists($updaterDir . '/.step')) { if (!file_exists($updaterDir)) { $result = mkdir($updaterDir); @@ -1084,7 +1083,7 @@ EOF; public function currentStep() { $this->silentLog('[info] currentStep()'); - $updaterDir = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); + $updaterDir = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); $jsonData = []; if (file_exists($updaterDir. '/.step')) { $state = file_get_contents($updaterDir . '/.step'); @@ -1109,7 +1108,7 @@ EOF; public function rollbackChanges($step) { $this->silentLog('[info] rollbackChanges("' . $step . '")'); - $updaterDir = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); + $updaterDir = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); if (file_exists($updaterDir . '/.step')) { $this->silentLog('[info] unlink .step'); $state = unlink($updaterDir . '/.step'); @@ -1153,7 +1152,7 @@ EOF; * @throws LogException */ public function log($message) { - $updaterLogPath = $this->getDataDirectoryLocation() . '/updater.log'; + $updaterLogPath = $this->getUpdateDirectoryLocation() . '/updater.log'; $fh = fopen($updaterLogPath, 'a'); if ($fh === false) { @@ -1831,13 +1830,13 @@ if (strpos($updaterUrl, 'index.php') === false) { </div> </li> </ul> - <?php else: ?> + <?php else : ?> <div id="login" class="section"> <h2>Authentication</h2> <p>To login you need to provide the unhashed value of "updater.secret" in your config file.</p> <p>If you don't know that value, you can access this updater directly via the Nextcloud admin screen or generate your own secret:</p> - <code>php -r '$password = trim(shell_exec("openssl rand -base64 48"));if(strlen($password) === 64) {$hash = password_hash($password, PASSWORD_DEFAULT) . "\n"; echo "Insert as \"updater.secret\": ".$hash; echo "The plaintext value is: ".$password."\n";}else{echo "Could not execute OpenSSL.\n";};'</code> + <code>php -r '$password = trim(shell_exec("openssl rand -base64 48")); if (strlen($password) === 64) {$hash = password_hash($password, PASSWORD_DEFAULT) . "\n"; echo "Insert as \"updater.secret\": ".$hash; echo "The plaintext value is: ".$password."\n";} else {echo "Could not execute OpenSSL.\n";};'</code> <form method="post" name="login"> <fieldset> <input type="password" name="updater-secret-input" value="" @@ -1856,7 +1855,8 @@ if (strpos($updaterUrl, 'index.php') === false) { </div> </body> -<?php if ($auth->isAuthenticated()): ?> + +<?php if ($auth->isAuthenticated()) : ?> <script> function escapeHTML(s) { return s.toString().split('&').join('&').split('<').join('<').split('>').join('>').split('"').join('"').split('\'').join('''); @@ -2244,4 +2244,3 @@ if (strpos($updaterUrl, 'index.php') === false) { <?php endif; ?> </html> - diff --git a/lib/Updater.php b/lib/Updater.php index e730ee5..59614b6 100644 --- a/lib/Updater.php +++ b/lib/Updater.php @@ -66,7 +66,7 @@ class Updater { return; } - $dataDir = $this->getDataDirectoryLocation(); + $dataDir = $this->getUpdateDirectoryLocation(); if (empty($dataDir) || !is_string($dataDir)) { throw new \Exception('Could not read data directory from config.php.'); } @@ -85,10 +85,7 @@ class Updater { $buildTime = $OC_Build; } - if ($version === null) { - return; - } - if ($buildTime === null) { + if ($version === null || $buildTime === null) { return; } @@ -186,8 +183,8 @@ class Updater { * * @return string */ - private function getDataDirectoryLocation() { - return $this->configValues['datadirectory']; + private function getUpdateDirectoryLocation() { + return $this->configValues['updatedirectory'] ?? $this->configValues['datadirectory']; } /** @@ -368,7 +365,7 @@ class Updater { ]; // Create new folder for the backup - $backupFolderLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid').'/backups/nextcloud-'.$this->getConfigOption('version') . '-' . time() . '/'; + $backupFolderLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid').'/backups/nextcloud-'.$this->getConfigOption('version') . '-' . time() . '/'; $this->silentLog('[info] backup folder location: ' . $backupFolderLocation); $state = mkdir($backupFolderLocation, 0750, true); @@ -520,7 +517,8 @@ class Updater { $this->silentLog('[info] downloadUpdate()'); $response = $this->getUpdateServerResponse(); - $storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/'; + + $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/'; if (file_exists($storageLocation)) { $this->silentLog('[info] storage location exists'); $this->recursiveDelete($storageLocation); @@ -588,7 +586,7 @@ class Updater { * @throws \Exception */ private function getDownloadedFilePath() { - $storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/'; + $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/'; $this->silentLog('[info] storage location: ' . $storageLocation); $filesInStorageLocation = scandir($storageLocation); @@ -809,7 +807,7 @@ EOF; throw new \Exception('core/shipped.json is not available'); } - $newShippedAppsFile = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/core/shipped.json'; + $newShippedAppsFile = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/core/shipped.json'; if (!file_exists($newShippedAppsFile)) { throw new \Exception('core/shipped.json is not available in the new release'); } @@ -967,7 +965,7 @@ EOF; 'ocs/v1.php', 'ocs/v2.php', ]; - $storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/'; + $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/'; $this->silentLog('[info] storage location: ' . $storageLocation); $this->moveWithExclusions($storageLocation, $excludedElements); @@ -983,14 +981,15 @@ EOF; public function finalize() { $this->silentLog('[info] finalize()'); - $storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/'; + $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/'; $this->silentLog('[info] storage location: ' . $storageLocation); $this->moveWithExclusions($storageLocation, []); $state = rmdir($storageLocation); if ($state === false) { throw new \Exception('Could not rmdir $storagelocation'); } - $state = unlink($this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/.step'); + + $state = unlink($this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/.step'); if ($state === false) { throw new \Exception('Could not rmdir .step'); } @@ -1009,7 +1008,7 @@ EOF; * @throws \Exception */ private function writeStep($state, $step) { - $updaterDir = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); + $updaterDir = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); if (!file_exists($updaterDir . '/.step')) { if (!file_exists($updaterDir)) { $result = mkdir($updaterDir); @@ -1054,7 +1053,7 @@ EOF; public function currentStep() { $this->silentLog('[info] currentStep()'); - $updaterDir = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); + $updaterDir = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); $jsonData = []; if (file_exists($updaterDir. '/.step')) { $state = file_get_contents($updaterDir . '/.step'); @@ -1079,7 +1078,7 @@ EOF; public function rollbackChanges($step) { $this->silentLog('[info] rollbackChanges("' . $step . '")'); - $updaterDir = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); + $updaterDir = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid'); if (file_exists($updaterDir . '/.step')) { $this->silentLog('[info] unlink .step'); $state = unlink($updaterDir . '/.step'); @@ -1123,7 +1122,7 @@ EOF; * @throws LogException */ public function log($message) { - $updaterLogPath = $this->getDataDirectoryLocation() . '/updater.log'; + $updaterLogPath = $this->getUpdateDirectoryLocation() . '/updater.log'; $fh = fopen($updaterLogPath, 'a'); if ($fh === false) { |