From 4d49f04d2ac2b16b4888b5bdb85e3d48fd4aada9 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 16 Aug 2022 22:25:27 +0100 Subject: [PATCH] #875 Node Search - swap IP and DNS, add system name, highlight most recent, in the Switch Port rows --- lib/App/Netdisco/DB/Result/NodeIp.pm | 2 +- lib/App/Netdisco/Web/Plugin/Search/Node.pm | 4 +- share/views/ajax/search/node_by_ip.tt | 40 +++++++++--------- share/views/ajax/search/node_by_mac.tt | 47 ++++++++++++---------- 4 files changed, 50 insertions(+), 43 deletions(-) diff --git a/lib/App/Netdisco/DB/Result/NodeIp.pm b/lib/App/Netdisco/DB/Result/NodeIp.pm index 00878c23..5ab5aed0 100644 --- a/lib/App/Netdisco/DB/Result/NodeIp.pm +++ b/lib/App/Netdisco/DB/Result/NodeIp.pm @@ -92,7 +92,7 @@ See also the C helper routine, below. =cut __PACKAGE__->has_many( nodes => 'App::Netdisco::DB::Result::Node', - { 'foreign.mac' => 'self.mac' } ); + { 'foreign.mac' => 'self.mac' }, { order_by => { '-desc' => 'time_last' }} ); =head2 netbios diff --git a/lib/App/Netdisco/Web/Plugin/Search/Node.pm b/lib/App/Netdisco/Web/Plugin/Search/Node.pm index 30c2fda1..e8c5a707 100644 --- a/lib/App/Netdisco/Web/Plugin/Search/Node.pm +++ b/lib/App/Netdisco/Web/Plugin/Search/Node.pm @@ -182,7 +182,7 @@ get '/ajax/content/search/node' => require_login sub { my $rs_dp = schema('netdisco')->resultset('DevicePort'); if ($sightings->has_rows or $ips->has_rows or $netbios->has_rows) { my $ports = param('deviceports') - ? $rs_dp->search({ -and => [@where_mac] }) : undef; + ? $rs_dp->search({ -and => [@where_mac] }, { order_by => { '-desc' => 'creation' }}) : undef; return template 'ajax/search/node_by_mac.tt', { ips => $ips, @@ -194,7 +194,7 @@ get '/ajax/content/search/node' => require_login sub { } else { my $ports = param('deviceports') - ? $rs_dp->search({ -and => [@where_mac, @porttimes] }) : undef; + ? $rs_dp->search({ -and => [@where_mac, @porttimes] }, { order_by => { '-desc' => 'creation' }}) : undef; if (defined $ports and $ports->has_rows) { return template 'ajax/search/node_by_mac.tt', { diff --git a/share/views/ajax/search/node_by_ip.tt b/share/views/ajax/search/node_by_ip.tt index 3f2f6525..e610c9d6 100644 --- a/share/views/ajax/search/node_by_ip.tt +++ b/share/views/ajax/search/node_by_ip.tt @@ -16,12 +16,13 @@ [% WHILE (row = macs.next) %] [% IF row.nbname %] - MAC: + MAC [% row.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% row.oui.company | html_entity %] ) [% END %] + seen as: NetBIOS \\[% row.domain | html_entity %]\[% row.nbname | html_entity %] @@ -34,12 +35,13 @@ [% ELSE %] - MAC: + MAC [% row.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% row.oui.company | html_entity %] ) [% END %] + seen as: IP → MAC @@ -55,12 +57,13 @@ [% END %] [% FOREACH nbt IN row.netbios %] - MAC: + MAC [% nbt.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% nbt.oui.company | html_entity %] ) [% END %] + seen as: NetBIOS \\[% nbt.domain | html_entity %]\[% nbt.nbname | html_entity %] @@ -74,12 +77,13 @@ [% END %] [% FOREACH ni IN row.nodeips %] - MAC: + MAC [% ni.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% ni.oui.company | html_entity %] ) [% END %] + seen as: IP → MAC @@ -95,37 +99,36 @@ [% END %] [% FOREACH node IN row.node_sightings(archive_filter) %] - MAC: + MAC [% node.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% node.oui.company | html_entity %] ) [% END %] + seen as: - Switch Port + Node on Port - - [% node.switch | html_entity %] - [% node.port | html_entity %] - [% ' ' IF NOT node.active %] - [% IF node.device.dns AND node.device_port AND node.device_port.name %] - ([% node.device.dns | html_entity %] - [% node.device_port.name | html_entity %]) - [% END %] - on vlan [% node.vlan | html_entity %] + + [% node.device.dns || node.switch | html_entity %] - [% node.port | html_entity %] + [% ' ' IF NOT node.active %] + on vlan [% node.vlan | html_entity %] +
([% node.switch | html_entity %] - [% node.device.name | html_entity %] - "[% node.device_port.name | html_entity %]") [% IF params.stamps %] - [% node.time_first_stamp | html_entity %] - [% node.time_last_stamp | html_entity %] + [% node.time_first_stamp | html_entity %] + [% node.time_last_stamp | html_entity %] [% END %] [% FOREACH wlan IN node.wireless %] - MAC: + MAC [% wlan.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% wlan.oui.company | html_entity %] ) [% END %] + seen as: Wireless Info SSID: [% wlan.ssid | html_entity %]
@@ -143,12 +146,13 @@ [% END %] [% FOREACH nodeip IN row.ip_aliases(archive_filter) %] - MAC: + MAC [% nodeip.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% nodeip.oui.company | html_entity %] ) [% END %] + seen as: MAC → IP diff --git a/share/views/ajax/search/node_by_mac.tt b/share/views/ajax/search/node_by_mac.tt index d81d1d7a..434857c1 100644 --- a/share/views/ajax/search/node_by_mac.tt +++ b/share/views/ajax/search/node_by_mac.tt @@ -15,12 +15,13 @@ [% WHILE (row = ips.next) %] - MAC: + MAC [% row.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% row.oui.company | html_entity %] ) [% END %] + seen as: MAC → IP [% row.ip | html_entity %] @@ -34,62 +35,63 @@ [% END %] [% WHILE (node = sightings.next) %] + [% SET nodecount = nodecount + 1 %] - MAC: + MAC [% node.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% node.oui.company | html_entity %] ) [% END %] + seen as: - Switch Port + Node on Port - - [% node.switch | html_entity %] - [% node.port | html_entity %] - [% '  ' IF NOT node.active %] - [% IF node.device.dns AND node.device_port AND node.device_port.name %] - ([% node.device.dns | html_entity %] - [% node.device_port.name | html_entity %]) - [% END %] - on vlan [% node.vlan | html_entity %] + + [% node.device.dns || node.switch | html_entity %] - [% node.port | html_entity %] + [% '  ' IF NOT node.active %] + on vlan [% node.vlan | html_entity %] +
([% node.switch | html_entity %] - [% node.device.name | html_entity %] - "[% node.device_port.name | html_entity %]") [% IF params.stamps %] - [% node.time_first_stamp | html_entity %] - [% node.time_last_stamp | html_entity %] + [% node.time_first_stamp | html_entity %] + [% node.time_last_stamp | html_entity %] [% END %] [% END %] [% WHILE (port = ports.next) %] + [% SET portcount = portcount + 1 %] - MAC: [% port.net_mac.$mac_format_call | html_entity %] + MAC [% port.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% port.oui.company | html_entity %] ) [% END %] + seen as: - Switch Port + Device Port - [% port.ip | html_entity %] - [% port.descr | html_entity %] - [% IF port.device.dns AND port.name %] - ([% port.device.dns | html_entity %] - [% port.name | html_entity %]) - [% END %] + [% port.device.dns || port.ip | html_entity %] - [% port.descr | html_entity %] +
([% port.ip | html_entity %] - [% port.device.name | html_entity %] - "[% port.name | html_entity %]") [% IF params.stamps %] - [% port.creation | html_entity %] - [% port.creation | html_entity %] + [% port.creation.remove(':[0-9./]+$') | html_entity %] + [% port.creation.remove(':[0-9./]+$') | html_entity %] [% END %] [% END %] [% WHILE (nbt = netbios.next) %] - MAC: [% nbt.net_mac.$mac_format_call | html_entity %] + MAC [% nbt.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% nbt.oui.company | html_entity %] ) [% END %] + seen as: NetBIOS \\[% nbt.domain | html_entity %]\[% nbt.nbname | html_entity %] @@ -104,11 +106,12 @@ [% WHILE (wlan = wireless.next) %] - MAC: [% wlan.net_mac.$mac_format_call | html_entity %] + MAC [% wlan.net_mac.$mac_format_call | html_entity %] [% IF params.show_vendor %] ( [% wlan.oui.company | html_entity %] ) [% END %] + seen as: Wireless Info SSID: [% wlan.ssid | html_entity %]