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
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):
...
@@ -425,6 +425,13 @@ def autocomplete(request, entity):
except
Exception
as
e
:
except
Exception
as
e
:
return
HttpResponse
(
'>:-3'
,
status
=
500
)
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
):
def
save_rule
(
request
):
data
=
json
.
loads
(
request
.
body
)
data
=
json
.
loads
(
request
.
body
)
...
@@ -432,6 +439,7 @@ def save_rule(request):
...
@@ -432,6 +439,7 @@ def save_rule(request):
rule
=
get_object_or_404
(
Rule
,
id
=
data
[
'id'
])
rule
=
get_object_or_404
(
Rule
,
id
=
data
[
'id'
])
else
:
else
:
rule
=
Rule
.
objects
.
create
()
rule
=
Rule
.
objects
.
create
()
errors
=
[]
rule
.
direction
=
data
[
'direction'
][
'value'
]
rule
.
direction
=
data
[
'direction'
][
'value'
]
rule
.
description
=
data
[
'description'
]
rule
.
description
=
data
[
'description'
]
rule
.
dport
=
data
[
'dport'
]
rule
.
dport
=
data
[
'dport'
]
...
@@ -439,15 +447,17 @@ def save_rule(request):
...
@@ -439,15 +447,17 @@ def save_rule(request):
rule
.
proto
=
data
[
'proto'
][
'value'
]
rule
.
proto
=
data
[
'proto'
][
'value'
]
rule
.
extra
=
data
[
'extra'
]
rule
.
extra
=
data
[
'extra'
]
rule
.
accept
=
data
[
'accept'
]
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
=
data
[
'nat'
]
rule
.
nat_dport
=
data
[
'nat_dport'
]
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
.
host
=
get_object_or_
error
(
Host
,
errors
,
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
.
hostgroup
=
get_object_or_
error
(
Group
,
errors
,
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
.
vlan
=
get_object_or_
error
(
Vlan
,
errors
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'vlan'
else
None
rule
.
vlangroup
=
get_object_or_
404
(
VlanGroup
,
name
=
data
[
'target'
][
rule
.
vlangroup
=
get_object_or_
error
(
VlanGroup
,
errors
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'vlangroup'
else
None
'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
.
firewall
=
get_object_or_error
(
Firewall
,
errors
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'firewall'
else
None
rule
.
foreign_network
=
get_object_or_404
(
VlanGroup
,
name
=
data
[
'foreignNetwork'
][
'name'
])
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
()
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