Revision d50fd7b6
b/flowspec/admin.py | ||
---|---|---|
2 | 2 |
from flowspy.flowspec.models import * |
3 | 3 |
from flowspy.accounts.models import * |
4 | 4 |
from utils import proxy as PR |
5 |
from flowspec.tasks import * |
|
6 |
from django.contrib.auth.models import User |
|
7 |
from django.contrib.auth.admin import UserAdmin |
|
8 |
from accounts.models import UserProfile |
|
5 | 9 |
|
6 |
#class RouteAdmin(admin.ModelAdmin): |
|
7 |
# |
|
8 |
# actions = ['deactivate'] |
|
9 |
# |
|
10 |
# def deactivate(self, request, queryset): |
|
11 |
# applier = PR.Applier(route_objects=queryset) |
|
12 |
# commit, response = applier.apply(configuration=applier.delete_routes()) |
|
13 |
# if commit: |
|
14 |
# rows = queryset.update(is_online=False, is_active=False) |
|
15 |
# queryset.update(response="Successfully removed route from network") |
|
16 |
# self.message_user(request, "Successfully removed %s routes from network" % rows) |
|
17 |
# else: |
|
18 |
# self.message_user(request, "Could not remove routes from network") |
|
19 |
# deactivate.short_description = "Deactivate selected routes from network" |
|
20 |
# |
|
21 |
# list_display = ('name', 'is_online', 'applier', 'get_match', 'get_then', 'response') |
|
22 |
# fieldsets = [ |
|
23 |
# (None, {'fields': ['name','applier']}), |
|
24 |
# ("Match", {'fields': ['source', 'sourceport', 'destination', 'destinationport', 'port']}), |
|
25 |
# ('Advanced Match Statements', {'fields': ['dscp', 'fragmenttype', 'icmpcode', 'icmptype', 'packetlength', 'protocol', 'tcpflag'], 'classes': ['collapse']}), |
|
26 |
# ("Then", {'fields': ['then' ]}), |
|
27 |
# (None, {'fields': ['comments',]}), |
|
28 |
# |
|
29 |
# ] |
|
10 |
|
|
11 |
class RouteAdmin(admin.ModelAdmin): |
|
12 |
|
|
13 |
actions = ['deactivate'] |
|
14 |
|
|
15 |
def deactivate(self, request, queryset): |
|
16 |
response = batch_delete.delay(queryset, reason="ADMININACTIVE") |
|
17 |
self.message_user(request, "Added request %s to job que. Check in a while for result" % response) |
|
18 |
deactivate.short_description = "Remove selected routes from network" |
|
19 |
|
|
20 |
list_display = ('name', 'status', 'applier' , 'applier_peer', 'get_match', 'get_then', 'response') |
|
21 |
fieldsets = [ |
|
22 |
(None, {'fields': ['name','applier']}), |
|
23 |
("Match", {'fields': ['source', 'sourceport', 'destination', 'destinationport', 'port']}), |
|
24 |
('Advanced Match Statements', {'fields': ['dscp', 'fragmenttype', 'icmpcode', 'icmptype', 'packetlength', 'protocol', 'tcpflag'], 'classes': ['collapse']}), |
|
25 |
("Then", {'fields': ['then' ]}), |
|
26 |
(None, {'fields': ['comments',]}), |
|
27 |
|
|
28 |
] |
|
29 |
|
|
30 |
class UserProfileInline(admin.StackedInline): |
|
31 |
model = UserProfile |
|
32 |
|
|
33 |
class UserProfileAdmin(UserAdmin): |
|
34 |
inlines = [UserProfileInline] |
|
30 | 35 |
# fields = ('name', 'applier', 'expires') |
31 | 36 |
|
32 | 37 |
#def formfield_for_dbfield(self, db_field, **kwargs): |
... | ... | |
35 | 40 |
# return db_field.formfield(**kwargs) |
36 | 41 |
|
37 | 42 |
#admin.site.register(MatchAddress) |
43 |
admin.site.unregister(User) |
|
38 | 44 |
admin.site.register(MatchPort) |
39 | 45 |
admin.site.register(MatchDscp) |
40 | 46 |
admin.site.register(UserProfile) |
... | ... | |
47 | 53 |
admin.site.register(ThenAction) |
48 | 54 |
#admin.site.register(ThenStatement) |
49 | 55 |
#admin.site.register(MatchStatement) |
50 |
admin.site.register(Route) |
|
51 |
|
|
56 |
admin.site.register(Route, RouteAdmin)
|
|
57 |
admin.site.register(User, UserProfileAdmin) |
|
52 | 58 |
admin.site.disable_action('delete_selected') |
53 | 59 |
|
54 | 60 |
|
b/flowspec/models.py | ||
---|---|---|
45 | 45 |
("EXPIRED", "EXPIRED"), |
46 | 46 |
("PENDING", "PENDING"), |
47 | 47 |
("OUTOFSYNC", "OUTOFSYNC"), |
48 |
("INACTIVE", "INACTIVE"), |
|
48 |
("INACTIVE", "INACTIVE"), |
|
49 |
("ADMININACTIVE", "ADMININACTIVE"), |
|
49 | 50 |
) |
50 | 51 |
|
51 | 52 |
|
... | ... | |
299 | 300 |
|
300 | 301 |
get_match.short_description = 'Match statement' |
301 | 302 |
get_match.allow_tags = True |
303 |
|
|
304 |
@property |
|
305 |
def applier_peer(self): |
|
306 |
try: |
|
307 |
applier_peer = self.applier.get_profile().peer |
|
308 |
except: |
|
309 |
applier_peer = None |
|
310 |
return applier_peer |
|
302 | 311 |
|
303 | 312 |
def send_message(msg, user): |
304 | 313 |
# username = user.username |
b/flowspec/tasks.py | ||
---|---|---|
71 | 71 |
if "reason" in kwargs and kwargs['reason']=='EXPIRED': |
72 | 72 |
status = 'EXPIRED' |
73 | 73 |
reason_text = " Reason: %s " %status |
74 |
elif "reason" in kwargs and kwargs['reason']!='EXPIRED': |
|
75 |
status = kwargs['reason'] |
|
76 |
reason_text = " Reason: %s " %status |
|
74 | 77 |
else: |
75 | 78 |
status = "ERROR" |
76 | 79 |
for route in routes: |
... | ... | |
102 | 105 |
if route_name: |
103 | 106 |
routes = routes.filter(name=route_name) |
104 | 107 |
for route in routes: |
105 |
if route.has_expired() and route.status != 'EXPIRED':
|
|
108 |
if route.has_expired() and (route.status != 'EXPIRED' or route.status != 'ADMININACTIVE' or route.status != 'INACTIVE'):
|
|
106 | 109 |
logger.info('Expiring route %s' %route.name) |
107 | 110 |
subtask(delete).delay(route, reason="EXPIRED") |
111 |
elif route.has_expired() and (route.status == 'ADMININACTIVE' or route.status == 'INACTIVE'): |
|
112 |
route.status = 'EXPIRED' |
|
113 |
route.response = 'Route Expired' |
|
114 |
route.save() |
|
108 | 115 |
elif route.status != 'EXPIRED': |
109 | 116 |
route.check_sync() |
110 | 117 |
|
b/flowspec/views.py | ||
---|---|---|
119 | 119 |
messages.add_message(request, messages.WARNING, |
120 | 120 |
"Insufficient rights to edit rule %s" %(route_slug)) |
121 | 121 |
return HttpResponseRedirect(reverse("group-routes")) |
122 |
if route_edit.status == "ADMININACTIVE" : |
|
123 |
messages.add_message(request, messages.WARNING, |
|
124 |
"Administrator has disabled editing of rule %s" %(route_slug)) |
|
125 |
return HttpResponseRedirect(reverse("group-routes")) |
|
126 |
if route_edit.status == "EXPIRED" : |
|
127 |
messages.add_message(request, messages.WARNING, |
|
128 |
"Cannot edit the expired rule %s. Contact helpdesk to enable it" %(route_slug)) |
|
129 |
return HttpResponseRedirect(reverse("group-routes")) |
|
122 | 130 |
route_original = deepcopy(route_edit) |
123 | 131 |
if request.POST: |
124 | 132 |
form = RouteForm(request.POST, instance = route_edit) |
b/poller/application.py | ||
---|---|---|
12 | 12 |
traceback.print_exc() |
13 | 13 |
|
14 | 14 |
got_request_exception.connect(exception_printer) |
15 |
|
|
16 | 15 |
call_command('syncdb') |
17 | 16 |
|
18 | 17 |
application = WSGIHandler() |
Also available in: Unified diff