From 6663eb4f3b8fb039a214f6d596d88408b3171c81 Mon Sep 17 00:00:00 2001 From: anderson.peterle@previdencia.gov.br Date: Thu, 23 Sep 2010 15:32:41 +0000 Subject: [PATCH] Implementação de USBDetect, ajustes para suporte de coleta de softwares à plataforma MS-Windows Vista/Seven, pequenas correções e faxina de código. --- USBdetectClass.pas | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cacic2.dpr | 5 +++-- cacic2.res | Bin 4880 -> 0 bytes cacicservice/CACICsvc.cfg | 5 +++-- cacicservice/CACICsvc.dof | 22 ++++++++++++++-------- cacicservice/CACICsvc.res | Bin 5300 -> 0 bytes chkcacic/chkcacic.res | Bin 5112 -> 0 bytes chksis/chksis.res | Bin 5092 -> 0 bytes col_anvi/col_anvi.dpr | 42 +++++++++++++++++++++--------------------- col_comp/col_comp.res | Bin 16296 -> 0 bytes col_hard/col_hard.dpr | 85 +++++++++++++++++++++++++++++++++++++++++++++---------------------------------------- col_hard/col_hard.res | Bin 16280 -> 0 bytes col_moni/col_moni.res | Bin 16304 -> 0 bytes col_patr/col_patr.res | Bin 16284 -> 0 bytes col_soft/col_soft.dpr | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- col_soft/col_soft.res | Bin 16300 -> 0 bytes col_undi/col_undi.res | Bin 16300 -> 0 bytes frmsenha.dfm | 4 ++-- ger_cols/ger_cols.dpr | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- ger_cols/ger_cols.res | Bin 4764 -> 0 bytes ini_cols/ini_cols.dpr | 1 + ini_cols/ini_cols.res | Bin 6700 -> 0 bytes main.dfm | 6 +++--- main.pas | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- mapa/mapacacic.res | Bin 5136 -> 0 bytes testacrypt/main_testacrypt.pas | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------- 26 files changed, 563 insertions(+), 230 deletions(-) create mode 100644 USBdetectClass.pas diff --git a/USBdetectClass.pas b/USBdetectClass.pas new file mode 100644 index 0000000..ae9dd5f --- /dev/null +++ b/USBdetectClass.pas @@ -0,0 +1,164 @@ +unit USBdetectClass; +// Código Original obtido em http://www.delphi3000.com/articles/article_4841.asp?SK= +interface +uses Windows, Messages, SysUtils, Classes; + +type + { Event Types } + TOnUsbChangeEvent = procedure(AObject : TObject; + const ADevType,AVendorID, + AProductID : string) of object; + + { USB Class } + TUsbClass = class(TObject) + private + FHandle : HWND; + FOnUsbRemoval, + FOnUsbInsertion : TOnUsbChangeEvent; + procedure GetUsbInfo(const ADeviceString : string; + out ADevType,AVendorID, + AProductID : string); + procedure WinMethod(var AMessage : TMessage); + procedure RegisterUsbHandler; + procedure WMDeviceChange(var AMessage : TMessage); + procedure Split(const Delimiter: Char;Input: string;const Strings: TStrings); + public + constructor Create; + destructor Destroy; override; + property OnUsbInsertion : TOnUsbChangeEvent read FOnUsbInsertion + write FOnUsbInsertion; + property OnUsbRemoval : TOnUsbChangeEvent read FOnUsbRemoval + write FOnUsbRemoval; + end; + + + +// ----------------------------------------------------------------------------- +implementation + +type + // Win API Definitions + PDevBroadcastDeviceInterface = ^DEV_BROADCAST_DEVICEINTERFACE; + DEV_BROADCAST_DEVICEINTERFACE = record + dbcc_size : DWORD; + dbcc_devicetype : DWORD; + dbcc_reserved : DWORD; + dbcc_classguid : TGUID; + dbcc_name : char; + end; + +const + // Miscellaneous + GUID_DEVINTF_USB_DEVICE : TGUID = '{A5DCBF10-6530-11D2-901F-00C04FB951ED}'; + USB_INTERFACE = $00000005; // Device interface class + USB_INSERTION = $8000; // System detected a new device + USB_REMOVAL = $8004; // Device is gone + +constructor TUsbClass.Create; +begin + inherited Create; + FHandle := AllocateHWnd(WinMethod); + RegisterUsbHandler; +end; + +destructor TUsbClass.Destroy; +begin + DeallocateHWnd(FHandle); + inherited Destroy; +end; + +procedure TUsbClass.GetUsbInfo(const ADeviceString : string; + out ADevType,AVendorID, + AProductID : string); +var sWork,sKey1 : string; + tstrAUX1,tstrAUX2 : TStringList; +begin + ADevType := ''; + AVendorID := ''; + AProductID := ''; + + if ADeviceString <> '' then + Begin + sWork := copy(ADeviceString,pos('#',ADeviceString) + 1,1026); + sKey1 := copy(sWork,1,pos('#',sWork) - 1); + + tstrAUX1 := TStringList.Create; + tstrAUX2 := TStringList.Create; + + Split('&',sKey1,tstrAUX1); + + Split('_',tstrAUX1[0],tstrAUX2); + AVendorID := tstrAUX2[1]; + + Split('_',tstrAUX1[1],tstrAUX2); + AProductID := tstrAUX2[1]; + + tstrAUX1.Free; + tstrAUX2.Free; + End; +end; + +procedure TUsbClass.Split(const Delimiter: Char; + Input: string; + const Strings: TStrings) ; +begin + Assert(Assigned(Strings)) ; + Strings.Clear; + Strings.Delimiter := Delimiter; + Strings.DelimitedText := Input; +end; + +procedure TUsbClass.WMDeviceChange(var AMessage : TMessage); +var iDevType : integer; + sDevString,sDevType, + sVendorID,sProductID : string; + pData : PDevBroadcastDeviceInterface; +begin + if (AMessage.wParam = USB_INSERTION) or + (AMessage.wParam = USB_REMOVAL) then + Begin + pData := PDevBroadcastDeviceInterface(AMessage.LParam); + iDevType := pData^.dbcc_devicetype; + + // Se for um dispositivo USB... + if iDevType = USB_INTERFACE then + Begin + sDevString := PChar(@pData^.dbcc_name); + + GetUsbInfo(sDevString,sDevType,sVendorID,sProductID); + + // O evento é disparado conforme a mensagem + if (AMessage.wParam = USB_INSERTION) and Assigned(FOnUsbInsertion) then + FOnUsbInsertion(self,sDevType,sVendorID,sProductID); + if (AMessage.wParam = USB_REMOVAL) and Assigned(FOnUsbRemoval) then + FOnUsbRemoval(self,sDevType,sVendorID,sProductID); + End; + End; +end; + +procedure TUsbClass.WinMethod(var AMessage : TMessage); +begin + if (AMessage.Msg = WM_DEVICECHANGE) then + WMDeviceChange(AMessage) + else + AMessage.Result := DefWindowProc(FHandle,AMessage.Msg, + AMessage.wParam,AMessage.lParam); +end; + + +procedure TUsbClass.RegisterUsbHandler; +var rDbi : DEV_BROADCAST_DEVICEINTERFACE; + iSize : integer; +begin + iSize := SizeOf(DEV_BROADCAST_DEVICEINTERFACE); + ZeroMemory(@rDbi,iSize); + rDbi.dbcc_size := iSize; + rDbi.dbcc_devicetype := USB_INTERFACE; + rDbi.dbcc_reserved := 0; + rDbi.dbcc_classguid := GUID_DEVINTF_USB_DEVICE; + rDbi.dbcc_name := #0; + RegisterDeviceNotification(FHandle,@rDbi,DEVICE_NOTIFY_WINDOW_HANDLE); +end; + + +end. diff --git a/cacic2.dpr b/cacic2.dpr index e5b6ead..7140fe9 100755 --- a/cacic2.dpr +++ b/cacic2.dpr @@ -26,7 +26,8 @@ uses frmLog in 'frmLog.pas' {FormLog}, LibXmlParser, WinVNC in 'winvnc.pas', - CACIC_Library in 'CACIC_Library.pas'; + CACIC_Library in 'CACIC_Library.pas', + USBdetectClass in 'USBdetectClass.pas'; {$R *.res} @@ -62,5 +63,5 @@ begin Application.Initialize; Application.Title := 'cacic2'; Application.CreateForm(TFormularioGeral, FormularioGeral); - Application.Run; + Application.Run; end. diff --git a/cacic2.res b/cacic2.res index c454c9a..77e46dc 100755 Binary files a/cacic2.res and b/cacic2.res differ diff --git a/cacicservice/CACICsvc.cfg b/cacicservice/CACICsvc.cfg index ae870e2..223035a 100755 --- a/cacicservice/CACICsvc.cfg +++ b/cacicservice/CACICsvc.cfg @@ -31,5 +31,6 @@ -M -$M16384,1048576 -K$00400000 --LE"c:\arquivos de programas\borland\delphi7\Projects\Bpl" --LN"c:\arquivos de programas\borland\delphi7\Projects\Bpl" +-E"..\" +-LE"c:\program files (x86)\borland\delphi7\Projects\Bpl" +-LN"c:\program files (x86)\borland\delphi7\Projects\Bpl" diff --git a/cacicservice/CACICsvc.dof b/cacicservice/CACICsvc.dof index 09a5ad0..0caba22 100755 --- a/cacicservice/CACICsvc.dof +++ b/cacicservice/CACICsvc.dof @@ -90,7 +90,7 @@ MaxStackSize=1048576 ImageBase=4194304 ExeDescription= [Directories] -OutputDir= +OutputDir=..\ UnitOutputDir= PackageDLLOutputDir= PackageDCPOutputDir= @@ -113,9 +113,9 @@ RootDir=E:\NTService\ IncludeVerInfo=1 AutoIncBuild=0 MajorVer=2 -MinorVer=5 +MinorVer=6 Release=0 -Build=774 +Build=2 Debug=0 PreRelease=0 Special=0 @@ -124,13 +124,19 @@ DLL=0 Locale=11274 CodePage=1252 [Version Info Keys] -CompanyName=Dataprev - Emp. de TI da Prev Social - URES -FileDescription=CACICservice - Módulo Serviço para Sustentação do Agente Principal -FileVersion=2.5.0.774 +CompanyName=Dataprev - Emp. de TI da Prev Social - UDSL/SSLC +FileDescription=Sistema CACIC - Módulo para Sustentação do Agente Principal +FileVersion=2.6.0.2 InternalName= LegalCopyright= LegalTrademarks= OriginalFilename= ProductName= -ProductVersion=2.6 -Comments=Baseado na Licença GNU/GPL +ProductVersion=2.6.0.1 +Comments=Licença: GNU/LGPL +[HistoryLists\hlUnitAliases] +Count=1 +Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; +[HistoryLists\hlOutputDirectorry] +Count=1 +Item0=..\ diff --git a/cacicservice/CACICsvc.res b/cacicservice/CACICsvc.res index db8056e..4ea6595 100755 Binary files a/cacicservice/CACICsvc.res and b/cacicservice/CACICsvc.res differ diff --git a/chkcacic/chkcacic.res b/chkcacic/chkcacic.res index 438d930..ffad421 100755 Binary files a/chkcacic/chkcacic.res and b/chkcacic/chkcacic.res differ diff --git a/chksis/chksis.res b/chksis/chksis.res index 9a13ce1..0ccdb09 100755 Binary files a/chksis/chksis.res and b/chksis/chksis.res differ diff --git a/col_anvi/col_anvi.dpr b/col_anvi/col_anvi.dpr index 4ef7327..be25bca 100755 --- a/col_anvi/col_anvi.dpr +++ b/col_anvi/col_anvi.dpr @@ -420,31 +420,31 @@ begin Begin g_oCacic.setCacicPath(strAux); - v_Debugs := false; - if DirectoryExists(g_oCacic.getCacicPath + 'Temp\Debugs') then - Begin - if (FormatDateTime('ddmmyyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then - Begin - v_Debugs := true; - log_diario('Pasta "' + g_oCacic.getCacicPath + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs'))+' encontrada. DEBUG ativado.'); + v_Debugs := false; + if DirectoryExists(g_oCacic.getCacicPath + 'Temp\Debugs') then + Begin + if (FormatDateTime('ddmmyyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then + Begin + v_Debugs := true; + log_diario('Pasta "' + g_oCacic.getCacicPath + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs'))+' encontrada. DEBUG ativado.'); + End; End; - End; - v_tstrCipherOpened := TStrings.Create; - v_tstrCipherOpened := CipherOpen(g_oCacic.getCacicPath + g_oCacic.getDatFileName); + v_tstrCipherOpened := TStrings.Create; + v_tstrCipherOpened := CipherOpen(g_oCacic.getCacicPath + g_oCacic.getDatFileName); - v_tstrCipherOpened1 := TStrings.Create; - v_tstrCipherOpened1 := CipherOpen(g_oCacic.getCacicPath + 'temp\col_anvi.dat'); + v_tstrCipherOpened1 := TStrings.Create; + v_tstrCipherOpened1 := CipherOpen(g_oCacic.getCacicPath + 'temp\col_anvi.dat'); - Try - Executa_Col_Anvi; - Except - Begin - SetValorDatMemoria('Col_Anvi.nada', 'nada', v_tstrCipherOpened1); - CipherClose(g_oCacic.getCacicPath + 'temp\col_anvi.dat', v_tstrCipherOpened1); - End; - End; + Try + Executa_Col_Anvi; + Except + Begin + SetValorDatMemoria('Col_Anvi.nada', 'nada', v_tstrCipherOpened1); + CipherClose(g_oCacic.getCacicPath + 'temp\col_anvi.dat', v_tstrCipherOpened1); + End; + End; + End; End; - End; g_oCacic.Free(); end. diff --git a/col_comp/col_comp.res b/col_comp/col_comp.res index f4f70c7..89f9126 100755 Binary files a/col_comp/col_comp.res and b/col_comp/col_comp.res differ diff --git a/col_hard/col_hard.dpr b/col_hard/col_hard.dpr index 556b5ea..4130996 100644 --- a/col_hard/col_hard.dpr +++ b/col_hard/col_hard.dpr @@ -48,8 +48,6 @@ var intAux : integer; g_oCacic : TCACIC; -const - CACIC_APP_NAME = 'col_hard'; // Dica baixada de http://www.marcosdellantonio.net/2007/06/14/operador-if-ternario-em-delphi-e-c/ // Fiz isso para não ter que acrescentar o componente Math ao USES! @@ -538,6 +536,16 @@ var v_te_cpu_fabricante, begin + v_Debugs := false; + if DirectoryExists(g_oCacic.getCacicPath + 'Temp\Debugs') then + Begin + if (FormatDateTime('ddmmyyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then + Begin + v_Debugs := true; + //log_diario('Pasta "' + g_oCacic.getCacicPath + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs'))+' encontrada. DEBUG ativado.'); + End; + End; + Try SetValorDatMemoria('Col_Hard.Inicio', FormatDateTime('hh:nn:ss', Now), v_tstrCipherOpened1); v_Report := TStringList.Create; @@ -973,51 +981,48 @@ begin g_oCacic.Free(); end; -var strAux : String; +// ATENÇÃO: Caso haja falha na execução deste agente pela estação de trabalho, +// a provável causa será a falta da Runtime Library RTL70.BPL, que +// costuma ser "confundida" com vírus e apagada por alguns anti-vírus +// como o Avasti. +// SOLUÇÃO: Baixar a partir do endereço http://nwvault.ign.com/View.php?view=Other.Detail&id=119 o pacote +// D70_Installer.zip, descompactar e executar na estação de trabalho. +var strAux : String; +const CACIC_APP_NAME = 'col_hard'; begin g_oCacic := TCACIC.Create(); - g_oCacic.setBoolCipher(true); if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) ) then - if (ParamCount>0) then - Begin - strAux := ''; - For intAux := 1 to ParamCount do - Begin - if LowerCase(Copy(ParamStr(intAux),1,11)) = '/cacicpath=' then - begin - strAux := Trim(Copy(ParamStr(intAux),12,Length((ParamStr(intAux))))); - log_DEBUG('Parâmetro /CacicPath recebido com valor="'+strAux+'"'); - end; - end; - - if (strAux <> '') then - Begin - g_oCacic.setCacicPath(strAux); + if (ParamCount>0) then + Begin + strAux := ''; + For intAux := 1 to ParamCount do + Begin + if LowerCase(Copy(ParamStr(intAux),1,11)) = '/cacicpath=' then + begin + strAux := Trim(Copy(ParamStr(intAux),12,Length((ParamStr(intAux))))); + //log_DEBUG('Parâmetro /CacicPath recebido com valor="'+strAux+'"'); + end; + end; - v_tstrCipherOpened := TStrings.Create; - v_tstrCipherOpened := CipherOpen(g_oCacic.getCacicPath + g_oCacic.getDatFileName); + if (strAux <> '') then + Begin + g_oCacic.setCacicPath(strAux); - v_tstrCipherOpened1 := TStrings.Create; - v_tstrCipherOpened1 := CipherOpen(g_oCacic.getCacicPath + 'temp\col_hard.dat'); + v_tstrCipherOpened := TStrings.Create; + v_tstrCipherOpened := CipherOpen(g_oCacic.getCacicPath + g_oCacic.getDatFileName); - Try - v_Debugs := false; - if DirectoryExists(g_oCacic.getCacicPath + 'Temp\Debugs') then - Begin - if (FormatDateTime('ddmmyyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then - Begin - v_Debugs := true; - log_diario('Pasta "' + g_oCacic.getCacicPath + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs'))+' encontrada. DEBUG ativado.'); - End; - End; - Executa_Col_Hard; - Except - SetValorDatMemoria('Col_Hard.nada', 'nada', v_tstrCipherOpened1); - CipherClose(g_oCacic.getCacicPath + 'temp\col_hard.dat', v_tstrCipherOpened1); - End; - End; - End; + v_tstrCipherOpened1 := TStrings.Create; + v_tstrCipherOpened1 := CipherOpen(g_oCacic.getCacicPath + 'temp\col_hard.dat'); + Try + Executa_Col_Hard; + Except + SetValorDatMemoria('Col_Hard.nada', 'nada', v_tstrCipherOpened1); + CipherClose(g_oCacic.getCacicPath + 'temp\col_hard.dat', v_tstrCipherOpened1); + End; + Halt(0); + End; + End; end. diff --git a/col_hard/col_hard.res b/col_hard/col_hard.res index 7bb5e5c..16fbe41 100755 Binary files a/col_hard/col_hard.res and b/col_hard/col_hard.res differ diff --git a/col_moni/col_moni.res b/col_moni/col_moni.res index 87ef5eb..5f7952a 100755 Binary files a/col_moni/col_moni.res and b/col_moni/col_moni.res differ diff --git a/col_patr/col_patr.res b/col_patr/col_patr.res index 8c67d21..89c6d3a 100755 Binary files a/col_patr/col_patr.res and b/col_patr/col_patr.res differ diff --git a/col_soft/col_soft.dpr b/col_soft/col_soft.dpr index 6b172d9..c535eff 100755 --- a/col_soft/col_soft.dpr +++ b/col_soft/col_soft.dpr @@ -480,12 +480,15 @@ end; procedure Executa_Col_Soft; var te_versao_mozilla, te_versao_ie, te_versao_jre, te_versao_acrobat_reader, - UVC,ValorChaveRegistro, te_inventario_softwares, te_variaveis_ambiente : String; + UVC,ValorChaveRegistro, te_inventario_softwares, te_variaveis_ambiente, + strDisplayName, + strKeyName : String; InfoSoft, v_Report : TStringList; i : integer; v_SOFTWARE : TMiTeC_Software; v_ENGINES : TMiTeC_Engines; v_OS : TMiTeC_OperatingSystem; + registrySoftwares : TRegistry; begin Try log_diario('Coletando informações de Softwares Básicos.'); @@ -495,44 +498,112 @@ begin te_versao_jre := GetVersaoJRE; te_versao_acrobat_reader := GetVersaoAcrobatReader; te_inventario_softwares := ''; + InfoSoft := TStringList.Create; - Try - InfoSoft := TStringList.Create; - v_SOFTWARE := TMiTeC_Software.Create(nil); - v_SOFTWARE.RefreshData; - MSI_XML_Reports.Software_XML_Report(v_SOFTWARE,true,InfoSoft); + if not g_oCacic.isWindowsGEVista then + Begin + Try + v_SOFTWARE := TMiTeC_Software.Create(nil); + v_SOFTWARE.RefreshData; + MSI_XML_Reports.Software_XML_Report(v_SOFTWARE,true,InfoSoft); + + // Caso exista a pasta ..temp/debugs, será criado o arquivo diário debug_.txt + // Usar esse recurso apenas para debug de coletas mal-sucedidas através do componente MSI-Mitec. + if v_Debugs then + Begin + v_Report := TStringList.Create; - // Caso exista a pasta ..temp/debugs, será criado o arquivo diário debug_.txt - // Usar esse recurso apenas para debug de coletas mal-sucedidas através do componente MSI-Mitec. - if v_Debugs then - Begin - v_Report := TStringList.Create; + MSI_XML_Reports.Software_XML_Report(v_SOFTWARE,true,v_Report); + v_SOFTWARE.Free; - MSI_XML_Reports.Software_XML_Report(v_SOFTWARE,true,v_Report); - v_SOFTWARE.Free; + v_OS := TMiTeC_OperatingSystem.Create(nil); + v_OS.RefreshData; - v_OS := TMiTeC_OperatingSystem.Create(nil); - v_OS.RefreshData; + MSI_XML_Reports.OperatingSystem_XML_Report(v_OS,true,v_Report); + v_OS.Free; + End - MSI_XML_Reports.OperatingSystem_XML_Report(v_OS,true,v_Report); - v_OS.Free; - End + except + log_diario('Problema em Software Report!'); + end; - except - log_diario('Problema em Software Report!'); - end; + for i := 0 to v_SOFTWARE.Count - 1 do + begin + if (trim(Copy(InfoSoft[i],1,14))='
',InfoSoft[i])-16); + End; + end; + + v_SOFTWARE.Free; + end + else + Begin + // Chave para 64Bits + strKeyName := 'Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'; + + registrySoftwares := TRegistry.Create; + with registrySoftwares do + begin + RootKey:=HKEY_LOCAL_MACHINE; + if OpenKey(strKeyName,False)=True then GetKeyNames(InfoSoft); + CloseKey; + + for i:=0 to InfoSoft.Count-1 do + begin + RootKey:=HKEY_LOCAL_MACHINE; + OpenKey(strKeyName + '\'+InfoSoft[i],False); + strDisplayName := ReadString('DisplayName'); + if (strDisplayName <> '') then + Begin + if (Copy(strDisplayName,1,1)='{') then + begin + OpenKey(strKeyName + '\'+InfoSoft[i]+'\'+strDisplayName,False); + strDisplayName := ReadString('DisplayName'); + end; + + if (te_inventario_softwares <> '') then + te_inventario_softwares := te_inventario_softwares + '#'; + te_inventario_softwares := te_inventario_softwares + strDisplayName; + end; + CloseKey; + end; + end; + + // Caso a consulta acima tenha retornado vazio, tentarei a chave para 32Bits + strKeyName := 'Software\Microsoft\Windows\CurrentVersion\Uninstall'; - for i := 0 to v_SOFTWARE.Count - 1 do - begin - if (trim(Copy(InfoSoft[i],1,14))='
'') then Begin + if (Copy(strDisplayName,1,1)='{') then + begin + OpenKey(strKeyName + '\'+InfoSoft[i]+'\'+strDisplayName,False); + strDisplayName := ReadString('DisplayName'); + end; + if (te_inventario_softwares <> '') then - te_inventario_softwares := te_inventario_softwares + '#'; - te_inventario_softwares := te_inventario_softwares + Copy(InfoSoft[i],16,Pos('">',InfoSoft[i])-16); - End; - end; + te_inventario_softwares := te_inventario_softwares + '#'; + te_inventario_softwares := te_inventario_softwares + strDisplayName; + end; + CloseKey; + end; + end; - v_SOFTWARE.Free; + // + end; try te_inventario_softwares := AnsiToAscii(te_inventario_softwares); diff --git a/col_soft/col_soft.res b/col_soft/col_soft.res index 7663320..b2516e9 100755 Binary files a/col_soft/col_soft.res and b/col_soft/col_soft.res differ diff --git a/col_undi/col_undi.res b/col_undi/col_undi.res index 9647af1..52bfc72 100755 Binary files a/col_undi/col_undi.res and b/col_undi/col_undi.res differ diff --git a/frmsenha.dfm b/frmsenha.dfm index b7e60b0..7ce2d09 100755 --- a/frmsenha.dfm +++ b/frmsenha.dfm @@ -1,6 +1,6 @@ object formSenha: TformSenha - Left = 152 - Top = 110 + Left = 361 + Top = 279 BorderIcons = [biSystemMenu] BorderStyle = bsDialog Caption = 'Senha' diff --git a/ger_cols/ger_cols.dpr b/ger_cols/ger_cols.dpr index 8b6475d..3bd24b5 100755 --- a/ger_cols/ger_cols.dpr +++ b/ger_cols/ger_cols.dpr @@ -56,6 +56,7 @@ var v_Endereco_Servidor, v_Aux, strAux, + strUSBinfo, endereco_servidor_cacic, v_ModulosOpcoes, v_ResultCompress, @@ -328,6 +329,7 @@ var v_strCipherOpenImploded, v_DatFileDebug : TextFile; v_cs_cipher : boolean; begin + log_DEBUG('CipherClose: datFileName="' + g_oCacic.getDatFileName + '"'); try FileSetAttr (p_DatFileName,0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000 AssignFile(v_DatFile,p_DatFileName); {Associa o arquivo a uma variável do tipo TextFile} @@ -347,6 +349,7 @@ begin {$IOChecks on} Append(v_DatFileDebug); End; + log_DEBUG('CipherClose: separatorKey="' + g_oCacic.getSeparatorKey + '"'); v_strCipherOpenImploded := g_oCacic.implode(p_tstrCipherOpened,g_oCacic.getSeparatorKey); @@ -2277,10 +2280,10 @@ Begin SetValorDatMemoria('Configs.te_palavra_chave',strAux, v_tstrCipherOpened); // Verifico se srCACIC está em execução e em caso positivo entrego a chave atualizada - Matar(g_oCacic.getCacicPath+'Temp\','aguarde_SRCACIC.txt'); - sleep(2000); - if (FileExists(g_oCacic.getCacicPath + 'Temp\aguarde_SRCACIC.txt')) then - Begin + //Matar(g_oCacic.getCacicPath+'Temp\','aguarde_SRCACIC.txt'); + //sleep(2000); + //if (FileExists(g_oCacic.getCacicPath + 'Temp\aguarde_SRCACIC.txt')) then + // Begin // Alguns cuidados necessários ao tráfego e recepção de valores pelo Gerente WEB // Some cares about send and receive at Gerente WEB v_Aux := StringReplace(strAux ,' ' ,'' ,[rfReplaceAll]); @@ -2296,7 +2299,7 @@ Begin Append(v_txtCookie); Writeln(v_txtCookie,v_Aux); CloseFile(v_txtCookie); - End; + // End; Request_SVG.Values['te_palavra_chave'] := g_oCacic.enCrypt(strAux); @@ -2495,7 +2498,8 @@ Begin end; procedure Executa_Ger_Cols; -var strDtHrColetaForcada, +var strRetorno, + strDtHrColetaForcada, strDtHrUltimaColeta : String; Begin Try @@ -2505,6 +2509,7 @@ Begin // /coletas => Chamada para ativação das coletas // /recuperaSR => Chamada para tentativa de recuperação do módulo srCACIC // /patrimonio => Chamada para ativação do Formulário de Patrimônio + // USBinfo => Informação sobre dispositivo USB inserido/removido // UpdatePrincipal => Atualização do Agente Principal // Chamada com parâmetros pelo chkcacic.exe ou linha de comando // Chamada efetuada pelo Cacic2.exe quando da existência de temp\cacic2.exe para AutoUpdate @@ -2552,6 +2557,34 @@ Begin Sair; End; + strUSBinfo := ''; + + // Chamada com informação de dispositivo USB inserido/removido + For intAux := 1 to ParamCount do + If LowerCase(Copy(ParamStr(intAux),1,9)) = '/usbinfo=' then + strUSBinfo := Trim(Copy(ParamStr(intAux),10,Length((ParamStr(intAux))))); + + // Envio da informação sobre o dispositivo USB ao Gerente WEB + if (strUSBinfo <> '') then + begin + log_DEBUG('Parâmetro USBinfo recebido: "'+strUSBinfo+'"'); + v_acao_gercols := 'Informando ao Gerente WEB sobre dispositivo USB inserido/removido.'; + + ChecaCipher; + ChecaCompress; + + Request_Ger_Cols := TStringList.Create; + log_DEBUG('Preparando para criptografar "'+strUSBinfo+'"'); + Request_Ger_Cols.Values['te_usb_info'] := StringReplace(g_oCacic.enCrypt(strUSBinfo),'+','',[rfReplaceAll]); + log_DEBUG('Preparando para empacotar "'+Request_Ger_Cols.Values['te_usb_info']+'"'); + strRetorno := ComunicaServidor('set_usbinfo.php', Request_Ger_Cols, '>> Enviando informações sobre ' + IfThen(Copy(strUSBinfo,1,1)='I','Inserção','Remoção')+ ' de dispositivo USB ao Gerente WEB!'); + if (g_oCacic.deCrypt(XML_RetornaValor('nm_device', strRetorno)) <> '') then + log_diario('Dispositivo USB ' + IfThen(Copy(strUSBinfo,1,1)='I','Inserido','Removido')+': "' + g_oCacic.deCrypt(XML_RetornaValor('nm_device', strRetorno)+'"')+'"'); + Request_Ger_Cols.Free; + + Finalizar(true); + end; + For intAux := 1 to ParamCount do Begin if LowerCase(Copy(ParamStr(intAux),1,15)) = '/ip_serv_cacic=' then @@ -2656,7 +2689,9 @@ Begin Finalizar(false); Sair; End; - End; + End + else + log_Diario('Indicador CS_AUTO_UPDATE="N". O recomendado é que esteja em "S" no Gerente WEB!'); if ((GetValorDatMemoria('Configs.CS_COLETA_HARDWARE' , v_tstrCipherOpened) = 'S') or (GetValorDatMemoria('Configs.CS_COLETA_SOFTWARE' , v_tstrCipherOpened) = 'S') or @@ -3272,15 +3307,28 @@ Begin // g_oCacic.Free; End; +procedure CriaCookie; +Begin + // A existência e bloqueio do arquivo abaixo evitará que Cacic2.exe chame o Ger_Cols quando este estiver em funcionamento + AssignFile(v_Aguarde,g_oCacic.getCacicPath + 'temp\aguarde_GER.txt'); {Associa o arquivo a uma variável do tipo TextFile} + {$IOChecks off} + Reset(v_Aguarde); {Abre o arquivo texto} + {$IOChecks on} + if (IOResult <> 0) then // Arquivo não existe, será recriado. + Rewrite (v_Aguarde); + + Append(v_Aguarde); + Writeln(v_Aguarde,'Apenas um pseudo-cookie para o Cacic2 esperar o término de Ger_Cols'); + Append(v_Aguarde); +End; + begin g_oCacic := TCACIC.Create(); - if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) ) then begin if ParamCount > 0 then Begin strAux := ''; - For intAux := 1 to ParamCount do Begin if (LowerCase(Copy(ParamStr(intAux),1,11)) = '/cacicpath=') then @@ -3322,18 +3370,8 @@ begin log_DEBUG('Te_So obtido: "' + g_oCacic.getWindowsStrId() +'"'); 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 - AssignFile(v_Aguarde,g_oCacic.getCacicPath + 'temp\aguarde_GER.txt'); {Associa o arquivo a uma variável do tipo TextFile} - {$IOChecks off} - Reset(v_Aguarde); {Abre o arquivo texto} - {$IOChecks on} - if (IOResult <> 0) then // Arquivo não existe, será recriado. - Rewrite (v_Aguarde); - - Append(v_Aguarde); - Writeln(v_Aguarde,'Apenas um pseudo-cookie para o Cacic2 esperar o término de Ger_Cols'); - Append(v_Aguarde); + CriaCookie; ChecaCipher; ChecaCompress; diff --git a/ger_cols/ger_cols.res b/ger_cols/ger_cols.res index f065286..39ad3ac 100755 Binary files a/ger_cols/ger_cols.res and b/ger_cols/ger_cols.res differ diff --git a/ini_cols/ini_cols.dpr b/ini_cols/ini_cols.dpr index d0a64a1..35486cb 100755 --- a/ini_cols/ini_cols.dpr +++ b/ini_cols/ini_cols.dpr @@ -324,6 +324,7 @@ begin log_DEBUG('Chamando "' + v_tstrModuloOpcao[0]+'.exe " /p_Option='+v_tstrModuloOpcao[2]); g_oCacic.createSampleProcess( g_oCacic.getCacicPath + '\modulos\' + strAux, CACIC_PROCESS_WAIT ); + Sleep(500); End; except end; diff --git a/ini_cols/ini_cols.res b/ini_cols/ini_cols.res index 28d6124..c01ceef 100755 Binary files a/ini_cols/ini_cols.res and b/ini_cols/ini_cols.res differ diff --git a/main.dfm b/main.dfm index 3f1eab6..f4e5450 100755 --- a/main.dfm +++ b/main.dfm @@ -1,6 +1,6 @@ object FormularioGeral: TFormularioGeral - Left = 301 - Top = 108 + Left = 300 + Top = 107 HorzScrollBar.Visible = False VertScrollBar.Visible = False BiDiMode = bdLeftToRight @@ -155,7 +155,7 @@ object FormularioGeral: TFormularioGeral Height = 16 BevelInner = bvLowered BevelOuter = bvLowered - Caption = 'v. 2.4.0.xxx' + Caption = 'v. 2.6.0.xxx' Color = clBackground Font.Charset = DEFAULT_CHARSET Font.Color = clWhite diff --git a/main.pas b/main.pas index 3698921..447c157 100755 --- a/main.pas +++ b/main.pas @@ -39,7 +39,8 @@ uses Buttons, CACIC_Library, ImgList, - Graphics; + Graphics, + USBdetectClass; //IdTCPServer; //IdFTPServer; @@ -211,9 +212,12 @@ type procedure Popup_Menu_ContextoPopup(Sender: TObject); procedure Timer_InicializaTrayTimer(Sender: TObject); private + FUsb : TUsbClass; ShutdownEmExecucao : Boolean; IsMenuOpen : Boolean; NotifyStruc : TNotifyIconData; {Estrutura do tray icon} + procedure UsbIN(ASender : TObject; const ADevType,AVendorID,ADeviceID : string); + procedure UsbOUT(ASender : TObject; const ADevType,AVendorID,ADeviceID : string); procedure InicializaTray; procedure Finaliza; procedure VerificaDebugs; @@ -221,7 +225,7 @@ type Function RetornaValorVetorUON1(id1 : string) : String; Function RetornaValorVetorUON1a(id1a : string) : String; Function RetornaValorVetorUON2(id2, idLocal: string) : String; - procedure Invoca_GerCols(p_acao:string); + procedure Invoca_GerCols(p_acao:string; boolShowInfo : Boolean = true); function GetVersionInfo(p_File: string):string; function VerFmt(const MS, LS: DWORD): string; procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; @@ -327,6 +331,29 @@ begin end; inherited; end; + +// Início de Procedimentos para monitoramento de dispositivos USB - Anderson Peterle - 02/2010 +procedure TFormularioGeral.UsbIN(ASender : TObject; const ADevType,AVendorID,ADeviceID : string); +begin + // Envio de valores ao Gerente WEB + // Formato: USBinfo=I_ddmmyyyyhhnnss_ADeviceID + // Os valores serão armazenados localmente (cacic2.dat) se for impossível o envio. + Log_Debug('<< USB INSERIDO .:. Vendor ID => ' + AVendorID + ' .:. Device ID = ' + ADeviceID); + Invoca_GerCols('USBinfo=I_'+FormatDateTime('yyyymmddhhnnss', now) + '_' + AVendorID + '_' + ADeviceID,false); +end; + + +procedure TFormularioGeral.UsbOUT(ASender : TObject; const ADevType,AVendorID,ADeviceID : string); +begin + // Envio de valores ao Gerente WEB + // Formato: USBinfo=O_ddmmyyyyhhnnss_ADeviceID + // Os valores serão armazenados localmente (cacic2.dat) se for impossível o envio. + Log_Debug('>> USB REMOVIDO .:. Vendor ID => ' + AVendorID + ' .:. Device ID = ' + ADeviceID); + Invoca_GerCols('USBinfo=O_'+FormatDateTime('yyyymmddhhnnss', now) + '_' + AVendorID + '_' + ADeviceID,false); +end; + +// Fim de Procedimentos para monitoramento de dispositivos USB - Anderson Peterle - 02/2010 + procedure TFormularioGeral.MontaVetoresPatrimonio(p_strConfigs : String); var Parser : TXmlParser; i : integer; @@ -1231,6 +1258,11 @@ var strAux, v_SystemDrive : TStrings; begin + // Criação do objeto para monitoramento de dispositivos USB + FUsb := TUsbClass.Create; + FUsb.OnUsbInsertion := UsbIN; + FUsb.OnUsbRemoval := UsbOUT; + // Essas variáveis ajudarão a controlar o redesenho do ícone no systray, // evitando o "roubo" do foco. g_intTaskBarAtual := 0; @@ -1516,6 +1548,7 @@ Begin log_diario('PROBLEMAS NA FINALIZAÇÃO'); End; g_oCacic.Free; + FreeAndNil(FUsb); FreeMemory(0); Application.Terminate; End; @@ -1527,7 +1560,7 @@ begin If (getValorDatMemoria('Configs.SJI',v_tstrCipherOpened) = 'S') Then Finaliza; end; -procedure TFormularioGeral.Invoca_GerCols(p_acao:string); +procedure TFormularioGeral.Invoca_GerCols(p_acao:string; boolShowInfo : Boolean = true); begin Matar(g_oCacic.getCacicPath + 'temp\','*.txt'); Matar(g_oCacic.getCacicPath + 'temp\','*.ini'); @@ -1535,12 +1568,17 @@ begin // Caso exista o Gerente de Coletas será verificada a versão e excluída caso antiga(Uma forma de ação pró-ativa) if ChecaGERCOLS then Begin + Timer_InicializaTray.Enabled := False; ChecaCONFIGS; CipherClose; - log_diario('Invocando Gerente de Coletas com ação: "'+p_acao+'"'); + if boolShowInfo then + log_diario('Invocando Gerente de Coletas com ação: "'+p_acao+'"') + else + log_DEBUG('Invocando Gerente de Coletas com ação: "'+p_acao+'"'); Timer_Nu_Exec_Apos.Enabled := False; - Log_DEBUG('Criando Processo Ger_Cols...'); + Log_DEBUG('Criando Processo Ger_Cols => "'+g_oCacic.getCacicPath + 'modulos\GER_COLS.EXE /'+p_acao+' /CacicPath='+g_oCacic.getCacicPath+'"'); g_oCacic.createSampleProcess(g_oCacic.getCacicPath + 'modulos\GER_COLS.EXE /'+p_acao+' /CacicPath='+g_oCacic.getCacicPath,false,SW_HIDE); + Timer_InicializaTray.Enabled := True; End else log_diario('Não foi possível invocar o Gerente de Coletas!'); @@ -2001,6 +2039,7 @@ procedure TFormularioGeral.WMQueryEndSession(var Msg: TWMQueryEndSession); begin // Quando há um shutdown do windows em execução, libera o close. OnCloseQuery := Nil; + FreeAndNil(FUsb); Application.Terminate; inherited // Continue ShutDown request end; @@ -2451,6 +2490,8 @@ begin // Alguns cuidados necessários ao tráfego e recepção de valores pelo Gerente WEB // Some cares about send and receive at Gerente WEB + // A partir da versão 2.6.0.2 deixo de enviar a palavra chave para que o srCACICsrv busque-a diretamente de cacic2.dat + { v_strPalavraChave := FormularioGeral.getValorDatMemoria('Configs.te_palavra_chave', v_tstrCipherOpened); v_strPalavraChave := StringReplace(v_strPalavraChave,' ' ,'' ,[rfReplaceAll]); v_strPalavraChave := StringReplace(v_strPalavraChave,'"' ,'' ,[rfReplaceAll]); @@ -2458,6 +2499,7 @@ begin v_strPalavraChave := StringReplace(v_strPalavraChave,'\' ,'' ,[rfReplaceAll]); v_strPalavraChave := g_oCacic.enCrypt(v_strPalavraChave); v_strPalavraChave := StringReplace(v_strPalavraChave,'+','',[rfReplaceAll]); + } v_strTeSO := trim(StringReplace(FormularioGeral.getValorDatMemoria('Configs.TE_SO', v_tstrCipherOpened),' ','',[rfReplaceAll])); v_strTeSO := g_oCacic.enCrypt(v_strTeSO); @@ -2500,8 +2542,8 @@ begin '[' + g_oCacic.enCrypt(FormularioGeral.getValorDatMemoria('Configs.Endereco_WS' , v_tstrCipherOpened)) + ']' + '[' + v_strTeSO + ']' + '[' + v_strTeNodeAddress + ']' + - '[' + v_strPalavraChave + ']' + - '[' + g_oCacic.getCacicPath + 'Temp\' + ']' + +// '[' + v_strPalavraChave + ']' + + '[' + g_oCacic.getCacicPath + ']' + '[' + v_strNuPortaSR + ']' + '[' + v_strNuTimeOutSR + ']'); @@ -2515,8 +2557,8 @@ begin '[' + g_oCacic.enCrypt(FormularioGeral.getValorDatMemoria('Configs.Endereco_WS' , v_tstrCipherOpened)) + ']' + '[' + v_strTeSO + ']' + '[' + v_strTeNodeAddress + ']' + - '[' + v_strPalavraChave + ']' + - '[' + g_oCacic.getCacicPath + 'Temp\' + ']' + +// '[' + v_strPalavraChave + ']' + + '[' + g_oCacic.getCacicPath + ']' + '[' + v_strNuPortaSR + ']' + '[' + v_strNuTimeOutSR + ']',false,SW_NORMAL); BoolServerON := true; diff --git a/mapa/mapacacic.res b/mapa/mapacacic.res index c58aad5..3e76b05 100755 Binary files a/mapa/mapacacic.res and b/mapa/mapacacic.res differ diff --git a/testacrypt/main_testacrypt.pas b/testacrypt/main_testacrypt.pas index f9a0e5b..c8fff80 100755 --- a/testacrypt/main_testacrypt.pas +++ b/testacrypt/main_testacrypt.pas @@ -99,9 +99,11 @@ implementation procedure TForm1.CriptografaPalavra; Begin if (trim(form1.Edit_FraseOriginal.Text)<>'') then - Form1.Edit_FraseCriptografadaEnviadaEstacao.Text := g_oCacic.enCrypt(trim(form1.Edit_FraseOriginal.Text)) - else if (trim(form1.Edit_FraseCriptografadaEnviadaEstacao.Text)<>'') then - Form1.Edit_FraseOriginal.Text := g_oCacic.deCrypt(trim(form1.Edit_FraseCriptografadaEnviadaEstacao.Text)); + Begin + Form1.Edit_FraseCriptografadaEnviadaEstacao.Text := g_oCacic.enCrypt(trim(form1.Edit_FraseOriginal.Text)) + //else if (trim(form1.Edit_FraseCriptografadaEnviadaEstacao.Text)<>'') then + // Form1.Edit_FraseOriginal.Text := g_oCacic.deCrypt(trim(form1.Edit_FraseCriptografadaEnviadaEstacao.Text)); + end; End; procedure TForm1.Button_EfetuaTesteClick(Sender: TObject); @@ -114,111 +116,113 @@ var v_retorno, IdHTTP1: TIdHTTP; intAux : integer; begin - - boolProcessaPausa := true; -// InicializaCampos; - CriptografaPalavra; - - intAux := POS('255.255.255.255',Edit_ScriptPath.Text); - if (intAux > 0) then - Begin - StatusBar_Mensagens.Panels[0].Text := 'ATENÇÃO: Caso não seja um teste local, informe um endereço válido.'; - StatusBar_Mensagens.Color := clYellow; - Edit_ScriptPath.SetFocus; - End - else + if (Trim(Edit_FraseCriptografadaEnviadaEstacao.Text) <> '') then Begin + boolProcessaPausa := true; + // InicializaCampos; + CriptografaPalavra; - Request_Config := TStringList.Create; - Request_Config.Values['cs_operacao'] := 'TestaCrypt'; - Request_Config.Values['cs_cipher'] := '1'; - Request_Config.Values['te_CipheredText'] := trim(Form1.Edit_FraseCriptografadaEnviadaEstacao.Text); - Response_Config := TStringStream.Create(''); - - Try - idHTTP1 := TIdHTTP.Create(nil); - idHTTP1.AllowCookies := true; - idHTTP1.ASCIIFilter := false; - idHTTP1.AuthRetries := 1; - idHTTP1.BoundPort := 0; - idHTTP1.HandleRedirects := false; - idHTTP1.ProxyParams.BasicAuthentication := false; - idHTTP1.ProxyParams.ProxyPort := 0; - idHTTP1.ReadTimeout := 0; - idHTTP1.RecvBufferSize := 32768; - idHTTP1.RedirectMaximum := 15; - idHTTP1.Request.Accept := 'text/html, */*'; - idHTTP1.Request.BasicAuthentication := true; - idHTTP1.Request.ContentLength := -1; - idHTTP1.Request.ContentRangeStart := 0; - idHTTP1.Request.ContentRangeEnd := 0; - idHTTP1.Request.ContentType := 'text/html'; - idHTTP1.SendBufferSize := 32768; - idHTTP1.Tag := 0; - - Form1.StatusBar_Mensagens.Panels[0].Text := 'Fazendo comunicação com "'+form1.Edit_ScriptPath.Text+'"'; - Sleep(1000); - Form1.StatusBar_Mensagens.Panels[0].Text := ''; - - IdHTTP1.Post(trim(Form1.Edit_ScriptPath.Text), Request_Config, Response_Config); - - //ShowMessage('Retorno: '+Response_Config.DataString); - idHTTP1.Free; - v_retorno := Response_Config.DataString; - v_Status := XML_RetornaValor('STATUS',v_retorno); - Except + intAux := POS('255.255.255.255',Edit_ScriptPath.Text); + if (intAux > 0) then Begin - Form1.StatusBar_Mensagens.Panels[0].Text := 'Problemas na comunicação...'; - Sleep(1000); - Form1.StatusBar_Mensagens.Panels[0].Text := ''; - End; - End; - Request_Config.Free; - Response_Config.Free; - - if (v_Status <> '') then + StatusBar_Mensagens.Panels[0].Text := 'ATENÇÃO: Caso não seja um teste local, informe um endereço válido.'; + StatusBar_Mensagens.Color := clYellow; + Edit_ScriptPath.SetFocus; + End + else Begin - v_strAux := XML_RetornaValor('UnCipheredText',v_retorno); - form1.Edit_IVServer.Text := XML_RetornaValor('IVServer',v_retorno); - form1.Edit_CipherKeyServer.Text := XML_RetornaValor('CipherKeyServer',v_retorno); - form1.Edit_FraseCriptografadaRecebidaServidor.Text := XML_RetornaValor('CipheredTextRecepted',v_retorno); - form1.Edit_OperacaoRecebidaServidor.Text := XML_RetornaValor('CS_OPERACAO',v_retorno); - if (v_strAux <> '') then + + Request_Config := TStringList.Create; + Request_Config.Values['cs_operacao'] := 'TestaCrypt'; + Request_Config.Values['cs_cipher'] := '1'; + Request_Config.Values['te_CipheredText'] := trim(Form1.Edit_FraseCriptografadaEnviadaEstacao.Text); + Response_Config := TStringStream.Create(''); + + Try + idHTTP1 := TIdHTTP.Create(nil); + idHTTP1.AllowCookies := true; + idHTTP1.ASCIIFilter := false; + idHTTP1.AuthRetries := 1; + idHTTP1.BoundPort := 0; + idHTTP1.HandleRedirects := false; + idHTTP1.ProxyParams.BasicAuthentication := false; + idHTTP1.ProxyParams.ProxyPort := 0; + idHTTP1.ReadTimeout := 0; + idHTTP1.RecvBufferSize := 32768; + idHTTP1.RedirectMaximum := 15; + idHTTP1.Request.Accept := 'text/html, */*'; + idHTTP1.Request.BasicAuthentication := true; + idHTTP1.Request.ContentLength := -1; + idHTTP1.Request.ContentRangeStart := 0; + idHTTP1.Request.ContentRangeEnd := 0; + idHTTP1.Request.ContentType := 'text/html'; + idHTTP1.SendBufferSize := 32768; + idHTTP1.Tag := 0; + + Form1.StatusBar_Mensagens.Panels[0].Text := 'Fazendo comunicação com "'+form1.Edit_ScriptPath.Text+'"'; + Sleep(1000); + Form1.StatusBar_Mensagens.Panels[0].Text := ''; + + IdHTTP1.Post(trim(Form1.Edit_ScriptPath.Text), Request_Config, Response_Config); + + //ShowMessage('Retorno: '+Response_Config.DataString); + idHTTP1.Free; + v_retorno := Response_Config.DataString; + v_Status := XML_RetornaValor('STATUS',v_retorno); + Except Begin - form1.Edit_FraseDecriptografadaDevolvidaServidor.Text := v_strAux; - if (trim(form1.Edit_FraseDecriptografadaDevolvidaServidor.Text) <> trim(form1.Edit_FraseOriginal.Text)) then + Form1.StatusBar_Mensagens.Panels[0].Text := 'Problemas na comunicação...'; + Sleep(1000); + Form1.StatusBar_Mensagens.Panels[0].Text := ''; + End; + End; + Request_Config.Free; + Response_Config.Free; + + if (v_Status <> '') then + Begin + v_strAux := XML_RetornaValor('UnCipheredText',v_retorno); + form1.Edit_IVServer.Text := XML_RetornaValor('IVServer',v_retorno); + form1.Edit_CipherKeyServer.Text := XML_RetornaValor('CipherKeyServer',v_retorno); + form1.Edit_FraseCriptografadaRecebidaServidor.Text := XML_RetornaValor('CipheredTextRecepted',v_retorno); + form1.Edit_OperacaoRecebidaServidor.Text := XML_RetornaValor('CS_OPERACAO',v_retorno); + if (v_strAux <> '') then Begin - form1.Edit_FraseDecriptografadaDevolvidaServidor.Font.Color := clRed; - if (Edit_CipherKeyStation.Text <> Edit_CipherKeyServer.Text) then + form1.Edit_FraseDecriptografadaDevolvidaServidor.Text := v_strAux; + if (trim(form1.Edit_FraseDecriptografadaDevolvidaServidor.Text) <> trim(form1.Edit_FraseOriginal.Text)) then Begin - Edit_CipherKeyStation.Color := clYellow; - Edit_CipherKeyServer.Color := clYellow; - End; - if (Edit_IVStation.Text <> Edit_IVServer.Text) then - Begin - Edit_IVStation.Color := clYellow; - Edit_IVServer.Color := clYellow; - End; - + form1.Edit_FraseDecriptografadaDevolvidaServidor.Font.Color := clRed; + if (Edit_CipherKeyStation.Text <> Edit_CipherKeyServer.Text) then + Begin + Edit_CipherKeyStation.Color := clYellow; + Edit_CipherKeyServer.Color := clYellow; + End; + if (Edit_IVStation.Text <> Edit_IVServer.Text) then + Begin + Edit_IVStation.Color := clYellow; + Edit_IVServer.Color := clYellow; + End; + + End + else + form1.Edit_FraseDecriptografadaDevolvidaServidor.Font.Color := clBlue; End else - form1.Edit_FraseDecriptografadaDevolvidaServidor.Font.Color := clBlue; + Begin + form1.Edit_FraseDecriptografadaDevolvidaServidor.Text := 'NÃO FOI POSSÍVEL DECRIPTOGRAFAR!!!'; + form1.Edit_FraseDecriptografadaDevolvidaServidor.Font.Style := [fsBold]; + form1.Edit_FraseDecriptografadaDevolvidaServidor.Font.Color := clRed; + End; + Form1.StatusBar_Mensagens.Panels[0].Text := 'Teste Concluído!'; End else Begin - form1.Edit_FraseDecriptografadaDevolvidaServidor.Text := 'NÃO FOI POSSÍVEL DECRIPTOGRAFAR!!!'; - form1.Edit_FraseDecriptografadaDevolvidaServidor.Font.Style := [fsBold]; - form1.Edit_FraseDecriptografadaDevolvidaServidor.Font.Color := clRed; + Form1.StatusBar_Mensagens.Panels[0].Text := 'Problemas na comunicação...'; + Sleep(1000); + Form1.StatusBar_Mensagens.Panels[0].Text := ''; End; - Form1.StatusBar_Mensagens.Panels[0].Text := 'Teste Concluído!'; - End - else - Begin - Form1.StatusBar_Mensagens.Panels[0].Text := 'Problemas na comunicação...'; - Sleep(1000); - Form1.StatusBar_Mensagens.Panels[0].Text := ''; End; - End; + end; end; // Pad a string with zeros so that it is a multiple of size function TForm1.PadWithZeros(const str : string; size : integer) : string; -- libgit2 0.21.2