Add the public IP information to the WebUI #2105

This commit is contained in:
nicolargo
2022-08-13 13:04:34 +02:00
parent ed5254d2a0
commit 2ee2ffbd24
5 changed files with 29 additions and 16 deletions

View File

@@ -25,5 +25,6 @@ export default function GlancesPluginIpController($scope, GlancesStats, ARGUMENT
vm.mask = ipStats.mask;
vm.maskCidr = ipStats.mask_cidr;
vm.publicAddress = ipStats.public_address
vm.publicInfo = ipStats.public_info_human
}
}

View File

@@ -1,4 +1,8 @@
<section id="ip" ng-if="vm.address != undefined && !vm.arguments.disable_ip">
&nbsp;-&nbsp;<span class="title">IP</span>&nbsp;<span>{{ vm.address }}/{{ vm.maskCidr }}</span>&nbsp;<span
ng-if="vm.publicAddress" class="title">Pub</span>&nbsp;<span>{{ vm.publicAddress }}</span>
-
<span ng-if="vm.address != undefined" class="title">IP</span>
<spanng-if="vm.address != undefined">{{ vm.address }}/{{ vm.maskCidr }}</span>
<span ng-if="vm.publicAddress" class="title">Pub</span>
<span ng-if="vm.publicAddress">{{ vm.publicAddress }}</span>
<span ng-if="vm.publicInfo">({{ vm.publicInfo }})</span>
</section>

View File

Binary file not shown.

View File

Binary file not shown.

View File

@@ -128,6 +128,7 @@ class Plugin(GlancesPlugin):
else:
stats['public_address'] = self.public_address
stats['public_info'] = self.public_info
stats['public_info_human'] = self.public_info_for_human(stats['public_info'])
elif self.input_method == 'snmp':
# Not implemented yet
@@ -174,23 +175,30 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg, 'TITLE', optional=True))
ret.append(self.curse_add_line(msg_pub, optional=True))
if 'public_info' in self.stats and self.stats['public_info']:
field_result = []
for f in self.censys_fields:
field = f.split(':')
if len(field) == 1 and field[0] in self.stats['public_info']:
field_result.append('{}'.format(self.stats['public_info'][field[0]]))
elif (
len(field) == 2
and field[0] in self.stats['public_info']
and field[1] in self.stats['public_info'][field[0]]
):
field_result.append('{}'.format(self.stats['public_info'][field[0]][field[1]]))
ret.append(self.curse_add_line(' ', optional=True))
ret.append(self.curse_add_line('/'.join(field_result), optional=True))
if self.stats['public_info_human']:
ret.append(self.curse_add_line(' {}'.format(self.stats['public_info_human']),
optional=True))
return ret
def public_info_for_human(self, public_info):
"""Return the data to pack to the client."""
if not public_info:
return ''
field_result = []
for f in self.censys_fields:
field = f.split(':')
if len(field) == 1 and field[0] in public_info:
field_result.append('{}'.format(public_info[field[0]]))
elif (
len(field) == 2
and field[0] in public_info
and field[1] in public_info[field[0]]
):
field_result.append('{}'.format(public_info[field[0]][field[1]]))
return '/'.join(field_result)
@staticmethod
def ip_to_cidr(ip):
"""Convert IP address to CIDR.