diff --git a/src/Cacic/RelatorioBundle/Resources/views/Hardware/rel_wmi.html.twig b/src/Cacic/RelatorioBundle/Resources/views/Hardware/rel_wmi.html.twig
index a7ed3f7..8e4ca5a 100755
--- a/src/Cacic/RelatorioBundle/Resources/views/Hardware/rel_wmi.html.twig
+++ b/src/Cacic/RelatorioBundle/Resources/views/Hardware/rel_wmi.html.twig
@@ -37,7 +37,7 @@
{{ reg.nmLocal }} |
{{ reg.nmRede }} / {{ reg.teIpRede }} |
{{ reg.nmPropertyName }} |
- {{ reg.numComp }} |
+ {{ reg.numComp }} |
{{ reg.teClassPropertyValue }} |
{% else %}
diff --git a/src/Cacic/WSBundle/Controller/NeoController.php b/src/Cacic/WSBundle/Controller/NeoController.php
new file mode 100644
index 0000000..9bbc1d6
--- /dev/null
+++ b/src/Cacic/WSBundle/Controller/NeoController.php
@@ -0,0 +1,232 @@
+maxIdleTime = $maxIdleTime;
+ }
+
+ public function indexAction(Request $request)
+ {
+ $logger = $this->get('logger');
+ //$logger->debug("222222222222222222222222222222222222 ");
+
+ $response = new JsonResponse();
+
+
+ if ( $request->isMethod('POST') ) {
+ $response->setStatusCode(200);
+ } else {
+ $response->setStatusCode(403);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Faz login do agente
+ */
+ public function loginAction(Request $request)
+ {
+ $logger = $this->get('logger');
+ $data = $request->getContent();
+
+ // JSON Serialization
+ //$usuario = $serializer->deserialize($data, 'Usuario', 'json');
+ $usuario = json_decode($data);
+ $logger->debug("JSON login received data".print_r($usuario, true));
+ $_SERVER['SERVER_ADDR'] = $this->getRequest()->getUri();
+
+ $auth = $this->forward('CacicCommonBundle:Security:login', array(
+ 'username' => $usuario->user,
+ 'password' => $usuario->senha,
+ ));
+
+ $session = $request->getSession();
+
+ $auth->setContent(json_encode(array(
+ 'session' => $session->getId()
+ )));
+
+ return $auth;
+ }
+
+ /**
+ * Controller só para testar a validação da sessão
+ */
+
+ public function checkSessionAction(Request $request)
+ {
+ $logger = $this->get('logger');
+ $data = $request->getContent();
+ $response = new JsonResponse();
+ $session = $request->getSession();
+ if (empty($session)) {
+ $response->setStatusCode('401');
+ }
+ $session_valid = $this->checkSession($session);
+ if ($session_valid) {
+ $response->setStatusCode('200');
+ } else {
+ $response->setStatusCode('401');
+ }
+
+ return $response;
+ }
+
+ public function getTestAction(Request $request)
+ {
+ //1 - Verificar se computador existe
+ $logger = $this->get('logger');
+ $status = $request->getContent();
+ $em = $this->getDoctrine()->getManager();
+
+ $response = new JsonResponse();
+ $dados = json_decode($status);
+ $logger->debug("JSON get Test status".print_r($dados, true));
+
+ $so_json = $dados['so'];
+
+ $rede_json = $dados['rede'];
+ $rede1 = $rede_json[0];
+ $mac_json = $rede1['mac'];
+ $rede = $rede1['interface'];
+
+ $so = $em->getRepository('CacicCommonBundle:So')->findOneBy(array('te_so' => $so_json));
+ $mac = $em->getRepository('CacicCommonBundle:Computador')->findOneBy(array('te_node_address'=> $mac_json));
+ $logger->debug("$so".print_r($so, true));
+ $logger->debug("$mac".print_r($mac, true));
+
+ // Regra: MAC e SO são únicos e não podem ser nulos
+ $computador = $em->findOneBy( array( 'te_node_address'=> $mac, 'te_so'=> $so->getTeSo()) );
+ $data = new \DateTime('NOW'); //armazena data Atual
+
+ //2 - Insere computador que não existe
+ if( empty ( $computador ) )
+ {
+ $computador = new Computador();
+
+ $computador->setTeNodeAddress( $mac );
+ $computador->setIdSo( $so );
+ $computador->setIdRede( $rede );
+ $computador->setDtHrInclusao( $data);
+ $computador->setTePalavraChave( $request->get('PHP_AUTH_PW') );
+
+ $em->persist( $computador );
+
+ }
+
+ /*
+ $computador->setDtHrUltAcesso( $data );
+ $computador->setTeVersaoCacic( $te_versao_cacic );
+ $computador->setTeVersaoGercols( $te_versao_gercols );
+ $computador->setTeUltimoLogin( TagValueHelper::getValueFromTags( 'UserName' ,$computer_system ) );
+ $computador->setTeIpComputador( TagValueHelper::getValueFromTags( 'IPAddress' ,$network_adapter ) );
+ $computador->setNmComputador( TagValueHelper::getValueFromTags( 'Caption' ,$computer_system ));
+ $this->getEntityManager()->persist( $computador );
+
+ $acoes = $this->getEntityManager()->getRepository('CacicCommonBundle:Acao')->findAll();
+ */
+
+ // 2.1 - Se existir, atualiza hora de inclusão
+ else
+ {
+ $update = $em->getRepository('CacicCommonBundle:Computador')->findBy(aresponserray('te_node_address'=> $mac, 'te_so'=> $so->getTeSo()));
+
+ $update->setDtHrInclusao($data);
+
+ //Atualiza hora de inclusão
+ $em->persist($update);
+ $em->flush();
+
+
+ }
+
+ // 3 - Grava no log de acesso
+ //Só adiciona se o último registro foi em data diferente da de hoje
+
+ $data_acesso = new \DateTime();
+ $hoje = $data_acesso->format('Y-m-d');
+
+ $ultimo_acesso = $em->getRepository('CacicCommonBundle:LogAcesso')->ultimoAcesso( $computador->getIdComputador() );
+ if (empty($ultimo_acesso)) {
+ // Se for o primeiro registro grava o acesso do computador
+ $logger->debug("Último acesso não encontrado. Registrando acesso para o computador $computador em $hoje");
+
+ $log_acesso = new LogAcesso();
+ $log_acesso->setIdComputador($computador);
+ $log_acesso->setData($data_acesso);
+
+ // Grava o log
+ $em->persist($log_acesso);
+ $em->flush();
+
+ } else {
+ $dt_ultimo_acesso = $ultimo_acesso->getData()->format('Y-m-d');
+
+ // Adiciona se a data de útimo acesso for diferente do dia de hoje
+ if ($hoje != $dt_ultimo_acesso) {
+ $logger->debug("Inserindo novo registro de acesso para o computador $computador em $hoje");
+
+ $log_acesso = new LogAcesso();
+ $log_acesso->setIdComputador($computador);
+ $log_acesso->setData($data_acesso);
+
+ // Grava o log
+ $em->persist($log_acesso);
+ $em->flush();
+ }
+ }
+
+ // 4 - Retorna chave de criptografia
+
+
+ $response->setStatusCode('200');
+ return $response;
+
+
+ }
+
+ /**
+ * Função para validar a sessão
+ */
+ public function checkSession(Session $session) {
+ $session->getMetadataBag()->getCreated();
+ $session->getMetadataBag()->getLastUsed();
+
+ if(time() - $session->getMetadataBag()->getLastUsed() > $this->maxIdleTime) {
+ $session->invalidate();
+ throw new SessionExpired(); // direciona para a página de sessão expirada
+ return false;
+ }
+ else{
+ return true;
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/Cacic/WSBundle/Resources/config/routing.yml b/src/Cacic/WSBundle/Resources/config/routing.yml
index f7d5cf6..283b2c0 100644
--- a/src/Cacic/WSBundle/Resources/config/routing.yml
+++ b/src/Cacic/WSBundle/Resources/config/routing.yml
@@ -43,3 +43,25 @@ cacic_ws_srcacic_set_session:
cacic_ws_srcacic_ayth_client:
pattern: /srcacic/auth/client
defaults: { _controller: CacicWSBundle:Coleta:srCacicAuthClient }
+
+cacic_neo_home:
+ pattern: /neo
+ defaults: { _controller: CacicWSBundle:Neo:index }
+ schemes: [https]
+
+cacic_neo_home_login:
+ pattern: /neo/login
+ defaults: { _controller: CacicWSBundle:Neo:login }
+ #schemes: [https]
+
+cacic_neo_home_checksession:
+ pattern: /neo/checkSession
+ defaults: { _controller: CacicWSBundle:Neo:checkSession }
+ #schemes: [https]
+
+cacic_neo_home_gettest:
+ pattern: /neo/getTest
+ defaults: { _controller: CacicWSBundle:Neo:getTest }
+ #schemes: [https]
+
+
diff --git a/src/Cacic/WSBundle/Tests/Controller/DefaultControllerTest.php b/src/Cacic/WSBundle/Tests/Controller/DefaultControllerTest.php
index 046efb4..d92385a 100644
--- a/src/Cacic/WSBundle/Tests/Controller/DefaultControllerTest.php
+++ b/src/Cacic/WSBundle/Tests/Controller/DefaultControllerTest.php
@@ -12,6 +12,6 @@ class DefaultControllerTest extends WebTestCase
$crawler = $client->request('GET', '/hello/Fabien');
- $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
+ $this->assertFalse($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
}
}
diff --git a/src/Cacic/WSBundle/Tests/Controller/NeoControllerTest.php b/src/Cacic/WSBundle/Tests/Controller/NeoControllerTest.php
new file mode 100644
index 0000000..3fdf66f
--- /dev/null
+++ b/src/Cacic/WSBundle/Tests/Controller/NeoControllerTest.php
@@ -0,0 +1,179 @@
+client = static::createClient();
+ $this->container = $this->client->getContainer();
+ }
+
+ /**
+ * Testa a comunicação SSL
+ */
+ public function testCommunication()
+ {
+ $client = $this->client;
+ $client->request(
+ 'POST',
+ '/ws/neo',
+ array(),
+ array(),
+ array(
+ 'CONTENT_TYPE' => 'application/json',
+ 'HTTPS' => true
+ ),
+ '{}'
+ );
+
+
+ $logger = $this->container->get('logger');
+ //$logger->debug("11111111111111111111111111111111111111 ".print_r($client->getRequest()->getUriForPath('/'), true));
+
+ $this->assertEquals(301,$client->getResponse()->getStatusCode());
+ }
+
+ /**
+ * test login
+ */
+ public function testLogin()
+ {
+
+ $logger = $this->container->get('logger');
+ $this->client->request(
+ 'POST',
+ '/ws/neo/login',
+ array(),
+ array(),
+ array(
+ 'CONTENT_TYPE' => 'application/json',
+ //'HTTPS' => true
+ ),
+ '{ "user" : "02128544106",
+ "senha": "159753"
+ }'
+ );
+ $logger->debug("Dados JSON de login enviados \n".$this->client->getRequest()->getcontent());
+
+ $response = $this->client->getResponse();
+ $data = $response->getContent();
+ $logger->debug("Response data: \n".print_r($data,true));
+ // JSON Serialization
+ $json = json_decode($data, true);
+ $session = $json['session'];
+
+ $this->assertTrue(is_string($session));
+
+
+ }
+
+ /**
+ *Teste da sessão
+ */
+ public function testSession() {
+ $logger = $this->container->get('logger');
+ $this->client->request(
+ 'POST',
+ '/ws/neo/login',
+ array(),
+ array(),
+ array(
+ 'CONTENT_TYPE' => 'application/json',
+ //'HTTPS' => true
+ ),
+ '{ "user" : "02128544106",
+ "senha": "159753"
+ }'
+ );
+ $logger->debug("Dados JSON de login enviados \n".$this->client->getRequest()->getcontent());
+
+ $response = $this->client->getResponse();
+ $data = $response->getContent();
+ $logger->debug("Response data: \n".print_r($data,true));
+ // JSON Serialization
+ $json = json_decode($data, true);
+ $session = $json['session'];
+
+ // Testa a sessão
+ $this->client->request(
+ 'POST',
+ '/ws/neo/checkSession',
+ array(),
+ array(),
+ array(
+ 'CONTENT_TYPE' => 'application/json',
+ //'HTTPS' => true
+ ),
+ '{ "session" : $session
+ }'
+ );
+
+ $response = $this->client->getResponse();
+ $status = $response->getStatusCode();
+ $logger->debug("Response status: $status");
+
+ $this->assertEquals($status, 200);
+ }
+
+ /**
+ * Testa inserção do computador se não existir
+ */
+ public function testGetTest() {
+ $logger = $this->container->get('logger');
+ $this->client->request(
+ 'POST',
+ '/ws/neo/getTest',
+ array(),
+ array(),
+ array(
+ 'CONTENT_TYPE' => 'application/json',
+ //'HTTPS' => true
+ ),
+ '{ "so" : "2.6.1",
+ "rede": [
+ { "mac" : "e0:3f:49:e4:72:75",
+ "ip" : "10.1.0.137",
+ "interface": "Rede Local"
+ },
+ { "mac" : "e0:3f:49:e4:72:76",
+ "ip" : "10.1.0.138",
+ "interface": "Rede Local"
+ }
+ ]
+ }'
+ );
+ $logger->debug("Dados JSON do computador enviados \n".$this->client->getRequest()->getcontent());
+
+ $response = $this->client->getResponse();
+ $status = $response->getStatusCode();
+ $logger->debug("Response status: $status");
+
+ $this->assertEquals($status, 200);
+
+ }
+
+
+ /**
+ * Método que apaga todos os dados criados no teste
+ */
+ public function tearDown() {
+
+ }
+
+}
\ No newline at end of file
--
libgit2 0.21.2