| 1 | package DBD::Sys::Plugin::Unix::Logins; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 4 | ▶ | use vars qw($VERSION @colNames); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 4 | ▶ | use base qw(DBD::Sys::Table); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | 4 | $VERSION = "0.102"; | |||||||||||||||||
| 10 | 4 | @colNames = qw(username id line pid type host timestamp); | |||||||||||||||||
| 11 | |||||||||||||||||||
| 12 | 4 | 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<logins> filled with the data from the utmp | ||||||||||||||||||
| 32 | database C<utmp(5)>. | ||||||||||||||||||
| 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<Sys::Utmp::Utent> 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 | ▶ | sub get_table_name() { return 'logins'; } | ||||||||||||||||
|
Subroutine
get_table_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 80 | |||||||||||||||||||
| 81 | =head2 get_col_names | ||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | Returns the column names of the table as named in L</Columns> | ||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | =cut | ||||||||||||||||||
| 86 | |||||||||||||||||||
| 87 | 0 | ▶ | sub get_col_names() { @colNames } | ||||||||||||||||
|
Subroutine
get_col_names: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 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 | ▶ | sub get_attributes() { return qw(filename) } | ||||||||||||||||
|
Subroutine
get_attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 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 | ▶ | sub get_primary_key() { return 'timestamp'; } | ||||||||||||||||
|
Subroutine
get_primary_key: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||
|
Subroutine
collect_data: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||
| 120 | 0 | my $self = $_[0]; | |||||||||||||||||
| 121 | 0 | my @data; | |||||||||||||||||
| 122 | |||||||||||||||||||
| 123 | 0 | ▶ | unless ( defined($haveSysUtmp) ) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 124 | { | ||||||||||||||||||
| 125 | 0 | $haveSysUtmp = 0; | |||||||||||||||||
| 126 | 0 | eval { | |||||||||||||||||
| 127 | 0 | require Sys::Utmp; | |||||||||||||||||
| 128 | 0 | $haveSysUtmp = 1; | |||||||||||||||||
| 129 | }; | ||||||||||||||||||
| 130 | } | ||||||||||||||||||
| 131 | |||||||||||||||||||
| 132 | 0 | ▶ | if ($haveSysUtmp) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 133 | { | ||||||||||||||||||
| 134 | 0 | my %params; | |||||||||||||||||
| 135 | 0 | ▶ | $self->{meta}->{filename} and $params{Filename} = $self->{attrs}->{filename}; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 136 | 0 | my $utmp = Sys::Utmp->new(%params); | |||||||||||||||||
| 137 | 0 | my $id = 0; | |||||||||||||||||
| 138 | |||||||||||||||||||
| 139 | 0 | ▶ | while ( my $utent = $utmp->getutent() ) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 140 | { | ||||||||||||||||||
| 141 | 0 | ▶ | next unless $utent->ut_user; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 142 | 0 | ▶ | push( | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 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<Sys::Utmp> 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 | 4 | 1; | |||||||||||||||||