Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Is it possible to set proxy for specific connection
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
pd1986
Guru
Guru


Joined: 19 Feb 2012
Posts: 382
Location: Paris

PostPosted: Sun Nov 23, 2014 6:00 am    Post subject: Is it possible to set proxy for specific connection Reply with quote

I would like to know if it is possible to set a proxy setting to a specific connection. for exmaple, use proxy for the wifi connection "ABC", but not use the proxy for the another connection "DEF". Thanks.


by the way, to set proxy,
export http_proxy="http://proxy.gentoo.org:8080"
doesn't work for me. Could someone please tell me why? Thanks
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14185

PostPosted: Sun Nov 23, 2014 3:51 pm    Post subject: Reply with quote

Proxy settings are part of an application, so the answer to your question will depend in part on what application you want to use the proxy. You say that setting the proxy via environment variable did not work for you. What did not work? Was the setting not respected? Was the proxy unreachable? How did you test that the proxy would serve your computer at all?
Back to top
View user's profile Send private message
pd1986
Guru
Guru


Joined: 19 Feb 2012
Posts: 382
Location: Paris

PostPosted: Sun Nov 23, 2014 4:05 pm    Post subject: Reply with quote

Hu wrote:
Proxy settings are part of an application, so the answer to your question will depend in part on what application you want to use the proxy. You say that setting the proxy via environment variable did not work for you. What did not work? Was the setting not respected? Was the proxy unreachable? How did you test that the proxy would serve your computer at all?


OK, here is the thing.

I have to go and return between home and work. At the office, only the company computer is recognized. I have to use a proxy (also provided by company. Very interesting. ) to get through the restriction. At home, I need to use another proxy. So that's why I am wondering if there is a way to satisfy my thoughtI could use opera, Firefox their own proxy setting and it works. But I can't use emerge. Setting proxy as environment doesn't work. So, that leads to my question
Back to top
View user's profile Send private message
WWWW
Tux's lil' helper
Tux's lil' helper


Joined: 30 Nov 2014
Posts: 143

PostPosted: Sun Nov 30, 2014 6:46 pm    Post subject: Reply with quote

pd1986 wrote:
Hu wrote:
Proxy settings are part of an application, so the answer to your question will depend in part on what application you want to use the proxy. You say that setting the proxy via environment variable did not work for you. What did not work? Was the setting not respected? Was the proxy unreachable? How did you test that the proxy would serve your computer at all?


OK, here is the thing.

I have to go and return between home and work. At the office, only the company computer is recognized. I have to use a proxy (also provided by company. Very interesting. ) to get through the restriction. At home, I need to use another proxy. So that's why I am wondering if there is a way to satisfy my thoughtI could use opera, Firefox their own proxy setting and it works. But I can't use emerge. Setting proxy as environment doesn't work. So, that leads to my question


emerge's proxy settings are through rsync options in /etc/portage/make.conf. From what I recall a few programs doesn't work via env but with its own options.

Keep in mind that emerge has a plethora of fetching options:

curl
rsync
wget
emerge-webrsync
etc..
Back to top
View user's profile Send private message
fpemud
Apprentice
Apprentice


Joined: 15 Feb 2012
Posts: 281

PostPosted: Wed Sep 09, 2015 4:26 pm    Post subject: Reply with quote

I have the same problem.

My notebook needs to use the company proxy at my office (for every application, browser, emerge, git...), and the proxy must be disabled at home.
My system uses NetworkManager, the office wifi and home wifi have different SSID, so they are different NM connections.

Perhaps it can be done via NetworkManager dispatcher script?
But I also want to dynamically enable/disable proxy for my applications, so that I can get a perfect experience. For example, I open a webpage using firefox at home, put the notebook into sleep, then wake it up at my office, I'd like to continue browsing without restarting firefox.
Back to top
View user's profile Send private message
pietinger
n00b
n00b


Joined: 17 Oct 2006
Posts: 56

PostPosted: Wed Sep 09, 2015 8:34 pm    Post subject: Reply with quote

pd1986 wrote:
I have to go and return between home and work. At the office, only the company computer is recognized. I have to use a proxy (also provided by company. Very interesting. ) to get through the restriction. At home, I need to use another proxy.


What if you install a local proxy like privoxy ? privoxy is able to use forwarding (This feature allows routing of HTTP requests through a chain of multiple proxies). you can set this local proxy in all your applications. with 2 different configs for privoxy you must only restart this local proxy with a new conig specifying the parent proxy.


(sorry for my bad english)
Back to top
View user's profile Send private message
fpemud
Apprentice
Apprentice


Joined: 15 Feb 2012
Posts: 281

PostPosted: Wed Sep 09, 2015 11:46 pm    Post subject: Reply with quote

Quote:
What if you install a local proxy like privoxy ? privoxy is able to use forwarding (This feature allows routing of HTTP requests through a chain of multiple proxies). you can set this local proxy in all your applications. with 2 different configs for privoxy you must only restart this local proxy with a new conig specifying the parent proxy.


It's really annoying to have a so complex solution.
Back to top
View user's profile Send private message
fpemud
Apprentice
Apprentice


Joined: 15 Feb 2012
Posts: 281

PostPosted: Thu Sep 10, 2015 3:52 am    Post subject: Reply with quote

This is what I found on Arch Wiki: https://wiki.archlinux.org/index.php/Proxy_settings#Proxy_settings_on_GNOME3

I wrote my own nm-dispatcher script by refering to proxydriver:
Code:
#!/bin/bash

# The interface which is brought up or down
INTERFACE=$1 

