change password generator
[cas.git] / src / ssh_keys / views.py
index 67401e3..dc16286 100644 (file)
@@ -1,5 +1,4 @@
 from datetime import datetime, timedelta
 from datetime import datetime, timedelta
-import logging
 import re
 from django.contrib.auth.mixins import LoginRequiredMixin
 from django.contrib import messages
 import re
 from django.contrib.auth.mixins import LoginRequiredMixin
 from django.contrib import messages
@@ -48,7 +47,6 @@ class DeleteSSHKeyView(LoginRequiredMixin, DeleteView):
 
 @csrf_exempt
 def ssh_keys_seen(request):
 
 @csrf_exempt
 def ssh_keys_seen(request):
-    logger = logging.getLogger('django.request')
     key = request.GET.get('key')
     service = get_object_or_404(Service, key=key)
     n = now()
     key = request.GET.get('key')
     service = get_object_or_404(Service, key=key)
     n = now()
@@ -61,18 +59,24 @@ def ssh_keys_seen(request):
             continue
         data = parse_log_line(line)
         if data is None:
             continue
         data = parse_log_line(line)
         if data is None:
-            logger.error('Unparsed: ' + line)
-            break
+            continue
         dt = data['datetime']
         dt = data['datetime']
-        key = data['algo'], data['md5']
+        algo = data['algo']
+        if 'md5' in data:
+            hash_type = 'md5'
+            hash_value = data['md5']
+        else:
+            hash_type = 'sha256'
+            hash_value = data['sha256']
+        key = algo, hash_type, hash_value
         last_seen[key] = max(last_seen.get(key, dt), dt)
 
     for key, dt in last_seen.items():
         last_seen[key] = max(last_seen.get(key, dt), dt)
 
     for key, dt in last_seen.items():
-        algo, md5 = key
+        algo, hash_type, hash_value = key
         SSHKey.objects.filter(
             Q(last_seen_at=None) | Q(last_seen_at__lt=dt),
             algorithm=algo,
         SSHKey.objects.filter(
             Q(last_seen_at=None) | Q(last_seen_at__lt=dt),
             algorithm=algo,
-            md5_hash=md5
+            **{f'{hash_type}_hash': hash_value}
         ).update(
             last_seen_at=dt
         )
         ).update(
             last_seen_at=dt
         )