Mercurial > kallithea
changeset 7784:719ed95c437e
ssh: keep track of latest use of SSH keys
Based on work by Ilya Beda <ir4y.ix@gmail.com> on
https://bitbucket.org/ir4y/rhodecode/commits/branch/ssh_server_support , also
heavily modified by Mads Kiilerich.
author | Christian Oyarzun <oyarzun@gmail.com> |
---|---|
date | Mon, 17 Nov 2014 14:42:45 -0500 |
parents | e4f27ab7cbea |
children | b5b91e854308 |
files | kallithea/lib/vcs/backends/ssh.py kallithea/templates/admin/my_account/my_account_ssh_keys.html kallithea/templates/admin/users/user_edit_ssh_keys.html |
diffstat | 3 files changed, 25 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 @@ <tr> <th>${_('Fingerprint')}</th> <th>${_('Description')}</th> + <th>${_('Last Used')}</th> <th>${_('Action')}</th> </tr> %for ssh_key in c.user_ssh_keys: @@ -14,6 +15,13 @@ ${ssh_key.description} </td> <td> + %if ssh_key.last_seen: + ${h.fmt_date(ssh_key.last_seen)} + %else: + ${_('Never')} + %endif + </td> + <td> ${h.form(url('my_account_ssh_keys_delete'))} ${h.hidden('del_public_key', ssh_key.public_key)} <button class="btn btn-danger btn-xs" type="submit"
--- a/kallithea/templates/admin/users/user_edit_ssh_keys.html Mon Nov 17 14:42:45 2014 -0500 +++ b/kallithea/templates/admin/users/user_edit_ssh_keys.html Mon Nov 17 14:42:45 2014 -0500 @@ -3,6 +3,7 @@ <tr> <th>${_('Fingerprint')}</th> <th>${_('Description')}</th> + <th>${_('Last Used')}</th> <th>${_('Action')}</th> </tr> %for ssh_key in c.user_ssh_keys: @@ -14,6 +15,13 @@ ${ssh_key.description} </td> <td> + %if ssh_key.last_seen: + ${h.fmt_date(ssh_key.last_seen)} + %else: + ${_('Never')} + %endif + </td> + <td> ${h.form(url('edit_user_ssh_keys_delete', id=c.user.user_id))} ${h.hidden('del_public_key', ssh_key.public_key)} <button class="btn btn-danger btn-xs" type="submit"