Pārlūkot izejas kodu

feature captive portal

Jean Sumara 5 gadi atpakaļ
vecāks
revīzija
81299ca2a9

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
app/DoctrineMigrations/src/workflow.yml


+ 11 - 1
app/Resources/workflows/workflow_list.yml.dist

@@ -32,6 +32,7 @@ framework:
         - active
         - disable
         - deleted
+        - pre_aviso
       transitions:
         disable_active:
           from: disable
@@ -50,4 +51,13 @@ framework:
           to: deleted
         deleted_active:
           from: deleted
-          to: active
+          to: active
+        active_preaviso:
+          from: active
+          to: pre_aviso
+        preaviso_active:
+          from: pre_aviso
+          to: active
+        preaviso_disable:
+          from: pre_aviso
+          to: disable

+ 9 - 1
src/FTTHBundle/Entity/CaptivePortal.php

@@ -4,12 +4,20 @@ namespace FTTHBundle\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
+use Base\AdminBundle\Traits\TenancyIdTrait;
+use Base\AdminBundle\Traits\TenancyIdTraitInterface;
 
 /**
+ * @ORM\Table
  * @ORM\Entity
  */
-class CaptivePortal
+class CaptivePortal implements TenancyIdTraitInterface
 {
+
+    use ONUTrait;
+    use TenancyIdTrait;
+
+    
     /**
      * @var int
      *

+ 6 - 0
src/FTTHBundle/EventListener/ONUSubscriber.php

@@ -15,6 +15,7 @@ use FTTHBundle\Entity\VLanID;
 use FTTHBundle\Entity\VLanProfile;
 use FTTHBundle\Factory\ExceptionFactory;
 use FTTHBundle\Service\ClientProxyService;
+use FTTHBundle\Service\ONUService;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\Session\SessionInterface;
 use Symfony\Component\Translation\TranslatorInterface;
@@ -121,6 +122,11 @@ class ONUSubscriber implements EventSubscriber
                 if(isset($args->getEntityChangeSet()['clientId']) && $args->getOldValue('clientId') != $entity->getClientId()){
                     $this->setStateOnu($entity);
                 }
+                if(isset($args->getEntityChangeSet()['currentState']) && $args->getOldValue('currentState') != $entity->getCurrentState() && $entity->getCurrentState() == "pre_aviso"){
+                    $this->em = $args->getEntityManager();
+                    $onuService = new ONUService($this->em);
+                    $onuService->setIPCaptivePortal($entity);
+                }
             }
         }catch(Exception $ex){
             ExceptionFactory::make($ex->getMessage());

+ 3 - 1
src/FTTHBundle/Resources/translations/FTTHBundle.es.yml

@@ -430,4 +430,6 @@ Set 0 to disable autodiscovery or set a x number to scan each x minutes the ONUs
 Profile to set the ONUs by autodiscovery: Perfíl con el cual se configurarán las ONUs mediante Autodiscovery.
 errors.duplicate_mac_key: La MAC se encuentra asignada a otra ONU
 warning.disabled.fields: Para evitar problemas en la configuración, algunos campos fueron deshabilitados
-Nap_Delete_Deneid: No puede eliminar un NAP que tiene ONUs asociadas
+Nap_Delete_Deneid: No puede eliminar un NAP que tiene ONUs asociadas
+portalcaptive.ip.required: Es necesario informar a la ip en la configuración del portal prudente
+portalcaptive.range.required: Es necesario informar el rango de ip en la configuración del portal prudente

+ 163 - 0
src/FTTHBundle/Service/CalcIPV4Address.php

@@ -0,0 +1,163 @@
+<?php
+
+
+namespace FTTHBundle\Service;
+
+class CalcIPV4Address {
+    // O endereço IP
+    public $endereco;
+    
+    // O cidr
+    public $cidr;
+    
+    // O endereço IP 
+    public $endereco_completo;
+
+    /**
+     * O construtor apenas configura as propriedades da classe
+     */
+    public function __construct( $endereco_completo ) {
+        $this->endereco_completo = $endereco_completo;
+        $this->valida_endereco();
+    }
+    
+    /**
+     * Valida o endereço IPv4
+     */
+    public function valida_endereco() {
+        // Expressão regular
+        $regexp = '/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/[0-9]{1,2}$/';
+        
+        // Verifica o IP/CIDR
+        if ( ! preg_match( $regexp, $this->endereco_completo ) ) {
+            return false;
+        }
+        
+        // Separa o IP do prefixo CIDR
+        $endereco = explode( '/', $this->endereco_completo );
+        var_dump($endereco);
+        exit;
+        
+        // CIDR
+        $this->cidr = (int) $endereco[1];
+        
+        // Endereço IPv4
+        $this->endereco = $endereco[0];
+        
+        // Verifica o prefixo
+        if ( $this->cidr > 32 ) {
+            return false;
+        }
+        
+        // Faz um loop e verifica cada número do IP
+        foreach( explode( '.', $this->endereco ) as $numero ) {
+        
+            // Garante que é um número
+            $numero = (int) $numero;
+            
+            // Não pode ser maior que 255 nem menor que 0
+            if ( $numero > 255 || $numero < 0 ) {
+                return false;
+            }
+        }
+        
+        // IP "válido" (correto)
+        return true;
+    }
+
+    /* Retorna o endereço IPv4/CIDR */
+    public function endereco_completo() { 
+        return ( $this->endereco_completo ); 
+    }
+
+    /* Retorna o endereço IPv4 */
+    public function endereco() { 
+        return ( $this->endereco ); 
+    }
+
+    /* Retorna o prefixo CIDR */
+    public function cidr() { 
+        return ( $this->cidr ); 
+    }
+
+    /* Retorna a máscara de sub-rede */
+    public function mascara() {
+        if ( $this->cidr() == 0 ) {
+            return '0.0.0.0';
+        }
+
+        return ( 
+            long2ip(
+                ip2long("255.255.255.255") << ( 32 - $this->cidr ) 
+            )
+        );
+    }
+
+    /* Retorna a rede na qual o IP está */
+    public function rede() {
+        if ( $this->cidr() == 0 ) {
+            return '0.0.0.0';
+        }
+
+        return (
+            long2ip( 
+                ( ip2long( $this->endereco ) ) & ( ip2long( $this->mascara() ) )
+            )
+        );
+    }
+
+    /* Retorna o IP de broadcast da rede */
+    public function broadcast() {
+        if ( $this->cidr() == 0 ) {
+            return '255.255.255.255';
+        }
+        
+        return (
+            long2ip( ip2long($this->rede() ) | ( ~ ( ip2long( $this->mascara() ) ) ) )
+        );
+    }
+    
+    /* Retorna o número total de IPs (com a rede e o broadcast) */
+    public function total_ips() {
+        return( pow(2, ( 32 - $this->cidr() ) ) );
+    }
+    
+    /* Retorna os número de IPs que podem ser utilizados na rede */
+    public function ips_rede() {
+        if ( $this->cidr() == 32 ) {
+            return 0;
+        } elseif ( $this->cidr() == 31 ) {
+            return 0;
+        }
+        
+        return( abs( $this->total_ips() - 2 ) );
+    }
+    
+    /* Retorna os número de IPs que podem ser utilizados na rede */
+    public function primeiro_ip() {
+        if ( $this->cidr() == 32 ) {
+            return null;
+        } elseif ( $this->cidr() == 31 ) {
+            return null;
+        } elseif ( $this->cidr() == 0 ) {
+            return '0.0.0.1';
+        }
+        
+        return (
+            long2ip( ip2long( $this->rede() ) | 1 )
+        );
+    }
+    
+    /* Retorna os número de IPs que podem ser utilizados na rede */
+    public function ultimo_ip() {
+        if ( $this->cidr() == 32 ) {
+            return null;
+        } elseif ( $this->cidr() == 31 ) {
+            return null;
+        }
+    
+        return (
+            long2ip( ip2long( $this->rede() ) | ( ( ~ ( ip2long( $this->mascara() ) ) ) - 1 ) )
+        );
+    }
+}

+ 31 - 0
src/FTTHBundle/Service/ONUService.php

@@ -0,0 +1,31 @@
+<?php
+namespace FTTHBundle\Service;
+
+use Exception;
+use FTTHBundle\Entity\ONU;
+
+class ONUService {
+
+    private $em;
+
+    public function __construct($em)
+    {
+        $this->em = $em;
+    }
+
+    public function setIPCaptivePortal(ONU $entity){
+        $query = $this->em->createQuery("
+            SELECT o FROM FTTHBundle:CaptivePortal o
+        ");
+
+        $captivePortal = $query->getOneOrNullResult();
+
+        if(is_null($captivePortal) || empty($captivePortal->getIp())){
+            throw new Exception('Es necesario informar a la ip en la configuración del portal prudente');
+        }else if(is_null($captivePortal->getIpRange())){
+            throw new Exception('Es necesario informar el rango de ip en la configuración del portal prudente');
+        }
+
+        $calculadoraIPv4 = new CalcIPV4Address('192.168.0.1/24');
+    }
+}