import os
from django.http import HttpResponse, HttpResponseRedirect
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from django.shortcuts import render_to_response
from settings import ELASTICSEARCH_PROXY, ELASTICSEARCH_REAL, KIBANA_DIR


def login_or_404(func):
    def inner(*args, **karags):
        request = args[0]
        if request.user.is_authenticated():
            return func(*args, **karags)
        else:
            return HttpResponseRedirect("/es/")

    return inner


@login_or_404
@csrf_exempt
def elasticsearch(request):
    fullpath = request.get_full_path()
    fullpath = fullpath[len(ELASTICSEARCH_PROXY):]
    response = HttpResponse()
    response['X-Accel-Redirect'] = ELASTICSEARCH_REAL + '/' + fullpath
    response['Django-User'] = request.user.username
    return response


def home(request):
    return HttpResponseRedirect("index.html")


@login_required
def index(request):
    html = open(os.path.join(KIBANA_DIR, "index.html")).read()
    return HttpResponse(html)

@@ -352,19 +352,36 @@
 ogin_or_
-404
+redirect_to_internal
 (func):%0A
@@ -581,14 +581,26 @@
 ect(
-%22/es/%22
+ELASTICSEARCH_REAL
 )%0A%0A 
@@ -631,11 +631,28 @@
 _or_
-404
+redirect_to_internal
 %0A@cs

rename to login_or_redirect_to_internal