]> git.wh0rd.org Git - tt-rss.git/commitdiff
Add proper support for proxies
authormartin scharm <git-dev@binfalse.de>
Sat, 13 Jan 2018 23:30:22 +0000 (00:30 +0100)
committermartin scharm <git-dev@binfalse.de>
Sat, 13 Jan 2018 23:30:22 +0000 (00:30 +0100)
There are situations where you want tt-rss to use a proxy (e.g.
because of network restrictions, or privacy concerns).
tt-rss already comes with an undocumented `_CURL_HTTP_PROXY`
variable (see eg https://binfalse.de/2015/05/06/ttrss-with-proxy/),
however that won't have an effect when, for example, php-curl is
not installed, see
https://git.tt-rss.org/git/tt-rss/src/c30f5e18119d1935e8fe6d422053b127e8f4f1b3/include/functions.php#L377
In this case it would use the `file_get_contents` with a stream
context without a proxy definition:
https://git.tt-rss.org/git/tt-rss/src/c30f5e18119d1935e8fe6d422053b127e8f4f1b3/include/functions.php#L487

Here I propose to properly support proxies, and I introduced a
`PROXY` variable, that is respected in both scenarios, with and
without curl installed.

config.php-dist
include/functions.php

index 7a076d97693c3b8d125b42536b61d335ffe90bf5..f9cc181af4287d5ad9cc642b626c61cc1a5b164f 100644 (file)
        // Expected config version. Please update this option in config.php
        // if necessary (after migrating all new options from this file).
 
+       define('PROXY', '');
+       // Connect to RSS feeds through a PROXY, this way tt-rss won't connect to
+       // webservers directly.
+       // Example format: '127.0.0.1:8123' (polipo proxy running on localhost)
+
        // vim:ft=php
index 649b77881024b42eedb3eaa17fbb74cb75cdb4a9..f58a2fc6865c8b4d0cf24c9cafda539f80b09eb8 100644 (file)
                                curl_setopt($ch, CURLOPT_COOKIEJAR, "/dev/null");
                        }
 
-                       if (defined('_CURL_HTTP_PROXY')) {
-                               curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);
+                       if (defined('PROXY')) {
+                               curl_setopt($ch, CURLOPT_PROXY, PROXY);
                        }
 
                        if ($post_query) {
 
                        // TODO: should this support POST requests or not? idk
 
+                        $context_options = array(
+                                 'http' => array(
+                                               'method' => 'GET',
+                                           'ignore_errors' => true,
+                                           'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
+                                               'protocol_version'=> 1.1)
+                                 );
+
                        if (!$post_query && $last_modified) {
-                                $context = stream_context_create(array(
-                                         'http' => array(
-                                                       'method' => 'GET',
-                                                   'ignore_errors' => true,
-                                                   'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
-                                                       'protocol_version'=> 1.1,
-                                                       'header' => "If-Modified-Since: $last_modified\r\n")
-                                         ));
-                       } else {
-                                $context = stream_context_create(array(
-                                         'http' => array(
-                                                       'method' => 'GET',
-                                                   'ignore_errors' => true,
-                                                   'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
-                                                       'protocol_version'=> 1.1
-                                         )));
+                $context_options['http']['header'] = "If-Modified-Since: $last_modified\r\n";
                        }
 
+                       if (defined('PROXY')) {
+                               $context_options['http']['proxy'] = PROXY;
+                       }
+
+            $context = stream_context_create($context_options);
+
                        $old_error = error_get_last();
 
                        $data = @file_get_contents($url, false, $context);