Commit c57f228b6a9aab6d8aecaa24741c57846dbfb68b
Exists in
master
and in
1 other branch
Corrige atribuição de IP do computador e escolha de subrede na coleta
Showing
4 changed files
with
57 additions
and
9 deletions
Show diff stats
src/Cacic/CommonBundle/Entity/ComputadorRepository.php
| ... | ... | @@ -316,6 +316,12 @@ class ComputadorRepository extends EntityRepository |
| 316 | 316 | |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | + // Atualiza subrede se houve mudança de subrede para o computador | |
| 320 | + if ($computador->getIdRede() != $rede) { | |
| 321 | + #error_log("Atualizando subrede paara o computador ".$computador->getTeIpComputador()." Antiga: ".$computador->getIdRede()->getNmRede()." | Nova: ".$rede->getNmRede()); | |
| 322 | + $computador->setIdRede($rede); | |
| 323 | + } | |
| 324 | + | |
| 319 | 325 | $computador->setDtHrUltAcesso( $data ); |
| 320 | 326 | $computador->setTeVersaoCacic( $te_versao_cacic ); |
| 321 | 327 | $computador->setTeVersaoGercols( $te_versao_gercols ); | ... | ... |
src/Cacic/CommonBundle/Entity/RedeRepository.php
| ... | ... | @@ -142,7 +142,7 @@ class RedeRepository extends EntityRepository |
| 142 | 142 | /* |
| 143 | 143 | * Método responsável por coletar verificar dados de rede |
| 144 | 144 | */ |
| 145 | - public function getDadosRedePreColeta( $ip_computador, $netmask ) | |
| 145 | + public function getDadosRedePreColeta( $ip_computador, $netmask = '255.255.255.0' ) | |
| 146 | 146 | { |
| 147 | 147 | |
| 148 | 148 | //obtem IP da Rede que a maquina coletada pertence |
| ... | ... | @@ -153,6 +153,15 @@ class RedeRepository extends EntityRepository |
| 153 | 153 | //error_log("Endereço IP do computador: $ip_computador \nEndereço Broadcast da rede: $te_ip_rede"); |
| 154 | 154 | $rede = $this->findOneBy( array( 'teIpRede'=> $te_ip_rede ) ); //procura rede |
| 155 | 155 | |
| 156 | + // Tenta uma última vez com outras máscaras | |
| 157 | + if (empty($rede)) { | |
| 158 | + $cidr = IPv4::mask2cidr('255.255.255.128'); | |
| 159 | + $ipv4 = new IPv4($ip_computador, $cidr); | |
| 160 | + | |
| 161 | + $te_ip_rede = $ipv4->network(); | |
| 162 | + $rede = $this->findOneBy( array( 'teIpRede'=> $te_ip_rede ) ); //procura rede | |
| 163 | + } | |
| 164 | + | |
| 156 | 165 | // Se a rede não existir, procuro uma com endereço 0.0.0.0 |
| 157 | 166 | if (empty($rede)) { |
| 158 | 167 | $rede = $this->findOneBy( array( 'teIpRede'=> '0.0.0.0' ) ); | ... | ... |
src/Cacic/WSBundle/Controller/ColetaController.php
| ... | ... | @@ -63,8 +63,12 @@ class ColetaController extends Controller |
| 63 | 63 | $computador = $this->getDoctrine()->getRepository('CacicCommonBundle:Computador')->findOneBy( array('idSo'=>$so, 'teNodeAddress'=>$te_node_adress) ); |
| 64 | 64 | $netmask = TagValueHelper::getValueFromTags( 'IPSubnet', $strNetworkAdapterConfiguration ); |
| 65 | 65 | $ip_computador = $request->get('te_ip_computador'); |
| 66 | - $ip_computador = empty( $ip_computador ) ?: TagValueHelper::getValueFromTags( 'IPAddress', $strNetworkAdapterConfiguration ); | |
| 67 | - $ip_computador = empty( $ip_computador ) ?: $request->getClientIp(); | |
| 66 | + if ( empty($ip_computador) ){ | |
| 67 | + $ip_computador = TagValueHelper::getValueFromTags( 'IPAddress', $strNetworkAdapterConfiguration ); | |
| 68 | + } | |
| 69 | + if (empty($ip_computador)) { | |
| 70 | + $ip_computador = $request->getClientIp(); | |
| 71 | + } | |
| 68 | 72 | |
| 69 | 73 | $rede = $this->getDoctrine()->getRepository('CacicCommonBundle:Rede')->getDadosRedePreColeta( $ip_computador, $netmask ); |
| 70 | 74 | //$local = $this->getDoctrine()->getRepository('CacicCommonBundle:Local')->findOneBy(array( 'idLocal' => $rede->getIdLocal() )); |
| ... | ... | @@ -274,6 +278,13 @@ class ColetaController extends Controller |
| 274 | 278 | $data = new \DateTime('NOW'); |
| 275 | 279 | $netmask = TagValueHelper::getValueFromTags( 'IPSubnet', $strNetworkAdapterConfiguration ); |
| 276 | 280 | $ip_computador = $request->get('te_ip_computador'); |
| 281 | + if ( empty($ip_computador) ){ | |
| 282 | + $ip_computador = TagValueHelper::getValueFromTags( 'IPAddress', $strNetworkAdapterConfiguration ); | |
| 283 | + } | |
| 284 | + if (empty($ip_computador)) { | |
| 285 | + $ip_computador = $request->getClientIp(); | |
| 286 | + } | |
| 287 | + | |
| 277 | 288 | $rede = $this->getDoctrine()->getRepository('CacicCommonBundle:Rede')->getDadosRedePreColeta( $ip_computador, $netmask ); |
| 278 | 289 | |
| 279 | 290 | $te_node_adress = TagValueHelper::getValueFromTags( 'MACAddress', $strNetworkAdapterConfiguration ); | ... | ... |
src/Cacic/WSBundle/Controller/DefaultController.php
| ... | ... | @@ -39,8 +39,12 @@ class DefaultController extends Controller |
| 39 | 39 | |
| 40 | 40 | $strNetworkAdapterConfiguration = OldCacicHelper::deCrypt( $request, $request->get('NetworkAdapterConfiguration') ); |
| 41 | 41 | $ip_computador = $request->get('te_ip_computador'); |
| 42 | - $ip_computador = empty( $ip_computador ) ?: TagValueHelper::getValueFromTags( 'IPAddress', $strNetworkAdapterConfiguration ); | |
| 43 | - $ip_computador = empty( $ip_computador ) ?: $request->getClientIp(); | |
| 42 | + if ( empty($ip_computador) ){ | |
| 43 | + $ip_computador = TagValueHelper::getValueFromTags( 'IPAddress', $strNetworkAdapterConfiguration ); | |
| 44 | + } | |
| 45 | + if (empty($ip_computador)) { | |
| 46 | + $ip_computador = $request->getClientIp(); | |
| 47 | + } | |
| 44 | 48 | |
| 45 | 49 | $insucesso = new InsucessoInstalacao(); |
| 46 | 50 | $insucesso->setTeIpComputador( $ip_computador ); |
| ... | ... | @@ -72,17 +76,30 @@ class DefaultController extends Controller |
| 72 | 76 | $strComputerSystem = OldCacicHelper::deCrypt( $request, $request->get('ComputerSystem') ); |
| 73 | 77 | $strOperatingSystem = OldCacicHelper::deCrypt( $request, $request->request->get('OperatingSystem') ); |
| 74 | 78 | |
| 79 | + $teste = $strNetworkAdapterConfiguration; | |
| 80 | + #$logger->debug("00000000000000000000000000000000000000000000 ".print_r($teste, true)); | |
| 81 | + | |
| 75 | 82 | $te_node_address = TagValueHelper::getValueFromTags( 'MACAddress', $strNetworkAdapterConfiguration ); |
| 76 | 83 | $netmask = TagValueHelper::getValueFromTags( 'IPSubnet', $strNetworkAdapterConfiguration ); |
| 77 | 84 | $te_so = $request->get( 'te_so' ); |
| 78 | 85 | $ultimo_login = TagValueHelper::getValueFromTags( 'UserName' , $strComputerSystem); |
| 79 | 86 | $ip_computador = $request->get('te_ip_computador'); |
| 80 | - $ip_computador = empty( $ip_computador ) ?: TagValueHelper::getValueFromTags( 'IPAddress', $strNetworkAdapterConfiguration ); | |
| 81 | - $ip_computador = empty( $ip_computador ) ?: $request->getClientIp(); | |
| 87 | + #$logger->debug("11111111111111111111111111111111111: $ip_computador"); | |
| 88 | + if ( empty($ip_computador) ){ | |
| 89 | + $ip_computador = TagValueHelper::getValueFromTags( 'IPAddress', $strNetworkAdapterConfiguration ); | |
| 90 | + #$logger->debug("555555555555555555555555555555555555555555: $ip_computador"); | |
| 91 | + } | |
| 92 | + #$logger->debug("22222222222222222222222222222222222: $ip_computador"); | |
| 93 | + if (empty($ip_computador)) { | |
| 94 | + $ip_computador = $request->getClientIp(); | |
| 95 | + } | |
| 96 | + #$logger->debug("333333333333333333333333333333333333: $ip_computador"); | |
| 97 | + $logger->debug("Teste de Conexão! Ip do computador: $ip_computador Máscara da rede: $netmask"); | |
| 82 | 98 | |
| 83 | 99 | //vefifica se existe SO coletado se não, insere novo SO |
| 84 | 100 | $so = $this->getDoctrine()->getRepository('CacicCommonBundle:So')->createIfNotExist( $te_so ); |
| 85 | 101 | $rede = $this->getDoctrine()->getRepository('CacicCommonBundle:Rede')->getDadosRedePreColeta( $ip_computador, $netmask ); |
| 102 | + #$logger->debug("444444444444444444444444444444444444: $netmask | ".$rede->getNmRede()); | |
| 86 | 103 | $computador = $this->getDoctrine()->getRepository('CacicCommonBundle:Computador')->getComputadorPreCole( $request, $te_so, $te_node_address, $rede, $so, $ip_computador ); |
| 87 | 104 | //$local = $this->getDoctrine()->getRepository('CacicCommonBundle:Local')->findOneBy(array( 'idLocal' => $rede->getIdLocal() )); |
| 88 | 105 | $local = $rede->getIdLocal(); |
| ... | ... | @@ -155,8 +172,13 @@ class DefaultController extends Controller |
| 155 | 172 | $strNetworkAdapterConfiguration = OldCacicHelper::deCrypt( $request, $request->get('NetworkAdapterConfiguration') ); |
| 156 | 173 | $netmask = TagValueHelper::getValueFromTags( 'IPSubnet', $strNetworkAdapterConfiguration ); |
| 157 | 174 | $ip_computador = $request->get('te_ip_computador'); |
| 158 | - $ip_computador = empty( $ip_computador ) ?: TagValueHelper::getValueFromTags( 'IPAddress', $strNetworkAdapterConfiguration ); | |
| 159 | - $ip_computador = empty( $ip_computador ) ?: $request->getClientIp(); | |
| 175 | + if ( empty($ip_computador) ){ | |
| 176 | + $ip_computador = TagValueHelper::getValueFromTags( 'IPAddress', $strNetworkAdapterConfiguration ); | |
| 177 | + #$logger->debug("555555555555555555555555555555555555555555: $ip_computador"); | |
| 178 | + } | |
| 179 | + if (empty($ip_computador)) { | |
| 180 | + $ip_computador = $request->getClientIp(); | |
| 181 | + } | |
| 160 | 182 | |
| 161 | 183 | $te_node_adress = TagValueHelper::getValueFromTags( 'MACAddress', OldCacicHelper::deCrypt( $request, $request->get('NetworkAdapterConfiguration'))); |
| 162 | 184 | $so = $this->getDoctrine()->getRepository('CacicCommonBundle:So')->findOneBy( array('teSo'=>$request->get( 'te_so' ))); | ... | ... |