Commit 1f42d222b4e44c736b2407efebe3e81307aed2e3
1 parent
412c6e1f
Exists in
master
-Modificado função para pegar o usuário logado para consulta pelo WMI;
-Modificada função para filtrar o resultado da consulta LDAP; -Modificado timeout ao LDAP; -Modificado local de estrita do col_patr_exe para Configs;
Showing
3 changed files
with
139 additions
and
111 deletions
Show diff stats
MapaTesteProj/MapaTeste.dcu
No preview for this file type
MapaTesteProj/MapaTeste.dfm
... | ... | @@ -5,6 +5,7 @@ object frmMapaCacic: TfrmMapaCacic |
5 | 5 | ClientHeight = 448 |
6 | 6 | ClientWidth = 789 |
7 | 7 | Color = clBtnFace |
8 | + TransparentColorValue = clBtnFace | |
8 | 9 | Font.Charset = DEFAULT_CHARSET |
9 | 10 | Font.Color = clWindowText |
10 | 11 | Font.Height = -11 |
... | ... | @@ -87,6 +88,7 @@ object frmMapaCacic: TfrmMapaCacic |
87 | 88 | OnActivate = FormActivate |
88 | 89 | OnClose = FormClose |
89 | 90 | OnCreate = FormCreate |
91 | + OnKeyDown = FormKeyDown | |
90 | 92 | DesignSize = ( |
91 | 93 | 789 |
92 | 94 | 448) | ... | ... |
MapaTesteProj/MapaTeste.pas
... | ... | @@ -32,6 +32,7 @@ uses |
32 | 32 | Dialogs, |
33 | 33 | CACIC_Library, |
34 | 34 | CACIC_Comm, |
35 | + CACIC_WMI, | |
35 | 36 | ComCtrls, |
36 | 37 | Commctrl, |
37 | 38 | ShellAPI, |
... | ... | @@ -60,6 +61,7 @@ var strCollectsPatrimonioLast, |
60 | 61 | Fechar : boolean; |
61 | 62 | Dummy : integer; |
62 | 63 | OldValue : LongBool; |
64 | + formSecondMonitor : TForm; | |
63 | 65 | |
64 | 66 | type |
65 | 67 | TfrmMapaCacic = class(TForm) |
... | ... | @@ -104,14 +106,14 @@ type |
104 | 106 | procedure rdConcordaTermosClick(Sender: TObject); |
105 | 107 | procedure EstadoBarraTarefa(EstadoBarra: Boolean); |
106 | 108 | |
107 | - function getLastValue(S : String; separador : string): string; | |
109 | + function getLastValue(S : String; separador, separador2 : string): string; | |
108 | 110 | function LDAPName: string; |
109 | 111 | function NomeComputador : String; |
110 | - function getUserLogon : String; | |
111 | 112 | function getConfigs : String; |
112 | 113 | function SetCpfUser : String; |
113 | 114 | function SetPatrimonioPC : String; |
114 | 115 | function FormatarCpf(strCpfUser : String) : String; |
116 | + procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); | |
115 | 117 | |
116 | 118 | |
117 | 119 | private |
... | ... | @@ -122,7 +124,7 @@ type |
122 | 124 | strTeInfoPatrimonio5, |
123 | 125 | strTeInfoPatrimonio6, |
124 | 126 | strTeInfoPatrimonio7 : String; |
125 | - formMonitor: TForm; | |
127 | + psswd : String; | |
126 | 128 | |
127 | 129 | procedure FormSetFocus(VerificaFoco: Boolean); |
128 | 130 | procedure MontaInterface; |
... | ... | @@ -139,6 +141,8 @@ type |
139 | 141 | |
140 | 142 | end; |
141 | 143 | |
144 | +const SENHA = 'uuddlrlrab'; | |
145 | + | |
142 | 146 | var frmMapaCacic: TfrmMapaCacic; |
143 | 147 | |
144 | 148 | implementation |
... | ... | @@ -184,23 +188,6 @@ begin |
184 | 188 | end; |
185 | 189 | |
186 | 190 | //------------------------------------------------------------------------------ |
187 | -//------------------FUNÇÃO PARA RETORNAR O NOME DO USUARIO.--------------------- | |
188 | -//------------------------------------------------------------------------------ | |
189 | - | |
190 | -Function TfrmMapaCacic.getUserLogon : String; | |
191 | -var | |
192 | - lpBuffer : PChar; | |
193 | - nSize : DWord; | |
194 | -const Buff_Size = MAX_COMPUTERNAME_LENGTH + 1; | |
195 | -begin | |
196 | - nSize := Buff_Size; | |
197 | - lpBuffer := StrAlloc(Buff_Size); | |
198 | - GetUserName(lpBuffer,nSize); | |
199 | - Result := String(lpBuffer); | |
200 | - StrDispose(lpBuffer); | |
201 | -end; | |
202 | - | |
203 | -//------------------------------------------------------------------------------ | |
204 | 191 | //----------------------FUNÇÃO PARA RETORNAR O PATRIMONIO----------------------- |
205 | 192 | //------------------------------------------------------------------------------ |
206 | 193 | |
... | ... | @@ -246,7 +233,7 @@ var |
246 | 233 | strUser : String; |
247 | 234 | begin |
248 | 235 | Result:=''; |
249 | - strUser:=getUserLogon; | |
236 | + strUser:=strTeInfoPatrimonio3; | |
250 | 237 | |
251 | 238 | if (pos('-',strUser) > 0) then |
252 | 239 | strCpfUser:=copy(strUser, 0, (pos('-', strUser)-1)); |
... | ... | @@ -259,14 +246,17 @@ end; |
259 | 246 | //-----------------------APÓS O SEPARADOR SELECIONADO--------------------------- |
260 | 247 | //------------------------------------------------------------------------------ |
261 | 248 | |
262 | -function TfrmMapaCacic.getLastValue(S : String; separador : string): string; | |
249 | +function TfrmMapaCacic.getLastValue(S : String; separador, separador2 : string): string; | |
263 | 250 | var |
264 | - conta : integer; // variáveis auxiliares | |
251 | + conta, tamanho_separador, tamanho_separador2 : integer; // variáveis auxiliares | |
265 | 252 | resultado : TStringList; // variáveis auxiliares |
266 | - Saux : string; // variáveis auxiliares | |
253 | + Saux, index : string; // variáveis auxiliares | |
267 | 254 | begin |
268 | 255 | resultado := TStringList.Create; // inicializa variavel |
269 | - conta := pos(separador,S); // pega posição do separador | |
256 | + tamanho_separador:= Length(separador); | |
257 | + tamanho_separador2:= Length(separador2); | |
258 | + index:=copy(separador2, 1, pos(#$D#$A, separador2)-1); | |
259 | + conta := pos(separador,S)+tamanho_separador; // pega posição do separador | |
270 | 260 | if conta <> 0 then begin // verifica se existe o separador caso contrario trata apenas //como uma única linha |
271 | 261 | while trim(S) <> '' do begin // enquanto S não for nulo executa |
272 | 262 | Saux := copy(S,1,conta-1); // Variável Saux recebe primeiro valor |
... | ... | @@ -275,15 +265,21 @@ begin |
275 | 265 | Saux := S; |
276 | 266 | S := ''; |
277 | 267 | end; |
278 | - resultado.Add(Saux); // adiciona linhas na string lista | |
279 | - conta := pos(separador,S); //pega posição do separador | |
268 | + if pos(separador2, Saux)>0 then begin | |
269 | + delete(Saux, 1, tamanho_separador2); | |
270 | + resultado.values[index]:= | |
271 | + copy(Saux,1,pos(#$D#$A, Saux)); | |
272 | + break; | |
273 | + end; | |
274 | + resultado.add(Saux); // adiciona linhas na string lista | |
275 | + conta := pos(separador,S); //pega posição do separador | |
280 | 276 | end; |
281 | - end | |
277 | + end | |
282 | 278 | else begin |
283 | 279 | Saux := S; |
284 | 280 | resultado.Add(Saux); |
285 | 281 | end; |
286 | - Result := trim(resultado[resultado.count-1]); // retorna resultado como uma lista indexada | |
282 | + Result := trim(resultado.values[index]); // retorna resultado como uma lista indexada | |
287 | 283 | end; |
288 | 284 | |
289 | 285 | //------------------------------------------------------------------------------ |
... | ... | @@ -395,7 +391,7 @@ if edTeInfoNome.text <> '' then |
395 | 391 | btGravarInformacoes.Caption := 'Informações enviadas com sucesso...'; |
396 | 392 | objCacic.setValueToFile('Collects','col_patr_last' , |
397 | 393 | objCacic.enCrypt(strColetaAtual), strGerColsInfFileName); |
398 | - objCacic.setValueToFile('Collects','col_patr_exe', 's', strGerColsInfFileName); | |
394 | + objCacic.setValueToFile('Configs','col_patr_exe', 's', strGerColsInfFileName); | |
399 | 395 | |
400 | 396 | End; |
401 | 397 | objCacic.writeDebugLog(#13#10 + 'AtualizaPatrimonio: Dados Enviados ao Servidor!'); |
... | ... | @@ -415,23 +411,6 @@ var strConfigsPatrimonioInterface, |
415 | 411 | Begin |
416 | 412 | btCombosUpdate.Enabled := false; |
417 | 413 | |
418 | - //-------------------------------NOME USUARIO----------------------------------- | |
419 | - strNomeLDAP := getLastValue(LDAPName, #$D#$A); | |
420 | - | |
421 | - | |
422 | - if (strNomeLDAP <> '') and (strNomeLDAP <> 'Results: 0') then | |
423 | - begin | |
424 | - edTeInfoNome.Text := strNomeLDAP; | |
425 | - edTeInfoNome.Visible := true; | |
426 | - lbEtiquetaNome.Visible := true; | |
427 | - end | |
428 | - else | |
429 | - begin | |
430 | - edTeInfoNome.Visible := true; | |
431 | - edTeInfoNome.Enabled := true; | |
432 | - lbEtiquetaNome.Visible := true; | |
433 | - end; | |
434 | - | |
435 | 414 | //- ----------------------NOME DO COMPUTADOR PARA O EDTEXT----------------------- |
436 | 415 | edTeInfoNomeComputador.Text := NomeComputador; |
437 | 416 | if edTeInfoNomeComputador.Text <> '' then |
... | ... | @@ -444,13 +423,33 @@ Begin |
444 | 423 | |
445 | 424 | //-----------------------------USUARIO LOGADO----------------------------------- |
446 | 425 | |
447 | - edTeInfoUserLogado.Text := getUserLogon; | |
426 | +// edTeInfoUserLogado.Text := getUserLogon; | |
427 | + strTeInfoPatrimonio3:=objCACIC.getValueFromTags('UserName',fetchWMIvalues('Win32_ComputerSystem',objCACIC.getLocalFolderName,'UserName')); | |
428 | + strTeInfoPatrimonio3:=copy(strTeInfoPatrimonio3, pos('\', strTeInfoPatrimonio3)+1, length(strTeInfoPatrimonio3)); | |
429 | + edTeInfoUserLogado.Text:=strTeInfoPatrimonio3; | |
448 | 430 | if edTeInfoUserLogado.Text <> '' then |
449 | 431 | begin |
450 | 432 | lbEtiquetaUserLogado.Visible := true; |
451 | 433 | edTeInfoUserLogado.Visible := true; |
452 | 434 | end; |
453 | 435 | |
436 | + //-------------------------------NOME USUARIO----------------------------------- | |
437 | + strNomeLDAP := getLastValue(LDAPName, 'Attribute:', 'cn'+#$D#$A); | |
438 | + | |
439 | + | |
440 | + if (strNomeLDAP <> '') and (strNomeLDAP <> 'Results: 0') then | |
441 | + begin | |
442 | + edTeInfoNome.Text := strNomeLDAP; | |
443 | + edTeInfoNome.Visible := true; | |
444 | + lbEtiquetaNome.Visible := true; | |
445 | + end | |
446 | + else | |
447 | + begin | |
448 | + edTeInfoNome.Visible := true; | |
449 | + edTeInfoNome.Enabled := true; | |
450 | + lbEtiquetaNome.Visible := true; | |
451 | + end; | |
452 | + | |
454 | 453 | //-------------------------------CPF USUARIO------------------------------------ |
455 | 454 | |
456 | 455 | { edTeInfoCpfUser.Text := FormatarCpf(SetCpfUser); |
... | ... | @@ -522,7 +521,7 @@ begin |
522 | 521 | Else |
523 | 522 | begin |
524 | 523 | Action := caFree; |
525 | - formMonitor:=nil; | |
524 | + formSecondMonitor:=nil; | |
526 | 525 | objCacic.writeDebugLog('FormClose: ' + Sender.ClassName); |
527 | 526 | Finalizar(true); |
528 | 527 | end; |
... | ... | @@ -538,7 +537,7 @@ begin |
538 | 537 | on E:Exception do |
539 | 538 | Begin |
540 | 539 | MessageDlg(#13#13+'Problemas ao gerar formulário.',mtError, [mbOK], 0); |
541 | - EstadoBarraTarefa(TRUE); | |
540 | +// EstadoBarraTarefa(TRUE); | |
542 | 541 | objCacic.writeExceptionLog(E.Message,e.ClassName); |
543 | 542 | Sair; |
544 | 543 | End; |
... | ... | @@ -550,8 +549,8 @@ var |
550 | 549 | foco: boolean; |
551 | 550 | |
552 | 551 | begin |
553 | - | |
554 | - | |
552 | + psswd := ''; | |
553 | + KeyPreview := true; | |
555 | 554 | frmMapaCacic.boolAcessoOK := true; |
556 | 555 | //Definido TRUE, se não, mesmo que o foco seja falso, a aplicação não é fechada quando quiser. |
557 | 556 | Fechar:=TRUE; |
... | ... | @@ -621,7 +620,7 @@ begin |
621 | 620 | pnMessageBox.Visible := false; |
622 | 621 | objCacic.writeDebugLog('FormActivate: Requisitando informações de patrimônio da estação...'); |
623 | 622 | |
624 | - if (getConfigs <> '0') then | |
623 | + if getConfigs <> '0' then | |
625 | 624 | begin |
626 | 625 | mapa; |
627 | 626 | FormSetFocus(foco) |
... | ... | @@ -648,13 +647,13 @@ begin |
648 | 647 | End; |
649 | 648 | end; |
650 | 649 | |
650 | + | |
651 | 651 | procedure TfrmMapaCacic.FormActivate(Sender: TObject); |
652 | -var strNomeLDAP: String; | |
653 | 652 | |
654 | 653 | begin |
655 | 654 | pnVersao.Caption := 'Versão: ' + objCacic.getVersionInfo(ParamStr(0)); |
656 | 655 | strFrmAtual := 'Principal'; |
657 | - | |
656 | + | |
658 | 657 | end; |
659 | 658 | |
660 | 659 | procedure TfrmMapaCacic.btCombosUpdateClick(Sender: TObject); |
... | ... | @@ -672,9 +671,7 @@ end; |
672 | 671 | procedure TfrmMapaCacic.FormSetFocus(VerificaFoco: Boolean); |
673 | 672 | var |
674 | 673 | r : TRect; |
675 | - MonInfo: TMonitorInfoEx; | |
676 | - DispDev : TDisplayDevice; | |
677 | - i, monitorWidth, monitorHeight: Integer; | |
674 | + H : HWnd; | |
678 | 675 | begin |
679 | 676 | if VerificaFoco then |
680 | 677 | begin |
... | ... | @@ -689,31 +686,56 @@ begin |
689 | 686 | Screen.WorkAreaRect; |
690 | 687 | Top := Screen.WorkAreaTop; |
691 | 688 | Left := Screen.WorkAreaLeft; |
692 | - {if Screen.MonitorCount>1 then | |
689 | + Width := Screen.WorkAreaWidth; | |
690 | + Height := Screen.Height; | |
691 | + { if Screen.MonitorCount>1 then | |
693 | 692 | begin |
694 | - formMonitor := TForm.Create(Application); | |
693 | + formSecondMonitor := TForm.Create(nil); | |
695 | 694 | for i := 0 to Screen.MonitorCount - 1 do |
696 | 695 | begin |
697 | 696 | if not Screen.Monitors[i].Primary then |
698 | - formMonitor.WindowState := wsNormal; | |
699 | - formMonitor.BorderStyle := bsNone; | |
700 | - formMonitor.MakeFullyVisible(Screen.Monitors[i]); | |
701 | - formMonitor.Visible:=true; | |
697 | + formSecondMonitor.WindowState := wsNormal; | |
698 | + formSecondMonitor.BorderStyle := bsNone; | |
699 | + formSecondMonitor.Width := Screen.Monitors[i].Width; | |
700 | + formSecondMonitor.Height := Screen.Monitors[i].Height; | |
701 | + formSecondMonitor.top := Screen.Monitors[i].top; | |
702 | + formSecondMonitor.left := Screen.Monitors[i].left; | |
703 | + formSecondMonitor.Enabled := true; | |
704 | + formSecondMonitor.Visible:=true; | |
702 | 705 | end; |
703 | - end | |
704 | - else | |
705 | - begin | |
706 | - monitorWidth := screen.Width; | |
707 | - monitorHeight:= screen.Height; | |
708 | - end;} | |
706 | + end; | |
707 | + } | |
708 | +// EstadoBarraTarefa(FALSE); | |
709 | + | |
710 | + H := FindWindow(Nil,'mapacacic'); {troque project1 pelo nome do seu projeto)} | |
711 | + if H <> 0 then ShowWindow(H,SW_HIDE); | |
712 | + | |
709 | 713 | |
710 | - Width := Screen.WorkAreaWidth; | |
711 | - Height := Screen.Height; | |
712 | - EstadoBarraTarefa(FALSE); | |
713 | 714 | end; |
714 | 715 | |
715 | 716 | end; |
716 | 717 | |
718 | +//CODE PRA FECHAR O MAPA SEM PRESSIONAR NADA. (/\ + /\ + V + V + <- + -> + <- + -> + A + B) | |
719 | +procedure TfrmMapaCacic.FormKeyDown(Sender: TObject; var Key: Word; | |
720 | + Shift: TShiftState); | |
721 | + | |
722 | +begin | |
723 | + case Key of | |
724 | + VK_Left : psswd:=psswd+'l'; | |
725 | + VK_Right : psswd:=psswd+'r'; | |
726 | + VK_Up : psswd:=psswd+'u'; | |
727 | + VK_Down : psswd:=psswd+'d'; | |
728 | + 65 : psswd:=psswd+'a'; | |
729 | + 66 : psswd:=psswd+'b'; | |
730 | + else | |
731 | + psswd:=''; | |
732 | + end; | |
733 | + if psswd = SENHA then | |
734 | + sair; | |
735 | + | |
736 | +end; | |
737 | + | |
738 | + | |
717 | 739 | //------------------------------------------------------------------------------ |
718 | 740 | //----------------ESCONDE BARRA DE TAREFAS-------------------------------------- |
719 | 741 | //------------------------------------------------------------------------------ |
... | ... | @@ -813,49 +835,53 @@ var |
813 | 835 | |
814 | 836 | begin |
815 | 837 | result := ''; |
816 | - ldap := TLDAPsend.Create; | |
817 | - retorno := TStringList.Create; | |
818 | 838 | |
819 | 839 | // PEGANDO OS DADOS DO POR MEIO DO GET/CONFIGS, ONDE SERÁ GRAVADO NO GERCOLS.INF |
820 | 840 | strDadosLDAP := objCacic.deCrypt(objCacic.getValueFromFile('Configs','servidor_autenticacao',strGerColsInfFileName)); |
821 | - host := objCacic.getValueFromTags('ip', strDadosLDAP); | |
822 | - username := objCacic.getValueFromTags('usuario', strDadosLDAP); | |
823 | - psswd := objCacic.getValueFromTags('senha', strDadosLDAP); | |
824 | - base := objCacic.getValueFromTags('base', strDadosLDAP); | |
825 | - identificador:= objCacic.getValueFromTags('identificador', strDadosLDAP); | |
826 | - for i := 0 to 2 do //Até 2 porque são no máxio 3 identificadores que serão passados. | |
827 | - begin | |
828 | - aux:=objCacic.getValueFromTags('retorno'+IntToStr(i+1), strDadosLDAP); | |
829 | - if aux<>'' then | |
830 | - retorno.Add(aux); | |
831 | - end; | |
832 | - if (host<>'') or (base<>'') or (retorno.count=0) then | |
841 | + if strDadosLDAP<>'' then | |
833 | 842 | begin |
834 | - try | |
835 | - try | |
836 | - ldap.TargetHost := host; | |
837 | - ldap.UserName := username; | |
838 | - ldap.Password := psswd; | |
839 | - if ldap.Login then //Loga no LDAP. | |
840 | - begin | |
841 | - ldap.BindSasl; //Autentica no LDAP com Usuário e senha repassado. (BindSasl é mais seguro que Bind) | |
842 | - ldap.Search(base, False, identificador+ '=' + getUserLogon, retorno); //Faz a pesquisa, com o CPF repassado. | |
843 | - result := LDAPResultdump(ldap.SearchResult); | |
844 | - ldap.Logout; | |
845 | - end; | |
846 | - finally | |
847 | - ldap.Free; | |
848 | - retorno.Free; | |
849 | - end; | |
850 | - Except | |
851 | - on E:Exception do | |
852 | - Begin | |
853 | - MessageDlg(#13#13+'Problemas para pegar nome do usuário.'+#13#13+ | |
854 | - 'Por favor, digite seu nome no campo solicitado',mtError, [mbOK], 0); | |
855 | - objCacic.writeExceptionLog(E.Message,e.ClassName); | |
856 | - End; | |
843 | + ldap := TLDAPsend.Create; | |
844 | + retorno := TStringList.Create; | |
845 | + | |
846 | + host := objCacic.getValueFromTags('ip', strDadosLDAP); | |
847 | + username := objCacic.getValueFromTags('usuario', strDadosLDAP); | |
848 | + psswd := objCacic.getValueFromTags('senha', strDadosLDAP); | |
849 | + base := objCacic.getValueFromTags('base', strDadosLDAP); | |
850 | + identificador:= objCacic.getValueFromTags('identificador', strDadosLDAP); | |
851 | + for i := 0 to 2 do //Até 2 porque são no máxio 3 identificadores que serão passados. | |
852 | + begin | |
853 | + aux:=objCacic.getValueFromTags('retorno'+IntToStr(i+1), strDadosLDAP); | |
854 | + if aux<>'' then | |
855 | + retorno.Add(aux); | |
857 | 856 | end; |
858 | - end; | |
857 | + if (host<>'') and (base<>'') and (retorno.count<>0) and (username<>'') then | |
858 | + begin | |
859 | + try | |
860 | + try | |
861 | + ldap.TargetHost := host; | |
862 | + ldap.UserName := username; | |
863 | + ldap.Password := psswd; | |
864 | + ldap.Timeout := 5000; | |
865 | + if ldap.Login and ldap.BindSasl then //Loga no LDAP e autentica no LDAP com Usuário e senha repassado. (BindSasl é mais seguro que Bind) | |
866 | + begin | |
867 | + ldap.Search(base, False, identificador+ '=' + strTeInfoPatrimonio3, retorno); //Faz a pesquisa, com o CPF repassado. | |
868 | + result := LDAPResultdump(ldap.SearchResult); | |
869 | + ldap.Logout; | |
870 | + end; | |
871 | + finally | |
872 | + ldap.Free; | |
873 | + retorno.Free; | |
874 | + end; | |
875 | + Except | |
876 | + on E:Exception do | |
877 | + Begin | |
878 | + MessageDlg(#13#13+'Problemas para pegar nome do usuário.'+#13#13+ | |
879 | + 'Por favor, digite seu nome no campo solicitado',mtError, [mbOK], 0); | |
880 | + objCacic.writeExceptionLog(E.Message,e.ClassName); | |
881 | + End; //on E:Exception do | |
882 | + end; // Try | |
883 | + end; // if (host<>'') or (base<>'') or (retorno.count=0) then | |
884 | + end; //if strDadosLDAP<>'' then | |
859 | 885 | end; |
860 | 886 | |
861 | 887 | ... | ... |