/** * Sets IPv4 or IPv6 from form to given VlanInterface. * * Function checks if IPvX address is provided if IPvX is enabled. Then * it checks if given IPvX address exists for current Vlan: * * * if it exists, it ensures is is not assigned to another interface; * * if !exists, creates a new one. * * @param IXP_Form $form Form to get IP address data (one of _Interface_AddWizard or _Interface_Vlan) * @param \Entities\VirtualInterface $vi Virtual interface to check if IP is not assign to different * @param \Entities\VlanInterface $vli Vlan interface to assign IP to * @param bool $ipv6 Bool to define if IP address is IPv4 or IPv6 * @return bool */ private function setIp($form, $vi, $vli, $ipv6 = false) { $iptype = $ipv6 ? "ipv6" : "ipv4"; $ipVer = $ipv6 ? "IPv6" : "IPv4"; $setter = "set{$ipVer}Address"; $getter = "get{$ipVer}Address"; $entity = "\\Entities\\{$ipVer}Address"; $vlan = $vli->getVlan(); if ($form->getValue($iptype . "enabled")) { if (!$form->getElement($iptype . 'addressid')->getValue()) { $form->getElement($iptype . 'addressid')->setErrors(["Please select or enter an {$ipVer} address."]); return false; } $ip = $this->getD2EM()->getRepository($entity)->findOneBy(["Vlan" => $vlan->getId(), 'address' => $form->getElement($iptype . 'addressid')->getValue()]); if (!$ip) { $ip = new $entity(); $this->getD2EM()->persist($ip); $ip->setVlan($vlan); $ip->setAddress($form->getElement($iptype . 'addressid')->getValue()); } else { if ($ip->getVlanInterface() && $ip->getVlanInterface() != $vli) { $address = $form->getElement($iptype . 'addressid')->getValue(); $form->getElement($iptype . 'addressid')->setErrors(["{$ipVer} address '{$address}' is already in use."]); return false; } } $vli->{$setter}($ip); } else { // ipvX has been disabled - see if we need to remove an assigned IP address if (!$form->getElement($iptype . 'addressid')->getValue() && $vli->{$getter}()) { // need to unset the IP address $vli->{$setter}(null); } } return true; }
public function getVlan() { $this->__load(); return parent::getVlan(); }
/** * You can add `OSS_Message`s here and redirect to a custom destination after a * successful add / edit operation. * * @param IXP_Form_Interface_Vlan $form The form object * @param \Entities\VlanInterface $object The Doctrine2 entity (being edited or blank for add) * @param bool $isEdit True of we are editing an object, false otherwise * @return bool `false` for standard message and redirection, otherwise redirect within this function */ protected function addDestinationOnSuccess($form, $object, $isEdit) { if ($this->getParam('rtn', false) == 'vli') { return false; } $this->addMessage('VLAN interface successfuly ' . ($isEdit ? 'edited.' : 'added.'), OSS_Message::SUCCESS); $this->redirectAndEnsureDie('virtual-interface/edit/id/' . $object->getVirtualInterface()->getId()); }