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