diff options
-rw-r--r-- | src/etc/inc/util.inc | 30 | ||||
-rw-r--r-- | src/usr/local/www/system_advanced_network.php | 15 |
2 files changed, 38 insertions, 7 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index 4d157d7..ad94157 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -2553,7 +2553,35 @@ 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) { + $formatted_dhcp6duid = strtolower(str_replace("-", ":", $dhcp6duid)); + $values = explode(":", $formatted_dhcp6duid); + if (count($values) == 14) { + $formatted_dhcp6duid = '0e:00:' . $formatted_dhcp6duid; + $values = explode(":", $formatted_dhcp6duid); + } + foreach ($values as $idx => $value) { + if (strlen($value) == 1) { + $values[$idx] = "0" . $value; + } + } + $formatted_dhcp6duid = implode(":", $values); + return $formatted_dhcp6duid; +} + +/* 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 b99dad8..acfe18d 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']); } |