Check for localhost in QR address

This commit is contained in:
JonnyWong16 2017-08-22 22:33:58 -07:00
parent be2989ead1
commit f414d7aa16

View file

@ -1378,13 +1378,16 @@
<p class="help-block"> <p class="help-block">
Scan the QR code below with the PlexPy Android app to automatically register it with the server. Scan the QR code below with the PlexPy Android app to automatically register it with the server.
Make sure the PlexPy Address below is correct. Make sure the PlexPy Address below is correct.
<span class="inline-pre">127.0.0.1</span> and <span class="inline-pre">localhost</span> will not work.
</p> </p>
<label>QR Code</label> <label>QR Code</label>
<pre id="api_qr_code" style="text-align: center"></pre> <pre id="api_qr_code" style="text-align: center"></pre>
<label>PlexPy Address</label> <label>PlexPy Address</label>
<input type="text" class="form-control" id="api_qr_address"> <input type="text" class="form-control" id="api_qr_address">
<input type="hidden" class="form-control" id="api_qr_token"> <input type="hidden" class="form-control" id="api_qr_token">
<p class="help-block" id="api_qr_localhost" style="display: none;">
Note: <span class="inline-pre">127.0.0.1</span> and <span class="inline-pre">localhost</span> will not work.
Please enter an internal or external IP address, or hostname or domain instead.
</p>
<p class="help-block" id="api_qr_private" style="display: none;"> <p class="help-block" id="api_qr_private" style="display: none;">
Note: This is a private IP address. PlexPy will not be reachable outside of your home network. Note: This is a private IP address. PlexPy will not be reachable outside of your home network.
Access PlexPy externally to generate the QR code for remote access. Access PlexPy externally to generate the QR code for remote access.
@ -2030,17 +2033,30 @@ $(document).ready(function() {
return deferred; return deferred;
} }
var verifiedDevice = false; function checkQRAddress(url) {
$('#generate_qr').click(function () { var parser = document.createElement('a');
getPlexPyURL().then(function (url) { parser.href = url;
var parser = document.createElement('a'); var hostname = parser.hostname;
parser.href = url; var protocol = parser.protocol;
isPrivateIP(parser.hostname).then(function (valid) {
if (hostname === '127.0.0.1' || hostname === 'localhost') {
$('#api_qr_localhost').toggle(true);
$('#api_qr_private').toggle(false);
} else {
$('#api_qr_localhost').toggle(false);
isPrivateIP(hostname).then(function (valid) {
$('#api_qr_private').toggle((valid !== 'n/a')); $('#api_qr_private').toggle((valid !== 'n/a'));
}, function () { }, function () {
$('#api_qr_private').toggle(false); $('#api_qr_private').toggle(false);
}); });
$('#api_qr_https').toggle(!(url.startsWith('https'))); }
$('#api_qr_https').toggle((protocol === 'http:'));
}
var verifiedDevice = false;
$('#generate_qr').click(function () {
getPlexPyURL().then(function (url) {
checkQRAddress(url)
$.get('generate_api_key', { device: true }).then(function (token) { $.get('generate_api_key', { device: true }).then(function (token) {
$('#api_qr_address').val(url); $('#api_qr_address').val(url);
@ -2079,14 +2095,7 @@ $(document).ready(function() {
$('#api_qr_address').change(function () { $('#api_qr_address').change(function () {
var url = $(this).val(); var url = $(this).val();
var parser = document.createElement('a'); checkQRAddress(url)
parser.href = url;
isPrivateIP(parser.hostname).then(function (valid) {
$('#api_qr_private').toggle((valid !== 'n/a'));
}, function () {
$('#api_qr_private').toggle(false);
});
$('#api_qr_https').toggle(!(url.startsWith('https')));
$('#api_qr_code').empty().qrcode({ $('#api_qr_code').empty().qrcode({
text: url + '|' + $('#api_qr_token').val() text: url + '|' + $('#api_qr_token').val()