Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f5f11cd8
authored
May 10, 2013
by
Bence Dányi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall_gui: code insanely refactored
parent
c3a5b38b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
0 deletions
+70
-0
firewall_gui/views.py
+70
-0
No files found.
firewall_gui/views.py
View file @
f5f11cd8
...
@@ -9,6 +9,76 @@ from firewall.models import *
...
@@ -9,6 +9,76 @@ from firewall.models import *
def
index
(
request
):
def
index
(
request
):
return
render
(
request
,
'firewall/index.html'
)
return
render
(
request
,
'firewall/index.html'
)
def
map_rule_target
(
rule
):
return
{
'name'
:
rule
.
vlan
.
name
,
'id'
:
rule
.
vlan
.
id
,
'type'
:
'vlan'
,
}
if
rule
.
vlan
else
{
'name'
:
rule
.
vlangroup
.
name
,
'id'
:
rule
.
vlangroup
.
id
,
'type'
:
'vlangroup'
,
}
if
rule
.
vlangroup
else
{
'name'
:
rule
.
hostgroup
.
name
,
'id'
:
rule
.
hostgroup
.
id
,
'type'
:
'hostgroup'
,
}
if
rule
.
hostgroup
else
{
'name'
:
rule
.
firewall
.
name
,
'id'
:
rule
.
firewall
.
id
,
'type'
:
'firewall'
,
}
if
rule
.
firewall
else
{
'name'
:
rule
.
host
.
hostname
,
'id'
:
rule
.
host
.
id
,
'type'
:
'host'
,
}
def
json_attr
(
entity
,
attr
):
common_names
=
{
'host'
:
'hostname'
,
'owner'
:
'username'
,
}
try
:
return
{
'ForeignKey'
:
lambda
entity
:
{
'id'
:
entity
.
id
,
'name'
:
getattr
(
entity
,
common_names
[
attr
]
if
attr
in
common_names
.
keys
()
else
'name'
)
}
if
entity
else
None
,
'DateTimeField'
:
lambda
entity
:
entity
.
isoformat
()
}[
entity
.
_meta
.
get_field_by_name
(
attr
)[
0
]
.
__class__
.
__name__
](
getattr
(
entity
,
attr
))
except
:
return
getattr
(
entity
,
attr
)
return
getattr
(
entity
,
attr
)
def
make_entity_lister
(
entity_type
,
mapping
):
def
jsonify
(
entity
):
result
=
{}
for
attr
in
mapping
:
if
type
(
attr
)
is
tuple
:
result
[
attr
[
0
]]
=
attr
[
1
](
entity
)
else
:
result
[
attr
]
=
json_attr
(
entity
,
attr
)
return
result
def
entity_lister
(
request
):
return
[
jsonify
(
entity
)
for
entity
in
entity_type
.
objects
.
all
()]
return
entity_lister
def
list_entities
(
request
,
name
):
return
HttpResponse
(
json
.
dumps
({
'rules'
:
make_entity_lister
(
Rule
,
[
'id'
,
(
'target'
,
map_rule_target
),
'r_type'
,
(
'direction'
,
lambda
rule
:
rule
.
get_direction_display
()),
'proto'
,
'owner'
,
'foreign_network'
,
'created_at'
,
'modified_at'
,
'nat'
,
'accept'
,
'description'
]),
}[
name
](
request
)),
content_type
=
'application/json'
)
def
list_rules
(
request
):
def
list_rules
(
request
):
rules
=
[{
rules
=
[{
...
...
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