123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace IPv4Bundle\Services;
- use Doctrine\ORM\EntityManager;
- use Doctrine\ORM\EntityRepository;
- use HostBundle\Entity\HostType;
- use IPv4Bundle\Entity\Pool;
- use KeaBundle\Entity\Lease4;
- class PoolService
- {
-
- /**
- * @var EntityRepository
- */
- private $poolRepository;
-
-
- /**
- * @param EntityManager $em
- */
- public function __construct(EntityManager $em)
- {
- $this->poolRepository = $em->getRepository(Pool::class);
- }
-
- /**
- * Retorna el primer pool donde se encuentra el lease
- *
- * @param Lease4 $lease
- *
- * @return Pool
- */
- public function getPoolFromLease(Lease4 $lease)
- {
- $address = ip2long($lease->getAddress());
- $pools = $this->poolRepository->findAll();
- foreach ($pools as $pool) {
- $firstIp = ip2long($pool->getFirstIp());
- $lastIp = ip2long($pool->getLastIp());
-
- if ($firstIp <= $address && $address <= $lastIp) {
- return $pool;
- }
- }
-
- return null;
- }
-
-
- /**
- * Retorna el primer pool donde se encuentra la $fixedIP
- *
- * @param string $fixedIP
- *
- * @return Pool
- */
- public function getPoolFromFixedIP($fixedIP)
- {
- $address = ip2long($fixedIP);
- $pools = $this->poolRepository->findAll();
- foreach ($pools as $pool) {
- $firstIp = ip2long($pool->getFirstIp());
- $lastIp = ip2long($pool->getLastIp());
-
- if ($firstIp <= $address && $address <= $lastIp) {
- return $pool;
- }
- }
-
- return null;
- }
-
- /**
- * @param HostType $hostType
- *
- * @return array
- */
- public function getStaticPoolIPRange(HostType $hostType = null)
- {
- $count = 1;
- $range = [];
- $pools = $this->poolRepository->findAllStaticByHostType($hostType);
- foreach ($pools as $pool) {
- $range[] = $pool->getFirstIp();
- $firstIp = ip2long($pool->getFirstIp());
- $lastIp = ip2long($pool->getLastIp());
- $currentIP = $firstIp + 1;
- while ($currentIP <= $lastIp) {
- $range[] = long2ip($currentIP);
- $currentIP++;
- }
- }
- sort($range);
-
- return $range;
- }
-
- }
|