Add a proxy Support

Development-related discussion, including bundled plugins
Physaphae
Bear Rating Trainee
Bear Rating Trainee
Posts: 1
Joined: 02 Apr 2015, 17:38
Location: France
Contact:

Add a proxy Support

Postby Physaphae » 02 Apr 2015, 18:01

Hello everybody

(first of all excuse my english i'am a foreigner ;-) )

I really like TT rss, so I used it at work (heaven if it is forbidden by my IT service). But there is a proxy... So I need to pass it.
It a really stupid proxy, so I need to adapt a lot of code.

For people who want to do so (or to add a feature) here is my long journey thru squid/curl and HTTP headers:

First of all I use curl so I Add Php_Curl to php extensions

I add some constant in config.php:

Code: Select all

   // ***************************************
   // *** Proxy settings (less important) ***
   // ***************************************
   
   // Special Add on by Physaphaé (no bug support or else)
   // To understand how it works, everything is in functions.php line 300~ and in functions2.php line 2300~
   // To use proxy, you need tu use php_curl (no way to use url_fopen for this)

   //define ("_CURL_HTTP_PROXY_IP","proxydns");                  // Proxy IP or DNS
   //define ("_CURL_HTTP_PROXY_PORT","proxuport");               // Proxy port
   //define ("_CURL_HTTP_PROXYTYPE","");                     // Proxy type default is CURLPROXY_HTTP
   //define ("_CURL_HTTP_PROXYAUTH","");                     // Proxy auth type default is CURLAUTH_BASIC
   //define ("_CURL_HTTP_PROXY_USER","login");                  // Proxy username
   //define ("_CURL_HTTP_PROXY_Password",'password');            // Proxy username's password
   //define ("_CURL_HTTP_PROXY_HTTP_Ver","CURL_HTTP_VERSION_1_1");   // Proxy specific HTTP Version (most of time not used)
   //define ("_CURL_HTTP_PROXY_ForceTunnel",true);               // Some Proxy need CURLOPT_HTTPPROXYTUNNEL = true
   //define ("_CURL_HTTP_PROXY_ForceFOLLOWLOCATION",true);         // Some Proxy need CURLOPT_FOLLOWLOCATION = true



I add some code in functions.php around line 378:

Code: Select all

         $headers[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
         $headers[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
         $headers[] = "Connection: keep-alive";
         $headers[] = "Proxy-Connection: keep-alive";//This is usefull to not be kicked off too quickly
         $headers[] = "Keep-Alive: 300";
         $headers[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
         $headers[] = "Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4";//Yes my mothertong is french ;-)
         
         if ($timestamp && !$post_query) {
            $headers[] = "If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T', $timestamp);   
         }
         $headers[] = "Pragma: ";
         
         curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
         
         if (defined("_CURL_HTTP_PROXY_HTTP_Ver")){
            switch (_CURL_HTTP_PROXY_HTTP_Ver) {
               case "CURL_HTTP_VERSION_NONE":
                  curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_NONE );
                  break;
               case "CURL_HTTP_VERSION_1_0":
                  curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0 );
                  break;
               case "CURL_HTTP_VERSION_1_1":
                  curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1 );
                  break;
               case "CURL_HTTP_VERSION_2_0":
                  curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2_0 );
                  break;
            }         
         }
         if (defined('_CURL_HTTP_PROXY_ForceTunnel')){
            curl_setopt($ch, CURLOPT_HTTP_VERSION,_CURL_HTTP_PROXY_ForceTunnel );
         }
         if (defined('_CURL_HTTP_PROXYTYPE')){
            curl_setopt($ch, CURLOPT_PROXYTYPE,_CURL_HTTP_PROXYTYPE );
         }
         if (defined('_CURL_HTTP_PROXYAUTH')){
            curl_setopt($ch, CURLOPT_PROXYAUTH,_CURL_HTTP_PROXYAUTH );
         }
         //Proxy IP:Port
         if ((defined("_CURL_HTTP_PROXY_IP"))and(defined("_CURL_HTTP_PROXY_PORT"))){
            curl_setopt($ch, CURLOPT_PROXY,"tcp://" . _CURL_HTTP_PROXY_IP . ":" . _CURL_HTTP_PROXY_PORT );
         }
         //Proxy redential
         if ((defined('_CURL_HTTP_PROXY_USER'))and(defined('_CURL_HTTP_PROXY_Password'))){
            curl_setopt($ch, CURLOPT_PROXYUSERPWD,_CURL_HTTP_PROXY_USER.":"._CURL_HTTP_PROXY_Password );
         }
         curl_setopt($ch, CURLOPT_PROTOCOLS , CURLPROTO_HTTP|CURLPROTO_HTTPS);

         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT);



I add some code in functions2.php around line 2283:

Code: Select all

      $headers[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
      $headers[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
      $headers[] = "Connection: keep-alive";
      $headers[] = "Proxy-Connection: keep-alive";
      $headers[] = "Keep-Alive: 300";
      $headers[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
      $headers[] = "Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4";
      $headers[] = "Pragma: ";

      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      //curl_setopt($curl, CURLOPT_TIMEOUT, 60);
      curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
      
      if (defined('_CURL_HTTP_PROXY_HTTP_Ver')){
         switch (_CURL_HTTP_PROXY_HTTP_Ver) {
            case "CURL_HTTP_VERSION_NONE":
               curl_setopt($curl, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_NONE );
               break;
            case "CURL_HTTP_VERSION_1_0":
               curl_setopt($curl, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0 );
               break;
            case "CURL_HTTP_VERSION_1_1":
               curl_setopt($curl, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1 );
               break;
            case "CURL_HTTP_VERSION_2_0":
               curl_setopt($curl, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2_0 );
               break;
         }         
      }
      if (defined('_CURL_HTTP_PROXY_ForceTunnel')){
         curl_setopt($curl, CURLOPT_HTTP_VERSION,_CURL_HTTP_PROXY_ForceTunnel );
      }
      if (defined('_CURL_HTTP_PROXYTYPE')){
         curl_setopt($curl, CURLOPT_PROXYTYPE,_CURL_HTTP_PROXYTYPE );
      }
      if (defined('_CURL_HTTP_PROXYAUTH')){
         curl_setopt($curl, CURLOPT_PROXYAUTH,_CURL_HTTP_PROXYAUTH );
      }
      //Proxy IP:Port
      if ((defined("_CURL_HTTP_PROXY_IP"))and(defined("_CURL_HTTP_PROXY_PORT"))){
         curl_setopt($curl, CURLOPT_PROXY,"tcp://" . _CURL_HTTP_PROXY_IP . ":" . _CURL_HTTP_PROXY_PORT );
      }
      //Proxy redential
      if ((defined('_CURL_HTTP_PROXY_USER'))and(defined('_CURL_HTTP_PROXY_Password'))){
         curl_setopt($curl, CURLOPT_PROXYUSERPWD,_CURL_HTTP_PROXY_USER.":"._CURL_HTTP_PROXY_Password );
      }
      curl_setopt($curl, CURLOPT_PROTOCOLS , CURLPROTO_HTTP|CURLPROTO_HTTPS);
      
      if (defined('_CURL_HTTP_PROXY_ForceFOLLOWLOCATION')){
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION,_CURL_HTTP_PROXY_ForceFOLLOWLOCATION );
      }else{
         
      }
      
      curl_setopt($curl, CURLOPT_REFERER, $url);
      curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Firefox/5.0');
      


You just have to fill config.php with your values, uncomment, and it works...

I'll be very happy if someone include it in the next release (I will not have to do do it again ;-) )

If you get some trouble to configure it, you can create a Test_Curl.php which look like this and perform test

Code: Select all

define ("_CURL_HTTP_PROXY_IP","");                        // Proxy IP or DNS
define ("_CURL_HTTP_PROXY_PORT","");                     // Proxy port
//define ("_CURL_HTTP_PROXYTYPE","");                     // Proxy type default is CURLPROXY_HTTP
//define ("_CURL_HTTP_PROXYAUTH","");                     // Proxy auth type default is CURLAUTH_BASIC
define ("_CURL_HTTP_PROXY_USER","");                     // Proxy username
define ("_CURL_HTTP_PROXY_Password",'');                  // Proxy username's password
define ("_CURL_HTTP_PROXY_HTTP_Ver","CURL_HTTP_VERSION_1_1");   // Proxy specific HTTP Version (most of time not used)
//define ("_CURL_HTTP_PROXY_ForceTunnel",true);               // Some Proxy need CURLOPT_HTTPPROXYTUNNEL = true
define ("_CURL_HTTP_PROXY_ForceFOLLOWLOCATION",true);         // Some Proxy need CURLOPT_FOLLOWLOCATION = true

function getPage($url, $referer, $agent, $header, $timeout) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
   //curl_setopt($curl, CURLOPT_HEADER, true);
   curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
   
   
   if (defined('_CURL_HTTP_PROXY_HTTP_Ver')){
         curl_setopt($curl, CURLOPT_HTTP_VERSION,_CURL_HTTP_PROXY_HTTP_Ver );
      }
      if (defined('_CURL_HTTP_PROXY_ForceTunnel')){
         curl_setopt($curl, CURLOPT_HTTP_VERSION,_CURL_HTTP_PROXY_ForceTunnel );
      }
      if (defined('_CURL_HTTP_PROXYTYPE')){
         curl_setopt($curl, CURLOPT_PROXYTYPE,_CURL_HTTP_PROXYTYPE );
      }
      if (defined('_CURL_HTTP_PROXYAUTH')){
         curl_setopt($curl, CURLOPT_PROXYAUTH,_CURL_HTTP_PROXYAUTH );
      }
      //Proxy IP:Port
      if ((defined('_CURL_HTTP_PROXY_IP'))and(defined('_CURL_HTTP_PROXY_PORT'))){
         curl_setopt($curl, CURLOPT_PROXY,"tcp://" . _CURL_HTTP_PROXY_IP . ":" . _CURL_HTTP_PROXY_PORT );
      }
      //Proxy redential
      if ((defined('_CURL_HTTP_PROXY_USER'))and(defined('_CURL_HTTP_PROXY_Password'))){
         curl_setopt($curl, CURLOPT_PROXYUSERPWD,_CURL_HTTP_PROXY_USER.":"._CURL_HTTP_PROXY_Password );
      }
      curl_setopt($curl, CURLOPT_PROTOCOLS , CURLPROTO_HTTP|CURLPROTO_HTTPS);
      
      if (defined('_CURL_HTTP_PROXY_ForceFOLLOWLOCATION')){
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION,_CURL_HTTP_PROXY_ForceFOLLOWLOCATION );
      }else{
         
      }
   
    curl_setopt($curl, CURLOPT_REFERER, $referer);
    curl_setopt($curl, CURLOPT_USERAGENT, $agent);
   //curl_setopt($curl, CURLOPT_VERBOSE, true);
   if (strpos($url, 'https://') === 0) {
      //curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
   }
    $result['EXE'] = curl_exec($curl);
    $result['INF'] = curl_getinfo($curl);
    $result['ERR'] = curl_error($curl);
   
   
   
    curl_close($curl);
 
    return $result;
}

$headers[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$headers[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$headers[] = "Connection: keep-alive";
$headers[] = "Proxy-Connection: keep-alive";
$headers[] = "Keep-Alive: 300";
$headers[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$headers[] = "Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4";
$headers[] = "Pragma: ";

$result = getPage(
    'http://www.undernews.fr/feed',
    'http://www.undernews.fr/feed',
    'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8',
    $headers,
    15);
 
if (empty($result['ERR'])) {
   
} else {
    echo $result['ERR'];
   echo("<HR>");
    var_dump( $result['INF']);
   echo("<HR>");
    echo $result['EXE'];
   echo("<HR>");
   var_dump( curl_version ());
   echo("<HR>");
   echo("<HR>");
}


Best regards,
Physaphaé

bashrc
Bear Rating Trainee
Bear Rating Trainee
Posts: 1
Joined: 09 Feb 2016, 14:50

Re: Add a proxy Support

Postby bashrc » 09 Feb 2016, 15:05

Not as comprehensive as above, but I made a small patch to enable setting of the proxy type. This allows me to specify socks5 and therefore be able to proxy through Tor.

Code: Select all

From 65f45ee952ce8a782fac112cbf04976039c8a472 Tue Feb 09 12:02:40 2016
From: Bob Mottram <[email protected]>
Date: Tue, 9 Feb 2016 12:02:40 +0000
Subject: [PATCH] Allow proxy type to be set using _CURL_HTTP_PROXY_TYPE

---
 include/functions.php      | 19 +++++++++++++++++++
 plugins/af_unburn/init.php | 19 +++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/include/functions.php b/include/functions.php
--- a/include/functions.php
+++ b/include/functions.php
@@ -378,6 +378,25 @@
             curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);
          }
 
+         if (defined('_CURL_HTTP_PROXY_TYPE')) {
+            switch(_CURL_HTTP_PROXY_TYPE) {
+               case 'socks4':
+                  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+                  break;
+               case 'socks4a':
+                  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4A);
+                  break;
+               case 'socks5':
+                  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+                  break;
+               case 'socks5host':
+                  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
+                  break;
+               default:
+                  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+            }
+         }
+
          if ($post_query) {
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $post_query);
diff --git a/plugins/af_unburn/init.php b/plugins/af_unburn/init.php
index e5f43e4..c9ab58c 100755
--- a/plugins/af_unburn/init.php
+++ b/plugins/af_unburn/init.php
@@ -41,6 +41,25 @@ class Af_Unburn extends Plugin {
                curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);
             }
 
