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

Advancing on transports & client fixes

This commit is contained in:
Adolfo Gómez García 2015-04-14 08:33:10 +02:00
parent c3316a4745
commit 6b19e75ce7
6 changed files with 20 additions and 166 deletions

View File

@ -36,6 +36,7 @@ import tempfile
import string import string
import random import random
import os import os
import sys
import stat import stat
_unlinkFiles = [] _unlinkFiles = []
@ -54,8 +55,12 @@ def saveTempFile(content, filename=None):
return filename return filename
def findApp(appName): def findApp(appName, extraPath=None):
for path in os.environ['PATH'].split(os.pathsep): searchPath = os.environ['PATH'].split(os.pathsep)
if extraPath is not None:
searchPath += extraPath
for path in searchPath:
fileName = os.path.join(path, appName) fileName = os.path.join(path, appName)
if os.path.isfile(fileName) and (os.stat(fileName).st_mode & stat.S_IXUSR) != 0: if os.path.isfile(fileName) and (os.stat(fileName).st_mode & stat.S_IXUSR) != 0:
return fileName return fileName

View File

@ -163,7 +163,14 @@ class Transport(Module):
If this is an uds transport, this will return the tranport script needed for executing If this is an uds transport, this will return the tranport script needed for executing
this on client this on client
''' '''
return '' return '''
from __future__ import unicode_literals
# pylint: disable=import-error, no-name-in-module, too-many-format-args, undefined-variable, invalid-sequence-index
from PyQt4 import QtCore, QtGui
QtGui.QMessageBox.critical(parent, 'Not supported', 'The transport {transport.name} is not supported on your platform.', QtGui.QMessageBox.Ok)
'''.format(service=userService, transport=transport)
def getLink(self, userService, transport, ip, os, user, password, request): def getLink(self, userService, transport, ip, os, user, password, request):
''' '''
@ -172,41 +179,5 @@ class Transport(Module):
''' '''
return None return None
def renderAsHtml(self, userService, transport, ip, request):
os, user, password = OsDetector.getOsFromRequest(request), request.user, webPassword(request)
info = self.getUDSTransportInfo(userService, transport, ip, os, user, password, request)
if info is not None:
ticket = Ticket(data=info)
template = loader.get_template('uds/transport/udslink.html')
if request.is_secure():
uri = 'udss://'
else:
uri = 'uds://'
uri += request.build_absolute_uri('/').split('//')[1] # Remove http or https
uri += ticket.key
return template.render(context=Context({'ticket': ticket, 'request': request, 'uri': uri}))
return self.renderForHtml(userService, transport, ip, os, user, password)
def renderForHtml(self, userService, transport, ip, os, user, password):
'''
Requests the html rendering of connector for the destination ip, (dbUser) and password
@param: userService: UserService for witch we are rendering the connection (db model)
@param transport: Transport (self db model)
@param ip: ip of the destination
@param user: user (dbUser) logged in
@param pass: password used in authentication
'''
return _('Transport empty')
def getHtmlComponent(self, id, os, componentId): # @ReservedAssignment
'''
This is a method to let the transport add own components (images, applets, or whatever) to the rendered html
The reference to object will be the access to the uds.web.views.transcomp, with parameters transportId = ourTransportId and
componentId = one id recognized by this method
We expect an return array, with first parameter as mime/type and second the content to return
'''
return ['text/plain', '']
def __str__(self): def __str__(self):
return "Base OS Manager" return "Base OS Manager"

View File

@ -39,7 +39,6 @@ from .BaseRDPTransport import BaseRDPTransport
from .RDPFile import RDPFile from .RDPFile import RDPFile
import logging import logging
import os
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -140,7 +139,7 @@ class RDPTransport(BaseRDPTransport):
}.get(m.os) }.get(m.os)
if os == '': if os is None:
return '' # In fact, should return an error, but this will be fine right now return super(RDPTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request)
return self.getScript('scripts/{}/direct.py'.format(os)).format(m=m) return self.getScript('scripts/{}/direct.py'.format(os)).format(m=m)

View File

@ -165,7 +165,7 @@ class TSRDPTransport(BaseRDPTransport):
}.get(m.os) }.get(m.os)
if os == '': if os is None:
return '' # In fact, should return an error, but this will be fine right now return super(TSRDPTransport, self).getUDSTransportScript(self, userService, transport, ip, os, user, password, request)
return self.getScript('scripts/{}/tunnel.py'.format(os)).format(m=m) return self.getScript('scripts/{}/tunnel.py'.format(os)).format(m=m)

