Commit 9046ccf94c1b2e41eca7262b9a0980f270758f3a
1 parent
152361a5
Exists in
master
correção na chave de cripto dos modulos chksis e gercols
git-svn-id: http://svn.softwarepublico.gov.br/svn/cacic/cacic/trunk/agente-windows@11 fecfc0c7-e812-0410-ae72-849f08638ee7
Showing
20 changed files
with
1689 additions
and
115 deletions
Show diff stats
No preview for this file type
No preview for this file type
No preview for this file type
chkcacic/FormConfig.dcu
No preview for this file type
chkcacic/FormConfig.dfm
1 | 1 | object Configs: TConfigs |
2 | - Left = 164 | |
3 | - Top = 137 | |
4 | - Width = 461 | |
5 | - Height = 440 | |
2 | + Left = 258 | |
3 | + Top = 175 | |
4 | + BorderIcons = [] | |
5 | + BorderStyle = bsSingle | |
6 | 6 | Caption = 'Configura'#231#245'es do CHKCACIC' |
7 | + ClientHeight = 331 | |
8 | + ClientWidth = 453 | |
7 | 9 | Color = clBtnFace |
8 | 10 | Font.Charset = DEFAULT_CHARSET |
9 | 11 | Font.Color = clWindowText |
... | ... | @@ -16,7 +18,7 @@ object Configs: TConfigs |
16 | 18 | TextHeight = 13 |
17 | 19 | object Label2: TLabel |
18 | 20 | Left = 402 |
19 | - Top = 380 | |
21 | + Top = 312 | |
20 | 22 | Width = 27 |
21 | 23 | Height = 12 |
22 | 24 | Caption = 'Label1' |
... | ... | @@ -29,10 +31,10 @@ object Configs: TConfigs |
29 | 31 | end |
30 | 32 | object GroupBox2: TGroupBox |
31 | 33 | Left = 5 |
32 | - Top = 114 | |
34 | + Top = 83 | |
33 | 35 | Width = 444 |
34 | - Height = 239 | |
35 | - Caption = 'Par'#226'metros Opcionais' | |
36 | + Height = 202 | |
37 | + Caption = 'Opcional' | |
36 | 38 | Font.Charset = DEFAULT_CHARSET |
37 | 39 | Font.Color = clWindowText |
38 | 40 | Font.Height = -11 |
... | ... | @@ -41,11 +43,11 @@ object Configs: TConfigs |
41 | 43 | ParentFont = False |
42 | 44 | TabOrder = 3 |
43 | 45 | object Label1: TLabel |
44 | - Left = 132 | |
45 | - Top = 0 | |
46 | - Width = 231 | |
46 | + Left = 63 | |
47 | + Top = -1 | |
48 | + Width = 200 | |
47 | 49 | Height = 13 |
48 | - Caption = '(N'#227'o preencher para o CHKCACIC do NetLogon)' | |
50 | + Caption = '(N'#227'o aplic'#225'vel ao ChkCacic do NetLogon)' | |
49 | 51 | Font.Charset = DEFAULT_CHARSET |
50 | 52 | Font.Color = clRed |
51 | 53 | Font.Height = -11 |
... | ... | @@ -53,35 +55,9 @@ object Configs: TConfigs |
53 | 55 | Font.Style = [] |
54 | 56 | ParentFont = False |
55 | 57 | end |
56 | - object Label_te_instala_frase_sucesso: TLabel | |
57 | - Left = 8 | |
58 | - Top = 25 | |
59 | - Width = 161 | |
60 | - Height = 13 | |
61 | - Caption = 'Frase para Sucesso na Instala'#231#227'o' | |
62 | - Font.Charset = DEFAULT_CHARSET | |
63 | - Font.Color = clWindowText | |
64 | - Font.Height = -11 | |
65 | - Font.Name = 'MS Sans Serif' | |
66 | - Font.Style = [] | |
67 | - ParentFont = False | |
68 | - end | |
69 | - object Label_te_instala_frase_insucesso: TLabel | |
70 | - Left = 8 | |
71 | - Top = 74 | |
72 | - Width = 168 | |
73 | - Height = 13 | |
74 | - Caption = 'Frase para Insucesso na Instala'#231#227'o' | |
75 | - Font.Charset = DEFAULT_CHARSET | |
76 | - Font.Color = clWindowText | |
77 | - Font.Height = -11 | |
78 | - Font.Name = 'MS Sans Serif' | |
79 | - Font.Style = [] | |
80 | - ParentFont = False | |
81 | - end | |
82 | 58 | object Label_te_instala_informacoes_extras: TLabel |
83 | - Left = 8 | |
84 | - Top = 121 | |
59 | + Left = 9 | |
60 | + Top = 50 | |
85 | 61 | Width = 89 |
86 | 62 | Height = 13 |
87 | 63 | Caption = 'Informa'#231#245'es extras' |
... | ... | @@ -92,54 +68,53 @@ object Configs: TConfigs |
92 | 68 | Font.Style = [] |
93 | 69 | ParentFont = False |
94 | 70 | end |
95 | - object Edit_te_instala_frase_sucesso: TEdit | |
96 | - Left = 8 | |
97 | - Top = 41 | |
98 | - Width = 427 | |
99 | - Height = 21 | |
100 | - Font.Charset = DEFAULT_CHARSET | |
101 | - Font.Color = clWindowText | |
102 | - Font.Height = -11 | |
103 | - Font.Name = 'MS Sans Serif' | |
104 | - Font.Style = [] | |
105 | - MaxLength = 100 | |
106 | - ParentFont = False | |
107 | - TabOrder = 0 | |
108 | - end | |
109 | - object Edit_te_instala_frase_insucesso: TEdit | |
110 | - Left = 8 | |
111 | - Top = 89 | |
112 | - Width = 427 | |
113 | - Height = 21 | |
71 | + object Memo_te_instala_informacoes_extras: TMemo | |
72 | + Left = 9 | |
73 | + Top = 65 | |
74 | + Width = 426 | |
75 | + Height = 127 | |
76 | + Color = clInactiveBorder | |
77 | + Enabled = False | |
114 | 78 | Font.Charset = DEFAULT_CHARSET |
115 | 79 | Font.Color = clWindowText |
116 | 80 | Font.Height = -11 |
117 | 81 | Font.Name = 'MS Sans Serif' |
118 | 82 | Font.Style = [] |
119 | - MaxLength = 100 | |
83 | + Lines.Strings = ( | |
84 | + 'Empresa-UF / Suporte T'#233'cnico' | |
85 | + '' | |
86 | + 'Emails: email1_do_suporte@xxxxxx.yyy.zz, ' | |
87 | + ' email2_do_suporte@xxxxxx.yyy.zz' | |
88 | + '' | |
89 | + 'Fones: (xx) yyyy-zzzz / (xx) yyyy-zzzz' | |
90 | + '' | |
91 | + 'Endere'#231'o: Rua Nome_da_Rua, N'#186' 99999' | |
92 | + ' Cidade/UF') | |
120 | 93 | ParentFont = False |
121 | 94 | TabOrder = 1 |
122 | 95 | end |
123 | - object Memo_te_instala_informacoes_extras: TMemo | |
124 | - Left = 8 | |
125 | - Top = 136 | |
126 | - Width = 425 | |
127 | - Height = 97 | |
96 | + object ckboxExibeInformacoes: TCheckBox | |
97 | + Left = 9 | |
98 | + Top = 23 | |
99 | + Width = 424 | |
100 | + Height = 17 | |
101 | + Caption = 'Exibe informa'#231#245'es sobre o processo de instala'#231#227'o' | |
128 | 102 | Font.Charset = DEFAULT_CHARSET |
129 | 103 | Font.Color = clWindowText |
130 | 104 | Font.Height = -11 |
131 | 105 | Font.Name = 'MS Sans Serif' |
132 | 106 | Font.Style = [] |
133 | 107 | ParentFont = False |
134 | - TabOrder = 2 | |
108 | + TabOrder = 0 | |
109 | + OnClick = ckboxExibeInformacoesClick | |
135 | 110 | end |
136 | 111 | end |
137 | 112 | object GroupBox1: TGroupBox |
138 | 113 | Left = 5 |
139 | - Top = 16 | |
114 | + Top = 8 | |
140 | 115 | Width = 444 |
141 | - Height = 81 | |
142 | - Caption = 'Par'#226'metros Obrigat'#243'rios' | |
116 | + Height = 64 | |
117 | + Caption = 'Obrigat'#243'rio' | |
143 | 118 | Font.Charset = DEFAULT_CHARSET |
144 | 119 | Font.Color = clWindowText |
145 | 120 | Font.Height = -11 |
... | ... | @@ -148,8 +123,8 @@ object Configs: TConfigs |
148 | 123 | ParentFont = False |
149 | 124 | TabOrder = 2 |
150 | 125 | object Label_ip_serv_cacic: TLabel |
151 | - Left = 80 | |
152 | - Top = 24 | |
126 | + Left = 8 | |
127 | + Top = 19 | |
153 | 128 | Width = 143 |
154 | 129 | Height = 13 |
155 | 130 | Caption = 'Identificador do Servidor WEB' |
... | ... | @@ -161,8 +136,8 @@ object Configs: TConfigs |
161 | 136 | ParentFont = False |
162 | 137 | end |
163 | 138 | object Label_cacic_dir: TLabel |
164 | - Left = 245 | |
165 | - Top = 24 | |
139 | + Left = 236 | |
140 | + Top = 19 | |
166 | 141 | Width = 103 |
167 | 142 | Height = 13 |
168 | 143 | Caption = 'Pasta para Instala'#231#227'o' |
... | ... | @@ -175,35 +150,54 @@ object Configs: TConfigs |
175 | 150 | end |
176 | 151 | end |
177 | 152 | object Edit_ip_serv_cacic: TEdit |
178 | - Left = 85 | |
179 | - Top = 56 | |
180 | - Width = 145 | |
153 | + Left = 13 | |
154 | + Top = 42 | |
155 | + Width = 200 | |
181 | 156 | Height = 21 |
182 | 157 | MaxLength = 100 |
183 | 158 | TabOrder = 0 |
184 | - OnExit = Edit_ip_serv_cacicExit | |
185 | 159 | end |
186 | 160 | object Edit_cacic_dir: TEdit |
187 | - Left = 250 | |
188 | - Top = 56 | |
189 | - Width = 121 | |
161 | + Left = 241 | |
162 | + Top = 42 | |
163 | + Width = 200 | |
190 | 164 | Height = 21 |
191 | - MaxLength = 15 | |
165 | + MaxLength = 100 | |
192 | 166 | TabOrder = 1 |
193 | 167 | Text = 'Cacic' |
194 | - OnExit = Edit_cacic_dirExit | |
195 | 168 | end |
196 | 169 | object Button_Gravar: TButton |
197 | - Left = 170 | |
198 | - Top = 367 | |
199 | - Width = 121 | |
200 | - Height = 25 | |
170 | + Left = 62 | |
171 | + Top = 292 | |
172 | + Width = 150 | |
173 | + Height = 30 | |
201 | 174 | Caption = 'Gravar Configura'#231#245'es' |
175 | + Font.Charset = DEFAULT_CHARSET | |
176 | + Font.Color = clWindowText | |
177 | + Font.Height = -13 | |
178 | + Font.Name = 'MS Sans Serif' | |
179 | + Font.Style = [] | |
180 | + ParentFont = False | |
202 | 181 | TabOrder = 4 |
203 | 182 | OnClick = Button_GravarClick |
204 | 183 | end |
184 | + object btSair: TButton | |
185 | + Left = 242 | |
186 | + Top = 292 | |
187 | + Width = 150 | |
188 | + Height = 30 | |
189 | + Caption = 'Sair' | |
190 | + Font.Charset = DEFAULT_CHARSET | |
191 | + Font.Color = clWindowText | |
192 | + Font.Height = -13 | |
193 | + Font.Name = 'MS Sans Serif' | |
194 | + Font.Style = [] | |
195 | + ParentFont = False | |
196 | + TabOrder = 5 | |
197 | + OnClick = btSairClick | |
198 | + end | |
205 | 199 | object PJVersionInfo1: TPJVersionInfo |
206 | - Left = 360 | |
207 | - Top = 360 | |
200 | + Left = 5 | |
201 | + Top = 293 | |
208 | 202 | end |
209 | 203 | end | ... | ... |
chkcacic/FormConfig.pas
... | ... | @@ -32,18 +32,16 @@ type |
32 | 32 | Label_cacic_dir: TLabel; |
33 | 33 | GroupBox2: TGroupBox; |
34 | 34 | Label1: TLabel; |
35 | - Label_te_instala_frase_sucesso: TLabel; | |
36 | - Edit_te_instala_frase_sucesso: TEdit; | |
37 | - Label_te_instala_frase_insucesso: TLabel; | |
38 | - Edit_te_instala_frase_insucesso: TEdit; | |
39 | 35 | Label_te_instala_informacoes_extras: TLabel; |
40 | 36 | Button_Gravar: TButton; |
41 | 37 | Memo_te_instala_informacoes_extras: TMemo; |
42 | 38 | PJVersionInfo1: TPJVersionInfo; |
43 | 39 | Label2: TLabel; |
40 | + ckboxExibeInformacoes: TCheckBox; | |
41 | + btSair: TButton; | |
44 | 42 | procedure Button_GravarClick(Sender: TObject); |
45 | - procedure Edit_ip_serv_cacicExit(Sender: TObject); | |
46 | - procedure Edit_cacic_dirExit(Sender: TObject); | |
43 | + procedure ckboxExibeInformacoesClick(Sender: TObject); | |
44 | + procedure btSairClick(Sender: TObject); | |
47 | 45 | private |
48 | 46 | { Private declarations } |
49 | 47 | public |
... | ... | @@ -59,17 +57,39 @@ implementation |
59 | 57 | |
60 | 58 | procedure TConfigs.Button_GravarClick(Sender: TObject); |
61 | 59 | begin |
62 | - main.GravaConfiguracoes; | |
63 | - Close; | |
60 | + if trim(Edit_cacic_dir.Text) = '' then | |
61 | + Edit_cacic_dir.Text := 'Cacic'; | |
62 | + | |
63 | + if trim(Edit_ip_serv_cacic.Text) = '' then | |
64 | + Edit_ip_serv_cacic.SetFocus | |
65 | + else | |
66 | + Begin | |
67 | + main.GravaConfiguracoes; | |
68 | + Close; | |
69 | + Application.terminate; | |
70 | + End; | |
64 | 71 | end; |
65 | -procedure TConfigs.Edit_ip_serv_cacicExit(Sender: TObject); | |
72 | + | |
73 | +procedure TConfigs.ckboxExibeInformacoesClick(Sender: TObject); | |
66 | 74 | begin |
67 | -if trim(Edit_ip_serv_cacic.Text) = '' then Edit_ip_serv_cacic.SetFocus; | |
75 | + if ckboxExibeInformacoes.Checked then | |
76 | + Begin | |
77 | + Memo_te_instala_informacoes_extras.Enabled := true; | |
78 | + Memo_te_instala_informacoes_extras.Color := clWindow; | |
79 | + v_exibe_informacoes := 'S'; | |
80 | + End | |
81 | + else | |
82 | + Begin | |
83 | + Memo_te_instala_informacoes_extras.Enabled := false; | |
84 | + Memo_te_instala_informacoes_extras.Color := clInactiveBorder; | |
85 | + v_exibe_informacoes := 'N'; | |
86 | + End; | |
68 | 87 | end; |
69 | 88 | |
70 | -procedure TConfigs.Edit_cacic_dirExit(Sender: TObject); | |
89 | +procedure TConfigs.btSairClick(Sender: TObject); | |
71 | 90 | begin |
72 | -if trim(Edit_cacic_dir.Text) = '' then Edit_cacic_dir.Text := 'Cacic'; | |
91 | + Close; | |
92 | + Application.Terminate; | |
73 | 93 | end; |
74 | 94 | |
75 | 95 | end. | ... | ... |
chkcacic/chkcacic.dof
... | ... | @@ -115,7 +115,7 @@ AutoIncBuild=0 |
115 | 115 | MajorVer=2 |
116 | 116 | MinorVer=2 |
117 | 117 | Release=0 |
118 | -Build=12 | |
118 | +Build=15 | |
119 | 119 | Debug=0 |
120 | 120 | PreRelease=0 |
121 | 121 | Special=0 |
... | ... | @@ -126,7 +126,7 @@ CodePage=1252 |
126 | 126 | [Version Info Keys] |
127 | 127 | CompanyName=Dataprev-ES |
128 | 128 | FileDescription= |
129 | -FileVersion=2.2.0.12 | |
129 | +FileVersion=2.2.0.15 | |
130 | 130 | InternalName= |
131 | 131 | LegalCopyright= |
132 | 132 | LegalTrademarks= | ... | ... |
chkcacic/chkcacic.res
No preview for this file type
chkcacic/main.dcu
No preview for this file type
... | ... | @@ -0,0 +1,1558 @@ |
1 | +(** | |
2 | +--------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
3 | +Copyright 2000, 2001, 2002, 2003, 2004, 2005 Dataprev - Empresa de Tecnologia e Informações da Previdência Social, Brasil | |
4 | + | |
5 | +Este arquivo é parte do programa CACIC - Configurador Automático e Coletor de Informações Computacionais | |
6 | + | |
7 | +O CACIC é um software livre; você pode redistribui-lo e/ou modifica-lo dentro dos termos da Licença Pública Geral GNU como | |
8 | +publicada pela Fundação do Software Livre (FSF); na versão 2 da Licença, ou (na sua opinião) qualquer versão. | |
9 | + | |
10 | +Este programa é distribuido na esperança que possa ser util, mas SEM NENHUMA GARANTIA; sem uma garantia implicita de ADEQUAÇÂO a qualquer | |
11 | +MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes. | |
12 | + | |
13 | +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 | |
14 | +Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
15 | + | |
16 | +--------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
17 | +===================================================================================================== | |
18 | +ChkCacic.exe : Verificador/Instalador dos agentes principais Cacic2.exe e Ger_Cols.exe | |
19 | +===================================================================================================== | |
20 | +v 2.2.0.14 | |
21 | ++ Críticas/mensagens: | |
22 | + "ATENÇÃO! Não foi possível estabelecer comunicação com o módulo Gerente WEB em <servidor>." e | |
23 | + "ATENÇÃO: Não foi possível efetuar FTP para <agente>. Verifique o Servidor de Updates." | |
24 | ++ Opção checkbox "Exibe informações sobre o processo de instalação" ao formulário de configuração; | |
25 | ++ Botão "Sair" ao formulário de configuração; | |
26 | ++ Execução automática do Agente Principal ao fim da instalação quando a unidade origem do ChkCacic não | |
27 | + for mapeamento de rede ou unidade inválida. | |
28 | + | |
29 | +- Retirados os campos "Frase para Sucesso na Instalação" e "Frase para Insucesso na Instalação" | |
30 | + do formulário de configuração, passando essas frases a serem fixas na aplicação. | |
31 | +- Retirada a opção radiobutton "Remove Versão Anterior?"; | |
32 | + | |
33 | +===================================================================================================== | |
34 | +*) | |
35 | + | |
36 | + | |
37 | +unit main; | |
38 | + | |
39 | +interface | |
40 | + | |
41 | +uses Windows, | |
42 | + strUtils, | |
43 | + SysUtils, | |
44 | + Classes, | |
45 | + Forms, | |
46 | + Registry, | |
47 | + Inifiles, | |
48 | + idFTPCommon, | |
49 | + XML, | |
50 | + LibXmlParser, | |
51 | + IdHTTP, | |
52 | + dialogs, | |
53 | + PJVersionInfo, | |
54 | + Controls, | |
55 | + StdCtrls, | |
56 | + IdBaseComponent, | |
57 | + IdComponent, | |
58 | + IdTCPConnection, | |
59 | + IdTCPClient, | |
60 | + variants, | |
61 | + DCPcrypt2, | |
62 | + DCPrijndael, | |
63 | + DCPbase64, | |
64 | + NTFileSecurity, IdFTP, | |
65 | + Tlhelp32; | |
66 | + | |
67 | +var v_ip_serv_cacic, | |
68 | + v_cacic_dir, | |
69 | +// v_rem_cacic_v0x, | |
70 | + v_te_instala_frase_sucesso, | |
71 | + v_te_instala_frase_insucesso, | |
72 | + v_te_instala_informacoes_extras, | |
73 | + v_exibe_informacoes, | |
74 | + v_versao_local, | |
75 | + v_versao_remota_inteira, | |
76 | + v_versao_remota_capada, | |
77 | + v_CipherKey, | |
78 | + v_SeparatorKey, | |
79 | + v_IV, | |
80 | + v_strCipherClosed, | |
81 | + v_strCipherOpened, | |
82 | + v_DatFileName : String; | |
83 | + | |
84 | +var v_tstrCipherOpened : TStrings; | |
85 | + | |
86 | +// Constantes a serem usadas pela função IsAdmin... | |
87 | +const constSECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5)); | |
88 | + constSECURITY_BUILTIN_DOMAIN_RID = $00000020; | |
89 | + constDOMAIN_ALIAS_RID_ADMINS = $00000220; | |
90 | + | |
91 | +// Some constants that are dependant on the cipher being used | |
92 | +// Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize) | |
93 | +const KeySize = 32; // 32 bytes = 256 bits | |
94 | + BlockSize = 16; // 16 bytes = 128 bits | |
95 | + | |
96 | +Procedure chkcacic; | |
97 | +Procedure CriaFormConfigura; | |
98 | +Procedure MostraFormConfigura; | |
99 | +Procedure GravaConfiguracoes; | |
100 | +Procedure DelValorReg(Chave: String); | |
101 | +procedure log_diario(strMsg : String); | |
102 | +Function ListFileDir(Path: string):string; | |
103 | +Function FTP(p_Host : String; p_Port : String; p_Username : String; p_Password : String; p_PathServer : String; p_File : String; p_Dest : String) : Boolean; | |
104 | +Function Explode(Texto, Separador : String) : TStrings; | |
105 | +Function GetRootKey(strRootKey: String): HKEY; | |
106 | +Function SetValorChaveRegEdit(Chave: String; Dado: Variant): Variant; | |
107 | +Function GetValorChaveRegEdit(Chave: String): Variant; | |
108 | +function SetValorChaveRegIni(p_Secao, p_Chave, p_Valor, p_File : String): String; | |
109 | +function GetValorChaveRegIni(p_Secao, p_Chave, p_File : String): String; | |
110 | +function HomeDrive : string; | |
111 | +Function RemoveCaracteresEspeciais(Texto : String) : String; | |
112 | +function FindWindowByTitle(WindowTitle: string): Hwnd; | |
113 | +function GetVersionInfo(p_File: string):string; | |
114 | +function VerFmt(const MS, LS: DWORD): string; | |
115 | +function GetWinVer: Integer; | |
116 | +function KillTask(ExeFileName: string): Integer; | |
117 | +procedure KillProcess(hWindowHandle: HWND); | |
118 | + | |
119 | +type | |
120 | + TForm1 = class(TForm) | |
121 | + PJVersionInfo1: TPJVersionInfo; | |
122 | + IdFTP1: TIdFTP; | |
123 | + FS: TNTFileSecurity; | |
124 | + procedure FormCreate(Sender: TObject); | |
125 | + procedure FS_SetSecurity(p_Target : String); | |
126 | + end; | |
127 | + | |
128 | +var | |
129 | + Form1: TForm1; | |
130 | + Dir, ENDERECO_SERV_CACIC, | |
131 | + v_home_drive : string; | |
132 | +implementation | |
133 | + | |
134 | +uses FormConfig; | |
135 | + | |
136 | +{$R *.dfm} | |
137 | +function IsAdmin: Boolean; | |
138 | +var hAccessToken: THandle; | |
139 | + ptgGroups: PTokenGroups; | |
140 | + dwInfoBufferSize: DWORD; | |
141 | + psidAdministrators: PSID; | |
142 | + x: Integer; | |
143 | + bSuccess: BOOL; | |
144 | +begin | |
145 | + Result := False; | |
146 | + bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, hAccessToken); | |
147 | + if not bSuccess then | |
148 | + begin | |
149 | + if GetLastError = ERROR_NO_TOKEN then | |
150 | + bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, hAccessToken); | |
151 | + end; | |
152 | + if bSuccess then | |
153 | + begin | |
154 | + GetMem(ptgGroups, 1024); | |
155 | + bSuccess := GetTokenInformation(hAccessToken, TokenGroups, ptgGroups, 1024, dwInfoBufferSize); | |
156 | + CloseHandle(hAccessToken); | |
157 | + if bSuccess then | |
158 | + begin | |
159 | + AllocateAndInitializeSid(constSECURITY_NT_AUTHORITY, 2, | |
160 | + constSECURITY_BUILTIN_DOMAIN_RID, | |
161 | + constDOMAIN_ALIAS_RID_ADMINS, | |
162 | + 0, 0, 0, 0, 0, 0, psidAdministrators); | |
163 | + {$R-} | |
164 | + for x := 0 to ptgGroups.GroupCount - 1 do | |
165 | + if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then | |
166 | + begin | |
167 | + Result := True; | |
168 | + Break; | |
169 | + end; | |
170 | + {$R+} | |
171 | + FreeSid(psidAdministrators); | |
172 | + end; | |
173 | + FreeMem(ptgGroups); | |
174 | + end; | |
175 | +end; | |
176 | + | |
177 | +procedure log_diario(strMsg : String); | |
178 | +var | |
179 | + HistoricoLog : TextFile; | |
180 | +begin | |
181 | + try | |
182 | + FileSetAttr (v_home_drive + 'chkcacic.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000 | |
183 | + AssignFile(HistoricoLog,v_home_drive + 'chkcacic.log'); {Associa o arquivo a uma variável do tipo TextFile} | |
184 | + | |
185 | + {$IOChecks off} | |
186 | + Reset(HistoricoLog); {Abre o arquivo texto} | |
187 | + {$IOChecks on} | |
188 | + | |
189 | + if (IOResult <> 0) then // Arquivo não existe, será recriado. | |
190 | + begin | |
191 | + Rewrite (HistoricoLog); | |
192 | + Append(HistoricoLog); | |
193 | + Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now) + '======================> Iniciando o Log <======================='); | |
194 | + end; | |
195 | + Append(HistoricoLog); | |
196 | + Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now)+ '[Instalador] '+strMsg); {Grava a string Texto no arquivo texto} | |
197 | + CloseFile(HistoricoLog); {Fecha o arquivo texto} | |
198 | + except | |
199 | + //Erro na gravação do log! | |
200 | + //Application.Terminate; | |
201 | + end; | |
202 | +end; | |
203 | + | |
204 | +// Pad a string with zeros so that it is a multiple of size | |
205 | +function PadWithZeros(const str : string; size : integer) : string; | |
206 | +var | |
207 | + origsize, i : integer; | |
208 | +begin | |
209 | + Result := str; | |
210 | + origsize := Length(Result); | |
211 | + if ((origsize mod size) <> 0) or (origsize = 0) then | |
212 | + begin | |
213 | + SetLength(Result,((origsize div size)+1)*size); | |
214 | + for i := origsize+1 to Length(Result) do | |
215 | + Result[i] := #0; | |
216 | + end; | |
217 | +end; | |
218 | + | |
219 | + | |
220 | +// Encrypt a string and return the Base64 encoded result | |
221 | +function EnCrypt(p_Data : String) : String; | |
222 | +var | |
223 | + l_Cipher : TDCP_rijndael; | |
224 | + l_Data, l_Key, l_IV : string; | |
225 | +begin | |
226 | + Try | |
227 | + // Pad Key, IV and Data with zeros as appropriate | |
228 | + l_Key := PadWithZeros(v_CipherKey,KeySize); | |
229 | + l_IV := PadWithZeros(v_IV,BlockSize); | |
230 | + l_Data := PadWithZeros(p_Data,BlockSize); | |
231 | + | |
232 | + // Create the cipher and initialise according to the key length | |
233 | + l_Cipher := TDCP_rijndael.Create(nil); | |
234 | + if Length(v_CipherKey) <= 16 then | |
235 | + l_Cipher.Init(l_Key[1],128,@l_IV[1]) | |
236 | + else if Length(v_CipherKey) <= 24 then | |
237 | + l_Cipher.Init(l_Key[1],192,@l_IV[1]) | |
238 | + else | |
239 | + l_Cipher.Init(l_Key[1],256,@l_IV[1]); | |
240 | + | |
241 | + // Encrypt the data | |
242 | + l_Cipher.EncryptCBC(l_Data[1],l_Data[1],Length(l_Data)); | |
243 | + | |
244 | + // Free the cipher and clear sensitive information | |
245 | + l_Cipher.Free; | |
246 | + FillChar(l_Key[1],Length(l_Key),0); | |
247 | + | |
248 | + // Return the Base64 encoded result | |
249 | + Result := Base64EncodeStr(l_Data); | |
250 | + Except | |
251 | + log_diario('Erro no Processo de Criptografia'); | |
252 | + End; | |
253 | +end; | |
254 | + | |
255 | +function DeCrypt(p_Data : String) : String; | |
256 | +var | |
257 | + l_Cipher : TDCP_rijndael; | |
258 | + l_Data, l_Key, l_IV : string; | |
259 | +begin | |
260 | + Try | |
261 | + // Pad Key and IV with zeros as appropriate | |
262 | + l_Key := PadWithZeros(v_CipherKey,KeySize); | |
263 | + l_IV := PadWithZeros(v_IV,BlockSize); | |
264 | + | |
265 | + // Decode the Base64 encoded string | |
266 | + l_Data := Base64DecodeStr(p_Data); | |
267 | + | |
268 | + // Create the cipher and initialise according to the key length | |
269 | + l_Cipher := TDCP_rijndael.Create(nil); | |
270 | + if Length(v_CipherKey) <= 16 then | |
271 | + l_Cipher.Init(l_Key[1],128,@l_IV[1]) | |
272 | + else if Length(v_CipherKey) <= 24 then | |
273 | + l_Cipher.Init(l_Key[1],192,@l_IV[1]) | |
274 | + else | |
275 | + l_Cipher.Init(l_Key[1],256,@l_IV[1]); | |
276 | + | |
277 | + // Decrypt the data | |
278 | + l_Cipher.DecryptCBC(l_Data[1],l_Data[1],Length(l_Data)); | |
279 | + | |
280 | + // Free the cipher and clear sensitive information | |
281 | + l_Cipher.Free; | |
282 | + FillChar(l_Key[1],Length(l_Key),0); | |
283 | + | |
284 | + // Return the result | |
285 | + Result := l_Data; | |
286 | + Except | |
287 | + log_diario('Erro no Processo de Decriptografia'); | |
288 | + End; | |
289 | +end; | |
290 | + | |
291 | + | |
292 | +Function Implode(p_Array : TStrings ; p_Separador : String) : String; | |
293 | +var intAux : integer; | |
294 | + strAux : string; | |
295 | +Begin | |
296 | + strAux := ''; | |
297 | + For intAux := 0 To p_Array.Count -1 do | |
298 | + Begin | |
299 | + if (strAux<>'') then strAux := strAux + p_Separador; | |
300 | + strAux := strAux + p_Array[intAux]; | |
301 | + End; | |
302 | + Implode := strAux; | |
303 | +end; | |
304 | + | |
305 | +Function CipherClose(p_DatFileName : string) : String; | |
306 | +var v_strCipherOpenImploded : string; | |
307 | + v_DatFile : TextFile; | |
308 | +begin | |
309 | + try | |
310 | + FileSetAttr (p_DatFileName,0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000 | |
311 | + AssignFile(v_DatFile,p_DatFileName); {Associa o arquivo a uma variável do tipo TextFile} | |
312 | + | |
313 | + // Recriação do arquivo .DAT | |
314 | + Rewrite (v_DatFile); | |
315 | + Append(v_DatFile); | |
316 | + | |
317 | + v_strCipherOpenImploded := Implode(v_tstrCipherOpened,v_SeparatorKey); | |
318 | + v_strCipherClosed := EnCrypt(v_strCipherOpenImploded); | |
319 | + | |
320 | + Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto} | |
321 | + | |
322 | + CloseFile(v_DatFile); | |
323 | + except | |
324 | + end; | |
325 | +end; | |
326 | + | |
327 | +Function CipherOpen(p_DatFileName : string) : TStrings; | |
328 | +var v_DatFile : TextFile; | |
329 | + v_strCipherOpened, | |
330 | + v_strCipherClosed : string; | |
331 | +begin | |
332 | + v_strCipherOpened := ''; | |
333 | + if FileExists(p_DatFileName) then | |
334 | + begin | |
335 | + AssignFile(v_DatFile,p_DatFileName); | |
336 | + {$IOChecks off} | |
337 | + Reset(v_DatFile); | |
338 | + {$IOChecks on} | |
339 | + if (IOResult <> 0) then // Arquivo não existe, será recriado. | |
340 | + begin | |
341 | + Rewrite (v_DatFile); | |
342 | + Append(v_DatFile); | |
343 | + end; | |
344 | + | |
345 | + Readln(v_DatFile,v_strCipherClosed); | |
346 | + while not EOF(v_DatFile) do Readln(v_DatFile,v_strCipherClosed); | |
347 | + CloseFile(v_DatFile); | |
348 | + v_strCipherOpened:= DeCrypt(v_strCipherClosed); | |
349 | + end; | |
350 | + if (trim(v_strCipherOpened)<>'') then | |
351 | + Result := explode(v_strCipherOpened,v_SeparatorKey) | |
352 | + else | |
353 | + Result := explode('Configs.ID_SO'+v_SeparatorKey+inttostr(GetWinVer)+v_SeparatorKey+'Configs.Endereco_WS'+v_SeparatorKey+'/cacic2/ws/',v_SeparatorKey); | |
354 | + | |
355 | + | |
356 | + if Result.Count mod 2 <> 0 then | |
357 | + Result.Add(''); | |
358 | + | |
359 | +end; | |
360 | + | |
361 | +Procedure SetValorDatMemoria(p_Chave : string; p_Valor : String); | |
362 | +begin | |
363 | + log_diario('Setando Chave "'+p_Chave+'" com "'+p_Valor+'"'); | |
364 | + // Exemplo: p_Chave => Configs.nu_ip_servidor : p_Valor => 10.71.0.120 | |
365 | + if (v_tstrCipherOpened.IndexOf(p_Chave)<>-1) then | |
366 | + v_tstrCipherOpened[v_tstrCipherOpened.IndexOf(p_Chave)+1] := p_Valor | |
367 | + else | |
368 | + Begin | |
369 | + v_tstrCipherOpened.Add(p_Chave); | |
370 | + v_tstrCipherOpened.Add(p_Valor); | |
371 | + End; | |
372 | +end; | |
373 | + | |
374 | +Function GetValorDatMemoria(p_Chave : String) : String; | |
375 | +begin | |
376 | + if (v_tstrCipherOpened.IndexOf(p_Chave)<>-1) then | |
377 | + Result := v_tstrCipherOpened[v_tstrCipherOpened.IndexOf(p_Chave)+1] | |
378 | + else | |
379 | + Result := ''; | |
380 | +end; | |
381 | + | |
382 | + | |
383 | +function VerFmt(const MS, LS: DWORD): string; | |
384 | + // Format the version number from the given DWORDs containing the info | |
385 | +begin | |
386 | + Result := Format('%d.%d.%d.%d', | |
387 | + [HiWord(MS), LoWord(MS), HiWord(LS), LoWord(LS)]) | |
388 | +end; | |
389 | + | |
390 | +function GetWinVer: Integer; | |
391 | +const | |
392 | + { operating system (OS)constants } | |
393 | + cOsUnknown = 0; | |
394 | + cOsWin95 = 1; | |
395 | + cOsWin95OSR2 = 2; // Não implementado. | |
396 | + cOsWin98 = 3; | |
397 | + cOsWin98SE = 4; | |
398 | + cOsWinME = 5; | |
399 | + cOsWinNT = 6; | |
400 | + cOsWin2000 = 7; | |
401 | + cOsXP = 8; | |
402 | + cOsServer2003 = 13; | |
403 | +var | |
404 | + osVerInfo: TOSVersionInfo; | |
405 | + majorVer, minorVer: Integer; | |
406 | +begin | |
407 | + Result := cOsUnknown; | |
408 | + { set operating system type flag } | |
409 | + osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); | |
410 | + if GetVersionEx(osVerInfo) then | |
411 | + begin | |
412 | + majorVer := osVerInfo.dwMajorVersion; | |
413 | + minorVer := osVerInfo.dwMinorVersion; | |
414 | + case osVerInfo.dwPlatformId of | |
415 | + VER_PLATFORM_WIN32_NT: { Windows NT/2000 } | |
416 | + begin | |
417 | + if majorVer <= 4 then | |
418 | + Result := cOsWinNT | |
419 | + else if (majorVer = 5) and (minorVer = 0) then | |
420 | + Result := cOsWin2000 | |
421 | + else if (majorVer = 5) and (minorVer = 1) then | |
422 | + Result := cOsXP | |
423 | + else if (majorVer = 5) and (minorVer = 2) then | |
424 | + Result := cOsServer2003 | |
425 | + else | |
426 | + Result := cOsUnknown; | |
427 | + end; | |
428 | + VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME } | |
429 | + begin | |
430 | + if (majorVer = 4) and (minorVer = 0) then | |
431 | + Result := cOsWin95 | |
432 | + else if (majorVer = 4) and (minorVer = 10) then | |
433 | + begin | |
434 | + if osVerInfo.szCSDVersion[1] = 'A' then | |
435 | + Result := cOsWin98SE | |
436 | + else | |
437 | + Result := cOsWin98; | |
438 | + end | |
439 | + else if (majorVer = 4) and (minorVer = 90) then | |
440 | + Result := cOsWinME | |
441 | + else | |
442 | + Result := cOsUnknown; | |
443 | + end; | |
444 | + else | |
445 | + Result := cOsUnknown; | |
446 | + end; | |
447 | + end | |
448 | + else | |
449 | + Result := cOsUnknown; | |
450 | +end; | |
451 | + | |
452 | + | |
453 | + | |
454 | +function GetVersionInfo(p_File: string):string; | |
455 | +begin | |
456 | + Form1.PJVersionInfo1.FileName := PChar(p_File); | |
457 | + Result := VerFmt(Form1.PJVersionInfo1.FixedFileInfo.dwFileVersionMS, Form1.PJVersionInfo1.FixedFileInfo.dwFileVersionLS); | |
458 | +end; | |
459 | + | |
460 | +function GetRootKey(strRootKey: String): HKEY; | |
461 | +begin | |
462 | + /// Encontrar uma maneira mais elegante de fazer esses testes. | |
463 | + if Trim(strRootKey) = 'HKEY_LOCAL_MACHINE' Then Result := HKEY_LOCAL_MACHINE | |
464 | + else if Trim(strRootKey) = 'HKEY_CLASSES_ROOT' Then Result := HKEY_CLASSES_ROOT | |
465 | + else if Trim(strRootKey) = 'HKEY_CURRENT_USER' Then Result := HKEY_CURRENT_USER | |
466 | + else if Trim(strRootKey) = 'HKEY_USERS' Then Result := HKEY_USERS | |
467 | + else if Trim(strRootKey) = 'HKEY_CURRENT_CONFIG' Then Result := HKEY_CURRENT_CONFIG | |
468 | + else if Trim(strRootKey) = 'HKEY_DYN_DATA' Then Result := HKEY_DYN_DATA; | |
469 | +end; | |
470 | + | |
471 | +function SetValorChaveRegEdit(Chave: String; Dado: Variant): Variant; | |
472 | +var RegEditSet: TRegistry; | |
473 | + RegDataType: TRegDataType; | |
474 | + strRootKey, strKey, strValue : String; | |
475 | + ListaAuxSet : TStrings; | |
476 | + I : Integer; | |
477 | +begin | |
478 | + ListaAuxSet := Explode(Chave, '\'); | |
479 | + strRootKey := ListaAuxSet[0]; | |
480 | + For I := 1 To ListaAuxSet.Count - 2 Do strKey := strKey + ListaAuxSet[I] + '\'; | |
481 | + strValue := ListaAuxSet[ListaAuxSet.Count - 1]; | |
482 | + | |
483 | + RegEditSet := TRegistry.Create; | |
484 | + try | |
485 | + RegEditSet.Access := KEY_WRITE; | |
486 | + RegEditSet.Rootkey := GetRootKey(strRootKey); | |
487 | + | |
488 | + if RegEditSet.OpenKey(strKey, True) then | |
489 | + Begin | |
490 | + RegDataType := RegEditSet.GetDataType(strValue); | |
491 | + if RegDataType = rdString then | |
492 | + begin | |
493 | + RegEditSet.WriteString(strValue, Dado); | |
494 | + end | |
495 | + else if RegDataType = rdExpandString then | |
496 | + begin | |
497 | + RegEditSet.WriteExpandString(strValue, Dado); | |
498 | + end | |
499 | + else if RegDataType = rdInteger then | |
500 | + begin | |
501 | + RegEditSet.WriteInteger(strValue, Dado); | |
502 | + end | |
503 | + else | |
504 | + begin | |
505 | + RegEditSet.WriteString(strValue, Dado); | |
506 | + end; | |
507 | + | |
508 | + end; | |
509 | + finally | |
510 | + RegEditSet.CloseKey; | |
511 | + end; | |
512 | + ListaAuxSet.Free; | |
513 | + RegEditSet.Free; | |
514 | +end; | |
515 | + | |
516 | +Function RemoveCaracteresEspeciais(Texto : String) : String; | |
517 | +var I : Integer; | |
518 | + strAux : String; | |
519 | +Begin | |
520 | + For I := 0 To Length(Texto) Do | |
521 | + if ord(Texto[I]) in [32..126] Then | |
522 | + strAux := strAux + Texto[I] | |
523 | + else strAux := strAux + ' '; // Coloca um espaço onde houver caracteres especiais | |
524 | + Result := strAux; | |
525 | +end; | |
526 | + | |
527 | +//Para buscar do RegEdit... | |
528 | +function GetValorChaveRegEdit(Chave: String): Variant; | |
529 | +var RegEditGet: TRegistry; | |
530 | + RegDataType: TRegDataType; | |
531 | + strRootKey, strKey, strValue, s: String; | |
532 | + ListaAuxGet : TStrings; | |
533 | + DataSize, Len, I : Integer; | |
534 | +begin | |
535 | + try | |
536 | + ListaAuxGet := Explode(Chave, '\'); | |
537 | + | |
538 | + strRootKey := ListaAuxGet[0]; | |
539 | + For I := 1 To ListaAuxGet.Count - 2 Do strKey := strKey + ListaAuxGet[I] + '\'; | |
540 | + strValue := ListaAuxGet[ListaAuxGet.Count - 1]; | |
541 | + RegEditGet := TRegistry.Create; | |
542 | + | |
543 | + RegEditGet.Access := KEY_READ; | |
544 | + RegEditGet.Rootkey := GetRootKey(strRootKey); | |
545 | + if RegEditGet.OpenKeyReadOnly(strKey) then //teste | |
546 | + Begin | |
547 | + RegDataType := RegEditGet.GetDataType(strValue); | |
548 | + if (RegDataType = rdString) or (RegDataType = rdExpandString) then Result := RegEditGet.ReadString(strValue) | |
549 | + else if RegDataType = rdInteger then Result := RegEditGet.ReadInteger(strValue) | |
550 | + else if (RegDataType = rdBinary) or (RegDataType = rdUnknown) | |
551 | + then | |
552 | + begin | |
553 | + DataSize := RegEditGet.GetDataSize(strValue); | |
554 | + if DataSize = -1 then exit; | |
555 | + SetLength(s, DataSize); | |
556 | + Len := RegEditGet.ReadBinaryData(strValue, PChar(s)^, DataSize); | |
557 | + if Len <> DataSize then exit; | |
558 | + Result := RemoveCaracteresEspeciais(s); | |
559 | + end | |
560 | + end; | |
561 | + finally | |
562 | + RegEditGet.CloseKey; | |
563 | + RegEditGet.Free; | |
564 | + ListaAuxGet.Free; | |
565 | + | |
566 | + end; | |
567 | +end; | |
568 | + | |
569 | +//Para gravar no Arquivo INI... | |
570 | +function SetValorChaveRegIni(p_Secao, p_Chave, p_Valor, p_File : String): String; | |
571 | +var Reg_Ini : TIniFile; | |
572 | +begin | |
573 | +// FileSetAttr (p_File,0); | |
574 | + { | |
575 | + To remove write protection on a file: | |
576 | + Den Schreibschutz einer Datei aufheben: | |
577 | + } | |
578 | + if (FileGetAttr(p_File) and faReadOnly) > 0 then | |
579 | + FileSetAttr(p_File, FileGetAttr(p_File) xor faReadOnly); | |
580 | + | |
581 | + Reg_Ini := TIniFile.Create(p_File); | |
582 | + Reg_Ini.WriteString(p_Secao, p_Chave, p_Valor); | |
583 | + Reg_Ini.Free; | |
584 | +end; | |
585 | + | |
586 | +function GetValorChaveRegIni(p_Secao, p_Chave, p_File : String): String; | |
587 | +//Para buscar do Arquivo INI... | |
588 | +// Marreta devido a limitações do KERNEL w9x no tratamento de arquivos texto e suas seções | |
589 | +//function GetValorChaveRegIni(p_SectionName, p_KeyName, p_IniFileName : String) : String; | |
590 | +var | |
591 | + FileText : TStringList; | |
592 | + i, j, v_Size_Section, v_Size_Key : integer; | |
593 | + v_SectionName, v_KeyName : string; | |
594 | + begin | |
595 | + Result := ''; | |
596 | + v_SectionName := '[' + p_Secao + ']'; | |
597 | + v_Size_Section := strLen(PChar(v_SectionName)); | |
598 | + v_KeyName := p_Chave + '='; | |
599 | + v_Size_Key := strLen(PChar(v_KeyName)); | |
600 | + FileText := TStringList.Create; | |
601 | + try | |
602 | + FileText.LoadFromFile(p_File); | |
603 | + For i := 0 To FileText.Count - 1 Do | |
604 | + Begin | |
605 | + if (LowerCase(Trim(PChar(Copy(FileText[i],1,v_Size_Section)))) = LowerCase(Trim(PChar(v_SectionName)))) then | |
606 | + Begin | |
607 | + For j := i to FileText.Count - 1 Do | |
608 | + Begin | |
609 | + if (LowerCase(Trim(PChar(Copy(FileText[j],1,v_Size_Key)))) = LowerCase(Trim(PChar(v_KeyName)))) then | |
610 | + Begin | |
611 | + Result := PChar(Copy(FileText[j],v_Size_Key + 1,strLen(PChar(FileText[j]))-v_Size_Key)); | |
612 | + Break; | |
613 | + End; | |
614 | + End; | |
615 | + End; | |
616 | + if (Result <> '') then break; | |
617 | + End; | |
618 | + finally | |
619 | + FileText.Free; | |
620 | + end; | |
621 | + end; | |
622 | + | |
623 | +Procedure DelValorReg(Chave: String); | |
624 | +var RegDelValorReg: TRegistry; | |
625 | + strRootKey, strKey, strValue : String; | |
626 | + ListaAuxDel : TStrings; | |
627 | + I : Integer; | |
628 | +begin | |
629 | + ListaAuxDel := Explode(Chave, '\'); | |
630 | + strRootKey := ListaAuxDel[0]; | |
631 | + For I := 1 To ListaAuxDel.Count - 2 Do strKey := strKey + ListaAuxDel[I] + '\'; | |
632 | + strValue := ListaAuxDel[ListaAuxDel.Count - 1]; | |
633 | + RegDelValorReg := TRegistry.Create; | |
634 | + | |
635 | + try | |
636 | + RegDelValorReg.Access := KEY_WRITE; | |
637 | + RegDelValorReg.Rootkey := GetRootKey(strRootKey); | |
638 | + | |
639 | + if RegDelValorReg.OpenKey(strKey, True) then | |
640 | + RegDelValorReg.DeleteValue(strValue); | |
641 | + finally | |
642 | + RegDelValorReg.CloseKey; | |
643 | + end; | |
644 | + RegDelValorReg.Free; | |
645 | + ListaAuxDel.Free; | |
646 | +end; | |
647 | + | |
648 | +Procedure CriaFormConfigura; | |
649 | +begin | |
650 | + Application.CreateForm(TConfigs, FormConfig.Configs); | |
651 | + FormConfig.Configs.Label2.Caption := 'v: ' + getVersionInfo(ParamStr(0)); | |
652 | +end; | |
653 | + | |
654 | +Procedure MostraFormConfigura; | |
655 | +begin | |
656 | + FormConfig.Configs.ShowModal; | |
657 | +end; | |
658 | + | |
659 | +Function Explode(Texto, Separador : String) : TStrings; | |
660 | +var | |
661 | + strItem : String; | |
662 | + ListaAuxUTILS : TStrings; | |
663 | + NumCaracteres, | |
664 | + TamanhoSeparador, | |
665 | + I : Integer; | |
666 | +Begin | |
667 | + ListaAuxUTILS := TStringList.Create; | |
668 | + strItem := ''; | |
669 | + NumCaracteres := Length(Texto); | |
670 | + TamanhoSeparador := Length(Separador); | |
671 | + I := 1; | |
672 | + While I <= NumCaracteres Do | |
673 | + Begin | |
674 | + If ((Copy(Texto,I,TamanhoSeparador) = Separador) and (Texto[I-1]<>'?')) or (I = NumCaracteres) Then | |
675 | + Begin | |
676 | + if (I = NumCaracteres) then strItem := strItem + Texto[I]; | |
677 | + ListaAuxUTILS.Add(trim(strItem)); | |
678 | + strItem := ''; | |
679 | + I := I + (TamanhoSeparador-1); | |
680 | + end | |
681 | + Else | |
682 | + if (Texto[I]<>'?') then strItem := strItem + Texto[I]; | |
683 | + I := I + 1; | |
684 | + End; | |
685 | + Explode := ListaAuxUTILS; | |
686 | +end; | |
687 | + | |
688 | + | |
689 | +Function FTP(p_Host : String; p_Port : String; p_Username : String; p_Password : String; p_PathServer : String; p_File : String; p_Dest : String) : Boolean; | |
690 | +var IdFTP : TIdFTP; | |
691 | +begin | |
692 | + Try | |
693 | + IdFTP := TIdFTP.Create(IdFTP); | |
694 | + IdFTP.Host := p_Host; | |
695 | + IdFTP.Username := p_Username; | |
696 | + IdFTP.Password := p_Password; | |
697 | + IdFTP.Port := strtoint(p_Port); | |
698 | + IdFTP.TransferType := ftBinary; | |
699 | + Try | |
700 | + if IdFTP.Connected = true then | |
701 | + begin | |
702 | + IdFTP.Disconnect; | |
703 | + end; | |
704 | + IdFTP.Connect(true); | |
705 | + IdFTP.ChangeDir(p_PathServer); | |
706 | + Try | |
707 | + IdFTP.Get(p_File, p_Dest + '\' + p_File, True); | |
708 | + result := true; | |
709 | + Except | |
710 | + result := false; | |
711 | + End; | |
712 | + Except | |
713 | + result := false; | |
714 | + end; | |
715 | + Except | |
716 | + result := false; | |
717 | + End; | |
718 | +end; | |
719 | + | |
720 | +function HomeDrive : string; | |
721 | +var | |
722 | +WinDir : array [0..144] of char; | |
723 | +begin | |
724 | +GetWindowsDirectory (WinDir, 144); | |
725 | +Result := StrPas (WinDir); | |
726 | +end; | |
727 | + | |
728 | +procedure GravaConfiguracoes; | |
729 | +var chkcacic_ini : TextFile; | |
730 | +begin | |
731 | + try | |
732 | + FileSetAttr (ExtractFilePath(Application.Exename) + '\chkcacic.ini',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000 | |
733 | + AssignFile(chkcacic_ini,ExtractFilePath(Application.Exename) + '\chkcacic.ini'); {Associa o arquivo a uma variável do tipo TextFile} | |
734 | + Rewrite (chkcacic_ini); // Recria o arquivo... | |
735 | + Append(chkcacic_ini); | |
736 | + Writeln(chkcacic_ini,'# ==================================================================================='); | |
737 | + Writeln(chkcacic_ini,'# A edição deste arquivo também pode ser feita com o comando "chkcacic.exe /config"'); | |
738 | + Writeln(chkcacic_ini,'# ==================================================================================='); | |
739 | + Writeln(chkcacic_ini,''); | |
740 | + Writeln(chkcacic_ini,''); | |
741 | + Writeln(chkcacic_ini,'# CHAVES E VALORES OBRIGATÓRIOS PARA USO DO CHKCACIC.EXE'); | |
742 | + Writeln(chkcacic_ini,'# ==================================================================================='); | |
743 | + Writeln(chkcacic_ini,'# ip_serv_cacic'); | |
744 | + Writeln(chkcacic_ini,'# Endereço IP ou Nome(DNS) do servidor onde o Módulo Gerente do CACIC foi instalado'); | |
745 | + Writeln(chkcacic_ini,'# Ex1.: ip_serv_cacic=10.xxx.yyy.zzz'); | |
746 | + Writeln(chkcacic_ini,'# Ex2.: ip_serv_cacic=uxesa001'); | |
747 | + Writeln(chkcacic_ini,'# cacic_dir'); | |
748 | + Writeln(chkcacic_ini,'# Pasta a ser criada na estação para instalação do CACIC agente'); | |
749 | + Writeln(chkcacic_ini,'# Ex.: cacic_dir=Cacic'); | |
750 | + Writeln(chkcacic_ini,'# exibe_informacoes'); | |
751 | + Writeln(chkcacic_ini,'# Indicador de exibicao de informações sobre o processo de instalação'); | |
752 | + Writeln(chkcacic_ini,'# Ex.: exibe_informacoes=N'); | |
753 | + Writeln(chkcacic_ini,''); | |
754 | + Writeln(chkcacic_ini,''); | |
755 | + Writeln(chkcacic_ini,'# CHAVES E VALORES OPCIONAIS PARA USO DO CHKCACIC.EXE'); | |
756 | + Writeln(chkcacic_ini,'# (ATENÇÃO: NÃO PREENCHER EM CASO DE CHKCACIC.INI PARA O NETLOGON!)'); | |
757 | + Writeln(chkcacic_ini,'# ==================================================================================='); | |
758 | + Writeln(chkcacic_ini,'# te_instala_informacoes_extras'); | |
759 | + Writeln(chkcacic_ini,'# Informações a serem mostradas na janela de Instalação/Recuperação'); | |
760 | + Writeln(chkcacic_ini,'# Ex.: Empresa-UF / Suporte Técnico'); | |
761 | + Writeln(chkcacic_ini,'# Emails: email_do_suporte@xxxxxx.yyy.zz, outro_email@outro_dominio.xxx.yy'); | |
762 | + Writeln(chkcacic_ini,'# Telefones: (xx) yyyy-zzzz / (xx) yyyy-zzzz'); | |
763 | + Writeln(chkcacic_ini,'# Endereço: Rua Nome_da_Rua, Nº 99999'); | |
764 | + Writeln(chkcacic_ini,'# Cidade/UF'); | |
765 | + Writeln(chkcacic_ini,''); | |
766 | + Writeln(chkcacic_ini,''); | |
767 | + Writeln(chkcacic_ini,'# Recomendação Importante:'); | |
768 | + Writeln(chkcacic_ini,'# ======================='); | |
769 | + Writeln(chkcacic_ini,'# Para benefício da rede local, criar uma pasta "modulos" no mesmo nível do chkcacic.exe, onde deverão'); | |
770 | + Writeln(chkcacic_ini,'# ser colocados todos os arquivos executáveis para uso do CACIC, pois, quando da necessidade de download'); | |
771 | + Writeln(chkcacic_ini,'# de módulo, o arquivo será apenas copiado e não será necessário o FTP:'); | |
772 | + Writeln(chkcacic_ini,'# cacic2.exe ............=> Agente Principal'); | |
773 | + Writeln(chkcacic_ini,'# ger_cols.exe ..........=> Gerente de Coletas'); | |
774 | + Writeln(chkcacic_ini,'# chksis.exe ............=> Check System Routine (chkcacic residente)'); | |
775 | + Writeln(chkcacic_ini,'# ini_cols.exe ..........=> Inicializador de Coletas'); | |
776 | + Writeln(chkcacic_ini,'# wscript.exe ...........=> Motor de Execução de Scripts VBS'); | |
777 | + Writeln(chkcacic_ini,'# col_anvi.exe ..........=> Agente Coletor de Informações de Anti-Vírus'); | |
778 | + Writeln(chkcacic_ini,'# col_comp.exe ..........=> Agente Coletor de Informações de Compartilhamentos'); | |
779 | + Writeln(chkcacic_ini,'# col_hard.exe ..........=> Agente Coletor de Informações de Hardware'); | |
780 | + Writeln(chkcacic_ini,'# col_moni.exe ..........=> Agente Coletor de Informações de Sistemas Monitorados'); | |
781 | + Writeln(chkcacic_ini,'# col_patr.exe ..........=> Agente Coletor de Informações de Patrimônio e Localização Física'); | |
782 | + Writeln(chkcacic_ini,'# col_soft.exe ..........=> Agente Coletor de Informações de Software'); | |
783 | + Writeln(chkcacic_ini,'# col_undi.exe ..........=> Agente Coletor de Informações de Unidades de Disco'); | |
784 | + Writeln(chkcacic_ini,'# ==================================================================================================================='); | |
785 | + Writeln(chkcacic_ini,''); | |
786 | + Writeln(chkcacic_ini,''); | |
787 | + Writeln(chkcacic_ini,'# ==================================================================================================================='); | |
788 | + Writeln(chkcacic_ini,'# Exemplo de estrutura para KIT (CD) de instalação'); | |
789 | + Writeln(chkcacic_ini,'# ==================================================================================================================='); | |
790 | + Writeln(chkcacic_ini,'# d:\chkcacic.exe'); | |
791 | + Writeln(chkcacic_ini,'# d:\chkcacic.ini'); | |
792 | + Writeln(chkcacic_ini,'# \modulos'); | |
793 | + Writeln(chkcacic_ini,'# cacic2.exe'); | |
794 | + Writeln(chkcacic_ini,'# chksis.exe'); | |
795 | + Writeln(chkcacic_ini,'# col_anvi.exe'); | |
796 | + Writeln(chkcacic_ini,'# col_comp.exe'); | |
797 | + Writeln(chkcacic_ini,'# col_hard.exe'); | |
798 | + Writeln(chkcacic_ini,'# col_moni.exe'); | |
799 | + Writeln(chkcacic_ini,'# col_patr.exe'); | |
800 | + Writeln(chkcacic_ini,'# col_soft.exe'); | |
801 | + Writeln(chkcacic_ini,'# col_undi.exe'); | |
802 | + Writeln(chkcacic_ini,'# ger_cols.exe'); | |
803 | + Writeln(chkcacic_ini,'# ini_cols.exe'); | |
804 | + Writeln(chkcacic_ini,'# wscript.exe'); | |
805 | + Writeln(chkcacic_ini,'# ==================================================================================================================='); | |
806 | + Writeln(chkcacic_ini,'# Obs.: Antes da gravação do CD ou imagem, é necessário executar "chkcacic.exe /config"'); | |
807 | + Writeln(chkcacic_ini,'# ==================================================================================================================='); | |
808 | + Writeln(chkcacic_ini,''); | |
809 | + Writeln(chkcacic_ini,'[Cacic2]'); | |
810 | + | |
811 | + // Atribuição dos valores do form FormConfig às variáveis... | |
812 | + v_ip_serv_cacic := Configs.Edit_ip_serv_cacic.text; | |
813 | + v_cacic_dir := Configs.Edit_cacic_dir.text; | |
814 | + if Configs.ckboxExibeInformacoes.Checked then | |
815 | + v_exibe_informacoes := 'S' | |
816 | + else | |
817 | + v_exibe_informacoes := 'N'; | |
818 | + | |
819 | + v_te_instala_informacoes_extras := Configs.Memo_te_instala_informacoes_extras.Text; | |
820 | + | |
821 | + // Escrita dos parâmetros obrigatórios | |
822 | + Writeln(chkcacic_ini,'ip_serv_cacic='+v_ip_serv_cacic); | |
823 | + Writeln(chkcacic_ini,'cacic_dir='+v_cacic_dir); | |
824 | + Writeln(chkcacic_ini,'exibe_informacoes='+v_exibe_informacoes); | |
825 | + | |
826 | + // Escrita dos valores opcionais quando existirem | |
827 | + if (v_te_instala_informacoes_extras <>'') then | |
828 | + Writeln(chkcacic_ini,'te_instala_informacoes_extras='+ StringReplace(v_te_instala_informacoes_extras,#13#10,'*13*10',[rfReplaceAll])); | |
829 | + CloseFile(chkcacic_ini); {Fecha o arquivo texto} | |
830 | + except | |
831 | + end; | |
832 | +end; | |
833 | + | |
834 | +Function ListFileDir(Path: string):string; | |
835 | +var | |
836 | + SR: TSearchRec; | |
837 | + FileList : string; | |
838 | +begin | |
839 | + if FindFirst(Path, faAnyFile, SR) = 0 then | |
840 | + begin | |
841 | + repeat | |
842 | + if (SR.Attr <> faDirectory) then | |
843 | + begin | |
844 | + if (FileList<>'') then FileList := FileList + '#'; | |
845 | + FileList := FileList + SR.Name; | |
846 | + end; | |
847 | + until FindNext(SR) <> 0; | |
848 | + FindClose(SR); | |
849 | + Result := FileList; | |
850 | + end; | |
851 | +end; | |
852 | +procedure LiberaFireWall(p_objeto:string); | |
853 | +begin | |
854 | + Try | |
855 | + if (trim(GetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\AuthorizedApplications\List\'+StringReplace(p_objeto+'.exe','\','?\',[rfReplaceAll])))='') then | |
856 | + Begin | |
857 | + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\AuthorizedApplications\List\'+StringReplace(p_objeto+'.exe','\','?\',[rfReplaceAll]),p_objeto+'.exe:*:Enabled:'+p_objeto); | |
858 | + log_diario('Liberação de FireWall para "'+p_objeto+'" efetivada!'); | |
859 | + End | |
860 | + else log_diario('Liberação de FireWall para "'+p_objeto+'" já existente.'); | |
861 | + Except | |
862 | + log_diario('Problema Liberando FireWall para "'+p_objeto+'"!'); | |
863 | + End; | |
864 | + | |
865 | +end; | |
866 | + | |
867 | +// Dica obtida em http://www.webmundi.com/delphi/dfuncaof.asp?SubTipo=Sistema | |
868 | +Function DriveType(Unidade: String):String; | |
869 | +Var StrDrive, | |
870 | + StrDriveType : String; | |
871 | + intDriveType : Integer; | |
872 | +begin | |
873 | + StrDrive := Unidade; | |
874 | + If StrDrive[Length(StrDrive)] <> '\' Then | |
875 | + StrDrive := StrDrive + ':\'; | |
876 | + | |
877 | + intDriveType := GetDriveType(PChar(StrDrive)); | |
878 | + Case intDriveType Of | |
879 | + 0 : StrDriveType := 'ERRO'; | |
880 | + 1 : StrDriveType := 'ERRO'; | |
881 | + DRIVE_REMOVABLE : StrDriveType := 'FLOPPY'; | |
882 | + DRIVE_FIXED : StrDriveType := 'HD'; | |
883 | + DRIVE_REMOTE : StrDriveType := 'REDE'; | |
884 | + DRIVE_CDROM : StrDriveType := 'CDROM'; | |
885 | + DRIVE_RAMDISK : StrDriveType := 'RAM'; | |
886 | + end; | |
887 | + Result := StrDriveType; | |
888 | +End; | |
889 | + | |
890 | +procedure chkcacic; | |
891 | +var bool_download_CACIC2, | |
892 | + bool_download_GER_COLS, | |
893 | + bool_configura, | |
894 | + bool_ExistsAutoRun : boolean; | |
895 | + | |
896 | + v_te_serv_updates, | |
897 | + v_nu_porta_serv_updates, | |
898 | + v_nm_usuario_login_serv_updates, | |
899 | + v_te_senha_login_serv_updates, | |
900 | + v_te_path_serv_updates, | |
901 | + v_te_texto_janela_instalacao, | |
902 | + v_modulos, | |
903 | + v_retorno, | |
904 | + strAux : String; | |
905 | + | |
906 | + Request_Config : TStringList; | |
907 | + v_array_modulos : TStrings; | |
908 | + Response_Config : TStringStream; | |
909 | + IdHTTP1: TIdHTTP; | |
910 | + intAux : integer; | |
911 | +begin | |
912 | + v_te_instala_frase_sucesso := 'INSTALAÇÃO/ATUALIZAÇÃO EFETUADA COM SUCESSO!'; | |
913 | + v_te_instala_frase_insucesso := '***** INSTALAÇÃO/ATUALIZAÇÃO NÃO EFETUADA COM SUCESSO *****'; | |
914 | + | |
915 | + Try | |
916 | + v_home_drive := MidStr(HomeDrive,1,3); //x:\ | |
917 | + If not (FileExists(ExtractFilePath(Application.Exename) + '\chkcacic.ini')) then | |
918 | + Begin | |
919 | + log_diario('Abrindo formulário de configurações'); | |
920 | + CriaFormConfigura; | |
921 | + MostraFormConfigura; | |
922 | + End; | |
923 | + | |
924 | + bool_download_CACIC2 := false; | |
925 | + bool_download_GER_COLS := false; | |
926 | + v_ip_serv_cacic := GetValorChaveRegIni('Cacic2', 'ip_serv_cacic' , ExtractFilePath(Application.Exename) + '\chkcacic.ini'); | |
927 | + v_cacic_dir := GetValorChaveRegIni('Cacic2', 'cacic_dir' , ExtractFilePath(Application.Exename) + '\chkcacic.ini'); | |
928 | + v_exibe_informacoes := GetValorChaveRegIni('Cacic2', 'exibe_informacoes', ExtractFilePath(Application.Exename) + '\chkcacic.ini'); | |
929 | + v_te_instala_informacoes_extras := StringReplace(GetValorChaveRegIni('Cacic2', 'te_instala_informacoes_extras', ExtractFilePath(Application.Exename) + '\chkcacic.ini'),'*13*10',#13#10,[rfReplaceAll]); | |
930 | + Dir := v_home_drive + v_cacic_dir; // Ex.: c:\cacic\ | |
931 | + | |
932 | + // Verifico se o S.O. é NT Like e se o Usuário está com privilégio administrativo... | |
933 | + if (GetWinVer >= 6) and | |
934 | + (v_exibe_informacoes = 'S') and | |
935 | + not IsAdmin then // Se NT/2000/XP/... | |
936 | + Begin | |
937 | + MessageDLG(#13#10+'ATENÇÃO! Essa aplicação requer execução com nível administrativo.',mtError,[mbOK],0); | |
938 | + End | |
939 | + else | |
940 | + Begin | |
941 | + log_diario(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'); | |
942 | + log_diario(':::::::::::::: OBTENDO VALORES DO "chkcacic.ini" ::::::::::::::'); | |
943 | + log_diario(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'); | |
944 | + log_diario('Drive de instalação......................: '+v_home_drive); | |
945 | + log_diario('Pasta para instalação....................: '+Dir); | |
946 | + log_diario('IP do servidor...........................: '+v_ip_serv_cacic); | |
947 | + log_diario(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'); | |
948 | + bool_configura := false; | |
949 | + | |
950 | + //chave AES. Recomenda-se que cada empresa/órgão altere a sua chave. | |
951 | + v_CipherKey := 'CacicBrasil'; | |
952 | + v_IV := 'abcdefghijklmnop'; | |
953 | + v_SeparatorKey := '=CacicIsFree='; // Usada apenas para o cacic2.dat | |
954 | + v_DatFileName := Dir + '\cacic2.dat'; | |
955 | + v_tstrCipherOpened := CipherOpen(v_DatFileName); | |
956 | + | |
957 | + | |
958 | + if (GetWinVer >= 8) then // Se >= WinXP... | |
959 | + Begin | |
960 | + Try | |
961 | + // Acrescento os valores para uso do FireWall nativo... | |
962 | + | |
963 | + {chkcacic} | |
964 | + LiberaFireWall(ExtractFilePath(Application.Exename) + 'chkcacic'); | |
965 | + | |
966 | + {chksis} | |
967 | + LiberaFireWall(HomeDrive + '\chksis'); | |
968 | + | |
969 | + {ger_cols} | |
970 | + LiberaFireWall(Dir + '\modulos\ger_cols'); | |
971 | + | |
972 | + Except | |
973 | + End; | |
974 | + End; | |
975 | + | |
976 | + | |
977 | + if (ParamCount > 0) and (LowerCase(Copy(ParamStr(1),1,7)) = '/config') then bool_configura := true; | |
978 | + | |
979 | + while (v_ip_serv_cacic = '') or (v_cacic_dir = '') or bool_configura do | |
980 | + Begin | |
981 | + log_diario('Abrindo formulário de configurações'); | |
982 | + bool_configura := false; | |
983 | + CriaFormConfigura; | |
984 | + Configs.Edit_ip_serv_cacic.text := v_ip_serv_cacic; | |
985 | + Configs.Edit_cacic_dir.text := v_cacic_dir; | |
986 | + if v_exibe_informacoes = 'S' then | |
987 | + Configs.ckboxExibeInformacoes.Checked := true | |
988 | + else | |
989 | + Configs.ckboxExibeInformacoes.Checked := false; | |
990 | + Configs.Memo_te_instala_informacoes_extras.text := v_te_instala_informacoes_extras; | |
991 | + MostraFormConfigura; | |
992 | + End; | |
993 | + | |
994 | + if (ParamCount > 0) and (LowerCase(Copy(ParamStr(1),1,7)) = '/config') then application.Terminate; | |
995 | + | |
996 | + // Caso o parâmetro rem_cacic_v0x seja "S/s" removo a chave/valor de execução do Cacic antigo | |
997 | + //if (LowerCase(v_rem_cacic_v0x)='s') then | |
998 | + // DelValorReg('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic'); | |
999 | + | |
1000 | + // Verifico a existência do diretório configurado para o Cacic, normalmente CACIC | |
1001 | + if not DirectoryExists(Dir) then | |
1002 | + begin | |
1003 | + log_diario('Criando pasta '+Dir); | |
1004 | + ForceDirectories(Dir); | |
1005 | + end; | |
1006 | + | |
1007 | + // Para eliminar versão 20014 e anteriores que provavelmente não fazem corretamente o AutoUpdate | |
1008 | + if not DirectoryExists(Dir+'\modulos') then | |
1009 | + begin | |
1010 | + if DeleteFile(Dir + '\cacic2.exe') then | |
1011 | + log_diario('Exclusão de '+Dir + '\cacic2.exe' + ' efetuada com sucesso!') | |
1012 | + else | |
1013 | + Begin | |
1014 | + log_diario('Exclusão não efetuada! Provavelmente já esteja sendo executado...'); | |
1015 | + log_diario('Tentarei finalizar Tarefa/Processo...'); | |
1016 | + if (GetWinVer <= 5) then // Até | |
1017 | + KillTask('cacic2.exe') | |
1018 | + else | |
1019 | + KillProcess(FindWindow('cacic2.exe',nil)); | |
1020 | + if DeleteFile(Dir + '\cacic2.exe') then | |
1021 | + log_diario('Exclusão Impossibilitada de '+Dir + '\cacic2.exe' + '!'); | |
1022 | + End; | |
1023 | + | |
1024 | + ForceDirectories(Dir + '\modulos'); | |
1025 | + log_diario('Criando pasta '+Dir+'\modulos'); | |
1026 | + end; | |
1027 | + | |
1028 | + // Crio o SubDiretório TEMP, caso não exista | |
1029 | + if not DirectoryExists(Dir+'\temp') then | |
1030 | + begin | |
1031 | + ForceDirectories(Dir + '\temp'); | |
1032 | + log_diario('Criando pasta '+Dir+'\temp'); | |
1033 | + end; | |
1034 | + | |
1035 | + | |
1036 | + // Tento o contato com o módulo gerente WEB para obtenção de | |
1037 | + // dados para conexão FTP e relativos às versões atuais dos principais agentes | |
1038 | + // Busco as configurações para acesso ao ambiente FTP - Updates | |
1039 | + Request_Config := TStringList.Create; | |
1040 | + Request_Config.Values['in_chkcacic'] := 'chkcacic'; | |
1041 | + Response_Config := TStringStream.Create(''); | |
1042 | + | |
1043 | + Try | |
1044 | + IdHTTP1 := TIdHTTP.Create(IdHTTP1); | |
1045 | + idHTTP1.AllowCookies := true; | |
1046 | + idHTTP1.ASCIIFilter := false; | |
1047 | + idHTTP1.AuthRetries := 1; | |
1048 | + idHTTP1.BoundPort := 0; | |
1049 | + idHTTP1.HandleRedirects := false; | |
1050 | + idHTTP1.ProxyParams.BasicAuthentication := false; | |
1051 | + idHTTP1.ProxyParams.ProxyPort := 0; | |
1052 | + idHTTP1.ReadTimeout := 0; | |
1053 | + idHTTP1.RecvBufferSize := 32768; | |
1054 | + idHTTP1.RedirectMaximum := 15; | |
1055 | + idHTTP1.Request.Accept := 'text/html, */*'; | |
1056 | + idHTTP1.Request.BasicAuthentication := true; | |
1057 | + idHTTP1.Request.ContentLength := -1; | |
1058 | + idHTTP1.Request.ContentRangeStart := 0; | |
1059 | + idHTTP1.Request.ContentRangeEnd := 0; | |
1060 | + idHTTP1.Request.ContentType := 'text/html'; | |
1061 | + idHTTP1.SendBufferSize := 32768; | |
1062 | + idHTTP1.Tag := 0; | |
1063 | + log_diario('Iniciando comunicação com '+'http://' + v_ip_serv_cacic + '/cacic2/ws/get_config.php'); | |
1064 | + IdHTTP1.Post('http://' + v_ip_serv_cacic + '/cacic2/ws/get_config.php', Request_Config, Response_Config); | |
1065 | + idHTTP1.Free; | |
1066 | + v_retorno := Response_Config.DataString; | |
1067 | + v_te_serv_updates := XML_RetornaValor('te_serv_updates' , v_retorno); | |
1068 | + v_nu_porta_serv_updates := XML_RetornaValor('nu_porta_serv_updates' , v_retorno); | |
1069 | + v_nm_usuario_login_serv_updates := XML_RetornaValor('nm_usuario_login_serv_updates', v_retorno); | |
1070 | + v_te_senha_login_serv_updates := XML_RetornaValor('te_senha_login_serv_updates' , v_retorno); | |
1071 | + v_te_path_serv_updates := XML_RetornaValor('te_path_serv_updates' , v_retorno); | |
1072 | + | |
1073 | + //log_diario('Retorno da comunicação: '+v_retorno); | |
1074 | + | |
1075 | + log_diario(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'); | |
1076 | + log_diario(':::::::::::::::: VALORES OBTIDOS NO Gerente WEB :::::::::::::::'); | |
1077 | + log_diario(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'); | |
1078 | + log_diario('Servidor de updates......................: '+v_te_serv_updates); | |
1079 | + log_diario('Porta do servidor de updates.............: '+v_nu_porta_serv_updates); | |
1080 | + log_diario('Usuário para login no servidor de updates: '+v_nm_usuario_login_serv_updates); | |
1081 | + log_diario('Pasta no servidor de updates.............: '+v_te_path_serv_updates); | |
1082 | + log_diario(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'); | |
1083 | + Except | |
1084 | + Begin | |
1085 | + if v_exibe_informacoes = 'S' then | |
1086 | + MessageDLG(#13#10+'ATENÇÃO! Não foi possível estabelecer comunicação com o módulo Gerente WEB em "'+v_ip_serv_cacic+'".',mtError,[mbOK],0); | |
1087 | + log_diario('**********************************************************'); | |
1088 | + log_diario('Oops! Não Foi Possível Comunicar com o Módulo Gerente WEB!'); | |
1089 | + log_diario('**********************************************************'); | |
1090 | + End | |
1091 | + End; | |
1092 | + Request_Config.Free; | |
1093 | + Response_Config.Free; | |
1094 | + | |
1095 | + // Verificação de versão do cacic2.exe e exclusão em caso de versão antiga | |
1096 | + If (FileExists(Dir + '\cacic2.exe')) Then | |
1097 | + Begin | |
1098 | + v_versao_local := trim(GetVersionInfo(Dir + '\cacic2.exe')); | |
1099 | + v_versao_local := StringReplace(v_versao_local,'.','',[rfReplaceAll]); | |
1100 | + | |
1101 | + v_versao_remota_inteira := XML_RetornaValor('CACIC2' , v_retorno); | |
1102 | + v_versao_remota_capada := Copy(v_versao_remota_inteira,1,StrLen(PAnsiChar(v_versao_remota_inteira))-4); | |
1103 | + | |
1104 | + if not (v_versao_remota_inteira = '') then | |
1105 | + log_diario('Versão remota de "cacic2.exe": '+v_versao_remota_capada + '('+v_versao_remota_inteira+')'); | |
1106 | + | |
1107 | + if (v_versao_local ='0000') or // Provavelmente versão muito antiga ou corrompida | |
1108 | + (v_versao_local ='2208') then | |
1109 | +// (v_versao_local <> v_versao_remota_capada) then | |
1110 | + Begin | |
1111 | + log_diario('Excluindo versão "'+v_versao_local+'" de Cacic2.exe'); | |
1112 | + if DeleteFile(Dir + '\cacic2.exe') then | |
1113 | + log_diario('Exclusão de '+Dir + '\cacic2.exe'+' efetuada com sucesso!') | |
1114 | + else | |
1115 | + Begin | |
1116 | + log_diario('Exclusão não efetuada! Provavelmente já esteja sendo executado...'); | |
1117 | + log_diario('Tentarei finalizar Tarefa/Processo...'); | |
1118 | + if (GetWinVer <= 5) then // Até | |
1119 | + KillTask('cacic2.exe') | |
1120 | + else | |
1121 | + KillProcess(FindWindow('cacic2.exe',nil)); | |
1122 | + if DeleteFile(Dir + '\cacic2.exe') then | |
1123 | + log_diario('Exclusão Impossibilitada de '+Dir + '\cacic2.exe' + '!'); | |
1124 | + End; | |
1125 | + End; | |
1126 | + End; | |
1127 | + | |
1128 | + // Verificação de versão do ger_cols.exe e exclusão em caso de versão antiga | |
1129 | + If (FileExists(Dir + '\modulos\ger_cols.exe')) Then | |
1130 | + Begin | |
1131 | + v_versao_local := trim(GetVersionInfo(Dir + '\modulos\ger_cols.exe')); | |
1132 | + v_versao_local := StringReplace(v_versao_local,'.','',[rfReplaceAll]); | |
1133 | + | |
1134 | + v_versao_remota_inteira := XML_RetornaValor('GER_COLS' , v_retorno); | |
1135 | + v_versao_remota_capada := Copy(v_versao_remota_inteira,1,StrLen(PAnsiChar(v_versao_remota_inteira))-4); | |
1136 | + | |
1137 | + if not (v_versao_remota_inteira = '') then | |
1138 | + log_diario('Versão remota de "ger_cols.exe": '+v_versao_remota_capada+ '('+v_versao_remota_inteira+')'); | |
1139 | + | |
1140 | + if (v_versao_local ='0000') then //or // Provavelmente versão muito antiga ou corrompida | |
1141 | +// (v_versao_local <> v_versao_remota_capada) then | |
1142 | + Begin | |
1143 | + log_diario('Excluindo versão "'+v_versao_local+'" de Ger_Cols.exe'); | |
1144 | + if DeleteFile(Dir + '\modulos\ger_cols.exe') then | |
1145 | + log_diario('Exclusão de '+Dir + '\modulos\ger_cols.exe'+' efetuada com sucesso!') | |
1146 | + else | |
1147 | + Begin | |
1148 | + log_diario('Exclusão não efetuada! Provavelmente já esteja sendo executado...'); | |
1149 | + log_diario('Tentarei finalizar Tarefa/Processo...'); | |
1150 | + if (GetWinVer <= 5) then // Até | |
1151 | + KillTask('ger_cols.exe') | |
1152 | + else | |
1153 | + KillProcess(FindWindow('ger_cols.exe',nil)); | |
1154 | + if DeleteFile(Dir + '\modulos\ger_cols.exe') then | |
1155 | + log_diario('Exclusão Impossibilitada de '+Dir + '\modulos\ger_cols.exe' + '!'); | |
1156 | + End; | |
1157 | + End; | |
1158 | + End; | |
1159 | + | |
1160 | + | |
1161 | + // Verificação de versão do chksis.exe e exclusão em caso de versão antiga | |
1162 | + If (FileExists(HomeDrive + '\chksis.exe')) Then | |
1163 | + Begin | |
1164 | + v_versao_local := trim(GetVersionInfo(HomeDrive + '\chksis.exe')); | |
1165 | + v_versao_local := StringReplace(v_versao_local,'.','',[rfReplaceAll]); | |
1166 | + | |
1167 | + v_versao_remota_inteira := XML_RetornaValor('CHKSIS' , v_retorno); | |
1168 | + v_versao_remota_capada := Copy(v_versao_remota_inteira,1,StrLen(PAnsiChar(v_versao_remota_inteira))-4); | |
1169 | + | |
1170 | + if not (v_versao_remota_inteira = '') then | |
1171 | + log_diario('Versão remota de "chksis.exe": '+v_versao_remota_capada+ '('+v_versao_remota_inteira+')'); | |
1172 | + | |
1173 | + if (v_versao_local ='0000') then //or // Provavelmente versão muito antiga ou corrompida | |
1174 | +// (v_versao_local <> v_versao_remota_capada) then | |
1175 | + Begin | |
1176 | + log_diario('Excluindo versão "'+v_versao_local+'" de ChkSis.exe'); | |
1177 | + if DeleteFile(HomeDrive + '\chksis.exe') then | |
1178 | + log_diario('Exclusão de '+HomeDrive + '\chksis.exe'+' efetuada com sucesso!') | |
1179 | + else | |
1180 | + Begin | |
1181 | + log_diario('Exclusão não efetuada! Provavelmente já esteja sendo executado...'); | |
1182 | + log_diario('Tentarei finalizar Tarefa/Processo...'); | |
1183 | + if (GetWinVer <= 5) then // Até | |
1184 | + KillTask('chksis.exe') | |
1185 | + else | |
1186 | + KillProcess(FindWindow('chksis.exe',nil)); | |
1187 | + if DeleteFile(HomeDrive + '\chksis.exe') then | |
1188 | + log_diario('Exclusão Impossibilitada de '+HomeDrive + '\chksis.exe' + '!'); | |
1189 | + End; | |
1190 | + | |
1191 | + End; | |
1192 | + End; | |
1193 | + | |
1194 | + // Tento detectar o ChkSis.EXE e copio ou faço FTP caso não exista | |
1195 | + If not FileExists(HomeDrive + '\chksis.exe') Then | |
1196 | + begin | |
1197 | + if (FileExists(ExtractFilePath(Application.Exename) + 'modulos\chksis.exe')) then | |
1198 | + Begin | |
1199 | + log_diario('Copiando ChkSis.exe de '+ExtractFilePath(Application.Exename)+'modulos\'); | |
1200 | + CopyFile(PChar(ExtractFilePath(Application.Exename) + 'modulos\chksis.exe'), PChar(HomeDrive + '\chksis.exe'),false); | |
1201 | + FileSetAttr (PChar(HomeDrive + '\chksis.exe'),0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000 | |
1202 | + End | |
1203 | + else | |
1204 | + Begin | |
1205 | + if not FTP(v_te_serv_updates, | |
1206 | + v_nu_porta_serv_updates, | |
1207 | + v_nm_usuario_login_serv_updates, | |
1208 | + v_te_senha_login_serv_updates, | |
1209 | + v_te_path_serv_updates, | |
1210 | + 'chksis.exe', | |
1211 | + HomeDrive) and (v_exibe_informacoes = 'S') then | |
1212 | + MessageDLG(#13#10+'ATENÇÃO! Não foi possível efetuar FTP para "'+HomeDrive + '\chksis.exe".'+#13#10+'Verifique o Servidor de Updates.',mtError,[mbOK],0); | |
1213 | + | |
1214 | + If not FileExists(HomeDrive + '\chksis.exe') Then | |
1215 | + Begin | |
1216 | + log_diario('Problemas Efetuando Download de ChkSis.exe(FTP):'); | |
1217 | + log_diario('v_te_serv_updates:'+v_te_serv_updates); | |
1218 | + log_diario('v_nu_porta_serv_updates:'+v_nu_porta_serv_updates); | |
1219 | + log_diario('v_nm_usuario_login_serv_updates:'+v_nm_usuario_login_serv_updates); | |
1220 | + log_diario('v_te_senha_login_serv_updates:'+v_te_senha_login_serv_updates); | |
1221 | + log_diario('v_te_path_serv_updates:'+v_te_path_serv_updates); | |
1222 | + End | |
1223 | + else log_diario('Download Concluído de ChkSis.exe (FTP)'); | |
1224 | + | |
1225 | + End; | |
1226 | + end; | |
1227 | + | |
1228 | + // Tento detectar o ChkSis.INI e crio-o apartir do chkcacic.ini | |
1229 | + If not FileExists(HomeDrive + '\chksis.ini') Then | |
1230 | + begin | |
1231 | + log_diario('Criando ChkSis.ini'); | |
1232 | + CopyFile(PChar(ExtractFilePath(Application.Exename) + 'chkcacic.ini'), PChar(HomeDrive + '\chksis.ini'),false); | |
1233 | + FileSetAttr ( PChar(HomeDrive + '\chksis.ini'),0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000 | |
1234 | + end; | |
1235 | + | |
1236 | + // Tento detectar o cacic2.INI e crio-o apartir do chkcacic.ini | |
1237 | + If not FileExists(Dir + '\cacic2.ini') Then | |
1238 | + begin | |
1239 | + CopyFile(PChar(ExtractFilePath(Application.Exename) + 'chkcacic.ini'), PChar(Dir + '\cacic2.ini'),false) | |
1240 | + end; | |
1241 | + | |
1242 | + // Verifico se existe a pasta "modulos" | |
1243 | + v_modulos := ListFileDir(ExtractFilePath(Application.Exename)+'\modulos\*.exe'); | |
1244 | + if (v_modulos <> '') then log_diario('Pasta "Modulos" encontrada..'); | |
1245 | + | |
1246 | + // Tento detectar o Agente Principal e copio ou faço FTP caso não exista | |
1247 | + If not FileExists(Dir + '\cacic2.exe') Then | |
1248 | + Begin | |
1249 | + if (FileExists(ExtractFilePath(Application.Exename) + '\modulos\cacic2.exe')) then | |
1250 | + Begin | |
1251 | + log_diario('Copiando Cacic2.exe de '+ExtractFilePath(Application.Exename)+'modulos\'); | |
1252 | + CopyFile(PChar(ExtractFilePath(Application.Exename) + 'modulos\cacic2.exe'), PChar(Dir + '\cacic2.exe'),false); | |
1253 | + FileSetAttr (PChar(Dir + '\cacic2.exe'),0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000 | |
1254 | + bool_download_CACIC2 := true; | |
1255 | + End | |
1256 | + else | |
1257 | + begin | |
1258 | + if not FTP(v_te_serv_updates, | |
1259 | + v_nu_porta_serv_updates, | |
1260 | + v_nm_usuario_login_serv_updates, | |
1261 | + v_te_senha_login_serv_updates, | |
1262 | + v_te_path_serv_updates, | |
1263 | + 'cacic2.exe', | |
1264 | + Dir) and (v_exibe_informacoes = 'S') then | |
1265 | + MessageDLG(#13#10+'ATENÇÃO! Não foi possível efetuar FTP para "'+Dir + '\cacic2.exe".'+#13#10+'Verifique o Servidor de Updates.',mtError,[mbOK],0); | |
1266 | + | |
1267 | + bool_download_CACIC2 := true; | |
1268 | + | |
1269 | + If not FileExists(Dir + '\cacic2.exe') Then | |
1270 | + Begin | |
1271 | + log_diario('Problemas Efetuando Download de Cacic2.exe(FTP):'); | |
1272 | + log_diario('v_te_serv_updates:'+v_te_serv_updates); | |
1273 | + log_diario('v_nu_porta_serv_updates:'+v_nu_porta_serv_updates); | |
1274 | + log_diario('v_nm_usuario_login_serv_updates:'+v_nm_usuario_login_serv_updates); | |
1275 | + log_diario('v_te_senha_login_serv_updates:'+v_te_senha_login_serv_updates); | |
1276 | + log_diario('v_te_path_serv_updates:'+v_te_path_serv_updates); | |
1277 | + bool_download_CACIC2 := false; | |
1278 | + End | |
1279 | + else log_diario('Download Concluído de Cacic2.exe (FTP)'); | |
1280 | + | |
1281 | + end; | |
1282 | + End; | |
1283 | + // Tento detectar o Gerente de Coletas e copio ou faço FTP caso não exista | |
1284 | + If (not FileExists(Dir + '\modulos\ger_cols.exe')) Then | |
1285 | + Begin | |
1286 | + if (FileExists(ExtractFilePath(Application.Exename) + '\modulos\ger_cols.exe')) then | |
1287 | + Begin | |
1288 | + log_diario('Copiando Ger_Cols.exe de '+ExtractFilePath(Application.Exename)+'modulos\'); | |
1289 | + CopyFile(PChar(ExtractFilePath(Application.Exename) + 'modulos\ger_cols.exe'), PChar(Dir + '\modulos\ger_cols.exe'),false); | |
1290 | + FileSetAttr (PChar(Dir + '\modulos\ger_cols.exe'),0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000 | |
1291 | + bool_download_GER_COLS := true; | |
1292 | + End | |
1293 | + else | |
1294 | + begin | |
1295 | + if not FTP(v_te_serv_updates, | |
1296 | + v_nu_porta_serv_updates, | |
1297 | + v_nm_usuario_login_serv_updates, | |
1298 | + v_te_senha_login_serv_updates, | |
1299 | + v_te_path_serv_updates, | |
1300 | + 'ger_cols.exe', | |
1301 | + Dir + '\modulos') and (v_exibe_informacoes = 'S') then | |
1302 | + MessageDLG(#13#10+'ATENÇÃO! Não foi possível efetuar FTP para "'+Dir + '\modulos\ger_cols.exe".'+#13#10+'Verifique o Servidor de Updates.',mtError,[mbOK],0); | |
1303 | + | |
1304 | + bool_download_GER_COLS := true; | |
1305 | + If (not FileExists(Dir + '\modulos\ger_cols.exe')) Then | |
1306 | + Begin | |
1307 | + log_diario('Problemas Efetuando Download de Ger_Cols.exe(FTP):'); | |
1308 | + log_diario('v_te_serv_updates:'+v_te_serv_updates); | |
1309 | + log_diario('v_nu_porta_serv_updates:'+v_nu_porta_serv_updates); | |
1310 | + log_diario('v_nm_usuario_login_serv_updates:'+v_nm_usuario_login_serv_updates); | |
1311 | + log_diario('v_te_senha_login_serv_updates:'+v_te_senha_login_serv_updates); | |
1312 | + log_diario('v_te_path_serv_updates:'+v_te_path_serv_updates); | |
1313 | + bool_download_GER_COLS := false; | |
1314 | + End | |
1315 | + else log_diario('Download Concluído de Ger_Cols.exe (FTP)'); | |
1316 | + | |
1317 | + end; | |
1318 | + End; | |
1319 | + | |
1320 | + // Caso exista a pasta "modulos", copio todos os executáveis para a pasta Cacic\modulos, exceto cacic2.exe, ger_cols.exe e chksis.exe | |
1321 | + if (v_modulos <> '') then | |
1322 | + Begin | |
1323 | + v_array_modulos := explode(v_modulos,'#'); | |
1324 | + For intAux := 0 To v_array_modulos.count -1 Do | |
1325 | + Begin | |
1326 | + if (v_array_modulos[intAux]<>'cacic2.exe') and | |
1327 | + (v_array_modulos[intAux]<>'ger_cols.exe') and | |
1328 | + (v_array_modulos[intAux]<>'chksis.exe') then | |
1329 | + Begin | |
1330 | + log_diario('Copiando '+v_array_modulos[intAux]+' de '+ExtractFilePath(Application.Exename)+'modulos\'); | |
1331 | + CopyFile(PChar(ExtractFilePath(Application.Exename) + 'modulos\'+v_array_modulos[intAux]), PChar(Dir + '\modulos\'+v_array_modulos[intAux]),false); | |
1332 | + FileSetAttr (PChar(Dir + '\modulos\'+v_array_modulos[intAux]),0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000 | |
1333 | + End; | |
1334 | + End; | |
1335 | + End; | |
1336 | + | |
1337 | + log_diario('Gravando registros para auto-execução'); | |
1338 | + | |
1339 | + // Crio a chave/valor cacic2 para autoexecução do Cacic, caso não exista esta chave/valor | |
1340 | + // Crio a chave/valor chksis para autoexecução do ChkSIS, caso não exista esta chave/valor | |
1341 | + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\CheckSystemRoutine', HomeDrive + '\chksis.exe'); | |
1342 | + | |
1343 | + bool_ExistsAutoRun := false; | |
1344 | + if (GetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic2')=Dir + '\cacic2.exe') then | |
1345 | + bool_ExistsAutoRun := true | |
1346 | + else | |
1347 | + SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic2', Dir + '\cacic2.exe'); | |
1348 | + | |
1349 | + // Igualo as chaves ip_serv_cacic dos arquivos chksis.ini e cacic2.ini! | |
1350 | + SetValorDatMemoria('Configs.EnderecoServidor', v_ip_serv_cacic); | |
1351 | + log_diario('Fechando Arquivo de Configurações do CACIC'); | |
1352 | + CipherClose(v_DatFileName); | |
1353 | + log_diario('Abrindo Arquivo de Configurações do CHKSIS'); | |
1354 | + CipherOpen(HomeDrive + '\chksis.dat'); | |
1355 | + SetValorDatMemoria('Cacic2.ip_serv_cacic', v_ip_serv_cacic); | |
1356 | + // SetValorChaveRegIni('Cacic2', 'ip_serv_cacic', v_ip_serv_cacic, HomeDrive + '\chksis.ini'); | |
1357 | + | |
1358 | + | |
1359 | + // Se NT/2K/XP... | |
1360 | + // If NT Like... | |
1361 | + if (GetWinVer > 5) then | |
1362 | + Begin | |
1363 | + log_diario(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'); | |
1364 | + log_diario('::::::: VERIFICANDO FILE SYSTEM E ATRIBUINDO PERMISSÕES :::::::'); | |
1365 | + log_diario(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'); | |
1366 | + Form1.FS_SetSecurity(Dir); | |
1367 | + Form1.FS_SetSecurity(Dir + '\cacic2.exe'); | |
1368 | + Form1.FS_SetSecurity(Dir + '\modulos'); | |
1369 | + Form1.FS_SetSecurity(Dir + '\temp'); | |
1370 | + Form1.FS_SetSecurity(v_DatFileName) ; // cacic2.dat | |
1371 | + | |
1372 | + // Atribuição de acesso a todos os módulos para permissão de atualizações de versão | |
1373 | + Form1.FS_SetSecurity(Dir + '\modulos\ger_cols.exe'); | |
1374 | + Form1.FS_SetSecurity(Dir + '\modulos\col_anvi.exe'); | |
1375 | + Form1.FS_SetSecurity(Dir + '\modulos\col_comp.exe'); | |
1376 | + Form1.FS_SetSecurity(Dir + '\modulos\col_hard.exe'); | |
1377 | + Form1.FS_SetSecurity(Dir + '\modulos\col_moni.exe'); | |
1378 | + Form1.FS_SetSecurity(Dir + '\modulos\col_patr.exe'); | |
1379 | + Form1.FS_SetSecurity(Dir + '\modulos\col_soft.exe'); | |
1380 | + Form1.FS_SetSecurity(Dir + '\modulos\col_undi.exe'); | |
1381 | + Form1.FS_SetSecurity(Dir + '\modulos\ini_cols.exe'); | |
1382 | + Form1.FS_SetSecurity(Dir + '\modulos\wscript.exe'); | |
1383 | + log_diario(':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'); | |
1384 | + End; | |
1385 | + | |
1386 | + // Caso o Cacic tenha sido baixado executo-o com parâmetro de configuração de servidor | |
1387 | + if (bool_download_CACIC2) or (bool_download_GER_COLS) then | |
1388 | + Begin | |
1389 | + v_te_texto_janela_instalacao := v_te_instala_informacoes_extras; | |
1390 | + if (GetValorChaveRegEdit('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\cacic2')=Dir + '\cacic2.exe') then | |
1391 | + Begin | |
1392 | + if (v_exibe_informacoes = 'S') then | |
1393 | + MessageDlg(#13#10+#13#10+v_te_instala_frase_sucesso+#13#10+#13#10+#13#10 + '======================================================' + #13#10 + v_te_texto_janela_instalacao+ '======================================================',mtInformation,[mbok],0); | |
1394 | + End | |
1395 | + else if (v_exibe_informacoes = 'S') then | |
1396 | + MessageDlg(#13#10+#13#10+v_te_instala_frase_insucesso+#13#10+#13#10+#13#10 + '======================================================' + #13#10 + v_te_texto_janela_instalacao+ '======================================================',mtInformation,[mbok],0); | |
1397 | + | |
1398 | + // Se eu não encontrei a chave de autoexecução ou | |
1399 | + // Se a unidade origem de chamada ao ChkCacic refere-se a Floppy, CDROM ou Flash | |
1400 | + // Eu executo o agente principal | |
1401 | + strAux := DriveType(Copy(ExtractFilePath(Application.Exename),1,1)); | |
1402 | + if not bool_ExistsAutoRun or | |
1403 | + (not(strAux = 'ERRO') and | |
1404 | + not(strAux = 'REDE')) then | |
1405 | + Begin | |
1406 | + log_diario('Executando '+Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic); | |
1407 | + WinExec(PChar(Dir + '\cacic2.exe /ip_serv_cacic=' + v_ip_serv_cacic+ ' /execute'), SW_HIDE); | |
1408 | + End | |
1409 | + else | |
1410 | + log_diario('Não Executei. Chave de AutoExecução já existente...'); | |
1411 | + | |
1412 | + End | |
1413 | + else | |
1414 | + log_diario('ATENÇÃO: A Instalação NÃO Foi Realizada com Sucesso ou Atualização Desnecessária!'); | |
1415 | + End; | |
1416 | + Except | |
1417 | + log_diario('Falha na instalação'); | |
1418 | + End; | |
1419 | + | |
1420 | +end; | |
1421 | + | |
1422 | +function FindWindowByTitle(WindowTitle: string): Hwnd; | |
1423 | +var | |
1424 | + NextHandle: Hwnd; | |
1425 | + NextTitle: array[0..260] of char; | |
1426 | +begin | |
1427 | + // Get the first window | |
1428 | + NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST); | |
1429 | + while NextHandle > 0 do | |
1430 | + begin | |
1431 | + // retrieve its text | |
1432 | + GetWindowText(NextHandle, NextTitle, 255); | |
1433 | + | |
1434 | + if (trim(StrPas(NextTitle))<> '') and (Pos(strlower(pchar(WindowTitle)), strlower(PChar(StrPas(NextTitle)))) <> 0) then | |
1435 | + begin | |
1436 | + Result := NextHandle; | |
1437 | + Exit; | |
1438 | + end | |
1439 | + else | |
1440 | + // Get the next window | |
1441 | + NextHandle := GetWindow(NextHandle, GW_HWNDNEXT); | |
1442 | + end; | |
1443 | + Result := 0; | |
1444 | +end; | |
1445 | + | |
1446 | +// Rotina obtida em http://www.swissdelphicenter.ch/torry/showcode.php?id=266 | |
1447 | +{For Windows 9x/ME/2000/XP } | |
1448 | +function KillTask(ExeFileName: string): Integer; | |
1449 | +const | |
1450 | + PROCESS_TERMINATE = $0001; | |
1451 | +var | |
1452 | + ContinueLoop: BOOL; | |
1453 | + FSnapshotHandle: THandle; | |
1454 | + FProcessEntry32: TProcessEntry32; | |
1455 | +begin | |
1456 | + Result := 0; | |
1457 | + FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | |
1458 | + FProcessEntry32.dwSize := SizeOf(FProcessEntry32); | |
1459 | + ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); | |
1460 | + | |
1461 | + while Integer(ContinueLoop) <> 0 do | |
1462 | + begin | |
1463 | + if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = | |
1464 | + UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = | |
1465 | + UpperCase(ExeFileName))) then | |
1466 | + Result := Integer(TerminateProcess( | |
1467 | + OpenProcess(PROCESS_TERMINATE, | |
1468 | + BOOL(0), | |
1469 | + FProcessEntry32.th32ProcessID), | |
1470 | + 0)); | |
1471 | + ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); | |
1472 | + end; | |
1473 | + CloseHandle(FSnapshotHandle); | |
1474 | +end; | |
1475 | + | |
1476 | +// Rotina obtida em http://www.swissdelphicenter.ch/torry/showcode.php?id=266 | |
1477 | +{ For Windows NT/2000/XP } | |
1478 | +procedure KillProcess(hWindowHandle: HWND); | |
1479 | +var | |
1480 | + hprocessID: INTEGER; | |
1481 | + processHandle: THandle; | |
1482 | + DWResult: DWORD; | |
1483 | +begin | |
1484 | + SendMessageTimeout(hWindowHandle, WM_DDE_TERMINATE, 0, 0, | |
1485 | + SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult); | |
1486 | + | |
1487 | + if isWindow(hWindowHandle) then | |
1488 | + begin | |
1489 | + // PostMessage(hWindowHandle, WM_QUIT, 0, 0); | |
1490 | + | |
1491 | + { Get the process identifier for the window} | |
1492 | + GetWindowThreadProcessID(hWindowHandle, @hprocessID); | |
1493 | + if hprocessID <> 0 then | |
1494 | + begin | |
1495 | + { Get the process handle } | |
1496 | + processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION, | |
1497 | + False, hprocessID); | |
1498 | + if processHandle <> 0 then | |
1499 | + begin | |
1500 | + { Terminate the process } | |
1501 | + TerminateProcess(processHandle, 0); | |
1502 | + CloseHandle(ProcessHandle); | |
1503 | + end; | |
1504 | + end; | |
1505 | + end; | |
1506 | +end; | |
1507 | + | |
1508 | +procedure TForm1.FormCreate(Sender: TObject); | |
1509 | +begin | |
1510 | + Application.ShowMainForm:=false; | |
1511 | + if (FindWindowByTitle('chksis') = 0) then | |
1512 | + chkcacic | |
1513 | + else | |
1514 | + log_diario('Não executei devido execução em paralelo de "chksis"'); | |
1515 | + | |
1516 | + Application.Terminate; | |
1517 | +end; | |
1518 | + | |
1519 | +procedure TForm1.FS_SetSecurity(p_Target : String); | |
1520 | +var intAux : integer; | |
1521 | + v_FS_Security : TNTFileSecurity; | |
1522 | +begin | |
1523 | + v_FS_Security := TNTFileSecurity.Create(nil); | |
1524 | + v_FS_Security.FileName := ''; | |
1525 | + v_FS_Security.FileName := p_Target; | |
1526 | + v_FS_Security.RefreshSecurity; | |
1527 | + | |
1528 | + if (v_FS_Security.FileSystemName='NTFS')then | |
1529 | + Begin | |
1530 | + for intAux := 0 to Pred(v_FS_Security.EntryCount) do | |
1531 | + begin | |
1532 | + case v_FS_Security.EntryType[intAux] of | |
1533 | + seAlias : Try | |
1534 | + // Atribuo total privilégio aos grupos locais sobre a pasta "CACIC" | |
1535 | + // Set all privilegies to local groups on p_Target | |
1536 | + case v_FS_Security.EntryType[intAux] of | |
1537 | + seAlias : // Se for grupo local... | |
1538 | + Begin // If local group... | |
1539 | + v_FS_Security.FileRights[intAux] := [faAll]; | |
1540 | + v_FS_Security.DirectoryRights[intAux] := [faAll]; | |
1541 | + log_diario(p_Target + ' [Full Access] >> '+v_FS_Security.EntryName[intAux]); | |
1542 | + //Setting total access on p_Target to local groups. | |
1543 | + End; | |
1544 | + end; | |
1545 | + Except | |
1546 | + End; | |
1547 | + End; | |
1548 | + end; | |
1549 | + | |
1550 | + // Atribui permissão total aos grupos locais | |
1551 | + // Set total permissions to local groups | |
1552 | + v_FS_Security.SetSecurity; | |
1553 | + end | |
1554 | + else Log_diario('File System diferente de "NTFS"'); | |
1555 | + | |
1556 | + v_FS_Security.Free; | |
1557 | +end; | |
1558 | +end. | ... | ... |
No preview for this file type
4.14 KB
ger_cols/ger_cols.dpr
... | ... | @@ -3115,7 +3115,7 @@ begin |
3115 | 3115 | |
3116 | 3116 | // Caso tenha sido invocado por um CACIC2.EXE versão antiga, assumo o valor abaixo... |
3117 | 3117 | // Solução provisória até a convergência das versões do Agente Principal e do Gerente de Coletas |
3118 | - if (trim(v_CipherKey)='') then v_CipherKey := 'CacicES2005'; | |
3118 | + if (trim(v_CipherKey)='') then v_CipherKey := 'CacicBrasil'; | |
3119 | 3119 | |
3120 | 3120 | if (trim(v_CipherKey)<>'') then |
3121 | 3121 | Begin | ... | ... |
main.dcu
No preview for this file type
mapa/main_mapa.dcu
No preview for this file type
mapa/main_mapa.pas
... | ... | @@ -62,7 +62,7 @@ const constSECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, |
62 | 62 | constSECURITY_BUILTIN_DOMAIN_RID = $00000020; |
63 | 63 | constDOMAIN_ALIAS_RID_ADMINS = $00000220; |
64 | 64 | |
65 | -const constCipherKey = 'CacicES2005'; | |
65 | +const constCipherKey = 'CacicBrasil'; | |
66 | 66 | constIV = 'abcdefghijklmnop'; |
67 | 67 | constSeparatorKey = '=CacicIsFree='; // Usada apenas para o cacic2.dat |
68 | 68 | |
... | ... | @@ -1148,15 +1148,15 @@ begin |
1148 | 1148 | Request_mapa.Values['te_workgroup'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('TcpIp.TE_WORKGROUP' , frmMapaCacic.tStringsCipherOpened)); |
1149 | 1149 | Request_mapa.Values['id_usuario'] := frmMapaCacic.EnCrypt(frmMapaCacic.strId_usuario); |
1150 | 1150 | |
1151 | - Request_mapa.Values['id_unid_organizacional_nivel1'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Patrimonio.id_unid_organizacional_nivel1' , frmMapaCacic.tStringsCipherOpened)); | |
1152 | - Request_mapa.Values['id_unid_organizacional_nivel2'] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Patrimonio.id_unid_organizacional_nivel2' , frmMapaCacic.tStringsCipherOpened)); | |
1153 | - Request_mapa.Values['te_localizacao_complementar' ] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Patrimonio.te_localizacao_complementar' , frmMapaCacic.tStringsCipherOpened)); | |
1154 | - Request_mapa.Values['te_info_patrimonio1' ] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Patrimonio.te_info_patrimonio1' , frmMapaCacic.tStringsCipherOpened)); | |
1155 | - Request_mapa.Values['te_info_patrimonio2' ] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Patrimonio.te_info_patrimonio2' , frmMapaCacic.tStringsCipherOpened)); | |
1156 | - Request_mapa.Values['te_info_patrimonio3' ] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Patrimonio.te_info_patrimonio3' , frmMapaCacic.tStringsCipherOpened)); | |
1157 | - Request_mapa.Values['te_info_patrimonio4' ] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Patrimonio.te_info_patrimonio4' , frmMapaCacic.tStringsCipherOpened)); | |
1158 | - Request_mapa.Values['te_info_patrimonio5' ] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Patrimonio.te_info_patrimonio5' , frmMapaCacic.tStringsCipherOpened)); | |
1159 | - Request_mapa.Values['te_info_patrimonio6' ] := frmMapaCacic.EnCrypt(frmMapaCacic.GetValorDatMemoria('Patrimonio.te_info_patrimonio6' , frmMapaCacic.tStringsCipherOpened)); | |
1151 | + Request_mapa.Values['id_unid_organizacional_nivel1'] := frmMapaCacic.EnCrypt(strAux1); | |
1152 | + Request_mapa.Values['id_unid_organizacional_nivel2'] := frmMapaCacic.EnCrypt(strAux2); | |
1153 | + Request_mapa.Values['te_localizacao_complementar' ] := frmMapaCacic.EnCrypt(ed_te_localizacao_complementar.Text); | |
1154 | + Request_mapa.Values['te_info_patrimonio1' ] := frmMapaCacic.EnCrypt(ed_te_info_patrimonio1.Text); | |
1155 | + Request_mapa.Values['te_info_patrimonio2' ] := frmMapaCacic.EnCrypt(ed_te_info_patrimonio2.Text); | |
1156 | + Request_mapa.Values['te_info_patrimonio3' ] := frmMapaCacic.EnCrypt(ed_te_info_patrimonio3.Text); | |
1157 | + Request_mapa.Values['te_info_patrimonio4' ] := frmMapaCacic.EnCrypt(ed_te_info_patrimonio4.Text); | |
1158 | + Request_mapa.Values['te_info_patrimonio5' ] := frmMapaCacic.EnCrypt(ed_te_info_patrimonio5.Text); | |
1159 | + Request_mapa.Values['te_info_patrimonio6' ] := frmMapaCacic.EnCrypt(ed_te_info_patrimonio6.Text); | |
1160 | 1160 | |
1161 | 1161 | strRetorno := frmMapaCacic.ComunicaServidor('mapa_set_patrimonio.php', Request_mapa, ''); |
1162 | 1162 | Request_mapa.Free; | ... | ... |
mapa/mapacacic.dof
... | ... | @@ -115,7 +115,7 @@ AutoIncBuild=0 |
115 | 115 | MajorVer=1 |
116 | 116 | MinorVer=0 |
117 | 117 | Release=0 |
118 | -Build=0 | |
118 | +Build=1 | |
119 | 119 | Debug=0 |
120 | 120 | PreRelease=0 |
121 | 121 | Special=0 |
... | ... | @@ -126,7 +126,7 @@ CodePage=1252 |
126 | 126 | [Version Info Keys] |
127 | 127 | CompanyName=Dataprev-ES |
128 | 128 | FileDescription=MapaCacic - Módulo Avulso para Coleta de Informações Patrimoniais para o Sistema CACIC |
129 | -FileVersion=1.0.0.0 | |
129 | +FileVersion=1.0.0.1 | |
130 | 130 | InternalName= |
131 | 131 | LegalCopyright= |
132 | 132 | LegalTrademarks= | ... | ... |
mapa/mapacacic.res
No preview for this file type
testacrypt/main_testacrypt.dcu
No preview for this file type