diff --git a/src/www/status_dhcpv6_leases.php b/src/www/status_dhcpv6_leases.php index 0b39f0a4a..518f1e5cd 100644 --- a/src/www/status_dhcpv6_leases.php +++ b/src/www/status_dhcpv6_leases.php @@ -306,11 +306,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $leases[] = $slease; } - if ($_GET['order']) { - usort($leases, function ($a, $b) { - return strcmp($a[$_GET['order']], $b[$_GET['order']]); - }); + if (isset($_GET['order']) && + in_array($_GET['order'], ['int', 'ip', 'iaid', 'duid', 'hostname', 'descr', 'start', 'end', 'online', 'act'])) { + $order = $_GET['order']; + } else { + $order = 'ip'; } + + usort($leases, + function ($a, $b) use ($order) { + $cmp = ($order === 'ip') ? 0 : strnatcasecmp($a[$order], $b[$order]); + if ($cmp === 0) { + $cmp = ipcmp($a['ip'], $b['ip']); + } + return $cmp; + } + ); } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($_POST['deleteip']) && is_ipaddr($_POST['deleteip'])) { killbypid('/var/dhcpd/var/run/dhcpdv6.pid', 'TERM', true); @@ -383,6 +394,11 @@ legacy_html_escape_form_data($leases); location.reload(); }); }); + // keep sorting in place. + $(".act_sort").click(function(){ + var all = =!empty($_GET['all']) ? 1 : 0;?> ; + document.location = document.location.origin + window.location.pathname +"?all="+all+"&order="+$(this).data('field'); + }); }); @@ -429,16 +445,16 @@ endif;?>
| =gettext("Interface"); ?> | -=gettext("IPv6 address"); ?> | -=gettext("IAID"); ?> | -=gettext("DUID"); ?> | -=gettext("Hostname/MAC"); ?> | -=gettext("Description"); ?> | -=gettext("Start"); ?> | -=gettext("End"); ?> | -=gettext("Online"); ?> | -=gettext("Lease Type"); ?> | +=gettext("Interface"); ?> | +=gettext("IPv6 address"); ?> | +=gettext("IAID"); ?> | +=gettext("DUID"); ?> | +=gettext("Hostname/MAC"); ?> | +=gettext("Description"); ?> | +=gettext("Start"); ?> | +=gettext("End"); ?> | +=gettext("Online"); ?> | +=gettext("Lease Type"); ?> |
|---|