Fix WebUI connecting to localhost

This commit is contained in:
Andrew Resch 2008-12-11 06:18:48 +00:00
parent 66476d7ea0
commit baa7cc7a41
1 changed files with 29 additions and 3 deletions

View File

@ -158,12 +158,36 @@ def get_newforms_data(form_class):
#/utils #/utils
#daemon: #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): def daemon_test_online_status(uri):
"""Tests the status of URI.. Returns True or False depending on status. """Tests the status of URI.. Returns True or False depending on status.
""" """
online = True online = True
host = None host = None
try: try:
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 = xmlrpclib.ServerProxy(uri)
host.ping() host.ping()
except socket.error: except socket.error:
@ -185,6 +209,10 @@ def daemon_connect(uri):
config['daemon'] = uri config['daemon'] = uri
config.save() 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) sclient.set_core_uri(uri)
webui_plugin_manager.start() webui_plugin_manager.start()
@ -277,5 +305,3 @@ def guess_mime_type(path):
return extensions_map[ext] return extensions_map[ext]
else: else:
return 'application/octet-stream' return 'application/octet-stream'