def post(self, request, service, address=None):
        '''
        Authorizes one address to shape another address,
        based on the provided auth token.
        '''
        if address is None:
            return Response(
                {'details': 'no address provided'},
                status=status.HTTP_400_BAD_REQUEST
                )
        controlled_ip = address

        controlling_ip = get_client_ip(request)

        if 'token' not in request.data:
            token = None
        else:
            token = AccessToken(token=request.data['token'])

        dev = TrafficControlledDevice(
            controlledIP=controlled_ip,
            controllingIP=controlling_ip
            )

        worked = service.requestRemoteControl(dev, token)

        if not worked:
            return Response(
                {'details': 'invalid token provided'},
                status=status.HTTP_401_UNAUTHORIZED,
                )

        print 'Worked:', worked

        data = {
            'controlling_ip': controlling_ip,
            'controlled_ip': controlled_ip,
        }

        return Response(data, status=status.HTTP_200_OK)
Example #2
0
    def get(self, request, service, address=None):
        '''
        Returns the addresses that the provided address is allowed to shape.
        '''
        if address is None:
            address = get_client_ip(request)

        controlled_ips = []

        for addr in service.getDevicesControlledBy(address):
            if addr is None:
                break
            controlled_ips.append({
                'controlled_ip': addr.device.controlledIP,
                'valid_until': addr.timeout,
            })

        data = {
            'address': address,
            'controlled_ips': controlled_ips,
        }
        return Response(data, status=status.HTTP_200_OK)
    def get(self, request, service, address=None):
        '''
        Returns the addresses that the provided address is allowed to shape.
        '''
        if address is None:
            address = get_client_ip(request)

        controlled_ips = []

        for addr in service.getDevicesControlledBy(address):
            if addr is None:
                break
            controlled_ips.append({
                'controlled_ip': addr.device.controlledIP,
                'valid_until': addr.timeout,
            })

        data = {
            'address': address,
            'controlled_ips': controlled_ips,
        }
        return Response(data, status=status.HTTP_200_OK)
Example #4
0
    def get(self, request, service):
        '''
        Returns the current authorization token for the provided address.
        '''
        # default duration...
        # 3 days in seconds
        duration = 3 * 24 * 60 * 60

        if 'duration' in request.query_params:
            duration = int(request.query_params['duration'])

        address = get_client_ip(request)

        stuff = service.requestToken(address, duration)

        data = {
            'token': stuff.token,
            'interval': stuff.interval,
            'valid_until': stuff.valid_until,
            'address': address,
        }

        return Response(data, status=status.HTTP_200_OK)
    def get(self, request, service):
        '''
        Returns the current authorization token for the provided address.
        '''
        # default duration...
        # 3 days in seconds
        duration = 3 * 24 * 60 * 60

        if 'duration' in request.query_params:
            duration = int(request.query_params['duration'])

        address = get_client_ip(request)

        stuff = service.requestToken(address, duration)

        data = {
            'token': stuff.token,
            'interval': stuff.interval,
            'valid_until': stuff.valid_until,
            'address': address,
        }

        return Response(data, status=status.HTTP_200_OK)
Example #6
0
    def post(self, request, service, address=None):
        '''
        Authorizes one address to shape another address,
        based on the provided auth token.
        '''
        if address is None:
            return Response({'details': 'no address provided'},
                            status=status.HTTP_400_BAD_REQUEST)
        controlled_ip = address

        controlling_ip = get_client_ip(request)

        if 'token' not in request.data:
            token = None
        else:
            token = AccessToken(token=request.data['token'])

        dev = TrafficControlledDevice(controlledIP=controlled_ip,
                                      controllingIP=controlling_ip)

        worked = service.requestRemoteControl(dev, token)

        if not worked:
            return Response(
                {'details': 'invalid token provided'},
                status=status.HTTP_401_UNAUTHORIZED,
            )

        print 'Worked:', worked

        data = {
            'controlling_ip': controlling_ip,
            'controlled_ip': controlled_ip,
        }

        return Response(data, status=status.HTTP_200_OK)
Example #7
0
 def _get_client_ip(self):
     return get_client_ip(self.context['request'])