1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-12 09:17:56 +03:00

* User preferences is deprecated (to be removed)

* NX is disabled in code (to be removed on 4.0)
* Increeased URL size for "URL" transport to 256 (was 64 only)
This commit is contained in:
Adolfo Gómez García 2021-06-15 11:49:16 +02:00
parent 41c94913f8
commit 69fe9e0d38
3 changed files with 50 additions and 90 deletions

View File

@ -37,14 +37,14 @@ import typing
from django import forms
from django.utils.translation import ugettext as _, ugettext_lazy
from uds.core.ui import gui
if typing.TYPE_CHECKING:
from uds.models import User
logger = logging.getLogger(__name__)
# UserPrefs is DEPRECATED
# Currently not used anywhere
class UserPrefsManager:
_manager: typing.Optional['UserPrefsManager'] = None
_prefs: typing.Dict[str, typing.Dict]
@ -73,7 +73,7 @@ class UserPrefsManager:
"""
# logger.debug('Self prefs: %s', self._prefs)
prefs = {}
for up in user.preferences.filter(module=modName):
for up in user.preferences.filter(module=modName): # type: ignore
prefs[up.name] = up.value
for p in self._prefs[modName]['prefs']:
if p.getName() not in prefs:
@ -83,14 +83,14 @@ class UserPrefsManager:
def setPreferenceForUser(self, user: 'User', modName: str, prefName: str, value: str):
try:
user.preferences.create(module=modName, name=prefName, value=value)
user.preferences.create(module=modName, name=prefName, value=value) # type: ignore
except Exception: # Already exits, update it
user.preferences.filter(module=modName, name=prefName).update(value=value)
user.preferences.filter(module=modName, name=prefName).update(value=value) # type: ignore
def getHtmlForUserPreferences(self, user: 'User'):
# First fill data for all preferences
data = {}
for up in user.preferences.all().order_by('module'):
for up in user.preferences.all().order_by('module'): # type: ignore
data[self.__nameFor(up.module, up.name)] = up.value
res = ''
for mod, v in sorted(self._prefs.items()):
@ -190,57 +190,6 @@ class UserPreference(object):
return None
class UserTextPreference(UserPreference):
TYPE = 'text'
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._length = kwargs.get('length', None)
def formField(self, value):
return forms.CharField(label=_(self._label), initial=value, attrs={'class': self._css})
class UserNumericPreference(UserPreference):
TYPE = 'numeric'
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._min = kwargs.get('minvalue', None)
self._max = kwargs.get('maxvalue', None)
def formField(self, value):
return forms.IntegerField(label=_(self._label), initial=value, min_value=self._min, max_value=self._max,
widget=forms.TextInput(attrs={'class': self._css})) # pylint: disable=unexpected-keyword-arg, no-value-for-parameter
class UserChoicePreference(UserPreference):
TYPE = 'choice'
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._values = kwargs['values']
def formField(self, value):
return forms.ChoiceField(label=_(self._label), initial=value, choices=self._values,
widget=forms.Select(attrs={'class': self._css})) # pylint: disable=unexpected-keyword-arg, no-value-for-parameter
def guiField(self, value):
vals = []
for v in self._values:
vals.append({'id': v[0], 'text': _(v[1])})
return gui.ChoiceField(label=_(self._label), rdonly=False, values=vals, defvalue=value, tooltip=_(self._label))
class UserCheckboxPreference(UserPreference):
TYPE = 'checkbox'
def formField(self, value):
if value is None:
value = False
logger.debug('Value type: %s', type(value))
return forms.BooleanField(label=_(self._label), initial=value)
class CommonPrefs(object):
SZ_PREF = 'screenSize'

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,
@ -30,13 +30,13 @@
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
# Disabled OLD NX. Will be removed soon
from django.utils.translation import ugettext_noop as _
# from django.utils.translation import ugettext_noop as _
# from uds.core.managers.user_preferences import UserPrefsManager, CommonPrefs
# from uds.core.util.config import Config
# from .nxtransport import NXTransport
# from .nxtunneltransport import TSNXTransport
from uds.core.managers.user_preferences import UserPrefsManager, CommonPrefs
from uds.core.util.config import Config
from .nxtransport import NXTransport
from .nxtunneltransport import TSNXTransport
Config.section('NX').value('downloadUrl', 'http://sourceforge.net/projects/opennx/files/opennx/CI-win32/OpenNX-0.16.0.725-Setup.exe/download').get()
Config.section('NX').value('downloadUrlMACOS', 'http://opennx.net/download.html').get()
# Config.section('NX').value('downloadUrl', 'http://sourceforge.net/projects/opennx/files/opennx/CI-win32/OpenNX-0.16.0.725-Setup.exe/download').get()
# Config.section('NX').value('downloadUrlMACOS', 'http://opennx.net/download.html').get()

View File

@ -58,6 +58,7 @@ class URLCustomTransport(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')
@ -68,22 +69,36 @@ class URLCustomTransport(transports.Transport):
protocol = transports.protocols.OTHER
group = transports.DIRECT_GROUP
urlPattern = 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=64, required=True)
urlPattern = 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.'),
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
tab=gui.ADVANCED_TAB,
)
def initialize(self, values: 'Module.ValuesType'):
if not values:
return
# Strip spaces
if not (self.urlPattern.value.startswith('http://') or self.urlPattern.value.startswith('https://')):
raise transports.Transport.ValidationException(_('The url must be http or https'))
if not (
self.urlPattern.value.startswith('http://')
or self.urlPattern.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:
@ -91,29 +106,25 @@ class URLCustomTransport(transports.Transport):
return True
def getLink( # pylint: disable=too-many-locals
self,
userService: 'models.UserService',
transport: 'models.Transport',
ip: str,
os: typing.Dict[str, str],
user: 'models.User',
password: str,
request: 'HttpRequest'
) -> str:
self,
userService: 'models.UserService',
transport: 'models.Transport',
ip: str,
os: typing.Dict[str, str],
user: 'models.User',
password: str,
request: 'HttpRequest',
) -> str:
# Fix username/password acording to os manager
username: str = user.getUsernameForAuth()
username, password = userService.processUserPassword(username, password)
url = (
self.urlPattern.value.replace('_IP_', ip)
.replace('_USERNAME_', username)
)
url = self.urlPattern.value.replace('_IP_', ip).replace('_USERNAME_', username)
onw = '&o_n_w={}'.format(hash(transport.name)) if self.forceNewWindow.isTrue() else ''
return str(
"{}{}".format(
url,
onw
)
onw = (
'&o_n_w={}'.format(hash(transport.name))
if self.forceNewWindow.isTrue()
else ''
)
return str("{}{}".format(url, onw))