-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.pas
executable file
·2767 lines (2431 loc) · 126 KB
/
main.pas
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
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(**
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Copyright 2000, 2001, 2002, 2003, 2004, 2005 Dataprev - Empresa de Tecnologia e Informa��es da Previd�ncia Social, Brasil
Este arquivo � parte do programa CACIC - Configurador Autom�tico e Coletor de Informa��es Computacionais
O CACIC � um software livre; voc� pode redistribui-lo e/ou modifica-lo dentro dos termos da Licen�a P�blica Geral GNU como
publicada pela Funda��o do Software Livre (FSF); na vers�o 2 da Licen�a, ou (na sua opini�o) qualquer vers�o.
Este programa � distribuido na esperan�a que possa ser util, mas SEM NENHUMA GARANTIA; sem uma garantia implicita de ADEQUA��O a qualquer
MERCADO ou APLICA��O EM PARTICULAR. Veja a Licen�a P�blica Geral GNU para maiores detalhes.
Voc� deve ter recebido uma c�pia da Licen�a P�blica Geral GNU, sob o t�tulo "LICENCA.txt", junto com este programa, se n�o, escreva para a Funda��o do Software
Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
---------------------------------------------------------------------------------------------------------------------------------------------------------------
*)
unit main;
interface
uses
Windows,
Messages,
Forms,
Menus,
Classes,
SysUtils,
Controls,
StdCtrls,
ExtCtrls,
ShellAPI,
registry,
dialogs,
ComCtrls,
IdBaseComponent,
IdComponent,
Buttons,
CACIC_Library,
CACIC_WMI,
ImgList,
Graphics,
USBdetectClass,
WinSVC,
SHChangeNotify, TrayIcon, AppEvnts;
//IdTCPServer;
//IdFTPServer;
const
KBYTE = Sizeof(Byte) shl 10;
MBYTE = KBYTE shl 10;
GBYTE = MBYTE shl 10;
NORMAL = 0; // Normal
COLETANDO = 1; // Raio - Coletando
DESCONFIGURADO = 2; // Interroga��o - Identificando Host
EM_SUPORTE = 3; // Telefone - Em Suporte Remoto
LEFT_MENU_ITEM = 13; // Coordenada X para escrita das op��es do menu de contexto
// Declara��o das vari�veis globais.
var strConfigsPatrimonio,
strMenuCaptionLAT,
strMenuCaptionCON,
strMenuCaptionEXE,
strMenuCaptionINF,
strMenuCaptionSUP,
strMenuCaptionFIN : string;
g_intTaskBarAtual,
g_intTaskBarAnterior,
g_intDesktopWindow,
g_intStatus,
g_intStatusAnterior,
g_intIconIndex : integer;
bl_primeira_execucao : bool = false;
objCACIC: TCACIC;
type
TFormularioGeral = class(TForm)
Pn_InfosGerais: TPanel;
Pn_SisMoni: TPanel;
Lb_SisMoni: TLabel;
Pn_TCPIP: TPanel;
Lb_TCPIP: TLabel;
GB_InfosTCPIP: TGroupBox;
ST_VL_MacAddress: TStaticText;
ST_LB_MacAddress: TStaticText;
ST_LB_NomeHost: TStaticText;
ST_VL_NomeHost: TStaticText;
ST_LB_IpEstacao: TStaticText;
ST_LB_IpRede: TStaticText;
ST_LB_DominioDNS: TStaticText;
ST_LB_DnsPrimario: TStaticText;
ST_LB_DnsSecundario: TStaticText;
ST_LB_Gateway: TStaticText;
ST_LB_Mascara: TStaticText;
ST_LB_ServidorDHCP: TStaticText;
ST_LB_WinsPrimario: TStaticText;
ST_LB_WinsSecundario: TStaticText;
ST_VL_IpEstacao: TStaticText;
ST_VL_DNSPrimario: TStaticText;
ST_VL_DNSSecundario: TStaticText;
ST_VL_Gateway: TStaticText;
ST_VL_Mascara: TStaticText;
ST_VL_ServidorDHCP: TStaticText;
ST_VL_WinsPrimario: TStaticText;
ST_VL_WinsSecundario: TStaticText;
ST_VL_DominioDNS: TStaticText;
ST_VL_IpRede: TStaticText;
Pn_Linha1_TCPIP: TPanel;
Pn_Linha2_TCPIP: TPanel;
Pn_Linha3_TCPIP: TPanel;
Pn_Linha4_TCPIP: TPanel;
Pn_Linha6_TCPIP: TPanel;
Pn_Linha5_TCPIP: TPanel;
timerNuExecApos: TTimer;
Popup_Menu_Contexto: TPopupMenu;
Mnu_LogAtividades: TMenuItem;
Mnu_Configuracoes: TMenuItem;
Mnu_ExecutarAgora: TMenuItem;
Mnu_InformacoesGerais: TMenuItem;
Mnu_FinalizarCacic: TMenuItem;
listSistemasMonitorados: TListView;
pnColetasRealizadasNestaData: TPanel;
lbColetasRealizadasNestaData: TLabel;
listaColetas: TListView;
teDataColeta: TLabel;
pnInformacoesPatrimoniais: TPanel;
lbInformacoesPatrimoniais: TLabel;
gpInfosPatrimoniais: TGroupBox;
st_lb_Etiqueta5: TStaticText;
st_lb_Etiqueta1: TStaticText;
st_vl_Etiqueta1: TStaticText;
st_lb_Etiqueta1a: TStaticText;
st_lb_Etiqueta2: TStaticText;
st_lb_Etiqueta7: TStaticText;
st_lb_Etiqueta6: TStaticText;
st_lb_Etiqueta8: TStaticText;
st_vl_Etiqueta1a: TStaticText;
st_vl_Etiqueta2: TStaticText;
Panel6: TPanel;
Panel7: TPanel;
Panel8: TPanel;
Panel9: TPanel;
Panel11: TPanel;
st_lb_Etiqueta4: TStaticText;
st_lb_Etiqueta3: TStaticText;
st_vl_Etiqueta3: TStaticText;
st_lb_Etiqueta9: TStaticText;
st_vl_etiqueta4: TStaticText;
st_vl_etiqueta5: TStaticText;
st_vl_etiqueta6: TStaticText;
st_vl_etiqueta7: TStaticText;
st_vl_etiqueta8: TStaticText;
st_vl_etiqueta9: TStaticText;
Mnu_SuporteRemoto: TMenuItem;
lbSemInformacoesPatrimoniais: TLabel;
pnServidores: TPanel;
lbServidores: TLabel;
GroupBox1: TGroupBox;
staticVlServidorUpdates: TStaticText;
staticNmServidorUpdates: TStaticText;
staticNmServidorAplicacao: TStaticText;
staticVlServidorAplicacao: TStaticText;
Panel4: TPanel;
Panel3: TPanel;
pnVersao: TPanel;
bt_Fechar_Infos_Gerais: TBitBtn;
ST_LB_DominioWindows: TStaticText;
ST_VL_DominioWindows: TStaticText;
cn: TSHChangeNotify;
imgIconList: TImageList;
timerCheckNoMinuto: TTimer;
timerNuIntervalo: TTimer;
TrayIcon1: TTrayIcon;
ApplicationEvents1: TApplicationEvents;
Panel1: TPanel;
ExecutarMapa1: TMenuItem;
CheckForcaColeta: TTimer;
procedure RemoveIconesMortos;
procedure ChecaCONFIGS;
procedure CriaFormSenha(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Sair(Sender: TObject);
procedure MinimizaParaTrayArea(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure ExecutaCACIC(Sender: TObject);
procedure SetaVariaveisGlobais;
procedure ExibirLogAtividades(Sender: TObject);
procedure ExibirConfiguracoes(Sender: TObject);
procedure HabilitaInformacoesGerais;
procedure HabilitaSuporteRemoto;
procedure Mnu_InformacoesGeraisClick(Sender: TObject);
procedure Bt_Fechar_InfosGeraisClick(Sender: TObject);
function ChecaGERCOLS : boolean;
function ChecaMAPACACIC : boolean;
function FindWindowByTitle(WindowTitle: string): Hwnd;
function ActualActivity : integer;
function Posso_Rodar : boolean;
{
procedure IdHTTPServerCACICCommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
procedure IdFTPServer1UserLogin(ASender: TIdFTPServerThread;
const AUsername, APassword: String; var AAuthenticated: Boolean);
}
procedure Mnu_SuporteRemotoClick(Sender: TObject);
procedure Popup_Menu_ContextoPopup(Sender: TObject);
procedure CNAssocChanged(Sender: TObject; Flags: Cardinal; Path1,
Path2: String);
procedure CNAttributes(Sender: TObject; Flags: Cardinal;
Path1: String);
procedure CNCreate(Sender: TObject; Flags: Cardinal; Path1: String);
procedure CNDelete(Sender: TObject; Flags: Cardinal; Path1: String);
procedure CNDriveAdd(Sender: TObject; Flags: Cardinal; Path1: String);
procedure CNDriveAddGUI(Sender: TObject; Flags: Cardinal;
Path1: String);
procedure CNDriveRemoved(Sender: TObject; Flags: Cardinal;
Path1: String);
procedure CNEndSessionQuery(Sender: TObject;
var CanEndSession: Boolean);
procedure CNMediaInserted(Sender: TObject; Flags: Cardinal;
Path1: String);
procedure CNMediaRemoved(Sender: TObject; Flags: Cardinal;
Path1: String);
procedure CNMkDir(Sender: TObject; Flags: Cardinal; Path1: String);
procedure CNNetShare(Sender: TObject; Flags: Cardinal; Path1: String);
procedure CNNetUnshare(Sender: TObject; Flags: Cardinal;
Path1: String);
procedure CNRenameFolder(Sender: TObject; Flags: Cardinal; Path1,
Path2: String);
procedure CNRenameItem(Sender: TObject; Flags: Cardinal; Path1,
Path2: String);
procedure CNRmDir(Sender: TObject; Flags: Cardinal; Path1: String);
procedure CNServerDisconnect(Sender: TObject; Flags: Cardinal;
Path1: String);
procedure CNUpdateDir(Sender: TObject; Flags: Cardinal; Path1: String);
procedure CNUpdateImage(Sender: TObject; Flags: Cardinal;
Path1: String);
procedure CNUpdateItem(Sender: TObject; Flags: Cardinal;
Path1: String);
procedure timerCheckNoMinutoTimer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Mnu_LogAtividadesDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure Mnu_ConfiguracoesDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure Mnu_ExecutarAgoraDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure Mnu_InformacoesGeraisDrawItem(Sender: TObject;
ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
procedure Mnu_SuporteRemotoDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure Mnu_FinalizarCacicDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure timerNuExecAposTimer(Sender: TObject);
procedure timerNuIntervaloTimer(Sender: TObject);
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
procedure InvocaMapa1Click(Sender: TObject);
procedure ExecutarMapa1DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure CheckForcaColetaTimer(Sender: TObject);
private
FUsb : TUsbClass;
ShutdownEmExecucao : Boolean;
tstrListRCActions : TStringList;
IsMenuOpen : Boolean;
procedure CheckRCActions(pStrRCAction : String = '');
procedure UsbIN(ASender : TObject; const ADevType,AVendorID,ADeviceID : string);
procedure UsbOUT(ASender : TObject; const ADevType,AVendorID,ADeviceID : string);
procedure InicializaTray;
procedure Finaliza(boolNormal : boolean = true);
// procedure MontaVetoresPatrimonio(p_strConfigs : String);
procedure Invoca_GerCols(p_acao:string; boolShowInfo : Boolean = true; boolCheckExecution : Boolean = false);
procedure Invoca_MapaCacic;
procedure CheckIfDownloadedVersion;
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
// A procedure WMQueryEndSession � usada para detectar o
// Shutdown do Windows e "derrubar" o Cacic.
procedure WMQueryEndSession(var Msg : TWMQueryEndSession); Message WM_QUERYENDSESSION;
procedure WMMENUSELECT(var msg: TWMMENUSELECT); message WM_MENUSELECT;
function getDesktopWindowHandle : integer;
function RetornaValorVetorUON1(id1 : string) : String;
function RetornaValorVetorUON1a(id1a : string) : String;
function RetornaValorVetorUON2(id2, idLocal: string) : String;
function ServiceStart(sMachine,sService : string ) : boolean;
protected
public
strMainProgramInfFileName,
strChkSisInfFileName,
strGerColsInfFileName : String;
function URLDecode(const S: string): string;
procedure DrawBar(ACanvas: TCanvas); // TrayIcon - Peterles
end;
var FormularioGeral : TFormularioGeral;
boolServerON : Boolean;
strWin32_ComputerSystem,
strWin32_NetworkAdapterConfiguration : String;
rmTaskbarCreated : DWord;
implementation
{$R *.dfm}
Uses StrUtils,
Inifiles,
frmConfiguracoes,
frmSenha,
frmLog,
Math;
// Estruturas de dados para armazenar os itens da uon1, uon1a e uon2
type
TRegistroUON1 = record
id1 : String;
nm1 : String;
end;
TVetorUON1 = array of TRegistroUON1;
TRegistroUON1a = record
id1 : String;
id1a : String;
nm1a : String;
id_local: String;
end;
TVetorUON1a = array of TRegistroUON1a;
TRegistroUON2 = record
id1a : String;
id2 : String;
nm2 : String;
id_local: String;
end;
TVetorUON2 = array of TRegistroUON2;
var VetorUON1 : TVetorUON1;
VetorUON1a : TVetorUON1a;
VetorUON2 : TVetorUON2;
Function TFormularioGeral.RetornaValorVetorUON1(id1 : string) : String;
var I : Integer;
begin
For I := 0 to (Length(VetorUON1)-1) Do
If (VetorUON1[I].id1 = id1) Then Result := VetorUON1[I].nm1;
end;
Function TFormularioGeral.RetornaValorVetorUON1a(id1a : string) : String;
var I : Integer;
begin
For I := 0 to (Length(VetorUON1a)-1) Do
If (VetorUON1a[I].id1a = id1a) Then Result := VetorUON1a[I].nm1a;
end;
Function TFormularioGeral.RetornaValorVetorUON2(id2, idLocal: string) : String;
var I : Integer;
begin
For I := 0 to (Length(VetorUON2)-1) Do
If (VetorUON2[I].id2 = id2) and
(VetorUON2[I].id_local = idLocal) Then Result := VetorUON2[I].nm2;
end;
procedure TFormularioGeral.DrawBar(ACanvas: TCanvas);
var
lf : TLogFont;
tf : TFont;
begin
with ACanvas do begin
Brush.Color := clGrayText;
FillRect(Rect(0, //ALeft
0, //ATop
12, //ARight
122));//ABottom
Font.Name := 'Arial';
Font.Size := 7;
Font.Style := [fsBold];
Font.Color := clWhite;
tf := TFont.Create;
try
tf.Assign(Font);
GetObject(tf.Handle, sizeof(lf), @lf);
lf.lfEscapement := 900;
lf.lfHeight := Font.Height ;
tf.Handle := CreateFontIndirect(lf);
Font.Assign(tf);
finally
tf.Free;
end;
TextOut( -1, // X
102, pnVersao.Caption);
end;
end;
function TFormularioGeral.ServiceStart(sMachine,sService : string ) : boolean;
var
schm, // Service Control Manager Handle
schs : SC_Handle; // Service Handle
ss : TServiceStatus; // Service Status
psTemp : PChar; // Temp Char Pointer
dwChkP : DWord; // Check Point
begin
// ss.dwCurrentState := -1;
objCACIC.writeDebugLog('ServiceStart: ' + sService + ' - Iniciando!');
ss.dwCurrentState := 0;
// connect to the Service Control Manager
schm := OpenSCManager(PChar(sMachine),Nil,SC_MANAGER_CONNECT);
// if successful...
if(schm > 0)then
begin
// open a handle to the specified service
schs := OpenService(schm,PChar(sService),SERVICE_START or SERVICE_QUERY_STATUS); // we want to start the service and query service status
// if successful...
if(schs > 0)then
begin
psTemp := Nil;
if(StartService(
schs,
0,
psTemp))then
begin
// 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.
//
// save current value
//
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
// couldn't check status break from the loop
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;
end;
// close service handle
CloseServiceHandle(schs);
end;
// close service control manager handle
CloseServiceHandle(schm);
end;
// return TRUE if the service status is running
Result := SERVICE_RUNNING = ss.dwCurrentState;
if Result then
objCACIC.writeDebugLog('ServiceStart: ' + sService + ' - OK!')
else
objCACIC.writeDebugLog('ServiceStart: ' + sService + ' - N�o Foi Poss�vel Iniciar!');
end;
// In�cio de Procedimentos para monitoramento de dispositivos USB - Anderson Peterle - 02/2010
procedure TFormularioGeral.UsbIN(ASender : TObject; const ADevType,AVendorID,ADeviceID : string);
begin
// Envio de valores ao Gerente WEB
// Formato: USBinfo=I_ddmmyyyyhhnnss_ADeviceID
// Os valores ser�o armazenados localmente (cacic280.inf) se for imposs�vel o envio.
objCACIC.writeDebugLog('UsbIN: << USB INSERIDO .:. Vendor ID => ' + AVendorID + ' .:. Device ID = ' + ADeviceID);
Invoca_GerCols('USBinfo=I_'+FormatDateTime('yyyymmddhhnnss', now) + '_' + AVendorID + '_' + ADeviceID, false, false);
end;
procedure TFormularioGeral.UsbOUT(ASender : TObject; const ADevType,AVendorID,ADeviceID : string);
begin
// Envio de valores ao Gerente WEB
// Formato: USBinfo=O_ddmmyyyyhhnnss_ADeviceID
// Os valores ser�o armazenados localmente (cacic280.inf) se for imposs�vel o envio.
objCACIC.writeDebugLog('UsbOUT: >> USB REMOVIDO .:. Vendor ID => ' + AVendorID + ' .:. Device ID = ' + ADeviceID);
Invoca_GerCols('USBinfo=O_'+FormatDateTime('yyyymmddhhnnss', now) + '_' + AVendorID + '_' + ADeviceID, false, false);
end;
// Fim de Procedimentos para monitoramento de dispositivos USB - Anderson Peterle - 02/2010
{
procedure TFormularioGeral.MontaVetoresPatrimonio(p_strConfigs : String);
var Parser : TXmlParser;
i : integer;
strAux,
strAux1,
strTagName,
strItemName : string;
begin
Parser := TXmlParser.Create;
Parser.Normalize := True;
Parser.LoadFromBuffer(PAnsiChar(p_strConfigs));
objCACIC.writeDebugLog('MontaVetoresPatrimonio: p_strConfigs: '+p_strConfigs);
// C�digo para montar o vetor UON1
Parser.StartScan;
i := -1;
strItemName := '';
strTagName := '';
While Parser.Scan DO
Begin
strItemName := UpperCase(Parser.CurName);
if (Parser.CurPartType = ptStartTag) and (strItemName = 'IT1') Then
Begin
i := i + 1;
SetLength(VetorUON1, i + 1); // Aumento o tamanho da matriz dinamicamente de acordo com o n�mero de itens recebidos.
strTagName := 'IT1';
end
else if (Parser.CurPartType = ptEndTag) and (strItemName = 'IT1') then
strTagName := ''
else if (Parser.CurPartType in [ptContent, ptCData]) and (strTagName='IT1')Then
Begin
strAux1 := objCACIC.deCrypt(Parser.CurContent);
if (strItemName = 'ID1') then
Begin
VetorUON1[i].id1 := strAux1;
objCACIC.writeDebugLog('MontaVetoresPatrimonio: Gravei VetorUON1.id1: "'+strAux1+'"');
End
else if (strItemName = 'NM1') then
Begin
VetorUON1[i].nm1 := strAux1;
objCACIC.writeDebugLog('MontaVetoresPatrimonio: Gravei VetorUON1.nm1: "'+strAux1+'"');
End;
End;
End;
// C�digo para montar o vetor UON1a
Parser.StartScan;
strTagName := '';
strAux1 := '';
i := -1;
While Parser.Scan DO
Begin
strItemName := UpperCase(Parser.CurName);
if (Parser.CurPartType = ptStartTag) and (strItemName = 'IT1A') Then
Begin
i := i + 1;
SetLength(VetorUON1a, i + 1); // Aumento o tamanho da matriz dinamicamente de acordo com o n�mero de itens recebidos.
strTagName := 'IT1A';
end
else if (Parser.CurPartType = ptEndTag) and (strItemName = 'IT1A') then
strTagName := ''
else if (Parser.CurPartType in [ptContent, ptCData]) and (strTagName='IT1A')Then
Begin
strAux1 := objCACIC.deCrypt(Parser.CurContent);
if (strItemName = 'ID1') then
Begin
VetorUON1a[i].id1 := strAux1;
objCACIC.writeDebugLog('Gravei VetorUON1a.id1: "'+strAux1+'"');
End
else if (strItemName = 'SG_LOC') then
Begin
strAux := ' ('+strAux1 + ')';
End
else if (strItemName = 'ID1A') then
Begin
VetorUON1a[i].id1a := strAux1;
objCACIC.writeDebugLog('Gravei VetorUON1a.id1a: "'+strAux1+'"');
End
else if (strItemName = 'NM1A') then
Begin
VetorUON1a[i].nm1a := strAux1+strAux;
objCACIC.writeDebugLog('Gravei VetorUON1a.nm1a: "'+strAux1+strAux+'"');
End
else if (strItemName = 'ID_LOCAL') then
Begin
VetorUON1a[i].id_local := strAux1;
objCACIC.writeDebugLog('Gravei VetorUON1a.id_local: "'+strAux1+'"');
End;
End;
end;
// C�digo para montar o vetor UON2
Parser.StartScan;
strTagName := '';
i := -1;
While Parser.Scan DO
Begin
strItemName := UpperCase(Parser.CurName);
if (Parser.CurPartType = ptStartTag) and (strItemName = 'IT2') Then
Begin
i := i + 1;
SetLength(VetorUON2, i + 1); // Aumento o tamanho da matriz dinamicamente de acordo com o n�mero de itens recebidos.
strTagName := 'IT2';
end
else if (Parser.CurPartType = ptEndTag) and (strItemName = 'IT2') then
strTagName := ''
else if (Parser.CurPartType in [ptContent, ptCData]) and (strTagName='IT2')Then
Begin
strAux1 := objCACIC.deCrypt(Parser.CurContent);
if (strItemName = 'ID1A') then
Begin
VetorUON2[i].id1a := strAux1;
objCACIC.writeDebugLog('Gravei VetorUON2.id1a: "'+strAux1+'"');
End
else if (strItemName = 'ID2') then
Begin
VetorUON2[i].id2 := strAux1;
objCACIC.writeDebugLog('Gravei VetorUON2.id2: "'+strAux1+'"');
End
else if (strItemName = 'NM2') then
Begin
VetorUON2[i].nm2 := strAux1;
objCACIC.writeDebugLog('Gravei VetorUON2.nm2: "'+strAux1+'"');
End
else if (strItemName = 'ID_LOCAL') then
Begin
VetorUON2[i].id_local := strAux1;
objCACIC.writeDebugLog('Gravei VetorUON2.id_local: "'+strAux1+'"');
End;
End;
end;
Parser.Free;
end;
}
function TFormularioGeral.ActualActivity : integer;
Begin
// Se eu conseguir matar os arquivos abaixo � porque srCACICsrv, GerCols e mapaCACIC j� finalizaram suas atividades...
objCACIC.writeDebugLog('ActualActivity: BEGIN');
objCACIC.deleteFileOrFolder(objCACIC.getLocalFolderName + 'Temp\aguarde_GER.txt');
objCACIC.deleteFileOrFolder(objCACIC.getLocalFolderName + 'Temp\aguarde_SRCACIC.txt');
objCACIC.deleteFileOrFolder(objCACIC.getLocalFolderName + 'Temp\aguarde_MAPACACIC.txt');
if not FileExists(objCACIC.getLocalFolderName + 'Temp\aguarde_GER.txt') and
not FileExists(objCACIC.getLocalFolderName + 'Temp\aguarde_SRCACIC.txt') and
not FileExists(objCACIC.getLocalFolderName + 'Temp\aguarde_MAPACACIC.txt') then
Result := 0 // NORMAL
else if FileExists(objCACIC.getLocalFolderName + 'Temp\aguarde_GER.txt') then
Result := 1 // COLETANDO
else if FileExists(objCACIC.getLocalFolderName + 'Temp\aguarde_SRCACIC.txt') then
Result := 3 // EM SUPORTE REMOTO
else if FileExists(objCacic.getLocalFolderName + 'Temp\aguarde_MAPACACIC.txt') then
Result := 4;
objCACIC.writeDebugLog('ActualActivity: Retornando '+IntToStr(Result));
objCACIC.writeDebugLog('ActualActivity: END');
End;
function Pode_Coletar : boolean;
var v_JANELAS_EXCECAO,
v_plural1,
v_plural2 : string;
tstrJANELAS : TStrings;
h : hwnd;
v_contador, intContaJANELAS, intAux : integer;
Begin
intContaJANELAS := 0;
h := 0;
if (FormularioGeral.ActualActivity = 0) then
Begin
// Verifica��o das janelas abertas para que n�o aconte�a coletas caso haja aplica��es pesadas rodando (configurado no M�dulo Gerente)
v_JANELAS_EXCECAO := objCACIC.GetValueFromFile('Configs','TeJanelasExcecao', FormularioGeral.strMainProgramInfFileName);
objCACIC.writeDebugLog('Pode_Coletar: Verificando Janelas para Exce��o...');
tstrJANELAS := TStrings.Create;
if (v_JANELAS_EXCECAO <> '') then
Begin
tstrJANELAS := objCACIC.explode(trim(v_JANELAS_EXCECAO),',');
if (tstrJANELAS.Count > 0) then
for intAux := 0 to tstrJANELAS.Count-1 Do
Begin
h := FormularioGeral.FindWindowByTitle(tstrJANELAS[intAux]);
if h <> 0 then intContaJANELAS := 1;
break;
End;
End;
// Caso alguma janela tenha algum nome de aplica��o cadastrada como "cr�tica" ou "pesada"...
if (intContaJANELAS > 0) then
Begin
objCACIC.writeDailyLog('EXECU��O DE ATIVIDADES ADIADA!');
v_contador := 0;
v_plural1 := '';
v_plural2 := '�O';
for intAux := 0 to tstrJANELAS.Count-1 Do
Begin
h := FormularioGeral.FindWindowByTitle(tstrJANELAS[intAux]);
if h <> 0 then
Begin
v_contador := v_contador + 1;
objCACIC.writeDailyLog('Aplica��o/Janela ' + inttostr(v_contador) + ': ' + tstrJANELAS[intAux]);
End;
End;
if (v_contador > 1) then
Begin
v_plural1 := 'S';
v_plural2 := '�ES';
End;
objCACIC.writeDailyLog('-> PARA PROCEDER, FINALIZE A' + v_plural1 + ' APLICA�' + v_plural2 + ' LISTADA' + v_plural1 + ' ACIMA.');
End;
End;
if (intContaJANELAS = 0) and (h = 0) and (FormularioGeral.ActualActivity = 0) then
Result := true
else
Begin
objCACIC.writeDebugLog('Pode_Coletar: A A��o foi NEGADA!');
if (intContaJANELAS=0) then
Begin
if (FileExists(objCACIC.getLocalFolderName + 'Temp\aguarde_GER.txt')) then
objCACIC.writeDebugLog('Pode_Coletar: Gerente de Coletas em atividade.');
if (FileExists(objCACIC.getLocalFolderName + 'Temp\aguarde_SRCACIC.txt')) then
objCACIC.writeDebugLog('Pode_Coletar: Suporte Remoto em atividade.');
if (FileExists(objCACIC.getLocalFolderName + 'Temp\aguarde_MAPACACIC.txt')) then
objCACIC.writeDebugLog('Pode_Coletar: M�dulo Avulso para Coleta de Patrim�nio em atividade.');
End;
//else
// objCACIC.cipherClose(objCACIC.getLocalFolderName + objCACIC.getDatFileName,v_tstrCipherOpened);
Result := false;
End;
End;
Procedure TFormularioGeral.RemoveIconesMortos;
var
TrayWindow : HWnd;
WindowRect : TRect;
SmallIconWidth : Integer;
SmallIconHeight : Integer;
CursorPos : TPoint;
Row : Integer;
Col : Integer;
begin
{ Get tray window handle and bounding rectangle }
TrayWindow := FindWindowEx(FindWindow('Shell_TrayWnd',NIL),0,'TrayNotifyWnd',NIL);
if not GetWindowRect(TrayWindow,WindowRect) then
Exit;
{ Get small icon metrics }
SmallIconWidth := GetSystemMetrics(SM_CXSMICON);
SmallIconHeight := GetSystemMetrics(SM_CYSMICON);
{ Save current mouse position }
GetCursorPos(CursorPos);
{ Sweep the mouse cursor over each icon in the tray in both dimensions }
with WindowRect do
begin
for Row := 0 to (Bottom - Top) DIV SmallIconHeight do
begin
for Col := 0 to (Right - Left) DIV SmallIconWidth do
begin
SetCursorPos(Left + Col * SmallIconWidth, Top + Row * SmallIconHeight);
Sleep(0);
end;
end;
end;
{ Restore mouse position }
SetCursorPos(CursorPos.X,CursorPos.Y);
{ Redraw tray window (to fix bug in multi-line tray area) }
RedrawWindow(TrayWindow,NIL,0,RDW_INVALIDATE OR RDW_ERASE OR RDW_UPDATENOW);
End;
procedure TFormularioGeral.WMMENUSELECT(var msg: TWMMENUSELECT);
begin
inherited;
IsMenuOpen := not ((msg.MenuFlag and $FFFF > 0) and (msg.Menu = 0));
end;
// Verifico a exist�ncia do Gerente de Coletas, caso n�o exista, o chksis.exe far� download!
function TFormularioGeral.ChecaMAPACACIC : boolean;
var strFileSize : String;
Begin
Result := true;
objCACIC.writeDebugLog('ChecaMAPA: Verificando exist�ncia e tamanho do Gerente de Coletas...');
strFileSize := objCACIC.getFileSize(objCACIC.getLocalFolderName + 'Modules\mapacacic.exe',true);
if ((objCACIC.getFileHash(objCACIC.getLocalFolderName + 'Modules\mapacacic.exe') <>
objCACIC.getValueFromFile('Hash-Codes', 'MAPACACIC.EXE', strChksisInfFileName)) or
(strFileSize <= '0')) then
begin
Result := false;
objCACIC.deleteFileOrFolder(objCACIC.getLocalFolderName + 'Modules\mapacacic.exe');
InicializaTray;
objCACIC.writeDailyLog('Acionando Recuperador de Mapa Cacic.');
objCACIC.writeDebugLog('ChecaMAPACACIC: Acionando Recuperador de M�dulo Gerente de Coletas: '+objCACIC.getWinDir + 'chksis.exe');
objCACIC.createOneProcess(objCACIC.getWinDir + 'chksis.exe',true,SW_HIDE);
objCacic.setBoolCipher(not objCacic.isInDebugMode);
strFileSize := objCACIC.getFileSize(objCACIC.getLocalFolderName + '\Modules\mapacacic.exe',true);
if not(strFileSize = '0') and not(strFileSize = '-1') then
Begin
objCACIC.writeDailyLog('M�dulo Mapa Cacic RECUPERADO COM SUCESSO!');
objCACIC.writeDebugLog('ChecaMAPACACIC: M�dulo Gerente de Coletas RECUPERADO COM SUCESSO!');
InicializaTray;
Result := True;
End
else
Begin
objCACIC.writeDailyLog('M�dulo Mapa Cacic N�O RECUPERADO!');
objCACIC.writeDebugLog('ChecaMAPACACIC: M�dulo Gerente de Coletas N�O RECUPERADO!');
End;
objCACIC.writeDebugLog('ChecaMAPACACIC: ' + DupeString('=',100));
end;
End;
// Verifico a exist�ncia do Gerente de Coletas, caso n�o exista, o chksis.exe far� download!
function TFormularioGeral.ChecaGERCOLS : boolean;
var strFileSize : String;
Begin
Result := true;
objCACIC.writeDebugLog('ChecaGERCOLS: Verificando exist�ncia e tamanho do Gerente de Coletas...');
strFileSize := objCACIC.getFileSize(objCACIC.getLocalFolderName + 'Modules\gercols.exe',true);
if (strFileSize = '0') or (strFileSize = '-1') then
Begin
Result := false;
objCACIC.deleteFileOrFolder(objCACIC.getLocalFolderName + 'Modules\gercols.exe');
InicializaTray;
objCACIC.writeDailyLog('Acionando Recuperador de M�dulo Gerente de Coletas.');
objCACIC.writeDebugLog('ChecaGERCOLS: Acionando Recuperador de M�dulo Gerente de Coletas: '+objCACIC.getWinDir + 'chksis.exe');
objCACIC.createOneProcess(objCACIC.getWinDir + 'chksis.exe',false,SW_HIDE);
sleep(30000); // 30 segundos de espera para download do gercols.exe
objCacic.setBoolCipher(not objCacic.isInDebugMode);
strFileSize := objCACIC.getFileSize(objCACIC.getLocalFolderName + '\Modules\gercols.exe',true);
if not(strFileSize = '0') and not(strFileSize = '-1') then
Begin
objCACIC.writeDailyLog('M�dulo Gerente de Coletas RECUPERADO COM SUCESSO!');
objCACIC.writeDebugLog('ChecaGERCOLS: M�dulo Gerente de Coletas RECUPERADO COM SUCESSO!');
InicializaTray;
Result := True;
End
else
Begin
objCACIC.writeDailyLog('M�dulo Gerente de Coletas N�O RECUPERADO!');
objCACIC.writeDebugLog('ChecaGERCOLS: M�dulo Gerente de Coletas N�O RECUPERADO!');
End;
End;
objCACIC.writeDebugLog('ChecaGERCOLS: ' + DupeString('=',100));
End;
procedure ExibirConfiguracoes(Sender: TObject);
begin
// SJI = Senha J� Informada...
// Esse valor � inicializado com "N"
if (objCACIC.deCrypt( objCACIC.GetValueFromFile('Configs','SJI',FormularioGeral.strMainProgramInfFileName)) = '') and
(objCACIC.GetValueFromFile('Configs','WebManagerAddress',FormularioGeral.strChkSisInfFileName) <> '') then
begin
FormularioGeral.CriaFormSenha(nil);
formSenha.ShowModal;
end;
if (objCACIC.deCrypt( objCACIC.GetValueFromFile('Configs','SJI',FormularioGeral.strMainProgramInfFileName)) <> '') or
(objCACIC.GetValueFromFile('Configs','WebManagerAddress',FormularioGeral.strChkSisInfFileName) = '') then
begin
Application.CreateForm(TFormConfiguracoes, FormConfiguracoes);
FormConfiguracoes.ShowModal;
end;
end;
procedure TFormularioGeral.CriaFormSenha(Sender: TObject);
begin
// Caso ainda n�o exista senha para administra��o do CACIC, define ADMINCACIC como inicial.
if (objCACIC.deCrypt( objCACIC.GetValueFromFile('Configs','TeSenhaAdmAgente',FormularioGeral.strMainProgramInfFileName),false,true) = '') Then
objCACIC.setValueToFile('Configs','TeSenhaAdmAgente', objCACIC.enCrypt('ADMINCACIC'), FormularioGeral.strMainProgramInfFileName);
Application.CreateForm(TFormSenha, FormSenha);
end;
procedure TFormularioGeral.ChecaCONFIGS;
var strAux : string;
Begin
// Verifico se o endere�o do servidor do cacic foi configurado.
if (objCACIC.GetValueFromFile('Configs','WebManagerAddress',strChkSisInfFileName) = '') then
Begin
strAux := objCACIC.fixWebAddress(objCACIC.GetValueFromFile('Configs','WebManagerAddress', strChkSisInfFileName));
if (strAux = '') then
begin
strAux := 'ATEN��O: Endere�o do servidor do CACIC ainda n�o foi configurado.';
objCACIC.writeDailyLog(strAux);
objCACIC.writeDailyLog('Ativando m�dulo de configura��o de endere�o de servidor.');
MessageDlg(strAux + chr(13) + 'Por favor, informe o endere�o do servidor do CACIC na tela que ser� exibida a seguir.', mtWarning, [mbOk], 0);
ExibirConfiguracoes(Nil);
end;
End;
end;
procedure TFormularioGeral.HabilitaInformacoesGerais;
Begin
// Desabilita/Habilita a op��o de Informa��es Gerais
Mnu_InformacoesGerais.Enabled := (objCACIC.getValueFromTags('Caption' ,strWin32_ComputerSystem) +
objCACIC.getValueFromTags('IPAddress' ,strWin32_NetworkAdapterConfiguration) +
objCACIC.getValueFromTags('DNSDomain' ,strWin32_NetworkAdapterConfiguration) +
objCACIC.getValueFromTags('DNSHostName' ,strWin32_NetworkAdapterConfiguration) +
objCACIC.getValueFromTags('DNSServerSearchOrder',strWin32_NetworkAdapterConfiguration) +
objCACIC.getValueFromTags('DefaultIPGateway' ,strWin32_NetworkAdapterConfiguration) +
objCACIC.getValueFromTags('IPSubnet' ,strWin32_NetworkAdapterConfiguration) +
objCACIC.getValueFromTags('DHCPServer' ,strWin32_NetworkAdapterConfiguration) +
objCACIC.getValueFromTags('WINSPrimaryServer' ,strWin32_NetworkAdapterConfiguration) +
objCACIC.getValueFromTags('WINSSecondaryServer' ,strWin32_NetworkAdapterConfiguration) <> '');
End;
procedure TFormularioGeral.HabilitaSuporteRemoto;
Begin
// Desabilita/Habilita a op��o de Suporte Remoto
Mnu_SuporteRemoto.Enabled := (objCACIC.GetValueFromFile('Configs','CsSuporteRemoto',strMainProgramInfFileName) = 'S') and (FileExists(objCACIC.getLocalFolderName + 'Modules\srcacicsrv.exe'));
End;
function TFormularioGeral.Posso_Rodar : boolean;
Begin
result := false;
objCACIC.writeDebugLog('Posso_Rodar: Verificando concomit�ncia de sess�es');
// 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');
Result := not (FileExists(objCACIC.getLocalFolderName + 'aguarde_CACIC.txt'));
End;
procedure TFormularioGeral.FormCreate(Sender: TObject);
var textFileAguarde : TextFile;
serviceType, wordServiceStatus : Cardinal;
service_start : bool;
begin
objCACIC := TCACIC.Create;
objCACIC.setLocalFolderName(ExtractFilePath(ParamStr(0)));
objCACIC.setMainProgramName(ExtractFileName(ParamStr(0)));
objCACIC.setBoolCipher(not objCACIC.isInDebugMode);
strMainProgramInfFileName := objCACIC.getLocalFolderName + ChangeFileExt(objCACIC.getMainProgramName,'.inf');
strGerColsInfFileName := objCACIC.getLocalFolderName + 'gercols.inf';
strChkSisInfFileName := objCACIC.getWinDir + 'chksis.inf';
bl_primeira_execucao := true;
// A verifica��o dupla � uma solu��o de contorno para o caso de o boolCipher ter sido setado ap�s criptografia/deCriptografia do dado gravado
if (objCACIC.deCrypt( objCACIC.getValueFromFile('Hash-Codes',objCACIC.getMainProgramName,strChkSisInfFileName),false,true) = objCACIC.getFileHash(ParamStr(0))) then
Begin
objCACIC.setMainProgramHash(objCACIC.getFileHash(ParamStr(0)));
objCACIC.setWebManagerAddress(objCACIC.getValueFromFile('Configs','WebManagerAddress',strChkSisInfFileName));
objCACIC.setWebServicesFolderName(objCACIC.getValueFromFile('Configs','WebServicesFolderName',strChkSisInfFileName));
rmTaskbarCreated := RegisterWindowMessage('TaskbarCreated');
pnVersao.Caption := 'CACIC v:' + objCACIC.getVersionInfo(ParamStr(0));
g_intIconIndex := 0;
Popup_Menu_Contexto.OwnerDraw := True;
strWin32_NetworkAdapterConfiguration := fetchWMIvalues('Win32_NetworkAdapterConfiguration', objCACIC.getLocalFolderName);
strWin32_ComputerSystem := fetchWMIvalues('Win32_ComputerSystem', objCACIC.getLocalFolderName);
//Corre��o do bug do script net logon da pgfn;
//O script estava instalando o cacic sem intera��o com desktop,
//bugando o mapa e o trayicon.