mirror of
https://github.com/dkmstr/openuds.git
synced 2025-02-07 01:58:15 +03:00
Some fixes
This commit is contained in:
parent
2f272da073
commit
3f9f641f6a
2
actor
2
actor
@ -1 +1 @@
|
||||
Subproject commit c73dd33e2bcb8630a701e8465f99c8f118afde09
|
||||
Subproject commit 0f8936f81ed084809f048ac8c8036bb8da2d7550
|
@ -35,6 +35,8 @@ import time
|
||||
import typing
|
||||
import collections.abc
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
# from uds.core import VERSION
|
||||
from uds.core import consts, exceptions, osmanagers, types
|
||||
from uds.core.managers.crypto import CryptoManager
|
||||
@ -144,6 +146,19 @@ class ActorV3Action(Handler):
|
||||
def setCommsUrl(userService: UserService, ip: str, port: int, secret: str):
|
||||
userService.setCommsUrl(f'https://{ip}:{port}/actor/{secret}')
|
||||
|
||||
@staticmethod
|
||||
def actorCertResult(key: str, certificate: str, password: str) -> dict[str, typing.Any]:
|
||||
return ActorV3Action.actorResult(
|
||||
{
|
||||
'private_key': key, # To be removed on 5.0
|
||||
'key': key,
|
||||
'server_certificate': certificate, # To be removed on 5.0
|
||||
'certificate': certificate,
|
||||
'password': password,
|
||||
'ciphers': getattr(settings, 'SECURE_CIPHERS', None),
|
||||
}
|
||||
)
|
||||
|
||||
def getUserService(self) -> UserService:
|
||||
'''
|
||||
Looks for an userService and, if not found, raises a BlockAccess request
|
||||
@ -372,10 +387,10 @@ class Initialize(ActorV3Action):
|
||||
) -> dict[str, typing.Any]:
|
||||
return ActorV3Action.actorResult(
|
||||
{
|
||||
'own_token': own_token,
|
||||
'own_token': alias_token or own_token, # Compat with old actor versions, TBR on 5.0
|
||||
'token': alias_token or own_token, # New token, will be used from now onwards
|
||||
'unique_id': unique_id,
|
||||
'os': os,
|
||||
'alias_token': alias_token,
|
||||
}
|
||||
)
|
||||
|
||||
@ -494,13 +509,7 @@ class BaseReadyChange(ActorV3Action):
|
||||
userService.properties['priv'] = privateKey
|
||||
userService.properties['priv_passwd'] = password
|
||||
|
||||
return ActorV3Action.actorResult(
|
||||
{
|
||||
'private_key': privateKey,
|
||||
'server_certificate': cert,
|
||||
'password': password,
|
||||
}
|
||||
)
|
||||
return ActorV3Action.actorCertResult(privateKey, cert, password)
|
||||
|
||||
|
||||
class IpChange(BaseReadyChange):
|
||||
@ -568,11 +577,9 @@ class Login(ActorV3Action):
|
||||
# payload received
|
||||
# {
|
||||
# 'type': actor_type or types.MANAGED,
|
||||
# 'id': [{'mac': i.mac, 'ip': i.ip} for i in interfaces],
|
||||
# 'token': token,
|
||||
# 'username': username,
|
||||
# 'session_type': sessionType,
|
||||
# 'secret': secret or '',
|
||||
# }
|
||||
|
||||
@staticmethod
|
||||
@ -786,13 +793,9 @@ class Unmanaged(ActorV3Action):
|
||||
except StopIteration:
|
||||
ip = self._params['id'][0]['ip'] # Get first IP if no valid ip found
|
||||
|
||||
# Generates a certificate and send it to client.
|
||||
# Generates a certificate and send it to client (actor).
|
||||
privateKey, certificate, password = security.selfSignedCert(ip)
|
||||
cert: dict[str, str] = {
|
||||
'private_key': privateKey,
|
||||
'server_certificate': certificate,
|
||||
'password': password,
|
||||
}
|
||||
|
||||
if validId:
|
||||
# If id is assigned to an user service, notify "logout" to it
|
||||
if userService:
|
||||
@ -811,7 +814,7 @@ class Unmanaged(ActorV3Action):
|
||||
},
|
||||
)
|
||||
|
||||
return ActorV3Action.actorResult(cert)
|
||||
return ActorV3Action.actorCertResult(privateKey, certificate, password)
|
||||
|
||||
|
||||
class Notify(ActorV3Action):
|
||||
|
@ -112,9 +112,7 @@ class ServerManager(metaclass=singleton.Singleton):
|
||||
Returns a list of stats for a list of servers
|
||||
"""
|
||||
# Paralelize stats retrieval
|
||||
retrievedStats: list[
|
||||
tuple[typing.Optional['types.servers.ServerStats'], 'models.Server']
|
||||
] = []
|
||||
retrievedStats: list[tuple[typing.Optional['types.servers.ServerStats'], 'models.Server']] = []
|
||||
|
||||
def _retrieveStats(server: 'models.Server') -> None:
|
||||
try:
|
||||
@ -474,11 +472,6 @@ class ServerManager(metaclass=singleton.Singleton):
|
||||
# Sort by weight, lower first (lower is better)
|
||||
return [s[1] for s in sorted(serverStats, key=lambda x: x[0].weight() if x[0] else 999999999)]
|
||||
|
||||
return sorted(
|
||||
serverGroup.servers.filter(maintenance_mode=False),
|
||||
key=lambda x: self.getUnmanagedUsage(x.uuid),
|
||||
)
|
||||
|
||||
def doMaintenance(self, serverGroup: 'models.ServerGroup') -> None:
|
||||
"""Realizes maintenance on server group
|
||||
|
||||
|
@ -199,12 +199,6 @@ class Server(UUIDModel, TaggingMixin, properties.PropertiesMixin):
|
||||
related_name='servers',
|
||||
)
|
||||
|
||||
def parent(self) -> typing.Optional['Server']:
|
||||
"""
|
||||
Returns the parent group (not valid for Tunnel Servers, that can belong to more than one group)
|
||||
"""
|
||||
return self.groups.first()
|
||||
|
||||
class Meta: # pylint: disable=too-few-public-methods
|
||||
app_label = 'uds'
|
||||
|
||||
|
@ -56,11 +56,11 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
readonly=True,
|
||||
tooltip=_('What to do when user logs out from service'),
|
||||
choices=[
|
||||
{'id': 'keep', 'text': gettext_lazy('Keep service assigned')},
|
||||
{'id': 'remove', 'text': gettext_lazy('Remove service')},
|
||||
{'id': 'keep', 'text': typing.cast(str, gettext_lazy('Keep service assigned'))},
|
||||
{'id': 'remove', 'text': typing.cast(str, gettext_lazy('Remove service'))},
|
||||
{
|
||||
'id': 'keep-always',
|
||||
'text': gettext_lazy('Keep service assigned even on new publication'),
|
||||
'text': typing.cast(str, gettext_lazy('Keep service assigned even on new publication')),
|
||||
},
|
||||
],
|
||||
default='keep',
|
||||
@ -178,7 +178,7 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
|
||||
creds = {'username': username, 'password': password, 'domain': domain}
|
||||
ticket = TicketStore.create(
|
||||
creds, validatorFnc=None, validity=300
|
||||
creds,validity=300
|
||||
) # , owner=SECURE_OWNER, secure=True)
|
||||
return ticket, ''
|
||||
|
||||
|
@ -59,10 +59,13 @@ class IPMachinesService(IPServiceBase):
|
||||
# Gui
|
||||
token = gui.TextField(
|
||||
order=1,
|
||||
label=_('Service Token'),
|
||||
label=typing.cast(str, _('Service Token')),
|
||||
length=64,
|
||||
tooltip=_(
|
||||
'Service token that will be used by actors to communicate with service. Leave empty for persistent assignation.'
|
||||
tooltip=typing.cast(
|
||||
str,
|
||||
_(
|
||||
'Service token that will be used by actors to communicate with service. Leave empty for persistent assignation.'
|
||||
),
|
||||
),
|
||||
default='',
|
||||
required=False,
|
||||
@ -70,25 +73,27 @@ class IPMachinesService(IPServiceBase):
|
||||
)
|
||||
|
||||
ipList = gui.EditableListField(
|
||||
label=_('List of servers'),
|
||||
tooltip=_('List of servers available for this service'),
|
||||
label=typing.cast(str, _('List of servers')),
|
||||
tooltip=typing.cast(str, _('List of servers available for this service')),
|
||||
)
|
||||
|
||||
port = gui.NumericField(
|
||||
length=5,
|
||||
label=_('Check Port'),
|
||||
label=typing.cast(str, _('Check Port')),
|
||||
default=0,
|
||||
order=2,
|
||||
tooltip=_('If non zero, only hosts responding to connection on that port will be served.'),
|
||||
tooltip=typing.cast(
|
||||
str, _('If non zero, only hosts responding to connection on that port will be served.')
|
||||
),
|
||||
required=True,
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
)
|
||||
skipTimeOnFailure = gui.NumericField(
|
||||
length=6,
|
||||
label=_('Skip time'),
|
||||
label=typing.cast(str, _('Skip time')),
|
||||
default=0,
|
||||
order=2,
|
||||
tooltip=_('If a host fails to check, skip it for this time (in minutes).'),
|
||||
tooltip=typing.cast(str, _('If a host fails to check, skip it for this time (in minutes).')),
|
||||
minValue=0,
|
||||
required=True,
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
@ -96,35 +101,38 @@ class IPMachinesService(IPServiceBase):
|
||||
|
||||
maxSessionForMachine = gui.NumericField(
|
||||
length=3,
|
||||
label=_('Max session per machine'),
|
||||
label=typing.cast(str, _('Max session per machine')),
|
||||
default=0,
|
||||
order=3,
|
||||
tooltip=_(
|
||||
'Maximum session duration before UDS thinks this machine got locked and releases it (hours). 0 means "never".'
|
||||
tooltip=typing.cast(
|
||||
str,
|
||||
_(
|
||||
'Maximum session duration before UDS thinks this machine got locked and releases it (hours). 0 means "never".'
|
||||
),
|
||||
),
|
||||
minValue=0,
|
||||
required=True,
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
)
|
||||
lockByExternalAccess = gui.CheckBoxField(
|
||||
label=_('Lock machine by external access'),
|
||||
tooltip=_('If checked, UDS will lock the machine if it is accesed from outside UDS.'),
|
||||
label=typing.cast(str, _('Lock machine by external access')),
|
||||
tooltip=typing.cast(str, _('If checked, UDS will lock the machine if it is accesed from outside UDS.')),
|
||||
default=False,
|
||||
order=4,
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
)
|
||||
useRandomIp = gui.CheckBoxField(
|
||||
label=_('Use random IP'),
|
||||
tooltip=_('If checked, UDS will use a random IP from the list of servers.'),
|
||||
label=typing.cast(str, _('Use random IP')),
|
||||
tooltip=typing.cast(str, _('If checked, UDS will use a random IP from the list of servers.')),
|
||||
default=False,
|
||||
order=5,
|
||||
tab=types.ui.Tab.ADVANCED,
|
||||
)
|
||||
|
||||
# Description of service
|
||||
typeName = _('Static Multiple IP')
|
||||
typeName = typing.cast(str, _('Static Multiple IP'))
|
||||
typeType = 'IPMachinesService'
|
||||
typeDescription = _('This service provides access to POWERED-ON Machines by IP')
|
||||
typeDescription = typing.cast(str, _('This service provides access to POWERED-ON Machines by IP'))
|
||||
iconFile = 'machines.png'
|
||||
|
||||
usesCache = False # Cache are running machine awaiting to be assigned
|
||||
@ -136,7 +144,6 @@ class IPMachinesService(IPServiceBase):
|
||||
|
||||
servicesTypeProvided = types.services.ServiceType.VDI
|
||||
|
||||
|
||||
_ips: list[str] = []
|
||||
_token: str = ''
|
||||
_port: int = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user