/**
  * @covers SysEleven\PowerDnsBundle\Validator\Constraints\RecordValidator::_validateAaaa
  * @covers SysEleven\PowerDnsBundle\Validator\Constraints\RecordValidator::_checkHostname
  */
 public function testValidateAaaa()
 {
     /**
      * @type DomainWorkflow $workflow
      */
     $workflow = $this->container->get('syseleven.pdns.workflow.domains');
     /**
      * @type Domains $domainObj
      */
     $domainObj = $workflow->getRepository()->findOneBy(array());
     $recordObj = new Records();
     $recordObj->setDomain($domainObj);
     $recordObj->setName('bogus___.');
     $recordObj->setType('AAAA');
     $recordObj->setContent('name');
     $validator = $this->container->get('validator');
     $errors = $validator->validate($recordObj);
     $this->assertCount(2, $errors);
     $recordObj->setName('a+.' . $domainObj->getName());
     $recordObj->setContent('::1');
     $validator = $this->container->get('validator');
     $errors = $validator->validate($recordObj);
     $this->assertCount(1, $errors);
 }
Ejemplo n.º 2
0
 public function loadFooBar_de(ObjectManager $manager)
 {
     /**
      * @type RecordWorkflow $recordWorkflow
      */
     $recordWorkflow = $this->container->get('syseleven.pdns.workflow.records');
     $domainObj = new Domains();
     $domainObj->setName('foobar.de');
     $domainObj->setType('NATIVE');
     $manager->persist($domainObj);
     $manager->flush();
     $soa = new Records();
     $soa->setName('foobar.de');
     $soa->setType('SOA');
     $soa->setContent('  1375872531 10800 604800 3600 ');
     $soa->setTtl(3600);
     $soa->setChangeDate(strtotime('now'));
     $soa->setManaged(1);
     $soa->setDomain($domainObj);
     $recordWorkflow->create($soa);
     $domainObj->addRecord($soa);
     $recordWorkflow->createHistory($soa, 'CREATE');
     $ns1 = new Records();
     $ns1->setName('foobar.de');
     $ns1->setContent('ns1.ns.de');
     $ns1->setPrio(10);
     $ns1->setTtl(3600);
     $ns1->setType('NS');
     $ns1->setDomain($domainObj);
     $recordWorkflow->create($ns1);
     $ns2 = new Records();
     $ns2->setName('foobar.de');
     $ns2->setContent('ns2.ns.de');
     $ns2->setPrio(20);
     $ns2->setTtl(3600);
     $ns2->setType('NS');
     $ns2->setDomain($domainObj);
     $recordWorkflow->create($ns2);
     $mx = new Records();
     $mx->setName('foobar.de');
     $mx->setContent('mail.foobar.de');
     $mx->setPrio(20);
     $mx->setTtl(3600);
     $mx->setType('MX');
     $mx->setDomain($domainObj);
     $recordWorkflow->create($mx);
     $www = new Records();
     $www->setName('www.foobar.de');
     $www->setType('A');
     $www->setContent('2.1.1.1');
     $www->setDomain($domainObj);
     $recordWorkflow->create($www);
     $www = new Records();
     $www->setName('www2.foobar.de');
     $www->setType('CNAME');
     $www->setContent('www.foobar.de');
     $www->setDomain($domainObj);
     $recordWorkflow->create($www);
 }
