Merge pull request #529 from drzoidberg33/machine-id-fix

Fix bad SSL connections.
This commit is contained in:
drzoidberg33 2016-02-08 02:08:51 +02:00
commit 39884b71fe
7 changed files with 1717 additions and 17 deletions

View file

@ -15,6 +15,7 @@
from operator import itemgetter
from xml.dom import minidom
from IPy import IP
import unicodedata
import plexpy
@ -28,7 +29,7 @@ import os
import json
import xmltodict
import math
import socket
def multikeysort(items, columns):
comparers = [((itemgetter(col[1:].strip()), -1) if col.startswith('-') else (itemgetter(col.strip()), 1)) for col in columns]
@ -455,4 +456,27 @@ def sanitize(string):
if string:
return unicode(string).replace('<','&lt;').replace('>','&gt;')
else:
return ''
return ''
def is_ip_public(host):
ip_address = get_ip(host)
ip = IP(ip_address)
if ip.iptype() == 'PUBLIC':
return True
return False
def get_ip(host):
from plexpy import logger
ip_address = ''
try:
socket.inet_aton(host)
ip_address = host
except socket.error:
try:
ip_address = socket.gethostbyname(host)
logger.debug(u"IP Checker :: Resolved %s to %s." % (host, ip_address))
except:
logger.error(u"IP Checker :: Bad IP or hostname provided.")
return ip_address

View file

@ -86,7 +86,7 @@ def get_real_pms_url():
plexpy.CONFIG.__setattr__('PMS_URL', item['uri'])
plexpy.CONFIG.write()
logger.info(u"PlexPy PlexTV :: Server URL retrieved.")
if not plexpy.CONFIG.PMS_IS_REMOTE and item['local'] == '1':
if not plexpy.CONFIG.PMS_IS_REMOTE and item['local'] == '1' and 'plex.direct' in item['uri']:
plexpy.CONFIG.__setattr__('PMS_URL', item['uri'])
plexpy.CONFIG.write()
logger.info(u"PlexPy PlexTV :: Server URL retrieved.")
@ -493,6 +493,16 @@ class PlexTV(object):
connections = d.getElementsByTagName('Connection')
for c in connections:
# If this is a remote server don't show any local IPs.
if helpers.get_xml_attr(d, 'publicAddressMatches') == '0' and \
helpers.get_xml_attr(c, 'local') == '1':
continue
# If this is a local server don't show any remote IPs.
if helpers.get_xml_attr(d, 'publicAddressMatches') == '1' and \
helpers.get_xml_attr(c, 'local') == '0':
continue
server = {'httpsRequired': helpers.get_xml_attr(d, 'httpsRequired'),
'clientIdentifier': helpers.get_xml_attr(d, 'clientIdentifier'),
'label': helpers.get_xml_attr(d, 'name'),

View file

@ -37,10 +37,13 @@ def start_thread():
def run():
from websocket import create_connection
uri = 'ws://%s:%s/:/websockets/notifications' % (
plexpy.CONFIG.PMS_IP,
plexpy.CONFIG.PMS_PORT
)
if plexpy.CONFIG.PMS_SSL and plexpy.CONFIG.PMS_URL[:5] == 'https':
uri = plexpy.CONFIG.PMS_URL.replace('https://', 'wss://') + '/:/websockets/notifications'
else:
uri = 'ws://%s:%s/:/websockets/notifications' % (
plexpy.CONFIG.PMS_IP,
plexpy.CONFIG.PMS_PORT
)
# Set authentication token (if one is available)
if plexpy.CONFIG.PMS_TOKEN:

View file

@ -14,7 +14,7 @@
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
from plexpy import logger, notifiers, plextv, pmsconnect, common, log_reader, datafactory, graphs, users, libraries
from plexpy.helpers import checked, radio
from plexpy.helpers import checked, radio, get_ip
from mako.lookup import TemplateLookup
from mako import exceptions
@ -1187,6 +1187,16 @@ class WebInterface(object):
(kwargs['monitor_remote_access'] != plexpy.CONFIG.MONITOR_REMOTE_ACCESS):
reschedule = True
# If we change the SSL setting for PMS, make sure we grab the new url.
if 'pms_ssl' in kwargs and \
(kwargs['pms_ssl'] != plexpy.CONFIG.PMS_SSL):
server_changed = True
# If we change the PMS remote setting, make sure we grab the new url.
if 'pms_is_remote' in kwargs and \
(kwargs['pms_is_remote'] != plexpy.CONFIG.PMS_IS_REMOTE):
server_changed = True
# Remove config with 'hscard-' prefix and change home_stats_cards to list
if 'home_stats_cards' in kwargs:
for k in kwargs.keys():
@ -1402,9 +1412,10 @@ class WebInterface(object):
if not identifier and hostname and port:
plex_tv = plextv.PlexTV()
servers = plex_tv.discover()
ip_address = get_ip(hostname)
for server in servers:
if server['ip'] == hostname and server['port'] == port:
if (server['ip'] == hostname or server['ip'] == ip_address) and server['port'] == port:
identifier = server['clientIdentifier']
break