Commit 4c2a85c754b2216e0640f11337510c142ed8255f

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

Adequacoes ao uso de library unica, pequenas correcoes e faxina de codigo.

git-svn-id: http://svn.softwarepublico.gov.br/svn/cacic/cacic/trunk/agente-windows@762 fecfc0c7-e812-0410-ae72-849f08638ee7
cacicservice/CACICsvc.dpr
... ... @@ -18,8 +18,8 @@ program CACICsvc;
18 18  
19 19 uses
20 20 SvcMgr,
21   - CACICsvcMain in 'CACICsvcMain.pas' {CACICservice: TService};
22   -
  21 + CACICsvcMain in 'CACICsvcMain.pas' {CACICservice: TService},
  22 + CACIC_Library in '..\CACIC_Library.pas';
23 23 {$R *.RES}
24 24  
25 25 begin
... ...
cacicservice/CACICsvcMain.pas
... ... @@ -18,17 +18,19 @@ unit CACICsvcMain;
18 18  
19 19 interface
20 20  
21   -uses Windows,
22   - Messages,
23   - SysUtils,
24   - Classes,
25   - SvcMgr,
26   - strUtils,
27   - ExtCtrls;
28   -
29   -var strHomeDrive,
30   - strCacicDir : String;
31   - boolStarted : boolean;
  21 +uses
  22 + Windows,
  23 + Messages,
  24 + SysUtils,
  25 + Classes,
  26 + SvcMgr,
  27 + strUtils,
  28 + ExtCtrls,
  29 + CACIC_Library;
  30 +
  31 +var
  32 + boolStarted : boolean;
  33 + g_oCacic : TCACIC;
32 34  
33 35 type
34 36 TCACICservice = class(TService)
... ... @@ -41,9 +43,7 @@ type
41 43 private
42 44  
43 45 { Internal Start & Stop methods }
44   - function HomeDrive : string;
45 46 function GetValorChaveRegIni(p_Secao, p_Chave, p_File : String): String;
46   - function GetAppPath: String;
47 47 procedure doSaveLog(Msg : String);
48 48 Procedure WMEndSession(var Msg : TWMEndSession) ; message WM_ENDSESSION;
49 49 procedure ExecutaCACIC;
... ... @@ -66,6 +66,7 @@ begin
66 66 inherited;
67 67 Application.Free;
68 68 end;
  69 +
69 70 // Funções Auxiliares
70 71 function TCACICservice.GetValorChaveRegIni(p_Secao, p_Chave, p_File : String): String;
71 72 //Para buscar do Arquivo INI...
... ... @@ -105,40 +106,11 @@ var
105 106 end;
106 107 end;
107 108  
108   -function TCACICservice.GetAppPath: String;
109   -Var
110   - Test : String;
111   - Res : Longint;
112   - CurSize : Longint;
113   -begin
114   - CurSize := 1024;
115   - SetLength(Test, CurSize);
116   - Res := GetModuleFilename(GetModuleHandle(nil), PChar(test), CurSize);
117   - If (res > curSize) then
118   - begin
119   - CurSize := res + 10;
120   - SetLength(Test, CurSize);
121   - Res := GetModuleFilename(GetModuleHandle(nil), PChar(test), CurSize);
122   - end;
123   - Setlength(Test, Res);
124   - test := ExtractFileDir(Test);
125   - if (test[Length(test)] = '\') or (test[Length(test)]='/') then
126   - SetLength(Test, Length(test) - 1);
127   - Result := test;
128   -end;
129   -
130   -function TCACICservice.HomeDrive : string;
131   -var WinDir : array [0..144] of char;
132   -begin
133   - GetWindowsDirectory (WinDir, 144);
134   - Result := StrPas (WinDir);
135   -end;
136   -
137 109 procedure TCACICservice.doSaveLog(Msg : String);
138 110 var fLog: textfile;
139 111 begin
140   - AssignFile(fLog, HomeDrive + '\CACICsvc.log');
141   - if FileExists(HomeDrive + '\CACICsvc.log') then
  112 + AssignFile(fLog, g_oCacic.Windows.getWinDir + 'CACICsvc.log');
  113 + if FileExists(g_oCacic.Windows.getWinDir + 'CACICsvc.log') then
142 114 Append(fLog)
143 115 else
144 116 Rewrite(fLog);
... ... @@ -172,6 +144,7 @@ end;
172 144  
173 145 procedure TCACICservice.ServiceStart(Sender: TService; var Started: Boolean);
174 146 begin
  147 + g_oCacic := TCACIC.Create;
175 148  
176 149 Started := true;
177 150  
... ... @@ -182,36 +155,32 @@ begin
182 155  
183 156 While not Terminated do
184 157 Sleep(250);
185   -
186   -
187 158 end;
188 159  
189 160 procedure TCACICservice.ExecutaCACIC;
190 161 Begin
  162 + g_oCacic.setCacicPath(g_oCacic.getHomeDrive + GetValorChaveRegIni('Cacic2', 'cacic_dir', g_oCacic.getWinDir + 'chksis.ini') + '\');
191 163  
192   - strHomeDrive := MidStr(HomeDrive,1,3); //x:\
193   - strCacicDir := strHomeDrive + GetValorChaveRegIni('Cacic2', 'cacic_dir', GetAppPath + '\chksis.ini');
194   -
195   - DeleteFile(strCacicDir + '\aguarde_CACIC.txt');
  164 + DeleteFile(g_oCacic.getCacicPath + 'aguarde_CACIC.txt');
196 165 Sleep(3000);
197 166  
198 167 // Se o arquivo indicador de execução não existir...
199   - if not (FileExists(strCacicDir + '\aguarde_CACIC.txt')) then
  168 + if not (FileExists(g_oCacic.getCacicPath + 'aguarde_CACIC.txt')) then
200 169 Begin
201 170 // Executo o CHKsis, verificando a estrutura do sistema
202 171 Try
203   - WinEXEC(PChar(HomeDrive + '\chksis.exe'),sw_HIDE);
  172 + WinEXEC(PChar(g_oCacic.getWinDir + 'chksis.exe'),sw_HIDE);
204 173 Except
205 174 End;
206 175  
207   - While not (FileExists(strCacicDir + '\cacic2.exe')) do
  176 + While not (FileExists(g_oCacic.getCacicPath + 'cacic2.exe')) do
208 177 Sleep(5000); // Espero 5 segundos...
209 178 End;
210 179  
211 180  
212 181 // Executo o Agente Principal do CACIC
213 182 Try
214   - WinEXEC(PChar(strCacicDir + '\cacic2.exe'),sw_hide);
  183 + WinEXEC(PChar(g_oCacic.getCacicPath + 'cacic2.exe'),sw_hide);
215 184 Except
216 185 End;
217 186 End;
... ...
chkcacic/chkcacic.dpr
... ... @@ -27,18 +27,18 @@ const
27 27 CACIC_APP_NAME = 'chkcacic';
28 28  
29 29 var
30   - oCacic : TCACIC;
  30 + g_oCacic : TCACIC;
31 31  
32 32 begin
33   - oCacic := TCACIC.Create();
  33 + g_oCacic := TCACIC.Create();
34 34  
35   - if( not oCacic.isAppRunning( CACIC_APP_NAME ) )
  35 + if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) )
36 36 then begin
37 37 Application.Initialize;
38 38 Application.CreateForm(TForm1, Form1);
39 39 Application.Run;
40 40 end;
41 41  
42   - oCacic.Free();
  42 + g_oCacic.Free();
43 43  
44 44 end.
... ...
chkcacic/main.pas
... ... @@ -56,71 +56,56 @@ unit main;
56 56  
57 57 interface
58 58  
59   -uses Windows,
60   - strUtils,
61   - SysUtils,
62   - Classes,
63   - Forms,
64   - Registry,
65   - Inifiles,
66   - idFTPCommon,
67   - XML,
68   - LibXmlParser,
69   - IdHTTP,
70   - PJVersionInfo,
71   - Controls,
72   - StdCtrls,
73   - IdBaseComponent,
74   - IdComponent,
75   - IdTCPConnection,
76   - IdTCPClient,
77   - variants,
78   - DCPcrypt2,
79   - DCPrijndael,
80   - DCPbase64,
81   - NTFileSecurity,
82   - IdFTP,
83   - Tlhelp32,
84   - ExtCtrls,
85   - CACIC_Library,
86   - WinSvc,
87   - dialogs;
88   -
89   -var v_ip_serv_cacic,
90   - v_cacic_dir,
91   - v_te_instala_frase_sucesso,
92   - v_te_instala_frase_insucesso,
93   - v_te_instala_informacoes_extras,
94   - v_exibe_informacoes,
95   - v_versao_local,
96   - v_versao_remota,
97   - v_CipherKey,
98   - v_SeparatorKey,
99   - v_IV,
100   - v_strCipherClosed,
101   - v_strCipherOpened,
102   - v_DatFileName,
103   - v_retorno,
104   - v_versao_REM,
105   - v_versao_LOC,
106   - v_te_so : String;
107   -
108   - v_Debugs : boolean;
109   -
110   -var v_tstrCipherOpened : TStrings;
  59 +uses
  60 + Windows,
  61 + strUtils,
  62 + SysUtils,
  63 + Classes,
  64 + Forms,
  65 + Registry,
  66 + Inifiles,
  67 + idFTPCommon,
  68 + XML,
  69 + LibXmlParser,
  70 + idHTTP,
  71 + PJVersionInfo,
  72 + Controls,
  73 + StdCtrls,
  74 + IdBaseComponent,
  75 + IdComponent,
  76 + IdTCPConnection,
  77 + IdTCPClient,
  78 + variants,
  79 + NTFileSecurity,
  80 + IdFTP,
  81 + Tlhelp32,
  82 + ExtCtrls,
  83 + CACIC_Library,
  84 + WinSvc,
  85 + dialogs;
111 86  
112 87 var
113   - g_oCacic: TCACIC; /// Biblioteca CACIC_Library
  88 + v_ip_serv_cacic,
  89 + v_te_instala_frase_sucesso,
  90 + v_te_instala_frase_insucesso,
  91 + v_te_instala_informacoes_extras,
  92 + v_exibe_informacoes,
  93 + v_versao_local,
  94 + v_versao_remota,
  95 + v_strCipherClosed,
  96 + v_strCipherOpened,
  97 + v_retorno,
  98 + v_versao_REM,
  99 + v_versao_LOC : String;
114 100  
115   -// Constantes a serem usadas pela função IsAdmin...
116   -const constSECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
117   - constSECURITY_BUILTIN_DOMAIN_RID = $00000020;
118   - constDOMAIN_ALIAS_RID_ADMINS = $00000220;
  101 +var
  102 + v_Debugs : boolean;
119 103  
120   -// Some constants that are dependant on the cipher being used
121   -// Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize)
122   -const KeySize = 32; // 32 bytes = 256 bits
123   - BlockSize = 16; // 16 bytes = 128 bits
  104 +var
  105 + v_tstrCipherOpened : TStrings;
  106 +
  107 +var
  108 + g_oCacic: TCACIC; /// Biblioteca CACIC_Library
124 109  
125 110 Procedure chkcacic;
126 111 procedure ComunicaInsucesso(strIndicador : String); //2.2.0.32
... ... @@ -135,7 +120,6 @@ procedure Matar(v_dir,v_files: string); // 2.2.0.16
135 120 Procedure MostraFormConfigura;
136 121  
137 122 Function ChecaVersoesAgentes(p_strNomeAgente : String) : integer; // 2.2.0.16
138   -Function Explode(Texto, Separador : String) : TStrings;
139 123 Function FindWindowByTitle(WindowTitle: string): Hwnd;
140 124 Function FTP(p_Host : String; p_Port : String; p_Username : String; p_Password : String; p_PathServer : String; p_File : String; p_Dest : String) : Boolean;
141 125 function GetFolderDate(Folder: string): TDateTime;
... ... @@ -144,7 +128,6 @@ Function GetRootKey(strRootKey: String): HKEY;
144 128 Function GetValorChaveRegEdit(Chave: String): Variant;
145 129 Function GetValorChaveRegIni(p_Secao, p_Chave, p_File : String): String;
146 130 Function GetVersionInfo(p_File: string):string;
147   -Function HomeDrive : string;
148 131 Function KillTask(ExeFileName: string): Integer;
149 132 Function ListFileDir(Path: string):string;
150 133 function Posso_Rodar_CACIC : boolean;
... ... @@ -167,8 +150,7 @@ type
167 150  
168 151 var
169 152 Form1: TForm1;
170   - Dir, ENDERECO_SERV_CACIC,
171   - v_home_drive : string;
  153 + ENDERECO_SERV_CACIC : string;
172 154 implementation
173 155  
174 156 uses FormConfig;
... ... @@ -315,52 +297,12 @@ begin
315 297 StrDispose(temp);
316 298 end;
317 299  
318   -function IsAdmin: Boolean;
319   -var hAccessToken: THandle;
320   - ptgGroups: PTokenGroups;
321   - dwInfoBufferSize: DWORD;
322   - psidAdministrators: PSID;
323   - x: Integer;
324   - bSuccess: BOOL;
325   -begin
326   - Result := False;
327   - bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, hAccessToken);
328   - if not bSuccess then
329   - begin
330   - if GetLastError = ERROR_NO_TOKEN then
331   - bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, hAccessToken);
332   - end;
333   - if bSuccess then
334   - begin
335   - GetMem(ptgGroups, 1024);
336   - bSuccess := GetTokenInformation(hAccessToken, TokenGroups, ptgGroups, 1024, dwInfoBufferSize);
337   - CloseHandle(hAccessToken);
338   - if bSuccess then
339   - begin
340   - AllocateAndInitializeSid(constSECURITY_NT_AUTHORITY, 2,
341   - constSECURITY_BUILTIN_DOMAIN_RID,
342   - constDOMAIN_ALIAS_RID_ADMINS,
343   - 0, 0, 0, 0, 0, 0, psidAdministrators);
344   - {$R-}
345   - for x := 0 to ptgGroups.GroupCount - 1 do
346   - if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then
347   - begin
348   - Result := True;
349   - Break;
350   - end;
351   - {$R+}
352   - FreeSid(psidAdministrators);
353   - end;
354   - FreeMem(ptgGroups);
355   - end;
356   -end;
357   -
358 300 procedure ComunicaInsucesso(strIndicador : String);
359 301 var IdHTTP2: TIdHTTP;
360 302 Request_Config : TStringList;
361 303 Response_Config : TStringStream;
362 304 begin
363   -
  305 +
