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
214ba8d8
authored
May 13, 2013
by
Bence Dányi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall_gui: save host
parent
a5fca488
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
11 deletions
+53
-11
cloud/urls.py
+1
-0
firewall_gui/static/partials/host-edit.html
+21
-11
firewall_gui/views.py
+31
-0
No files found.
cloud/urls.py
View file @
214ba8d8
...
...
@@ -106,4 +106,5 @@ urlpatterns = patterns('',
url
(
r'^firewall/autocomplete/(?P<entity>\w+)/$'
,
'firewall_gui.views.autocomplete'
),
url
(
r'^firewall/rules/save/$'
,
'firewall_gui.views.save_rule'
),
url
(
r'^firewall/hosts/save/$'
,
'firewall_gui.views.save_host'
),
)
firewall_gui/static/partials/host-edit.html
View file @
214ba8d8
...
...
@@ -18,55 +18,63 @@
<input
class=
"input"
type=
"text"
id=
"modified_at"
ng-model=
"entity.modified_at"
disabled=
"disabled"
>
</div>
</div>
<div
class=
"control-group"
>
<div
class=
"control-group"
ng-class=
"hasError('name')"
>
<label
class=
"control-label"
for=
"name"
>
Name
</label>
<div
class=
"controls"
>
<input
type=
"text"
id=
"name"
ng-model=
"entity.name"
/>
<span
class=
"help-inline"
ng-bind=
"getError('name')"
></span>
</div>
</div>
<div
class=
"control-group"
>
<div
class=
"control-group"
ng-class=
"hasError('mac')"
>
<label
class=
"control-label"
for=
"mac"
>
MAC
</label>
<div
class=
"controls"
>
<input
type=
"text"
id=
"mac"
ng-model=
"entity.mac"
/>
<span
class=
"help-inline"
ng-bind=
"getError('mac')"
></span>
</div>
</div>
<div
class=
"control-group"
>
<div
class=
"control-group"
ng-class=
"hasError('ipv4')"
>
<label
class=
"control-label"
for=
"ipv4"
>
IPv4
</label>
<div
class=
"controls"
>
<input
type=
"text"
id=
"ipv4"
ng-model=
"entity.ipv4"
/>
<span
class=
"help-inline"
ng-bind=
"getError('ipv4')"
></span>
</div>
</div>
<div
class=
"control-group"
>
<div
class=
"control-group"
ng-class=
"hasError('pub_ipv4')"
>
<label
class=
"control-label"
for=
"pub_ipv4"
>
Public IPv4
</label>
<div
class=
"controls"
>
<input
type=
"text"
id=
"pub_ipv4"
ng-model=
"entity.pub_ipv4"
/>
<span
class=
"help-inline"
ng-bind=
"getError('pub_ipv4')"
></span>
</div>
</div>
<div
class=
"control-group"
>
<div
class=
"control-group"
ng-class=
"hasError('ipv6')"
>
<label
class=
"control-label"
for=
"ipv6"
>
IPv6
</label>
<div
class=
"controls"
>
<input
type=
"text"
class=
"input-xlarge"
id=
"ipv6"
ng-model=
"entity.ipv6"
/>
<span
class=
"help-inline"
ng-bind=
"getError('ipv6')"
></span>
</div>
</div>
<div
class=
"control-group"
>
<div
class=
"control-group"
ng-class=
"hasError('owner')"
>
<label
class=
"control-label"
for=
"owner"
>
Owner
</label>
<div
class=
"controls"
>
<input
type=
"text"
autocomplete=
"off"
id=
"owner"
ng-model=
"entity.owner.name"
/>
<span
class=
"help-inline"
ng-bind=
"getError('owner')"
></span>
</div>
</div>
<div
class=
"control-group"
>
<div
class=
"control-group"
ng-class=
"hasError('vlan')"
>
<label
class=
"control-label"
for=
"vlan"
>
Vlan
</label>
<div
class=
"controls"
>
<input
type=
"text"
data-provide=
"typeahead"
autocomplete=
"off"
class=
"vlan"
id=
"vlan"
ng-model=
"entity.vlan.name"
/>
<span
class=
"help-inline"
ng-bind=
"getError('vlan')"
></span>
</div>
</div>
</div>
<div
class=
"span5"
>
<div
class=
"control-group"
>
<div
class=
"control-group"
ng-class=
"hasError('description')"
>
<label
class=
"control-label"
for=
"description"
>
Description
</label>
<div
class=
"controls"
>
<textarea
rows=
"4"
id=
"description"
ng-model=
"entity.description"
>
</textarea>
<span
class=
"help-inline"
ng-bind=
"getError('description')"
></span>
</div>
</div>
<div
class=
"control-group"
>
...
...
@@ -76,14 +84,15 @@
</label>
</div>
</div>
<div
class=
"control-group"
>
<div
class=
"control-group"
ng-class=
"hasError('comment')"
>
<label
class=
"control-label"
for=
"comment"
>
Comment
</label>
<div
class=
"controls"
>
<textarea
rows=
"2"
id=
"comment"
ng-model=
"entity.comment"
>
</textarea>
<span
class=
"help-inline"
ng-bind=
"getError('comment')"
></span>
</div>
</div>
<div
class=
"control-group"
>
<div
class=
"control-group"
ng-class=
"hasError('groups')"
>
<label
class=
"control-label"
for=
"hostgroups"
>
Host groups
</label>
<div
class=
"controls"
>
<div
class=
"well well-small"
>
...
...
@@ -95,12 +104,13 @@
<div
class=
"input-append"
>
<input
class=
"span2 hostgroup"
id=
"hostgroup"
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>
</div>
</div>
<div
class=
"control-group"
>
<div
class=
"controls"
>
<button
type=
"submit"
class=
"btn"
>
Save (nem működik!)
</button>
<button
type=
"submit"
class=
"btn"
ng-click=
"save()"
>
Save
</button>
</div>
</div>
</div>
...
...
firewall_gui/views.py
View file @
214ba8d8
...
...
@@ -70,6 +70,7 @@ def make_entity_lister(entity_type, mapping):
return
[
jsonify
(
entity
)
for
entity
in
entity_type
.
objects
.
all
()]
return
entity_lister
@user_passes_test
(
req_staff
)
def
list_entities
(
request
,
name
):
return
HttpResponse
(
json
.
dumps
({
'rules'
:
make_entity_lister
(
Rule
,
[
...
...
@@ -423,3 +424,33 @@ def save_rule(request):
return
HttpResponse
(
json
.
dumps
(
errors
),
content_type
=
'application/json'
,
status
=
400
)
rule
.
save
()
return
HttpResponse
(
'KTHXBYE'
)
@user_passes_test
(
req_staff
)
def
save_host
(
request
):
data
=
json
.
loads
(
request
.
body
)
if
data
[
'id'
]:
host
=
get_object_or_404
(
Host
,
id
=
data
[
'id'
])
else
:
host
=
Host
.
objects
.
create
()
errors
=
{}
host
.
reverse
=
data
[
'reverse'
]
host
.
hostname
=
data
[
'name'
]
host
.
mac
=
data
[
'mac'
]
host
.
ipv4
=
data
[
'ipv4'
]
host
.
ipv6
=
data
[
'ipv6'
]
host
.
pub_ipv4
=
data
[
'pub_ipv4'
]
host
.
shared_ip
=
data
[
'shared_ip'
]
host
.
description
=
data
[
'description'
]
host
.
comment
=
data
[
'comment'
]
host
.
location
=
data
[
'location'
]
set_field
(
host
,
'vlan'
,
errors
,
name
=
data
[
'vlan'
][
'name'
])
set_field
(
host
,
'owner'
,
errors
,
username
=
data
[
'owner'
][
'name'
])
# todo: group save
try
:
host
.
full_clean
()
except
Exception
as
e
:
errors
=
dict
(
errors
.
items
()
+
e
.
message_dict
.
items
())
if
len
(
errors
)
>
0
:
return
HttpResponse
(
json
.
dumps
(
errors
),
content_type
=
'application/json'
,
status
=
400
)
host
.
save
()
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