Ejemplo n.º 1
0
def group(request, group):
    if not CONFIG.valid(group):
        if settings.DEBUG:
            raise Exception("Invalid group: %s (valid groups %s)" % (group, CONFIG.groups()))
        else:
            return NeverCacheRedirectView.as_view(url="/")(request)

    config = CONFIG.config(group)

    template = request.GET.get('template', 'default')
    if not re.match(r'^[-a-z]+$', template):
        if settings.DEBUG:
            raise Exception("Unknown template: %s" % template)
        else:
            return NeverCacheRedirectView.as_view(url="/")(request)
    elif template == 'default':
        template = "group"
        # Is the request coming from the room?
        for ipregex in LOCALIPS:
            if ipregex.match(request.META[settings.HTTP_REMOTE_ADDR_META]):
                template = 'inroom'
                break

    screenstr = request.GET.get('screen', 'False')
    if screenstr.lower()[0] in ('y', 't'):
        screen = True
    else:
        screen = False

    return render_to_response('%s.html' % template, dict(screen=screen, config=config, group=group))
Ejemplo n.º 2
0
def group(request, group):
    if not CONFIG.valid(group):
        if settings.DEBUG:
            raise Exception("Invalid group: %s (valid groups %s)" %
                            (group, CONFIG.groups()))
        else:
            return NeverCacheRedirectView.as_view(url="/")(request)

    config = CONFIG.config(group)

    template = request.GET.get('template', 'default')
    if not re.match(r'^[-a-z]+$', template):
        if settings.DEBUG:
            raise Exception("Unknown template: %s" % template)
        else:
            return NeverCacheRedirectView.as_view(url="/")(request)
    elif template == 'default':
        template = "group"
        # Is the request coming from the room?
        for ipregex in LOCALIPS:
            if ipregex.match(request.META[settings.HTTP_REMOTE_ADDR_META]):
                template = 'inroom'
                break

    screenstr = request.GET.get('screen', 'False')
    if screenstr.lower()[0] in ('y', 't'):
        screen = True
    else:
        screen = False

    return render_to_response('%s.html' % template,
                              dict(screen=screen, config=config, group=group))
Ejemplo n.º 3
0
def endpoint_common(request, check_group=True):
    """Check the common information for an endpoint request."""
    if request.method != 'POST':
        return NeverCacheRedirectView.as_view(url="/")(request)

    response = http.HttpResponse(content_type='text/plain')

    if not CONFIG['config'].get('secret', None):
        response.write('ERROR CONFIG (No secret)\n')
        return response, None, None

    secret = request.POST.get('secret', '')
    if secret != CONFIG['config']['secret']:
        response.write('ERROR SECRET\n')
        return response, None, None

    if check_group:
        group = request.POST.get('group', '')
        if not CONFIG.valid(group):
            response.write('ERROR GROUP\n')
            return response, None, None
    else:
        group = None

    ip = request.META[settings.HTTP_REMOTE_ADDR_META]

    return None, group, ip
Ejemplo n.º 4
0
def endpoint_common(request, check_group=True):
    """Check the common information for an endpoint request."""
    if request.method != 'POST':
        return (NeverCacheRedirectView.as_view(url="/")(request), None, None)

    response = http.HttpResponse(content_type='text/plain')

    if not CONFIG['config'].get('secret', None):
        response.write('ERROR CONFIG (No secret)\n')
        return response, None, None

    secret = request.POST.get('secret', '')
    if secret != CONFIG['config']['secret']:
        response.write('ERROR SECRET\n')
        return response, None, None

    if check_group:
        group = request.POST.get('group', '')
        if not CONFIG.valid(group):
            response.write('ERROR GROUP\n')
            return response, None, None
    else:
        group = None

    ip = request.META[settings.HTTP_REMOTE_ADDR_META]

    return None, group, ip
Ejemplo n.º 5
0
def client_common(request, group):
    """Check the common information for an client request."""
    if request.method != 'POST':
        return NeverCacheRedirectView.as_view(url="/")(request)

    response = http.HttpResponse(content_type='application/javascript')

    if not CONFIG.valid(group):
        response.write(
            json.dumps({
                'code': error.ERROR_GROUP,
                'error': 'Unknown group',
                'next': -1,
            }))
        return (response, None, None)

    # Check the cookie value exists
    if 'user' not in request.COOKIES:
        response.set_cookie('user', value=user_key(request))
        response.write(
            json.dumps({
                'code': error.WARNING_COOKIE,
                'error': 'No cookie set',
                'next': 0,
            }))
        return (response, None, None)

    # Check the cookie value is valid
    salt, digest = request.COOKIES['user'].split(':')
    if user_key(request, salt) != request.COOKIES['user']:
        response.delete_cookie('user')
        response.write(
            json.dumps({
                'code': error.WARNING_COOKIE,
                'error': 'Cookie was invalid?',
                'next': 0,
            }))
        return (response, None, None)

    return (None, group, request.COOKIES['user'])
Ejemplo n.º 6
0
def client_common(request, group):
    """Check the common information for an client request."""
    if request.method != 'POST':
        return NeverCacheRedirectView.as_view(url="/")(request)

    response = http.HttpResponse(content_type='application/javascript')

    if not CONFIG.valid(group):
        response.write(json.dumps({
            'code': error.ERROR_GROUP,
            'error': 'Unknown group',
            'next': -1,
            }))
        return (response, None, None)

    # Check the cookie value exists
    if 'user' not in request.COOKIES:
        response.set_cookie('user', value=user_key(request))
        response.write(json.dumps({
            'code': error.WARNING_COOKIE,
            'error': 'No cookie set',
            'next': 0,
            }))
        return (response, None, None)

    # Check the cookie value is valid
    salt, digest = request.COOKIES['user'].split(':')
    if user_key(request, salt) != request.COOKIES['user']:
        response.delete_cookie('user')
        response.write(json.dumps({
            'code': error.WARNING_COOKIE,
            'error': 'Cookie was invalid?',
            'next': 0,
            }))
        return (response, None, None)

    return (None, group, request.COOKIES['user'])