From 6b05989498e93fc3ed63b827b31ae1cd123736ad Mon Sep 17 00:00:00 2001 From: D9ping Date: Tue, 23 Oct 2018 11:57:55 +0200 Subject: [PATCH] Showing multiple IPv4/IPv6 addresses. Signed-off-by: D9ping --- includes/dashboard.php | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index d94416c1..2469f017 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -26,14 +26,36 @@ function DisplayDashboard(){ preg_match('/link\/ether ([0-9a-f:]+)/i', $stdoutIpWRepeatedSpaces, $matchesMacAddr ) || $matchesMacAddr[1] = _('No MAC Address Found'); $macAddr = $matchesMacAddr[1]; - preg_match('/inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/(([0-3][0-9]))/i', $stdoutIpWRepeatedSpaces, $matchesIpv4AddrAndSubnet) || $matchesIpv4Addr[1] = _('No IPv4 Address Found'); - $ipv4Addr = $matchesIpv4AddrAndSubnet[1]; - $ipv4Netmask = long2ip(-1 << (32 -(int)$matchesIpv4AddrAndSubnet[2])); - // TODO multiple ipv4 addresses + $ipv4Addrs = ''; + $ipv4Netmasks = ''; + if (!preg_match_all('/inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/([0-3][0-9])/i', $stdoutIpWRepeatedSpaces, $matchesIpv4AddrAndSubnet)) { + $ipv4Addrs = _('No IPv4 Address Found'); + } else { + $numMatchesIpv4AddrAndSubnet = count($matchesIpv4AddrAndSubnet); + for ($i = 1; $i < $numMatchesIpv4AddrAndSubnet; $i += 2) { + if ($i > 2) { + $ipv4Netmasks .= ' '; + $ipv4Addrs .= ' '; + } - preg_match('/inet6 ([a-f0-9:]+)/i', $stdoutIpWRepeatedSpaces, $matchesIpv4Addr ) || $matchesIpv6Addr[1] = _('No IPv6 Address Found'); - $ipv6Addr = $matchesIpv6Addr[1]; - // TODO multiple ipv6 addresses + $ipv4Addrs .= $matchesIpv4AddrAndSubnet[$i][0]; + $ipv4Netmasks .= long2ip(-1 << (32 -(int)$matchesIpv4AddrAndSubnet[$i+1][0])); + } + } + + $ipv6Addrs = ''; + if (!preg_match_all('/inet6 ([a-f0-9:]+)/i', $stdoutIpWRepeatedSpaces, $matchesIpv6Addr)) { + $ipv6Addrs = _('No IPv6 Address Found'); + } else { + $numMatchesIpv6Addr = count($matchesIpv6Addr); + for ($i = 1; $i < $numMatchesIpv6Addr; ++$i) { + if ($i > 1) { + $ipv6Addrs .= ' '; + } + + $ipv6Addrs .= $matchesIpv6Addr[$i]; + } + } preg_match('/state (UP|DOWN)/i', $stdoutIpWRepeatedSpaces, $matchesState ) || $matchesState[1] = 'unknown'; $interfaceState = $matchesState[1]; @@ -165,9 +187,9 @@ function DisplayDashboard(){


-

-

-

+

+

+