Commit d665ff76c7cd21f97d929858c4e6d2019b0ce654

Authored by anderson.peterle@previdencia.gov.br
1 parent d018b43d
Exists in master

Informacoes patrimoniais em Informacoes Gerais do agente principal. Hash para au…

…tenticacao de comunicacao entre modulos e novas versoes. Tratamento de agentes Linux no V.A.C.A.

git-svn-id: http://svn.softwarepublico.gov.br/svn/cacic/cacic/trunk/agente-windows@510 fecfc0c7-e812-0410-ae72-849f08638ee7
cacic2.dof
... ... @@ -108,7 +108,7 @@ DebugCWD=
108 108 [Language]
109 109 ActiveLang=
110 110 ProjectLang=
111   -RootDir=C:\arariboia\
  111 +RootDir=Y:\arariboia_mod\
112 112 [Version Info]
113 113 IncludeVerInfo=1
114 114 AutoIncBuild=0
... ...
cacic2.dpr
... ... @@ -24,7 +24,8 @@ uses
24 24 main in 'main.pas' {FormularioGeral},
25 25 frmSenha in 'frmsenha.pas' {formSenha},
26 26 frmConfiguracoes in 'frmConfiguracoes.pas' {FormConfiguracoes},
27   - frmLog in 'frmLog.pas' {FormLog};
  27 + frmLog in 'frmLog.pas' {FormLog},
  28 + LibXmlParser in 'LibXmlParser.pas';
28 29  
29 30 {$R *.res}
30 31  
... ...
ger_cols/ger_cols.dpr
... ... @@ -47,6 +47,7 @@ uses
47 47 DCPrijndael,
48 48 DCPbase64,
49 49 ZLibEx;
  50 +
50 51 {$APPTYPE CONSOLE}
51 52 var p_path_cacic,
52 53 v_scripter,
... ... @@ -91,7 +92,6 @@ var BatchFile,
91 92 const KeySize = 32; // 32 bytes = 256 bits
92 93 BlockSize = 16; // 16 bytes = 128 bits
93 94  
94   -
95 95 // Pad a string with zeros so that it is a multiple of size
96 96 function PadWithZeros(const str : string; size : integer) : string;
97 97 var
... ... @@ -140,6 +140,32 @@ begin
140 140 end;
141 141 end;
142 142  
  143 +// Gerador de Palavras-Chave
  144 +function GeraPalavraChave: String;
  145 +var intLimite,
  146 + intContaLetras : integer;
  147 + strPalavra,
  148 + strCaracter : String;
  149 + charCaracter : Char;
  150 +begin
  151 + Randomize;
  152 + strPalavra := '';
  153 + intLimite := RandomRange(10,30); // Gerarei uma palavra com tamanho mínimo 10 e máximo 30
  154 + for intContaLetras := 1 to intLimite do
  155 + Begin
  156 + strCaracter := '.';
  157 + while not (strCaracter[1] in ['0'..'9','A'..'Z','a'..'z']) do
  158 + Begin
  159 + if (strCaracter = '.') then strCaracter := '';
  160 + Randomize;
  161 + strCaracter := chr(RandomRange(1,250));
  162 + End;
  163 +
  164 + strPalavra := strPalavra + strCaracter;
  165 + End;
  166 + Result := strPalavra;
  167 +end;
  168 +
143 169 function VerFmt(const MS, LS: DWORD): string;
144 170 // Format the version number from the given DWORDs containing the info
145 171 begin
... ... @@ -372,8 +398,6 @@ begin
372 398 log_DEBUG('Criptografia(ATIVADA) de "'+p_Data+'" => "'+l_Data+'"');
373 399 // Return the Base64 encoded result
374 400  
375   - // Substituo os sinais de "+" por <MAIS> devido a problema com tráfego POST
376   -
377 401 Result := trim(Base64EncodeStr(l_Data));
378 402 End
379 403 else
... ... @@ -1291,6 +1315,8 @@ Begin
1291 1315 idHTTP1.SendBufferSize := 32768; // ATENÇÃO: Esta propriedade deixa de existir na próxima versão do Indy (10.x)
1292 1316 idHTTP1.Tag := 0;
1293 1317  
  1318 + // ATENÇÃO: Substituo os sinais de "+" acima por <MAIS> devido a problemas encontrados no envio POST
  1319 +
1294 1320 if v_Debugs then
1295 1321 Begin
1296 1322 Log_Debug('te_so => '+v_te_so);
... ... @@ -1459,27 +1485,27 @@ Begin
1459 1485 End;
1460 1486 End;
1461 1487  
1462   -Function FTP_Get(Arq : String; DirDestino : String) : Boolean;
1463   -var v_te_senha_login_serv_updates : string;
1464   - IdFTP1 : TIdFTP;
  1488 +Function FTP_Get(strHost, strUser, strPass, strArq, strDirOrigem, strDirDestino, strTipo : String; intPort : integer) : Boolean;
  1489 +var IdFTP1 : TIdFTP;
1465 1490 begin
1466   - v_te_senha_login_serv_updates := GetValorDatMemoria('Configs.TE_SENHA_LOGIN_SERV_UPDATES', v_tstrCipherOpened);
1467 1491 log_DEBUG('Instanciando FTP...');
1468   - IdFTP1 := TIdFTP.Create(IdFTP1);
1469   -
  1492 + IdFTP1 := TIdFTP.Create(IdFTP1);
