Statistics
| Branch: | Tag: | Revision:

root / flowspec / admin.py @ 6d153302

History | View | Annotate | Download (2.3 kB)

1 a24fbf37 Leonidas Poulopoulos
from django.contrib import admin
2 a24fbf37 Leonidas Poulopoulos
from flowspy.flowspec.models import *
3 6ee21ffd Leonidas Poulopoulos
from flowspy.accounts.models import *
4 357d48dc Leonidas Poulopoulos
from utils import proxy as PR
5 d50fd7b6 Leonidas Poulopoulos
from flowspec.tasks import *
6 d50fd7b6 Leonidas Poulopoulos
from django.contrib.auth.models import User
7 d50fd7b6 Leonidas Poulopoulos
from django.contrib.auth.admin import UserAdmin
8 d50fd7b6 Leonidas Poulopoulos
from accounts.models import UserProfile
9 357d48dc Leonidas Poulopoulos
10 d50fd7b6 Leonidas Poulopoulos
11 d50fd7b6 Leonidas Poulopoulos
class RouteAdmin(admin.ModelAdmin):
12 d50fd7b6 Leonidas Poulopoulos
    
13 d50fd7b6 Leonidas Poulopoulos
    actions = ['deactivate']
14 d50fd7b6 Leonidas Poulopoulos
    
15 d50fd7b6 Leonidas Poulopoulos
    def deactivate(self, request, queryset):
16 fd3870ee Leonidas Poulopoulos
        queryset = queryset.filter(status='ACTIVE')
17 fd3870ee Leonidas Poulopoulos
        rows = queryset.update(status='PENDING')
18 d50fd7b6 Leonidas Poulopoulos
        response = batch_delete.delay(queryset, reason="ADMININACTIVE")
19 d50fd7b6 Leonidas Poulopoulos
        self.message_user(request, "Added request %s to job que. Check in a while for result" % response)
20 d50fd7b6 Leonidas Poulopoulos
    deactivate.short_description = "Remove selected routes from network"
21 d50fd7b6 Leonidas Poulopoulos
22 7d408f6f Leonidas Poulopoulos
    list_display = ('name', 'status', 'applier' , 'applier_peer', 'get_match', 'get_then', 'response', "expires", "comments")
23 7d408f6f Leonidas Poulopoulos
24 d50fd7b6 Leonidas Poulopoulos
    fieldsets = [
25 d50fd7b6 Leonidas Poulopoulos
        (None,               {'fields': ['name','applier']}),
26 d50fd7b6 Leonidas Poulopoulos
        ("Match",               {'fields': ['source', 'sourceport', 'destination', 'destinationport', 'port']}),
27 d50fd7b6 Leonidas Poulopoulos
        ('Advanced Match Statements', {'fields': ['dscp', 'fragmenttype', 'icmpcode', 'icmptype', 'packetlength', 'protocol', 'tcpflag'], 'classes': ['collapse']}),
28 d50fd7b6 Leonidas Poulopoulos
        ("Then",               {'fields': ['then' ]}),
29 d50fd7b6 Leonidas Poulopoulos
        (None,               {'fields': ['comments',]}),
30 d50fd7b6 Leonidas Poulopoulos
        
31 d50fd7b6 Leonidas Poulopoulos
    ]
32 d50fd7b6 Leonidas Poulopoulos
    
33 d50fd7b6 Leonidas Poulopoulos
class UserProfileInline(admin.StackedInline):
34 d50fd7b6 Leonidas Poulopoulos
    model = UserProfile
35 d50fd7b6 Leonidas Poulopoulos
    
36 d50fd7b6 Leonidas Poulopoulos
class UserProfileAdmin(UserAdmin):
37 d50fd7b6 Leonidas Poulopoulos
    inlines = [UserProfileInline]
38 b10e01d6 Leonidas Poulopoulos
#    fields = ('name', 'applier', 'expires')
39 357d48dc Leonidas Poulopoulos
40 357d48dc Leonidas Poulopoulos
    #def formfield_for_dbfield(self, db_field, **kwargs):
41 357d48dc Leonidas Poulopoulos
    #    if db_field.name == 'password':
42 357d48dc Leonidas Poulopoulos
    #        kwargs['widget'] = PasswordInput
43 357d48dc Leonidas Poulopoulos
    #    return db_field.formfield(**kwargs)
44 a24fbf37 Leonidas Poulopoulos
45 b10e01d6 Leonidas Poulopoulos
#admin.site.register(MatchAddress)
46 d50fd7b6 Leonidas Poulopoulos
admin.site.unregister(User)
47 a24fbf37 Leonidas Poulopoulos
admin.site.register(MatchPort)
48 a24fbf37 Leonidas Poulopoulos
admin.site.register(MatchDscp)
49 6ee21ffd Leonidas Poulopoulos
admin.site.register(UserProfile)
50 b10e01d6 Leonidas Poulopoulos
#admin.site.register(MatchFragmentType)
51 b10e01d6 Leonidas Poulopoulos
#admin.site.register(MatchIcmpCode)
52 b10e01d6 Leonidas Poulopoulos
#admin.site.register(MatchIcmpType)
53 b10e01d6 Leonidas Poulopoulos
#admin.site.register(MatchPacketLength)
54 b10e01d6 Leonidas Poulopoulos
#admin.site.register(MatchProtocol)
55 b10e01d6 Leonidas Poulopoulos
#admin.site.register(MatchTcpFlag)
56 a24fbf37 Leonidas Poulopoulos
admin.site.register(ThenAction)
57 b10e01d6 Leonidas Poulopoulos
#admin.site.register(ThenStatement)
58 b10e01d6 Leonidas Poulopoulos
#admin.site.register(MatchStatement)
59 d50fd7b6 Leonidas Poulopoulos
admin.site.register(Route, RouteAdmin)
60 d50fd7b6 Leonidas Poulopoulos
admin.site.register(User, UserProfileAdmin)
61 357d48dc Leonidas Poulopoulos
admin.site.disable_action('delete_selected')
62 357d48dc Leonidas Poulopoulos