Commit b73c91c6 by Dudás Ádám

firewall: enforcing guidelines

parent e14a1b89
""" """
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.
""" """
......
...@@ -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()
......
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