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
40c3495c
authored
Jan 24, 2013
by
x
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: code formatting
parent
114e301a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
170 additions
and
170 deletions
+170
-170
firewall/fields.py
+2
-2
firewall/fw.py
+0
-0
firewall/models.py
+86
-86
firewall/tasks.py
+36
-36
firewall/views.py
+46
-46
No files found.
firewall/fields.py
View file @
40c3495c
...
@@ -42,5 +42,5 @@ def val_domain(value):
...
@@ -42,5 +42,5 @@ def val_domain(value):
raise
ValidationError
(
u'
%
s - helytelen domain'
%
value
)
raise
ValidationError
(
u'
%
s - helytelen domain'
%
value
)
def
ipv4_2_ipv6
(
ipv4
):
def
ipv4_2_ipv6
(
ipv4
):
m
=
ipv4_re
.
match
(
ipv4
)
m
=
ipv4_re
.
match
(
ipv4
)
return
"2001:738:2001:4031:
%
s:
%
s:
%
s:0"
%
(
m
.
group
(
1
),
m
.
group
(
2
),
m
.
group
(
3
))
return
"2001:738:2001:4031:
%
s:
%
s:
%
s:0"
%
(
m
.
group
(
1
),
m
.
group
(
2
),
m
.
group
(
3
))
firewall/fw.py
View file @
40c3495c
This diff is collapsed.
Click to expand it.
firewall/models.py
View file @
40c3495c
This diff is collapsed.
Click to expand it.
firewall/tasks.py
View file @
40c3495c
...
@@ -6,43 +6,43 @@ from firewall.fw import *
...
@@ -6,43 +6,43 @@ from firewall.fw import *
def
reload_firewall_lock
():
def
reload_firewall_lock
():
acquire_lock
=
lambda
:
cache
.
add
(
"reload_lock1"
,
"true"
,
9
)
acquire_lock
=
lambda
:
cache
.
add
(
"reload_lock1"
,
"true"
,
9
)
if
acquire_lock
():
if
acquire_lock
():
print
"megszereztem"
print
"megszereztem"
ReloadTask
.
delay
()
ReloadTask
.
delay
()
else
:
else
:
print
"nem szereztem meg"
print
"nem szereztem meg"
class
ReloadTask
(
Task
):
class
ReloadTask
(
Task
):
def
run
(
self
,
**
kwargs
):
def
run
(
self
,
**
kwargs
):
acquire_lock
=
lambda
:
cache
.
add
(
"reload_lock1"
,
"true"
,
90
)
acquire_lock
=
lambda
:
cache
.
add
(
"reload_lock1"
,
"true"
,
90
)
release_lock
=
lambda
:
cache
.
delete
(
"reload_lock1"
)
release_lock
=
lambda
:
cache
.
delete
(
"reload_lock1"
)
if
not
acquire_lock
():
if
not
acquire_lock
():
print
"mar folyamatban van egy reload"
print
"mar folyamatban van egy reload"
return
return
print
"indul"
print
"indul"
time
.
sleep
(
10
)
time
.
sleep
(
10
)
try
:
try
:
print
"ipv4"
print
"ipv4"
ipv4
=
firewall
()
ipv4
=
firewall
()
ipv4
.
reload
()
ipv4
.
reload
()
#
print ipv4.show()
#
print ipv4.show()
print
"ipv6"
print
"ipv6"
ipv6
=
firewall
(
True
)
ipv6
=
firewall
(
True
)
ipv6
.
reload
()
ipv6
.
reload
()
print
"dns"
print
"dns"
dns
()
dns
()
print
"dhcp"
print
"dhcp"
dhcp
()
dhcp
()
print
"vege"
print
"vege"
except
:
except
:
raise
raise
print
"nem sikerult :("
print
"nem sikerult :("
print
"leall"
print
"leall"
release_lock
()
release_lock
()
firewall/views.py
View file @
40c3495c
...
@@ -15,63 +15,63 @@ import sys
...
@@ -15,63 +15,63 @@ 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
)
@csrf_exempt
@csrf_exempt
def
firewall_api
(
request
):
def
firewall_api
(
request
):
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
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
()
else
:
else
:
raise
Exception
(
"rossz parancs"
)
raise
Exception
(
"rossz parancs"
)
reload_firewall_lock
()
reload_firewall_lock
()
except
(
ValidationError
,
IntegrityError
,
AttributeError
,
Exception
)
as
e
:
except
(
ValidationError
,
IntegrityError
,
AttributeError
,
Exception
)
as
e
:
return
HttpResponse
(
u"rosszul hasznalod! :(
\n
%
s
\n
"
%
e
);
return
HttpResponse
(
u"rosszul hasznalod! :(
\n
%
s
\n
"
%
e
);
except
:
except
:
#
raise
#
raise
return
HttpResponse
(
u"rosszul hasznalod! :(
\n
"
);
return
HttpResponse
(
u"rosszul hasznalod! :(
\n
"
);
return
HttpResponse
(
u"ok"
);
return
HttpResponse
(
u"ok"
);
return
HttpResponse
(
u"ez kerlek egy api lesz!
\n
"
);
return
HttpResponse
(
u"ez kerlek egy api lesz!
\n
"
);
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