mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 06:00:51 -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) {
|
||||
var pms_ip = $("#pms_ip").val()
|
||||
var pms_port = $("#pms_port").val()
|
||||
var pms_identifier = $("#pms_identifier").val()
|
||||
var pms_ssl = $("#pms_ssl").val()
|
||||
var pms_is_remote = $("#pms_is_remote").val()
|
||||
var pms_ip = $("#pms_ip").val();
|
||||
var pms_port = $("#pms_port").val();
|
||||
var pms_identifier = $("#pms_identifier").val();
|
||||
var pms_ssl = $("#pms_ssl").is(':checked') ? 1 : 0;
|
||||
var pms_is_remote = $("#pms_is_remote").is(':checked') ? 1 : 0;
|
||||
if (($("#pms_ip").val() !== '') || ($("#pms_port").val() !== '')) {
|
||||
$("#pms-verify").html('<i class="fa fa-refresh fa-spin"></i>');
|
||||
$('#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 },
|
||||
cache: true,
|
||||
async: true,
|
||||
timeout: 5000,
|
||||
timeout: 10000,
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
$("#pms-verify").html('<i class="fa fa-close"></i>');
|
||||
$('#pms-verify').fadeIn('fast');
|
||||
$("#pms-ip-group").addClass("has-error");
|
||||
},
|
||||
success: function (xml) {
|
||||
if ($(xml).find('MediaContainer').attr('machineIdentifier')) {
|
||||
$("#pms_identifier").val($(xml).find('MediaContainer').attr('machineIdentifier'));
|
||||
success: function (json) {
|
||||
var machine_identifier = json;
|
||||
if (machine_identifier) {
|
||||
$("#pms_identifier").val(machine_identifier);
|
||||
$("#pms-verify").html('<i class="fa fa-check"></i>');
|
||||
$('#pms-verify').fadeIn('fast');
|
||||
$("#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').fadeIn('fast');
|
||||
},
|
||||
success: function (xml) {
|
||||
if ($(xml).find('MediaContainer').attr('machineIdentifier')) {
|
||||
$("#pms_identifier").val($(xml).find('MediaContainer').attr('machineIdentifier'));
|
||||
success: function (json) {
|
||||
var machine_identifier = json;
|
||||
if (machine_identifier) {
|
||||
$("#pms_identifier").val(machine_identifier);
|
||||
$("#pms-verify-status").html('<i class="fa fa-check"></i> Server found!');
|
||||
$('#pms-verify-status').fadeIn('fast');
|
||||
pms_verified = true;
|
||||
|
|
|
@ -44,7 +44,8 @@ class HTTPHandler(object):
|
|||
headers=None,
|
||||
output_format='raw',
|
||||
return_type=False,
|
||||
no_token=False):
|
||||
no_token=False,
|
||||
timeout=20):
|
||||
|
||||
valid_request_types = ['GET', 'POST', 'PUT', 'DELETE']
|
||||
|
||||
|
@ -56,12 +57,12 @@ class HTTPHandler(object):
|
|||
if proto.upper() == 'HTTPS':
|
||||
if not self.ssl_verify and hasattr(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.")
|
||||
else:
|
||||
handler = HTTPSConnection(host=self.host, port=self.port, timeout=20)
|
||||
handler = HTTPSConnection(host=self.host, port=self.port, timeout=timeout)
|
||||
else:
|
||||
handler = HTTPConnection(host=self.host, port=self.port, timeout=20)
|
||||
handler = HTTPConnection(host=self.host, port=self.port, timeout=timeout)
|
||||
|
||||
token_string = ''
|
||||
if not no_token:
|
||||
|
|
|
@ -1382,7 +1382,11 @@ class WebInterface(object):
|
|||
|
||||
@cherrypy.expose
|
||||
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()
|
||||
servers = plex_tv.discover()
|
||||
|
||||
|
@ -1391,27 +1395,28 @@ class WebInterface(object):
|
|||
identifier = server['clientIdentifier']
|
||||
break
|
||||
|
||||
if identifier and hostname and port:
|
||||
# Set PMS attributes to get the real PMS url
|
||||
plexpy.CONFIG.__setattr__('PMS_IP', hostname)
|
||||
plexpy.CONFIG.__setattr__('PMS_PORT', port)
|
||||
plexpy.CONFIG.__setattr__('PMS_IDENTIFIER', identifier)
|
||||
plexpy.CONFIG.__setattr__('PMS_SSL', ssl)
|
||||
plexpy.CONFIG.__setattr__('PMS_IS_REMOTE', remote)
|
||||
plexpy.CONFIG.write()
|
||||
|
||||
plextv.get_real_pms_url()
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
request = pms_connect.get_local_server_identity()
|
||||
|
||||
if request:
|
||||
cherrypy.response.headers['Content-type'] = 'application/xml'
|
||||
return request
|
||||
else:
|
||||
logger.warn(u"Unable to retrieve data for get_server_id.")
|
||||
return None
|
||||
# Fallback to checking /identity endpoint is server is unpublished
|
||||
# Cannot set SSL settings on the PMS if unpublished so 'http' is okay
|
||||
if not identifier:
|
||||
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:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(identifier)
|
||||
else:
|
||||
logger.warn('Unable to retrieve the PMS identifier.')
|
||||
return None
|
||||
|
||||
@cherrypy.expose
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue