From 8bdbf8df2e60faf1bdbe398b2aa1d45772fe4115 Mon Sep 17 00:00:00 2001 From: Dean Gardiner Date: Tue, 11 Mar 2014 00:29:56 +1300 Subject: [PATCH 1/3] Updated rtorrent-python library - Fixed bug with basic auth on secure connections - Added 'test_connection' method to RTorrent class - Minor adjustment to authorization encoding --- libs/rtorrent/__init__.py | 7 +++-- libs/rtorrent/lib/xmlrpc/basic_auth.py | 38 ++++++++++++++++++++------ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/libs/rtorrent/__init__.py b/libs/rtorrent/__init__.py index d70e6e10..a3f16078 100755 --- a/libs/rtorrent/__init__.py +++ b/libs/rtorrent/__init__.py @@ -89,13 +89,16 @@ class RTorrent: def _get_conn(self): """Get ServerProxy instance""" - if self.username is not None and self.password is not None: + + if self.username and self.password: if self.scheme == 'scgi': raise NotImplementedError() + secure = self.scheme == 'https' + return self.sp( self.uri, - transport=BasicAuthTransport(self.username, self.password), + transport=BasicAuthTransport(secure, self.username, self.password), **self.sp_kwargs ) diff --git a/libs/rtorrent/lib/xmlrpc/basic_auth.py b/libs/rtorrent/lib/xmlrpc/basic_auth.py index 20c02d9a..c5654a21 100644 --- a/libs/rtorrent/lib/xmlrpc/basic_auth.py +++ b/libs/rtorrent/lib/xmlrpc/basic_auth.py @@ -20,24 +20,46 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -from base64 import encodestring -import string +from base64 import b64encode +import httplib import xmlrpclib class BasicAuthTransport(xmlrpclib.Transport): - def __init__(self, username=None, password=None): + def __init__(self, secure=False, username=None, password=None): xmlrpclib.Transport.__init__(self) + self.secure = secure + self.username = username self.password = password def send_auth(self, h): - if self.username is not None and self.password is not None: - h.putheader('AUTHORIZATION', "Basic %s" % string.replace( - encodestring("%s:%s" % (self.username, self.password)), - "\012", "" - )) + if not self.username or not self.password: + return + + auth = b64encode("%s:%s" % (self.username, self.password)) + + h.putheader('Authorization', "Basic %s" % auth) + + def make_connection(self, host): + if self._connection and host == self._connection[0]: + return self._connection[1] + + chost, self._extra_headers, x509 = self.get_host_info(host) + + if self.secure: + try: + self._connection = host, httplib.HTTPSConnection(chost, None, **(x509 or {})) + except AttributeError: + raise NotImplementedError( + "your version of httplib doesn't support HTTPS" + ) + else: + self._connection = host, httplib.HTTPConnection(chost) + + return self._connection[1] + def single_request(self, host, handler, request_body, verbose=0): # issue XML-RPC request From 28062eacb66eed52c2697f685170f4e963f0bdf4 Mon Sep 17 00:00:00 2001 From: Dean Gardiner Date: Tue, 11 Mar 2014 15:13:49 +1300 Subject: [PATCH 2/3] [rtorrent] cleaned up connection, '+https' is now added to 'httprpc' protocol if SSL option is enabled --- couchpotato/core/downloaders/rtorrent_.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/couchpotato/core/downloaders/rtorrent_.py b/couchpotato/core/downloaders/rtorrent_.py index fb8948c6..d5dbf7d8 100644 --- a/couchpotato/core/downloaders/rtorrent_.py +++ b/couchpotato/core/downloaders/rtorrent_.py @@ -59,20 +59,24 @@ class rTorrent(Downloader): return self.rt url = cleanHost(self.conf('host'), protocol = True, ssl = self.conf('ssl')) + + # Automatically add '+https' to 'httprpc' protocol if SSL is enabled + if self.conf('ssl') and url.startswith('httprpc://'): + url = url.replace('httprpc://', 'httprpc+https://') + parsed = urlparse(url) # rpc_url is only used on http/https scgi pass-through if parsed.scheme in ['http', 'https']: url += self.conf('rpc_url') - if self.conf('username') and self.conf('password'): - self.rt = RTorrent( - url, - self.conf('username'), - self.conf('password') - ) - else: - self.rt = RTorrent(url) + print url + + self.rt = RTorrent( + url, + self.conf('username'), + self.conf('password') + ) self.error_msg = '' try: From 61f1fdabd131a9c89bae2aec6cfa3c312ed16f63 Mon Sep 17 00:00:00 2001 From: Dean Gardiner Date: Sat, 22 Mar 2014 02:46:05 +1300 Subject: [PATCH 3/3] Removed print statement from rtorrent downloader --- couchpotato/core/downloaders/rtorrent_.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/couchpotato/core/downloaders/rtorrent_.py b/couchpotato/core/downloaders/rtorrent_.py index d5dbf7d8..6e5c4b62 100644 --- a/couchpotato/core/downloaders/rtorrent_.py +++ b/couchpotato/core/downloaders/rtorrent_.py @@ -70,8 +70,6 @@ class rTorrent(Downloader): if parsed.scheme in ['http', 'https']: url += self.conf('rpc_url') - print url - self.rt = RTorrent( url, self.conf('username'),