From 1f6846bd10682f4c6a82b3c950c71ae76288a7f1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 15 Nov 2023 19:05:43 +0100 Subject: [inc/Download] Fix downloading from Wikipedia --- inc/download.inc.php | 5 +++++ modules-available/sysconfig/addmodule_branding.inc.php | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/inc/download.inc.php b/inc/download.inc.php index 578992a6..2eef219c 100644 --- a/inc/download.inc.php +++ b/inc/download.inc.php @@ -27,6 +27,8 @@ class Download curl_setopt(self::$curlHandle, CURLOPT_FOLLOWLOCATION, true); curl_setopt(self::$curlHandle, CURLOPT_AUTOREFERER, true); curl_setopt(self::$curlHandle, CURLOPT_MAXREDIRS, 6); + curl_setopt(self::$curlHandle, CURLOPT_ACCEPT_ENCODING, ''); + curl_setopt(self::$curlHandle, CURLOPT_PROTOCOLS, CURLPROTO_FTP | CURLPROTO_FTPS | CURLPROTO_HTTP | CURLPROTO_HTTPS); } curl_setopt(self::$curlHandle, CURLOPT_URL, $url); @@ -41,6 +43,7 @@ class Download public static function asString(string $url, int $timeout, ?int &$code) { $ch = self::initCurl($url, $timeout); + curl_setopt($ch, CURLOPT_FILE, null); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $code = (int)curl_getinfo($ch, CURLINFO_RESPONSE_CODE); @@ -68,6 +71,7 @@ class Download } } $ch = self::initCurl($url, $timeout); + curl_setopt($ch, CURLOPT_FILE, null); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $string); @@ -90,6 +94,7 @@ class Download if ($fh === false) ErrorHandler::traceError("Could not open $target for writing."); $ch = self::initCurl($url, $timeout); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_FILE, $fh); $res = curl_exec($ch); $code = (int)curl_getinfo($ch, CURLINFO_RESPONSE_CODE); diff --git a/modules-available/sysconfig/addmodule_branding.inc.php b/modules-available/sysconfig/addmodule_branding.inc.php index 5d94a489..52d466fe 100644 --- a/modules-available/sysconfig/addmodule_branding.inc.php +++ b/modules-available/sysconfig/addmodule_branding.inc.php @@ -47,8 +47,10 @@ class Branding_ProcessFile extends AddModule_Base if (strpos($url, '://') === false) $url = "http://$url"; $title = false; - if (!Branding_ProcessFile::downloadSvg($this->svgFile, $url, $title)) + if (!Branding_ProcessFile::downloadSvg($this->svgFile, $url, $title)) { + @unlink($this->svgFile); Util::redirect('?do=SysConfig&action=addmodule&step=Branding_Start'); + } Session::set('logo_name', $title); } chmod($this->svgFile, 0644); -- cgit v1.2.3-55-g7522