mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
* Fixed several "last hour" REST requests related to tickets
* Added OS Detector so if os is not detected before, tries it at request moment * Added a new error so services in maintenance mode are notified
This commit is contained in:
parent
3fbcee60cb
commit
2549510eaa
@ -81,7 +81,7 @@ class ServicesPools(ModelHandler):
|
||||
'id': item.uuid,
|
||||
'name': item.name,
|
||||
'comments': item.comments,
|
||||
'state': item.state,
|
||||
'state': item.state if item.service.provider.maintenance_mode is False else State.MAINTENANCE,
|
||||
'service_id': item.service.uuid,
|
||||
'provider_id': item.service.provider.uuid,
|
||||
'image_id': item.image.uuid if item.image is not None else None,
|
||||
|
@ -434,7 +434,6 @@ class UserServiceManager(object):
|
||||
return True
|
||||
|
||||
def isReady(self, uService):
|
||||
return True
|
||||
UserService.objects.update()
|
||||
uService = UserService.objects.get(id=uService.id)
|
||||
logger.debug('Checking ready of {0}'.format(uService))
|
||||
|
@ -32,7 +32,7 @@
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
__updated__ = '2014-03-22'
|
||||
__updated__ = '2015-02-10'
|
||||
|
||||
|
||||
class UnsupportedException(Exception):
|
||||
@ -82,3 +82,10 @@ class MaxServicesReachedException(Exception):
|
||||
can be created for users.
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class ServiceInMaintenanceMode(Exception):
|
||||
'''
|
||||
The service is in maintenance mode and can't be accesed right now
|
||||
'''
|
||||
pass
|
||||
|
@ -50,6 +50,7 @@ mobilesODD = list(set(allOss) - set(desktopOss))
|
||||
|
||||
DEFAULT_OS = 'Windows'
|
||||
|
||||
|
||||
def getOsFromUA(ua):
|
||||
'''
|
||||
Basic OS Client detector (very basic indeed :-))
|
||||
@ -69,3 +70,12 @@ def getOsFromUA(ua):
|
||||
logger.debug('User-Agent: {0}'.format(ua))
|
||||
logger.debug('Detected OS: {0}'.format(res))
|
||||
return res
|
||||
|
||||
|
||||
def getOsFromRequest(request):
|
||||
try:
|
||||
return request.session['OS']
|
||||
except:
|
||||
request.session['OS'] = getOsFromUA(request.META['HTTP_USER_AGENT'])
|
||||
|
||||
return request.session['OS']
|
||||
|
@ -74,3 +74,6 @@ class Ticket(object):
|
||||
Removes a ticket from storage (db)
|
||||
'''
|
||||
self.cache.remove(self.key)
|
||||
|
||||
def __unicode__(self):
|
||||
return "Ticket: {}, {}".format(self.key, self.data)
|
||||
|
@ -42,7 +42,7 @@ from .transformers import scrambleId, transformId
|
||||
|
||||
from uds.models import DeployedService, Transport, UserService, Authenticator
|
||||
from uds.core.auths.Exceptions import InvalidUserException, InvalidAuthenticatorException
|
||||
from uds.core.services.Exceptions import InvalidServiceException, MaxServicesReachedException
|
||||
from uds.core.services.Exceptions import InvalidServiceException, MaxServicesReachedException, ServiceInMaintenanceMode
|
||||
from uds.core.ui import theme
|
||||
|
||||
|
||||
@ -61,7 +61,8 @@ ERR_USER_SERVICE_NOT_FOUND = 7
|
||||
AUTHENTICATOR_NOT_FOUND = 8
|
||||
INVALID_CALLBACK = 9
|
||||
INVALID_REQUEST = 10
|
||||
BROWSER_NOT_SUPPORTED = 11
|
||||
BROWSER_NOT_SUPPORTED = 11,
|
||||
SERVICE_IN_MAINTENANCE = 12
|
||||
|
||||
|
||||
strings = [
|
||||
@ -76,7 +77,8 @@ strings = [
|
||||
_('Authenticator not found'),
|
||||
_('Invalid authenticator'),
|
||||
_('Invalid request received'),
|
||||
_('Your browser is not supported. Please, upgrade it to a modern HTML5 browser like Firefox or Chrome')
|
||||
_('Your browser is not supported. Please, upgrade it to a modern HTML5 browser like Firefox or Chrome'),
|
||||
_('The requested service is in maintenance mode')
|
||||
]
|
||||
|
||||
|
||||
@ -113,6 +115,8 @@ def exceptionView(request, exception):
|
||||
return errorView(request, MAX_SERVICES_REACHED)
|
||||
except InvalidAuthenticatorException:
|
||||
return errorView(request, INVALID_CALLBACK)
|
||||
except ServiceInMaintenanceMode:
|
||||
return errorView(request, SERVICE_IN_MAINTENANCE)
|
||||
except Exception as e:
|
||||
logger.exception('Exception cautgh at view!!!')
|
||||
raise e
|
||||
|
@ -37,6 +37,7 @@ from django.shortcuts import redirect
|
||||
from django.template import RequestContext
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.views.decorators.cache import never_cache
|
||||
|
||||
from uds.core.auths.auth import webLogin, webLogout, webLoginRequired, authenticateViaCallback, authLogLogin, getUDSCookie
|
||||
from uds.models import Authenticator, DeployedService, Transport
|
||||
@ -45,7 +46,7 @@ from uds.core.util.Ticket import Ticket
|
||||
from uds.core.util.State import State
|
||||
from uds.core.ui import theme
|
||||
from uds.core.auths.Exceptions import InvalidUserException
|
||||
from uds.core.services.Exceptions import InvalidServiceException
|
||||
from uds.core.services.Exceptions import InvalidServiceException, ServiceInMaintenanceMode
|
||||
|
||||
import uds.web.errors as errors
|
||||
|
||||
@ -139,7 +140,7 @@ def authJava(request, idAuth, hasJava):
|
||||
request.session['java'] = hasJava == 'y'
|
||||
try:
|
||||
authenticator = Authenticator.objects.get(uuid=idAuth)
|
||||
os = request.session['OS']
|
||||
os = OsDetector.getOsFromRequest(request)
|
||||
authLogLogin(request, authenticator, request.user.name, request.session['java'], os)
|
||||
return redirect('uds.web.views.index')
|
||||
|
||||
@ -147,12 +148,15 @@ def authJava(request, idAuth, hasJava):
|
||||
return errors.exceptionView(request, e)
|
||||
|
||||
|
||||
@never_cache
|
||||
def ticketAuth(request, ticketId):
|
||||
'''
|
||||
Used to authenticate an user via a ticket
|
||||
'''
|
||||
ticket = Ticket(ticketId)
|
||||
|
||||
logger.debug('Ticket: {}'.format(ticket))
|
||||
|
||||
try:
|
||||
try:
|
||||
# Extract ticket.data from ticket.data storage, and remove it if success
|
||||
@ -182,7 +186,7 @@ def ticketAuth(request, ticketId):
|
||||
|
||||
if len(grps) == 0:
|
||||
logger.error('Ticket has no valid groups')
|
||||
raise Exception('Invalid ticket authentification')
|
||||
raise Exception('Invalid ticket authentication')
|
||||
|
||||
usr = auth.getOrCreateUser(username, realname)
|
||||
if usr is None or State.isActive(usr.state) is False: # If user is inactive, raise an exception
|
||||
@ -192,18 +196,22 @@ def ticketAuth(request, ticketId):
|
||||
usr.groups = grps
|
||||
|
||||
# Right now, we assume that user supports java, let's see how this works
|
||||
# Force cookie generation
|
||||
webLogin(request, None, usr, password)
|
||||
|
||||
request.session['java'] = True
|
||||
request.session['OS'] = OsDetector.getOsFromUA(request.META.get('HTTP_USER_AGENT'))
|
||||
request.user = usr # Temporaly store this user as "authenticated" user, next requests will be done using session
|
||||
|
||||
# Force cookie generation
|
||||
webLogin(request, None, usr, password)
|
||||
|
||||
# Check if servicePool is part of the ticket
|
||||
if servicePool is not None:
|
||||
servicePool = DeployedService.objects.get(uuid=servicePool)
|
||||
# Check if service pool can't be accessed by groups
|
||||
servicePool.validateUser(usr)
|
||||
if servicePool.isInMaintenance():
|
||||
raise ServiceInMaintenanceMode()
|
||||
|
||||
transport = Transport.objects.get(uuid=transport)
|
||||
|
||||
response = service(request, 'F' + servicePool.uuid, transport.uuid) # 'A' Indicates 'assigned service'
|
||||
@ -223,5 +231,3 @@ def ticketAuth(request, ticketId):
|
||||
except Exception as e:
|
||||
logger.exception('Exception')
|
||||
return errors.exceptionView(request, e)
|
||||
|
||||
return HttpResponse(ticketId, content_type='text/plain')
|
||||
|
@ -39,6 +39,8 @@ from uds.core.auths.auth import webLoginRequired
|
||||
|
||||
from uds.models import DeployedService, Transport, UserService, Network
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
from uds.core.util import OsDetector
|
||||
|
||||
from uds.core.ui import theme
|
||||
from uds.core.managers.UserServiceManager import UserServiceManager
|
||||
|
||||
@ -63,7 +65,7 @@ def index(request):
|
||||
:param request: http request
|
||||
'''
|
||||
# Session data
|
||||
os = request.session['OS']
|
||||
os = OsDetector.getOsFromRequest(request)
|
||||
java = request.session.get('java', None)
|
||||
|
||||
# We look for services for this authenticator groups. User is logged in in just 1 authenticator, so his groups must coincide with those assigned to ds
|
||||
|
@ -40,6 +40,7 @@ from uds.models import DeployedService, Transport, UserService, Image
|
||||
from uds.core.ui.images import DEFAULT_IMAGE
|
||||
from uds.core.managers.UserServiceManager import UserServiceManager
|
||||
from uds.core.util import log
|
||||
from uds.core.util import OsDetector
|
||||
from uds.core.util.stats import events
|
||||
from uds.core.ui import theme
|
||||
|
||||
@ -49,7 +50,7 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
__updated__ = '2015-01-28'
|
||||
__updated__ = '2015-02-10'
|
||||
|
||||
|
||||
@webLoginRequired
|
||||
@ -79,7 +80,7 @@ def service(request, idService, idTransport):
|
||||
itrans = trans.getInstance()
|
||||
if itrans.isAvailableFor(ip):
|
||||
log.doLog(ads, log.INFO, "User service ready, rendering transport", log.WEB)
|
||||
transportHtml = itrans.renderForHtml(ads, trans, ip, request.session['OS'], request.user, webPassword(request))
|
||||
transportHtml = itrans.renderForHtml(ads, trans, ip, OsDetector.getOsFromRequest(request), request.user, webPassword(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:
|
||||
@ -102,7 +103,7 @@ def transcomp(request, idTransport, componentId):
|
||||
# We got translated first id
|
||||
trans = Transport.objects.get(uuid=idTransport.upper())
|
||||
itrans = trans.getInstance()
|
||||
res = itrans.getHtmlComponent(trans.uuid, request.session['OS'], componentId)
|
||||
res = itrans.getHtmlComponent(trans.uuid, OsDetector.getOsFromRequest(request), componentId)
|
||||
response = HttpResponse(res[1], content_type=res[0])
|
||||
response['Content-Length'] = len(res[1])
|
||||
return response
|
||||
|
Loading…
Reference in New Issue
Block a user