From a678ccb5df37ba4678848df5372899d18a49b975 Mon Sep 17 00:00:00 2001 From: Rainer Hihn Date: Tue, 23 Oct 2012 15:17:02 +0200 Subject: [PATCH 01/16] added parameter 'proxy_type' --- wikisync/plugin.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wikisync/plugin.py b/wikisync/plugin.py index f1483be..c435743 100644 --- a/wikisync/plugin.py +++ b/wikisync/plugin.py @@ -173,6 +173,7 @@ def render_admin_panel(self, req, cat, page, path_info): username = req.args.get("username", "") password = req.args.get("password", "") proxy = req.args.get("proxy", "") + proxy_type = req.args.get("proxy_type", "") if password == password_stud: password = self._get_config("password") ignorelist = req.args.get("ignorelist", "") @@ -185,7 +186,7 @@ def render_admin_panel(self, req, cat, page, path_info): if server_info_changed and url: # remote server info has changed, test connection try: - wc = WebClient(url, username, password, proxy, True) + wc = WebClient(url, username, password, proxy, proxy_type, True) wc.test() except Exception, e: if hasattr(e, "code") and e.code == 401: @@ -201,6 +202,7 @@ def render_admin_panel(self, req, cat, page, path_info): self._set_config("password", password) self._set_config("ignorelist", ignorelist) self._set_config("proxy", proxy) + self._set_config("proxy_type", proxy_type) self._save_config(req) if not url: add_warning(req, "Remote server not set, " @@ -217,6 +219,7 @@ def render_admin_panel(self, req, cat, page, path_info): "url": self._get_config("url", ""), "username": self._get_config("username", ""), "proxy": self._get_config("proxy", ""), + "proxy_type": self._get_config("proxy_type", ""), "password": password, "ignorelist": self._get_config("ignorelist", ""), } @@ -458,10 +461,11 @@ def _get_web_client(self): username = self._get_config("username") password = self._get_config("password") proxy = self._get_config("proxy") + proxy_type = self._get_config("proxy_type") if password: try: password = str_unmask(password) except ValueError: # assume its in clear text pass - return WebClient(baseurl, username, password, proxy, debug=False) + return WebClient(baseurl, username, password, proxy, proxy_type, debug=False) From 4ef4f2a686da7ae24be71c844cdb99932cdfda98 Mon Sep 17 00:00:00 2001 From: rain0r Date: Tue, 23 Oct 2012 15:18:10 +0200 Subject: [PATCH 02/16] added select-field 'proxy_type' and some js to enable/disabled fields --- wikisync/templates/wikisync_admin.html | 63 ++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/wikisync/templates/wikisync_admin.html b/wikisync/templates/wikisync_admin.html index 19af22f..e149e6a 100644 --- a/wikisync/templates/wikisync_admin.html +++ b/wikisync/templates/wikisync_admin.html @@ -19,10 +19,6 @@

Wiki Synchronization

-
-
- -

: @@ -35,6 +31,24 @@

Wiki Synchronization

+
+ Proxy +
+
+

+ +

+ + +

+

+

+
+
Advance Options
@@ -54,6 +68,47 @@

Wiki Synchronization

