Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
015de106
authored
Jan 26, 2015
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
network: firewall CRUD
parent
8916d530
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
205 additions
and
53 deletions
+205
-53
circle/firewall/models.py
+4
-0
circle/network/forms.py
+19
-2
circle/network/static/network/network.less
+17
-0
circle/network/tables.py
+11
-0
circle/network/templates/network/base.html
+0
-26
circle/network/templates/network/firewall-create.html
+18
-0
circle/network/templates/network/firewall-edit.html
+21
-0
circle/network/templates/network/firewall-list.html
+20
-0
circle/network/templates/network/menu.html
+3
-9
circle/network/urls.py
+35
-8
circle/network/views.py
+57
-8
No files found.
circle/firewall/models.py
View file @
015de106
...
...
@@ -970,6 +970,10 @@ class Firewall(models.Model):
logger
.
exception
(
"get_dhcp_clients failed"
)
return
{}
@models.permalink
def
get_absolute_url
(
self
):
return
(
'network.firewall'
,
None
,
{
'pk'
:
self
.
pk
})
class
Domain
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
40
,
validators
=
[
val_domain
],
...
...
circle/network/forms.py
View file @
015de106
...
...
@@ -23,8 +23,10 @@ from crispy_forms.helper import FormHelper
from
crispy_forms.layout
import
Layout
,
Fieldset
,
Div
,
Submit
,
BaseInput
from
crispy_forms.bootstrap
import
FormActions
,
FieldWithButtons
,
StrictButton
from
firewall.models
import
(
Host
,
Vlan
,
Domain
,
Group
,
Record
,
BlacklistItem
,
Rule
,
VlanGroup
,
SwitchPort
)
from
firewall.models
import
(
Host
,
Vlan
,
Domain
,
Group
,
Record
,
BlacklistItem
,
Rule
,
VlanGroup
,
SwitchPort
,
Firewall
)
class
LinkButton
(
BaseInput
):
...
...
@@ -88,6 +90,21 @@ class DomainForm(ModelForm):
model
=
Domain
class
FirewallForm
(
ModelForm
):
helper
=
FormHelper
()
helper
.
layout
=
Layout
(
Div
(
Fieldset
(
''
,
'name'
,
)
),
FormActions
(
Submit
(
'submit'
,
_
(
"Save"
)),
LinkButton
(
'back'
,
_
(
"Back"
),
reverse_lazy
(
'network.firewall_list'
))
)
)
class
Meta
:
model
=
Firewall
class
GroupForm
(
ModelForm
):
helper
=
FormHelper
()
helper
.
layout
=
Layout
(
...
...
circle/network/static/network/network.less
View file @
015de106
...
...
@@ -11,3 +11,20 @@
text-align: center;
width: 60px;
}
body {
padding-top: 40px;
}
/* note: this doesn't really work */
a i:hover {
text-decoration: none;
}
footer {
margin-top: 45px;
}
.messagelist {
margin-top: 25px;
}
circle/network/tables.py
View file @
015de106
...
...
@@ -233,3 +233,14 @@ class HostRecordsTable(Table):
fields
=
(
"type"
,
"fqdn"
)
order_by
=
(
"name"
,
)
empty_text
=
_
(
"No records."
)
class
FirewallTable
(
Table
):
pk
=
LinkColumn
(
'network.firewall'
,
args
=
[
A
(
'pk'
)],
verbose_name
=
"ID"
)
class
Meta
:
model
=
SwitchPort
attrs
=
{
'class'
:
'table table-striped'
}
fields
=
(
'pk'
,
'name'
,
)
order_by
=
'pk'
circle/network/templates/network/base.html
View file @
015de106
...
...
@@ -6,32 +6,6 @@
{% block title-site %}{% trans "Network" %} | CIRCLE{% endblock %}
{% block extra_link %}
<link
href=
'//fonts.googleapis.com/css?family=Source+Sans+Pro:200,400&subset=latin,latin-ext'
rel=
'stylesheet'
type=
'text/css'
>
<link
href=
"{% static "
network
/
network
.
css
"
%}"
rel=
"stylesheet"
>
{% endblock %}
{% block extra_css %}
<style
type=
"text/css"
>
body
{
padding-top
:
40px
;
}
/* note: this doesn't really work */
a
i
:hover
{
text-decoration
:
none
;
}
footer
{
margin-top
:
45px
;
}
.messagelist
{
margin-top
:
25px
;
}
</style>
{% endblock %}
{% block navbar-brand %}
<a
class=
"navbar-brand"
href=
"{% url "
network
.
index
"
%}"
>
CIRCLE Network
</a>
{% endblock %}
...
...
circle/network/templates/network/firewall-create.html
0 → 100644
View file @
015de106
{% extends "network/base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load crispy_forms_tags %}
{% block title-page %}{% trans "Create" %} | {% trans "firewall" %}{% endblock %}
{% block content %}
<div
class=
"page-header"
>
<h2>
{% trans "Create a new firewall" %}
</h2>
</div>
<div
class=
"row"
>
<div
class=
"col-sm-8"
>
{% crispy form %}
</div>
</div>
{% endblock %}
circle/network/templates/network/firewall-edit.html
0 → 100644
View file @
015de106
{% extends "network/base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load crispy_forms_tags %}
{% block title-page %}{{ switch_port_pk }} | {% trans "firewall" %}{% endblock %}
{% block content %}
<div
class=
"page-header"
>
<a
href=
"{% url "
network
.
firewall_delete
"
pk=
object.pk
%}"
class=
"btn btn-danger pull-right"
>
<i
class=
"fa fa-times-circle"
></i>
{% trans "Delete this firewall" %}
</a>
<h2>
{{ object.name }}
</h2>
</div>
<div
class=
"row"
>
<div
class=
"col-sm-5"
>
{% crispy form %}
</div>
</div>
{% endblock %}
circle/network/templates/network/firewall-list.html
0 → 100644
View file @
015de106
{% extends "network/base.html" %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% load l10n %}
{% load staticfiles %}
{% block title-page %}{% trans "Firewalls" %}{% endblock %}
{% block content %}
<div
class=
"page-header"
>
<a
href=
"{% url "
network
.
firewall_create
"
%}"
class=
"btn btn-success pull-right"
>
<i
class=
"fa fa-plus-circle"
></i>
{% trans "Create a new firewall" %}
</a>
<h1>
{% trans "Firewalls" %}
</h1>
</div>
<div
class=
"table-responsive"
>
{% render_table table %}
</div>
{% endblock %}
circle/network/templates/network/menu.html
View file @
015de106
...
...
@@ -22,6 +22,9 @@
{% url "network.switch_port_list" as u %}
{% trans "Switch ports" as t %}
{% include "network/menu-item.html" with href=u text=t %}
{% url "network.firewall_list" as u %}
{% trans "Firewalls" as t %}
{% include "network/menu-item.html" with href=u text=t %}
<li
class=
"dropdown{% if "
groups
"
in
request
.
path
%}
active
{%
endif
%}"
>
<a
href=
"#"
class=
"dropdown-toggle"
data-toggle=
"dropdown"
>
Groups
<b
class=
"caret"
></b></a>
...
...
@@ -35,12 +38,3 @@
{% include "network/menu-item.html" with href=u text=t %}
</ul>
</li>
{#
<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>
#}
{#
<li><a
href=
"/firewalls/"
>
{% trans "Firewalls" %}
</a></li>
#}
{#
<li><a
href=
"/domains/"
>
{% trans "Domains" %}
</a></li>
#}
{#
<li><a
href=
"/records/"
>
{% trans "DNS records" %}
</a></li>
#}
{#
<li><a
href=
"/blacklist/"
>
{% trans "Blacklist" %}
</a></li>
#}
circle/network/urls.py
View file @
015de106
...
...
@@ -16,26 +16,27 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
django.conf.urls
import
patterns
,
url
from
.views
import
(
IndexView
,
from
.views
import
(
IndexView
,
HostList
,
HostDetail
,
HostCreate
,
HostDelete
,
VlanList
,
VlanDetail
,
VlanDelete
,
VlanCreate
,
DomainList
,
DomainDetail
,
DomainDelete
,
DomainCreate
,
GroupList
,
GroupDetail
,
GroupDelete
,
GroupCreate
,
RecordList
,
RecordDetail
,
RecordCreate
,
RecordDelete
,
BlacklistList
,
BlacklistDetail
,
BlacklistDelete
,
BlacklistCreate
,
BlacklistList
,
BlacklistDetail
,
BlacklistDelete
,
BlacklistCreate
,
RuleList
,
RuleDetail
,
RuleDelete
,
RuleCreate
,
SwitchPortList
,
SwitchPortDetail
,
SwitchPortCreate
,
SwitchPortDelete
,
VlanGroupList
,
VlanGroupDetail
,
VlanGroupDelete
,
VlanGroupCreate
,
SwitchPortList
,
SwitchPortDetail
,
SwitchPortCreate
,
SwitchPortDelete
,
VlanGroupList
,
VlanGroupDetail
,
VlanGroupDelete
,
VlanGroupCreate
,
FirewallList
,
FirewallDetail
,
FirewallCreate
,
FirewallDelete
,
remove_host_group
,
add_host_group
,
remove_switch_port_device
,
add_switch_port_device
,
VlanAclUpdateView
)
VlanAclUpdateView
)
urlpatterns
=
patterns
(
''
,
url
(
'^$'
,
IndexView
.
as_view
(),
name
=
'network.index'
),
# blacklist
url
(
'^blacklist/$'
,
BlacklistList
.
as_view
(),
name
=
'network.blacklist_list'
),
url
(
'^blacklist/create$'
,
BlacklistCreate
.
as_view
(),
...
...
@@ -44,6 +45,8 @@ urlpatterns = patterns(
name
=
'network.blacklist'
),
url
(
'^blacklist/delete/(?P<pk>
\
d+)/$'
,
BlacklistDelete
.
as_view
(),
name
=
"network.blacklist_delete"
),
# domain
url
(
'^domains/$'
,
DomainList
.
as_view
(),
name
=
'network.domain_list'
),
url
(
'^domains/create$'
,
DomainCreate
.
as_view
(),
name
=
'network.domain_create'
),
...
...
@@ -51,17 +54,33 @@ urlpatterns = patterns(
name
=
'network.domain'
),
url
(
'^domains/delete/(?P<pk>
\
d+)/$'
,
DomainDelete
.
as_view
(),
name
=
"network.domain_delete"
),
# firewall
url
(
'^firewalls/$'
,
FirewallList
.
as_view
(),
name
=
'network.firewall_list'
),
url
(
'^firewalls/create$'
,
FirewallCreate
.
as_view
(),
name
=
'network.firewall_create'
),
url
(
'^firewalls/(?P<pk>
\
d+)/$'
,
FirewallDetail
.
as_view
(),
name
=
'network.firewall'
),
url
(
'^firewalls/delete/(?P<pk>
\
d+)/$'
,
FirewallDelete
.
as_view
(),
name
=
"network.firewall_delete"
),
# group (host)
url
(
'^groups/$'
,
GroupList
.
as_view
(),
name
=
'network.group_list'
),
url
(
'^groups/create$'
,
GroupCreate
.
as_view
(),
name
=
'network.group_create'
),
url
(
'^groups/(?P<pk>
\
d+)/$'
,
GroupDetail
.
as_view
(),
name
=
'network.group'
),
url
(
'^groups/delete/(?P<pk>
\
d+)/$'
,
GroupDelete
.
as_view
(),
name
=
"network.group_delete"
),
# host
url
(
'^hosts/$'
,
HostList
.
as_view
(),
name
=
'network.host_list'
),
url
(
'^hosts/create$'
,
HostCreate
.
as_view
(),
name
=
'network.host_create'
),
url
(
'^hosts/(?P<pk>
\
d+)/$'
,
HostDetail
.
as_view
(),
name
=
'network.host'
),
url
(
'^hosts/delete/(?P<pk>
\
d+)/$'
,
HostDelete
.
as_view
(),
name
=
"network.host_delete"
),
# record
url
(
'^records/$'
,
RecordList
.
as_view
(),
name
=
'network.record_list'
),
url
(
'^records/create$'
,
RecordCreate
.
as_view
(),
name
=
'network.record_create'
),
...
...
@@ -69,10 +88,14 @@ urlpatterns = patterns(
name
=
'network.record'
),
url
(
'^records/delete/(?P<pk>
\
d+)/$'
,
RecordDelete
.
as_view
(),
name
=
"network.record_delete"
),
# rule
url
(
'^rules/$'
,
RuleList
.
as_view
(),
name
=
'network.rule_list'
),
url
(
'^rules/create$'
,
RuleCreate
.
as_view
(),
name
=
'network.rule_create'
),
url
(
'^rules/(?P<pk>
\
d+)/$'
,
RuleDetail
.
as_view
(),
name
=
'network.rule'
),
# switchport
url
(
'^switchports/$'
,
SwitchPortList
.
as_view
(),
name
=
'network.switch_port_list'
),
url
(
'^switchports/create$'
,
SwitchPortCreate
.
as_view
(),
...
...
@@ -81,6 +104,8 @@ urlpatterns = patterns(
name
=
'network.switch_port'
),
url
(
'^switchports/delete/(?P<pk>
\
d+)/$'
,
SwitchPortDelete
.
as_view
(),
name
=
"network.switch_port_delete"
),
# vlan
url
(
'^vlans/$'
,
VlanList
.
as_view
(),
name
=
'network.vlan_list'
),
url
(
'^vlans/create$'
,
VlanCreate
.
as_view
(),
name
=
'network.vlan_create'
),
url
(
'^vlans/(?P<vid>
\
d+)/$'
,
VlanDetail
.
as_view
(),
name
=
'network.vlan'
),
...
...
@@ -88,6 +113,8 @@ urlpatterns = patterns(
name
=
'network.vlan-acl'
),
url
(
'^vlans/delete/(?P<vid>
\
d+)/$'
,
VlanDelete
.
as_view
(),
name
=
"network.vlan_delete"
),
# vlangroup
url
(
'^vlangroups/$'
,
VlanGroupList
.
as_view
(),
name
=
'network.vlan_group_list'
),
url
(
'^vlangroups/create$'
,
VlanGroupCreate
.
as_view
(),
...
...
circle/network/views.py
View file @
015de106
...
...
@@ -25,15 +25,20 @@ from django.http import HttpResponse, Http404
from
django_tables2
import
SingleTableView
from
firewall.models
import
(
Host
,
Vlan
,
Domain
,
Group
,
Record
,
BlacklistItem
,
Rule
,
VlanGroup
,
SwitchPort
,
EthernetDevice
)
from
firewall.models
import
(
Host
,
Vlan
,
Domain
,
Group
,
Record
,
BlacklistItem
,
Rule
,
VlanGroup
,
SwitchPort
,
EthernetDevice
,
Firewall
)
from
vm.models
import
Interface
from
.tables
import
(
HostTable
,
VlanTable
,
SmallHostTable
,
DomainTable
,
GroupTable
,
RecordTable
,
BlacklistItemTable
,
RuleTable
,
VlanGroupTable
,
SmallRuleTable
,
SmallGroupRuleTable
,
SmallRecordTable
,
SwitchPortTable
,
SmallDhcpTable
,
)
from
.forms
import
(
HostForm
,
VlanForm
,
DomainForm
,
GroupForm
,
RecordForm
,
BlacklistItemForm
,
RuleForm
,
VlanGroupForm
,
SwitchPortForm
)
from
.tables
import
(
HostTable
,
VlanTable
,
SmallHostTable
,
DomainTable
,
GroupTable
,
RecordTable
,
BlacklistItemTable
,
RuleTable
,
VlanGroupTable
,
SmallRuleTable
,
SmallGroupRuleTable
,
SmallRecordTable
,
SwitchPortTable
,
SmallDhcpTable
,
FirewallTable
)
from
.forms
import
(
HostForm
,
VlanForm
,
DomainForm
,
GroupForm
,
RecordForm
,
BlacklistItemForm
,
RuleForm
,
VlanGroupForm
,
SwitchPortForm
,
FirewallForm
)
from
django.contrib
import
messages
from
django.contrib.messages.views
import
SuccessMessageMixin
...
...
@@ -284,6 +289,50 @@ class DomainDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
return
context
class
FirewallList
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SingleTableView
):
model
=
Firewall
table_class
=
FirewallTable
template_name
=
"network/firewall-list.html"
table_pagination
=
False
class
FirewallDetail
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
Firewall
template_name
=
"network/firewall-edit.html"
form_class
=
FirewallForm
success_message
=
_
(
u'Succesfully modified firewall.'
)
def
get_success_url
(
self
):
if
'pk'
in
self
.
kwargs
:
return
reverse_lazy
(
'network.firewall'
,
kwargs
=
self
.
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
FirewallDetail
,
self
)
.
get_context_data
(
**
kwargs
)
return
context
class
FirewallCreate
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
Firewall
template_name
=
"network/firewall-create.html"
form_class
=
FirewallForm
success_message
=
_
(
u'Successfully created firewall.'
)
class
FirewallDelete
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DeleteView
):
model
=
Firewall
template_name
=
"network/confirm/base_delete.html"
def
get_success_url
(
self
):
next
=
self
.
request
.
POST
.
get
(
'next'
)
if
next
:
return
next
else
:
return
reverse_lazy
(
'network.firewall_list'
)
class
GroupList
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SingleTableView
):
model
=
Group
table_class
=
GroupTable
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment