Commit d9b4cfea00ec0a54c32ed2c7fd6b03ca9e35ae14
1 parent
f4f92d02
Exists in
master
Excluído arquivos desnecessários
git-svn-id: http://svn.softwarepublico.gov.br/svn/cacic/cacic/trunk/agente-windows@1273 fecfc0c7-e812-0410-ae72-849f08638ee7
Showing
2 changed files
with
0 additions
and
417 deletions
Show diff stats
srcacic/WinVNC/WinVNC/CACIC_Crypt.cpp.bak
@@ -1,66 +0,0 @@ | @@ -1,66 +0,0 @@ | ||
1 | -/** | ||
2 | - * Copyright (C) 2009 DATAPREV-ES | ||
3 | - * @author Vinicius Avellar Moreira | ||
4 | - * Classe para criptografia de dados. | ||
5 | - */ | ||
6 | - | ||
7 | -#include "CACIC_Crypt.h" | ||
8 | - | ||
9 | -#include "CACIC_Utils.h" | ||
10 | - | ||
11 | -#include <math.h> | ||
12 | - | ||
13 | -#include "Rijndael.h" | ||
14 | -#include "base64.h" | ||
15 | - | ||
16 | -const unsigned int CACIC_Crypt::SRCACIC_BLOCK_SIZE = 16; | ||
17 | -const unsigned int CACIC_Crypt::SRCACIC_KEY_SIZE = 16; | ||
18 | -const char CACIC_Crypt::SRCACIC_KEY[17] = "CacicBrasil"; | ||
19 | -const char CACIC_Crypt::SRCACIC_IV[17] = "abcdefghijklmnop"; | ||
20 | - | ||
21 | -string CACIC_Crypt::decodifica(const char* entrada) | ||
22 | -{ | ||
23 | - string decode_base64; | ||
24 | - string entradaStr = string(entrada); | ||
25 | - | ||
26 | - CACIC_Utils::simpleUrlDecode(entradaStr); | ||
27 | - | ||
28 | - decode_base64 = base64_decode(entradaStr); | ||
29 | - | ||
30 | - const unsigned int saidaLen = decode_base64.length(); | ||
31 | - | ||
32 | - const unsigned int buffLen = saidaLen + 1; | ||
33 | - char* saidaBuff = new char[buffLen]; | ||
34 | - memset(saidaBuff, 0, buffLen); | ||
35 | - | ||
36 | - CRijndael oRijndael; | ||
37 | - oRijndael.MakeKey(SRCACIC_KEY, SRCACIC_IV, SRCACIC_KEY_SIZE, SRCACIC_BLOCK_SIZE); | ||
38 | - oRijndael.Decrypt(decode_base64.c_str(), saidaBuff, saidaLen, CRijndael::CBC); | ||
39 | - | ||
40 | - string saida = string(saidaBuff); | ||
41 | - delete []saidaBuff; | ||
42 | - return saida; | ||
43 | -} | ||
44 | - | ||
45 | -string CACIC_Crypt::codifica(const char* entrada) | ||
46 | -{ | ||
47 | - const unsigned int entradaLen = strlen(entrada); | ||
48 | - const unsigned int saidaLen = (int)ceil((float)(entradaLen)/SRCACIC_BLOCK_SIZE)*SRCACIC_BLOCK_SIZE; | ||
49 | - | ||
50 | - const unsigned int buffLen = saidaLen + 1; | ||
51 | - char* saidaBuff = new char[buffLen]; | ||
52 | - memset(saidaBuff, 0, buffLen); | ||
53 | - char* zerofEntrada = new char[buffLen]; | ||
54 | - memset(zerofEntrada, 0, buffLen); | ||
55 | - | ||
56 | - strncpy(zerofEntrada, entrada, entradaLen); | ||
57 | - | ||
58 | - CRijndael oRijndael; | ||
59 | - oRijndael.MakeKey(SRCACIC_KEY, SRCACIC_IV, SRCACIC_KEY_SIZE, SRCACIC_BLOCK_SIZE); | ||
60 | - oRijndael.Encrypt(zerofEntrada, saidaBuff, saidaLen, CRijndael::CBC); | ||
61 | - | ||
62 | - string saida = base64_encode(reinterpret_cast<const unsigned char*>(saidaBuff), saidaLen); | ||
63 | - delete []saidaBuff; | ||
64 | - delete []zerofEntrada; | ||
65 | - return saida; | ||
66 | -} |
srcacic/WinVNC/WinVNC/vnclog.cpp.bak
@@ -1,351 +0,0 @@ | @@ -1,351 +0,0 @@ | ||
1 | -// Copyright (C) 2002 RealVNC Ltd. All Rights Reserved. | ||
2 | -// | ||
3 | -// This program is free software; you can redistribute it and/or modify | ||
4 | -// it under the terms of the GNU General Public License as published by | ||
5 | -// the Free Software Foundation; either version 2 of the License, or | ||
6 | -// (at your option) any later version. | ||
7 | -// | ||
8 | -// This program is distributed in the hope that it will be useful, | ||
9 | -// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | -// GNU General Public License for more details. | ||
12 | -// | ||
13 | -// You should have received a copy of the GNU General Public License | ||
14 | -// along with this program; if not, write to the Free Software | ||
15 | -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | ||
16 | -// USA. | ||
17 | -// | ||
18 | -// If the source code for the program is not available from the place from | ||
19 | -// which you received this file, check http://www.realvnc.com/ or contact | ||
20 | -// the authors on info@realvnc.com for information on obtaining it. | ||
21 | - | ||
22 | -// Log.cpp: implementation of the VNCLog class. | ||
23 | -// | ||
24 | -////////////////////////////////////////////////////////////////////// | ||
25 | - | ||
26 | -#include "stdhdrs.h" | ||
27 | -#include <io.h> | ||
28 | -#include "VNCLog.h" | ||
29 | - | ||
30 | -#include "CACIC_Con.h" | ||
31 | -#include "CACIC_Auth.h" | ||
32 | - | ||
33 | -////////////////////////////////////////////////////////////////////// | ||
34 | -// Construction/Destruction | ||
35 | -////////////////////////////////////////////////////////////////////// | ||
36 | - | ||
37 | -const int VNCLog::ToDebug = 1; | ||
38 | -const int VNCLog::ToFile = 2; | ||
39 | -const int VNCLog::ToConsole = 4; | ||
40 | -// modo de envio para o script que tratara o log | ||
41 | -// o enviando para o banco de dados | ||
42 | -const int VNCLog::ToScript = 8; | ||
43 | - | ||
44 | -static const int LINE_BUFFER_SIZE = 1024; | ||
45 | - | ||
46 | -VNCLog::VNCLog() | ||
47 | - : m_tofile(false) | ||
48 | - , m_todebug(false) | ||
49 | - , m_toconsole(false) | ||
50 | - , m_toscript(false) // ADICIONADO | ||
51 | - , m_mode(0) | ||
52 | - , m_level(0) | ||
53 | - , hlogfile(NULL) | ||
54 | - , m_filename(NULL) | ||
55 | - , m_append(false) | ||
56 | - , m_lastLogTime(0) | ||
57 | -{ | ||
58 | -} | ||
59 | - | ||
60 | -void VNCLog::SetMode(int mode) | ||
61 | -{ | ||
62 | - m_mode = mode; | ||
63 | - | ||
64 | - // ---> modo de log adicionado | ||
65 | - if (mode & ToScript) { | ||
66 | - m_toscript = true; | ||
67 | - } else { | ||
68 | - m_toscript = false; | ||
69 | - } | ||
70 | - | ||
71 | - if (mode & ToDebug) | ||
72 | - m_todebug = true; | ||
73 | - else | ||
74 | - m_todebug = false; | ||
75 | - | ||
76 | - if (mode & ToFile) { | ||
77 | - if (!m_tofile) | ||
78 | - OpenFile(); | ||
79 | - } else { | ||
80 | - CloseFile(); | ||
81 | - m_tofile = false; | ||
82 | - } | ||
83 | - | ||
84 | - if (mode & ToConsole) { | ||
85 | - if (!m_toconsole) { | ||
86 | - AllocConsole(); //lint !e534 | ||
87 | - fclose(stdout); | ||
88 | - fclose(stderr); | ||
89 | -#ifdef _MSC_VER | ||
90 | - int fh = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), 0); | ||
91 | - _dup2(fh, 1); | ||
92 | - _dup2(fh, 2); | ||
93 | - _fdopen(1, "wt"); | ||
94 | - _fdopen(2, "wt"); | ||
95 | - printf("fh is %d\n",fh); | ||
96 | - fflush(stdout); | ||
97 | -#endif | ||
98 | - } | ||
99 | - | ||
100 | - m_toconsole = true; | ||
101 | - | ||
102 | - } else { | ||
103 | - m_toconsole = false; | ||
104 | - } | ||
105 | -} | ||
106 | - | ||
107 | - | ||
108 | -void VNCLog::SetLevel(int level) { | ||
109 | - m_level = level; | ||
110 | -} | ||
111 | - | ||
112 | -void VNCLog::SetFile(const char* filename, bool append) | ||
113 | -{ | ||
114 | - //SetMode(2); | ||
115 | - //SetLevel(10); | ||
116 | - if (m_filename != NULL) | ||
117 | - free(m_filename); | ||
118 | - m_filename = _strdup(filename); | ||
119 | - m_append = append; | ||
120 | - if (m_tofile) | ||
121 | - OpenFile(); | ||
122 | -} | ||
123 | - | ||
124 | -void VNCLog::OpenFile() | ||
125 | -{ | ||
126 | - // Is there a file-name? | ||
127 | - if (m_filename == NULL) | ||
128 | - { | ||
129 | - m_todebug = true; | ||
130 | - m_tofile = false; | ||
131 | - Print(0, "Error opening log file\n"); | ||
132 | - return; | ||
133 | - } | ||
134 | - | ||
135 | - m_tofile = true; | ||
136 | - | ||
137 | - // If there's an existing log and we're not appending then move it | ||
138 | - if (!m_append) | ||
139 | - { | ||
140 | - // Build the backup filename | ||
141 | - char *backupfilename = new char[strlen(m_filename)+5]; | ||
142 | - if (backupfilename) | ||
143 | - { | ||
144 | - strcpy(backupfilename, m_filename); | ||
145 | - strcat(backupfilename, ".bak"); | ||
146 | - // Attempt the move and replace any existing backup | ||
147 | - // Note that failure is silent - where would we log a message to? ;) | ||
148 | - MoveFileEx(m_filename, backupfilename, MOVEFILE_REPLACE_EXISTING); | ||
149 | - delete [] backupfilename; | ||
150 | - } | ||
151 | - } | ||
152 | - | ||
153 | - CloseFile(); | ||
154 | - | ||
155 | - // If filename is NULL or invalid we should throw an exception here | ||
156 | - hlogfile = CreateFile( | ||
157 | - m_filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, | ||
158 | - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); | ||
159 | - | ||
160 | - if (hlogfile == INVALID_HANDLE_VALUE) { | ||
161 | - // We should throw an exception here | ||
162 | - m_todebug = true; | ||
163 | - m_tofile = false; | ||
164 | - Print(0, "Error opening log file %s\n", m_filename); | ||
165 | - } | ||
166 | - if (m_append) { | ||
167 | - SetFilePointer( hlogfile, 0, NULL, FILE_END ); | ||
168 | - } else { | ||
169 | - SetEndOfFile( hlogfile ); | ||
170 | - } | ||
171 | -} | ||
172 | - | ||
173 | -// if a log file is open, close it now. | ||
174 | -void VNCLog::CloseFile() { | ||
175 | - if (hlogfile != NULL) { | ||
176 | - CloseHandle(hlogfile); | ||
177 | - hlogfile = NULL; | ||
178 | - } | ||
179 | -} | ||
180 | - | ||
181 | -inline void VNCLog::ReallyPrintLine(const char* line) | ||
182 | -{ | ||
183 | - // pega a data e hora local | ||
184 | - time_t now = time(0); | ||
185 | - struct tm ts; | ||
186 | - char data_buf[20]; | ||
187 | - | ||
188 | - ts = *localtime(&now); | ||
189 | - strftime(data_buf, sizeof(data_buf), "%d/%m %X", &ts); | ||
190 | - | ||
191 | - if (m_toscript) enviaLog(data_buf, (char*)line, SCRIPT); // ADICIONADO | ||
192 | - if (m_todebug) OutputDebugString(line); | ||
193 | - if (m_toconsole) { | ||
194 | - DWORD byteswritten; | ||
195 | - WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), line, strlen(line), &byteswritten, NULL); | ||
196 | - }; | ||
197 | - if (m_tofile && (hlogfile != NULL)) { | ||
198 | - string strLine; | ||
199 | - strLine.append(data_buf); | ||
200 | - strLine.append(" : "); | ||
201 | - strLine.append("[Suporte Remoto]"); | ||
202 | - | ||
203 | - //if (/*Verificar modo DEBUG!*/){ | ||
204 | - // strLine.append(" ("); | ||
205 | - // strLine.append(/*Funcao de retorno da Versao: v.2.6.0.0*/); | ||
206 | - // strLine.append(")"); | ||
207 | - // strLine.append(" DEBUG -"); | ||
208 | - //} | ||
209 | - | ||
210 | - if (IsDebugModeON()) { | ||
211 | - strLine.append(" (v."); | ||
212 | - strLine.append(SRVersion()); | ||
213 | - strLine.append(")"); | ||
214 | - strLine.append(" DEBUG -"); | ||
215 | - } | ||
216 | - | ||
217 | - strLine.append(" "); | ||
218 | - strLine.append(line); | ||
219 | - DWORD byteswritten; | ||
220 | - WriteFile(hlogfile, strLine.c_str(), strLine.length(), &byteswritten, NULL); | ||
221 | - } | ||
222 | -} | ||
223 | - | ||
224 | -void VNCLog::ReallyPrint(const char* format, va_list ap) | ||
225 | -{ | ||
226 | - //time_t current = time(0); | ||
227 | - //if (current != m_lastLogTime) { | ||
228 | - // m_lastLogTime = current; | ||
229 | - // ReallyPrintLine(ctime(&m_lastLogTime)); | ||
230 | - //} | ||
231 | - | ||
232 | - // - Write the log message, safely, limiting the output buffer size | ||
233 | - TCHAR line[(LINE_BUFFER_SIZE * 2) + 1]; // sf@2006 - Prevents buffer overflow | ||
234 | - TCHAR szErrorMsg[LINE_BUFFER_SIZE]; | ||
235 | - DWORD dwErrorCode = GetLastError(); | ||
236 | - _vsnprintf(line, LINE_BUFFER_SIZE, format, ap); | ||
237 | - SetLastError(0); | ||
238 | - if (dwErrorCode != 0) { | ||
239 | - FormatMessage( | ||
240 | - FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwErrorCode, | ||
241 | - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(char *)&szErrorMsg, | ||
242 | - LINE_BUFFER_SIZE, NULL); | ||
243 | - strcat(line," --"); | ||
244 | - strcat(line,szErrorMsg); | ||
245 | - } | ||
246 | - else strcat(line,"\r\n"); | ||
247 | - ReallyPrintLine(line); | ||
248 | -} | ||
249 | - | ||
250 | - | ||
251 | -VNCLog::~VNCLog() | ||
252 | -{ | ||
253 | - if (m_filename != NULL) | ||
254 | - free(m_filename); | ||
255 | - try | ||
256 | - { | ||
257 | - CloseFile(); | ||
258 | - } | ||
259 | - catch(...) | ||
260 | - { | ||
261 | - } | ||
262 | -} | ||
263 | - | ||
264 | -bool VNCLog::IsDebugModeON(){ | ||
265 | -// LPCTSTR diretorio_debugs; | ||
266 | - | ||
267 | -/** Trecho especifico para teste com o Path fixo do Cacic. | ||
268 | - string caminho = "C:\\Cacic\\Temp\\debugs"; | ||
269 | - diretorio_debugs = caminho.c_str(); | ||
270 | -*/ | ||
271 | - | ||
272 | -// LPTSTR diretorio_corrente; | ||
273 | -// string diretorio; | ||
274 | -// string diretorio = "Temp\\debugs"; | ||
275 | -// SetCurrentDirectory(".."); | ||
276 | -// GetCurrentDirectory(MAX_PATH,diretorio_corrente); | ||
277 | -// diretorio.append(diretorio_corrente); | ||
278 | -// diretorio.replace(diretorio.begin(),diretorio.end(),'\',"\\"); | ||
279 | -// diretorio.append ("Temp\\debugs"); | ||
280 | -/* | ||
281 | - diretorio_corrente = (LPTSTR)diretorio.c_str(); | ||
282 | - MessageBox (NULL,diretorio_corrente,"Warning! Nussa!!! o.O", MB_OKCANCEL| MB_ICONASTERISK); | ||
283 | -*/ | ||
284 | -// diretorio_debugs = diretorio.c_str(); | ||
285 | - | ||
286 | - HANDLE hDir = CreateFile("Temp\\debugs", | ||
287 | - GENERIC_ALL, | ||
288 | - FILE_SHARE_READ, | ||
289 | - NULL, | ||
290 | - OPEN_EXISTING, | ||
291 | - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, | ||
292 | - NULL); | ||
293 | - if (hDir == INVALID_HANDLE_VALUE){ | ||
294 | - CloseHandle(hDir); | ||
295 | - return false; | ||
296 | - } | ||
297 | - | ||
298 | - FILETIME dirCreationTime; | ||
299 | - SYSTEMTIME dirCreationTimeSystem, currentSystemTime; | ||
300 | - | ||
301 | - if (GetFileTime(hDir, &dirCreationTime, NULL, NULL)) { | ||
302 | - FileTimeToSystemTime (&dirCreationTime,&dirCreationTimeSystem); | ||
303 | - GetSystemTime(¤tSystemTime); | ||
304 | - CloseHandle(hDir); | ||
305 | - if (CACIC_Utils::DateCompare (currentSystemTime,dirCreationTimeSystem) == 0){ | ||
306 | - return true; | ||
307 | - } | ||
308 | - else { | ||
309 | - return false; | ||
310 | - } | ||
311 | - } | ||
312 | - CloseHandle(hDir); | ||
313 | - return false; | ||
314 | -} | ||
315 | - | ||
316 | -void VNCLog::GetLastErrorMsg(LPSTR szErrorMsg) const { | ||
317 | - | ||
318 | - DWORD dwErrorCode = GetLastError(); | ||
319 | - | ||
320 | - // Format the error message. | ||
321 | - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | ||
322 | - | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwErrorCode, | ||
323 | - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &szErrorMsg, | ||
324 | - 0, NULL); | ||
325 | -} | ||
326 | - | ||
327 | -// Envia o log passado para o servidor. | ||
328 | -void VNCLog::enviaLog(char data[], char log[], char script[]) | ||
329 | -{ | ||
330 | - string servidor = CACIC_Auth::getInstance()->getServidorWeb(); | ||
331 | - if (servidor.empty()) return; | ||
332 | - | ||
333 | - string post = CACIC_Auth::getInstance()->getPostComum(); | ||
334 | - post = "te_data_log="; | ||
335 | - post += data; | ||
336 | - post += "&te_log="; | ||
337 | - post += log; | ||
338 | - | ||
339 | - CACIC_Con m_con; | ||
340 | - m_con.setServer(servidor.c_str()); | ||
341 | - try | ||
342 | - { | ||
343 | - m_con.conecta(); | ||
344 | - m_con.sendRequest(HTTP_POST, script, (char*)post.data()); | ||
345 | - } | ||
346 | - catch(SRCException ex) | ||
347 | - { | ||
348 | - MessageBox(NULL, ex.getMessage().c_str(), "Erro!", MB_OK | MB_ICONERROR); | ||
349 | - return; | ||
350 | - } | ||
351 | -} |