1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-25 06:03:51 +03:00

Refactoring some transports, better code

This commit is contained in:
Adolfo Gómez García 2023-02-14 15:52:18 +01:00
parent 6165d2db15
commit 22116aba27
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
9 changed files with 63 additions and 93 deletions

View File

@ -100,7 +100,7 @@ class Login(Handler):
Linux = 'Linux' Linux = 'Linux'
WindowsPhone = 'Windows Phone' WindowsPhone = 'Windows Phone'
Windows = 'Windows' Windows = 'Windows'
Macintosh = 'Mac' Macintosh = 'MacOsX'
Android = 'Android' Android = 'Android'
iPad = 'iPad' iPad = 'iPad'
iPhone = 'iPhone' iPhone = 'iPhone'

View File

@ -49,18 +49,20 @@ class KnownOS(enum.Enum):
ChromeOS = ('CrOS',) ChromeOS = ('CrOS',)
WindowsPhone = ('Windows Phone',) WindowsPhone = ('Windows Phone',)
Windows = ('Windows',) Windows = ('Windows',)
Macintosh = ('Mac',) MacOS = ('MacOsX',)
Android = ('Android',) Android = ('Android',)
iPad = ('iPad',) # iPad = ('iPad',) #
iPhone = ('iPhone',) # In fact, these are IOS both, but we can diferentiate them iPhone = ('iPhone',) # In fact, these are IOS both, but we can diferentiate them
WYSE = ('WYSE',) WYSE = ('WYSE',)
Unknown = ('Unknown',) Unknown = ('Unknown',)
def os_name(self):
return self.value[0].lower()
knownOss = tuple(os for os in KnownOS if os != KnownOS.Unknown) knownOss = tuple(os for os in KnownOS if os != KnownOS.Unknown)
allOss = knownOss + (KnownOS.Unknown,) allOss = knownOss + (KnownOS.Unknown,)
desktopOss = (KnownOS.Linux, KnownOS.Windows, KnownOS.Macintosh) desktopOss = (KnownOS.Linux, KnownOS.Windows, KnownOS.MacOS)
mobilesODD = list(set(allOss) - set(desktopOss)) mobilesODD = list(set(allOss) - set(desktopOss))

View File

@ -34,7 +34,7 @@ import logging
import typing import typing
from django.utils.translation import gettext_noop as _ from django.utils.translation import gettext_noop as _
from uds.core.util import os_detector as OsDetector from uds.core.util import os_detector
from .rdp_base import BaseRDPTransport from .rdp_base import BaseRDPTransport
from .rdp_file import RDPFile from .rdp_file import RDPFile
@ -43,7 +43,6 @@ if typing.TYPE_CHECKING:
from uds import models from uds import models
from uds.core import transports from uds.core import transports
from uds.core.util.request import ExtendedHttpRequestWithUser from uds.core.util.request import ExtendedHttpRequestWithUser
from uds.core.util.os_detector import DetectedOsInfo
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -101,7 +100,7 @@ class RDPTransport(BaseRDPTransport):
userService: 'models.UserService', userService: 'models.UserService',
transport: 'models.Transport', transport: 'models.Transport',
ip: str, ip: str,
os: 'DetectedOsInfo', os: 'os_detector.DetectedOsInfo',
user: 'models.User', user: 'models.User',
password: str, password: str,
request: 'ExtendedHttpRequestWithUser', request: 'ExtendedHttpRequestWithUser',
@ -147,21 +146,6 @@ class RDPTransport(BaseRDPTransport):
r.enforcedShares = self.enforceDrives.value r.enforcedShares = self.enforceDrives.value
r.redirectUSB = self.usbRedirection.value r.redirectUSB = self.usbRedirection.value
osName = {
OsDetector.KnownOS.Windows: 'windows',
OsDetector.KnownOS.Linux: 'linux',
OsDetector.KnownOS.Macintosh: 'macosx',
}.get(os.os)
if osName is None:
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: typing.MutableMapping[str, typing.Any] = { sp: typing.MutableMapping[str, typing.Any] = {
'password': password, 'password': password,
'this_server': request.build_absolute_uri('/'), 'this_server': request.build_absolute_uri('/'),
@ -170,7 +154,7 @@ class RDPTransport(BaseRDPTransport):
'address': r.address, 'address': r.address,
} }
if osName == 'windows': if os == os_detector.KnownOS.Windows:
r.customParameters = self.customParametersWindows.value r.customParameters = self.customParametersWindows.value
if password: if password:
r.password = '{password}' # nosec: password is not hardcoded r.password = '{password}' # nosec: password is not hardcoded
@ -179,7 +163,7 @@ class RDPTransport(BaseRDPTransport):
'as_file': r.as_file, 'as_file': r.as_file,
} }
) )
elif osName == 'linux': elif os == os_detector.KnownOS.Linux:
r.customParameters = self.customParameters.value r.customParameters = self.customParameters.value
sp.update( sp.update(
{ {
@ -187,7 +171,7 @@ class RDPTransport(BaseRDPTransport):
'address': r.address, 'address': r.address,
} }
) )
else: # Mac elif os == os_detector.KnownOS.MacOS:
r.customParameters = self.customParametersMAC.value r.customParameters = self.customParametersMAC.value
sp.update( sp.update(
{ {
@ -197,5 +181,13 @@ class RDPTransport(BaseRDPTransport):
'address': r.address, 'address': r.address,
} }
) )
else:
logger.error(
'Os not valid for RDP Transport: %s',
request.META.get('HTTP_USER_AGENT', 'Unknown'),
)
return super().getUDSTransportScript(
userService, transport, ip, os, user, password, request
)
return self.getScript(osName, 'direct', sp) return self.getScript(os.os.os_name(), 'direct', sp)

View File

@ -90,7 +90,7 @@ class RDPFile:
if self.target in ( if self.target in (
OsDetector.KnownOS.Windows, OsDetector.KnownOS.Windows,
OsDetector.KnownOS.Linux, OsDetector.KnownOS.Linux,
OsDetector.KnownOS.Macintosh, OsDetector.KnownOS.MacOS,
): ):
return self.getGeneric() return self.getGeneric()
# Unknown target # Unknown target
@ -120,7 +120,7 @@ class RDPFile:
params.append('/smartcard') params.append('/smartcard')
if self.redirectAudio: if self.redirectAudio:
if self.alsa and self.target != OsDetector.KnownOS.Macintosh: if self.alsa and self.target != OsDetector.KnownOS.MacOS:
params.append('/sound:sys:alsa,format:1,quality:high') params.append('/sound:sys:alsa,format:1,quality:high')
params.append('/microphone:sys:alsa') params.append('/microphone:sys:alsa')
else: else:
@ -132,7 +132,7 @@ class RDPFile:
params.append('/video') params.append('/video')
if self.redirectDrives != 'false': if self.redirectDrives != 'false':
if self.target in (OsDetector.KnownOS.Linux, OsDetector.KnownOS.Macintosh): if self.target in (OsDetector.KnownOS.Linux, OsDetector.KnownOS.MacOS):
params.append('/drive:home,$HOME') params.append('/drive:home,$HOME')
else: else:
params.append('/drive:Users,/Users') params.append('/drive:Users,/Users')
@ -158,7 +158,7 @@ class RDPFile:
params.append('/multimon') params.append('/multimon')
if self.fullScreen: if self.fullScreen:
if self.target != OsDetector.KnownOS.Macintosh: if self.target != OsDetector.KnownOS.MacOS:
params.append('/f') params.append('/f')
else: # On mac, will fix this later... else: # On mac, will fix this later...
params.append('/w:#WIDTH#') params.append('/w:#WIDTH#')

View File

