diff --git a/indefero/scripts/gitserve.py b/indefero/scripts/gitserve.py index 24d1860..f343242 100644 --- a/indefero/scripts/gitserve.py +++ b/indefero/scripts/gitserve.py @@ -27,7 +27,7 @@ import subprocess SCRIPTDIR = os.path.abspath(__file__).rsplit(os.path.sep, 1)[0] GITSERVEPHP = '%s/gitserve.php' % SCRIPTDIR -process = subprocess.Popen(['php', GITSERVEPHP, sys.argv[1]], +process = subprocess.Popen(['php', GITSERVEPHP, sys.argv[1], sys.argv[2]], stdout=subprocess.PIPE, stderr=subprocess.PIPE) output = str.encode("\n").join(process.communicate()).strip() status = process.wait() diff --git a/indefero/src/IDF/Key.php b/indefero/src/IDF/Key.php index 85c9469..6fa4f99 100644 --- a/indefero/src/IDF/Key.php +++ b/indefero/src/IDF/Key.php @@ -54,6 +54,30 @@ class IDF_Key extends Pluf_Model 'blank' => false, 'verbose' => __('public key'), ), + 'last_used' => + array( + 'type' => 'Pluf_DB_Field_Datetime', + 'blank' => true, + 'verbose' => __('last used date'), + 'index' => true, + 'help_text' => 'Date of when key was last used', + ), + 'creation_dtime' => + array( + 'type' => 'Pluf_DB_Field_Datetime', + 'blank' => true, + 'verbose' => __('creation date'), + 'index' => true, + 'help_text' => 'Date of addition', + ), + 'ipaddress' => + array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'editable' => false, + 'verbose' => __('ipaddress'), + 'help_text' => __('IP address that was last connected with this key'), + ), ); // WARNING: Not using getSqlTable on the Pluf_User object to // avoid recursion. @@ -155,6 +179,10 @@ class IDF_Key extends Pluf_Model $params = array('key' => $this, 'created' => $create); Pluf_Signal::send('IDF_Key::postSave', 'IDF_Key', $params); + + if ($create) { + $this->creation_dtime = gmdate('Y-m-d H:i:s'); + } } function preDelete() diff --git a/indefero/src/IDF/Migrations/34GitSSHTracking.php b/indefero/src/IDF/Migrations/34GitSSHTracking.php new file mode 100644 index 0000000..37fa28b --- /dev/null +++ b/indefero/src/IDF/Migrations/34GitSSHTracking.php @@ -0,0 +1,47 @@ +getSqlTable(); + + $sql = array(); + + $sql["MySQL"] = <<execute($sql[$engine]); +} + +function IDF_Migrations_34GitSSHTracking_down() +{ + $table = Pluf::factory('IDF_Key')->getSqlTable(); + + $sql = array(); + + $sql["MySQL"] = <<execute($sql[$engine]); +} \ No newline at end of file diff --git a/indefero/src/IDF/Plugin/SyncGit/Cron.php b/indefero/src/IDF/Plugin/SyncGit/Cron.php index bbbf55e..6432126 100644 --- a/indefero/src/IDF/Plugin/SyncGit/Cron.php +++ b/indefero/src/IDF/Plugin/SyncGit/Cron.php @@ -29,7 +29,7 @@ class IDF_Plugin_SyncGit_Cron /** * Template for the SSH key. */ - public $template = 'command="python %s %s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s'; + public $template = 'command="python %s %s %s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s'; /** * Synchronize. @@ -56,7 +56,7 @@ class IDF_Plugin_SyncGit_Cron } if ($key_type == 'ssh' and preg_match('/^[a-zA-Z][a-zA-Z0-9_.-]*(@[a-zA-Z][a-zA-Z0-9.-]*)?$/', $key->login)) { $content = trim(str_replace(array("\n", "\r"), '', $key->content)); - $out .= sprintf($template, $cmd, $key->login, $content)."\n"; + $out .= sprintf($template, $cmd, $key->login, $key->id, $content)."\n"; } } $out = "# indefero start" . PHP_EOL . $out . "# indefero end" . PHP_EOL; diff --git a/indefero/src/IDF/Plugin/SyncGit/Serve.php b/indefero/src/IDF/Plugin/SyncGit/Serve.php index 83fda42..e296197 100644 --- a/indefero/src/IDF/Plugin/SyncGit/Serve.php +++ b/indefero/src/IDF/Plugin/SyncGit/Serve.php @@ -107,10 +107,11 @@ class IDF_Plugin_SyncGit_Serve */ public static function main($argv, $env) { - if (count($argv) != 2) { - self::fatalError('Missing argument USER.'); + if (count($argv) != 3) { + self::fatalError('Missing argument USER and SSH key id.'); } $username = $argv[1]; + $keyId = $argv[2]; umask(0022); if (!isset($env['SSH_ORIGINAL_COMMAND'])) { self::fatalError('Need SSH_ORIGINAL_COMMAND in environment.'); @@ -120,6 +121,12 @@ class IDF_Plugin_SyncGit_Serve $serve = new IDF_Plugin_SyncGit_Serve(); try { $new_cmd = $serve->serve($username, $cmd); + if ($keyId) { + $key = Pluf::factory('IDF_Key', $keyId); + $key->ipaddress = explode(" ", $_SERVER["SSH_CLIENT"])[0]; + $key->last_used = gmdate('Y-m-d H:i:s'); + $key->update(); + } } catch (Exception $e) { self::fatalError($e->getMessage()); } diff --git a/indefero/src/IDF/templates/idf/user/myaccount.html b/indefero/src/IDF/templates/idf/user/myaccount.html index 7623635..90ebe2b 100644 --- a/indefero/src/IDF/templates/idf/user/myaccount.html +++ b/indefero/src/IDF/templates/idf/user/myaccount.html @@ -147,11 +147,35 @@ {if count($keys)} - -{foreach $keys as $key} -{/foreach} + + + + + + + + + + + {foreach $keys as $key} + + + + + + + + {/foreach}
{trans 'Your Current Public Keys'}
-{$key.showCompact()}
-
{trans 'Your Current Public Keys'}
KeyKey AddedKey Last UsedLast IPDelete
+ {$key.showCompact()} + + {$key.creation_dtime|date} + + {$key.last_used|dateago} + + {$key.ipaddress} + +
+
{/if} {if count($mailaddrs)>1}