Revision 94a504e6
b/cron_renew_apikeys.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 |
from django.contrib.sites.models import Site |
|
8 |
from tastypie.models import ApiKey |
|
9 |
|
|
10 |
import datetime |
|
11 |
|
|
12 |
|
|
13 |
def renew_apikeys(): |
|
14 |
apikeys = ApiKey.objects.all() |
|
15 |
for apikey in apikeys: |
|
16 |
if (datetime.datetime.today() - apikey.created).days >= settings.APIKEY_RENEWAL_PERIOD: |
|
17 |
try: |
|
18 |
user = apikey.user |
|
19 |
apikey.key = apikey.generate_key() |
|
20 |
apikey.created = datetime.datetime.now() |
|
21 |
apikey.save() |
|
22 |
fqdn = Site.objects.get_current().domain |
|
23 |
admin_url = "https://%s%s" %(fqdn,"/fod/profile/") |
|
24 |
mail_body = render_to_string("apikey_renewal.txt", |
|
25 |
{"user": user, 'url':admin_url}) |
|
26 |
send_mail(settings.EMAIL_SUBJECT_PREFIX + "API Key expiration", |
|
27 |
mail_body, settings.SERVER_EMAIL, |
|
28 |
[user.email]) |
|
29 |
except Exception as e: |
|
30 |
print e |
|
31 |
pass |
|
32 |
|
|
33 |
if __name__ == "__main__": |
|
34 |
renew_apikeys() |
|
35 |
|
b/rapi/api.py | ||
---|---|---|
62 | 62 |
fields = ['action', 'action_value'] |
63 | 63 |
|
64 | 64 |
class RuleResource(ModelResource): |
65 |
name = fields.CharField(attribute='name') |
|
65 |
name = fields.CharField(attribute='name', help_text="A slug field (no spaces)")
|
|
66 | 66 |
sourceport = fields.ManyToManyField(SourcePortRes, 'sourceport', full=True, null=True) |
67 | 67 |
destinationport = fields.ManyToManyField(DestPortRes, 'destinationport', full=True, null=True) |
68 | 68 |
then = fields.ManyToManyField(ThenResource, 'then', full=True, null=True) |
b/templates/apikey_renewal.txt | ||
---|---|---|
1 |
Dear user {{user.username}}, |
|
2 |
|
|
3 |
Your API key for Firewall on Demand REST API access has been renewed. |
|
4 |
This occurs due to security reasons. |
|
5 |
|
|
6 |
Your new API Key can be found here: {{url}} |
Also available in: Unified diff