root / flowspec / admin.py @ 2a2ea58f
History | View | Annotate | Download (3.2 kB)
1 |
from django.contrib import admin |
---|---|
2 |
from flowspy.flowspec.models import * |
3 |
from flowspy.accounts.models import * |
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 flowspy.peers.models import * |
9 |
from flowspy.flowspec.forms import * |
10 |
import datetime |
11 |
from django.conf import settings |
12 |
|
13 |
from flowspy.monkey_patch.forms import UserCreationForm, UserChangeForm |
14 |
|
15 |
class RouteAdmin(admin.ModelAdmin): |
16 |
form = RouteForm |
17 |
actions = ['deactivate']
|
18 |
|
19 |
def deactivate(self, request, queryset): |
20 |
queryset = queryset.filter(status='ACTIVE')
|
21 |
response = batch_delete.delay(queryset, reason="ADMININACTIVE")
|
22 |
self.message_user(request, "Added request %s to job que. Check in a while for result" % response) |
23 |
deactivate.short_description = "Remove selected routes from network"
|
24 |
|
25 |
def save_model(self, request, obj, form, change): |
26 |
obj.status = "PENDING"
|
27 |
obj.save() |
28 |
if change:
|
29 |
obj.commit_edit() |
30 |
else:
|
31 |
obj.commit_add() |
32 |
|
33 |
def has_delete_permission(self, request, obj=None): |
34 |
return False |
35 |
|
36 |
list_display = ('name', 'status', 'applier' , 'applier_peer', 'get_match', 'get_then', 'response', "expires", "comments") |
37 |
|
38 |
fieldsets = [ |
39 |
(None, {'fields': ['name','applier']}), |
40 |
("Match", {'fields': ['source', 'sourceport', 'destination', 'destinationport', 'port']}), |
41 |
('Advanced Match Statements', {'fields': ['dscp', 'fragmenttype', 'icmpcode', 'icmptype', 'packetlength', 'protocol', 'tcpflag'], 'classes': ['collapse']}), |
42 |
("Then", {'fields': ['then' ]}), |
43 |
("Expires", {'fields': ['expires' ]}), |
44 |
(None, {'fields': ['comments',]}), |
45 |
|
46 |
] |
47 |
|
48 |
|
49 |
|
50 |
class UserProfileInline(admin.StackedInline): |
51 |
model = UserProfile |
52 |
|
53 |
class UserProfileAdmin(UserAdmin): |
54 |
add_form = UserCreationForm |
55 |
form = UserChangeForm |
56 |
actions = ['deactivate', 'activate'] |
57 |
list_display = ('username', 'email', 'first_name' , 'last_name', 'is_staff', 'is_active', 'is_superuser', 'get_userprofile_peer') |
58 |
inlines = [UserProfileInline] |
59 |
|
60 |
def deactivate(self, request, queryset): |
61 |
queryset = queryset.update(is_active=False)
|
62 |
deactivate.short_description = "Deactivate Selected Users"
|
63 |
|
64 |
def activate(self, request, queryset): |
65 |
queryset = queryset.update(is_active=True)
|
66 |
activate.short_description = "Activate Selected Users"
|
67 |
|
68 |
def get_userprofile_peer(self, instance): |
69 |
# instance is User instance
|
70 |
return instance.get_profile().peer
|
71 |
get_userprofile_peer.short_description = "User Peer"
|
72 |
# fields = ('name', 'applier', 'expires')
|
73 |
|
74 |
#def formfield_for_dbfield(self, db_field, **kwargs):
|
75 |
# if db_field.name == 'password':
|
76 |
# kwargs['widget'] = PasswordInput
|
77 |
# return db_field.formfield(**kwargs)
|
78 |
|
79 |
admin.site.unregister(User) |
80 |
admin.site.register(MatchPort) |
81 |
admin.site.register(MatchProtocol) |
82 |
admin.site.register(MatchDscp) |
83 |
admin.site.register(ThenAction) |
84 |
admin.site.register(Route, RouteAdmin) |
85 |
admin.site.register(User, UserProfileAdmin) |
86 |
admin.site.disable_action('delete_selected')
|
87 |
|
88 |
|