mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 07:22:37 -07:00
Fix server verification for unpublished servers
This commit is contained in:
parent
1ff1270bfa
commit
c17bf79d79
4 changed files with 45 additions and 37 deletions
|
@ -1569,11 +1569,11 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
function verifyServer(_callback) {
|
function verifyServer(_callback) {
|
||||||
var pms_ip = $("#pms_ip").val()
|
var pms_ip = $("#pms_ip").val();
|
||||||
var pms_port = $("#pms_port").val()
|
var pms_port = $("#pms_port").val();
|
||||||
var pms_identifier = $("#pms_identifier").val()
|
var pms_identifier = $("#pms_identifier").val();
|
||||||
var pms_ssl = $("#pms_ssl").val()
|
var pms_ssl = $("#pms_ssl").is(':checked') ? 1 : 0;
|
||||||
var pms_is_remote = $("#pms_is_remote").val()
|
var pms_is_remote = $("#pms_is_remote").is(':checked') ? 1 : 0;
|
||||||
if (($("#pms_ip").val() !== '') || ($("#pms_port").val() !== '')) {
|
if (($("#pms_ip").val() !== '') || ($("#pms_port").val() !== '')) {
|
||||||
$("#pms-verify").html('<i class="fa fa-refresh fa-spin"></i>');
|
$("#pms-verify").html('<i class="fa fa-refresh fa-spin"></i>');
|
||||||
$('#pms-verify').fadeIn('fast');
|
$('#pms-verify').fadeIn('fast');
|
||||||
|
@ -1582,15 +1582,16 @@ $(document).ready(function() {
|
||||||
data : { hostname: pms_ip, port: pms_port, identifier: pms_identifier, ssl: pms_ssl, remote: pms_is_remote },
|
data : { hostname: pms_ip, port: pms_port, identifier: pms_identifier, ssl: pms_ssl, remote: pms_is_remote },
|
||||||
cache: true,
|
cache: true,
|
||||||
async: true,
|
async: true,
|
||||||
timeout: 5000,
|
timeout: 10000,
|
||||||
error: function(jqXHR, textStatus, errorThrown) {
|
error: function(jqXHR, textStatus, errorThrown) {
|
||||||
$("#pms-verify").html('<i class="fa fa-close"></i>');
|
$("#pms-verify").html('<i class="fa fa-close"></i>');
|
||||||
$('#pms-verify').fadeIn('fast');
|
$('#pms-verify').fadeIn('fast');
|
||||||
$("#pms-ip-group").addClass("has-error");
|
$("#pms-ip-group").addClass("has-error");
|
||||||
},
|
},
|
||||||
success: function (xml) {
|
success: function (json) {
|
||||||
if ($(xml).find('MediaContainer').attr('machineIdentifier')) {
|
var machine_identifier = json;
|
||||||
$("#pms_identifier").val($(xml).find('MediaContainer').attr('machineIdentifier'));
|
if (machine_identifier) {
|
||||||
|
$("#pms_identifier").val(machine_identifier);
|
||||||
$("#pms-verify").html('<i class="fa fa-check"></i>');
|
$("#pms-verify").html('<i class="fa fa-check"></i>');
|
||||||
$('#pms-verify').fadeIn('fast');
|
$('#pms-verify').fadeIn('fast');
|
||||||
$("#pms-ip-group").removeClass("has-error");
|
$("#pms-ip-group").removeClass("has-error");
|
||||||
|
|
|
@ -393,9 +393,10 @@ from plexpy import common
|
||||||
$("#pms-verify-status").html('<i class="fa fa-exclamation-circle"></i> This is not a Plex Server!');
|
$("#pms-verify-status").html('<i class="fa fa-exclamation-circle"></i> This is not a Plex Server!');
|
||||||
$('#pms-verify-status').fadeIn('fast');
|
$('#pms-verify-status').fadeIn('fast');
|
||||||
},
|
},
|
||||||
success: function (xml) {
|
success: function (json) {
|
||||||
if ($(xml).find('MediaContainer').attr('machineIdentifier')) {
|
var machine_identifier = json;
|
||||||
$("#pms_identifier").val($(xml).find('MediaContainer').attr('machineIdentifier'));
|
if (machine_identifier) {
|
||||||
|
$("#pms_identifier").val(machine_identifier);
|
||||||
$("#pms-verify-status").html('<i class="fa fa-check"></i> Server found!');
|
$("#pms-verify-status").html('<i class="fa fa-check"></i> Server found!');
|
||||||
$('#pms-verify-status').fadeIn('fast');
|
$('#pms-verify-status').fadeIn('fast');
|
||||||
pms_verified = true;
|
pms_verified = true;
|
||||||
|
|
|
@ -44,7 +44,8 @@ class HTTPHandler(object):
|
||||||
headers=None,
|
headers=None,
|
||||||
output_format='raw',
|
output_format='raw',
|
||||||
return_type=False,
|
return_type=False,
|
||||||
no_token=False):
|
no_token=False,
|
||||||
|
timeout=20):
|
||||||
|
|
||||||
valid_request_types = ['GET', 'POST', 'PUT', 'DELETE']
|
valid_request_types = ['GET', 'POST', 'PUT', 'DELETE']
|
||||||
|
|
||||||
|
@ -56,12 +57,12 @@ class HTTPHandler(object):
|
||||||
if proto.upper() == 'HTTPS':
|
if proto.upper() == 'HTTPS':
|
||||||
if not self.ssl_verify and hasattr(ssl, '_create_unverified_context'):
|
if not self.ssl_verify and hasattr(ssl, '_create_unverified_context'):
|
||||||
context = ssl._create_unverified_context()
|
context = ssl._create_unverified_context()
|
||||||
handler = HTTPSConnection(host=self.host, port=self.port, timeout=20, context=context)
|
handler = HTTPSConnection(host=self.host, port=self.port, timeout=timeout, context=context)
|
||||||
logger.warn(u"PlexPy HTTP Handler :: Unverified HTTPS request made. This connection is not secure.")
|
logger.warn(u"PlexPy HTTP Handler :: Unverified HTTPS request made. This connection is not secure.")
|
||||||
else:
|
else:
|
||||||
handler = HTTPSConnection(host=self.host, port=self.port, timeout=20)
|
handler = HTTPSConnection(host=self.host, port=self.port, timeout=timeout)
|
||||||
else:
|
else:
|
||||||
handler = HTTPConnection(host=self.host, port=self.port, timeout=20)
|
handler = HTTPConnection(host=self.host, port=self.port, timeout=timeout)
|
||||||
|
|
||||||
token_string = ''
|
token_string = ''
|
||||||
if not no_token:
|
if not no_token:
|
||||||
|
|
|
@ -1382,7 +1382,11 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
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):
|
||||||
if not identifier:
|
from plexpy import http_handler
|
||||||
|
|
||||||
|
# Attempt to get the pms_identifier from plex.tv if the server is published
|
||||||
|
# Works for all PMS SSL settings
|
||||||
|
if not identifier and hostname and port:
|
||||||
plex_tv = plextv.PlexTV()
|
plex_tv = plextv.PlexTV()
|
||||||
servers = plex_tv.discover()
|
servers = plex_tv.discover()
|
||||||
|
|
||||||
|
@ -1391,27 +1395,28 @@ class WebInterface(object):
|
||||||
identifier = server['clientIdentifier']
|
identifier = server['clientIdentifier']
|
||||||
break
|
break
|
||||||
|
|
||||||
if identifier and hostname and port:
|
# Fallback to checking /identity endpoint is server is unpublished
|
||||||
# Set PMS attributes to get the real PMS url
|
# Cannot set SSL settings on the PMS if unpublished so 'http' is okay
|
||||||
plexpy.CONFIG.__setattr__('PMS_IP', hostname)
|
if not identifier:
|
||||||
plexpy.CONFIG.__setattr__('PMS_PORT', port)
|
request_handler = http_handler.HTTPHandler(host=hostname,
|
||||||
plexpy.CONFIG.__setattr__('PMS_IDENTIFIER', identifier)
|
port=port,
|
||||||
plexpy.CONFIG.__setattr__('PMS_SSL', ssl)
|
token=None)
|
||||||
plexpy.CONFIG.__setattr__('PMS_IS_REMOTE', remote)
|
uri = '/identity'
|
||||||
plexpy.CONFIG.write()
|
request = request_handler.make_request(uri=uri,
|
||||||
|
proto='http',
|
||||||
plextv.get_real_pms_url()
|
request_type='GET',
|
||||||
|
output_format='xml',
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
no_token=True,
|
||||||
request = pms_connect.get_local_server_identity()
|
timeout=10)
|
||||||
|
if request:
|
||||||
if request:
|
xml_head = request.getElementsByTagName('MediaContainer')[0]
|
||||||
cherrypy.response.headers['Content-type'] = 'application/xml'
|
identifier = xml_head.getAttribute('machineIdentifier')
|
||||||
return request
|
|
||||||
else:
|
if identifier:
|
||||||
logger.warn(u"Unable to retrieve data for get_server_id.")
|
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||||
return None
|
return json.dumps(identifier)
|
||||||
else:
|
else:
|
||||||
|
logger.warn('Unable to retrieve the PMS identifier.')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue