From c51a6916c31773e6607ee7c0e62d0d6acaedabb5 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sun, 18 Mar 2018 18:28:35 +0000 Subject: [PATCH] openvpn: tunnel network tweaks, only one needed #2266 --- src/www/guiconfig.inc | 11 ++++++++++- src/www/vpn_openvpn_client.php | 12 ++++-------- src/www/vpn_openvpn_server.php | 12 +++++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/www/guiconfig.inc b/src/www/guiconfig.inc index 4778a4785..19cb12f46 100644 --- a/src/www/guiconfig.inc +++ b/src/www/guiconfig.inc @@ -161,7 +161,16 @@ function do_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_error } for ($i = 0; $i < count($reqdfields); $i++) { - if (empty($postdata[$reqdfields[$i]])) { + $fields = explode(',', $reqdfields[$i]); + $found = false; + + foreach ($fields as $field) { + if (!empty($postdata[$field])) { + $found = true; + } + } + + if (!$found) { $input_errors[] = sprintf(gettext("The field %s is required."), $reqdfieldsn[$i]); } } diff --git a/src/www/vpn_openvpn_client.php b/src/www/vpn_openvpn_client.php index c4ecfb034..31f99f069 100644 --- a/src/www/vpn_openvpn_client.php +++ b/src/www/vpn_openvpn_client.php @@ -251,15 +251,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } } } - if (!empty($pconfig['tunnel_network'])) { - if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'IPv4 Tunnel Network', false, "ipv4")) { - $input_errors[] = $result; - } + if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'IPv4 Tunnel Network', false, "ipv4")) { + $input_errors[] = $result; } - if (!empty($pconfig['tunnel_networkv6'])) { - if ($result = openvpn_validate_cidr($pconfig['tunnel_networkv6'], 'IPv6 Tunnel Network', false, "ipv6")) { - $input_errors[] = $result; - } + if ($result = openvpn_validate_cidr($pconfig['tunnel_networkv6'], 'IPv6 Tunnel Network', false, "ipv6")) { + $input_errors[] = $result; } if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'IPv4 Remote Network', true, "ipv4")) { $input_errors[] = $result; diff --git a/src/www/vpn_openvpn_server.php b/src/www/vpn_openvpn_server.php index d1c1b2d81..1d1b4b775 100644 --- a/src/www/vpn_openvpn_server.php +++ b/src/www/vpn_openvpn_server.php @@ -295,10 +295,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } if ($pconfig['dev_mode'] != "tap") { - $reqdfields[] = 'tunnel_network'; - $reqdfieldsn[] = gettext('Tunnel network'); + $reqdfields[] = 'tunnel_network,tunnel_networkv6'; + $reqdfieldsn[] = gettext('Tunnel Network'); } else { - if ($pconfig['serverbridge_dhcp'] && $pconfig['tunnel_network']) { + if ($pconfig['serverbridge_dhcp'] && ($pconfig['tunnel_network'] || $pconfig['tunnel_networkv6'])) { $input_errors[] = gettext("Using a tunnel network and server bridge settings together is not allowed."); } if (($pconfig['serverbridge_dhcp_start'] && !$pconfig['serverbridge_dhcp_end']) @@ -318,6 +318,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (isset($pconfig['reneg-sec']) && $pconfig['reneg-sec'] != "" && (string)((int)$pconfig['reneg-sec']) != $pconfig['reneg-sec']) { $input_errors[] = gettext("Renegotiate time should contain a valid number of seconds."); } + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); if (count($input_errors) == 0) { @@ -1622,8 +1623,9 @@ endif; ?> / - - + + +