View File

@ -18,6 +18,6 @@ theFile = '''{m.r.as_file}'''.format(password=win32crypt.CryptProtectData(six.bi
filename = tools.saveTempFile(theFile) filename = tools.saveTempFile(theFile)
executable = tools.findApp('mstsc.exe') executable = tools.findApp('mstsc.exe')
subprocess.call([executable, filename]) subprocess.call([executable, filename])
# tools.addFileToUnlink(filename) tools.addFileToUnlink(filename)
# QtGui.QMessageBox.critical(parent, 'Notice', filename + ", " + executable, QtGui.QMessageBox.Ok) # QtGui.QMessageBox.critical(parent, 'Notice', filename + ", " + executable, QtGui.QMessageBox.Ok)

View File

@ -1,121 +0,0 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012 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 django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from uds.core.util import OsDetector
import logging
import os
import sys
logger = logging.getLogger(__name__)
def scramble(data):
'''
Simple scrambler so password are not seen at source page
'''
res = []
n = 0x32
for c in data[::-1]:
res.append(chr(ord(c) ^ n))
n = (n + ord(c)) & 0xFF
return "".join(res).encode('hex')
def generateHtmlForRdp(transport, idUserService, idTransport, os, ip, port, user, password, domain, extra):
isMac = os['OS'] == OsDetector.Macintosh
applet = reverse('uds.web.views.transcomp', kwargs={'idTransport': idTransport, 'componentId': '1'})
logger.debug('Applet: {0}'.format(applet))
# Gets the codebase, simply remove last char from applet
codebase = applet[:-1]
# We generate the "data" parameter
data = [
'u:' + user,
'p:' + password,
'd:' + domain,
's:' + ip,
'po:' + port,
'sc:' + (extra['smartcards'] and '1' or '0'),
'pr:' + (extra['printers'] and '1' or '0'),
'se:' + (extra['serials'] and '1' or '0'),
'dr:' + (extra['drives'] and '1' or '0'),
'au:' + '1', # Audio, 0 do not play, 1 play
'w:' + str(extra['width']),
'h:' + str(extra['height']),
'c:' + str(extra['depth']),
'cr:' + (extra['compression'] and '1' or '0'),
'is:' + idUserService,
'sw:' + (extra['wallpaper'] and '1' or '0'),
'mm:' + (extra['multimon'] and '1' or '0'),
]
logger.debug('Data: {0}'.format(data))
if 'tun' in extra:
data.append('tun:' + extra['tun'])
data = scramble('\t'.join(data))
res = '<div id="applet"><applet code="RdpApplet.class" codebase="%s" archive="%s" width="200" height="22"><param name="data" value="%s"/><param name="permissions" value="all-permissions"/></applet></div>' % (codebase, '1', data)
if isMac is True:
res += ('<div><p>' + _('In order to use this service, you should first install CoRD.') + '</p>'
'<p><a href="/static/other/CoRD.pkg">' + _('Download CoRD') + '</a></p>'
'</div>'
'<div>'
'<p>' + _('Attention Safari Users:') + '<br/>'
'<p>' + _('In order to access theese services, you will need to enable this in order to access to service:') + '</p>'
'<p>' + _('Go to Safari > Preferences > Security > Manage Website Settings') + '</p>'
'<p>' + _('Click Java in left hand panel, and select site to allow UDS Rdp, and set it to Allow Always (also mark "Unsecure mode").') + '</p>'
'<p>' + _('Users of Firefox or Chrome:') + '</p>'
'<p>' + _('If any warning is shown when launching RDP Applet, press "ignore" and continue') + '</p>'
'</div>'
)
return res
def getHtmlComponent(module, componentId):
filesDict = {
'1': ['rdp.jar', 'application/java-archive'],
'2': ['rdppass.dll', 'application/x-msdos-program'],
'3': ['launcher.jar', 'application/java-archive']
}
if componentId not in filesDict:
return ['text/plain', 'no component']
fname = os.path.dirname(sys.modules[module].__file__) + '/applet/' + filesDict[componentId][0]
logger.debug('Loading component {0} from {1}'.format(componentId, fname))
with open(fname, 'rb') as f:
data = f.read()
return [filesDict[componentId][1], data]