Пример #1
0
 /**
  * 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();
 }
 /**
  * @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
  * @param array $options Options passed onto Zend_Form
  * @param string $cancelLocation Where to redirect to if 'Cancal' is clicked
  * @return void
  */
 protected function formPostProcess($form, $object, $isEdit, $options = null, $cancelLocation = null)
 {
     if ($isEdit) {
         $form->getElement('virtualinterfaceid')->setValue($object->getVirtualInterface()->getId());
         $form->getElement('preselectCustomer')->setValue($object->getVirtualInterface()->getCustomer()->getId());
         $form->getElement('vlanid')->setValue($object->getVlan()->getId());
         $form->getElement('preselectIPv4Address')->setValue($object->getIPv4Address() ? $object->getIPv4Address()->getAddress() : null);
         $form->getElement('preselectIPv6Address')->setValue($object->getIPv6Address() ? $object->getIPv6Address()->getAddress() : null);
         $form->getElement('preselectVlanInterface')->setValue($object->getId());
         if ($this->getParam('rtn', false) == 'vli') {
             $form->setAction(OSS_Utils::genUrl('vlan-interface', 'edit', false, ['id' => $object->getId(), 'rtn' => 'vli']));
         } else {
             $form->getElement('cancel')->setAttrib('href', OSS_Utils::genUrl('virtual-interface', 'edit', false, ['id' => $object->getVirtualInterface()->getId()]));
         }
     } else {
         if ($this->getRequest()->isPost() && ($vintid = isset($_POST['virtualinterfaceid']) && $_POST['virtualinterfaceid'])) {
             $vint = $this->getD2EM()->getRepository('\\Entities\\VirtualInterface')->find($_POST['virtualinterfaceid']);
         } else {
             if (($vintid = $this->getRequest()->getParam('vintid')) !== null) {
                 $vint = $this->getD2EM()->getRepository('\\Entities\\VirtualInterface')->find($vintid);
             }
         }
         if (!isset($vint) || !$vint) {
             $this->addMessage('You need a containing virtual interface before you add a VLAN interface', OSS_Message::ERROR);
             $this->redirect('virtual-interface/add');
         }
         // make BGP MD5 easy
         $form->getElement('ipv4bgpmd5secret')->setValue(OSS_String::random());
         $form->getElement('ipv6bgpmd5secret')->setValue($form->getElement('ipv4bgpmd5secret')->getValue());
         $form->getElement('maxbgpprefix')->setValue($vint->getCustomer()->getMaxprefixes());
         $form->getElement('virtualinterfaceid')->setValue($vint->getId());
         $form->getElement('preselectCustomer')->setValue($vint->getCustomer()->getId());
         $form->getElement('cancel')->setAttrib('href', OSS_Utils::genUrl('virtual-interface', 'edit', false, ['id' => $vint->getId()]));
     }
 }