DataTables for NetBIOS inventory report

This commit is contained in:
Eric A. Miller
2014-05-28 23:44:33 -04:00
parent fa1f928c09
commit cff24e4834
3 changed files with 75 additions and 29 deletions

View File

@@ -58,16 +58,19 @@ get '/ajax/content/report/netbios' => require_login sub {
} }
return unless $rs->has_rows; my @results = $rs->all;
return unless scalar @results;
if ( request->is_ajax ) { if ( request->is_ajax ) {
template 'ajax/report/netbios.tt', { results => $rs, opt => $domain }, my $json = to_json( \@results );
template 'ajax/report/netbios.tt',
{ results => $json, opt => $domain },
{ layout => undef }; { layout => undef };
} }
else { else {
header( 'Content-Type' => 'text/comma-separated-values' ); header( 'Content-Type' => 'text/comma-separated-values' );
template 'ajax/report/netbios_csv.tt', template 'ajax/report/netbios_csv.tt',
{ results => $rs, opt => $domain }, { results => \@results, opt => $domain },
{ layout => undef }; { layout => undef };
} }
}; };

View File

@@ -1,7 +1,5 @@
[% USE date(format = '%Y-%m-%d %H:%M') %]
[% USE Number.Format %]
[% IF opt %] [% IF opt %]
<table class="table table-bordered table-condensed table-striped nd_floatinghead"> <table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
<thead> <thead>
<tr> <tr>
<th>Domain</th> <th>Domain</th>
@@ -12,34 +10,79 @@
<th>Last Seen</th> <th>Last Seen</th>
</tr> </tr>
</thead> </thead>
</tbody>
[% WHILE (row = results.next) %]
<tr>
<td>[% row.domain | html_entity %]</td>
<td><a href="[% search_node %]&q=[% row.mac | uri %]">[% row.mac.upper | html_entity %]</td>
<td>[% IF row.domain %]\\[% row.domain | html_entity %]\[% END %]<a href="[% search_node %]&q=[% row.nbname | uri %]">[% row.nbname | html_entity %]</a></td>
<td>[% row.nbuser || '[No User]' | html_entity %]@<a href="[% search_node %]&q=[% row.ip | uri %]">[% row.ip | html_entity %]</a></td>
<td>[% date.format(row.time_first) | html_entity %]</td>
<td>[% date.format(row.time_last) | html_entity %]</td>
</tr>
[% END %]
</tbody>
</table> </table>
[% ELSE %] [% ELSE %]
<table class="table table-bordered table-condensed table-striped nd_floatinghead"> <table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
<thead> <thead>
<tr> <tr>
<th>Domain</th> <th>Domain</th>
<th>Count</th> <th>Count</th>
</tr> </tr>
</thead> </thead>
</tbody>
[% WHILE (row = results.next) %]
<tr>
<td class="nd_linkcell"><a href="[% uri_for('/report/netbios') %]?domain=[% row.domain || 'blank' | uri %]">[% row.domain || '(Blank Domain)' | html_entity %]</a></td>
<td>[% row.count | format_number %]</td>
</tr>
[% END %]
</tbody>
</table> </table>
[% END %] [% END %]
<script type="text/javascript">
$(document).ready(function() {
var table = $('#data-table').dataTable({
"deferRender": true,
"data": [% results %],
[% IF opt %]
"columns": [
{
"data": 'domain',
"render": function(data, type, row, meta) {
return he.encode(data || '(Blank Domain)');
}
}, {
"data": 'mac',
"render": function(data, type, row, meta) {
return '<a href="[% search_node %]&q=' + encodeURIComponent(data) + '">' + he.encode(data.toUpperCase()) + '</a>';
}
}, {
"data": 'nbname',
"render": function(data, type, row, meta) {
var prefix = '';
if (row.domain) {
prefix = '\\\\' + row.domain + '\\';
}
return he.encode(prefix) + '<a href="[% search_node %]&q=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>';
}
}, {
"data": 'nbuser',
"render": function(data, type, row, meta) {
return he.encode(row.nbuser || '[No User]');
}
}, {
"data": 'time_first',
"render": function(data, type, row, meta) {
return moment(data).format('YYYY-MM-DD HH:mm');
}
}, {
"data": 'time_last',
"render": function(data, type, row, meta) {
return moment(data).format('YYYY-MM-DD HH:mm');
}
}
],
"order": [[0, "asc"], [5, "desc"]]
[% ELSE %]
"columns": [
{
"data": 'domain',
"render": function(data, type, full, meta) {
return '<a href="[% uri_for('/report/netbios') %]?domain=' + encodeURIComponent(data || 'blank') + '">' + he.encode(data || '(Blank Domain)') + '</a>';
}
}, {
"data": 'count',
"render": function(data, type, full, meta) {
return data.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
],
"order": [[1, "desc"]]
[% END %]
});
});
</script>

View File

@@ -3,7 +3,7 @@
[% IF opt %] [% IF opt %]
[% CSV.dump(['Domain' 'Node' 'Name' 'User' 'First Seen' 'Last Seen']) %] [% CSV.dump(['Domain' 'Node' 'Name' 'User' 'First Seen' 'Last Seen']) %]
[% WHILE (row = results.next) %] [% FOREACH row IN results %]
[% mylist = [] %] [% mylist = [] %]
[% device = row.device.dns || row.device.name || row.device.ip %] [% device = row.device.dns || row.device.name || row.device.ip %]
[% FOREACH col IN [ row.domain row.mac.upper row.nbname row.nbuser date.format(row.time_first) date.format(row.time_last) ] %] [% FOREACH col IN [ row.domain row.mac.upper row.nbname row.nbuser date.format(row.time_first) date.format(row.time_last) ] %]
@@ -15,7 +15,7 @@
[% ELSE %] [% ELSE %]
[% CSV.dump(['Domain' 'Count']) %] [% CSV.dump(['Domain' 'Count']) %]
[% WHILE (row = results.next) %] [% FOREACH row IN results %]
[% mylist = [] %] [% mylist = [] %]
[% domain = row.domain || '(Blank Domain)' %] [% domain = row.domain || '(Blank Domain)' %]
[% FOREACH col IN [ domain row.count ] %] [% FOREACH col IN [ domain row.count ] %]