@ -36,7 +36,7 @@ from django.utils.translation import gettext_noop as _
from uds.core.ui import gui from uds.core.ui import gui
from uds.core import transports from uds.core import transports
from uds.models import TicketStore from uds.models import TicketStore
from uds.core.util import os_detector as OsDetector from uds.core.util import os_detector
from uds.core.util import validators from uds.core.util import validators
from .rdp_base import BaseRDPTransport from .rdp_base import BaseRDPTransport
@ -48,7 +48,6 @@ if typing.TYPE_CHECKING:
from uds import models from uds import models
from uds.core import Module from uds.core import Module
from uds.core.util.request import ExtendedHttpRequestWithUser from uds.core.util.request import ExtendedHttpRequestWithUser
from uds.core.util.os_detector import DetectedOsInfo
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -143,7 +142,7 @@ class TRDPTransport(BaseRDPTransport):
userService: 'models.UserService', userService: 'models.UserService',
transport: 'models.Transport', transport: 'models.Transport',
ip: str, ip: str,
os: 'DetectedOsInfo', os: 'os_detector.DetectedOsInfo',
user: 'models.User', user: 'models.User',
password: str, password: str,
request: 'ExtendedHttpRequestWithUser', request: 'ExtendedHttpRequestWithUser',
@ -198,17 +197,6 @@ class TRDPTransport(BaseRDPTransport):
r.enforcedShares = self.enforceDrives.value r.enforcedShares = self.enforceDrives.value
r.redirectUSB = self.usbRedirection.value r.redirectUSB = self.usbRedirection.value
osName = {
OsDetector.KnownOS.Windows: 'windows',
OsDetector.KnownOS.Linux: 'linux',
OsDetector.KnownOS.Macintosh: 'macosx',
}.get(os.os)
if osName is None:
return super().getUDSTransportScript(
userService, transport, ip, os, user, password, request
)
sp: typing.MutableMapping[str, typing.Any] = { sp: typing.MutableMapping[str, typing.Any] = {
'tunHost': tunHost, 'tunHost': tunHost,
'tunPort': tunPort, 'tunPort': tunPort,
@ -219,7 +207,7 @@ class TRDPTransport(BaseRDPTransport):
'this_server': request.build_absolute_uri('/'), 'this_server': request.build_absolute_uri('/'),
} }
if osName == 'windows': if os.os == os_detector.KnownOS.Windows:
r.customParameters = self.customParametersWindows.value r.customParameters = self.customParametersWindows.value
if password: if password:
r.password = '{password}' # nosec: password is not hardcoded r.password = '{password}' # nosec: password is not hardcoded
@ -228,14 +216,14 @@ class TRDPTransport(BaseRDPTransport):
'as_file': r.as_file, 'as_file': r.as_file,
} }
) )
elif osName == 'linux': elif os.os == os_detector.KnownOS.Linux:
r.customParameters = self.customParameters.value r.customParameters = self.customParameters.value
sp.update( sp.update(
{ {
'as_new_xfreerdp_params': r.as_new_xfreerdp_params, 'as_new_xfreerdp_params': r.as_new_xfreerdp_params,
} }
) )
else: # Mac elif os.os == os_detector.KnownOS.MacOS:
r.customParameters = self.customParametersMAC.value r.customParameters = self.customParametersMAC.value
sp.update( sp.update(
{ {
@ -244,5 +232,15 @@ class TRDPTransport(BaseRDPTransport):
'as_rdp_url': r.as_rdp_url if self.allowMacMSRDC.isTrue() else '', 'as_rdp_url': r.as_rdp_url if self.allowMacMSRDC.isTrue() else '',
} }
) )
else:
logger.error(
'Os not valid for RDP Transport: %s',
request.META.get('HTTP_USER_AGENT', 'Unknown'),
)
return super().getUDSTransportScript(
userService, transport, ip, os, user, password, request
)
return self.getScript(osName, 'tunnel', sp)
return self.getScript(os.os.os_name(), 'tunnel', sp)

View File

@ -113,17 +113,6 @@ class SPICETransport(BaseSpiceTransport):
r.smartcard = self.smartCardRedirect.isTrue() r.smartcard = self.smartCardRedirect.isTrue()
r.ssl_connection = self.sslConnection.isTrue() r.ssl_connection = self.sslConnection.isTrue()
osName = {
OsDetector.KnownOS.Windows: 'windows',
OsDetector.KnownOS.Linux: 'linux',
OsDetector.KnownOS.Macintosh: 'macosx',
}.get(os.os)
if osName is None:
return super().getUDSTransportScript(
userService, transport, ip, os, user, password, request
)
# if sso: # If SSO requested, and when supported by platform # if sso: # If SSO requested, and when supported by platform
# userServiceInstance.desktopLogin(user, password, '') # userServiceInstance.desktopLogin(user, password, '')
@ -131,4 +120,10 @@ class SPICETransport(BaseSpiceTransport):
'as_file': r.as_file, 'as_file': r.as_file,
} }
return self.getScript(osName, 'direct', sp) try:
return self.getScript(os.os.os_name(), 'direct', sp)
except Exception:
return super().getUDSTransportScript(
userService, transport, ip, os, user, password, request
)

View File

@ -188,17 +188,6 @@ class TSPICETransport(BaseSpiceTransport):
r.smartcard = self.smartCardRedirect.isTrue() r.smartcard = self.smartCardRedirect.isTrue()
r.ssl_connection = self.sslConnection.isTrue() r.ssl_connection = self.sslConnection.isTrue()
osName = {
OsDetector.KnownOS.Windows: 'windows',
OsDetector.KnownOS.Linux: 'linux',
OsDetector.KnownOS.Macintosh: 'macosx',
}.get(os.os)
if osName is None:
return super().getUDSTransportScript(
userService, transport, ip, os, user, password, request
)
# if sso: # If SSO requested, and when supported by platform # if sso: # If SSO requested, and when supported by platform
# userServiceInstance.desktopLogin(user, password, '') # userServiceInstance.desktopLogin(user, password, '')
@ -213,4 +202,9 @@ class TSPICETransport(BaseSpiceTransport):
'ticket_secure': ticket_secure, 'ticket_secure': ticket_secure,
} }
return self.getScript(osName, 'tunnel', sp) try:
return self.getScript(os.os.os_name(), 'tunnel', sp)
except Exception:
return super().getUDSTransportScript(
userService, transport, ip, os, user, password, request
)

View File

@ -53,6 +53,7 @@ class X2GOTransport(BaseX2GOTransport):
Provides access via X2GO to service. Provides access via X2GO to service.
This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password This transport can use an domain. If username processed by authenticator contains '@', it will split it and left-@-part will be username, and right password
""" """
isBase = False isBase = False
typeName = _('X2Go') typeName = _('X2Go')
@ -108,17 +109,11 @@ class X2GOTransport(BaseX2GOTransport):
user=username, user=username,
) )
osName = { sp = {'ip': ip, 'port': '22', 'key': priv, 'xf': xf}
OsDetector.KnownOS.Windows: 'windows',
OsDetector.KnownOS.Linux: 'linux',
# OsDetector.Macintosh: 'macosx'
}.get(os.os)
if osName is None: try:
return self.getScript(os.os.os_name(), 'tunnel', sp)
except Exception:
return super().getUDSTransportScript( return super().getUDSTransportScript(
userService, transport, ip, os, user, password, request userService, transport, ip, os, user, password, request
) )
sp = {'ip': ip, 'port': '22', 'key': priv, 'xf': xf}
return self.getScript(osName, 'direct', sp)

View File

@ -159,17 +159,6 @@ class TX2GOTransport(BaseX2GOTransport):
tunHost, tunPort = self.tunnelServer.value.split(':') tunHost, tunPort = self.tunnelServer.value.split(':')
osName = {
OsDetector.KnownOS.Windows: 'windows',
OsDetector.KnownOS.Linux: 'linux',
# OsDetector.Macintosh: 'macosx'
}.get(os.os)
if osName is None:
return super().getUDSTransportScript(
userService, transport, ip, os, user, password, request
)
sp = { sp = {
'tunHost': tunHost, 'tunHost': tunHost,
'tunPort': tunPort, 'tunPort': tunPort,
@ -180,4 +169,9 @@ class TX2GOTransport(BaseX2GOTransport):
'xf': xf, 'xf': xf,
} }
return self.getScript(osName, 'tunnel', sp) try:
return self.getScript(os.os.os_name(), 'tunnel', sp)
except Exception:
return super().getUDSTransportScript(
userService, transport, ip, os, user, password, request
)