+ + From 74f3735b764d44e467714636b0f71d9719f41f37 Mon Sep 17 00:00:00 2001 From: rain0r Date: Tue, 23 Oct 2012 15:18:33 +0200 Subject: [PATCH 03/16] added functionality for http proxies --- wikisync/util.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/wikisync/util.py b/wikisync/util.py index 69fd78a..fdfc7cc 100644 --- a/wikisync/util.py +++ b/wikisync/util.py @@ -222,7 +222,7 @@ def matches(self, name): class WebClient(object): - def __init__(self, baseurl, username=None, password=None, proxy=None, debug=False): + def __init__(self, baseurl, username=None, password=None, proxy=None, proxy_type=None, debug=False): assert isinstance(baseurl, basestring) and len(baseurl), \ "'baseurl' expects string, got '%s'" % baseurl if baseurl.endswith("/"): @@ -235,6 +235,7 @@ def __init__(self, baseurl, username=None, password=None, proxy=None, debug=Fals self._opener = None self._authenticated = False self.proxy = proxy or None + self.proxy_type = proxy_type or None def open(self, path, data=None, method="GET"): self.authenticate() @@ -271,16 +272,21 @@ def opener(self, no_cache=False): if self.debug: handlers.append(urllib2.HTTPHandler(debuglevel=1)) if self.proxy is not None: - import socks - import socket - split = self.proxy.split(":") - port = split.pop() - hostname = split[1].split("//")[1] - # port = 9050 - # hostname = '127.0.0.1' - socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, str(hostname), int(port)) - socket.socket = socks.socksocket - # handlers.append(urllib2.ProxyHandler({self.proxy_type or 'http': self.proxy})) + if 'http' in self.proxy: + # assumed format: + # http://mybeautifulproxy.ru:12345 + split = self.proxy.split(":") + port = split.pop() + hostname = str(split[1].split("//")[1]) + if self.proxy_type == 'socks': + import socks + import socket + socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, hostname, int(port)) + socket.socket = socks.socksocket + elif self.proxy_type == 'http': + proxy_handler = urllib2.ProxyHandler( {'https' if 'https' in self.proxy else 'http' : self.proxy} ) + opener = urllib2.build_opener(proxy_handler) + handlers.append(proxy_handler) if has_cookie: cookie_jar.load(ignore_discard=True) opener = urllib2.build_opener(*handlers) From ad4b4081d4cdddc75125344d141665039cd815b5 Mon Sep 17 00:00:00 2001 From: rain0r Date: Tue, 23 Oct 2012 15:54:07 +0200 Subject: [PATCH 04/16] removed merge shit --- wikisync/util.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/wikisync/util.py b/wikisync/util.py index 1a92ff5..372a81b 100644 --- a/wikisync/util.py +++ b/wikisync/util.py @@ -271,7 +271,6 @@ def opener(self, no_cache=False): cookie_processor = urllib2.HTTPCookieProcessor(cookie_jar) if self.debug: handlers.append(urllib2.HTTPHandler(debuglevel=1)) -<<<<<<< HEAD if self.proxy is not None: if 'http' in self.proxy: # assumed format: @@ -288,7 +287,6 @@ def opener(self, no_cache=False): proxy_handler = urllib2.ProxyHandler( {'https' if 'https' in self.proxy else 'http' : self.proxy} ) opener = urllib2.build_opener(proxy_handler) handlers.append(proxy_handler) -======= if self.proxy: import socks import socket @@ -300,7 +298,6 @@ def opener(self, no_cache=False): socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, str(hostname), int(port)) socket.socket = socks.socksocket # handlers.append(urllib2.ProxyHandler({self.proxy_type or 'http': self.proxy})) ->>>>>>> mrsavage/master if has_cookie: cookie_jar.load(ignore_discard=True) opener = urllib2.build_opener(*handlers) From bacaad53e673ffec0b9abbbdcfd165e0f9f90a01 Mon Sep 17 00:00:00 2001 From: rain0r Date: Tue, 23 Oct 2012 16:10:05 +0200 Subject: [PATCH 05/16] fixed a buggy comparison --- wikisync/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wikisync/util.py b/wikisync/util.py index 372a81b..8e987bd 100644 --- a/wikisync/util.py +++ b/wikisync/util.py @@ -271,7 +271,7 @@ def opener(self, no_cache=False): cookie_processor = urllib2.HTTPCookieProcessor(cookie_jar) if self.debug: handlers.append(urllib2.HTTPHandler(debuglevel=1)) - if self.proxy is not None: + if self.proxy: if 'http' in self.proxy: # assumed format: # http://mybeautifulproxy.ru:12345 From 4ec34cf4cbcf6053203de1b1f8ce3d2f59eddd3e Mon Sep 17 00:00:00 2001 From: rain0r Date: Thu, 25 Oct 2012 15:59:55 +0200 Subject: [PATCH 06/16] added username/password fields for proxy-connection --- wikisync/plugin.py | 12 ++++++++++-- wikisync/templates/wikisync_admin.html | 15 +++++++++++++++ wikisync/util.py | 8 +++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/wikisync/plugin.py b/wikisync/plugin.py index c435743..24d67f0 100644 --- a/wikisync/plugin.py +++ b/wikisync/plugin.py @@ -174,6 +174,8 @@ def render_admin_panel(self, req, cat, page, path_info): password = req.args.get("password", "") proxy = req.args.get("proxy", "") proxy_type = req.args.get("proxy_type", "") + proxy_username = req.args.get("proxy_username", "") + proxy_password = req.args.get("proxy_password", "") if password == password_stud: password = self._get_config("password") ignorelist = req.args.get("ignorelist", "") @@ -186,7 +188,7 @@ def render_admin_panel(self, req, cat, page, path_info): if server_info_changed and url: # remote server info has changed, test connection try: - wc = WebClient(url, username, password, proxy, proxy_type, True) + wc = WebClient(url, username, password, proxy, proxy_type, proxy_username, proxy_password, True) wc.test() except Exception, e: if hasattr(e, "code") and e.code == 401: @@ -203,6 +205,8 @@ def render_admin_panel(self, req, cat, page, path_info): self._set_config("ignorelist", ignorelist) self._set_config("proxy", proxy) self._set_config("proxy_type", proxy_type) + self._set_config("proxy_username", proxy_username) + self._set_config("proxy_password", proxy_password) self._save_config(req) if not url: add_warning(req, "Remote server not set, " @@ -220,6 +224,8 @@ def render_admin_panel(self, req, cat, page, path_info): "username": self._get_config("username", ""), "proxy": self._get_config("proxy", ""), "proxy_type": self._get_config("proxy_type", ""), + "proxy_username": self._get_config("proxy_username", ""), + "proxy_password": self._get_config("proxy_password", ""), "password": password, "ignorelist": self._get_config("ignorelist", ""), } @@ -462,10 +468,12 @@ def _get_web_client(self): password = self._get_config("password") proxy = self._get_config("proxy") proxy_type = self._get_config("proxy_type") + proxy_username = self._get_config("proxy_username") + proxy_password = self._get_config("proxy_password") if password: try: password = str_unmask(password) except ValueError: # assume its in clear text pass - return WebClient(baseurl, username, password, proxy, proxy_type, debug=False) + return WebClient(baseurl, username, password, proxy, proxy_type, proxy_username, proxy_password, debug=False) diff --git a/wikisync/templates/wikisync_admin.html b/wikisync/templates/wikisync_admin.html index e149e6a..a0a3f3e 100644 --- a/wikisync/templates/wikisync_admin.html +++ b/wikisync/templates/wikisync_admin.html @@ -47,6 +47,13 @@

Wiki Synchronization

+

+ Proxy-Username:
+ +

+ Proxy-Password:
+ +

@@ -73,11 +80,15 @@

Wiki Synchronization

if ( "${data.proxy}" == "" ) { $("#proxy").attr('disabled', 'disabled'); $("#proxy_type").attr('disabled', 'disabled'); + $("#proxy_username").attr('disabled', 'disabled'); + $("#proxy_password").attr('disabled', 'disabled'); } else { $('#proxy_toggle').attr('checked', true); $("#proxy").removeAttr('disabled'); $("#proxy_type").removeAttr('disabled'); + $("#proxy_username").removeAttr('disabled'); + $("#proxy_password").removeAttr('disabled'); } $("#proxy_toggle").click(function(){ @@ -85,12 +96,16 @@

Wiki Synchronization

// use a proxy $("#proxy").removeAttr('disabled'); $("#proxy_type").removeAttr('disabled'); + $("#proxy_username").removeAttr('disabled'); + $("#proxy_password").removeAttr('disabled'); } else { // use no proxy $("#proxy").attr('disabled', 'disabled'); $("#proxy_type").attr('disabled', 'disabled'); + $("#proxy_username").attr('disabled', 'disabled'); + $("#proxy_password").attr('disabled', 'disabled'); } }) diff --git a/wikisync/util.py b/wikisync/util.py index 8e987bd..7835cd8 100644 --- a/wikisync/util.py +++ b/wikisync/util.py @@ -222,7 +222,7 @@ def matches(self, name): class WebClient(object): - def __init__(self, baseurl, username=None, password=None, proxy=None, proxy_type=None, debug=False): + def __init__(self, baseurl, username=None, password=None, proxy=None, proxy_type=None, proxy_username=None, proxy_password=None, debug=False): assert isinstance(baseurl, basestring) and len(baseurl), \ "'baseurl' expects string, got '%s'" % baseurl if baseurl.endswith("/"): @@ -236,6 +236,8 @@ def __init__(self, baseurl, username=None, password=None, proxy=None, proxy_type self._authenticated = False self.proxy = proxy self.proxy_type = proxy_type + self.proxy_username = proxy_username + self.proxy_password = proxy_password def open(self, path, data=None, method="GET"): self.authenticate() @@ -284,6 +286,10 @@ def opener(self, no_cache=False): socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, hostname, int(port)) socket.socket = socks.socksocket elif self.proxy_type == 'http': + if self.proxy_username and self.proxy_password: + proxy_auth_handler = urllib2.ProxyBasicAuthHandler() + proxy_auth_handler.add_password(None, self.proxy, self.proxy_username, self.proxy_password) + handlers.append(proxy_auth_handler) proxy_handler = urllib2.ProxyHandler( {'https' if 'https' in self.proxy else 'http' : self.proxy} ) opener = urllib2.build_opener(proxy_handler) handlers.append(proxy_handler) From d4fcb5b27717f3aeee114fc3990a180bb1a79f42 Mon Sep 17 00:00:00 2001 From: rain0r Date: Thu, 25 Oct 2012 17:50:37 +0200 Subject: [PATCH 07/16] added auth functionality for proxy connection --- wikisync/plugin.py | 8 ++++++-- wikisync/templates/wikisync_admin.html | 3 ++- wikisync/util.py | 27 ++++++++++---------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/wikisync/plugin.py b/wikisync/plugin.py index 24d67f0..59b4609 100644 --- a/wikisync/plugin.py +++ b/wikisync/plugin.py @@ -176,6 +176,7 @@ def render_admin_panel(self, req, cat, page, path_info): proxy_type = req.args.get("proxy_type", "") proxy_username = req.args.get("proxy_username", "") proxy_password = req.args.get("proxy_password", "") + proxy_port = req.args.get("proxy_port", "") if password == password_stud: password = self._get_config("password") ignorelist = req.args.get("ignorelist", "") @@ -188,7 +189,7 @@ def render_admin_panel(self, req, cat, page, path_info): if server_info_changed and url: # remote server info has changed, test connection try: - wc = WebClient(url, username, password, proxy, proxy_type, proxy_username, proxy_password, True) + wc = WebClient(url, username, password, proxy, proxy_type, proxy_username, proxy_password, proxy_port, True) wc.test() except Exception, e: if hasattr(e, "code") and e.code == 401: @@ -207,6 +208,7 @@ def render_admin_panel(self, req, cat, page, path_info): self._set_config("proxy_type", proxy_type) self._set_config("proxy_username", proxy_username) self._set_config("proxy_password", proxy_password) + self._set_config("proxy_port", proxy_port) self._save_config(req) if not url: add_warning(req, "Remote server not set, " @@ -226,6 +228,7 @@ def render_admin_panel(self, req, cat, page, path_info): "proxy_type": self._get_config("proxy_type", ""), "proxy_username": self._get_config("proxy_username", ""), "proxy_password": self._get_config("proxy_password", ""), + "proxy_port": self._get_config("proxy_port", ""), "password": password, "ignorelist": self._get_config("ignorelist", ""), } @@ -470,10 +473,11 @@ def _get_web_client(self): proxy_type = self._get_config("proxy_type") proxy_username = self._get_config("proxy_username") proxy_password = self._get_config("proxy_password") + proxy_port = self._get_config("proxy_port") if password: try: password = str_unmask(password) except ValueError: # assume its in clear text pass - return WebClient(baseurl, username, password, proxy, proxy_type, proxy_username, proxy_password, debug=False) + return WebClient(baseurl, username, password, proxy, proxy_type, proxy_username, proxy_password, proxy_port, debug=False) diff --git a/wikisync/templates/wikisync_admin.html b/wikisync/templates/wikisync_admin.html index a0a3f3e..6238c05 100644 --- a/wikisync/templates/wikisync_admin.html +++ b/wikisync/templates/wikisync_admin.html @@ -38,7 +38,8 @@

Wiki Synchronization

- + +