forked from shaba/openuds
Refactorized transport to adapt parameter typing
This commit is contained in:
parent
11b56571d2
commit
d5eafb1179
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2012-2021 Virtual Cable S.L.U.
|
||||
# Copyright (c) 2012-2022 Virtual Cable S.L.U.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -43,7 +43,7 @@ from uds.core.util import net
|
||||
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
from uds.core.environment import Environment
|
||||
from uds import models
|
||||
|
||||
@ -210,7 +210,7 @@ class Transport(Module):
|
||||
os: typing.Dict[str, str],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
|
||||
"""
|
||||
If this is an uds transport, this will return the tranport script needed for executing
|
||||
@ -244,7 +244,7 @@ class Transport(Module):
|
||||
os: typing.Dict[str, str],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> typing.Tuple[str, str, typing.Mapping[str, str]]:
|
||||
"""
|
||||
Encodes the script so the client can understand it
|
||||
@ -270,7 +270,7 @@ class Transport(Module):
|
||||
os: typing.Dict[str, str],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> str:
|
||||
"""
|
||||
Must override if transport does provides its own link
|
||||
|
35
server/src/uds/osmanagers/Test/__init__.py
Normal file
35
server/src/uds/osmanagers/Test/__init__.py
Normal file
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2022 Virtual Cable S.L.U.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * 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
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from django.utils.translation import gettext_noop as _
|
||||
|
||||
from .testing_osmanager import TestOsManager
|
||||
|
BIN
server/src/uds/osmanagers/Test/osmanger.png
Normal file
BIN
server/src/uds/osmanagers/Test/osmanger.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
160
server/src/uds/osmanagers/Test/testing_osmanager.py
Normal file
160
server/src/uds/osmanagers/Test/testing_osmanager.py
Normal file
@ -0,0 +1,160 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2012-2019 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * 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
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
import logging
|
||||
import typing
|
||||
|
||||
from django.utils.translation import gettext_noop as _, gettext_lazy
|
||||
|
||||
from uds.core.services import types as serviceTypes
|
||||
from uds.core.ui import gui
|
||||
from uds.core import osmanagers
|
||||
from uds.core.util.state import State
|
||||
from uds.core.util import log
|
||||
from uds.core.managers import userServiceManager
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds.models.user_service import UserService
|
||||
from uds.core.module import Module
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestOsManager(osmanagers.OSManager):
|
||||
typeName = _('Test OS Manager')
|
||||
typeType = 'TestOsManager'
|
||||
typeDescription = _('Os Manager for testing pourposes')
|
||||
iconFile = 'osmanager.png'
|
||||
|
||||
servicesType = serviceTypes.ALL
|
||||
|
||||
onLogout = gui.ChoiceField(
|
||||
label=_('Logout Action'),
|
||||
order=10,
|
||||
rdonly=True,
|
||||
tooltip=_('What to do when user logs out from service'),
|
||||
values=[
|
||||
{'id': 'keep', 'text': gettext_lazy('Keep service assigned')},
|
||||
{'id': 'remove', 'text': gettext_lazy('Remove service')},
|
||||
{
|
||||
'id': 'keep-always',
|
||||
'text': gettext_lazy('Keep service assigned even on new publication'),
|
||||
},
|
||||
],
|
||||
defvalue='keep',
|
||||
)
|
||||
|
||||
idle = gui.NumericField(
|
||||
label=_("Max.Idle time"),
|
||||
length=4,
|
||||
defvalue=-1,
|
||||
rdonly=False,
|
||||
order=11,
|
||||
tooltip=_(
|
||||
'Maximum idle time (in seconds) before session is automatically closed to the user (<= 0 means no max. idle time)'
|
||||
),
|
||||
required=True,
|
||||
)
|
||||
|
||||
def initialize(self, values: 'Module.ValuesType'):
|
||||
self.processUnusedMachines = True
|
||||
|
||||
def release(self, userService: 'UserService') -> None:
|
||||
logger.debug('User service %s released', userService)
|
||||
|
||||
def isRemovableOnLogout(self, userService: 'UserService') -> bool:
|
||||
'''
|
||||
Says if a machine is removable on logout
|
||||
'''
|
||||
if not userService.in_use:
|
||||
if (self.onLogout.value == 'remove') or (
|
||||
not userService.isValidPublication() and self.onLogout.value == 'keep'
|
||||
):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def getName(self, userService: 'UserService') -> str:
|
||||
"""
|
||||
gets name from deployed
|
||||
"""
|
||||
return userService.getName()
|
||||
|
||||
def doLog(self, service, data, origin=log.OSMANAGER):
|
||||
# Stores a log associated with this service
|
||||
try:
|
||||
msg, level = data.split('\t')
|
||||
try:
|
||||
level = int(level)
|
||||
except Exception:
|
||||
logger.debug('Do not understand level %s', level)
|
||||
level = log.INFO
|
||||
log.doLog(service, level, msg, origin)
|
||||
except Exception:
|
||||
log.doLog(service, log.ERROR, "do not understand {0}".format(data), origin)
|
||||
|
||||
def actorData(
|
||||
self, userService: 'UserService'
|
||||
) -> typing.MutableMapping[str, typing.Any]:
|
||||
return {'action': 'rename', 'name': userService.getName()}
|
||||
|
||||
def processUnused(self, userService: 'UserService') -> None:
|
||||
"""
|
||||
This will be invoked for every assigned and unused user service that has been in this state at least 1/2 of Globalconfig.CHECK_UNUSED_TIME
|
||||
This function can update userService values. Normal operation will be remove machines if this state is not valid
|
||||
"""
|
||||
if self.isRemovableOnLogout(userService):
|
||||
log.doLog(
|
||||
userService,
|
||||
log.INFO,
|
||||
'Unused user service for too long. Removing due to OS Manager parameters.',
|
||||
log.OSMANAGER,
|
||||
)
|
||||
userService.remove()
|
||||
|
||||
def isPersistent(self):
|
||||
return self.onLogout.value == 'keep-always'
|
||||
|
||||
def checkState(self, userService: 'UserService') -> str:
|
||||
logger.debug('Checking state for service %s', userService)
|
||||
return State.RUNNING
|
||||
|
||||
def maxIdle(self) -> typing.Optional[int]:
|
||||
"""
|
||||
On production environments, will return no idle for non removable machines
|
||||
"""
|
||||
if (
|
||||
self.idle.value <= 0
|
||||
): # or (settings.DEBUG is False and self._onLogout != 'remove'):
|
||||
return None
|
||||
|
||||
return self.idle.value
|
@ -141,28 +141,6 @@ class WindowsOsManager(osmanagers.OSManager):
|
||||
def getName(self, userService: 'UserService') -> str:
|
||||
return userService.getName()
|
||||
|
||||
def infoVal(self, userService: 'UserService') -> str:
|
||||
return 'rename:' + self.getName(userService)
|
||||
|
||||
def infoValue(self, userService: 'UserService') -> str:
|
||||
return 'rename\r' + self.getName(userService)
|
||||
|
||||
def notifyIp(
|
||||
self, uid: str, userService, data: typing.Dict[str, typing.Any]
|
||||
) -> None:
|
||||
userServiceInstance = userService.getInstance()
|
||||
|
||||
ip = ''
|
||||
# Notifies IP to deployed
|
||||
for p in data['ips']:
|
||||
if p[0].lower() == uid.lower():
|
||||
userServiceInstance.setIp(p[1])
|
||||
ip = p[1]
|
||||
break
|
||||
|
||||
self.logKnownIp(userService, ip)
|
||||
userService.updateData(userServiceInstance)
|
||||
|
||||
def doLog(self, userService: 'UserService', data: str, origin=log.OSMANAGER):
|
||||
# Stores a log associated with this service
|
||||
try:
|
||||
|
@ -48,7 +48,7 @@ from uds import models
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds.core import Module
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -406,7 +406,7 @@ class HTML5RDPTransport(transports.Transport):
|
||||
'domain': domain,
|
||||
}
|
||||
|
||||
def getLink( # pylint: disable=too-many-locals
|
||||
def getLink(
|
||||
self,
|
||||
userService: 'models.UserService',
|
||||
transport: 'models.Transport',
|
||||
@ -414,7 +414,7 @@ class HTML5RDPTransport(transports.Transport):
|
||||
os: typing.Dict[str, str],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> str:
|
||||
credsInfo = self.getConnectionInfo(userService, user, password)
|
||||
username, password, domain = (
|
||||
|
@ -47,7 +47,7 @@ from uds import models
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds.core import Module
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -201,7 +201,7 @@ class HTML5VNCTransport(transports.Transport):
|
||||
self.cache.put(ip, 'N', READY_CACHE_TIMEOUT)
|
||||
return ready == 'Y'
|
||||
|
||||
def getLink( # pylint: disable=too-many-locals
|
||||
def getLink(
|
||||
self,
|
||||
userService: 'models.UserService',
|
||||
transport: 'models.Transport',
|
||||
@ -209,7 +209,7 @@ class HTML5VNCTransport(transports.Transport):
|
||||
os: typing.Dict[str, str],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> str:
|
||||
# Build params dict
|
||||
params = {
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2012-2021 Virtual Cable S.L.U.
|
||||
# Copyright (c) 2012-2022 Virtual Cable S.L.U.
|
||||
# All rights reservem.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -41,7 +41,7 @@ from .rdp_file import RDPFile
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds import models
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -101,7 +101,7 @@ class RDPTransport(BaseRDPTransport):
|
||||
os: typing.Dict[str, typing.Any],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
|
||||
# We use helper to keep this clean
|
||||
# prefs = user.prefs('rdp')
|
||||
@ -170,8 +170,8 @@ class RDPTransport(BaseRDPTransport):
|
||||
}
|
||||
|
||||
if osName == 'windows':
|
||||
if password != '':
|
||||
r.password = '{password}'
|
||||
if password:
|
||||
r.password = '{password}' # nosec: no hardcoded password
|
||||
sp.update(
|
||||
{
|
||||
'as_file': r.as_file,
|
||||
|
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2012-2021 Virtual Cable S.L.U.
|
||||
# Copyright (c) 2012-2022 Virtual Cable S.L.U.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -47,7 +47,7 @@ from .rdp_file import RDPFile
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds import models
|
||||
from uds.core import Module
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -144,7 +144,7 @@ class TRDPTransport(BaseRDPTransport):
|
||||
os: typing.Dict[str, typing.Any],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
|
||||
# We use helper to keep this clean
|
||||
# prefs = user.prefs('rdp')
|
||||
@ -220,8 +220,8 @@ class TRDPTransport(BaseRDPTransport):
|
||||
}
|
||||
|
||||
if osName == 'windows':
|
||||
if password != '':
|
||||
r.password = '{password}'
|
||||
if password:
|
||||
r.password = '{password}' # nosec: no hardcoded password
|
||||
sp.update(
|
||||
{
|
||||
'as_file': r.as_file,
|
||||
|
@ -32,4 +32,4 @@
|
||||
"""
|
||||
|
||||
from .spice import SPICETransport
|
||||
from .spice_tunnel import TSPICETransport
|
||||
from .spicetunnel import TSPICETransport
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2012-2019 Virtual Cable S.L.
|
||||
# Copyright (c) 2012-2022 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.
|
||||
#
|
||||
@ -41,7 +41,7 @@ from .remote_viewer_file import RemoteViewerFile
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds import models
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -74,7 +74,7 @@ class SPICETransport(BaseSpiceTransport):
|
||||
os: typing.Dict[str, typing.Any],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
|
||||
userServiceInstance: typing.Any = userService.getInstance()
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2012-2021 Virtual Cable S.L.U.
|
||||
# Copyright (c) 2012-2022 Virtual Cable S.L.U.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -47,7 +47,7 @@ from .remote_viewer_file import RemoteViewerFile
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds import models
|
||||
from uds.core import Module
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -114,7 +114,7 @@ class TSPICETransport(BaseSpiceTransport):
|
||||
os: typing.Dict[str, typing.Any],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
|
||||
userServiceInstance: typing.Any = userService.getInstance()
|
||||
|
34
server/src/uds/transports/Test/__init__.py
Normal file
34
server/src/uds/transports/Test/__init__.py
Normal file
@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2022 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * 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
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
|
||||
from .transport import TestTransport
|
BIN
server/src/uds/transports/Test/transport.png
Normal file
BIN
server/src/uds/transports/Test/transport.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
128
server/src/uds/transports/Test/transport.py
Normal file
128
server/src/uds/transports/Test/transport.py
Normal file
@ -0,0 +1,128 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2022 Virtual Cable S.L.U.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * 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.U. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
import logging
|
||||
import typing
|
||||
|
||||
from django.utils.translation import gettext_noop as _
|
||||
|
||||
from uds.core.ui import gui
|
||||
|
||||
from uds.core import transports
|
||||
|
||||
from uds.core.util import os_detector as OsDetector
|
||||
from uds.core.managers import cryptoManager
|
||||
from uds import models
|
||||
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds.core import Module
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestTransport(transports.Transport):
|
||||
"""
|
||||
Provides access via RDP 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
|
||||
"""
|
||||
|
||||
typeName = _('URL Launcher')
|
||||
typeType = 'URLTransport'
|
||||
typeDescription = _('Launchs an external UDS customized URL')
|
||||
iconFile = 'url.png'
|
||||
|
||||
ownLink = True
|
||||
supportedOss = OsDetector.allOss
|
||||
protocol = transports.protocols.OTHER
|
||||
group = transports.DIRECT_GROUP
|
||||
|
||||
testURL = gui.TextField(
|
||||
label=_('URL Pattern'),
|
||||
order=1,
|
||||
tooltip=_('URL Pattern to open (i.e. https://_IP_/test?user=_USER_'),
|
||||
defvalue='https://www.udsenterprise.com',
|
||||
length=256,
|
||||
required=True,
|
||||
)
|
||||
|
||||
forceNewWindow = gui.CheckBoxField(
|
||||
label=_('Force new HTML Window'),
|
||||
order=91,
|
||||
tooltip=_(
|
||||
'If checked, every connection will try to open its own window instead of reusing the "global" one.'
|
||||
),
|
||||
defvalue=gui.FALSE,
|
||||
tab=gui.ADVANCED_TAB,
|
||||
)
|
||||
|
||||
def initialize(self, values: 'Module.ValuesType'):
|
||||
if not values:
|
||||
return
|
||||
# Strip spaces
|
||||
if not (
|
||||
self.testURL.value.startswith('http://')
|
||||
or self.testURL.value.startswith('https://')
|
||||
):
|
||||
raise transports.Transport.ValidationException(
|
||||
_('The url must be http or https')
|
||||
)
|
||||
|
||||
# Same check as normal RDP transport
|
||||
def isAvailableFor(self, userService: 'models.UserService', ip: str) -> bool:
|
||||
# No check is done for URL transport
|
||||
return True
|
||||
|
||||
def getLink(
|
||||
self,
|
||||
userService: 'models.UserService',
|
||||
transport: 'models.Transport',
|
||||
ip: str,
|
||||
os: typing.Dict[str, str],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> str:
|
||||
|
||||
# Fix username/password acording to os manager
|
||||
username: str = user.getUsernameForAuth()
|
||||
username, password = userService.processUserPassword(username, password)
|
||||
|
||||
url = self.testURL.value.replace('_IP_', ip).replace('_USER_', username)
|
||||
|
||||
onw = (
|
||||
'&o_n_w={}'.format(hash(transport.name))
|
||||
if self.forceNewWindow.isTrue()
|
||||
else ''
|
||||
)
|
||||
return str("{}{}".format(url, onw))
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2012-2019 Virtual Cable S.L.
|
||||
# Copyright (c) 2012-202 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.
|
||||
#
|
||||
|
@ -34,21 +34,18 @@ import logging
|
||||
import typing
|
||||
|
||||
from django.utils.translation import gettext_noop as _
|
||||
from django.urls import reverse
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
from uds.core.ui import gui
|
||||
|
||||
from uds.core import transports
|
||||
|
||||
from uds.core.util import os_detector as OsDetector
|
||||
from uds.core.managers import cryptoManager
|
||||
from uds import models
|
||||
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds.core import Module
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -105,7 +102,7 @@ class URLCustomTransport(transports.Transport):
|
||||
# No check is done for URL transport
|
||||
return True
|
||||
|
||||
def getLink( # pylint: disable=too-many-locals
|
||||
def getLink(
|
||||
self,
|
||||
userService: 'models.UserService',
|
||||
transport: 'models.Transport',
|
||||
@ -113,7 +110,7 @@ class URLCustomTransport(transports.Transport):
|
||||
os: typing.Dict[str, str],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> str:
|
||||
|
||||
# Fix username/password acording to os manager
|
||||
|
@ -34,4 +34,4 @@
|
||||
from django.utils.translation import gettext_noop as _
|
||||
from uds.core.managers.user_preferences import UserPrefsManager, CommonPrefs
|
||||
from .x2go import X2GOTransport
|
||||
from .x2go_tunnel import TX2GOTransport
|
||||
from .x2gotunnel import TX2GOTransport
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2016-2021 Virtual Cable S.L.U.
|
||||
# Copyright (c) 2016-2022 Virtual Cable S.L.U.
|
||||
# All rights reservem.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -41,7 +41,7 @@ from . import x2go_file
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds import models
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -78,7 +78,7 @@ class X2GOTransport(BaseX2GOTransport):
|
||||
os: typing.Dict[str, typing.Any],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
|
||||
ci = self.getConnectionInfo(userService, user, password)
|
||||
username = ci['username']
|
||||
|
@ -46,7 +46,7 @@ from . import x2go_file
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds import models
|
||||
from uds.core import Module
|
||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||
from uds.core.util.request import ExtendedHttpRequestWithUser
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -121,7 +121,7 @@ class TX2GOTransport(BaseX2GOTransport):
|
||||
os: typing.Dict[str, typing.Any],
|
||||
user: 'models.User',
|
||||
password: str,
|
||||
request: 'HttpRequest',
|
||||
request: 'ExtendedHttpRequestWithUser',
|
||||
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
|
||||
|
||||
ci = self.getConnectionInfo(userService, user, password)
|
Loading…
x
Reference in New Issue
Block a user