Merge pull request #414 from JonnyWong16/miscellaneous-fixes

Allow SSL when verifying server in settings and test notifications
This commit is contained in:
JonnyWong16 2015-12-31 20:14:12 -08:00
commit 78a87db017
6 changed files with 124 additions and 111 deletions

View file

@ -66,6 +66,27 @@ from plexpy import helpers
% endfor % endfor
</div> </div>
</form> </form>
<div class="col-md-12" style="margin-top: 10px; padding-top: 10px; border-top: 1px solid #444;">
<h4>Test ${agent['name']}</h4>
<p class="help-block">Test if ${agent['name']} notifications are working. See <a href="/logs">logs</a> for troubleshooting.</p>
<div class="form-group">
<label for="test_subject">Subject Line</label>
<input class="form-control" type="text" id="test_subject" name="test_subject" value="PlexPy">
<p class="help-block">Set a custom subject line.</p>
</div>
<div class="form-group">
<label for="test_body">Message Body</label>
<input class="form-control" type="text" id="test_body" name="test_body" value="Test notification">
<p class="help-block">Set a custom body.</p>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-8">
<input type="button" class="btn btn-bright" id="test_notifier" name="test_notifier" value="Test ${agent['name']}">
</div>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -120,24 +141,24 @@ from plexpy import helpers
$.get("/twitterStep2", { 'key': twitter_key }, function (data) { $('#ajaxMsg').html("<i class='fa fa-check'></i> " + data); }); $.get("/twitterStep2", { 'key': twitter_key }, function (data) { $('#ajaxMsg').html("<i class='fa fa-check'></i> " + data); });
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut(); $('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
}); });
$('#testTwitter').click(function () {
$.get("/testTwitter", $('#test_notifier').click(function () {
function (data) { $('#ajaxMsg').html("<i class='fa fa-check'></i> " + data); }); doAjaxCall('set_notification_config', $(this), 'tabs', true);
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut(); $.ajax({
url: 'test_notifier',
data: { config_id: '${agent["id"]}',
subject: $('#test_subject').val(),
body: $('#test_body').val() },
cache: false,
async: true,
complete: function (xhr, status) {
msg = '<i class="fa fa-check"></i>&nbsp; ' + xhr.responseText;
showMsg(msg, false, true, 2000);
}
});
}); });
$('#testIFTTT').click(function () { $('#pushbullet_apikey, #pushover_apitoken').on('change', function () {
$.get("/test_ifttt",
function (data) { $('#ajaxMsg').html("<i class='fa fa-check'></i> " + data); });
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
});
$('#testSlack').click(function() {
$.get("/test_slack", function(data) { $('#ajaxMsg').html("<i class='fa fa-check'></i>" + data); });
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
});
$('#pushbullet_apikey').on('change', function () {
doAjaxCall('set_notification_config', $(this), 'tabs', true); doAjaxCall('set_notification_config', $(this), 'tabs', true);
reloadModal(); reloadModal();
return false; return false;

View file

@ -1422,12 +1422,15 @@ $(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_ssl = $("#pms_ssl").val()
var pms_is_remote = $("#pms_is_remote").val()
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');
$.ajax({ $.ajax({
url: 'get_server_id', url: 'get_server_id',
data : { hostname: pms_ip, port: pms_port }, 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: 5000,

View file

@ -372,12 +372,15 @@ from plexpy import common
$("#verify-plex-server").click(function() { $("#verify-plex-server").click(function() {
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_ssl = $("#pms_ssl").val()
var pms_is_remote = $("#pms_is_remote").val()
if (($("#pms_ip").val() !== '') || ($("#pms_port").val() !== '')) { if (($("#pms_ip").val() !== '') || ($("#pms_port").val() !== '')) {
$("#pms-verify-status").html('<i class="fa fa-refresh fa-spin"></i> Validating server...'); $("#pms-verify-status").html('<i class="fa fa-refresh fa-spin"></i> Validating server...');
$('#pms-verify-status').fadeIn('fast'); $('#pms-verify-status').fadeIn('fast');
$.ajax({ $.ajax({
url: 'get_server_id', url: 'get_server_id',
data : { hostname: pms_ip, port: pms_port }, 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: 5000,

View file

@ -61,6 +61,7 @@ _CONFIG_DEFINITIONS = {
'CONFIG_VERSION': (str, 'General', '0'), 'CONFIG_VERSION': (str, 'General', '0'),
'DO_NOT_OVERRIDE_GIT_BRANCH': (int, 'General', 0), 'DO_NOT_OVERRIDE_GIT_BRANCH': (int, 'General', 0),
'EMAIL_ENABLED': (int, 'Email', 0), 'EMAIL_ENABLED': (int, 'Email', 0),
'EMAIL_FROM_NAME': (str, 'Email', 'PlexPy'),
'EMAIL_FROM': (str, 'Email', ''), 'EMAIL_FROM': (str, 'Email', ''),
'EMAIL_TO': (str, 'Email', ''), 'EMAIL_TO': (str, 'Email', ''),
'EMAIL_CC': (str, 'Email', ''), 'EMAIL_CC': (str, 'Email', ''),

View file

@ -983,15 +983,11 @@ class PUSHOVER(object):
def __init__(self): def __init__(self):
self.enabled = plexpy.CONFIG.PUSHOVER_ENABLED self.enabled = plexpy.CONFIG.PUSHOVER_ENABLED
self.application_token = plexpy.CONFIG.PUSHOVER_APITOKEN
self.keys = plexpy.CONFIG.PUSHOVER_KEYS self.keys = plexpy.CONFIG.PUSHOVER_KEYS
self.priority = plexpy.CONFIG.PUSHOVER_PRIORITY self.priority = plexpy.CONFIG.PUSHOVER_PRIORITY
self.sound = plexpy.CONFIG.PUSHOVER_SOUND self.sound = plexpy.CONFIG.PUSHOVER_SOUND
if plexpy.CONFIG.PUSHOVER_APITOKEN:
self.application_token = plexpy.CONFIG.PUSHOVER_APITOKEN
else:
self.application_token = "aVny3NZFwZaXC642c831b4wd7KUhQS"
def conf(self, options): def conf(self, options):
return cherrypy.config['config'].get('Pushover', options) return cherrypy.config['config'].get('Pushover', options)
@ -1041,25 +1037,35 @@ class PUSHOVER(object):
self.notify('Main Screen Activate', 'Test Message') self.notify('Main Screen Activate', 'Test Message')
def get_sounds(self): def get_sounds(self):
http_handler = HTTPSConnection("api.pushover.net") if plexpy.CONFIG.PUSHOVER_APITOKEN:
http_handler.request("GET", "/1/sounds.json?token=" + self.application_token) http_handler = HTTPSConnection("api.pushover.net")
response = http_handler.getresponse() http_handler.request("GET", "/1/sounds.json?token=" + self.application_token)
request_status = response.status response = http_handler.getresponse()
request_status = response.status
if request_status == 200:
data = json.loads(response.read()) if request_status == 200:
sounds = data.get('sounds', {}) data = json.loads(response.read())
sounds.update({'': ''}) sounds = data.get('sounds', {})
return sounds sounds.update({'': ''})
elif request_status >= 400 and request_status < 500: return sounds
logger.info(u"Unable to retrieve Pushover notification sounds list: %s" % response.reason) elif request_status >= 400 and request_status < 500:
return {'': ''} logger.info(u"Unable to retrieve Pushover notification sounds list: %s" % response.reason)
return {'': ''}
else:
logger.info(u"Unable to retrieve Pushover notification sounds list.")
return {'': ''}
else: else:
logger.info(u"Unable to retrieve Pushover notification sounds list.")
return {'': ''} return {'': ''}
def return_config_options(self): def return_config_options(self):
config_option = [{'label': 'Pushover User or Group Key', config_option = [{'label': 'Pushover API Token',
'value': plexpy.CONFIG.PUSHOVER_APITOKEN,
'name': 'pushover_apitoken',
'description': 'Your Pushover API token.',
'input_type': 'text'
},
{'label': 'Pushover User or Group Key',
'value': self.keys, 'value': self.keys,
'name': 'pushover_keys', 'name': 'pushover_keys',
'description': 'Your Pushover user or group key.', 'description': 'Your Pushover user or group key.',
@ -1078,12 +1084,6 @@ class PUSHOVER(object):
'description': 'Set the notification sound. Leave blank for the default sound.', 'description': 'Set the notification sound. Leave blank for the default sound.',
'input_type': 'select', 'input_type': 'select',
'select_options': self.get_sounds() 'select_options': self.get_sounds()
},
{'label': 'Pushover API Token',
'value': plexpy.CONFIG.PUSHOVER_APITOKEN,
'name': 'pushover_apitoken',
'description': 'Your Pushover API token. Leave blank to use PlexPy default.',
'input_type': 'text'
} }
] ]
@ -1198,12 +1198,6 @@ class TwitterNotifier(object):
'description': 'Step 3: Verify the key.', 'description': 'Step 3: Verify the key.',
'input_type': 'button' 'input_type': 'button'
}, },
{'label': 'Test Twitter',
'value': 'Test Twitter',
'name': 'testTwitter',
'description': 'Test if Twitter notifications are working. See logs for troubleshooting.',
'input_type': 'button'
},
{'input_type': 'nosave' {'input_type': 'nosave'
} }
] ]
@ -1380,7 +1374,7 @@ class Email(object):
message = MIMEText(message, 'plain', "utf-8") message = MIMEText(message, 'plain', "utf-8")
message['Subject'] = subject message['Subject'] = subject
message['From'] = email.utils.formataddr(('PlexPy', plexpy.CONFIG.EMAIL_FROM)) message['From'] = email.utils.formataddr((plexpy.CONFIG.EMAIL_FROM_NAME, plexpy.CONFIG.EMAIL_FROM))
message['To'] = plexpy.CONFIG.EMAIL_TO message['To'] = plexpy.CONFIG.EMAIL_TO
message['CC'] = plexpy.CONFIG.EMAIL_CC message['CC'] = plexpy.CONFIG.EMAIL_CC
@ -1411,7 +1405,13 @@ class Email(object):
return False return False
def return_config_options(self): def return_config_options(self):
config_option = [{'label': 'From', config_option = [{'label': 'From Name',
'value': plexpy.CONFIG.EMAIL_FROM_NAME,
'name': 'email_from_name',
'description': 'The name of the sender.',
'input_type': 'text'
},
{'label': 'From',
'value': plexpy.CONFIG.EMAIL_FROM, 'value': plexpy.CONFIG.EMAIL_FROM,
'name': 'email_from', 'name': 'email_from',
'description': 'The email address of the sender.', 'description': 'The email address of the sender.',
@ -1522,12 +1522,6 @@ class IFTTT(object):
'description': 'The Ifttt maker event to fire. The notification subject and body will be sent' 'description': 'The Ifttt maker event to fire. The notification subject and body will be sent'
' as value1 and value2 respectively.', ' as value1 and value2 respectively.',
'input_type': 'text' 'input_type': 'text'
},
{'label': 'Test Event',
'value': 'Test Event',
'name': 'testIFTTT',
'description': 'Test if IFTTT notifications are working. See logs for troubleshooting.',
'input_type': 'button'
} }
] ]
@ -1664,27 +1658,21 @@ class SLACK(object):
{'label': 'Slack Channel', {'label': 'Slack Channel',
'value': self.channel, 'value': self.channel,
'name': 'slack_channel', 'name': 'slack_channel',
'description': 'Your slack channel name. (Begin with \'#\')', 'description': 'Your Slack channel name (begin with \'#\'). Leave blank for webhook integration default.',
'input_type': 'text' 'input_type': 'text'
}, },
{'label': 'Slack Username', {'label': 'Slack Username',
'value': self.username, 'value': self.username,
'name': 'slack_username', 'name': 'slack_username',
'description': 'Slack username which will be shown', 'description': 'The Slack username which will be shown. Leave blank for webhook integration default.',
'input_type': 'text' 'input_type': 'text'
}, },
{'label': 'Slack Icon', {'label': 'Slack Icon',
'value': self.icon_emoji, 'value': self.icon_emoji,
'description': 'Your icon you wish to show, use Slack emoji or image url', 'description': 'The icon you wish to show, use Slack emoji or image url. Leave blank for webhook integration default.',
'name': 'slack_icon_emoji', 'name': 'slack_icon_emoji',
'input_type': 'text' 'input_type': 'text'
}, }
{'label': 'Test Event',
'value': 'Test Event',
'name': 'testSlack',
'description': 'Test if Slack notifications are working. See logs for troubleshooting.',
'input_type': 'button'
}
] ]
return config_option return config_option

View file

@ -554,8 +554,8 @@ class WebInterface(object):
# Get new server URLs for SSL communications. # Get new server URLs for SSL communications.
plextv.get_real_pms_url() plextv.get_real_pms_url()
# Get new server friendly name # Get new server friendly name
pmsconnect.get_server_friendly_name() pmsconnect.get_server_friendly_name()
# Reconfigure scheduler if intervals changed # Reconfigure scheduler if intervals changed
@ -659,6 +659,30 @@ class WebInterface(object):
return a.fetchData() return a.fetchData()
@cherrypy.expose
def test_notifier(self, config_id=None, subject='PlexPy', body='Test notification', **kwargs):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
if config_id.isdigit():
agents = notifiers.available_notification_agents()
for agent in agents:
if int(config_id) == agent['id']:
this_agent = agent
break
else:
this_agent = None
if this_agent:
logger.debug("Sending test %s notification." % this_agent['name'])
notifiers.send_notification(this_agent['id'], subject, body)
return "Notification sent."
else:
logger.debug("Unable to send test notification, invalid notification agent ID %s." % config_id)
return "Invalid notification agent ID %s." % config_id
else:
logger.debug("Unable to send test notification, no notification agent ID received.")
return "No notification agent ID received."
@cherrypy.expose @cherrypy.expose
def twitterStep1(self): def twitterStep1(self):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store" cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
@ -676,37 +700,6 @@ class WebInterface(object):
else: else:
return "Unable to verify key" return "Unable to verify key"
@cherrypy.expose
def testTwitter(self):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
tweet = notifiers.TwitterNotifier()
result = tweet.test_notify()
if result:
return "Tweet successful, check your twitter to make sure it worked"
else:
return "Error sending tweet"
@cherrypy.expose
def test_ifttt(self):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
event = notifiers.IFTTT()
result = event.test()
if result:
return "Notification successful."
else:
return "Error sending event."
@cherrypy.expose
def test_slack(self):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
event = notifiers.SLACK()
result = event.test()
if result:
return "Notification successful."
else:
return "Error sending event."
@cherrypy.expose @cherrypy.expose
def osxnotifyregister(self, app): def osxnotifyregister(self, app):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store" cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
@ -1335,19 +1328,23 @@ class WebInterface(object):
return serve_template(templatename="plexwatch_import.html", title="Import PlexWatch Database") return serve_template(templatename="plexwatch_import.html", title="Import PlexWatch Database")
@cherrypy.expose @cherrypy.expose
def get_server_id(self, hostname=None, port=None, **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
if hostname and port: if hostname and port:
request_handler = http_handler.HTTPHandler(host=hostname, # Set PMS attributes to get the real PMS url
port=port, plexpy.CONFIG.__setattr__('PMS_IP', hostname)
token=None) plexpy.CONFIG.__setattr__('PMS_PORT', port)
uri = '/identity' plexpy.CONFIG.__setattr__('PMS_IDENTIFIER', identifier)
request = request_handler.make_request(uri=uri, plexpy.CONFIG.__setattr__('PMS_SSL', ssl)
proto='http', plexpy.CONFIG.__setattr__('PMS_IS_REMOTE', remote)
request_type='GET', plexpy.CONFIG.write()
output_format='',
no_token=True) plextv.get_real_pms_url()
pms_connect = pmsconnect.PmsConnect()
request = pms_connect.get_local_server_identity()
if request: if request:
cherrypy.response.headers['Content-type'] = 'application/xml' cherrypy.response.headers['Content-type'] = 'application/xml'
return request return request