Commit ba35574daf79a929cc7f764ee13474c1a37075bd
1 parent
b7741da9
Exists in
master
and in
110 other branches
Uniformize proxy host definition
Showing
6 changed files
with
45 additions
and
50 deletions
Show diff stats
... | ... | @@ -0,0 +1,33 @@ |
1 | +<?php | |
2 | + | |
3 | +class ProxyUtils { | |
4 | + static function addProxyForCurl(&$ch) { | |
5 | + if (defined('PROXY_HOST')) { | |
6 | + curl_setopt($ch, CURLOPT_PROXY, "http://".PROXY_HOST); | |
7 | + if (defined('PROXY_USERPWD')) { | |
8 | + curl_setopt($ch, CURLOPT_PROXYUSERPWD, PROXY_USERPWD); | |
9 | + } | |
10 | + } | |
11 | + } | |
12 | + | |
13 | + static function getStreamContextWithProxy() { | |
14 | + if (!defined('PROXY_HOST')) | |
15 | + return; | |
16 | + $options = array( | |
17 | + 'http' => array( | |
18 | + 'method' => 'GET', | |
19 | + 'timeout' => '5', | |
20 | + 'user_agent' => 'PHP libxml agent', | |
21 | + 'ignore_errors' => true, | |
22 | + ) | |
23 | + ); | |
24 | + $options['http']['proxy'] = 'tcp://'.PROXY_HOST; | |
25 | + $options['http']['request_fulluri'] = TRUE; | |
26 | + if (defined('PROXY_USERPWD')) { | |
27 | + $options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode(PROXY_USERPWD); | |
28 | + } | |
29 | + return stream_context_create($options); | |
30 | + } | |
31 | +} | |
32 | + | |
33 | +?> | ... | ... |
php/classes/VOTableMgr.php
... | ... | @@ -32,28 +32,11 @@ class VOTableMgr { |
32 | 32 | { |
33 | 33 | $this->is_little_endian = array_values(unpack('L1L', pack('V', 1)))[0] == 1; |
34 | 34 | |
35 | - // see http://php.net/manual/en/domdocument.load.php#91384 | |
36 | - $options = array( | |
37 | - 'http' => array( | |
38 | - 'method' => 'GET', | |
39 | - 'timeout' => '5', | |
40 | - 'user_agent' => 'PHP libxml agent', | |
41 | - // If the query is wrong, epn-tap service returns an HTTP error code 400, along with xml containing some usefull informations. | |
42 | - 'ignore_errors' => true | |
43 | - ) | |
44 | - ); | |
45 | - | |
46 | 35 | // BRE - Add proxy host if exists |
47 | - if (defined('HTTP_PROXY_HOST')) { | |
48 | - $options['http']['proxy'] = 'tcp://'.HTTP_PROXY_HOST; | |
49 | - $options['http']['request_fulluri'] = TRUE; | |
50 | - if (defined('HTTP_PROXY_USER')) { | |
51 | - $options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode(HTTP_PROXY_USER); | |
52 | - } | |
53 | - } | |
54 | - | |
55 | - $context = stream_context_create($options); | |
56 | - libxml_set_streams_context($context); | |
36 | + $context = ProxyUtils::getStreamContextWithProxy(); | |
37 | + if (isset($context)) { | |
38 | + libxml_set_streams_context($context); | |
39 | + } | |
57 | 40 | $this->xml = new DomDocument(); |
58 | 41 | |
59 | 42 | if (!@$this->xml->load($fileName)) { | ... | ... |
php/getEnv.php
php/my_config.php
... | ... | @@ -23,9 +23,8 @@ define('TITLE', 'AMDANEW-Test'); |
23 | 23 | // here for additional flexibility |
24 | 24 | define('MAX_UPLOADED_FILESIZE',30000000); // in bytes !!! |
25 | 25 | |
26 | -#define('PROXY_HOST',''); | |
27 | -#define('PROXY_PORT',''); | |
28 | -#define('PROXY_NAME',''); | |
29 | -#define('PROXY_PWD',''); | |
26 | +// To define only if you are behind a proxy | |
27 | +define('PROXY_HOST','and-fgt-ha.akka.eu:9090'); | |
28 | +define('PROXY_USERPWD','benjamin.renard:Ocu4teickpa&da'); | |
30 | 29 | |
31 | 30 | ?> | ... | ... |
php/uploadFile.php
... | ... | @@ -40,12 +40,7 @@ |
40 | 40 | curl_setopt($ch, CURLOPT_HEADER, true); |
41 | 41 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
42 | 42 | // BRE - Add proxy host if exists |
43 | - if (defined('HTTP_PROXY_HOST')) { | |
44 | - curl_setopt($ch, CURLOPT_PROXY, "http://".HTTP_PROXY_HOST); | |
45 | - if (defined('HTTP_PROXY_USER')) { | |
46 | - curl_setopt($ch, CURLOPT_PROXYUSERPWD, HTTP_PROXY_USER); | |
47 | - } | |
48 | - } | |
43 | + ProxyUtils::addProxyForCurl($ch); | |
49 | 44 | $data = curl_exec($ch); |
50 | 45 | curl_close($ch); |
51 | 46 | |
... | ... | @@ -223,21 +218,8 @@ |
223 | 218 | |
224 | 219 | // BRE - Add proxy host if exists |
225 | 220 | $result = FALSE; |
226 | - if (defined('HTTP_PROXY_HOST')) { | |
227 | - $options = array( | |
228 | - 'http' => array( | |
229 | - 'method' => 'GET', | |
230 | - 'timeout' => '5', | |
231 | - 'user_agent' => 'PHP libxml agent', | |
232 | - 'ignore_errors' => true, | |
233 | - ) | |
234 | - ); | |
235 | - $options['http']['proxy'] = 'tcp://'.HTTP_PROXY_HOST; | |
236 | - $options['http']['request_fulluri'] = TRUE; | |
237 | - if (defined('HTTP_PROXY_USER')) { | |
238 | - $options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode(HTTP_PROXY_USER); | |
239 | - } | |
240 | - $context = stream_context_create($options); | |
221 | + $context = ProxyUtils::getStreamContextWithProxy(); | |
222 | + if (isset($context)) { | |
241 | 223 | $result = copy($remoteName, $localName, $context); |
242 | 224 | } |
243 | 225 | else { | ... | ... |