364 306 // Envio notificação de insucesso para o Módulo Gerente Centralizado
365 307 Request_Config := TStringList.Create;
366 308 Request_Config.Values['cs_indicador'] := strIndicador;
... ... @@ -390,8 +332,8 @@ var
390 332 HistoricoLog : TextFile;
391 333 begin
392 334 try
393   - FileSetAttr (v_home_drive + 'chkcacic.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
394   - AssignFile(HistoricoLog,v_home_drive + 'chkcacic.log'); {Associa o arquivo a uma variável do tipo TextFile}
  335 + FileSetAttr (g_oCacic.getHomeDrive + 'chkcacic.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
  336 + AssignFile(HistoricoLog,g_oCacic.getHomeDrive + 'chkcacic.log'); {Associa o arquivo a uma variável do tipo TextFile}
395 337  
396 338 {$IOChecks off}
397 339 Reset(HistoricoLog); {Abre o arquivo texto}
... ... @@ -423,107 +365,6 @@ Begin
423 365 End;
424 366 End;
425 367  
426   -// Pad a string with zeros so that it is a multiple of size
427   -function PadWithZeros(const str : string; size : integer) : string;
428   -var
429   - origsize, i : integer;
430   -begin
431   - Result := str;
432   - origsize := Length(Result);
433   - if ((origsize mod size) <> 0) or (origsize = 0) then
434   - begin
435   - SetLength(Result,((origsize div size)+1)*size);
436   - for i := origsize+1 to Length(Result) do
437   - Result[i] := #0;
438   - end;
439   -end;
440   -
441   -
442   -// Encrypt a string and return the Base64 encoded result
443   -function EnCrypt(p_Data : String) : String;
444   -var
445   - l_Cipher : TDCP_rijndael;
446   - l_Data, l_Key, l_IV : string;
447   -begin
448   - Try
449   - // Pad Key, IV and Data with zeros as appropriate
450   - l_Key := PadWithZeros(v_CipherKey,KeySize);
451   - l_IV := PadWithZeros(v_IV,BlockSize);
452   - l_Data := PadWithZeros(p_Data,BlockSize);
453   -
454   - // Create the cipher and initialise according to the key length
455   - l_Cipher := TDCP_rijndael.Create(nil);
456   - if Length(v_CipherKey) <= 16 then
457   - l_Cipher.Init(l_Key[1],128,@l_IV[1])
458   - else if Length(v_CipherKey) <= 24 then
459   - l_Cipher.Init(l_Key[1],192,@l_IV[1])
460   - else
461   - l_Cipher.Init(l_Key[1],256,@l_IV[1]);
462   -
463   - // Encrypt the data
464   - l_Cipher.EncryptCBC(l_Data[1],l_Data[1],Length(l_Data));
465   -
466   - // Free the cipher and clear sensitive information
467   - l_Cipher.Free;
468   - FillChar(l_Key[1],Length(l_Key),0);
469   -
470   - // Return the Base64 encoded result
471   - Result := Base64EncodeStr(l_Data);
472   - Except
473   - LogDiario('Erro no Processo de Criptografia');
474   - End;
475   -end;
476   -
477   -function DeCrypt(p_Data : String) : String;
478   -var
479   - l_Cipher : TDCP_rijndael;
480   - l_Data, l_Key, l_IV : string;
481   -begin
482   - Try
483   - // Pad Key and IV with zeros as appropriate
484   - l_Key := PadWithZeros(v_CipherKey,KeySize);
485   - l_IV := PadWithZeros(v_IV,BlockSize);
486   -
487   - // Decode the Base64 encoded string
488   - l_Data := Base64DecodeStr(p_Data);
489   -
490   - // Create the cipher and initialise according to the key length
491   - l_Cipher := TDCP_rijndael.Create(nil);
492   - if Length(v_CipherKey) <= 16 then
493   - l_Cipher.Init(l_Key[1],128,@l_IV[1])
494   - else if Length(v_CipherKey) <= 24 then
495   - l_Cipher.Init(l_Key[1],192,@l_IV[1])
496   - else
497   - l_Cipher.Init(l_Key[1],256,@l_IV[1]);
498   -
499   - // Decrypt the data
500   - l_Cipher.DecryptCBC(l_Data[1],l_Data[1],Length(l_Data));
501   -
502   - // Free the cipher and clear sensitive information
503   - l_Cipher.Free;
504   - FillChar(l_Key[1],Length(l_Key),0);
505   -
506   - // Return the result
507   - Result := l_Data;
508   - Except
509   - LogDiario('Erro no Processo de Decriptografia');
510   - End;
511   -end;
512   -
513   -
514   -Function Implode(p_Array : TStrings ; p_Separador : String) : String;
515   -var intAux : integer;
516   - strAux : string;
517   -Begin
518   - strAux := '';
519   - For intAux := 0 To p_Array.Count -1 do
520   - Begin
521   - if (strAux<>'') then strAux := strAux + p_Separador;
522   - strAux := strAux + p_Array[intAux];
523   - End;
524   - Implode := strAux;
525   -end;
526   -
527 368 Function CipherClose(p_DatFileName : string) : String;
528 369 var v_strCipherOpenImploded : string;
529 370 v_DatFile : TextFile;
... ... @@ -536,8 +377,8 @@ begin
536 377 Rewrite (v_DatFile);
537 378 Append(v_DatFile);
538 379  
539   - v_strCipherOpenImploded := Implode(v_tstrCipherOpened,v_SeparatorKey);
540   - v_strCipherClosed := EnCrypt(v_strCipherOpenImploded);
  380 + v_strCipherOpenImploded := g_oCacic.implode(v_tstrCipherOpened,g_oCacic.getSeparatorKey);
  381 + v_strCipherClosed := g_oCacic.enCrypt(v_strCipherOpenImploded);
541 382  
542 383 Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto}
543 384  
... ... @@ -567,12 +408,12 @@ begin
567 408 Readln(v_DatFile,v_strCipherClosed);
568 409 while not EOF(v_DatFile) do Readln(v_DatFile,v_strCipherClosed);
569 410 CloseFile(v_DatFile);
570   - v_strCipherOpened:= DeCrypt(v_strCipherClosed);
  411 + v_strCipherOpened:= g_oCacic.deCrypt(v_strCipherClosed);
571 412 end;
572 413 if (trim(v_strCipherOpened)<>'') then
573   - Result := explode(v_strCipherOpened,v_SeparatorKey)
  414 + Result := g_oCacic.explode(v_strCipherOpened,g_oCacic.getSeparatorKey)
574 415 else
575   - Result := explode('Configs.ID_SO'+v_SeparatorKey+ g_oCacic.getWindowsStrId() +v_SeparatorKey+'Configs.Endereco_WS'+v_SeparatorKey+'/cacic2/ws/',v_SeparatorKey);
  416 + Result := g_oCacic.explode('Configs.ID_SO'+g_oCacic.getSeparatorKey+ g_oCacic.getWindowsStrId() +g_oCacic.getSeparatorKey+'Configs.Endereco_WS'+g_oCacic.getSeparatorKey+'/cacic2/ws/',g_oCacic.getSeparatorKey);
576 417  
577 418  
578 419 if Result.Count mod 2 <> 0 then
... ... @@ -635,7 +476,7 @@ var RegEditSet: TRegistry;
635 476 ListaAuxSet : TStrings;
636 477 I : Integer;
637 478 begin
638   - ListaAuxSet := Explode(Chave, ');
  479 + ListaAuxSet := g_oCacic.explode(Chave, ');
639 480 strRootKey := ListaAuxSet[0];
640 481 For I := 1 To ListaAuxSet.Count - 2 do
641 482 strKey := strKey + ListaAuxSet[I] + '\';
... ... @@ -695,7 +536,7 @@ var RegEditGet: TRegistry;
695 536 DataSize, Len, I : Integer;
696 537 begin
697 538 try
698   - ListaAuxGet := Explode(Chave, ');
  539 + ListaAuxGet := g_oCacic.Explode(Chave, ');
699 540  
700 541 strRootKey := ListaAuxGet[0];
701 542 For I := 1 To ListaAuxGet.Count - 2 Do strKey := strKey + ListaAuxGet[I] + '\';
... ... @@ -788,7 +629,7 @@ var RegDelValorReg: TRegistry;
788 629 ListaAuxDel : TStrings;
789 630 I : Integer;
790 631 begin
791   - ListaAuxDel := Explode(Chave, ');
  632 + ListaAuxDel := g_oCacic.explode(Chave, ');
792 633 strRootKey := ListaAuxDel[0];
793 634 For I := 1 To ListaAuxDel.Count - 2 Do strKey := strKey + ListaAuxDel[I] + '\';
794 635 strValue := ListaAuxDel[ListaAuxDel.Count - 1];
... ... @@ -906,18 +747,12 @@ begin
906 747 End;
907 748 end;
908 749  
909   -function HomeDrive : string;
910   -var
911   -WinDir : array [0..144] of char;
912   -begin
913   -GetWindowsDirectory (WinDir, 144);
914   -Result := StrPas (WinDir);
915   -end;
916   -
917 750 procedure GravaConfiguracoes;
918 751 var chkcacic_ini : TextFile;
919 752 begin
920 753 try
  754 + g_oCacic.setCacicPath(Configs.Edit_cacic_dir.text+'\');
  755 +
921 756 FileSetAttr (ExtractFilePath(Application.Exename) + '\chkcacic.ini',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
922 757 AssignFile(chkcacic_ini,ExtractFilePath(Application.Exename) + '\chkcacic.ini'); {Associa o arquivo a uma variável do tipo TextFile}
923 758 Rewrite (chkcacic_ini); // Recria o arquivo...
... ... @@ -1000,18 +835,17 @@ begin
1000 835 Writeln(chkcacic_ini,'[Cacic2]');
1001 836  
1002 837 // Atribuição dos valores do form FormConfig às variáveis...
1003   - v_ip_serv_cacic := Configs.Edit_ip_serv_cacic.text;
1004   - v_cacic_dir := Configs.Edit_cacic_dir.text;
1005 838 if Configs.ckboxExibeInformacoes.Checked then
1006 839 v_exibe_informacoes := 'S'
1007 840 else
1008 841 v_exibe_informacoes := 'N';
1009 842  
  843 + v_ip_serv_cacic := Configs.Edit_ip_serv_cacic.text;
1010 844 v_te_instala_informacoes_extras := Configs.Memo_te_instala_informacoes_extras.Text;
1011 845  
1012 846 // Escrita dos parâmetros obrigatórios
1013 847 Writeln(chkcacic_ini,'ip_serv_cacic='+v_ip_serv_cacic);
1014   - Writeln(chkcacic_ini,'cacic_dir='+v_cacic_dir);
  848 + Writeln(chkcacic_ini,'cacic_dir='+Configs.Edit_cacic_dir.text);
1015 849 Writeln(chkcacic_ini,'exibe_informacoes='+v_exibe_informacoes);
1016 850  
1017 851 // Escrita dos valores opcionais quando existirem
... ... @@ -1033,7 +867,7 @@ begin
1033 867 Writeln(iniFile,'');
1034 868 Writeln(iniFile,'[Cacic2]');
1035 869 Writeln(iniFile,'ip_serv_cacic='+v_ip_serv_cacic);
1036   - Writeln(iniFile,'cacic_dir='+v_cacic_dir);
  870 + Writeln(iniFile,'cacic_dir='+g_oCacic.getCacicPath);
1037 871 CloseFile(iniFile); {Fecha o arquivo texto}
1038 872 except
1039 873 end;
... ... @@ -1159,7 +993,7 @@ Begin
1159 993 result := false;
1160 994  
1161 995 // Se eu conseguir matar o arquivo abaixo é porque não há outra sessão deste agente aberta... (POG? Nããão! :) )
1162   - Matar(v_cacic_dir,'aguarde_CACIC.txt');
  996 + Matar(g_oCacic.getCacicPath,'aguarde_CACIC.txt');
1163 997  
1164 998 // Se o aguarde_CACIC.txt existir é porque refere-se a uma versão mais atual: 2.2.0.20 ou maior
1165 999 if not (FileExists(g_oCacic.getCacicPath() + '\aguarde_CACIC.txt')) then
... ... @@ -1247,6 +1081,7 @@ var bool_configura,
1247 1081 bool_ArquivoINI,
1248 1082 bool_CommandLine : boolean;
1249 1083  
  1084 + v_cacic_dir,
1250 1085 v_te_serv_updates,
1251 1086 v_nu_porta_serv_updates,
1252 1087 v_nm_usuario_login_serv_updates,
... ... @@ -1280,7 +1115,6 @@ begin
1280 1115 bool_ArquivoINI := FileExists(ExtractFilePath(Application.Exename) + '\chkcacic.ini');
1281 1116  
1282 1117 Try
1283   - v_home_drive := MidStr(HomeDrive,1,3); //x:\
1284 1118  
1285 1119 // 2.2.0.17 - Tratamento de opções passadas em linha de comando
1286 1120 // Grande dica do grande Cláudio Filho (OpenOffice.org)
... ... @@ -1332,16 +1166,14 @@ begin
1332 1166 End;
1333 1167  
1334 1168 g_oCacic := TCACIC.Create();
1335   - g_oCacic.setCacicPath(v_home_drive + v_cacic_dir);
1336   -
1337   - Dir := v_home_drive + v_cacic_dir; // Ex.: c:\cacic\
  1169 + g_oCacic.setCacicPath(g_oCacic.getHomeDrive + v_cacic_dir + '\');
1338 1170  
1339   - if DirectoryExists(Dir + '\Temp\Debugs') then
  1171 + if DirectoryExists(g_oCacic.getCacicPath + 'Temp\Debugs') then
1340 1172 Begin
1341   - if (FormatDateTime('ddmmyyyy', GetFolderDate(Dir + '\Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then
  1173 + if (FormatDateTime('ddmmyyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then
1342 1174 Begin
1343 1175 v_Debugs := true;
1344   - LogDebug('Pasta "' + Dir + '\Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(Dir + '\Temp\Debugs'))+' encontrada. DEBUG ativado.');
  1176 + LogDebug('Pasta "' + g_oCacic.getCacicPath + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs'))+' encontrada. DEBUG ativado.');
1345 1177 End;
1346 1178 End;
1347 1179  
... ... @@ -1393,18 +1225,14 @@ begin
1393 1225 LogDebug(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::');
1394 1226 LogDebug(':::::::::::::: OBTENDO VALORES DO "chkcacic.ini" ::::::::::::::');
1395 1227 LogDebug(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::');
1396   - LogDebug('Drive de instalação......................: '+v_home_drive);
1397   - LogDebug('Pasta para instalação....................: '+Dir);
  1228 + LogDebug('Drive de instalação......................: '+g_oCacic.getHomeDrive);
  1229 + LogDebug('Pasta para instalação....................: '+g_oCacic.getCacicPath);
1398 1230 LogDebug('IP do servidor...........................: '+v_ip_serv_cacic);
1399 1231 LogDebug(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::');
1400 1232 bool_configura := false;
1401 1233  
1402 1234 //chave AES. Recomenda-se que cada empresa/órgão altere a sua chave.
1403   - v_CipherKey := 'CacicBrasil';
1404   - v_IV := 'abcdefghijklmnop';
1405   - v_SeparatorKey := '=CacicIsFree='; // Usada apenas para o cacic2.dat
1406   - v_DatFileName := Dir + '\cacic2.dat';
1407   - v_tstrCipherOpened := CipherOpen(v_DatFileName);
  1235 + v_tstrCipherOpened := CipherOpen(g_oCacic.getCacicPath + '\' + g_oCacic.getDatFileName);
1408 1236  
1409 1237 if (g_oCacic.isWindowsGEXP()) then // Se >= Maior ou Igual ao WinXP...
1410 1238 Begin
... ... @@ -1415,24 +1243,24 @@ begin
1415 1243 Try
1416 1244 Begin
1417 1245 // Liberando as conexões de Saída para o FTP
1418   - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\FTP-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App='+HomeDrive+'\system32\\ftp.exe|Name=Programa de transferência de arquivos|Desc=Programa de transferência de arquivos|Edge=FALSE|');
1419   - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\FTP-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App='+HomeDrive+'\system32\\ftp.exe|Name=Programa de transferência de arquivos|Desc=Programa de transferência de arquivos|Edge=FALSE|');
  1246 + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\FTP-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App='+g_oCacic.getHomeDrive+'system32\\ftp.exe|Name=Programa de transferência de arquivos|Desc=Programa de transferência de arquivos|Edge=FALSE|');
  1247 + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\FTP-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App='+g_oCacic.getHomeDrive+'system32\\ftp.exe|Name=Programa de transferência de arquivos|Desc=Programa de transferência de arquivos|Edge=FALSE|');
1420 1248  
1421 1249 // Liberando as conexões de Saída para o Ger_Cols
1422   - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-GERCOLS-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App='+Dir+'\modulos\\ger_cols.exe|Name=Módulo Gerente de Coletas do Sistema CACIC|Desc=Módulo Gerente de Coletas do Sistema CACIC|Edge=FALSE|');
1423   - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-GERCOLS-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App='+Dir+'\modulos\\ger_cols.exe|Name=Módulo Gerente de Coletas do Sistema CACIC|Desc=Módulo Gerente de Coletas do Sistema CACIC|Edge=FALSE|');
  1250 + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-GERCOLS-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App='+g_oCacic.getCacicPath+'modulos\\ger_cols.exe|Name=Módulo Gerente de Coletas do Sistema CACIC|Desc=Módulo Gerente de Coletas do Sistema CACIC|Edge=FALSE|');
  1251 + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-GERCOLS-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App='+g_oCacic.getCacicPath+'modulos\\ger_cols.exe|Name=Módulo Gerente de Coletas do Sistema CACIC|Desc=Módulo Gerente de Coletas do Sistema CACIC|Edge=FALSE|');
1424 1252  
1425 1253 // Liberando as conexões de Saída para o SrCACICsrv
1426   - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-SRCACICSRV-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App='+Dir+'\modulos\\srcacicsrv.exe|Name=Módulo Suporte Remoto Seguro do Sistema CACIC|Desc=Módulo Suporte Remoto Seguro do Sistema CACIC|Edge=FALSE|');
1427   - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-SRCACICSRV-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App='+Dir+'\modulos\\srcacicsrv.exe|Name=Módulo Suporte Remoto Seguro do Sistema CACIC|Desc=Módulo Suporte Remoto Seguro do Sistema CACIC|Edge=FALSE|');
  1254 + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-SRCACICSRV-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App='+g_oCacic.getCacicPath+'modulos\\srcacicsrv.exe|Name=Módulo Suporte Remoto Seguro do Sistema CACIC|Desc=Módulo Suporte Remoto Seguro do Sistema CACIC|Edge=FALSE|');
  1255 + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-SRCACICSRV-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App='+g_oCacic.getCacicPath+'modulos\\srcacicsrv.exe|Name=Módulo Suporte Remoto Seguro do Sistema CACIC|Desc=Módulo Suporte Remoto Seguro do Sistema CACIC|Edge=FALSE|');
1428 1256  
1429 1257 // Liberando as conexões de Saída para o ChkCacic
1430 1258 SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-CHKCACIC-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App='+ExtractFilePath(Application.Exename) + '\chkcacic.exe|Name=chkcacic.exe|Desc=chkcacic.exe|Edge=FALSE|');
1431 1259 SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-CHKCACIC-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App='+ExtractFilePath(Application.Exename) + '\chkcacic.exe|Name=chkcacic.exe|Desc=chkcacic.exe|Edge=FALSE|');
1432 1260  
1433 1261 // Liberando as conexões de Saída para o ChkSis
1434   - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-CHKSIS-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App='+HomeDrive + '\chksis.exe|Name=Módulo Verificador de Integridade do Sistema CACIC|Desc=Módulo Verificador de Integridade do Sistema CACIC|Edge=FALSE|');
1435   - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-CHKSIS-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App='+HomeDrive + '\chksis.exe|Name=Módulo Verificador de Integridade do Sistema CACIC|Desc=Módulo Verificador de Integridade do Sistema CACIC|Edge=FALSE|');
  1262 + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-CHKSIS-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App='+g_oCacic.getWinDir + 'chksis.exe|Name=Módulo Verificador de Integridade do Sistema CACIC|Desc=Módulo Verificador de Integridade do Sistema CACIC|Edge=FALSE|');
  1263 + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-CHKSIS-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App='+g_oCacic.getWinDir + 'chksis.exe|Name=Módulo Verificador de Integridade do Sistema CACIC|Desc=Módulo Verificador de Integridade do Sistema CACIC|Edge=FALSE|');
1436 1264 End
1437 1265 Except
1438 1266 LogDebug('Problema Liberando Policies de FireWall!');
... ... @@ -1477,25 +1305,25 @@ begin
1477 1305 end;
1478 1306  
1479 1307 // Verifico a existência do diretório configurado para o Cacic, normalmente CACIC
1480   - if not DirectoryExists(Dir) then
  1308 + if not DirectoryExists(g_oCacic.getCacicPath) then
1481 1309 begin
1482   - LogDiario('Criando pasta '+Dir);
1483   - ForceDirectories(Dir);
  1310 + LogDiario('Criando pasta '+g_oCacic.getCacicPath);
  1311 + ForceDirectories(g_oCacic.getCacicPath);
1484 1312 end;
1485 1313  
1486 1314 // Para eliminar versão 20014 e anteriores que provavelmente não fazem corretamente o AutoUpdate
1487   - if not DirectoryExists(Dir+'\modulos') then
  1315 + if not DirectoryExists(g_oCacic.getCacicPath+'modulos') then
1488 1316 begin
1489   - Matar(Dir, '\cacic2.exe');
1490   - ForceDirectories(Dir + '\modulos');
1491   - LogDiario('Criando pasta '+Dir+'\modulos');
  1317 + Matar(g_oCacic.getCacicPath, 'cacic2.exe');
  1318 + ForceDirectories(g_oCacic.getCacicPath + 'modulos');
  1319 + LogDiario('Criando pasta '+g_oCacic.getCacicPath+'modulos');
1492 1320 end;
1493 1321  
1494 1322 // Crio o SubDiretório TEMP, caso não exista
1495   - if not DirectoryExists(Dir+'\temp') then
  1323 + if not DirectoryExists(g_oCacic.getCacicPath+'temp') then
1496 1324 begin
1497   - ForceDirectories(Dir + '\temp');
1498   - LogDiario('Criando pasta '+Dir+'\temp');
  1325 + ForceDirectories(g_oCacic.getCacicPath + 'temp');
  1326 + LogDiario('Criando pasta '+g_oCacic.getCacicPath+'temp');
1499 1327 end;
1500 1328  
1501 1329  
... ... @@ -1573,101 +1401,101 @@ begin
1573 1401 LogDebug(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::');
1574 1402  
1575 1403 // Atribuição de acesso ao módulo principal e pastas
1576   - Form1.FS_SetSecurity(Dir);
1577   - Form1.FS_SetSecurity(Dir + '\cacic2.exe');
1578   - Form1.FS_SetSecurity(Dir + '\cacic2.dat');
1579   - Form1.FS_SetSecurity(Dir + '\cacic2.log');
1580   - Form1.FS_SetSecurity(Dir + '\modulos');
1581   - Form1.FS_SetSecurity(Dir + '\temp');
  1404 + Form1.FS_SetSecurity(g_oCacic.getCacicPath);
  1405 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'cacic2.exe');
  1406 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'cacic2.dat');
  1407 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'cacic2.log');
  1408 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos');
  1409 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'temp');
1582 1410  
1583 1411 // Atribuição de acesso aos módulos de gerenciamento de coletas e coletas para permissão de atualizações de versões
1584   - Form1.FS_SetSecurity(Dir + '\modulos\ger_cols.exe');
1585   - Form1.FS_SetSecurity(Dir + '\modulos\srcacicsrv.exe');
1586   - Form1.FS_SetSecurity(Dir + '\modulos\col_anvi.exe');
1587   - Form1.FS_SetSecurity(Dir + '\modulos\col_comp.exe');
1588   - Form1.FS_SetSecurity(Dir + '\modulos\col_hard.exe');
1589   - Form1.FS_SetSecurity(Dir + '\modulos\col_moni.exe');
1590   - Form1.FS_SetSecurity(Dir + '\modulos\col_patr.exe');
1591   - Form1.FS_SetSecurity(Dir + '\modulos\col_soft.exe');
1592   - Form1.FS_SetSecurity(Dir + '\modulos\col_undi.exe');
1593   - Form1.FS_SetSecurity(Dir + '\modulos\ini_cols.exe');
1594   - Form1.FS_SetSecurity(Dir + '\modulos\wscript.exe');
  1412 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\ger_cols.exe');
  1413 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\srcacicsrv.exe');
  1414 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\col_anvi.exe');
  1415 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\col_comp.exe');
  1416 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\col_hard.exe');
  1417 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\col_moni.exe');
  1418 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\col_patr.exe');
  1419 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\col_soft.exe');
  1420 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\col_undi.exe');
  1421 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\ini_cols.exe');
  1422 + Form1.FS_SetSecurity(g_oCacic.getCacicPath + 'modulos\wscript.exe');
1595 1423  
1596 1424 // Atribuição de acesso para atualização do módulo verificador de integridade do sistema e seus arquivos
1597   - Form1.FS_SetSecurity(HomeDrive + '\chksis.exe');
1598   - Form1.FS_SetSecurity(HomeDrive + '\chksis.log');
1599   - Form1.FS_SetSecurity(HomeDrive + '\chksis.dat');
  1425 + Form1.FS_SetSecurity(g_oCacic.getWinDir + 'chksis.exe');
  1426 + Form1.FS_SetSecurity(g_oCacic.getWinDir + 'chksis.log');
  1427 + Form1.FS_SetSecurity(g_oCacic.getWinDir + 'chksis.dat');
1600 1428  
1601 1429 // Atribuição de acesso para atualização/exclusão de log do instalador
1602   - Form1.FS_SetSecurity(v_home_drive + 'chkcacic.log');
  1430 + Form1.FS_SetSecurity(g_oCacic.getHomeDrive + 'chkcacic.log');
1603 1431 LogDebug(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::');
1604 1432 End;
1605 1433  
1606 1434 // Verificação de versão do cacic2.exe e exclusão em caso de versão antiga/diferente da atual
1607   - If (FileExists(Dir + '\cacic2.exe')) Then
  1435 + If (FileExists(g_oCacic.getCacicPath + 'cacic2.exe')) Then
1608 1436 Begin
1609 1437 // Pego as informações de dia/mês/ano/horas/minutos/segundos/milésimos que identificam o agente Cacic2
1610   - strDataHoraCACIC2_INI := FormatDateTime('ddmmyyyyhhnnsszzz', GetFolderDate(Dir + '\cacic2.exe'));
  1438 + strDataHoraCACIC2_INI := FormatDateTime('ddmmyyyyhhnnsszzz', GetFolderDate(g_oCacic.getCacicPath + 'cacic2.exe'));
1611 1439  
1612   - intAux := ChecaVersoesAgentes(Dir + '\cacic2.exe');
  1440 + intAux := ChecaVersoesAgentes(g_oCacic.getCacicPath + 'cacic2.exe');
1613 1441 // 0 => Arquivo de versões ou informação inexistente
1614 1442 // 1 => Versões iguais
1615 1443 // 2 => Versões diferentes
1616 1444 if (intAux = 0) then
1617 1445 Begin
1618   - v_versao_local := StringReplace(trim(GetVersionInfo(Dir + '\cacic2.exe')),'.','',[rfReplaceAll]);
  1446 + v_versao_local := StringReplace(trim(GetVersionInfo(g_oCacic.getCacicPath + 'cacic2.exe')),'.','',[rfReplaceAll]);
1619 1447 v_versao_remota := StringReplace(XML_RetornaValor('CACIC2' , v_retorno),'0103','',[rfReplaceAll]);
1620 1448 End;
1621 1449  
1622 1450 if (intAux = 2) or // Caso haja diferença na comparação de versões com "versoes_agentes.ini"...
1623 1451 (v_versao_local ='0000') or // Provavelmente versão muito antiga ou corrompida
1624 1452 (v_versao_local ='2208') then
1625   - Matar(Dir, '\cacic2.exe');
  1453 + Matar(g_oCacic.getCacicPath, 'cacic2.exe');
1626 1454 End;
1627 1455  
1628 1456 // Verificação de versão do ger_cols.exe e exclusão em caso de versão antiga/diferente da atual
1629   - If (FileExists(Dir + '\modulos\ger_cols.exe')) Then
  1457 + If (FileExists(g_oCacic.getCacicPath + 'modulos\ger_cols.exe')) Then
1630 1458 Begin
1631 1459 // Pego as informações de dia/mês/ano/horas/minutos/segundos/milésimos que identificam o agente Ger_Cols
1632   - strDataHoraGERCOLS_INI := FormatDateTime('ddmmyyyyhhnnsszzz', GetFolderDate(Dir + '\modulos\ger_cols.exe'));
  1460 + strDataHoraGERCOLS_INI := FormatDateTime('ddmmyyyyhhnnsszzz', GetFolderDate(g_oCacic.getCacicPath + 'modulos\ger_cols.exe'));
1633 1461  
1634   - intAux := ChecaVersoesAgentes(Dir + '\modulos\ger_cols.exe');
  1462 + intAux := ChecaVersoesAgentes(g_oCacic.getCacicPath + 'modulos\ger_cols.exe');
1635 1463 // 0 => Arquivo de versões ou informação inexistente
1636 1464 // 1 => Versões iguais
1637 1465 // 2 => Versões diferentes
1638 1466 if (intAux = 0) then
1639 1467 Begin
1640   - v_versao_local := StringReplace(trim(GetVersionInfo(Dir + '\modulos\ger_cols.exe')),'.','',[rfReplaceAll]);
  1468 + v_versao_local := StringReplace(trim(GetVersionInfo(g_oCacic.getCacicPath + 'modulos\ger_cols.exe')),'.','',[rfReplaceAll]);
1641 1469 v_versao_remota := StringReplace(XML_RetornaValor('GER_COLS' , v_retorno),'0103','',[rfReplaceAll]);
1642 1470 End;
1643 1471  
1644 1472 if (intAux = 2) or // Caso haja diferença na comparação de versões com "versoes_agentes.ini"...
1645 1473 (v_versao_local ='0000') then // Provavelmente versão muito antiga ou corrompida
1646   - Matar(Dir + '\modulos, 'ger_cols.exe');
  1474 + Matar(g_oCacic.getCacicPath + 'modulos, 'ger_cols.exe');
1647 1475 End;
1648 1476  
1649 1477 // Verificação de versão do chksis.exe e exclusão em caso de versão antiga/diferente da atual
1650   - If (FileExists(HomeDrive + '\chksis.exe')) Then
  1478 + If (FileExists(g_oCacic.getWinDir + 'chksis.exe')) Then
1651 1479 Begin
1652   - intAux := ChecaVersoesAgentes(HomeDrive + '\chksis.exe');
  1480 + intAux := ChecaVersoesAgentes(g_oCacic.getWinDir + 'chksis.exe');
1653 1481 // 0 => Arquivo de versões ou informação inexistente
1654 1482 // 1 => Versões iguais
1655 1483 // 2 => Versões diferentes
1656 1484 if (intAux = 0) then
1657 1485 Begin
1658   - v_versao_local := StringReplace(trim(GetVersionInfo(HomeDrive + '\chksis.exe')),'.','',[rfReplaceAll]);
  1486 + v_versao_local := StringReplace(trim(GetVersionInfo(g_oCacic.getWinDir + 'chksis.exe')),'.','',[rfReplaceAll]);
1659 1487 v_versao_remota := StringReplace(XML_RetornaValor('CHKSIS' , v_retorno),'0103','',[rfReplaceAll]);
1660 1488 End;
1661 1489  
1662 1490 if (intAux = 2) or // Caso haja diferença na comparação de versões com "versoes_agentes.ini"...
1663 1491 (v_versao_local ='0000') then // Provavelmente versão muito antiga ou corrompida
1664   - Matar(HomeDrive,'chksis.exe');
  1492 + Matar(g_oCacic.getWinDir,'chksis.exe');
1665 1493 End;
1666 1494  
1667 1495 // Tento detectar o ChkSis.EXE e copio ou faço FTP caso não exista
1668 1496 verifyAndGet('chksis.exe',
1669 1497 XML_RetornaValor('CHKSIS_HASH', v_retorno),
1670   - HomeDrive,
  1498 + g_oCacic.getWinDir,
1671 1499 v_te_serv_updates,
1672 1500 v_nu_porta_serv_updates,
1673 1501 v_nm_usuario_login_serv_updates,
... ... @@ -1676,11 +1504,11 @@ begin
1676 1504 v_exibe_informacoes);
1677 1505  
1678 1506 // Tento detectar o ChkSis.INI e crio-o caso necessário
1679   - If not FileExists(HomeDrive + '\chksis.ini') Then
  1507 + If not FileExists(g_oCacic.getWinDir + 'chksis.ini') Then
1680 1508 begin
1681   - LogDebug('Criando '+HomeDrive + '\chksis.ini');
1682   - GravaIni(HomeDrive + '\chksis.ini');
1683   - FileSetAttr ( PChar(HomeDrive + '\chksis.ini'),0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
  1509 + LogDebug('Criando '+g_oCacic.getWinDir + 'chksis.ini');
  1510 + GravaIni(g_oCacic.getWinDir + 'chksis.ini');
  1511 + FileSetAttr ( PChar(g_oCacic.getWinDir + 'chksis.ini'),0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
1684 1512 end;
1685 1513  
1686 1514  
... ... @@ -1689,8 +1517,8 @@ begin
1689 1517 Begin
1690 1518 // Tento detectar o CACICsvc.EXE e copio ou faço FTP caso não exista
1691 1519 verifyAndGet('cacicsvc.exe',
1692   - XML_RetornaValor('CACICSVC_HASH', v_retorno),
1693   - HomeDrive,
  1520 + XML_RetornaValor('CACICSVC_HASH', v_retorno),
  1521 + g_oCacic.getWinDir,
1694 1522 v_te_serv_updates,
1695 1523 v_nu_porta_serv_updates,
1696 1524 v_nm_usuario_login_serv_updates,
... ... @@ -1699,16 +1527,13 @@ begin
1699 1527 v_exibe_informacoes);
1700 1528  
1701 1529 // O CACICsvc usará o arquivo de configurações \Windows\chksis.ini
1702   -
1703   - //LogDebug('reCriando '+HomeDrive + '\cacicsvc.ini');
1704   - //GravaIni(HomeDrive + '\cacicsvc.ini');
1705 1530 End;
1706 1531  
1707 1532 // Tento detectar o cacic2.INI e crio-o caso necessário
1708   - If not FileExists(Dir + '\cacic2.ini') Then
  1533 + If not FileExists(g_oCacic.getCacicPath + 'cacic2.ini') Then
1709 1534 begin
1710   - LogDebug('Criando/Recriando '+Dir + '\cacic2.ini');
1711   - GravaIni(Dir + '\cacic2.ini');
  1535 + LogDebug('Criando/Recriando '+g_oCacic.getCacicPath + 'cacic2.ini');
  1536 + GravaIni(g_oCacic.getCacicPath + 'cacic2.ini');
1712 1537 end;
1713 1538  
1714 1539 // Verifico se existe a pasta "modulos"
... ... @@ -1717,8 +1542,8 @@ begin
1717 1542  
1718 1543 // Tento detectar o Agente Principal e copio ou faço FTP caso não exista
1719 1544 verifyAndGet('cacic2.exe',
1720   - XML_RetornaValor('CACIC2_HASH', v_retorno),
1721   - Dir,
  1545 + XML_RetornaValor('CACIC2_HASH', v_retorno),
  1546 + g_oCacic.getCacicPath,
1722 1547 v_te_serv_updates,
1723 1548 v_nu_porta_serv_updates,
1724 1549 v_nm_usuario_login_serv_updates,
... ... @@ -1728,7 +1553,7 @@ begin
1728 1553  
1729 1554 verifyAndGet('ger_cols.exe',
1730 1555 XML_RetornaValor('GER_COLS_HASH', v_retorno),
1731   - Dir + '\modulos',
  1556 + g_oCacic.getCacicPath + 'modulos',
1732 1557 v_te_serv_updates,
1733 1558 v_nu_porta_serv_updates,
1734 1559 v_nm_usuario_login_serv_updates,
... ... @@ -1747,8 +1572,8 @@ begin
1747 1572 (v_array_modulos[intAux]<>'chksis.exe') then
1748 1573 Begin
1749 1574 LogDiario('Copiando '+v_array_modulos[intAux]+' de '+ExtractFilePath(Application.Exename)+'modulos\');
1750   - CopyFile(PChar(ExtractFilePath(Application.Exename) + 'modulos\'+v_array_modulos[intAux]), PChar(Dir + '\modulos\'+v_array_modulos[intAux]),false);
1751   - FileSetAttr (PChar(Dir + '\modulos\'+v_array_modulos[intAux]),0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
  1575 + CopyFile(PChar(ExtractFilePath(Application.Exename) + 'modulos\'+v_array_modulos[intAux]), PChar(g_oCacic.getCacicPath + 'modulos\'+v_array_modulos[intAux]),false);
  1576 + FileSetAttr (PChar(g_oCacic.getCacicPath + 'modulos\'+v_array_modulos[intAux]),0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
1752 1577 End;
1753 1578 End;
1754 1579 End;
... ... @@ -1760,7 +1585,7 @@ begin
1760 1585 // Tento detectar (de novo) o ChkSis.EXE e copio ou faço FTP caso não exista
1761 1586 verifyAndGet('chksis.exe',
1762 1587 XML_RetornaValor('CHKSIS_HASH', v_retorno),
1763   - HomeDrive,
  1588 + g_oCacic.getWinDir,
1764 1589 v_te_serv_updates,
1765 1590 v_nu_porta_serv_updates,
1766 1591 v_nm_usuario_login_serv_updates,
... ... @@ -1771,7 +1596,7 @@ begin
1771 1596 // Tento detectar (de novo) o Agente Principal e copio ou faço FTP caso não exista
1772 1597 verifyAndGet('cacic2.exe',
1773 1598 XML_RetornaValor('CACIC2_HASH', v_retorno),
1774   - Dir,
  1599 + g_oCacic.getCacicPath,
1775 1600 v_te_serv_updates,
1776 1601 v_nu_porta_serv_updates,
1777 1602 v_nm_usuario_login_serv_updates,
... ... @@ -1781,7 +1606,7 @@ begin
1781 1606  
1782 1607 verifyAndGet('ger_cols.exe',
1783 1608 XML_RetornaValor('GER_COLS_HASH', v_retorno),
1784   - Dir + '\modulos',
  1609 + g_oCacic.getCacicPath + 'modulos',
1785 1610 v_te_serv_updates,
1786 1611 v_nu_porta_serv_updates,
1787 1612 v_nm_usuario_login_serv_updates,
... ... @@ -1789,28 +1614,22 @@ begin
1789 1614 v_te_path_serv_updates,
1790 1615 v_exibe_informacoes);
1791 1616  
1792   -
1793   - {
1794   - if ((intWinVer <> 0) and (intWinVer >= 8)) or
1795   - (abstraiCSD(v_te_so) >= 250) then // Se >= WinXP...
1796   - }
1797   -
1798 1617 if (g_oCacic.isWindowsNTPlataform) then
1799 1618 Begin
1800 1619 Try
1801 1620 // Acrescento o Ger_Cols e srCacicSrv às exceções do FireWall nativo...
1802 1621  
1803 1622 {chksis}
1804   - LogDebug('Inserindo "'+HomeDrive + '\chksis" nas exceções do FireWall!');
1805   - LiberaFireWall(HomeDrive + '\chksis');
  1623 + LogDebug('Inserindo "'+g_oCacic.getWinDir + 'chksis" nas exceções do FireWall!');
  1624 + LiberaFireWall(g_oCacic.getWinDir + 'chksis');
1806 1625  
1807 1626 {ger_cols}
1808   - LogDebug('Inserindo "'+Dir + '\modulos\ger_cols" nas exceções do FireWall!');
1809   - LiberaFireWall(Dir + '\modulos\ger_cols');
  1627 + LogDebug('Inserindo "'+g_oCacic.getCacicPath + 'modulos\ger_cols" nas exceções do FireWall!');
  1628 + LiberaFireWall(g_oCacic.getCacicPath + 'modulos\ger_cols');
1810 1629  
1811 1630 {srcacicsrv}
1812   - LogDebug('Inserindo "'+Dir + '\modulos\srcacicsrv" nas exceções do FireWall!');
1813   - LiberaFireWall(Dir + '\modulos\srcacicsrv');
  1631 + LogDebug('Inserindo "'+g_oCacic.getCacicPath + 'modulos\srcacicsrv" nas exceções do FireWall!');
  1632 + LiberaFireWall(g_oCacic.getCacicPath + 'modulos\srcacicsrv');
1814 1633  
1815 1634 Except
1816 1635 End;
... ... @@ -1823,13 +1642,13 @@ begin
1823 1642 Begin
1824 1643 // Crio a chave/valor cacic2 para autoexecução do Cacic, caso não exista esta chave/valor
1825 1644 // Crio a chave/valor chksis para autoexecução do ChkSIS, caso não exista esta chave/valor
1826   - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\CheckSystemRoutine', HomeDrive + '\chksis.exe');
  1645 + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\CheckSystemRoutine', g_oCacic.getWinDir + 'chksis.exe');
1827 1646  
1828 1647 bool_ExistsAutoRun := false;
1829   - if (GetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic2')=Dir + '\cacic2.exe') then
  1648 + if (GetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic2')=g_oCacic.getCacicPath + 'cacic2.exe') then
1830 1649 bool_ExistsAutoRun := true
1831 1650 else
1832   - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic2', Dir + '\cacic2.exe');
  1651 + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic2', g_oCacic.getCacicPath + 'cacic2.exe');
1833 1652 End
1834 1653 else
1835 1654 Begin
... ... @@ -1840,24 +1659,24 @@ begin
1840 1659 // Igualo as chaves ip_serv_cacic dos arquivos chksis.ini e cacic2.ini!
1841 1660 SetValorDatMemoria('Configs.EnderecoServidor', v_ip_serv_cacic);
1842 1661 LogDebug('Fechando Arquivo de Configurações do Cacic');
1843   - CipherClose(v_DatFileName);
  1662 + CipherClose(g_oCacic.getDatFileName);
1844 1663  
1845 1664 LogDebug('Abrindo Arquivo de Configurações do ChkSis');
1846   - CipherOpen(HomeDrive + '\chksis.dat');
  1665 + CipherOpen(g_oCacic.getWinDir + 'chksis.dat');
1847 1666 SetValorDatMemoria('Cacic2.ip_serv_cacic', v_ip_serv_cacic);
1848   - CipherClose(HomeDrive + '\chksis.dat');
  1667 + CipherClose(g_oCacic.getWinDir + 'chksis.dat');
1849 1668  
1850 1669 // Volto a gravar o chksis.ini para o difícil caso de leitura por versões antigas
1851   - SetValorChaveRegIni('Cacic2', 'ip_serv_cacic', v_ip_serv_cacic, HomeDrive + '\chksis.ini');
  1670 + SetValorChaveRegIni('Cacic2', 'ip_serv_cacic', v_ip_serv_cacic, g_oCacic.getWinDir + 'chksis.ini');
1852 1671 LogDebug('Fechando Arquivo de Configurações do ChkSis');
1853 1672  
1854 1673 LogDebug('Resgatando informações para identificação de alteração do agente CACIC2');
1855 1674 // Pego as informações de dia/mês/ano/horas/minutos/segundos/milésimos que identificam os agentes
1856   - strDataHoraCACIC2_FIM := FormatDateTime('ddmmyyyyhhnnsszzz', GetFolderDate(Dir + '\cacic2.exe'));
  1675 + strDataHoraCACIC2_FIM := FormatDateTime('ddmmyyyyhhnnsszzz', GetFolderDate(g_oCacic.getCacicPath + 'cacic2.exe'));
1857 1676 LogDebug('Inicial => "' + strDataHoraCACIC2_INI + '" Final => "' + strDataHoraCACIC2_FIM + '"');
1858 1677  
1859 1678 LogDebug('Resgatando informações para identificação de alteração do agente GER_COLS');
1860   - strDataHoraGERCOLS_FIM := FormatDateTime('ddmmyyyyhhnnsszzz', GetFolderDate(Dir + '\modulos\ger_cols.exe'));
  1679 + strDataHoraGERCOLS_FIM := FormatDateTime('ddmmyyyyhhnnsszzz', GetFolderDate(g_oCacic.getCacicPath + 'modulos\ger_cols.exe'));
1861 1680 LogDebug('Inicial => "' + strDataHoraGERCOLS_INI + '" Final => "' + strDataHoraGERCOLS_FIM + '"');
1862 1681  
1863 1682 // Caso o Cacic tenha sido baixado executo-o com parâmetro de configuração de servidor
... ... @@ -1866,7 +1685,7 @@ begin
1866 1685 Begin
1867 1686 v_te_texto_janela_instalacao := v_te_instala_informacoes_extras;
1868 1687  
1869   - if (GetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic2')=Dir + '\cacic2.exe') and
  1688 + if (GetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic2')=g_oCacic.getCacicPath + 'cacic2.exe') and
1870 1689 (not g_oCacic.isWindowsNTPlataform()) or
1871 1690 (g_oCacic.isWindowsNTPlataform()) then
1872 1691 Begin
... ... @@ -1888,11 +1707,11 @@ begin
1888 1707 // Se não for plataforma NT executo o agente principal
1889 1708 if not (g_oCacic.isWindowsNTPlataform()) then
1890 1709 Begin
1891   - LogDebug('Executando '+Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic);
  1710 + LogDebug('Executando '+g_oCacic.getCacicPath + 'cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic);
1892 1711 if (strDataHoraCACIC2_INI <> strDataHoraCACIC2_FIM) then
1893   - WinExec(PChar(Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic+ ' /execute'), SW_HIDE)
  1712 + WinExec(PChar(g_oCacic.getCacicPath + 'cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic+ ' /execute'), SW_HIDE)
1894 1713 else
1895   - WinExec(PChar(Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic ), SW_HIDE);
  1714 + WinExec(PChar(g_oCacic.getCacicPath + 'cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic ), SW_HIDE);
1896 1715 End
1897 1716 else
1898 1717 Begin
... ... @@ -1911,13 +1730,13 @@ begin
1911 1730 Begin
1912 1731 // Instalo e Habilito o serviço
1913 1732 LogDiario('Instalando CACICservice...');
1914   - WinExec(PChar(HomeDrive + '\cacicsvc.exe -install'), SW_NORMAL);
  1733 + WinExec(PChar(g_oCacic.getWinDir + 'cacicsvc.exe -install'), SW_NORMAL);
1915 1734 End
1916 1735 else if ((wordServiceStatus < 4) or
1917 1736 (wordServiceStatus > 4)) then
1918 1737 Begin
1919 1738 LogDiario('Iniciando CACICservice');
1920   - WinExec(PChar(HomeDrive + '\cacicsvc.exe -start'), SW_NORMAL);
  1739 + WinExec(PChar(g_oCacic.getWinDir + 'cacicsvc.exe -start'), SW_NORMAL);
1921 1740 End
1922 1741 else
1923 1742 LogDiario('Não instalei o CACICservice. Já está rodando...');
... ... @@ -1937,14 +1756,11 @@ begin
1937 1756 LogDiario('Falha na Instalação/Atualização');
1938 1757 End;
1939 1758  
1940   - Application.Terminate;
1941   - {
1942   - Considerando-se que o objeto se libera ao fim da aplicação
1943 1759 try
1944 1760 g_oCacic.Free();
1945 1761 except
1946 1762 end;
1947   - }
  1763 + Application.Terminate;
1948 1764 end;
1949 1765  
1950 1766 function ServiceRunning(sMachine, sService: PChar): Boolean;
... ...
chksis/chksis.dpr
... ... @@ -37,63 +37,22 @@ uses
37 37 IdTCPClient,
38 38 PJVersionInfo,
39 39 Winsock,
40   - DCPcrypt2,
41   - DCPrijndael,
42   - DCPbase64,
43 40 Tlhelp32,
44 41 CACIC_Library in '..\CACIC_Library.pas';
45 42  
46   -var PJVersionInfo1: TPJVersionInfo;
47   - Dir,
48   - v_CipherKey,
49   - v_IV,
50   - v_SeparatorKey,
51   - v_strCipherClosed,
52   - v_DatFileName,
53   - v_versao_local,
54   - v_versao_remota,
55   - v_retorno,
56   - v_te_so : String;
57   - v_Debugs : Boolean;
58   -var v_tstrCipherOpened : TStrings;
59   -
60   -var g_oCacic : TCACIC;
61   -
62   -// Some constants that are dependant on the cipher being used
63   -// Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize)
64   -const KeySize = 32; // 32 bytes = 256 bits
65   - BlockSize = 16; // 16 bytes = 128 bits
66   -
67   -Function Explode(Texto, Separador : String) : TStrings;
68 43 var
69   - strItem : String;
70   - ListaAuxUTILS : TStrings;
71   - NumCaracteres,
72   - TamanhoSeparador,
73   - I : Integer;
74   -Begin
75   - ListaAuxUTILS := TStringList.Create;
76   - strItem := '';
77   - NumCaracteres := Length(Texto);
78   - TamanhoSeparador := Length(Separador);
79   - I := 1;
80   - While I <= NumCaracteres Do
81   - Begin
82   - If (Copy(Texto,I,TamanhoSeparador) = Separador) or (I = NumCaracteres) Then
83   - Begin
84   - if (I = NumCaracteres) then strItem := strItem + Texto[I];
85   - ListaAuxUTILS.Add(trim(strItem));
86   - strItem := '';
87   - I := I + (TamanhoSeparador-1);
88   - end
89   - Else
90   - strItem := strItem + Texto[I];
91   -
92   - I := I + 1;
93   - End;
94   - Explode := ListaAuxUTILS;
95   -end;
  44 + PJVersionInfo1: TPJVersionInfo;
  45 + v_strCipherClosed,
  46 + v_versao_local,
  47 + v_versao_remota,
  48 + v_retorno : String;
  49 + v_Debugs : Boolean;
96 50  
  51 +var
  52 + v_tstrCipherOpened : TStrings;
  53 +
  54 +var
  55 + g_oCacic : TCACIC;
97 56  
98 57 function VerFmt(const MS, LS: DWORD): string;
99 58 // Format the version number from the given DWORDs containing the info
... ... @@ -102,31 +61,17 @@ begin
102 61 [HiWord(MS), LoWord(MS), HiWord(LS), LoWord(LS)])
103 62 end;
104 63  
105   -{ TMainForm }
106   -Function Implode(p_Array : TStrings ; p_Separador : String) : String;
107   -var intAux : integer;
108   - strAux : string;
109   -Begin
110   - strAux := '';
111   - For intAux := 0 To p_Array.Count -1 do
112   - Begin
113   - if (strAux<>'') then strAux := strAux + p_Separador;
114   - strAux := strAux + p_Array[intAux];
115   - End;
116   - Implode := strAux;
117   -end;
118   -
119 64 procedure log_diario(strMsg : String);
120 65 var
121 66 HistoricoLog : TextFile;
122 67 strDataArqLocal,
123 68 strDataAtual,
124   - p_path : string;
  69 + v_path : string;
125 70 begin
126 71 try
127   - p_path := Dir + '\chksis.log';
128   - FileSetAttr (p_path,0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
129   - AssignFile(HistoricoLog,p_path); {Associa o arquivo a uma variável do tipo TextFile}
  72 + v_path := g_oCacic.getWinDir + 'chksis.log';
  73 + FileSetAttr (v_path,0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
  74 + AssignFile(HistoricoLog,v_path); {Associa o arquivo a uma variável do tipo TextFile}
130 75 {$IOChecks off}
131 76 Reset(HistoricoLog); {Abre o arquivo texto}
132 77 {$IOChecks on}
... ... @@ -136,7 +81,7 @@ begin
136 81 Append(HistoricoLog);
137 82 Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now) + '======================> Iniciando o Log <=======================');
138 83 end;
139   - DateTimeToString(strDataArqLocal, 'yyyymmdd', FileDateToDateTime(Fileage(p_path)));
  84 + DateTimeToString(strDataArqLocal, 'yyyymmdd', FileDateToDateTime(Fileage(v_path)));
140 85 DateTimeToString(strDataAtual , 'yyyymmdd', Date);
141 86 if (strDataAtual <> strDataArqLocal) then // Se o arquivo INI não é da data atual...
142 87 begin
... ... @@ -163,93 +108,6 @@ Begin
163 108 if v_Debugs then log_diario('(v.'+getVersionInfo(ParamStr(0))+') DEBUG - '+p_msg);
164 109 End;
165 110  
166   -// Pad a string with zeros so that it is a multiple of size
167   -function PadWithZeros(const str : string; size : integer) : string;
168   -var
169   - origsize, i : integer;
170   -begin
171   - Result := str;
172   - origsize := Length(Result);
173   - if ((origsize mod size) <> 0) or (origsize = 0) then
174   - begin
175   - SetLength(Result,((origsize div size)+1)*size);
176   - for i := origsize+1 to Length(Result) do
177   - Result[i] := #0;
178   - end;
179   -end;
180   -
181   -
182   -// Encrypt a string and return the Base64 encoded result
183   -function EnCrypt(p_Data : String) : String;
184   -var
185   - l_Cipher : TDCP_rijndael;
186   - l_Data, l_Key, l_IV : string;
187   -begin
188   - Try
189   - // Pad Key, IV and Data with zeros as appropriate
190   - l_Key := PadWithZeros(v_CipherKey,KeySize);
191   - l_IV := PadWithZeros(v_IV,BlockSize);
192   - l_Data := PadWithZeros(p_Data,BlockSize);
193   -
194   - // Create the cipher and initialise according to the key length
195   - l_Cipher := TDCP_rijndael.Create(nil);
196   - if Length(v_CipherKey) <= 16 then
197   - l_Cipher.Init(l_Key[1],128,@l_IV[1])
198   - else if Length(v_CipherKey) <= 24 then
199   - l_Cipher.Init(l_Key[1],192,@l_IV[1])
200   - else
201   - l_Cipher.Init(l_Key[1],256,@l_IV[1]);
202   -
203   - // Encrypt the data
204   - l_Cipher.EncryptCBC(l_Data[1],l_Data[1],Length(l_Data));
205   -
206   - // Free the cipher and clear sensitive information
207   - l_Cipher.Free;
208   - FillChar(l_Key[1],Length(l_Key),0);
209   -
210   - // Return the Base64 encoded result
211   - Result := Base64EncodeStr(l_Data);
212   - Except
213   - log_diario('Erro no Processo de Criptografia');
214   - End;
215   -end;
216   -
217   -function DeCrypt(p_Data : String) : String;
218   -var
219   - l_Cipher : TDCP_rijndael;
220   - l_Data, l_Key, l_IV : string;
221   -begin
222   - Try
223   - // Pad Key and IV with zeros as appropriate
224   - l_Key := PadWithZeros(v_CipherKey,KeySize);
225   - l_IV := PadWithZeros(v_IV,BlockSize);
226   -
227   - // Decode the Base64 encoded string
228   - l_Data := Base64DecodeStr(p_Data);
229   -
230   - // Create the cipher and initialise according to the key length
231   - l_Cipher := TDCP_rijndael.Create(nil);
232   - if Length(v_CipherKey) <= 16 then
233   - l_Cipher.Init(l_Key[1],128,@l_IV[1])
234   - else if Length(v_CipherKey) <= 24 then
235   - l_Cipher.Init(l_Key[1],192,@l_IV[1])
236   - else
237   - l_Cipher.Init(l_Key[1],256,@l_IV[1]);
238   -
239   - // Decrypt the data
240   - l_Cipher.DecryptCBC(l_Data[1],l_Data[1],Length(l_Data));
241   -
242   - // Free the cipher and clear sensitive information
243   - l_Cipher.Free;
244   - FillChar(l_Key[1],Length(l_Key),0);
245   -
246   - // Return the result
247   - Result := l_Data;
248   - Except
249   - log_diario('Erro no Processo de Decriptografia');
250   - End;
251   -end;
252   -
253 111 Function CipherClose(p_DatFileName : string) : String;
254 112 var v_strCipherOpenImploded : string;
255 113 v_DatFile : TextFile;
... ... @@ -270,8 +128,8 @@ begin
270 128 Append(v_DatFile);
271 129 End;
272 130  
273   - v_strCipherOpenImploded := Implode(v_tstrCipherOpened,v_SeparatorKey);
274   - v_strCipherClosed := EnCrypt(v_strCipherOpenImploded);
  131 + v_strCipherOpenImploded := g_oCacic.implode(v_tstrCipherOpened,g_oCacic.getSeparatorKey);
  132 + v_strCipherClosed := g_oCacic.enCrypt(v_strCipherOpenImploded);
275 133  
276 134 Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto}
277 135  
... ... @@ -302,12 +160,12 @@ begin
302 160 Readln(v_DatFile,v_strCipherClosed);
303 161 while not EOF(v_DatFile) do Readln(v_DatFile,v_strCipherClosed);
304 162 CloseFile(v_DatFile);
305   - v_strCipherOpened:= DeCrypt(v_strCipherClosed);
  163 + v_strCipherOpened:= g_oCacic.deCrypt(v_strCipherClosed);
306 164 end;
307 165 if (trim(v_strCipherOpened)<>'') then
308   - Result := explode(v_strCipherOpened,v_SeparatorKey)
  166 + Result := g_oCacic.explode(v_strCipherOpened,g_oCacic.getSeparatorKey)
309 167 else
310   - Result := explode('Configs.ID_SO' + v_SeparatorKey + g_oCacic.getWindowsStrId() +v_SeparatorKey+'Configs.Endereco_WS'+v_SeparatorKey+'/cacic2/ws/',v_SeparatorKey);
  168 + Result := g_oCacic.explode('Configs.ID_SO' + g_oCacic.getSeparatorKey + g_oCacic.getWindowsStrId() + g_oCacic.getSeparatorKey + 'Configs.Endereco_WS' + g_oCacic.getSeparatorKey + '/cacic2/ws/',g_oCacic.getSeparatorKey);
311 169  
312 170 if Result.Count mod 2 <> 0 then
313 171 Result.Add('');
... ... @@ -344,7 +202,7 @@ var RegEditSet: TRegistry;
344 202 ListaAuxSet : TStrings;
345 203 I : Integer;
346 204 begin
347   - ListaAuxSet := Explode(Chave, ');
  205 + ListaAuxSet := g_oCacic.explode(Chave, ');
348 206 strRootKey := ListaAuxSet[0];
349 207 For I := 1 To ListaAuxSet.Count - 2 Do strKey := strKey + ListaAuxSet[I] + '\';
350 208 strValue := ListaAuxSet[ListaAuxSet.Count - 1];
... ... @@ -402,7 +260,7 @@ var RegEditGet: TRegistry;
402 260 DataSize, Len, I : Integer;
403 261 begin
404 262 try
405   - ListaAuxGet := Explode(Chave, ');
  263 + ListaAuxGet := g_oCacic.explode(Chave, ');
406 264  
407 265 strRootKey := ListaAuxGet[0];
408 266 For I := 1 To ListaAuxGet.Count - 2 Do strKey := strKey + ListaAuxGet[I] + '\';
... ... @@ -484,7 +342,7 @@ var RegDelValorReg: TRegistry;
484 342 ListaAuxDel : TStrings;
485 343 I : Integer;
486 344 begin
487   - ListaAuxDel := Explode(Chave, ');
  345 + ListaAuxDel := g_oCacic.explode(Chave, ');
488 346 strRootKey := ListaAuxDel[0];
489 347 For I := 1 To ListaAuxDel.Count - 2 Do strKey := strKey + ListaAuxDel[I] + '\';
490 348 strValue := ListaAuxDel[ListaAuxDel.Count - 1];
... ... @@ -521,8 +379,6 @@ begin
521 379 Result := IntToStr(I1);
522 380 end;
523 381  
524   -
525   -
526 382 Function FTP(p_Host : String; p_Port : String; p_Username : String; p_Password : String; p_PathServer : String; p_File : String; p_Dest : String) : Boolean;
527 383 var IdFTP : TIdFTP;
528 384 msg_error : string;
... ... @@ -565,15 +421,6 @@ begin
565 421 End;
566 422 end;
567 423  
568   -
569   -function HomeDrive : string;
570   -var
571   -WinDir : array [0..144] of char;
572   -begin
573   -GetWindowsDirectory (WinDir, 144);
574   -Result := StrPas (WinDir);
575   -end;
576   -
577 424 function GetIP: string;
578 425 var ipwsa:TWSAData; p:PHostEnt; s:array[0..128] of char; c:pchar;
579 426 begin
... ... @@ -704,11 +551,11 @@ Begin
704 551 result := false;
705 552  
706 553 // Se o aguarde_CACIC.txt existir é porque refere-se a uma versão mais atual: 2.2.0.20 ou maior
707   - if (FileExists(Dir + '\aguarde_CACIC.txt')) then
  554 + if (FileExists(g_oCacic.getCacicPath + 'aguarde_CACIC.txt')) then
708 555 Begin
709 556 // Se eu conseguir matar o arquivo abaixo é porque não há outra sessão deste agente aberta... (POG? Nããão! :) )
710   - Matar(Dir,'aguarde_CACIC.txt');
711   - if (not (FileExists(Dir + '\aguarde_CACIC.txt'))) then
  557 + Matar(g_oCacic.getCacicPath,'aguarde_CACIC.txt');
  558 + if (not (FileExists(g_oCacic.getCacicPath + 'aguarde_CACIC.txt'))) then
712 559 result := true;
713 560 End;
714 561 End;
... ... @@ -720,7 +567,7 @@ var v_versao_REM,
720 567 v_array_NomeAgente : TStrings;
721 568 intAux : integer;
722 569 Begin
723   - v_array_NomeAgente := explode(p_strNomeAgente,');
  570 + v_array_NomeAgente := g_oCacic.explode(p_strNomeAgente,');
724 571  
725 572 v_versao_REM := XML_RetornaValor(StringReplace(StrUpper(PChar(v_array_NomeAgente[v_array_NomeAgente.count-1])),'.EXE','',[rfReplaceAll]), v_retorno);
726 573 v_versao_LOC := GetVersionInfo(p_strNomeAgente);
... ... @@ -779,7 +626,7 @@ procedure executa_chksis;
779 626 var
780 627 bool_download_CACIC2,
781 628 bool_ExistsAutoRun : boolean;
782   - v_home_drive, v_ip_serv_cacic, v_cacic_dir, v_rem_cacic_v0x,
  629 + v_ip_serv_cacic, v_cacic_dir, v_rem_cacic_v0x,
783 630 v_te_serv_updates, v_nu_porta_serv_updates, v_nm_usuario_login_serv_updates,
784 631 v_te_senha_login_serv_updates, v_te_path_serv_updates : String;
785 632 Request_Config : TStringList;
... ... @@ -789,19 +636,19 @@ var
789 636 begin
790 637  
791 638 bool_download_CACIC2 := false;
792   - v_home_drive := MidStr(HomeDrive,1,3); //x:\
793 639 v_ip_serv_cacic := GetValorChaveRegIni('Cacic2', 'ip_serv_cacic', ExtractFilePath(ParamStr(0)) + 'chksis.ini');
794   - v_cacic_dir := GetValorChaveRegIni('Cacic2', 'cacic_dir', ExtractFilePath(ParamStr(0)) + 'chksis.ini');
  640 + v_cacic_dir := GetValorChaveRegIni('Cacic2', 'cacic_dir' , ExtractFilePath(ParamStr(0)) + 'chksis.ini');
795 641 v_rem_cacic_v0x := GetValorChaveRegIni('Cacic2', 'rem_cacic_v0x', ExtractFilePath(ParamStr(0)) + 'chksis.ini');
796   - Dir := v_home_drive + v_cacic_dir;
  642 +
  643 + g_oCacic.setCacicPath(g_oCacic.getHomeDrive + v_cacic_dir +'\');
797 644  
798 645 v_Debugs := false;
799   - if DirectoryExists(v_cacic_dir + '\Temp\Debugs') then
  646 + if DirectoryExists(g_oCacic.getCacicPath + 'Temp\Debugs') then
800 647 Begin
801   - if (FormatDateTime('ddmmyyyy', GetFolderDate(v_cacic_dir + '\Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then
  648 + if (FormatDateTime('ddmmyyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then
802 649 Begin
803 650 v_Debugs := true;
804   - log_DEBUG('Pasta "' + v_cacic_dir + '\Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(v_cacic_dir + '\Temp\Debugs'))+' encontrada. DEBUG ativado.');
  651 + log_DEBUG('Pasta "' + g_oCacic.getCacicPath + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs'))+' encontrada. DEBUG ativado.');
805 652 End;
806 653 End;
807 654  
... ... @@ -813,36 +660,30 @@ begin
813 660 end;
814 661  
815 662 // Verifico a existência do diretório configurado para o Cacic, normalmente CACIC
816   - if not DirectoryExists(Dir) then
  663 + if not DirectoryExists(g_oCacic.getCacicPath) then
817 664 begin
818 665 //log_diario('Criando diretório ' + Dir,ExtractFilePath(ParamStr(0)));
819   - ForceDirectories(Dir);
  666 + ForceDirectories(g_oCacic.getCacicPath);
820 667 end;
821 668  
822 669 // Para eliminar versão 20014 e anteriores que provavelmente não fazem corretamente o AutoUpdate
823   - if not DirectoryExists(Dir+'\modulos') then
  670 + if not DirectoryExists(g_oCacic.getCacicPath+'modulos') then
824 671 begin
825   - log_diario('Excluindo '+ Dir + '\cacic2.exe');
826   - Matar(Dir,'\cacic2.exe');
827   - log_diario('Criando diretório ' + Dir + '\modulos');
828   - ForceDirectories(Dir + '\modulos');
  672 + log_diario('Excluindo '+ g_oCacic.getCacicPath + 'cacic2.exe');
  673 + Matar(g_oCacic.getCacicPath,'cacic2.exe');
  674 + log_diario('Criando diretório ' + g_oCacic.getCacicPath + 'modulos');
  675 + ForceDirectories(g_oCacic.getCacicPath + 'modulos');
829 676 end;
830 677  
831 678 // Crio o SubDiretório TEMP, caso não exista
832   - if not DirectoryExists(Dir+'\temp') then
  679 + if not DirectoryExists(g_oCacic.getCacicPath+'temp') then
833 680 begin
834   - log_diario('Criando diretório ' + Dir + '\temp');
835   - ForceDirectories(Dir + '\temp');
  681 + log_diario('Criando diretório ' + g_oCacic.getCacicPath + 'temp');
  682 + ForceDirectories(g_oCacic.getCacicPath + 'temp');
836 683 end;
837 684  
838   - //chave AES. Recomenda-se que cada empresa altere a sua chave.
839   - v_CipherKey := 'CacicBrasil';
840   - v_IV := 'abcdefghijklmnop';
841   - v_SeparatorKey := '=CacicIsFree=';
842   - v_DatFileName := Dir + '\cacic2.dat';
843   -
844 685 // Verifico existência dos dois principais objetos
845   - If (not FileExists(Dir + '\cacic2.exe')) or (not FileExists(Dir + '\modulos\ger_cols.exe')) Then
  686 + If (not FileExists(g_oCacic.getCacicPath + 'cacic2.exe')) or (not FileExists(g_oCacic.getCacicPath + 'modulos\ger_cols.exe')) Then
846 687 Begin
847 688 // Busco as configurações para acesso ao ambiente FTP - Updates
848 689 Request_Config := TStringList.Create;
... ... @@ -886,68 +727,68 @@ begin
886 727 Response_Config.Free;
887 728  
888 729 // Verificação de versão do cacic2.exe e exclusão em caso de versão antiga
889   - If (FileExists(Dir + '\cacic2.exe')) Then
  730 + If (FileExists(g_oCacic.getCacicPath + 'cacic2.exe')) Then
890 731 Begin
891   - intAux := ChecaVersoesAgentes(Dir + '\cacic2.exe');
  732 + intAux := ChecaVersoesAgentes(g_oCacic.getCacicPath + 'cacic2.exe');
892 733 // 0 => Arquivo de versões ou informação inexistente
893 734 // 1 => Versões iguais
894 735 // 2 => Versões diferentes
895 736 if (intAux = 0) then
896 737 Begin
897   - v_versao_local := StringReplace(trim(GetVersionInfo(Dir + '\cacic2.exe')),'.','',[rfReplaceAll]);
  738 + v_versao_local := StringReplace(trim(GetVersionInfo(g_oCacic.getCacicPath + 'cacic2.exe')),'.','',[rfReplaceAll]);
898 739 v_versao_remota := StringReplace(XML_RetornaValor('CACIC2' , v_retorno),'0103','',[rfReplaceAll]);
899 740 End;
900 741  
901 742 if (intAux = 2) or // Caso haja diferença na comparação de versões com "versoes_agentes.ini"...
902 743 (v_versao_local ='0000') or // Provavelmente versão muito antiga ou corrompida
903 744 (v_versao_local ='2208') then
904   - Matar(Dir, '\cacic2.exe');
  745 + Matar(g_oCacic.getCacicPath, 'cacic2.exe');
905 746 End;
906 747  
907 748 // Verificação de versão do ger_cols.exe e exclusão em caso de versão antiga
908   - If (FileExists(Dir + '\modulos\ger_cols.exe')) Then
  749 + If (FileExists(g_oCacic.getCacicPath + 'modulos\ger_cols.exe')) Then
909 750 Begin
910   - intAux := ChecaVersoesAgentes(Dir + '\modulos\ger_cols.exe');
  751 + intAux := ChecaVersoesAgentes(g_oCacic.getCacicPath + 'modulos\ger_cols.exe');
911 752 // 0 => Arquivo de versões ou informação inexistente
912 753 // 1 => Versões iguais
913 754 // 2 => Versões diferentes
914 755 if (intAux = 0) then
915 756 Begin
916   - v_versao_local := StringReplace(trim(GetVersionInfo(Dir + '\modulos\ger_cols.exe')),'.','',[rfReplaceAll]);
  757 + v_versao_local := StringReplace(trim(GetVersionInfo(g_oCacic.getCacicPath + 'modulos\ger_cols.exe')),'.','',[rfReplaceAll]);
917 758 v_versao_remota := StringReplace(XML_RetornaValor('GER_COLS' , v_retorno),'0103','',[rfReplaceAll]);
918 759 End;
919 760  
920 761 if (intAux = 2) or // Caso haja diferença na comparação de versões com "versoes_agentes.ini"...
921 762 (v_versao_local ='0000') then // Provavelmente versão muito antiga ou corrompida
922   - Matar(Dir + '\modulos, 'ger_cols.exe');
  763 + Matar(g_oCacic.getCacicPath + 'modulos, 'ger_cols.exe');
923 764  
924 765 End;
925 766  
926 767  
927 768 // Tento detectar o Agente Principal e faço FTP caso não exista
928   - If not FileExists(Dir + '\cacic2.exe') Then
  769 + If not FileExists(g_oCacic.getCacicPath + 'cacic2.exe') Then
929 770 begin
930 771 log_diario('Fazendo FTP de cacic2.exe a partir de ' + v_te_serv_updates + '/' +
931 772 v_nu_porta_serv_updates+'/'+
932 773 v_nm_usuario_login_serv_updates + '/' +
933   - v_te_path_serv_updates + ' para a pasta ' + Dir);
  774 + v_te_path_serv_updates + ' para a pasta ' + g_oCacic.getCacicPath);
934 775 FTP(v_te_serv_updates,
935 776 v_nu_porta_serv_updates,
936 777 v_nm_usuario_login_serv_updates,
937 778 v_te_senha_login_serv_updates,
938 779 v_te_path_serv_updates,
939 780 'cacic2.exe',
940   - Dir);
  781 + g_oCacic.getCacicPath);
941 782 bool_download_CACIC2 := true;
942 783 end;
943 784  
944 785 // Tento detectar o Gerente de Coletas e faço FTP caso não exista
945   - If (not FileExists(Dir + '\modulos\ger_cols.exe')) Then
  786 + If (not FileExists(g_oCacic.getCacicPath + 'modulos\ger_cols.exe')) Then
946 787 begin
947 788 log_diario('Fazendo FTP de ger_cols.exe a partir de ' + v_te_serv_updates + '/' +
948 789 v_nu_porta_serv_updates+'/'+
949 790 v_nm_usuario_login_serv_updates + '/' +
950   - v_te_path_serv_updates + ' para a pasta ' + Dir + '\modulos');
  791 + v_te_path_serv_updates + ' para a pasta ' + g_oCacic.getCacicPath + 'modulos');
951 792  
952 793 FTP(v_te_serv_updates,
953 794 v_nu_porta_serv_updates,
... ... @@ -955,7 +796,7 @@ begin
955 796 v_te_senha_login_serv_updates,
956 797 v_te_path_serv_updates,
957 798 'ger_cols.exe',
958   - Dir + '\modulos');
  799 + g_oCacic.getCacicPath + 'modulos');
959 800 end;
960 801  
961 802  
... ... @@ -988,13 +829,13 @@ begin
988 829 // Caso o Cacic tenha sido baixado executo-o com parâmetro de configuração de servidor
989 830 if Posso_Rodar_CACIC or not bool_ExistsAutoRun then
990 831 Begin
991   - log_diario('Executando '+Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic);
  832 + log_diario('Executando '+g_oCacic.getCacicPath + 'cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic);
992 833  
993 834 // Caso tenha havido download de agentes principais, executar coletas imediatamente...
994 835 if (bool_download_CACIC2) then
995   - WinExec(PChar(Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic+ ' /execute'), SW_HIDE)
  836 + WinExec(PChar(g_oCacic.getCacicPath + 'cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic+ ' /execute'), SW_HIDE)
996 837 else
997   - WinExec(PChar(Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic ), SW_HIDE);
  838 + WinExec(PChar(g_oCacic.getCacicPath + 'cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic ), SW_HIDE);
998 839 End;
999 840 end;
1000 841  
... ...
col_anvi/col_anvi.dpr
... ... @@ -26,16 +26,9 @@ uses
26 26 TLHELP32,
27 27 ShellAPI,
28 28 PJVersionInfo,
29   - DCPcrypt2,
30   - DCPrijndael,
31   - DCPbase64,
32 29 CACIC_Library in '..\CACIC_Library.pas';
33 30  
34   -var p_path_cacic,
35   - v_CipherKey,
36   - v_IV,
37   - v_strCipherClosed,
38   - v_DatFileName : String;
  31 +var v_strCipherClosed : String;
39 32  
40 33 var v_Debugs : boolean;
41 34  
... ... @@ -45,11 +38,6 @@ var v_tstrCipherOpened,
45 38 var
46 39 g_oCacic : TCACIC;
47 40  
48   -// Some constants that are dependant on the cipher being used
49   -// Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize)
50   -const KeySize = 32; // 32 bytes = 256 bits
51   - BlockSize = 16; // 16 bytes = 128 bits
52   -
53 41 function VerFmt(const MS, LS: DWORD): string;
54 42 // Format the version number from the given DWORDs containing the info
55 43 begin
... ... @@ -57,24 +45,14 @@ begin
57 45 [HiWord(MS), LoWord(MS), HiWord(LS), LoWord(LS)])
58 46 end;
59 47  
60   -{ TMainForm }
61   -{ TMainForm }
62   -function HomeDrive : string;
63   -var
64   -WinDir : array [0..144] of char;
65   -begin
66   -GetWindowsDirectory (WinDir, 144);
67   -Result := StrPas (WinDir);
68   -end;
69   -
70 48 procedure log_diario(strMsg : String);
71 49 var
72 50 HistoricoLog : TextFile;
73 51 strDataArqLocal, strDataAtual : string;
74 52 begin
75 53 try
76   - FileSetAttr (p_path_cacic + 'cacic2.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
77   - AssignFile(HistoricoLog,p_path_cacic + 'cacic2.log'); {Associa o arquivo a uma variável do tipo TextFile}
  54 + FileSetAttr (g_oCacic.getCacicPath + '\cacic2.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
  55 + AssignFile(HistoricoLog,g_oCacic.getCacicPath + '\cacic2.log'); {Associa o arquivo a uma variável do tipo TextFile}
78 56 {$IOChecks off}
79 57 Reset(HistoricoLog); {Abre o arquivo texto}
80 58 {$IOChecks on}
... ... @@ -84,7 +62,7 @@ begin
84 62 Append(HistoricoLog);
85 63 Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now) + '======================> Iniciando o Log do CACIC <=======================');
86 64 end;
87   - DateTimeToString(strDataArqLocal, 'yyyymmdd', FileDateToDateTime(Fileage(p_path_cacic + 'cacic2.log')));
  65 + DateTimeToString(strDataArqLocal, 'yyyymmdd', FileDateToDateTime(Fileage(g_oCacic.getCacicPath + '\cacic2.log')));
88 66 DateTimeToString(strDataAtual , 'yyyymmdd', Date);
89 67 if (strDataAtual <> strDataArqLocal) then // Se o arquivo INI não é da data atual...
90 68 begin
... ... @@ -127,92 +105,6 @@ begin
127 105 end;
128 106 end;
129 107  
130   -
131   -// Encrypt a string and return the Base64 encoded result
132   -function EnCrypt(p_Data : String) : String;
133   -var
134   - l_Cipher : TDCP_rijndael;
135   - l_Data, l_Key, l_IV : string;
136   -begin
137   - Try
138   - // Pad Key, IV and Data with zeros as appropriate
139   - l_Key := PadWithZeros(v_CipherKey,KeySize);
140   - l_IV := PadWithZeros(v_IV,BlockSize);
141   - l_Data := PadWithZeros(p_Data,BlockSize);
142   -
143   - // Create the cipher and initialise according to the key length
144   - l_Cipher := TDCP_rijndael.Create(nil);
145   - if Length(v_CipherKey) <= 16 then
146   - l_Cipher.Init(l_Key[1],128,@l_IV[1])
147   - else if Length(v_CipherKey) <= 24 then
148   - l_Cipher.Init(l_Key[1],192,@l_IV[1])
149   - else
150   - l_Cipher.Init(l_Key[1],256,@l_IV[1]);
151   -
152   - // Encrypt the data
153   - l_Cipher.EncryptCBC(l_Data[1],l_Data[1],Length(l_Data));
154   -
155   - // Free the cipher and clear sensitive information
156   - l_Cipher.Free;
157   - FillChar(l_Key[1],Length(l_Key),0);
158   -
159   - // Return the Base64 encoded result
160   - Result := Base64EncodeStr(l_Data);
161   - Except
162   - log_diario('Erro no Processo de Criptografia');
163   - End;
164   -end;
165   -
166   -function DeCrypt(p_Data : String) : String;
167   -var
168   - l_Cipher : TDCP_rijndael;
169   - l_Data, l_Key, l_IV : string;
170   -begin
171   - Try
172   - // Pad Key and IV with zeros as appropriate
173   - l_Key := PadWithZeros(v_CipherKey,KeySize);
174   - l_IV := PadWithZeros(v_IV,BlockSize);
175   -
176   - // Decode the Base64 encoded string
177   - l_Data := Base64DecodeStr(p_Data);
178   -
179   - // Create the cipher and initialise according to the key length
180   - l_Cipher := TDCP_rijndael.Create(nil);
181   - if Length(v_CipherKey) <= 16 then
182   - l_Cipher.Init(l_Key[1],128,@l_IV[1])
183   - else if Length(v_CipherKey) <= 24 then
184   - l_Cipher.Init(l_Key[1],192,@l_IV[1])
185   - else
186   - l_Cipher.Init(l_Key[1],256,@l_IV[1]);
187   -
188   - // Decrypt the data
189   - l_Cipher.DecryptCBC(l_Data[1],l_Data[1],Length(l_Data));
190   -
191   - // Free the cipher and clear sensitive information
192   - l_Cipher.Free;
193   - FillChar(l_Key[1],Length(l_Key),0);
194   -
195   - // Return the result
196   - Result := l_Data;
197   - Except
198   - log_diario('Erro no Processo de Decriptografia');
199   - End;
200   -end;
201   -
202   -Function Implode(p_Array : TStrings ; p_Separador : String) : String;
203   -var intAux : integer;
204   - strAux : string;
205   -Begin
206   -//log_diario('IMPLODE - Tamanho de p_Array='+inttostr(p_array.Count));
207   - strAux := '';
208   - For intAux := 0 To p_Array.Count -1 do
209   - Begin
210   - if (strAux<>'') then strAux := strAux + p_Separador;
211   - strAux := strAux + p_Array[intAux];
212   - End;
213   - Result := strAux;
214   -end;
215   -
216 108 Procedure CipherClose(p_DatFileName : string; p_tstrCipherOpened : TStrings);
217 109 var v_strCipherOpenImploded : string;
218 110 v_DatFile : TextFile;
... ... @@ -225,50 +117,14 @@ begin
225 117 Rewrite (v_DatFile);
226 118 Append(v_DatFile);
227 119  
228   - //v_Cipher := TDCP_rijndael.Create(nil);
229   - //v_Cipher.InitStr(v_CipherKey,TDCP_md5);
230   - v_strCipherOpenImploded := Implode(p_tstrCipherOpened,'=CacicIsFree=');
231   -// v_strCipherClosed := v_Cipher.EncryptString(v_strCipherOpenImploded);
232   - v_strCipherClosed := EnCrypt(v_strCipherOpenImploded);
233   -// v_Cipher.Burn;
234   -// v_Cipher.Free;
  120 + v_strCipherOpenImploded := g_oCacic.implode(p_tstrCipherOpened,g_oCacic.getSeparatorKey);
  121 + v_strCipherClosed := g_oCacic.enCrypt(v_strCipherOpenImploded);
235 122 Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto}
236 123 CloseFile(v_DatFile);
237 124 except
238 125 end;
239 126 end;
240 127  
241   -Function Explode(Texto, Separador : String) : TStrings;
242   -var
243   - strItem : String;
244   - ListaAuxUTILS : TStrings;
245   - NumCaracteres,
246   - TamanhoSeparador,
247   - I : Integer;
248   -Begin
249   - ListaAuxUTILS := TStringList.Create;
250   - strItem := '';
251   - NumCaracteres := Length(Texto);
252   - TamanhoSeparador := Length(Separador);
253   - I := 1;
254   - While I <= NumCaracteres Do
255   - Begin
256   - If (Copy(Texto,I,TamanhoSeparador) = Separador) or (I = NumCaracteres) Then
257   - Begin
258   - if (I = NumCaracteres) then strItem := strItem + Texto[I];
259   - ListaAuxUTILS.Add(trim(strItem));
260   - strItem := '';
261   - I := I + (TamanhoSeparador-1);
262   - end
263   - Else
264   - strItem := strItem + Texto[I];
265   -
266   - I := I + 1;
267   - End;
268   - Explode := ListaAuxUTILS;
269   -end;
270   -
271   -
272 128 Function CipherOpen(p_DatFileName : string) : TStrings;
273 129 var v_DatFile : TextFile;
274 130 v_strCipherOpened,
... ... @@ -290,12 +146,12 @@ begin
290 146 Readln(v_DatFile,v_strCipherClosed);
291 147 while not EOF(v_DatFile) do Readln(v_DatFile,v_strCipherClosed);
292 148 CloseFile(v_DatFile);
293   - v_strCipherOpened:= DeCrypt(v_strCipherClosed);
  149 + v_strCipherOpened:= g_oCacic.deCrypt(v_strCipherClosed);
294 150 end;
295 151 if (trim(v_strCipherOpened)<>'') then
296   - Result := explode(v_strCipherOpened,'=CacicIsFree=')
  152 + Result := g_oCacic.explode(v_strCipherOpened,g_oCacic.getSeparatorKey)
297 153 else
298   - Result := explode('Configs.ID_SO=CacicIsFree='+ g_oCacic.getWindowsStrId() +'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree=');
  154 + Result := g_oCacic.explode('Configs.ID_SO'+g_oCacic.getSeparatorKey+ g_oCacic.getWindowsStrId() + g_oCacic.getSeparatorKey + 'Configs.Endereco_WS'+g_oCacic.getSeparatorKey+'/cacic2/ws/',g_oCacic.getSeparatorKey);
299 155  
300 156 if Result.Count mod 2 <> 0 then
301 157 Result.Add('');
... ... @@ -349,7 +205,7 @@ var RegEditGet: TRegistry;
349 205 begin
350 206 try
351 207 Result := '';
352   - ListaAuxGet := Explode(Chave, ');
  208 + ListaAuxGet := g_oCacic.explode(Chave, ');
353 209  
354 210 strRootKey := ListaAuxGet[0];
355 211 For I := 1 To ListaAuxGet.Count - 2 Do strKey := strKey + ListaAuxGet[I] + '\';
... ... @@ -454,7 +310,7 @@ begin
454 310 If FileExists(strDirTrend + '\filter32.vxd') Then
455 311 Begin
456 312 // Em máquinas Windows 9X a versão do engine e do pattern não são gravadas no registro. Tenho que pegar direto dos arquivos.
457   - Lista2_RCO := Explode(getVersionInfo(strDirTrend + 'filter32.vxd'), '.'); // Pego só os dois primeiros dígitos. Por exemplo: 6.640.0.1001 vira 6.640.
  313 + Lista2_RCO := g_oCacic.explode(getVersionInfo(strDirTrend + 'filter32.vxd'), '.'); // Pego só os dois primeiros dígitos. Por exemplo: 6.640.0.1001 vira 6.640.
458 314 nu_versao_engine := Lista2_RCO[0] + '.' + Lista2_RCO[1];
459 315 Lista2_RCO.Free;
460 316 end
... ... @@ -517,24 +373,25 @@ begin
517 373 SetValorDatMemoria('Col_Anvi.te_servidor' , te_servidor , v_tstrCipherOpened1);
518 374 SetValorDatMemoria('Col_Anvi.in_ativo' , in_ativo , v_tstrCipherOpened1);
519 375 SetValorDatMemoria('Col_Anvi.UVC' , UVC , v_tstrCipherOpened1);
520   - CipherClose(p_path_cacic + 'temp\col_anvi.dat' , v_tstrCipherOpened1);
  376 + CipherClose(g_oCacic.getCacicPath + '\temp\col_anvi.dat' , v_tstrCipherOpened1);
521 377 end
522 378 else
523 379 Begin
524 380 SetValorDatMemoria('Col_Anvi.nada', 'nada', v_tstrCipherOpened1);
525   - CipherClose(p_path_cacic + 'temp\col_anvi.dat', v_tstrCipherOpened1);
  381 + CipherClose(g_oCacic.getCacicPath + '\temp\col_anvi.dat', v_tstrCipherOpened1);
526 382 End;
527 383 Except
528 384 Begin
529 385 SetValorDatMemoria('Col_Anvi.nada', 'nada', v_tstrCipherOpened1);
530 386 SetValorDatMemoria('Col_Anvi.Fim', '99999999', v_tstrCipherOpened1);
531   - CipherClose(p_path_cacic + 'temp\col_anvi.dat', v_tstrCipherOpened1);
  387 + CipherClose(g_oCacic.getCacicPath + '\temp\col_anvi.dat', v_tstrCipherOpened1);
532 388 End;
533 389 End;
534 390 end;
535 391  
536 392 var tstrTripa1 : TStrings;
537 393 intAux : integer;
  394 + v_path_cacic : String;
538 395 const
539 396 CACIC_APP_NAME = 'col_anvi';
540 397  
... ... @@ -544,50 +401,38 @@ begin
544 401 if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) ) then
545 402 if (ParamCount>0) then
546 403 Begin
547   - For intAux := 1 to ParamCount do
548   - Begin
549   - if LowerCase(Copy(ParamStr(intAux),1,13)) = '/p_cipherkey=' then
550   - v_CipherKey := Trim(Copy(ParamStr(intAux),14,Length((ParamStr(intAux)))));
  404 + //Pegarei o nível anterior do diretório, que deve ser, por exemplo \Cacic, para leitura do cacic2.ini
  405 + tstrTripa1 := g_oCacic.explode(ExtractFilePath(ParamStr(0)),'\');
  406 + v_path_cacic := '';
  407 + For intAux := 0 to tstrTripa1.Count -2 do
  408 + v_path_cacic := v_path_cacic + tstrTripa1[intAux] + '\';
  409 +
  410 + g_oCacic.setCacicPath(v_path_cacic);
  411 +
  412 + v_Debugs := false;
  413 + if DirectoryExists(g_oCacic.getCacicPath + 'Temp\Debugs') then
  414 + Begin
  415 + if (FormatDateTime('ddmmyyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then
  416 + Begin
  417 + v_Debugs := true;
  418 + log_diario('Pasta "' + g_oCacic.getCacicPath + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs'))+' encontrada. DEBUG ativado.');
  419 + End;
551 420 End;
  421 +
  422 + v_tstrCipherOpened := TStrings.Create;
  423 + v_tstrCipherOpened := CipherOpen(g_oCacic.getDatFileName);
552 424  
553   - if (trim(v_CipherKey)<>'') then
  425 + v_tstrCipherOpened1 := TStrings.Create;
  426 + v_tstrCipherOpened1 := CipherOpen(g_oCacic.getCacicPath + 'temp\col_anvi.dat');
  427 +
  428 + Try
  429 + Executa_Col_Anvi;
  430 + Except
554 431 Begin
555   - //Pegarei o nível anterior do diretório, que deve ser, por exemplo \Cacic, para leitura do cacic2.ini
556   - tstrTripa1 := explode(ExtractFilePath(ParamStr(0)),'\');
557   - p_path_cacic := '';
558   - For intAux := 0 to tstrTripa1.Count -2 do
559   - begin
560   - p_path_cacic := p_path_cacic + tstrTripa1[intAux] + '\';
561   - end;
562   -
563   - v_Debugs := false;
564   - if DirectoryExists(p_path_cacic + 'Temp\Debugs') then
565   - Begin
566   - if (FormatDateTime('ddmmyyyy', GetFolderDate(p_path_cacic + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then
567   - Begin
568   - v_Debugs := true;
569   - log_diario('Pasta "' + p_path_cacic + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(p_path_cacic + 'Temp\Debugs'))+' encontrada. DEBUG ativado.');
570   - End;
571   - End;
572   -
573   - // A chave AES foi obtida no parâmetro p_CipherKey. Recomenda-se que cada empresa altere a sua chave.
574   - v_IV := 'abcdefghijklmnop';
575   - v_DatFileName := p_path_cacic + 'cacic2.dat';
576   - v_tstrCipherOpened := TStrings.Create;
577   - v_tstrCipherOpened := CipherOpen(v_DatFileName);
578   -
579   - v_tstrCipherOpened1 := TStrings.Create;
580   - v_tstrCipherOpened1 := CipherOpen(p_path_cacic + 'temp\col_anvi.dat');
581   -
582   - Try
583   - Executa_Col_Anvi;
584   - Except
585   - Begin
586   - SetValorDatMemoria('Col_Anvi.nada', 'nada', v_tstrCipherOpened1);
587   - CipherClose(p_path_cacic + 'temp\col_anvi.dat', v_tstrCipherOpened1);
588   - End;
589   - End;
  432 + SetValorDatMemoria('Col_Anvi.nada', 'nada', v_tstrCipherOpened1);
  433 + CipherClose(g_oCacic.getCacicPath + 'temp\col_anvi.dat', v_tstrCipherOpened1);
590 434 End;
  435 + End;
591 436 End;
592 437 g_oCacic.Free();
593 438 end.
... ...
col_comp/col_comp.dpr
... ... @@ -23,56 +23,23 @@ uses
23 23 SysUtils,
24 24 Classes,
25 25 Registry,
26   - DCPcrypt2,
27   - DCPrijndael,
28   - DCPbase64,
29 26 CACIC_Library in '..\CACIC_Library.pas';
30 27  
31   -var p_path_cacic : string;
32   - v_CipherKey,
33   - v_IV,
34   - v_strCipherClosed,
35   - v_DatFileName : String;
  28 +var v_strCipherClosed : String;
36 29  
37 30 var v_tstrCipherOpened,
38 31 v_tstrCipherOpened1 : TStrings;
39 32  
40 33 var g_oCacic : TCACIC;
41 34  
42   -// Some constants that are dependant on the cipher being used
43   -// Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize)
44   -const KeySize = 32; // 32 bytes = 256 bits
45   - BlockSize = 16; // 16 bytes = 128 bits
46   -
47   -function HomeDrive : string;
48   -var
49   -WinDir : array [0..144] of char;
50   -begin
51   -GetWindowsDirectory (WinDir, 144);
52   -Result := StrPas (WinDir);
53   -end;
54   -
55   -Function Implode(p_Array : TStrings ; p_Separador : String) : String;
56   -var intAux : integer;
57   - strAux : string;
58   -Begin
59   - strAux := '';
60   - For intAux := 0 To p_Array.Count -1 do
61   - Begin
62   - if (strAux<>'') then strAux := strAux + p_Separador;
63   - strAux := strAux + p_Array[intAux];
64   - End;
65   - Implode := strAux;
66   -end;
67   -
68 35 procedure log_diario(strMsg : String);
69 36 var
70 37 HistoricoLog : TextFile;
71 38 strDataArqLocal, strDataAtual : string;
72 39 begin
73 40 try
74   - FileSetAttr (p_path_cacic + 'cacic2.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
75   - AssignFile(HistoricoLog,p_path_cacic + 'cacic2.log'); {Associa o arquivo a uma variável do tipo TextFile}
  41 + FileSetAttr (g_oCacic.getCacicPath + 'cacic2.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
  42 + AssignFile(HistoricoLog,g_oCacic.getCacicPath + 'cacic2.log'); {Associa o arquivo a uma variável do tipo TextFile}
76 43 {$IOChecks off}
77 44 Reset(HistoricoLog); {Abre o arquivo texto}
78 45 {$IOChecks on}
... ... @@ -82,7 +49,7 @@ begin
82 49 Append(HistoricoLog);
83 50 Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now) + '======================> Iniciando o Log do CACIC <=======================');
84 51 end;
85   - DateTimeToString(strDataArqLocal, 'yyyymmdd', FileDateToDateTime(Fileage(p_path_cacic + 'cacic2.log')));
  52 + DateTimeToString(strDataArqLocal, 'yyyymmdd', FileDateToDateTime(Fileage(g_oCacic.getCacicPath + 'cacic2.log')));
86 53 DateTimeToString(strDataAtual , 'yyyymmdd', Date);
87 54 if (strDataAtual <> strDataArqLocal) then // Se o arquivo INI não é da data atual...
88 55 begin
... ... @@ -98,92 +65,6 @@ begin
98 65 log_diario('Erro na gravação do log!');
99 66 end;
100 67 end;
101   -// Pad a string with zeros so that it is a multiple of size
102   -function PadWithZeros(const str : string; size : integer) : string;
103   -var
104   - origsize, i : integer;
105   -begin
106   - Result := str;
107   - origsize := Length(Result);
108   - if ((origsize mod size) <> 0) or (origsize = 0) then
109   - begin
110   - SetLength(Result,((origsize div size)+1)*size);
111   - for i := origsize+1 to Length(Result) do
112   - Result[i] := #0;
113   - end;
114   -end;
115   -
116   -
117   -// Encrypt a string and return the Base64 encoded result
118   -function EnCrypt(p_Data : String) : String;
119   -var
120   - l_Cipher : TDCP_rijndael;
121   - l_Data, l_Key, l_IV : string;
122   -begin
123   - Try
124   - // Pad Key, IV and Data with zeros as appropriate
125   - l_Key := PadWithZeros(v_CipherKey,KeySize);
126   - l_IV := PadWithZeros(v_IV,BlockSize);
127   - l_Data := PadWithZeros(p_Data,BlockSize);
128   -
129   - // Create the cipher and initialise according to the key length
130   - l_Cipher := TDCP_rijndael.Create(nil);
131   - if Length(v_CipherKey) <= 16 then
132   - l_Cipher.Init(l_Key[1],128,@l_IV[1])
133   - else if Length(v_CipherKey) <= 24 then
134   - l_Cipher.Init(l_Key[1],192,@l_IV[1])
135   - else
136   - l_Cipher.Init(l_Key[1],256,@l_IV[1]);
137   -
138   - // Encrypt the data
139   - l_Cipher.EncryptCBC(l_Data[1],l_Data[1],Length(l_Data));
140   -
141   - // Free the cipher and clear sensitive information
142   - l_Cipher.Free;
143   - FillChar(l_Key[1],Length(l_Key),0);
144   -
145   - // Return the Base64 encoded result
146   - Result := Base64EncodeStr(l_Data);
147   - Except
148   - log_diario('Erro no Processo de Criptografia');
149   - End;
150   -end;
151   -
152   -function DeCrypt(p_Data : String) : String;
153   -var
154   - l_Cipher : TDCP_rijndael;
155   - l_Data, l_Key, l_IV : string;
156   -begin
157   - Try
158   - // Pad Key and IV with zeros as appropriate
159   - l_Key := PadWithZeros(v_CipherKey,KeySize);
160   - l_IV := PadWithZeros(v_IV,BlockSize);
161   -
162   - // Decode the Base64 encoded string
163   - l_Data := Base64DecodeStr(p_Data);
164   -
165   - // Create the cipher and initialise according to the key length
166   - l_Cipher := TDCP_rijndael.Create(nil);
167   - if Length(v_CipherKey) <= 16 then
168   - l_Cipher.Init(l_Key[1],128,@l_IV[1])
169   - else if Length(v_CipherKey) <= 24 then
170   - l_Cipher.Init(l_Key[1],192,@l_IV[1])
171   - else
172   - l_Cipher.Init(l_Key[1],256,@l_IV[1]);
173   -
174   - // Decrypt the data
175   - l_Cipher.DecryptCBC(l_Data[1],l_Data[1],Length(l_Data));
176   -
177   - // Free the cipher and clear sensitive information
178   - l_Cipher.Free;
179   - FillChar(l_Key[1],Length(l_Key),0);
180   -
181   - // Return the result
182   - Result := l_Data;
183   - Except
184   - log_diario('Erro no Processo de Decriptografia');
185   - End;
186   -end;
187 68  
188 69 Function CipherClose(p_DatFileName : string; p_tstrCipherOpened : TStrings) : String;
189 70 var v_strCipherOpenImploded : string;
... ... @@ -197,45 +78,14 @@ begin
197 78 Rewrite (v_DatFile);
198 79 Append(v_DatFile);
199 80  
200   - v_strCipherOpenImploded := Implode(p_tstrCipherOpened,'=CacicIsFree=');
201   - v_strCipherClosed := EnCrypt(v_strCipherOpenImploded);
  81 + v_strCipherOpenImploded := g_oCacic.implode(p_tstrCipherOpened,g_oCacic.getSeparatorKey);
  82 + v_strCipherClosed := g_oCacic.enCrypt(v_strCipherOpenImploded);
202 83 Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto}
203 84 CloseFile(v_DatFile);
204 85 except
205 86 end;
206 87 end;
207 88  
208   -Function Explode(Texto, Separador : String) : TStrings;
209   -var
210   - strItem : String;
211   - ListaAuxUTILS : TStrings;
212   - NumCaracteres,
213   - TamanhoSeparador,
214   - I : Integer;
215   -Begin
216   - ListaAuxUTILS := TStringList.Create;
217   - strItem := '';
218   - NumCaracteres := Length(Texto);
219   - TamanhoSeparador := Length(Separador);
220   - I := 1;
221   - While I <= NumCaracteres Do
222   - Begin
223   - If (Copy(Texto,I,TamanhoSeparador) = Separador) or (I = NumCaracteres) Then
224   - Begin
225   - if (I = NumCaracteres) then strItem := strItem + Texto[I];
226   - ListaAuxUTILS.Add(trim(strItem));
227   - strItem := '';
228   - I := I + (TamanhoSeparador-1);
229   - end
230   - Else
231   - strItem := strItem + Texto[I];
232   -
233   - I := I + 1;
234   - End;
235   - Explode := ListaAuxUTILS;
236   -end;
237   -
238   -
239 89 Function CipherOpen(p_DatFileName : string) : TStrings;
240 90 var v_DatFile : TextFile;
241 91 v_strCipherOpened,
... ... @@ -257,12 +107,12 @@ begin
257 107 Readln(v_DatFile,v_strCipherClosed);
258 108 while not EOF(v_DatFile) do Readln(v_DatFile,v_strCipherClosed);
259 109 CloseFile(v_DatFile);
260   - v_strCipherOpened:= DeCrypt(v_strCipherClosed);
  110 + v_strCipherOpened:= g_oCacic.deCrypt(v_strCipherClosed);
261 111 end;
262 112 if (trim(v_strCipherOpened)<>'') then
263   - Result := explode(v_strCipherOpened,'=CacicIsFree=')
  113 + Result := g_oCacic.explode(v_strCipherOpened,g_oCacic.getSeparatorKey)
264 114 else
265   - Result := explode('Configs.ID_SO=CacicIsFree='+ g_oCacic.getWindowsStrId() +'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree=');
  115 + Result := g_oCacic.explode('Configs.ID_SO'+g_oCacic.getSeparatorKey+g_oCacic.getWindowsStrId() +g_oCacic.getSeparatorKey+'Configs.Endereco_WS'+g_oCacic.getSeparatorKey+'/cacic2/ws/',g_oCacic.getSeparatorKey);
266 116  
267 117  
268 118 if Result.Count mod 2 <> 0 then
... ... @@ -322,7 +172,7 @@ var RegEditGet: TRegistry;
322 172 begin
323 173 try
324 174 Result := '';
325   - ListaAuxGet := Explode(Chave, ');
  175 + ListaAuxGet := g_oCacic.explode(Chave, ');
326 176  
327 177 strRootKey := ListaAuxGet[0];
328 178 For I := 1 To ListaAuxGet.Count - 2 Do strKey := strKey + ListaAuxGet[I] + '\';
... ... @@ -475,68 +325,55 @@ Begin
475 325 (strTripaDados <> '') Then
476 326 Begin
477 327 SetValorDatMemoria('Col_Comp.UVC', strTripaDados, v_tstrCipherOpened1);
478   - CipherClose(p_path_cacic + 'temp\col_comp.dat', v_tstrCipherOpened1);
  328 + CipherClose(g_oCacic.getCacicPath + 'temp\col_comp.dat', v_tstrCipherOpened1);
479 329 End
480 330 else
481 331 SetValorDatMemoria('Col_Comp.nada', 'nada', v_tstrCipherOpened1);
482 332  
483   - CipherClose(p_path_cacic + 'temp\col_comp.dat', v_tstrCipherOpened1);
  333 + CipherClose(g_oCacic.getCacicPath + 'temp\col_comp.dat', v_tstrCipherOpened1);
484 334 End;
485 335 Except
486 336 Begin
487 337 SetValorDatMemoria('Col_Comp.nada', 'nada', v_tstrCipherOpened1);
488 338 SetValorDatMemoria('Col_Comp.Fim', '99999999', v_tstrCipherOpened1);
489   - CipherClose(p_path_cacic + 'temp\col_comp.dat', v_tstrCipherOpened1);
  339 + CipherClose(g_oCacic.getCacicPath + 'temp\col_comp.dat', v_tstrCipherOpened1);
490 340 End;
491 341 End;
492 342 end;
493 343  
494 344 var tstrTripa1 : TStrings;
495 345 intAux : integer;
  346 + v_path_cacic : String;
  347 +
496 348 const
497 349 CACIC_APP_NAME = 'col_comp';
498 350  
499   -var
500   - hwind:HWND;
501   -
502 351 begin
503 352 g_oCacic := TCACIC.Create();
504 353 if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) ) then
505 354 if (ParamCount>0) then
506 355 Begin
507   - For intAux := 1 to ParamCount do
508   - Begin
509   - if LowerCase(Copy(ParamStr(intAux),1,13)) = '/p_cipherkey=' then
510   - v_CipherKey := Trim(Copy(ParamStr(intAux),14,Length((ParamStr(intAux)))));
511   - End;
512   -
513   - if (trim(v_CipherKey)<>'') then
514   - Begin
515   - //Pegarei o nível anterior do diretório, que deve ser, por exemplo \Cacic, para leitura do cacic2.ini
516   - tstrTripa1 := explode(ExtractFilePath(ParamStr(0)),'\');
517   - p_path_cacic := '';
518   - For intAux := 0 to tstrTripa1.Count -2 do
519   - begin
520   - p_path_cacic := p_path_cacic + tstrTripa1[intAux] + '\';
521   - end;
522   -
523   - // A chave AES foi obtida no parâmetro p_CipherKey. Recomenda-se que cada empresa altere a sua chave.
524   - v_IV := 'abcdefghijklmnop';
525   - v_DatFileName := p_path_cacic + 'cacic2.dat';
526   - v_tstrCipherOpened := TStrings.Create;
527   - v_tstrCipherOpened := CipherOpen(v_DatFileName);
528   -
529   - v_tstrCipherOpened1 := TStrings.Create;
530   - v_tstrCipherOpened1 := CipherOpen(p_path_cacic + 'temp\col_comp.dat');
531   -
532   - Try
533   - Executa_Col_comp;
534   - Except
535   - SetValorDatMemoria('Col_Comp.nada', 'nada', v_tstrCipherOpened1);
536   - CipherClose(p_path_cacic + 'temp\col_comp.dat', v_tstrCipherOpened1);
537   - End;
538   - Halt(0);
539   - End;
  356 + //Pegarei o nível anterior do diretório, que deve ser, por exemplo \Cacic, para leitura do cacic2.ini
  357 + tstrTripa1 := g_oCacic.explode(ExtractFilePath(ParamStr(0)),'\');
  358 + v_path_cacic := '';
  359 + For intAux := 0 to tstrTripa1.Count -2 do
  360 + v_path_cacic := v_path_cacic + tstrTripa1[intAux] + '\';
  361 +
  362 + g_oCacic.setCacicPath(v_path_cacic);
  363 +
  364 + v_tstrCipherOpened := TStrings.Create;
  365 + v_tstrCipherOpened := CipherOpen(g_oCacic.getDatFileName);
  366 +
  367 + v_tstrCipherOpened1 := TStrings.Create;
  368 + v_tstrCipherOpened1 := CipherOpen(g_oCacic.getCacicPath + 'temp\col_comp.dat');
  369 +
  370 + Try
  371 + Executa_Col_comp;
  372 + Except
  373 + SetValorDatMemoria('Col_Comp.nada', 'nada', v_tstrCipherOpened1);
  374 + CipherClose(g_oCacic.getCacicPath + 'temp\col_comp.dat', v_tstrCipherOpened1);
  375 + End;
  376 + Halt(0);
540 377 End;
541 378 g_oCacic.Free();
542 379 end.
... ...
col_hard/col_hard.dpr
... ... @@ -35,26 +35,22 @@ uses
35 35 MSI_MEDIA,
36 36 MSI_NETWORK,
37 37 MSI_XML_Reports,
38   - DCPcrypt2,
39   - DCPrijndael,
40   - DCPbase64,
41 38 PJVersionInfo,
42 39 CACIC_Library in '..\CACIC_Library.pas';
43 40  
44   -var p_path_cacic, v_mensagem : string;
45   - v_debugs : boolean;
46   - v_CipherKey,
47   - v_IV,
48   - v_strCipherClosed,
49   - v_DatFileName : String;
50   -
51   -var v_tstrCipherOpened,
52   - v_tstrCipherOpened1 : TStrings;
  41 +var
  42 + v_path_cacic,
  43 + v_mensagem,
  44 + v_strCipherClosed : String;
  45 + v_debugs : boolean;
  46 + v_tstrCipherOpened,
  47 + v_tstrCipherOpened1,
  48 + tstrTripa1 : TStrings;
  49 + intAux : integer;
  50 + g_oCacic : TCACIC;
53 51  
54   -// Some constants that are dependant on the cipher being used
55   -// Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize)
56   -const KeySize = 32; // 32 bytes = 256 bits
57   - BlockSize = 16; // 16 bytes = 128 bits
  52 +const
  53 + CACIC_APP_NAME = 'col_hard';
58 54  
59 55 // Dica baixada de http://www.marcosdellantonio.net/2007/06/14/operador-if-ternario-em-delphi-e-c/
60 56 // Fiz isso para não ter que acrescentar o componente Math ao USES!
... ... @@ -65,50 +61,15 @@ function iif(condicao : boolean; resTrue, resFalse : Variant) : Variant;
65 61 else
66 62 Result := resFalse;
67 63 End;
68   -
69   -function HomeDrive : string;
70   -var
71   -WinDir : array [0..144] of char;
72   -begin
73   -GetWindowsDirectory (WinDir, 144);
74   -Result := StrPas (WinDir);
75   -end;
76 64  
77   -
78   -Function Implode(p_Array : TStrings ; p_Separador : String) : String;
79   -var intAux : integer;
80   - strAux : string;
81   -Begin
82   - strAux := '';
83   - For intAux := 0 To p_Array.Count -1 do
84   - Begin
85   - if (strAux<>'') then strAux := strAux + p_Separador;
86   - strAux := strAux + p_Array[intAux];
87   - End;
88   - Implode := strAux;
89   -end;
90   -// Pad a string with zeros so that it is a multiple of size
91   -function PadWithZeros(const str : string; size : integer) : string;
92   -var
93   - origsize, i : integer;
94   -begin
95   - Result := str;
96   - origsize := Length(Result);
97   - if ((origsize mod size) <> 0) or (origsize = 0) then
98   - begin
99   - SetLength(Result,((origsize div size)+1)*size);
100   - for i := origsize+1 to Length(Result) do
101   - Result[i] := #0;
102   - end;
103   -end;
104 65 procedure log_diario(strMsg : String);
105 66 var
106 67 HistoricoLog : TextFile;
107 68 strDataArqLocal, strDataAtual : string;
108 69 begin
109 70 try
110   - FileSetAttr (p_path_cacic + 'cacic2.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
111   - AssignFile(HistoricoLog,p_path_cacic + 'cacic2.log'); {Associa o arquivo a uma variável do tipo TextFile}
  71 + FileSetAttr (g_oCacic.getCacicPath + 'cacic2.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
  72 + AssignFile(HistoricoLog,g_oCacic.getCacicPath + 'cacic2.log'); {Associa o arquivo a uma variável do tipo TextFile}
112 73 {$IOChecks off}
113 74 Reset(HistoricoLog); {Abre o arquivo texto}
114 75 {$IOChecks on}
... ... @@ -118,7 +79,7 @@ begin
118 79 Append(HistoricoLog);
119 80 Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now) + '======================> Iniciando o Log <=======================');
120 81 end;
121   - DateTimeToString(strDataArqLocal, 'yyyymmdd', FileDateToDateTime(Fileage(p_path_cacic + 'cacic2.log')));
  82 + DateTimeToString(strDataArqLocal, 'yyyymmdd', FileDateToDateTime(Fileage(g_oCacic.getCacicPath + 'cacic2.log')));
122 83 DateTimeToString(strDataAtual , 'yyyymmdd', Date);
123 84 if (strDataAtual <> strDataArqLocal) then // Se o arquivo INI não é da data atual...
124 85 begin
... ... @@ -137,76 +98,6 @@ begin
137 98 end;
138 99  
139 100  
140   -// Encrypt a string and return the Base64 encoded result
141   -function EnCrypt(p_Data : String) : String;
142   -var
143   - l_Cipher : TDCP_rijndael;
144   - l_Data, l_Key, l_IV : string;
145   -begin
146   - Try
147   - // Pad Key, IV and Data with zeros as appropriate
148   - l_Key := PadWithZeros(v_CipherKey,KeySize);
149   - l_IV := PadWithZeros(v_IV,BlockSize);
150   - l_Data := PadWithZeros(p_Data,BlockSize);
151   -
152   - // Create the cipher and initialise according to the key length
153   - l_Cipher := TDCP_rijndael.Create(nil);
154   - if Length(v_CipherKey) <= 16 then
155   - l_Cipher.Init(l_Key[1],128,@l_IV[1])
156   - else if Length(v_CipherKey) <= 24 then
157   - l_Cipher.Init(l_Key[1],192,@l_IV[1])
158   - else
159   - l_Cipher.Init(l_Key[1],256,@l_IV[1]);
160   -
161   - // Encrypt the data
162   - l_Cipher.EncryptCBC(l_Data[1],l_Data[1],Length(l_Data));
163   -
164   - // Free the cipher and clear sensitive information
165   - l_Cipher.Free;
166   - FillChar(l_Key[1],Length(l_Key),0);
167   -
168   - // Return the Base64 encoded result
169   - Result := Base64EncodeStr(l_Data);
170   - Except
171   - log_diario('Erro no Processo de Criptografia');
172   - End;
173   -end;
174   -
175   -function DeCrypt(p_Data : String) : String;
176   -var
177   - l_Cipher : TDCP_rijndael;
178   - l_Data, l_Key, l_IV : string;
179   -begin
180   - Try
181   - // Pad Key and IV with zeros as appropriate
182   - l_Key := PadWithZeros(v_CipherKey,KeySize);
183   - l_IV := PadWithZeros(v_IV,BlockSize);
184   -
185   - // Decode the Base64 encoded string
186   - l_Data := Base64DecodeStr(p_Data);
187   -
188   - // Create the cipher and initialise according to the key length
189   - l_Cipher := TDCP_rijndael.Create(nil);
190   - if Length(v_CipherKey) <= 16 then
191   - l_Cipher.Init(l_Key[1],128,@l_IV[1])
192   - else if Length(v_CipherKey) <= 24 then
193   - l_Cipher.Init(l_Key[1],192,@l_IV[1])
194   - else
195   - l_Cipher.Init(l_Key[1],256,@l_IV[1]);
196   -
197   - // Decrypt the data
198   - l_Cipher.DecryptCBC(l_Data[1],l_Data[1],Length(l_Data));
199   -
200   - // Free the cipher and clear sensitive information
201   - l_Cipher.Free;
202   - FillChar(l_Key[1],Length(l_Key),0);
203   -
204   - // Return the result
205   - Result := l_Data;
206   - Except
207   - log_diario('Erro no Processo de Decriptografia');
208   - End;
209   -end;
210 101  
211 102 Function CipherClose(p_DatFileName : string; p_tstrCipherOpened : TStrings) : String;
212 103 var v_strCipherOpenImploded : string;
... ... @@ -220,13 +111,8 @@ begin
220 111 Rewrite (v_DatFile);
221 112 Append(v_DatFile);
222 113  
223   - //v_Cipher := TDCP_rijndael.Create(nil);
224   - //v_Cipher.InitStr(v_CipherKey,TDCP_md5);
225   - v_strCipherOpenImploded := Implode(p_tstrCipherOpened,'=CacicIsFree=');
226   - v_strCipherClosed := EnCrypt(v_strCipherOpenImploded);
227   - //v_strCipherClosed := v_Cipher.EncryptString(v_strCipherOpenImploded);
228   - //v_Cipher.Burn;
229   - //v_Cipher.Free;
  114 + v_strCipherOpenImploded := g_oCacic.implode(p_tstrCipherOpened,g_oCacic.getSeparatorKey);
  115 + v_strCipherClosed := g_oCacic.enCrypt(v_strCipherOpenImploded);
230 116  
231 117 Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto}
232 118  
... ... @@ -234,94 +120,6 @@ begin
234 120 except
235 121 end;
236 122 end;
237   -function GetWinVer: Integer;
238   -const
239   - { operating system (OS)constants }
240   - cOsUnknown = 0;
241   - cOsWin95 = 1;
242   - cOsWin95OSR2 = 2; // Não implementado.
243   - cOsWin98 = 3;
244   - cOsWin98SE = 4;
245   - cOsWinME = 5;
246   - cOsWinNT = 6;
247   - cOsWin2000 = 7;
248   - cOsXP = 8;
249   -var
250   - osVerInfo: TOSVersionInfo;
251   - majorVer, minorVer: Integer;
252   -begin
253   - Result := cOsUnknown;
254   - { set operating system type flag }
255   - osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
256   - if GetVersionEx(osVerInfo) then
257   - begin
258   - majorVer := osVerInfo.dwMajorVersion;
259   - minorVer := osVerInfo.dwMinorVersion;
260   - case osVerInfo.dwPlatformId of
261   - VER_PLATFORM_WIN32_NT: { Windows NT/2000 }
262   - begin
263   - if majorVer <= 4 then
264   - Result := cOsWinNT
265   - else if (majorVer = 5) and (minorVer = 0) then
266   - Result := cOsWin2000
267   - else if (majorVer = 5) and (minorVer = 1) then
268   - Result := cOsXP
269   - else
270   - Result := cOsUnknown;
271   - end;
272   - VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME }
273   - begin
274   - if (majorVer = 4) and (minorVer = 0) then
275   - Result := cOsWin95
276   - else if (majorVer = 4) and (minorVer = 10) then
277   - begin
278   - if osVerInfo.szCSDVersion[1] = 'A' then
279   - Result := cOsWin98SE
280   - else
281   - Result := cOsWin98;
282   - end
283   - else if (majorVer = 4) and (minorVer = 90) then
284   - Result := cOsWinME
285   - else
286   - Result := cOsUnknown;
287   - end;
288   - else
289   - Result := cOsUnknown;
290   - end;
291   - end
292   - else
293   - Result := cOsUnknown;
294   -end;
295   -Function Explode(Texto, Separador : String) : TStrings;
296   -var
297   - strItem : String;
298   - ListaAuxUTILS : TStrings;
299   - NumCaracteres,
300   - TamanhoSeparador,
301   - I : Integer;
302   -Begin
303   - ListaAuxUTILS := TStringList.Create;
304   - strItem := '';
305   - NumCaracteres := Length(Texto);
306   - TamanhoSeparador := Length(Separador);
307   - I := 1;
308   - While I <= NumCaracteres Do
309   - Begin
310   - If (Copy(Texto,I,TamanhoSeparador) = Separador) or (I = NumCaracteres) Then
311   - Begin
312   - if (I = NumCaracteres) then strItem := strItem + Texto[I];
313   - ListaAuxUTILS.Add(trim(strItem));
314   - strItem := '';
315   - I := I + (TamanhoSeparador-1);
316   - end
317   - Else
318   - strItem := strItem + Texto[I];
319   -
320   - I := I + 1;
321   - End;
322   - Explode := ListaAuxUTILS;
323   -end;
324   -
325 123  
326 124 Function CipherOpen(p_DatFileName : string) : TStrings;
327 125 var v_DatFile : TextFile;
... ... @@ -344,12 +142,12 @@ begin
344 142 Readln(v_DatFile,v_strCipherClosed);
345 143 while not EOF(v_DatFile) do Readln(v_DatFile,v_strCipherClosed);
346 144 CloseFile(v_DatFile);
347   - v_strCipherOpened:= DeCrypt(v_strCipherClosed);
  145 + v_strCipherOpened:= g_oCacic.deCrypt(v_strCipherClosed);
348 146 end;
349 147 if (trim(v_strCipherOpened)<>'') then
350   - Result := explode(v_strCipherOpened,'=CacicIsFree=')
  148 + Result := g_oCacic.explode(v_strCipherOpened,g_oCacic.getSeparatorKey)
351 149 else
352   - Result := explode('Configs.ID_SO=CacicIsFree='+inttostr(GetWinVer)+'=CacicIsFree=Configs.Endereco_WS=CacicIsFree=/cacic2/ws/','=CacicIsFree=');
  150 + Result := g_oCacic.explode('Configs.ID_SO' + g_oCacic.getSeparatorKey + g_oCacic.getWindowsStrId + g_oCacic.getSeparatorKey + 'Configs.Endereco_WS'+g_oCacic.getSeparatorKey+'/cacic2/ws/',g_oCacic.getSeparatorKey);
353 151  
354 152 if Result.Count mod 2 <> 0 then
355 153 Result.Add('');
... ... @@ -404,7 +202,7 @@ begin
404 202 Result := '';
405 203 if (p_SectionName <> '') then
406 204 Begin
407   - v_array_SectionName := explode(p_SectionName,'/');
  205 + v_array_SectionName := g_oCacic.explode(p_SectionName,'/');
408 206 v_array_SectionName_Count := v_array_SectionName.Count;
409 207 End
410 208 else v_array_SectionName_Count := 0;
... ... @@ -485,7 +283,7 @@ var
485 283 strDataArqLocal, strDataAtual, v_file_debugs : string;
486 284 begin
487 285 try
488   - v_file_debugs := p_path_cacic + '\Temp\Debugs\debug_'+StringReplace(ExtractFileName(StrUpper(PChar(ParamStr(0)))),'.EXE','',[rfReplaceAll])+'.txt';
  286 + v_file_debugs := g_oCacic.getCacicPath + 'Temp\Debugs\debug_'+StringReplace(ExtractFileName(StrUpper(PChar(ParamStr(0)))),'.EXE','',[rfReplaceAll])+'.txt';
489 287 FileSetAttr (v_file_debugs,0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
490 288 AssignFile(DebugsFile,v_file_debugs); {Associa o arquivo a uma variável do tipo TextFile}
491 289  
... ... @@ -667,7 +465,7 @@ Begin
667 465 v_conta_EXCECOES := 0;
668 466 if (p_excecao <> '') then
669 467 Begin
670   - tstrEXCECOES := Explode(p_excecao,','); // Excecoes a serem tratadas
  468 + tstrEXCECOES := g_oCacic.explode(p_excecao,','); // Excecoes a serem tratadas
671 469 for intAux1 := 0 to tstrEXCECOES.Count-1 Do
672 470 Begin
673 471 if (rat(tstrEXCECOES[intAux1],p_mac) > 0) then
... ... @@ -739,10 +537,8 @@ var v_te_cpu_fabricante,
739 537 v_cpu_freq : TStrings;
740 538 v_registry : TRegistry;
741 539  
742   - oCacic : TCACIC;
743   -
744 540 begin
745   - oCacic := TCACIC.Create();
  541 + g_oCacic := TCACIC.Create();
746 542 Try
747 543 SetValorDatMemoria('Col_Hard.Inicio', FormatDateTime('hh:nn:ss', Now), v_tstrCipherOpened1);
748 544 v_Report := TStringList.Create;
... ... @@ -1084,7 +880,7 @@ begin
1084 880 Try
1085 881 // Monto a string que será comparada com o valor armazenado no registro.
1086 882 v_mensagem := 'Montando pacote para comparações...';
1087   - UVC := oCacic.trimEspacosExcedentes(v_Tripa_TCPIP + ';' +
  883 + UVC := g_oCacic.trimEspacosExcedentes(v_Tripa_TCPIP + ';' +
1088 884 v_Tripa_CPU + ';' +
1089 885 v_Tripa_CDROM + ';' +
1090 886 v_te_mem_ram_desc + ';' +
... ... @@ -1115,30 +911,30 @@ begin
1115 911 // e, se não houver problemas durante esse procedimento, atualizo as
1116 912 // informações no registro.
1117 913 If (GetValorDatMemoria('Configs.IN_COLETA_FORCADA_HARD',v_tstrCipherOpened)='S') or
1118   - (oCacic.trimEspacosExcedentes(UVC) <> oCacic.trimEspacosExcedentes(ValorChaveRegistro)) Then
  914 + (g_oCacic.trimEspacosExcedentes(UVC) <> g_oCacic.trimEspacosExcedentes(ValorChaveRegistro)) Then
1119 915 Begin
1120 916 Try
1121 917 //Envio via rede para ao Agente Gerente, para gravação no BD.
1122   - SetValorDatMemoria('Col_Hard.te_Tripa_TCPIP' , oCacic.trimEspacosExcedentes( v_Tripa_TCPIP ), v_tstrCipherOpened1);
1123   - SetValorDatMemoria('Col_Hard.te_Tripa_CPU' , oCacic.trimEspacosExcedentes( v_Tripa_CPU ), v_tstrCipherOpened1);
1124   - SetValorDatMemoria('Col_Hard.te_Tripa_CDROM' , oCacic.trimEspacosExcedentes( v_Tripa_CDROM ), v_tstrCipherOpened1);
1125   - SetValorDatMemoria('Col_Hard.te_placa_mae_fabricante' , oCacic.trimEspacosExcedentes( v_te_placa_mae_fabricante ) , v_tstrCipherOpened1);
1126   - SetValorDatMemoria('Col_Hard.te_placa_mae_desc' , oCacic.trimEspacosExcedentes( v_te_placa_mae_desc ) , v_tstrCipherOpened1);
1127   - SetValorDatMemoria('Col_Hard.qt_mem_ram' , oCacic.trimEspacosExcedentes( IntToStr(v_qt_mem_ram) ) , v_tstrCipherOpened1);
1128   - SetValorDatMemoria('Col_Hard.te_mem_ram_desc' , oCacic.trimEspacosExcedentes( v_te_mem_ram_desc ) , v_tstrCipherOpened1);
1129   - SetValorDatMemoria('Col_Hard.te_bios_desc' , oCacic.trimEspacosExcedentes( v_te_bios_desc ) , v_tstrCipherOpened1);
1130   - SetValorDatMemoria('Col_Hard.te_bios_data' , oCacic.trimEspacosExcedentes( v_te_bios_data ) , v_tstrCipherOpened1);
1131   - SetValorDatMemoria('Col_Hard.te_bios_fabricante' , oCacic.trimEspacosExcedentes( v_te_bios_fabricante ) , v_tstrCipherOpened1);
1132   - SetValorDatMemoria('Col_Hard.qt_placa_video_cores' , oCacic.trimEspacosExcedentes( v_qt_placa_video_cores ) , v_tstrCipherOpened1);
1133   - SetValorDatMemoria('Col_Hard.te_placa_video_desc' , oCacic.trimEspacosExcedentes( v_te_placa_video_desc ) , v_tstrCipherOpened1);
1134   - SetValorDatMemoria('Col_Hard.qt_placa_video_mem' , oCacic.trimEspacosExcedentes( v_qt_placa_video_mem ) , v_tstrCipherOpened1);
1135   - SetValorDatMemoria('Col_Hard.te_placa_video_resolucao', oCacic.trimEspacosExcedentes( v_te_placa_video_resolucao ) , v_tstrCipherOpened1);
1136   - SetValorDatMemoria('Col_Hard.te_placa_som_desc' , oCacic.trimEspacosExcedentes( v_te_placa_som_desc ) , v_tstrCipherOpened1);
1137   - SetValorDatMemoria('Col_Hard.te_teclado_desc' , oCacic.trimEspacosExcedentes( v_te_teclado_desc ) , v_tstrCipherOpened1);
1138   - SetValorDatMemoria('Col_Hard.te_mouse_desc' , oCacic.trimEspacosExcedentes( v_te_mouse_desc ) , v_tstrCipherOpened1);
1139   - SetValorDatMemoria('Col_Hard.te_modem_desc' , oCacic.trimEspacosExcedentes( v_te_modem_desc ) , v_tstrCipherOpened1);
1140   - SetValorDatMemoria('Col_Hard.UVC' , oCacic.trimEspacosExcedentes( UVC ) , v_tstrCipherOpened1);
1141   - CipherClose(p_path_cacic + 'temp\col_hard.dat', v_tstrCipherOpened1);
  918 + SetValorDatMemoria('Col_Hard.te_Tripa_TCPIP' , g_oCacic.trimEspacosExcedentes( v_Tripa_TCPIP ), v_tstrCipherOpened1);
  919 + SetValorDatMemoria('Col_Hard.te_Tripa_CPU' , g_oCacic.trimEspacosExcedentes( v_Tripa_CPU ), v_tstrCipherOpened1);
  920 + SetValorDatMemoria('Col_Hard.te_Tripa_CDROM' , g_oCacic.trimEspacosExcedentes( v_Tripa_CDROM ), v_tstrCipherOpened1);
  921 + SetValorDatMemoria('Col_Hard.te_placa_mae_fabricante' , g_oCacic.trimEspacosExcedentes( v_te_placa_mae_fabricante ) , v_tstrCipherOpened1);
  922 + SetValorDatMemoria('Col_Hard.te_placa_mae_desc' , g_oCacic.trimEspacosExcedentes( v_te_placa_mae_desc ) , v_tstrCipherOpened1);
  923 + SetValorDatMemoria('Col_Hard.qt_mem_ram' , g_oCacic.trimEspacosExcedentes( IntToStr(v_qt_mem_ram) ) , v_tstrCipherOpened1);
  924 + SetValorDatMemoria('Col_Hard.te_mem_ram_desc' , g_oCacic.trimEspacosExcedentes( v_te_mem_ram_desc ) , v_tstrCipherOpened1);
  925 + SetValorDatMemoria('Col_Hard.te_bios_desc' , g_oCacic.trimEspacosExcedentes( v_te_bios_desc ) , v_tstrCipherOpened1);
  926 + SetValorDatMemoria('Col_Hard.te_bios_data' , g_oCacic.trimEspacosExcedentes( v_te_bios_data ) , v_tstrCipherOpened1);
  927 + SetValorDatMemoria('Col_Hard.te_bios_fabricante' , g_oCacic.trimEspacosExcedentes( v_te_bios_fabricante ) , v_tstrCipherOpened1);
  928 + SetValorDatMemoria('Col_Hard.qt_placa_video_cores' , g_oCacic.trimEspacosExcedentes( v_qt_placa_video_cores ) , v_tstrCipherOpened1);
  929 + SetValorDatMemoria('Col_Hard.te_placa_video_desc' , g_oCacic.trimEspacosExcedentes( v_te_placa_video_desc ) , v_tstrCipherOpened1);
  930 + SetValorDatMemoria('Col_Hard.qt_placa_video_mem' , g_oCacic.trimEspacosExcedentes( v_qt_placa_video_mem ) , v_tstrCipherOpened1);
  931 + SetValorDatMemoria('Col_Hard.te_placa_video_resolucao', g_oCacic.trimEspacosExcedentes( v_te_placa_video_resolucao ) , v_tstrCipherOpened1);
  932 + SetValorDatMemoria('Col_Hard.te_placa_som_desc' , g_oCacic.trimEspacosExcedentes( v_te_placa_som_desc ) , v_tstrCipherOpened1);
  933 + SetValorDatMemoria('Col_Hard.te_teclado_desc' , g_oCacic.trimEspacosExcedentes( v_te_teclado_desc ) , v_tstrCipherOpened1);
  934 + SetValorDatMemoria('Col_Hard.te_mouse_desc' , g_oCacic.trimEspacosExcedentes( v_te_mouse_desc ) , v_tstrCipherOpened1);
  935 + SetValorDatMemoria('Col_Hard.te_modem_desc' , g_oCacic.trimEspacosExcedentes( v_te_modem_desc ) , v_tstrCipherOpened1);
  936 + SetValorDatMemoria('Col_Hard.UVC' , g_oCacic.trimEspacosExcedentes( UVC ) , v_tstrCipherOpened1);
  937 + CipherClose(g_oCacic.getCacicPath + 'temp\col_hard.dat', v_tstrCipherOpened1);
1142 938 Except log_diario('Problema em gravação de dados no DAT!');
1143 939 End;
1144 940 end
... ... @@ -1146,77 +942,60 @@ begin
1146 942 Begin
1147 943 SetValorDatMemoria('Col_Hard.nada','nada', v_tstrCipherOpened1);
1148 944 SetValorDatMemoria('Col_Hard.Fim' , FormatDateTime('hh:nn:ss', Now), v_tstrCipherOpened1);
1149   - CipherClose(p_path_cacic + 'temp\col_hard.dat', v_tstrCipherOpened1);
  945 + CipherClose(g_oCacic.getCacicPath + 'temp\col_hard.dat', v_tstrCipherOpened1);
1150 946 End;
1151 947 Except
1152 948 Begin
1153 949 SetValorDatMemoria('Col_Hard.nada','nada', v_tstrCipherOpened1);
1154 950 SetValorDatMemoria('Col_Hard.Fim' , '99999999', v_tstrCipherOpened1);
1155   - CipherClose(p_path_cacic + 'temp\col_hard.dat', v_tstrCipherOpened1);
  951 + CipherClose(g_oCacic.getCacicPath + 'temp\col_hard.dat', v_tstrCipherOpened1);
1156 952 log_diario('Problema na execução => ' + v_mensagem);
1157 953 End;
1158 954 End;
1159   - oCacic.Free();
  955 + g_oCacic.Free();
1160 956 end;
1161 957  
1162   -const
1163   - CACIC_APP_NAME = 'col_hard';
1164   -
1165   -var tstrTripa1 : TStrings;
1166   - intAux : integer;
1167   - oCacic : TCACIC;
1168   -
1169 958 begin
1170   - oCacic := TCACIC.Create();
  959 + g_oCacic := TCACIC.Create();
1171 960  
1172   - if( not oCacic.isAppRunning( CACIC_APP_NAME ) ) then
  961 + if( not g_oCacic.isAppRunning( CACIC_APP_NAME ) ) then
1173 962 if (ParamCount>0) then
1174   - Begin
1175   - For intAux := 1 to ParamCount do
1176   - Begin
1177   - if LowerCase(Copy(ParamStr(intAux),1,13)) = '/p_cipherkey=' then
1178   - v_CipherKey := Trim(Copy(ParamStr(intAux),14,Length((ParamStr(intAux)))));
1179   - End;
1180   -
1181   - if (trim(v_CipherKey)<>'') then
1182   - Begin
1183   - //Pegarei o nível anterior do diretório, que deve ser, por exemplo \Cacic, para leitura do cacic2.ini
1184   - tstrTripa1 := explode(ExtractFilePath(ParamStr(0)),'\');
1185   - p_path_cacic := '';
1186   - intAux :=0;
1187   - While intAux < tstrTripa1.Count -1 do
1188   - begin
1189   - p_path_cacic := p_path_cacic + tstrTripa1[intAux] + '\';
1190   - intAux := intAux + 1
1191   - end;
1192   -
1193   - // A chave AES foi obtida no parâmetro p_CipherKey. Recomenda-se que cada empresa altere a sua chave.
1194   - v_IV := 'abcdefghijklmnop';
1195   - v_DatFileName := p_path_cacic + 'cacic2.dat';
1196   - v_tstrCipherOpened := TStrings.Create;
1197   - v_tstrCipherOpened := CipherOpen(v_DatFileName);
1198   -
1199   - v_tstrCipherOpened1 := TStrings.Create;
1200   - v_tstrCipherOpened1 := CipherOpen(p_path_cacic + 'temp\col_hard.dat');
1201   -
1202   - Try
1203   - v_Debugs := false;
1204   - if DirectoryExists(p_path_cacic + 'Temp\Debugs') then
  963 + Begin
  964 + //Pegarei o nível anterior do diretório, que deve ser, por exemplo \Cacic, para leitura do cacic2.ini
  965 + tstrTripa1 := g_oCacic.explode(ExtractFilePath(ParamStr(0)),'\');
  966 + v_path_cacic := '';
  967 + intAux :=0;
  968 + While intAux < tstrTripa1.Count -1 do
  969 + begin
  970 + v_path_cacic := v_path_cacic + tstrTripa1[intAux] + '\';
  971 + intAux := intAux + 1
  972 + end;
  973 +
  974 + g_oCacic.setCacicPath(v_path_cacic);
  975 +
  976 + v_tstrCipherOpened := TStrings.Create;
  977 + v_tstrCipherOpened := CipherOpen(g_oCacic.getDatFileName);
  978 +
  979 + v_tstrCipherOpened1 := TStrings.Create;
  980 + v_tstrCipherOpened1 := CipherOpen(g_oCacic.getCacicPath + 'temp\col_hard.dat');
  981 +
  982 + Try
  983 + v_Debugs := false;
  984 + if DirectoryExists(g_oCacic.getCacicPath + 'Temp\Debugs') then
  985 + Begin
  986 + if (FormatDateTime('ddmmyyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then
1205 987 Begin
1206   - if (FormatDateTime('ddmmyyyy', GetFolderDate(p_path_cacic + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then
1207   - Begin
1208   - v_Debugs := true;
1209   - log_diario('Pasta "' + p_path_cacic + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(p_path_cacic + 'Temp\Debugs'))+' encontrada. DEBUG ativado.');
1210   - End;
  988 + v_Debugs := true;
  989 + log_diario('Pasta "' + g_oCacic.getCacicPath + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs'))+' encontrada. DEBUG ativado.');
1211 990 End;
1212   - Executa_Col_Hard;
1213   - Except
1214   - SetValorDatMemoria('Col_Hard.nada', 'nada', v_tstrCipherOpened1);
1215   - CipherClose(p_path_cacic + 'temp\col_hard.dat', v_tstrCipherOpened1);
1216   - End;
1217   - End;
  991 + End;
  992 + Executa_Col_Hard;
  993 + Except
  994 + SetValorDatMemoria('Col_Hard.nada', 'nada', v_tstrCipherOpened1);
  995 + CipherClose(g_oCacic.getCacicPath + 'temp\col_hard.dat', v_tstrCipherOpened1);
  996 + End;
1218 997 End;
1219 998  
1220   - oCacic.Free();
  999 + g_oCacic.Free();
1221 1000  
1222 1001 end.
... ...