# The new state of the interface
STATUS=$2     

# The connection name
CONNNAME=`/usr/bin/nmcli -t -f name,device connection show | /usr/bin/awk -F':' "\\$2 == \"$1\" { print \\$1 }"`

if [[ $CONNNAME =~ .*(Office) ]] ; then
    if [ "$STATUS" == "up" ] ; then
        proxy="10.153.49.62"
        port=3128
        auth='false'
        login=''
        pass=''

        https_proxy=$proxy
        https_port=$port
        ftp_proxy=$proxy
        ftp_port=$port
        socks_proxy=$proxy
        socks_proxy=$port

        gnome_mode='maual'
        gnome2_ignorelist=''
        gnome3_ignorelist=''

        which /usr/bin/gsettings
        if [ $? == 0 ] ; then
            /usr/bin/gsettings set org.gnome.system.proxy mode "$gnome_mode"

            /usr/bin/gsettings set org.gnome.system.proxy.http host '"$proxy"'
            /usr/bin/gsettings set org.gnome.system.proxy.http port "$port"

            /usr/bin/gsettings set org.gnome.system.proxy.https host '"$https_proxy"'
            /usr/bin/gsettings set org.gnome.system.proxy.https port "$https_port"

            /usr/bin/gsettings set org.gnome.system.proxy.ftp host '"$ftp_proxy"'
            /usr/bin/gsettings set org.gnome.system.proxy.ftp port "$ftp_port"

            # my office doesn't provide socks proxy
            # /usr/bin/gsettings set org.gnome.system.proxy.socks host '"$socks_proxy"'
            # /usr/bin/gsettings set org.gnome.system.proxy.socks port "$socks_port"

            /usr/bin/gsettings set org.gnome.system.proxy.http use-authentication "$auth"
            /usr/bin/gsettings set org.gnome.system.proxy.http authentication-user "$login"
            /usr/bin/gsettings set org.gnome.system.proxy.http authentication-password "$pass"

            /usr/bin/gsettings set org.gnome.system.proxy ignore-hosts "${gnome3_ignorelist}"
        fi

        which /usr/bin/gconftool-2
        if [ $? == 0 ] ; then
            /usr/bin/gconftool-2 --type string --set /system/proxy/mode "$gnome_mode"

            /usr/bin/gconftool-2 --type string --set /system/http_proxy/host "$proxy"
            /usr/bin/gconftool-2 --type int    --set /system/http_proxy/port "$port"

            /usr/bin/gconftool-2 --type string --set /system/proxy/secure_host "$https_proxy"
            /usr/bin/gconftool-2 --type int    --set /system/proxy/secure_port "$https_port"

            /usr/bin/gconftool-2 --type string --set /system/proxy/ftp_host "$ftp_proxy"
            /usr/bin/gconftool-2 --type int    --set /system/proxy/ftp_port "$ftp_port"

            # my office doesn't provide socks proxy
            # /usr/bin/gconftool-2 --type string --set /system/proxy/socks_host "$socks_proxy"
            # /usr/bin/gconftool-2 --type int    --set /system/proxy/socks_port "$socks_port"

            /usr/bin/gconftool-2 --type bool   --set /system/http_proxy/use_authentication "$auth"
            /usr/bin/gconftool-2 --type string --set /system/http_proxy/authentication_user "$login"
            /usr/bin/gconftool-2 --type string --set /system/http_proxy/authentication_password "$pass"

            /usr/bin/gconftool-2 --type list --list-type string --set /system/http_proxy/ignore_hosts "${gnome2_ignorelist}"
        fi
    else
        which /usr/bin/gsettings
        if [ $? == 0 ] ; then
            /usr/bin/gsettings reset-recursively org.gnome.system.proxy
        fi

        which /usr/bin/gconftool-2
        if [ $? == 0 ] ; then
            /usr/bin/gconftool-2 --recursive-unset /system/http_proxy
            /usr/bin/gconftool-2 --recursive-unset /system/proxy
        fi
    fi
fi


#        kde_mode='1'
#        which /usr/bin/kwriteconfig
#        if [ $? == 0 ] ; then
#            /usr/bin/kwriteconfig --file kioslaverc --group 'Proxy Settings' --key ProxyType "$kde_mode"
#
#            /usr/bin/kwriteconfig --file kioslaverc --group 'Proxy Settings' --key httpProxy "http://${proxy}:${port}/"
#
#            /usr/bin/kwriteconfig --file kioslaverc --group 'Proxy Settings' --key httpsProxy "http://${https_proxy}:${https_port}/"
#
#            /usr/bin/kwriteconfig --file kioslaverc --group 'Proxy Settings' --key ftpProxy "ftp://${ftp_proxy}:${ftp_port}/"
#
# my office doesn't provide socks proxy
#           /usr/bin/kwriteconfig --file kioslaverc --group 'Proxy Settings' --key socksProxy "http://${socks_proxy}:${socks_port}/"
#
#            # KDE Prompts 'as needed'
#            /usr/bin/kwriteconfig --file kioslaverc --group 'Proxy Settings' --key Authmode 0
#
#            /usr/bin/kwriteconfig --file kioslaverc --group 'Proxy Settings' --key NoProxyFor "${kde_ignorelist}"
#        fi


I have not extensively tested it yet, but it is definitely far from perfect:
1. only gnome and kde applications can benefit from this script. I highly doubt wget, git is in the range. Project [url=http://code.google.com/p/libproxy/]libproxy] is great, why don't people use it.
2. the proxy setting may not be correctly deleted if networkmanager exit abnormally.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum