interfaces: fix loopholes in the VipNetworkField #6775

This commit is contained in:
Franco Fichtner 2023-09-21 10:38:13 +02:00
parent bcd8cec574
commit e239ac2ab2
3 changed files with 8 additions and 11 deletions

View File

@ -43,12 +43,12 @@ class VipSettingsController extends ApiMutableModelControllerBase
*/
private function getVipOverlay()
{
$overlay = ['network' => ''];
$overlay = ['network' => '', 'subnet' => '', 'subnet_bits' => ''];
$tmp = $this->request->getPost('vip');
if (!empty($tmp['network'])) {
$parts = explode('/', $tmp['network'], 2);
$overlay['subnet'] = $parts[0];
if (count($parts) < 2) {
if (count($parts) == 1 || $parts[1] == '') {
$overlay['subnet_bits'] = strpos($parts[0], ':') !== false ? 128 : 32;
} else {
$overlay['subnet_bits'] = $parts[1];

View File

@ -45,15 +45,12 @@ class VipNetworkField extends TextField
}
$validators[] = new CallbackValidator(["callback" => function ($data) {
$parent = $this->getParentNode();
$subnet_bits = (string)$parent->subnet_bits;
$subnet = (string)$parent->subnet;
$messages = [];
if (!Util::isSubnet($subnet . "/" . $subnet_bits)) {
$messages[] = sprintf(
gettext('Entry "%s/%s" is not a valid network address.'),
$subnet,
$subnet_bits
);
$network = implode('/', [(string)$parent->subnet, (string)$parent->subnet_bits]);
if (empty((string)$parent->subnet)) {
$messages[] = gettext('A network address is required.');
} elseif (!Util::isIpAddress((string)$parent->subnet) || !Util::isSubnet($network)) {
$messages[] = sprintf(gettext('Entry "%s" is not a valid network address.'), $network);
}
return $messages;
}

View File

@ -44,7 +44,7 @@ class Vip extends BaseModel
$vips = [];
$carp_vhids = [];
// collect chaned VIP entries
// collect changed VIP entries
$vip_fields = ['mode', 'subnet', 'subnet_bits', 'password', 'vhid', 'interface'];
foreach ($this->getFlatNodes() as $key => $node) {
$tagName = $node->getInternalXMLTagName();