Fix WebUI connecting to localhost
This commit is contained in:
parent
66476d7ea0
commit
baa7cc7a41
|
@ -158,12 +158,36 @@ 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:
|
||||
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:
|
||||
|
@ -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'
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue