Skip to content

Commit

Permalink
No longer storing plex username and password. Only token.
Browse files Browse the repository at this point in the history
Redirect to config page if no Plexwatch database set.
  • Loading branch information
drzoidberg33 committed Jun 27, 2015
1 parent c0f4879 commit d2c65e6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 38 deletions.
80 changes: 72 additions & 8 deletions data/interfaces/default/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,11 @@ <h3>PMS Settings</h3>
<p class="help-block">Port that Plex Media Server is listening on.</p>
</div>
<div class="form-group">
<label for="pms_username">PMS Username</label>
<input type="text" id="pms_username" name="pms_username" value="${config['pms_username']}" size="30">
<p class="help-block">Username for Plex.tv authentication. Leave empty if no authentication is required.</p>
</div>
<div class="form-group">
<label for="pms_password">PMS Password</label>
<input type="password" id="pms_password" name="pms_password" value="${config['pms_password']}" size="30">
<p class="help-block">Password for Plex.tv authentication. Leave empty if no authentication is required.</p>
<label for="pms_token">PMS Token</label>
<input type="text" id="pms_token" name="pms_token" value="${config['pms_token']}" size="30">
<p class="help-block">Token for Plex.tv authentication. Leave empty if no authentication is required.</p>
</div>
<p class="help-block"><a href="#pms-auth-modal" data-toggle="modal">Fetch Token</a></p>
</fieldset>
</div>
<div class="span4">
Expand Down Expand Up @@ -325,6 +321,42 @@ <h3 id="myModalLabel">Date &amp; Time Format Options</h3>
</div>
<div class="modal-footer"></div>
</div>

<div id="pms-auth-modal" class="modal hide fade" tabindex="-1" role="dialog"
aria-labelledby="ip-info-modal" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i
class="fa fa-remove"></i></button>
<h3 id="PMSAuthModal">Fetch Plex.tv Token</h3>
</div>
<div class="modal-body" id="modal-text">
<div>
<div class="span6">
<span>
This will attempt to fetch your token for you. This will not work on Internet Explorer 9 or lower.
PlexPy does not store your username and password.
</span>
<br/><br/>
<div class="form-group">
<label for="pms_username">PMS Username</label>
<input type="text" id="pms_username" name="pms_username" size="30">
<p class="help-block">Username for Plex.tv authentication.</p>
</div>
<div class="form-group">
<label for="pms_password">PMS Password</label>
<input type="password" id="pms_password" name="pms_password" size="30">
<p class="help-block">Password for Plex.tv authentication.</p>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="">
<input type="button" id="get-pms-auth-token" class="btn btn-primary" value="Fetch Token">
<span id="pms-token-status"></span>
</div>
</div>
</div>
</div>
<!--
<div role="tabpanel" class="tab-pane" id="tabs-5">
Expand Down Expand Up @@ -683,6 +715,38 @@ <h3>MPC</h3>
<%def name="javascriptIncludes()">
<script>

// Plex.tv auth token fetch
$("#get-pms-auth-token").click(function() {
$("#pms-token-status").html('<i class="fa fa-refresh fa-spin"></i> Fetching token...');
if (($("#pms_username").val() !== '') || ($("#pms_password").val() !== '')) {
$.ajax({
type: "post",
url: "https://plex.tv/users/sign_in.xml",
dataType: 'xml',
async: true,
headers: {'Content-Type': 'application/xml; charset=utf-8',
'Content-Length': '0',
'X-Plex-Device-Name': 'PlexPy',
'X-Plex-Product': 'PlexPy',
'X-Plex-Version': 'v0.1 dev',
'X-Plex-Client-Identifier': 'f0864d3531d75b19fa9204eaea456515e2502017',

This comment has been minimized.

Copy link
@Arcanemagus

Arcanemagus Jun 27, 2015

Contributor

You should be generating a unique ID per client, not a single one for all PlexPy users.

This comment has been minimized.

Copy link
@drzoidberg33

drzoidberg33 Jun 28, 2015

Author Contributor

Thanks. Honestly didn't spend much time researching this part. Will fix this in upcoming commits.

This comment has been minimized.

Copy link
@drzoidberg33

drzoidberg33 Jun 28, 2015

Author Contributor

Fixed in 4f1056c

'Authorization': 'Basic ' + btoa($("#pms_username").val() + ':' + $("#pms_password").val())
},
error: function(jqXHR, textStatus, errorThrown) {
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i> Authentation failed!');
},
success: function (xml) {
var authToken = $(xml).find('user').attr('authenticationToken');
$("#pms-token-status").html('<i class="fa fa-check"></i> Authentation successful!');
$("#pms_token").val(authToken);
$('#pms-auth-modal').modal('hide');
}
});
} else {
$("#pms-token-status").html("You must enter both fields.");
}
});

function openExtrasDialog() {
$("#dialog").dialog({ close: function(){
var elem = '<input type="button" data-success="Changes saved successfully">';
Expand Down
2 changes: 0 additions & 2 deletions data/interfaces/default/css/plexwatch.css
Original file line number Diff line number Diff line change
Expand Up @@ -2224,8 +2224,6 @@ input[type="button"].btn-block {
/* Darken IE7 buttons by default so they stand out more given they won't have borders */
filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
padding: 6px 25px;
font-size: 18px;
font-weight: bold;
}
.btn-primary:hover,
.btn-primary:focus,
Expand Down
34 changes: 6 additions & 28 deletions plexpy/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def index(self):

@cherrypy.expose
def home(self):
return serve_template(templatename="index.html", title="Home")
if plexpy.CONFIG.PLEXWATCH_DATABASE == '':
raise cherrypy.HTTPRedirect("config")
else:
return serve_template(templatename="index.html", title="Home")

@cherrypy.expose
def get_date_formats(self):
Expand Down Expand Up @@ -202,10 +205,6 @@ def config(self):
http_password = ' '
else:
http_password = ''
if plexpy.CONFIG.PMS_PASSWORD != '':
pms_password = ' '
else:
pms_password = ''

config = {
"http_host": plexpy.CONFIG.HTTP_HOST,
Expand Down Expand Up @@ -273,8 +272,7 @@ def config(self):
"email_tls": checked(plexpy.CONFIG.EMAIL_TLS),
"pms_ip": plexpy.CONFIG.PMS_IP,
"pms_port": plexpy.CONFIG.PMS_PORT,
"pms_username": plexpy.CONFIG.PMS_USERNAME,
"pms_password": pms_password,
"pms_token": plexpy.CONFIG.PMS_TOKEN,
"plexwatch_database": plexpy.CONFIG.PLEXWATCH_DATABASE,
"date_format": plexpy.CONFIG.DATE_FORMAT,
"time_format": plexpy.CONFIG.TIME_FORMAT,
Expand Down Expand Up @@ -303,29 +301,9 @@ def configUpdate(self, **kwargs):
# checked items should be zero or one. if they were not sent then the item was not checked
kwargs[checked_config] = 0

# Write Plex token to the config
if (not plexpy.CONFIG.PMS_TOKEN or plexpy.CONFIG.PMS_TOKEN == '' \
or kwargs['pms_username'] != plexpy.CONFIG.PMS_USERNAME) \
and (kwargs['pms_username'] != '' or kwargs['pms_password'] != ''):

plex_tv = plextv.PlexTV(kwargs['pms_username'], kwargs['pms_password'])
token = plex_tv.get_token()

if token:
kwargs['pms_token'] = token
logger.info('Plex.tv token sucessfully written to config.')
else:
logger.warn('Unable to write Plex.tv token to config.')

# Clear Plex token if username or password set to blank
if kwargs['pms_username'] == '' or kwargs['pms_password'] == '':
kwargs['pms_token'] = ''

# If passwords exists in config, do not overwrite when blank value received
# If http password exists in config, do not overwrite when blank value received
if kwargs['http_password'] == ' ' and plexpy.CONFIG.HTTP_PASSWORD != '':
kwargs['http_password'] = plexpy.CONFIG.HTTP_PASSWORD
if kwargs['pms_password'] == ' ' and plexpy.CONFIG.PMS_PASSWORD != '':
kwargs['pms_password'] = plexpy.CONFIG.PMS_PASSWORD

for plain_config, use_config in [(x[4:], x) for x in kwargs if x.startswith('use_')]:
# the use prefix is fairly nice in the html, but does not match the actual config
Expand Down

0 comments on commit d2c65e6

Please sign in to comment.