Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0d815cd3
authored
May 28, 2013
by
Bence Dányi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall_gui: allow to save new hosts
parent
e6e4c489
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
17 deletions
+42
-17
cloud/urls.py
+1
-1
firewall_gui/static/partials/host-edit.html
+1
-1
firewall_gui/static/partials/host-list.html
+1
-1
firewall_gui/views.py
+39
-14
No files found.
cloud/urls.py
View file @
0d815cd3
...
...
@@ -118,7 +118,7 @@ urlpatterns = patterns('',
url
(
r'^firewall/(?P<name>\w+)/(?P<id>\d+)/delete/'
,
'firewall_gui.views.delete_entity'
),
url
(
r'^firewall/rules/new/$'
,
'firewall_gui.views.show_rule'
),
# url(r'^firewall/hosts/save/$', 'firewall_gui.views.save
_host'),
url
(
r'^firewall/hosts/new/$'
,
'firewall_gui.views.show
_host'
),
# url(r'^firewall/vlans/save/$', 'firewall_gui.views.save_vlan'),
# url(r'^firewall/vlangroups/save/$', 'firewall_gui.views.save_vlangroup'),
# url(r'^firewall/hostgroups/save/$', 'firewall_gui.views.save_hostgroup'),
...
...
firewall_gui/static/partials/host-edit.html
View file @
0d815cd3
...
...
@@ -163,7 +163,7 @@
</span>
</div>
<div
class=
"input-append has-tooltip"
title=
"Hostgroups of this host"
>
<input
class=
"span2 hostgroup"
id=
"
hostgroup
"
type=
"text"
ng-model=
"newGroup"
>
<input
class=
"span2 hostgroup"
id=
"
groups
"
type=
"text"
ng-model=
"newGroup"
>
<button
class=
"btn"
type=
"button"
ng-click=
"addHostGroup(newGroup)"
>
Add
</button>
<span
class=
"help-inline"
ng-bind=
"getError('groups')"
></span>
</div>
...
...
firewall_gui/static/partials/host-list.html
View file @
0d815cd3
...
...
@@ -16,7 +16,7 @@
<form
class=
"navbar-search"
style=
"margin: 20px"
>
<input
type=
"text"
class=
"search-query"
placeholder=
"Search"
ng-model=
"query"
>
</form>
<a
style=
"margin-top:
19
px"
href=
"#/hosts/new"
class=
"btn"
>
New host
</a>
<a
style=
"margin-top:
20
px"
href=
"#/hosts/new"
class=
"btn"
>
New host
</a>
</div>
</div>
<table
class=
"table table-striped"
>
...
...
firewall_gui/views.py
View file @
0d815cd3
...
...
@@ -252,8 +252,9 @@ def show_rule(request, id=None):
return
HttpResponse
(
json
.
dumps
(
rule
),
content_type
=
'application/json'
)
def
show_host
(
request
,
id
):
host
=
get_object_or_404
(
Host
,
id
=
id
)
def
show_host
(
request
,
id
=
None
):
try
:
host
=
Host
.
objects
.
get
(
id
=
id
)
host
=
{
'id'
:
host
.
id
,
'reverse'
:
host
.
reverse
,
...
...
@@ -292,6 +293,30 @@ def show_host(request, id):
'nat'
:
rule
.
nat
}
for
rule
in
host
.
rules
.
all
()]
}
except
:
host
=
{
'id'
:
None
,
'reverse'
:
None
,
'name'
:
None
,
'mac'
:
None
,
'ipv4'
:
None
,
'ipv6'
:
None
,
'pub_ipv4'
:
None
,
'shared_ip'
:
False
,
'description'
:
''
,
'comment'
:
''
,
'location'
:
''
,
'vlan'
:
{
'name'
:
None
,
},
'owner'
:
{
'name'
:
None
,
},
'created_at'
:
None
,
'modified_at'
:
None
,
'groups'
:
[],
'rules'
:
[]
}
return
HttpResponse
(
json
.
dumps
(
host
),
content_type
=
'application/json'
)
...
...
@@ -516,10 +541,10 @@ def save_rule(request):
@user_passes_test
(
req_staff
)
def
save_host
(
request
):
data
=
json
.
loads
(
request
.
body
)
if
data
[
'id'
]:
if
'id'
in
data
and
data
[
'id'
]:
host
=
get_object_or_404
(
Host
,
id
=
data
[
'id'
])
else
:
host
=
Host
.
objects
.
create
()
host
=
Host
()
errors
=
{}
host
.
reverse
=
data
[
'reverse'
]
host
.
hostname
=
data
[
'name'
]
...
...
@@ -533,17 +558,17 @@ def save_host(request):
host
.
location
=
data
[
'location'
]
set_field
(
host
,
'vlan'
,
errors
,
name
=
data
[
'vlan'
][
'name'
])
set_field
(
host
,
'owner'
,
errors
,
username
=
data
[
'owner'
][
'name'
])
for
host
in
data
[
'vlan
s'
]:
for
group
in
data
[
'group
s'
]:
try
:
if
'__destroyed'
in
host
and
host
[
'__destroyed'
]:
host_object
=
Vlan
.
objects
.
get
(
name
=
host
[
'name'
])
vlan
.
snat_to
.
remove
(
host
_object
)
elif
'__created'
in
host
and
host
[
'__created'
]:
host_object
=
Vlan
.
objects
.
get
(
name
=
host
[
'name'
])
vlan
.
snat_to
.
add
(
host
_object
)
if
'__destroyed'
in
group
and
group
[
'__destroyed'
]:
group_object
=
Group
.
objects
.
get
(
name
=
group
[
'name'
])
host
.
groups
.
remove
(
group
_object
)
elif
'__created'
in
group
and
group
[
'__created'
]:
group_object
=
Group
.
objects
.
get
(
name
=
group
[
'name'
])
host
.
groups
.
add
(
group
_object
)
except
Exception
as
e
:
errors
[
'
vlans'
]
=
(
'Host
with the name "
%(name)
s" does not exists!'
)
%
{
'name'
:
host
[
'name'
]
errors
[
'
groups'
]
=
(
'Group
with the name "
%(name)
s" does not exists!'
)
%
{
'name'
:
group
[
'name'
]
}
try
:
host
.
full_clean
()
...
...
@@ -552,7 +577,7 @@ def save_host(request):
if
len
(
errors
)
>
0
:
return
HttpResponse
(
json
.
dumps
(
errors
),
content_type
=
'application/json'
,
status
=
400
)
host
.
save
()
return
HttpResponse
(
'KTHXBYE'
)
return
HttpResponse
(
host
.
id
)
@user_passes_test
(
req_staff
)
def
save_vlan
(
request
):
...
...
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