1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-25 23:21:41 +03:00

Adding support for custom connection userServices data for RDP

This commit is contained in:
Adolfo Gómez García 2021-01-28 13:09:43 +01:00
parent 99d3393a33
commit caf1d5d825
13 changed files with 46 additions and 31 deletions

View File

@ -160,7 +160,7 @@ class Transport(Module):
userService: typing.Union['models.UserService', 'models.ServicePool'],
user: 'models.User',
password: str
) -> typing.Dict[str, str]:
) -> typing.Mapping[str, str]:
"""
This method must provide information about connection.
We don't have to implement it, but if we wont to allow some types of connections
@ -203,7 +203,7 @@ class Transport(Module):
user: 'models.User',
password: str,
request: 'HttpRequest'
) -> typing.Tuple[str, str, typing.Dict[str, typing.Any]]:
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
"""
If this is an uds transport, this will return the tranport script needed for executing
this on client
@ -234,7 +234,7 @@ class Transport(Module):
user: 'models.User',
password: str,
request: 'HttpRequest'
) -> typing.Tuple[str, str, typing.Dict[str, str]]:
) -> typing.Tuple[str, str, typing.Mapping[str, str]]:
"""
Encodes the script so the client can understand it
"""

View File

@ -368,11 +368,11 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
and self.fallbackAccess == states.action.DENY
):
nextE = CalendarChecker(ac.calendar).nextEvent(chkDateTime, False)
if deadLine is None or deadLine > nextE:
if not deadLine or (nextE and deadLine > nextE):
deadLine = nextE
elif ac.access == states.action.DENY: # DENY
nextE = CalendarChecker(ac.calendar).nextEvent(chkDateTime, True)
if deadLine is None or deadLine > nextE:
if not deadLine or (nextE and deadLine > nextE):
deadLine = nextE
if deadLine is None:

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012-2019 Virtual Cable S.L.
# Copyright (c) 2012-2021 Virtual Cable S.L.U.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,

View File

@ -199,7 +199,7 @@ class NXTransport(BaseNXTransport):
user: 'models.User',
password: str,
request: 'HttpRequest'
) -> typing.Tuple[str, str, typing.Dict[str, typing.Any]]:
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
username = user.getUsernameForAuth()
proc = username.split('@')
username = proc[0]

View File

@ -302,7 +302,7 @@ class TSNXTransport(BaseNXTransport):
user: 'models.User',
password: str,
request: 'HttpRequest',
) -> typing.Tuple[str, str, typing.Dict[str, typing.Any]]:
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
prefs = self.screenSize.value
username = user.getUsernameForAuth()

View File

@ -98,7 +98,7 @@ class RDPTransport(BaseRDPTransport):
user: 'models.User',
password: str,
request: 'HttpRequest'
) -> typing.Tuple[str, str, typing.Dict[str, typing.Any]]:
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
# We use helper to keep this clean
# prefs = user.prefs('rdp')
@ -151,7 +151,7 @@ class RDPTransport(BaseRDPTransport):
logger.error('Os not detected for RDP Transport: %s', request.META.get('HTTP_USER_AGENT', 'Unknown'))
return super().getUDSTransportScript(userService, transport, ip, os, user, password, request)
sp = {
sp: typing.MutableMapping[str, typing.Any] = {
'password': password,
'this_server': request.build_absolute_uri('/'),
'ip': ip,

View File

@ -37,6 +37,7 @@ import typing
from django.utils.translation import ugettext_noop as _
from uds.core.ui import gui
from uds.core import transports
from uds.models import UserService
# TODO: do this
def createADUser():
@ -313,22 +314,26 @@ class BaseRDPTransport(transports.Transport):
def processedUser(
self, userService: 'models.UserService', user: 'models.User'
) -> str:
v = self.processUserPassword(userService, user, '')
v = self.processUserPassword(userService, user, '', altUsername=None)
return v['username']
def processUserPassword(
self, userService: 'models.UserService', user: 'models.User', password: 'str'
) -> typing.Dict[str, typing.Any]:
username = user.getUsernameForAuth()
self,
userService: 'models.UserService',
user: 'models.User',
password: str,
*,
altUsername: typing.Optional[str]
) -> typing.Mapping[str, str]:
username: str = altUsername or user.getUsernameForAuth()
if self.fixedName.value:
username = self.fixedName.value
proc = username.split('@')
domain: str = ''
if len(proc) > 1:
domain = proc[1]
else:
domain = ''
username = proc[0]
if self.fixedPassword.value:
@ -362,7 +367,7 @@ class BaseRDPTransport(transports.Transport):
'protocol': self.protocol,
'username': username,
'password': password,
'domain': domain,
'domain': domain
}
def getConnectionInfo(
@ -370,14 +375,24 @@ class BaseRDPTransport(transports.Transport):
userService: typing.Union['models.UserService', 'models.ServicePool'],
user: 'models.User',
password: str,
) -> typing.Dict[str, str]:
) -> typing.Mapping[str, str]:
username = None
if isinstance(userService, UserService):
cdata = userService.getInstance().getConnectionData()
if cdata:
_, username, password = cdata # Host is unused
return self.processUserPassword(
typing.cast('models.UserService', userService), user, password
typing.cast('models.UserService', userService), user, password, altUsername=username
)
def getScript(
self, scriptNameTemplate: str, osName: str, params: typing.Dict[str, typing.Any]
) -> typing.Tuple[str, str, typing.Dict[str, typing.Any]]:
self,
scriptNameTemplate: str,
osName: str,
params: typing.Mapping[str, typing.Any],
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
# Reads script
scriptNameTemplate = scriptNameTemplate.format(osName)
with open(os.path.join(os.path.dirname(__file__), scriptNameTemplate)) as f:

View File

@ -145,7 +145,7 @@ class TRDPTransport(BaseRDPTransport):
user: 'models.User',
password: str,
request: 'HttpRequest',
) -> typing.Tuple[str, str, typing.Dict[str, typing.Any]]:
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
# We use helper to keep this clean
# prefs = user.prefs('rdp')
@ -207,7 +207,7 @@ class TRDPTransport(BaseRDPTransport):
userService, transport, ip, os, user, password, request
)
sp = {
sp: typing.MutableMapping[str, typing.Any] = {
'tunHost': tunHost,
'tunPort': tunPort,
'tunWait': self.tunnelWait.num(),

View File

@ -73,7 +73,7 @@ class SPICETransport(BaseSpiceTransport):
user: 'models.User',
password: str,
request: 'HttpRequest'
) -> typing.Tuple[str, str, typing.Dict[str, typing.Any]]:
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
userServiceInstance: typing.Any = userService.getInstance()
con = userServiceInstance.getConsoleConnection()

View File

@ -117,7 +117,7 @@ class TSPICETransport(BaseSpiceTransport):
user: 'models.User',
password: str,
request: 'HttpRequest',
) -> typing.Tuple[str, str, typing.Dict[str, typing.Any]]:
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
userServiceInstance: typing.Any = userService.getInstance()
# Spice connection

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012-2019 Virtual Cable S.L.
# Copyright (c) 2012-2021 Virtual Cable S.L.U.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
@ -12,7 +12,7 @@
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# * Neither the name of Virtual Cable S.L.U. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2019 Virtual Cable S.L.
# Copyright (c) 2016-2021 Virtual Cable S.L.U.
# All rights reservem.
#
# Redistribution and use in source and binary forms, with or without modification,
@ -12,7 +12,7 @@
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# * Neither the name of Virtual Cable S.L.U. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
@ -77,7 +77,7 @@ class X2GOTransport(BaseX2GOTransport):
user: 'models.User',
password: str,
request: 'HttpRequest'
) -> typing.Tuple[str, str, typing.Dict[str, typing.Any]]:
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
ci = self.getConnectionInfo(userService, user, password)
username = ci['username']

View File

@ -126,7 +126,7 @@ class TX2GOTransport(BaseX2GOTransport):
user: 'models.User',
password: str,
request: 'HttpRequest',
) -> typing.Tuple[str, str, typing.Dict[str, typing.Any]]:
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
ci = self.getConnectionInfo(userService, user, password)
username = ci['username']