mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 15:56:07 -07:00
Add mobile device last seen
This commit is contained in:
parent
019787b32d
commit
ecd0a199f1
5 changed files with 61 additions and 22 deletions
|
@ -17,6 +17,15 @@ DOCUMENTATION :: END
|
||||||
<span class="toggle-left"><i class="fa fa-lg fa-mobile"></i></span>
|
<span class="toggle-left"><i class="fa fa-lg fa-mobile"></i></span>
|
||||||
${device['friendly_name'] or device['device_name']} <span class="friendly_name">(${device['id']})</span>
|
${device['friendly_name'] or device['device_name']} <span class="friendly_name">(${device['id']})</span>
|
||||||
<span class="toggle-right"><i class="fa fa-lg fa-cog"></i></span>
|
<span class="toggle-right"><i class="fa fa-lg fa-cog"></i></span>
|
||||||
|
<span class="toggle-right friendly_name" id="device-last_seen-${device['id']}">
|
||||||
|
% if device['last_seen']:
|
||||||
|
<script>
|
||||||
|
$("#device-last_seen-${device['id']}").text(moment("${device['last_seen']}", "X").fromNow())
|
||||||
|
</script>
|
||||||
|
% else:
|
||||||
|
never
|
||||||
|
% endif
|
||||||
|
</span>
|
||||||
<!--<span class="toggle-right delete-mobile-device" data-toggle="tooltip" data-placement="top" title="Remove Device"><i class="fa fa-lg fa-times"></i></span>-->
|
<!--<span class="toggle-right delete-mobile-device" data-toggle="tooltip" data-placement="top" title="Remove Device"><i class="fa fa-lg fa-times"></i></span>-->
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -1076,7 +1076,7 @@
|
||||||
<p class="help-block">Register a new device, or configure an existing device by clicking the settings icon on the right.</p>
|
<p class="help-block">Register a new device, or configure an existing device by clicking the settings icon on the right.</p>
|
||||||
<p id="app_api_msg" style="color: #eb8600;">The API must be enabled under <a data-tab-destination="tabs-access_control" style="cursor: pointer;">Access Control</a> to use the app.</p>
|
<p id="app_api_msg" style="color: #eb8600;">The API must be enabled under <a data-tab-destination="tabs-access_control" style="cursor: pointer;">Access Control</a> to use the app.</p>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div id="plexpy-mobile-devices-table" class="col-md-6">
|
<div id="plexpy-mobile-devices-table" class="col-md-12">
|
||||||
<div class='text-muted'><i class="fa fa-refresh fa-spin"></i> Loading registered devices...</div>
|
<div class='text-muted'><i class="fa fa-refresh fa-spin"></i> Loading registered devices...</div>
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1429,26 +1429,28 @@
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<label>Instructions</label>
|
<label>Instructions</label>
|
||||||
<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
|
||||||
|
or manually enter the into into the app settings.
|
||||||
Make sure the PlexPy Address below is correct.
|
Make sure the PlexPy Address below is correct.
|
||||||
</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">
|
|
||||||
<p class="help-block" id="api_qr_localhost" style="display: none;">
|
<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.
|
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.
|
Please enter an internal or external IP address, or hostname or domain instead.
|
||||||
</p>
|
</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 via an externally address or manually enter the address above to generate the QR code for remote access.
|
||||||
</p>
|
</p>
|
||||||
<p class="help-block" id="api_qr_https" style="display: none;">
|
<p class="help-block" id="api_qr_https" style="display: none;">
|
||||||
Note: This URL is not secure. Requests between the app and the server will not be encrypted.
|
Note: This URL is not secure. Requests between the app and the server will not be encrypted.
|
||||||
Enable HTTPS to connect the app securely.
|
Enable HTTPS to connect the app securely.
|
||||||
</p>
|
</p>
|
||||||
|
<label>Device Token</label>
|
||||||
|
<input type="text" class="form-control" id="api_qr_token" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<input type="button" class="btn btn-bright" data-dismiss="modal" value="Cancel">
|
<input type="button" class="btn btn-bright" data-dismiss="modal" value="Cancel">
|
||||||
|
|
|
@ -540,7 +540,8 @@ def dbcheck():
|
||||||
# mobile_devices table :: This table keeps record of devices linked with the mobile app
|
# mobile_devices table :: This table keeps record of devices linked with the mobile app
|
||||||
c_db.execute(
|
c_db.execute(
|
||||||
'CREATE TABLE IF NOT EXISTS mobile_devices (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
'CREATE TABLE IF NOT EXISTS mobile_devices (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||||
'device_id TEXT NOT NULL UNIQUE, device_token TEXT, device_name TEXT, friendly_name TEXT)'
|
'device_id TEXT NOT NULL UNIQUE, device_token TEXT, device_name TEXT, friendly_name TEXT, '
|
||||||
|
'last_seen INTEGER)'
|
||||||
)
|
)
|
||||||
|
|
||||||
# tvmaze_lookup table :: This table keeps record of the TVmaze lookups
|
# tvmaze_lookup table :: This table keeps record of the TVmaze lookups
|
||||||
|
@ -1084,6 +1085,15 @@ def dbcheck():
|
||||||
logger.warn(u"Failed to recreate mobile_devices table.")
|
logger.warn(u"Failed to recreate mobile_devices table.")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Upgrade mobile_devices table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT last_seen FROM mobile_devices')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug(u"Altering database. Updating database table mobile_devices.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE mobile_devices ADD COLUMN last_seen INTEGER'
|
||||||
|
)
|
||||||
|
|
||||||
# Upgrade notifiers table from earlier versions
|
# Upgrade notifiers table from earlier versions
|
||||||
try:
|
try:
|
||||||
c_db.execute('SELECT custom_conditions FROM notifiers')
|
c_db.execute('SELECT custom_conditions FROM notifiers')
|
||||||
|
|
|
@ -89,11 +89,6 @@ class API2:
|
||||||
elif 'apikey' not in kwargs:
|
elif 'apikey' not in kwargs:
|
||||||
self._api_msg = 'Parameter apikey is required'
|
self._api_msg = 'Parameter apikey is required'
|
||||||
|
|
||||||
elif (kwargs.get('apikey', '') != plexpy.CONFIG.API_KEY and
|
|
||||||
kwargs.get('apikey', '') != mobile_app.TEMP_DEVICE_TOKEN and
|
|
||||||
not mobile_app.get_mobile_device_by_token(kwargs.get('apikey', ''))):
|
|
||||||
self._api_msg = 'Invalid apikey'
|
|
||||||
|
|
||||||
elif 'cmd' not in kwargs:
|
elif 'cmd' not in kwargs:
|
||||||
self._api_msg = 'Parameter cmd is required. Possible commands are: %s' % ', '.join(self._api_valid_methods)
|
self._api_msg = 'Parameter cmd is required. Possible commands are: %s' % ', '.join(self._api_valid_methods)
|
||||||
|
|
||||||
|
@ -108,18 +103,26 @@ class API2:
|
||||||
# Allow override for the api.
|
# Allow override for the api.
|
||||||
self._api_out_type = kwargs.pop('out_type', 'json')
|
self._api_out_type = kwargs.pop('out_type', 'json')
|
||||||
|
|
||||||
if ((self._api_apikey == plexpy.CONFIG.API_KEY or
|
if plexpy.CONFIG.API_ENABLED and not self._api_msg:
|
||||||
self._api_apikey == mobile_app.TEMP_DEVICE_TOKEN or
|
if self._api_apikey in (plexpy.CONFIG.API_KEY, mobile_app.TEMP_DEVICE_TOKEN):
|
||||||
mobile_app.get_mobile_device_by_token(self._api_apikey)) and
|
self._api_authenticated = True
|
||||||
plexpy.CONFIG.API_ENABLED and self._api_cmd in self._api_valid_methods):
|
|
||||||
self._api_authenticated = True
|
elif mobile_app.get_mobile_device_by_token(self._api_apikey):
|
||||||
self._api_msg = None
|
mobile_app.set_last_seen(self._api_apikey)
|
||||||
self._api_kwargs = kwargs
|
self._api_authenticated = True
|
||||||
elif self._api_cmd in ('get_apikey', 'docs', 'docs_md') and plexpy.CONFIG.API_ENABLED:
|
|
||||||
self._api_authenticated = True
|
else:
|
||||||
# Remove the old error msg
|
self._api_msg = 'Invalid apikey'
|
||||||
self._api_msg = None
|
|
||||||
self._api_kwargs = kwargs
|
if self._api_authenticated and self._api_cmd in self._api_valid_methods:
|
||||||
|
self._api_msg = None
|
||||||
|
self._api_kwargs = kwargs
|
||||||
|
|
||||||
|
elif not self._api_authenticated and self._api_cmd in ('get_apikey', 'docs', 'docs_md'):
|
||||||
|
self._api_authenticated = True
|
||||||
|
# Remove the old error msg
|
||||||
|
self._api_msg = None
|
||||||
|
self._api_kwargs = kwargs
|
||||||
|
|
||||||
if self._api_msg:
|
if self._api_msg:
|
||||||
logger.api_debug(u'PlexPy APIv2 :: %s.' % self._api_msg)
|
logger.api_debug(u'PlexPy APIv2 :: %s.' % self._api_msg)
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
import plexpy
|
import plexpy
|
||||||
import database
|
import database
|
||||||
import helpers
|
import helpers
|
||||||
|
@ -121,6 +123,19 @@ def delete_mobile_device(mobile_device_id=None):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def set_last_seen(device_token=None):
|
||||||
|
db = database.MonitorDatabase()
|
||||||
|
|
||||||
|
last_seen = int(time.time())
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = db.action('UPDATE mobile_devices SET last_seen = ? WHERE device_token = ?',
|
||||||
|
args=[last_seen, device_token])
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn(u"PlexPy MobileApp :: Failed to set last_seen time for device: %s." % e)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def blacklist_logger():
|
def blacklist_logger():
|
||||||
devices = get_mobile_devices()
|
devices = get_mobile_devices()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue