From b6b4c4c9201af1539c07f611f3e24ec0de5e0667 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 14 Dec 2012 18:52:16 +0100 Subject: [PATCH 1/6] add curl proxy support. Fixes #504 https://github.com/owncloud/core/issues/504 --- config/config.sample.php | 6 ++++++ lib/util.php | 2 ++ 2 files changed, 8 insertions(+) diff --git a/config/config.sample.php b/config/config.sample.php index f531d5f146b..c915a877291 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -42,6 +42,12 @@ $CONFIG = array( /* Time in seconds how long an user is authenticated without entering his password again before performing sensitive actions like creating or deleting users etc...*/ "enhancedauthtime" => 15 * 60, +/* A proxy to use to connect to the internet. For example "myproxy.org:88" */ +"curlproxy" => "", + +/* The optional authentication for the proxy to use to connect to the internet. The format is: [username]:[password] */ +"curlproxyuserpwd" => "", + /* Theme to use for ownCloud */ "theme" => "", diff --git a/lib/util.php b/lib/util.php index 34c4d4f9b11..370e5dc13fc 100755 --- a/lib/util.php +++ b/lib/util.php @@ -696,6 +696,8 @@ class OC_Util { curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); + if(OC_Config::getValue('curlproxy','')=='') curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('curlproxy')); + if(OC_Config::getValue('curlproxyuserpwd','')=='') curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('curlproxyuserpwd')); $data = curl_exec($curl); curl_close($curl); From 2a55beab74e6ddaac80213565121c23b5357a229 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 14 Dec 2012 22:54:21 +0100 Subject: [PATCH 2/6] make it more readable as deepdiver suggested --- lib/util.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/util.php b/lib/util.php index 370e5dc13fc..61b327d0b8c 100755 --- a/lib/util.php +++ b/lib/util.php @@ -696,8 +696,12 @@ class OC_Util { curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); - if(OC_Config::getValue('curlproxy','')=='') curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('curlproxy')); - if(OC_Config::getValue('curlproxyuserpwd','')=='') curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('curlproxyuserpwd')); + if(OC_Config::getValue('curlproxy','')=='') { + curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('curlproxy')); + } + if(OC_Config::getValue('curlproxyuserpwd','')=='') { + curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('curlproxyuserpwd')); + } $data = curl_exec($curl); curl_close($curl); From f381d2e9ed4606f44641b24250379ab4c5000b6e Mon Sep 17 00:00:00 2001 From: root Date: Sat, 15 Dec 2012 00:09:39 +0100 Subject: [PATCH 3/6] call it "proxy" instead of "curlproxy" Thanks Bart for the hint. This also switches "==" to "<>" and not the code actually works ;-) --- config/config.sample.php | 4 ++-- lib/util.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index c915a877291..78dfe17ea79 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -43,10 +43,10 @@ $CONFIG = array( "enhancedauthtime" => 15 * 60, /* A proxy to use to connect to the internet. For example "myproxy.org:88" */ -"curlproxy" => "", +"proxy" => "", /* The optional authentication for the proxy to use to connect to the internet. The format is: [username]:[password] */ -"curlproxyuserpwd" => "", +"proxyuserpwd" => "", /* Theme to use for ownCloud */ "theme" => "", diff --git a/lib/util.php b/lib/util.php index 61b327d0b8c..f2044625b41 100755 --- a/lib/util.php +++ b/lib/util.php @@ -696,11 +696,11 @@ class OC_Util { curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); - if(OC_Config::getValue('curlproxy','')=='') { - curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('curlproxy')); + if(OC_Config::getValue('proxy','')<>'') { + curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('proxy')); } - if(OC_Config::getValue('curlproxyuserpwd','')=='') { - curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('curlproxyuserpwd')); + if(OC_Config::getValue('proxyuserpwd','')<>'') { + curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('proxyuserpwd')); } $data = curl_exec($curl); curl_close($curl); From 019da9943a594cb2e4c727140dbd87cd103231d8 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 14 Dec 2012 18:52:16 +0100 Subject: [PATCH 4/6] add curl proxy support. Fixes #504 https://github.com/owncloud/core/issues/504 --- config/config.sample.php | 6 +++++ lib/util.php | 51 ++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index f531d5f146b..c915a877291 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -42,6 +42,12 @@ $CONFIG = array( /* Time in seconds how long an user is authenticated without entering his password again before performing sensitive actions like creating or deleting users etc...*/ "enhancedauthtime" => 15 * 60, +/* A proxy to use to connect to the internet. For example "myproxy.org:88" */ +"curlproxy" => "", + +/* The optional authentication for the proxy to use to connect to the internet. The format is: [username]:[password] */ +"curlproxyuserpwd" => "", + /* Theme to use for ownCloud */ "theme" => "", diff --git a/lib/util.php b/lib/util.php index 4d69f3d86db..8c71d3cb4ed 100755 --- a/lib/util.php +++ b/lib/util.php @@ -667,34 +667,35 @@ class OC_Util { * If not, file_get_element is used. */ - public static function getUrlContent($url){ + public static function getUrlContent($url){ - if (function_exists('curl_init')) { + if (function_exists('curl_init')) { + + $curl = curl_init(); - $curl = curl_init(); + curl_setopt($curl, CURLOPT_HEADER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); + if(OC_Config::getValue('curlproxy','')=='') curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('curlproxy')); + if(OC_Config::getValue('curlproxyuserpwd','')=='') curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('curlproxyuserpwd')); + $data = curl_exec($curl); + curl_close($curl); - curl_setopt($curl, CURLOPT_HEADER, 0); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); - $data = curl_exec($curl); - curl_close($curl); - - } else { - - $ctx = stream_context_create( - array( - 'http' => array( - 'timeout' => 10 - ) - ) - ); - $data=@file_get_contents($url, 0, $ctx); - - } - - return $data; + } else { + + $ctx = stream_context_create( + array( + 'http' => array( + 'timeout' => 10 + ) + ) + ); + $data=@file_get_contents($url, 0, $ctx); + + } + return $data; } } From f012135992df29d48bb61f7c71315f2e54b1366b Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 14 Dec 2012 22:54:21 +0100 Subject: [PATCH 5/6] make it more readable as deepdiver suggested --- lib/util.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/util.php b/lib/util.php index 8c71d3cb4ed..65d66abc59d 100755 --- a/lib/util.php +++ b/lib/util.php @@ -678,8 +678,12 @@ class OC_Util { curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); - if(OC_Config::getValue('curlproxy','')=='') curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('curlproxy')); - if(OC_Config::getValue('curlproxyuserpwd','')=='') curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('curlproxyuserpwd')); + if(OC_Config::getValue('curlproxy','')=='') { + curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('curlproxy')); + } + if(OC_Config::getValue('curlproxyuserpwd','')=='') { + curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('curlproxyuserpwd')); + } $data = curl_exec($curl); curl_close($curl); From a64a923d5618de68ced9aaacbb3aa490e3d7594d Mon Sep 17 00:00:00 2001 From: root Date: Sat, 15 Dec 2012 00:09:39 +0100 Subject: [PATCH 6/6] call it "proxy" instead of "curlproxy" Thanks Bart for the hint. This also switches "==" to "<>" and not the code actually works ;-) --- config/config.sample.php | 4 ++-- lib/util.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index c915a877291..78dfe17ea79 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -43,10 +43,10 @@ $CONFIG = array( "enhancedauthtime" => 15 * 60, /* A proxy to use to connect to the internet. For example "myproxy.org:88" */ -"curlproxy" => "", +"proxy" => "", /* The optional authentication for the proxy to use to connect to the internet. The format is: [username]:[password] */ -"curlproxyuserpwd" => "", +"proxyuserpwd" => "", /* Theme to use for ownCloud */ "theme" => "", diff --git a/lib/util.php b/lib/util.php index 65d66abc59d..4170de2125a 100755 --- a/lib/util.php +++ b/lib/util.php @@ -678,11 +678,11 @@ class OC_Util { curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); - if(OC_Config::getValue('curlproxy','')=='') { - curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('curlproxy')); + if(OC_Config::getValue('proxy','')<>'') { + curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('proxy')); } - if(OC_Config::getValue('curlproxyuserpwd','')=='') { - curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('curlproxyuserpwd')); + if(OC_Config::getValue('proxyuserpwd','')<>'') { + curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('proxyuserpwd')); } $data = curl_exec($curl); curl_close($curl);