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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
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
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
53 deletions
+78
-53
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
+75
-50
No files found.
cloud/urls.py
View file @
0d815cd3
...
@@ -118,7 +118,7 @@ urlpatterns = patterns('',
...
@@ -118,7 +118,7 @@ urlpatterns = patterns('',
url
(
r'^firewall/(?P<name>\w+)/(?P<id>\d+)/delete/'
,
'firewall_gui.views.delete_entity'
),
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/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/vlans/save/$', 'firewall_gui.views.save_vlan'),
# url(r'^firewall/vlangroups/save/$', 'firewall_gui.views.save_vlangroup'),
# url(r'^firewall/vlangroups/save/$', 'firewall_gui.views.save_vlangroup'),
# url(r'^firewall/hostgroups/save/$', 'firewall_gui.views.save_hostgroup'),
# url(r'^firewall/hostgroups/save/$', 'firewall_gui.views.save_hostgroup'),
...
...
firewall_gui/static/partials/host-edit.html
View file @
0d815cd3
...
@@ -163,7 +163,7 @@
...
@@ -163,7 +163,7 @@
</span>
</span>
</div>
</div>
<div
class=
"input-append has-tooltip"
title=
"Hostgroups of this host"
>
<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>
<button
class=
"btn"
type=
"button"
ng-click=
"addHostGroup(newGroup)"
>
Add
</button>
<span
class=
"help-inline"
ng-bind=
"getError('groups')"
></span>
<span
class=
"help-inline"
ng-bind=
"getError('groups')"
></span>
</div>
</div>
...
...
firewall_gui/static/partials/host-list.html
View file @
0d815cd3
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
<form
class=
"navbar-search"
style=
"margin: 20px"
>
<form
class=
"navbar-search"
style=
"margin: 20px"
>
<input
type=
"text"
class=
"search-query"
placeholder=
"Search"
ng-model=
"query"
>
<input
type=
"text"
class=
"search-query"
placeholder=
"Search"
ng-model=
"query"
>
</form>
</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>
</div>
</div>
<table
class=
"table table-striped"
>
<table
class=
"table table-striped"
>
...
...
firewall_gui/views.py
View file @
0d815cd3
...
@@ -252,46 +252,71 @@ def show_rule(request, id=None):
...
@@ -252,46 +252,71 @@ def show_rule(request, id=None):
return
HttpResponse
(
json
.
dumps
(
rule
),
content_type
=
'application/json'
)
return
HttpResponse
(
json
.
dumps
(
rule
),
content_type
=
'application/json'
)
def
show_host
(
request
,
id
):
def
show_host
(
request
,
id
=
None
):
host
=
get_object_or_404
(
Host
,
id
=
id
)
try
:
host
=
{
host
=
Host
.
objects
.
get
(
id
=
id
)
'id'
:
host
.
id
,
host
=
{
'reverse'
:
host
.
reverse
,
'id'
:
host
.
id
,
'name'
:
host
.
hostname
,
'reverse'
:
host
.
reverse
,
'mac'
:
host
.
mac
,
'name'
:
host
.
hostname
,
'ipv4'
:
host
.
ipv4
,
'mac'
:
host
.
mac
,
'ipv6'
:
host
.
ipv6
,
'ipv4'
:
host
.
ipv4
,
'pub_ipv4'
:
host
.
pub_ipv4
,
'ipv6'
:
host
.
ipv6
,
'shared_ip'
:
host
.
shared_ip
,
'pub_ipv4'
:
host
.
pub_ipv4
,
'description'
:
host
.
description
,
'shared_ip'
:
host
.
shared_ip
,
'comment'
:
host
.
comment
,
'description'
:
host
.
description
,
'location'
:
host
.
location
,
'comment'
:
host
.
comment
,
'vlan'
:
{
'location'
:
host
.
location
,
'name'
:
host
.
vlan
.
name
,
'vlan'
:
{
'id'
:
host
.
vlan
.
id
'name'
:
host
.
vlan
.
name
,
},
'id'
:
host
.
vlan
.
id
'owner'
:
{
},
'name'
:
str
(
host
.
owner
),
'id'
:
host
.
owner
.
id
},
'created_at'
:
host
.
created_at
.
isoformat
(),
'modified_at'
:
host
.
modified_at
.
isoformat
(),
'groups'
:
[{
'name'
:
group
.
name
,
'id'
:
group
.
id
,
}
for
group
in
host
.
groups
.
all
()],
'rules'
:
[{
'id'
:
rule
.
id
,
'direction'
:
rule
.
get_direction_display
(),
'proto'
:
rule
.
proto
,
'owner'
:
{
'owner'
:
{
'
id'
:
rule
.
owner
.
id
,
'
name'
:
str
(
host
.
owner
)
,
'
name'
:
str
(
rule
.
owner
),
'
id'
:
host
.
owner
.
id
},
},
'accept'
:
rule
.
accept
,
'created_at'
:
host
.
created_at
.
isoformat
(),
'nat'
:
rule
.
nat
'modified_at'
:
host
.
modified_at
.
isoformat
(),
}
for
rule
in
host
.
rules
.
all
()]
'groups'
:
[{
}
'name'
:
group
.
name
,
'id'
:
group
.
id
,
}
for
group
in
host
.
groups
.
all
()],
'rules'
:
[{
'id'
:
rule
.
id
,
'direction'
:
rule
.
get_direction_display
(),
'proto'
:
rule
.
proto
,
'owner'
:
{
'id'
:
rule
.
owner
.
id
,
'name'
:
str
(
rule
.
owner
),
},
'accept'
:
rule
.
accept
,
'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'
)
return
HttpResponse
(
json
.
dumps
(
host
),
content_type
=
'application/json'
)
...
@@ -516,10 +541,10 @@ def save_rule(request):
...
@@ -516,10 +541,10 @@ def save_rule(request):
@user_passes_test
(
req_staff
)
@user_passes_test
(
req_staff
)
def
save_host
(
request
):
def
save_host
(
request
):
data
=
json
.
loads
(
request
.
body
)
data
=
json
.
loads
(
request
.
body
)
if
data
[
'id'
]:
if
'id'
in
data
and
data
[
'id'
]:
host
=
get_object_or_404
(
Host
,
id
=
data
[
'id'
])
host
=
get_object_or_404
(
Host
,
id
=
data
[
'id'
])
else
:
else
:
host
=
Host
.
objects
.
create
()
host
=
Host
()
errors
=
{}
errors
=
{}
host
.
reverse
=
data
[
'reverse'
]
host
.
reverse
=
data
[
'reverse'
]
host
.
hostname
=
data
[
'name'
]
host
.
hostname
=
data
[
'name'
]
...
@@ -533,17 +558,17 @@ def save_host(request):
...
@@ -533,17 +558,17 @@ def save_host(request):
host
.
location
=
data
[
'location'
]
host
.
location
=
data
[
'location'
]
set_field
(
host
,
'vlan'
,
errors
,
name
=
data
[
'vlan'
][
'name'
])
set_field
(
host
,
'vlan'
,
errors
,
name
=
data
[
'vlan'
][
'name'
])
set_field
(
host
,
'owner'
,
errors
,
username
=
data
[
'owner'
][
'name'
])
set_field
(
host
,
'owner'
,
errors
,
username
=
data
[
'owner'
][
'name'
])
for
host
in
data
[
'vlan
s'
]:
for
group
in
data
[
'group
s'
]:
try
:
try
:
if
'__destroyed'
in
host
and
host
[
'__destroyed'
]:
if
'__destroyed'
in
group
and
group
[
'__destroyed'
]:
host_object
=
Vlan
.
objects
.
get
(
name
=
host
[
'name'
])
group_object
=
Group
.
objects
.
get
(
name
=
group
[
'name'
])
vlan
.
snat_to
.
remove
(
host
_object
)
host
.
groups
.
remove
(
group
_object
)
elif
'__created'
in
host
and
host
[
'__created'
]:
elif
'__created'
in
group
and
group
[
'__created'
]:
host_object
=
Vlan
.
objects
.
get
(
name
=
host
[
'name'
])
group_object
=
Group
.
objects
.
get
(
name
=
group
[
'name'
])
vlan
.
snat_to
.
add
(
host
_object
)
host
.
groups
.
add
(
group
_object
)
except
Exception
as
e
:
except
Exception
as
e
:
errors
[
'
vlans'
]
=
(
'Host
with the name "
%(name)
s" does not exists!'
)
%
{
errors
[
'
groups'
]
=
(
'Group
with the name "
%(name)
s" does not exists!'
)
%
{
'name'
:
host
[
'name'
]
'name'
:
group
[
'name'
]
}
}
try
:
try
:
host
.
full_clean
()
host
.
full_clean
()
...
@@ -552,7 +577,7 @@ def save_host(request):
...
@@ -552,7 +577,7 @@ def save_host(request):
if
len
(
errors
)
>
0
:
if
len
(
errors
)
>
0
:
return
HttpResponse
(
json
.
dumps
(
errors
),
content_type
=
'application/json'
,
status
=
400
)
return
HttpResponse
(
json
.
dumps
(
errors
),
content_type
=
'application/json'
,
status
=
400
)
host
.
save
()
host
.
save
()
return
HttpResponse
(
'KTHXBYE'
)
return
HttpResponse
(
host
.
id
)
@user_passes_test
(
req_staff
)
@user_passes_test
(
req_staff
)
def
save_vlan
(
request
):
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