Exemplo n.º 1
0
 /**
  * Transform domain to vhost.
  *
  * @param Domain    $domain
  * @param Subdomain $subdomain
  *
  * @return Vhost[]
  */
 public static function transformDomain(Domain $domain, Subdomain $subdomain = null)
 {
     /** @var Vhost[] $return */
     $return = array();
     $ips = $domain->getIpaddress();
     if (($max = count($ips)) < 1) {
         $max = 1;
     }
     for ($i = 0; $i < $max; $i++) {
         $vhost = new Vhost();
         $ip = null;
         if ($ips->containsKey($i)) {
             /** @var IpAddress $ip */
             $ip = $ips[$i];
         }
         $vhost->setDomain($domain)->setSubdomain($subdomain);
         if ($ip !== null) {
             $vhost->setIpaddress($ip);
         }
         /*
          * Only add if:
          * - Domain has no IP's (so no SSL is required).
          * - IP has no SSL support.
          * - Domain has a Certificate AND IP supports SSL.
          */
         if ($ip === null || $vhost->getSSLEnabled() || !$ip->getHasSsl()) {
             $return[] = $vhost;
         }
     }
     return $return;
 }
Exemplo n.º 2
0
 /**
  * Displays a form to create a new Domain entity.
  *
  * @Route("/new", name="config_domain_new")
  * @Template()
  */
 public function newAction()
 {
     $entity = new Domain();
     $entity->setPath('(auto)');
     $form = $this->createForm(new DomainType(), $entity);
     return array('entity' => $entity, 'form' => $form->createView());
 }
 /**
  * Get domain.
  *
  * @return Domain
  */
 protected function _getDomain()
 {
     $user = new User();
     $domain = new Domain();
     $user->setName('www-data')->setUid(1000)->setGid(1000)->setGroupname('www-data');
     $domain->setUser($user)->setPath($this->_getTestPath());
     return $domain;
 }
Exemplo n.º 4
0
 /**
  * Get DNS.
  *
  * @param string $subdomain
  *
  * @return Dns
  */
 protected function _getDns($subdomain = '')
 {
     $domain = new Domain();
     $domain->setDomain('lampcp.de');
     $dns = new Dns($domain);
     if (!empty($subdomain)) {
         $dns->setSubdomain($subdomain);
     }
     return $dns;
 }
Exemplo n.º 5
0
 /**
  * Provide test domains.
  *
  * @return array
  */
 public function domainProvider()
 {
     $certRoot = new Certificate();
     $certRoot->setName('root');
     $certAlias = new Certificate();
     $certAlias->setName('alias');
     $root = new Domain();
     $root->setDomain('root.de')->setPath('/var/www/root')->setCertificate($certRoot);
     $alias = new Domain();
     $alias->setDomain('alias.de')->setPath('/var/www/alias')->setCertificate($certAlias)->setParent($root);
     return array(array($root), array($alias));
 }
 /**
  * Provides protections.
  *
  * @return array
  */
 public function dataProvider()
 {
     $domain = new Domain();
     $domain->setPath('/var/www/test.de');
     $protection = new Protection($domain);
     $user1 = new ProtectionUser($domain, $protection);
     $user2 = new ProtectionUser($domain, $protection);
     $user1->setUsername('test1')->setPassword('pw1');
     $user2->setUsername('test2')->setPassword('pw2');
     $collection = new ArrayCollection(array($user1, $user2));
     $protection->setProtectionuser($collection)->setId(1)->setPath('/var/www/test.de/htdocs/test');
     return array(array($protection));
 }
Exemplo n.º 7
0
 /**
  * Get origin
  *
  * @return string
  */
 public function getOrigin()
 {
     if (!empty($this->subdomain)) {
         return $this->subdomain . '.' . $this->domain->getDomain();
     } else {
         return $this->domain->getDomain();
     }
 }
Exemplo n.º 8
0
 /**
  * Get parent domain and set some properties
  * from alias domain.
  *
  * @param Domain $domain
  *
  * @return Domain
  */
 public static function transformAliasDomain(Domain $domain)
 {
     if ($domain->getParent() !== null) {
         $parent = clone $domain->getParent();
         $parent->setDomain($domain->getDomain())->setIpaddress($domain->getIpaddress())->setCertificate($domain->getCertificate());
         return $parent;
     }
     return $domain;
 }