+            if (defined('_CURL_HTTP_PROXY_TYPE')) {
+               switch(_CURL_HTTP_PROXY_TYPE) {
+                  case 'socks4':
+                     curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+                     break;
+                  case 'socks4a':
+                     curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4A);
+                     break;
+                  case 'socks5':
+                     curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+                     break;
+                  case 'socks5host':
+                     curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
+                     break;
+                  default:
+                     curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+               }
+            }
+
             @curl_exec($ch);
 
             $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
--
2.4.1

bron.nsk
Bear Rating Trainee
Bear Rating Trainee
Posts: 1
Joined: 14 Feb 2016, 13:56

Re: Add a proxy Support

Postby bron.nsk » 14 Feb 2016, 14:02

bashrc wrote:Not as comprehensive as above, but I made a small patch to enable setting of the proxy type. This allows me to specify socks5 and therefore be able to proxy through Tor.


so can you please upload result files funcions.php, functions2.php anywhere, or attach in here?

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: Add a proxy Support

Postby fox » 14 Feb 2016, 14:09

this is a fascinatingly terrible idea

SimbaLion
Bear Rating Trainee
Bear Rating Trainee
Posts: 21
Joined: 07 Jul 2015, 02:04

Re: Add a proxy Support

Postby SimbaLion » 14 Mar 2016, 17:29

Does this still work? I know Fox said it's a bad idea but I really need some kind of basic proxy support.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: Add a proxy Support

Postby fox » 14 Mar 2016, 17:55

there's basic (undocumented and unsupported) http proxy support already (curl only):

Code: Select all

define('_CURL_HTTP_PROXY', 'hostname:port');


e: to clarify, posting patched source files is a fascinatingly bad idea, for obvious reasons (a few months later replacing something with an older file can break things completely)

SimbaLion
Bear Rating Trainee
Bear Rating Trainee
Posts: 21
Joined: 07 Jul 2015, 02:04

Re: Add a proxy Support

Postby SimbaLion » 14 Mar 2016, 18:16

Does that undoccumented feature include basic http authentication, user/pass?

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: Add a proxy Support

Postby fox » 14 Mar 2016, 18:40

if curl_setopt CURLOPT_PROXY supports it, then yes

otherwise, no

SimbaLion
Bear Rating Trainee
Bear Rating Trainee
Posts: 21
Joined: 07 Jul 2015, 02:04

Re: Add a proxy Support

Postby SimbaLion » 14 Mar 2016, 20:39

well I've configured define('_CURL_HTTP_PROXY', 'hostname:port');

however from what I can tell it is not even attempting to use the proxy. The proxy is receiving zero traffic from the tt-rss server, according to the squid logs, and I'm using update.php --feeds, the output shows all the feeds being processed but doesnt say anything about errors or results, I'm not certain how to figure out where the failure is. I know the proxy is working as I tested it successfully with lynx and firefox.

I understand you do not want to support this so I appreciate the help you've already given.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: Add a proxy Support

Postby fox » 14 Mar 2016, 20:56

you're probably not using curl

update.php has options to debug feed updates, all the information is going to be there

SimbaLion
Bear Rating Trainee
Bear Rating Trainee
Posts: 21
Joined: 07 Jul 2015, 02:04

Re: Add a proxy Support

Postby SimbaLion » 14 Mar 2016, 21:54

I am confused, I thought curl is the only way to update?

Thanks again I will dive into it.


Return to “Development”

Who is online

Users browsing this forum: No registered users and 5 guests