Revision fd3870ee
b/cron_notify_expired.py | ||
---|---|---|
1 |
from django.core.management import setup_environ |
|
2 |
import settings |
|
3 |
setup_environ(settings) |
|
4 |
from django.core.mail import send_mail |
|
5 |
from flowspy.flowspec.models import * |
|
6 |
from django.template.loader import render_to_string |
|
7 |
import datetime |
|
8 |
|
|
9 |
|
|
10 |
def notify_expired(): |
|
11 |
routes = Route.objects.all() |
|
12 |
for route in routes: |
|
13 |
if route.status != 'EXPIRED': |
|
14 |
expiration_days = (route.expires - datetime.date.today()).days |
|
15 |
if expiration_days < settings.EXPIRATION_NOTIFY_DAYS: |
|
16 |
try: |
|
17 |
mail_body = render_to_string("rule_expiration.txt", |
|
18 |
{"route": route, 'expiration_days':expiration_days}) |
|
19 |
send_mail(settings.EMAIL_SUBJECT_PREFIX + "Rule %s expires in %s days" % |
|
20 |
(route.name,expiration_days), |
|
21 |
mail_body, settings.SERVER_EMAIL, |
|
22 |
[route.applier.email]) |
|
23 |
except Exception as e: |
|
24 |
print e |
|
25 |
pass |
|
26 |
|
|
27 |
if __name__ == "__main__": |
|
28 |
notify_expired() |
|
29 |
|
b/flowspec/admin.py | ||
---|---|---|
13 | 13 |
actions = ['deactivate'] |
14 | 14 |
|
15 | 15 |
def deactivate(self, request, queryset): |
16 |
queryset = queryset.filter(status='ACTIVE') |
|
17 |
rows = queryset.update(status='PENDING') |
|
16 | 18 |
response = batch_delete.delay(queryset, reason="ADMININACTIVE") |
17 | 19 |
self.message_user(request, "Added request %s to job que. Check in a while for result" % response) |
18 | 20 |
deactivate.short_description = "Remove selected routes from network" |
b/flowspec/models.py | ||
---|---|---|
253 | 253 |
self.status = "ACTIVE" |
254 | 254 |
self.save() |
255 | 255 |
found = True |
256 |
if not found and self.status == "ADMININACTIVE": |
|
257 |
found = True |
|
256 | 258 |
return found |
257 | 259 |
|
258 | 260 |
def get_then(self): |
b/flowspec/tasks.py | ||
---|---|---|
3 | 3 |
from celery.task.sets import subtask |
4 | 4 |
import logging |
5 | 5 |
import json |
6 |
|
|
7 | 6 |
from celery.task.http import * |
8 | 7 |
from flowspy.utils import beanstalkc |
9 | 8 |
from django.conf import settings |
... | ... | |
105 | 104 |
if route_name: |
106 | 105 |
routes = routes.filter(name=route_name) |
107 | 106 |
for route in routes: |
108 |
if route.has_expired() and (route.status != 'EXPIRED' or route.status != 'ADMININACTIVE' or route.status != 'INACTIVE'):
|
|
107 |
if route.has_expired() and (route.status != 'EXPIRED' and route.status != 'ADMININACTIVE' and route.status != 'INACTIVE'):
|
|
109 | 108 |
logger.info('Expiring route %s' %route.name) |
110 | 109 |
subtask(delete).delay(route, reason="EXPIRED") |
111 | 110 |
elif route.has_expired() and (route.status == 'ADMININACTIVE' or route.status == 'INACTIVE'): |
112 | 111 |
route.status = 'EXPIRED' |
113 | 112 |
route.response = 'Route Expired' |
114 | 113 |
route.save() |
115 |
elif route.status != 'EXPIRED': |
|
116 |
route.check_sync() |
|
114 |
else: |
|
115 |
if route.status != 'EXPIRED': |
|
116 |
route.check_sync() |
|
117 | 117 |
|
118 | 118 |
|
119 | 119 |
#def delete(route): |
b/flowspec/views.py | ||
---|---|---|
11 | 11 |
from django.shortcuts import get_object_or_404, render_to_response |
12 | 12 |
from django.core.context_processors import request |
13 | 13 |
from django.template.context import RequestContext |
14 |
from django.template.loader import get_template |
|
14 |
from django.template.loader import get_template, render_to_string
|
|
15 | 15 |
from django.utils import simplejson |
16 | 16 |
from django.core.urlresolvers import reverse |
17 | 17 |
from django.contrib import messages |
... | ... | |
30 | 30 |
|
31 | 31 |
from django.views.decorators.cache import never_cache |
32 | 32 |
from django.conf import settings |
33 |
from django.core.mail import mail_admins, mail_managers, send_mail |
|
33 | 34 |
|
34 | 35 |
|
35 | 36 |
def days_offset(): return datetime.date.today() + datetime.timedelta(days = settings.EXPIRATION_DAYS_OFFSET) |
... | ... | |
80 | 81 |
route.save() |
81 | 82 |
form.save_m2m() |
82 | 83 |
route.commit_add() |
84 |
mail_body = render_to_string("rule_add_mail.txt", |
|
85 |
{"route": route}) |
|
86 |
mail_admins("Rule %s creation request submitted by %s" %(route.name, route.applier.username), |
|
87 |
mail_body, fail_silently=True) |
|
83 | 88 |
return HttpResponseRedirect(reverse("group-routes")) |
84 | 89 |
else: |
85 | 90 |
return render_to_response('apply.html', {'form': form, 'applier':applier}, |
... | ... | |
127 | 132 |
messages.add_message(request, messages.WARNING, |
128 | 133 |
"Cannot edit the expired rule %s. Contact helpdesk to enable it" %(route_slug)) |
129 | 134 |
return HttpResponseRedirect(reverse("group-routes")) |
135 |
if route_edit.status == "PENDING" : |
|
136 |
messages.add_message(request, messages.WARNING, |
|
137 |
"Cannot edit a pending rule: %s." %(route_slug)) |
|
138 |
return HttpResponseRedirect(reverse("group-routes")) |
|
130 | 139 |
route_original = deepcopy(route_edit) |
131 | 140 |
if request.POST: |
132 | 141 |
form = RouteForm(request.POST, instance = route_edit) |
... | ... | |
139 | 148 |
route.save() |
140 | 149 |
form.save_m2m() |
141 | 150 |
route.commit_edit() |
151 |
mail_body = render_to_string("rule_edit_mail.txt", |
|
152 |
{"route": route}) |
|
153 |
mail_admins("Rule %s edit request submitted by %s" %(route.name, route.applier.username), |
|
154 |
mail_body, fail_silently=True) |
|
142 | 155 |
return HttpResponseRedirect(reverse("group-routes")) |
143 | 156 |
else: |
144 | 157 |
return render_to_response('apply.html', {'form': form, 'edit':True, 'applier': applier}, |
... | ... | |
160 | 173 |
if applier_peer == requester_peer: |
161 | 174 |
route.status = "PENDING" |
162 | 175 |
route.commit_delete() |
176 |
mail_body = render_to_string("rule_delete_mail.txt", |
|
177 |
{"route": route}) |
|
178 |
mail_admins("Rule %s removal request submitted by %s" %(route.name, route.applier.username), |
|
179 |
mail_body, fail_silently=True) |
|
163 | 180 |
html = "<html><body>Done</body></html>" |
164 | 181 |
return HttpResponse(html) |
165 | 182 |
else: |
/dev/null | ||
---|---|---|
1 |
Η αίτησή σας #{{ application.pk }} για τη δημιουργία εικονικής μηχανής με όνομα |
|
2 |
{{ application.hostname }} απορρίφθηκε για τους παρακάτω λόγους: |
|
3 |
|
|
4 |
{{ application.admin_comments }} |
|
5 |
|
|
6 |
Για το ΚΕΔ ΕΔΕΤ |
/dev/null | ||
---|---|---|
1 |
Η εικονική μηχανή με όνομα {{ application.hostname }} δημιουργήθηκε. |
|
2 |
|
|
3 |
Μπορείτε να τη χειριστείτε και να δείτε τα στοιχεία της στην ακόλουθη |
|
4 |
διεύθυνση: |
|
5 |
{{instance_url}} |
|
6 |
|
|
7 |
{% if application.admin_comments %}Σχόλια διαχειριστή: |
|
8 |
{{ application.admin_comments }} |
|
9 |
{% endif %} |
|
10 |
Για το ΚΕΔ ΕΔΕΤ |
Also available in: Unified diff