From ec1f895ad5f35f85aeadf23a87c339c9f89838d4 Mon Sep 17 00:00:00 2001
From: Thijs Kinkhorst <thijs@kinkhorst.com>
Date: Mon, 27 Aug 2018 12:06:35 +0000
Subject: [PATCH] Check for presence of cURL extension before performing update
 check.

Otherwise new installs that do not have this extension get a "white
page" with an exception in the logs, because the check happens before
the page reports on the required modules. This will no doubt lead to
many support questions on the mailing list.
---
 modules/core/dictionaries/frontpage.definition.json  |  3 +++
 modules/core/dictionaries/frontpage.translation.json |  3 +++
 modules/core/locales/en/LC_MESSAGES/core.po          |  3 +++
 modules/core/locales/nl/LC_MESSAGES/core.po          |  3 +++
 modules/core/www/frontpage_config.php                | 12 ++++++++----
 5 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/modules/core/dictionaries/frontpage.definition.json b/modules/core/dictionaries/frontpage.definition.json
index ee509f4b5..c470b5ba8 100644
--- a/modules/core/dictionaries/frontpage.definition.json
+++ b/modules/core/dictionaries/frontpage.definition.json
@@ -41,6 +41,9 @@
 	"warnings": {
 		"en": "Warnings"
 	},
+	"warnings_curlmissing": {
+		"en": "PHP cURL extension missing. Cannot check for SimpleSAMLphp updates."
+	},
 	"warnings_https": {
 		"en": "<strong>You are not using HTTPS<\/strong> - encrypted communication with the user. HTTP works fine for test purposes, but in a production environment, you should use HTTPS. [ <a href=\"https:\/\/simplesamlphp.org\/docs\/stable\/simplesamlphp-maintenance\">Read more about SimpleSAMLphp maintenance<\/a> ]"
 	},
diff --git a/modules/core/dictionaries/frontpage.translation.json b/modules/core/dictionaries/frontpage.translation.json
index 767bf766f..13337fd26 100644
--- a/modules/core/dictionaries/frontpage.translation.json
+++ b/modules/core/dictionaries/frontpage.translation.json
@@ -1630,5 +1630,8 @@
 		"es": "Su instalaci&oacute;n de SimpleSAMLphp est&aacute; desactualizada. Por favor, actualice a la <a href=\"%LATEST_URL%\">&uacute;ltima versi&oacute;n</a> lo antes posible.",
 		"zh-tw": "\u60a8\u6b63\u5728\u4f7f\u7528\u5df2\u904e\u6642\u7684 SimpleSAMLphp \u7248\u672c\uff0c\u8acb\u76e1\u5feb\u66f4\u65b0\u81f3<a href=\"%LATEST_URL%\">\u6700\u65b0\u7248\u672c</a>\u3002",
 		"nl": "Deze installatie van SimpleSAMLphp is verouderd. Het is aan te raden zo snel mogelijk te upgraden naar <a href=\"%LATEST_URL%\">de meest recente versie</a>."
+	},
+	"warnings_curlmissing": {
+		"nl": "PHP cURL-extensie ontbreekt. Kan niet controleren op updates voor simpleSAMLphp."
 	}
 }
diff --git a/modules/core/locales/en/LC_MESSAGES/core.po b/modules/core/locales/en/LC_MESSAGES/core.po
index 9ddd25f62..38593a5ec 100644
--- a/modules/core/locales/en/LC_MESSAGES/core.po
+++ b/modules/core/locales/en/LC_MESSAGES/core.po
@@ -360,6 +360,9 @@ msgstr "Configure Shibboleth 1.3 SP to work with SimpleSAMLphp IdP"
 msgid "Using the back and forward buttons in the web browser."
 msgstr "Using the back and forward buttons in the web browser."
 
+msgid "PHP cURL extension missing. Cannot check for SimpleSAMLphp updates."
+msgstr "PHP cURL extension missing. Cannot check for SimpleSAMLphp updates."
+
 msgid ""
 "You are running an outdated version of SimpleSAMLphp. Please update to <a"
 " href=\"%LATEST_URL%\">the latest version</a> as soon as possible."
diff --git a/modules/core/locales/nl/LC_MESSAGES/core.po b/modules/core/locales/nl/LC_MESSAGES/core.po
index edeee369e..95f5aa885 100644
--- a/modules/core/locales/nl/LC_MESSAGES/core.po
+++ b/modules/core/locales/nl/LC_MESSAGES/core.po
@@ -137,6 +137,9 @@ msgstr ""
 "snel mogelijk te upgraden naar <a href=\"%LATEST_URL%\">de meest recente "
 "versie</a>."
 
+msgid "{core:frontpage:warnings_curlmissing}"
+msgstr "PHP cURL-extensie ontbreekt. Kan niet controleren op updates voor SimpleSAMLphp."
+
 msgid "{core:frontpage:loggedin_as_admin}"
 msgstr "Je bent ingelogd als beheerder"
 
diff --git a/modules/core/www/frontpage_config.php b/modules/core/www/frontpage_config.php
index 26d388b8b..a343b9580 100644
--- a/modules/core/www/frontpage_config.php
+++ b/modules/core/www/frontpage_config.php
@@ -58,9 +58,12 @@ $allLinks = array(
 // don't need to fetch it on every access to this page.
 $current = $config->getVersion();
 if ($config->getBoolean('admin.checkforupdates', true) && $current !== 'master') {
-    $latest = $session->getData("core:latest_simplesamlphp_version", "version");
+    if (!function_exists('curl_init')) {
+        $warnings[] = [ '{core:frontpage:warnings_curlmissing}' ];
+    } else {
+        $latest = $session->getData("core:latest_simplesamlphp_version", "version");
 
-    if (!$latest) {
+        if (!$latest) {
         $api_url = 'https://api.github.com/repos/simplesamlphp/simplesamlphp/releases';
         $ch = curl_init($api_url.'/latest');
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@@ -75,14 +78,15 @@ if ($config->getBoolean('admin.checkforupdates', true) && $current !== 'master')
             $session->setData("core:latest_simplesamlphp_version", "version", $latest);
         }
         curl_close($ch);
-    }
+        }
 
-    if ($latest && version_compare($current, ltrim($latest['tag_name'], 'v'), 'lt')) {
+        if ($latest && version_compare($current, ltrim($latest['tag_name'], 'v'), 'lt')) {
         $outdated = true;
         $warnings[] = array(
             '{core:frontpage:warnings_outdated}',
             array('%LATEST_URL%' => $latest['html_url'])
         );
+        }
     }
 }
 
-- 
GitLab