Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
71 deletions
+13
-71
circle/firewall/models.py
+2
-2
circle/firewall/tasks.py
+5
-10
circle/firewall/views.py
+6
-59
No files found.
circle/firewall/models.py
View file @
5b27960e
...
...
@@ -778,8 +778,8 @@ class Blacklist(models.Model):
def
send_task
(
sender
,
instance
,
created
,
**
kwargs
):
from
firewall.tasks
import
ReloadT
ask
ReloadT
ask
.
apply_async
(
args
=
[
sender
.
__name__
])
from
firewall.tasks
import
reloadt
ask
reloadt
ask
.
apply_async
(
args
=
[
sender
.
__name__
])
post_save
.
connect
(
send_task
,
sender
=
Host
)
...
...
circle/firewall/tasks.py
View file @
5b27960e
from
celery.task
import
Task
,
PeriodicTask
import
celery
from
django.core.cache
import
cache
from
firewall.fw
import
*
from
firewall.fw
import
Firewall
,
dhcp
,
dns
,
ipset
import
django.conf
settings
=
django
.
conf
.
settings
.
FIREWALL_SETTINGS
...
...
@@ -32,11 +31,8 @@ def get_dhcp_clients_task(data):
pass
class
Periodic
(
PeriodicTask
):
run_every
=
timedelta
(
seconds
=
10
)
def
run
(
self
,
**
kwargs
):
@celery.task
def
periodic_task
():
if
cache
.
get
(
'dns_lock'
):
cache
.
delete
(
"dns_lock"
)
reload_dns_task
.
delay
(
dns
())
...
...
@@ -60,9 +56,8 @@ class Periodic(PeriodicTask):
print
"blacklist ujratoltese kesz"
class
ReloadTask
(
Task
):
def
run
(
self
,
type
=
'Host'
):
@celery.task
def
reloadtask
(
type
=
'Host'
):
if
type
in
[
"Host"
,
"Record"
,
"Domain"
,
"Vlan"
]:
cache
.
add
(
"dns_lock"
,
"true"
,
30
)
...
...
circle/firewall/views.py
View file @
5b27960e
import
base64
import
datetime
import
json
import
re
from
django.co
nf
import
settings
from
django.co
re.exceptions
import
ValidationError
from
django.db
import
IntegrityError
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.translation
import
ugettext_lazy
as
_
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.http
import
require_POST
from
tasks
import
*
from
firewall.fw
import
*
from
firewall.models
import
*
from
one.tasks
import
SendMailTask
from
.tasks
import
reloadtask
from
.models
import
Blacklist
,
Host
def
reload_firewall
(
request
):
...
...
@@ -25,7 +19,7 @@ def reload_firewall(request):
if
request
.
user
.
is_superuser
:
html
=
(
_
(
"Dear
%
s, you've signed in as administrator!<br />"
"Reloading in 10 seconds..."
)
%
request
.
user
.
username
)
ReloadT
ask
.
delay
()
reloadt
ask
.
delay
()
else
:
html
=
(
_
(
"Dear
%
s, you've signed in!"
)
%
request
.
user
.
username
)
else
:
...
...
@@ -49,22 +43,6 @@ def firewall_api(request):
if
created
:
try
:
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
,
IntegrityError
,
AttributeError
):
pass
...
...
@@ -73,40 +51,9 @@ def firewall_api(request):
now
=
datetime
.
dateime
.
utcnow
()
.
replace
(
tzinfo
=
utc
)
if
obj
.
type
==
'tempwhite'
and
modified
<
now
:
obj
.
type
=
'tempban'
obj
.
save
()
if
obj
.
type
!=
'whitelist'
:
obj
.
save
()
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
:
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