line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBD::Sys::Plugin::Unix::Logins; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2764
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
90
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
118
|
|
5
|
3
|
|
|
3
|
|
15
|
use vars qw($VERSION @colNames); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
168
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
14
|
use base qw(DBD::Sys::Table); |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
1185
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION = "0.102"; |
10
|
|
|
|
|
|
|
@colNames = qw(username id line pid type host timestamp); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $haveSysUtmp; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=pod |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
DBD::Sys::Plugin::Unix::Logins - provides a table containing logged on users |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$logins = $dbh->selectall_hashref("select * from logins", "time"); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 ISA |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
DBD::Sys::Plugin::Unix::Logins; |
27
|
|
|
|
|
|
|
ISA DBD::Sys::Table |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This module provides the table I filled with the data from the utmp |
32
|
|
|
|
|
|
|
database C. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 COLUMNS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head3 username |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Username if this is a record for a user process. Some systems may return |
39
|
|
|
|
|
|
|
other information depending on the record type. If no user was set this |
40
|
|
|
|
|
|
|
entry is skipped. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head3 id |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
The identifier for this record - it might be the inittab tag or some other |
45
|
|
|
|
|
|
|
system dependent value. If the system lacks support for this field, it's |
46
|
|
|
|
|
|
|
a counted number. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head3 line |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
For user process records this will be the name of the terminalor line that |
51
|
|
|
|
|
|
|
the user is connected on. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head3 pid |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
The process ID of the process that created this record. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head3 type |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The type of the record. See L for details. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head3 host |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
On systems which support this the method will return the hostname of the |
64
|
|
|
|
|
|
|
host for which the process that created the record was started - for |
65
|
|
|
|
|
|
|
example for a telnet login. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head3 timestamp |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The time in epoch seconds which the record was created. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 METHODS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 get_table_name |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Returns 'logins'. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
4
|
|
|
4
|
1
|
14
|
sub get_table_name() { return 'logins'; } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 get_col_names |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Returns the column names of the table as named in L |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
0
|
1
|
0
|
sub get_col_names() { @colNames } |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 get_attributes |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Return the attributes supported by this module: |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head3 filename |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Allows to specify an alternate filename to use. It's unused per default |
96
|
|
|
|
|
|
|
and will use C<_PATH_UTMP>. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$dbh->{sys_logins_filename} = q(/var/log/wtmp); # last logings |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
4
|
|
|
4
|
1
|
13
|
sub get_attributes() { return qw(filename) } |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 get_primary_key |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns 'timestamp' - you must be very quick to login twice per second |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
0
|
1
|
|
sub get_primary_key() { return 'timestamp'; } |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 collect_data |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Retrieves the data from the utmp database and put it into fetchable rows. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub collect_data() |
119
|
|
|
|
|
|
|
{ |
120
|
0
|
|
|
0
|
1
|
|
my $self = $_[0]; |
121
|
0
|
|
|
|
|
|
my @data; |
122
|
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
|
unless ( defined($haveSysUtmp) ) |
124
|
|
|
|
|
|
|
{ |
125
|
0
|
|
|
|
|
|
$haveSysUtmp = 0; |
126
|
0
|
|
|
|
|
|
eval { |
127
|
0
|
|
|
|
|
|
require Sys::Utmp; |
128
|
0
|
|
|
|
|
|
$haveSysUtmp = 1; |
129
|
|
|
|
|
|
|
}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
if ($haveSysUtmp) |
133
|
|
|
|
|
|
|
{ |
134
|
0
|
|
|
|
|
|
my %params; |
135
|
0
|
0
|
|
|
|
|
$self->{meta}->{filename} and $params{Filename} = $self->{attrs}->{filename}; |
136
|
0
|
|
|
|
|
|
my $utmp = Sys::Utmp->new(%params); |
137
|
0
|
|
|
|
|
|
my $id = 0; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
while ( my $utent = $utmp->getutent() ) |
140
|
|
|
|
|
|
|
{ |
141
|
0
|
0
|
|
|
|
|
next unless $utent->ut_user; |
142
|
0
|
0
|
|
|
|
|
push( |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
143
|
|
|
|
|
|
|
@data, |
144
|
|
|
|
|
|
|
[ |
145
|
|
|
|
|
|
|
$utent->ut_user, $utent->ut_id eq "" ? $id++ : $utent->ut_id, |
146
|
|
|
|
|
|
|
$utent->ut_line, $utent->ut_pid == -1 ? undef : $utent->ut_pid, |
147
|
|
|
|
|
|
|
$utent->ut_type, $utent->ut_host eq "" ? undef : $utent->ut_host, |
148
|
|
|
|
|
|
|
$utent->ut_time |
149
|
|
|
|
|
|
|
] |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
$utmp->endutent; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
return \@data; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 PREREQUISITES |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
The module C is required to provide data for the table. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 AUTHOR |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Jens Rehsack |
166
|
|
|
|
|
|
|
CPAN ID: REHSACK |
167
|
|
|
|
|
|
|
rehsack@cpan.org |
168
|
|
|
|
|
|
|
http://www.rehsack.de/ |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 COPYRIGHT |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This program is free software; you can redistribute |
173
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
The full text of the license can be found in the |
176
|
|
|
|
|
|
|
LICENSE file included with this module. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SUPPORT |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Free support can be requested via regular CPAN bug-tracking system. There is |
181
|
|
|
|
|
|
|
no guaranteed reaction time or solution time, but it's always tried to give |
182
|
|
|
|
|
|
|
accept or reject a reported ticket within a week. It depends on business load. |
183
|
|
|
|
|
|
|
That doesn't mean that ticket via rt aren't handles as soon as possible, |
184
|
|
|
|
|
|
|
that means that soon depends on how much I have to do. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Business and commercial support should be acquired from the authors via |
187
|
|
|
|
|
|
|
preferred freelancer agencies. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |