template import correctly handles updates of existing templates
[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;
b368969c 88 NXCPMessage *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 */
5039dede
AK
98#include "nms_dcoll.h"
99#include "nms_users.h"
46ee6286 100#include "nxcore_winperf.h"
5039dede 101#include "nms_objects.h"
5039dede
AK
102#include "nms_locks.h"
103#include "nms_pkg.h"
104#include "nms_topo.h"
105#include "nms_script.h"
5039dede 106#include "nxcore_situations.h"
ab621f39 107#include "nxcore_jobs.h"
e05b1945 108#include "nxcore_logs.h"
fd72d846 109#include "nxcore_schedule.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
ebb2dc70
VK
122#define PING_TIME_TIMEOUT 10000
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
ec13a467 160#define IDG_SCHEDULED_TASK 24
5039dede 161
0f506caa
VK
162/**
163 * Exit codes for console commands
164 */
5039dede
AK
165#define CMD_EXIT_CONTINUE 0
166#define CMD_EXIT_CLOSE_SESSION 1
167#define CMD_EXIT_SHUTDOWN 2
168
0f506caa
VK
169/**
170 * Network discovery mode
171 */
5039dede
AK
172#define DISCOVERY_DISABLED 0
173#define DISCOVERY_PASSIVE_ONLY 1
174#define DISCOVERY_ACTIVE 2
175
0f506caa
VK
176/**
177 * Client session flags
178 */
134c3d00 179#define CSF_TERMINATED ((UINT32)0x00000001)
850ce3ed
VK
180#define CSF_EPP_LOCKED ((UINT32)0x00000002)
181#define CSF_PACKAGE_DB_LOCKED ((UINT32)0x00000004)
182#define CSF_USER_DB_LOCKED ((UINT32)0x00000008)
183#define CSF_EPP_UPLOAD ((UINT32)0x00000010)
184#define CSF_CONSOLE_OPEN ((UINT32)0x00000020)
185#define CSF_AUTHENTICATED ((UINT32)0x00000080)
186#define CSF_RECEIVING_MAP_DATA ((UINT32)0x00000200)
187#define CSF_SYNC_OBJECT_COMMENTS ((UINT32)0x00000400)
678fe569
VK
188#define CSF_CUSTOM_LOCK_1 ((UINT32)0x01000000)
189#define CSF_CUSTOM_LOCK_2 ((UINT32)0x02000000)
190#define CSF_CUSTOM_LOCK_3 ((UINT32)0x04000000)
191#define CSF_CUSTOM_LOCK_4 ((UINT32)0x08000000)
192#define CSF_CUSTOM_LOCK_5 ((UINT32)0x10000000)
193#define CSF_CUSTOM_LOCK_6 ((UINT32)0x20000000)
194#define CSF_CUSTOM_LOCK_7 ((UINT32)0x40000000)
195#define CSF_CUSTOM_LOCK_8 ((UINT32)0x80000000)
5039dede 196
0f506caa
VK
197/**
198 * Client session states
199 */
5039dede
AK
200#define SESSION_STATE_INIT 0
201#define SESSION_STATE_IDLE 1
202#define SESSION_STATE_PROCESSING 2
203
0f506caa
VK
204/**
205 * Information categories for UPDATE_INFO structure
206 */
5039dede
AK
207#define INFO_CAT_EVENT 1
208#define INFO_CAT_OBJECT_CHANGE 2
209#define INFO_CAT_ALARM 3
210#define INFO_CAT_ACTION 4
211#define INFO_CAT_SYSLOG_MSG 5
212#define INFO_CAT_SNMP_TRAP 6
213#define INFO_CAT_AUDIT_RECORD 7
214#define INFO_CAT_SITUATION 8
624f1165 215#define INFO_CAT_LIBRARY_IMAGE 9
5039dede 216
0f506caa
VK
217/**
218 * Certificate types
219 */
5039dede
AK
220#define CERT_TYPE_TRUSTED_CA 0
221#define CERT_TYPE_USER 1
222
0f506caa
VK
223/**
224 * Audit subsystems
225 */
5039dede
AK
226#define AUDIT_SECURITY _T("SECURITY")
227#define AUDIT_OBJECTS _T("OBJECTS")
228#define AUDIT_SYSCFG _T("SYSCFG")
229#define AUDIT_CONSOLE _T("CONSOLE")
230
2a964810
VK
231#define AUDIT_SYSTEM_SID (-1)
232
0f506caa
VK
233/**
234 * Event handling subsystem definitions
235 */
5039dede
AK
236#include "nms_events.h"
237#include "nms_actions.h"
238#include "nms_alarm.h"
239
0f506caa
VK
240/**
241 * New node information
242 */
5039dede
AK
243typedef struct
244{
c75e9ee4 245 InetAddress ipAddr;
967893bb 246 UINT32 zoneId;
5039dede 247 BOOL ignoreFilter;
baa5324c 248 BYTE bMacAddr[MAC_ADDR_LENGTH];
5039dede
AK
249} NEW_NODE;
250
0f506caa
VK
251/**
252 * New node flags
253 */
5039dede
AK
254#define NNF_IS_SNMP 0x0001
255#define NNF_IS_AGENT 0x0002
256#define NNF_IS_ROUTER 0x0004
257#define NNF_IS_BRIDGE 0x0008
258#define NNF_IS_PRINTER 0x0010
259#define NNF_IS_CDP 0x0020
260#define NNF_IS_SONMP 0x0040
261#define NNF_IS_LLDP 0x0080
262
0f506caa
VK
263/**
264 * Node information for autodiscovery filter
265 */
5039dede
AK
266typedef struct
267{
c75e9ee4 268 InetAddress ipAddr;
967893bb 269 UINT32 dwFlags;
5039dede 270 int nSNMPVersion;
35f836fe
VK
271 TCHAR szObjectId[MAX_OID_LEN * 4]; // SNMP OID
272 TCHAR szAgentVersion[MAX_AGENT_VERSION_LEN];
273 TCHAR szPlatform[MAX_PLATFORM_NAME_LEN];
5039dede
AK
274} DISCOVERY_FILTER_DATA;
275
0f506caa
VK
276/**
277 * Data update structure for client sessions
278 */
5039dede
AK
279typedef struct
280{
967893bb
VK
281 UINT32 dwCategory; // Data category - event, network object, etc.
282 UINT32 dwCode; // Data-specific update code
5039dede
AK
283 void *pData; // Pointer to data block
284} UPDATE_INFO;
285
534e1b83
VK
286/**
287 * Extended agent connection
288 */
5039dede
AK
289class AgentConnectionEx : public AgentConnection
290{
291protected:
967893bb 292 UINT32 m_nodeId;
d1c1c522 293
af21affe 294 virtual void printMsg(const TCHAR *format, ...);
b368969c
VK
295 virtual void onTrap(NXCPMessage *msg);
296 virtual void onDataPush(NXCPMessage *msg);
297 virtual void onFileMonitoringData(NXCPMessage *msg);
298 virtual void onSnmpTrap(NXCPMessage *pMsg);
02d936bd 299 virtual UINT32 processCollectedData(NXCPMessage *msg);
e9902466 300 virtual bool processCustomMessage(NXCPMessage *msg);
5039dede
AK
301
302public:
c11eee9b 303 AgentConnectionEx(UINT32 nodeId, InetAddress ipAddr, WORD port = AGENT_LISTEN_PORT, int authMethod = AUTH_NONE, const TCHAR *secret = NULL) :
69c6604d 304 AgentConnection(ipAddr, port, authMethod, secret) { m_nodeId = nodeId; }
5039dede 305 virtual ~AgentConnectionEx();
45d84f8a 306
967893bb
VK
307 UINT32 deployPolicy(AgentPolicy *policy);
308 UINT32 uninstallPolicy(AgentPolicy *policy);
5039dede
AK
309};
310
534e1b83
VK
311/**
312 * Mobile device session
313 */
314class NXCORE_EXPORTABLE MobileDeviceSession
315{
316private:
317 SOCKET m_hSocket;
318 Queue *m_pSendQueue;
319 Queue *m_pMessageQueue;
2a964810
VK
320 int m_id;
321 int m_state;
534e1b83 322 WORD m_wCurrentCmd;
967893bb
VK
323 UINT32 m_dwUserId;
324 UINT32 m_deviceObjectId;
b368969c 325 NXCP_BUFFER *m_pMsgBuffer;
534e1b83
VK
326 NXCPEncryptionContext *m_pCtx;
327 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
328 THREAD m_hWriteThread;
329 THREAD m_hProcessingThread;
330 MUTEX m_mutexSocketWrite;
331 struct sockaddr *m_clientAddr;
332 TCHAR m_szHostName[256]; // IP address of name of conneced host in textual form
333 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
334 TCHAR m_szClientInfo[96]; // Client app info string
967893bb
VK
335 UINT32 m_dwEncryptionRqId;
336 UINT32 m_dwEncryptionResult;
534e1b83 337 CONDITION m_condEncryptionSetup;
967893bb 338 UINT32 m_dwRefCount;
534e1b83
VK
339 bool m_isAuthenticated;
340
341 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
342 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
343 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
5039dede 344
534e1b83
VK
345 void readThread();
346 void writeThread();
347 void processingThread();
348
b368969c 349 void setupEncryption(NXCPMessage *request);
967893bb 350 void respondToKeepalive(UINT32 dwRqId);
534e1b83 351 void debugPrintf(int level, const TCHAR *format, ...);
967893bb 352 void sendServerInfo(UINT32 dwRqId);
b368969c
VK
353 void login(NXCPMessage *pRequest);
354 void updateDeviceInfo(NXCPMessage *pRequest);
355 void updateDeviceStatus(NXCPMessage *pRequest);
356 void pushData(NXCPMessage *request);
534e1b83
VK
357
358public:
359 MobileDeviceSession(SOCKET hSocket, struct sockaddr *addr);
360 ~MobileDeviceSession();
361
534e1b83
VK
362 void run();
363
19dbc8ef 364 void postMessage(NXCPMessage *pMsg) { m_pSendQueue->put(pMsg->createMessage()); }
b368969c 365 void sendMessage(NXCPMessage *pMsg);
5039dede 366
2a964810
VK
367 int getId() { return m_id; }
368 void setId(int id) { if (m_id == -1) m_id = id; }
369 int getState() { return m_state; }
534e1b83
VK
370 const TCHAR *getUserName() { return m_szUserName; }
371 const TCHAR *getClientInfo() { return m_szClientInfo; }
372 const TCHAR *getHostName() { return m_szHostName; }
967893bb 373 UINT32 getUserId() { return m_dwUserId; }
534e1b83
VK
374 bool isAuthenticated() { return m_isAuthenticated; }
375 WORD getCurrentCmd() { return m_wCurrentCmd; }
376 int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
377};
378
379/**
380 * Client (user) session
381 */
134c3d00 382#define DECLARE_THREAD_STARTER(func) static void ThreadStarter_##func(void *);
5039dede 383
a0e3917e 384class NXCORE_EXPORTABLE ClientSession
5039dede
AK
385{
386private:
387 SOCKET m_hSocket;
388 Queue *m_pSendQueue;
389 Queue *m_pMessageQueue;
390 Queue *m_pUpdateQueue;
2a964810
VK
391 int m_id;
392 int m_state;
5039dede 393 WORD m_wCurrentCmd;
967893bb 394 UINT32 m_dwUserId;
f4d8fe18 395 UINT64 m_dwSystemAccess; // User's system access rights
967893bb 396 UINT32 m_dwFlags; // Session flags
f8c6f10f 397 int m_clientType; // Client system type - desktop, web, mobile, etc.
98abc9f1 398 NXCPEncryptionContext *m_pCtx;
5039dede
AK
399 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
400 THREAD m_hWriteThread;
401 THREAD m_hProcessingThread;
402 THREAD m_hUpdateThread;
d3a7cf4c 403 MUTEX m_mutexSocketWrite;
5039dede
AK
404 MUTEX m_mutexSendEvents;
405 MUTEX m_mutexSendSyslog;
406 MUTEX m_mutexSendTrapLog;
407 MUTEX m_mutexSendObjects;
408 MUTEX m_mutexSendAlarms;
409 MUTEX m_mutexSendActions;
410 MUTEX m_mutexSendAuditLog;
411 MUTEX m_mutexSendSituations;
412 MUTEX m_mutexPollerInit;
60557d06 413 struct sockaddr *m_clientAddr;
91f6b72c
VK
414 TCHAR m_workstation[256]; // IP address or name of connected host in textual form
415 TCHAR m_webServerAddress[256]; // IP address or name of web server for web sessions
77a08c86
VK
416 TCHAR m_loginName[MAX_USER_NAME];
417 TCHAR m_sessionName[MAX_SESSION_NAME]; // String in form login_name@host
418 TCHAR m_clientInfo[96]; // Client app info string
2a964810 419 TCHAR m_language[8]; // Client's desired language
a51628e2 420 time_t m_loginTime;
967893bb
VK
421 UINT32 m_dwOpenDCIListSize; // Number of open DCI lists
422 UINT32 *m_pOpenDCIList; // List of nodes with DCI lists open
423 UINT32 m_dwNumRecordsToUpload; // Number of records to be uploaded
424 UINT32 m_dwRecordsUploaded;
5039dede
AK
425 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
426 int m_hCurrFile;
967893bb
VK
427 UINT32 m_dwFileRqId;
428 UINT32 m_dwUploadCommand;
429 UINT32 m_dwUploadData;
e928a6db 430 uuid_t m_uploadImageGuid;
5039dede 431 TCHAR m_szCurrFileName[MAX_PATH];
967893bb
VK
432 UINT32 m_dwRefCount;
433 UINT32 m_dwEncryptionRqId;
434 UINT32 m_dwEncryptionResult;
5039dede 435 CONDITION m_condEncryptionSetup;
967893bb 436 UINT32 m_dwActiveChannels; // Active data channels
200d662d 437 CONSOLE_CTX m_console; // Server console context
810bd8c4 438 StringList m_musicTypeList;
7cf549ad 439 ObjectIndex m_agentConn;
5039dede 440
534e1b83
VK
441 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
442 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
443 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
444 static THREAD_RESULT THREAD_CALL updateThreadStarter(void *);
134c3d00 445 static void pollerThreadStarter(void *);
5039dede 446
92c51b1d
VK
447 DECLARE_THREAD_STARTER(getCollectedData)
448 DECLARE_THREAD_STARTER(getTableCollectedData)
449 DECLARE_THREAD_STARTER(clearDCIData)
79633a65 450 DECLARE_THREAD_STARTER(forceDCIPoll)
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)
529956a0 477 DECLARE_THREAD_STARTER(executeScript)
5039dede 478
62768df3
VK
479 void readThread();
480 void writeThread();
481 void processingThread();
482 void updateThread();
967893bb 483 void pollerThread(Node *pNode, int iPollType, UINT32 dwRqId);
5039dede 484
b368969c 485 void setupEncryption(NXCPMessage *request);
967893bb 486 void respondToKeepalive(UINT32 dwRqId);
e05b1945 487 void onFileUpload(BOOL bSuccess);
534e1b83 488 void debugPrintf(int level, const TCHAR *format, ...);
967893bb 489 void sendServerInfo(UINT32 dwRqId);
b368969c
VK
490 void login(NXCPMessage *pRequest);
491 void sendAllObjects(NXCPMessage *pRequest);
492 void sendSelectedObjects(NXCPMessage *pRequest);
493 void sendEventLog(NXCPMessage *pRequest);
c85c8ef2
VK
494 void getConfigurationVariables(UINT32 dwRqId);
495 void getPublicConfigurationVariable(NXCPMessage *request);
496 void setConfigurationVariable(NXCPMessage *pRequest);
497 void deleteConfigurationVariable(NXCPMessage *pRequest);
967893bb
VK
498 void sendUserDB(UINT32 dwRqId);
499 void sendAllAlarms(UINT32 dwRqId);
b368969c
VK
500 void createUser(NXCPMessage *pRequest);
501 void updateUser(NXCPMessage *pRequest);
2d8d8ea2 502 void detachLdapUser(NXCPMessage *pRequest);
b368969c 503 void deleteUser(NXCPMessage *pRequest);
77a08c86
VK
504 void setPassword(NXCPMessage *request);
505 void validatePassword(NXCPMessage *request);
967893bb
VK
506 void lockUserDB(UINT32 dwRqId, BOOL bLock);
507 void sendEventDB(UINT32 dwRqId);
b368969c
VK
508 void modifyEventTemplate(NXCPMessage *pRequest);
509 void deleteEventTemplate(NXCPMessage *pRequest);
967893bb 510 void generateEventCode(UINT32 dwRqId);
b368969c
VK
511 void modifyObject(NXCPMessage *pRequest);
512 void changeObjectMgmtStatus(NXCPMessage *pRequest);
7e18667a
VK
513 void enterMaintenanceMode(NXCPMessage *request);
514 void leaveMaintenanceMode(NXCPMessage *request);
b368969c
VK
515 void openNodeDCIList(NXCPMessage *pRequest);
516 void closeNodeDCIList(NXCPMessage *pRequest);
517 void modifyNodeDCI(NXCPMessage *pRequest);
518 void copyDCI(NXCPMessage *pRequest);
519 void applyTemplate(NXCPMessage *pRequest);
520 void getCollectedData(NXCPMessage *pRequest);
521 void getTableCollectedData(NXCPMessage *pRequest);
522 bool getCollectedDataFromDB(NXCPMessage *request, NXCPMessage *response, DataCollectionTarget *object, int dciType);
523 void clearDCIData(NXCPMessage *pRequest);
79633a65 524 void forceDCIPoll(NXCPMessage *pRequest);
b368969c
VK
525 void changeDCIStatus(NXCPMessage *pRequest);
526 void getLastValues(NXCPMessage *pRequest);
527 void getLastValuesByDciId(NXCPMessage *pRequest);
528 void getTableLastValues(NXCPMessage *pRequest);
529 void getThresholdSummary(NXCPMessage *request);
530 void openEPP(NXCPMessage *request);
967893bb 531 void closeEPP(UINT32 dwRqId);
b368969c
VK
532 void saveEPP(NXCPMessage *pRequest);
533 void processEPPRecord(NXCPMessage *pRequest);
967893bb 534 void sendMIBTimestamp(UINT32 dwRqId);
b368969c
VK
535 void sendMib(NXCPMessage *request);
536 void createObject(NXCPMessage *request);
537 void changeObjectBinding(NXCPMessage *request, BOOL bBind);
538 void deleteObject(NXCPMessage *request);
539 void getAlarm(NXCPMessage *request);
540 void getAlarmEvents(NXCPMessage *request);
541 void acknowledgeAlarm(NXCPMessage *request);
542 void resolveAlarm(NXCPMessage *request, bool terminate);
543 void deleteAlarm(NXCPMessage *request);
544 void openHelpdeskIssue(NXCPMessage *request);
545 void getHelpdeskUrl(NXCPMessage *request);
546 void unlinkHelpdeskIssue(NXCPMessage *request);
547 void getAlarmComments(NXCPMessage *pRequest);
548 void updateAlarmComment(NXCPMessage *pRequest);
549 void deleteAlarmComment(NXCPMessage *request);
550 void updateAlarmStatusFlow(NXCPMessage *request);
551 void createAction(NXCPMessage *pRequest);
552 void updateAction(NXCPMessage *pRequest);
553 void deleteAction(NXCPMessage *pRequest);
967893bb
VK
554 void sendAllActions(UINT32 dwRqId);
555 void SendContainerCategories(UINT32 dwRqId);
b368969c
VK
556 void forcedNodePoll(NXCPMessage *pRequest);
557 void onTrap(NXCPMessage *pRequest);
558 void onWakeUpNode(NXCPMessage *pRequest);
559 void queryParameter(NXCPMessage *pRequest);
560 void queryAgentTable(NXCPMessage *pRequest);
561 void editTrap(int iOperation, NXCPMessage *pRequest);
967893bb
VK
562 void LockTrapCfg(UINT32 dwRqId, BOOL bLock);
563 void sendAllTraps(UINT32 dwRqId);
564 void sendAllTraps2(UINT32 dwRqId);
565 void LockPackageDB(UINT32 dwRqId, BOOL bLock);
566 void SendAllPackages(UINT32 dwRqId);
b368969c
VK
567 void InstallPackage(NXCPMessage *pRequest);
568 void RemovePackage(NXCPMessage *pRequest);
569 void DeployPackage(NXCPMessage *pRequest);
570 void getParametersList(NXCPMessage *pRequest);
571 void getUserVariable(NXCPMessage *pRequest);
572 void setUserVariable(NXCPMessage *pRequest);
573 void copyUserVariable(NXCPMessage *pRequest);
574 void enumUserVariables(NXCPMessage *pRequest);
575 void deleteUserVariable(NXCPMessage *pRequest);
576 void changeObjectZone(NXCPMessage *pRequest);
577 void getAgentConfig(NXCPMessage *pRequest);
578 void updateAgentConfig(NXCPMessage *pRequest);
579 void executeAction(NXCPMessage *pRequest);
b576249a
VK
580 void getObjectTools(UINT32 requestId);
581 void getObjectToolDetails(NXCPMessage *request);
b368969c
VK
582 void updateObjectTool(NXCPMessage *pRequest);
583 void deleteObjectTool(NXCPMessage *pRequest);
584 void changeObjectToolStatus(NXCPMessage *pRequest);
967893bb 585 void generateObjectToolId(UINT32 dwRqId);
b368969c
VK
586 void execTableTool(NXCPMessage *pRequest);
587 void changeSubscription(NXCPMessage *pRequest);
588 void sendSyslog(NXCPMessage *pRequest);
967893bb
VK
589 void sendServerStats(UINT32 dwRqId);
590 void sendScriptList(UINT32 dwRqId);
b368969c
VK
591 void sendScript(NXCPMessage *pRequest);
592 void updateScript(NXCPMessage *pRequest);
593 void renameScript(NXCPMessage *pRequest);
594 void deleteScript(NXCPMessage *pRequest);
967893bb 595 void SendSessionList(UINT32 dwRqId);
b368969c
VK
596 void KillSession(NXCPMessage *pRequest);
597 void SendTrapLog(NXCPMessage *pRequest);
598 void StartSnmpWalk(NXCPMessage *pRequest);
599 void resolveDCINames(NXCPMessage *pRequest);
967893bb 600 UINT32 resolveDCIName(UINT32 dwNode, UINT32 dwItem, TCHAR **ppszName);
b368969c 601 void sendConfigForAgent(NXCPMessage *pRequest);
967893bb 602 void sendAgentCfgList(UINT32 dwRqId);
b368969c
VK
603 void OpenAgentConfig(NXCPMessage *pRequest);
604 void SaveAgentConfig(NXCPMessage *pRequest);
605 void DeleteAgentConfig(NXCPMessage *pRequest);
606 void SwapAgentConfigs(NXCPMessage *pRequest);
607 void SendObjectComments(NXCPMessage *pRequest);
608 void updateObjectComments(NXCPMessage *pRequest);
609 void pushDCIData(NXCPMessage *pRequest);
610 void getAddrList(NXCPMessage *pRequest);
611 void setAddrList(NXCPMessage *pRequest);
612 void resetComponent(NXCPMessage *pRequest);
25a1e9d0
VK
613 void getDCIEventList(NXCPMessage *request);
614 void getDCIScriptList(NXCPMessage *request);
b368969c
VK
615 void SendDCIInfo(NXCPMessage *pRequest);
616 void sendPerfTabDCIList(NXCPMessage *pRequest);
617 void exportConfiguration(NXCPMessage *pRequest);
618 void importConfiguration(NXCPMessage *pRequest);
6f8e39e5 619 void sendGraphList(UINT32 dwRqId);
b368969c
VK
620 void saveGraph(NXCPMessage *pRequest);
621 void deleteGraph(NXCPMessage *pRequest);
622 void AddCACertificate(NXCPMessage *pRequest);
623 void DeleteCertificate(NXCPMessage *pRequest);
624 void UpdateCertificateComments(NXCPMessage *pRequest);
967893bb 625 void getCertificateList(UINT32 dwRqId);
b368969c
VK
626 void queryL2Topology(NXCPMessage *pRequest);
627 void sendSMS(NXCPMessage *pRequest);
967893bb 628 void SendCommunityList(UINT32 dwRqId);
b368969c 629 void UpdateCommunityList(NXCPMessage *pRequest);
a882b714 630 void getSituationList(UINT32 dwRqId);
b368969c
VK
631 void createSituation(NXCPMessage *pRequest);
632 void updateSituation(NXCPMessage *pRequest);
633 void deleteSituation(NXCPMessage *pRequest);
634 void deleteSituationInstance(NXCPMessage *pRequest);
635 void setConfigCLOB(NXCPMessage *pRequest);
636 void getConfigCLOB(NXCPMessage *pRequest);
637 void registerAgent(NXCPMessage *pRequest);
638 void getServerFile(NXCPMessage *pRequest);
639 void cancelFileMonitoring(NXCPMessage *request);
640 void getAgentFile(NXCPMessage *pRequest);
641 void testDCITransformation(NXCPMessage *pRequest);
967893bb 642 void sendJobList(UINT32 dwRqId);
b368969c
VK
643 void cancelJob(NXCPMessage *pRequest);
644 void holdJob(NXCPMessage *pRequest);
645 void unholdJob(NXCPMessage *pRequest);
646 void deployAgentPolicy(NXCPMessage *pRequest, bool uninstallFlag);
647 void getUserCustomAttribute(NXCPMessage *request);
648 void setUserCustomAttribute(NXCPMessage *request);
649 void openServerLog(NXCPMessage *request);
650 void closeServerLog(NXCPMessage *request);
651 void queryServerLog(NXCPMessage *request);
652 void getServerLogQueryData(NXCPMessage *request);
967893bb 653 void sendUsmCredentials(UINT32 dwRqId);
b368969c
VK
654 void updateUsmCredentials(NXCPMessage *pRequest);
655 void sendDCIThresholds(NXCPMessage *request);
656 void addClusterNode(NXCPMessage *request);
657 void findNodeConnection(NXCPMessage *request);
658 void findMacAddress(NXCPMessage *request);
659 void findIpAddress(NXCPMessage *request);
660 void sendLibraryImage(NXCPMessage *request);
661 void updateLibraryImage(NXCPMessage *request);
662 void listLibraryImages(NXCPMessage *request);
663 void deleteLibraryImage(NXCPMessage *request);
664 void executeServerCommand(NXCPMessage *request);
665 void uploadFileToAgent(NXCPMessage *request);
666 void listServerFileStore(NXCPMessage *request);
667 void processConsoleCommand(NXCPMessage *msg);
967893bb
VK
668 void openConsole(UINT32 rqId);
669 void closeConsole(UINT32 rqId);
b368969c
VK
670 void getVlans(NXCPMessage *msg);
671 void receiveFile(NXCPMessage *request);
672 void deleteFile(NXCPMessage *request);
673 void getNetworkPath(NXCPMessage *request);
674 void getNodeComponents(NXCPMessage *request);
675 void getNodeSoftware(NXCPMessage *request);
676 void getWinPerfObjects(NXCPMessage *request);
677 void listMappingTables(NXCPMessage *request);
678 void getMappingTable(NXCPMessage *request);
679 void updateMappingTable(NXCPMessage *request);
680 void deleteMappingTable(NXCPMessage *request);
681 void getWirelessStations(NXCPMessage *request);
967893bb 682 void getSummaryTables(UINT32 rqId);
b368969c
VK
683 void getSummaryTableDetails(NXCPMessage *request);
684 void modifySummaryTable(NXCPMessage *request);
685 void deleteSummaryTable(NXCPMessage *request);
686 void querySummaryTable(NXCPMessage *request);
687 void queryAdHocSummaryTable(NXCPMessage *request);
688 void forwardToReportingServer(NXCPMessage *request);
689 void getSubnetAddressMap(NXCPMessage *request);
690 void getEffectiveRights(NXCPMessage *request);
691 void fileManagerControl(NXCPMessage *request);
692 void uploadUserFileToAgent(NXCPMessage *request);
693 void getSwitchForwardingDatabase(NXCPMessage *request);
694 void getRoutingTable(NXCPMessage *request);
695 void getLocationHistory(NXCPMessage *request);
696 void getScreenshot(NXCPMessage *request);
697 void executeScript(NXCPMessage *request);
5f573844 698 void compileScript(NXCPMessage *request);
4b535d78 699 void resyncAgentDciConfiguration(NXCPMessage *request);
700 void cleanAgentDciConfiguration(NXCPMessage *request);
ec13a467
VK
701 void getSchedulerTaskHandlers(NXCPMessage *request);
702 void getScheduledTasks(NXCPMessage *request);
703 void addScheduledTask(NXCPMessage *request);
704 void updateScheduledTask(NXCPMessage *request);
705 void removeScheduledTask(NXCPMessage *request);
5039dede
AK
706
707public:
60557d06 708 ClientSession(SOCKET hSocket, struct sockaddr *addr);
5039dede
AK
709 ~ClientSession();
710
e05b1945
VK
711 void incRefCount() { m_dwRefCount++; }
712 void decRefCount() { if (m_dwRefCount > 0) m_dwRefCount--; }
713
714 void run();
715
19dbc8ef 716 void postMessage(NXCPMessage *pMsg) { m_pSendQueue->put(pMsg->createMessage()); }
a07511b5 717 bool sendMessage(NXCPMessage *pMsg);
b368969c 718 void sendRawMessage(NXCP_MESSAGE *pMsg);
967893bb 719 void sendPollerMsg(UINT32 dwRqId, const TCHAR *pszMsg);
cc022855 720 BOOL sendFile(const TCHAR *file, UINT32 dwRqId, long offset);
e05b1945 721
2a964810
VK
722 int getId() { return m_id; }
723 void setId(int id) { if (m_id == -1) m_id = id; }
724 int getState() { return m_state; }
77a08c86
VK
725 const TCHAR *getLoginName() { return m_loginName; }
726 const TCHAR *getSessionName() { return m_sessionName; }
727 const TCHAR *getClientInfo() { return m_clientInfo; }
91f6b72c
VK
728 const TCHAR *getWorkstation() { return m_workstation; }
729 const TCHAR *getWebServerAddress() { return m_webServerAddress; }
967893bb 730 UINT32 getUserId() { return m_dwUserId; }
f4d8fe18 731 UINT64 getSystemRights() { return m_dwSystemAccess; }
87f56b19 732 UINT32 getFlags() { return m_dwFlags; }
f669df41 733 bool isAuthenticated() { return (m_dwFlags & CSF_AUTHENTICATED) ? true : false; }
134c3d00 734 bool isTerminated() { return (m_dwFlags & CSF_TERMINATED) ? true : false; }
f669df41 735 bool isConsoleOpen() { return (m_dwFlags & CSF_CONSOLE_OPEN) ? true : false; }
967893bb 736 bool isSubscribed(UINT32 dwChannel) { return (m_dwActiveChannels & dwChannel) ? true : false; }
f669df41 737 WORD getCurrentCmd() { return m_wCurrentCmd; }
98abc9f1 738 int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
f8c6f10f 739 int getClientType() { return m_clientType; }
a51628e2 740 time_t getLoginTime() { return m_loginTime; }
e05b1945 741
3fd05687 742 bool checkSysAccessRights(UINT64 requiredAccess)
88f2990c 743 {
744 return (m_dwUserId == 0) ? true :
badf9a95 745 ((requiredAccess & m_dwSystemAccess) == requiredAccess);
e05b1945
VK
746 }
747
87f56b19
VK
748 void setCustomLock(UINT32 bit, bool value)
749 {
750 if (value)
751 m_dwFlags |= (bit & 0xFF000000);
752 else
753 m_dwFlags &= ~(bit & 0xFF000000);
754 }
755
f669df41 756 void kill();
967893bb 757 void notify(UINT32 dwCode, UINT32 dwData = 0);
e05b1945 758
19dbc8ef 759 void queueUpdate(UPDATE_INFO *pUpdate) { m_pUpdateQueue->put(pUpdate); }
e05b1945 760 void onNewEvent(Event *pEvent);
e0f99bf0 761 void onSyslogMessage(NX_SYSLOG_RECORD *pRec);
b368969c 762 void onNewSNMPTrap(NXCPMessage *pMsg);
e05b1945 763 void onObjectChange(NetObj *pObject);
967893bb
VK
764 void onUserDBUpdate(int code, UINT32 id, UserDatabaseObject *user);
765 void onAlarmUpdate(UINT32 dwCode, NXC_ALARM *pAlarm);
766 void onActionDBUpdate(UINT32 dwCode, NXC_ACTION *pAction);
b368969c 767 void onSituationChange(NXCPMessage *msg);
72f6ece2 768 void onLibraryImageChange(uuid_t *guid, bool removed = false);
5039dede
AK
769};
770
2bac37f9
VK
771/**
772 * Delayed SQL request
773 */
7dad92fb
VK
774typedef struct
775{
776 TCHAR *query;
777 int bindCount;
778 BYTE *sqlTypes;
779 TCHAR *bindings[1]; /* actual size determined by bindCount field */
780} DELAYED_SQL_REQUEST;
781
2bac37f9
VK
782/**
783 * Delayed request for idata_ INSERT
784 */
f68d9eac
VK
785typedef struct
786{
787 time_t timestamp;
967893bb
VK
788 UINT32 nodeId;
789 UINT32 dciId;
f68d9eac
VK
790 TCHAR value[MAX_RESULT_LENGTH];
791} DELAYED_IDATA_INSERT;
792
76fcb995
VK
793/**
794 * Delayed request for raw_dci_values UPDATE
795 */
796typedef struct
797{
798 time_t timestamp;
799 UINT32 dciId;
800 TCHAR rawValue[MAX_RESULT_LENGTH];
801 TCHAR transformedValue[MAX_RESULT_LENGTH];
802} DELAYED_RAW_DATA_UPDATE;
803
7a4c94ee 804/**
805 * Graph ACL entry
806 */
807struct GRAPH_ACL_ENTRY
808{
809 UINT32 dwGraphId;
810 UINT32 dwUserId;
811 UINT32 dwAccess;
812};
813
814/**
815 * Information about graph with name existence and it's ID.
816 */
817struct GRAPH_ACL_AND_ID
818{
88f2990c 819 UINT32 graphId;
7a4c94ee 820 UINT32 status;
821};
822
9f3db00f
VK
823/**
824 * Thread pool stats
825 */
826enum ThreadPoolStat
827{
828 THREAD_POOL_CURR_SIZE,
829 THREAD_POOL_MIN_SIZE,
830 THREAD_POOL_MAX_SIZE,
831 THREAD_POOL_REQUESTS,
832 THREAD_POOL_LOAD,
833 THREAD_POOL_USAGE,
834 THREAD_POOL_LOADAVG_1,
835 THREAD_POOL_LOADAVG_5,
836 THREAD_POOL_LOADAVG_15
837};
838
234079c4
VK
839/**
840 * Server command execution data
841 */
842class ServerCommandExecData
843{
844private:
845 TCHAR *m_command;
846 bool m_sendOutput;
847 UINT32 m_requestId;
848 ClientSession *m_session;
849
850public:
851 ServerCommandExecData(TCHAR *command, bool sendOutput, UINT32 requestId, ClientSession *session);
852 ~ServerCommandExecData();
853
854 bool sendOutput() { return m_sendOutput; }
855 const TCHAR *getCommand() { return m_command; }
856 UINT32 getRequestId() { return m_requestId; }
857 ClientSession *getSession() { return m_session; }
858};
859
2bac37f9
VK
860/**
861 * Functions
862 */
35959841 863bool NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
9bd1bace 864bool NXCORE_EXPORTABLE ConfigReadStrEx(DB_HANDLE hdb, const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
35f836fe 865#ifdef UNICODE
35959841 866bool NXCORE_EXPORTABLE ConfigReadStrA(const WCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
35f836fe
VK
867#else
868#define ConfigReadStrA ConfigReadStr
869#endif
43526096 870bool NXCORE_EXPORTABLE ConfigReadStrUTF8(const TCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
5039dede 871int NXCORE_EXPORTABLE ConfigReadInt(const TCHAR *szVar, int iDefault);
9bd1bace 872int NXCORE_EXPORTABLE ConfigReadIntEx(DB_HANDLE hdb, const TCHAR *szVar, int iDefault);
967893bb 873UINT32 NXCORE_EXPORTABLE ConfigReadULong(const TCHAR *szVar, UINT32 dwDefault);
35959841
VK
874bool NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray, int nSize, int nDefault);
875bool NXCORE_EXPORTABLE ConfigWriteStr(const TCHAR *szVar, const TCHAR *szValue, bool bCreate, bool isVisible = true, bool needRestart = false);
876bool NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, bool bCreate, bool isVisible = true, bool needRestart = false);
877bool NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, UINT32 dwValue, bool bCreate, bool isVisible = true, bool needRestart = false);
878bool NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray, int nSize, bool bCreate, bool isVisible = true, bool needRestart = false);
5039dede 879TCHAR NXCORE_EXPORTABLE *ConfigReadCLOB(const TCHAR *var, const TCHAR *defValue);
35959841
VK
880bool NXCORE_EXPORTABLE ConfigWriteCLOB(const TCHAR *var, const TCHAR *value, bool bCreate);
881bool NXCORE_EXPORTABLE ConfigDelete(const TCHAR *name);
5039dede 882
35959841 883bool NXCORE_EXPORTABLE MetaDataReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
40dedf5d 884INT32 NXCORE_EXPORTABLE MetaDataReadInt(const TCHAR *var, UINT32 defaultValue);
e9902466 885bool NXCORE_EXPORTABLE MetaDataWriteStr(const TCHAR *varName, const TCHAR *value);
28f5b9a4 886
35959841 887bool NXCORE_EXPORTABLE LoadConfig();
5039dede 888
35f836fe
VK
889void NXCORE_EXPORTABLE Shutdown();
890void NXCORE_EXPORTABLE FastShutdown();
891BOOL NXCORE_EXPORTABLE Initialize();
5039dede 892THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *);
35f836fe
VK
893void NXCORE_EXPORTABLE ShutdownDB();
894void InitiateShutdown();
5039dede 895
400e55c4 896bool NXCORE_EXPORTABLE SleepAndCheckForShutdown(int iSeconds);
5039dede 897
6e383343
VK
898void ConsolePrintf(CONSOLE_CTX pCtx, const TCHAR *pszFormat, ...)
899#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
900 __attribute__ ((format(printf, 2, 3)))
901#endif
902;
532990d2 903void ConsoleWrite(CONSOLE_CTX pCtx, const TCHAR *text);
35f836fe 904int ProcessConsoleCommand(const TCHAR *pszCmdLine, CONSOLE_CTX pCtx);
5039dede
AK
905
906void SaveObjects(DB_HANDLE hdb);
ff6d2c5d
VK
907void NXCORE_EXPORTABLE ObjectTransactionStart();
908void NXCORE_EXPORTABLE ObjectTransactionEnd();
5039dede 909
ce7565e7 910void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query);
7dad92fb 911void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query, int bindCount, int *sqlTypes, const TCHAR **values);
967893bb 912void QueueIDataInsert(time_t timestamp, UINT32 nodeId, UINT32 dciId, const TCHAR *value);
76fcb995 913void QueueRawDciDataUpdate(time_t timestamp, UINT32 dciId, const TCHAR *rawValue, const TCHAR *transformedValue);
ce7565e7
VK
914void StartDBWriter();
915void StopDBWriter();
5039dede 916
ea50bc33
VK
917void PerfDataStorageRequest(DCItem *dci, time_t timestamp, const TCHAR *value);
918void PerfDataStorageRequest(DCTable *dci, time_t timestamp, Table *value);
919
b368969c 920void DecodeSQLStringAndSetVariable(NXCPMessage *pMsg, UINT32 dwVarId, TCHAR *pszStr);
5039dede 921
d0a2ada6 922SNMP_Transport *SnmpCheckCommSettings(UINT32 snmpProxy, const InetAddress& ipAddr, INT16 *version, UINT16 originalPort, SNMP_SecurityContext *originalContext, StringList *customTestOids);
35f836fe 923void StrToMac(const TCHAR *pszStr, BYTE *pBuffer);
5039dede 924
f42b8099 925void InitLocalNetInfo();
5039dede 926
f42b8099 927ARP_CACHE *GetLocalArpCache();
967893bb 928ARP_CACHE *SnmpGetArpCache(UINT32 dwVersion, SNMP_Transport *pTransport);
5039dede 929
98762401 930InterfaceList *GetLocalInterfaceList();
5039dede 931
967893bb 932ROUTING_TABLE *SnmpGetRoutingTable(UINT32 dwVersion, SNMP_Transport *pTransport);
5039dede 933
9796ce45 934void LoadNetworkDeviceDrivers();
21254a93 935NetworkDeviceDriver *FindDriverForNode(Node *node, SNMP_Transport *pTransport);
28e1575f 936NetworkDeviceDriver *FindDriverByName(const TCHAR *name);
1f4c37ee 937void AddDriverSpecificOids(StringList *list);
9796ce45 938
5ad2167d 939void WatchdogInit();
967893bb
VK
940UINT32 WatchdogAddThread(const TCHAR *szName, time_t tNotifyInterval);
941void WatchdogNotify(UINT32 dwId);
5039dede
AK
942void WatchdogPrintStatus(CONSOLE_CTX pCtx);
943
5ad2167d 944void CheckForMgmtNode();
c75e9ee4 945Node NXCORE_EXPORTABLE *PollNewNode(const InetAddress& ipAddr, UINT32 dwCreationFlags, WORD agentPort,
1050c826
VK
946 WORD snmpPort, const TCHAR *pszName, UINT32 dwProxyNode, UINT32 dwSNMPProxy, Cluster *pCluster,
947 UINT32 zoneId, bool doConfPoll, bool discoveredNode);
5039dede 948
b1e9b6b3 949void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg);
967893bb 950void NXCORE_EXPORTABLE NotifyClientSessions(UINT32 dwCode, UINT32 dwData);
32f372a5 951void NXCORE_EXPORTABLE NotifyClientGraphUpdate(NXCPMessage *update, UINT32 graphId);
64909a13 952int GetSessionCount(bool includeSystemAccount);
967893bb 953bool IsLoggedIn(UINT32 dwUserId);
5d9a9c84 954bool NXCORE_EXPORTABLE KillClientSession(int id);
5039dede 955
35f836fe 956void GetSysInfoStr(TCHAR *pszBuffer, int nMaxSize);
c30c0c0f 957InetAddress GetLocalIpAddr();
f7694811 958TCHAR *GetLocalHostName(TCHAR *buffer, size_t bufSize);
5039dede 959
35f836fe 960BOOL ExecCommand(TCHAR *pszCommand);
967893bb 961BOOL SendMagicPacket(UINT32 dwIpAddr, BYTE *pbMacAddr, int iNumPackets);
5039dede 962
35f836fe 963BOOL InitIdTable();
967893bb 964UINT32 CreateUniqueId(int iGroup);
35f836fe 965QWORD CreateUniqueEventId();
69bb7f47 966void SaveCurrentFreeId();
5039dede 967
35f836fe
VK
968void InitMailer();
969void ShutdownMailer();
970void NXCORE_EXPORTABLE PostMail(const TCHAR *pszRcpt, const TCHAR *pszSubject, const TCHAR *pszText);
5039dede 971
35f836fe
VK
972void InitSMSSender();
973void ShutdownSMSSender();
974void NXCORE_EXPORTABLE PostSMS(const TCHAR *pszRcpt, const TCHAR *pszText);
5039dede 975
35f836fe 976void InitTraps();
967893bb 977void SendTrapsToClient(ClientSession *pSession, UINT32 dwRqId);
b368969c 978void CreateTrapCfgMessage(NXCPMessage &msg);
967893bb
VK
979UINT32 CreateNewTrap(UINT32 *pdwTrapId);
980UINT32 CreateNewTrap(NXC_TRAP_CFG_ENTRY *pTrap);
b368969c 981UINT32 UpdateTrapFromMsg(NXCPMessage *pMsg);
967893bb 982UINT32 DeleteTrap(UINT32 dwId);
25a1e9d0 983void CreateTrapExportRecord(String &xml, UINT32 id);
967893bb
VK
984
985BOOL IsTableTool(UINT32 dwToolId);
986BOOL CheckObjectToolAccess(UINT32 dwToolId, UINT32 dwUserId);
987UINT32 ExecuteTableTool(UINT32 dwToolId, Node *pNode, UINT32 dwRqId, ClientSession *pSession);
988UINT32 DeleteObjectToolFromDB(UINT32 dwToolId);
6f8e39e5 989UINT32 ChangeObjectToolStatus(UINT32 toolId, bool enabled);
b368969c 990UINT32 UpdateObjectToolFromMessage(NXCPMessage *pMsg);
4c3cc965 991void CreateObjectToolExportRecord(String &xml, UINT32 id);
271e3971 992bool ImportObjectTool(ConfigEntry *config);
b576249a
VK
993UINT32 GetObjectToolsIntoMessage(NXCPMessage *msg, UINT32 userId, bool fullAccess);
994UINT32 GetObjectToolDetailsIntoMessage(UINT32 toolId, NXCPMessage *msg);
967893bb 995
234079c4
VK
996void ExecuteServerCommand(void *arg);
997
b368969c 998UINT32 ModifySummaryTable(NXCPMessage *msg, LONG *newId);
967893bb 999UINT32 DeleteSummaryTable(LONG tableId);
5389f7b0 1000Table *QuerySummaryTable(LONG tableId, SummaryTable *adHocDefinition, UINT32 baseObjectId, UINT32 userId, UINT32 *rcc);
2096c8f0 1001bool CreateSummaryTableExportRecord(INT32 id, String &xml);
c7a9d87c 1002bool ImportSummaryTable(ConfigEntry *config);
b4c2a628 1003
b368969c 1004void CreateMessageFromSyslogMsg(NXCPMessage *pMsg, NX_SYSLOG_RECORD *pRec);
4262c0dc 1005void ReinitializeSyslogParser();
5039dede
AK
1006
1007void EscapeString(String &str);
1008
ce7565e7 1009void InitAuditLog();
967893bb 1010void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, BOOL isSuccess, UINT32 userId,
2a964810 1011 const TCHAR *workstation, int sessionId, UINT32 objectId,
ce7565e7 1012 const TCHAR *format, ...);
88f2990c 1013
967893bb
VK
1014bool ValidateConfig(Config *config, UINT32 flags, TCHAR *errorText, int errorTextLen);
1015UINT32 ImportConfig(Config *config, UINT32 flags);
5039dede
AK
1016
1017#ifdef _WITH_ENCRYPTION
b368969c 1018X509 *CertificateFromLoginMessage(NXCPMessage *pMsg);
a50eaebe 1019BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChallenge,
967893bb 1020 BYTE *pSignature, UINT32 dwSigLen, int nMappingMethod,
a50eaebe 1021 const TCHAR *pszMappingData);
9796ce45 1022void ReloadCertificates();
5039dede
AK
1023#endif
1024
1025#ifndef _WIN32
1026THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL SignalHandler(void *);
1027#endif /* not _WIN32 */
1028
5d3459af
VK
1029void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX console);
1030void DumpClientSessions(CONSOLE_CTX console);
1031void DumpMobileDeviceSessions(CONSOLE_CTX console);
5d3459af
VK
1032void ShowServerStats(CONSOLE_CTX console);
1033void ShowQueueStats(CONSOLE_CTX console, Queue *pQueue, const TCHAR *pszName);
1034void ShowThreadPool(CONSOLE_CTX console, ThreadPool *p);
9f3db00f 1035LONG GetThreadPoolStat(ThreadPoolStat stat, const TCHAR *param, TCHAR *value);
5d3459af 1036void DumpProcess(CONSOLE_CTX console);
5039dede 1037
bd360fd5 1038GRAPH_ACL_ENTRY *LoadGraphACL(DB_HANDLE hdb, UINT32 graphId, int *pnACLSize);
9ad921e5 1039BOOL CheckGraphAccess(GRAPH_ACL_ENTRY *pACL, int nACLSize, UINT32 graphId, UINT32 graphUserId, UINT32 graphDesiredAccess);
fff23fae 1040UINT32 GetGraphAccessCheckResult(UINT32 graphId, UINT32 graphUserId);
9ad921e5 1041GRAPH_ACL_AND_ID IsGraphNameExists(const TCHAR *graphName);
7a4c94ee 1042
d00ad4c6 1043#if XMPP_SUPPORTED
098ef635 1044void SendXMPPMessage(const TCHAR *rcpt, const TCHAR *text);
d00ad4c6 1045#endif
244c65ef 1046
9fa031cd 1047/**
1048 * File monitoring
1049 */
1050struct MONITORED_FILE
1051{
1052 TCHAR fileName[MAX_PATH];
1053 ClientSession *session;
1054 UINT32 nodeID;
1055};
1056
1057class FileMonitoringList
1058{
1059private:
1060 MUTEX m_mutex;
1061 ObjectArray<MONITORED_FILE> m_monitoredFiles;
9fa031cd 1062
1063public:
1064 FileMonitoringList();
1065 ~FileMonitoringList();
e13420c1 1066 void addMonitoringFile(MONITORED_FILE *fileForAdd, Node *obj, AgentConnection *conn);
e2338033 1067 bool checkDuplicate(MONITORED_FILE *fileForAdd);
1068 ObjectArray<ClientSession>* findClientByFNameAndNodeID(const TCHAR *fileName, UINT32 nodeID);
9fa031cd 1069 bool removeMonitoringFile(MONITORED_FILE *fileForRemove);
1070 void removeDisconectedNode(UINT32 nodeId);
1071
1072private:
1073 void lock();
1074 void unlock();
1075};
1076
534e1b83
VK
1077/**
1078 * Global variables
1079 */
5039dede
AK
1080extern TCHAR NXCORE_EXPORTABLE g_szConfigFile[];
1081extern TCHAR NXCORE_EXPORTABLE g_szLogFile[];
967893bb
VK
1082extern UINT32 g_dwLogRotationMode;
1083extern UINT32 g_dwMaxLogSize;
1084extern UINT32 g_dwLogHistorySize;
4f8998ca 1085extern TCHAR g_szDailyLogFileSuffix[64];
5039dede
AK
1086extern TCHAR NXCORE_EXPORTABLE g_szDumpDir[];
1087extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
1088#ifndef _WIN32
1089extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
1090#endif
db6a6b45
VK
1091extern TCHAR NXCORE_EXPORTABLE g_netxmsdDataDir[];
1092extern TCHAR NXCORE_EXPORTABLE g_netxmsdLibDir[];
967893bb 1093extern UINT32 NXCORE_EXPORTABLE g_processAffinityMask;
e9902466 1094extern UINT64 g_serverId;
5039dede 1095extern RSA *g_pServerKey;
c59466d2
VK
1096extern UINT32 g_icmpPingSize;
1097extern UINT32 g_icmpPingTimeout;
1098extern UINT32 g_auditFlags;
1099extern time_t g_serverStartTime;
1100extern UINT32 g_lockTimeout;
1101extern UINT32 g_agentCommandTimeout;
1102extern UINT32 g_thresholdRepeatInterval;
1103extern int g_requiredPolls;
1104extern UINT32 g_slmPollingInterval;
5039dede 1105
b8c1ec69
VK
1106extern TCHAR g_szDbDriver[];
1107extern TCHAR g_szDbDrvParams[];
1108extern TCHAR g_szDbServer[];
1109extern TCHAR g_szDbLogin[];
1110extern TCHAR g_szDbPassword[];
1111extern TCHAR g_szDbName[];
f3c30cf5 1112extern TCHAR g_szDbSchema[];
b8c1ec69 1113extern DB_DRIVER g_dbDriver;
76fcb995
VK
1114extern Queue *g_dbWriterQueue;
1115extern Queue *g_dciDataWriterQueue;
1116extern Queue *g_dciRawDataWriterQueue;
6547a540
VK
1117extern UINT64 g_idataWriteRequests;
1118extern UINT64 g_rawDataWriteRequests;
1119extern UINT64 g_otherWriteRequests;
5039dede 1120
2a964810 1121extern int NXCORE_EXPORTABLE g_dbSyntax;
9fa031cd 1122extern FileMonitoringList g_monitoringList;
5039dede 1123
5d3459af
VK
1124extern ThreadPool *g_mainThreadPool;
1125
5039dede 1126#endif /* _nms_core_h_ */