From 4205ec7f0a43182934b9daa73027771523ab2189 Mon Sep 17 00:00:00 2001
From: Ankit Agarwal <ankit@moodle.com>
Date: Wed, 2 Nov 2016 16:06:20 +0530
Subject: [PATCH] MDL-55777 installation: Check libcurl version on install

---
 admin/environment.xml         | 20 ++++++++++++++++++++
 lang/en/admin.php             |  1 +
 lib/tests/upgradelib_test.php | 16 ++++++++++++++++
 lib/upgradelib.php            | 25 +++++++++++++++++++++++++
 version.php                   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/admin/environment.xml b/admin/environment.xml
index 1f522ab..f2f135d 100644
--- a/admin/environment.xml
+++ b/admin/environment.xml
@@ -1145,6 +1145,11 @@
           <ON_CHECK message="unsupporteddbtablerowformat" />
         </FEEDBACK>
       </CUSTOM_CHECK>
+      <CUSTOM_CHECK file="lib/upgradelib.php" function="check_libcurl_version" level="optional">
+        <FEEDBACK>
+          <ON_CHECK message="libcurlwarning" />
+        </FEEDBACK>
+      </CUSTOM_CHECK>
     </CUSTOM_CHECKS>
   </MOODLE>
   <MOODLE version="2.8" requires="2.2">
@@ -1556,6 +1561,11 @@
           <ON_CHECK message="unsupporteddbtablerowformat" />
         </FEEDBACK>
       </CUSTOM_CHECK>
+      <CUSTOM_CHECK file="lib/upgradelib.php" function="check_libcurl_version" level="optional">
+        <FEEDBACK>
+          <ON_CHECK message="libcurlwarning" />
+        </FEEDBACK>
+      </CUSTOM_CHECK>
     </CUSTOM_CHECKS>
   </MOODLE>
   <MOODLE version="3.1" requires="2.7">
@@ -1696,6 +1706,11 @@
           <ON_CHECK message="unsupporteddbtablerowformat" />
         </FEEDBACK>
       </CUSTOM_CHECK>
+      <CUSTOM_CHECK file="lib/upgradelib.php" function="check_libcurl_version" level="optional">
+        <FEEDBACK>
+          <ON_CHECK message="libcurlwarning" />
+        </FEEDBACK>
+      </CUSTOM_CHECK>
     </CUSTOM_CHECKS>
   </MOODLE>
   <MOODLE version="3.2" requires="2.7">
@@ -1841,6 +1856,11 @@
           <ON_CHECK message="unoconvwarning" />
         </FEEDBACK>
       </CUSTOM_CHECK>
+      <CUSTOM_CHECK file="lib/upgradelib.php" function="check_libcurl_version" level="optional">
+        <FEEDBACK>
+          <ON_CHECK message="libcurlwarning" />
+        </FEEDBACK>
+      </CUSTOM_CHECK>
     </CUSTOM_CHECKS>
   </MOODLE>
 </COMPATIBILITY_MATRIX>
diff --git a/lang/en/admin.php b/lang/en/admin.php
index db5d648..b56a86a 100644
--- a/lang/en/admin.php
+++ b/lang/en/admin.php
@@ -610,6 +610,7 @@ $string['legacyfilesaddallowed'] = 'Allow adding to legacy course files';
 $string['legacyfilesaddallowed_help'] = 'If a course has legacy course files, allow new files and folders to be added to it.';
 $string['legacyfilesinnewcourses'] = 'Legacy course files in new courses';
 $string['legacyfilesinnewcourses_help'] = 'By default, legacy course files areas are available in upgraded courses only. Please note that some features such as activity backup and restore are not compatible with this setting.';
+$string['libcurlwarning'] = 'Libcurl with CURLOPT_PROTOCOL support has not been detected. It is recommended to have an up to date libcurl installation for security reasons.';
 $string['licensesettings'] = 'Licence settings';
 $string['linkadmincategories'] = 'Link admin categories';
 $string['linkadmincategories_help'] = 'If enabled admin setting categories will be displayed as links in the navigation and will lead to the admin category pages.';
diff --git a/lib/tests/upgradelib_test.php b/lib/tests/upgradelib_test.php
index a40837a..5417c61 100644
--- a/lib/tests/upgradelib_test.php
+++ b/lib/tests/upgradelib_test.php
@@ -351,4 +351,20 @@ class core_upgradelib_testcase extends advanced_testcase {
                     (object)array('userfield' => 'email', 'shortname' => null, 'operator' => 'isempty'),
                 )));
     }
+
+    /**
+     * Test libcurl custom check api.
+     */
+    public function test_check_libcurl_version() {
+        $supportedversion = 0x071304;
+        $curlinfo = curl_version();
+        $currentversion = $curlinfo['version_number'];
+
+        $result = new environment_results("custom_checks");
+        if ($currentversion < $supportedversion) {
+            $this->assertFalse(check_libcurl_version($result)->getStatus());
+        } else {
+            $this->assertTrue(check_libcurl_version($result)->getStatus());
+        }
+    }
 }
diff --git a/lib/upgradelib.php b/lib/upgradelib.php
index d404e59..3d38f91 100644
--- a/lib/upgradelib.php
+++ b/lib/upgradelib.php
@@ -2266,3 +2266,28 @@ function check_database_tables_row_format(environment_results $result) {
 
     return null;
 }
+
+function check_libcurl_version(environment_results $result) {
+
+    // Supported version and version number.
+    $supportedversion = 0x071304;
+    $supportedversionstring = "7.19.4";
+
+    // Installed version.
+    $curlinfo = curl_version();
+    $currentversion = $curlinfo['version_number'];
+
+    // Set info, we want to let user know how to resolve the problem.
+    $result->setInfo('Libcurl version check');
+    $result->setNeededVersion($supportedversionstring);
+    $result->setCurrentVersion($curlinfo['version']);
+
+    if ($currentversion < $supportedversion) {
+        // Test fail.
+        $result->setStatus(false);
+    } else {
+        $result->setStatus(true);
+    }
+
+    return $result;
+}
\ No newline at end of file
diff --git a/version.php b/version.php
index ce6a8b5..0e0b8cc 100644
--- a/version.php
+++ b/version.php
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2014051216.01;              // 20140512      = branching date YYYYMMDD - do not modify!
+$version  = 2014051216.02;              // 20140512      = branching date YYYYMMDD - do not modify!
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.
 
-- 
2.7.4

