wallabag icon indicating copy to clipboard operation
wallabag copied to clipboard

fetching articles via HTTP(S) proxy

Open m0 opened this issue 8 years ago • 9 comments

Wallabag should be able to fetch articles through an outbound HTTP(S) proxy as it's a common security measure to only allow systems to connect to the "outside internet" via proxy.

There should be some config option to set a HTTP and HTTPS proxy that, when set, is used for all outgoing HTTP and HTTPS connects by wallabag.

Note:

This request was already adressed by other issues that were closed (https://github.com/wallabag/wallabag/issues/794 and https://github.com/wallabag/wallabag/issues/698), but the reasoning for closing them seems to be outdated and / or implementation details changed in the meantime as @j0k3r pointed out in https://github.com/wallabag/wallabag/issues/794#issuecomment-309276006.

m0 avatar Jul 10 '17 22:07 m0

+1

solotimes avatar Nov 13 '17 08:11 solotimes

It could be resolved by #3390, the proxy configuration could be set in the httplug section of app/config/config.yml

aaa2000 avatar Nov 13 '17 10:11 aaa2000

@aaa2000 do you have a sample of the config?

kstevenard avatar Jan 16 '18 22:01 kstevenard

@kstevenard #3390 is not yet merged, there is still work before.

The config will be like that https://github.com/hwi/HWIOAuthBundle/blob/master/Resources/doc/internals/configuring_the_http_client.md#configure-with-httplugbundle

aaa2000 avatar Jan 18 '18 20:01 aaa2000

Sorry to ask a dumb question but where would the actual proxy bit go? After stepping through the patches from #3390 I see an httplug config added to config.yml but am unsure how to bring in the information from @aaa2000 above? Thanks for any thoughts / pointers

httplug: clients: wallabag_core: factory: 'wallabag_core.http_client_factory' config: defaults: timeout: 10 proxy: "10.0.0.1:8080" <-- should it be something like this? plugins: ['httplug.plugin.logger'] wallabag_core.entry.download_images: factory: 'httplug.factory.auto' plugins: ['httplug.plugin.logger'] wallabag_import.pocket.client: factory: 'httplug.factory.auto' plugins: - 'httplug.plugin.logger' - header_defaults: headers: 'content-type': 'application/json' 'X-Accept': 'application/json' discovery: client: false

kour1er avatar Jun 17 '18 19:06 kour1er

Would be great to add socks5 proxing as well. It's especially valuable for countries with lots of blocked sites. The only workaround for such cases now is wallabagger, but it doesn't upload images unfortunately :( And works only on browsers. Clearly backend proxy option would be far more useful.

GEkuL avatar Jul 13 '22 13:07 GEkuL

I dive into soruce code and found some way to add proxy, just need add 2 line in source code

1. get into docker container shell

docker exec -it <your_wallabag_container_name> bash

2. change fetch article proxy

vi /var/www/wallabag/vendor/php-http/guzzle5-adapter/src/Client.php jump to line 71, change like this:

 $options = [
            'exceptions' => false,
            'allow_redirects' => false,
            'proxy' => ['https' => 'http://192.168.xx.xx:7890'] //yourself proxy address
        ];

3. change fetch image proxy

vi /var/www/wallabag/vendor/symfony/http-client/HttplugClient.php jump to line 264, similarly change like the following:

return $this->client->request($request->getMethod(), (string) $request->getUri(), [
                'headers' => $request->getHeaders(),
                'body' => $body->getContents(),
                'http_version' => '1.0' === $request->getProtocolVersion() ? '1.0' : null,
                'buffer' => $buffer,
                'proxy' => 'http://192.168.xxx.xx:7890' //yourself proxy address
            ]);

and then, it's works fine

4. make modify permant

upon change it's a temporary modify, if container be recreated and everything is be restore; so may be you need to rebuild the image. or simply like this:

# save container to image
docker commit -m  ""   -a  ""   <wallabag_container_name> wallabag_with_proxy:1.0

then use the new image

5. Finally

Finally, I think wallabag support environment HTTPS_PROXY still is the best way

firer1946 avatar Jul 15 '22 07:07 firer1946

Adding to the above, if one wishes to use a SOCKS v5 proxy, the URL scheme is like so, socks5h://localhost:2080.

aniqueta avatar Mar 27 '23 04:03 aniqueta

for future visitor

fetching articles via HTTP(S) proxy confirmed work on wallabag:2.6.1 with custom app/config/config.yml

add this yml under httplug.clients.wallabag_core.config.defaults

proxy:
    http: "http://<ip>:<port>"
    https: "http://<ip>:<port>"

detailed config can be found on docs.guzzlephp.org/en/stable/request-options.html?#proxy

before

...
httplug:
    clients:
        wallabag_core:
            factory: Wallabag\CoreBundle\Helper\HttpClientFactory
            config:
                defaults:
                    timeout: 10
            plugins: ["httplug.plugin.logger"]
        ...
    discovery:
        client: false
...

after

...
httplug:
    clients:
        wallabag_core:
            factory: Wallabag\CoreBundle\Helper\HttpClientFactory
            config:
                defaults:
                    timeout: 10
                    proxy:
                        http: "http://<ip>:<port>"
                        https: "http://<ip>:<port>"
            plugins: ["httplug.plugin.logger"]
        ...
    discovery:
        client: false
...

Thanks @aaa2000 for the help

AndryYosua avatar Aug 14 '23 23:08 AndryYosua