Skip to content

Commit 31ad0c7

Browse files
jbm715MattLicense
jbm715
authored andcommitted
Added user's last login widget
1 parent 841e3e0 commit 31ad0c7

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,20 @@ <h3>
362362
</div><!-- /widget-content -->
363363
</div><!-- /widget -->
364364
</div><!-- /span6 -->
365+
<div class="span6">
366+
<div id="lastlog-widget" class="widget widget-table action-table">
367+
<div class="widget-header">
368+
<i class="icon-group"></i>
369+
<h3>
370+
Last Login
371+
</h3>
372+
<div id="refresh-lastlog" class="btn icon-refresh js-refresh-info"></div>
373+
</div><!-- /widget-header -->
374+
<div class="widget-content">
375+
<table id="lastlog_dashboard" class="table table-hover table-bordered table-condensed"></table>
376+
</div><!-- /widget-content -->
377+
</div><!-- /widget -->
378+
</div><!-- /span6 -->
365379
</div><!--./row -->
366380

367381
<div class="row">

js/dashboard.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,31 @@ dashboard.getOnline = function () {
213213
$("select[name='online_dashboard_length']").val("5");
214214
}
215215

216+
dashboard.getLastLog = function () {
217+
$.get("sh/lastlog.php", function (data) {
218+
destroy_dataTable("lastlog_dashboard");
219+
220+
$("#lastlog_dashboard").dataTable({
221+
aaData: data,
222+
aoColumns: [
223+
{ sTitle: "Who" },
224+
{ sTitle: "From" },
225+
{ sTitle: "Last Login" },
226+
],
227+
aaSorting: [
228+
[2, "desc"]
229+
],
230+
iDisplayLength: 5,
231+
bPaginate: true,
232+
sPaginationType: "full_numbers",
233+
bFilter: false,
234+
bAutoWidth: false,
235+
bInfo: false
236+
}).fadeIn();
237+
}, "json");
238+
$("select[name='lastlog_dashboard_length']").val("5");
239+
}
240+
216241
dashboard.getRam = function () {
217242
$.get("sh/mem.php", function (data) {
218243
var ram_total = data[1];
@@ -453,6 +478,7 @@ dashboard.fnMap = {
453478
os: dashboard.getOs,
454479
users: dashboard.getUsers,
455480
online: dashboard.getOnline,
481+
lastlog: dashboard.getLastLog,
456482
whereis: dashboard.getWhereIs,
457483
ip: dashboard.getIp,
458484
ispeed: dashboard.getIspeed,

sh/lastlog.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
exec(
4+
'/usr/bin/lastlog --time 365 |' .
5+
' /usr/bin/awk \'{print $1","$3","$4" "$5" "$6" "$7" "$8}\'',
6+
$users
7+
);
8+
$result = array();
9+
# ignore the first line of column names
10+
for ($i = 1; $i < count($users); ++$i) {
11+
$result[$i-1] = explode(",", $users[$i]);
12+
}
13+
14+
header('Content-Type: application/json; charset=UTF-8');
15+
echo json_encode($result);

0 commit comments

Comments
 (0)