Sfoglia il codice sorgente

added logging of mails sent unencrypted (in database)

Hendrik Sünkler 8 anni fa
parent
commit
dbade47d9f

+ 1
- 1
posttls/config/settings/base.py Vedi File

@@ -75,7 +75,7 @@ AUTH_USER_MODEL = 'core.User'
75 75
 
76 76
 LANGUAGE_CODE = 'en-us'
77 77
 
78
-TIME_ZONE = 'UTC'
78
+TIME_ZONE = 'Europe/Berlin'
79 79
 
80 80
 USE_I18N = True
81 81
 

+ 6
- 1
posttls/core/admin.py Vedi File

@@ -1,7 +1,7 @@
1 1
 from django.contrib import admin
2 2
 from django.contrib.auth.admin import UserAdmin
3 3
 
4
-from .models import User, TLSNotification
4
+from .models import User, TLSNotification, TLSLogEntry
5 5
 
6 6
 
7 7
 # Custom User Model
@@ -16,5 +16,10 @@ class TLSNotificationAdmin(admin.ModelAdmin):
16 16
     list_display = ('queue_id', 'notification')
17 17
 
18 18
 
19
+class TLSLogEntryAdmin(admin.ModelAdmin):
20
+    list_display = ('queue_id', 'sender', 'recipients', 'action', 'date')
21
+
22
+
19 23
 admin.site.register(TLSNotification, TLSNotificationAdmin)
24
+admin.site.register(TLSLogEntry, TLSLogEntryAdmin)
20 25
 

+ 31
- 0
posttls/core/migrations/0003_auto_20160228_1436.py Vedi File

@@ -0,0 +1,31 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.9.2 on 2016-02-28 14:36
3
+from __future__ import unicode_literals
4
+
5
+import django.core.validators
6
+from django.db import migrations, models
7
+
8
+
9
+class Migration(migrations.Migration):
10
+
11
+    dependencies = [
12
+        ('core', '0002_tlsnotification'),
13
+    ]
14
+
15
+    operations = [
16
+        migrations.CreateModel(
17
+            name='TLSLogEntry',
18
+            fields=[
19
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20
+                ('queue_id', models.CharField(max_length=20, verbose_name='Queue ID')),
21
+                ('sender', models.CharField(max_length=55, verbose_name='Sender')),
22
+                ('action', models.CharField(max_length=100, verbose_name='Action')),
23
+                ('date', models.DateTimeField(verbose_name='Date')),
24
+            ],
25
+        ),
26
+        migrations.AlterField(
27
+            model_name='user',
28
+            name='username',
29
+            field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=30, unique=True, validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.')], verbose_name='username'),
30
+        ),
31
+    ]

+ 26
- 0
posttls/core/migrations/0004_auto_20160228_1600.py Vedi File

@@ -0,0 +1,26 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.9.2 on 2016-02-28 15:00
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('core', '0003_auto_20160228_1436'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AddField(
16
+            model_name='tlslogentry',
17
+            name='recipients',
18
+            field=models.CharField(default='', max_length=255, verbose_name='Recipients'),
19
+            preserve_default=False,
20
+        ),
21
+        migrations.AlterField(
22
+            model_name='tlslogentry',
23
+            name='sender',
24
+            field=models.CharField(max_length=255, verbose_name='Sender'),
25
+        ),
26
+    ]

+ 20
- 0
posttls/core/migrations/0005_auto_20160228_1615.py Vedi File

@@ -0,0 +1,20 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.9.2 on 2016-02-28 15:15
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        ('core', '0004_auto_20160228_1600'),
12
+    ]
13
+
14
+    operations = [
15
+        migrations.AlterField(
16
+            model_name='tlslogentry',
17
+            name='recipients',
18
+            field=models.CharField(max_length=255, null=True, verbose_name='Recipients'),
19
+        ),
20
+    ]

+ 13
- 0
posttls/core/models.py Vedi File

@@ -18,5 +18,18 @@ class TLSNotification(models.Model):
18 18
     queue_id = models.CharField('Queue ID', max_length=20)
19 19
     notification = models.DateTimeField('Notification')  # Time of the last notification
20 20
 
21
+    def __str__(self):
22
+        return self.queue_id
23
+
24
+
25
+class TLSLogEntry(models.Model):
26
+    """Log entries for handled mails (forwarded/deleted)"""
27
+
28
+    queue_id = models.CharField('Queue ID', max_length=20)
29
+    sender = models.CharField('Sender', max_length=255)
30
+    recipients = models.CharField('Recipients', max_length=255, null=True)
31
+    action = models.CharField('Action', max_length=100)
32
+    date = models.DateTimeField('Date')
33
+
21 34
     def __str__(self):
22 35
         return self.queue_id

+ 11
- 2
posttls/core/views.py Vedi File

@@ -2,8 +2,9 @@ import subprocess
2 2
 import re
3 3
 
4 4
 from django.shortcuts import render
5
+from django.utils import timezone
5 6
 
6
-from core.models import TLSNotification
7
+from core.models import TLSNotification, TLSLogEntry
7 8
 
8 9
 
9 10
 def mailaction(request):
@@ -69,7 +70,7 @@ def mailaction(request):
69 70
         # - the recipients: we do want to send the mail not to all recipients mentioned
70 71
         #                   in the header. The mail was already sent to most of the
71 72
         #                   recipients. We just want so send the mail to those recipients
72
-        #                   who did not already get the email since there were errors why
73
+        #                   who did not already get the email since there were errors so
73 74
         #                   the mail was not delivered. These are the recipient lines in
74 75
         #                   the envelope!
75 76
 
@@ -139,6 +140,14 @@ def mailaction(request):
139 140
                              stderr=subprocess.STDOUT)
140 141
         output += str(p.stdout.read(), "utf-8")
141 142
 
143
+        # Create log entry in database
144
+        q = TLSLogEntry(queue_id=queue_id,
145
+                        sender=envelope_sender,
146
+                        action=action,
147
+                        recipients=recipients,
148
+                        date=timezone.now())
149
+        q.save()
150
+
142 151
     ######################################################
143 152
     # DELETE MAIL
144 153
     elif action == "delete":

Loading…
Annulla
Salva