From 3bc22371cc58e6e72ac2dc27645c9af5afe9cb0a Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 19 Dec 2007 14:42:04 +0000 Subject: [PATCH] [ruiabreuferreira and I] ability to use http_proxy environment variable. fixes #2977 --- data/glade/accounts_window.glade | 157 ++++++++++++++++++++----------- src/common/config.py | 1 + src/common/connection.py | 33 +++++++ src/config.py | 14 +++ 4 files changed, 151 insertions(+), 54 deletions(-) diff --git a/data/glade/accounts_window.glade b/data/glade/accounts_window.glade index 4915193f9..0a5aa1990 100644 --- a/data/glade/accounts_window.glade +++ b/data/glade/accounts_window.glade @@ -51,6 +51,7 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK gtk-add True + 0 @@ -66,6 +67,7 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK gtk-remove True + 0 @@ -79,6 +81,7 @@ True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 @@ -138,6 +141,7 @@ False + True @@ -152,9 +156,6 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - False - @@ -222,6 +223,7 @@ Click to request authorization to all contacts of another account Synchronise contacts True + 0 @@ -235,6 +237,7 @@ Click to change account's password Chan_ge Password True + 0 @@ -288,6 +291,7 @@ Priority will change automatically according to your status. _Adjust to status True + 0 True @@ -336,6 +340,7 @@ Save pass_word True False + 0 True @@ -394,9 +399,6 @@ - - False - @@ -405,7 +407,6 @@ tab - False False @@ -421,6 +422,7 @@ If checked, Gajim, when launched, will automatically connect to jabber using this account C_onnect on Gajim startup True + 0 True @@ -435,6 +437,7 @@ True Auto-reconnect when connection is lost True + 0 True @@ -450,6 +453,7 @@ True Save conversation _logs for all contacts True + 0 True True @@ -467,6 +471,7 @@ If checked, any change to the global status (handled by the combobox at the bottom of the roster window) will change the status of this account accordingly Synch_ronize account status with global status True + 0 True @@ -483,6 +488,7 @@ If checked, Gajim will also broadcast some more IPs except from just your IP, so file transfer has higher chances of working. Use file transfer proxies True + 0 True @@ -495,7 +501,6 @@ 1 - False @@ -507,7 +512,6 @@ tab 1 - False False @@ -517,48 +521,84 @@ 6 12 - + True - 6 - 6 + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + GTK_SHADOW_NONE + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 12 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 6 + 6 + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + use HTTP_PROXY environment variable + 0 + True + + + + False + + + + + True + 6 + + + True + None + + + + + + True + True + Manage... + True + 0 + + + + False + False + 1 + + + + + False + 1 + + + + + + True - Proxy: + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + <b>Proxy</b> + True - False - False - - - - - True - None - - - - 1 - - - - - True - True - Manage... - True - - - - False - False - 2 + label_item - - False - @@ -581,6 +621,7 @@ Check this so Gajim will connect in port 5223 where legacy servers are expected to have SSL capabilities. Note that Gajim uses TLS encryption by default if broadcasted by the server, and with this option enabled TLS will be disabled Use _SSL (legacy) True + 0 True @@ -596,6 +637,7 @@ If checked, Gajim will send keep-alive packets to prevent connection timeout which results in disconnection Send keep-alive packets True + 0 True True @@ -612,6 +654,7 @@ True Use custom hostname/port True + 0 True @@ -700,7 +743,6 @@ 2 - False @@ -711,7 +753,6 @@ tab 2 - False False @@ -766,6 +807,7 @@ True Choose _Key... True + 0 @@ -787,12 +829,14 @@ If checked, Gajim will get the password from a GPG agent like seahorse Use GPG _Agent True + 0 True False False + 1 @@ -831,6 +875,7 @@ Information about you, as stored in the server Edit Personal Information... True + 0 @@ -855,7 +900,6 @@ 3 - False @@ -866,14 +910,12 @@ tab 3 - False False 1 - False @@ -892,6 +934,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK Enable + 0 True @@ -915,6 +958,7 @@ If checked, Gajim, when launched, will automatically connect to jabber using this account C_onnect on Gajim startup True + 0 True @@ -929,6 +973,7 @@ True Save conversation _logs for all contacts True + 0 True @@ -945,6 +990,7 @@ If checked, any change to the global status (handled by the combobox at the bottom of the roster window) will change the status of this account accordingly Synch_ronize account status with global status True + 0 True @@ -965,6 +1011,7 @@ You might consider to change possible firewall settings. Use custom port: True + 0 True @@ -994,9 +1041,6 @@ You might consider to change possible firewall settings. - - False - @@ -1006,7 +1050,6 @@ You might consider to change possible firewall settings. tab - False False @@ -1181,6 +1224,7 @@ You might consider to change possible firewall settings. True Choose _Key... True + 0 @@ -1201,12 +1245,14 @@ You might consider to change possible firewall settings. If checked, Gajim will get the password from a GPG agent like seahorse Use GPG _Agent True + 0 True False False + 2 @@ -1218,7 +1264,6 @@ You might consider to change possible firewall settings. 1 - False @@ -1229,7 +1274,6 @@ You might consider to change possible firewall settings. tab 1 - False False @@ -1241,7 +1285,6 @@ You might consider to change possible firewall settings. 2 - False @@ -1251,6 +1294,10 @@ You might consider to change possible firewall settings. + + True + True + @@ -1261,6 +1308,7 @@ You might consider to change possible firewall settings. GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK Mer_ge accounts True + 0 True @@ -1293,6 +1341,7 @@ You might consider to change possible firewall settings. GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK gtk-close True + 0 diff --git a/src/common/config.py b/src/common/config.py index 96a73b808..3a137b63e 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -313,6 +313,7 @@ class Config: 'zeroconf_last_name': [ opt_str, '', '', True ], 'zeroconf_jabber_id': [ opt_str, '', '', True ], 'zeroconf_email': [ opt_str, '', '', True ], + 'use_env_http_proxy' : [opt_bool, False], }, {}), 'statusmsg': ({ 'message': [ opt_str, '' ], diff --git a/src/common/connection.py b/src/common/connection.py index 75e851252..a5bad82ff 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -428,6 +428,39 @@ class Connection(ConnectionHandlers): proxy['user'] = gajim.config.get_per('proxies', p, 'user') proxy['password'] = gajim.config.get_per('proxies', p, 'pass') proxy['type'] = gajim.config.get_per('proxies', p, 'type') + elif gajim.config.get_per('accounts', self.name, 'use_env_http_proxy'): + try: + try: + env_http_proxy = os.environ['HTTP_PROXY'] + except: + env_http_proxy = os.environ['http_proxy'] + env_http_proxy = env_http_proxy.strip('"') + # Dispose of the http:// prefix + env_http_proxy = env_http_proxy.split('://') + env_http_proxy = env_http_proxy[len(env_http_proxy)-1] + env_http_proxy = env_http_proxy.split('@') + + if len(env_http_proxy) == 2: + login = env_http_proxy[0].split(':') + addr = env_http_proxy[1].split(':') + else: + login = ['', ''] + addr = env_http_proxy[0].split(':') + + proxy = {'host': addr[0], 'type' : u'http', 'user':login[0]} + + if len(addr) == 2: + proxy['port'] = addr[1] + else: + proxy['port'] = 3128 + + if len(login) == 2: + proxy['password'] = login[1] + else: + proxy['password'] = u'' + + except: + proxy = None else: proxy = None diff --git a/src/config.py b/src/config.py index 58e58b17f..5d5c16206 100644 --- a/src/config.py +++ b/src/config.py @@ -1647,6 +1647,12 @@ class AccountsWindow: 'priority')) # Connection tab + use_env_http_proxy = gajim.config.get_per('accounts', account, + 'use_env_http_proxy') + self.xml.get_widget('use_env_http_proxy_checkbutton1').set_active( + use_env_http_proxy) + self.xml.get_widget('proxy_hbox1').set_sensitive(not use_env_http_proxy) + usessl = gajim.config.get_per('accounts', account, 'usessl') self.xml.get_widget('use_ssl_checkbutton1').set_active(usessl) @@ -1979,6 +1985,14 @@ class AccountsWindow: self.on_checkbutton_toggled(widget, 'use_ft_proxies', account=self.current_account) + def on_use_env_http_proxy_checkbutton1_toggled(self, widget): + if self.ignore_events: + return + self.on_checkbutton_toggled(widget, 'use_env_http_proxy', + account=self.current_account) + hbox = self.xml.get_widget('proxy_hbox1') + hbox.set_sensitive(not widget.get_active()) + def on_proxies_combobox1_changed(self, widget): active = widget.get_active() proxy = widget.get_model()[active][0].decode('utf-8')