From 683da8ded99c65272b9c757641f791416b508ae0 Mon Sep 17 00:00:00 2001 From: harpiain@gmail.com Date: Fri, 20 Feb 2009 03:30:39 +0000 Subject: [PATCH] - merge de branch (2.4) revisão [709:726] --- CACIC_Library.pas | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------- chkcacic/main.pas | 123 ++------------------------------------------------------------------------------------------------------------------------- chksis/chksis.dpr | 140 ++++++++++++++------------------------------------------------------------------------------------------------------------------------------ chksis/chksis_erro.ini | 2 -- chksis/main.ddp | Bin 51 -> 0 bytes chksis/main.dfm | 46 ---------------------------------------------- chksis/main.pas | 474 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ col_comp/col_comp.dpr | 108 ++++++++++++++++-------------------------------------------------------------------------------------------- col_hard/col_hard.dpr | 80 +++++++++----------------------------------------------------------------------- col_moni/col_moni.dpr | 70 +++++++--------------------------------------------------------------- col_moni/coleta_monitorado.pas | 226 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- col_moni/main_moni.ddp | Bin 51 -> 0 bytes col_moni/main_moni.dfm | 22 ---------------------- col_moni/main_moni.pas | 776 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- col_undi/col_undi.dpr | 86 ++++++++------------------------------------------------------------------------------ ger_cols/ger_cols.dpr | 111 +++++++++++---------------------------------------------------------------------------------------------------- ini_cols/ini_cols.dpr | 30 +----------------------------- mapa/main_mapa.pas | 107 +++++++++++------------------------------------------------------------------------------------------------ 18 files changed, 206 insertions(+), 2345 deletions(-) delete mode 100755 chksis/chksis_erro.ini delete mode 100755 chksis/main.ddp delete mode 100755 chksis/main.dfm delete mode 100755 chksis/main.pas delete mode 100755 col_moni/coleta_monitorado.pas delete mode 100755 col_moni/main_moni.ddp delete mode 100755 col_moni/main_moni.dfm delete mode 100755 col_moni/main_moni.pas diff --git a/CACIC_Library.pas b/CACIC_Library.pas index e85e27e..386e01b 100644 --- a/CACIC_Library.pas +++ b/CACIC_Library.pas @@ -23,6 +23,7 @@ - start with "g" character for global - start with "v" character for local - start with "p" character for methods parameters + - start with "P" character for pointers - use underscore for better read e.g. var g_global : string; @@ -49,6 +50,25 @@ uses Windows, SysUtils, StrUtils; type + +{ ------------------------------------------------------------------------------ + Tipo de dados para obter informacoes extendidas dos Sistema Operacional + ver MSDN: http://msdn.microsoft.com/en-us/library/ms724833(VS.85).aspx +-------------------------------------------------------------------------------} + TOSVersionInfoEx = packed record + dwOSVersionInfoSize: DWORD; + dwMajorVersion: DWORD; + dwMinorVersion: DWORD; + dwBuildNumber: DWORD; + dwPlatformId: DWORD; + szCSDVersion: array[0..127] of AnsiChar; + wServicePackMajor: WORD; + wServicePackMinor: WORD; + wSuiteMask: WORD; + wProductType: Byte; + wReserved: Byte; + end; + {*------------------------------------------------------------------------------ Classe para obter informações do sistema windows -------------------------------------------------------------------------------} @@ -57,7 +77,11 @@ type protected /// Mantem a identificação do sistema operacional - g_osVerInfo: TOSVersionInfo; + g_osVersionInfo: TOSVersionInfo; + /// Mantem a identificação extendida do sistema operacional + g_osVersionInfoEx: TOSVersionInfoEx; + /// TRUE se houver informação extendida do SO, FALSE caso contrário + g_osVersionInfoExtended: boolean; public function isWindowsVista() : boolean; @@ -94,6 +118,7 @@ type -------------------------------------------------------------------------------} TCACIC = class(TCACIC_Windows) constructor Create(); + destructor Destroy; override; private protected @@ -112,6 +137,8 @@ type // Declaração de constantes para a biblioteca const CACIC_PROCESS_WAIT = true; // aguardar fim do processo const CACIC_PROCESS_NOWAIT = false; // não aguardar o fim do processo +var + P_OSVersionInfo: POSVersionInfo; implementation @@ -123,13 +150,33 @@ implementation -------------------------------------------------------------------------------} constructor TCACIC.Create(); begin - Self.g_osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); - GetVersionEx(Self.g_osVerInfo); + FillChar(Self.g_osVersionInfoEx, SizeOf(Self.g_osVersionInfoEx), 0); + {$TYPEDADDRESS OFF} + P_OSVersionInfo := @Self.g_osVersionInfoEx; + {$TYPEDADDRESS ON} + + Self.g_osVersionInfoEx.dwOSVersionInfoSize:= SizeOf(TOSVersionInfoEx); + Self.g_osVersionInfoExtended := GetVersionEx(P_OSVersionInfo^); + if (not Self.g_osVersionInfoExtended) then begin + Self.g_osVersionInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); + GetVersionEx(Self.g_osVersionInfo); + end; Self.Windows := TCACIC_Windows.Create(); Self.Debug := TCACIC_Debug.Create(); end; {*------------------------------------------------------------------------------ + Destrutor para a classe + + Objetiva finalizar valores usados pelos objetos da classe. +-------------------------------------------------------------------------------} +destructor TCACIC.Destroy(); +begin + FreeMemory(P_OSVersionInfo); + inherited; +end; + +{*------------------------------------------------------------------------------ Elimina espacos excedentes na string @param p_str String a excluir espacos @@ -219,8 +266,13 @@ end; function TCACIC_Windows.isWindowsGEVista() : boolean; begin Result := false; - if((g_osVerInfo.dwMajorVersion >= 6) and (g_osVerInfo.dwMinorVersion >= 0)) then - Result := true; + if(Self.g_osVersionInfoExtended) then begin + if((g_osVersionInfoEx.dwMajorVersion >= 6) and (g_osVersionInfoEx.dwMinorVersion >= 0)) then + Result := true; + end + else + if((g_osVersionInfo.dwMajorVersion >= 6) and (g_osVersionInfo.dwMinorVersion >= 0)) then + Result := true; end; {*------------------------------------------------------------------------------ @@ -233,8 +285,13 @@ end; function TCACIC_Windows.isWindowsVista() : boolean; begin Result := false; - if((g_osVerInfo.dwMajorVersion = 6) and (g_osVerInfo.dwMinorVersion = 0)) then - Result := true; + if(Self.g_osVersionInfoExtended) then begin + if((g_osVersionInfoEx.dwMajorVersion = 6) and (g_osVersionInfoEx.dwMinorVersion = 0)) then + Result := true; + end + else + if((g_osVersionInfo.dwMajorVersion = 6) and (g_osVersionInfo.dwMinorVersion = 0)) then + Result := true; end; {*------------------------------------------------------------------------------ @@ -247,8 +304,13 @@ end; function TCACIC_Windows.isWindowsGEXP() : boolean; begin Result := false; - if((g_osVerInfo.dwMajorVersion >= 5) and (g_osVerInfo.dwMinorVersion >= 1)) then - Result := true; + if(Self.g_osVersionInfoExtended) then begin + if((g_osVersionInfoEx.dwMajorVersion >= 5) and (g_osVersionInfoEx.dwMinorVersion >= 1)) then + Result := true; + end + else + if((g_osVersionInfo.dwMajorVersion >= 5) and (g_osVersionInfo.dwMinorVersion >= 1)) then + Result := true; end; {*------------------------------------------------------------------------------ @@ -261,8 +323,13 @@ end; function TCACIC_Windows.isWindowsXP() : boolean; begin Result := false; - if((g_osVerInfo.dwMajorVersion = 5) and (g_osVerInfo.dwMinorVersion = 1)) then - Result := true; + if(Self.g_osVersionInfoExtended) then begin + if((g_osVersionInfoEx.dwMajorVersion = 5) and (g_osVersionInfoEx.dwMinorVersion = 1)) then + Result := true; + end + else + if((g_osVersionInfo.dwMajorVersion = 5) and (g_osVersionInfo.dwMinorVersion = 1)) then + Result := true; end; {*------------------------------------------------------------------------------ @@ -275,8 +342,13 @@ end; function TCACIC_Windows.isWindows2000() : boolean; begin Result := false; - if((g_osVerInfo.dwMajorVersion = 5) and (g_osVerInfo.dwMinorVersion = 0)) then - Result := true; + if(Self.g_osVersionInfoExtended) then begin + if((g_osVersionInfoEx.dwMajorVersion = 5) and (g_osVersionInfoEx.dwMinorVersion = 0)) then + Result := true; + end + else + if((g_osVersionInfo.dwMajorVersion = 5) and (g_osVersionInfo.dwMinorVersion = 0)) then + Result := true; end; {*------------------------------------------------------------------------------ @@ -289,8 +361,13 @@ end; function TCACIC_Windows.isWindowsNT() : boolean; begin Result := false; - if((g_osVerInfo.dwMajorVersion = 4) and (g_osVerInfo.dwMinorVersion = 0)) then - Result := true; + if(Self.g_osVersionInfoExtended) then begin + if((g_osVersionInfoEx.dwMajorVersion = 4) and (g_osVersionInfoEx.dwMinorVersion = 0)) then + Result := true; + end + else + if((g_osVersionInfo.dwMajorVersion = 4) and (g_osVersionInfo.dwMinorVersion = 0)) then + Result := true; end; {*------------------------------------------------------------------------------ @@ -302,7 +379,10 @@ end; -------------------------------------------------------------------------------} function TCACIC_Windows.isWindows9xME() : boolean; begin - Result := (Self.g_osVerInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS); + if (Self.g_osVersionInfoExtended) then + Result := (Self.g_osVersionInfoEx.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS) + else + Result := (Self.g_osVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS); end; {*------------------------------------------------------------------------------ @@ -312,13 +392,35 @@ end; @example 1.4.10.A -------------------------------------------------------------------------------} function TCACIC_Windows.getWindowsStrId() : string; +var + v_version_id: string; begin - Result := IntToStr(Self.g_osVerInfo.dwPlatformId) + '.' + - IntToStr(Self.g_osVerInfo.dwMajorVersion) + '.' + - IntToStr(Self.g_osVerInfo.dwMinorVersion) + - ifThen(trim(Self.g_osVerInfo.szCSDVersion)='', - '', - '.'+Self.g_osVerInfo.szCSDVersion); + v_version_id := 'S.O.unknown'; + try + if (Self.g_osVersionInfoExtended) then + if(Self.isWindows9xME) then + v_version_id := IntToStr(Self.g_osVersionInfoEx.dwPlatformId) + '.' + + IntToStr(Self.g_osVersionInfoEx.dwMajorVersion) + '.' + + IntToStr(Self.g_osVersionInfoEx.dwMinorVersion) + + ifThen(trim(Self.g_osVersionInfoEx.szCSDVersion)='', + '', + '.'+trim(Self.g_osVersionInfoEx.szCSDVersion)) + else + v_version_id := IntToStr(Self.g_osVersionInfoEx.dwPlatformId) + '.' + + IntToStr(Self.g_osVersionInfoEx.dwMajorVersion) + '.' + + IntToStr(Self.g_osVersionInfoEx.dwMinorVersion) + '.' + + IntToStr(Self.g_osVersionInfoEx.wProductType) + '.' + + IntToStr(Self.g_osVersionInfoEx.wSuiteMask) + else + v_version_id := IntToStr(Self.g_osVersionInfo.dwPlatformId) + '.' + + IntToStr(Self.g_osVersionInfo.dwMajorVersion) + '.' + + IntToStr(Self.g_osVersionInfo.dwMinorVersion) + + ifThen(trim(Self.g_osVersionInfo.szCSDVersion)='', + '', + '.'+trim(Self.g_osVersionInfo.szCSDVersion)); + except + end; + Result := v_version_id; end; @@ -330,7 +432,9 @@ end; -------------------------------------------------------------------------------} function TCACIC_Windows.isWindowsNTPlataform() : boolean; begin - Result := (Self.g_osVerInfo.dwPlatformId = VER_PLATFORM_WIN32_NT); + if(Self.g_osVersionInfoExtended) + then Result := (Self.g_osVersionInfoEx.dwPlatformId = VER_PLATFORM_WIN32_NT) + else Result := (Self.g_osVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT); end; {*------------------------------------------------------------------------------ diff --git a/chkcacic/main.pas b/chkcacic/main.pas index 293e98f..1d8f559 100644 --- a/chkcacic/main.pas +++ b/chkcacic/main.pas @@ -87,7 +87,6 @@ uses Windows, var v_ip_serv_cacic, v_cacic_dir, -// v_rem_cacic_v0x, v_te_instala_frase_sucesso, v_te_instala_frase_insucesso, v_te_instala_informacoes_extras, @@ -105,7 +104,6 @@ var v_ip_serv_cacic, v_versao_LOC, v_te_so : String; - intWinVer : integer; v_Debugs : boolean; var v_tstrCipherOpened : TStrings; @@ -135,7 +133,6 @@ procedure LogDiario(strMsg : String); procedure Matar(v_dir,v_files: string); // 2.2.0.16 Procedure MostraFormConfigura; -function abstraiCSD(p_te_so : String) : integer; Function ChecaVersoesAgentes(p_strNomeAgente : String) : integer; // 2.2.0.16 Function Explode(Texto, Separador : String) : TStrings; Function FindWindowByTitle(WindowTitle: string): Hwnd; @@ -147,7 +144,6 @@ Function GetRootKey(strRootKey: String): HKEY; Function GetValorChaveRegEdit(Chave: String): Variant; Function GetValorChaveRegIni(p_Secao, p_Chave, p_File : String): String; Function GetVersionInfo(p_File: string):string; -Function GetWinVer: Integer; Function HomeDrive : string; Function KillTask(ExeFileName: string): Integer; Function ListFileDir(Path: string):string; @@ -175,83 +171,7 @@ implementation uses FormConfig; {$R *.dfm} -function GetWinVer: Integer; -const - { operating system (OS)constants } - cOsUnknown = 0; - cOsWin95 = 1; - cOsWin95OSR2 = 2; // Não implementado. - cOsWin98 = 3; - cOsWin98SE = 4; - cOsWinME = 5; - cOsWinNT = 6; - cOsWin2000 = 7; - cOsXP = 8; - cOsServer2003 = 13; -var - osVerInfo: TOSVersionInfo; - platformID, - majorVer, - minorVer: Integer; - CSDVersion : String; -begin - Result := cOsUnknown; - { set operating system type flag } - osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); - if GetVersionEx(osVerInfo) then - begin - platformId := osVerInfo.dwPlatformId; - majorVer := osVerInfo.dwMajorVersion; - minorVer := osVerInfo.dwMinorVersion; - CSDVersion := trim(osVerInfo.szCSDVersion); - - case osVerInfo.dwPlatformId of - VER_PLATFORM_WIN32_NT: { Windows NT/2000 } - begin - if majorVer <= 4 then - Result := cOsWinNT - else if (majorVer = 5) and (minorVer = 0) then - Result := cOsWin2000 - else if (majorVer = 5) and (minorVer = 1) then - Result := cOsXP - else if (majorVer = 5) and (minorVer = 2) then - Result := cOsServer2003 - else - Result := cOsUnknown; - end; - VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME } - begin - if (majorVer = 4) and (minorVer = 0) then - Result := cOsWin95 - else if (majorVer = 4) and (minorVer = 10) then - begin - if osVerInfo.szCSDVersion[1] = 'A' then - Result := cOsWin98SE - else - Result := cOsWin98; - end - else if (majorVer = 4) and (minorVer = 90) then - Result := cOsWinME - else - Result := cOsUnknown; - end; - else - Result := cOsUnknown; - end; - end - else - Result := cOsUnknown; - - // A partir da versão 2.2.0.24, defino o valor da ID Interna e atribuo-a sem o CSDVersion à versão externa - v_te_so := IntToStr(platformId) + '.' + - IntToStr(majorVer) + '.' + - IntToStr(minorVer) + - IfThen(CSDVersion='','','.'+CSDVersion); - if (Result = 0) then - Result := abstraiCSD(v_te_so); - LogDebug('GetWinVer => ID_interna: '+ v_te_so + ' ID_Externa: ' + IntToStr(Result)); -end; function GetNetworkUserName : String; // Gets the name of the user currently logged into the network on // the local PC @@ -360,7 +280,6 @@ begin CloseFile(HistoricoLog); {Fecha o arquivo texto} except //Erro na gravação do log! - //Application.Terminate; end; end; @@ -368,10 +287,6 @@ procedure LogDebug(p_msg:string); Begin if v_Debugs then Begin - - //if FileExists(Dir + '\Temp\Debugs\show.txt') then - // ShowMessage('DEBUG - '+p_msg); - LogDiario('(v.'+getVersionInfo(ParamStr(0))+') DEBUG - '+p_msg); End; End; @@ -525,7 +440,7 @@ begin if (trim(v_strCipherOpened)<>'') then Result := explode(v_strCipherOpened,v_SeparatorKey) else - Result := explode('Configs.ID_SO'+v_SeparatorKey+inttostr(intWinVer)+v_SeparatorKey+'Configs.Endereco_WS'+v_SeparatorKey+'/cacic2/ws/',v_SeparatorKey); + Result := explode('Configs.ID_SO'+v_SeparatorKey+ g_oCacic.getWindowsStrId() +v_SeparatorKey+'Configs.Endereco_WS'+v_SeparatorKey+'/cacic2/ws/',v_SeparatorKey); if Result.Count mod 2 <> 0 then @@ -564,14 +479,6 @@ end; -function abstraiCSD(p_te_so : String) : integer; - var tstrTe_so : tstrings; - Begin - tstrTe_so := Explode(p_te_so, '.'); - Result := StrToInt(tstrTe_so[0] + tstrTe_so[1] + tstrTe_so[2]); - LogDebug('abstraiCSD=> '+ tstrTe_so[0] + tstrTe_so[1] + tstrTe_so[2]); - End; - function GetVersionInfo(p_File: string):string; begin Form1.PJVersionInfo1.FileName := PChar(p_File); @@ -1041,31 +948,6 @@ begin End; end; -{ -// Dica obtida em http://www.webmundi.com/delphi/dfuncaof.asp?SubTipo=Sistema -Function DriveType(Unidade: String):String; -Var StrDrive, - StrDriveType : String; - intDriveType : Integer; -begin - StrDrive := Unidade; - If StrDrive[Length(StrDrive)] <> '\' Then - StrDrive := StrDrive + ':\'; - - intDriveType := GetDriveType(PChar(StrDrive)); - Case intDriveType Of - 0 : StrDriveType := 'ERRO'; - 1 : StrDriveType := 'ERRO'; - DRIVE_REMOVABLE : StrDriveType := 'FLOPPY'; - DRIVE_FIXED : StrDriveType := 'HD'; - DRIVE_REMOTE : StrDriveType := 'REDE'; - DRIVE_CDROM : StrDriveType := 'CDROM'; - DRIVE_RAMDISK : StrDriveType := 'RAM'; - end; - Result := StrDriveType; -End; -} - Function ChecaVersoesAgentes(p_strNomeAgente : String) : integer; // 2.2.0.16 var strNomeAgente : String; v_array_NomeAgente : TStrings; @@ -1341,12 +1223,11 @@ begin End; End; - intWinVer := GetWinVer; - // Verifica se o S.O. é NT Like e se o Usuário está com privilégio administrativo... if (g_oCacic.isWindowsNTPlataform()) and (not g_oCacic.isWindowsAdmin()) then begin // Se NT/2000/XP/... if (v_exibe_informacoes = 'S') then MessageDLG(#13#10+'ATENÇÃO! Essa aplicação requer execução com nível administrativo.',mtError,[mbOK],0); + LogDiario('Sem Privilégios: Necessário ser administrador "local" da estação'); ComunicaInsucesso('0'); // O indicador "0" (zero) sinalizará falta de privilégio na estação end else begin diff --git a/chksis/chksis.dpr b/chksis/chksis.dpr index 7043d27..def272d 100755 --- a/chksis/chksis.dpr +++ b/chksis/chksis.dpr @@ -54,10 +54,11 @@ var PJVersionInfo1: TPJVersionInfo; v_versao_remota, v_retorno, v_te_so : String; - intWinVer : integer; v_Debugs : Boolean; var v_tstrCipherOpened : TStrings; +var g_oCacic : TCACIC; + // Some constants that are dependant on the cipher being used // Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize) const KeySize = 32; // 32 bytes = 256 bits @@ -269,14 +270,8 @@ begin Append(v_DatFile); End; - //v_Cipher := TDCP_rijndael.Create(nil); - //v_Cipher.InitStr(v_CipherKey,TDCP_md5); v_strCipherOpenImploded := Implode(v_tstrCipherOpened,v_SeparatorKey); v_strCipherClosed := EnCrypt(v_strCipherOpenImploded); - //log_diario('Finalizando o Arquivo de Configurações com criptografia de: '+v_strCipherOpenImploded,ExtractFilePath(ParamStr(0))); - //v_strCipherClosed := v_Cipher.EncryptString(v_strCipherOpenImploded); - //v_Cipher.Burn; - //v_Cipher.Free; Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto} @@ -286,90 +281,6 @@ begin end; end; -function abstraiCSD(p_te_so : String) : integer; - var tstrTe_so : tstrings; - Begin - tstrTe_so := Explode(p_te_so, '.'); - Result := StrToInt(tstrTe_so[0] + tstrTe_so[1] + tstrTe_so[2]); - End; - -function GetWinVer: Integer; -const - { operating system (OS)constants } - cOsUnknown = 0; - cOsWin95 = 1; - cOsWin95OSR2 = 2; // Não implementado. - cOsWin98 = 3; - cOsWin98SE = 4; - cOsWinME = 5; - cOsWinNT = 6; - cOsWin2000 = 7; - cOsXP = 8; - cOsServer2003 = 13; -var - osVerInfo: TOSVersionInfo; - platformID, - majorVer, - minorVer: Integer; - CSDVersion : String; -begin - Result := cOsUnknown; - { set operating system type flag } - osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); - if GetVersionEx(osVerInfo) then - begin - platformId := osVerInfo.dwPlatformId; - majorVer := osVerInfo.dwMajorVersion; - minorVer := osVerInfo.dwMinorVersion; - CSDVersion := trim(osVerInfo.szCSDVersion); - - case osVerInfo.dwPlatformId of - VER_PLATFORM_WIN32_NT: { Windows NT/2000 } - begin - if majorVer <= 4 then - Result := cOsWinNT - else if (majorVer = 5) and (minorVer = 0) then - Result := cOsWin2000 - else if (majorVer = 5) and (minorVer = 1) then - Result := cOsXP - else if (majorVer = 5) and (minorVer = 2) then - Result := cOsServer2003 - else - Result := cOsUnknown; - end; - VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME } - begin - if (majorVer = 4) and (minorVer = 0) then - Result := cOsWin95 - else if (majorVer = 4) and (minorVer = 10) then - begin - if osVerInfo.szCSDVersion[1] = 'A' then - Result := cOsWin98SE - else - Result := cOsWin98; - end - else if (majorVer = 4) and (minorVer = 90) then - Result := cOsWinME - else - Result := cOsUnknown; - end; - else - Result := cOsUnknown; - end; - end - else - Result := cOsUnknown; - - // A partir da versão 2.2.0.24, defino o valor da ID Interna e atribuo-a sem o CSDVersion à versão externa - v_te_so := IntToStr(platformId) + '.' + - IntToStr(majorVer) + '.' + - IntToStr(minorVer) + - IfThen(CSDVersion='','','.'+CSDVersion); - if (Result = 0) then - Result := abstraiCSD(v_te_so); - -end; - Function CipherOpen(p_DatFileName : string) : TStrings; var v_DatFile : TextFile; v_strCipherOpened, @@ -396,7 +307,7 @@ begin if (trim(v_strCipherOpened)<>'') then Result := explode(v_strCipherOpened,v_SeparatorKey) else - Result := explode('Configs.ID_SO' + v_SeparatorKey + inttostr(intWinVer)+v_SeparatorKey+'Configs.Endereco_WS'+v_SeparatorKey+'/cacic2/ws/',v_SeparatorKey); + Result := explode('Configs.ID_SO' + v_SeparatorKey + g_oCacic.getWindowsStrId() +v_SeparatorKey+'Configs.Endereco_WS'+v_SeparatorKey+'/cacic2/ws/',v_SeparatorKey); if Result.Count mod 2 <> 0 then Result.Add(''); @@ -404,7 +315,6 @@ end; Procedure SetValorDatMemoria(p_Chave : string; p_Valor : String); begin - //log_diario('Setando chave: '+p_Chave+' com valor: '+p_Valor,ExtractFilePath(ParamStr(0))); // Exemplo: p_Chave => Configs.nu_ip_servidor : p_Valor => 10.71.0.120 if (v_tstrCipherOpened.IndexOf(p_Chave)<>-1) then v_tstrCipherOpened[v_tstrCipherOpened.IndexOf(p_Chave)+1] := p_Valor @@ -615,7 +525,9 @@ end; Function FTP(p_Host : String; p_Port : String; p_Username : String; p_Password : String; p_PathServer : String; p_File : String; p_Dest : String) : Boolean; var IdFTP : TIdFTP; + msg_error : string; begin + msg_error := ''; Try IdFTP := TIdFTP.Create(IdFTP); IdFTP.Host := p_Host; @@ -629,21 +541,25 @@ begin begin IdFTP.Disconnect; end; + msg_error := 'Falha ao tentar conexão com o servidor FTP: "' + p_Host + '"'; IdFTP.Connect(true); + msg_error := 'Falha ao tentar mudar diretório no servidor FTP: "' + p_PathServer + '"'; IdFTP.ChangeDir(p_PathServer); Try log_DEBUG('Size de "'+p_File+'" Antes do FTP => '+IntToSTR(IdFTP.Size(p_File))); + msg_error := 'Falha ao tentar obter arquivo no servidor FTP: "' + p_File + '"'; IdFTP.Get(p_File, p_Dest + '\' + p_File, True); log_DEBUG('Size de "'+p_Dest + '\' + p_File +'" Após o FTP => '+Get_File_Size(p_Dest + '\' + p_File,true)); Finally log_DEBUG('Size de "'+p_Dest + '\' + p_File +'" Após o FTP em Finally => '+Get_File_Size(p_Dest + '\' + p_File,true)); idFTP.Disconnect; - idFTP.Free; result := true; End; Except + log_diario(msg_error); result := false; end; + idFTP.Free; Except result := false; End; @@ -772,12 +688,10 @@ begin if not DeleteFile(strFileName) then Begin - if ((intWinVer <> 0) and (intWinVer <= 5)) or - (abstraiCSD(v_te_so) < 250) then // Menor que NT Like + if (not g_oCacic.isWindowsNTPlataform()) then // Menor que NT Like KillTask(SearchRec.Name) else KillProcess(FindWindow(PChar(SearchRec.Name),nil)); - DeleteFile(strFileName); End; @@ -891,8 +805,6 @@ begin End; End; - intWinVer := GetWinVer; - // Caso o parâmetro rem_cacic_v0x seja "S/s" removo a chave/valor de execução do Cacic antigo if (LowerCase(v_rem_cacic_v0x)='s') then begin @@ -923,25 +835,12 @@ begin ForceDirectories(Dir + '\temp'); end; - - // Igualo as chaves ip_serv_cacic e cacic dos arquivos chksis.ini e cacic2.ini! -// log_diario('Setando chave Configs/EnderecoServidor=' + v_ip_serv_cacic + ' em '+Dir + '\cacic2.dat',ExtractFilePath(ParamStr(0))); -// SetValorChaveRegIni('Configs', 'EnderecoServidor', v_ip_serv_cacic, Dir + '\cacic2.ini'); - //chave AES. Recomenda-se que cada empresa altere a sua chave. v_CipherKey := 'CacicBrasil'; v_IV := 'abcdefghijklmnop'; v_SeparatorKey := '=CacicIsFree='; v_DatFileName := Dir + '\cacic2.dat'; - //v_tstrCipherOpened := CipherOpen(v_DatFileName); - //SetValorDatMemoria('Configs.EnderecoServidor', v_ip_serv_cacic); - -// log_diario('Setando chave Configs/cacic_dir=' + v_cacic_dir + ' em '+Dir + '\cacic2.ini',ExtractFilePath(ParamStr(0))); -// SetValorChaveRegIni('Configs', 'cacic_dir', v_cacic_dir, Dir + '\cacic2.ini'); - //SetValorDatMemoria('Configs.cacic_dir', v_cacic_dir); - - //CipherClose(v_DatFileName); // Verifico existência dos dois principais objetos If (not FileExists(Dir + '\cacic2.exe')) or (not FileExists(Dir + '\modulos\ger_cols.exe')) Then Begin @@ -1083,10 +982,6 @@ begin End; // Caso o Cacic tenha sido baixado executo-o com parâmetro de configuração de servidor - //if (bool_download_CACIC2) then - //Begin - //if not bool_ExistsAutoRun then - // Begin if Posso_Rodar_CACIC or not bool_ExistsAutoRun then Begin log_diario('Executando '+Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic); @@ -1097,23 +992,16 @@ begin else WinExec(PChar(Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic ), SW_HIDE); End; - // End - // else log_diario('Não Executei. Chave de AutoExecução já existente...'); - //End - Application.Terminate; end; const CACIC_APP_NAME = 'chksis'; -var - oCacic : TCACIC; - begin - oCacic := TCACIC.Create(); + g_oCacic := TCACIC.Create(); - if( not oCacic.isAppRunning( CACIC_APP_NAME ) ) + if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) ) then begin if (FindWindowByTitle('chkcacic') = 0) and (FindWindowByTitle('cacic2') = 0) then @@ -1122,7 +1010,7 @@ begin else log_diario('Não executei devido execução em paralelo de "chkcacic" ou "cacic2"!'); end; - oCacic.Free(); + g_oCacic.Free(); end. diff --git a/chksis/chksis_erro.ini b/chksis/chksis_erro.ini deleted file mode 100755 index 39c38a6..0000000 --- a/chksis/chksis_erro.ini +++ /dev/null @@ -1,2 +0,0 @@ -[Erro] -Erro=Arquivo chkcacic.ini inexistente! diff --git a/chksis/main.ddp b/chksis/main.ddp deleted file mode 100755 index 4370276..0000000 Binary files a/chksis/main.ddp and /dev/null differ diff --git a/chksis/main.dfm b/chksis/main.dfm deleted file mode 100755 index 1f87c78..0000000 --- a/chksis/main.dfm +++ /dev/null @@ -1,46 +0,0 @@ -object Form1: TForm1 - Left = 232 - Top = 106 - Width = 544 - Height = 375 - Caption = 'Form1' - Color = clBtnFace - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -11 - Font.Name = 'MS Sans Serif' - Font.Style = [] - OldCreateOrder = False - OnCreate = FormCreate - PixelsPerInch = 96 - TextHeight = 13 - object IdFTP1: TIdFTP - MaxLineAction = maException - ReadTimeout = 0 - ProxySettings.ProxyType = fpcmNone - ProxySettings.Port = 0 - Left = 240 - Top = 72 - end - object IdHTTP1: TIdHTTP - MaxLineAction = maException - ReadTimeout = 0 - AllowCookies = True - ProxyParams.BasicAuthentication = False - ProxyParams.ProxyPort = 0 - Request.ContentLength = -1 - Request.ContentRangeEnd = 0 - Request.ContentRangeStart = 0 - Request.ContentType = 'text/html' - Request.Accept = 'text/html, */*' - Request.BasicAuthentication = False - Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)' - HTTPOptions = [hoForceEncodeParams] - Left = 320 - Top = 72 - end - object PJVersionInfo1: TPJVersionInfo - Left = 80 - Top = 72 - end -end diff --git a/chksis/main.pas b/chksis/main.pas deleted file mode 100755 index 7fa8acb..0000000 --- a/chksis/main.pas +++ /dev/null @@ -1,474 +0,0 @@ -(** ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -Copyright 2000, 2001, 2002, 2003, 2004, 2005 Dataprev - Empresa de Tecnologia e Informações da Previdência Social, Brasil - -Este arquivo é parte do programa CACIC - Configurador Automático e Coletor de Informações Computacionais - -O CACIC é um software livre; você pode redistribui-lo e/ou modifica-lo dentro dos termos da Licença Pública Geral GNU como -publicada pela Fundação do Software Livre (FSF); na versão 2 da Licença, ou (na sua opinião) qualquer versão. - -Este programa é distribuido na esperança que possa ser util, mas SEM NENHUMA GARANTIA; sem uma garantia implicita de ADEQUAÇÂO a qualquer -MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes. - -Você deve ter recebido uma cópia da Licença Pública Geral GNU, sob o título "LICENCA.txt", junto com este programa, se não, escreva para a Fundação do Software -Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -*) - -unit main; - -interface - -uses Windows, SysUtils, Classes, Forms, Registry, Inifiles, XML, LibXmlParser, strUtils,IdHTTP, IdFTP, idFTPCommon, - IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, PJVersionInfo; - -Procedure chksis; -Procedure DelValorReg(Chave: String); -Function FTP(p_Host : String; p_Port : String; p_Username : String; p_Password : String; p_PathServer : String; p_File : String; p_Dest : String) : Boolean; -Function Explode(Texto, Separador : String) : TStrings; -Function GetRootKey(strRootKey: String): HKEY; -Function SetValorChaveRegEdit(Chave: String; Dado: Variant): Variant; -Function GetValorChaveRegEdit(Chave: String): Variant; -function SetValorChaveRegIni(p_Secao, p_Chave, p_Valor, p_File : String): String; -function GetValorChaveRegIni(p_Secao, p_Chave, p_File : String): String; -function HomeDrive : string; -Function RemoveCaracteresEspeciais(Texto : String) : String; -function FindWindowByTitle(WindowTitle: string): Hwnd; -function GetVersionInfo(p_File: string):string; -function VerFmt(const MS, LS: DWORD): string; - -type - TForm1 = class(TForm) - IdFTP1: TIdFTP; - IdHTTP1: TIdHTTP; - PJVersionInfo1: TPJVersionInfo; - procedure FormCreate(Sender: TObject); - private - { Private declarations } - public - { Public declarations } - end; - -var - Form1: TForm1; - Dir, ENDERECO_SERV_CACIC : string; -implementation - -{$R *.dfm} -function VerFmt(const MS, LS: DWORD): string; - // Format the version number from the given DWORDs containing the info -begin - Result := Format('%d.%d.%d.%d', - [HiWord(MS), LoWord(MS), HiWord(LS), LoWord(LS)]) -end; - -{ TMainForm } - -function GetVersionInfo(p_File: string):string; -begin - Form1.PJVersionInfo1.FileName := PChar(p_File); - Result := VerFmt(Form1.PJVersionInfo1.FixedFileInfo.dwFileVersionMS, Form1.PJVersionInfo1.FixedFileInfo.dwFileVersionLS); -end; - -function GetRootKey(strRootKey: String): HKEY; -begin - /// Encontrar uma maneira mais elegante de fazer esses testes. - if Trim(strRootKey) = 'HKEY_LOCAL_MACHINE' Then Result := HKEY_LOCAL_MACHINE - else if Trim(strRootKey) = 'HKEY_CLASSES_ROOT' Then Result := HKEY_CLASSES_ROOT - else if Trim(strRootKey) = 'HKEY_CURRENT_USER' Then Result := HKEY_CURRENT_USER - else if Trim(strRootKey) = 'HKEY_USERS' Then Result := HKEY_USERS - else if Trim(strRootKey) = 'HKEY_CURRENT_CONFIG' Then Result := HKEY_CURRENT_CONFIG - else if Trim(strRootKey) = 'HKEY_DYN_DATA' Then Result := HKEY_DYN_DATA; -end; -function SetValorChaveRegEdit(Chave: String; Dado: Variant): Variant; -var RegEditSet: TRegistry; - RegDataType: TRegDataType; - strRootKey, strKey, strValue : String; - ListaAuxSet : TStrings; - I : Integer; -begin - ListaAuxSet := Explode(Chave, '\'); - strRootKey := ListaAuxSet[0]; - For I := 1 To ListaAuxSet.Count - 2 Do strKey := strKey + ListaAuxSet[I] + '\'; - strValue := ListaAuxSet[ListaAuxSet.Count - 1]; - - RegEditSet := TRegistry.Create; - try - RegEditSet.Access := KEY_WRITE; - RegEditSet.Rootkey := GetRootKey(strRootKey); - - if RegEditSet.OpenKey(strKey, True) then - Begin - RegDataType := RegEditSet.GetDataType(strValue); - if RegDataType = rdString then - begin - RegEditSet.WriteString(strValue, Dado); - end - else if RegDataType = rdExpandString then - begin - RegEditSet.WriteExpandString(strValue, Dado); - end - else if RegDataType = rdInteger then - begin - RegEditSet.WriteInteger(strValue, Dado); - end - else - begin - RegEditSet.WriteString(strValue, Dado); - end; - - end; - finally - RegEditSet.CloseKey; - end; - ListaAuxSet.Free; - RegEditSet.Free; -end; - -Function RemoveCaracteresEspeciais(Texto : String) : String; -var I : Integer; - strAux : String; -Begin - For I := 0 To Length(Texto) Do - if ord(Texto[I]) in [32..126] Then - strAux := strAux + Texto[I] - else strAux := strAux + ' '; // Coloca um espaço onde houver caracteres especiais - Result := strAux; -end; - -//Para buscar do RegEdit... -function GetValorChaveRegEdit(Chave: String): Variant; -var RegEditGet: TRegistry; - RegDataType: TRegDataType; - strRootKey, strKey, strValue, s: String; - ListaAuxGet : TStrings; - DataSize, Len, I : Integer; -begin - try - ListaAuxGet := Explode(Chave, '\'); - - strRootKey := ListaAuxGet[0]; - For I := 1 To ListaAuxGet.Count - 2 Do strKey := strKey + ListaAuxGet[I] + '\'; - strValue := ListaAuxGet[ListaAuxGet.Count - 1]; - RegEditGet := TRegistry.Create; - - RegEditGet.Access := KEY_READ; - RegEditGet.Rootkey := GetRootKey(strRootKey); - if RegEditGet.OpenKeyReadOnly(strKey) then //teste - Begin - RegDataType := RegEditGet.GetDataType(strValue); - if (RegDataType = rdString) or (RegDataType = rdExpandString) then Result := RegEditGet.ReadString(strValue) - else if RegDataType = rdInteger then Result := RegEditGet.ReadInteger(strValue) - else if (RegDataType = rdBinary) or (RegDataType = rdUnknown) - then - begin - DataSize := RegEditGet.GetDataSize(strValue); - if DataSize = -1 then exit; - SetLength(s, DataSize); - Len := RegEditGet.ReadBinaryData(strValue, PChar(s)^, DataSize); - if Len <> DataSize then exit; - Result := RemoveCaracteresEspeciais(s); - end - end; - finally - RegEditGet.CloseKey; - RegEditGet.Free; - ListaAuxGet.Free; - - end; -end; - -//Para gravar no Arquivo INI... -function SetValorChaveRegIni(p_Secao, p_Chave, p_Valor, p_File : String): String; -var Reg_Ini : TIniFile; -begin - FileSetAttr (p_File,0); - Reg_Ini := TIniFile.Create(p_File); -// Reg_Ini.WriteString(utils_cacic.Crip(p_Secao), utils_cacic.Crip(p_Chave), utils_cacic.Crip(p_Valor)); - Reg_Ini.WriteString(p_Secao, p_Chave, p_Valor); - Reg_Ini.Free; -end; - -function GetValorChaveRegIni(p_Secao, p_Chave, p_File : String): String; -//Para buscar do Arquivo INI... -// Marreta devido a limitações do KERNEL w9x no tratamento de arquivos texto e suas seções -//function GetValorChaveRegIni(p_SectionName, p_KeyName, p_IniFileName : String) : String; -var - FileText : TStringList; - i, j, v_Size_Section, v_Size_Key : integer; - v_SectionName, v_KeyName : string; - begin - Result := ''; - v_SectionName := '[' + p_Secao + ']'; - v_Size_Section := strLen(PChar(v_SectionName)); - v_KeyName := p_Chave + '='; - v_Size_Key := strLen(PChar(v_KeyName)); - FileText := TStringList.Create; - try - FileText.LoadFromFile(p_File); - For i := 0 To FileText.Count - 1 Do - Begin - if (LowerCase(Trim(PChar(Copy(FileText[i],1,v_Size_Section)))) = LowerCase(Trim(PChar(v_SectionName)))) then - Begin - For j := i to FileText.Count - 1 Do - Begin - if (LowerCase(Trim(PChar(Copy(FileText[j],1,v_Size_Key)))) = LowerCase(Trim(PChar(v_KeyName)))) then - Begin - Result := PChar(Copy(FileText[j],v_Size_Key + 1,strLen(PChar(FileText[j]))-v_Size_Key)); - Break; - End; - End; - End; - if (Result <> '') then break; - End; - finally - FileText.Free; - end; - end; - - -Procedure DelValorReg(Chave: String); -var RegDelValorReg: TRegistry; - strRootKey, strKey, strValue : String; - ListaAuxDel : TStrings; - I : Integer; -begin - ListaAuxDel := Explode(Chave, '\'); - strRootKey := ListaAuxDel[0]; - For I := 1 To ListaAuxDel.Count - 2 Do strKey := strKey + ListaAuxDel[I] + '\'; - strValue := ListaAuxDel[ListaAuxDel.Count - 1]; - RegDelValorReg := TRegistry.Create; - - try - RegDelValorReg.Access := KEY_WRITE; - RegDelValorReg.Rootkey := GetRootKey(strRootKey); - - if RegDelValorReg.OpenKey(strKey, True) then - RegDelValorReg.DeleteValue(strValue); - finally - RegDelValorReg.CloseKey; - end; - RegDelValorReg.Free; - ListaAuxDel.Free; -end; - - -Function Explode(Texto, Separador : String) : TStrings; -var - strItem : String; - ListaAuxUTILS : TStrings; - NumCaracteres, I : Integer; -Begin - ListaAuxUTILS := TStringList.Create; - strItem := ''; - NumCaracteres := Length(Texto); - For I := 0 To NumCaracteres Do - If (Texto[I] = Separador) or (I = NumCaracteres) Then - Begin - If (I = NumCaracteres) then strItem := strItem + Texto[I]; - ListaAuxUTILS.Add(Trim(strItem)); - strItem := ''; - end - Else strItem := strItem + Texto[I]; - Explode := ListaAuxUTILS; -end; - -Function FTP(p_Host : String; p_Port : String; p_Username : String; p_Password : String; p_PathServer : String; p_File : String; p_Dest : String) : Boolean; -var IdFTP : TIdFTP; -begin - Try - IdFTP := TIdFTP.Create(IdFTP); - IdFTP.Host := p_Host; - IdFTP.Username := p_Username; - IdFTP.Password := p_Password; - IdFTP.Port := strtoint(p_Port); - IdFTP.TransferType := ftBinary; - Try - if IdFTP.Connected = true then - begin - IdFTP.Disconnect; - end; - IdFTP.Connect(true); - IdFTP.ChangeDir(p_PathServer); - Try - IdFTP.Get(p_File, p_Dest + '\' + p_File, True); - result := true; - Except - result := false; - End; - Except - result := false; - end; - Except - result := false; - End; -end; - - -function HomeDrive : string; -var -WinDir : array [0..144] of char; -begin -GetWindowsDirectory (WinDir, 144); -Result := StrPas (WinDir); -end; - -procedure chksis; -var - v_download_CACIC2 : boolean; - v_home_drive, v_ip_serv_cacic, v_cacic_dir, v_rem_cacic_v0x, - v_var_inst_cac, v_te_serv_updates, v_nu_porta_serv_updates, v_nm_usuario_login_serv_updates, - v_te_senha_login_serv_updates, v_te_path_serv_updates,strDataCACIC2 : String; - BatchFile, Request_Config : TStringList; - Response_Config : TStringStream; - IdHTTP1: TIdHTTP; -begin - v_download_CACIC2 := false; - v_home_drive := MidStr(HomeDrive,1,3); //x:\ - v_ip_serv_cacic := GetValorChaveRegIni('Cacic2', 'ip_serv_cacic', ExtractFilePath(Application.Exename) + '\chksis.ini'); - v_cacic_dir := GetValorChaveRegIni('Cacic2', 'cacic_dir', ExtractFilePath(Application.Exename) + '\chksis.ini'); - v_rem_cacic_v0x := GetValorChaveRegIni('Cacic2', 'rem_cacic_v0x', ExtractFilePath(Application.Exename) + '\chksis.ini'); - Dir := v_home_drive + v_cacic_dir; - - // Caso o parâmetro rem_cacic_v0x seja "S/s" removo a chave/valor de execução do Cacic antigo - if (LowerCase(v_rem_cacic_v0x)='s') then - begin - DelValorReg('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic'); - end; - - // Verifico a existência do diretório configurado para o Cacic, normalmente CACIC - if not DirectoryExists(Dir) then - begin - ForceDirectories(Dir); - end; - - // Para eliminar versão 20014 e anteriores que provavelmente não fazem corretamente o AutoUpdate - if not DirectoryExists(Dir+'\modulos') then - begin - DeleteFile(Dir + '\cacic2.exe'); - ForceDirectories(Dir + '\modulos'); - end; - - // Crio o SubDiretório TEMP, caso não exista - if not DirectoryExists(Dir+'\temp') then - begin - ForceDirectories(Dir + '\temp'); - end; - - // Exclusão do arquivo cacic2.exe para que seja baixado novamente, devido a problema com versão 2.0.0.23 - // após alteração do método de leitura de arquivos INI. - If (FileExists(Dir + '\cacic2.exe')) Then - Begin - if (StrToInt(StringReplace(GetVersionInfo(Dir + '\cacic2.exe'),'.','',[rfReplaceAll]))>20000) or - (trim(GetVersionInfo(Dir + '\cacic2.exe'))='0.0.0.0') then - Begin - DeleteFile(Dir + '\cacic2.exe'); - End; - End; - - If (FileExists(Dir + '\modulos\ger_cols.exe')) Then - Begin - if (StrToInt(StringReplace(GetVersionInfo(Dir + '\modulos\ger_cols.exe'),'.','',[rfReplaceAll]))>20000) or - (trim(GetVersionInfo(Dir + '\modulos\ger_cols.exe'))='0.0.0.0') then - Begin - DeleteFile(Dir + '\modulos\ger_cols.exe'); - End; - End; - - // Igualo as chaves ip_serv_cacic dos arquivos chksis.ini e cacic2.ini! - SetValorChaveRegIni('Configs', 'EnderecoServidor', v_ip_serv_cacic, Dir + '\cacic2.ini'); - - // Verifico existência dos dois principais objetos - If (not FileExists(Dir + '\cacic2.exe')) or (not FileExists(Dir + '\modulos\ger_cols.exe')) Then - Begin - // Busco as configurações para acesso ao ambiente FTP - Updates - Request_Config := TStringList.Create; - Request_Config.Values['in_chkcacic'] := 'chkcacic'; - Response_Config := TStringStream.Create(''); - - Try - IdHTTP1 := TIdHTTP.Create(IdHTTP1); - IdHTTP1.Post('http://' + v_ip_serv_cacic + '/cacic2/ws/get_config.php', Request_Config, Response_Config); - - v_te_serv_updates := XML_RetornaValor('te_serv_updates' , Response_Config.DataString); - v_nu_porta_serv_updates := XML_RetornaValor('nu_porta_serv_updates' , Response_Config.DataString); - v_nm_usuario_login_serv_updates := XML_RetornaValor('nm_usuario_login_serv_updates', Response_Config.DataString); - v_te_senha_login_serv_updates := XML_RetornaValor('te_senha_login_serv_updates' , Response_Config.DataString); - v_te_path_serv_updates := XML_RetornaValor('te_path_serv_updates' , Response_Config.DataString); - Except - End; - Request_Config.Free; - Response_Config.Free; - - // Tento detectar o Agente Principal e faço FTP caso não exista - If not FileExists(Dir + '\cacic2.exe') Then - begin - FTP(v_te_serv_updates, - v_nu_porta_serv_updates, - v_nm_usuario_login_serv_updates, - v_te_senha_login_serv_updates, - v_te_path_serv_updates, - 'cacic2.exe', - Dir); - v_download_CACIC2 := true; - end; - - // Tento detectar o Gerente de Coletas e faço FTP caso não exista - If (not FileExists(Dir + '\modulos\ger_cols.exe')) Then - begin - FTP(v_te_serv_updates, - v_nu_porta_serv_updates, - v_nm_usuario_login_serv_updates, - v_te_senha_login_serv_updates, - v_te_path_serv_updates, - 'ger_cols.exe', - Dir + '\modulos'); - end; - End; - - // Crio a chave/valor cacic2 para autoexecução do Cacic, caso não exista esta chave/valor - // Crio a chave/valor chksis para autoexecução do Cacic, caso não exista esta chave/valor - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\CheckSystemRoutine', HomeDrive + '\chksis.exe'); - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic2', Dir + '\cacic2.exe'); - - // Caso o Cacic tenha sido baixado executo-o com parâmetro de configuração de servidor - if (v_download_CACIC2) then - Begin - WinExec(PChar(Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic), SW_HIDE); - End -end; -function FindWindowByTitle(WindowTitle: string): Hwnd; -var - NextHandle: Hwnd; - NextTitle: array[0..260] of char; -begin - // Get the first window - NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST); - while NextHandle > 0 do - begin - // retrieve its text - GetWindowText(NextHandle, NextTitle, 255); - - if (trim(StrPas(NextTitle))<> '') and (Pos(strlower(pchar(WindowTitle)), strlower(PChar(StrPas(NextTitle)))) <> 0) then - begin - Result := NextHandle; - Exit; - end - else - // Get the next window - NextHandle := GetWindow(NextHandle, GW_HWNDNEXT); - end; - Result := 0; -end; - -procedure TForm1.FormCreate(Sender: TObject); -begin - Application.ShowMainForm:=false; - if (FindWindowByTitle('chkcacic') = 0) then - Begin - chksis; - End; - Application.Terminate; -end; - -end. diff --git a/col_comp/col_comp.dpr b/col_comp/col_comp.dpr index b73da3d..ba585a2 100755 --- a/col_comp/col_comp.dpr +++ b/col_comp/col_comp.dpr @@ -37,6 +37,8 @@ var p_path_cacic : string; var v_tstrCipherOpened, v_tstrCipherOpened1 : TStrings; +var g_oCacic : TCACIC; + // Some constants that are dependant on the cipher being used // Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize) const KeySize = 32; // 32 bytes = 256 bits @@ -91,7 +93,6 @@ begin Append(HistoricoLog); Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now)+ '[Coletor COMP] '+strMsg); {Grava a string Texto no arquivo texto} CloseFile(HistoricoLog); {Fecha o arquivo texto} -// FileSetAttr (ExtractFilePath(Application.Exename) + '\cacic2.log',6); // Muda o atributo para arquivo de SISTEMA e OCULTO except log_diario('Erro na gravação do log!'); @@ -196,77 +197,14 @@ begin Rewrite (v_DatFile); Append(v_DatFile); - //v_Cipher := TDCP_rijndael.Create(nil); - //v_Cipher.InitStr(v_CipherKey,TDCP_md5); v_strCipherOpenImploded := Implode(p_tstrCipherOpened,'=CacicIsFree='); - //v_strCipherClosed := v_Cipher.EncryptString(v_strCipherOpenImploded); v_strCipherClosed := EnCrypt(v_strCipherOpenImploded); - //v_Cipher.Burn; - //v_Cipher.Free; Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto} CloseFile(v_DatFile); except end; end; -function GetWinVer: Integer; -const - { operating system (OS)constants } - cOsUnknown = 0; - cOsWin95 = 1; - cOsWin95OSR2 = 2; // Não implementado. - cOsWin98 = 3; - cOsWin98SE = 4; - cOsWinME = 5; - cOsWinNT = 6; - cOsWin2000 = 7; - cOsXP = 8; -var - osVerInfo: TOSVersionInfo; - majorVer, minorVer: Integer; -begin - Result := cOsUnknown; - { set operating system type flag } - osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); - if GetVersionEx(osVerInfo) then - begin - majorVer := osVerInfo.dwMajorVersion; - minorVer := osVerInfo.dwMinorVersion; - case osVerInfo.dwPlatformId of - VER_PLATFORM_WIN32_NT: { Windows NT/2000 } - begin - if majorVer <= 4 then - Result := cOsWinNT - else if (majorVer = 5) and (minorVer = 0) then - Result := cOsWin2000 - else if (majorVer = 5) and (minorVer = 1) then - Result := cOsXP - else - Result := cOsUnknown; - end; - VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME } - begin - if (majorVer = 4) and (minorVer = 0) then - Result := cOsWin95 - else if (majorVer = 4) and (minorVer = 10) then - begin - if osVerInfo.szCSDVersion[1] = 'A' then - Result := cOsWin98SE - else - Result := cOsWin98; - end - else if (majorVer = 4) and (minorVer = 90) then - Result := cOsWinME - else - Result := cOsUnknown; - end; - else - Result := cOsUnknown; - end; - end - else - Result := cOsUnknown; -end; Function Explode(Texto, Separador : String) : TStrings; var strItem : String; @@ -324,7 +262,7 @@ begin if (trim(v_strCipherOpened)<>'') then Result := explode(v_strCipherOpened,'=CacicIsFree=') else - Result := explode('Configs.ID_SO=CacicIsFree='+inttostr(GetWinVer)+'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); + Result := explode('Configs.ID_SO=CacicIsFree='+ g_oCacic.getWindowsStrId() +'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); if Result.Count mod 2 <> 0 then @@ -333,7 +271,6 @@ end; Procedure SetValorDatMemoria(p_Chave : string; p_Valor : String; p_tstrCipherOpened : TStrings); begin -//log_diario('Gravando: '+p_Chave+' Valor: '+p_Valor); // Exemplo: p_Chave => Configs.nu_ip_servidor : p_Valor => 10.71.0.120 if (p_tstrCipherOpened.IndexOf(p_Chave)<>-1) then p_tstrCipherOpened[v_tstrCipherOpened.IndexOf(p_Chave)+1] := p_Valor @@ -351,7 +288,6 @@ begin Result := v_tstrCipherOpened[v_tstrCipherOpened.IndexOf(p_Chave)+1] else Result := ''; -//log_diario('Buscando: '+p_Chave+' Resultado: '+Result); end; @@ -420,18 +356,17 @@ begin end; end; - - - procedure Executa_Col_comp; -function RetornaValorShareNT(ValorReg : String; LimiteEsq : String; LimiteDir : String) : String; -var intAux, intAux2 : Integer; -Begin - intAux := Pos(LimiteEsq, ValorReg) + Length(LimiteEsq); - if (LimiteDir = 'Fim') Then intAux2 := Length(ValorReg) - 1 - Else intAux2 := Pos(LimiteDir, ValorReg) - intAux - 1; - result := Trim(Copy(ValorReg, intAux, intAux2)); -end; + + function RetornaValorShareNT(ValorReg : String; LimiteEsq : String; LimiteDir : String) : String; + var intAux, intAux2 : Integer; + Begin + intAux := Pos(LimiteEsq, ValorReg) + Length(LimiteEsq); + if (LimiteDir = 'Fim') Then intAux2 := Length(ValorReg) - 1 + Else intAux2 := Pos(LimiteDir, ValorReg) - intAux - 1; + result := Trim(Copy(ValorReg, intAux, intAux2)); + end; + var Reg_RCC : TRegistry; ChaveRegistro, ValorChaveRegistro, nm_compartilhamento, nm_dir_compart, in_senha_escrita, in_senha_leitura, te_comentario, strTripaDados, strAux, @@ -453,16 +388,6 @@ Begin Reg_RCC.LazyWrite := False; Lista_RCC := TStringList.Create; Reg_RCC.Rootkey := HKEY_LOCAL_MACHINE; - { - strXML := '' + - '' + - '' + GetValorChaveRegIni('TcpIp' ,'TE_NODE_ADDRESS' ,p_path_cacic_ini) + '' + - '' + GetValorChaveRegIni('TcpIp' ,'TE_NOME_COMPUTADOR',p_path_cacic_ini) + '' + - '' + GetValorChaveRegIni('TcpIp' ,'TE_WORKGROUP' ,p_path_cacic_ini) + '' + - '' + GetValorChaveRegIni('Configs','ID_SO' ,p_path_cacic_ini) + ''; - } - - //strXML := ''; strTripaDados := ''; if Win32Platform = VER_PLATFORM_WIN32_NT then @@ -573,11 +498,10 @@ const var hwind:HWND; - oCacic : TCACIC; begin - oCacic := TCACIC.Create(); - if( not oCacic.isAppRunning( CACIC_APP_NAME ) ) then + g_oCacic := TCACIC.Create(); + if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) ) then if (ParamCount>0) then Begin For intAux := 1 to ParamCount do @@ -614,5 +538,5 @@ begin Halt(0); End; End; - oCacic.Free(); + g_oCacic.Free(); end. diff --git a/col_hard/col_hard.dpr b/col_hard/col_hard.dpr index ab2b3a3..e87c681 100755 --- a/col_hard/col_hard.dpr +++ b/col_hard/col_hard.dpr @@ -51,6 +51,8 @@ var p_path_cacic, v_mensagem : string; var v_tstrCipherOpened, v_tstrCipherOpened1 : TStrings; +var g_oCacic : TCACIC; + // Some constants that are dependant on the cipher being used // Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize) const KeySize = 32; // 32 bytes = 256 bits @@ -129,7 +131,6 @@ begin Append(HistoricoLog); Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now)+ '[Coletor HARD] '+strMsg); {Grava a string Texto no arquivo texto} CloseFile(HistoricoLog); {Fecha o arquivo texto} -// FileSetAttr (ExtractFilePath(Application.Exename) + '\cacic2.log',6); // Muda o atributo para arquivo de SISTEMA e OCULTO except log_diario('Erro na gravação do log!'); @@ -220,13 +221,8 @@ begin Rewrite (v_DatFile); Append(v_DatFile); - //v_Cipher := TDCP_rijndael.Create(nil); - //v_Cipher.InitStr(v_CipherKey,TDCP_md5); v_strCipherOpenImploded := Implode(p_tstrCipherOpened,'=CacicIsFree='); v_strCipherClosed := EnCrypt(v_strCipherOpenImploded); - //v_strCipherClosed := v_Cipher.EncryptString(v_strCipherOpenImploded); - //v_Cipher.Burn; - //v_Cipher.Free; Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto} @@ -234,64 +230,7 @@ begin except end; end; -function GetWinVer: Integer; -const - { operating system (OS)constants } - cOsUnknown = 0; - cOsWin95 = 1; - cOsWin95OSR2 = 2; // Não implementado. - cOsWin98 = 3; - cOsWin98SE = 4; - cOsWinME = 5; - cOsWinNT = 6; - cOsWin2000 = 7; - cOsXP = 8; -var - osVerInfo: TOSVersionInfo; - majorVer, minorVer: Integer; -begin - Result := cOsUnknown; - { set operating system type flag } - osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); - if GetVersionEx(osVerInfo) then - begin - majorVer := osVerInfo.dwMajorVersion; - minorVer := osVerInfo.dwMinorVersion; - case osVerInfo.dwPlatformId of - VER_PLATFORM_WIN32_NT: { Windows NT/2000 } - begin - if majorVer <= 4 then - Result := cOsWinNT - else if (majorVer = 5) and (minorVer = 0) then - Result := cOsWin2000 - else if (majorVer = 5) and (minorVer = 1) then - Result := cOsXP - else - Result := cOsUnknown; - end; - VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME } - begin - if (majorVer = 4) and (minorVer = 0) then - Result := cOsWin95 - else if (majorVer = 4) and (minorVer = 10) then - begin - if osVerInfo.szCSDVersion[1] = 'A' then - Result := cOsWin98SE - else - Result := cOsWin98; - end - else if (majorVer = 4) and (minorVer = 90) then - Result := cOsWinME - else - Result := cOsUnknown; - end; - else - Result := cOsUnknown; - end; - end - else - Result := cOsUnknown; -end; + Function Explode(Texto, Separador : String) : TStrings; var strItem : String; @@ -349,7 +288,7 @@ begin if (trim(v_strCipherOpened)<>'') then Result := explode(v_strCipherOpened,'=CacicIsFree=') else - Result := explode('Configs.ID_SO=CacicIsFree='+inttostr(GetWinVer)+'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); + Result := explode('Configs.ID_SO=CacicIsFree='+ g_oCacic.getWindowsStrId() +'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); if Result.Count mod 2 <> 0 then Result.Add(''); @@ -791,9 +730,9 @@ begin Try for i:=0 to v_CPU.CPUCount-1 do begin v_te_cpu_serial := v_CPU.SerialNumber; - v_te_cpu_desc := v_CPU.CPUName; + v_te_cpu_desc := v_CPU.MarketingName; if(v_te_cpu_desc = '') then - v_te_cpu_desc := v_CPU.MarketingName; + v_te_cpu_desc := v_CPU.CPUName; v_te_cpu_fabricante := cVendorNames[v_CPU.Vendor].Prefix; @@ -1158,12 +1097,11 @@ const var tstrTripa1 : TStrings; intAux : integer; - oCacic : TCACIC; begin - oCacic := TCACIC.Create(); + g_oCacic := TCACIC.Create(); - if( not oCacic.isAppRunning( CACIC_APP_NAME ) ) then + if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) ) then if (ParamCount>0) then Begin For intAux := 1 to ParamCount do @@ -1211,6 +1149,6 @@ begin End; End; - oCacic.Free(); + g_oCacic.Free(); end. diff --git a/col_moni/col_moni.dpr b/col_moni/col_moni.dpr index 5f625d8..8c275be 100755 --- a/col_moni/col_moni.dpr +++ b/col_moni/col_moni.dpr @@ -42,6 +42,8 @@ var v_Debugs : boolean; var v_tstrCipherOpened, v_tstrCipherOpened1 : TStrings; +var g_oCacic : TCACIC; + // Some constants that are dependant on the cipher being used // Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize) const KeySize = 32; // 32 bytes = 256 bits @@ -342,64 +344,7 @@ begin except end; end; -function GetWinVer: Integer; -const - { operating system (OS)constants } - cOsUnknown = 0; - cOsWin95 = 1; - cOsWin95OSR2 = 2; // Não implementado. - cOsWin98 = 3; - cOsWin98SE = 4; - cOsWinME = 5; - cOsWinNT = 6; - cOsWin2000 = 7; - cOsXP = 8; -var - osVerInfo: TOSVersionInfo; - majorVer, minorVer: Integer; -begin - Result := cOsUnknown; - { set operating system type flag } - osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); - if GetVersionEx(osVerInfo) then - begin - majorVer := osVerInfo.dwMajorVersion; - minorVer := osVerInfo.dwMinorVersion; - case osVerInfo.dwPlatformId of - VER_PLATFORM_WIN32_NT: { Windows NT/2000 } - begin - if majorVer <= 4 then - Result := cOsWinNT - else if (majorVer = 5) and (minorVer = 0) then - Result := cOsWin2000 - else if (majorVer = 5) and (minorVer = 1) then - Result := cOsXP - else - Result := cOsUnknown; - end; - VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME } - begin - if (majorVer = 4) and (minorVer = 0) then - Result := cOsWin95 - else if (majorVer = 4) and (minorVer = 10) then - begin - if osVerInfo.szCSDVersion[1] = 'A' then - Result := cOsWin98SE - else - Result := cOsWin98; - end - else if (majorVer = 4) and (minorVer = 90) then - Result := cOsWinME - else - Result := cOsUnknown; - end; - else - Result := cOsUnknown; - end; - end - else - Result := cOsUnknown; -end; + Function Explode(Texto, Separador : String) : TStrings; var strItem : String; @@ -457,7 +402,7 @@ begin if (trim(v_strCipherOpened)<>'') then Result := explode(v_strCipherOpened,'=CacicIsFree=') else - Result := explode('Configs.ID_SO=CacicIsFree='+inttostr(GetWinVer)+'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); + Result := explode('Configs.ID_SO=CacicIsFree='+ g_oCacic.getWindowsStrId() +'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); if Result.Count mod 2 <> 0 then Result.Add(''); @@ -1081,12 +1026,11 @@ const var tstrTripa1 : TStrings; intAux : integer; - oCacic : TCACIC; begin - oCacic := TCACIC.Create(); + g_oCacic := TCACIC.Create(); - if( not oCacic.isAppRunning( CACIC_APP_NAME ) ) then + if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) ) then if (ParamCount>0) then Begin For intAux := 1 to ParamCount do @@ -1134,6 +1078,6 @@ begin End; End; - oCacic.Free(); + g_oCacic.Free(); end. diff --git a/col_moni/coleta_monitorado.pas b/col_moni/coleta_monitorado.pas deleted file mode 100755 index 3a9eb80..0000000 --- a/col_moni/coleta_monitorado.pas +++ /dev/null @@ -1,226 +0,0 @@ -unit coleta_monitorado; - -interface - -uses Windows, Registry, SysUtils, Classes, dialogs; - -procedure RealizarColetaMonitorado; - -implementation - - -Uses main, comunicacao, utils, registro, Math; - -procedure RealizarColetaMonitorado; -var Request_RCH : TStringlist; - tstrTripa2, tstrTripa3, v_array1, v_array2, v_array3, v_array4 : TStrings; - strAux, strAux1, strAux3, strAux4, strTripa, ValorChavePerfis, ValorChaveColetado : String; - intAux4, v1, v3, v_achei : Integer; -begin - // Verifica se deverá ser realizada a coleta de informações de aplicativos monitorados neste - // computador, perguntando ao agente gerente. - if (CS_COLETA_MONITORADO) Then - Begin - main.frmMain.Log_Historico('* Coletando informações de aplicativos monitorados.'); - intAux4 := 1; - strAux3 := ''; - ValorChavePerfis := '*'; - while ValorChavePerfis <> '' do - begin - strAux3 := 'APL' + trim(inttostr(intAux4)); - - strTripa := ''; // Conterá as informações a serem enviadas ao Gerente. - // Obtenho do registro o valor que foi previamente armazenado - ValorChavePerfis := Trim(Registro.GetValorChaveRegIni('Coleta',strAux3, p_path_cacic_ini)); - if (ValorChavePerfis <> '') then - Begin - //Atenção, OS ELEMENTOS DEVEM ESTAR DE ACORDO COM A ORDEM QUE SÃO TRATADOS NO MÓDULO GERENTE. - tstrTripa2 := Utils.Explode(ValorChavePerfis,','); - if (strAux <> '') then strAux := strAux + '#'; - strAux := strAux + trim(tstrTripa2[0]) + ','; - - - //Coleta de Informação de Licença - if (trim(tstrTripa2[2])='0') then //Vazio - Begin - strAux := strAux + ','; - End; - if (trim(tstrTripa2[2])='1') then //Caminho\Chave\Valor em Registry - Begin - strAux4 := Trim(Registro.GetValorChaveRegEdit(trim(tstrTripa2[3]))); - if (strAux4 = '') then strAux4 := '?'; - strAux := strAux + strAux4 + ','; - End; - if (trim(tstrTripa2[2])='2') then //Nome\Seção\Chave de Arquivo INI - Begin - Try - if (LastPos('/',trim(tstrTripa2[3]))>0) then - Begin - tstrTripa3 := Utils.Explode(trim(tstrTripa2[3]),'\'); - strAux4 := Trim(Registro.GetValorChaveRegIni(tstrTripa3[1],tstrTripa3[2],tstrTripa3[0])); - if (strAux4 = '') then strAux4 := '?'; - strAux := strAux + strAux4 + ','; - End; - if (LastPos('\',trim(tstrTripa2[3]))=0) then - Begin - strAux := strAux + 'Parâm.Lic.Incorreto,'; - End - Except - strAux := strAux + 'Parâm.Lic.Incorreto,'; - End; - End; - - - //Coleta de Informação de Instalação - if (trim(tstrTripa2[4])='0') then //Vazio - Begin - strAux := strAux + ','; - End; - - if (trim(tstrTripa2[4])='1') or (trim(tstrTripa2[4]) = '2') then //Nome de Executável OU Nome de Arquivo de Configuração (CADPF!!!) - Begin - strAux1 := trim(utils.FileSearch('\',trim(tstrTripa2[5]))); - if (strAux1 <> '') then strAux := strAux + 'S,'; - if (strAux1 = '') then strAux := strAux + 'N,'; - End; - - if (trim(tstrTripa2[4])='3') then //Caminho\Chave\Valor em Registry - Begin - strAux1 := Trim(Registro.GetValorChaveRegEdit(trim(tstrTripa2[5]))); - if (strAux1 <> '') then strAux := strAux + 'S,'; - if (strAux1 = '') then strAux := strAux + 'N,'; - End; - - - //Coleta de Informação de Versão - if (trim(tstrTripa2[6])='0') then //Vazio - Begin - strAux := strAux + ','; - End; - - if (trim(tstrTripa2[6])='1') then //Data de Arquivo - Begin - strAux1 := trim(utils.FileSearch('\',trim(tstrTripa2[7]))); - if (strAux1 <> '') then - Begin - strAux := strAux + DateToStr(FileDateToDateTime(FileAge(strAux1)))+','; - End; - if (strAux1 = '') then strAux := strAux + '?,'; - End; - - if (trim(tstrTripa2[6])='2') then //Caminho\Chave\Valor em Registry - Begin - strAux1 := Trim(Registro.GetValorChaveRegEdit(trim(tstrTripa2[7]))); - if (strAux1 <> '') then strAux := strAux + strAux1 + ','; - if (strAux1 = '') then strAux := strAux + '?,'; - End; - - if (trim(tstrTripa2[6])='3') then //Nome\Seção\Chave de Arquivo INI - Begin - Try - if (LastPos('\',trim(tstrTripa2[7]))>0) then - Begin - tstrTripa3 := Utils.Explode(trim(tstrTripa2[7]),'\'); - strAux4 := Trim(Registro.GetValorChaveRegIni(tstrTripa3[1],tstrTripa3[2],tstrTripa3[0])); - if (strAux4 = '') then strAux4 := '?'; - strAux := strAux + strAux4 + ','; - - End; - if (LastPos('\',trim(tstrTripa2[7]))=0) then - Begin - strAux := strAux + 'Parâm.Versao Incorreto,'; - End - Except - strAux := strAux + 'Parâm.Versao Incorreto,'; - End; - End; - - //Coleta de Informação de Engine - if (trim(tstrTripa2[8])='.') then //Vazio - Begin - strAux := strAux + ','; - End; - //O ponto é proposital para quando o último parâmetro vem vazio do Gerente!!! :) - if (trim(tstrTripa2[8])<>'.') then //Arquivo para Versão de Engine - Begin - strAux1 := trim(utils.FileSearch('\',trim(tstrTripa2[8]))); - if (strAux1 <> '') then - Begin - tstrTripa3 := utils.Explode(utils.getVersionInfo(strAux1), '.'); // Pego só os dois primeiros dígitos. Por exemplo: 6.640.0.1001 vira 6.640. - strAux := strAux + tstrTripa3[0] + '.' + tstrTripa3[1]; - End; - if (strAux1 = '') then strAux := strAux + '?,'; - End; - - //Coleta de Informação de Pattern - //O ponto é proposital para quando o último parâmetro vem vazio do Gerente!!! :) - if (trim(tstrTripa2[9])<>'.') then //Arquivo para Versão de Pattern - Begin - strAux1 := trim(utils.FileSearch('\',trim(tstrTripa2[9]))); - if (strAux1 <> '') then - Begin - tstrTripa3 := utils.Explode(utils.getVersionInfo(strAux1), '.'); // Pego só os dois primeiros dígitos. Por exemplo: 6.640.0.1001 vira 6.640. - strAux := strAux + tstrTripa3[0] + '.' + tstrTripa3[1]; - End; - if (strAux1 = '') then strAux := strAux + '?,'; - End; - End; - intAux4 := intAux4 + 1; - End; - - ValorChaveColetado := Trim(Registro.GetValorChaveRegIni('Coleta','APLICATIVOS_MONITORADOS_COLETADOS', p_path_cacic_ini)); -If ((trim(strAux) <> trim(ValorChaveColetado)) and (trim(ValorChaveColetado) <> '')) Then - begin - v_array1 := utils.Explode(strAux, '#'); - strAux := ''; - v_array3 := utils.Explode(ValorChaveColetado, '#'); - for v1 := 0 to (v_array1.count)-1 do - Begin - v_array2 := utils.Explode(v_array1[v1], ','); - v_achei := 0; - for v3 := 0 to (v_array3.count)-1 do - Begin - v_array4 := utils.Explode(v_array3[v3], ','); - if (v_array4=v_array2) then v_achei := 1; - End; - if (v_achei = 0) then - Begin - if (strAUX <> '') then strAUX := strAUX + '#'; - strAUX := strAUX + v_array1[v1]; - End; - End; - end; - - - // Se essas informações forem diferentes significa que houve alguma alteração - // na configuração de hardware. Nesse caso, gravo as informações no BD Central - // e, se não houver problemas durante esse procedimento, atualizo as - // informações no registro. - If (IN_COLETA_FORCADA or (trim(strAux) <> trim(ValorChaveColetado))) Then - Begin - //Envio via rede para ao Agente Gerente, para gravação no BD. - Request_RCH:=TStringList.Create; - Request_RCH.Values['te_node_address'] := TE_NODE_ADDRESS; - Request_RCH.Values['id_so'] := ID_SO; - Request_RCH.Values['te_nome_computador'] := TE_NOME_COMPUTADOR; - Request_RCH.Values['id_ip_rede'] := ID_IP_REDE; - Request_RCH.Values['te_ip'] := TE_IP; - Request_RCH.Values['te_workgroup'] := TE_WORKGROUP; - Request_RCH.Values['te_tripa_monitorados'] := strAux; - - - // Somente atualizo o registro caso não tenha havido nenhum erro durante o envio das informações para o BD - //Sobreponho a informação no registro para posterior comparação, na próxima execução. - if (comunicacao.ComunicaServidor('set_monitorado.php', Request_RCH, '>> Enviando informações de aplicativos monitorados para o servidor.') <> '0') Then - Begin - Registro.SetValorChaveRegIni('Coleta','APLICATIVOS_MONITORADOS_COLETADOS',strAux, p_path_cacic_ini); - end; - Request_RCH.Free; - end - else main.frmMain.Log_Historico('Coleta de informações de aplicativos monitorados não configurada.'); - end; -end; - - -end. - diff --git a/col_moni/main_moni.ddp b/col_moni/main_moni.ddp deleted file mode 100755 index 4370276..0000000 Binary files a/col_moni/main_moni.ddp and /dev/null differ diff --git a/col_moni/main_moni.dfm b/col_moni/main_moni.dfm deleted file mode 100755 index 9b0895d..0000000 --- a/col_moni/main_moni.dfm +++ /dev/null @@ -1,22 +0,0 @@ -object frm_col_moni: Tfrm_col_moni - Left = 910 - Top = 715 - Width = 112 - Height = 27 - Caption = 'CACIC - Coletor Aplicativos Monitorados' - Color = clBtnFace - TransparentColor = True - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -11 - Font.Name = 'MS Sans Serif' - Font.Style = [] - OldCreateOrder = False - PrintScale = poNone - OnCreate = FormCreate - PixelsPerInch = 96 - TextHeight = 13 - object PJVersionInfo1: TPJVersionInfo - Left = 40 - end -end diff --git a/col_moni/main_moni.pas b/col_moni/main_moni.pas deleted file mode 100755 index d36c369..0000000 --- a/col_moni/main_moni.pas +++ /dev/null @@ -1,776 +0,0 @@ -(** ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -Copyright 2000, 2001, 2002, 2003, 2004, 2005 Dataprev - Empresa de Tecnologia e Informações da Previdência Social, Brasil - -Este arquivo é parte do programa CACIC - Configurador Automático e Coletor de Informações Computacionais - -O CACIC é um software livre; você pode redistribui-lo e/ou modifica-lo dentro dos termos da Licença Pública Geral GNU como -publicada pela Fundação do Software Livre (FSF); na versão 2 da Licença, ou (na sua opinião) qualquer versão. - -Este programa é distribuido na esperança que possa ser util, mas SEM NENHUMA GARANTIA; sem uma garantia implicita de ADEQUAÇÂO a qualquer -MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes. - -Você deve ter recebido uma cópia da Licença Pública Geral GNU, sob o título "LICENCA.txt", junto com este programa, se não, escreva para a Fundação do Software -Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -*) - -unit main_moni; - -interface - -uses Windows, Forms, sysutils, inifiles, Registry, Classes, PJVersionInfo; - -var p_path_cacic, p_path_cacic_ini, v_Res_Search, v_Drive, v_File : string; - -type - Tfrm_col_moni = class(TForm) - PJVersionInfo1: TPJVersionInfo; - procedure Executa_Col_moni; - procedure Log_Historico(strMsg : String); - Function Crip(PNome: String): String; - Function DesCrip(PNome: String): String; - function SetValorChaveRegIni(p_Secao: String; p_Chave: String; p_Valor: String; p_Path : String): String; - function GetValorChaveRegIni(p_SectionName, p_KeyName, p_IniFileName : String) : String; - function GetValorChaveRegEdit(Chave: String): Variant; - function GetRootKey(strRootKey: String): HKEY; - Function Explode(Texto, Separador : String) : TStrings; - Function RemoveCaracteresEspeciais(Texto : String) : String; - function GetVersionInfo(p_File: string):string; - function VerFmt(const MS, LS: DWORD): string; - function LetrasDrives : string; - function LastPos(SubStr, S: string): Integer; - function SearchFile(p_Drive,p_File:string) : boolean; - procedure GetSubDirs(Folder:string; sList:TStringList); - procedure FormCreate(Sender: TObject); - private - { Private declarations } - public - { Public declarations } - end; - -var - frm_col_moni: Tfrm_col_moni; - -implementation - -{$R *.dfm} -function Tfrm_col_moni.VerFmt(const MS, LS: DWORD): string; - // Format the version number from the given DWORDs containing the info -begin - Result := Format('%d.%d.%d.%d', - [HiWord(MS), LoWord(MS), HiWord(LS), LoWord(LS)]) -end; - -{ TMainForm } - -function Tfrm_col_moni.GetVersionInfo(p_File: string):string; -begin - PJVersionInfo1.FileName := PChar(p_File); - Result := VerFmt(PJVersionInfo1.FixedFileInfo.dwFileVersionMS, PJVersionInfo1.FixedFileInfo.dwFileVersionLS); -end; - -// Baixada de http://www.infoeng.hpg.ig.com.br/borland_delphi_dicas_2.htm -function Tfrm_col_moni.LetrasDrives: string; -var -Drives: DWord; -I, Tipo: byte; -v_Unidade : string; -begin -Result := ''; -Drives := GetLogicalDrives; -if Drives <> 0 then -for I := 65 to 90 do - if ((Drives shl (31 - (I - 65))) shr 31) = 1 then - Begin - v_Unidade := Char(I) + ':\'; - Tipo := GetDriveType(PChar(v_Unidade)); - case Tipo of - DRIVE_FIXED: Result := Result + Char(I); - end; - End; -end; - -// By Muad Dib 2003 -// at http://www.planet-source-code.com. -// Excelente!!! -function Tfrm_col_moni.SearchFile(p_Drive,p_File:string) : boolean; -var sr:TSearchRec; - sDirList:TStringList; - i:integer; -begin - Result := false; - v_Res_Search := ''; - if FindFirst(p_Drive+p_File,faAnyFile,sr) = 0 then - Begin - v_Res_Search := p_Drive+p_File; - Result := true; - End - else - Begin - repeat - until FindNext(sr)<>0; - FindClose(sr); - sDirList:= TStringList.Create; - try - GetSubDirs(p_Drive,sDirList); - for i:=0 to sDirList.Count-1 do - if (sDirList[i]<>'.') and (sDirList[i]<>'..') then - begin - Application.ProcessMessages; - if (SearchFile(IncludeTrailingPathDelimiter(p_Drive+sDirList[i]),p_File)) then - Begin - Result := true; - Break; - End; - end; - finally - sDirList.Free; - End; - end; -end; - -procedure Tfrm_col_moni.GetSubDirs(Folder:string; sList:TStringList); - var - sr:TSearchRec; -begin - if FindFirst(Folder+'*.*',faDirectory,sr)=0 then - try - repeat - if(sr.Attr and faDirectory)=faDirectory then - sList.Add(sr.Name); - until FindNext(sr)<>0; - finally - FindClose(sr); - end; -end; - - -//Para gravar no Arquivo INI... -function Tfrm_col_moni.SetValorChaveRegIni(p_Secao: String; p_Chave: String; p_Valor: String; p_Path : String): String; -var Reg_Ini : TIniFile; -begin - FileSetAttr (p_Path,0); - Reg_Ini := TIniFile.Create(p_Path); -// Reg_Ini.WriteString(frm_col_moni.Crip(p_Secao), frm_col_moni.Crip(p_Chave), frm_col_moni.Crip(p_Valor)); - Reg_Ini.WriteString(p_Secao, p_Chave, p_Valor); - Reg_Ini.Free; -end; - -//Para buscar do Arquivo INI... -// Marreta devido a limitações do KERNEL w9x no tratamento de arquivos texto e suas seções -function Tfrm_col_moni.GetValorChaveRegIni(p_SectionName, p_KeyName, p_IniFileName : String) : String; -var - FileText : TStringList; - i, j, v_Size_Section, v_Size_Key : integer; - v_SectionName, v_KeyName : string; - begin - Result := ''; - v_SectionName := '[' + p_SectionName + ']'; - v_Size_Section := strLen(PChar(v_SectionName)); - v_KeyName := p_KeyName + '='; - v_Size_Key := strLen(PChar(v_KeyName)); - FileText := TStringList.Create; - try - FileText.LoadFromFile(p_IniFileName); - For i := 0 To FileText.Count - 1 Do - Begin - if (LowerCase(Trim(PChar(Copy(FileText[i],1,v_Size_Section)))) = LowerCase(Trim(PChar(v_SectionName)))) then - Begin - For j := i to FileText.Count - 1 Do - Begin - if (LowerCase(Trim(PChar(Copy(FileText[j],1,v_Size_Key)))) = LowerCase(Trim(PChar(v_KeyName)))) then - Begin - Result := PChar(Copy(FileText[j],v_Size_Key + 1,strLen(PChar(FileText[j]))-v_Size_Key)); - Break; - End; - End; - End; - if (Result <> '') then break; - End; - finally - FileText.Free; - end; - end; - -Function Tfrm_col_moni.Explode(Texto, Separador : String) : TStrings; -var - strItem : String; - ListaAuxUTILS : TStrings; - NumCaracteres, I : Integer; -Begin - ListaAuxUTILS := TStringList.Create; - strItem := ''; - NumCaracteres := Length(Texto); - For I := 0 To NumCaracteres Do - If (Texto[I] = Separador) or (I = NumCaracteres) Then - Begin - If (I = NumCaracteres) then strItem := strItem + Texto[I]; - ListaAuxUTILS.Add(Trim(strItem)); - strItem := ''; - end - Else strItem := strItem + Texto[I]; - Explode := ListaAuxUTILS; -end; - -function Tfrm_col_moni.GetRootKey(strRootKey: String): HKEY; -begin - if Trim(strRootKey) = 'HKEY_LOCAL_MACHINE' Then Result := HKEY_LOCAL_MACHINE - else if Trim(strRootKey) = 'HKEY_CLASSES_ROOT' Then Result := HKEY_CLASSES_ROOT - else if Trim(strRootKey) = 'HKEY_CURRENT_USER' Then Result := HKEY_CURRENT_USER - else if Trim(strRootKey) = 'HKEY_USERS' Then Result := HKEY_USERS - else if Trim(strRootKey) = 'HKEY_CURRENT_CONFIG' Then Result := HKEY_CURRENT_CONFIG - else if Trim(strRootKey) = 'HKEY_DYN_DATA' Then Result := HKEY_DYN_DATA; -end; - -Function Tfrm_col_moni.RemoveCaracteresEspeciais(Texto : String) : String; -var I : Integer; - strAux : String; -Begin - For I := 0 To Length(Texto) Do - if ord(Texto[I]) in [32..126] Then - strAux := strAux + Texto[I] - else strAux := strAux + ' '; // Coloca um espaço onde houver caracteres especiais - Result := strAux; -end; - -function Tfrm_col_moni.GetValorChaveRegEdit(Chave: String): Variant; -var RegEditGet: TRegistry; - RegDataType: TRegDataType; - strRootKey, strKey, strValue, s: String; - ListaAuxGet : TStrings; - DataSize, Len, I : Integer; -begin - try - Result := ''; - ListaAuxGet := frm_col_moni.Explode(Chave, '\'); - - strRootKey := ListaAuxGet[0]; - For I := 1 To ListaAuxGet.Count - 2 Do strKey := strKey + ListaAuxGet[I] + '\'; - strValue := ListaAuxGet[ListaAuxGet.Count - 1]; - if (strValue = '(Padrão)') then strValue := ''; //Para os casos de se querer buscar o valor default (Padrão) - RegEditGet := TRegistry.Create; - - RegEditGet.Access := KEY_READ; - RegEditGet.Rootkey := GetRootKey(strRootKey); - if RegEditGet.OpenKeyReadOnly(strKey) then //teste - Begin - RegDataType := RegEditGet.GetDataType(strValue); - if (RegDataType = rdString) or (RegDataType = rdExpandString) then Result := RegEditGet.ReadString(strValue) - else if RegDataType = rdInteger then Result := RegEditGet.ReadInteger(strValue) - else if (RegDataType = rdBinary) or (RegDataType = rdUnknown) - then - begin - DataSize := RegEditGet.GetDataSize(strValue); - if DataSize = -1 then exit; - SetLength(s, DataSize); - Len := RegEditGet.ReadBinaryData(strValue, PChar(s)^, DataSize); - if Len <> DataSize then exit; - Result := frm_col_moni.RemoveCaracteresEspeciais(s); - end - end; - finally - RegEditGet.CloseKey; - RegEditGet.Free; - ListaAuxGet.Free; - - end; -end; - - -// Simples rotinas de Criptografação e Descriptografação -// Baixadas de http://www.costaweb.com.br/forum/delphi/474.shtml -Function Tfrm_col_moni.Crip(PNome: String): String; -Var - TamI, TamF: Integer; - SenA, SenM, SenD: String; -Begin - SenA := Trim(PNome); - TamF := Length(SenA); - if (TamF > 1) then - begin - SenM := ''; - SenD := ''; - For TamI := TamF Downto 1 do - Begin - SenM := SenM + Copy(SenA,TamI,1); - End; - SenD := Chr(TamF+95)+Copy(SenM,1,1)+Copy(SenA,1,1)+Copy(SenM,2,TamF-2)+Chr(75+TamF); - end - else SenD := SenA; - Result := SenD; -End; - -Function Tfrm_col_moni.DesCrip(PNome: String): String; -Var - TamI, TamF: Integer; - SenA, SenM, SenD: String; -Begin - SenA := Trim(PNome); - TamF := Length(SenA) - 2; - if (TamF > 1) then - begin - SenM := ''; - SenD := ''; - SenA := Copy(SenA,2,TamF); - SenM := Copy(SenA,1,1)+Copy(SenA,3,TamF)+Copy(SenA,2,1); - For TamI := TamF Downto 1 do - Begin - SenD := SenD + Copy(SenM,TamI,1); - End; - end - else SenD := SenA; - Result := SenD; -End; - -procedure Tfrm_col_moni.Log_Historico(strMsg : String); -var - HistoricoLog : TextFile; - strDataArqLocal, strDataAtual : string; -begin - try - FileSetAttr (p_path_cacic + 'cacic2.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000 - AssignFile(HistoricoLog,p_path_cacic + 'cacic2.log'); {Associa o arquivo a uma variável do tipo TextFile} - {$IOChecks off} - Reset(HistoricoLog); {Abre o arquivo texto} - {$IOChecks on} - if (IOResult <> 0) then // Arquivo não existe, será recriado. - begin - Rewrite (HistoricoLog); - Append(HistoricoLog); - Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now) + '======================> Iniciando o Log do CACIC <======================='); - end; - DateTimeToString(strDataArqLocal, 'yyyymmdd', FileDateToDateTime(Fileage(p_path_cacic + 'cacic2.log'))); - DateTimeToString(strDataAtual , 'yyyymmdd', Date); - if (strDataAtual <> strDataArqLocal) then // Se o arquivo INI não é da data atual... - begin - Rewrite (HistoricoLog); //Cria/Recria o arquivo - Append(HistoricoLog); - Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now) + '======================> Iniciando o Log do CACIC <======================='); - end; - Append(HistoricoLog); - Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now) + strMsg); {Grava a string Texto no arquivo texto} - CloseFile(HistoricoLog); {Fecha o arquivo texto} - except - Log_Historico('Erro na gravação do log!'); - end; -end; - -function Tfrm_col_moni.LastPos(SubStr, S: string): Integer; -var - Found, Len, Pos: integer; -begin - Pos := Length(S); - Len := Length(SubStr); - Found := 0; - while (Pos > 0) and (Found = 0) do - begin - if Copy(S, Pos, Len) = SubStr then - Found := Pos; - Dec(Pos); - end; - LastPos := Found; -end; - - -procedure Tfrm_col_moni.Executa_Col_moni; -var tstrTripa2, tstrTripa3, v_array1, v_array2, v_array3, v_array4 : TStrings; - strAux, strAux1, strAux3, strAux4, strTripa, ValorChavePerfis, ValorChaveColetado, v_LetrasDrives, v_Data : String; - intAux4, v1, v3, v_achei : Integer; - -begin - Try - // Verifica se deverá ser realizada a coleta de informações de sistemas monitorados neste - // computador, perguntando ao agente gerente. - Log_Historico('* Coletando informações de Sistemas Monitorados.'); - ShortDateFormat := 'dd/mm/yyyy'; - intAux4 := 1; - strAux3 := ''; - ValorChavePerfis := '*'; - v_LetrasDrives := LetrasDrives; - - while ValorChavePerfis <> '' do - begin - strAux3 := 'SIS' + trim(inttostr(intAux4)); - strTripa := ''; // Conterá as informações a serem enviadas ao Gerente. - // Obtenho do registro o valor que foi previamente armazenado - ValorChavePerfis := Trim(GetValorChaveRegIni('Coleta',strAux3, p_path_cacic + 'cacic2.ini')); - - if (ValorChavePerfis <> '') then - Begin - //Atenção, OS ELEMENTOS DEVEM ESTAR DE ACORDO COM A ORDEM QUE SÃO TRATADOS NO MÓDULO GERENTE. - tstrTripa2 := Explode(ValorChavePerfis,','); - if (strAux <> '') then strAux := strAux + '#'; - strAux := strAux + trim(tstrTripa2[0]) + ','; - - //Coleta de Informação de Licença - if (trim(tstrTripa2[2])='0') then //Vazio - Begin - strAux := strAux + ','; - End; - - if (trim(tstrTripa2[2])='1') then //Caminho\Chave\Valor em Registry - Begin - strAux4 := ''; - Try - strAux4 := Trim(GetValorChaveRegEdit(trim(tstrTripa2[3]))); - Except - End; - if (strAux4 = '') then strAux4 := '?'; - strAux := strAux + strAux4 + ','; - End; - - if (trim(tstrTripa2[2])='2') then //Nome/Seção/Chave de Arquivo INI - Begin - Try - if (LastPos('/',trim(tstrTripa2[3]))>0) then - Begin - tstrTripa3 := Explode(trim(tstrTripa2[3]),'/'); - // - for v1:=1 to length(v_LetrasDrives) do - Begin - v_File := trim(tstrTripa3[0]); - if (LastPos(':\',v_File)>0) then - Begin - v_Drive := Copy(v_File,1,3); - v_File := Copy(v_File,4,Length(v_File)); - End - else - Begin - v_Drive := v_LetrasDrives[v1] + ':'; - if (Copy(v_File,1,1)<>'\') then v_Drive := v_Drive + '\'; - v_File := Copy(v_File,1,Length(v_File)); - End; - - strAux1 := ExtractShortPathName(v_Drive + v_File); - if (strAux1 = '') then - begin - if (SearchFile(v_Drive,v_File)) then - Begin - strAux1 := v_Res_Search; - break; - End; - end - else break; - End; - - - // - strAux4 := Trim(GetValorChaveRegIni(tstrTripa3[1],tstrTripa3[2],strAux1)); - if (strAux4 = '') then strAux4 := '?'; - strAux := strAux + strAux4 + ','; - End; - - if (LastPos('/',trim(tstrTripa2[3]))=0) then - Begin - strAux := strAux + 'Parâm.Lic.Incorreto,'; - End - Except - strAux := strAux + 'Parâm.Lic.Incorreto,'; - End; - End; - - //Coleta de Informação de Instalação - if (trim(tstrTripa2[5])='0') then //Vazio - Begin - strAux := strAux + ','; - End; - - if (trim(tstrTripa2[5])='1') or (trim(tstrTripa2[5]) = '2') then //Nome de Executável OU Nome de Arquivo de Configuração (CADPF!!!) - Begin - strAux1 := ''; - for v1:=1 to length(v_LetrasDrives) do - Begin - v_File := trim(tstrTripa2[6]); - if (LastPos(':\',v_File)>0) then - Begin - v_Drive := Copy(v_File,1,3); - v_File := Copy(v_File,4,Length(v_File)); - End - else - Begin - v_Drive := v_LetrasDrives[v1] + ':'; - if (Copy(v_File,1,1)<>'\') then v_Drive := v_Drive + '\'; - v_File := Copy(v_File,1,Length(v_File)); - End; - - strAux1 := ExtractShortPathName(v_Drive + v_File); - if (strAux1 = '') then - begin - if (SearchFile(v_Drive,v_File)) then - Begin - strAux1 := v_Res_Search; - break; - End; - end - else break; - - End; - - if (strAux1 <> '') then strAux := strAux + 'S,'; - if (strAux1 = '') then strAux := strAux + 'N,'; - strAux1 := ''; - End; - - if (trim(tstrTripa2[5])='3') then //Caminho\Chave\Valor em Registry - Begin - strAux1 := ''; - Try - strAux1 := Trim(GetValorChaveRegEdit(trim(tstrTripa2[5]))); - Except - End; - if (strAux1 <> '') then strAux := strAux + 'S,'; - if (strAux1 = '') then strAux := strAux + 'N,'; - strAux1 := ''; - End; - - //Coleta de Informação de Versão - if (trim(tstrTripa2[7])='0') then //Vazio - Begin - strAux := strAux + ','; - End; - - if (trim(tstrTripa2[7])='1') then //Data de Arquivo - Begin - strAux1 := ''; - for v1:=1 to length(v_LetrasDrives) do - Begin - v_File := trim(tstrTripa2[8]); - if (LastPos(':\',v_File)>0) then - Begin - v_Drive := Copy(v_File,1,3); - v_File := Copy(v_File,4,Length(v_File)); - End - else - Begin - v_Drive := v_LetrasDrives[v1] + ':'; - if (Copy(v_File,1,1)<>'\') then v_Drive := v_Drive + '\'; - v_File := Copy(v_File,1,Length(v_File)); - End; - - strAux1 := ExtractShortPathName(v_Drive + v_File); - if (strAux1 = '') then - begin - if (SearchFile(v_Drive,v_File)) then - Begin - strAux1 := v_Res_Search; - break; - End; - end - else break; - End; - if (strAux1 <> '') then - Begin - v_Data := StringReplace(DateToStr(FileDateToDateTime(FileAge(strAux1))),'.','/',[rfReplaceAll]); - v_Data := StringReplace(v_Data,'-','/',[rfReplaceAll]); - strAux := strAux + v_Data + ','; - v_Data := ''; - End; - if (strAux1 = '') then strAux := strAux + '?,'; - strAux1 := ''; - End; - - if (trim(tstrTripa2[7])='2') then //Caminho\Chave\Valor em Registry - Begin - strAux1 := ''; - Try - strAux1 := Trim(GetValorChaveRegEdit(trim(tstrTripa2[8]))); - Except - End; - if (strAux1 <> '') then strAux := strAux + strAux1 + ','; - if (strAux1 = '') then strAux := strAux + '?,'; - strAux1 := ''; - End; - - if (trim(tstrTripa2[7])='3') then //Nome/Seção/Chave de Arquivo INI - Begin - Try - if (LastPos('/',trim(tstrTripa2[8]))>0) then - Begin - tstrTripa3 := Explode(trim(tstrTripa2[8]),'/'); - // - for v1:=1 to length(v_LetrasDrives) do - Begin - v_File := trim(tstrTripa3[0]); - if (LastPos(':\',v_File)>0) then - Begin - v_Drive := Copy(v_File,1,3); - v_File := Copy(v_File,4,Length(v_File)); - End - else - Begin - v_Drive := v_LetrasDrives[v1] + ':'; - if (Copy(v_File,1,1)<>'\') then v_Drive := v_Drive + '\'; - v_File := Copy(v_File,1,Length(v_File)); - End; - - - strAux1 := ExtractShortPathName(v_Drive + v_File); - if (strAux1 = '') then - begin - if (SearchFile(v_Drive,v_File)) then - Begin - strAux1 := v_Res_Search; - break; - End; - end - else break; - End; - - // - strAux4 := Trim(GetValorChaveRegIni(tstrTripa3[1],tstrTripa3[2],strAux1)); - if (strAux4 = '') then strAux4 := '?'; - strAux := strAux + strAux4 + ','; - End - else - Begin - strAux := strAux + 'Parâm.Versao Incorreto,'; - End; - Except - End; - End; - - //Coleta de Informação de Engine - if (trim(tstrTripa2[9])='.') then //Vazio - Begin - strAux := strAux + ','; - End; - //O ponto é proposital para quando o último parâmetro vem vazio do Gerente!!! :) - if (trim(tstrTripa2[9])<>'.') then //Arquivo para Versão de Engine - Begin - for v1:=1 to length(v_LetrasDrives) do - Begin - v_File := trim(tstrTripa2[9]); - if (LastPos(':\',v_File)>0) then - Begin - v_Drive := Copy(v_File,1,3); - v_File := Copy(v_File,4,Length(v_File)); - End - else - Begin - v_Drive := v_LetrasDrives[v1] + ':'; - if (Copy(v_File,1,1)<>'\') then v_Drive := v_Drive + '\'; - v_File := Copy(v_File,1,Length(v_File)); - End; - - strAux1 := ExtractShortPathName(v_Drive + v_File); - if (strAux1 = '') then - begin - if (SearchFile(v_Drive,v_File)) then - Begin - strAux1 := v_Res_Search; - break; - End; - end - else break; - End; - if (strAux1 <> '') then - Begin - tstrTripa3 := Explode(getVersionInfo(strAux1), '.'); // Pego só os dois primeiros dígitos. Por exemplo: 6.640.0.1001 vira 6.640. - strAux := strAux + tstrTripa3[0] + '.' + tstrTripa3[1]; - End; - End; - - //Coleta de Informação de Pattern - //O ponto é proposital para quando o último parâmetro vem vazio do Gerente!!! :) - strAux1 := ''; - if (trim(tstrTripa2[10])<>'.') then //Arquivo para Versão de Pattern - Begin - for v1:=1 to length(v_LetrasDrives) do - Begin - v_File := trim(tstrTripa2[10]); - if (LastPos(':\',v_File)>0) then - Begin - v_Drive := Copy(v_File,1,3); - v_File := Copy(v_File,4,Length(v_File)); - End - else - Begin - v_Drive := v_LetrasDrives[v1] + ':'; - if (Copy(v_File,1,1)<>'\') then v_Drive := v_Drive + '\'; - v_File := Copy(v_File,1,Length(v_File)); - End; - - strAux1 := ExtractShortPathName(v_Drive + v_File); - if (strAux1 = '') then - begin - if (SearchFile(v_Drive, v_File)) then - Begin - strAux1 := v_Res_Search; - break; - End; - end - else break; - - End; - End; - if (strAux1 <> '') then - Begin - tstrTripa3 := Explode(getVersionInfo(strAux1), '.'); // Pego só os dois primeiros dígitos. Por exemplo: 6.640.0.1001 vira 6.640. - strAux := strAux + tstrTripa3[0] + '.' + tstrTripa3[1]; - End; - if (strAux1 = '') then strAux := strAux + ','; - strAux1 := ''; - End; - intAux4 := intAux4 + 1; - End; - ValorChaveColetado := Trim(GetValorChaveRegIni('Coleta','Sistemas_Monitorados', p_path_cacic + 'cacic2.ini')); - If (GetValorChaveRegIni('Configs','IN_COLETA_FORCADA_MONI',p_path_cacic_ini)='S') or (trim(strAux) <> trim(ValorChaveColetado)) Then - Begin - if (trim(ValorChaveColetado) <> '') then - begin - v_array1 := Explode(strAux, '#'); - strAux := ''; - v_array3 := Explode(ValorChaveColetado, '#'); - for v1 := 0 to (v_array1.count)-1 do - Begin - v_array2 := Explode(v_array1[v1], ','); - v_achei := 0; - for v3 := 0 to (v_array3.count)-1 do - Begin - v_array4 := Explode(v_array3[v3], ','); - if (v_array4=v_array2) then v_achei := 1; - End; - if (v_achei = 0) then - Begin - if (strAUX <> '') then strAUX := strAUX + '#'; - strAUX := strAUX + v_array1[v1]; - End; - End; - end; - frm_col_moni.SetValorChaveRegIni('Col_Moni','Sistemas_Monitorados', strAux,frm_col_moni.GetValorChaveRegIni('Configs','P_PATH_COLETAS_INI',p_path_cacic + 'cacic2.ini')+'col_moni.ini'); - end - else frm_col_moni.SetValorChaveRegIni('Col_Moni','nada', 'nada',frm_col_moni.GetValorChaveRegIni('Configs','P_PATH_COLETAS_INI',p_path_cacic + 'cacic2.ini')+'col_moni.ini'); - application.Terminate; - Except - Begin - frm_col_moni.SetValorChaveRegIni('Col_Moni','nada', 'nada',frm_col_moni.GetValorChaveRegIni('Configs','P_PATH_COLETAS_INI',p_path_cacic + 'cacic2.ini')+'col_moni.ini'); - application.Terminate; - End; - End; -END; - -procedure Tfrm_col_moni.FormCreate(Sender: TObject); -var tstrTripa1 : TStrings; - intAux : integer; -begin - - //Pegarei o nível anterior do diretório, que deve ser, por exemplo \Cacic, para leitura do cacic2.ini - tstrTripa1 := explode(ExtractFilePath(Application.Exename),'\'); - p_path_cacic := ''; - For intAux := 0 to tstrTripa1.Count -2 do - begin - p_path_cacic := p_path_cacic + tstrTripa1[intAux] + '\'; - end; - p_path_cacic_ini := p_path_cacic + 'cacic2.ini'; - Application.ShowMainForm := false; - - Try - Executa_Col_moni; - Except - frm_col_moni.SetValorChaveRegIni('Col_Moni','nada', 'nada',frm_col_moni.GetValorChaveRegIni('Configs','P_PATH_COLETAS_INI',p_path_cacic + 'cacic2.ini')+'col_moni.ini'); - application.Terminate; - End; -end; -end. - diff --git a/col_undi/col_undi.dpr b/col_undi/col_undi.dpr index 161321b..40f48c1 100755 --- a/col_undi/col_undi.dpr +++ b/col_undi/col_undi.dpr @@ -44,6 +44,8 @@ var p_path_cacic, var v_tstrCipherOpened, v_tstrCipherOpened1 : TStrings; +var g_oCacic : TCACIC; + // Some constants that are dependant on the cipher being used // Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize) const KeySize = 32; // 32 bytes = 256 bits @@ -199,14 +201,9 @@ begin // Criação do arquivo .DAT Rewrite (v_DatFile); Append(v_DatFile); - - //v_Cipher := TDCP_rijndael.Create(nil); - //v_Cipher.InitStr(v_CipherKey,TDCP_md5); + v_strCipherOpenImploded := Implode(p_tstrCipherOpened,'=CacicIsFree='); v_strCipherClosed := EnCrypt(v_strCipherOpenImploded); - //v_strCipherClosed := v_Cipher.EncryptString(v_strCipherOpenImploded); - //v_Cipher.Burn; - //v_Cipher.Free; Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto} @@ -244,66 +241,6 @@ Begin Explode := ListaAuxUTILS; end; - -function GetWinVer: Integer; -const - { operating system (OS)constants } - cOsUnknown = 0; - cOsWin95 = 1; - cOsWin95OSR2 = 2; // Não implementado. - cOsWin98 = 3; - cOsWin98SE = 4; - cOsWinME = 5; - cOsWinNT = 6; - cOsWin2000 = 7; - cOsXP = 8; -var - osVerInfo: TOSVersionInfo; - majorVer, minorVer: Integer; -begin - Result := cOsUnknown; - { set operating system type flag } - osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); - if GetVersionEx(osVerInfo) then - begin - majorVer := osVerInfo.dwMajorVersion; - minorVer := osVerInfo.dwMinorVersion; - case osVerInfo.dwPlatformId of - VER_PLATFORM_WIN32_NT: { Windows NT/2000 } - begin - if majorVer <= 4 then - Result := cOsWinNT - else if (majorVer = 5) and (minorVer = 0) then - Result := cOsWin2000 - else if (majorVer = 5) and (minorVer = 1) then - Result := cOsXP - else - Result := cOsUnknown; - end; - VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME } - begin - if (majorVer = 4) and (minorVer = 0) then - Result := cOsWin95 - else if (majorVer = 4) and (minorVer = 10) then - begin - if osVerInfo.szCSDVersion[1] = 'A' then - Result := cOsWin98SE - else - Result := cOsWin98; - end - else if (majorVer = 4) and (minorVer = 90) then - Result := cOsWinME - else - Result := cOsUnknown; - end; - else - Result := cOsUnknown; - end; - end - else - Result := cOsUnknown; -end; - Function CipherOpen(p_DatFileName : string) : TStrings; var v_DatFile : TextFile; v_strCipherOpened, @@ -330,7 +267,7 @@ begin if (trim(v_strCipherOpened)<>'') then Result := explode(v_strCipherOpened,'=CacicIsFree=') else - Result := explode('Configs.ID_SO=CacicIsFree='+inttostr(GetWinVer)+'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); + Result := explode('Configs.ID_SO=CacicIsFree='+ g_oCacic.getWindowsStrId() +'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); if Result.Count mod 2 <> 0 then Result.Add(''); @@ -346,9 +283,8 @@ begin p_tstrCipherOpened.Add(p_Chave); p_tstrCipherOpened.Add(p_Valor); End; -//DEBUG -//log_diario('Gravando: '+p_Chave +' => '+p_Valor); end; + Function GetValorDatMemoria(p_Chave : String; p_tstrCipherOpened : TStrings) : String; begin if (p_tstrCipherOpened.IndexOf(p_Chave)<>-1) then @@ -357,7 +293,6 @@ begin Result := ''; end; - function GetFolderDate(Folder: string): TDateTime; var Rec: TSearchRec; @@ -379,8 +314,6 @@ begin end; end; - - function GetRootKey(strRootKey: String): HKEY; begin /// Encontrar uma maneira mais elegante de fazer esses testes. @@ -446,8 +379,6 @@ begin end; end; - - procedure Grava_Debugs(strMsg : String); var DebugsFile : TextFile; @@ -597,12 +528,11 @@ const var tstrTripa1 : TStrings; intAux : integer; - oCacic : TCACIC; begin - oCacic := TCACIC.Create(); + g_oCacic := TCACIC.Create(); - if( not oCacic.isAppRunning( CACIC_APP_NAME ) ) then + if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) ) then if (ParamCount>0) then Begin For intAux := 1 to ParamCount do @@ -650,6 +580,6 @@ begin End; End; - oCacic.Free(); + g_oCacic.Free(); end. diff --git a/ger_cols/ger_cols.dpr b/ger_cols/ger_cols.dpr index 02c24ba..726e87e 100755 --- a/ger_cols/ger_cols.dpr +++ b/ger_cols/ger_cols.dpr @@ -330,12 +330,6 @@ Begin End; Implode := strAux; end; -function abstraiCSD(p_te_so : String) : integer; - var tstrTe_so : tstrings; - Begin - tstrTe_so := Explode(p_te_so, '.'); - Result := StrToInt(tstrTe_so[0] + tstrTe_so[1] + tstrTe_so[2]); - End; Procedure SetValorDatMemoria(p_Chave : string; p_Valor : String; p_tstrCipherOpened : TStrings); var v_Aux : string; @@ -458,89 +452,6 @@ begin End; end; -function GetWinVer: Integer; -const - { operating system (OS)constants } - cOsUnknown = 0; - cOsWin95 = 1; - cOsWin95OSR2 = 2; // Não implementado. - cOsWin98 = 3; - cOsWin98SE = 4; - cOsWinME = 5; - cOsWinNT = 6; - cOsWin2000 = 7; - cOsXP = 8; - cOsWinServer2003 = 13; -var - osVerInfo: TOSVersionInfo; - platformID, - majorVer, - minorVer : Integer; - CSDVersion : String; -begin - Result := cOsUnknown; - { set operating system type flag } - osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); - if GetVersionEx(osVerInfo) then - begin - platformId := osVerInfo.dwPlatformId; - majorVer := osVerInfo.dwMajorVersion; - minorVer := osVerInfo.dwMinorVersion; - CSDVersion := trim(osVerInfo.szCSDVersion); - - case osVerInfo.dwPlatformId of - VER_PLATFORM_WIN32_NT: {Windows NT Like} - begin - if majorVer <= 4 then - Result := cOsWinNT - else if (majorVer = 5) and (minorVer = 0) then - Result := cOsWin2000 - else if (majorVer = 5) and (minorVer = 1) then - Result := cOsXP - else if (majorVer = 5) and (minorVer = 2) then - Result := cOsWinServer2003 - else - Result := cOsUnknown; - - end; - VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME } - begin - if (majorVer = 4) and (minorVer = 0) then - Result := cOsWin95 - else if (majorVer = 4) and (minorVer = 10) then - begin - if osVerInfo.szCSDVersion[1] = 'A' then - Result := cOsWin98SE - else - Result := cOsWin98; - end - else if (majorVer = 4) and (minorVer = 90) then - Result := cOsWinME - else - Result := cOsUnknown; - - end; - - else - Result := cOsUnknown; - end; - end - else - Result := cOsUnknown; - - // A partir da versão 2.2.0.24, defino o valor da ID Interna e atribuo-a sem o CSDVersion à versão externa - v_te_so := IntToStr(platformId) + '.' + - IntToStr(majorVer) + '.' + - IntToStr(minorVer) + - ifThen(CSDVersion='','','.'+CSDVersion); - - { - Forço o envio do identificador interno - if (Result = 0) then - } - Result := abstraiCSD(v_te_so); -end; - procedure Matar(v_dir,v_files: string); var SearchRec: TSearchRec; Result: Integer; @@ -639,7 +550,7 @@ begin if (trim(v_strCipherOpened)<>'') then Result := explode(v_strCipherOpened,'=CacicIsFree=') else - Result := explode('Configs.ID_SO=CacicIsFree='+inttostr(GetWinVer)+'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); + Result := explode('Configs.ID_SO=CacicIsFree='+g_oCacic.getWindowsStrId()+'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); if Result.Count mod 2 = 0 then Result.Add(''); @@ -1215,8 +1126,6 @@ Function ComunicaServidor(URL : String; Request : TStringList; MsgAcao: String) var Response_CS : TStringStream; strEndereco, v_Endereco_WS, - v_Aux, - v_Aux1, strAux : String; idHTTP1 : TIdHTTP; intAux : integer; @@ -1231,13 +1140,12 @@ Begin // A partir da versão 2.0.2.18+ envio um Classificador indicativo de dados compactados... v_AuxRequest.Values['cs_compress'] := GetValorDatMemoria('Configs.CS_COMPRESS',v_tstrCipherOpened); - intAux := GetWinVer; strAux := GetValorDatMemoria('TcpIp.TE_IP', v_tstrCipherOpened); if (strAux = '') then strAux := 'A.B.C.D'; // Apenas para forçar que o Gerente extraia via _SERVER[REMOTE_ADDR] v_AuxRequest.Values['te_node_address'] := StringReplace(EnCrypt(GetValorDatMemoria('TcpIp.TE_NODE_ADDRESS' , v_tstrCipherOpened),l_cs_compress),'+','',[rfReplaceAll]); - v_AuxRequest.Values['id_so'] := StringReplace(EnCrypt(IntToStr(intAux) ,l_cs_compress),'+','',[rfReplaceAll]); + v_AuxRequest.Values['id_so'] := StringReplace(EnCrypt(g_oCacic.getWindowsStrId() , l_cs_compress),'+','',[rfReplaceAll]); // Tratamentos de valores para tráfego POST: // v_te_so => transformar ' ' em Razão: o mmcrypt se perde quando encontra ' ' (espaço) //v_te_so := StringReplace(v_te_so,' ','',[rfReplaceAll]); @@ -1792,7 +1700,8 @@ procedure Patrimnio1Click(Sender: TObject); begin SetValorDatMemoria('Patrimonio.dt_ultima_renovacao_patrim','', v_tstrCipherOpened); if ChecaAgente(p_path_cacic + 'modulos', 'ini_cols.exe') then - WinExec(PChar(p_path_cacic + 'modulos\ini_cols.exe /p_CipherKey='+v_CipherKey+ ' /p_ModulosOpcoes=col_patr,wait,user#'),SW_HIDE); + g_oCacic.createSampleProcess( p_path_cacic + 'modulos\ini_cols.exe /p_CipherKey=' + v_CipherKey + + ' /p_ModulosOpcoes=col_patr,wait,user#', CACIC_PROCESS_WAIT ); end; procedure ChecaCipher; @@ -2929,8 +2838,8 @@ Begin Finalizar(false); Matar(p_path_cacic + 'temp\','*.dat'); CriaTXT(p_path_cacic+'temp','coletas'); - WinExec(PChar(p_path_cacic + 'modulos\ini_cols.exe /p_CipherKey='+v_CipherKey+' /p_ModulosOpcoes='+v_ModulosOpcoes), SW_HIDE); - Sair; + g_oCacic.createSampleProcess( p_path_cacic + 'modulos\ini_cols.exe /p_CipherKey=' + v_CipherKey + + ' /p_ModulosOpcoes=' + v_ModulosOpcoes, CACIC_PROCESS_WAIT ); End; end @@ -3326,9 +3235,11 @@ Begin if (intAux = 0) then log_diario('Sem informações para envio ao Gerente WEB.') - // Atualizo a data de última coleta - else + else begin + // Atualiza a data de última coleta SetValorDatMemoria('Configs.DT_HR_ULTIMA_COLETA',FormatDateTime('YYYYmmddHHnnss', Now), v_tstrCipherOpened); + log_diario('Todos os dados coletados foram enviados ao Gerente WEB.'); + end; end; Except Begin @@ -3398,7 +3309,7 @@ begin v_tstrCipherOpened := CipherOpen(v_DatFileName); // Não tirar desta posição - SetValorDatMemoria('Configs.ID_SO',IntToStr(GetWinVer), v_tstrCipherOpened); + SetValorDatMemoria('Configs.ID_SO',g_oCacic.getWindowsStrId(), v_tstrCipherOpened); v_scripter := 'wscript.exe'; // A existência e bloqueio do arquivo abaixo evitará que Cacic2.exe chame o Ger_Cols quando este estiver em funcionamento diff --git a/ini_cols/ini_cols.dpr b/ini_cols/ini_cols.dpr index 54ca22a..4bd8118 100755 --- a/ini_cols/ini_cols.dpr +++ b/ini_cols/ini_cols.dpr @@ -518,36 +518,8 @@ begin v_Aux := v_tstrModuloOpcao[0]+'.exe /p_CipherKey='+v_CipherKey+ ' /p_Option='+v_tstrModuloOpcao[2]; log_DEBUG('Chamando "' + v_tstrModuloOpcao[0]+'.exe /p_CipherKey=*****" /p_Option='+v_tstrModuloOpcao[2]); - WinExec(PChar(v_Aux), SW_HIDE); - - if (v_tstrModuloOpcao[1]='wait') then - while not FileExists(p_path_cacic + 'temp\'+v_tstrModuloOpcao[0]+'.dat') do - Sleep(2000) - else - Begin - v_ContaTempo := 0; - while not FileExists(p_path_cacic + 'temp\'+v_tstrModuloOpcao[0]+'.dat') and - ((v_ContaTempo/60)< v_Tolerancia) do // Tolerância para a coleta - Begin - Sleep(2000); - v_ContaTempo := v_ContaTempo + 2; - End; - End; - End; + oCacic.createSampleProcess( p_path_cacic + '\modulos\' + v_aux, CACIC_PROCESS_WAIT ); - For intAux := 0 to v_tstrModulosOpcoes.Count -1 do - Begin - v_tstrModuloOpcao := explode(v_tstrModulosOpcoes[intAux],','); - v_Aux := p_path_cacic + 'temp\'+v_tstrModuloOpcao[0]+'.dat'; - if (FileExists(v_Aux)) then - Begin - log_DEBUG('Chamando "'+'ger_cols.exe /p_CipherKey=*****'); - WinExec(PChar('ger_cols.exe /p_CipherKey='+v_CipherKey), SW_HIDE); - // Fecha o arquivo temp\aguarde_INI.txt - CloseFile(v_Aguarde); - Matar(p_path_cacic+'temp\','aguarde_INI'); - break; - End; End; except end; diff --git a/mapa/main_mapa.pas b/mapa/main_mapa.pas index cf9f9fc..8340744 100755 --- a/mapa/main_mapa.pas +++ b/mapa/main_mapa.pas @@ -43,17 +43,18 @@ uses IniFiles, DCPbase64, ExtCtrls, Graphics, - Dialogs; + Dialogs, + CACIC_Library; var strCipherClosed, strCipherOpened, - strPathCacic, - str_te_so : string; + strPathCacic : string; var intPausaPadrao : integer; var boolDebugs : boolean; +var g_oCacic : TCACIC; // Some constants that are dependant on the cipher being used // Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize) @@ -111,7 +112,6 @@ type function HomeDrive : string; Function Implode(p_Array : TStrings ; p_Separador : String) : String; Function CipherClose(p_DatFileName : string; p_tstrCipherOpened : TStrings) : String; - function GetWinVer: Integer; Function Explode(Texto, Separador : String) : TStrings; Function CipherOpen(p_DatFileName : string) : TStrings; Function GetValorDatMemoria(p_Chave : String; p_tstrCipherOpened : TStrings) : String; @@ -456,9 +456,8 @@ end; procedure TfrmMapaCacic.Sair; Begin - application.Terminate; -// FreeMemory(0); -// Halt(0); + g_oCacic.Free(); + Application.Terminate; End; procedure TfrmMapaCacic.Finalizar(p_pausa:boolean); @@ -818,79 +817,6 @@ begin except end; end; -function TfrmMapaCacic.GetWinVer: Integer; -const - { operating system (OS)constants } - cOsUnknown = 0; - cOsWin95 = 1; - cOsWin95OSR2 = 2; // Não implementado. - cOsWin98 = 3; - cOsWin98SE = 4; - cOsWinME = 5; - cOsWinNT = 6; - cOsWin2000 = 7; - cOsXP = 8; - -var - osVerInfo: TOSVersionInfo; - platformID, - majorVer, - minorVer: Integer; - CSDVersion : String; -begin - Result := cOsUnknown; - { set operating system type flag } - osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); - if GetVersionEx(osVerInfo) then - begin - platformId := osVerInfo.dwPlatformId; - majorVer := osVerInfo.dwMajorVersion; - minorVer := osVerInfo.dwMinorVersion; - CSDVersion := trim(osVerInfo.szCSDVersion); - - case osVerInfo.dwPlatformId of - VER_PLATFORM_WIN32_NT: { Windows NT/2000 } - begin - if majorVer <= 4 then - Result := cOsWinNT - else if (majorVer = 5) and (minorVer = 0) then - Result := cOsWin2000 - else if (majorVer = 5) and (minorVer = 1) then - Result := cOsXP - else - Result := cOsUnknown; - end; - VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME } - begin - if (majorVer = 4) and (minorVer = 0) then - Result := cOsWin95 - else if (majorVer = 4) and (minorVer = 10) then - begin - if osVerInfo.szCSDVersion[1] = 'A' then - Result := cOsWin98SE - else - Result := cOsWin98; - end - else if (majorVer = 4) and (minorVer = 90) then - Result := cOsWinME - else - Result := cOsUnknown; - end; - else - Result := cOsUnknown; - end; - end - else - Result := cOsUnknown; - - // Defino o valor da ID Interna - str_te_so := IntToStr(platformId) + '.' + - IntToStr(majorVer) + '.' + - IntToStr(minorVer) + - IfThen(CSDVersion='','','.'+CSDVersion); - -end; - Function TfrmMapaCacic.CipherOpen(p_DatFileName : string) : TStrings; var v_DatFile : TextFile; @@ -919,7 +845,7 @@ begin if (trim(strCipherOpened)<>'') then Result := explode(strCipherOpened,'=CacicIsFree=') else - Result := explode('Configs.ID_SO=CacicIsFree='+inttostr(GetWinVer)+'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); + Result := explode('Configs.ID_SO=CacicIsFree='+ g_oCacic.getWindowsStrId() +'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree='); if Result.Count mod 2 = 0 then Result.Add(''); @@ -1388,25 +1314,13 @@ begin tstrAux.Free; -// Assim, o envio será incondicional! - 01/12/2006 - Anderson Peterle -// if (strAux1 <> strId_unid_organizacional_nivel1) or -// (strAux2 <> strId_unid_organizacional_nivel2) or -// (ed_te_localizacao_complementar.Text <> strTe_localizacao_complementar) or -// (ed_te_info_patrimonio1.Text <> strTe_info_patrimonio1) or -// (ed_te_info_patrimonio2.Text <> strTe_info_patrimonio2) or -// (ed_te_info_patrimonio3.Text <> strTe_info_patrimonio3) or -// (ed_te_info_patrimonio4.Text <> strTe_info_patrimonio4) or -// (ed_te_info_patrimonio5.Text <> strTe_info_patrimonio5) or -// (ed_te_info_patrimonio6.Text <> strTe_info_patrimonio6) then -// begin - Mensagem('Enviando Informações Coletadas ao Banco de Dados...',false,intPausaPadrao div 3); // Envio dos Dados Coletados ao Banco de Dados tstrListAux := TStringList.Create; tstrListAux.Values['te_node_address'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('TcpIp.TE_NODE_ADDRESS' , frmMapaCacic.tStringsCipherOpened)); tstrListAux.Values['id_so'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Configs.ID_SO' , frmMapaCacic.tStringsCipherOpened)); - tstrListAux.Values['te_so'] := frmMapaCacic.EnCrypt(str_te_so); + tstrListAux.Values['te_so'] := frmMapaCacic.EnCrypt(g_oCacic.getWindowsStrId()); tstrListAux.Values['id_ip_rede'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('TcpIp.ID_IP_REDE' , frmMapaCacic.tStringsCipherOpened)); tstrListAux.Values['te_ip'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('TcpIp.TE_IP' , frmMapaCacic.tStringsCipherOpened)); tstrListAux.Values['te_nome_computador'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('TcpIp.TE_NOME_COMPUTADOR' , frmMapaCacic.tStringsCipherOpened)); @@ -1746,9 +1660,10 @@ var intAux : integer; strRetorno : String; Request_mapa : TStringList; begin + g_oCacic := TCACIC.Create(); frmMapaCacic.lbVersao.Caption := 'Versão: ' + frmMapaCacic.GetVersionInfo(ParamStr(0)); log_DEBUG('Versão do MapaCacic: '+frmMapaCacic.lbVersao.Caption); - if (GetWinVer > 5) and not IsAdmin then + if (g_oCacic.isWindowsNTPlataform()) and (not g_oCacic.isWindowsAdmin()) then Begin MessageDLG(#13#10+'ATENÇÃO! Essa aplicação requer execução com nível administrativo.',mtError,[mbOK],0); Sair; @@ -1805,7 +1720,7 @@ begin Request_mapa := TStringList.Create; Request_mapa.Values['te_node_address'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('TcpIp.TE_NODE_ADDRESS' , frmMapaCacic.tStringsCipherOpened)); Request_mapa.Values['id_so'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Configs.ID_SO' , frmMapaCacic.tStringsCipherOpened)); - Request_mapa.Values['te_so'] := frmMapaCacic.EnCrypt(str_te_so); + Request_mapa.Values['te_so'] := frmMapaCacic.EnCrypt(g_oCacic.getWindowsStrId()); Request_mapa.Values['id_ip_rede'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('TcpIp.ID_IP_REDE' , frmMapaCacic.tStringsCipherOpened)); Request_mapa.Values['te_ip'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('TcpIp.TE_IP' , frmMapaCacic.tStringsCipherOpened)); Request_mapa.Values['te_nome_computador']:= frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('TcpIp.TE_NOME_COMPUTADOR', frmMapaCacic.tStringsCipherOpened)); -- libgit2 0.21.2