Commit 5b27960e by Bach Dániel

firewall: remove old code

parent 97a5a111
......@@ -778,8 +778,8 @@ class Blacklist(models.Model):
def send_task(sender, instance, created, **kwargs):
from firewall.tasks import ReloadTask
ReloadTask.apply_async(args=[sender.__name__])
from firewall.tasks import reloadtask
reloadtask.apply_async(args=[sender.__name__])
post_save.connect(send_task, sender=Host)
......
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)
......
import base64
import datetime
import json
import re
from django.conf import settings
from django.core.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)
ReloadTask.delay()
reloadtask.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."))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment