Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
e9a40a29
authored
May 09, 2013
by
Bence Dányi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall_gui: validate Rule fields
parent
a7d77040
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
8 deletions
+12
-8
firewall_gui/views.py
+12
-8
No files found.
firewall_gui/views.py
View file @
e9a40a29
...
@@ -452,17 +452,21 @@ def save_rule(request):
...
@@ -452,17 +452,21 @@ 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_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_error
(
Host
,
errors
,
hostname
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'host'
else
None
set_field
(
rule
,
'owner'
,
errors
,
username
=
data
[
'owner'
][
'name'
])
rule
.
hostgroup
=
get_object_or_error
(
Group
,
errors
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'hostgroup'
else
None
for
attr
in
[
'host'
,
'hostgroup'
,
'vlan'
,
'vlangroup'
,
'firewall'
]:
rule
.
vlan
=
get_object_or_error
(
Vlan
,
errors
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'vlan'
else
None
searchBy
=
'name'
if
attr
!=
'host'
else
'hostname'
rule
.
vlangroup
=
get_object_or_error
(
VlanGroup
,
errors
,
name
=
data
[
'target'
][
if
data
[
'target'
][
'type'
]
==
attr
:
'name'
])
if
data
[
'target'
][
'type'
]
==
'vlangroup'
else
None
set_field
(
rule
,
attr
,
errors
,
**
{
searchBy
:
data
[
'target'
][
'name'
]})
rule
.
firewall
=
get_object_or_error
(
Firewall
,
errors
,
name
=
data
[
'target'
][
'name'
])
if
data
[
'target'
][
'type'
]
==
'firewall'
else
None
else
:
rule
.
foreign_network
=
get_object_or_error
(
VlanGroup
,
errors
,
name
=
data
[
'foreignNetwork'
][
'name'
])
setattr
(
rule
,
attr
,
None
)
set_field
(
rule
,
'foreign_network'
,
errors
,
name
=
data
[
'foreignNetwork'
][
'name'
])
if
len
(
errors
)
>
0
:
if
len
(
errors
)
>
0
:
return
HttpResponse
(
json
.
dumps
(
errors
),
content_type
=
'application/json'
,
status
=
404
)
return
HttpResponse
(
json
.
dumps
(
errors
),
content_type
=
'application/json'
,
status
=
404
)
try
:
rule
.
full_clean
()
except
Exception
as
e
:
return
HttpResponse
(
json
.
dumps
(
e
.
message_dict
),
content_type
=
'application/json'
,
status
=
409
)
rule
.
save
()
rule
.
save
()
return
HttpResponse
(
'KTHXBYE'
)
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