diff --git a/deluge/ui/webui/utils.py b/deluge/ui/webui/utils.py index 667701962..7c30041f3 100644 --- a/deluge/ui/webui/utils.py +++ b/deluge/ui/webui/utils.py @@ -158,13 +158,37 @@ def get_newforms_data(form_class): #/utils #daemon: +def get_localhost_auth_uri(uri): + """ + Grabs the localclient auth line from the 'auth' file and creates a localhost uri + + :param uri: the uri to add the authentication info to + :returns: a localhost uri containing authentication information or None if the information is not available + """ + import deluge.configmanager + auth_file = deluge.configmanager.get_config_dir("auth") + if os.path.exists(auth_file): + import urlparse + u = urlparse.urlsplit(uri) + for line in open(auth_file): + username, password = line.split(":") + if username == "localclient": + # We use '127.0.0.1' in place of 'localhost' just incase this isn't defined properly + hostname = u.hostname.replace("localhost", "127.0.0.1") + return u.scheme + "://" + username + ":" + password + "@" + hostname + ":" + str(u.port) + return None def daemon_test_online_status(uri): """Tests the status of URI.. Returns True or False depending on status. """ online = True host = None try: - host = xmlrpclib.ServerProxy(uri) + import urlparse + u = urlparse.urlsplit(uri) + if u.hostname == "localhost" or u.hostname == "127.0.0.1": + host = xmlrpclib.ServerProxy(get_localhost_auth_uri(uri)) + else: + host = xmlrpclib.ServerProxy(uri) host.ping() except socket.error: online = False @@ -185,6 +209,10 @@ def daemon_connect(uri): config['daemon'] = uri config.save() + import urlparse + u = urlparse.urlsplit(uri) + if u.hostname == "localhost" or u.hostname == "127.0.0.1": + uri = get_localhost_auth_uri(uri) sclient.set_core_uri(uri) webui_plugin_manager.start() @@ -277,5 +305,3 @@ def guess_mime_type(path): return extensions_map[ext] else: return 'application/octet-stream' - -