Merge pull request #1121 from croneter/fix-connection
Improve PKC automatically connecting to local PMS
This commit is contained in:
commit
a2197eb8a6
2 changed files with 48 additions and 40 deletions
|
@ -241,20 +241,18 @@ class InitialSetup(object):
|
||||||
"""
|
"""
|
||||||
Checks for server's connectivity. Returns check_connection result
|
Checks for server's connectivity. Returns check_connection result
|
||||||
"""
|
"""
|
||||||
# Re-direct via plex if remote - will lead to the correct SSL
|
|
||||||
# certificate
|
|
||||||
if server['local']:
|
if server['local']:
|
||||||
url = ('%s://%s:%s'
|
|
||||||
% (server['scheme'], server['ip'], server['port']))
|
|
||||||
# Deactive SSL verification if the server is local for Kodi 17
|
# Deactive SSL verification if the server is local for Kodi 17
|
||||||
verifySSL = True if v.KODIVERSION >= 18 else False
|
verifySSL = True if v.KODIVERSION >= 18 else False
|
||||||
else:
|
else:
|
||||||
url = server['baseURL']
|
|
||||||
verifySSL = True
|
verifySSL = True
|
||||||
chk = PF.check_connection(url,
|
if not server['token']:
|
||||||
|
# Plex GDM: we only get the token from plex.tv after
|
||||||
|
# Sign-in to plex.tv
|
||||||
|
server['token'] = utils.settings('plexToken') or None
|
||||||
|
return PF.check_connection(server['baseURL'],
|
||||||
token=server['token'],
|
token=server['token'],
|
||||||
verifySSL=verifySSL)
|
verifySSL=verifySSL)
|
||||||
return chk
|
|
||||||
|
|
||||||
def pick_pms(self, showDialog=False, inform_of_search=False):
|
def pick_pms(self, showDialog=False, inform_of_search=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -210,22 +210,29 @@ def discover_pms(token=None):
|
||||||
if pms['machineIdentifier'] == plex_pms['machineIdentifier']:
|
if pms['machineIdentifier'] == plex_pms['machineIdentifier']:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# Only found PMS using GDM - add it to the PMS from plex.tv
|
# Only found PMS using GDM. Check whether we can use baseURL
|
||||||
https = _pms_https_enabled('%s:%s' % (pms['ip'], pms['port']))
|
# (which is in a different format) or need to connect directly
|
||||||
if https is None:
|
if not _correct_baseurl(pms,
|
||||||
# Error contacting url. Skip and ignore this PMS for now
|
'%s:%s' % (pms['baseURL'], pms['port'])):
|
||||||
LOG.error('Could not contact PMS %s but we should have', pms)
|
if not _correct_baseurl(pms,
|
||||||
|
'%s:%s' % (pms['ip'], pms['port'])):
|
||||||
continue
|
continue
|
||||||
|
plex_pms_list.append(pms)
|
||||||
|
_log_pms(plex_pms_list)
|
||||||
|
return plex_pms_list
|
||||||
|
|
||||||
|
|
||||||
|
def _correct_baseurl(pms, url):
|
||||||
|
https = _pms_https_enabled(url)
|
||||||
|
if https is None:
|
||||||
|
# Error contacting url
|
||||||
|
return False
|
||||||
elif https is True:
|
elif https is True:
|
||||||
pms['scheme'] = 'https'
|
pms['scheme'] = 'https'
|
||||||
else:
|
else:
|
||||||
pms['scheme'] = 'http'
|
pms['scheme'] = 'http'
|
||||||
pms['baseURL'] = '%s://%s:%s' % (pms['scheme'],
|
pms['baseURL'] = '%s://%s' % (pms['scheme'], url)
|
||||||
pms['ip'],
|
return True
|
||||||
pms['port'])
|
|
||||||
plex_pms_list.append(pms)
|
|
||||||
_log_pms(plex_pms_list)
|
|
||||||
return plex_pms_list
|
|
||||||
|
|
||||||
|
|
||||||
def _log_pms(pms_list):
|
def _log_pms(pms_list):
|
||||||
|
@ -846,28 +853,31 @@ def _pms_https_enabled(url):
|
||||||
|
|
||||||
Prefers HTTPS over HTTP
|
Prefers HTTPS over HTTP
|
||||||
"""
|
"""
|
||||||
res = DU().downloadUrl('https://%s/identity' % url,
|
# Try HTTPS first
|
||||||
authenticate=False,
|
|
||||||
verifySSL=True if v.KODIVERSION >= 18 else False)
|
|
||||||
try:
|
try:
|
||||||
res.attrib
|
DU().downloadUrl('https://%s/identity' % url,
|
||||||
except AttributeError:
|
|
||||||
# Might have SSL deactivated. Try with http
|
|
||||||
res = DU().downloadUrl('http://%s/identity' % url,
|
|
||||||
authenticate=False,
|
authenticate=False,
|
||||||
verifySSL=True if v.KODIVERSION >= 18 else False)
|
reraise=True)
|
||||||
try:
|
except exceptions.SSLError:
|
||||||
res.attrib
|
LOG.debug('SSLError trying to connect to https://%s/identity', url)
|
||||||
except AttributeError:
|
except Exception as e:
|
||||||
LOG.error("Could not contact PMS %s", url)
|
LOG.info('Couldnt check https connection to https://%s/identity: %s',
|
||||||
return None
|
url, e)
|
||||||
else:
|
else:
|
||||||
# Received a valid XML. Server wants to talk HTTP
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
# Received a valid XML. Server wants to talk HTTPS
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# Try HTTP next
|
||||||
|
try:
|
||||||
|
DU().downloadUrl('http://%s/identity' % url,
|
||||||
|
authenticate=False,
|
||||||
|
reraise=True)
|
||||||
|
except Exception as e:
|
||||||
|
LOG.info('Couldnt check http connection to http://%s/identity: %s',
|
||||||
|
url, e)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def GetMachineIdentifier(url):
|
def GetMachineIdentifier(url):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue