# HG changeset patch # User Christian Oyarzun # Date 1416253365 18000 # Node ID 719ed95c437ea99f25e817317fff9f15804ecda6 # Parent e4f27ab7cbea8353a3bfead772d58b6cf215962a ssh: keep track of latest use of SSH keys Based on work by Ilya Beda on https://bitbucket.org/ir4y/rhodecode/commits/branch/ssh_server_support , also heavily modified by Mads Kiilerich. diff -r e4f27ab7cbea -r 719ed95c437e kallithea/lib/vcs/backends/ssh.py --- a/kallithea/lib/vcs/backends/ssh.py Mon Nov 17 14:42:45 2014 -0500 +++ b/kallithea/lib/vcs/backends/ssh.py Mon Nov 17 14:42:45 2014 -0500 @@ -20,9 +20,11 @@ """ import sys +import datetime import logging -from kallithea.model.db import Repository, User +from kallithea.model.db import Repository, User, UserSshKeys +from kallithea.model.meta import Session from kallithea.lib.auth import HasPermissionAnyMiddleware, AuthUser from kallithea.lib.utils2 import safe_str, set_hook_environment @@ -65,6 +67,12 @@ if self.authuser is None: # not ok ... but already kind of authenticated by SSH ... but not really not authorized ... self.exit('User %s from %s cannot be authorized' % (dbuser.username, client_ip)) + ssh_key = UserSshKeys.get(key_id) + if ssh_key is None: + self.exit('SSH key %r not found' % key_id) + ssh_key.last_seen = datetime.datetime.now() + Session().commit() + if HasPermissionAnyMiddleware('repository.write', 'repository.admin')(self.authuser, self.repo_name): self.allow_push = True diff -r e4f27ab7cbea -r 719ed95c437e kallithea/templates/admin/my_account/my_account_ssh_keys.html --- a/kallithea/templates/admin/my_account/my_account_ssh_keys.html Mon Nov 17 14:42:45 2014 -0500 +++ b/kallithea/templates/admin/my_account/my_account_ssh_keys.html Mon Nov 17 14:42:45 2014 -0500 @@ -3,6 +3,7 @@ ${_('Fingerprint')} ${_('Description')} + ${_('Last Used')} ${_('Action')} %for ssh_key in c.user_ssh_keys: @@ -14,6 +15,13 @@ ${ssh_key.description} + %if ssh_key.last_seen: + ${h.fmt_date(ssh_key.last_seen)} + %else: + ${_('Never')} + %endif + + ${h.form(url('my_account_ssh_keys_delete'))} ${h.hidden('del_public_key', ssh_key.public_key)}