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
|
# File 'lib/kanrisuru/core/system/parsers/last.rb', line 9
def parse(command, opts)
lines = command.to_a
mapping = {}
lines.each do |line|
next if Kanrisuru::Util.blank?(line)
next if line.include?('wtmp') || line.include?('btmp')
line = line.gsub(' still logged in', '- still logged in') if line.include?('still logged in')
values = line.split(/\s{2,}/, 4)
user = values[0]
tty = values[1]
ip = IPAddr.new(values[2])
date_range = values[3]
login, logout = date_range.split(' - ')
login = parse_last_date(login) if login
logout = parse_last_date(logout) if logout
detail = Kanrisuru::Core::System::SessionDetail.new
detail.tty = tty
detail.ip_address = ip
detail.login_at = login
detail.logout_at = logout
detail.success = !Kanrisuru::Util.present?(opts[:failed_attemps])
mapping[user] = Kanrisuru::Core::System::LoginUser.new(user, []) unless mapping.key?(user)
mapping[user].sessions << detail
end
mapping.values
end
|