1470 1493 log_DEBUG('FTP Instanciado!');
1471   - IdFTP1.Host := GetValorDatMemoria('Configs.TE_SERV_UPDATES', v_tstrCipherOpened);
1472   - IdFTP1.Username := GetValorDatMemoria('Configs.NM_USUARIO_LOGIN_SERV_UPDATES', v_tstrCipherOpened);
1473   - IdFTP1.Password := v_te_senha_login_serv_updates;
1474   - IdFTP1.Port := strtoint(GetValorDatMemoria('Configs.NU_PORTA_SERV_UPDATES', v_tstrCipherOpened));
1475   - IdFTP1.TransferType := ftBinary;
1476   - IdFTP1.Passive := true;
1477   -
1478   - log_DEBUG('Iniciando FTP de '+Arq +' para '+StringReplace(DirDestino + '\' + Arq,'\\','\',[rfReplaceAll]));
  1494 + IdFTP1.Host := strHost;
  1495 + IdFTP1.Username := strUser;
  1496 + IdFTP1.Password := strPass;
  1497 + IdFTP1.Port := intPort;
  1498 + IdFTP1.Passive := true;
  1499 + if (strTipo = 'ASC') then
  1500 + IdFTP1.TransferType := ftASCII
  1501 + else
  1502 + IdFTP1.TransferType := ftBinary;
  1503 +
  1504 + log_DEBUG('Iniciando FTP de '+strArq +' para '+StringReplace(strDirDestino + '\' + strArq,'\\','\',[rfReplaceAll]));
1479 1505 log_DEBUG('Host........ ='+IdFTP1.Host);
1480 1506 log_DEBUG('UserName.... ='+IdFTP1.Username);
1481 1507 log_DEBUG('Port........ ='+inttostr(IdFTP1.Port));
1482   - log_DEBUG('Pasta Origem ='+GetValorDatMemoria('Configs.TE_PATH_SERV_UPDATES', v_tstrCipherOpened));
  1508 + log_DEBUG('Pasta Origem ='+strDirOrigem);
1483 1509  
1484 1510 Try
1485 1511 if IdFTP1.Connected = true then
... ... @@ -1488,20 +1514,20 @@ begin
1488 1514 end;
1489 1515 //IdFTP1.Connect(True);
1490 1516 IdFTP1.Connect;
1491   - IdFTP1.ChangeDir(GetValorDatMemoria('Configs.TE_PATH_SERV_UPDATES', v_tstrCipherOpened));
  1517 + IdFTP1.ChangeDir(strDirOrigem);
1492 1518 Try
1493 1519 // Substituo \\ por \ devido a algumas vezes em que o DirDestino assume o valor de DirTemp...
1494   - log_DEBUG('FTP - Size de "'+Arq+'" Antes => '+IntToSTR(IdFTP1.Size(Arq)));
1495   - IdFTP1.Get(Arq, StringReplace(DirDestino + '\' + Arq,'\\','\',[rfReplaceAll]), True);
1496   - log_DEBUG('FTP - Size de "'+DirDestino + '\' + Arq +'" Após => '+Get_File_Size(DirDestino + '\' + Arq,true));
  1520 + log_DEBUG('FTP - Size de "'+strArq+'" Antes => '+IntToSTR(IdFTP1.Size(strArq)));
  1521 + IdFTP1.Get(strArq, StringReplace(strDirDestino + '\' + strArq,'\\','\',[rfReplaceAll]), True);
  1522 + log_DEBUG('FTP - Size de "'+strDirDestino + '\' + strArq +'" Após => '+Get_File_Size(strDirDestino + '\' + strArq,true));
1497 1523 Finally
1498 1524 result := true;
1499   - log_DEBUG('FTP - Size de "'+DirDestino + '\' + Arq +'" Após em Finally => '+Get_File_Size(DirDestino + '\' + Arq,true));
  1525 + log_DEBUG('FTP - Size de "'+strDirDestino + '\' + strArq +'" Após em Finally => '+Get_File_Size(strDirDestino + '\' + strArq,true));
1500 1526 idFTP1.Disconnect;
1501 1527 IdFTP1.Free;
1502 1528 End;
1503 1529 Except
1504   - log_DEBUG('FTP - Erro - Size de "'+DirDestino + '\' + Arq +'" Após em Finally => '+Get_File_Size(DirDestino + '\' + Arq,true));
  1530 + log_DEBUG('FTP - Erro - Size de "'+strDirDestino + '\' + strArq +'" Após em Except => '+Get_File_Size(strDirDestino + '\' + strArq,true));
1505 1531 result := false;
1506 1532 end;
1507 1533 end;
... ... @@ -1588,7 +1614,14 @@ Begin
1588 1614  
1589 1615 Try
1590 1616 log_DEBUG('Baixando: '+ p_File + '.exe para '+v_Dir_Temp);
1591   - if (FTP_Get(p_File + '.exe', v_Dir_Temp) = False) Then
  1617 + if (FTP_Get(GetValorDatMemoria('Configs.TE_SERV_UPDATES', v_tstrCipherOpened),
  1618 + GetValorDatMemoria('Configs.NM_USUARIO_LOGIN_SERV_UPDATES', v_tstrCipherOpened),
  1619 + GetValorDatMemoria('Configs.TE_SENHA_LOGIN_SERV_UPDATES', v_tstrCipherOpened),
  1620 + p_File + '.exe',
  1621 + GetValorDatMemoria('Configs.TE_PATH_SERV_UPDATES', v_tstrCipherOpened),
  1622 + v_Dir_Temp,
  1623 + 'BIN',
  1624 + strtoint(GetValorDatMemoria('Configs.NU_PORTA_SERV_UPDATES', v_tstrCipherOpened))) = False) Then
1592 1625 Begin
1593 1626 log_diario('ERRO!');
1594 1627 strAux := 'Não foi possível baixar o módulo "'+ p_Nome_Modulo + '".';
... ... @@ -2004,13 +2037,13 @@ Begin
2004 2037  
2005 2038 // Verifica existência dos dados de configurações principais e estado de CountUPD. Caso verdadeiro, simula uma instalação pelo chkCACIC...
2006 2039 if ((GetValorDatMemoria('Configs.TE_SERV_UPDATES' , v_tstrCipherOpened) = '') or
2007   - (GetValorDatMemoria('Configs.NM_USUARIO_LOGIN_SERV_UPDATES', v_tstrCipherOpened) = '') or
2008   - (GetValorDatMemoria('Configs.TE_SENHA_LOGIN_SERV_UPDATES' , v_tstrCipherOpened) = '') or
2009   - (GetValorDatMemoria('Configs.TE_PATH_SERV_UPDATES' , v_tstrCipherOpened) = '') or
2010   - (GetValorDatMemoria('Configs.NU_PORTA_SERV_UPDATES' , v_tstrCipherOpened) = '') or
2011   - (GetValorDatMemoria('TcpIp.TE_ENDERECOS_MAC_INVALIDOS' , v_tstrCipherOpened) = '') or
2012   - (CountUPD > 0)) and
2013   - (GetValorDatMemoria('Configs.ID_FTP', v_tstrCipherOpened) = '') then
  2040 + (GetValorDatMemoria('Configs.NM_USUARIO_LOGIN_SERV_UPDATES', v_tstrCipherOpened) = '') or
  2041 + (GetValorDatMemoria('Configs.TE_SENHA_LOGIN_SERV_UPDATES' , v_tstrCipherOpened) = '') or
  2042 + (GetValorDatMemoria('Configs.TE_PATH_SERV_UPDATES' , v_tstrCipherOpened) = '') or
  2043 + (GetValorDatMemoria('Configs.NU_PORTA_SERV_UPDATES' , v_tstrCipherOpened) = '') or
  2044 + (GetValorDatMemoria('TcpIp.TE_ENDERECOS_MAC_INVALIDOS' , v_tstrCipherOpened) = '') or
  2045 + (CountUPD > 0)) and
  2046 + (GetValorDatMemoria('Configs.ID_FTP', v_tstrCipherOpened) = '') then
2014 2047 Begin
2015 2048 log_DEBUG('Preparando contato com módulo Gerente WEB para Downloads.');
2016 2049 v_acao_gercols := 'Contactando o módulo Gerente WEB: get_config.php...';
... ... @@ -2392,6 +2425,13 @@ Begin
2392 2425 // Request_SVG.Values['te_tripa_perfis'] := strTripa;
2393 2426 // Proposital, para forçar a chegada dos perfis, solução temporária...
2394 2427 Request_SVG.Values['te_tripa_perfis'] := StringReplace(EnCrypt('',l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
  2428 +
  2429 + // Gero e armazeno uma palavra-chave e a envio ao Gerente WEB para atualização no BD.
  2430 + // Essa palavra-chave será usada para o acesso ao Agente Principal
  2431 + strAux := GeraPalavraChave;
  2432 +
  2433 + SetValorDatMemoria('Configs.te_palavra_chave',strAux, v_tstrCipherOpened);
  2434 + Request_SVG.Values['te_palavra_chave'] := EnCrypt(strAux,l_cs_compress);
2395 2435 v_te_serv_cacic := GetValorDatMemoria('Configs.EnderecoServidor', v_tstrCipherOpened);
2396 2436  
2397 2437 strRetorno := ComunicaServidor('get_config.php', Request_SVG, v_mensagem_log);
... ... @@ -2967,16 +3007,6 @@ Begin
2967 3007  
2968 3008 if (GetValorDatMemoria('Col_Anvi.nada',v_tstrCipherOpened1)='') then
2969 3009 Begin
2970   -
2971   - // Dados para uso do Gerente WEB...
2972   - //Request_Ger_Cols.Values['te_node_address' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NODE_ADDRESS' ,v_tstrCipherOpened),l_cs_compress);
2973   - //Request_Ger_Cols.Values['id_so' ] := EnCrypt(GetValorDatMemoria('Configs.ID_SO' ,v_tstrCipherOpened),l_cs_compress);
2974   - //Request_Ger_Cols.Values['te_so' ] := EnCrypt(v_te_so,l_cs_compress);
2975   - //Request_Ger_Cols.Values['te_ip' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_IP' ,v_tstrCipherOpened),l_cs_compress);
2976   - //Request_Ger_Cols.Values['id_ip_rede' ] := EnCrypt(GetValorDatMemoria('TcpIp.ID_IP_REDE' ,v_tstrCipherOpened),l_cs_compress);
2977   - //Request_Ger_Cols.Values['te_workgroup' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_WORKGROUP' ,v_tstrCipherOpened),l_cs_compress);
2978   - //Request_Ger_Cols.Values['te_nome_computador'] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NOME_COMPUTADOR',v_tstrCipherOpened),l_cs_compress);
2979   -
2980 3010 // Preparação para envio...
2981 3011 Request_Ger_Cols.Values['nu_versao_engine' ] := StringReplace(EnCrypt(GetValorDatMemoria('Col_Anvi.nu_versao_engine' ,v_tstrCipherOpened1),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
2982 3012 Request_Ger_Cols.Values['nu_versao_pattern'] := StringReplace(EnCrypt(GetValorDatMemoria('Col_Anvi.nu_versao_pattern',v_tstrCipherOpened1),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
... ... @@ -3027,15 +3057,6 @@ Begin
3027 3057  
3028 3058 if (GetValorDatMemoria('Col_Comp.nada',v_tstrCipherOpened1)='') then
3029 3059 Begin
3030   - // Dados para uso do Gerente WEB...
3031   - //Request_Ger_Cols.Values['te_node_address' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NODE_ADDRESS' ,v_tstrCipherOpened),l_cs_compress);
3032   - //Request_Ger_Cols.Values['id_so' ] := EnCrypt(GetValorDatMemoria('Configs.ID_SO' ,v_tstrCipherOpened),l_cs_compress);
3033   - //Request_Ger_Cols.Values['te_so' ] := EnCrypt(v_te_so,l_cs_compress);
3034   - //Request_Ger_Cols.Values['te_ip' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_IP' ,v_tstrCipherOpened),l_cs_compress);
3035   - //Request_Ger_Cols.Values['id_ip_rede' ] := EnCrypt(GetValorDatMemoria('TcpIp.ID_IP_REDE' ,v_tstrCipherOpened),l_cs_compress);
3036   - //Request_Ger_Cols.Values['te_workgroup' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_WORKGROUP' ,v_tstrCipherOpened),l_cs_compress);
3037   - //Request_Ger_Cols.Values['te_nome_computador'] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NOME_COMPUTADOR',v_tstrCipherOpened),l_cs_compress);
3038   -
3039 3060 // Preparação para envio...
3040 3061 Request_Ger_Cols.Values['CompartilhamentosLocais'] := StringReplace(EnCrypt(StringReplace(GetValorDatMemoria('Col_Comp.UVC',v_tstrCipherOpened1),'\','<BarrInv>',[rfReplaceAll]),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
3041 3062 if v_Debugs then
... ... @@ -3083,15 +3104,6 @@ Begin
3083 3104  
3084 3105 if (GetValorDatMemoria('Col_Hard.nada',v_tstrCipherOpened1)='') then
3085 3106 Begin
3086   - // Dados para uso do Gerente WEB...
3087   - //Request_Ger_Cols.Values['te_node_address' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NODE_ADDRESS' ,v_tstrCipherOpened),l_cs_compress);
3088   - //Request_Ger_Cols.Values['id_so' ] := EnCrypt(GetValorDatMemoria('Configs.ID_SO' ,v_tstrCipherOpened),l_cs_compress);
3089   - //Request_Ger_Cols.Values['te_so' ] := EnCrypt(v_te_so,l_cs_compress);
3090   - //Request_Ger_Cols.Values['te_ip' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_IP' ,v_tstrCipherOpened),l_cs_compress);
3091   - //Request_Ger_Cols.Values['id_ip_rede' ] := EnCrypt(GetValorDatMemoria('TcpIp.ID_IP_REDE' ,v_tstrCipherOpened),l_cs_compress);
3092   - //Request_Ger_Cols.Values['te_workgroup' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_WORKGROUP' ,v_tstrCipherOpened),l_cs_compress);
3093   - //Request_Ger_Cols.Values['te_nome_computador'] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NOME_COMPUTADOR',v_tstrCipherOpened),l_cs_compress);
3094   -
3095 3107 // Preparação para envio...
3096 3108 Request_Ger_Cols.Values['te_Tripa_TCPIP' ] := StringReplace(EnCrypt(GetValorDatMemoria('Col_Hard.te_Tripa_TCPIP' ,v_tstrCipherOpened1),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
3097 3109 Request_Ger_Cols.Values['te_Tripa_CPU' ] := StringReplace(EnCrypt(GetValorDatMemoria('Col_Hard.te_Tripa_CPU' ,v_tstrCipherOpened1),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
... ... @@ -3153,15 +3165,6 @@ Begin
3153 3165  
3154 3166 if (GetValorDatMemoria('Col_Patr.nada',v_tstrCipherOpened1)='') then
3155 3167 Begin
3156   - // Dados para uso do Gerente WEB...
3157   - //Request_Ger_Cols.Values['te_node_address' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NODE_ADDRESS' ,v_tstrCipherOpened),l_cs_compress);
3158   - //Request_Ger_Cols.Values['id_so' ] := EnCrypt(GetValorDatMemoria('Configs.ID_SO' ,v_tstrCipherOpened),l_cs_compress);
3159   - //Request_Ger_Cols.Values['te_so' ] := EnCrypt(v_te_so,l_cs_compress);
3160   - //Request_Ger_Cols.Values['te_ip' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_IP' ,v_tstrCipherOpened),l_cs_compress);
3161   - //Request_Ger_Cols.Values['id_ip_rede' ] := EnCrypt(GetValorDatMemoria('TcpIp.ID_IP_REDE' ,v_tstrCipherOpened),l_cs_compress);
3162   - //Request_Ger_Cols.Values['te_workgroup' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_WORKGROUP' ,v_tstrCipherOpened),l_cs_compress);
3163   - //Request_Ger_Cols.Values['te_nome_computador'] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NOME_COMPUTADOR',v_tstrCipherOpened),l_cs_compress);
3164   -
3165 3168 // Preparação para envio...
3166 3169 Request_Ger_Cols.Values['id_unid_organizacional_nivel1'] := StringReplace(EnCrypt(GetValorDatMemoria('Col_Patr.id_unid_organizacional_nivel1' ,v_tstrCipherOpened1),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
3167 3170 Request_Ger_Cols.Values['id_unid_organizacional_nivel1a'] := StringReplace(EnCrypt(GetValorDatMemoria('Col_Patr.id_unid_organizacional_nivel1a' ,v_tstrCipherOpened1),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
... ... @@ -3225,15 +3228,6 @@ Begin
3225 3228  
3226 3229 if (GetValorDatMemoria('Col_Moni.nada',v_tstrCipherOpened1)='') then
3227 3230 Begin
3228   - // Dados para uso do Gerente WEB...
3229   - //Request_Ger_Cols.Values['te_node_address' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NODE_ADDRESS' ,v_tstrCipherOpened),l_cs_compress);
3230   - //Request_Ger_Cols.Values['id_so' ] := EnCrypt(GetValorDatMemoria('Configs.ID_SO' ,v_tstrCipherOpened),l_cs_compress);
3231   - //Request_Ger_Cols.Values['te_so' ] := EnCrypt(v_te_so,l_cs_compress);
3232   - //Request_Ger_Cols.Values['te_ip' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_IP' ,v_tstrCipherOpened),l_cs_compress);
3233   - //Request_Ger_Cols.Values['id_ip_rede' ] := EnCrypt(GetValorDatMemoria('TcpIp.ID_IP_REDE' ,v_tstrCipherOpened),l_cs_compress);
3234   - //Request_Ger_Cols.Values['te_workgroup' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_WORKGROUP' ,v_tstrCipherOpened),l_cs_compress);
3235   - //Request_Ger_Cols.Values['te_nome_computador'] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NOME_COMPUTADOR',v_tstrCipherOpened),l_cs_compress);
3236   -
3237 3231 // Preparação para envio...
3238 3232 Request_Ger_Cols.Values['te_tripa_monitorados'] := StringReplace(EnCrypt(GetValorDatMemoria('Col_Moni.UVC',v_tstrCipherOpened1),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
3239 3233  
... ... @@ -3279,15 +3273,6 @@ Begin
3279 3273  
3280 3274 if (GetValorDatMemoria('Col_Soft.nada',v_tstrCipherOpened1)='') then
3281 3275 Begin
3282   - // Dados para uso do Gerente WEB...
3283   - //Request_Ger_Cols.Values['te_node_address' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NODE_ADDRESS' ,v_tstrCipherOpened),l_cs_compress);
3284   - //Request_Ger_Cols.Values['id_so' ] := EnCrypt(GetValorDatMemoria('Configs.ID_SO' ,v_tstrCipherOpened),l_cs_compress);
3285   - //Request_Ger_Cols.Values['te_so' ] := EnCrypt(v_te_so,l_cs_compress);
3286   - //Request_Ger_Cols.Values['te_ip' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_IP' ,v_tstrCipherOpened),l_cs_compress);
3287   - //Request_Ger_Cols.Values['id_ip_rede' ] := EnCrypt(GetValorDatMemoria('TcpIp.ID_IP_REDE' ,v_tstrCipherOpened),l_cs_compress);
3288   - //Request_Ger_Cols.Values['te_workgroup' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_WORKGROUP' ,v_tstrCipherOpened),l_cs_compress);
3289   - //Request_Ger_Cols.Values['te_nome_computador'] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NOME_COMPUTADOR',v_tstrCipherOpened),l_cs_compress);
3290   -
3291 3276 // Preparação para envio...
3292 3277 Request_Ger_Cols.Values['te_versao_bde' ] := StringReplace(EnCrypt(GetValorDatMemoria('Col_Soft.te_versao_bde' ,v_tstrCipherOpened1),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
3293 3278 Request_Ger_Cols.Values['te_versao_dao' ] := StringReplace(EnCrypt(GetValorDatMemoria('Col_Soft.te_versao_dao' ,v_tstrCipherOpened1),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
... ... @@ -3343,15 +3328,6 @@ Begin
3343 3328  
3344 3329 if (GetValorDatMemoria('Col_Undi.nada',v_tstrCipherOpened1)='') then
3345 3330 Begin
3346   - // Dados para uso do Gerente WEB...
3347   - //Request_Ger_Cols.Values['te_node_address' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NODE_ADDRESS' ,v_tstrCipherOpened),l_cs_compress);
3348   - //Request_Ger_Cols.Values['id_so' ] := EnCrypt(GetValorDatMemoria('Configs.ID_SO' ,v_tstrCipherOpened),l_cs_compress);
3349   - //Request_Ger_Cols.Values['te_so' ] := EnCrypt(v_te_so,l_cs_compress);
3350   - //Request_Ger_Cols.Values['te_ip' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_IP' ,v_tstrCipherOpened),l_cs_compress);
3351   - //Request_Ger_Cols.Values['id_ip_rede' ] := EnCrypt(GetValorDatMemoria('TcpIp.ID_IP_REDE' ,v_tstrCipherOpened),l_cs_compress);
3352   - //Request_Ger_Cols.Values['te_workgroup' ] := EnCrypt(GetValorDatMemoria('TcpIp.TE_WORKGROUP' ,v_tstrCipherOpened),l_cs_compress);
3353   - //Request_Ger_Cols.Values['te_nome_computador'] := EnCrypt(GetValorDatMemoria('TcpIp.TE_NOME_COMPUTADOR',v_tstrCipherOpened),l_cs_compress);
3354   -
3355 3331 // Preparação para envio...
3356 3332 Request_Ger_Cols.Values['UnidadesDiscos'] := StringReplace(EnCrypt(GetValorDatMemoria('Col_Undi.UVC',v_tstrCipherOpened1),l_cs_compress),'+','<MAIS>',[rfReplaceAll]);
3357 3333  
... ...
main.pas
... ... @@ -34,8 +34,14 @@ uses Windows,
34 34 PJVersionInfo,
35 35 DCPcrypt2,
36 36 DCPrijndael,
37   - DCPbase64, ComCtrls;
38   -
  37 + DCPbase64,
  38 + ComCtrls,
  39 + IdBaseComponent,
  40 + IdComponent,
  41 + IdTCPServer,
  42 + IdCustomHTTPServer,
  43 + IdHTTPServer,
  44 + IdFTPServer;
39 45  
40 46 const WM_MYMESSAGE = WM_USER+100;
41 47  
... ... @@ -53,7 +59,8 @@ var p_path_cacic,
53 59 v_DatFileName,
54 60 v_DataCacic2DAT,
55 61 v_Tamanho_Arquivo,
56   - v_te_so : string;
  62 + v_te_so,
  63 + strConfigsPatrimonio : string;
57 64 v_tstrCipherOpened : TStrings;
58 65 v_Debugs : Boolean;
59 66  
... ... @@ -106,7 +113,7 @@ type
106 113 Mnu_InfosPatrimoniais: TMenuItem;
107 114 Mnu_FinalizarCacic: TMenuItem;
108 115 listSistemasMonitorados: TListView;
109   - Panel1: TPanel;
  116 + pnColetasRealizadasNestaData: TPanel;
110 117 lbColetasRealizadasNestaData: TLabel;
111 118 listaColetas: TListView;
112 119 teDataColeta: TLabel;
... ... @@ -116,6 +123,37 @@ type
116 123 lbServidorWEB: TLabel;
117 124 teServidorWEB: TLabel;
118 125 Panel5: TPanel;
  126 + IdHTTPServerCACIC: TIdHTTPServer;
  127 + IdFTPServer1: TIdFTPServer;
  128 + pnInformacoesPatrimoniais: TPanel;
  129 + lbInformacoesPatrimoniais: TLabel;
  130 + gpInfosPatrimoniais: TGroupBox;
  131 + st_lb_Etiqueta5: TStaticText;
  132 + st_lb_Etiqueta1: TStaticText;
  133 + st_vl_Etiqueta1: TStaticText;
  134 + st_lb_Etiqueta1a: TStaticText;
  135 + st_lb_Etiqueta2: TStaticText;
  136 + st_lb_Etiqueta7: TStaticText;
  137 + st_lb_Etiqueta6: TStaticText;
  138 + st_lb_Etiqueta8: TStaticText;
  139 + st_vl_Etiqueta1a: TStaticText;
  140 + st_vl_Etiqueta2: TStaticText;
  141 + Panel6: TPanel;
  142 + Panel7: TPanel;
  143 + Panel8: TPanel;
  144 + Panel9: TPanel;
  145 + Panel11: TPanel;
  146 + Panel12: TPanel;
  147 + st_lb_Etiqueta4: TStaticText;
  148 + st_lb_Etiqueta3: TStaticText;
  149 + st_vl_Etiqueta3: TStaticText;
  150 + st_lb_Etiqueta9: TStaticText;
  151 + st_vl_etiqueta4: TStaticText;
  152 + st_vl_etiqueta5: TStaticText;
  153 + st_vl_etiqueta6: TStaticText;
  154 + st_vl_etiqueta7: TStaticText;
  155 + st_vl_etiqueta8: TStaticText;
  156 + st_vl_etiqueta9: TStaticText;
119 157 procedure RemoveIconesMortos;
120 158 procedure ChecaCONFIGS;
121 159 procedure CriaFormSenha(Sender: TObject);
... ... @@ -146,6 +184,11 @@ type
146 184 function Get_File_Size(sFileToExamine: string; bInKBytes: Boolean): string;
147 185 function Posso_Rodar : boolean;
148 186 function abstraiCSD(p_te_so : String) : integer;
  187 + procedure IdHTTPServerCACICCommandGet(AThread: TIdPeerThread;
  188 + ARequestInfo: TIdHTTPRequestInfo;
  189 + AResponseInfo: TIdHTTPResponseInfo);
  190 + procedure IdFTPServer1UserLogin(ASender: TIdFTPServerThread;
  191 + const AUsername, APassword: String; var AAuthenticated: Boolean);
149 192 private
150 193 ShutdownEmExecucao : Boolean;
151 194 IsMenuOpen : Boolean;
... ... @@ -161,6 +204,8 @@ type
161 204 // Shutdown do Windows e "derrubar" o Cacic.
162 205 procedure WMQueryEndSession(var Msg : TWMQueryEndSession); Message WM_QUERYENDSESSION;
163 206 procedure WMMENUSELECT(var msg: TWMMENUSELECT); message WM_MENUSELECT;
  207 + function GetFileHash(strFileName : String) : String;
  208 + Function XML_ResgataValorPatrimonio(strIT, strID : String; Fonte : String): String;
164 209 public
165 210 Function Implode(p_Array : TStrings ; p_Separador : String) : String;
166 211 function HomeDrive : string;
... ... @@ -173,7 +218,8 @@ type
173 218 function PadWithZeros(const str : string; size : integer) : string;
174 219 function EnCrypt(p_Data : String) : String;
175 220 function DeCrypt(p_Data : String) : String;
176   -
  221 + function URLDecode(const S: string): string;
  222 + Function XML_RetornaValor(Tag : String; Fonte : String): String;
177 223 end;
178 224  
179 225 var FormularioGeral: TFormularioGeral;
... ... @@ -188,7 +234,18 @@ implementation
188 234  
189 235 {$R *.dfm}
190 236  
191   -Uses StrUtils, Inifiles, frmConfiguracoes, frmSenha, frmLog;
  237 +Uses StrUtils, Inifiles, frmConfiguracoes, frmSenha, frmLog,
  238 + IdHTTPHeaderInfo, Math,md5,LibXmlParser;
  239 +
  240 +// Para cálculo de HASH de determinado arquivo.
  241 +// Objetivo principal: Verificar autenticidade de agentes para trabalho cooperativo
  242 +// Anderson Peterle - Dataprev/ES - 08/Maio/2008
  243 +function TFormularioGeral.GetFileHash(strFileName : String) : String;
  244 +Begin
  245 + Result := 'Arquivo "'+strFileName+'" Inexistente!';
  246 + if (FileExists(strFileName)) then
  247 + Result := MD5Print(MD5File(strFileName));
  248 +End;
192 249  
193 250 // Pad a string with zeros so that it is a multiple of size
194 251 function TFormularioGeral.PadWithZeros(const str : string; size : integer) : string;
... ... @@ -1015,6 +1072,24 @@ begin
1015 1072 else
1016 1073 p_path_cacic := ExtractFilePath(Application.Exename) ;
1017 1074  
  1075 + if not DirectoryExists(p_path_cacic + 'Temp') then
  1076 + begin
  1077 + ForceDirectories(p_path_cacic + 'Temp');
  1078 + Log_Diario('Criando pasta '+p_path_cacic + 'Temp');
  1079 + end;
  1080 +
  1081 + if not DirectoryExists(p_path_cacic + 'Modulos') then
  1082 + begin
  1083 + ForceDirectories(p_path_cacic + 'Modulos');
  1084 + Log_Diario('Criando pasta '+p_path_cacic + 'Modulos');
  1085 + end;
  1086 +
  1087 + if not DirectoryExists(p_path_cacic + 'Repositorio') then
  1088 + begin
  1089 + ForceDirectories(p_path_cacic + 'Repositorio');
  1090 + Log_Diario('Criando pasta '+p_path_cacic + 'Repositorio');
  1091 + end;
  1092 +
1018 1093 v_Debugs := false;
1019 1094 if DirectoryExists(p_path_cacic + 'Temp\Debugs') then
1020 1095 Begin
... ... @@ -1046,7 +1121,7 @@ begin
1046 1121 // Chave AES. Recomenda-se que cada empresa altere a sua chave.
1047 1122 // Esta chave é passada como parâmetro para o Gerente de Coletas que, por sua vez,
1048 1123 // passa para o Inicializador de Coletas e este passa para os coletores...
1049   - v_CipherKey := 'CacicBrasil';
  1124 + v_CipherKey := 'CacicBrasil';
1050 1125 v_IV := 'abcdefghijklmnop';
1051 1126 v_SeparatorKey := '=CacicIsFree='; // Usada apenas para o cacic2.dat
1052 1127 v_DatFileName := p_path_cacic + 'cacic2.dat';
... ... @@ -1816,6 +1891,68 @@ begin
1816 1891 listSistemasMonitorados.Items.Add;
1817 1892 listSistemasMonitorados.Items[0].Caption := 'Não Há Coletas Registradas Nesta Data';
1818 1893 End;
  1894 +
  1895 + strConfigsPatrimonio := GetValorDatMemoria('Patrimonio.Configs' , v_tstrCipherOpened);
  1896 +
  1897 + st_lb_Etiqueta1.Caption := DeCrypt(XML_RetornaValor('te_etiqueta1', strConfigsPatrimonio));
  1898 + st_lb_Etiqueta1.Visible := true;
  1899 + st_vl_Etiqueta1.Caption := XML_ResgataValorPatrimonio('IT1',GetValorDatMemoria('Patrimonio.id_unid_organizacional_nivel1',v_tstrCipherOpened),strConfigsPatrimonio);
  1900 +
  1901 + st_lb_Etiqueta1a.Caption := DeCrypt(XML_RetornaValor('te_etiqueta1a', strConfigsPatrimonio));
  1902 + st_lb_Etiqueta1a.Visible := true;
  1903 + st_vl_Etiqueta1a.Caption := XML_ResgataValorPatrimonio('IT1a',GetValorDatMemoria('Patrimonio.id_unid_organizacional_nivel1a',v_tstrCipherOpened),strConfigsPatrimonio);
  1904 +
  1905 + st_lb_Etiqueta2.Caption := DeCrypt(XML_RetornaValor('te_etiqueta2', strConfigsPatrimonio));
  1906 + st_lb_Etiqueta2.Visible := true;
  1907 + st_vl_Etiqueta2.Caption := XML_ResgataValorPatrimonio('IT2',GetValorDatMemoria('Patrimonio.id_unid_organizacional_nivel2',v_tstrCipherOpened),strConfigsPatrimonio);
  1908 +
  1909 + st_lb_Etiqueta3.Caption := DeCrypt(XML_RetornaValor('te_etiqueta3', strConfigsPatrimonio));
  1910 + st_lb_Etiqueta3.Visible := true;
  1911 + st_vl_Etiqueta3.Caption := GetValorDatMemoria('Patrimonio.te_localizacao_complementar',v_tstrCipherOpened);
  1912 +
  1913 +
  1914 + if (DeCrypt(XML_RetornaValor('in_exibir_etiqueta4', strConfigsPatrimonio)) = 'S') then
  1915 + begin
  1916 + st_lb_Etiqueta4.Caption := DeCrypt(XML_RetornaValor('te_etiqueta4', strConfigsPatrimonio));
  1917 + st_lb_Etiqueta4.Visible := true;
  1918 + st_vl_etiqueta4.Caption := GetValorDatMemoria('Patrimonio.te_info_patrimonio1',v_tstrCipherOpened);
  1919 + end;
  1920 +
  1921 + if (DeCrypt(XML_RetornaValor('in_exibir_etiqueta5', strConfigsPatrimonio)) = 'S') then
  1922 + begin
  1923 + st_lb_Etiqueta5.Caption := DeCrypt(XML_RetornaValor('te_etiqueta5', strConfigsPatrimonio));
  1924 + st_lb_Etiqueta5.Visible := true;
  1925 + st_vl_etiqueta5.Caption := GetValorDatMemoria('Patrimonio.te_info_patrimonio2',v_tstrCipherOpened);
  1926 + end;
  1927 +
  1928 + if (DeCrypt(XML_RetornaValor('in_exibir_etiqueta6', strConfigsPatrimonio)) = 'S') then
  1929 + begin
  1930 + st_lb_Etiqueta6.Caption := DeCrypt(XML_RetornaValor('te_etiqueta6', strConfigsPatrimonio));
  1931 + st_lb_Etiqueta6.Visible := true;
  1932 + st_vl_etiqueta6.Caption := GetValorDatMemoria('Patrimonio.te_info_patrimonio3',v_tstrCipherOpened);
  1933 + end;
  1934 +
  1935 + if (DeCrypt(XML_RetornaValor('in_exibir_etiqueta7', strConfigsPatrimonio)) = 'S') then
  1936 + begin
  1937 + st_lb_Etiqueta7.Caption := DeCrypt(XML_RetornaValor('te_etiqueta7', strConfigsPatrimonio));
  1938 + st_lb_Etiqueta7.Visible := true;
  1939 + st_vl_etiqueta7.Caption := GetValorDatMemoria('Patrimonio.te_info_patrimonio4',v_tstrCipherOpened);
  1940 + end;
  1941 +
  1942 + if (DeCrypt(XML_RetornaValor('in_exibir_etiqueta8', strConfigsPatrimonio)) = 'S') then
  1943 + begin
  1944 + st_lb_Etiqueta8.Caption := DeCrypt(XML_RetornaValor('te_etiqueta8', strConfigsPatrimonio));
  1945 + st_lb_Etiqueta8.Visible := true;
  1946 + st_vl_etiqueta8.Caption := GetValorDatMemoria('Patrimonio.te_info_patrimonio5',v_tstrCipherOpened);
  1947 + end;
  1948 +
  1949 + if (DeCrypt(XML_RetornaValor('in_exibir_etiqueta9', strConfigsPatrimonio)) = 'S') then
  1950 + begin
  1951 + st_lb_Etiqueta9.Caption := DeCrypt(XML_RetornaValor('te_etiqueta9', strConfigsPatrimonio));
  1952 + st_lb_Etiqueta9.Visible := true;
  1953 + st_vl_etiqueta9.Caption := GetValorDatMemoria('Patrimonio.te_info_patrimonio6',v_tstrCipherOpened);
  1954 + end;
  1955 +
1819 1956 end;
1820 1957  
1821 1958 procedure TFormularioGeral.Bt_Fechar_InfosGeraisClick(Sender: TObject);
... ... @@ -1824,4 +1961,182 @@ procedure TFormularioGeral.Bt_Fechar_InfosGeraisClick(Sender: TObject);
1824 1961 FormularioGeral.Visible := false;
1825 1962 end;
1826 1963  
  1964 +Function TFormularioGeral.XML_RetornaValor(Tag : String; Fonte : String): String;
  1965 +VAR
  1966 + Parser : TXmlParser;
  1967 +begin
  1968 + Parser := TXmlParser.Create;
  1969 + Parser.Normalize := TRUE;
  1970 + Parser.LoadFromBuffer(PAnsiChar(Fonte));
  1971 + Parser.StartScan;
  1972 + WHILE Parser.Scan DO
  1973 + Begin
  1974 + if (Parser.CurPartType in [ptContent, ptCData]) Then // Process Parser.CurContent field here
  1975 + begin
  1976 + if (UpperCase(Parser.CurName) = UpperCase(Tag)) then
  1977 + Result := RemoveZerosFimString(Parser.CurContent);
  1978 + end;
  1979 + end;
  1980 + Parser.Free;
  1981 + log_DEBUG('XML Parser retornando: "'+Result+'" para Tag "'+Tag+'"');
  1982 +end;
  1983 +
  1984 +Function TFormularioGeral.XML_ResgataValorPatrimonio(strIT, strID : String; Fonte : String): String;
  1985 +VAR Parser : TXmlParser;
  1986 + strItemName,
  1987 + strTagName,
  1988 + strValor : String;
  1989 +begin
  1990 + Parser := TXmlParser.Create;
  1991 + Parser.Normalize := TRUE;
  1992 + Parser.LoadFromBuffer(PAnsiChar(Fonte));
  1993 + Parser.StartScan;
  1994 + WHILE Parser.Scan DO
  1995 + Begin
  1996 + strItemName := UpperCase(Parser.CurName);
  1997 + if (Parser.CurPartType = ptStartTag) and (strItemName = strIT) Then
  1998 + strTagName := strIT
  1999 + else if (Parser.CurPartType = ptEndTag) and (strItemName = strIT) then
  2000 + strTagName := ''
  2001 + else if (Parser.CurPartType in [ptContent, ptCData]) and (strTagName = strIT)Then
  2002 + Begin
  2003 + strValor := DeCrypt(Parser.CurContent);
  2004 + if (strItemName = strID) then
  2005 + Begin
  2006 + Result := strValor;
  2007 + exit;
  2008 + End;
  2009 + End;
  2010 + end;
  2011 + Parser.Free;
  2012 +end;
  2013 +
  2014 +// Solução baixada de http://www.delphidabbler.com/codesnip.php?action=named&routines=URLDecode&showsrc=1
  2015 +function TFormularioGeral.URLDecode(const S: string): string;
  2016 +var
  2017 + Idx: Integer; // loops thru chars in string
  2018 + Hex: string; // string of hex characters
  2019 + Code: Integer; // hex character code (-1 on error)
  2020 +begin
  2021 + // Intialise result and string index
  2022 + Result := '';
  2023 + Idx := 1;
  2024 + // Loop thru string decoding each character
  2025 + while Idx <= Length(S) do
  2026 + begin
  2027 + case S[Idx] of
  2028 + '%':
  2029 + begin
  2030 + // % should be followed by two hex digits - exception otherwise
  2031 + if Idx <= Length(S) - 2 then
  2032 + begin
  2033 + // there are sufficient digits - try to decode hex digits
  2034 + Hex := S[Idx+1] + S[Idx+2];
  2035 + Code := SysUtils.StrToIntDef('$' + Hex, -1);
  2036 + Inc(Idx, 2);
  2037 + end
  2038 + else
  2039 + // insufficient digits - error
  2040 + Code := -1;
  2041 + // check for error and raise exception if found
  2042 + if Code = -1 then
  2043 + raise SysUtils.EConvertError.Create(
  2044 + 'Invalid hex digit in URL'
  2045 + );
  2046 + // decoded OK - add character to result
  2047 + Result := Result + Chr(Code);
  2048 + end;
  2049 + '+':
  2050 + // + is decoded as a space
  2051 + Result := Result + ' '
  2052 + else
  2053 + // All other characters pass thru unchanged
  2054 + Result := Result + S[Idx];
  2055 + end;
  2056 + Inc(Idx);
  2057 + end;
  2058 +end;
  2059 +
  2060 +procedure TFormularioGeral.IdHTTPServerCACICCommandGet(
  2061 + AThread: TIdPeerThread; ARequestInfo: TIdHTTPRequestInfo;
  2062 + AResponseInfo: TIdHTTPResponseInfo);
  2063 +var strXML,
  2064 + strCmd,
  2065 + strFileName,
  2066 + strFileHash : String;
  2067 + intAux : integer;
  2068 + boolOK : boolean;
  2069 +begin
  2070 + // **********************************************************************************************************
  2071 + // Esta procedure tratará os comandos e suas ações, enviados em um pacote XML na requisição, conforme abaixo:
  2072 + // **********************************************************************************************************
  2073 + // Execute -> Comando que forçará a execução do Gerente de Coletas (Sugestão: Configurar coletas forçadas no Gerente WEB e executar esse comando)
  2074 + // Requisição: Tag <Execute>
  2075 + // Respostas: AResponseinfo.ContentText := AResponseinfo.ContentText + 'OK'
  2076 + //
  2077 + // Ask -> Comando que perguntará sobre a existência de um determinado arquivo na estação.
  2078 + // Requisição: Tag <FileName>: Nome do arquivo a pesquisar no repositório local
  2079 + // Tag <FileHash>: Hash referente ao arquivo a ser pesquisado no repositório local
  2080 + // Respostas: AResponseinfo.ContentText := AResponseinfo.ContentText + 'OK';
  2081 + // AResponseinfo.ContentText := AResponseinfo.ContentText + 'Tenho' ou
  2082 + // AResponseinfo.ContentText := AResponseinfo.ContentText + 'NaoTenho' ou
  2083 + // AResponseinfo.ContentText := AResponseinfo.ContentText + 'Baixando' ou
  2084 + // AResponseinfo.ContentText := AResponseinfo.ContentText + 'Ocupado'.
  2085 + //
  2086 + //
  2087 + // Erase -> Comando que provocará a exclusão de determinado arquivo.
  2088 + // Deverá ser acompanhado das tags <FileName> e <FileHash>
  2089 + // Requisição: Tag <FileName>: Nome do arquivo a ser excluído do repositório local
  2090 + // Tag <FileHash>: Hash referente ao arquivo a ser excluído do repositório local
  2091 + // Respostas: AResponseinfo.ContentText := AResponseinfo.ContentText + 'OK';
  2092 + //
  2093 + //
  2094 + // Exit -> Comando para finalização do agente principal (bandeja)
  2095 +
  2096 + // Palavra Chave definida por Ger_Cols, enviada e armazenada no BD. A autenticação da comunicação é baseada na verificação deste valor.
  2097 + // te_palavra_chave -> <TE_PALAVRA_CHAVE>
  2098 +
  2099 + // Tratamento da requisição http...
  2100 + strXML := URLDecode(ARequestInfo.UnparsedParams);
  2101 + intAux := Pos('=',strXML);
  2102 + strXML := copy(strXML,(intAux+1),StrLen(PAnsiChar(strXML))-intAux);
  2103 + strXML := DeCrypt(strXML);
  2104 +
  2105 +
  2106 +
  2107 + // Autenticação e tratamento da requisição
  2108 + if (XML_RetornaValor('te_palavra_chave',strXML) = FormularioGeral.getValorDatMemoria('Configs.te_palavra_chave',v_tstrCipherOpened)) then
  2109 + Begin
  2110 + strCmd := XML_RetornaValor('cmd',strXML);
  2111 + // As ações terão seus valores
  2112 +
  2113 + if (strCmd in ['Execute','Ask','Erase','Exit']) then
  2114 + AResponseinfo.ContentText := 'OK'
  2115 + else
  2116 + AResponseinfo.ContentText := 'COMANDO NÃO PERMITIDO!';
  2117 + End
  2118 + else
  2119 + AResponseinfo.ContentText := 'ACESSO NÃO PERMITIDO!';
  2120 +
  2121 + if (strCmd = 'Execute') then
  2122 + ExecutaCacic(nil);
  2123 + else if (strCmd = 'Ask') then
  2124 + Begin
  2125 + strFileName := XML_RetornaValor('FileName',strXML);
  2126 + strFileHash := XML_RetornaValor('FileHash',strXML);
  2127 + End
  2128 + else if (strCmd = 'Erase') then
  2129 + else if (strCmd = 'Exit') then
  2130 + Finaliza;
  2131 +
  2132 +end;
  2133 +
  2134 +procedure TFormularioGeral.IdFTPServer1UserLogin(ASender: TIdFTPServerThread; const AUsername, APassword: String; var AAuthenticated: Boolean);
  2135 +begin
  2136 + AAuthenticated := false;
  2137 + if (AUsername = 'CACIC') and
  2138 + (APassword=getValorDatMemoria('Configs.PalavraChave',v_tstrCipherOpened)) then
  2139 + AAuthenticated := true;
  2140 +end;
  2141 +
1827 2142 end.
... ...
vaca/main_vaca.dfm
1 1 object Form1: TForm1
2   - Left = 27
3   - Top = 146
  2 + Left = 276
  3 + Top = 405
4 4 AutoScroll = False
5 5 Caption = 'VACA - Vers'#245'es Agentes Creator/Atualizator'
6   - ClientHeight = 336
  6 + ClientHeight = 334
7 7 ClientWidth = 647
8 8 Color = clBtnFace
9 9 Font.Charset = DEFAULT_CHARSET
... ... @@ -89,13 +89,13 @@ object Form1: TForm1
89 89 OnCreate = FormCreate
90 90 DesignSize = (
91 91 647
92   - 336)
  92 + 334)
93 93 PixelsPerInch = 96
94 94 TextHeight = 13
95 95 object Label1: TLabel
96 96 Left = 2
97 97 Top = 0
98   - Width = 626
  98 + Width = 643
99 99 Height = 27
100 100 Alignment = taCenter
101 101 AutoSize = False
... ... @@ -112,7 +112,7 @@ object Form1: TForm1
112 112 object Label2: TLabel
113 113 Left = 2
114 114 Top = 27
115   - Width = 626
  115 + Width = 643
116 116 Height = 13
117 117 Alignment = taCenter
118 118 AutoSize = False
... ... @@ -130,7 +130,7 @@ object Form1: TForm1
130 130 object Label3: TLabel
131 131 Left = 2
132 132 Top = 41
133   - Width = 626
  133 + Width = 643
134 134 Height = 13
135 135 Alignment = taCenter
136 136 AutoSize = False
... ... @@ -203,26 +203,27 @@ object Form1: TForm1
203 203 OnClick = Image1Click
204 204 end
205 205 object Panel1: TPanel
206   - Left = 592
  206 + Left = 583
207 207 Top = 314
208   - Width = 54
  208 + Width = 62
209 209 Height = 20
210 210 BevelInner = bvRaised
211 211 BevelOuter = bvLowered
212 212 Caption = 'Panel1'
213 213 TabOrder = 3
214 214 object Label4: TLabel
215   - Left = 3
216   - Top = 3
217   - Width = 47
218   - Height = 13
  215 + Left = 2
  216 + Top = 2
  217 + Width = 58
  218 + Height = 16
  219 + Align = alClient
219 220 Alignment = taCenter
220 221 Caption = 'Label4'
221 222 end
222 223 end
223 224 object Bt_Fechar: TButton
224 225 Left = 551
225   - Top = 156
  226 + Top = 154
226 227 Width = 81
227 228 Height = 30
228 229 Cursor = crHandPoint
... ... @@ -235,7 +236,7 @@ object Form1: TForm1
235 236 end
236 237 object Bt_VAI: TButton
237 238 Left = 551
238   - Top = 116
  239 + Top = 114
239 240 Width = 81
240 241 Height = 30
241 242 Cursor = crHandPoint
... ... @@ -253,7 +254,7 @@ object Form1: TForm1
253 254 Left = 0
254 255 Top = 72
255 256 Width = 534
256   - Height = 260
  257 + Height = 258
257 258 Anchors = [akLeft, akTop, akRight, akBottom]
258 259 BiDiMode = bdLeftToRight
259 260 Color = clWhite
... ... @@ -308,70 +309,134 @@ object Form1: TForm1
308 309 Top = 243
309 310 Bitmap = {
310 311 494C010102000400040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
311   - 0000000000003600000028000000400000001000000001001000000000000008
312   - 0000000000000000000000000000000000000000F75EEF3DEF3DEF3DEF3DEF3D
313   - EF3DEF3DEF3DEF3DEF3DEF3DEF3DEF3D00000000000000000000EF3D10420000
  312 + 0000000000003600000028000000400000001000000001002000000000000010
  313 + 00000000000000000000000000000000000000000000BDBDBD007B7B7B007B7B
  314 + 7B007B7B7B007B7B7B007B7B7B007B7B7B007B7B7B007B7B7B007B7B7B007B7B
  315 + 7B007B7B7B007B7B7B007B7B7B00000000000000000000000000000000000000
  316 + 00007B7B7B008484840000000000000000000000000000000000000000000000
  317 + 0000000000000000000000000000000000000000000000000000000000000000
  318 + 0000000000000000000000000000000000000000000000000000000000000000
  319 + 0000000000000000000000000000000000000000000000000000000000000000
  320 + 0000000000000000000000000000000000000000000000000000000000000000
  321 + 00000000000000000000000000000000000000393900007B7B00007B7B00007B
  322 + 7B00007B7B00007B7B00007B7B00007B7B00007B7B00007B7B00007B7B00007B
  323 + 7B00007B7B00007B7B00000000007B7B7B000000000000000000000000000000
  324 + 0000319C0000319C00007B7B7B00000000000000000000000000000000000000
  325 + 0000000000000000000000000000000000000000000000000000000000000000
  326 + 0000000000000000000000000000000000000000000000000000000000000000
  327 + 0000000000000000000000000000000000000000000000000000000000000000
  328 + 0000000000000000000000000000000000000000000000000000000000000000
  329 + 000000000000000000000000000000000000007B7B0000FFFF0000FFFF0000FF
  330 + FF0000FFFF0000FFFF0000BDBD00007B7B0000FFFF0000FFFF0000FFFF0000FF
  331 + FF0000FFFF0000BDBD0000000000BDBDBD000000000000000000000000008484
  332 + 8400319C0000319C0000319C0000848484000000000000000000000000000000
  333 + 0000000000000000000000000000000000000000000000000000000000000000
  334 + 0000000000000000000000000000000000000000000000000000000000000000
  335 + 0000000000000000000000000000000000000000000000000000000000000000
  336 + 0000000000000000000000000000000000000000000000000000000000000000
  337 + 0000000000000000000000000000000000007B7B7B0000FFFF0000FFFF0000FF
  338 + FF0000FFFF0000FFFF000000000000000000007B7B0000FFFF0000FFFF0000FF
  339 + FF0000FFFF0000393900393939000000000000000000000000007B7B7B00319C
  340 + 0000319C0000319C0000319C0000319C00007B7B7B0000000000000000000000
  341 + 0000000000000000000000000000000000000000000000000000000000000000
  342 + 0000000000000000000000000000000000000000000000000000000000000000
  343 + 0000000000000000000000000000000000000000000000000000000000000000
  344 + 0000000000000000000000000000000000000000000000000000000000000000
  345 + 00000000000000000000000000000000000000000000007B7B0000FFFF0000FF
  346 + FF0000FFFF0000FFFF0000BDBD00007B7B0000FFFF0000FFFF0000FFFF0000FF
  347 + FF0000BDBD0000000000BDBDBD00000000000000000084848400319C0000319C
  348 + 0000CEFF9C00319C0000319C0000319C0000319C000084848400000000000000
  349 + 0000000000000000000000000000000000000000000000000000000000000000
  350 + 0000000000000000000000000000000000000000000000000000000000000000
  351 + 0000000000000000000000000000000000000000000000000000000000000000
  352 + 0000000000000000000000000000000000000000000000000000000000000000
  353 + 000000000000000000000000000000000000000000007B7B7B0000FFFF0000FF
  354 + FF0000FFFF0000FFFF00007B7B000000000000FFFF0000FFFF0000FFFF0000FF
  355 + FF000039390039393900000000000000000000000000319C0000319C0000319C
  356 + 000000000000CEFF9C00319C0000319C0000319C000084848400000000000000
  357 + 0000000000000000000000000000000000000000000000000000000000000000
  358 + 0000000000000000000000000000000000000000000000000000000000000000
  359 + 0000000000000000000000000000000000000000000000000000000000000000
  360 + 0000000000000000000000000000000000000000000000000000000000000000
  361 + 0000000000000000000000000000000000000000000000000000007B7B0000FF
  362 + FF0000FFFF0000FFFF00007B7B000000000000FFFF0000FFFF0000FFFF0000BD
  363 + BD0000000000BDBDBD00000000000000000000000000CEFF9C00319C0000CEFF
  364 + 9C000000000000000000CEFF9C00319C0000319C0000319C0000848484000000
  365 + 0000000000000000000000000000000000000000000000000000000000000000
  366 + 0000000000000000000000000000000000000000000000000000000000000000
  367 + 0000000000000000000000000000000000000000000000000000000000000000
  368 + 0000000000000000000000000000000000000000000000000000000000000000
  369 + 00000000000000000000000000000000000000000000000000007B7B7B0000FF
  370 + FF0000FFFF0000FFFF000000000000000000007B7B0000FFFF0000FFFF000039
  371 + 3900393939000000000000000000000000000000000000000000CEFF9C000000
  372 + 0000000000000000000000000000CEFF9C00319C0000319C0000319C00008484
  373 + 8400000000000000000000000000000000000000000000000000000000000000
  374 + 0000000000000000000000000000000000000000000000000000000000000000
  375 + 0000000000000000000000000000000000000000000000000000000000000000
  376 + 0000000000000000000000000000000000000000000000000000000000000000
  377 + 000000000000000000000000000000000000000000000000000000000000007B
  378 + 7B0000FFFF0000FFFF000000000000000000007B7B0000FFFF0000BDBD000000
  379 + 0000BDBDBD000000000000000000000000000000000000000000CEFF9C000000
  380 + 0000000000000000000000000000CEFF9C00319C0000319C0000319C00008484
  381 + 8400000000000000000000000000000000000000000000000000000000000000
  382 + 0000000000000000000000000000000000000000000000000000000000000000
  383 + 0000000000000000000000000000000000000000000000000000000000000000
  384 + 0000000000000000000000000000000000000000000000000000000000000000
  385 + 0000000000000000000000000000000000000000000000000000000000007B7B
  386 + 7B0000FFFF0000FFFF000000000000000000007B7B0000FFFF00003939003939
  387 + 3900000000000000000000000000000000000000000000000000000000000000
  388 + 000000000000000000000000000000000000CEFF9C00319C0000319C0000319C
  389 + 0000000000000000000000000000000000000000000000000000000000000000
  390 + 0000000000000000000000000000000000000000000000000000000000000000
  391 + 0000000000000000000000000000000000000000000000000000000000000000
  392 + 0000000000000000000000000000000000000000000000000000000000000000
  393 + 0000000000000000000000000000000000000000000000000000000000000000
  394 + 0000007B7B0000FFFF000000000000000000007B7B0000BDBD0000000000BDBD
  395 + BD00000000000000000000000000000000000000000000000000000000000000
  396 + 00000000000000000000000000000000000000000000CEFF9C00319C0000319C
  397 + 0000848484000000000000000000000000000000000000000000000000000000
  398 + 0000000000000000000000000000000000000000000000000000000000000000
  399 + 0000000000000000000000000000000000000000000000000000000000000000
  400 + 0000000000000000000000000000000000000000000000000000000000000000
  401 + 0000000000000000000000000000000000000000000000000000000000000000
  402 + 00007B7B7B0000FFFF0000BDBD00007B7B0000FFFF0000393900393939000000
  403 + 0000000000000000000000000000000000000000000000000000000000000000
  404 + 0000000000000000000000000000000000000000000000000000CEFF9C00319C
  405 + 0000319C00008484840000000000000000000000000000000000000000000000
  406 + 0000000000000000000000000000000000000000000000000000000000000000
  407 + 0000000000000000000000000000000000000000000000000000000000000000
  408 + 0000000000000000000000000000000000000000000000000000000000000000
  409 + 0000000000000000000000000000000000000000000000000000000000000000
  410 + 000000000000007B7B0000FFFF0000FFFF0000BDBD0000000000BDBDBD000000
  411 + 0000000000000000000000000000000000000000000000000000000000000000
  412 + 000000000000000000000000000000000000000000000000000000000000CEFF
  413 + 9C00319C0000319C00007B7B7B00000000000000000000000000000000000000
  414 + 0000000000000000000000000000000000000000000000000000000000000000
  415 + 0000000000000000000000000000000000000000000000000000000000000000
314 416 0000000000000000000000000000000000000000000000000000000000000000
315 417 0000000000000000000000000000000000000000000000000000000000000000
316   - 000000000000000000000000000000000000E01CE03DE03DE03DE03DE03DE03D
317   - E03DE03DE03DE03DE03DE03DE03D0000EF3D000000000000000066026602EF3D
  418 + 0000000000007B7B7B0000FFFF0000FFFF000039390039393900000000000000
318 419 0000000000000000000000000000000000000000000000000000000000000000
319 420 0000000000000000000000000000000000000000000000000000000000000000
320   - 000000000000000000000000000000000000E03DE07FE07FE07FE07FE07FE05E
321   - E03DE07FE07FE07FE07FE07FE05E0000F75E0000000000001042660266026602
322   - 1042000000000000000000000000000000000000000000000000000000000000
  421 + 0000319C0000319C00007B7B7B00000000000000000000000000000000000000
323 422 0000000000000000000000000000000000000000000000000000000000000000
324   - 000000000000000000000000000000000000EF3DE07FE07FE07FE07FE07F0000
325   - 0000E03DE07FE07FE07FE07FE01CE71C000000000000EF3D6602660266026602
326   - 6602EF3D00000000000000000000000000000000000000000000000000000000
327 423 0000000000000000000000000000000000000000000000000000000000000000
328   - 0000000000000000000000000000000000000000E03DE07FE07FE07FE07FE05E
329   - E03DE07FE07FE07FE07FE05E0000F75E00000000104266026602F94F66026602
330   - 6602660210420000000000000000000000000000000000000000000000000000
331 424 0000000000000000000000000000000000000000000000000000000000000000
332   - 0000000000000000000000000000000000000000EF3DE07FE07FE07FE07FE03D
333   - 0000E07FE07FE07FE07FE01CE71C0000000000006602660266020000F94F6602
334   - 6602660210420000000000000000000000000000000000000000000000000000
335 425 0000000000000000000000000000000000000000000000000000000000000000
336   - 00000000000000000000000000000000000000000000E03DE07FE07FE07FE03D
337   - 0000E07FE07FE07FE05E0000F75E000000000000F94F6602F94F00000000F94F
338   - 6602660266021042000000000000000000000000000000000000000000000000
  426 + 00000000000000000000397B7B00007B7B00BDBDBD0000000000000000000000
339 427 0000000000000000000000000000000000000000000000000000000000000000
340   - 00000000000000000000000000000000000000000000EF3DE07FE07FE07F0000
341   - 0000E03DE07FE07FE01CE71C00000000000000000000F94F0000000000000000
342   - F94F660266026602104200000000000000000000000000000000000000000000
343 428 0000000000000000000000000000000000000000000000000000000000000000
344   - 000000000000000000000000000000000000000000000000E03DE07FE07F0000
345   - 0000E03DE07FE05E0000F75E00000000000000000000F94F0000000000000000
346   - F94F660266026602104200000000000000000000000000000000000000000000
  429 + 0000CEFF9C00319C0000319C0000000000000000000000000000000000000000
347 430 0000000000000000000000000000000000000000000000000000000000000000
348   - 000000000000000000000000000000000000000000000000EF3DE07FE07F0000
349   - 0000E03DE07FE01CE71C00000000000000000000000000000000000000000000
350   - 0000F94F66026602660200000000000000000000000000000000000000000000
351 431 0000000000000000000000000000000000000000000000000000000000000000
352   - 0000000000000000000000000000000000000000000000000000E03DE07F0000
353   - 0000E03DE05E0000F75E00000000000000000000000000000000000000000000
354   - 00000000F94F6602660210420000000000000000000000000000000000000000
355 432 0000000000000000000000000000000000000000000000000000000000000000
356   - 0000000000000000000000000000000000000000000000000000EF3DE07FE05E
357   - E03DE07FE01CE71C000000000000000000000000000000000000000000000000
358   - 000000000000F94F660266021042000000000000000000000000000000000000
359 433 0000000000000000000000000000000000000000000000000000000000000000
360   - 00000000000000000000000000000000000000000000000000000000E03DE07F
361   - E07FE05E0000F75E000000000000000000000000000000000000000000000000
362   - 0000000000000000F94F66026602EF3D00000000000000000000000000000000
363 434 0000000000000000000000000000000000000000000000000000000000000000
364   - 00000000000000000000000000000000000000000000000000000000EF3DE07F
365   - E07FE01CE71C0000000000000000000000000000000000000000000000000000
366   - 0000000000000000000066026602EF3D00000000000000000000000000000000
367 435 0000000000000000000000000000000000000000000000000000000000000000
368   - 000000000000000000000000000000000000000000000000000000000000E73D
369   - E03DF75E00000000000000000000000000000000000000000000000000000000
370   - 00000000000000000000F94F6602660200000000000000000000000000000000
371 436 0000000000000000000000000000000000000000000000000000000000000000
  437 + 000000000000CEFF9C0000000000000000000000000000000000000000000000
372 438 0000000000000000000000000000000000000000000000000000000000000000
373 439 0000000000000000000000000000000000000000000000000000000000000000
374   - 000000000000000000000000F94F000000000000000000000000000000000000
375 440 0000000000000000000000000000000000000000000000000000000000000000
376 441 000000000000000000000000000000000000424D3E000000000000003E000000
377 442 2800000040000000100000000100010000000000800000000000000000000000
... ...
vaca/main_vaca.pas
... ... @@ -3,8 +3,19 @@ unit main_vaca;
3 3 interface
4 4  
5 5 uses
6   - Windows, SysUtils, Classes, Graphics, Controls, Forms,
7   - StdCtrls, ExtCtrls, ImgList, ComCtrls, PJVersionInfo, inifiles;
  6 + Windows,
  7 + SysUtils,
  8 + Classes,
  9 + Graphics,
  10 + Controls,
  11 + Forms,
  12 + StdCtrls,
  13 + ExtCtrls,
  14 + ImgList,
  15 + ComCtrls,
  16 + PJVersionInfo,
  17 + inifiles,
  18 + md5;
8 19  
9 20 type
10 21 TForm1 = class(TForm)
... ... @@ -33,7 +44,11 @@ type
33 44 procedure Image1Click(Sender: TObject);
34 45 procedure ListAdvancedCustomDrawSubItem(Sender: TCustomListView;
35 46 Item: TListItem; SubItem: Integer; State: TCustomDrawState;
36   - Stage: TCustomDrawStage; var DefaultDraw: Boolean);
  47 + Stage: TCustomDrawStage; var DefaultDraw: Boolean);
  48 + function InsertItemLISTA(strName,strVerINI,strVerEXE,strSize,strDate : string; boolOK : boolean) : boolean;
  49 + function getDadosAgenteLinux(strNomeAgenteLinux:String) : TStrings;
  50 + procedure RemontaINI(strTripaChavesValores,p_Path : String);
  51 + function GetFileHash(strFileName : String) : String;
37 52 private
38 53 { Private declarations }
39 54 public
... ... @@ -41,7 +56,6 @@ type
41 56  
42 57 var
43 58 Form1: TForm1;
44   - v_versao_INI, v_versao_EXE : string;
45 59  
46 60 implementation
47 61  
... ... @@ -49,13 +63,13 @@ implementation
49 63 //Para gravar no Arquivo INI...
50 64 function TForm1.SetValorChaveRegIni(p_Secao: String; p_Chave: String; p_Valor: String; p_Path : String): String;
51 65 var Reg_Ini : TIniFile;
52   - File_Ini : TextFile;
53 66 begin
54 67 // FileSetAttr (p_Path,0);
55 68 {
56 69 To remove write protection on a file:
57 70 Den Schreibschutz einer Datei aufheben:
58 71 }
  72 +
59 73 if (FileGetAttr(p_Path) and faReadOnly) > 0 then
60 74 FileSetAttr(p_Path, FileGetAttr(p_Path) xor faReadOnly);
61 75  
... ... @@ -73,31 +87,34 @@ var
73 87 v_SectionName, v_KeyName : string;
74 88 begin
75 89 Result := '';
76   - v_SectionName := '[' + p_SectionName + ']';
77   - v_Size_Section := strLen(PChar(v_SectionName));
78   - v_KeyName := p_KeyName + '=';
79   - v_Size_Key := strLen(PChar(v_KeyName));
80   - FileText := TStringList.Create;
81   - try
82   - FileText.LoadFromFile(p_IniFileName);
83   - For i := 0 To FileText.Count - 1 Do
84   - Begin
85   - if (LowerCase(Trim(PChar(Copy(FileText[i],1,v_Size_Section)))) = LowerCase(Trim(PChar(v_SectionName)))) then
86   - Begin
87   - For j := i to FileText.Count - 1 Do
88   - Begin
89   - if (LowerCase(Trim(PChar(Copy(FileText[j],1,v_Size_Key)))) = LowerCase(Trim(PChar(v_KeyName)))) then
90   - Begin
91   - Result := PChar(Copy(FileText[j],v_Size_Key + 1,strLen(PChar(FileText[j]))-v_Size_Key));
92   - Break;
93   - End;
94   - End;
95   - End;
96   - if (Result <> '') then break;
97   - End;
98   - finally
99   - FileText.Free;
100   - end;
  90 + Try
  91 + v_SectionName := '[' + p_SectionName + ']';
  92 + v_Size_Section := strLen(PChar(v_SectionName));
  93 + v_KeyName := p_KeyName + '=';
  94 + v_Size_Key := strLen(PChar(v_KeyName));
  95 + FileText := TStringList.Create;
  96 + try
  97 + FileText.LoadFromFile(p_IniFileName);
  98 + For i := 0 To FileText.Count - 1 Do
  99 + Begin
  100 + if (LowerCase(Trim(PChar(Copy(FileText[i],1,v_Size_Section)))) = LowerCase(Trim(PChar(v_SectionName)))) then
  101 + Begin
  102 + For j := i to FileText.Count - 1 Do
  103 + Begin
  104 + if (LowerCase(Trim(PChar(Copy(FileText[j],1,v_Size_Key)))) = LowerCase(Trim(PChar(v_KeyName)))) then
  105 + Begin
  106 + Result := PChar(Copy(FileText[j],v_Size_Key + 1,strLen(PChar(FileText[j]))-v_Size_Key));
  107 + Break;
  108 + End;
  109 + End;
  110 + End;
  111 + if (Result <> '') then break;
  112 + End;
  113 + finally
  114 + FileText.Free;
  115 + end;
  116 + Except
  117 + End;
101 118 end;
102 119 function TForm1.Get_File_Size(sFileToExamine: string; bInKBytes: Boolean): string;
103 120 var
... ... @@ -121,80 +138,177 @@ end;
121 138 procedure TForm1.FormCreate(Sender: TObject);
122 139 begin
123 140 Label4.Caption := 'v: '+GetVersionInfo(ExtractFilePath(Application.Exename)+'vaca.exe');
  141 + SetValorChaveRegIni('Informação','Nota','Versoes dos Agentes do Sistema CACIC',ExtractFilePath(Application.Exename)+'versoes_agentes.ini');
124 142 Refresh;
125 143 end;
  144 +// Para cálculo de HASH de determinado arquivo.
  145 +// Objetivo principal: Verificar autenticidade de agentes para trabalho cooperativo
  146 +// Anderson Peterle - Dataprev/ES - 08/Maio/2008
  147 +function TForm1.GetFileHash(strFileName : String) : String;
  148 +Begin
  149 + Result := 'Arquivo "'+strFileName+'" Inexistente!';
  150 + if (FileExists(strFileName)) then
  151 + Result := MD5Print(MD5File(strFileName));
  152 +End;
  153 +
  154 +procedure TForm1.RemontaINI(strTripaChavesValores,p_Path : String);
  155 +var Reg_Ini : TIniFile;
  156 + intAux : integer;
  157 + tstrAux1,
  158 + tstrAux2 : TStrings;
  159 +begin
  160 + tstrAux1 := TStrings.Create;
  161 + tstrAux1 := explode(strTripaChavesValores,'#');
  162 + tstrAux2 := TStrings.Create;
  163 +
  164 + Reg_Ini := TIniFile.Create(p_Path);
  165 + if (FileGetAttr(p_Path) and faReadOnly) > 0 then
  166 + FileSetAttr(p_Path, FileGetAttr(p_Path) xor faReadOnly);
  167 +
  168 + Reg_Ini.EraseSection('versoes_agentes');
  169 +
  170 + for intAux := 0 to (tstrAux1.Count -1) do
  171 + Begin
  172 + tstrAux2 := explode(tstrAux1[intAux],'=');
  173 + Reg_Ini.WriteString('versoes_agentes', tstrAux2[0], tstrAux2[1]);
  174 + End;
  175 +
  176 + tstrAux1.Free;
  177 + tstrAux2.Free;
  178 + Reg_Ini.Free;
  179 +End;
  180 +
  181 +function TForm1.InsertItemLISTA(strName,strVerINI,strVerEXE,strSize,strDate : string; boolOK : boolean) : boolean;
  182 +var intAux : integer;
  183 +Begin
  184 + intAux := Form1.List.Items.Count;
  185 +
  186 + Form1.List.Items.Add;
  187 + Form1.List.Items[intAux].Caption := '';
  188 + Form1.List.Items[intAux].SubItems.Add(strName);
  189 + Form1.List.Items[intAux].SubItems.Add(strVerINI);
  190 + Form1.List.Items[intAux].SubItems.Add(strVerEXE);
  191 + Form1.List.Items[intAux].SubItems.Add(strSize);
  192 + Form1.List.Items[intAux].SubItems.Add(strDate);
  193 +
  194 + if boolOK then
  195 + Form1.List.Items[intAux].ImageIndex := 1
  196 + else
  197 + Form1.List.Items[intAux].ImageIndex := 0;
  198 +End;
126 199  
127 200 procedure TForm1.Refresh;
128   -var v_modulos : string;
129   - v_array_modulos : TStrings;
130   - intAux, v_conta_itens, v_pointer : integer;
131   - v_mostra_atualiza : boolean;
  201 +var v_modulos,
  202 + strNomePacoteLinux,
  203 + strVersaoPacoteLinux,
  204 + strAux,
  205 + strTripaVersoesValidas : string;
  206 + v_array_modulos,
  207 + tstrAux,
  208 + tstrDadosAgenteLinux : TStrings;
  209 + intAux : integer;
  210 + boolAtivarAtualizaVersoes,
  211 + boolVersoesIguais : boolean;
132 212 begin
133 213 Caption:='VACA - Versões de Agentes do CACIC';
134 214 Screen.Cursor:=crHourglass;
135 215 List.Clear;
136   - v_mostra_atualiza := false;
  216 +
  217 + boolAtivarAtualizaVersoes := false;
  218 +
137 219 v_modulos := ListFileDir(ExtractFilePath(Application.Exename)+'*.exe',ExtractFileName(Application.Exename));
138   - v_pointer := 0;
  220 +
139 221 Try
140 222 if (v_modulos <> '') then
141 223 Begin
142 224 v_array_modulos := explode(v_modulos,'#');
143   - v_conta_itens :=0;
144   - if FileExists(ExtractFilePath(Application.Exename)+'versoes_agentes.ini') then
145   - Begin
146   - For intAux := 0 To v_array_modulos.count -1 Do
147   - Begin
148   - if (GetValorChaveRegIni('versoes_agentes',v_array_modulos[intAux],ExtractFilePath(Application.Exename)+'versoes_agentes.ini')<>'') then
149   - Begin
150   - v_versao_INI := GetValorChaveRegIni('versoes_agentes',v_array_modulos[intAux],ExtractFilePath(Application.Exename)+'versoes_agentes.ini');
151   - v_versao_EXE := GetVersionInfo(v_array_modulos[intAux]);
152   - List.Items.Add;
153   - List.Items[v_conta_itens].Caption := '';
154   - List.Items[v_conta_itens].SubItems.Add(v_array_modulos[intAux]);
155   - List.Items[v_conta_itens].SubItems.Add(v_versao_INI);
156   - List.Items[v_conta_itens].SubItems.Add(v_versao_EXE);
157   - List.Items[v_conta_itens].SubItems.Add(Get_File_Size(v_array_modulos[intAux],true));
158   - List.Items[v_conta_itens].SubItems.Add(DateToStr(FileDateToDateTime(FileAge(v_array_modulos[intAux]))));
159   -
160   - if (v_versao_INI = GetVersionInfo(v_array_modulos[intAux])) then
161   - List.Items[v_conta_itens].ImageIndex := 1
162   - else
163   - Begin
164   - List.Items[v_conta_itens].ImageIndex := 0;
165   - v_mostra_atualiza := true;
166   - End;
167   -
168   - v_conta_itens := v_conta_itens + 1;
169   - End;
170   - End;
171   - End
172   - else
  225 + For intAux := 0 To v_array_modulos.count -1 Do
173 226 Begin
174   - For intAux := 0 To v_array_modulos.count -1 Do
  227 + boolVersoesIguais := true;
  228 + if (GetValorChaveRegIni('versoes_agentes',v_array_modulos[intAux],ExtractFilePath(Application.Exename)+'versoes_agentes.ini')='') then
  229 + SetValorChaveRegIni('versoes_agentes',v_array_modulos[intAux],GetVersionInfo(v_array_modulos[intAux]),ExtractFilePath(Application.Exename)+'versoes_agentes.ini')
  230 + else if (GetValorChaveRegIni('versoes_agentes',v_array_modulos[intAux],ExtractFilePath(Application.Exename)+'versoes_agentes.ini')<>GetVersionInfo(v_array_modulos[intAux])) then
175 231 Begin
176   - v_versao_EXE := GetVersionInfo(v_array_modulos[intAux]);
177   - v_versao_INI := v_versao_EXE;
178   - SetValorChaveRegIni('versoes_agentes',v_array_modulos[intAux],v_versao_INI,ExtractFilePath(Application.Exename)+'versoes_agentes.ini');
179   - List.Items.Add;
180   - List.Items[v_conta_itens].Caption := '';
181   - List.Items[v_conta_itens].SubItems.Add(v_array_modulos[intAux]);
182   - List.Items[v_conta_itens].SubItems.Add(v_versao_INI);
183   - List.Items[v_conta_itens].SubItems.Add(v_versao_EXE);
184   - List.Items[v_conta_itens].SubItems.Add(Get_File_Size(v_array_modulos[intAux],true));
185   - List.Items[v_conta_itens].SubItems.Add(DateToStr(FileDateToDateTime(FileAge(v_array_modulos[intAux]))));
186   - List.Items[v_conta_itens].ImageIndex := 1;
187   - v_conta_itens := v_conta_itens + 1;
  232 + boolVersoesIguais := false;
  233 + boolAtivarAtualizaVersoes := true;
188 234 End;
  235 +
  236 + InsertItemLISTA(v_array_modulos[intAux],
  237 + GetValorChaveRegIni('versoes_agentes',v_array_modulos[intAux],ExtractFilePath(Application.Exename)+'versoes_agentes.ini'),
  238 + GetVersionInfo(v_array_modulos[intAux]),
  239 + Get_File_Size(v_array_modulos[intAux],true),
  240 + DateToStr(FileDateToDateTime(FileAge(v_array_modulos[intAux]))),
  241 + boolVersoesIguais);
  242 +
  243 + if (strTripaVersoesValidas <> '') then
  244 + strTripaVersoesValidas := strTripaVersoesValidas + '#';
  245 + strTripaVersoesValidas := strTripaVersoesValidas + v_array_modulos[intAux] + '=' + GetValorChaveRegIni('versoes_agentes',v_array_modulos[intAux],ExtractFilePath(Application.Exename)+'versoes_agentes.ini');
  246 + strTripaVersoesValidas := strTripaVersoesValidas + '#';
  247 + strTripaVersoesValidas := strTripaVersoesValidas + v_array_modulos[intAux] + '_HASH=' + GetFileHash(v_array_modulos[intAux]);
189 248 End;
190 249 End;
  250 + Except
  251 + End;
  252 +
  253 + Try
  254 + tstrAux := TStrings.Create;
  255 + v_modulos := ListFileDir(ExtractFilePath(Application.Exename)+'agentes_linux\*.tgz',ExtractFileName(Application.Exename));
  256 + Try
  257 + if (v_modulos <> '') then
  258 + Begin
  259 + v_array_modulos := explode(v_modulos,'#');
  260 + tstrDadosAgenteLinux := TStrings.Create;
  261 + For intAux := 0 To v_array_modulos.count -1 Do
  262 + Begin
  263 + boolVersoesIguais := true;
  264 + tstrDadosAgenteLinux := getDadosAgenteLinux(v_array_modulos[intAux]);
  265 +
  266 + if (GetValorChaveRegIni('versoes_agentes',tstrDadosAgenteLinux[0],ExtractFilePath(Application.Exename)+'versoes_agentes.ini')='') then
  267 + SetValorChaveRegIni('versoes_agentes',tstrDadosAgenteLinux[0],tstrDadosAgenteLinux[1],ExtractFilePath(Application.Exename)+'versoes_agentes.ini')
  268 + else if (GetValorChaveRegIni('versoes_agentes',tstrDadosAgenteLinux[0],ExtractFilePath(Application.Exename)+'versoes_agentes.ini') <> tstrDadosAgenteLinux[1]) then
  269 + Begin
  270 + boolVersoesIguais := false;
  271 + boolAtivarAtualizaVersoes := true;
  272 + End;
  273 +
  274 + InsertItemLISTA(tstrDadosAgenteLinux[0],
  275 + GetValorChaveRegIni('versoes_agentes',tstrDadosAgenteLinux[0],ExtractFilePath(Application.Exename)+'versoes_agentes.ini'),
  276 + tstrDadosAgenteLinux[1],
  277 + Get_File_Size(ExtractFilePath(Application.Exename)+'agentes_linux\'+v_array_modulos[intAux],true),
  278 + DateToStr(FileDateToDateTime(FileAge(ExtractFilePath(Application.Exename)+'agentes_linux\'+v_array_modulos[intAux]))),
  279 + boolVersoesIguais);
  280 +
  281 + if (strTripaVersoesValidas <> '') then
  282 + strTripaVersoesValidas := strTripaVersoesValidas + '#';
  283 + strTripaVersoesValidas := strTripaVersoesValidas + tstrDadosAgenteLinux[0] + '=' + GetValorChaveRegIni('versoes_agentes',tstrDadosAgenteLinux[0],ExtractFilePath(Application.Exename)+'versoes_agentes.ini');
  284 +
  285 + strTripaVersoesValidas := strTripaVersoesValidas + '#';
  286 +
  287 + strTripaVersoesValidas := strTripaVersoesValidas + 'te_pacote_PyCACIC=' + v_array_modulos[intAux];
  288 + strTripaVersoesValidas := strTripaVersoesValidas + '#';
  289 + strTripaVersoesValidas := strTripaVersoesValidas + 'te_pacote_PyCACIC_HASH= ' + GetFileHash(ExtractFilePath(Application.Exename)+'agentes_linux\'+v_array_modulos[intAux]);
  290 + End;
  291 + End;
  292 + Except
  293 + End;
191 294 finally
  295 + RemontaINI(strTripaVersoesValidas,ExtractFilePath(Application.Exename)+'versoes_agentes.ini');
192 296 List.Show;
193 297 Screen.Cursor:=crdefault;
194   - Bt_VAI.Enabled := v_mostra_atualiza;
  298 + Bt_VAI.Enabled := boolAtivarAtualizaVersoes;
195 299 end;
196 300 end;
197 301  
  302 +function TForm1.getDadosAgenteLinux(strNomeAgenteLinux:String) : TStrings;
  303 +var tstrAux : TStrings;
  304 + strAux : String;
  305 +Begin
  306 + strAux := StringReplace(strNomeAgenteLinux,'.tgz','',[rfReplaceAll]);
  307 + tstrAux := TStrings.Create;
  308 + tstrAux := Explode(strAux,'_');
  309 + Result := tstrAux;
  310 +End;
  311 +
198 312 Function TForm1.ListFileDir(Path,p_exception : string):string;
199 313 var
200 314 SR: TSearchRec;
... ... @@ -204,10 +318,10 @@ begin
204 318 begin
205 319 repeat
206 320 if (SR.Attr <> faDirectory) and (SR.Name <> p_exception) then
207   - begin
208   - if (FileList<>'') then FileList := FileList + '#';
209   - FileList := FileList + SR.Name;
210   - end;
  321 + Begin
  322 + if (FileList <> '') then FileList := FileList + '#';
  323 + FileList := FileList + SR.Name;
  324 + End
211 325 until FindNext(SR) <> 0;
212 326 FindClose(SR);
213 327 Result := FileList;
... ... @@ -253,7 +367,8 @@ end;
253 367  
254 368 procedure TForm1.Bt_VAIClick(Sender: TObject);
255 369 var v_modulos : string;
256   - v_array_modulos : TStrings;
  370 + v_array_modulos,
  371 + tstrDadosAgenteLinux : TStrings;
257 372 intAux : integer;
258 373 begin
259 374 Screen.Cursor:=crHourglass;
... ... @@ -264,17 +379,32 @@ begin
264 379 Begin
265 380 v_array_modulos := explode(v_modulos,'#');
266 381 For intAux := 0 To v_array_modulos.count -1 Do
267   - Begin
268 382 if (GetValorChaveRegIni('versoes_agentes',v_array_modulos[intAux],ExtractFilePath(Application.Exename)+'versoes_agentes.ini')<>'') then
269   - Begin
270 383 SetValorChaveRegIni('versoes_agentes',v_array_modulos[intAux],GetVersionInfo(v_array_modulos[intAux]),ExtractFilePath(Application.Exename)+'versoes_agentes.ini');
271   - End;
272   - End;
273 384 End;
274 385 finally
275 386 Screen.Cursor:=crdefault;
276 387 Refresh;
277 388 end;
  389 +
  390 +
  391 + tstrDadosAgenteLinux := TStrings.Create;
  392 + v_modulos := ListFileDir(ExtractFilePath(Application.Exename)+'agentes_linux/*.tgz',ExtractFileName(Application.Exename));
  393 +
  394 + Try
  395 + if (v_modulos <> '') then
  396 + Begin
  397 + v_array_modulos := explode(v_modulos,'#');
  398 + For intAux := 0 To v_array_modulos.count -1 Do
  399 + tstrDadosAgenteLinux := getDadosAgenteLinux(v_array_modulos[intAux]);
  400 + if (GetValorChaveRegIni('versoes_agentes',tstrDadosAgenteLinux[0],ExtractFilePath(Application.Exename)+'versoes_agentes.ini')<>'') then
  401 + SetValorChaveRegIni('versoes_agentes',tstrDadosAgenteLinux[0],tstrDadosAgenteLinux[1],ExtractFilePath(Application.Exename)+'versoes_agentes.ini')
  402 + End;
  403 + finally
  404 + Screen.Cursor:=crdefault;
  405 + Refresh;
  406 + end;
  407 +
278 408 end;
279 409  
280 410 procedure TForm1.Image1Click(Sender: TObject);
... ...
vaca/vaca.dpr
... ... @@ -8,7 +8,7 @@ uses
8 8  
9 9 begin
10 10 Application.Initialize;
11   - Application.Title := 'MSI Demo';
  11 + Application.Title := 'V.A.C.A.';
12 12 Application.CreateForm(TForm1, Form1);
13 13 Application.Run;
14 14 end.
... ...