forked from shaba/openuds
Several minor fixes and protocol detection seems to work
This commit is contained in:
parent
3ddf2f91ad
commit
d73c8f49cc
server/src/uds
core
templates/uds/html5
templatetags
web
@ -138,6 +138,6 @@ class CryptoManager(object):
|
||||
if isinstance(obj, six.text_type):
|
||||
obj = obj.decode('utf-8')
|
||||
else:
|
||||
obj = six. binary_type(obj)
|
||||
obj = six.binary_type(obj)
|
||||
|
||||
return six.text_type(uuid.uuid5(self._namespace, six.binary_type(obj))).lower() # I believe uuid returns a lowercase uuid always, but in case... :)
|
||||
|
@ -33,7 +33,11 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.template import loader, Context
|
||||
|
||||
from uds.core.util import OsDetector
|
||||
from uds.core.util.Ticket import Ticket
|
||||
from uds.core.auths.auth import webPassword
|
||||
from uds.core import Module
|
||||
from uds.core.transports import protocols
|
||||
|
||||
@ -152,6 +156,25 @@ class Transport(Module):
|
||||
'''
|
||||
return user.name
|
||||
|
||||
def getUDSTransportInfo(self, userService, transport, ip, os, user, password, request):
|
||||
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
|
||||
|
@ -34,7 +34,7 @@ UDS Service modules interfaces and classes.
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from uds.core.transports.BaseTransport import Transport
|
||||
from .BaseTransport import Transport
|
||||
|
||||
|
||||
def factory():
|
||||
|
@ -44,21 +44,22 @@ class Ticket(object):
|
||||
Right now, uses cache as backend
|
||||
'''
|
||||
|
||||
def __init__(self, key=None):
|
||||
self.uuidGenerator = cryptoManager().uuid
|
||||
def __init__(self, key=None, data=None):
|
||||
self.uuidGenerator = lambda: (cryptoManager().uuid() + cryptoManager().uuid()).replace('-', '')
|
||||
self.cache = Cache(TICKET_OWNER)
|
||||
self.data = None
|
||||
self.data = data
|
||||
self.key = key
|
||||
if key is not None:
|
||||
self.load()
|
||||
else:
|
||||
self.key = self.uuidGenerator()
|
||||
|
||||
def save(self, data, validity):
|
||||
def save(self, data=None, validity=Cache.DEFAULT_VALIDITY):
|
||||
'''
|
||||
Stores data inside ticket, and make data persistent (store in db)
|
||||
'''
|
||||
self.data = data
|
||||
if data is not None:
|
||||
self.data = data
|
||||
self.cache.put(self.key, self.data, validity)
|
||||
return self.key
|
||||
|
||||
|
@ -41,32 +41,11 @@ from functools import wraps
|
||||
|
||||
import logging
|
||||
|
||||
__updated__ = '2014-09-09'
|
||||
__updated__ = '2015-03-16'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Have to test this decorator before using them
|
||||
def retryOnException(retries=3, delay=0):
|
||||
'''
|
||||
Decorator to retry
|
||||
'''
|
||||
def decorator(func):
|
||||
@wraps(func)
|
||||
def _wrapped_func(*args, **kwargs):
|
||||
while retries > 0:
|
||||
retries -= 1
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception:
|
||||
if retries == 0:
|
||||
raise
|
||||
if delay > 0:
|
||||
sleep(delay)
|
||||
return _wrapped_func
|
||||
return decorator
|
||||
|
||||
|
||||
# Decorator that protects pages that needs at least a browser version
|
||||
# Default is to deny IE < 9
|
||||
def denyBrowsers(browsers=['ie<9'], errorResponse=lambda request: errors.errorView(request, errors.BROWSER_NOT_SUPPORTED)):
|
||||
@ -88,6 +67,7 @@ def denyBrowsers(browsers=['ie<9'], errorResponse=lambda request: errors.errorVi
|
||||
return _wrapped_view
|
||||
return wrap
|
||||
|
||||
|
||||
def deprecated(func):
|
||||
'''This is a decorator which can be used to mark functions
|
||||
as deprecated. It will result in a warning being emitted
|
||||
@ -100,9 +80,10 @@ def deprecated(func):
|
||||
caller = inspect.stack()[1]
|
||||
logger.warn(
|
||||
"Call to deprecated function {0} from {1}:{2}.".format(func.__name__,
|
||||
caller[1], caller[2]
|
||||
))
|
||||
except:
|
||||
caller[1], caller[2]
|
||||
)
|
||||
)
|
||||
except Exception:
|
||||
logger.info('No stack info on deprecated function call {0}'.format(func.__name__))
|
||||
|
||||
return func(*args, **kwargs)
|
||||
|
@ -35,7 +35,7 @@ from __future__ import unicode_literals
|
||||
import threading
|
||||
import logging
|
||||
|
||||
__updated__ = '2014-10-30'
|
||||
__updated__ = '2015-03-17'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -57,6 +57,7 @@ class GlobalRequestMiddleware(object):
|
||||
def process_request(self, request):
|
||||
# Add IP to request
|
||||
GlobalRequestMiddleware.fillIps(request)
|
||||
# Add a counter var, reseted on every request
|
||||
_requests[getIdent()] = request
|
||||
return None
|
||||
|
||||
|
@ -4,17 +4,10 @@
|
||||
{% block body %}
|
||||
<div class="panel panel-default text-center">
|
||||
<div id="transport">
|
||||
{{ transport }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<a href="{% url 'uds.web.views.index' %}" class="btn btn-info"><i class="fa fa-home"></i> {% trans "Back to services list" %}</a>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('#transport').append("{{ transport|escapejs }}");
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
@ -90,10 +90,12 @@
|
||||
<script src="{% get_static_prefix %}js/bootstrap.min.js"></script>
|
||||
<script src="{% get_static_prefix %}js/bootstrap-switch.min.js"></script>
|
||||
<script src="{% get_static_prefix %}js/bootstrap-select.min.js"></script>
|
||||
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}js/uds-client.coffee"></script>
|
||||
|
||||
<script>
|
||||
$(function(){
|
||||
$('.selectpicker').selectpicker();
|
||||
window.uds.onLink();
|
||||
});
|
||||
</script>
|
||||
{% endcompress %}
|
||||
|
@ -34,6 +34,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django import template
|
||||
from uds.core.util import html
|
||||
from uds.core.util.request import getRequest
|
||||
from uds.core.auths.auth import ROOT_ID
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
from uds.models.Image import Image
|
||||
@ -91,6 +92,29 @@ def enhaced_visual(parser, token):
|
||||
return EnhacedVisual(states['enhaced_visual'], states.get('else', None))
|
||||
|
||||
|
||||
class TabIndex(template.Node):
|
||||
def __init__(self, tabIndexName):
|
||||
self.tabIndexIname = tabIndexName
|
||||
|
||||
def render(self, context):
|
||||
counter = context.get(self.tabIndexIname, 0) + 1
|
||||
context[self.tabIndexIname] = counter
|
||||
return "{}".format(counter)
|
||||
|
||||
|
||||
@register.tag(name='tabindex')
|
||||
def tabindex(parser, token):
|
||||
try:
|
||||
# split_contents() knows not to split quoted strings.
|
||||
tag_name, tabIndexName = token.split_contents()
|
||||
except ValueError:
|
||||
raise template.TemplateSyntaxError(
|
||||
"%r tag requires a single argument" % token.contents.split()[0]
|
||||
)
|
||||
|
||||
return TabIndex(tabIndexName)
|
||||
|
||||
|
||||
@register.assignment_tag
|
||||
def preferences_allowed():
|
||||
return GlobalConfig.PREFERENCES_ALLOWED.getBool(True)
|
||||
|
@ -45,7 +45,7 @@ from uds.core.auths.Exceptions import InvalidUserException, InvalidAuthenticator
|
||||
from uds.core.services.Exceptions import InvalidServiceException, MaxServicesReachedException, ServiceInMaintenanceMode
|
||||
from uds.core.ui import theme
|
||||
|
||||
|
||||
import traceback
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -97,6 +97,8 @@ def exceptionView(request, exception):
|
||||
'''
|
||||
Tries to render an error page with error information
|
||||
'''
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
try:
|
||||
raise exception
|
||||
except UserService.DoesNotExist:
|
||||
|
@ -30,7 +30,7 @@
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
__updated__ = '2015-02-28'
|
||||
__updated__ = '2015-03-16'
|
||||
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response
|
||||
@ -89,7 +89,7 @@ def service(request, idService, idTransport):
|
||||
if itrans.isAvailableFor(ip):
|
||||
ads.setConnectionSource(request.ip, 'unknown')
|
||||
log.doLog(ads, log.INFO, "User service ready, rendering transport", log.WEB)
|
||||
transportHtml = itrans.renderForHtml(ads, trans, ip, OsDetector.getOsFromRequest(request), request.user, webPassword(request))
|
||||
transportHtml = itrans.renderAsHtml(ads, trans, ip, request)
|
||||
UserServiceManager.manager().notifyPreconnect(ads, itrans.processedUser(ads, request.user), itrans.protocol)
|
||||
return render_to_response(theme.template('show_transport.html'), {'transport': transportHtml, 'nolang': True}, context_instance=RequestContext(request))
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user