1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-03-12 04:58:34 +03:00
This commit is contained in:
Adolfo Gómez 2021-06-16 14:34:57 +02:00
commit 7b0ad08685
6 changed files with 60 additions and 91 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

@ -130,7 +130,7 @@ class IPMachinesService(IPServiceBase):
else:
# Check that ips are valid
for v in values['ipList']:
if not net.isValidHost(v):
if not net.isValidHost(v.split(';')[0]): # Get only IP/hostname
raise IPServiceBase.ValidationException(gettext('Invalid value detected on servers list: "{}"').format(v))
self._ips = [
'{}~{}'.format(str(ip).strip(), i)
@ -269,7 +269,12 @@ class IPMachinesService(IPServiceBase):
IPMachineDeployed, userDeployment
)
theIP = IPServiceBase.getIp(assignableId)
theMAC = IPServiceBase.getMac(assignableId)
if self.storage.readData(theIP) is None:
self.storage.saveData(theIP, theIP)
if theMAC:
theIP += ';' + theMAC
return userServiceInstance.assign(theIP)
return userServiceInstance.error('IP already assigned')

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))

View File

@ -186,6 +186,9 @@ def udsJs(request: 'ExtendedHttpRequest') -> str:
('udsclient3_{version}_all.deb', gettext('Debian based Linux client') + ' ' + gettext('(requires Python-3.6 or newer)'), 'Linux', False),
('udsclient3-{version}-1.noarch.rpm', gettext('RPM based Linux client (Fedora, Suse, ...)') + ' ' + gettext('(requires Python-3.6 or newer)'), 'Linux', False),
('udsclient3-{version}.tar.gz', gettext('Generic .tar.gz Linux client') + ' ' + gettext('(requires Python-3.6 or newer)'), 'Linux', False),
('udsclient3-x86_64-{version}.tar.gz', gettext('Binary appimage X86_64 Linux client'), 'Linux', False),
('udsclient3-armhf-{version}.tar.gz', gettext('Binary appimage Raspberry Linux client'), 'Linux', False),
('udsclient3-{version}.tar.gz', gettext('Generic .tar.gz Linux client') + ' ' + gettext('(requires Python-3.6 or newer)'), 'Linux', False),
('udsclient_{version}_all.deb', gettext('Legacy Debian based Python 2.7 Linux client') + ' ' + gettext('(requires outdated Python-2.7)'), 'Linux', True),
('udsclient-{version}-1.noarch.rpm', gettext('Legacy RH based Linux client (Fedora, Centos, Suse, ...)') + ' ' + gettext('(requires outdated Python-2.7)'), 'Linux', True),
('udsclient-opensuse-{version}-1.noarch.rpm', gettext('Legacy OpenSuse based Linux client)') + ' ' + gettext('(requires outdated Python-2.7)'), 'Linux', True),

View File

@ -137,6 +137,7 @@ async def getServerStats(detailed: bool = False) -> None:
# Context for local connection (ignores cert hostname)
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE # For ServerStats, do not checks certificate
try:
host = cfg.listen_address if cfg.listen_address != '0.0.0.0' else 'localhost'