From a7fce608672c1c9080b598084c2442f4c2d1035e Mon Sep 17 00:00:00 2001 From: Brian King Date: Mon, 29 Apr 2013 17:39:12 +0200 Subject: [PATCH] MDL-39409 auth/cas pass web proxy settings along to phpCAS --- auth/cas/auth.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/auth/cas/auth.php b/auth/cas/auth.php index 7d76eefe7fd..40528e6828a 100644 --- a/auth/cas/auth.php +++ b/auth/cas/auth.php @@ -162,7 +162,7 @@ class auth_plugin_cas extends auth_plugin_ldap { * */ function connectCAS() { - global $PHPCAS_CLIENT; + global $CFG, $PHPCAS_CLIENT; if (!is_object($PHPCAS_CLIENT)) { // Make sure phpCAS doesn't try to start a new PHP session when connecting to the CAS server. @@ -173,6 +173,27 @@ class auth_plugin_cas extends auth_plugin_ldap { } } + // If Moodle is configured to use a proxy, phpCAS needs some curl options set. + if (!empty($CFG->proxyhost) && !is_proxybypass($this->config->hostname)) { + phpCAS::setExtraCurlOption(CURLOPT_PROXY, $CFG->proxyhost); + if (!empty($CFG->proxyport)) { + phpCAS::setExtraCurlOption(CURLOPT_PROXYPORT, $CFG->proxyport); + } + if (!empty($CFG->proxytype)) { + // Only set CURLOPT_PROXYTYPE if it's something other than the curl-default http + if ($CFG->proxytype == 'SOCKS5') { + phpCAS::setExtraCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); + } + } + if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) { + phpCAS::setExtraCurlOption(CURLOPT_PROXYUSERPWD, $CFG->proxyuser.':'.$CFG->proxypassword); + if (defined('CURLOPT_PROXYAUTH')) { + // any proxy authentication if PHP 5.1 + phpCAS::setExtraCurlOption(CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM); + } + } + } + if($this->config->certificate_check && $this->config->certificate_path){ phpCAS::setCasServerCACert($this->config->certificate_path); }else{