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