11<?php
22/**
3- * @copyright Copyright (c) 2016-2017 Lukas Reschke <lukas@statuscode.ch>
4- * @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de>
5- * @copyright Copyright (c) 2018 Jonas Sulzer <jonas@violoncello.ch>
6- *
7- * @license GNU AGPL version 3 or any later version
8- *
9- * This program is free software: you can redistribute it and/or modify
10- * it under the terms of the GNU Affero General Public License as
11- * published by the Free Software Foundation, either version 3 of the
12- * License, or (at your option) any later version.
13- *
14- * This program is distributed in the hope that it will be useful,
15- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17- * GNU Affero General Public License for more details.
18- *
19- * You should have received a copy of the GNU Affero General Public License
20- * along with this program. If not, see <http://www.gnu.org/licenses/>.
21- *
3+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
4+ * SPDX-License-Identifier: AGPL-3.0-or-later
225 */
236
247namespace NC \Updater ;
@@ -529,11 +512,9 @@ private function getUpdateServerResponse(): array {
529512 *
530513 * @throws \Exception
531514 */
532- public function downloadUpdate (): void {
515+ public function downloadUpdate (? string $ url = null ): void {
533516 $ this ->silentLog ('[info] downloadUpdate() ' );
534517
535- $ response = $ this ->getUpdateServerResponse ();
536-
537518 $ storageLocation = $ this ->getUpdateDirectoryLocation () . '/updater- ' .$ this ->getConfigOptionMandatoryString ('instanceid ' ) . '/downloads/ ' ;
538519 if (file_exists ($ storageLocation )) {
539520 $ this ->silentLog ('[info] storage location exists ' );
@@ -544,12 +525,26 @@ public function downloadUpdate(): void {
544525 throw new \Exception ('Could not mkdir storage location ' );
545526 }
546527
547- if (!isset ($ response ['url ' ]) || !is_string ($ response ['url ' ])) {
548- throw new \Exception ('Response from update server is missing url ' );
528+ $ downloadURL = '' ;
529+ if ($ url ) {
530+ // If a URL is provided, use it directly
531+ $ downloadURL = $ url ;
532+ } else {
533+ // Otherwise, get the download URLs from the update server
534+ $ response = $ this ->getUpdateServerResponse ();
535+
536+ if (!isset ($ response ['url ' ]) || !is_string ($ response ['url ' ])) {
537+ throw new \Exception ('Response from update server is missing url ' );
538+ }
539+ $ downloadURL = $ response ['url ' ];
540+ }
541+
542+ if (!$ downloadURL ) {
543+ throw new \Exception ('No download URL provided or available from update server ' );
549544 }
550545
551- $ fp = fopen ($ storageLocation . basename ($ response [ ' url ' ] ), 'w+ ' );
552- $ ch = curl_init ($ response [ ' url ' ] );
546+ $ fp = fopen ($ storageLocation . basename ($ downloadURL ), 'w+ ' );
547+ $ ch = curl_init ($ downloadURL );
553548 curl_setopt_array ($ ch , [
554549 CURLOPT_FILE => $ fp ,
555550 CURLOPT_USERAGENT => 'Nextcloud Updater ' ,
@@ -591,7 +586,7 @@ public function downloadUpdate(): void {
591586 $ message .= ' - curl error message: ' . $ curlErrorMessage ;
592587 }
593588
594- $ message .= ' - URL: ' . htmlentities ($ response [ ' url ' ] );
589+ $ message .= ' - URL: ' . htmlentities ($ downloadURL );
595590
596591 throw new \Exception ($ message );
597592 }
@@ -624,14 +619,19 @@ private function getDownloadedFilePath(): string {
624619 *
625620 * @throws \Exception
626621 */
627- public function verifyIntegrity (): void {
622+ public function verifyIntegrity (? string $ urlOverride = null ): void {
628623 $ this ->silentLog ('[info] verifyIntegrity() ' );
629624
630625 if ($ this ->getCurrentReleaseChannel () === 'daily ' ) {
631626 $ this ->silentLog ('[info] current channel is "daily" which is not signed. Skipping verification. ' );
632627 return ;
633628 }
634629
630+ if ($ urlOverride ) {
631+ $ this ->silentLog ('[info] custom download url provided, cannot verify signature ' );
632+ return ;
633+ }
634+
635635 $ response = $ this ->getUpdateServerResponse ();
636636 if (empty ($ response ['signature ' ])) {
637637 throw new \Exception ('No signature specified for defined update ' );
0 commit comments