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
b73c91c6
authored
Feb 13, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: enforcing guidelines
parent
e14a1b89
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
12 deletions
+22
-12
firewall/tests.py
+2
-2
firewall/views.py
+20
-10
No files found.
firewall/tests.py
View file @
b73c91c6
"""
"""
This file demonstrates writing tests using the unittest module. These will
pass
This file demonstrates writing tests using the unittest module. These will
when you run "manage.py test".
pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
Replace this with more appropriate tests for your application.
"""
"""
...
...
firewall/views.py
View file @
b73c91c6
...
@@ -16,12 +16,14 @@ import sys
...
@@ -16,12 +16,14 @@ import sys
def
reload_firewall
(
request
):
def
reload_firewall
(
request
):
if
request
.
user
.
is_authenticated
():
if
request
.
user
.
is_authenticated
():
if
(
request
.
user
.
is_superuser
):
if
request
.
user
.
is_superuser
:
html
=
u"Be vagy jelentkezve es admin is vagy, kedves
%
s!"
%
request
.
user
.
username
html
=
(
u"Be vagy jelentkezve es admin is vagy, kedves
%
s!"
%
request
.
user
.
username
)
html
+=
"<br> 10 masodperc mulva ujratoltodik"
html
+=
"<br> 10 masodperc mulva ujratoltodik"
ReloadTask
.
delay
()
ReloadTask
.
delay
()
else
:
else
:
html
=
u"Be vagy jelentkezve, csak nem vagy admin, kedves
%
s!"
%
request
.
user
.
username
html
=
(
u"Be vagy jelentkezve, csak nem vagy admin, kedves
%
s!"
%
request
.
user
.
username
)
else
:
else
:
html
=
u"Nem vagy bejelentkezve, kedves ismeretlen!"
html
=
u"Nem vagy bejelentkezve, kedves ismeretlen!"
return
HttpResponse
(
html
)
return
HttpResponse
(
html
)
...
@@ -32,31 +34,39 @@ def firewall_api(request):
...
@@ -32,31 +34,39 @@ def firewall_api(request):
try
:
try
:
data
=
json
.
loads
(
base64
.
b64decode
(
request
.
POST
[
"data"
]))
data
=
json
.
loads
(
base64
.
b64decode
(
request
.
POST
[
"data"
]))
command
=
request
.
POST
[
"command"
]
command
=
request
.
POST
[
"command"
]
if
(
data
[
"password"
]
!=
"bdmegintelrontottaanetet"
)
:
if
data
[
"password"
]
!=
"bdmegintelrontottaanetet"
:
raise
Exception
(
"rossz jelszo"
)
raise
Exception
(
"rossz jelszo"
)
if
(
not
(
data
[
"vlan"
]
==
"vm-net"
or
data
[
"vlan"
]
==
"war"
)
):
if
not
(
data
[
"vlan"
]
==
"vm-net"
or
data
[
"vlan"
]
==
"war"
):
raise
Exception
(
"csak vm-net es war-re mukodik"
)
raise
Exception
(
"csak vm-net es war-re mukodik"
)
data
[
"hostname"
]
=
re
.
sub
(
r' '
,
'_'
,
data
[
"hostname"
])
data
[
"hostname"
]
=
re
.
sub
(
r' '
,
'_'
,
data
[
"hostname"
])
if
(
command
==
"create"
)
:
if
command
==
"create"
:
data
[
"owner"
]
=
"opennebula"
data
[
"owner"
]
=
"opennebula"
owner
=
auth
.
models
.
User
.
objects
.
get
(
username
=
data
[
"owner"
])
owner
=
auth
.
models
.
User
.
objects
.
get
(
username
=
data
[
"owner"
])
host
=
models
.
Host
(
hostname
=
data
[
"hostname"
],
vlan
=
models
.
Vlan
.
objects
.
get
(
name
=
data
[
"vlan"
]),
mac
=
data
[
"mac"
],
ipv4
=
data
[
"ip"
],
owner
=
owner
,
description
=
data
[
"description"
],
pub_ipv4
=
models
.
Vlan
.
objects
.
get
(
name
=
data
[
"vlan"
])
.
snat_ip
,
shared_ip
=
True
)
host
=
models
.
Host
(
hostname
=
data
[
"hostname"
],
vlan
=
models
.
Vlan
.
objects
.
get
(
name
=
data
[
"vlan"
]),
mac
=
data
[
"mac"
],
ipv4
=
data
[
"ip"
],
owner
=
owner
,
description
=
data
[
"description"
],
pub_ipv4
=
models
.
Vlan
.
objects
.
get
(
name
=
data
[
"vlan"
])
.
snat_ip
,
shared_ip
=
True
)
host
.
full_clean
()
host
.
full_clean
()
host
.
save
()
host
.
save
()
host
.
enable_net
()
host
.
enable_net
()
for
p
in
data
[
"portforward"
]:
for
p
in
data
[
"portforward"
]:
host
.
add_port
(
proto
=
p
[
"proto"
],
public
=
int
(
p
[
"public_port"
]),
private
=
int
(
p
[
"private_port"
]))
host
.
add_port
(
proto
=
p
[
"proto"
],
public
=
int
(
p
[
"public_port"
]),
private
=
int
(
p
[
"private_port"
]))
elif
(
command
==
"destroy"
)
:
elif
command
==
"destroy"
:
data
[
"owner"
]
=
"opennebula"
data
[
"owner"
]
=
"opennebula"
print
data
[
"hostname"
]
print
data
[
"hostname"
]
owner
=
auth
.
models
.
User
.
objects
.
get
(
username
=
data
[
"owner"
])
owner
=
auth
.
models
.
User
.
objects
.
get
(
username
=
data
[
"owner"
])
host
=
models
.
Host
.
objects
.
get
(
hostname
=
data
[
"hostname"
],
owner
=
owner
)
host
=
models
.
Host
.
objects
.
get
(
hostname
=
data
[
"hostname"
],
owner
=
owner
)
host
.
del_rules
()
host
.
del_rules
()
host
.
delete
()
host
.
delete
()
...
...
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