Skip to content

Commit

Permalink
MDL-36950 Make mdeploy.php accept proxy related settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Nov 30, 2012
1 parent 333048e commit 42c6731
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mdeploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public function get_option_info($name=null) {
$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'),
Expand Down Expand Up @@ -979,6 +982,27 @@ protected function download_file($source, $target) {
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) {
Expand Down

0 comments on commit 42c6731

Please sign in to comment.