Commit 5e89f776 by Kálmán Viktor

network: add rule views

parent 32045459
......@@ -5,7 +5,8 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, Row, HTML
from crispy_forms.layout import Div, ButtonHolder, Submit, BaseInput
from firewall.models import Host, Vlan, Domain, Group, Record, Blacklist
from firewall.models import (Host, Vlan, Domain, Group, Record, Blacklist,
Rule)
class LinkButton(BaseInput):
......@@ -189,6 +190,51 @@ class RecordForm(ModelForm):
model = Record
class RuleForm(ModelForm):
helper = FormHelper()
helper.layout = Layout(
Div(
Row(
Div(
Fieldset(
'Identity',
'direction',
'description',
'foreign_network',
'dport',
'sport',
'proto',
'extra',
'accept',
'owner',
'r_type',
'nat',
'nat_dport',
),
Fieldset(
'External',
'vlan',
'vlangroup',
'host',
'hostgroup',
'firewall'
),
css_class='span8'),
Div(
HTML('<p>hello</p>'),
css_class='span4'),
),
ButtonHolder(
Submit('submit', 'Save'),
LinkButton('back', 'Back', reverse_lazy(
'network.rule_list'))
),
css_class="form-horizontal"))
class Meta:
model = Rule
class VlanForm(ModelForm):
helper = FormHelper()
helper.layout = Layout(
......
from django_tables2 import Table, A
from django_tables2.columns import LinkColumn
from django_tables2.columns import LinkColumn, TemplateColumn
from firewall.models import Host, Vlan, Domain, Group, Record
from firewall.models import Host, Vlan, Domain, Group, Record, Rule
class BlacklistTable(Table):
......@@ -68,6 +68,18 @@ class RecordTable(Table):
order_by = 'name'
class RuleTable(Table):
r_type = LinkColumn('network.rule', args=[A('pk')])
color_desc = TemplateColumn(template_name="network/color_desc.html")
class Meta:
model = Rule
attrs = {'class': 'table table-striped table-hover table-condensed'}
fields = ('r_type', 'color_desc', 'owner', 'extra', 'direction',
'accept', 'proto', 'sport', 'dport', 'nat', 'nat_dport', )
order_by = 'direction'
class VlanTable(Table):
name = LinkColumn('network.vlan', args=[A('vid')])
......
{% load i18n %}
{% load l10n %}
<span style="color: #FF0000;">[{{ record.r_type }}]</span>
{% if record.direction == "1" %}{{ record.foreign_network }}{% else %}{{ record.r_type }}{% endif %}
{#<span style="color: #0000FF;"> ▸ </span>#}
<i class="icon-arrow-right"></i>
{% if record.direction == "0" %}{{ record.foreign_network }}{% else %}{{ record.r_type }}{% endif %}
<span style="color: #00FF00;">
{% if record.proto %}
proto={{ record.proto }}
{% endif %}
{% if record.sport %}
sport={{ record.sport }}
{% endif %}
{% if record.dport %}
dport={{ record.dport }}
{% endif %}
{{ record.description }}
......@@ -13,8 +13,11 @@
{% include "network/menu-item.html" with href=u text="Records" %}
{% url network.blacklist_list as u %}
{% include "network/menu-item.html" with href=u text="Blacklists" %}
{# <li><a href="/vlans/">{% trans "Vlans" %}</a></li> #}
{% url network.rule_list as u %}
{% include "network/menu-item.html" with href=u text="Rules" %}
{# <li><a href="/vlans/">{% trans "Vlans" %}</a></li> #}
{# <li><a href="/vlangroups/">{% trans "Vlan groups" %}</a></li> #}
{# <li><a href="/hostgroups/">{% trans "Host groups" %}</a></li> #}
{# <li><a href="/hosts/">{% trans "Hosts" %}</a></li> #}
......
{% extends "network/base.html" %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% load l10n %}
{% load staticfiles %}
{% load crispy_forms_tags %}
{% block content %}
<div class="page-heading">
<h1>{{ form.hostname.value }} <small>details of rule</small></h1>
</div>
{% crispy form %}
{% endblock %}
{% extends "network/base.html" %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% load l10n %}
{% load staticfiles %}
{% block content %}
<div class="page-heading">
<h1>Rules <small>list of all rules</small></h1>
</div>
{% render_table table %}
{% endblock %}
......@@ -2,7 +2,8 @@ from django.conf.urls import patterns, url
from .views import (IndexView, HostList, HostDetail, VlanList, VlanDetail,
DomainList, DomainDetail, GroupList, GroupDetail,
RecordList, RecordDetail, BlacklistList, BlacklistDetail)
RecordList, RecordDetail, BlacklistList, BlacklistDetail,
RuleList, RuleDetail)
urlpatterns = patterns(
......@@ -22,6 +23,9 @@ urlpatterns = patterns(
url('^records/$', RecordList.as_view(), name='network.record_list'),
url('^records/(?P<pk>\d+)/$', RecordDetail.as_view(),
name='network.record'),
url('^rules/$', RuleList.as_view(), name='network.rule_list'),
url('^rules/(?P<pk>\d+)/$', RuleDetail.as_view(),
name='network.rule'),
url('^vlans/$', VlanList.as_view(), name='network.vlan_list'),
url('^vlans/(?P<vid>\d+)/$', VlanDetail.as_view(), name='network.vlan'),
)
......@@ -4,11 +4,12 @@ from django.core.urlresolvers import reverse_lazy
from django_tables2 import SingleTableView
from firewall.models import Host, Vlan, Domain, Group, Record, Blacklist
from firewall.models import (Host, Vlan, Domain, Group, Record, Blacklist,
Rule)
from .tables import (HostTable, VlanTable, SmallHostTable, DomainTable,
GroupTable, RecordTable, BlacklistTable)
GroupTable, RecordTable, BlacklistTable, RuleTable)
from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm,
BlacklistForm)
BlacklistForm, RuleForm)
from itertools import chain
......@@ -26,10 +27,11 @@ class IndexView(TemplateView):
hosts = Host.objects.all().order_by('-modified_at')[:size]
records = Record.objects.all().order_by('-modified_at')[:size]
vlans = Vlan.objects.all().order_by('-modified_at')[:size]
rules = Rule.objects.all().order_by('-modified_at')[:size]
result_list = []
for i in (sorted(chain(blacklists, domains, groups, hosts,
records, vlans),
records, vlans, rules),
key=lambda x: x.modified_at, reverse=True)[:size]):
result_list.append(
{
......@@ -151,6 +153,23 @@ class RecordDetail(UpdateView):
return reverse_lazy('network.record', kwargs=self.kwargs)
class RuleList(SingleTableView):
model = Rule
table_class = RuleTable
template_name = "network/rule-list.html"
table_pagination = False
class RuleDetail(UpdateView):
model = Rule
template_name = "network/rule-edit.html"
form_class = RuleForm
def get_success_url(self):
if 'pk' in self.kwargs:
return reverse_lazy('network.rule', kwargs=self.kwargs)
class VlanList(SingleTableView):
model = Vlan
table_class = VlanTable
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment