Revision fdc3d663
b/cron_notify_expired.py | ||
---|---|---|
13 | 13 |
def notify_expired(): |
14 | 14 |
routes = Route.objects.all() |
15 | 15 |
for route in routes: |
16 |
if route.status not in ['EXPIRED', 'ADMININACTIVE', 'ERROR']: |
|
16 |
if route.status not in ['EXPIRED', 'ADMININACTIVE', 'INACTIVE', 'ERROR']:
|
|
17 | 17 |
expiration_days = (route.expires - datetime.date.today()).days |
18 | 18 |
if expiration_days < settings.EXPIRATION_NOTIFY_DAYS: |
19 | 19 |
try: |
b/flowspec/admin.py | ||
---|---|---|
7 | 7 |
from django.contrib.auth.admin import UserAdmin |
8 | 8 |
from accounts.models import UserProfile |
9 | 9 |
from flowspy.flowspec.forms import * |
10 |
|
|
10 |
import datetime |
|
11 | 11 |
|
12 | 12 |
class RouteAdmin(admin.ModelAdmin): |
13 | 13 |
form = RouteForm |
... | ... | |
21 | 21 |
|
22 | 22 |
def save_model(self, request, obj, form, change): |
23 | 23 |
obj.status = "PENDING" |
24 |
obj.expires = datetime.date.today() |
|
24 | 25 |
obj.save() |
25 | 26 |
obj.commit_add() |
26 | 27 |
|
b/flowspec/models.py | ||
---|---|---|
75 | 75 |
return ret.rstrip(":") |
76 | 76 |
class Meta: |
77 | 77 |
db_table = u'then_action' |
78 |
ordering = ['action', 'action_value'] |
|
78 | 79 |
unique_together = ("action", "action_value") |
79 | 80 |
|
80 | 81 |
class Route(models.Model): |
b/flowspec/tasks.py | ||
---|---|---|
121 | 121 |
if route.has_expired() and (route.status != 'EXPIRED' and route.status != 'ADMININACTIVE' and route.status != 'INACTIVE'): |
122 | 122 |
logger.info('Expiring route %s' %route.name) |
123 | 123 |
subtask(delete).delay(route, reason="EXPIRED") |
124 |
elif route.has_expired() and (route.status == 'ADMININACTIVE' or route.status == 'INACTIVE'): |
|
125 |
route.status = 'EXPIRED' |
|
126 |
route.response = 'Rule Expired' |
|
127 |
logger.info('Expiring route %s' %route.name) |
|
128 |
route.save() |
|
124 |
# elif route.has_expired() and (route.status == 'ADMININACTIVE' or route.status == 'INACTIVE'):
|
|
125 |
# route.status = 'EXPIRED'
|
|
126 |
# route.response = 'Rule Expired'
|
|
127 |
# logger.info('Expiring route %s' %route.name)
|
|
128 |
# route.save()
|
|
129 | 129 |
else: |
130 | 130 |
if route.status != 'EXPIRED': |
131 | 131 |
route.check_sync() |
b/flowspec/views.py | ||
---|---|---|
32 | 32 |
from django.views.decorators.cache import never_cache |
33 | 33 |
from django.conf import settings |
34 | 34 |
from django.core.mail import mail_admins, mail_managers, send_mail |
35 |
|
|
35 |
import datetime |
|
36 | 36 |
import os |
37 | 37 |
|
38 | 38 |
LOG_FILENAME = os.path.join(settings.LOG_FILE_LOCATION, 'celery_jobs.log') |
... | ... | |
174 | 174 |
requester_peer = request.user.get_profile().peer |
175 | 175 |
if applier_peer == requester_peer: |
176 | 176 |
route.status = "PENDING" |
177 |
route.expires = datetime.date.today() |
|
177 | 178 |
route.save() |
178 | 179 |
route.commit_delete() |
179 | 180 |
requesters_address = request.META['HTTP_X_FORWARDED_FOR'] |
b/templates/user_routes.html | ||
---|---|---|
282 | 282 |
title = "{% ifequal route.status 'INACTIVE' %}Suspended by user{% else %}{% ifequal route.status 'ADMININACTIVE' %}Suspended by administrator{% else %}{% ifequal route.status 'EXPIRED' %}Suspended due to expiration{% else %}{% ifequal route.status 'OUTOFSYNC' %}Syncronization error. Configuration in device deffers from rule{% endifequal %}{% endifequal %}{% endifequal %}{% endifequal %}"{% endif %}>{% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' %}SUSPENDED{% else %}{% if route.status == 'OUTOFSYNC' %}ERROR{% else %}{{route.status}}{% endif %}{% endif %}</span></td> |
283 | 283 |
{% comment %}<td style="text-align: center;">{{ route.response }}</td>{% endcomment %} |
284 | 284 |
<td style="text-align: center;">{{ route.applier }}</td> |
285 |
<td style="text-align: center;"><span {% if route.days_to_expire %} |
|
285 |
<td style="text-align: center;"><span {% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' or route.status == 'OUTOFSYNC'%}{% else %}{% if route.days_to_expire %}
|
|
286 | 286 |
class="expiresclass" |
287 | 287 |
style="border-bottom:2px dashed red;" |
288 | 288 |
title="Expires {% ifequal route.days_to_expire '0' %}today{% else%}in {{route.days_to_expire}} day{{ route.days_to_expire|pluralize }}{% endifequal %}" |
289 |
{% endif %}>{{ route.expires }}</span></td> |
|
290 |
<td style="text-align: center;">{{ route.response }}</td>
|
|
289 |
{% endif %}{% endif %}>{{ route.expires }}</span></td>
|
|
290 |
<td style="text-align: center;">{% if route.status == 'EXPIRED' %}Rule expired{% else %}{% if route.status == 'ADMININACTIVE' %}Suspended by administrator{% else %}{% if route.status == 'INACTIVE' %}Suspended by user{% else %}{{ route.response }}{% endif %}{% endif %}{% endif %}</td>
|
|
291 | 291 |
<td style="text-align: center; width:180px;"> |
292 | 292 |
{% ifequal route.status 'ACTIVE' %} |
293 | 293 |
<a href="{% url edit-route route.name %}" class="edit_button" id="edit_button_{{route.pk}}">Edit</a> |
Also available in: Unified diff