forked from shaba/openuds
* Fixed an issue with tunneled transport for NX
* Some minor code fixes
This commit is contained in:
parent
0c0ec581c0
commit
85a32cf667
@ -49,8 +49,9 @@ from uds.core.util.State import State
|
||||
from uds.models import User
|
||||
|
||||
import logging
|
||||
import six
|
||||
|
||||
__updated__ = '2014-11-02'
|
||||
__updated__ = '2014-11-11'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
authLogger = logging.getLogger('authLog')
|
||||
@ -67,7 +68,7 @@ def getUDSCookie(request, response=None, force=False):
|
||||
if 'uds' not in request.COOKIES:
|
||||
import random
|
||||
import string
|
||||
cookie = ''.join(random.choice(string.letters + string.digits) for _ in xrange(32))
|
||||
cookie = ''.join(random.choice(string.letters + string.digits) for _ in range(32)) # @UndefinedVariable
|
||||
if response is not None:
|
||||
response.set_cookie('uds', cookie)
|
||||
request.COOKIES['uds'] = cookie
|
||||
|
@ -45,10 +45,11 @@ from uds.core.util import log
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
|
||||
import logging
|
||||
import six
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
OT_USERSERVICE, OT_PUBLICATION, OT_DEPLOYED_SERVICE, OT_SERVICE, OT_PROVIDER, OT_USER, OT_GROUP, OT_AUTHENTICATOR = xrange(8)
|
||||
OT_USERSERVICE, OT_PUBLICATION, OT_DEPLOYED_SERVICE, OT_SERVICE, OT_PROVIDER, OT_USER, OT_GROUP, OT_AUTHENTICATOR = range(8) # @UndefinedVariable
|
||||
|
||||
# Dict for translations
|
||||
transDict = {
|
||||
|
@ -41,7 +41,7 @@ logger = logging.getLogger(__name__)
|
||||
useLogger = logging.getLogger('useLog')
|
||||
|
||||
# Logging levels
|
||||
OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (10000 * (x + 1) for x in six.moves.xrange(6)) # @UndefinedVariable
|
||||
OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (10000 * (x + 1) for x in range(6)) # @UndefinedVariable
|
||||
|
||||
# Logging sources
|
||||
INTERNAL, ACTOR, TRANSPORT, OSMANAGER, UNKNOWN, WEB, ADMIN, SERVICE = ('internal', 'actor', 'transport', 'osmanager', 'unknown', 'web', 'admin', 'service')
|
||||
|
@ -102,7 +102,7 @@ def networksFromString(strNets, allowMultipleNetworks=True):
|
||||
|
||||
def maskFromBits(nBits):
|
||||
v = 0
|
||||
for n in xrange(nBits):
|
||||
for n in range(nBits):
|
||||
v |= 1 << (31 - n)
|
||||
return v
|
||||
|
||||
|
@ -36,13 +36,14 @@ import cairo
|
||||
import pycha.line
|
||||
import StringIO
|
||||
import time
|
||||
import six
|
||||
|
||||
from uds.models import getSqlDatetime
|
||||
|
||||
import counters
|
||||
|
||||
# Chart types
|
||||
CHART_TYPE_LINE, CHART_TYPE_AREA, CHART_TYPE_BAR = xrange(3)
|
||||
CHART_TYPE_LINE, CHART_TYPE_AREA, CHART_TYPE_BAR = range(3) # @UndefinedVariable
|
||||
|
||||
__typeTitles = None
|
||||
|
||||
@ -55,7 +56,7 @@ def make(obj, counterType, **kwargs):
|
||||
to = kwargs.get('to', None)
|
||||
if since is None and to is None:
|
||||
interval = kwargs.get('interval', None)
|
||||
if interval is not None:
|
||||
if interval is not None:
|
||||
to = getSqlDatetime()
|
||||
since = to - datetime.timedelta(days=interval)
|
||||
|
||||
|
@ -36,6 +36,7 @@ from uds.models import NEVER
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from uds.core.managers import statsManager
|
||||
import datetime
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -45,7 +46,7 @@ logger = logging.getLogger(__name__)
|
||||
# FIRST_COUNTER_TYPE, LAST_COUNTER_TYPE are just a placeholder for sanity checks
|
||||
(
|
||||
CT_LOAD, CT_STORAGE, CT_ASSIGNED, CT_INUSE,
|
||||
) = xrange(4)
|
||||
) = range(4)
|
||||
|
||||
__caRead = None
|
||||
__caWrite = None
|
||||
@ -190,7 +191,7 @@ def _initializeData():
|
||||
return res
|
||||
return ()
|
||||
|
||||
OT_PROVIDER, OT_SERVICE, OT_DEPLOYED = xrange(3)
|
||||
OT_PROVIDER, OT_SERVICE, OT_DEPLOYED = range(3)
|
||||
|
||||
# Dict to convert objects to owner types
|
||||
# Dict for translations
|
||||
|
@ -41,12 +41,16 @@ from uds.core.util.Cache import Cache
|
||||
from uds.core.util import connection
|
||||
from web import generateHtmlForNX, getHtmlComponent
|
||||
|
||||
import logging, random, string, time
|
||||
import logging
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
READY_CACHE_TIMEOUT = 30
|
||||
|
||||
|
||||
class TSNXTransport(Transport):
|
||||
'''
|
||||
Provides access via RDP to service.
|
||||
@ -66,13 +70,17 @@ class TSNXTransport(Transport):
|
||||
fixedName = gui.TextField(label=_('Username'), order=4, tooltip=_('If not empty, this username will be always used as credential'))
|
||||
fixedPassword = gui.PasswordField(label=_('Password'), order=5, tooltip=_('If not empty, this password will be always used as credential'))
|
||||
listenPort = gui.NumericField(label=_('Listen port'), length=5, order=6, tooltip=_('Listening port of NX (ssh) at client machine'), defvalue='22')
|
||||
connection = gui.ChoiceField(label=_('Connection'), order=7, tooltip=_('Connection speed for this transport (quality)'), values=[
|
||||
{'id' : 'modem', 'text' : 'modem'},
|
||||
{'id' : 'isdn', 'text' : 'isdn'},
|
||||
{'id' : 'adsl', 'text' : 'adsl'},
|
||||
{'id' : 'wan', 'text' : 'wan'},
|
||||
{'id' : 'lan', 'text' : 'lan'},
|
||||
])
|
||||
connection = gui.ChoiceField(label=_('Connection'),
|
||||
order=7,
|
||||
tooltip=_('Connection speed for this transport (quality)'),
|
||||
values=[
|
||||
{'id': 'modem', 'text': 'modem'},
|
||||
{'id': 'isdn', 'text': 'isdn'},
|
||||
{'id': 'adsl', 'text': 'adsl'},
|
||||
{'id': 'wan', 'text': 'wan'},
|
||||
{'id': 'lan', 'text': 'lan'},
|
||||
]
|
||||
)
|
||||
session = gui.ChoiceField(label=_('Session'), order=8, tooltip=_('Desktop session'), values=[
|
||||
{'id' : 'gnome', 'text' : 'gnome'},
|
||||
{'id' : 'kde', 'text' : 'kde'},
|
||||
@ -95,7 +103,6 @@ class TSNXTransport(Transport):
|
||||
{'id' : '128', 'text' : '128 Mb'},
|
||||
])
|
||||
|
||||
|
||||
def __init__(self, environment, values=None):
|
||||
super(TSNXTransport, self).__init__(environment, values)
|
||||
if values != None:
|
||||
@ -136,13 +143,19 @@ class TSNXTransport(Transport):
|
||||
self._useEmptyCreds = gui.strToBool(data[1])
|
||||
self._fixedName, self._fixedPassword, self._listenPort, self._connection, self._session, self._cacheDisk, self._cacheMem, self._tunnelServer, self._tunnelCheckServer = data[2:]
|
||||
|
||||
|
||||
def valuesDict(self):
|
||||
return { 'useEmptyCreds' : gui.boolToStr(self._useEmptyCreds), 'fixedName' : self._fixedName,
|
||||
'fixedPassword' : self._fixedPassword, 'listenPort': self._listenPort,
|
||||
'connection' : self._connection, 'session' : self._session, 'cacheDisk' : self._cacheDisk,
|
||||
'cacheMem' : self._cacheMem, 'tunnelServer' : self._tunnelServer,
|
||||
'tunnelCheckServer' : self._tunnelCheckServer }
|
||||
return {
|
||||
'useEmptyCreds': gui.boolToStr(self._useEmptyCreds),
|
||||
'fixedName': self._fixedName,
|
||||
'fixedPassword': self._fixedPassword,
|
||||
'listenPort': self._listenPort,
|
||||
'connection': self._connection,
|
||||
'session': self._session,
|
||||
'cacheDisk': self._cacheDisk,
|
||||
'cacheMem': self._cacheMem,
|
||||
'tunnelServer': self._tunnelServer,
|
||||
'tunnelCheckServer': self._tunnelCheckServer
|
||||
}
|
||||
|
||||
def isAvailableFor(self, ip):
|
||||
'''
|
||||
@ -177,9 +190,8 @@ class TSNXTransport(Transport):
|
||||
width, height = CommonPrefs.getWidthHeight(prefs)
|
||||
cache = Cache('pam')
|
||||
|
||||
|
||||
tunuser = ''.join(random.choice(string.letters + string.digits) for i in xrange(12)) + ("%f" % time.time()).split('.')[1]
|
||||
tunpass = ''.join(random.choice(string.letters + string.digits) for i in xrange(12))
|
||||
tunuser = ''.join(random.choice(string.letters + string.digits) for _ in range(12)) + ("%f" % time.time()).split('.')[1]
|
||||
tunpass = ''.join(random.choice(string.letters + string.digits) for _ in range(12))
|
||||
cache.put(tunuser, tunpass, 60 * 10) # Credential valid for ten minutes, and for 1 use only
|
||||
|
||||
sshHost, sshPort = self._tunnelServer.split(':')
|
||||
@ -188,15 +200,20 @@ class TSNXTransport(Transport):
|
||||
tun = "{0} {1} {2} {3} {4} {5} {6}".format(tunuser, tunpass, sshHost, sshPort, ip, self._listenPort, '9')
|
||||
|
||||
# Extra data
|
||||
extra = { 'width': width, 'height' : height,
|
||||
'connection' : self._connection,
|
||||
'session' : self._session, 'cacheDisk': self._cacheDisk,
|
||||
'cacheMem' : self._cacheMem, 'tun' : tun }
|
||||
extra = {
|
||||
'width': width,
|
||||
'height': height,
|
||||
'connection': self._connection,
|
||||
'session': self._session,
|
||||
'cacheDisk': self._cacheDisk,
|
||||
'cacheMem': self._cacheMem,
|
||||
'tun': tun
|
||||
}
|
||||
|
||||
# Fix username/password acording to os manager
|
||||
username, password = userService.processUserPassword(username, password)
|
||||
|
||||
return generateHtmlForNX(self, idUserService, idTransport, os, username, password, extra)
|
||||
return generateHtmlForNX(self, idUserService, idTransport, ip, os, username, password, extra)
|
||||
|
||||
def getHtmlComponent(self, theId, os, componentId):
|
||||
# We use helper to keep this clean
|
||||
|
@ -39,12 +39,16 @@ from uds.core.util import connection
|
||||
from uds.core.util.Cache import Cache
|
||||
from web import generateHtmlForRdp, getHtmlComponent
|
||||
|
||||
import logging, random, string, time
|
||||
import logging
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
READY_CACHE_TIMEOUT = 30
|
||||
|
||||
|
||||
class TSRDPTransport(Transport):
|
||||
'''
|
||||
Provides access via RDP to service.
|
||||
@ -72,7 +76,7 @@ class TSRDPTransport(Transport):
|
||||
|
||||
def __init__(self, environment, values=None):
|
||||
super(TSRDPTransport, self).__init__(environment, values)
|
||||
if values != None:
|
||||
if values is not None:
|
||||
if values['tunnelServer'].count(':') != 1:
|
||||
raise Transport.ValidationException(_('Must use HOST:PORT in Tunnel Server Field'))
|
||||
self._tunnelServer = values['tunnelServer']
|
||||
@ -136,11 +140,20 @@ class TSRDPTransport(Transport):
|
||||
self._withoutDomain = gui.strToBool(data[11 + i])
|
||||
|
||||
def valuesDict(self):
|
||||
return { 'allowSmartcards' : gui.boolToStr(self._allowSmartcards), 'allowPrinters' : gui.boolToStr(self._allowPrinters),
|
||||
'allowDrives': gui.boolToStr(self._allowDrives), 'allowSerials': gui.boolToStr(self._allowSerials),
|
||||
'fixedName' : self._fixedName, 'fixedPassword' : self._fixedPassword, 'fixedDomain' : self._fixedDomain,
|
||||
'useEmptyCreds' : gui.boolToStr(self._useEmptyCreds), 'tunnelServer' : self._tunnelServer,
|
||||
'tunnelCheckServer' : self._tunnelCheckServer, 'wallpaper': self._wallPaper, 'withoutDomain': gui.boolToStr(self._withoutDomain) }
|
||||
return {
|
||||
'allowSmartcards': gui.boolToStr(self._allowSmartcards),
|
||||
'allowPrinters': gui.boolToStr(self._allowPrinters),
|
||||
'allowDrives': gui.boolToStr(self._allowDrives),
|
||||
'allowSerials': gui.boolToStr(self._allowSerials),
|
||||
'fixedName': self._fixedName,
|
||||
'fixedPassword': self._fixedPassword,
|
||||
'fixedDomain': self._fixedDomain,
|
||||
'useEmptyCreds': gui.boolToStr(self._useEmptyCreds),
|
||||
'tunnelServer': self._tunnelServer,
|
||||
'tunnelCheckServer': self._tunnelCheckServer,
|
||||
'wallpaper': self._wallPaper,
|
||||
'withoutDomain': gui.boolToStr(self._withoutDomain)
|
||||
}
|
||||
|
||||
def isAvailableFor(self, ip):
|
||||
'''
|
||||
@ -190,8 +203,8 @@ class TSRDPTransport(Transport):
|
||||
depth = CommonPrefs.getDepth(prefs)
|
||||
cache = Cache('pam')
|
||||
|
||||
tunuser = ''.join(random.choice(string.letters + string.digits) for i in xrange(12)) + ("%f" % time.time()).split('.')[1]
|
||||
tunpass = ''.join(random.choice(string.letters + string.digits) for i in xrange(12))
|
||||
tunuser = ''.join(random.choice(string.letters + string.digits) for i in range(12)) + ("%f" % time.time()).split('.')[1]
|
||||
tunpass = ''.join(random.choice(string.letters + string.digits) for i in range(12))
|
||||
cache.put(tunuser, tunpass, 60 * 10) # Credential valid for ten minutes, and for 1 use only
|
||||
|
||||
sshHost, sshPort = self._tunnelServer.split(':')
|
||||
@ -201,10 +214,18 @@ class TSRDPTransport(Transport):
|
||||
ip = '127.0.0.1'
|
||||
|
||||
# Extra data
|
||||
extra = { 'width': width, 'height' : height, 'depth' : depth,
|
||||
'printers' : self._allowPrinters, 'smartcards' : self._allowSmartcards,
|
||||
'drives' : self._allowDrives, 'serials' : self._allowSerials,
|
||||
'tun': tun, 'compression':True, 'wallpaper': self._wallPaper }
|
||||
extra = {
|
||||
'width': width,
|
||||
'height' : height,
|
||||
'depth': depth,
|
||||
'printers': self._allowPrinters,
|
||||
'smartcards': self._allowSmartcards,
|
||||
'drives': self._allowDrives,
|
||||
'serials': self._allowSerials,
|
||||
'tun': tun,
|
||||
'compression': True,
|
||||
'wallpaper': self._wallPaper
|
||||
}
|
||||
|
||||
# Fix username/password acording to os manager
|
||||
username, password = userService.processUserPassword(username, password)
|
||||
|
@ -178,8 +178,8 @@ class TSNXTransport(Transport):
|
||||
cache = Cache('pam')
|
||||
|
||||
|
||||
tunuser = ''.join(random.choice(string.letters + string.digits) for i in xrange(12)) + ("%f" % time.time()).split('.')[1]
|
||||
tunpass = ''.join(random.choice(string.letters + string.digits) for i in xrange(12))
|
||||
tunuser = ''.join(random.choice(string.letters + string.digits) for i in range(12)) + ("%f" % time.time()).split('.')[1]
|
||||
tunpass = ''.join(random.choice(string.letters + string.digits) for i in range(12))
|
||||
cache.put(tunuser, tunpass, 60 * 10) # Credential valid for ten minutes, and for 1 use only
|
||||
|
||||
sshHost, sshPort = self._tunnelServer.split(':')
|
||||
|
@ -52,22 +52,23 @@ def transformId(view_func):
|
||||
To use this decorator, the view must receive 'response' and 'id' and (optionaly) 'id2', 'id3'
|
||||
example: def view(response, id)
|
||||
'''
|
||||
|
||||
@wraps(view_func)
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
import errors
|
||||
from uds.web import errors
|
||||
for k in kwargs.keys():
|
||||
if k[:2] == 'id':
|
||||
try:
|
||||
kwargs[k] = unscrambleId(request, kwargs[k])
|
||||
except:
|
||||
except Exception:
|
||||
return errors.errorView(request, errors.INVALID_REQUEST)
|
||||
return view_func(request, *args, **kwargs)
|
||||
return _wrapped_view
|
||||
|
||||
|
||||
def scrambleId(request, id_):
|
||||
if request.session.get(SCRAMBLE_SES) == None:
|
||||
request.session[SCRAMBLE_SES] = ''.join(random.choice(string.letters) for _ in xrange(SCRAMBLE_LEN))
|
||||
if request.session.get(SCRAMBLE_SES) is None:
|
||||
request.session[SCRAMBLE_SES] = ''.join(random.choice(string.letters) for _ in range(SCRAMBLE_LEN))
|
||||
return base64.b64encode(unicode(id_) + request.session.get(SCRAMBLE_SES)).encode('hex')
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user