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
cf56970e
authored
May 09, 2013
by
Bence Dányi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall_gui: some server-side validation
parent
e0580823
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
firewall_gui/views.py
+18
-8
No files found.
firewall_gui/views.py
View file @
cf56970e
...
...
@@ -425,6 +425,13 @@ def autocomplete(request, entity):
except
Exception
as
e
:
return
HttpResponse
(
'>:-3'
,
status
=
500
)
def
get_object_or_error
(
entity
,
errors
,
**
kwargs
):
try
:
return
entity
.
objects
.
get
(
**
kwargs
)
except
:
errors
.
append
((
'
%(entity)
s with the name "
%(name)
s" does not exists!'
)
%
{
'entity'
:
getattr
(
entity
,
'__name__'
),
'name'
:
kwargs
.
values
()[
0
]})
return
None
def
save_rule
(
request
):
data
=
json
.
loads
(
request
.
body
)
...
...
@@ -432,6 +439,7 @@ def save_rule(request):
rule
=
get_object_or_404
(
Rule
,
id
=
data
[
'id'
])
else
:
rule
=
Rule
.
objects
.
create
()
errors
=
[]
rule
.
direction
=
data
[
'direction'
][
'value'
]
rule
.
description
=
data
[
'description'
]
rule
.
dport
=
data
[
'dport'
]
...
...
@@ -439,15 +447,17 @@ def save_rule(request):
rule
.
proto
=
data
[
'proto'
][
'value'
]
rule
.
extra
=
data
[
'extra'
]
rule
.
accept
=
data
[
'accept'
]
rule
.
owner
=
get_object_or_
404
(
User
,
username
=
data
[
'owner'
][
'name'
])
rule
.
owner
=
get_object_or_
error
(
User
,
errors
,
username
=
data
[
'owner'
][
'name'
])
rule
.
nat
=
data
[
'nat'
]
rule
.
nat_dport
=
data
[
'nat_dport'
]
rule
.
host
=
get_object_or_
404
(
Host
,
hostname
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'host'
else
None
rule
.
hostgroup
=
get_object_or_
404
(
Group
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'hostgroup'
else
None
rule
.
vlan
=
get_object_or_
404
(
Vlan
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'vlan'
else
None
rule
.
vlangroup
=
get_object_or_
404
(
VlanGroup
,
name
=
data
[
'target'
][
rule
.
host
=
get_object_or_
error
(
Host
,
errors
,
hostname
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'host'
else
None
rule
.
hostgroup
=
get_object_or_
error
(
Group
,
errors
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'hostgroup'
else
None
rule
.
vlan
=
get_object_or_
error
(
Vlan
,
errors
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'vlan'
else
None
rule
.
vlangroup
=
get_object_or_
error
(
VlanGroup
,
errors
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'vlangroup'
else
None
rule
.
firewall
=
get_object_or_404
(
Firewall
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'firewall'
else
None
rule
.
foreign_network
=
get_object_or_404
(
VlanGroup
,
name
=
data
[
'foreignNetwork'
][
'name'
])
rule
.
firewall
=
get_object_or_error
(
Firewall
,
errors
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'firewall'
else
None
rule
.
foreign_network
=
get_object_or_error
(
VlanGroup
,
errors
,
name
=
data
[
'foreignNetwork'
][
'name'
])
if
len
(
errors
)
>
0
:
return
HttpResponse
(
json
.
dumps
(
errors
),
content_type
=
'application/json'
,
status
=
404
)
rule
.
save
()
return
HttpResponse
(
str
(
json
.
loads
(
request
.
body
))
)
return
HttpResponse
(
'KTHXBYE'
)
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