Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
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
5b27960e
authored
Sep 18, 2013
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: remove old code
parent
97a5a111
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
70 deletions
+12
-70
circle/firewall/models.py
+2
-2
circle/firewall/tasks.py
+5
-10
circle/firewall/views.py
+5
-58
No files found.
circle/firewall/models.py
View file @
5b27960e
...
@@ -778,8 +778,8 @@ class Blacklist(models.Model):
...
@@ -778,8 +778,8 @@ class Blacklist(models.Model):
def
send_task
(
sender
,
instance
,
created
,
**
kwargs
):
def
send_task
(
sender
,
instance
,
created
,
**
kwargs
):
from
firewall.tasks
import
ReloadT
ask
from
firewall.tasks
import
reloadt
ask
ReloadT
ask
.
apply_async
(
args
=
[
sender
.
__name__
])
reloadt
ask
.
apply_async
(
args
=
[
sender
.
__name__
])
post_save
.
connect
(
send_task
,
sender
=
Host
)
post_save
.
connect
(
send_task
,
sender
=
Host
)
...
...
circle/firewall/tasks.py
View file @
5b27960e
from
celery.task
import
Task
,
PeriodicTask
import
celery
import
celery
from
django.core.cache
import
cache
from
django.core.cache
import
cache
from
firewall.fw
import
*
from
firewall.fw
import
Firewall
,
dhcp
,
dns
,
ipset
import
django.conf
import
django.conf
settings
=
django
.
conf
.
settings
.
FIREWALL_SETTINGS
settings
=
django
.
conf
.
settings
.
FIREWALL_SETTINGS
...
@@ -32,11 +31,8 @@ def get_dhcp_clients_task(data):
...
@@ -32,11 +31,8 @@ def get_dhcp_clients_task(data):
pass
pass
class
Periodic
(
PeriodicTask
):
@celery.task
run_every
=
timedelta
(
seconds
=
10
)
def
periodic_task
():
def
run
(
self
,
**
kwargs
):
if
cache
.
get
(
'dns_lock'
):
if
cache
.
get
(
'dns_lock'
):
cache
.
delete
(
"dns_lock"
)
cache
.
delete
(
"dns_lock"
)
reload_dns_task
.
delay
(
dns
())
reload_dns_task
.
delay
(
dns
())
...
@@ -60,9 +56,8 @@ class Periodic(PeriodicTask):
...
@@ -60,9 +56,8 @@ class Periodic(PeriodicTask):
print
"blacklist ujratoltese kesz"
print
"blacklist ujratoltese kesz"
class
ReloadTask
(
Task
):
@celery.task
def
run
(
self
,
type
=
'Host'
):
def
reloadtask
(
type
=
'Host'
):
if
type
in
[
"Host"
,
"Record"
,
"Domain"
,
"Vlan"
]:
if
type
in
[
"Host"
,
"Record"
,
"Domain"
,
"Vlan"
]:
cache
.
add
(
"dns_lock"
,
"true"
,
30
)
cache
.
add
(
"dns_lock"
,
"true"
,
30
)
...
...
circle/firewall/views.py
View file @
5b27960e
import
base64
import
base64
import
datetime
import
datetime
import
json
import
json
import
re
from
django.co
nf
import
settings
from
django.co
re.exceptions
import
ValidationError
from
django.db
import
IntegrityError
from
django.db
import
IntegrityError
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.template.loader
import
render_to_string
from
django.utils
import
translation
from
django.utils.timezone
import
utc
from
django.utils.timezone
import
utc
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.http
import
require_POST
from
django.views.decorators.http
import
require_POST
from
tasks
import
*
from
.tasks
import
reloadtask
from
.models
import
Blacklist
,
Host
from
firewall.fw
import
*
from
firewall.models
import
*
from
one.tasks
import
SendMailTask
def
reload_firewall
(
request
):
def
reload_firewall
(
request
):
...
@@ -25,7 +19,7 @@ def reload_firewall(request):
...
@@ -25,7 +19,7 @@ def reload_firewall(request):
if
request
.
user
.
is_superuser
:
if
request
.
user
.
is_superuser
:
html
=
(
_
(
"Dear
%
s, you've signed in as administrator!<br />"
html
=
(
_
(
"Dear
%
s, you've signed in as administrator!<br />"
"Reloading in 10 seconds..."
)
%
request
.
user
.
username
)
"Reloading in 10 seconds..."
)
%
request
.
user
.
username
)
ReloadT
ask
.
delay
()
reloadt
ask
.
delay
()
else
:
else
:
html
=
(
_
(
"Dear
%
s, you've signed in!"
)
%
request
.
user
.
username
)
html
=
(
_
(
"Dear
%
s, you've signed in!"
)
%
request
.
user
.
username
)
else
:
else
:
...
@@ -49,22 +43,6 @@ def firewall_api(request):
...
@@ -49,22 +43,6 @@ def firewall_api(request):
if
created
:
if
created
:
try
:
try
:
obj
.
host
=
Host
.
objects
.
get
(
ipv4
=
data
[
"ip"
])
obj
.
host
=
Host
.
objects
.
get
(
ipv4
=
data
[
"ip"
])
user
=
obj
.
host
.
owner
lang
=
user
.
person_set
.
all
()[
0
]
.
language
translation
.
activate
(
lang
)
msg
=
render_to_string
(
'mails/notification-ban-now.txt'
,
{
'user'
:
user
,
'bl'
:
obj
,
'instance:'
:
obj
.
host
.
instance_set
.
get
(),
'url'
:
settings
.
CLOUD_URL
})
SendMailTask
.
delay
(
to
=
obj
.
host
.
owner
.
email
,
subject
=
'[IK Cloud]
%
s'
%
obj
.
host
.
instance_set
.
get
()
.
name
,
msg
=
msg
,
sender
=
u'cloud@ik.bme.hu'
)
except
(
Host
.
DoesNotExist
,
ValidationError
,
except
(
Host
.
DoesNotExist
,
ValidationError
,
IntegrityError
,
AttributeError
):
IntegrityError
,
AttributeError
):
pass
pass
...
@@ -73,40 +51,9 @@ def firewall_api(request):
...
@@ -73,40 +51,9 @@ def firewall_api(request):
now
=
datetime
.
dateime
.
utcnow
()
.
replace
(
tzinfo
=
utc
)
now
=
datetime
.
dateime
.
utcnow
()
.
replace
(
tzinfo
=
utc
)
if
obj
.
type
==
'tempwhite'
and
modified
<
now
:
if
obj
.
type
==
'tempwhite'
and
modified
<
now
:
obj
.
type
=
'tempban'
obj
.
type
=
'tempban'
if
obj
.
type
!=
'whitelist'
:
obj
.
save
()
obj
.
save
()
return
HttpResponse
(
unicode
(
_
(
"OK"
)))
return
HttpResponse
(
unicode
(
_
(
"OK"
)))
if
not
(
data
[
"vlan"
]
==
"vm-net"
or
data
[
"vlan"
]
==
"war"
):
raise
Exception
(
_
(
"Only vm-net and war can be used."
))
data
[
"hostname"
]
=
re
.
sub
(
r' '
,
'_'
,
data
[
"hostname"
])
if
command
==
"create"
:
data
[
"owner"
]
=
"opennebula"
owner
=
auth
.
models
.
User
.
objects
.
get
(
username
=
data
[
"owner"
])
host
=
Host
(
hostname
=
data
[
"hostname"
],
vlan
=
Vlan
.
objects
.
get
(
name
=
data
[
"vlan"
]),
mac
=
data
[
"mac"
],
ipv4
=
data
[
"ip"
],
owner
=
owner
,
description
=
data
[
"description"
],
pub_ipv4
=
Vlan
.
objects
.
get
(
name
=
data
[
"vlan"
])
.
snat_ip
,
shared_ip
=
True
)
host
.
full_clean
()
host
.
save
()
host
.
enable_net
()
for
p
in
data
[
"portforward"
]:
host
.
add_port
(
proto
=
p
[
"proto"
],
public
=
int
(
p
[
"public_port"
]),
private
=
int
(
p
[
"private_port"
]))
elif
command
==
"destroy"
:
data
[
"owner"
]
=
"opennebula"
print
data
[
"hostname"
]
owner
=
auth
.
models
.
User
.
objects
.
get
(
username
=
data
[
"owner"
])
host
=
Host
.
objects
.
get
(
hostname
=
data
[
"hostname"
],
owner
=
owner
)
host
.
delete
()
else
:
else
:
raise
Exception
(
_
(
"Unknown command."
))
raise
Exception
(
_
(
"Unknown command."
))
...
...
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