+
+
+@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()
+
+ logline_re = r'^(?P<time>\w{3}\s+\d+\s+\d\d:\d\d:\d\d).*: Accepted publickey for .* from .* port .* ssh2: (?P<algo>\w+) (?P<hash>[a-f0-9:]+)$'
+
+ last_seen = {}
+ for line in request.body.decode('latin1').split('\n'):
+ if not line.strip():
+ continue
+ data = parse_log_line(line)
+ if data is None:
+ logger.error('Unparsed: ' + line)
+ break
+ dt = data['datetime']
+ key = data['algo'], data['md5']
+ last_seen[key] = max(last_seen.get(key, dt), dt)
+
+ for key, dt in last_seen.items():
+ algo, md5 = key
+ SSHKey.objects.filter(
+ Q(last_seen_at=None) | Q(last_seen_at__lt=dt),
+ algorithm=algo,
+ md5_hash=md5
+ ).update(
+ last_seen_at=dt
+ )
+
+ return http.HttpResponse('ok')
+