Commit 370ce61c authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos

Merged all email files into one to make it easier to manage. Changed code accordingly

parent 8188d3e9
......@@ -150,8 +150,8 @@ def notify_expired():
admin_url = "https://%s%s" % \
(fqdn,
"/fod/edit/%s"%route.name)
mail_body = render_to_string("rule_expiration.txt",
{"route": route, 'expiration_days':expiration_days, 'url':admin_url})
mail_body = render_to_string("rule_action.txt",
{"route": route, 'expiration_days':expiration_days, 'action':'expires', 'url':admin_url})
days_num = ' days'
expiration_days_text = "%s %s" %('in',expiration_days)
if expiration_days == 0:
......
......@@ -118,8 +118,10 @@ def add_route(request):
form.save_m2m()
route.commit_add()
requesters_address = request.META['HTTP_X_FORWARDED_FOR']
mail_body = render_to_string("rule_add_mail.txt",
{"route": route, "address": requesters_address})
fqdn = Site.objects.get_current().domain
admin_url = "https://%s%s" % (fqdn, "/fod/edit/%s"%route.name)
mail_body = render_to_string("rule_action.txt",
{"route": route, "address": requesters_address, "action": "creation", "url": admin_url})
user_mail = "%s" %route.applier.email
user_mail = user_mail.split(';')
send_new_mail(settings.EMAIL_SUBJECT_PREFIX + "Rule %s creation request submitted by %s" %(route.name, route.applier.username),
......@@ -189,8 +191,10 @@ def edit_route(request, route_slug):
form.save_m2m()
route.commit_edit()
requesters_address = request.META['HTTP_X_FORWARDED_FOR']
mail_body = render_to_string("rule_edit_mail.txt",
{"route": route, "address": requesters_address})
fqdn = Site.objects.get_current().domain
admin_url = "https://%s%s" % (fqdn, "/fod/edit/%s"%route.name)
mail_body = render_to_string("rule_action.txt",
{"route": route, "address": requesters_address, "action": "edit", "url": admin_url})
user_mail = "%s" %route.applier.email
user_mail = user_mail.split(';')
send_new_mail(settings.EMAIL_SUBJECT_PREFIX + "Rule %s edit request submitted by %s" %(route.name, route.applier.username),
......@@ -239,8 +243,10 @@ def delete_route(request, route_slug):
route.save()
route.commit_delete()
requesters_address = request.META['HTTP_X_FORWARDED_FOR']
mail_body = render_to_string("rule_delete_mail.txt",
{"route": route, "address": requesters_address})
fqdn = Site.objects.get_current().domain
admin_url = "https://%s%s" % (fqdn, "/fod/edit/%s"%route.name)
mail_body = render_to_string("rule_action.txt",
{"route": route, "address": requesters_address, "action": "removal", "url": admin_url})
user_mail = "%s" %route.applier.email
user_mail = user_mail.split(';')
send_new_mail(settings.EMAIL_SUBJECT_PREFIX + "Rule %s removal request submitted by %s" %(route.name, route.applier.username),
......
{% load tofqdn %}{% ifequal action 'expires' %}Rule {{route.name}} expires {% ifequal expiration_days 0 %}today{% else%}in {{expiration_days}} day{{ expiration_days|pluralize }}{% endifequal %}{% else %}A new rule {{action}} job has spawned
Peer: {{route.applier.get_profile.peer.peer_name}}
User {{route.applier.username}} requested the {{action}} of the following rule from address {{address}} {% if address|tofqdn %}({{address|tofqdn}}){% endif %}:
Rule name: {{route.name}}{% endifequal %}
Match Statements:
* Source Address: {{route.source}}
* Destination Address: {{route.destination}}
* Protocol: {% if route.protocol.all %}{% for protocol in route.protocol.all %}{{ protocol }}{% if not forloop.last %}, {% endif %}{% endfor %}{% else %}any{% endif %}
* Ports: {% if route.sourceport.all or route.destinationport.all %}Defined by source/destination ports{% else %}{% if route.port.all %}{% for port in route.port.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}{% else %}any{% endif %}{% endif %}
* Source Ports: {% if route.port.all %}same as ports{% else %}{% if route.sourceport.all %}{% for port in route.sourceport.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}{% else %}any{% endif %}{% endif %}
* Destination Ports: {% if route.port.all %}same as ports{% else %}{% if route.destinationport.all %}{% for port in route.destinationport.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}{% else %}any{% endif %}{% endif %}
Then Actions:
* Action:{% for then in route.then.all %}{{ then }}{% if not forloop.last %}, {% endif %}{% endfor %}
Comments: {% if route.comments %}{{route.comments}}{% else %}-{% endif %}
Expires: {% ifequal action 'removal' %}Now, removal requested{%else%}{{route.expires}}{% endifequal %}
Rule url: {{url}}
{% load tofqdn %}
A new rule creation job has spawned
Peer: {{route.applier.get_profile.peer.peer_name}}
User {{route.applier.username}} requested the application of the following rule from address {{address}} {% if address|tofqdn %}({{address|tofqdn}}){% endif %}:
Match
* Dst Addr:{{route.destination}}
* Src Addr: {{route.source}}
* Protocol:{% for protocol in route.protocol.all %}{{ protocol }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Ports:{% for port in route.ports.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Source Ports:{% for port in route.sourceport.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Destination Ports:{% for port in route.destinationport.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
*Then:{% for then in route.then.all %}{{ then }}{% if not forloop.last %}, {% endif %}{% endfor %}
{% load tofqdn %}
A new rule removal job has spawned
Peer: {{route.applier.get_profile.peer.peer_name}}
User {{route.applier.username}} requested the removal of the following rule from address {{address}} {% if address|tofqdn %}({{address|tofqdn}}){% endif %}:
Match
* Dst Addr:{{route.destination}}
* Src Addr: {{route.source}}
* Protocol:{% for protocol in route.protocol.all %}{{ protocol }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Ports:{% for port in route.ports.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Source Ports:{% for port in route.sourceport.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Destination Ports:{% for port in route.destinationport.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
*Then:{% for then in route.then.all %}{{ then }}{% if not forloop.last %}, {% endif %}{% endfor %}
{% load tofqdn %}
A new rule edit job has spawned
Peer: {{route.applier.get_profile.peer.peer_name}}
User {{route.applier.username}} requested the application of the following rule from address {{address}} {% if address|tofqdn %}({{address|tofqdn}}){% endif %}:
Match
* Dst Addr:{{route.destination}}
* Src Addr: {{route.source}}
* Protocol:{% for protocol in route.protocol.all %}{{ protocol }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Ports:{% for port in route.ports.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Source Ports:{% for port in route.sourceport.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Destination Ports:{% for port in route.destinationport.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Then:{% for then in route.then.all %}{{ then }}{% if not forloop.last %}, {% endif %}{% endfor %}
Rule {{route.name}} expires {% ifequal expiration_days 0 %}today{% else%}in {{expiration_days}} day{{ expiration_days|pluralize }}{% endifequal %}
Match
* Dst Addr:{{route.destination}}
* Src Addr: {{route.source}}
* Protocol:{% for protocol in route.protocol.all %}{{ protocol }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Ports:{% for port in route.ports.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Source Ports:{% for port in route.sourceport.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
* Destination Ports:{% for port in route.destinationport.all %}{{ port }}{% if not forloop.last %}, {% endif %}{% endfor %}
*Then:{% for then in route.then.all %}{{ then }}{% if not forloop.last %}, {% endif %}{% endfor %}
Visit {{url}} to edit the rule.
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 to comment