Ejemplo n.º 3
0
 /**
  * Creates a new SOA record for the given domain, see documentation for details
  *
  * @ApiDoc(
  *      description="Creates a new soa record for the given domain",
  *      input="SysEleven\PowerDnsBundle\Form\SoaType",
  *      requirements={
  *          {"name" = "domain", "dataType" = "integer", "requirement" = "\d+", "description" = "Id of the domain"},
  *          {"name" = "_format", "dataType" = "string", "pattern" = "(json|xml)", "description" = "Output Format"}
  *      },
  *
  *      output={
  *          "class"="SysEleven\PowerDnsBundle\Entity\Records",
  *          "groups"="details"
  *      }
  * )
  *
  * @param Request $request
  * @param int     $domain
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @Rest\Post("soa.{_format}", name="syseleven_powerdns_api_domains_soa_create")
  */
 public function soaCreateAction(Request $request, $domain)
 {
     try {
         /**
          * @type DomainWorkflow $workflow;
          */
         $workflow = $this->get('syseleven.pdns.workflow.domains');
         /**
          * @type Domains $domainObj
          */
         $domainObj = $workflow->get($domain);
         if ($soaRecord = $domainObj->getSoa()) {
             $data = array('status' => 'error', 'errors' => array('soa' => 'Already Exists'));
             return $this->returnView($data, 200, array(), array('details'));
         }
         $soa = new Soa();
         $form = $this->createForm(new SoaType(), $soa, array('method' => 'POST'));
         $form->submit($request, false);
         if (0 == $soa->getSerial()) {
             $soa->setSerial(strtotime('now'));
         }
         $recordObj = new Records();
         $recordObj->setName($domainObj->getName());
         $recordObj->setDomain($domainObj);
         $recordObj->setContent($soa);
         $recordObj->setType('SOA');
         /**
          * @type RecordWorkflow $recordWorkflow;
          */
         $recordWorkflow = $this->get('syseleven.pdns.workflow.records');
         $recordObj = $recordWorkflow->create($recordObj);
         $recordWorkflow->createHistory($recordObj);
         return $this->redirect($this->generateUrl('syseleven_powerdns_api_domains_soa', array('domain' => $domainObj->getId(), '_format' => $request->getRequestFormat())));
     } catch (NotFoundException $nf) {
         $data = array('status' => 'error', 'errors' => array('domain' => 'Not found'));
     } catch (ValidationException $ve) {
         $data = array('status' => 'error', 'errors' => Tools::prepareSymfonyErrorArray($ve->getErrors()));
     }
     return $this->returnView($data, 200, array(), array('details'));
 }
