diff --git a/cron_notify_expired.py b/cron_notify_expired.py index 6969133e79bd45698e4a5e538f6f59a8e7d7e5ba..122625d28cf31e817dd51139d69d4aec57bbd559 100755 --- a/cron_notify_expired.py +++ b/cron_notify_expired.py @@ -13,7 +13,7 @@ import datetime def notify_expired(): routes = Route.objects.all() for route in routes: - if route.status not in ['EXPIRED', 'ADMININACTIVE', 'ERROR']: + if route.status not in ['EXPIRED', 'ADMININACTIVE', 'INACTIVE', 'ERROR']: expiration_days = (route.expires - datetime.date.today()).days if expiration_days < settings.EXPIRATION_NOTIFY_DAYS: try: diff --git a/flowspec/admin.py b/flowspec/admin.py index 76307a12ac319ade075bbd9a7aac86407a9e0327..5ee2e914af67d198a2905c6ef3bdad89189cb873 100644 --- a/flowspec/admin.py +++ b/flowspec/admin.py @@ -7,7 +7,7 @@ from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin from accounts.models import UserProfile from flowspy.flowspec.forms import * - +import datetime class RouteAdmin(admin.ModelAdmin): form = RouteForm @@ -21,6 +21,7 @@ class RouteAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): obj.status = "PENDING" + obj.expires = datetime.date.today() obj.save() obj.commit_add() diff --git a/flowspec/models.py b/flowspec/models.py index ebfaebfe8aa8ed30abb6ad0bfa47d05795c1a193..0caba4932251ec1fd5e4448e724f714d3d871cb8 100644 --- a/flowspec/models.py +++ b/flowspec/models.py @@ -75,6 +75,7 @@ class ThenAction(models.Model): return ret.rstrip(":") class Meta: db_table = u'then_action' + ordering = ['action', 'action_value'] unique_together = ("action", "action_value") class Route(models.Model): diff --git a/flowspec/tasks.py b/flowspec/tasks.py index 35a52bcbffeb4a183e775816b8ffe3f188f12f5d..d793402f28855a7b73530c7e6f735d440d5c97a9 100644 --- a/flowspec/tasks.py +++ b/flowspec/tasks.py @@ -121,11 +121,11 @@ def check_sync(route_name=None, selected_routes = []): if route.has_expired() and (route.status != 'EXPIRED' and route.status != 'ADMININACTIVE' and route.status != 'INACTIVE'): logger.info('Expiring route %s' %route.name) subtask(delete).delay(route, reason="EXPIRED") - elif route.has_expired() and (route.status == 'ADMININACTIVE' or route.status == 'INACTIVE'): - route.status = 'EXPIRED' - route.response = 'Rule Expired' - logger.info('Expiring route %s' %route.name) - route.save() +# elif route.has_expired() and (route.status == 'ADMININACTIVE' or route.status == 'INACTIVE'): +# route.status = 'EXPIRED' +# route.response = 'Rule Expired' +# logger.info('Expiring route %s' %route.name) +# route.save() else: if route.status != 'EXPIRED': route.check_sync() diff --git a/flowspec/views.py b/flowspec/views.py index c183989560fe3ef3154cabb344508a11f416345f..b3c93024f13ef4978aecce993277f75c23d6e486 100644 --- a/flowspec/views.py +++ b/flowspec/views.py @@ -32,7 +32,7 @@ from flowspy.utils.decorators import shib_required from django.views.decorators.cache import never_cache from django.conf import settings from django.core.mail import mail_admins, mail_managers, send_mail - +import datetime import os LOG_FILENAME = os.path.join(settings.LOG_FILE_LOCATION, 'celery_jobs.log') @@ -174,6 +174,7 @@ def delete_route(request, route_slug): requester_peer = request.user.get_profile().peer if applier_peer == requester_peer: route.status = "PENDING" + route.expires = datetime.date.today() route.save() route.commit_delete() requesters_address = request.META['HTTP_X_FORWARDED_FOR'] diff --git a/templates/user_routes.html b/templates/user_routes.html index 97c1acc6ba5505eb73dc8f83b4c7ba7e912972ae..9c86c0116aa939428f913da3dda7347550df8927 100644 --- a/templates/user_routes.html +++ b/templates/user_routes.html @@ -282,12 +282,12 @@ function delete_route(route){ 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> {% comment %}<td style="text-align: center;">{{ route.response }}</td>{% endcomment %} <td style="text-align: center;">{{ route.applier }}</td> - <td style="text-align: center;"><span {% if route.days_to_expire %} + <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 %} class="expiresclass" style="border-bottom:2px dashed red;" title="Expires {% ifequal route.days_to_expire '0' %}today{% else%}in {{route.days_to_expire}} day{{ route.days_to_expire|pluralize }}{% endifequal %}" - {% endif %}>{{ route.expires }}</span></td> - <td style="text-align: center;">{{ route.response }}</td> + {% endif %}{% endif %}>{{ route.expires }}</span></td> + <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> <td style="text-align: center; width:180px;"> {% ifequal route.status 'ACTIVE' %} <a href="{% url edit-route route.name %}" class="edit_button" id="edit_button_{{route.pk}}">Edit</a>