From ac546356283552201f05d0375acdc03ff482e671 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 11 Nov 2023 22:05:02 +0000 Subject: [PATCH] #1118 user configurable external links from node search and device details * frontend example * process config with template macro * shared external links template for mac and IP search * default into product config * add support for device external links * better presentation of IP links and change color to grey --- share/config.yml | 4 ++++ share/public/css/netdisco.css | 3 ++- share/views/ajax/device/details.tt | 4 +++- share/views/ajax/search/node_by_ip.tt | 9 +++++++++ share/views/ajax/search/node_by_mac.tt | 7 +++++++ share/views/externallinks.tt | 26 ++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 share/views/externallinks.tt diff --git a/share/config.yml b/share/config.yml index 508403b6..f81406e5 100644 --- a/share/config.yml +++ b/share/config.yml @@ -278,6 +278,10 @@ defanged_api_admin: 'api_admin' hide_deviceports: 'group:__ANY__': - 'group:__HIDE_NOTPRESENT_TYPES__' +external_links: + node: [] + device: [] + device_port: [] # ------------- # NETDISCO CORE diff --git a/share/public/css/netdisco.css b/share/public/css/netdisco.css index 7ad931bc..1acfda55 100644 --- a/share/public/css/netdisco.css +++ b/share/public/css/netdisco.css @@ -357,7 +357,8 @@ td > form.nd_inline-form { } /* for the tagged vlans total when hiding the full list */ -.nd_vlan-total { +/* and external links from node search */ +.nd_vlan-total, .nd_node-ext-link { float: right; } diff --git a/share/views/ajax/device/details.tt b/share/views/ajax/device/details.tt index 4c61a2af..836e845a 100644 --- a/share/views/ajax/device/details.tt +++ b/share/views/ajax/device/details.tt @@ -1,3 +1,4 @@ +[% PROCESS 'externallinks.tt' -%] [% SET user_can_port_control = user_has_role('port_control', d) %] @@ -115,7 +116,7 @@ [% END %] [% END %] - + diff --git a/share/views/ajax/search/node_by_ip.tt b/share/views/ajax/search/node_by_ip.tt index e610c9d6..09401951 100644 --- a/share/views/ajax/search/node_by_ip.tt +++ b/share/views/ajax/search/node_by_ip.tt @@ -1,5 +1,6 @@ [% USE date(format = '%Y-%m-%d %H:%M') %] [% USE Number.Format %] +[% PROCESS 'externallinks.tt' -%]
AdministrationExternal Links SSH @@ -123,6 +124,7 @@ Telnet Web + [% INCLUDE external_device_links item = d %]
@@ -23,6 +24,7 @@ [% row.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = row %] [% IF params.stamps %] diff --git a/share/views/ajax/search/node_by_mac.tt b/share/views/ajax/search/node_by_mac.tt index 11179653..befd95ff 100644 --- a/share/views/ajax/search/node_by_mac.tt +++ b/share/views/ajax/search/node_by_mac.tt @@ -1,4 +1,5 @@ [% USE Number.Format %] +[% PROCESS 'externallinks.tt' -%]
NetBIOS \\[% row.domain | html_entity %]\[% row.nbname | html_entity %] @@ -42,6 +44,7 @@ [% row.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = row %] IP → MAC @@ -64,6 +67,7 @@ [% nbt.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = nbt %] NetBIOS \\[% nbt.domain | html_entity %]\[% nbt.nbname | html_entity %] @@ -84,6 +88,7 @@ [% ni.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = ni %] IP → MAC @@ -106,6 +111,7 @@ [% node.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = node %] Node on Port @@ -129,6 +135,7 @@ [% wlan.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = wlan %] Wireless Info SSID: [% wlan.ssid | html_entity %]
@@ -153,12 +160,14 @@ [% nodeip.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = nodeip %]
MAC → IP [% nodeip.ip | html_entity %] [% '  ' IF NOT nodeip.active %] [% ' (' _ nodeip.dns.remove(settings.domain_suffix) _ ')' IF nodeip.dns %] +
[% INCLUDE external_ip_links item = nodeip %]
[% nodeip.time_first_stamp | html_entity %]
@@ -22,11 +23,13 @@ [% row.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = row %] [% IF params.stamps %] @@ -46,6 +49,7 @@ [% node.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = node %]
MAC → IP [% row.ip | html_entity %] [% '  ' IF NOT row.active %] [% ' (' _ row.dns.remove(settings.domain_suffix) _ ')' IF row.dns %] +
[% INCLUDE external_ip_links item = row %]
[% row.time_first_stamp | html_entity %] Node on Port @@ -72,6 +76,7 @@ [% port.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = port %] Device Port @@ -94,6 +99,7 @@ [% nbt.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = nbt %] NetBIOS \\[% nbt.domain | html_entity %]\[% nbt.nbname | html_entity %] @@ -114,6 +120,7 @@ [% wlan.oui.company | html_entity %] ) [% END %] seen as: + [% INCLUDE external_mac_links item = wlan %] Wireless Info SSID: [% wlan.ssid | html_entity %]
diff --git a/share/views/externallinks.tt b/share/views/externallinks.tt new file mode 100644 index 00000000..c2fc3205 --- /dev/null +++ b/share/views/externallinks.tt @@ -0,0 +1,26 @@ +[% BLOCK external_link %] + + [% link.displayname | html_entity %] +[% END %] +[% BLOCK external_mac_links %] + [% FOREACH link IN settings.external_links.node.reverse %] + [% NEXT UNLESS link.for_mac %] + [% mac_format = 'as_' _ (link.mac_format.lower || 'ieee') %] + [% node = item.net_mac.$mac_format FILTER uri %] + [% PROCESS external_link %] +   + [% END %] +[% END %] +[% BLOCK external_ip_links %] + [% FOREACH link IN settings.external_links.node.reverse %] + [% NEXT UNLESS link.for_ip %] + [% node = item.ip FILTER uri %] + [% PROCESS external_link %] + [% END %] +[% END %] +[% BLOCK external_device_links %] + [% FOREACH link IN settings.external_links.device.reverse %] + [% device = item.ip FILTER uri %] + [% PROCESS external_link %] + [% END %] +[% END %]