DataTables for NetBIOS inventory report
This commit is contained in:
@@ -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 ) {
|
||||
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 };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/netbios_csv.tt',
|
||||
{ results => $rs, opt => $domain },
|
||||
{ results => \@results, opt => $domain },
|
||||
{ layout => undef };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
[% USE date(format = '%Y-%m-%d %H:%M') %]
|
||||
[% USE Number.Format %]
|
||||
[% 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>
|
||||
<tr>
|
||||
<th>Domain</th>
|
||||
@@ -12,34 +10,79 @@
|
||||
<th>Last Seen</th>
|
||||
</tr>
|
||||
</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>
|
||||
[% 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>
|
||||
<tr>
|
||||
<th>Domain</th>
|
||||
<th>Count</th>
|
||||
</tr>
|
||||
</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>
|
||||
[% 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>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[% IF opt %]
|
||||
[% CSV.dump(['Domain' 'Node' 'Name' 'User' 'First Seen' 'Last Seen']) %]
|
||||
|
||||
[% WHILE (row = results.next) %]
|
||||
[% FOREACH row IN results %]
|
||||
[% mylist = [] %]
|
||||
[% 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) ] %]
|
||||
@@ -15,7 +15,7 @@
|
||||
[% ELSE %]
|
||||
[% CSV.dump(['Domain' 'Count']) %]
|
||||
|
||||
[% WHILE (row = results.next) %]
|
||||
[% FOREACH row IN results %]
|
||||
[% mylist = [] %]
|
||||
[% domain = row.domain || '(Blank Domain)' %]
|
||||
[% FOREACH col IN [ domain row.count ] %]
|
||||
|
||||
Reference in New Issue
Block a user