|
3 | 3 | declare(strict_types=1); |
4 | 4 |
|
5 | 5 | /** |
6 | | - * @copyright Copyright (c) 2016-2017 Lukas Reschke <lukas@statuscode.ch> |
7 | | - * @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de> |
8 | | - * @copyright Copyright (c) 2018 Jonas Sulzer <jonas@violoncello.ch> |
9 | | - * |
10 | | - * @license GNU AGPL version 3 or any later version |
11 | | - * |
12 | | - * This program is free software: you can redistribute it and/or modify |
13 | | - * it under the terms of the GNU Affero General Public License as |
14 | | - * published by the Free Software Foundation, either version 3 of the |
15 | | - * License, or (at your option) any later version. |
16 | | - * |
17 | | - * This program is distributed in the hope that it will be useful, |
18 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | | - * GNU Affero General Public License for more details. |
21 | | - * |
22 | | - * You should have received a copy of the GNU Affero General Public License |
23 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
24 | | - * |
| 6 | + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
25 | 8 | */ |
26 | 9 |
|
27 | 10 | namespace NC\Updater; |
@@ -534,27 +517,35 @@ private function getUpdateServerResponse(): array { |
534 | 517 | * |
535 | 518 | * @throws \Exception |
536 | 519 | */ |
537 | | - public function downloadUpdate(): void { |
| 520 | + public function downloadUpdate(?string $url = null): void { |
538 | 521 | $this->silentLog('[info] downloadUpdate()'); |
539 | 522 |
|
540 | | - $response = $this->getUpdateServerResponse(); |
| 523 | + $downloadURL = ''; |
| 524 | + if ($url) { |
| 525 | + // If a URL is provided, use it directly |
| 526 | + $downloadURL = $url; |
| 527 | + } else { |
| 528 | + // Otherwise, get the download URLs from the update server |
| 529 | + $response = $this->getUpdateServerResponse(); |
541 | 530 |
|
542 | | - $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/'; |
543 | | - if (file_exists($storageLocation)) { |
544 | | - $this->silentLog('[info] storage location exists'); |
545 | | - $this->recursiveDelete($storageLocation); |
546 | | - } |
547 | | - $state = mkdir($storageLocation, 0750, true); |
548 | | - if ($state === false) { |
549 | | - throw new \Exception('Could not mkdir storage location'); |
550 | | - } |
| 531 | + $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/'; |
| 532 | + if (file_exists($storageLocation)) { |
| 533 | + $this->silentLog('[info] storage location exists'); |
| 534 | + $this->recursiveDelete($storageLocation); |
| 535 | + } |
| 536 | + $state = mkdir($storageLocation, 0750, true); |
| 537 | + if ($state === false) { |
| 538 | + throw new \Exception('Could not mkdir storage location'); |
| 539 | + } |
551 | 540 |
|
552 | | - if (!isset($response['url']) || !is_string($response['url'])) { |
553 | | - throw new \Exception('Response from update server is missing url'); |
| 541 | + if (!isset($response['url']) || !is_string($response['url'])) { |
| 542 | + throw new \Exception('Response from update server is missing url'); |
| 543 | + } |
| 544 | + $downloadURL = $response['url']; |
554 | 545 | } |
555 | 546 |
|
556 | | - $fp = fopen($storageLocation . basename($response['url']), 'w+'); |
557 | | - $ch = curl_init($response['url']); |
| 547 | + $fp = fopen($storageLocation . basename($downloadURL), 'w+'); |
| 548 | + $ch = curl_init($downloadURL); |
558 | 549 | curl_setopt_array($ch, [ |
559 | 550 | CURLOPT_FILE => $fp, |
560 | 551 | CURLOPT_USERAGENT => 'Nextcloud Updater', |
@@ -598,7 +589,7 @@ public function downloadUpdate(): void { |
598 | 589 | $message .= ' - curl error message: ' . $curlErrorMessage; |
599 | 590 | } |
600 | 591 |
|
601 | | - $message .= ' - URL: ' . htmlentities($response['url']); |
| 592 | + $message .= ' - URL: ' . htmlentities($downloadURL); |
602 | 593 |
|
603 | 594 | throw new \Exception($message); |
604 | 595 | } |
@@ -631,14 +622,19 @@ private function getDownloadedFilePath(): string { |
631 | 622 | * |
632 | 623 | * @throws \Exception |
633 | 624 | */ |
634 | | - public function verifyIntegrity(): void { |
| 625 | + public function verifyIntegrity(?string $urlOverride = null): void { |
635 | 626 | $this->silentLog('[info] verifyIntegrity()'); |
636 | 627 |
|
637 | 628 | if ($this->getCurrentReleaseChannel() === 'daily') { |
638 | 629 | $this->silentLog('[info] current channel is "daily" which is not signed. Skipping verification.'); |
639 | 630 | return; |
640 | 631 | } |
641 | 632 |
|
| 633 | + if ($urlOverride) { |
| 634 | + $this->silentLog('[info] custom download url provided, cannot verify signature'); |
| 635 | + return; |
| 636 | + } |
| 637 | + |
642 | 638 | $response = $this->getUpdateServerResponse(); |
643 | 639 | if (empty($response['signature'])) { |
644 | 640 | throw new \Exception('No signature specified for defined update'); |
|
0 commit comments