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