fixed build error; fixed compilation warnings
[public/netxms.git] / src / server / include / nms_core.h
CommitLineData
88f2990c 1/*
5039dede 2** NetXMS - Network Management System
7806c906 3** Copyright (C) 2003-2014 Victor Kirhenshtein
5039dede
AK
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: nms_core.h
20**
21**/
22
23#ifndef _nms_core_h_
24#define _nms_core_h_
25
26#ifdef _WIN32
27#ifdef NXCORE_EXPORTS
28#define NXCORE_EXPORTABLE __declspec(dllexport)
29#else
30#define NXCORE_EXPORTABLE __declspec(dllimport)
31#endif
32#else /* _WIN32 */
33#define NXCORE_EXPORTABLE
34#endif
35
36#define LIBNXCL_NO_DECLARATIONS 1
37
38#include <nms_common.h>
39
40#ifndef _WIN32
41
42#if HAVE_SYS_TYPES_H
43# include <sys/types.h>
44#endif
45
46#if HAVE_DLFCN_H
47#include <dlfcn.h>
48#endif
49
d9177dd1 50
5039dede
AK
51#define WSAGetLastError() (errno)
52
53#endif /* _WIN32 */
54
55#include <time.h>
56#include <stdio.h>
57#include <string.h>
58#include <stdarg.h>
59
958a9397
VK
60#ifdef _WITH_ENCRYPTION
61#include <openssl/ssl.h>
62#endif
63
5039dede
AK
64//
65// Common includes
66//
67
68#include <nms_util.h>
69#include <dbdrv.h>
70#include <nms_cscp.h>
71#include <uuid.h>
72#include <nxsrvapi.h>
5039dede
AK
73#include <nxqueue.h>
74#include <nxsnmp.h>
75#include <nxmodule.h>
76#include <nxsl.h>
9d88cdc9 77#include <nxdbapi.h>
9796ce45 78#include <nddrv.h>
d41edbd3 79#include <nxcore_smclp.h>
5039dede 80
46ee6286
VK
81/**
82 * Console context
83 */
5039dede
AK
84struct __console_ctx
85{
86 SOCKET hSocket;
d3a7cf4c 87 MUTEX socketMutex;
5039dede 88 CSCPMessage *pMsg;
200d662d 89 ClientSession *session;
244c65ef 90 String *output;
5039dede
AK
91};
92
93typedef __console_ctx * CONSOLE_CTX;
94
2bac37f9
VK
95/**
96 * Server includes
97 */
7806c906 98#include "server_timers.h"
5039dede
AK
99#include "nms_dcoll.h"
100#include "nms_users.h"
46ee6286 101#include "nxcore_winperf.h"
5039dede 102#include "nms_objects.h"
5039dede
AK
103#include "nms_locks.h"
104#include "nms_pkg.h"
105#include "nms_topo.h"
106#include "nms_script.h"
5039dede 107#include "nxcore_situations.h"
ab621f39 108#include "nxcore_jobs.h"
e05b1945 109#include "nxcore_logs.h"
5039dede 110
2bac37f9
VK
111/**
112 * Common constants and macros
113 */
73869331 114#define MAX_LINE_SIZE 4096
967893bb 115#define GROUP_FLAG_BIT ((UINT32)0x80000000)
73869331
VK
116#define CHECKPOINT_SNMP_PORT 260
117#define DEFAULT_AFFINITY_MASK 0xFFFFFFFF
5039dede 118
2a964810
VK
119#define MAX_CLIENT_SESSIONS 128
120#define MAX_DEVICE_SESSIONS 256
121
5039dede
AK
122typedef void * HSNMPSESSION;
123
0f506caa
VK
124/**
125 * Prefixes for poller messages
126 */
df8a4ca2
VK
127#define POLLER_ERROR _T("\x7F") _T("e")
128#define POLLER_WARNING _T("\x7Fw")
129#define POLLER_INFO _T("\x7Fi")
130
0f506caa
VK
131/**
132 * Unique identifier group codes
133 */
5039dede
AK
134#define IDG_NETWORK_OBJECT 0
135#define IDG_CONTAINER_CAT 1
136#define IDG_EVENT 2
137#define IDG_ITEM 3
138#define IDG_SNMP_TRAP 4
24dc5346 139#define IDG_JOB 5
5039dede
AK
140#define IDG_ACTION 6
141#define IDG_EVENT_GROUP 7
142#define IDG_THRESHOLD 8
143#define IDG_USER 9
144#define IDG_USER_GROUP 10
145#define IDG_ALARM 11
146#define IDG_ALARM_NOTE 12
147#define IDG_PACKAGE 13
636e0c72 148#define IDG_SLM_TICKET 14
5039dede
AK
149#define IDG_OBJECT_TOOL 15
150#define IDG_SCRIPT 16
151#define IDG_AGENT_CONFIG 17
152#define IDG_GRAPH 18
153#define IDG_CERTIFICATE 19
154#define IDG_SITUATION 20
ba89fed2 155#define IDG_DCT_COLUMN 21
0f506caa 156#define IDG_MAPPING_TABLE 22
b4c2a628 157#define IDG_DCI_SUMMARY_TABLE 23
5039dede 158
0f506caa
VK
159/**
160 * Exit codes for console commands
161 */
5039dede
AK
162#define CMD_EXIT_CONTINUE 0
163#define CMD_EXIT_CLOSE_SESSION 1
164#define CMD_EXIT_SHUTDOWN 2
165
0f506caa
VK
166/**
167 * Network discovery mode
168 */
5039dede
AK
169#define DISCOVERY_DISABLED 0
170#define DISCOVERY_PASSIVE_ONLY 1
171#define DISCOVERY_ACTIVE 2
172
0f506caa
VK
173/**
174 * Client session flags
175 */
850ce3ed
VK
176#define CSF_EPP_LOCKED ((UINT32)0x00000002)
177#define CSF_PACKAGE_DB_LOCKED ((UINT32)0x00000004)
178#define CSF_USER_DB_LOCKED ((UINT32)0x00000008)
179#define CSF_EPP_UPLOAD ((UINT32)0x00000010)
180#define CSF_CONSOLE_OPEN ((UINT32)0x00000020)
181#define CSF_AUTHENTICATED ((UINT32)0x00000080)
182#define CSF_RECEIVING_MAP_DATA ((UINT32)0x00000200)
183#define CSF_SYNC_OBJECT_COMMENTS ((UINT32)0x00000400)
678fe569
VK
184#define CSF_CUSTOM_LOCK_1 ((UINT32)0x01000000)
185#define CSF_CUSTOM_LOCK_2 ((UINT32)0x02000000)
186#define CSF_CUSTOM_LOCK_3 ((UINT32)0x04000000)
187#define CSF_CUSTOM_LOCK_4 ((UINT32)0x08000000)
188#define CSF_CUSTOM_LOCK_5 ((UINT32)0x10000000)
189#define CSF_CUSTOM_LOCK_6 ((UINT32)0x20000000)
190#define CSF_CUSTOM_LOCK_7 ((UINT32)0x40000000)
191#define CSF_CUSTOM_LOCK_8 ((UINT32)0x80000000)
5039dede 192
0f506caa
VK
193/**
194 * Client session states
195 */
5039dede
AK
196#define SESSION_STATE_INIT 0
197#define SESSION_STATE_IDLE 1
198#define SESSION_STATE_PROCESSING 2
199
0f506caa
VK
200/**
201 * Information categories for UPDATE_INFO structure
202 */
5039dede
AK
203#define INFO_CAT_EVENT 1
204#define INFO_CAT_OBJECT_CHANGE 2
205#define INFO_CAT_ALARM 3
206#define INFO_CAT_ACTION 4
207#define INFO_CAT_SYSLOG_MSG 5
208#define INFO_CAT_SNMP_TRAP 6
209#define INFO_CAT_AUDIT_RECORD 7
210#define INFO_CAT_SITUATION 8
624f1165 211#define INFO_CAT_LIBRARY_IMAGE 9
5039dede 212
0f506caa
VK
213/**
214 * Certificate types
215 */
5039dede
AK
216#define CERT_TYPE_TRUSTED_CA 0
217#define CERT_TYPE_USER 1
218
0f506caa
VK
219/**
220 * Audit subsystems
221 */
5039dede
AK
222#define AUDIT_SECURITY _T("SECURITY")
223#define AUDIT_OBJECTS _T("OBJECTS")
224#define AUDIT_SYSCFG _T("SYSCFG")
225#define AUDIT_CONSOLE _T("CONSOLE")
226
2a964810
VK
227#define AUDIT_SYSTEM_SID (-1)
228
0f506caa
VK
229/**
230 * Event handling subsystem definitions
231 */
5039dede
AK
232#include "nms_events.h"
233#include "nms_actions.h"
234#include "nms_alarm.h"
235
0f506caa
VK
236/**
237 * New node information
238 */
5039dede
AK
239typedef struct
240{
967893bb
VK
241 UINT32 dwIpAddr;
242 UINT32 dwNetMask;
243 UINT32 zoneId;
5039dede 244 BOOL ignoreFilter;
baa5324c 245 BYTE bMacAddr[MAC_ADDR_LENGTH];
5039dede
AK
246} NEW_NODE;
247
0f506caa
VK
248/**
249 * New node flags
250 */
5039dede
AK
251#define NNF_IS_SNMP 0x0001
252#define NNF_IS_AGENT 0x0002
253#define NNF_IS_ROUTER 0x0004
254#define NNF_IS_BRIDGE 0x0008
255#define NNF_IS_PRINTER 0x0010
256#define NNF_IS_CDP 0x0020
257#define NNF_IS_SONMP 0x0040
258#define NNF_IS_LLDP 0x0080
259
0f506caa
VK
260/**
261 * Node information for autodiscovery filter
262 */
5039dede
AK
263typedef struct
264{
967893bb
VK
265 UINT32 dwIpAddr;
266 UINT32 dwNetMask;
267 UINT32 dwSubnetAddr;
268 UINT32 dwFlags;
5039dede 269 int nSNMPVersion;
35f836fe
VK
270 TCHAR szObjectId[MAX_OID_LEN * 4]; // SNMP OID
271 TCHAR szAgentVersion[MAX_AGENT_VERSION_LEN];
272 TCHAR szPlatform[MAX_PLATFORM_NAME_LEN];
5039dede
AK
273} DISCOVERY_FILTER_DATA;
274
0f506caa
VK
275/**
276 * Data update structure for client sessions
277 */
5039dede
AK
278typedef struct
279{
967893bb
VK
280 UINT32 dwCategory; // Data category - event, network object, etc.
281 UINT32 dwCode; // Data-specific update code
5039dede
AK
282 void *pData; // Pointer to data block
283} UPDATE_INFO;
284
534e1b83
VK
285/**
286 * Extended agent connection
287 */
5039dede
AK
288class AgentConnectionEx : public AgentConnection
289{
290protected:
967893bb 291 UINT32 m_nodeId;
d1c1c522 292
af21affe 293 virtual void printMsg(const TCHAR *format, ...);
f480bdd4
VK
294 virtual void onTrap(CSCPMessage *msg);
295 virtual void onDataPush(CSCPMessage *msg);
9fa031cd 296 virtual void onFileMonitoringData(CSCPMessage *msg);
489b117b 297 virtual void onSnmpTrap(CSCPMessage *pMsg);
5039dede
AK
298
299public:
69c6604d
VK
300 AgentConnectionEx(UINT32 nodeId, UINT32 ipAddr, WORD port = AGENT_LISTEN_PORT, int authMethod = AUTH_NONE, const TCHAR *secret = NULL) :
301 AgentConnection(ipAddr, port, authMethod, secret) { m_nodeId = nodeId; }
5039dede 302 virtual ~AgentConnectionEx();
45d84f8a 303
967893bb
VK
304 UINT32 deployPolicy(AgentPolicy *policy);
305 UINT32 uninstallPolicy(AgentPolicy *policy);
5039dede
AK
306};
307
534e1b83
VK
308/**
309 * Mobile device session
310 */
311class NXCORE_EXPORTABLE MobileDeviceSession
312{
313private:
314 SOCKET m_hSocket;
315 Queue *m_pSendQueue;
316 Queue *m_pMessageQueue;
2a964810
VK
317 int m_id;
318 int m_state;
534e1b83 319 WORD m_wCurrentCmd;
967893bb
VK
320 UINT32 m_dwUserId;
321 UINT32 m_deviceObjectId;
534e1b83
VK
322 CSCP_BUFFER *m_pMsgBuffer;
323 NXCPEncryptionContext *m_pCtx;
324 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
325 THREAD m_hWriteThread;
326 THREAD m_hProcessingThread;
327 MUTEX m_mutexSocketWrite;
328 struct sockaddr *m_clientAddr;
329 TCHAR m_szHostName[256]; // IP address of name of conneced host in textual form
330 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
331 TCHAR m_szClientInfo[96]; // Client app info string
967893bb
VK
332 UINT32 m_dwEncryptionRqId;
333 UINT32 m_dwEncryptionResult;
534e1b83 334 CONDITION m_condEncryptionSetup;
967893bb 335 UINT32 m_dwRefCount;
534e1b83
VK
336 bool m_isAuthenticated;
337
338 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
339 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
340 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
5039dede 341
534e1b83
VK
342 void readThread();
343 void writeThread();
344 void processingThread();
345
346 void setupEncryption(CSCPMessage *request);
967893bb 347 void respondToKeepalive(UINT32 dwRqId);
534e1b83 348 void debugPrintf(int level, const TCHAR *format, ...);
967893bb 349 void sendServerInfo(UINT32 dwRqId);
534e1b83
VK
350 void login(CSCPMessage *pRequest);
351 void updateDeviceInfo(CSCPMessage *pRequest);
352 void updateDeviceStatus(CSCPMessage *pRequest);
7777b139 353 void pushData(CSCPMessage *request);
534e1b83
VK
354
355public:
356 MobileDeviceSession(SOCKET hSocket, struct sockaddr *addr);
357 ~MobileDeviceSession();
358
534e1b83
VK
359 void run();
360
5c44534b 361 void postMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->createMessage()); }
534e1b83 362 void sendMessage(CSCPMessage *pMsg);
5039dede 363
2a964810
VK
364 int getId() { return m_id; }
365 void setId(int id) { if (m_id == -1) m_id = id; }
366 int getState() { return m_state; }
534e1b83
VK
367 const TCHAR *getUserName() { return m_szUserName; }
368 const TCHAR *getClientInfo() { return m_szClientInfo; }
369 const TCHAR *getHostName() { return m_szHostName; }
967893bb 370 UINT32 getUserId() { return m_dwUserId; }
534e1b83
VK
371 bool isAuthenticated() { return m_isAuthenticated; }
372 WORD getCurrentCmd() { return m_wCurrentCmd; }
373 int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
374};
375
376/**
377 * Client (user) session
378 */
5039dede
AK
379#define DECLARE_THREAD_STARTER(func) static THREAD_RESULT THREAD_CALL ThreadStarter_##func(void *);
380
a0e3917e 381class NXCORE_EXPORTABLE ClientSession
5039dede
AK
382{
383private:
384 SOCKET m_hSocket;
385 Queue *m_pSendQueue;
386 Queue *m_pMessageQueue;
387 Queue *m_pUpdateQueue;
2a964810
VK
388 int m_id;
389 int m_state;
5039dede 390 WORD m_wCurrentCmd;
967893bb 391 UINT32 m_dwUserId;
f4d8fe18 392 UINT64 m_dwSystemAccess; // User's system access rights
967893bb 393 UINT32 m_dwFlags; // Session flags
f8c6f10f 394 int m_clientType; // Client system type - desktop, web, mobile, etc.
5039dede 395 CSCP_BUFFER *m_pMsgBuffer;
98abc9f1 396 NXCPEncryptionContext *m_pCtx;
5039dede
AK
397 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
398 THREAD m_hWriteThread;
399 THREAD m_hProcessingThread;
400 THREAD m_hUpdateThread;
d3a7cf4c 401 MUTEX m_mutexSocketWrite;
5039dede
AK
402 MUTEX m_mutexSendEvents;
403 MUTEX m_mutexSendSyslog;
404 MUTEX m_mutexSendTrapLog;
405 MUTEX m_mutexSendObjects;
406 MUTEX m_mutexSendAlarms;
407 MUTEX m_mutexSendActions;
408 MUTEX m_mutexSendAuditLog;
409 MUTEX m_mutexSendSituations;
410 MUTEX m_mutexPollerInit;
60557d06 411 struct sockaddr *m_clientAddr;
91f6b72c
VK
412 TCHAR m_workstation[256]; // IP address or name of connected host in textual form
413 TCHAR m_webServerAddress[256]; // IP address or name of web server for web sessions
5039dede
AK
414 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
415 TCHAR m_szClientInfo[96]; // Client app info string
2a964810 416 TCHAR m_language[8]; // Client's desired language
a51628e2 417 time_t m_loginTime;
967893bb
VK
418 UINT32 m_dwOpenDCIListSize; // Number of open DCI lists
419 UINT32 *m_pOpenDCIList; // List of nodes with DCI lists open
420 UINT32 m_dwNumRecordsToUpload; // Number of records to be uploaded
421 UINT32 m_dwRecordsUploaded;
5039dede
AK
422 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
423 int m_hCurrFile;
967893bb
VK
424 UINT32 m_dwFileRqId;
425 UINT32 m_dwUploadCommand;
426 UINT32 m_dwUploadData;
e928a6db 427 uuid_t m_uploadImageGuid;
5039dede 428 TCHAR m_szCurrFileName[MAX_PATH];
967893bb
VK
429 UINT32 m_dwRefCount;
430 UINT32 m_dwEncryptionRqId;
431 UINT32 m_dwEncryptionResult;
5039dede 432 CONDITION m_condEncryptionSetup;
967893bb 433 UINT32 m_dwActiveChannels; // Active data channels
200d662d 434 CONSOLE_CTX m_console; // Server console context
810bd8c4 435 StringList m_musicTypeList;
7cf549ad 436 ObjectIndex m_agentConn;
5039dede 437
534e1b83
VK
438 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
439 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
440 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
441 static THREAD_RESULT THREAD_CALL updateThreadStarter(void *);
442 static THREAD_RESULT THREAD_CALL pollerThreadStarter(void *);
5039dede 443
92c51b1d
VK
444 DECLARE_THREAD_STARTER(getCollectedData)
445 DECLARE_THREAD_STARTER(getTableCollectedData)
446 DECLARE_THREAD_STARTER(clearDCIData)
adac28be
VK
447 DECLARE_THREAD_STARTER(queryParameter)
448 DECLARE_THREAD_STARTER(queryAgentTable)
84880c89 449 DECLARE_THREAD_STARTER(queryL2Topology)
b1e9b6b3
VK
450 DECLARE_THREAD_STARTER(sendEventLog)
451 DECLARE_THREAD_STARTER(sendSyslog)
1da08bc6
VK
452 DECLARE_THREAD_STARTER(createObject)
453 DECLARE_THREAD_STARTER(getServerFile)
6f16f12d 454 DECLARE_THREAD_STARTER(getAgentFile)
9fa031cd 455 DECLARE_THREAD_STARTER(cancelFileMonitoring)
e05b1945
VK
456 DECLARE_THREAD_STARTER(queryServerLog)
457 DECLARE_THREAD_STARTER(getServerLogQueryData)
e31c8e60 458 DECLARE_THREAD_STARTER(executeAction)
630e15d6 459 DECLARE_THREAD_STARTER(findNodeConnection)
06a93345 460 DECLARE_THREAD_STARTER(findMacAddress)
80e0db05 461 DECLARE_THREAD_STARTER(findIpAddress)
200d662d 462 DECLARE_THREAD_STARTER(processConsoleCommand)
b08d31f4 463 DECLARE_THREAD_STARTER(sendMib)
6d069676 464 DECLARE_THREAD_STARTER(getNetworkPath)
2bac37f9 465 DECLARE_THREAD_STARTER(getAlarmEvents)
3c35018e 466 DECLARE_THREAD_STARTER(openHelpdeskIssue)
d75003e1 467 DECLARE_THREAD_STARTER(forwardToReportingServer)
74d0b136 468 DECLARE_THREAD_STARTER(fileManagerControl)
7cf549ad 469 DECLARE_THREAD_STARTER(uploadUserFileToAgent)
c44cf458
VK
470 DECLARE_THREAD_STARTER(getSwitchForwardingDatabase)
471 DECLARE_THREAD_STARTER(getRoutingTable)
4899db4d 472 DECLARE_THREAD_STARTER(getLocationHistory)
529956a0 473 DECLARE_THREAD_STARTER(executeScript)
5039dede 474
62768df3
VK
475 void readThread();
476 void writeThread();
477 void processingThread();
478 void updateThread();
967893bb 479 void pollerThread(Node *pNode, int iPollType, UINT32 dwRqId);
5039dede 480
9e9d631e 481 void setupEncryption(CSCPMessage *request);
967893bb 482 void respondToKeepalive(UINT32 dwRqId);
e05b1945 483 void onFileUpload(BOOL bSuccess);
534e1b83 484 void debugPrintf(int level, const TCHAR *format, ...);
967893bb 485 void sendServerInfo(UINT32 dwRqId);
711e5e9a 486 void login(CSCPMessage *pRequest);
62768df3
VK
487 void sendAllObjects(CSCPMessage *pRequest);
488 void sendSelectedObjects(CSCPMessage *pRequest);
b1e9b6b3 489 void sendEventLog(CSCPMessage *pRequest);
967893bb 490 void sendAllConfigVars(UINT32 dwRqId);
b1e9b6b3
VK
491 void setConfigVariable(CSCPMessage *pRequest);
492 void deleteConfigVariable(CSCPMessage *pRequest);
967893bb
VK
493 void sendUserDB(UINT32 dwRqId);
494 void sendAllAlarms(UINT32 dwRqId);
b1e9b6b3
VK
495 void createUser(CSCPMessage *pRequest);
496 void updateUser(CSCPMessage *pRequest);
497 void deleteUser(CSCPMessage *pRequest);
498 void setPassword(CSCPMessage *pRequest);
967893bb
VK
499 void lockUserDB(UINT32 dwRqId, BOOL bLock);
500 void sendEventDB(UINT32 dwRqId);
8eb2d92b
VK
501 void modifyEventTemplate(CSCPMessage *pRequest);
502 void deleteEventTemplate(CSCPMessage *pRequest);
967893bb 503 void generateEventCode(UINT32 dwRqId);
92c51b1d 504 void modifyObject(CSCPMessage *pRequest);
1da08bc6 505 void changeObjectMgmtStatus(CSCPMessage *pRequest);
92c51b1d
VK
506 void openNodeDCIList(CSCPMessage *pRequest);
507 void closeNodeDCIList(CSCPMessage *pRequest);
508 void modifyNodeDCI(CSCPMessage *pRequest);
509 void copyDCI(CSCPMessage *pRequest);
510 void applyTemplate(CSCPMessage *pRequest);
511 void getCollectedData(CSCPMessage *pRequest);
512 void getTableCollectedData(CSCPMessage *pRequest);
6fd6de0a 513 bool getCollectedDataFromDB(CSCPMessage *request, CSCPMessage *response, DataCollectionTarget *object, int dciType);
92c51b1d
VK
514 void clearDCIData(CSCPMessage *pRequest);
515 void changeDCIStatus(CSCPMessage *pRequest);
b9a8e081 516 void getLastValues(CSCPMessage *pRequest);
2ab9314f 517 void getLastValuesByDciId(CSCPMessage *pRequest);
b9a8e081 518 void getTableLastValues(CSCPMessage *pRequest);
711e5e9a 519 void getThresholdSummary(CSCPMessage *request);
c9630390 520 void openEPP(CSCPMessage *request);
967893bb 521 void closeEPP(UINT32 dwRqId);
92c51b1d
VK
522 void saveEPP(CSCPMessage *pRequest);
523 void processEPPRecord(CSCPMessage *pRequest);
967893bb 524 void sendMIBTimestamp(UINT32 dwRqId);
b08d31f4 525 void sendMib(CSCPMessage *request);
b1e9b6b3
VK
526 void createObject(CSCPMessage *request);
527 void changeObjectBinding(CSCPMessage *request, BOOL bBind);
528 void deleteObject(CSCPMessage *request);
529 void getAlarm(CSCPMessage *request);
530 void getAlarmEvents(CSCPMessage *request);
531 void acknowledgeAlarm(CSCPMessage *request);
532 void resolveAlarm(CSCPMessage *request, bool terminate);
533 void deleteAlarm(CSCPMessage *request);
3c35018e 534 void openHelpdeskIssue(CSCPMessage *request);
6cedeb69 535 void getHelpdeskUrl(CSCPMessage *request);
1eb0b101 536 void unlinkHelpdeskIssue(CSCPMessage *request);
4644eee7
VK
537 void getAlarmComments(CSCPMessage *pRequest);
538 void updateAlarmComment(CSCPMessage *pRequest);
539 void deleteAlarmComment(CSCPMessage *request);
b81d7b7d 540 void updateAlarmStatusFlow(CSCPMessage *request);
1b94acbf
VK
541 void createAction(CSCPMessage *pRequest);
542 void updateAction(CSCPMessage *pRequest);
543 void deleteAction(CSCPMessage *pRequest);
967893bb
VK
544 void sendAllActions(UINT32 dwRqId);
545 void SendContainerCategories(UINT32 dwRqId);
92c51b1d 546 void forcedNodePoll(CSCPMessage *pRequest);
b1e9b6b3
VK
547 void onTrap(CSCPMessage *pRequest);
548 void onWakeUpNode(CSCPMessage *pRequest);
adac28be
VK
549 void queryParameter(CSCPMessage *pRequest);
550 void queryAgentTable(CSCPMessage *pRequest);
fdbee7f8 551 void editTrap(int iOperation, CSCPMessage *pRequest);
967893bb
VK
552 void LockTrapCfg(UINT32 dwRqId, BOOL bLock);
553 void sendAllTraps(UINT32 dwRqId);
554 void sendAllTraps2(UINT32 dwRqId);
555 void LockPackageDB(UINT32 dwRqId, BOOL bLock);
556 void SendAllPackages(UINT32 dwRqId);
5039dede
AK
557 void InstallPackage(CSCPMessage *pRequest);
558 void RemovePackage(CSCPMessage *pRequest);
559 void DeployPackage(CSCPMessage *pRequest);
074498ac 560 void getParametersList(CSCPMessage *pRequest);
fdbee7f8
VK
561 void getUserVariable(CSCPMessage *pRequest);
562 void setUserVariable(CSCPMessage *pRequest);
563 void copyUserVariable(CSCPMessage *pRequest);
564 void enumUserVariables(CSCPMessage *pRequest);
565 void deleteUserVariable(CSCPMessage *pRequest);
4c789f9e 566 void changeObjectZone(CSCPMessage *pRequest);
92c51b1d
VK
567 void getAgentConfig(CSCPMessage *pRequest);
568 void updateAgentConfig(CSCPMessage *pRequest);
e31c8e60 569 void executeAction(CSCPMessage *pRequest);
967893bb 570 void sendObjectTools(UINT32 dwRqId);
0e950f45
VK
571 void sendObjectToolDetails(CSCPMessage *pRequest);
572 void updateObjectTool(CSCPMessage *pRequest);
573 void deleteObjectTool(CSCPMessage *pRequest);
6f8e39e5 574 void changeObjectToolStatus(CSCPMessage *pRequest);
967893bb 575 void generateObjectToolId(UINT32 dwRqId);
0e950f45 576 void execTableTool(CSCPMessage *pRequest);
b1e9b6b3
VK
577 void changeSubscription(CSCPMessage *pRequest);
578 void sendSyslog(CSCPMessage *pRequest);
967893bb
VK
579 void sendServerStats(UINT32 dwRqId);
580 void sendScriptList(UINT32 dwRqId);
0c7aca90
VK
581 void sendScript(CSCPMessage *pRequest);
582 void updateScript(CSCPMessage *pRequest);
583 void renameScript(CSCPMessage *pRequest);
584 void deleteScript(CSCPMessage *pRequest);
967893bb 585 void SendSessionList(UINT32 dwRqId);
5039dede
AK
586 void KillSession(CSCPMessage *pRequest);
587 void SendTrapLog(CSCPMessage *pRequest);
588 void StartSnmpWalk(CSCPMessage *pRequest);
241c2740 589 void resolveDCINames(CSCPMessage *pRequest);
967893bb 590 UINT32 resolveDCIName(UINT32 dwNode, UINT32 dwItem, TCHAR **ppszName);
6b29839d 591 void sendConfigForAgent(CSCPMessage *pRequest);
967893bb 592 void sendAgentCfgList(UINT32 dwRqId);
5039dede
AK
593 void OpenAgentConfig(CSCPMessage *pRequest);
594 void SaveAgentConfig(CSCPMessage *pRequest);
595 void DeleteAgentConfig(CSCPMessage *pRequest);
596 void SwapAgentConfigs(CSCPMessage *pRequest);
597 void SendObjectComments(CSCPMessage *pRequest);
6fd6de0a
VK
598 void updateObjectComments(CSCPMessage *pRequest);
599 void pushDCIData(CSCPMessage *pRequest);
600 void getAddrList(CSCPMessage *pRequest);
601 void setAddrList(CSCPMessage *pRequest);
92c51b1d 602 void resetComponent(CSCPMessage *pRequest);
7a46028e 603 void sendDCIEventList(CSCPMessage *request);
5039dede 604 void SendDCIInfo(CSCPMessage *pRequest);
74526d25 605 void sendPerfTabDCIList(CSCPMessage *pRequest);
a7ff20a5
VK
606 void exportConfiguration(CSCPMessage *pRequest);
607 void importConfiguration(CSCPMessage *pRequest);
6f8e39e5
VK
608 void sendGraphList(UINT32 dwRqId);
609 void saveGraph(CSCPMessage *pRequest);
610 void deleteGraph(CSCPMessage *pRequest);
5039dede
AK
611 void AddCACertificate(CSCPMessage *pRequest);
612 void DeleteCertificate(CSCPMessage *pRequest);
613 void UpdateCertificateComments(CSCPMessage *pRequest);
967893bb 614 void getCertificateList(UINT32 dwRqId);
84880c89 615 void queryL2Topology(CSCPMessage *pRequest);
b1e9b6b3 616 void sendSMS(CSCPMessage *pRequest);
967893bb 617 void SendCommunityList(UINT32 dwRqId);
5039dede 618 void UpdateCommunityList(CSCPMessage *pRequest);
a882b714
VK
619 void getSituationList(UINT32 dwRqId);
620 void createSituation(CSCPMessage *pRequest);
621 void updateSituation(CSCPMessage *pRequest);
622 void deleteSituation(CSCPMessage *pRequest);
623 void deleteSituationInstance(CSCPMessage *pRequest);
1da08bc6
VK
624 void setConfigCLOB(CSCPMessage *pRequest);
625 void getConfigCLOB(CSCPMessage *pRequest);
1da08bc6
VK
626 void registerAgent(CSCPMessage *pRequest);
627 void getServerFile(CSCPMessage *pRequest);
9fa031cd 628 void cancelFileMonitoring(CSCPMessage *request);
6f16f12d 629 void getAgentFile(CSCPMessage *pRequest);
1da08bc6 630 void testDCITransformation(CSCPMessage *pRequest);
967893bb 631 void sendJobList(UINT32 dwRqId);
45d84f8a 632 void cancelJob(CSCPMessage *pRequest);
8d9f7450
VK
633 void holdJob(CSCPMessage *pRequest);
634 void unholdJob(CSCPMessage *pRequest);
93599cfd 635 void deployAgentPolicy(CSCPMessage *pRequest, bool uninstallFlag);
d83dc1f0
VK
636 void getUserCustomAttribute(CSCPMessage *request);
637 void setUserCustomAttribute(CSCPMessage *request);
e05b1945
VK
638 void openServerLog(CSCPMessage *request);
639 void closeServerLog(CSCPMessage *request);
640 void queryServerLog(CSCPMessage *request);
641 void getServerLogQueryData(CSCPMessage *request);
967893bb 642 void sendUsmCredentials(UINT32 dwRqId);
df8a4ca2 643 void updateUsmCredentials(CSCPMessage *pRequest);
071fd171 644 void sendDCIThresholds(CSCPMessage *request);
1da08bc6 645 void addClusterNode(CSCPMessage *request);
630e15d6 646 void findNodeConnection(CSCPMessage *request);
06a93345 647 void findMacAddress(CSCPMessage *request);
80e0db05 648 void findIpAddress(CSCPMessage *request);
e6b9439a
AK
649 void sendLibraryImage(CSCPMessage *request);
650 void updateLibraryImage(CSCPMessage *request);
651 void listLibraryImages(CSCPMessage *request);
652 void deleteLibraryImage(CSCPMessage *request);
f69c6203 653 void executeServerCommand(CSCPMessage *request);
619e5c9b 654 void uploadFileToAgent(CSCPMessage *request);
1a5e0c22 655 void listServerFileStore(CSCPMessage *request);
200d662d 656 void processConsoleCommand(CSCPMessage *msg);
967893bb
VK
657 void openConsole(UINT32 rqId);
658 void closeConsole(UINT32 rqId);
7f632dfe 659 void getVlans(CSCPMessage *msg);
68f898c9
VK
660 void receiveFile(CSCPMessage *request);
661 void deleteFile(CSCPMessage *request);
6d069676 662 void getNetworkPath(CSCPMessage *request);
8836184f 663 void getNodeComponents(CSCPMessage *request);
caa04e26 664 void getNodeSoftware(CSCPMessage *request);
46ee6286 665 void getWinPerfObjects(CSCPMessage *request);
fdbee7f8
VK
666 void listMappingTables(CSCPMessage *request);
667 void getMappingTable(CSCPMessage *request);
668 void updateMappingTable(CSCPMessage *request);
669 void deleteMappingTable(CSCPMessage *request);
d5de1d1d 670 void getWirelessStations(CSCPMessage *request);
967893bb 671 void getSummaryTables(UINT32 rqId);
b4c2a628
VK
672 void getSummaryTableDetails(CSCPMessage *request);
673 void modifySummaryTable(CSCPMessage *request);
674 void deleteSummaryTable(CSCPMessage *request);
675 void querySummaryTable(CSCPMessage *request);
5389f7b0 676 void queryAdHocSummaryTable(CSCPMessage *request);
d75003e1 677 void forwardToReportingServer(CSCPMessage *request);
ceb0fc8d 678 void getSubnetAddressMap(CSCPMessage *request);
d39de9a8 679 void getEffectiveRights(CSCPMessage *request);
74d0b136 680 void fileManagerControl(CSCPMessage *request);
7cf549ad 681 void uploadUserFileToAgent(CSCPMessage *request);
c44cf458
VK
682 void getSwitchForwardingDatabase(CSCPMessage *request);
683 void getRoutingTable(CSCPMessage *request);
4899db4d 684 void getLocationHistory(CSCPMessage *request);
d9e5a5be 685 void getScreenshot(CSCPMessage *request);
529956a0 686 void executeScript(CSCPMessage *request);
5039dede
AK
687
688public:
60557d06 689 ClientSession(SOCKET hSocket, struct sockaddr *addr);
5039dede
AK
690 ~ClientSession();
691
e05b1945
VK
692 void incRefCount() { m_dwRefCount++; }
693 void decRefCount() { if (m_dwRefCount > 0) m_dwRefCount--; }
694
695 void run();
696
5c44534b 697 void postMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->createMessage()); }
d3a7cf4c 698 void sendMessage(CSCPMessage *pMsg);
92c51b1d 699 void sendRawMessage(CSCP_MESSAGE *pMsg);
967893bb 700 void sendPollerMsg(UINT32 dwRqId, const TCHAR *pszMsg);
cc022855 701 BOOL sendFile(const TCHAR *file, UINT32 dwRqId, long offset);
e05b1945 702
2a964810
VK
703 int getId() { return m_id; }
704 void setId(int id) { if (m_id == -1) m_id = id; }
705 int getState() { return m_state; }
889d7ff7
VK
706 const TCHAR *getUserName() { return m_szUserName; }
707 const TCHAR *getClientInfo() { return m_szClientInfo; }
91f6b72c
VK
708 const TCHAR *getWorkstation() { return m_workstation; }
709 const TCHAR *getWebServerAddress() { return m_webServerAddress; }
967893bb 710 UINT32 getUserId() { return m_dwUserId; }
f4d8fe18 711 UINT64 getSystemRights() { return m_dwSystemAccess; }
87f56b19 712 UINT32 getFlags() { return m_dwFlags; }
f669df41
VK
713 bool isAuthenticated() { return (m_dwFlags & CSF_AUTHENTICATED) ? true : false; }
714 bool isConsoleOpen() { return (m_dwFlags & CSF_CONSOLE_OPEN) ? true : false; }
967893bb 715 bool isSubscribed(UINT32 dwChannel) { return (m_dwActiveChannels & dwChannel) ? true : false; }
f669df41 716 WORD getCurrentCmd() { return m_wCurrentCmd; }
98abc9f1 717 int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
f8c6f10f 718 int getClientType() { return m_clientType; }
a51628e2 719 time_t getLoginTime() { return m_loginTime; }
e05b1945 720
3fd05687 721 bool checkSysAccessRights(UINT64 requiredAccess)
88f2990c 722 {
723 return (m_dwUserId == 0) ? true :
badf9a95 724 ((requiredAccess & m_dwSystemAccess) == requiredAccess);
e05b1945
VK
725 }
726
87f56b19
VK
727 void setCustomLock(UINT32 bit, bool value)
728 {
729 if (value)
730 m_dwFlags |= (bit & 0xFF000000);
731 else
732 m_dwFlags &= ~(bit & 0xFF000000);
733 }
734
f669df41 735 void kill();
967893bb 736 void notify(UINT32 dwCode, UINT32 dwData = 0);
e05b1945
VK
737
738 void queueUpdate(UPDATE_INFO *pUpdate) { m_pUpdateQueue->Put(pUpdate); }
739 void onNewEvent(Event *pEvent);
e0f99bf0 740 void onSyslogMessage(NX_SYSLOG_RECORD *pRec);
e05b1945
VK
741 void onNewSNMPTrap(CSCPMessage *pMsg);
742 void onObjectChange(NetObj *pObject);
967893bb
VK
743 void onUserDBUpdate(int code, UINT32 id, UserDatabaseObject *user);
744 void onAlarmUpdate(UINT32 dwCode, NXC_ALARM *pAlarm);
745 void onActionDBUpdate(UINT32 dwCode, NXC_ACTION *pAction);
72f6ece2
AK
746 void onSituationChange(CSCPMessage *msg);
747 void onLibraryImageChange(uuid_t *guid, bool removed = false);
5039dede
AK
748};
749
2bac37f9
VK
750/**
751 * Delayed SQL request
752 */
7dad92fb
VK
753typedef struct
754{
755 TCHAR *query;
756 int bindCount;
757 BYTE *sqlTypes;
758 TCHAR *bindings[1]; /* actual size determined by bindCount field */
759} DELAYED_SQL_REQUEST;
760
2bac37f9
VK
761/**
762 * Delayed request for idata_ INSERT
763 */
f68d9eac
VK
764typedef struct
765{
766 time_t timestamp;
967893bb
VK
767 UINT32 nodeId;
768 UINT32 dciId;
f68d9eac
VK
769 TCHAR value[MAX_RESULT_LENGTH];
770} DELAYED_IDATA_INSERT;
771
76fcb995
VK
772/**
773 * Delayed request for raw_dci_values UPDATE
774 */
775typedef struct
776{
777 time_t timestamp;
778 UINT32 dciId;
779 TCHAR rawValue[MAX_RESULT_LENGTH];
780 TCHAR transformedValue[MAX_RESULT_LENGTH];
781} DELAYED_RAW_DATA_UPDATE;
782
7a4c94ee 783/**
784 * Graph ACL entry
785 */
786struct GRAPH_ACL_ENTRY
787{
788 UINT32 dwGraphId;
789 UINT32 dwUserId;
790 UINT32 dwAccess;
791};
792
793/**
794 * Information about graph with name existence and it's ID.
795 */
796struct GRAPH_ACL_AND_ID
797{
88f2990c 798 UINT32 graphId;
7a4c94ee 799 UINT32 status;
800};
801
2bac37f9
VK
802/**
803 * Functions
804 */
35959841 805bool NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
35f836fe 806#ifdef UNICODE
35959841 807bool NXCORE_EXPORTABLE ConfigReadStrA(const WCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
35f836fe
VK
808#else
809#define ConfigReadStrA ConfigReadStr
810#endif
43526096 811bool NXCORE_EXPORTABLE ConfigReadStrUTF8(const TCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
5039dede 812int NXCORE_EXPORTABLE ConfigReadInt(const TCHAR *szVar, int iDefault);
967893bb 813UINT32 NXCORE_EXPORTABLE ConfigReadULong(const TCHAR *szVar, UINT32 dwDefault);
35959841
VK
814bool NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray, int nSize, int nDefault);
815bool NXCORE_EXPORTABLE ConfigWriteStr(const TCHAR *szVar, const TCHAR *szValue, bool bCreate, bool isVisible = true, bool needRestart = false);
816bool NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, bool bCreate, bool isVisible = true, bool needRestart = false);
817bool NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, UINT32 dwValue, bool bCreate, bool isVisible = true, bool needRestart = false);
818bool NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray, int nSize, bool bCreate, bool isVisible = true, bool needRestart = false);
5039dede 819TCHAR NXCORE_EXPORTABLE *ConfigReadCLOB(const TCHAR *var, const TCHAR *defValue);
35959841
VK
820bool NXCORE_EXPORTABLE ConfigWriteCLOB(const TCHAR *var, const TCHAR *value, bool bCreate);
821bool NXCORE_EXPORTABLE ConfigDelete(const TCHAR *name);
5039dede 822
35959841 823bool NXCORE_EXPORTABLE MetaDataReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
40dedf5d 824INT32 NXCORE_EXPORTABLE MetaDataReadInt(const TCHAR *var, UINT32 defaultValue);
28f5b9a4 825
35959841 826bool NXCORE_EXPORTABLE LoadConfig();
5039dede 827
35f836fe
VK
828void NXCORE_EXPORTABLE Shutdown();
829void NXCORE_EXPORTABLE FastShutdown();
830BOOL NXCORE_EXPORTABLE Initialize();
5039dede 831THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *);
35f836fe
VK
832void NXCORE_EXPORTABLE ShutdownDB();
833void InitiateShutdown();
5039dede 834
400e55c4 835bool NXCORE_EXPORTABLE SleepAndCheckForShutdown(int iSeconds);
5039dede 836
6e383343
VK
837void ConsolePrintf(CONSOLE_CTX pCtx, const TCHAR *pszFormat, ...)
838#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
839 __attribute__ ((format(printf, 2, 3)))
840#endif
841;
35f836fe 842int ProcessConsoleCommand(const TCHAR *pszCmdLine, CONSOLE_CTX pCtx);
5039dede
AK
843
844void SaveObjects(DB_HANDLE hdb);
ff6d2c5d
VK
845void NXCORE_EXPORTABLE ObjectTransactionStart();
846void NXCORE_EXPORTABLE ObjectTransactionEnd();
5039dede 847
ce7565e7 848void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query);
7dad92fb 849void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query, int bindCount, int *sqlTypes, const TCHAR **values);
967893bb 850void QueueIDataInsert(time_t timestamp, UINT32 nodeId, UINT32 dciId, const TCHAR *value);
76fcb995 851void QueueRawDciDataUpdate(time_t timestamp, UINT32 dciId, const TCHAR *rawValue, const TCHAR *transformedValue);
ce7565e7
VK
852void StartDBWriter();
853void StopDBWriter();
5039dede 854
ea50bc33
VK
855void PerfDataStorageRequest(DCItem *dci, time_t timestamp, const TCHAR *value);
856void PerfDataStorageRequest(DCTable *dci, time_t timestamp, Table *value);
857
967893bb 858bool NXCORE_EXPORTABLE IsDatabaseRecordExist(DB_HANDLE hdb, const TCHAR *table, const TCHAR *idColumn, UINT32 id);
ba89fed2 859
967893bb 860void DecodeSQLStringAndSetVariable(CSCPMessage *pMsg, UINT32 dwVarId, TCHAR *pszStr);
5039dede 861
1f4c37ee 862SNMP_SecurityContext *SnmpCheckCommSettings(SNMP_Transport *pTransport, int *version, SNMP_SecurityContext *originalContext, StringList *customTestOids);
35f836fe 863void StrToMac(const TCHAR *pszStr, BYTE *pBuffer);
5039dede 864
f42b8099 865void InitLocalNetInfo();
5039dede 866
f42b8099 867ARP_CACHE *GetLocalArpCache();
967893bb 868ARP_CACHE *SnmpGetArpCache(UINT32 dwVersion, SNMP_Transport *pTransport);
5039dede 869
98762401 870InterfaceList *GetLocalInterfaceList();
967893bb 871void SnmpGetInterfaceStatus(UINT32 dwVersion, SNMP_Transport *pTransport, UINT32 dwIfIndex, int *adminState, int *operState);
5039dede 872
967893bb 873ROUTING_TABLE *SnmpGetRoutingTable(UINT32 dwVersion, SNMP_Transport *pTransport);
5039dede 874
9796ce45 875void LoadNetworkDeviceDrivers();
21254a93 876NetworkDeviceDriver *FindDriverForNode(Node *node, SNMP_Transport *pTransport);
28e1575f 877NetworkDeviceDriver *FindDriverByName(const TCHAR *name);
1f4c37ee 878void AddDriverSpecificOids(StringList *list);
9796ce45 879
5ad2167d 880void WatchdogInit();
967893bb
VK
881UINT32 WatchdogAddThread(const TCHAR *szName, time_t tNotifyInterval);
882void WatchdogNotify(UINT32 dwId);
5039dede
AK
883void WatchdogPrintStatus(CONSOLE_CTX pCtx);
884
5ad2167d 885void CheckForMgmtNode();
967893bb 886Node *PollNewNode(UINT32 dwIpAddr, UINT32 dwNetMask, UINT32 dwCreationFlags, WORD agentPort,
88f2990c 887 WORD snmpPort, const TCHAR *pszName, UINT32 dwProxyNode, UINT32 dwSNMPProxy, Cluster *pCluster,
967893bb 888 UINT32 zoneId, bool doConfPoll, bool discoveredNode);
5039dede 889
b1e9b6b3 890void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg);
967893bb 891void NXCORE_EXPORTABLE NotifyClientSessions(UINT32 dwCode, UINT32 dwData);
e1ebbfc2 892int GetSessionCount(bool withRoot = true);
967893bb 893bool IsLoggedIn(UINT32 dwUserId);
5d9a9c84 894bool NXCORE_EXPORTABLE KillClientSession(int id);
5039dede 895
35f836fe 896void GetSysInfoStr(TCHAR *pszBuffer, int nMaxSize);
967893bb 897UINT32 GetLocalIpAddr();
f7694811 898TCHAR *GetLocalHostName(TCHAR *buffer, size_t bufSize);
5039dede 899
35f836fe 900BOOL ExecCommand(TCHAR *pszCommand);
967893bb 901BOOL SendMagicPacket(UINT32 dwIpAddr, BYTE *pbMacAddr, int iNumPackets);
5039dede 902
35f836fe 903BOOL InitIdTable();
967893bb 904UINT32 CreateUniqueId(int iGroup);
35f836fe 905QWORD CreateUniqueEventId();
69bb7f47 906void SaveCurrentFreeId();
5039dede 907
35f836fe
VK
908void InitMailer();
909void ShutdownMailer();
910void NXCORE_EXPORTABLE PostMail(const TCHAR *pszRcpt, const TCHAR *pszSubject, const TCHAR *pszText);
5039dede 911
35f836fe
VK
912void InitSMSSender();
913void ShutdownSMSSender();
914void NXCORE_EXPORTABLE PostSMS(const TCHAR *pszRcpt, const TCHAR *pszText);
5039dede 915
35f836fe 916void InitTraps();
967893bb 917void SendTrapsToClient(ClientSession *pSession, UINT32 dwRqId);
5039dede 918void CreateTrapCfgMessage(CSCPMessage &msg);
967893bb
VK
919UINT32 CreateNewTrap(UINT32 *pdwTrapId);
920UINT32 CreateNewTrap(NXC_TRAP_CFG_ENTRY *pTrap);
921UINT32 UpdateTrapFromMsg(CSCPMessage *pMsg);
922UINT32 DeleteTrap(UINT32 dwId);
923void CreateNXMPTrapRecord(String &str, UINT32 dwId);
924
925BOOL IsTableTool(UINT32 dwToolId);
926BOOL CheckObjectToolAccess(UINT32 dwToolId, UINT32 dwUserId);
927UINT32 ExecuteTableTool(UINT32 dwToolId, Node *pNode, UINT32 dwRqId, ClientSession *pSession);
928UINT32 DeleteObjectToolFromDB(UINT32 dwToolId);
6f8e39e5 929UINT32 ChangeObjectToolStatus(UINT32 toolId, bool enabled);
967893bb
VK
930UINT32 UpdateObjectToolFromMessage(CSCPMessage *pMsg);
931
932UINT32 ModifySummaryTable(CSCPMessage *msg, LONG *newId);
933UINT32 DeleteSummaryTable(LONG tableId);
5389f7b0 934Table *QuerySummaryTable(LONG tableId, SummaryTable *adHocDefinition, UINT32 baseObjectId, UINT32 userId, UINT32 *rcc);
b4c2a628 935
e0f99bf0 936void CreateMessageFromSyslogMsg(CSCPMessage *pMsg, NX_SYSLOG_RECORD *pRec);
4262c0dc 937void ReinitializeSyslogParser();
5039dede
AK
938
939void EscapeString(String &str);
940
ce7565e7 941void InitAuditLog();
967893bb 942void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, BOOL isSuccess, UINT32 userId,
2a964810 943 const TCHAR *workstation, int sessionId, UINT32 objectId,
ce7565e7 944 const TCHAR *format, ...);
88f2990c 945
967893bb
VK
946bool ValidateConfig(Config *config, UINT32 flags, TCHAR *errorText, int errorTextLen);
947UINT32 ImportConfig(Config *config, UINT32 flags);
5039dede
AK
948
949#ifdef _WITH_ENCRYPTION
950X509 *CertificateFromLoginMessage(CSCPMessage *pMsg);
a50eaebe 951BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChallenge,
967893bb 952 BYTE *pSignature, UINT32 dwSigLen, int nMappingMethod,
a50eaebe 953 const TCHAR *pszMappingData);
9796ce45 954void ReloadCertificates();
5039dede
AK
955#endif
956
957#ifndef _WIN32
958THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL SignalHandler(void *);
959#endif /* not _WIN32 */
960
5039dede 961void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX pCtx);
534e1b83
VK
962void DumpClientSessions(CONSOLE_CTX pCtx);
963void DumpMobileDeviceSessions(CONSOLE_CTX pCtx);
5039dede 964void ShowPollerState(CONSOLE_CTX pCtx);
35f836fe 965void SetPollerInfo(int nIdx, const TCHAR *pszMsg);
5039dede 966void ShowServerStats(CONSOLE_CTX pCtx);
35f836fe 967void ShowQueueStats(CONSOLE_CTX pCtx, Queue *pQueue, const TCHAR *pszName);
5039dede
AK
968void DumpProcess(CONSOLE_CTX pCtx);
969
bd360fd5 970GRAPH_ACL_ENTRY *LoadGraphACL(DB_HANDLE hdb, UINT32 graphId, int *pnACLSize);
9ad921e5 971BOOL CheckGraphAccess(GRAPH_ACL_ENTRY *pACL, int nACLSize, UINT32 graphId, UINT32 graphUserId, UINT32 graphDesiredAccess);
fff23fae 972UINT32 GetGraphAccessCheckResult(UINT32 graphId, UINT32 graphUserId);
9ad921e5 973GRAPH_ACL_AND_ID IsGraphNameExists(const TCHAR *graphName);
7a4c94ee 974
d00ad4c6 975#if XMPP_SUPPORTED
244c65ef 976bool SendXMPPMessage(const TCHAR *rcpt, const TCHAR *message);
d00ad4c6 977#endif
244c65ef 978
9fa031cd 979/**
980 * File monitoring
981 */
982struct MONITORED_FILE
983{
984 TCHAR fileName[MAX_PATH];
985 ClientSession *session;
986 UINT32 nodeID;
987};
988
989class FileMonitoringList
990{
991private:
992 MUTEX m_mutex;
993 ObjectArray<MONITORED_FILE> m_monitoredFiles;
994 MONITORED_FILE* m_monitoredFile;
995
996public:
997 FileMonitoringList();
998 ~FileMonitoringList();
999 void addMonitoringFile(MONITORED_FILE *fileForAdd);
e2338033 1000 bool checkDuplicate(MONITORED_FILE *fileForAdd);
1001 ObjectArray<ClientSession>* findClientByFNameAndNodeID(const TCHAR *fileName, UINT32 nodeID);
9fa031cd 1002 bool removeMonitoringFile(MONITORED_FILE *fileForRemove);
1003 void removeDisconectedNode(UINT32 nodeId);
1004
1005private:
1006 void lock();
1007 void unlock();
1008};
1009
534e1b83
VK
1010/**
1011 * Global variables
1012 */
5039dede
AK
1013extern TCHAR NXCORE_EXPORTABLE g_szConfigFile[];
1014extern TCHAR NXCORE_EXPORTABLE g_szLogFile[];
967893bb
VK
1015extern UINT32 g_dwLogRotationMode;
1016extern UINT32 g_dwMaxLogSize;
1017extern UINT32 g_dwLogHistorySize;
4f8998ca 1018extern TCHAR g_szDailyLogFileSuffix[64];
5039dede
AK
1019extern TCHAR NXCORE_EXPORTABLE g_szDumpDir[];
1020extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
1021#ifndef _WIN32
1022extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
1023#endif
1024extern TCHAR g_szDataDir[];
9796ce45 1025extern TCHAR g_szLibDir[];
967893bb 1026extern UINT32 NXCORE_EXPORTABLE g_processAffinityMask;
5039dede
AK
1027extern QWORD g_qwServerId;
1028extern RSA *g_pServerKey;
c59466d2
VK
1029extern UINT32 g_icmpPingSize;
1030extern UINT32 g_icmpPingTimeout;
1031extern UINT32 g_auditFlags;
1032extern time_t g_serverStartTime;
1033extern UINT32 g_lockTimeout;
1034extern UINT32 g_agentCommandTimeout;
1035extern UINT32 g_thresholdRepeatInterval;
1036extern int g_requiredPolls;
1037extern UINT32 g_slmPollingInterval;
5039dede 1038
b8c1ec69
VK
1039extern TCHAR g_szDbDriver[];
1040extern TCHAR g_szDbDrvParams[];
1041extern TCHAR g_szDbServer[];
1042extern TCHAR g_szDbLogin[];
1043extern TCHAR g_szDbPassword[];
1044extern TCHAR g_szDbName[];
f3c30cf5 1045extern TCHAR g_szDbSchema[];
b8c1ec69 1046extern DB_DRIVER g_dbDriver;
5039dede 1047extern DB_HANDLE NXCORE_EXPORTABLE g_hCoreDB;
76fcb995
VK
1048extern Queue *g_dbWriterQueue;
1049extern Queue *g_dciDataWriterQueue;
1050extern Queue *g_dciRawDataWriterQueue;
5039dede 1051
2a964810 1052extern int NXCORE_EXPORTABLE g_dbSyntax;
9fa031cd 1053extern FileMonitoringList g_monitoringList;
5039dede
AK
1054
1055#endif /* _nms_core_h_ */