srchub

srchub Commit Details


Date:2016-04-30 17:14:41 (8 years 7 months ago)
Author:Natalie Adams
Branch:master
Commit:ac5ced20a7b440ccb4a0511d6723700105dcdd00
Parents: c16adf0a896e6105623adc9b688ffb9fd4f860da
Message:Issue 104: Create service that tracks SSH key usage

Changes:

File differences

indefero/scripts/gitserve.py
2727
2828
2929
30
30
3131
3232
3333
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()
indefero/src/IDF/Key.php
5454
5555
5656
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
5781
5882
5983
......
155179
156180
157181
182
183
184
185
158186
159187
160188
'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.
$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()
indefero/src/IDF/Migrations/34GitSSHTracking.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
function IDF_Migrations_34GitSSHTracking_up()
{
$table = Pluf::factory('IDF_Key')->getSqlTable();
$sql = array();
$sql["MySQL"] = <<<EOD
ALTER TABLE `$table`
ADD COLUMN `last_used` DATETIME NOT NULL AFTER `content`,
ADD COLUMN `creation_dtime` DATETIME NOT NULL AFTER `last_used`,
ADD COLUMN `ipaddress` VARCHAR(255) NOT NULL AFTER `creation_dtime`,
ADD INDEX `last_used` (`last_used`),
ADD INDEX `creation_dtime` (`creation_dtime`);
UPDATE indefero_idf_keys SET creation_dtime = '2016-04-30 03:19:54';
EOD;
$db = Pluf::db();
$engine = Pluf::f('db_engine');
$db->execute($sql[$engine]);
}
function IDF_Migrations_34GitSSHTracking_down()
{
$table = Pluf::factory('IDF_Key')->getSqlTable();
$sql = array();
$sql["MySQL"] = <<<EOD
ALTER TABLE `$table`
DROP COLUMN `last_used` DATETIME NOT NULL AFTER `content`,
DROP COLUMN `creation_dtime` DATETIME NOT NULL AFTER `last_used`,
DROP COLUMN `ipaddress` VARCHAR(255) NOT NULL AFTER `creation_dtime`,
DROP INDEX `last_used` (`last_used`),
DROP INDEX `creation_dtime` (`creation_dtime`);
EOD;
$db = Pluf::db();
$engine = Pluf::f('db_engine');
$db->execute($sql[$engine]);
}
indefero/src/IDF/Plugin/SyncGit/Cron.php
2929
3030
3131
32
32
3333
3434
3535
......
5656
5757
5858
59
59
6060
6161
6262
/**
* 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.
}
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;
indefero/src/IDF/Plugin/SyncGit/Serve.php
107107
108108
109109
110
111
110
111
112112
113113
114
114115
115116
116117
......
120121
121122
122123
124
125
126
127
128
129
123130
124131
125132
*/
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.');
$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());
}
indefero/src/IDF/templates/idf/user/myaccount.html
147147
148148
149149
150
151
152
153
154
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
155179
156180
157181
{if count($keys)}
<table summary=" " class="recent-issues">
<tr><th colspan="2">{trans 'Your Current Public Keys'}</th></tr>
{foreach $keys as $key}<tr><td>
<span class="mono">{$key.showCompact()}</span></td><td> <form class="star" method="post" action="{url 'IDF_Views_User::deleteKey', array($key.id)}"><input type="image" src="{media '/idf/img/trash.png'}" name="submit" value="{trans 'Delete this key'}" /></form>
</td>
</tr>{/foreach}
<tr>
<th colspan="5">{trans 'Your Current Public Keys'}</th>
</tr>
<tr>
<th>Key</th>
<th>Key Added</th>
<th>Key Last Used</th>
<th>Last IP</th>
<th>Delete</th>
</tr>
{foreach $keys as $key}
<tr>
<td>
<span class="mono">{$key.showCompact()}</span>
</td>
<td width="13%" style="text-align: center">
<span title="{$key.creation_dtime}">{$key.creation_dtime|date}</span>
</td>
<td width="16%">
<span title="{$key.last_used|date:"%Y-%m-%d %H:%M:%S"}">{$key.last_used|dateago}</span>
</td>
<td>
{$key.ipaddress}
</td>
<td>
<form class="star" method="post" action="{url 'IDF_Views_User::deleteKey', array($key.id)}"><input type="image" src="{media '/idf/img/trash.png'}" name="submit" value="{trans 'Delete this key'}" /></form>
</td>
</tr>
{/foreach}
</table>
{/if}
{if count($mailaddrs)>1}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.07508s using 20 queries.