Exemplo n.º 9
0
 /**
  * Provide test-data.
  */
 public function dataProvider()
 {
     $certificate = new Certificate();
     $domainWithoutIp = new Domain();
     $domainWithoutIp->setDomain('withoutIp.de');
     $ipaddressWithSSL = new IpAddress();
     $ipaddressWithSSL->setHasSsl(true);
     $ipaddressWithoutSSL = new IpAddress();
     $ipaddressWithoutSSL->setHasSsl(false);
     $domainWithIPs = new Domain();
     $domainWithIPs->setDomain('withIp.de')->setIpaddress(new ArrayCollection(array($ipaddressWithoutSSL, $ipaddressWithSSL)))->setCertificate($certificate);
     $subdomainWithSSL = new Subdomain($domainWithIPs);
     $subdomainWithSSL->setCertificate($certificate)->setSubdomain('withssl');
     $subdomainWithSSL2 = new Subdomain($domainWithoutIp);
     $subdomainWithSSL2->setCertificate($certificate)->setSubdomain('withssl');
     $subdomainWithoutSSL = new Subdomain($domainWithIPs);
     $subdomainWithoutSSL->setSubdomain('withoutssl');
     $subdomainWithoutSSL2 = new Subdomain($domainWithoutIp);
     $subdomainWithoutSSL2->setSubdomain('withoutssl');
     return array(array($domainWithIPs, $subdomainWithoutSSL), array($domainWithIPs, $subdomainWithSSL), array($domainWithoutIp, $subdomainWithSSL2), array($domainWithoutIp, $subdomainWithoutSSL2), array($domainWithIPs), array($domainWithoutIp));
 }
Exemplo n.º 10
0
 /**
  * Change directory owners.
  *
  * @param Domain $domain
  *
  * @return bool
  */
 protected function _changeDirectoryOwner(Domain $domain)
 {
     $fs = new Filesystem();
     try {
         $fs->chown($domain->getPath(), self::_root);
         // Domain Root
         $fs->chgrp($domain->getPath(), $domain->getUser()->getGroupname(), true);
         // Domain Root + Child
         // Child directories
         $fs->chown($this->_getDefaultDirs($domain->getPath()), $domain->getUser()->getName(), true);
     } catch (IOException $e) {
         return false;
     }
     return true;
 }
Exemplo n.º 11
0
 /**
  * Test createAuthUserFile().
  */
 public function testCreateAuthUserFile()
 {
     $fs = new Filesystem();
     $fs->mkdir(sys_get_temp_dir() . '/conf');
     $domain = new Domain();
     $protection = new Protection($domain);
     $protectionuser = new ProtectionUser($domain, $protection);
     $domain->setPath(sys_get_temp_dir());
     $protection->setId(1)->setProtectionuser(new ArrayCollection(array($protectionuser)));
     $protectionuser->setUsername('test')->setPassword('tester')->setProtection($protection);
     $this->getService()->createAuthUserFile($protection);
     $this->assertFileExists(sys_get_temp_dir() . '/conf/authuser_1.passwd');
 }
Exemplo n.º 12
0
 /**
  * Set domain
  *
  * @param Domain $domain
  */
 public function setDomain(Domain $domain)
 {
     $this->_session->set(self::SESSIONKEY, $domain->getId());
 }
