From acacfe33a125e046495a0cbd485891cb27b0fd38 Mon Sep 17 00:00:00 2001 From: Stijn Geens Date: Wed, 3 Jan 2018 10:34:38 +0100 Subject: [PATCH 1/5] Added IP address and subnet mask --- content/network/NetworkData.php | 6 ++++++ content/network/NetworkView.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/content/network/NetworkData.php b/content/network/NetworkData.php index 9c4f980..73d7db8 100644 --- a/content/network/NetworkData.php +++ b/content/network/NetworkData.php @@ -31,12 +31,18 @@ private function prepareData() $output = shell_exec('sh ./lib/transfer_rate.sh ' . $this->interface); $rates = explode(' ', $output); + $ip_address = shell_exec("ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1"); + $subnet_mask = shell_exec("ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f2"); + // data object $data = new \stdClass(); $data->down = StringHelpers::prettyBaud($rates[0]); $data->up = StringHelpers::prettyBaud($rates[1]); + $data->ip_address = trim($ip_address); + $data->subnet_mask = $subnet_mask; + return $data; } diff --git a/content/network/NetworkView.php b/content/network/NetworkView.php index 6cbffaf..f362465 100644 --- a/content/network/NetworkView.php +++ b/content/network/NetworkView.php @@ -11,6 +11,10 @@ + + + + From 19d634d0bcb82378309388a5f6aa14405f6db93b Mon Sep 17 00:00:00 2001 From: Stijn Geens Date: Wed, 3 Jan 2018 12:21:26 +0100 Subject: [PATCH 2/5] Added support for other interfaces than eth0 --- content/network/NetworkData.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/network/NetworkData.php b/content/network/NetworkData.php index 73d7db8..f792f50 100644 --- a/content/network/NetworkData.php +++ b/content/network/NetworkData.php @@ -31,8 +31,8 @@ private function prepareData() $output = shell_exec('sh ./lib/transfer_rate.sh ' . $this->interface); $rates = explode(' ', $output); - $ip_address = shell_exec("ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1"); - $subnet_mask = shell_exec("ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f2"); + $ip_address = shell_exec("ip addr show " . $this->interface . " | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1"); + $subnet_mask = shell_exec("ip addr show " . $this->interface . " | grep 'inet\b' | awk '{print $2}' | cut -d/ -f2"); // data object $data = new \stdClass(); From 3a5c7c8dfa7f28275837f4ca339a165f0562d9e8 Mon Sep 17 00:00:00 2001 From: Stijn Geens Date: Wed, 3 Jan 2018 12:32:31 +0100 Subject: [PATCH 3/5] Improved API output --- content/network/NetworkData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/network/NetworkData.php b/content/network/NetworkData.php index f792f50..c379b12 100644 --- a/content/network/NetworkData.php +++ b/content/network/NetworkData.php @@ -41,7 +41,7 @@ private function prepareData() $data->up = StringHelpers::prettyBaud($rates[1]); $data->ip_address = trim($ip_address); - $data->subnet_mask = $subnet_mask; + $data->subnet_mask = trim($subnet_mask); return $data; } From 10072c3abdd73f41ab2cef14b7c22b07059e04e9 Mon Sep 17 00:00:00 2001 From: Stijn Geens Date: Wed, 3 Jan 2018 13:03:04 +0100 Subject: [PATCH 4/5] Added comment --- content/network/NetworkData.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/content/network/NetworkData.php b/content/network/NetworkData.php index c379b12..30c324c 100644 --- a/content/network/NetworkData.php +++ b/content/network/NetworkData.php @@ -26,6 +26,9 @@ private function prepareData() * * Also using one of the scripts in lib/string_helpers.php to * print the network speed in either b/s, Kb/s or Gb/s. + * + * The local IP address and subnet mask are retrieved using the + * 'ip' command. */ $output = shell_exec('sh ./lib/transfer_rate.sh ' . $this->interface); From e8e0859f9306e1b766216992fa49168847606096 Mon Sep 17 00:00:00 2001 From: Stijn Geens Date: Wed, 3 Jan 2018 18:11:58 +0100 Subject: [PATCH 5/5] Changed Down and Up to one row --- content/network/NetworkView.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/content/network/NetworkView.php b/content/network/NetworkView.php index f362465..782808e 100644 --- a/content/network/NetworkView.php +++ b/content/network/NetworkView.php @@ -12,16 +12,14 @@

IP address:

ip_address . "/" . $network_data->subnet_mask;?>

Down:

down;?>

- - + + - - - - - - + + + +

IP address:

ip_address . "/" . $network_data->subnet_mask;?>

IP address:

ip_address . "/" . $network_data->subnet_mask;?>

Down:

down;?>

Up:

up;?>

Down:

down;?>

Up:

up;?>