added "accesedByClient" property so we can check, from web, if local plugin is installed....

This commit is contained in:
Adolfo Gómez García 2021-04-29 13:01:07 +02:00
parent 87c2ea8add
commit 2b5543905a
3 changed files with 20 additions and 4 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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'