mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Allows us to retrieve the serverId again if we have secure connections required.
This commit is contained in:
parent
a4dfc57cbe
commit
98c1063e07
3 changed files with 1706 additions and 18 deletions
1652
lib/IPy.py
Normal file
1652
lib/IPy.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
|
from IPy import IP
|
||||||
|
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import plexpy
|
import plexpy
|
||||||
|
@ -28,7 +29,7 @@ import os
|
||||||
import json
|
import json
|
||||||
import xmltodict
|
import xmltodict
|
||||||
import math
|
import math
|
||||||
|
import socket
|
||||||
|
|
||||||
def multikeysort(items, columns):
|
def multikeysort(items, columns):
|
||||||
comparers = [((itemgetter(col[1:].strip()), -1) if col.startswith('-') else (itemgetter(col.strip()), 1)) for col in 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:
|
if string:
|
||||||
return unicode(string).replace('<','<').replace('>','>')
|
return unicode(string).replace('<','<').replace('>','>')
|
||||||
else:
|
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
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
# 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 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.lookup import TemplateLookup
|
||||||
from mako import exceptions
|
from mako import exceptions
|
||||||
|
@ -1402,22 +1402,34 @@ class WebInterface(object):
|
||||||
def get_server_id(self, hostname=None, port=None, identifier=None, ssl=0, remote=0, **kwargs):
|
def get_server_id(self, hostname=None, port=None, identifier=None, ssl=0, remote=0, **kwargs):
|
||||||
from plexpy import http_handler
|
from plexpy import http_handler
|
||||||
|
|
||||||
# Grab our serverId.
|
# Attempt to get the pms_identifier from plex.tv if the server is published
|
||||||
# This endpoint always works over plain HTTP even when secure connections on PMS is set to required.
|
# Works for all PMS SSL settings
|
||||||
if not identifier and hostname and port:
|
if not identifier and hostname and port:
|
||||||
request_handler = http_handler.HTTPHandler(host=hostname,
|
plex_tv = plextv.PlexTV()
|
||||||
port=port,
|
servers = plex_tv.discover()
|
||||||
token=None)
|
ip_address = get_ip(hostname)
|
||||||
uri = '/identity'
|
|
||||||
request = request_handler.make_request(uri=uri,
|
for server in servers:
|
||||||
proto='http',
|
if (server['ip'] == hostname or server['ip'] == ip_address) and server['port'] == port:
|
||||||
request_type='GET',
|
identifier = server['clientIdentifier']
|
||||||
output_format='xml',
|
break
|
||||||
no_token=True,
|
|
||||||
timeout=10)
|
# Fallback to checking /identity endpoint is server is unpublished
|
||||||
if request:
|
# Cannot set SSL settings on the PMS if unpublished so 'http' is okay
|
||||||
xml_head = request.getElementsByTagName('MediaContainer')[0]
|
if not identifier:
|
||||||
identifier = xml_head.getAttribute('machineIdentifier')
|
request_handler = http_handler.HTTPHandler(host=hostname,
|
||||||
|
port=port,
|
||||||
|
token=None)
|
||||||
|
uri = '/identity'
|
||||||
|
request = request_handler.make_request(uri=uri,
|
||||||
|
proto='http',
|
||||||
|
request_type='GET',
|
||||||
|
output_format='xml',
|
||||||
|
no_token=True,
|
||||||
|
timeout=10)
|
||||||
|
if request:
|
||||||
|
xml_head = request.getElementsByTagName('MediaContainer')[0]
|
||||||
|
identifier = xml_head.getAttribute('machineIdentifier')
|
||||||
|
|
||||||
if identifier:
|
if identifier:
|
||||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue