mirror of
https://github.com/dkmstr/openuds.git
synced 2025-02-02 09:47:13 +03:00
Fixed external url lauchern
This commit is contained in:
parent
01c41704a9
commit
c794b2befa
@ -181,7 +181,7 @@ class Connection(Handler):
|
||||
self._request.user = self._user
|
||||
setattr(self._request, '_cryptedpass', self.session['REST']['password'])
|
||||
setattr(self._request, '_scrambler', self._request.META['HTTP_SCRAMBLER'])
|
||||
linkInfo = services.enable_service(self._request, idService=idService, idTransport=idTransport)
|
||||
linkInfo = services.enable_service(self._request, service_id=idService, transport_id=idTransport)
|
||||
if linkInfo['error']:
|
||||
return Connection.result(error=linkInfo['error'])
|
||||
return Connection.result(result=linkInfo['url'])
|
||||
|
File diff suppressed because one or more lines are too long
@ -109,6 +109,6 @@
|
||||
</svg>
|
||||
</div>
|
||||
</uds-root>
|
||||
<script src="/uds/res/modern/polyfills.js" type="module" crossorigin="anonymous" integrity="sha384-gjZXw6bYB+td6SIdruY5JyqQBkqxY+puwSPNXlrc1Fu5fcv6y+sthRBgUlAL3EJp"></script><script src="/uds/res/modern/scripts.js" defer crossorigin="anonymous" integrity="sha384-gJ6CPuwXlJNL6wOYMLzD98cFi988rpY6Ln6S+UhAkZs84+MOQ+ws+0qgV4WicE5i"></script><script src="/uds/res/modern/main.js" type="module" crossorigin="anonymous" integrity="sha384-VkqJ9v78yv207fqag61pn4a9C+EAkxIJCF73KFrxILjfW0nDUWsFZPbRorw3jmH/"></script></body>
|
||||
<script src="/uds/res/modern/polyfills.js" type="module" crossorigin="anonymous" integrity="sha384-gjZXw6bYB+td6SIdruY5JyqQBkqxY+puwSPNXlrc1Fu5fcv6y+sthRBgUlAL3EJp"></script><script src="/uds/res/modern/scripts.js" defer crossorigin="anonymous" integrity="sha384-gJ6CPuwXlJNL6wOYMLzD98cFi988rpY6Ln6S+UhAkZs84+MOQ+ws+0qgV4WicE5i"></script><script src="/uds/res/modern/main.js" type="module" crossorigin="anonymous" integrity="sha384-paI3+lCzde3tptXNLh7Ks3Yy4KLmNrYLnc4G572MAo0fvzhGJnLCfHk0hExxBp3T"></script></body>
|
||||
|
||||
</html>
|
||||
|
@ -418,10 +418,10 @@ def get_services_info_dict(
|
||||
|
||||
|
||||
def enable_service(
|
||||
request: 'ExtendedHttpRequestWithUser', idService: str, idTransport: str
|
||||
request: 'ExtendedHttpRequestWithUser', service_id: str, transport_id: str
|
||||
) -> collections.abc.Mapping[str, typing.Any]:
|
||||
# Maybe we could even protect this even more by limiting referer to own server /? (just a meditation..)
|
||||
logger.debug('idService: %s, idTransport: %s', idService, idTransport)
|
||||
logger.debug('idService: %s, idTransport: %s', service_id, transport_id)
|
||||
url = ''
|
||||
error = gettext('Service not ready. Please, try again in a while.')
|
||||
|
||||
@ -429,24 +429,24 @@ def enable_service(
|
||||
|
||||
try:
|
||||
res = UserServiceManager.manager().get_user_service_info(
|
||||
request.user, request.os, request.ip, idService, idTransport, validate_with_test=False
|
||||
request.user, request.os, request.ip, service_id, transport_id, validate_with_test=False
|
||||
)
|
||||
scrambler = CryptoManager().random_string(32)
|
||||
password = CryptoManager().symmetric_encrypt(web_password(request), scrambler)
|
||||
|
||||
userService, trans = res[1], res[3]
|
||||
userservice, trans = res[1], res[3]
|
||||
|
||||
userService.properties['accessed_by_client'] = False # Reset accesed property to
|
||||
userservice.properties['accessed_by_client'] = False # Reset accesed property to
|
||||
|
||||
typeTrans = trans.get_type()
|
||||
transport_type = trans.get_type()
|
||||
|
||||
error = '' # No error
|
||||
|
||||
if typeTrans.own_link:
|
||||
url = reverse('webapi.transport_own_link', args=('A' + userService.uuid, trans.uuid))
|
||||
if transport_type.own_link:
|
||||
url = reverse('webapi.transport_own_link', args=('A' + userservice.uuid, trans.uuid))
|
||||
else:
|
||||
data = {
|
||||
'service': 'A' + userService.uuid,
|
||||
'service': 'A' + userservice.uuid,
|
||||
'transport': trans.uuid,
|
||||
'user': request.user.uuid,
|
||||
'password': password,
|
||||
@ -463,10 +463,10 @@ def enable_service(
|
||||
+ f'({e.code.as_percent()}%)'
|
||||
)
|
||||
except MaxServicesReachedError:
|
||||
logger.info('Number of service reached MAX for service pool "%s"', idService)
|
||||
logger.info('Number of service reached MAX for service pool "%s"', service_id)
|
||||
error = types.errors.Error.MAX_SERVICES_REACHED.message
|
||||
except ServiceAccessDeniedByCalendar:
|
||||
logger.info('Access tried to a calendar limited access pool "%s"', idService)
|
||||
logger.info('Access tried to a calendar limited access pool "%s"', service_id)
|
||||
error = types.errors.Error.SERVICE_CALENDAR_DENIED.message
|
||||
except Exception as e:
|
||||
logger.exception('Error')
|
||||
|
@ -33,6 +33,7 @@ import logging
|
||||
import typing
|
||||
import collections.abc
|
||||
|
||||
from django.utils.translation import gettext
|
||||
from django.http import HttpResponse
|
||||
from django.views.decorators.cache import cache_page, never_cache
|
||||
|
||||
@ -44,7 +45,7 @@ from uds.core.consts.images import DEFAULT_IMAGE
|
||||
from uds.core.util.model import process_uuid
|
||||
from uds.models import Transport, Image
|
||||
from uds.core.util import log
|
||||
from uds.core.services.exceptions import ServiceNotReadyError
|
||||
from uds.core.services.exceptions import ServiceNotReadyError, MaxServicesReachedError, ServiceAccessDeniedByCalendar
|
||||
|
||||
from uds.web.util import services
|
||||
|
||||
@ -60,11 +61,11 @@ logger = logging.getLogger(__name__)
|
||||
def transport_own_link(
|
||||
request: 'ExtendedHttpRequestWithUser', service_id: str, transport_id: str
|
||||
) -> HttpResponse:
|
||||
def _response(url: str = '', percent: int = 100, error: typing.Any = '') -> typing.Dict[str, typing.Any]:
|
||||
return {'running': percent, 'url': url, 'error': str(error)}
|
||||
|
||||
response: collections.abc.MutableMapping[str, typing.Any] = {}
|
||||
|
||||
# If userService is not owned by user, will raise an exception
|
||||
|
||||
# For type checkers to "be happy"
|
||||
try:
|
||||
res = UserServiceManager.manager().get_user_service_info(
|
||||
request.user, request.os, request.ip, service_id, transport_id
|
||||
@ -72,8 +73,8 @@ def transport_own_link(
|
||||
ip, userService, _iads, trans, itrans = res
|
||||
# This returns a response object in fact
|
||||
if itrans and ip:
|
||||
response = {
|
||||
'url': itrans.get_link(
|
||||
response = _response(
|
||||
url=itrans.get_link(
|
||||
userService,
|
||||
trans,
|
||||
ip,
|
||||
@ -81,14 +82,23 @@ def transport_own_link(
|
||||
request.user,
|
||||
web_password(request),
|
||||
request,
|
||||
)
|
||||
}
|
||||
),
|
||||
)
|
||||
except ServiceNotReadyError as e:
|
||||
response = {'running': e.code.as_percent()}
|
||||
logger.debug('Service not ready')
|
||||
# Not ready, show message and return to this page in a while
|
||||
# error += ' (code {0:04X})'.format(e.code)
|
||||
response = _response(percent=e.code)
|
||||
except MaxServicesReachedError:
|
||||
logger.info('Number of service reached MAX for service pool "%s"', service_id)
|
||||
response = _response(error=types.errors.Error.MAX_SERVICES_REACHED.message)
|
||||
except ServiceAccessDeniedByCalendar:
|
||||
logger.info('Access tried to a calendar limited access pool "%s"', service_id)
|
||||
response = _response(error=types.errors.Error.SERVICE_CALENDAR_DENIED.message)
|
||||
except Exception as e:
|
||||
logger.exception("Exception")
|
||||
response = {'error': str(e)}
|
||||
|
||||
logger.exception('Error')
|
||||
response = _response(error=gettext('Internal error'))
|
||||
|
||||
return HttpResponse(content=json.dumps(response), content_type='application/json')
|
||||
|
||||
|
||||
@ -128,7 +138,7 @@ def user_service_enabler(
|
||||
request: 'ExtendedHttpRequestWithUser', service_id: str, transport_id: str
|
||||
) -> HttpResponse:
|
||||
return HttpResponse(
|
||||
json.dumps(services.enable_service(request, idService=service_id, idTransport=transport_id)),
|
||||
json.dumps(services.enable_service(request, service_id=service_id, transport_id=transport_id)),
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user