From 2b5543905afce5b0bb84789e6b9cf1330490c2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Thu, 29 Apr 2021 13:01:07 +0200 Subject: [PATCH] added "accesedByClient" property so we can check, from web, if local plugin is installed.... --- server/src/uds/REST/methods/client.py | 6 +++++- server/src/uds/models/user_service.py | 2 +- server/src/uds/web/views/service.py | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/server/src/uds/REST/methods/client.py b/server/src/uds/REST/methods/client.py index 4a59d754..f5b89412 100644 --- a/server/src/uds/REST/methods/client.py +++ b/server/src/uds/REST/methods/client.py @@ -38,7 +38,7 @@ from django.utils.translation import ugettext as _ from django.urls import reverse from uds.REST import Handler from uds.REST import RequestError -from uds.models import TicketStore +from uds.models import TicketStore, user from uds.models import User from uds.web.util import errors from uds.core.managers import cryptoManager, userServiceManager @@ -147,6 +147,10 @@ class Client(Handler): # userService.setConnectionSource(srcIp, hostname) # Store where we are accessing from so we can notify Service if not ip: raise ServiceNotReadyError + + # Set "accesedByClient" + userService.setProperty('accessedByClient', '1') + transportScript, signature, params = transportInstance.getEncodedTransportScript(userService, transport, ip, self._request.os, self._request.user, password, self._request) logger.debug('Signature: %s', signature) diff --git a/server/src/uds/models/user_service.py b/server/src/uds/models/user_service.py index 66bc07cf..1c4c4cd4 100644 --- a/server/src/uds/models/user_service.py +++ b/server/src/uds/models/user_service.py @@ -535,7 +535,7 @@ class UserService(UUIDModel): # pylint: disable=too-many-public-methods dct[v.name] = v.value return dct - def setProperty(self, propName: str, propValue: typing.Optional[str]) -> None: + def setProperty(self, propName: str, propValue: typing.Optional[str] = None) -> None: prop, _ = self.properties.get_or_create(name=propName) prop.value = propValue or '' prop.save() diff --git a/server/src/uds/web/views/service.py b/server/src/uds/web/views/service.py index 172722de..71e28561 100644 --- a/server/src/uds/web/views/service.py +++ b/server/src/uds/web/views/service.py @@ -163,6 +163,9 @@ def userServiceEnabler( 'password': password, } + # Ensure "client access" is removed on enable action... + userService.setProperty('accessedByClient', '0') + ticket = TicketStore.create(data) url = html.udsLink(request, ticket, scrambler) except ServiceNotReadyError as e: @@ -198,9 +201,14 @@ def userServiceStatus( request: 'ExtendedHttpRequestWithUser', idService: str, idTransport: str ) -> HttpResponse: ''' - Returns 'running' if not ready, or 'ready' if ready (as json) + Returns; + 'running' if not ready + 'ready' if is ready but not accesed by client + 'accessed' if ready and accesed by UDS client + Note: ''' ip: typing.Union[str, None, bool] + userService = None try: ( ip, @@ -217,7 +225,11 @@ def userServiceStatus( except Exception as e: ip = False - status = 'running' if ip is None else 'error' if ip is False else 'ready' + ready = 'ready' + if userService and userService.getProperty('accessedByClient') != '0': + ready = 'accessed' + + status = 'running' if ip is None else 'error' if ip is False else ready return HttpResponse( json.dumps({'status': status}), content_type='application/json'