From 81c6775d329e7b282766732f504e9957d757384a Mon Sep 17 00:00:00 2001 From: ljm42 Date: Sun, 22 Oct 2017 19:27:02 -0700 Subject: [PATCH 1/7] improve sorting of DHCP leases * replaces strcmp with strnatcasecmp, which is much better at sorting ip addresses * sorts the list by IP address by default * does a secondary sort by IP address, which gives better results when sorting by status or lease type * fixes sorting on the "status" column (the underlying data structure is keyed on "online" instead of "status") * removes the option to sort by interface, since that doesn't work (the data doesn't exist at the time the array is sorted) --- src/www/status_dhcp_leases.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/www/status_dhcp_leases.php b/src/www/status_dhcp_leases.php index 75e1ec66d..f4188820a 100644 --- a/src/www/status_dhcp_leases.php +++ b/src/www/status_dhcp_leases.php @@ -33,11 +33,6 @@ require_once("config.inc"); require_once("services.inc"); require_once("interfaces.inc"); -function leasecmp($a, $b) -{ - return strcmp($a[$_GET['order']], $b[$_GET['order']]); -} - function adjust_gmt($dt) { global $config; @@ -242,9 +237,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } } - if ($_GET['order']) { - usort($leases, "leasecmp"); + $order = ( $_GET['order'] ) ? $_GET['order'] : 'ip'; + usort($leases, function ($a, $b) use ($order) { + return strnatcasecmp($a[$order].$a[ip],$b[$order].$b[ip]); } + ); } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($_POST['deleteip']) && is_ipaddr($_POST['deleteip'])) { // delete dhcp lease @@ -353,14 +350,14 @@ include("head.inc");?> - + - + From 22cba875cb481146a031bda9ad396392503382fc Mon Sep 17 00:00:00 2001 From: ljm42 Date: Sun, 22 Oct 2017 19:34:17 -0700 Subject: [PATCH 2/7] adjust spacing --- src/www/status_dhcp_leases.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/www/status_dhcp_leases.php b/src/www/status_dhcp_leases.php index f4188820a..64af775e0 100644 --- a/src/www/status_dhcp_leases.php +++ b/src/www/status_dhcp_leases.php @@ -238,10 +238,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } $order = ( $_GET['order'] ) ? $_GET['order'] : 'ip'; - usort($leases, function ($a, $b) use ($order) { - return strnatcasecmp($a[$order].$a[ip],$b[$order].$b[ip]); - } - ); + usort($leases, + function ($a, $b) use ($order) { + return strnatcasecmp($a[$order].$a[ip],$b[$order].$b[ip]); + } + ); } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($_POST['deleteip']) && is_ipaddr($_POST['deleteip'])) { // delete dhcp lease From 0d8b5c14e7ec440b47d7f0708cb0dad543039eea Mon Sep 17 00:00:00 2001 From: ljm42 Date: Sun, 22 Oct 2017 20:47:13 -0700 Subject: [PATCH 3/7] fixes sorting by description fixes sorting on the "description" column (the underlying data structure is keyed on "descr" instead of "desc") --- src/www/status_dhcp_leases.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/www/status_dhcp_leases.php b/src/www/status_dhcp_leases.php index 64af775e0..5e1a61d02 100644 --- a/src/www/status_dhcp_leases.php +++ b/src/www/status_dhcp_leases.php @@ -240,9 +240,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $order = ( $_GET['order'] ) ? $_GET['order'] : 'ip'; usort($leases, function ($a, $b) use ($order) { - return strnatcasecmp($a[$order].$a[ip],$b[$order].$b[ip]); + return strnatcasecmp($a[$order].$a[ip], $b[$order].$b[ip]); } ); + } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($_POST['deleteip']) && is_ipaddr($_POST['deleteip'])) { // delete dhcp lease @@ -355,7 +356,7 @@ include("head.inc");?> - + From ec39f8d389137f08703a3844fc95bd0b050f8fdf Mon Sep 17 00:00:00 2001 From: ljm42 Date: Sun, 22 Oct 2017 21:11:05 -0700 Subject: [PATCH 4/7] fixes sorting by lease type fixes sorting on the "lease type" column (the underlying data structure is keyed on "act" instead of "type") --- src/www/status_dhcp_leases.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/www/status_dhcp_leases.php b/src/www/status_dhcp_leases.php index 5e1a61d02..8baae396d 100644 --- a/src/www/status_dhcp_leases.php +++ b/src/www/status_dhcp_leases.php @@ -360,7 +360,7 @@ include("head.inc");?> - + From f5f51bdebed5e508239644146af565299d978332 Mon Sep 17 00:00:00 2001 From: ljm42 Date: Mon, 23 Oct 2017 15:05:45 -0700 Subject: [PATCH 5/7] add quotes around strings --- src/www/status_dhcp_leases.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/www/status_dhcp_leases.php b/src/www/status_dhcp_leases.php index 8baae396d..3b1f9d3d4 100644 --- a/src/www/status_dhcp_leases.php +++ b/src/www/status_dhcp_leases.php @@ -240,7 +240,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $order = ( $_GET['order'] ) ? $_GET['order'] : 'ip'; usort($leases, function ($a, $b) use ($order) { - return strnatcasecmp($a[$order].$a[ip], $b[$order].$b[ip]); + return strnatcasecmp($a[$order].$a['ip'], $b[$order].$b['ip']); } ); From c030c3fa18e996b377f0d30eb707b28996c4332f Mon Sep 17 00:00:00 2001 From: ljm42 Date: Tue, 24 Oct 2017 08:41:31 -0700 Subject: [PATCH 6/7] improved secondary sort --- src/www/status_dhcp_leases.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/www/status_dhcp_leases.php b/src/www/status_dhcp_leases.php index 3b1f9d3d4..fb548bddf 100644 --- a/src/www/status_dhcp_leases.php +++ b/src/www/status_dhcp_leases.php @@ -240,7 +240,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $order = ( $_GET['order'] ) ? $_GET['order'] : 'ip'; usort($leases, function ($a, $b) use ($order) { - return strnatcasecmp($a[$order].$a['ip'], $b[$order].$b['ip']); + $cmp = strnatcasecmp($a[$order], $b[$order]); + if ($cmp === 0) { + $cmp = strnatcasecmp($a['ip'], $b['ip']); + } + return $cmp; } ); From 7b84bc03b0d0ed714f943ff6dfd3952879a247f1 Mon Sep 17 00:00:00 2001 From: ljm42 Date: Tue, 24 Oct 2017 08:56:35 -0700 Subject: [PATCH 7/7] tabs to spaces --- src/www/status_dhcp_leases.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/www/status_dhcp_leases.php b/src/www/status_dhcp_leases.php index fb548bddf..ad47220a3 100644 --- a/src/www/status_dhcp_leases.php +++ b/src/www/status_dhcp_leases.php @@ -240,10 +240,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $order = ( $_GET['order'] ) ? $_GET['order'] : 'ip'; usort($leases, function ($a, $b) use ($order) { - $cmp = strnatcasecmp($a[$order], $b[$order]); - if ($cmp === 0) { - $cmp = strnatcasecmp($a['ip'], $b['ip']); - } + $cmp = strnatcasecmp($a[$order], $b[$order]); + if ($cmp === 0) { + $cmp = strnatcasecmp($a['ip'], $b['ip']); + } return $cmp; } );