diff options
author | lukehamburg <luke.hamburg@gmail.com> | 2017-02-06 11:01:42 -0500 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2017-02-10 15:57:52 -0200 |
commit | 9a20d17098ee74a96370aeeb0fd9a1fcf7f8d86c (patch) | |
tree | 1ed76308d49daaae6d7fe0f73ab155fe2a84c5c8 | |
parent | 804f6a165fbb80deac018be43e8d41607fa67594 (diff) | |
download | pfsense-9a20d17098ee74a96370aeeb0fd9a1fcf7f8d86c.zip pfsense-9a20d17098ee74a96370aeeb0fd9a1fcf7f8d86c.tar.gz |
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
(cherry picked from commit 478e89190a295b48d221ddf2f683cac6f02d7012)
-rw-r--r-- | src/usr/local/www/services_dhcp_edit.php | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/usr/local/www/services_dhcp_edit.php b/src/usr/local/www/services_dhcp_edit.php index f597be1..02ac9d9 100644 --- a/src/usr/local/www/services_dhcp_edit.php +++ b/src/usr/local/www/services_dhcp_edit.php @@ -404,8 +404,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 = ''; @@ -433,7 +444,6 @@ $macaddress = new Form_Input( $pconfig['mac'], ['placeholder' => 'xx:xx:xx:xx:xx:xx'] ); - $btnmymac = new Form_Button( 'btnmymac', 'Copy My MAC', @@ -442,10 +452,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); |