rfe: Added logged in time to Login History
This commit is contained in:
parent
6e04c4b705
commit
46a6d404bf
7 changed files with 145 additions and 37 deletions
|
|
@ -55,6 +55,7 @@
|
|||
- rfe: After committing a version there is now a back to site link
|
||||
- rfe: Added sort order to Folder assets
|
||||
- rfe: Added canEdit and canAddFile template vars to Folder assets
|
||||
- rfe: Add logged-in time to Login History
|
||||
|
||||
7.5.22
|
||||
- fixed: Layout template now gets prepared correctly
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ addUrlToAssetHistory ( $session ); ##This sub MUST GO FIRST
|
|||
removeDoNothingOnDelete( $session );
|
||||
fixIsPublicOnTemplates ( $session );
|
||||
addSortOrderToFolder( $session );
|
||||
addLoginTimeStats( $session );
|
||||
addEMSBadgeTemplate ( $session );
|
||||
redirectChoice ($session);
|
||||
|
||||
|
|
@ -68,6 +69,15 @@ sub addSortOrderToFolder {
|
|||
print "Done.\n" unless $quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub addLoginTimeStats {
|
||||
my $session = shift;
|
||||
print "\tAdding login time statistics... " unless $quiet;
|
||||
$session->db->write( "alter table userLoginLog add column sessionId varchar(22)" );
|
||||
$session->db->write( "alter table userLoginLog add column lastPageViewed int(11)" );
|
||||
print "Done.\n" unless $quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub removeDoNothingOnDelete {
|
||||
my $session = shift;
|
||||
|
|
|
|||
|
|
@ -102,13 +102,18 @@ sub _isValidUsername {
|
|||
#-------------------------------------------------------------------
|
||||
sub _logLogin {
|
||||
my $self = shift;
|
||||
$self->session->db->write("insert into userLoginLog values (?,?,?,?,?)",
|
||||
[ $_[0],
|
||||
$_[1],
|
||||
$self->session->datetime->time(),
|
||||
$self->session->env->getIp,
|
||||
$self->session->env->get("HTTP_USER_AGENT") ]
|
||||
);
|
||||
$self->timeRecordSession;
|
||||
$self->session->db->write("insert into userLoginLog values (?,?,?,?,?,?,?)",
|
||||
[
|
||||
$_[0],
|
||||
$_[1],
|
||||
$self->session->datetime->time(),
|
||||
$self->session->env->getIp,
|
||||
$self->session->env->get("HTTP_USER_AGENT"),
|
||||
$self->session->getId,
|
||||
$self->session->datetime->time(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -911,6 +916,32 @@ sub showMessageOnLogin {
|
|||
return $output;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 timeRecordSession
|
||||
|
||||
Record the last page viewed and the time viewed for the user
|
||||
|
||||
=cut
|
||||
|
||||
sub timeRecordSession {
|
||||
my $self = shift;
|
||||
my ($nonTimeRecordedRows) = $self->session->db->quickArray("select count(*) from userLoginLog where lastPageViewed = timeStamp and sessionId = ? ", [$self->session->getId] );
|
||||
if ($nonTimeRecordedRows eq "1") {
|
||||
# We would normally expect to only find one entry
|
||||
$self->session->db->write("update userLoginLog set lastPageViewed = (select lastPageView from userSession where sessionId = ?) where lastPageViewed = timeStamp and sessionId = ? ",
|
||||
[ $self->session->getId,
|
||||
$self->session->getId]);
|
||||
} elsif ($nonTimeRecordedRows eq "0") {
|
||||
# Do nothing
|
||||
} else {
|
||||
# If something strange happened and we ended up with > 1 matching rows, cut our losses and remove offending userLoginLog rows (otherwise we
|
||||
# could end up with ridiculously long user recorded times)
|
||||
$self->session->errorHandler->warn("More than 1 old userLoginLog rows found, removing offending rows");
|
||||
$self->session->db->write("delete from userLoginLog where lastPageViewed = timeStamp and sessionId = ? ", [$self->session->getId] );
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 user ( [user] )
|
||||
|
|
|
|||
|
|
@ -61,7 +61,21 @@ sub www_viewLoginHistory {
|
|||
$row[$i] .= '<td>'.$data{status}.'</td>';
|
||||
$row[$i] .= '<td>'.$session->datetime->epochToHuman($data{timeStamp},"%H:%n%p %M/%D/%y").'</td>';
|
||||
$row[$i] .= '<td>'.$data{ipAddress}.'</td>';
|
||||
$row[$i] .= '<td>'.$data{userAgent}.'</td></tr>';
|
||||
$row[$i] .= '<td>'.$data{userAgent}.'</td>';
|
||||
$row[$i] .= '<td>'.$data{sessionId}.'</td>';
|
||||
if ($data{lastPageViewed}) {
|
||||
if ($data{lastPageViewed} == $data{timeStamp}) {
|
||||
$row[$i] .= "<td>Active</td>";
|
||||
$row[$i] .= "<td>Active</td></tr>";
|
||||
} else {
|
||||
$row[$i] .= '<td>'.$session->datetime->epochToHuman($data{lastPageViewed},"%H:%n%p %M/%D/%y").'</td>';
|
||||
my ($interval, $units) = $session->datetime->secondsToInterval($data{lastPageViewed} - $data{timeStamp});
|
||||
$row[$i] .= "<td>$interval $units</td></tr>";
|
||||
}
|
||||
} else {
|
||||
$row[$i] .= "<td></td>";
|
||||
$row[$i] .= "<td></td></tr>";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
|
|
@ -72,7 +86,10 @@ sub www_viewLoginHistory {
|
|||
$output .= '<td>'.$i18n->get(434).'</td>';
|
||||
$output .= '<td>'.$i18n->get(429).'</td>';
|
||||
$output .= '<td>'.$i18n->get(431).'</td>';
|
||||
$output .= '<td>'.$i18n->get(433).'</td></tr>';
|
||||
$output .= '<td>'.$i18n->get(433).'</td>';
|
||||
$output .= '<td>' . $i18n->get( 435 ) . '</td>';
|
||||
$output .= '<td>' . $i18n->get( 430 ) . '</td>';
|
||||
$output .= '<td>' . $i18n->get( "session length" ) . '</td></tr>';
|
||||
$output .= $p->getPage($session->form->process("pn"));
|
||||
$output .= '</table>';
|
||||
$output .= $p->getBar($session->form->process("pn"));
|
||||
|
|
|
|||
|
|
@ -663,33 +663,54 @@ sub www_listUsers {
|
|||
<td class="tableHeader">'.$i18n->get(454).'</td>
|
||||
<td class="tableHeader">'.$i18n->get(429).'</td>
|
||||
<td class="tableHeader">'.$i18n->get(434).'</td>
|
||||
<td class="tableHeader">'.$i18n->get(430).'</td>
|
||||
<td class="tableHeader">'.$i18n->get( "time recorded" ).'</td>
|
||||
</tr>';
|
||||
my $p = doUserSearch($session,"listUsers",1);
|
||||
foreach my $data (@{$p->getPageData}) {
|
||||
$output .= '<tr class="tableData">';
|
||||
$output .= '<td>'.$status{$data->{status}}.'</td>';
|
||||
$output .= '<td><a href="'.$session->url->page('op=editUser;uid='.$data->{userId})
|
||||
.'">'.$data->{username}.'</a></td>';
|
||||
$output .= '<td class="tableData">'.$data->{email}.'</td>';
|
||||
$output .= '<td class="tableData">'.$session->datetime->epochToHuman($data->{dateCreated},"%z").'</td>';
|
||||
$output .= '<td class="tableData">'.$session->datetime->epochToHuman($data->{lastUpdated},"%z").'</td>';
|
||||
my ($lastLoginStatus, $lastLogin) = $session->db->quickArray("select status,timeStamp from userLoginLog where
|
||||
userId=".$session->db->quote($data->{userId})." order by timeStamp DESC");
|
||||
if ($lastLogin) {
|
||||
$output .= '<td class="tableData">'.$session->datetime->epochToHuman($lastLogin).'</td>';
|
||||
} else {
|
||||
$output .= '<td class="tableData"> - </td>';
|
||||
}
|
||||
if ($lastLoginStatus) {
|
||||
$output .= '<td class="tableData">'.$lastLoginStatus.'</td>';
|
||||
} else {
|
||||
$output .= '<td class="tableData"> - </td>';
|
||||
}
|
||||
$output .= '</tr>';
|
||||
$output .= '<tr class="tableData">';
|
||||
$output .= '<td>'.$status{$data->{status}}.'</td>';
|
||||
$output .= '<td><a href="'.$session->url->page('op=editUser;uid='.$data->{userId})
|
||||
.'">'.$data->{username}.'</a></td>';
|
||||
$output .= '<td class="tableData">'.$data->{email}.'</td>';
|
||||
$output .= '<td class="tableData">'.$session->datetime->epochToHuman($data->{dateCreated},"%z").'</td>';
|
||||
$output .= '<td class="tableData">'.$session->datetime->epochToHuman($data->{lastUpdated},"%z").'</td>';
|
||||
# Total Time Recorded is computed from userLoginLog table
|
||||
my ($totalTimeRecorded)= $session->db->quickArray("select sum(lastPageViewed-timeStamp) from userLoginLog where userId = ?", [$data->{userId}]);
|
||||
my ($lastLoginStatus, $lastLogin, $lastPageView)
|
||||
= $session->db->quickArray(
|
||||
"select ull.status, ull.timeStamp, us.lastPageView
|
||||
from userLoginLog ull, userSession us
|
||||
where ull.sessionId = us.sessionId and ull.lastPageViewed != ull.timeStamp and
|
||||
ull.userId=".$session->db->quote($data->{userId})."
|
||||
order by ull.timeStamp DESC"
|
||||
);
|
||||
if ($lastLogin) {
|
||||
$output .= '<td class="tableData">'.$session->datetime->epochToHuman($lastLogin).'</td>';
|
||||
}
|
||||
else {
|
||||
$output .= '<td class="tableData"> - </td>';
|
||||
}
|
||||
if ($lastLoginStatus) {
|
||||
$output .= '<td class="tableData">'.$lastLoginStatus.'</td>';
|
||||
}
|
||||
else {
|
||||
$output .= '<td class="tableData"> - </td>';
|
||||
}
|
||||
if ($lastPageView) {
|
||||
$output .= '<td class="tableData"> '.$session->datetime->epochToHuman($lastPageView).'</td>';
|
||||
my ($interval, $units) = $session->datetime->secondsToInterval($totalTimeRecorded);
|
||||
$output .= "<td class='tableData'>$interval $units</td></tr>";
|
||||
}
|
||||
else {
|
||||
$output .= "<td class='tableData'> - </td>";
|
||||
$output .= "<td class='tableData'> - </td></tr>";
|
||||
}
|
||||
$output .= '</tr>';
|
||||
}
|
||||
$output .= '</table>';
|
||||
$p->setAlphabeticalKey('username');
|
||||
$output .= $p->getBarTraditional;
|
||||
$output .= '</table>';
|
||||
$p->setAlphabeticalKey('username');
|
||||
$output .= $p->getBarTraditional;
|
||||
my $submenu = _submenu(
|
||||
$session,
|
||||
{ workarea => $output, }
|
||||
|
|
|
|||
|
|
@ -68,21 +68,37 @@ See WebGUI::Workflow::Activity::execute() for details.
|
|||
|
||||
sub execute {
|
||||
my $self = shift;
|
||||
my $sth = $self->session->db->read("select sessionId from userSession where expires<?",[time()]);
|
||||
my $sth = $self->session->db->read("select sessionId, lastPageView from userSession where expires<?",[time()]);
|
||||
my $time = time();
|
||||
my $ttl = $self->getTTL;
|
||||
while (my ($sessionId) = $sth->array) {
|
||||
|
||||
while ( my ( $sessionId, $lastPageView ) = $sth->array ) {
|
||||
# timeRecordSessions
|
||||
my ($nonTimeRecordedRows) = $self->session->db->quickArray("select count(*) from userLoginLog where lastPageViewed = timeStamp and sessionId = ? ", [$sessionId] );
|
||||
if ($nonTimeRecordedRows eq "1") {
|
||||
# We would normally expect to only find one entry
|
||||
$self->session->db->write("update userLoginLog set lastPageViewed = ? where lastPageViewed = timeStamp and sessionId = ? ",
|
||||
[ $lastPageView, $sessionId ]);
|
||||
} elsif ($nonTimeRecordedRows eq "0") {
|
||||
# Do nothing
|
||||
} else {
|
||||
# If something strange happened and we ended up with > 1 matching rows, cut our losses and remove offending userLoginLog rows (otherwise we
|
||||
# could end up with ridiculously long user recorded times)
|
||||
$self->session->errorHandler->warn("More than 1 old userLoginLog rows found, removing offending rows");
|
||||
$self->session->db->write("delete from userLoginLog where lastPageViewed = timeStamp and sessionId = ? ", [$sessionId] );
|
||||
}
|
||||
my $session = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename, undef, undef, $sessionId, 1);
|
||||
if (defined $session) {
|
||||
$session->var->end;
|
||||
$session->close;
|
||||
}
|
||||
if ((time() - $time) > $ttl) {
|
||||
$sth->finish;
|
||||
$sth->finish;
|
||||
return $self->WAITING;
|
||||
}
|
||||
}
|
||||
return $self->COMPLETE;
|
||||
}
|
||||
|
||||
return $self->COMPLETE;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4129,6 +4129,18 @@ LongTruncOk=1</p>
|
|||
context => q{Title of the template created by the Site Setup screen},
|
||||
},
|
||||
|
||||
'session length' => {
|
||||
message => q{Session Length},
|
||||
lastUpdated => 0,
|
||||
context => q{The length the session has been alive},
|
||||
},
|
||||
|
||||
"time recorded" => {
|
||||
message => q{Time Recorded (excludes active sessions)},
|
||||
lastUpdated => 0,
|
||||
context => q{Column heading for the total logged in time for the user},
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue