uInstallCACIC.pas
55.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
(**
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Copyright 2000, 2001, 2002, 2003, 2004, 2005 Dataprev - Empresa de Tecnologia e Informações da Previdência Social, Brasil
Este arquivo é parte do programa CACIC - Configurador Automático e Coletor de Informações Computacionais
O CACIC é um software livre; você pode redistribui-lo e/ou modifica-lo dentro dos termos da Licença Pública Geral GNU como
publicada pela Fundação do Software Livre (FSF); na versão 2 da Licença, ou (na sua opinião) qualquer versão.
Este programa é distribuido na esperança que possa ser util, mas SEM NENHUMA GARANTIA; sem uma garantia implicita de ADEQUAÇÂO a qualquer
MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes.
Você deve ter recebido uma cópia da Licença Pública Geral GNU, sob o título "LICENCA.txt", junto com este programa, se não, escreva para a Fundação do Software
Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
---------------------------------------------------------------------------------------------------------------------------------------------------------------
===============================================================================================================
InstallCACIC.exe : Verificador/Instalador do Serviço de Sustentação e Verificador de Estrutura do Sistema CACIC
===============================================================================================================
v 2.8.0.3
* O módulo ChkCACIC teve seu nome alterado para InstallCACIC, visando primeiramente facilitar o entendimento quanto à sua finalidade;
* A forma de instalação foi otimizada, ficando o InstallCACIC responsável em instalar e executar apenas o chkSIS.exe caso seja instalação "silenciosa".;
v 2.6.0.0
+ Acrescentado suporte à plataforma Microsoft 64Bits
v 2.2.0.38
+ Acrescentado a obtenção de versão interna do S.O.
+ Acrescentado a inserção dos agentes principais nas exceções do FireWall interno do MS-Windows VISTA...
.
Diversas rebuilds...
.
v 2.2.0.17
+ Acrescentado o tratamento da passagem de opções em linha de comando (sugestão do Cláudio Filho - BrOffice.org)
* chkcacic /serv=<WebManagerAddress> /dir=<LocalFolder>
Exemplo de uso: chkcacic /serv=UXbra001 /dir=Cacic /silent
v 2.2.0.16
* Corrigido o fechamento do arquivo de configurações de ChkSis
v 2.2.0.15
* Substituída a mensagem "File System diferente de "NTFS" por 'File System: "<NomeFileSystem>" - Ok!'
v 2.2.0.14
+ Críticas/mensagens:
"ATENÇÃO! Não foi possível estabelecer comunicação com o módulo Gerente WEB em <servidor>." e
"ATENÇÃO: Não foi possível efetuar FTP para <agente>. Verifique o Servidor de Updates."
+ Opção checkbox "Exibe informações sobre o processo de instalação" ao formulário de configuração;
+ Botão "Sair" ao formulário de configuração;
+ Execução automática do Agente Principal ao fim da instalação quando a unidade origem do ChkCacic não
for mapeamento de rede ou unidade inválida.
- Retirados os campos "Frase para Sucesso na Instalação" e "Frase para Insucesso na Instalação"
do formulário de configuração, passando essas frases a serem fixas na aplicação.
- Retirada a opção radiobutton "Remove Versão Anterior?";
=====================================================================================================
*)
unit uInstallCACIC;
interface
uses Windows,
Messages,
SysUtils,
StrUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
NTFileSecurity,
WinSvc,
StdCtrls,
ExtCtrls,
ComCtrls,
ShellAPI,
CACIC_Library,
CACIC_WMI,
CACIC_Comm,
CACIC_VerifyAndGetModules;
function IsUserAnAdmin() : boolean; external shell32;
type
TfrmInstallCACIC = class(TForm)
pnVersao: TPanel;
gbMandatory: TGroupBox;
lbWebManagerAddress: TLabel;
lbInformeEndereco: TLabel;
edWebManagerAddress: TEdit;
btConfirmProcess: TButton;
btExit: TButton;
lbActionsLog: TStaticText;
gbProgress: TGroupBox;
richProgress: TRichEdit;
staticStatus: TStaticText;
procedure FormCreate(Sender: TObject);
procedure comunicaInsucesso(strIndicador : String); //2.2.0.32
procedure FS_SetSecurity(p_Target : String);
procedure gravaConfiguracoes;
procedure informaProgresso(pStrMessage : String; pBoolAlert : boolean = false);
procedure installCACIC;
procedure btConfirmProcessClick(Sender: TObject);
procedure btExitClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
function boolCanRunCACIC : boolean;
function findWindowByTitle(pStrWindowTitle: string) : Hwnd;
function listFileDir(pStrPath: string) : string;
function serviceStart(pStrServiceName : string ) : boolean;
function serviceRunning(pCharMachineName, pCharServiceName: PChar) : boolean;
function serviceStopped(pCharMachineName, pCharServiceName: PChar) : boolean;
private
public
strTeSuccessPhrase,
strTeInsuccessPhrase,
strCommResponse,
strChkSisInfFileName,
strFieldsAndValuesToRequest,
strMainProgramInfFileName,
strGerColsInfFileName : String;
boolShowForm : boolean;
objCACIC : TCACIC;
end;
var frmInstallCACIC : TfrmInstallCACIC;
implementation
{$R *.dfm}
procedure TfrmInstallCACIC.FormCreate(Sender: TObject);
var
wordServiceStatus, serviceType : DWord;
begin
Try
boolShowForm := true;
objCacic := TCACIC.Create();
objCacic.setBoolCipher(true);
objCacic.setLocalFolderName('Cacic');
objCacic.setWebServicesFolderName('ws/');
objCacic.setWebManagerAddress(objCacic.fixWebAddress(objCacic.getParam('Serv')));
boolShowForm := not FindCmdLineSwitch('silent',true);
if IsUserAnAdmin then
Begin
// Verifico se foi uma execução duvidosa e mostro o diálogo
if (ParamCount > 0) and (objCacic.getWebManagerAddress = '') then
Begin
boolShowForm := true;
ShowMessage('Forma de Uso COM PASSAGEM DE PARÂMETROS:' + #13#10 +
'-------------------------------------------------' + #13#10 +
'installcacic.exe < /serv=NomeOuIpDoServidorDeAplicacao > [/silent]'+ #13#10 + #13#10 +
'1) O parâmetro "/serv" é obrigatório;' + #13#10 +
'2) A opção /silent é opcional e não exibirá o processo de instalação. Ideal para uso em scripts de logon.' + #13#10 + #13#10);
End
else
Begin
strChkSisInfFileName := objCacic.getWinDir + 'chksis.inf';
strGerColsInfFileName := objCacic.getLocalFolderName + 'gercols.inf';
if boolShowForm then
Begin
Visible := true;
WindowState := wsNormal;
gbMandatory.BringToFront;
lbWebManagerAddress.BringToFront;
edWebManagerAddress.BringToFront;
edWebManagerAddress.Text := objCacic.getWebManagerAddress;
self.Refresh;
edWebManagerAddress.SetFocus;
End
else if (objCacic.getWebManagerAddress <> '') then
installCACIC
else
objCacic.writeDailyLog('ATENÇÃO: InstallCACIC chamado com opção "/silent" mas sem a opção "/serv"!');
End;
End
else
Begin // Se NT/2000/XP/...
if boolShowForm then
MessageDLG(#13#10+'ATENÇÃO! Essa aplicação requer execução com nível administrativo.',mtError,[mbOK],0);
objCacic.writeDailyLog('SEM PRIVILÉGIOS: Necessário ser administrador "local" ou de Domínio!');
ComunicaInsucesso('0'); // O indicador "0" (zero) sinalizará falta de privilégio na estação
if not boolShowForm then
btExitClick(nil);
End;
Finally
End;
end;
// start service
//
// return TRUE if successful
//
// sService
// service name, ie: Alerter
//
function TfrmInstallCACIC.ServiceStart(pStrServiceName : string ) : boolean;
var schm,
schs : SC_Handle;
ss : TServiceStatus;
psTemp : PChar;
dwChkP : DWord;
begin
ss.dwCurrentState := 0;
objCacic.writeDebugLog('ServiceStart: BEGIN');
// connect to the service control manager
schm := OpenSCManager(Nil,Nil,SC_MANAGER_CONNECT);
// if successful...
if(schm > 0)then
begin
// open a handle to the specified service
schs := OpenService(schm,PChar(pStrServiceName),SERVICE_START or SERVICE_QUERY_STATUS);
// if successful...
if(schs > 0)then
begin
objCacic.writeDebugLog('ServiceStart: Open Service OK');
psTemp := Nil;
if(StartService(schs,0,psTemp)) then
begin
objCacic.writeDebugLog('ServiceStart: Entrando em Start Service');
// check status
if(QueryServiceStatus(schs,ss))then
begin
while(SERVICE_RUNNING <> ss.dwCurrentState)do
begin
// dwCheckPoint contains a value that the service increments periodically
// to report its progress during a lengthy operation.
dwChkP := ss.dwCheckPoint;
// wait a bit before checking status again
// dwWaitHint is the estimated amount of time the calling program should wait before calling
// QueryServiceStatus() again idle events should be handled here...
Sleep(ss.dwWaitHint);
if(not QueryServiceStatus(schs,ss))then
begin
break;
end;
if(ss.dwCheckPoint < dwChkP)then
begin
// QueryServiceStatus didn't increment dwCheckPoint as it should have.
// avoid an infinite loop by breaking
break;
end;
end;
end
else
objCacic.writeDebugLog('ServiceStart: Oops! Problema com StartService!');
end;
// close service handle
CloseServiceHandle(schs);
end;
// close service control manager handle
CloseServiceHandle(schm);
end
else
richProgress.Lines.Add('Oops! Problema com o Service Control Manager!');
// return TRUE if the service status is running
Result := SERVICE_RUNNING = ss.dwCurrentState;
end;
procedure TfrmInstallCACIC.ComunicaInsucesso(strIndicador : String);
begin
Try
// Envio notificação de insucesso para o Módulo Gerente Centralizado
strFieldsAndValuesToRequest := 'cs_indicador=' + strIndicador + ',';
strFieldsAndValuesToRequest := strFieldsAndValuesToRequest + 'id_usuario=' + objCACIC.getValueFromTags('UserName',fetchWMIvalues('Win32_ComputerSystem',objCACIC.getLocalFolderName,'UserName'));
Try
Comm(objCacic.getWebManagerAddress + objCacic.getWebServicesFolderName + 'instala/cacic', strFieldsAndValuesToRequest, objCACIC.getLocalFolderName, 'Enviando informação de insucesso ao Gerente WEB');
Except
on E : Exception do
objCacic.writeExceptionLog(E.Message,E.ClassName,'ComunicaInsucesso');
End;
finally
End;
end;
procedure TfrmInstallCACIC.GravaConfiguracoes;
var textFileChkSisInf : TextFile;
begin
try
FileSetAttr (strChkSisInfFileName,0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
AssignFile(textFileChkSisInf,strChkSisInfFileName); {Associa o arquivo a uma variável do tipo TextFile}
Rewrite(textFileChkSisInf); // Recria o arquivo...
Writeln(textFileChkSisInf,'[Configs]');
// Escrita dos parâmetros obrigatórios
Append(textFileChkSisInf);
Writeln(textFileChkSisInf,'WebManagerAddress=' + objCacic.getWebManagerAddress);
Append(textFileChkSisInf);
Writeln(textFileChkSisInf,'WebServicesFolderName=' + objCacic.getWebServicesFolderName);
CloseFile(textFileChkSisInf); {Fecha o arquivo texto}
objCacic.writeDebugLog('GravaConfiguracoes: Concluindo geração do arquivo de configurações chkSIS.ini');
except
on E : Exception do
Begin
objCacic.writeExceptionLog(E.Message,E.ClassName,'GravaConfiguracoes');
End;
end;
end;
Function TfrmInstallCACIC.listFileDir(pStrPath: string):string;
var
SR: TSearchRec;
FileList : string;
begin
if FindFirst(pStrPath, faAnyFile, SR) = 0 then
begin
repeat
if (SR.Attr <> faDirectory) then
begin
if (FileList<>'') then FileList := FileList + '#';
FileList := FileList + SR.Name;
end;
until FindNext(SR) <> 0;
FindClose(SR);
Result := FileList;
end;
end;
function TfrmInstallCACIC.boolCanRunCACIC : boolean;
Begin
// Se eu conseguir matar o arquivo abaixo é porque não há outra sessão deste agente aberta... (POG? Nããão! :) )
objCacic.deleteFileOrFolder(objCacic.getLocalFolderName + 'aguarde_CACIC.txt');
// Se o aguarde_CACIC.txt existir é porque refere-se a uma versão mais atual: 2.8.x ou maior
Result := not (FileExists(objCacic.getLocalFolderName + 'aguarde_CACIC.txt'));
End;
procedure TfrmInstallCACIC.installCACIC;
var wordServiceStatus, serviceType : cardinal;
tstrRequest_ConfigIC : TStringList;
strAuxInstallCACIC : String;
begin
strTeSuccessPhrase := 'INSTALAÇÃO/ATUALIZAÇÃO EFETUADA COM SUCESSO!';
strTeInsuccessPhrase := '***** INSTALAÇÃO/ATUALIZAÇÃO NÃO EFETUADA COM SUCESSO *****';
richProgress.ScrollBars := ssNone;
btConfirmProcess.Enabled := false;
btExit.Enabled := false;
frmInstallCACIC.Visible := boolShowForm;
Try
if (objCacic.getValueFromFile('Hash-Codes', UpperCase(objCacic.getValueFromFile('Configs','MainProgramName',strChkSisInfFileName)), strChkSisInfFileName) = '') then
Begin
objCacic.deleteFileOrFolder(objCacic.getWinDir + 'chksis.exe');
objCacic.deleteFileOrFolder(objCacic.getWinDir + 'chksis.ini');
objCacic.deleteFileOrFolder(objCacic.getWinDir + 'chksis.dat');
objCacic.deleteFileOrFolder(objCacic.getWinDir + 'chksis.log');
End;
objCacic.writeDebugLog('installCACIC: Verificando pasta "' + objCacic.getLocalFolderName + '"');
// Verifico a existência do diretório configurado para o Cacic, normalmente CACIC
if not DirectoryExists(objCacic.getLocalFolderName) then
begin
informaProgresso('Criando pasta '+objCacic.getLocalFolderName);
ForceDirectories(objCacic.getLocalFolderName);
end;
objCacic.writeDebugLog('installCACIC: Verificando pasta "'+objCacic.getLocalFolderName+'Temp'+'"');
// Crio o SubDiretório TEMP, caso não exista
if not DirectoryExists(objCacic.getLocalFolderName+'Temp') then
begin
ForceDirectories(objCacic.getLocalFolderName + 'Temp');
informaProgresso('Criando pasta '+objCacic.getLocalFolderName+'Temp');
end;
objCacic.writeDebugLog('installCACIC: Verificando pasta "' + objCacic.getLocalFolderName + 'Modules' + '"');
// Crio o SubDiretório TEMP, caso não exista
if not DirectoryExists(objCacic.getLocalFolderName + 'Modules') then
begin
ForceDirectories(objCacic.getLocalFolderName + 'Modules');
informaProgresso('Criando pasta ' + objCacic.getLocalFolderName + 'Modules');
end;
objCacic.writeDebugLog('installCACIC: isWindowsNTPlataform => ' + objCacic.getBoolToString(objCacic.isWindowsNTPlataform()));
objCacic.writeDebugLog('installCACIC: isWindowsAdmin => ' + objCacic.getBoolToString(objCacic.isWindowsAdmin()));
objCacic.writeDebugLog('installCACIC: isUserAnAdmin => ' + objCacic.getBoolToString(IsUserAnAdmin()));
// Verifica se o S.O. é NT Like e se o Usuário está com privilégio administrativo...
{
if ((objCacic.isWindowsNTPlataform()) and (objCacic.isWindowsAdmin())) or
not objCacic.isWindowsNTPlataform then
}
objCacic.writeDebugLog('installCACIC: Drive de Instalação......................: ' + objCacic.getHomeDrive);
objCacic.writeDebugLog('installCACIC: Pasta para Instalação Local..............: ' + objCacic.getLocalFolderName);
objCacic.writeDebugLog('installCACIC: Endereço de Acesso ao Gerente WEB........: ' + objCacic.getWebManagerAddress);
objCacic.writeDebugLog('installCACIC: Pasta para WebServices no Gerente WEB....: ' + objCacic.getWebServicesFolderName);
objCacic.writeDebugLog('installCACIC: ' + DupeString(':',100));
objCacic.writeDebugLog('installCACIC: :::::::::::::::::::: LIBERAÇÃO DE FIREWALL ::::::::::::::::::::');
objCacic.writeDebugLog('installCACIC: isWindowsGEXP => ' + objCacic.getBoolToString(objCacic.isWindowsGEXP()));
if (objCacic.isWindowsGEXP()) then // Se >= Maior ou Igual ao WinXP...
Begin
objCacic.writeDebugLog('installCACIC: => S.O. Maior/Igual a WinXP <=');
Try
// Libero as policies do FireWall Interno
objCacic.writeDebugLog('installCACIC: isWindowsGEVista => ' + objCacic.getBoolToString(objCacic.isWindowsGEVista()));
if (objCacic.isWindowsGEVista()) then // Maior ou Igual ao VISTA...
Begin
objCacic.writeDebugLog('installCACIC: => S.O. Maior/Igual a WinVISTA <=');
Try
Begin
// Liberando as conexões de Saída para o FTP
informaProgresso('Liberando as conexões de Saída para o serviço FTP');
objCacic.setValueRegistryKey('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=' + objCacic.getHomeDrive + 'system32\\ftp.exe|Name=FTP|Desc=Programa de transferência de arquivos|Edge=FALSE|');
objCacic.setValueRegistryKey('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=' + objCacic.getHomeDrive + 'system32\\ftp.exe|Name=FTP|Desc=Programa de transferência de arquivos|Edge=FALSE|');
objCacic.setValueRegistryKey('HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\FTP-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App=' + objCacic.getHomeDrive + 'system32\\ftp.exe|Name=FTP|Desc=Programa de transferência de arquivos|Edge=FALSE|');
objCacic.setValueRegistryKey('HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\FTP-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App=' + objCacic.getHomeDrive + 'system32\\ftp.exe|Name=FTP|Desc=Programa de transferência de arquivos|Edge=FALSE|');
// Liberando as conexões de Saída para o InstallCACIC
informaProgresso('Liberando as conexões de Saída para o InstallCACIC');
objCacic.setValueRegistryKey('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-INSTALLCACIC-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App=' + ExtractFilePath(Application.Exename) + '\installcacic.exe|Name=InstallCACIC|Desc=Módulo Verificador de Integridade e Instalador do Sistema CACIC|Edge=FALSE|');
objCacic.setValueRegistryKey('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-INSTALLCACIC-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App=' + ExtractFilePath(Application.Exename) + '\installcacic.exe|Name=InstallCACIC|Desc=Módulo Verificador de Integridade e Instalador do Sistema CACIC|Edge=FALSE|');
objCacic.setValueRegistryKey('HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-INSTALLCACIC-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App=' + ExtractFilePath(Application.Exename) + '\installcacic.exe|Name=InstallCACIC|Desc=Módulo Verificador de Integridade e Instalador do Sistema CACIC|Edge=FALSE|');
objCacic.setValueRegistryKey('HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-INSTALLCACIC-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App=' + ExtractFilePath(Application.Exename) + '\installcacic.exe|Name=InstallCACIC|Desc=Módulo Verificador de Integridade e Instalador do Sistema CACIC|Edge=FALSE|');
// Liberando as conexões de Saída para o ChkSis
informaProgresso('Liberando as conexões de Saída para o ChkSIS');
objCacic.setValueRegistryKey('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=' + objCacic.getWinDir + 'chksis.exe|Name=chkSIS|Desc=Módulo Verificador de Integridade do Sistema CACIC|Edge=FALSE|');
objCacic.setValueRegistryKey('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=' + objCacic.getWinDir + 'chksis.exe|Name=chkSIS|Desc=Módulo Verificador de Integridade do Sistema CACIC|Edge=FALSE|');
objCacic.setValueRegistryKey('HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-CHKSIS-Out-TCP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=6|Profile=Private|App=' + objCacic.getWinDir + 'chksis.exe|Name=chkSIS|Desc=Módulo Verificador de Integridade do Sistema CACIC|Edge=FALSE|');
objCacic.setValueRegistryKey('HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\CACIC-CHKSIS-Out-UDP','v2.0|Action=Allow|Active=TRUE|Dir=Out|Protocol=17|Profile=Private|App=' + objCacic.getWinDir + 'chksis.exe|Name=chkSIS|Desc=Módulo Verificador de Integridade do Sistema CACIC|Edge=FALSE|');
End
Except
on E : Exception do
Begin
objCacic.writeExceptionLog(E.Message,E.ClassName,'Escrevendo Firewallpolicies para liberações de conexões. (1)');
informaProgresso('Oops! Problema Liberando Policies de FireWall!',true);
objCacic.writeDebugLog('installCACIC: Problema Liberando Policies de FireWall!');
End;
End;
End
else
Begin
objCacic.writeDebugLog('installCACIC: => S.O. Menor que WinVISTA <=');
// Acrescento o InstallCacic e srCACICsrv às exceções do FireWall nativo...
{installcacic}
informaProgresso('Inserindo o InstallCACIC.exe nas exceções do FireWall!');
objCacic.writeDebugLog('installCACIC: Inserindo "'+ExtractFilePath(Application.Exename) + 'installcacic.exe" nas exceções do FireWall!');
objCacic.addApplicationToFirewall('InstallCACIC - Instalador do Sistema CACIC',ExtractFilePath(Application.Exename) + Application.Exename,true);
End;
Except
on E : Exception do
Begin
informaProgresso('Oops! Problemas ao escrever Firewallpolicies para liberações de conexões. (2)',true);
objCacic.writeExceptionLog(E.Message,E.ClassName,'Escrevendo Firewallpolicies para liberações de conexões. (2)');
objCacic.writeDebugLog('installCACIC: Problema Liberando Policies de FireWall!');
End;
End;
End;
objCacic.writeDebugLog('installCACIC: ' + DupeString(':',100));
Try
// Tento o contato com o módulo gerente WEB para obtenção de
// dados para conexão FTP e relativos às versões atuais dos principais agentes
// Busco as configurações para acesso ao ambiente FTP - Updates
strFieldsAndValuesToRequest := 'in_instalacao=OK';
objCacic.writeDebugLog('installCACIC: Preparando Chamada ao Gerente WEB: "' + objCacic.getWebManagerAddress + objCacic.getWebServicesFolderName +'get/config');
informaProgresso('Fazendo contato com Gerente WEB.');
informaProgresso('Endereço do gerente: ' + objCacic.getWebManagerAddress);
strCommResponse := Comm(objCacic.getWebManagerAddress + objCacic.getWebServicesFolderName + 'get/config', strFieldsAndValuesToRequest, objCACIC.getLocalFolderName);
if (strCommResponse <> '0') then
Begin
{ Já realizados na chamada ao get_test.php substituido por get/test
objCacic.setBoolCipher
objCacic.setMainProgramName
objCacic.setMainProgramHash
objCacic.setLocalFolderName
objCacic.setWebManagerAddress
objCacic.setWebServicesFolderName
}
FileSetAttr ( PChar(strChkSisInfFileName),0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000
objCACIC.setMainProgramName(objCacic.getValueFromTags('MainProgramName', strCommResponse,'<>'));
strMainProgramInfFileName := ChangeFileExt(objCacic.getMainProgramName,'.inf');
objCacic.setValueToFile('Configs' ,'NmUsuarioLoginServUpdates' , objCacic.getValueFromTags('nm_usuario_login_serv_updates' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Configs' ,'NuPortaServUpdates' , objCacic.getValueFromTags('nu_porta_serv_updates' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Configs' ,'LocalFolderName' , objCacic.getValueFromTags('LocalFolderName' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Configs' ,'MainProgramName' , objCacic.getValueFromTags('MainProgramName' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Configs' ,'TePathServUpdates' , objCacic.getValueFromTags('te_path_serv_updates' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Configs' ,'TeServUpdates' , objCacic.getValueFromTags('te_serv_updates' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Configs' ,'TeSenhaLoginServUpdates' , objCacic.getValueFromTags('te_senha_login_serv_updates' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Configs' ,'WebManagerAddress' , objCacic.getWebManagerAddress , strChkSisInfFileName);
objCacic.setValueToFile('Configs' ,'WebServicesFolderName' , objCacic.getWebServicesFolderName , strChkSisInfFileName);
objCacic.setValueToFile('Hash-Codes','CHKSIS.EXE' , objCacic.getValueFromTags('CHKSIS.EXE_HASH' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Hash-Codes','CACICSERVICE.EXE' , objCacic.getValueFromTags('CACICSERVICE.EXE_HASH' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Hash-Codes','GERCOLS.EXE' , objCacic.getValueFromTags('GERCOLS.EXE_HASH' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Hash-Codes','SRCACICSRV.EXE' , objCacic.getValueFromTags('SRCACICSRV.EXE_HASH' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Hash-Codes','MAPACACIC.EXE' , objCacic.getValueFromTags('SRCACICSRV.EXE_HASH' , strCommResponse,'<>') , strChkSisInfFileName);
objCacic.setValueToFile('Hash-Codes',objCacic.getMainProgramName , objCacic.getValueFromTags(objCacic.getMainProgramName + '_HASH', strCommResponse,'<>') , strChkSisInfFileName);
informaProgresso('Informações obtidas:');
informaProgresso('Servidor de updates.........................................: ' + objCACIC.deCrypt(objCacic.getValueFromTags('te_serv_updates' , strCommResponse,'<>')));
informaProgresso('Porta do servidor de updates................................: ' + objCACIC.deCrypt( objCacic.getValueFromTags('nu_porta_serv_updates' , strCommResponse,'<>')));
informaProgresso('Usuário para login no servidor de updates...................: ' + objCacic.deCrypt(objCacic.getValueFromTags('nm_usuario_login_serv_updates', strCommResponse,'<>'),true,true));
informaProgresso('Pasta no servidor de updates................................: ' + objCACIC.deCrypt(objCacic.getValueFromTags('te_path_serv_updates' , strCommResponse,'<>')));
informaProgresso('Versão do Serviço para Sustentação do Sistema (CACICSERVICE): ' + objCACIC.deCrypt(objCacic.getValueFromTags('CACICSERVICE.EXE_VER' , strCommResponse,'<>')));
informaProgresso('Versão do Verificador de Integridade do Sistema (CHKSIS)....: ' + objCACIC.deCrypt(objCacic.getValueFromTags('CHKSIS.EXE_VER' , strCommResponse,'<>')));
informaProgresso('Versão do Agente Principal do Sistema (' + ChangeFileExt(objCacic.getMainProgramName,'') + ')....: ' + objCACIC.deCrypt(objCacic.getValueFromTags(objCacic.getMainProgramName + '_VER', strCommResponse,'<>')));
objCacic.writeDebugLog('installCACIC: :::::::::::::::: VALORES OBTIDOS NO Gerente WEB :::::::::::::::');
objCacic.writeDebugLog('installCACIC: Endereço do Servidor de Aplicações..........................: ' + objCacic.deCrypt(objCacic.getValueFromTags('WebManagerAddress' , strCommResponse,'<>')) );
objCacic.writeDebugLog('installCACIC: Pasta WebServices no Servidor de Aplicações.................: ' + objCacic.deCrypt(objCacic.getValueFromTags('WebServicesFolderName' , strCommResponse,'<>')) );
objCacic.writeDebugLog('installCACIC: Servidor de updates.........................................: ' + objCacic.deCrypt(objCacic.getValueFromTags('te_serv_updates' , strCommResponse,'<>')) );
objCacic.writeDebugLog('installCACIC: Porta do servidor de updates................................: ' + objCacic.deCrypt(objCacic.getValueFromTags('nu_porta_serv_updates' , strCommResponse,'<>')) );
objCacic.writeDebugLog('installCACIC: Usuário para login no servidor de updates...................: ' + objCacic.deCrypt(objCacic.getValueFromTags('nm_usuario_login_serv_updates' , strCommResponse,'<>'),true,true));
objCacic.writeDebugLog('installCACIC: Pasta no servidor de updates................................: ' + objCacic.deCrypt(objCacic.getValueFromTags('te_path_serv_updates' , strCommResponse,'<>')) );
objCacic.writeDebugLog('installCACIC: Versão do Serviço para Sustentação do Sistema (CACICSERVICE): ' + objCacic.deCrypt(objCacic.getValueFromTags('CACICSERVICE.EXE_VER' , strCommResponse,'<>')) );
objCacic.writeDebugLog('installCACIC: Versão do Verificador de Integridade do Sistema (CHKSIS)....: ' + objCacic.deCrypt(objCacic.getValueFromTags('CHKSIS.EXE_VER' , strCommResponse,'<>')) );
objCacic.writeDebugLog('installCACIC: Versão do Agente Principal do Sistema (' + ChangeFileExt(objCacic.getMainProgramName,'') + ')....: ' + objCacic.deCrypt(objCacic.getValueFromTags(objCacic.getMainProgramName + '_VER', strCommResponse,'<>')));
objCacic.writeDebugLog('installCACIC: ' + DupeString(':',100));
// Verificar existência do AGENTE PRINCIPAL!!!!!!
if FileExists(objCacic.getLocalFolderName + objCacic.getMainProgramName) then
if (objCacic.getFileHash(objCacic.getLocalFolderName + objCacic.getMainProgramName) = objCacic.getValueFromFile('Hash-Codes', objCacic.getMainProgramName,strChkSisInfFileName) ) then
Begin
if boolShowForm then
Begin
informaProgresso('Agente principal encontrado localmente com versão atual!');
ShowMessage('ATENÇÃO: Para desinstalação do CACIC faz-se necessária a parada e desinstalação do serviço "CacicService" em modo de segurança.');
End
End
else
Begin
informaProgresso('Versão divergente de Agente Principal encontrada. Excluindo...');
objCacic.deleteFileOrFolder(objCacic.getLocalFolderName + objCacic.getMainProgramName);
sleep(2000);
// Faço FTP do Agente Principal
strAuxInstallCACIC := verifyAndGetModules(objCacic.getMainProgramName,
objCacic.getMainProgramHash,
objCacic.getLocalFolderName,
objCacic.getLocalFolderName,
objCacic,
strChkSisInfFileName);
informaProgresso(strAuxInstallCACIC);
End;
// Verificação de versão do agente principal e exclusão em caso de versão antiga/diferente da atual
objCacic.deleteFileOrFolder(objCacic.getLocalFolderName + 'cacic2.exe');
// Tento detectar o GerCols.EXE e faço FTP caso não exista ou tenha o Hash-Code diferente do repositório
strAuxInstallCACIC := verifyAndGetModules('gercols.exe',
objCacic.deCrypt(objCacic.getValueFromTags('GERCOLS.EXE_HASH', strCommResponse,'<>'),true,true),
objCacic.getLocalFolderName + 'Modules',
objCacic.getLocalFolderName,
objCacic,
strChkSisInfFileName);
informaProgresso(strAuxInstallCACIC);
// Tento detectar o Agente Principal e faço FTP caso não exista ou tenha o Hash-Code diferente do repositório
strAuxInstallCACIC := verifyAndGetModules(objCacic.getMainProgramName,
objCacic.getMainProgramHash,
objCacic.getLocalFolderName,
objCacic.getLocalFolderName,
objCacic,
strChkSisInfFileName);
informaProgresso(strAuxInstallCACIC);
// Tento detectar o Servidor de Suporte Remoto e faço FTP caso não exista ou tenha o Hash-Code diferente do repositório
strAuxInstallCACIC := verifyAndGetModules('srcacicsrv.exe',
objCacic.deCrypt(objCacic.getValueFromTags('SRCACICSRV.EXE_HASH', strCommResponse,'<>'),true,true),
objCacic.getLocalFolderName + 'Modules',
objCacic.getLocalFolderName,
objCacic,
strChkSisInfFileName);
informaProgresso(strAuxInstallCACIC);
// Tento detectar o ChkSis.EXE e faço FTP caso não exista ou tenha o Hash-Code diferente do repositório
strAuxInstallCACIC := verifyAndGetModules('chksis.exe',
objCacic.deCrypt(objCacic.getValueFromTags('CHKSIS.EXE_HASH', strCommResponse,'<>'),true,true),
objCacic.getWinDir,
objCacic.getLocalFolderName,
objCacic,
strChkSisInfFileName);
informaProgresso(strAuxInstallCACIC);
strAuxInstallCACIC := verifyAndGetModules('mapacacic.exe',
objCacic.deCrypt(objCacic.getValueFromTags('GERCOLS.EXE_HASH', strCommResponse,'<>'),true,true),
objCacic.getLocalFolderName + 'Modules',
objCacic.getLocalFolderName,
objCacic,
strChkSisInfFileName);
informaProgresso(strAuxInstallCACIC);
// Se NTFS em NT/2K/XP...
// If NTFS on NT Like...
If (objCacic.isWindowsNTPlataform()) then
Begin
Try
strAuxInstallCACIC := verifyAndGetModules('cacicservice.exe',
objCacic.deCrypt(objCacic.getValueFromTags('CACICSERVICE.EXE_HASH', strCommResponse,'<>'),true,true),
objCacic.getWinDir,
objCacic.getLocalFolderName,
objCacic,
strChkSisInfFileName);
informaProgresso(strAuxInstallCACIC);
objCacic.setValueToFile('Installation','CacicService.exe' , objCacic.checkModule(objCacic.getWinDir + 'cacicservice.exe', objCACIC.deCrypt( objCacic.getValueFromTags('CACICSERVICE.EXE_HASH', strCommResponse,'<>'),false,true)), strChkSisInfFileName);
informaProgresso('Atribuindo permissões de acessos a instalador e verificador de integridade.');
objCacic.writeDebugLog('installCACIC: ::::::: VERIFICANDO FILE SYSTEM E ATRIBUINDO PERMISSÕES :::::::');
objCacic.writeDebugLog('installCACIC: ' + DupeString(':',100));
// Atribuição de acesso para atualização do módulo verificador de integridade do sistema e seus arquivos
FS_SetSecurity(objCacic.getWinDir + ChangeFileExt(strChkSisInfFileName,'.exe'));
FS_SetSecurity(objCacic.getLocalFolderName + 'Logs\' + ChangeFileExt(strChkSisInfFileName,'.log'));
FS_SetSecurity(strChkSisInfFileName);
// Atribuição de acesso para atualização/exclusão de log do instalador
FS_SetSecurity(objCacic.getLocalFolderName + 'Logs\installcacic.log');
objCacic.writeDebugLog('installCACIC: ' + DupeString(':',100));
// Acrescento o chkSIS às exceções do FireWall nativo...
{chksis}
objCacic.writeDebugLog('installCACIC: Inserindo "'+objCacic.getWinDir + 'chksis" nas exceções do FireWall!');
objCacic.addApplicationToFirewall('chkSIS - Módulo Verificador de Integridade do Sistema CACIC',objCacic.getWinDir + 'chksis.exe',true);
Except
on E : Exception do
Begin
objCacic.writeExceptionLog(E.Message,E.ClassName,'Criando exceções na FireWall (isWindowsNTPlatform)');
End;
End;
End;
objCacic.writeDebugLog('installCACIC: Gravando registros para auto-execução');
// Somente para S.O. NOT NT LIKE
if NOT (objCacic.isWindowsNTPlataform) then
Begin
// Crio a chave/valor chksis para autoexecução do ChkSIS, caso não exista esta chave/valor
objCacic.setValueRegistryKey('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\CheckSystemRoutine', objCacic.getWinDir + 'chksis.exe');
End;
// ATENÇÃO:
// Após testes no Vista, percebí que o firewall nativo interrompia o FTP e truncava o agente com tamanho zero...
// A nova tentativa abaixo ajudará a sobrepor o agente truncado e corrompido
// Tento detectar (de novo) o ChkSis.EXE e faço FTP caso não exista
verifyAndGetModules('chksis.exe',
objCacic.deCrypt(objCacic.getValueFromTags('CHKSIS.EXE_HASH', strCommResponse,'<>'),true,true),
objCacic.getWinDir,
objCacic.getLocalFolderName,
objCacic,
strChkSisInfFileName);
objCacic.setValueToFile('Installation','chkSIS.exe',
objCacic.checkModule(objCacic.getWinDir + 'chksis.exe',
objCACIC.deCrypt( objCacic.getValueFromTags
('CHKSIS.EXE_HASH', strCommResponse,'<>'),
false,true)), strChkSisInfFileName);
// Caso o Cacic tenha sido baixado executo-o com parâmetro de configuração de servidor
if (objCacic.getValueFromFile('Installation','CacicService.exe' , strChkSisInfFileName) = 'Ok!') and
(objCacic.getValueFromFile('Installation','ChkSIS.exe' , strChkSisInfFileName) = 'Ok!') then
Begin
informaProgresso(strTeSuccessPhrase);
informaProgresso('A Estrutura do Sistema encontra-se Ok!');
End
else
Begin
informaProgresso(DupeString('*',100),true);
informaProgresso('A Estrutura do Sistema encontra-se Inconsistente!',true);
informaProgresso(DupeString('*',100),true);
informaProgresso('Recomendação Principal:',true);
informaProgresso(DupeString('-',15),true);
informaProgresso('Acessar a opção Manutenção / Atualização de SubRedes e atualizar devidamente o Servidor de Updates.',true);
informaProgresso(DupeString('-',15),true);
informaProgresso(strTeInsuccessPhrase,true);
ComunicaInsucesso('1'); // O indicador "1" sinalizará que não foi devido a privilégio na estação
End;
if (objCacic.getValueFromFile('Installation','ChkSIS.exe', strChkSisInfFileName) = 'Ok!') then
Begin
// Se não for plataforma NT executo o agente principal
if not (objCacic.isWindowsNTPlataform()) then
Begin
if boolShowForm then
objCacic.writeDebugLog('installCACIC: Executando ' + objCacic.getLocalFolderName + objCacic.getMainProgramName + ' /WebManagerAddress=' + objCacic.getWebManagerAddress+ ' /WebServicesFolderName=' + objCacic.getWebServicesFolderName)
else
objCacic.writeDebugLog('installCACIC: Executando ' + objCacic.getWinDir + 'chksis.exe /WebManagerAddress=' + objCacic.getWebManagerAddress + ' /WebServicesFolderName=' + objCacic.getWebServicesFolderName);
End
else
Begin
{*** 1 = SERVICE_STOPPED ***}
{*** 2 = SERVICE_START_PENDING ***}
{*** 3 = SERVICE_STOP_PENDING ***}
{*** 4 = SERVICE_RUNNING ***}
{*** 5 = SERVICE_CONTINUE_PENDING ***}
{*** 6 = SERVICE_PAUSE_PENDING ***}
{*** 7 = SERVICE_PAUSED ***}
informaProgresso('Verificando CACICservice.');
// Verifico se o serviço está instalado/rodando,etc.
wordServiceStatus := objCacic.ServiceGetStatus(nil,'CacicSustainService');
//Verifico o serviço para correção de bug
if wordServiceStatus <> 0 then
begin
//verifica o status, se não estiver correto altera
serviceType := objCacic.serviceGetType('', 'CacicSustainService');
end;
if (wordServiceStatus = 0) then
Begin
// Instalo e Habilito o serviço
informaProgresso('Instalando o CACICservice em modo silencioso.');
objCacic.createOneProcess(objCacic.getWinDir + 'cacicservice.exe /install /silent',true);
End
else if (wordServiceStatus < 4) then
Begin
informaProgresso('Iniciando o CACICservice');
objCacic.createOneProcess(objCacic.getWinDir + 'cacicservice.exe -start', true);
End
else if (wordServiceStatus > 4) then
Begin
informaProgresso('Continuando o CACICservice');
objCacic.createOneProcess(objCacic.getWinDir + 'cacicservice.exe -continue', true);
End
else
informaProgresso('CACICservice não foi instalado por já estar rodando!');
End;
if boolShowForm then
Begin
MessageDLG(#13#10+'ATENÇÃO!'+#13#10+#13#10+'Se o ícone do CACIC não for exibido na bandeja do sistema, é recomendável a reinicialização da máquina.',mtInformation,[mbOK],0);
informaProgresso('Executando o Agente Principal do CACIC.');
End;
if boolCanRunCACIC then
objCacic.createOneProcess(objCacic.getLocalFolderName + objCACIC.getMainProgramName, false);
End
else
if FileExists(objCacic.getLocalFolderName + 'aguarde_CACIC.txt') then
objCacic.writeDebugLog('installCACIC: CACIC em Execução!')
else
objCacic.writeDebugLog('installCACIC: Problema no Download do Verificador de Integridade do Sistema (ChkSIS)');
End;
Except
on E : Exception do
Begin
objCacic.writeExceptionLog(E.Message,E.ClassName,'Falha no processo de Instalação/Atualização');
informaProgresso('Falha no processo de Instalação/Atualização',true);
End;
End;
Except
on E : Exception do
Begin
objCacic.writeExceptionLog(E.Message,E.ClassName,'Falha na Instalação/Atualização');
informaProgresso('Falha na Instalação/Atualização',true);
End;
End;
if boolShowForm then
Begin
richProgress.ScrollBars := ssBoth;
richProgress.Perform(EM_SCROLLCARET,0,0);
End
else
btExitClick(nil);
end;
function TfrmInstallCACIC.serviceRunning(pCharMachineName, pCharServiceName: PChar): Boolean;
begin
Result := SERVICE_RUNNING = objCacic.ServiceGetStatus(pCharMachineName, pCharServiceName);
end;
function TfrmInstallCACIC.serviceStopped(pCharMachineName, pCharServiceName: PChar): Boolean;
begin
Result := SERVICE_STOPPED = objCacic.ServiceGetStatus(pCharMachineName, pCharServiceName);
end;
function TfrmInstallCACIC.findWindowByTitle(pStrWindowTitle: string): Hwnd;
var
NextHandle: Hwnd;
NextTitle: array[0..260] of char;
begin
// Get the first window
NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
while NextHandle > 0 do
begin
// retrieve its text
GetWindowText(NextHandle, NextTitle, 255);
if (trim(StrPas(NextTitle))<> '') and (Pos(strlower(pchar(pStrWindowTitle)), strlower(PChar(StrPas(NextTitle)))) <> 0) then
begin
Result := NextHandle;
Exit;
end
else
// Get the next window
NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
end;
Result := 0;
end;
procedure TfrmInstallCACIC.informaProgresso(pStrMessage : String; pBoolAlert : boolean = false);
Begin
if boolShowForm then
Begin
staticStatus.Font.Size := 8;
staticStatus.Font.Style := staticStatus.Font.Style - [fsBold];
staticStatus.Font.Color := clBlack;
richProgress.SelAttributes.Color := clWhite;
if pBoolAlert then
Begin
staticStatus.Font.Color := clMaroon;
richProgress.SelAttributes.Color := clYellow;
End;
staticStatus.Caption := pStrMessage;
richProgress.Lines.Add(pStrMessage);
richProgress.Perform(EM_SCROLLCARET,0,0);
richProgress.Repaint;
Application.ProcessMessages;
Application.ProcessMessages;
End;
objCacic.writeDailyLog(pStrMessage);
End;
procedure TfrmInstallCACIC.FS_SetSecurity(p_Target : String);
var intAux : integer;
v_FS_Security : TNTFileSecurity;
begin
v_FS_Security := TNTFileSecurity.Create(nil);
v_FS_Security.FileName := '';
v_FS_Security.FileName := p_Target;
v_FS_Security.RefreshSecurity;
if (v_FS_Security.FileSystemName='NTFS')then
Begin
for intAux := 0 to Pred(v_FS_Security.EntryCount) do
begin
case v_FS_Security.EntryType[intAux] of seAlias, seDomain, seGroup :
Begin // If local group, alias or user...
v_FS_Security.FileRights[intAux] := [faAll];
v_FS_Security.DirectoryRights[intAux] := [faAll];
objCacic.writeDebugLog('FS_SetSecurity: ' + p_Target + ' [Full Access] >> '+v_FS_Security.EntryName[intAux]);
//Setting total access on p_Target to local groups.
End;
End;
end;
// Atribui permissão total aos grupos locais
// Set total permissions to local groups
v_FS_Security.SetSecurity;
end
else
objCacic.writeDailyLog('File System: "' + v_FS_Security.FileSystemName+'" - Ok!');
v_FS_Security.Free;
end;
procedure TfrmInstallCACIC.btConfirmProcessClick(Sender: TObject);
var strCommResponseTest : String;
begin
if (trim(edWebManagerAddress.Text)<> '') then
Begin
Try
edWebManagerAddress.Text := objCacic.fixWebAddress(edWebManagerAddress.Text);
objCacic.setWebManagerAddress(edWebManagerAddress.Text);
informaProgresso('Efetuando comunicação com o endereço informado...');
strCommResponseTest := Comm(objCacic.getWebManagerAddress + objCacic.getWebServicesFolderName + 'get/test', strFieldsAndValuesToRequest, objCACIC.getLocalFolderName,'>> Testando conexão');
if (strCommResponseTest <> '0') then
Begin
objCacic.setBoolCipher(not objCacic.isInDebugMode);
if (objCacic.getFileHash(ParamStr(0)) = objCacic.deCrypt(objCacic.getValueFromTags('INSTALLCACIC.EXE_HASH',strCommResponseTest,'<>'),true,true)) then
Begin
objCacic.setLocalFolderName(objCacic.deCrypt(objCacic.getValueFromTags('LocalFolderName' ,strCommResponseTest,'<>')));
objCacic.setMainProgramName(objCacic.deCrypt(objCacic.getValueFromTags('MainProgramName' ,strCommResponseTest,'<>')));
objCacic.setWebManagerAddress(objCacic.deCrypt(objCacic.getValueFromTags('WebManagerAddress' ,strCommResponseTest,'<>')));
objCacic.setWebServicesFolderName(objCacic.deCrypt(objCacic.getValueFromTags('WebServicesFolderName',strCommResponseTest,'<>')));
staticStatus.Font.Size := 12;
staticStatus.Font.Style := [fsBold];
richProgress.Lines.Add('>> Teste de Conexão OK!');
staticStatus.Caption := 'Teste de Comunicação Efetuado Com Sucesso!';
staticStatus.Font.Color := clGreen;
frmInstallCACIC.btConfirmProcess.Enabled := false;
frmInstallCACIC.btExit.Enabled := false;
installCACIC;
frmInstallCACIC.btConfirmProcess.Enabled := true;
frmInstallCACIC.btExit.Enabled := true;
End
else
Begin
ShowMessage('ATENÇÃO:' + #13#10 +
'-------' + #13#10 + #13#10 +
'A estrutura deste instalador encontra-se diferente da estrutura disponibilizada no servidor "' + objCacic.getWebManagerAddress + '"'+ #13#10 + #13#10 + #13#10 +
'Parâmetro Local.: "' + objCacic.getFileHash(ParamStr(0)) + '"' + #13#10 +
'Parâmetro Remoto: "' + objCacic.deCrypt(objCacic.getValueFromTags('INSTALLCACIC.EXE_HASH',strCommResponseTest,'<>'),true,true) + '"' + #13#10 + #13#10 + #13#10 +
'Acesse ao servidor e baixe um novo executável através do link "Repositório" da página principal do Sistema CACIC.' + #13#10 + #13#10 + #13#10 +
'A EXECUÇÃO SERÁ FINALIZADA!' + #13#10 + #13#10 + #13#10);
btExitClick(nil);
End;
End
else
Begin
richProgress.Lines.Add('>> Teste de Conexão Negativo!');
staticStatus.Caption := 'Insucesso no Teste de Comunicação com o Endereço Informado!';
staticStatus.Font.Color := clRed;
edWebManagerAddress.SetFocus;
End;
Except
on E : Exception do
Begin
objCacic.writeExceptionLog(E.Message,E.ClassName,'Processo de instalação.');
End;
End;
End
else
Begin
staticStatus.Caption := 'Endereço de Acesso ao Gerente WEB Não Informado!';
staticStatus.Font.Color := clMaroon;
edWebManagerAddress.SetFocus;
End;
end;
procedure TfrmInstallCACIC.btExitClick(Sender: TObject);
begin
Application.Terminate;
end;
procedure TfrmInstallCACIC.FormActivate(Sender: TObject);
begin
pnVersao.Caption := objCacic.getVersionInfo(ParamStr(0));
end;
end.