Revision 94fb8123

b/poller/views.py
11 11
from django.http import HttpResponse
12 12
from gevent.event import Event
13 13
from django.conf import settings
14
from django.views.decorators.csrf import csrf_exempt
14
#from django.views.decorators.csrf import csrf_exempt
15 15
from django.http import HttpResponseRedirect
16 16
from django.core.urlresolvers import reverse
17 17

  
......
37 37
    return HttpResponse(simplejson.dumps(value), **kwargs)
38 38

  
39 39
class Msgs(object):
40
    cache_size = 200
40
    cache_size = 500
41 41

  
42 42
    def __init__(self):
43 43
        self.user = None
......
52 52
            request.session['cursor'] = self.user_cache[-1]['id']
53 53
        return render_to_response('poll.html', {'messages': self.user_cache})
54 54

  
55
    @csrf_exempt
56 55
    def message_existing(self, request):
57 56
        if request.is_ajax():
58 57
            try:
......
72 71
                self.user_cache[user] = []
73 72
                self.user_cursor[user] = ''
74 73
            return json_response({'messages': self.user_cache[user]})
75
        return HttpResponseRedirect(reverse('login'))
74
        return HttpResponseRedirect(reverse('group-routes'))
76 75
    
77
    @csrf_exempt
78 76
    def message_new(self, mesg=None):
79 77
        if mesg:
80 78
            message = mesg['message']
......
97 95
        self.new_message_user_event[user].clear()
98 96
        return json_response(msg)
99 97
    
100
    @csrf_exempt
101 98
    def message_updates(self, request):
102 99
        if request.is_ajax():
103 100
            cursor = {}
......
126 123
            finally:
127 124
                if self.user_cache[user]:
128 125
                    self.user_cursor[user] = self.user_cache[user][-1]['id']
129
        return HttpResponseRedirect(reverse('login'))
126
        return HttpResponseRedirect(reverse('group-routes'))
130 127
    #            else:
131 128
    #                request.session.pop('cursor', None)
132 129

  
b/static/js/jquery_csrf_protect.js
1
$(document).ajaxSend(function(event, xhr, settings) {
2
    function getCookie(name) {
3
        var cookieValue = null;
4
        if (document.cookie && document.cookie != '') {
5
            var cookies = document.cookie.split(';');
6
            for (var i = 0; i < cookies.length; i++) {
7
                var cookie = jQuery.trim(cookies[i]);
8
                // Does this cookie string begin with the name we want?
9
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
10
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
11
                    break;
12
                }
13
            }
14
        }
15
        return cookieValue;
16
    }
17
    function sameOrigin(url) {
18
        // url could be relative or scheme relative or absolute
19
        var host = document.location.host; // host + port
20
        var protocol = document.location.protocol;
21
        var sr_origin = '//' + host;
22
        var origin = protocol + sr_origin;
23
        // Allow absolute or scheme relative URLs to same origin
24
        return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
25
            (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
26
            // or any other URL that isn't scheme relative or absolute i.e relative.
27
            !(/^(\/\/|http:|https:).*/.test(url));
28
    }
29
    function safeMethod(method) {
30
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
31
    }
32

  
33
    if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
34
        xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
35
    }
36
});
b/templates/base.html
6 6
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
7 7

  
8 8
<script src="/static/js/jquery.min.js" type="text/javascript"></script>
9
<script src="/static/js/jquery_csrf_protect.js" type="text/javascript"></script>
9 10
<link rel="stylesheet" type="text/css" href="/static/css/base.css">
10 11
<link rel="stylesheet" type="text/css" href="/static/css/smoothness/jquery-ui-1.8.13.custom.css">
11 12
<script type="text/javascript" src="/static/js/jquery-ui-1.8.12.custom.min.js"></script>
b/templates/poller.js
27 27
	}
28 28
    });
29 29
    $("#message").select();
30
    {% if user.is_authenticated %}
30 31
    updater.start();
31 32
    updater.poll();
33
    {% endif %}
32 34
});
33 35

  
34 36
function newMessage(form) {
......
52 54
}
53 55

  
54 56
jQuery.postJSON = function(url, args, callback) {
55
    args._xsrf = getCookie("_xsrf");
56
    $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST",
57
    $.ajax({url: url, dataType: "text", type: "POST",
57 58
	    success: function(response) {
58 59
	if (callback) callback(eval("(" + response + ")"));
59 60
    }, error: function(response) {
......
90 91
    cursor: null,
91 92
    
92 93
    start: function() {
93
    	var args = {"_xsrf": getCookie("_xsrf")};
94
    	if (updater.cursor) args.cursor = updater.cursor;
95 94
    	$.ajax({url: "{% url fetch-existing %}", type: "POST", dataType: "text",
96
    		data: $.param(args), success: updater.onFetchExisting,
95
    		success: updater.onFetchExisting,
97 96
    		error: updater.onError});
98 97
        },
99 98
    
100 99
    poll: function() {
101
	var args = {"_xsrf": getCookie("_xsrf")};
102
	if (updater.cursor) args.cursor = updater.cursor;
100
	{% if user.is_authenticated %}
103 101
	$.ajax({url: "{% url fetch-updates %}", type: "POST", dataType: "text",
104
		data: $.param(args), success: updater.onSuccess,
102
		success: updater.onSuccess,
105 103
		error: updater.onError});
104
	{% endif %}
106 105
    },
107 106

  
108 107
    onSuccess: function(response) {
b/utils/proxy.py
43 43
        else:
44 44
            device = self.proccess_xml()
45 45
            if device.routing_options:
46
                cache.set("device", device, 600)
46
                cache.set("device", device)
47 47
                return device
48 48
            else:
49 49
                return False
......
188 188
                                    logger.info("Successfully committed @ %s" % self.device)
189 189
                                    newconfig = m.get_config(source='running', filter=('subtree',settings.ROUTES_FILTER)).data_xml
190 190
                                    retrieve = Retriever(xml=newconfig)
191
                                    cache.set("device", retrieve.proccess_xml(), 600)
191
                                    cache.set("device", retrieve.proccess_xml())
192 192
                                    
193 193
                                    if not commit_is_successful:
194 194
                                        raise Exception()

Also available in: Unified diff