diff options
-rw-r--r-- | src/etc/inc/util.inc | 27 | ||||
-rw-r--r-- | src/usr/local/www/system_advanced_network.php | 15 |
2 files changed, 35 insertions, 7 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index 4d157d7..f6e758a 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -2553,7 +2553,32 @@ function validateipaddr(&$addr, $type, $label, &$err_msg, $alias=false) { return false; } -/* returns true if $dhcp6duid is a valid duid entrry */ +/* format a string to look (more) like the expected DUID format: + * 1) Replace any "-" with ":" + * 2) If the user inputs 14 components, then add the expected "0e:00:" to the front. + * This is convenience, because the actual DUID (which is reported in logs) is the last 14 components. + * 3) If any components are input with just a single char (hex digit hopefully), put a "0" in front. + * + * The final result should be closer to: + * + * "0e:00:00:01:00:01:nn:nn:nn:nn:nn:nn:nn:nn:nn:nn" + * + * This function does not validate the input. is_duid() will do validation. +*/ +function format_duid($dhcp6duid) { + $values = explode(":", strtolower(str_replace("-", ":", $dhcp6duid))); + if (count($values) == 14) { + array_unshift($values, "0e", "00"); + } + + array_walk($values, function(&$value) { + $value = str_pad($value, 2, '0', STR_PAD_LEFT); + }); + + return implode(":", $values); +} + +/* returns true if $dhcp6duid is a valid duid entry */ function is_duid($dhcp6duid) { $values = explode(":", $dhcp6duid); if (count($values) != 16 || strlen($dhcp6duid) != 47) { diff --git a/src/usr/local/www/system_advanced_network.php b/src/usr/local/www/system_advanced_network.php index 529d03b..1200996 100644 --- a/src/usr/local/www/system_advanced_network.php +++ b/src/usr/local/www/system_advanced_network.php @@ -56,6 +56,14 @@ if ($_POST) { $input_errors[] = gettext("An IP address to NAT IPv6 packets must be specified."); } + if (!empty($_POST['global-v6duid'])) { + $_POST['global-v6duid'] = format_duid($_POST['global-v6duid']); + $pconfig['global-v6duid'] = $_POST['global-v6duid']; + if (!is_duid($_POST['global-v6duid'])) { + $input_errors[] = gettext("A valid DUID must be specified"); + } + } + ob_flush(); flush(); if (!$input_errors) { @@ -85,12 +93,7 @@ if ($_POST) { } if (!empty($_POST['global-v6duid'])) { - $_POST['global-v6duid'] = strtolower(str_replace("-", ":", $_POST['global-v6duid'])); - if (!is_duid($_POST['global-v6duid'])) { - $input_errors[] = gettext("A valid DUID must be specified"); - } else { - $config['system']['global-v6duid'] = $_POST['global-v6duid']; - } + $config['system']['global-v6duid'] = $_POST['global-v6duid']; } else { unset($config['system']['global-v6duid']); } |