Commit 3eeb702c68048491921e586b712f3087a9b514e0

Authored by Eduardo Santos
1 parent 1c3f244a
Exists in master

Mudança na atualização de subredes com base no tipo de SO

src/Cacic/CommonBundle/Controller/AgenteController.php
... ... @@ -22,6 +22,7 @@ use ZipArchive;
22 22 class AgenteController extends Controller {
23 23  
24 24 public function indexAction(Request $request) {
  25 + $em = $this->getDoctrine()->getManager();
25 26 $logger = $this->get('logger');
26 27 // Cria diretório dos agentes se não existir
27 28 $rootDir = $this->container->get('kernel')->getRootDir();
... ... @@ -36,132 +37,62 @@ class AgenteController extends Controller {
36 37 mkdir($cacicDir);
37 38 }
38 39  
39   - $linuxDir = $cacicDir . "linux/";
40   - if (!is_dir($linuxDir)) {
41   - mkdir($linuxDir);
42   - }
43   -
44   - $windowsDir = $cacicDir . "windows/";
45   - if (!is_dir($windowsDir)) {
46   - mkdir($windowsDir);
47   - }
  40 + #$linuxDir = $cacicDir . "linux/";
  41 + #if (!is_dir($linuxDir)) {
  42 + # mkdir($linuxDir);
  43 + #}
  44 + #
  45 + #$windowsDir = $cacicDir . "windows/";
  46 + #if (!is_dir($windowsDir)) {
  47 + # mkdir($windowsDir);
  48 + #}
48 49  
49 50  
50 51 $outrosDir = $downloadsDir . "outros/";
51 52 if (!is_dir($outrosDir)) {
52 53 mkdir($outrosDir);
53 54 }
  55 + // Carrega a lista de Agentes por plataforma
  56 + $tipo_so = $em->getRepository('CacicCommonBundle:TipoSo')->findAll();
54 57  
55 58  
56   - $form = $this->createForm( new AgenteType() );
  59 + $form = $this->createForm( new AgenteType(), null, array(
  60 + 'tipo_so' => $tipo_so
  61 + ));
57 62 $locale = $request->getLocale();
58 63  
59   - // Constrói array de arquivos e hashes
60   - $finder = new Finder();
61   - $saida = array();
62   - $base_url = $request->getBaseUrl();
63   - $base_url = preg_replace('/\/app.*.php/', "/", $base_url);
64   -
65   - // Primeiro tratamos agentes Linux
66   - // A regra é que o agente mais atual estará na pasta current
67   - $finder->directories()->in($linuxDir);
68   - $saida['linux']['versions'] = array();
69   - foreach($finder as $version) {
70   - $agentes = new Finder();
71   - if ($version->getFileName() == 'current') {
72   - continue;
73   - }
74   - $saida['linux']['versions'][$version->getFileName()] = array();
75   - $agentes->files()->in($version->getRealPath());
76   - foreach ($agentes as $file) {
77   - array_push($saida['linux']['versions'][$version->getFileName()], array(
78   - 'name' => $file->getFileName(),
79   - 'download_url' => $base_url . 'downloads/cacic/linux/' . $version->getFileName() . '/' . $file->getFileName(),
80   - 'hash' => md5_file($file->getRealPath()),
81   - 'size' => $file->getSize(),
82   - 'filename' => 'cacic/linux/' . $version->getFileName() . '/' . $file->getFileName()
83   - ));
84   -
85   - }
86   - }
87   - // Get latest version
88   - $current = @basename(@readlink($linuxDir."current"));
89   - $saida['linux']['live_version'] = $current;
90   -
91   - // Aí tratamos Windows
92   - $finder->directories()->in($windowsDir);
93   - $saida['windows']['versions'] = array();
94   - foreach($finder as $version) {
95   - $agentes = new Finder();
96   - if ($version->getFileName() == 'current') {
97   - continue;
98   - }
99   - $saida['windows']['versions'][$version->getFileName()] = array();
100   - $agentes->files()->in($version->getRealPath());
101   - //$logger->debug("1111111111111111111111111111111111111111111 ".$version->getRealPath());
102   - foreach ($agentes as $file) {
103   - //$logger->debug("77777777777777777777777777777777777777777 $file");
104   - array_push($saida['windows']['versions'][$version->getFileName()], array(
105   - 'name' => $file->getFileName(),
106   - 'download_url' => $base_url . 'downloads/cacic/windows/' . $version->getFileName() . '/' . $file->getFileName(),
107   - 'hash' => md5_file($file->getRealPath()),
108   - 'size' => $file->getSize(),
109   - 'filename' => 'cacic/windows/' . $version->getFileName() . '/' . $file->getFileName()
110   - ));
111   -
112   - }
113   - }
114   - // Get latest version
115   - $current = @basename(@readlink($windowsDir."current"));
116   - $saida['windows']['live_version'] = $current;
117   -
118 64 //$logger->debug("4444444444444444444444444444444444 ".print_r($saida, true));
119 65  
120 66 if ( $request->isMethod('POST') )
121 67 {
122 68 // Aqui vamos fazer o tratamento dos agentes
123 69 $data = $form->getData();
124   - $data['windows_version'] = $request->get('agentes')['windows_version'];
125   - $data['linux_version'] = $request->get('agentes')['linux_version'];
  70 + $data['version'] = $request->get('agentes')['version'];
126 71 $files = $request->files->get('agentes');
127 72  
128 73 //$logger->debug("99999999999999999999999999999999999 ".print_r($data, true));
129   - if (!empty($files['windows'])) {
  74 + if (!empty($files)) {
130 75 //$logger->debug("88888888888888888888888888888888888888 ".print_r($files['windows'], true));
131   - if (empty($data['windows_version'])) {
  76 + if (empty($data['version'])) {
132 77 $logger->error("O parâmetro versão é obrigatório");
133 78 $this->get('session')->getFlashBag()->add('error', 'O parâmetro versão é obrigatório');
134 79 } else {
135   - $versionDir = $windowsDir . $data['windows_version'];
136   - $result = $this->uploadPackage($files['windows'], $versionDir);
137   - if (!$result) {
138   - $logger->error("Erro na atualização dos Agentes Windows");
139   - $this->get('session')->getFlashBag()->add('error', 'Erro na atualização dos agentes Windows');
140   - } else {
141   - // Make this version current
142   - $logger->debug("Agentes atualizados com sucesso. Ajustando para versão $versionDir");
143   - @unlink("$windowsDir"."current");
144   - symlink($versionDir, "$windowsDir"."current");
145   - $this->get('session')->getFlashBag()->add('success', 'Agentes atualizados com sucesso!');
  80 + // Carrega as versões dos sistemas operacionais
  81 + $versionDir = $cacicDir . $data['version'];
  82 + $result = false;
  83 + foreach($tipo_so as $so) {
  84 + $tipoDir = $versionDir . "/" . $so->getTipo();
  85 + $result = $this->uploadPackage($files[$so->getTipo()], $tipoDir);
146 86 }
147   - }
148   - }
149 87  
150   - if (!empty($files['linux'])) {
151   - if (empty($data['linux_version'])) {
152   - $logger->error("O parâmetro versão é obrigatório");
153   - $this->get('session')->getFlashBag()->add('error', 'O parâmetro versão é obrigatório');
154   - } else {
155   - $versionDir = $linuxDir . $data['linux_version'];
156   - $result = $this->uploadPackage($files['linux'], $versionDir);
157 88 if (!$result) {
158   - $logger->error("Erro na atualização dos Agentes Linux");
159   - $this->get('session')->getFlashBag()->add('error', 'Erro na atualização dos agentes Linux');
  89 + $logger->error("Erro na atualização dos Agentes");
  90 + $this->get('session')->getFlashBag()->add('error', 'Erro na atualização dos agentes');
160 91 } else {
161 92 // Make this version current
162 93 $logger->debug("Agentes atualizados com sucesso. Ajustando para versão $versionDir");
163   - @unlink("$linuxDir"."current");
164   - symlink($versionDir, $linuxDir."current");
  94 + @unlink("$cacicDir"."current");
  95 + symlink($versionDir, "$cacicDir"."current");
165 96 $this->get('session')->getFlashBag()->add('success', 'Agentes atualizados com sucesso!');
166 97 }
167 98 }
... ... @@ -169,6 +100,52 @@ class AgenteController extends Controller {
169 100  
170 101 }
171 102  
  103 + // Constrói array de arquivos e hashes
  104 + $finder = new Finder();
  105 + $saida = array();
  106 + $base_url = $request->getBaseUrl();
  107 + $base_url = preg_replace('/\/app.*.php/', "", $base_url);
  108 +
  109 + // Varre diretório do Cacic
  110 + $finder->depth('== 0');
  111 + $finder->directories()->in($cacicDir);
  112 +
  113 + // Agora busca diretórios de versão
  114 + $saida['tipo_so'] = array();
  115 + foreach($finder as $version) {
  116 + //$logger->debug("1111111111111111111111111111111 ".$version->getFileName());
  117 + if ($version->getFileName() == 'current') {
  118 + continue;
  119 + }
  120 +
  121 + // Agora busca um diretório pra cada tipo de SO
  122 + foreach($tipo_so as $so) {
  123 + $saida['tipo_so'][$so->getTipo()][$version->getFileName()] = array();
  124 + $agentes_path = $version->getRealPath() . "/" . $so->getTipo();
  125 +
  126 + // Cria diretório se não existir
  127 + if (!is_dir($agentes_path)) {
  128 + mkdir($agentes_path);
  129 + }
  130 + $agentes = new Finder();
  131 + $agentes->files()->in($agentes_path);
  132 + foreach($agentes as $file) {
  133 + array_push($saida['tipo_so'][$so->getTipo()][$version->getFileName()], array(
  134 + 'name' => $file->getFileName(),
  135 + 'download_url' => $base_url . '/downloads/cacic/' . $version->getFileName() . '/' . $so->getTipo() . "/" . $file->getFileName(),
  136 + 'hash' => md5_file($file->getRealPath()),
  137 + 'size' => $file->getSize(),
  138 + 'filename' => 'cacic/' . $version->getFileName() . '/' . $so->getTipo() . "/" . $file->getFileName()
  139 + ));
  140 + }
  141 + }
  142 + }
  143 +
  144 +
  145 + // Get latest version
  146 + $current = @basename(@readlink($cacicDir."current"));
  147 + $saida['live_version'] = $current;
  148 +
172 149 return $this->render( 'CacicCommonBundle:Agente:index.html.twig',
173 150 array(
174 151 'local'=>$locale,
... ... @@ -322,7 +299,7 @@ class AgenteController extends Controller {
322 299  
323 300 }
324 301  
325   - $logger->debug("3333333333333333333333333333333333333333 ".print_r($saida, true));
  302 + //$logger->debug("3333333333333333333333333333333333333333 ".print_r($saida, true));
326 303  
327 304 return $this->render( 'CacicCommonBundle:Agente:deploy.html.twig',
328 305 array(
... ...
src/Cacic/CommonBundle/Controller/RedeController.php
... ... @@ -734,40 +734,39 @@ class RedeController extends Controller
734 734  
735 735 // Varro todas as subredes para cada módulo
736 736 $subredes = array();
737   - $windows = array();
738   - $linux = array();
  737 + $saida = array();
739 738 foreach ($subredesOrig as $redeItem) {
740   - // Busca o módulo em cada uma das redes
  739 + // Busca o tipo de SO
741 740 $codigos = array();
742   - foreach ($modulos as $key => $value) {
743   - $idRede = $redeItem['idRede'];
744   - // Verifico se o módulo existe na subrede
745   - $rede = $this->getDoctrine()->getRepository('CacicCommonBundle:RedeVersaoModulo')->subrede($idRede, $key);
746   -
747   - if (empty($rede)) {
748   - // O módulo não foi encontrado. Adiciona o código 1
749   - array_push($codigos, 0);
750   - //$rede = $redeItem[0];
751   - } else {
752   - if ($value['hash'] == $rede[0]['teHash']) {
753   - // Se o hash for igual, adiciona o código 2
754   - array_push($codigos, 2);
755   -
  741 + foreach($modulos as $tipo_so => $file) {
  742 + // Busca o módulo em cada uma das redes
  743 + foreach ($file as $key => $value) {
  744 + $idRede = $redeItem['idRede'];
  745 + // Verifico se o módulo existe na subrede
  746 + $rede = $this->getDoctrine()->getRepository('CacicCommonBundle:RedeVersaoModulo')->subredeFilePath($idRede, $value['filename']);
  747 +
  748 + if (empty($rede)) {
  749 + // O módulo não foi encontrado. Adiciona o código 1
  750 + array_push($codigos, 0);
  751 + //$rede = $redeItem[0];
756 752 } else {
757   - // Se o hash for diferente, adiciona o código 1
758   - array_push($codigos, 1);
  753 + if ($value['hash'] == $rede[0]['teHash']) {
  754 + // Se o hash for igual, adiciona o código 2
  755 + array_push($codigos, 2);
  756 +
  757 + } else {
  758 + // Se o hash for diferente, adiciona o código 1
  759 + array_push($codigos, 1);
  760 + }
759 761 }
760   - }
761 762  
762   - // Cria um array para Windows e outro para Linux
763   - if ($value['tipoSo'] == 'windows') {
764   - $windows[$key] = $value;
765   - } else {
766   - $linux[$key] = $value;
767   - }
  763 + // Array de saída
  764 + $saida[$tipo_so][$value['name']] = $value;
768 765  
  766 + }
769 767 }
770 768  
  769 +
771 770 // Define o elemento HTML para os módulos
772 771 if (in_array(0, $codigos)) {
773 772 // Se o código 0 for encontrato, marcamos o módulo como inexistente
... ... @@ -799,10 +798,11 @@ class RedeController extends Controller
799 798 }
800 799 }
801 800  
  801 + //$logger->debug("111111111111111111111111111111111111111 \n".print_r($saida, true));
  802 +
802 803 return $this->render( 'CacicCommonBundle:Rede:manutencaoNeo.html.twig',
803 804 array(
804   - 'windows'=> $windows,
805   - 'linux' => $linux,
  805 + 'saida'=> $saida,
806 806 'subredes' => $subredes
807 807 )
808 808 );
... ... @@ -839,78 +839,50 @@ class RedeController extends Controller
839 839 // Constrói array de arquivos e hashes
840 840 $saida = array();
841 841 $base_url = $request->getBaseUrl();
842   - $base_url = preg_replace('/\/app.*.php/', "/", $base_url);
  842 + $base_url = preg_replace('/\/app.*.php/', "", $base_url);
843 843  
844 844 // Primeiro tratamos agentes Linux
845 845 // A regra é que o agente mais atual estará na pasta current
846   - $current = basename(readlink($linuxDir."current"));
  846 + $current = basename(readlink($cacicDir."current"));
847 847 $finder = new Finder();
848   - $finder->directories()->in($linuxDir);
  848 + $finder->depth('== 0');
  849 + $finder->directories()->in($cacicDir);
849 850 foreach($finder as $version) {
850   - $agentes = new Finder();
851 851 if ($version->getFileName() == 'current') {
852   - // Aqui considera somente a última versão
853   - $agentes->files()->in($version->getRealPath());
854   - foreach ($agentes as $file) {
855   - if (!empty($nmModulos)) {
856   - // Filtra por nome de módulo
857   - if (!in_array($file->getFileName(), $nmModulos)) {
858   - continue;
  852 + $tipos = new Finder();
  853 + $tipos->depth('== 0');
  854 + $tipos->directories()->in($version->getRealPath());
  855 + foreach($tipos as $tipo_so) {
  856 + // Aqui considera somente a última versão
  857 + $agentes = new Finder();
  858 + $agentes->depth('== 0');
  859 + $agentes->files()->in($tipo_so->getRealPath());
  860 + foreach ($agentes as $file) {
  861 + $filename = 'cacic/' . $version->getFileName() . '/' . $tipo_so->getFileName() . "/" . $file->getFileName();
  862 + if (!empty($nmModulos)) {
  863 + // Filtra por nome de módulo
  864 + if (!in_array($filename, $nmModulos)) {
  865 + continue;
  866 + }
859 867 }
  868 + $saida[$tipo_so->getFileName()][$file->getFileName()] = array(
  869 + 'name' => $file->getFileName(),
  870 + 'download_url' => $base_url . '/downloads/cacic/' . $version->getFileName() . '/' . $tipo_so->getFileName() . "/" . $file->getFileName(),
  871 + 'hash' => md5_file($file->getRealPath()),
  872 + 'size' => $file->getSize(),
  873 + 'filename' => $filename,
  874 + 'versao' => $current,
  875 + 'tipoSo' => $tipo_so->getFileName()
  876 + );
860 877 }
861   - $saida[$file->getFileName()] = array(
862   - 'name' => $file->getFileName(),
863   - 'versao' => $current,
864   - 'download_url' => $base_url . 'downloads/cacic/linux/' . $version->getFileName() . '/' . $file->getFileName(),
865   - 'hash' => md5_file($file->getRealPath()),
866   - 'size' => $file->getSize(),
867   - 'filename' => 'cacic/linux/' . $version->getFileName() . '/' . $file->getFileName(),
868   - 'tipoSo' => 'linux'
869   - );
870 878 }
871   - } else {
872   - continue;
873   - }
874   -
875   - }
876   - // Get latest version
877   - //$current = basename(readlink($cacicDir."current"));
878   - //$saida['linux']['live_version'] = $current;
879 879  
880   - // Aí tratamos Windows
881   - $finder = new Finder();
882   - $finder->directories()->in($windowsDir);
883   - $current = basename(readlink($windowsDir."current"));
884   - foreach($finder as $version) {
885   - $agentes = new Finder();
886   - if ($version->getFileName() == 'current') {
887   - // Aqui considera somente a última versão
888   - $agentes->files()->in($version->getRealPath());
889   - foreach ($agentes as $file) {
890   - if (!empty($nmModulos)) {
891   - // Filtra por nome de módulo
892   - if (!in_array($file->getFileName(), $nmModulos)) {
893   - continue;
894   - }
895   - }
896   - $saida[$file->getFileName()] = array(
897   - 'name' => $file->getFileName(),
898   - 'versao' => $current,
899   - 'download_url' => $base_url . 'downloads/cacic/windows/' . $version->getFileName() . '/' . $file->getFileName(),
900   - 'hash' => md5_file($file->getRealPath()),
901   - 'size' => $file->getSize(),
902   - 'filename' => 'cacic/windows/' . $version->getFileName() . '/' . $file->getFileName(),
903   - 'tipoSo' => 'windows'
904   - );
905   - }
906 880 } else {
907 881 continue;
908 882 }
909 883  
910 884 }
911   - // Get latest version
912   - //$current = basename(readlink($windowsDir."current"));
913   - //$saida['windows']['live_version'] = $current;
  885 +
914 886  
915 887 // Retorna o array com todos os resultados
916 888 return $saida;
... ... @@ -934,66 +906,84 @@ class RedeController extends Controller
934 906 $modulos = $this->modulosNeoArray($request, $modulos);
935 907 //$logger->debug("6666666666666666666666666666666666666 ".print_r($modulos, true));
936 908  
937   - foreach ($modulos as $key => $value)
938   - {
939   - $logger->debug("Nome do módulo: $key");
  909 + foreach($modulos as $tipo => $modulo) {
940 910  
941   - // Carrega dados da rede
942   - $em = $this->getDoctrine()->getManager();
943   - //$arrDadosRede = array( 'rede' => $em->getRepository( 'CacicCommonBundle:Rede' )->listar() );
944   - //Debug::dump($arrDadosRede['rede'][0][0]);
945   - //$arrDadosRede = $arrDadosRede['rede'][0];
946   - $arrDadosRede = array(
947   - 'teServUpdates' => $rede->getTeServUpdates(),
948   - 'tePathServUpdates' => $rede->getTePathServUpdates(),
949   - 'nmUsuarioLoginServUpdatesGerente' => $rede->getNmUsuarioLoginServUpdatesGerente(),
950   - 'teSenhaLoginServUpdatesGerente' => $rede->getTeSenhaLoginServUpdatesGerente(),
951   - 'nuPortaServUpdates' => $rede->getNuPortaServUpdates(),
952   - );
953   -
954   - $strResult = $this->checkAndSend(
955   - $value['name'],
956   - $downloadsDir . $value['filename'],
957   - $arrDadosRede['teServUpdates'],
958   - $arrDadosRede['tePathServUpdates'],
959   - $arrDadosRede['nmUsuarioLoginServUpdatesGerente'],
960   - $arrDadosRede['teSenhaLoginServUpdatesGerente'],
961   - $arrDadosRede['nuPortaServUpdates']
962   - );
963   -
964   - $arrResult = explode('_=_',$strResult);
965   -
966   - if ($arrResult[1] == 'Ok!')
  911 + foreach ($modulo as $key => $value)
967 912 {
968   - // Consertar CRUD no Symfony
969   - $redeVersaoModulo = $em->getRepository('CacicCommonBundle:RedeVersaoModulo')->findOneBy(
970   - array(
971   - 'idRede' => $pIntIdRede,
972   - 'nmModulo' => $value['name']
973   - )
  913 + $logger->debug("Nome do módulo: ".$value['filename']);
  914 +
  915 + // Carrega dados da rede
  916 + $em = $this->getDoctrine()->getManager();
  917 + //$arrDadosRede = array( 'rede' => $em->getRepository( 'CacicCommonBundle:Rede' )->listar() );
  918 + //Debug::dump($arrDadosRede['rede'][0][0]);
  919 + //$arrDadosRede = $arrDadosRede['rede'][0];
  920 + $arrDadosRede = array(
  921 + 'teServUpdates' => $rede->getTeServUpdates(),
  922 + 'tePathServUpdates' => $rede->getTePathServUpdates(),
  923 + 'nmUsuarioLoginServUpdatesGerente' => $rede->getNmUsuarioLoginServUpdatesGerente(),
  924 + 'teSenhaLoginServUpdatesGerente' => $rede->getTeSenhaLoginServUpdatesGerente(),
  925 + 'nuPortaServUpdates' => $rede->getNuPortaServUpdates(),
974 926 );
975 927  
976   - // Se não existir, instancia o objeto
977   - if (empty($redeVersaoModulo)) {
978   - $redeVersaoModulo = new RedeVersaoModulo(null, null, null, null, null, $rede);
  928 + if ($rede->getDownloadMethod() == 'ftp') {
  929 + $strResult = $this->checkAndSend(
  930 + $value['name'],
  931 + $downloadsDir . $value['filename'],
  932 + $arrDadosRede['teServUpdates'],
  933 + $arrDadosRede['tePathServUpdates'],
  934 + $arrDadosRede['nmUsuarioLoginServUpdatesGerente'],
  935 + $arrDadosRede['teSenhaLoginServUpdatesGerente'],
  936 + $arrDadosRede['nuPortaServUpdates']
  937 + );
  938 +
  939 + $arrResult = explode('_=_',$strResult);
  940 + } else {
  941 + $arrResult[1] = 'Ok!';
979 942 }
980 943  
981   - // Adicione o restante dos atributos
982   - $redeVersaoModulo->setNmModulo($value['name']);
983   - $redeVersaoModulo->setTeVersaoModulo($value['versao']);
984   - $redeVersaoModulo->setDtAtualizacao(new \DateTime('NOW'));
985   - $redeVersaoModulo->setCsTipoSo( $value['tipoSo'] );
986   - $redeVersaoModulo->setTeHash($value['hash']);
987   - $redeVersaoModulo->setTipo('cacic');
988 944  
989   - $em->persist($redeVersaoModulo);
990   - $em->flush();
991   - } else {
992   - $logger->error("Erro no envio dos módulos via FTP!\n".$arrResult[1]);
993   - return false;
  945 +
  946 + if ($arrResult[1] == 'Ok!')
  947 + {
  948 + // Consertar CRUD no Symfony
  949 + $redeVersaoModulo = $em->getRepository('CacicCommonBundle:RedeVersaoModulo')->findOneBy(
  950 + array(
  951 + 'idRede' => $pIntIdRede,
  952 + 'nmModulo' => $value['name'],
  953 + 'filepath' => $value['filename']
  954 + )
  955 + );
  956 +
  957 + // Se não existir, instancia o objeto
  958 + if (empty($redeVersaoModulo)) {
  959 + $redeVersaoModulo = new RedeVersaoModulo(null, null, null, null, null, $rede);
  960 + }
  961 +
  962 + $tipo_so = $em->getRepository('CacicCommonBundle:TipoSo')->findOneBy(array(
  963 + 'tipo' => $tipo
  964 + ));
  965 +
  966 + // Adicione o restante dos atributos
  967 + $redeVersaoModulo->setNmModulo($value['name']);
  968 + $redeVersaoModulo->setTeVersaoModulo($value['versao']);
  969 + $redeVersaoModulo->setDtAtualizacao(new \DateTime('NOW'));
  970 + $redeVersaoModulo->setCsTipoSo( $value['tipoSo'] );
  971 + $redeVersaoModulo->setTeHash($value['hash']);
  972 + $redeVersaoModulo->setTipoSo($tipo_so);
  973 + $redeVersaoModulo->setFilepath($value['filename']);
  974 + $redeVersaoModulo->setTipo('cacic');
  975 +
  976 + $em->persist($redeVersaoModulo);
  977 + $em->flush();
  978 + } else {
  979 + $logger->error("Erro no envio dos módulos via FTP!\n".$arrResult[1]);
  980 + return false;
  981 + }
994 982 }
995 983 }
996 984  
  985 +
  986 +
997 987 return true;
998 988 }
999 989  
... ...
src/Cacic/CommonBundle/Entity/RedeVersaoModulo.php
... ... @@ -239,4 +239,60 @@ class RedeVersaoModulo
239 239 {
240 240 return $this->tipo;
241 241 }
  242 + /**
  243 + * @var \Cacic\CommonBundle\Entity\TipoSo
  244 + */
  245 + private $tipoSo;
  246 +
  247 +
  248 + /**
  249 + * Set tipoSo
  250 + *
  251 + * @param \Cacic\CommonBundle\Entity\TipoSo $tipoSo
  252 + * @return RedeVersaoModulo
  253 + */
  254 + public function setTipoSo(\Cacic\CommonBundle\Entity\TipoSo $tipoSo = null)
  255 + {
  256 + $this->tipoSo = $tipoSo;
  257 +
  258 + return $this;
  259 + }
  260 +
  261 + /**
  262 + * Get tipoSo
  263 + *
  264 + * @return \Cacic\CommonBundle\Entity\TipoSo
  265 + */
  266 + public function getTipoSo()
  267 + {
  268 + return $this->tipoSo;
  269 + }
  270 + /**
  271 + * @var string
  272 + */
  273 + private $filepath;
  274 +
  275 +
  276 + /**
  277 + * Set filepath
  278 + *
  279 + * @param string $filepath
  280 + * @return RedeVersaoModulo
  281 + */
  282 + public function setFilepath($filepath)
  283 + {
  284 + $this->filepath = $filepath;
  285 +
  286 + return $this;
  287 + }
  288 +
  289 + /**
  290 + * Get filepath
  291 + *
  292 + * @return string
  293 + */
  294 + public function getFilepath()
  295 + {
  296 + return $this->filepath;
  297 + }
242 298 }
... ...
src/Cacic/CommonBundle/Entity/RedeVersaoModuloRepository.php
... ... @@ -70,4 +70,39 @@ class RedeVersaoModuloRepository extends EntityRepository
70 70 return $qb->getQuery()->getArrayResult();
71 71 }
72 72  
  73 + /*
  74 + * Traz a lista de módulos para a subrede fornecida
  75 + */
  76 + public function subredeFilePath($id = null, $modulo = null)
  77 + {
  78 + $qb = $this->createQueryBuilder('r')
  79 + ->select('red.idRede',
  80 + 'r.nmModulo',
  81 + 'r.teVersaoModulo',
  82 + 'r.teHash',
  83 + 'red.teIpRede',
  84 + 'red.nmRede',
  85 + 'red.teServUpdates',
  86 + 'red.tePathServUpdates',
  87 + 'l.nmLocal')
  88 + ->innerJoin('CacicCommonBundle:Rede', 'red', 'WITH', 'red.idRede = r.idRede')
  89 + ->innerJoin('CacicCommonBundle:Local', 'l', 'WITH', 'red.idLocal = l.idLocal')
  90 + ->groupBy('r', 'l', 'red')
  91 + ->orderBy('red.nmRede');
  92 +
  93 + // Adiciona filtro por módulo se fornecido
  94 + if ($modulo != null) {
  95 + // Aqui trago somente a lista de todos os módulos naquela subrede
  96 + $qb->andWhere('r.filepath = :modulo')->setParameter('modulo', $modulo);
  97 + }
  98 +
  99 + // Adiciona filtro por subrede se fornecido
  100 + if ($id != null) {
  101 + // Somente os módulos desa subrede
  102 + $qb->andWhere('r.idRede = :id')->setParameter('id', $id);
  103 + }
  104 +
  105 + return $qb->getQuery()->getArrayResult();
  106 + }
  107 +
73 108 }
74 109 \ No newline at end of file
... ...
src/Cacic/CommonBundle/Entity/TipoSo.php
... ... @@ -97,4 +97,42 @@ class TipoSo
97 97 {
98 98 return $this->so;
99 99 }
  100 + /**
  101 + * @var \Doctrine\Common\Collections\Collection
  102 + */
  103 + private $redeVersaoModulo;
  104 +
  105 +
  106 + /**
  107 + * Add redeVersaoModulo
  108 + *
  109 + * @param \Cacic\CommonBundle\Entity\RedeVersaoModulo $redeVersaoModulo
  110 + * @return TipoSo
  111 + */
  112 + public function addRedeVersaoModulo(\Cacic\CommonBundle\Entity\RedeVersaoModulo $redeVersaoModulo)
  113 + {
  114 + $this->redeVersaoModulo[] = $redeVersaoModulo;
  115 +
  116 + return $this;
  117 + }
  118 +
  119 + /**
  120 + * Remove redeVersaoModulo
  121 + *
  122 + * @param \Cacic\CommonBundle\Entity\RedeVersaoModulo $redeVersaoModulo
  123 + */
  124 + public function removeRedeVersaoModulo(\Cacic\CommonBundle\Entity\RedeVersaoModulo $redeVersaoModulo)
  125 + {
  126 + $this->redeVersaoModulo->removeElement($redeVersaoModulo);
  127 + }
  128 +
  129 + /**
  130 + * Get redeVersaoModulo
  131 + *
  132 + * @return \Doctrine\Common\Collections\Collection
  133 + */
  134 + public function getRedeVersaoModulo()
  135 + {
  136 + return $this->redeVersaoModulo;
  137 + }
100 138 }
... ...
src/Cacic/CommonBundle/Form/Type/AgenteType.php
... ... @@ -10,6 +10,7 @@ namespace Cacic\CommonBundle\Form\Type;
10 10  
11 11 use Symfony\Component\Form\AbstractType;
12 12 use Symfony\Component\Form\FormBuilderInterface;
  13 +use Symfony\Component\OptionsResolver\OptionsResolverInterface;
13 14  
14 15 /**
15 16 * Formulário para upload dos agentes
... ... @@ -30,33 +31,39 @@ class AgenteType extends AbstractType {
30 31  
31 32 public function buildForm( FormBuilderInterface $builder, array $options )
32 33 {
33   - $builder->add('windows_version', 'text',
34   - array(
35   - 'label' => 'Versão dos Agentes Windows',
36   - 'required' => false
37   - )
38   - );
  34 + $tipo_so = $options['tipo_so'];
39 35  
40   - $builder->add('windows', 'file',
  36 + $builder->add('version', 'text',
41 37 array(
42   - 'label' => 'Agentes Windows',
  38 + 'label' => 'Versão dos Agentes',
43 39 'required' => false
44 40 )
45 41 );
46 42  
47   - $builder->add('linux_version', 'text',
48   - array(
49   - 'label' => 'Versão dos Agentes Linux',
50   - 'required' => false
51   - )
52   - );
  43 + foreach($tipo_so as $so) {
  44 + $builder->add($so->getTipo(), 'file',
  45 + array(
  46 + 'label' => 'Agentes para SO Tipo '.$so->getTipo(),
  47 + 'required' => false
  48 + )
  49 + );
  50 + }
53 51  
54   - $builder->add('linux', 'file',
55   - array(
56   - 'label' => 'Agentes Linux',
57   - 'required' => false
58   - )
59   - );
60 52 }
61 53  
  54 + /**
  55 + * Add TipoSo as required option
  56 + *
  57 + * @param OptionsResolverInterface $resolver
  58 + */
  59 + public function setDefaultOptions(OptionsResolverInterface $resolver)
  60 + {
  61 + $resolver
  62 + ->setRequired(array(
  63 + 'tipo_so',
  64 + ));
  65 +
  66 + }
  67 +
  68 +
62 69 }
63 70 \ No newline at end of file
... ...
src/Cacic/CommonBundle/Resources/config/doctrine/RedeVersaoModulo.orm.yml
... ... @@ -40,6 +40,10 @@ Cacic\CommonBundle\Entity\RedeVersaoModulo:
40 40 fixed: false
41 41 nullable: true
42 42 column: tipo
  43 + filepath:
  44 + type: text
  45 + nullable: true
  46 + column: filepath
43 47 manyToOne:
44 48 idRede:
45 49 targetEntity: Rede
... ... @@ -50,4 +54,13 @@ Cacic\CommonBundle\Entity\RedeVersaoModulo:
50 54 id_rede:
51 55 referencedColumnName: id_rede
52 56 orphanRemoval: false
  57 + tipoSo:
  58 + targetEntity: TipoSo
  59 + cascade: { }
  60 + mappedBy: null
  61 + inversedBy: null
  62 + joinColumns:
  63 + id_tipo_so:
  64 + referencedColumnName: id_tipo_so
  65 + orphanRemoval: false
53 66 lifecycleCallbacks: { }
... ...
src/Cacic/CommonBundle/Resources/config/doctrine/TipoSo.orm.yml
... ... @@ -20,4 +20,7 @@ Cacic\CommonBundle\Entity\TipoSo:
20 20 so:
21 21 targetEntity: So
22 22 mappedBy: tipo
  23 + redeVersaoModulo:
  24 + targetEntity: RedeVersaoModulo
  25 + mappedBy: tipoSo
23 26 lifecycleCallbacks: { }
... ...
src/Cacic/CommonBundle/Resources/views/Agente/index.html.twig
... ... @@ -40,13 +40,9 @@
40 40  
41 41 {{ form_errors(form) }}
42 42  
43   - {{ form_row(form.windows_version) }}
  43 + {{ form_row(form.version) }}
44 44  
45   - {{ form_row(form.windows) }}
46   -
47   - {{ form_row(form.linux_version) }}
48   -
49   - {{ form_row(form.linux) }}
  45 + {{ form_rest(form) }}
50 46  
51 47 <input type="submit">
52 48  
... ... @@ -82,65 +78,12 @@
82 78 <div class="box grad_colour_black">
83 79 <h2 class="box_head round_top"><i class="icon-list"></i> {{'Resultado da pesquisa' |trans }}</h2>
84 80  
85   - <div class="block box_content round_bottom padding_10">
86   - <h4><center>{{ "Agentes para GNU/LINUX"|trans }}</h4>
87   - <table class="table table-striped table-bordered">
88   - <thead>
89   - <tr>
90   - <th width="15%" style="text-align: center">{{ 'Versão'|trans }}</th>
91   - <th width="30%" style="text-align: center">{{ 'Arquivo'|trans }}</th>
92   - <th width="25%" style="text-align: center">{{ 'Hash'|trans }}</th>
93   - <th width="20%" style="text-align: center">{{ 'Tamanho'|trans }}</th>
94   - <th style="text-align: center">{{ "Ações"|trans }}</th>
95   - </tr>
96   - </thead>
97   - <tbody>
98   -
99   - {% for version, value in saida.linux.versions %}
100   -
101   - {% if version == saida.linux.live_version %}
102   - <tr>
103   - <th rowspan="{{ value|length + 1 }}" style="vertical-align: middle; text-align: center;">
104   - {{ "Versão"|trans }} {{ version }} <br> {{ "(Em Produção)"|trans }}
105   - </th>
106   - </tr>
107   - {% else %}
108   - <tr>
109   - <th rowspan="{{ value|length + 1 }}" style="vertical-align: middle; text-align: center;">
110   - {{ "Versão"|trans }} {{ version }}
111   - </th>
112   - </tr>
113   - {% endif %}
114 81  
115   - {% for modulo in value %}
  82 + <div class="block box_content round_bottom padding_10">
116 83  
117   - <tr id="{{ modulo['filename'] }}" class="{{ cycle(['row0', 'row1'], loop.index) }}">
118   - <td style="text-align: center" >{{ modulo['name'] }}</td>
119   - <td style="text-align: center" >{{ modulo['hash'] }}</td>
120   - <td style="text-align: center" >{{ format.bytesToSize(modulo['size']) }}</td>
121   - <td class="td-actions">
122   - <a href="{{ path('cacic_agente_excluir') }}" class="btn btn-small btn-danger bt-excluir" title="{{ "Excluir Item"|trans }}">
123   - <i class="btn-icon-only icon-trash icon-large"></i>
124   - </a>
125   - <a href="{{ modulo['download_url'] }}" class="btn btn-small" title="{{ "Baixar"|trans }}" target="_blank">
126   - <i class="btn-icon-only icon-download-alt icon-large"></i>
127   - </a>
128   - </td>
129   - </tr>
130   - {% else %}
131   - <tr>
132   - <td style="text-align: center" colspan="6"><b>{{ 'NENHUM REGISTRO ENCONTRADO!'|trans }}</b></td>
133   - </tr>
134   - {% endfor %}
135   - {% else %}
136   - <tr>
137   - <td style="text-align: center" colspan="6"><b>{{ 'NENHUM REGISTRO ENCONTRADO!'|trans }}</b></td>
138   - </tr>
139   - {% endfor %}
140   - </tbody>
141   - </table>
  84 + {% for tipo, so in saida.tipo_so %}
142 85  
143   - <h4><center>{{ "Agentes para Windows"|trans }}</h4>
  86 + <h4><center>{{ "Agentes para "|trans }}{{ tipo }}</h4>
144 87 <table class="table table-striped table-bordered">
145 88 <thead>
146 89 <tr>
... ... @@ -153,9 +96,9 @@
153 96 </thead>
154 97 <tbody>
155 98  
156   - {% for version, value in saida.windows.versions %}
  99 + {% for version, value in so %}
157 100  
158   - {% if version == saida.windows.live_version %}
  101 + {% if version == saida.live_version %}
159 102 <tr>
160 103 <th rowspan="{{ value|length + 1 }}" style="vertical-align: middle; text-align: center;">
161 104 {{ "Versão"|trans }} {{ version }} <br> {{ "(Em Produção)"|trans }}
... ... @@ -169,7 +112,6 @@
169 112 </tr>
170 113 {% endif %}
171 114  
172   -
173 115 {% for modulo in value %}
174 116  
175 117 <tr id="{{ modulo['filename'] }}" class="{{ cycle(['row0', 'row1'], loop.index) }}">
... ... @@ -197,6 +139,7 @@
197 139 {% endfor %}
198 140 </tbody>
199 141 </table>
  142 + {% endfor %}
200 143  
201 144 </div> <!-- /block -->
202 145 </div> <!-- /box -->
... ...
src/Cacic/CommonBundle/Resources/views/Rede/manutencaoNeo.html.twig
... ... @@ -20,77 +20,45 @@
20 20 <br />
21 21  
22 22 <form id={{ 'formSoftwaresNaoUsados'|trans }} class="form-horizontal" action="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')) }}" method="post">
23   - <h4 align="center">{{ "Agentes para MS-Windows"|trans }}</h4>
24   - <table class="table table-striped table-bordered">
25   - <thead>
26   - <tr>
27   - <th width="40%" style="text-align: center">{{ 'Arquivo'|trans }}</th>
28   - <th width="20%" style="text-align: center">{{ 'Versão'|trans }}</th>
29   - <th width="40%" style="text-align: center">{{ 'Hash'|trans }}</th>
30   - <th style="text-align: center">
31   - <label style="margin: auto; width:12px; height:10px;">
32   - <input type="checkbox" class="toggleCheck" name="toggleCheck[]" value="windows" checked>
33   - </label>
34   - </th>
35   - </tr>
36   - </thead>
37   - <tbody>
38   -
39   - {% for key, modulo in windows %}
40 23  
41   - <tr id="item_{{ key }}">
42   - <td style="text-align: center" id="item_desc_{{ key }}">{{ key }}</td>
43   - <td style="text-align: center" >{{ modulo['versao'] }}</td>
44   - <td style="text-align: center" >{{ modulo['hash'] }}</td>
45   - <td>
46   - <label style="margin: auto; width:12px; height:10px;">
47   - <input type="checkbox" id="item_id_{{ key }}" name="windows[]" value="{{ key }}" checked>
48   - </label>
49   - </td>
50   - </tr>
51   - {% else %}
52   - <tr>
53   - <td style="text-align: center" colspan="6"><b>{{ 'NENHUM REGISTRO ENCONTRADO!'|trans }}</b></td>
54   - </tr>
55   - {% endfor %}
56   - </tbody>
57   - </table>
58   - <br />
59   - <table class="table table-striped table-bordered">
60   - <h4><center>{{ "Agentes para GNU/LINUX"|trans }}</h4>
61   - <thead>
62   - <tr>
63   - <th width="40%"style="text-align: center">{{ 'Arquivo'|trans }}</th>
64   - <th width="20%"style="text-align: center">{{ 'Versão'|trans }}</th>
65   - <th width="40%"style="text-align: center">{{ 'Hash'|trans }}</th>
66   - <th style="text-align: center">
67   - <label style="margin: auto; width:12px; height:10px;">
68   - <input type="checkbox" class="toggleCheck" name="toggleCheck[]" value="linux" checked>
69   - </label>
70   - </th>
71   - </tr>
72   - </thead>
73   - <tbody>
74   - {% for key, modulo in linux %}
75   -
76   - <tr id="item_{{ key }}">
77   - <td style="text-align: center" id="item_desc_{{ key }}">{{ key }}</td>
78   - <td style="text-align: center" >{{ modulo['versao'] }}</td>
79   - <td style="text-align: center" >{{ modulo['hash'] }}</td>
80   - <td>
81   - <label style="margin: auto; width:12px; height:10px;">
82   - <input type="checkbox" id="item_id_{{ key }}" name="linux[]" value="{{ key }}" checked>
83   - </label>
84   - </td>
85   - </tr>
86   - {% else %}
87   - <tr>
88   - <td style="text-align: center" colspan="6"><b>{{ 'NENHUM REGISTRO ENCONTRADO!'|trans }}</b></td>
89   - </tr>
  24 + {% for so, files in saida %}
  25 + <h4 align="center">{{ "Agentes para "|trans }}{{ so }}</h4>
  26 + <table class="table table-striped table-bordered">
  27 + <thead>
  28 + <tr>
  29 + <th width="40%" style="text-align: center">{{ 'Arquivo'|trans }}</th>
  30 + <th width="20%" style="text-align: center">{{ 'Versão'|trans }}</th>
  31 + <th width="40%" style="text-align: center">{{ 'Hash'|trans }}</th>
  32 + <th style="text-align: center">
  33 + <label style="margin: auto; width:12px; height:10px;">
  34 + <input type="checkbox" class="toggleCheck" name="toggleCheck[]" value="windows" checked>
  35 + </label>
  36 + </th>
  37 + </tr>
  38 + </thead>
  39 + <tbody>
  40 +
  41 + {% for key, modulo in files %}
  42 +
  43 + <tr id="item_{{ modulo['filename'] }}">
  44 + <td style="text-align: center" id="item_desc_{{ key }}">{{ key }}</td>
  45 + <td style="text-align: center" >{{ modulo['versao'] }}</td>
  46 + <td style="text-align: center" >{{ modulo['hash'] }}</td>
  47 + <td>
  48 + <label style="margin: auto; width:12px; height:10px;">
  49 + <input type="checkbox" id="item_id_{{ modulo['filename'] }}" name="windows[]" value="{{ modulo['filename'] }}" checked>
  50 + </label>
  51 + </td>
  52 + </tr>
  53 + {% else %}
  54 + <tr>
  55 + <td style="text-align: center" colspan="6"><b>{{ 'NENHUM REGISTRO ENCONTRADO!'|trans }}</b></td>
  56 + </tr>
  57 + {% endfor %}
  58 + </tbody>
  59 + </table>
  60 + <br />
90 61 {% endfor %}
91   -
92   - </tbody>
93   - </table>
94 62 <br />
95 63  
96 64 <hr>
... ...
src/Cacic/WSBundle/Controller/NeoController.php
... ... @@ -245,6 +245,7 @@ class NeoController extends Controller {
245 245  
246 246 // 0 - Array de saída
247 247 $saida['agentcomputer'] = "";
  248 + $so_json = $dados['computador']['operatingSystem'];
248 249  
249 250  
250 251 // 1 - Ações para o computador
... ... @@ -277,11 +278,16 @@ class NeoController extends Controller {
277 278 if (empty($mods[$tipo])) {
278 279 $mods[$tipo] = array();
279 280 }
280   - // Adiciona módulos e hashes
281   - array_push($mods[$tipo], array(
282   - 'nome' => $elm->getNmModulo(),
283   - 'hash' => $elm->getTeHash()
284   - ));
  281 +
  282 + // Adiciona somente o módulo que estiver com o tipo de SO cadastrado
  283 + if ($so_json['tipo'] == $elm->getTipoSo()->getTipo() ) {
  284 + // Adiciona módulos e hashes
  285 + array_push($mods[$tipo], array(
  286 + 'nome' => $elm->getNmModulo(),
  287 + 'hash' => $elm->getTeHash()
  288 + ));
  289 + }
  290 +
285 291 }
286 292 $saida['agentcomputer']['modulos'] = $mods;
287 293 //$logger->debug("2222222222222222222222222222222222222 \n".print_r($saida, true));
... ... @@ -302,10 +308,20 @@ class NeoController extends Controller {
302 308 $saida['agentcomputer']['metodoDownload'] = array(
303 309 "tipo" => $computador->getIdRede()->getDownloadMethod(),
304 310 "url" => $computador->getIdRede()->getTeServUpdates(),
305   - "path" => $computador->getIdRede()->getTePathServUpdates(),
306 311 "usuario" => $computador->getIdRede()->getNmUsuarioLoginServUpdates(),
307 312 "senha" => $computador->getIdRede()->getTeSenhaLoginServUpdates()
308 313 );
  314 +
  315 + // 4.1 - Configuração de método de Download
  316 + if ($computador->getIdRede()->getDownloadMethod() == 'http') {
  317 + $base_url = $request->getBaseUrl();
  318 + $base_url = preg_replace('/\/app.*.php/', "", $base_url);
  319 + $saida['agentcomputer']['metodoDownload']['path'] = $base_url . '/downloads/cacic/current/' . $so_json['tipo'];
  320 + } else {
  321 + $saida['agentcomputer']['metodoDownload']['path'] = $computador->getIdRede()->getTePathServUpdates();
  322 + }
  323 +
  324 +
309 325 //$logger->debug("4444444444444444444444444444444444444444 \n".print_r($saida, true));
310 326  
311 327 // 5 - Configurações do local
... ...