Exemplo n.º 13
0
 /**
  * Test getDirectoryOptions().
  */
 public function testGetDirectoryOptions()
 {
     $domain = new Domain();
     $po1 = new PathOption($domain);
     $po2 = new PathOption($domain);
     $po3 = new PathOption($domain);
     $protection1 = new Protection($domain);
     $protection2 = new Protection($domain);
     $protection3 = new Protection($domain);
     $domain->setPath('/var/www/domain.de')->setWebroot('htdocs/test');
     $domain->getPathoption()->add($po1);
     $domain->getPathoption()->add($po2);
     $domain->getPathoption()->add($po3);
     $domain->getProtection()->add($protection1);
     $domain->getProtection()->add($protection2);
     $domain->getProtection()->add($protection3);
     $po1->setPath('htdocs/test/subfolder');
     $po2->setPath('htdocs');
     $po3->setPath('htdocs/test');
     $protection1->setPath('htdocs');
     $protection2->setPath('htdocs/test/subfolder2');
     $protection3->setPath('htdocs/test');
     $vhost = new Vhost();
     $vhost->setDomain($domain);
     $options = $vhost->getDirectoryOptions();
     $this->assertCount(2, $options);
     $testPo = false;
     $testProt = false;
     foreach ($options as $optset) {
         if ($optset['pathoption'] !== null) {
             $this->assertEquals($po1, $optset['pathoption']);
             $testPo = true;
         }
         if ($optset['protection'] !== null) {
             $this->assertEquals($protection2, $optset['protection']);
             $testProt = true;
         }
     }
     $this->assertTrue($testPo);
     $this->assertTrue($testProt);
 }
Exemplo n.º 14
0
 /**
  * Get PHP-FPM Socket.
  *
  * @param Domain $domain
  *
  * @return string
  */
 public function getPhpSocket(Domain $domain)
 {
     $socket = $this->getPhpFpmConfigBuilder()->getPoolCreator($domain->getUser())->getSocketPath();
     return $socket;
 }
Exemplo n.º 15
0
 /**
  * Remove obsolete auth-user files.
  *
  * @param Domain $domain
  */
 public function removeObsoleteAuthUserFiles(Domain $domain)
 {
     $finder = new Finder();
     $fs = new Filesystem();
     $files = array();
     $ids = array();
     foreach ($domain->getProtection() as $protection) {
         /** @var Protection $protection */
         $ids[] = $protection->getId();
     }
     $finder->in($domain->getPath() . '/conf')->name('authuser_*.passwd')->depth(0)->files();
     foreach ($finder as $file) {
         /** @var SplFileInfo $file */
         $id = $this->getIdFromFilename($file->getFilename());
         if ($id === null) {
             continue;
         }
         if (!in_array($id, $ids)) {
             // Obsolete file.
             $files[] = $file->getPathname();
         }
     }
     if (count($files) > 0) {
         $fs->remove($files);
     }
 }
Exemplo n.º 16
0
 /**
  * Generate LampCP Domain.
  *
  * @param Vhost $vhost
  *
  * @return Domain
  * @throws UserNotFoundException
  */
 protected function _generateLampcpDomain(Vhost $vhost)
 {
     $domain = new Domain();
     $ip = new IpAddress();
     /** @var User $user */
     $user = $this->getUserRepository()->findOneBy(array('name' => $vhost->user));
     if (!$user) {
         throw new UserNotFoundException();
     }
     $ip->setAlias('Default ip address')->setIp($vhost->ipaddress);
     $domain->setDomain($vhost->address)->setPath(realpath(__DIR__ . '/../../../../../../'))->setWebroot('htdocs/web')->setUser($user)->getIpaddress()->add($ip);
     return $domain;
 }
Exemplo n.º 17
0
 /**
  * Delete domain.
  *
  * @param Domain $domain
  */
 protected function _deleteDomain(Domain $domain)
 {
     /** @var EntityManager $em */
     if ($domain->getId() > 0) {
         $em = $this->createClient()->getContainer()->get('doctrine.orm.entity_manager');
         $aDomain = $em->getRepository(self::ENTITY_NAME)->findOneBy(array('id' => $domain->getId()));
         $em->remove($aDomain);
         $em->flush();
     }
 }
Exemplo n.º 18
0
 /**
  * ErrorLog
  *
  * @return string
  */
 public function getErrorLog()
 {
     return $this->domain->getPath() . self::_log_error;
 }
Exemplo n.º 19
0
 /**
  * Get full address (user@domain.de)
  *
  * @return string
  */
 public function getFullAddress()
 {
     return $this->address . '@' . $this->domain->getDomain();
 }
Exemplo n.º 20
0
 /**
  * Test get / set domain.
  */
 public function testDomainGetterSetter()
 {
     $service = $this->getVhostBuilderService();
     $domain = new Domain();
     $domains = array($domain);
     $domain->setDomain('test.de');
     $service->setDomains($domains);
     $this->assertEquals($domains, $service->getDomains());
 }