Ejemplo n.º 4
0
 /**
  * Checks a CNAME record for validity.
  *
  * @param Records    $record
  *
  * @return bool
  */
 public function _validateCname(Records $record)
 {
     $name = $record->getName();
     $looseHostname = 0 == $record->getLooseCheck() ? false : true;
     if (0 != strlen($name)) {
         if (false === $looseHostname) {
             if (false === strpos($name, '.' . $record->getDomain()->getName())) {
                 $this->context->addViolationAt('name', 'Name: ' . $name . ' is not in domain: ' . $record->getDomain()->getName(), array(), null);
             } else {
                 if (!$this->_checkHostname($name, false, true, true, $looseHostname)) {
                     $this->context->addViolationAt('name', 'Name: ' . $name . ' is not a valid hostname', array(), null);
                 }
             }
         }
     }
     if (!$this->_checkHostname($record->getContent(), false, true, true, $looseHostname)) {
         $this->context->addViolationAt('content', 'Name: ' . $record->getContent() . ' is not a valid hostname', array(), null);
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Retransforms the content to a soa object if applicable
  */
 public function postUpdate(Records $record, LifecycleEventArgs $event)
 {
     if ($record->getType() == 'SOA') {
         $transformer = new SoaTransformer();
         $record->setContent($transformer->transform($record->getContent()));
     }
 }
Ejemplo n.º 6
0
 /**
  * Creates a new Soa Entry for the class
  *
  * @param Domains $domainObj
  * @return Records
  */
 public function createSoa(Domains $domainObj)
 {
     if ($soa = $domainObj->getSoa()) {
         $this->updateSoa($domainObj);
     }
     $soaDefaults = new Soa($this->getSoaDefaults());
     $soa = new Records();
     $soa->setName($domainObj->getName());
     $soa->setType('SOA');
     $soa->setContent($soaDefaults);
     $soa->setDomain($domainObj);
     $soa->setTtl($soaDefaults->getDefaultTtl());
     $this->getDatabase()->persist($soa);
     $this->getDatabase()->flush();
     $domainObj->addRecord($soa);
     return $soa;
 }
Ejemplo n.º 7
0
 /**
  * Creates a new history.
  *
  * @param Records $record
  * @param string  $action
  *
  * @return bool
  */
 public function createHistory(Records $record, $action = 'CREATE')
 {
     $changes = $record->getChanges();
     if (0 == count($changes) && !in_array($action, array('CREATE', 'DELETE'))) {
         return true;
     }
     $content = $this->getSerializer()->serialize($record, 'json', SerializationContext::create()->setGroups('history'));
     $history = new RecordsHistory();
     $history->setDomainId($record->getDomain()->getId());
     $history->setRecordId($record->getId());
     $history->setDomainName($record->getDomain()->getName());
     $history->setRecordType($record->getType());
     $history->setAction($action);
     $history->setContents(json_decode($content, true));
     $history->setChanges($changes);
     $history->setCreated(new \DateTime());
     $history->setUser($record->getUser());
     $this->getDatabase()->persist($history);
     $this->getDatabase()->flush($history);
     return true;
 }
 /**
  * Creates a new record in the given domain. Note when creating a new
  * record the serial of the domain will automatically updated.
  *
  * @ApiDoc(
  *      description="Creates a new record",
  *      input="SysEleven\PowerDnsBundle\Form\RecordsType",
  *      requirements={
  *          {"name" = "domain", "dataType" = "integer", "requirement" = "\d+", "description" = "Id of the domain"},
  *          {"name" = "_format", "dataType" = "string", "pattern" = "(json|xml)", "description" = "Output Format"}
  *      },
  *
  *      output={
  *          "class"="SysEleven\PowerDnsBundle\Entity\Records",
  *          "groups"="details"
  *      }
  * )
  *
  * @param Request $request
  * @param int     $domain
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @Rest\Post("/records.{_format}", name="syseleven_powerdns_api_domains_records_create")
  */
 public function createAction(Request $request, $domain)
 {
     try {
         /**
          * @type DomainWorkflow $workflow
          */
         $workflow = $this->get('syseleven.pdns.workflow.domains');
         $domainObj = $workflow->get($domain);
         $recordObj = new Records();
         $recordObj->setDomain($domainObj);
         $form = $this->createForm(new RecordsType(), $recordObj, array('method' => 'POST'));
         $form->remove('domain');
         // Remove domain from form
         $form->handleRequest($request, true);
         /**
          * @type RecordWorkflow $recordWorkflow
          */
         $recordWorkflow = $this->get('syseleven.pdns.workflow.records');
         $force = $request->get('force', false);
         /**
          * @type Records $recordObj
          */
         $recordObj = $recordWorkflow->create($recordObj, array(), $force);
         return $this->redirect($this->generateUrl('syseleven_powerdns_api_domains_records_show', array('domain' => $domainObj->getId(), 'record' => $recordObj->getId(), '_format' => $request->getRequestFormat()), 201));
     } catch (NotFoundException $e) {
         $data = array('status' => 'error', 'errors' => array('id' => 'Not found'));
         return $this->returnView($data, 200);
     } catch (ValidationException $ve) {
         $data = array('status' => 'error', 'errors' => Tools::prepareSymfonyErrorArray($ve->getErrors()));
         return $this->returnView($data, 200);
     }
 }
 public function testCreate()
 {
     /**
      * @type Domains $domainObj
      */
     $domainObj = $this->container->get('syseleven.pdns.workflow.domains')->getRepository()->findOneBy(array('type' => 'NATIVE'));
     $serial = $domainObj->getSerial();
     sleep(4);
     $recordObj = new Records();
     $recordObj->setName('www.' . $domainObj->getName());
     $recordObj->setType('A');
     $recordObj->setContent('1.1.1.9');
     $recordObj->setDomain($domainObj);
     $recordObj = $this->workflow->create($recordObj);
     $this->assertNotEmpty($recordObj->getId());
     $this->assertNotEquals($serial, $domainObj->getSerial());
     return $recordObj->getId();
 }
Ejemplo n.º 10
0
 public function testPtr()
 {
     /**
      * @type DomainWorkflow $workflow;
      * @type Domains $domainObj
      */
     $workflow = $this->container->get('syseleven.pdns.workflow.domains');
     $domainObj = $workflow->get(1);
     $recordObj = new Records();
     $recordObj->setDomain($domainObj);
     /**
      * @type FormBuilder $form
      */
     $form = $this->container->get('form.factory')->create(new RecordsType(), $recordObj);
     $requestData = array('content' => 'www.test.de', 'name' => '1.2.3.4', 'type' => 'PTR');
     $form->submit($requestData, false);
     $data = $form->getData();
     $this->assertEquals('PTR', $recordObj->getType());
     $this->assertEquals('4.3.2.1.in-addr.arpa', $recordObj->getName());
     $this->assertEquals('1.2.3.4', $recordObj->getForwardName());
 }