diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 3790a7005..e33d8df9c 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -1571,8 +1571,8 @@ function interfaces_carp_setup($verbose = false) } if (!empty($carp_sync_int) && isset($config['hasync']['pfsyncenabled'])) { - if (isset($config['hasync']['pfsyncpeerip']) && is_ipaddr($config['hasync']['pfsyncpeerip'])) { - $syncpeer = "syncpeer " . $config['hasync']['pfsyncpeerip']; + if (!empty($config['hasync']['pfsyncpeerip']) && is_ipaddrv4($config['hasync']['pfsyncpeerip'])) { + $syncpeer = "syncpeer {$config['hasync']['pfsyncpeerip']}"; } else { $syncpeer = "-syncpeer"; } diff --git a/src/www/system_hasync.php b/src/www/system_hasync.php index ecab7068e..b90fbfd01 100644 --- a/src/www/system_hasync.php +++ b/src/www/system_hasync.php @@ -69,9 +69,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig[$tag] = null; } } - } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + $input_errors = array(); $pconfig = $_POST; + foreach ($checkbox_names as $name) { if (isset($pconfig[$name])) { $a_hasync[$name] = $pconfig[$name]; @@ -79,27 +80,47 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $a_hasync[$name] = false; } } - $a_hasync['pfsyncpeerip'] = $pconfig['pfsyncpeerip']; - $a_hasync['pfsyncinterface'] = $pconfig['pfsyncinterface']; - $a_hasync['synchronizetoip'] = $pconfig['synchronizetoip']; - $a_hasync['username'] = $pconfig['username']; - $a_hasync['password'] = $pconfig['password']; - write_config("Updated High Availability configuration"); - interfaces_carp_setup(); - header(url_safe('Location: /system_hasync.php')); - exit; + + if (!empty($pconfig['pfsyncpeerip']) && is_ipaddrv4($pconfig['pfsyncpeerip'])) { + $input_errors[] = gettext('The synchronize peer IP must be an IPv4 address or left empty.'); + } + + if (!count($input_errors)) { + $a_hasync['pfsyncinterface'] = $pconfig['pfsyncinterface']; + $a_hasync['synchronizetoip'] = $pconfig['synchronizetoip']; + $a_hasync['username'] = $pconfig['username']; + $a_hasync['password'] = $pconfig['password']; + + if (!empty($pconfig['pfsyncpeerip'])) { + $a_hasync['pfsyncpeerip'] = $pconfig['pfsyncpeerip']; + } elseif (isset($a_hasync['pfsyncpeerip'])) { + unset($a_hasync['pfsyncpeerip']); + } + + write_config('Updated High Availability configuration'); + interfaces_carp_setup(); + + header(url_safe('Location: /system_hasync.php')); + exit; + } } legacy_html_escape_form_data($pconfig); -include("head.inc"); -?> +include("head.inc"); + +?>