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