From 478e89190a295b48d221ddf2f683cac6f02d7012 Mon Sep 17 00:00:00 2001 From: lukehamburg Date: Mon, 6 Feb 2017 11:01:42 -0500 Subject: enhancements to services_dhcp_edit.php - added ndp call to get MAC addr if remote client is connected via IPv6 - automatically hide `Copy MAC` button if arp/ndp returns null - switch to exec() instead of backticks for calls to arp - uses builtin is_ipaddr() function from util.inc --- src/usr/local/www/services_dhcp_edit.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/usr/local/www/services_dhcp_edit.php') diff --git a/src/usr/local/www/services_dhcp_edit.php b/src/usr/local/www/services_dhcp_edit.php index c347630..9b5df91 100644 --- a/src/usr/local/www/services_dhcp_edit.php +++ b/src/usr/local/www/services_dhcp_edit.php @@ -385,8 +385,19 @@ if ($_POST) { // Get our MAC address $ip = $_SERVER['REMOTE_ADDR']; -$mymac = `/usr/sbin/arp -an | grep '('{$ip}')' | cut -d" " -f4`; -$mymac = str_replace("\n", "", $mymac); + +switch (is_ipaddr($ip)) { + case 4: + $mymac = exec("/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d' ' -f4"); + $mymac = str_replace("\n", "", $mymac); + break; + case 6: + $mymac = exec("/usr/sbin/ndp -na | /usr/bin/grep '{$ip}' | /usr/bin/head -n 1 | /usr/bin/awk '{ print $2 }'"); + $mymac = str_replace("\n", "", $mymac); + break; + default: + unset($mymac); +} $iflist = get_configured_interface_with_descr(); $ifname = ''; @@ -415,7 +426,6 @@ $macaddress = new Form_Input( $pconfig['mac'], ['placeholder' => 'xx:xx:xx:xx:xx:xx'] ); - $btnmymac = new Form_Button( 'btnmymac', 'Copy My MAC', @@ -424,10 +434,11 @@ $btnmymac = new Form_Button( ); $btnmymac->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-success btn-sm'); - $group = new Form_Group('MAC Address'); $group->add($macaddress); -$group->add($btnmymac); +if (!empty($mymac)) { + $group->add($btnmymac); +} $group->setHelp('MAC address (6 hex octets separated by colons)'); $section->add($group); -- cgit v1.1