Merge branch 'MDL-36950-updates-proxy' of git://github.com/mudrd8mz/moodle
authorDan Poltawski <dan@moodle.com>
Mon, 3 Dec 2012 07:21:25 +0000 (15:21 +0800)
committerDan Poltawski <dan@moodle.com>
Mon, 3 Dec 2012 07:21:25 +0000 (15:21 +0800)
lib/pluginlib.php
mdeploy.php

index 02a6d99..9211a5b 100644 (file)
@@ -1691,6 +1691,28 @@ class available_update_deployer {
             'returnurl' => $upgradeurl->out(true),
         );
 
+        if (!empty($CFG->proxyhost)) {
+            // Beware - we should call just !is_proxybypass() here. But currently, our cURL wrapper
+            // class does not do it. So, to have consistent behaviour, we pass proxy setting
+            // regardless the $CFG->proxybypass setting. Once the {@link curl} class is fixed,
+            // the condition should be amended.
+            if (true or !is_proxybypass($info->download)) {
+                if (empty($CFG->proxyport)) {
+                    $params['proxy'] = $CFG->proxyhost;
+                } else {
+                    $params['proxy'] = $CFG->proxyhost.':'.$CFG->proxyport;
+                }
+
+                if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) {
+                    $params['proxyuserpwd'] = $CFG->proxyuser.':'.$CFG->proxypassword;
+                }
+
+                if (!empty($CFG->proxytype)) {
+                    $params['proxytype'] = $CFG->proxytype;
+                }
+            }
+        }
+
         $widget = new single_button(
             new moodle_url('/mdeploy.php', $params),
             get_string('updateavailableinstall', 'core_admin'),
index fa53d04..8381a90 100644 (file)
@@ -171,6 +171,9 @@ class input_manager extends singleton_pattern {
         $supportedoptions = array(
             array('', 'passfile', input_manager::TYPE_FILE, 'File name of the passphrase file (HTTP access only)'),
             array('', 'password', input_manager::TYPE_RAW, 'Session passphrase (HTTP access only)'),
+            array('', 'proxy', input_manager::TYPE_RAW, 'HTTP proxy host and port (e.g. \'our.proxy.edu:8888\')'),
+            array('', 'proxytype', input_manager::TYPE_RAW, 'Proxy type (HTTP or SOCKS5)'),
+            array('', 'proxyuserpwd', input_manager::TYPE_RAW, 'Proxy username and password (e.g. \'username:password\')'),
             array('', 'returnurl', input_manager::TYPE_URL, 'Return URL (HTTP access only)'),
             array('d', 'dataroot', input_manager::TYPE_PATH, 'Full path to the dataroot (moodledata) directory'),
             array('h', 'help', input_manager::TYPE_FLAG, 'Prints usage information'),
@@ -979,6 +982,27 @@ class worker extends singleton_pattern {
             curl_setopt($ch, CURLOPT_CAINFO, $cacertfile);
         }
 
+        $proxy = $this->input->get_option('proxy', false);
+        if (!empty($proxy)) {
+            curl_setopt($ch, CURLOPT_PROXY, $proxy);
+
+            $proxytype = $this->input->get_option('proxytype', false);
+            if (strtoupper($proxytype) === 'SOCKS5') {
+                $this->log('Using SOCKS5 proxy');
+                curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+            } else if (!empty($proxytype)) {
+                $this->log('Using HTTP proxy');
+                curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+                curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);
+            }
+
+            $proxyuserpwd = $this->input->get_option('proxyuserpwd', false);
+            if (!empty($proxyuserpwd)) {
+                curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuserpwd);
+                curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM);
+            }
+        }
+
         $targetfile = fopen($target, 'w');
 
         if (!$targetfile) {