From 489091dcf7c8bebbe9f6f722057c985a8d938295 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Thu, 23 Jun 2016 00:34:18 +0200 Subject: Allow passing comma in string quoted DHCP client options (cherry picked from commit 332a64d0c8a6486d40c6295351ca3068a77a216a) --- src/etc/inc/interfaces.inc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index e845c29..1bbb438 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -4027,7 +4027,7 @@ function DHCP6_Config_File_Advanced($interface, $wancfg, $wanif) { $send_options = ""; if ($wancfg['adv_dhcp6_interface_statement_send_options'] != '') { - $options = explode(',', $wancfg['adv_dhcp6_interface_statement_send_options']); + $options = DHCP_Config_Option_Split($wancfg['adv_dhcp6_interface_statement_send_options']); foreach ($options as $option) { $send_options .= "\tsend " . trim($option) . ";\n"; } @@ -4035,7 +4035,7 @@ function DHCP6_Config_File_Advanced($interface, $wancfg, $wanif) { $request_options = ""; if ($wancfg['adv_dhcp6_interface_statement_request_options'] != '') { - $options = explode(',', $wancfg['adv_dhcp6_interface_statement_request_options']); + $options = DHCP_Config_Option_Split($wancfg['adv_dhcp6_interface_statement_request_options']); foreach ($options as $option) { $request_options .= "\trequest " . trim($option) . ";\n"; } @@ -4305,7 +4305,7 @@ function DHCP_Config_File_Advanced($interface, $wancfg, $wanif) { $send_options = ""; if ($wancfg['adv_dhcp_send_options'] != '') { - $options = explode(',', $wancfg['adv_dhcp_send_options']); + $options = DHCP_Config_Option_Split($wancfg['adv_dhcp_send_options']); foreach ($options as $option) { $send_options .= "\tsend " . trim($option) . ";\n"; } @@ -4323,7 +4323,7 @@ function DHCP_Config_File_Advanced($interface, $wancfg, $wanif) { $option_modifiers = ""; if ($wancfg['adv_dhcp_option_modifiers'] != '') { - $modifiers = explode(',', $wancfg['adv_dhcp_option_modifiers']); + $modifiers = DHCP_Config_Option_Split($wancfg['adv_dhcp_option_modifiers']); foreach ($modifiers as $modifier) { $option_modifiers .= "\t" . trim($modifier) . ";\n"; } @@ -4357,6 +4357,14 @@ function DHCP_Config_File_Advanced($interface, $wancfg, $wanif) { return $dhclientconf; } +function DHCP_Config_Option_Split($option_string) { + $options = []; + preg_match_all('/[^",]*(?:"[^"]*"[^",]*)+(?:"[^",]*)?|[^,]+/m', $option_string, $result, PREG_PATTERN_ORDER); + for ($i = 0; $i < count($result[0]); $i++) { + $options[] = $result[0][$i]; + } + return $options; +} function DHCP_Config_File_Override($wancfg, $wanif) { -- cgit v1.1