Beispiel #1
0
def clientEnabler(request, idService, idTransport):

    # Maybe we could even protect this even more by limiting referer to own server /? (just a meditation..)
    logger.debug('idService: {}, idTransport: {}'.format(
        idService, idTransport))
    url = ''
    error = _('Service not ready. Please, try again in a while.')
    try:
        res = userServiceManager().getService(request.user,
                                              request.ip,
                                              idService,
                                              idTransport,
                                              doTest=False)
        scrambler = cryptoManager().randomString(32)
        password = cryptoManager().xor(webPassword(request), scrambler)

        _x, userService, _x, trans, _x = res

        data = {
            'service': 'A' + userService.uuid,
            'transport': trans.uuid,
            'user': request.user.uuid,
            'password': password
        }

        ticket = TicketStore.create(data)
        error = ''
        url = html.udsLink(request, ticket, scrambler)
    except ServiceNotReadyError as e:
        logger.debug('Service not ready')
        # Not ready, show message and return to this page in a while
        error += ' (code {0:04X})'.format(e.code)
    except MaxServicesReachedError:
        logger.info(
            'Number of service reached MAX for service pool "{}"'.format(
                idService))
        error = errors.errorString(errors.MAX_SERVICES_REACHED)
    except ServiceAccessDeniedByCalendar:
        logger.info(
            'Access tried to a calendar limited access pool "{}"'.format(
                idService))
        error = errors.errorString(errors.SERVICE_CALENDAR_DENIED)
    except Exception as e:
        logger.exception('Error')
        error = six.text_type(e)

    return HttpResponse(json.dumps({
        'url': six.text_type(url),
        'error': six.text_type(error)
    }),
                        content_type='application/json')
Beispiel #2
0
def clientEnabler(request, idService, idTransport):

    # Maybe we could even protect this even more by limiting referer to own server /? (just a meditation..)
    logger.debug('idService: {}, idTransport: {}'.format(idService, idTransport))
    url = ''
    error = _('Service not ready. Please, try again in a while.')
    try:
        res = userServiceManager().getService(request.user, request.ip, idService, idTransport, doTest=False)
        scrambler = cryptoManager().randomString(32)
        password = cryptoManager().xor(webPassword(request), scrambler)

        _x, userService, _x, trans, _x = res

        data = {
            'service': 'A' + userService.uuid,
            'transport': trans.uuid,
            'user': request.user.uuid,
            'password': password
        }

        ticket = TicketStore.create(data)
        error = ''
        url = html.udsLink(request, ticket, scrambler)
    except ServiceNotReadyError as e:
        logger.debug('Service not ready')
        # Not ready, show message and return to this page in a while
        error += ' (code {0:04X})'.format(e.code)
    except MaxServicesReachedError:
        logger.info('Number of service reached MAX for service pool "{}"'.format(idService))
        error = errors.errorString(errors.MAX_SERVICES_REACHED)
    except ServiceAccessDeniedByCalendar:
        logger.info('Access tried to a calendar limited access pool "{}"'.format(idService))
        error = errors.errorString(errors.SERVICE_CALENDAR_DENIED)
    except Exception as e:
        logger.exception('Error')
        error = six.text_type(e)


    return HttpResponse(
        json.dumps({
            'url': six.text_type(url),
            'error': six.text_type(error)
        }),
        content_type='application/json'
    )
Beispiel #3
0
 def result(result=None, error=None):
     '''
     Helper method to create a "result" set for actor response
     :param result: Result value to return (can be None, in which case it is converted to empty string '')
     :param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code
     :return: A dictionary, suitable for response to Caller
     '''
     result = result if result is not None else ''
     res = {'result': result}
     if error is not None:
         if isinstance(error, int):
             error = errors.errorString(error)
         res['error'] = error
     return res
Beispiel #4
0
    def result(result=None, error=None, errorCode=0, retryable=False):
        '''
        Helper method to create a "result" set for connection response
        :param result: Result value to return (can be None, in which case it is converted to empty string '')
        :param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code
        :return: A dictionary, suitable for response to Caller
        '''
        result = result if result is not None else ''
        res = {'result': result, 'date': datetime.datetime.now()}
        if error is not None:
            if isinstance(error, int):
                error = errors.errorString(error)
            if errorCode != 0:
                error += ' (code {0:04X})'.format(errorCode)
            res['error'] = error

        res['retryable'] = retryable and '1' or '0'

        return res
Beispiel #5
0
    def result(result=None, error=None, errorCode=0, retryable=False):
        '''
        Helper method to create a "result" set for connection response
        :param result: Result value to return (can be None, in which case it is converted to empty string '')
        :param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code
        :return: A dictionary, suitable for response to Caller
        '''
        result = result if result is not None else ''
        res = {'result': result, 'date': datetime.datetime.now()}
        if error is not None:
            if isinstance(error, int):
                error = errors.errorString(error)
            if errorCode != 0:
                error += ' (code {0:04X})'.format(errorCode)
            res['error'] = error

        res['retryable'] = retryable and '1' or '0'

        return res
Beispiel #6
0
    def result(result=None, error=None, errorCode=0, retryable=False):
        '''
        Helper method to create a "result" set for actor response
        :param result: Result value to return (can be None, in which case it is converted to empty string '')
        :param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code
        :param errorCode: Code of the error to return, if error is not None
        :param retryable: If True, this operation can (and must) be retryed
        :return: A dictionary, suitable for response to Caller
        '''
        result = result if result is not None else ''
        res = {'result': result}
        if error is not None:
            if isinstance(error, int):
                error = errors.errorString(error)
            if errorCode != 0:
                error += ' (code {0:04X})'.format(errorCode)

            res['error'] = error
            res['retryable'] = retryable and '1' or '0'

        logger.debug('Client Result: {}'.format(res))

        return res
Beispiel #7
0
    def result(result=None, error=None, errorCode=0, retryable=False):
        """
        Helper method to create a "result" set for actor response
        :param result: Result value to return (can be None, in which case it is converted to empty string '')
        :param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code
        :param errorCode: Code of the error to return, if error is not None
        :param retryable: If True, this operation can (and must) be retryed
        :return: A dictionary, suitable for response to Caller
        """
        result = result if result is not None else ''
        res = {'result': result}
        if error is not None:
            if isinstance(error, int):
                error = errors.errorString(error)
            if errorCode != 0:
                error += ' (code {0:04X})'.format(errorCode)

            res['error'] = error
            res['retryable'] = retryable and '1' or '0'

        logger.debug('Client Result: {}'.format(res))

        return res