- Implemented selection to show or not the toast notification.
[public/netxms.git] / src / server / include / nms_core.h
CommitLineData
5039dede
AK
1/*
2** NetXMS - Network Management System
6adc4a1a 3** Copyright (C) 2003-2012 Victor Kirhenshtein
5039dede
AK
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: nms_core.h
20**
21**/
22
23#ifndef _nms_core_h_
24#define _nms_core_h_
25
26#ifdef _WIN32
27#ifdef NXCORE_EXPORTS
28#define NXCORE_EXPORTABLE __declspec(dllexport)
29#else
30#define NXCORE_EXPORTABLE __declspec(dllimport)
31#endif
32#else /* _WIN32 */
33#define NXCORE_EXPORTABLE
34#endif
35
36#define LIBNXCL_NO_DECLARATIONS 1
37
38#include <nms_common.h>
39
40#ifndef _WIN32
41
42#if HAVE_SYS_TYPES_H
43# include <sys/types.h>
44#endif
45
46#if HAVE_DLFCN_H
47#include <dlfcn.h>
48#endif
49
50#define WSAGetLastError() (errno)
51
52#endif /* _WIN32 */
53
54#include <time.h>
55#include <stdio.h>
56#include <string.h>
57#include <stdarg.h>
58
59#define SHOW_FLAG_VALUE(x) _T(" %-32s = %d\n"), _T(#x), (g_dwFlags & x) ? 1 : 0
60
61
62//
63// Common includes
64//
65
66#include <nms_util.h>
67#include <dbdrv.h>
68#include <nms_cscp.h>
69#include <uuid.h>
70#include <nxsrvapi.h>
5039dede
AK
71#include <nxqueue.h>
72#include <nxsnmp.h>
73#include <nxmodule.h>
74#include <nxsl.h>
9d88cdc9 75#include <nxdbapi.h>
9796ce45 76#include <nddrv.h>
d41edbd3 77#include <nxcore_smclp.h>
5039dede
AK
78
79
80//
81// Console context
82//
83
84struct __console_ctx
85{
86 SOCKET hSocket;
d3a7cf4c 87 MUTEX socketMutex;
5039dede 88 CSCPMessage *pMsg;
200d662d 89 ClientSession *session;
5039dede
AK
90};
91
92typedef __console_ctx * CONSOLE_CTX;
93
94
95//
96// Server includes
97//
98
99#include "nms_dcoll.h"
100#include "nms_users.h"
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"
5039dede
AK
109
110
111//
112// Common constants and macros
113//
114
73869331
VK
115#define MAX_LINE_SIZE 4096
116#define GROUP_FLAG_BIT ((DWORD)0x80000000)
117#define CHECKPOINT_SNMP_PORT 260
118#define DEFAULT_AFFINITY_MASK 0xFFFFFFFF
5039dede
AK
119
120typedef void * HSNMPSESSION;
121
5039dede 122
df8a4ca2
VK
123//
124// Prefixes for poller messages
125//
126
127#define POLLER_ERROR _T("\x7F") _T("e")
128#define POLLER_WARNING _T("\x7Fw")
129#define POLLER_INFO _T("\x7Fi")
130
131
5039dede
AK
132//
133// Unique identifier group codes
134//
135
136#define IDG_NETWORK_OBJECT 0
137#define IDG_CONTAINER_CAT 1
138#define IDG_EVENT 2
139#define IDG_ITEM 3
140#define IDG_SNMP_TRAP 4
24dc5346 141#define IDG_JOB 5
5039dede
AK
142#define IDG_ACTION 6
143#define IDG_EVENT_GROUP 7
144#define IDG_THRESHOLD 8
145#define IDG_USER 9
146#define IDG_USER_GROUP 10
147#define IDG_ALARM 11
148#define IDG_ALARM_NOTE 12
149#define IDG_PACKAGE 13
636e0c72 150#define IDG_SLM_TICKET 14
5039dede
AK
151#define IDG_OBJECT_TOOL 15
152#define IDG_SCRIPT 16
153#define IDG_AGENT_CONFIG 17
154#define IDG_GRAPH 18
155#define IDG_CERTIFICATE 19
156#define IDG_SITUATION 20
ba89fed2 157#define IDG_DCT_COLUMN 21
5039dede
AK
158
159
160//
161// Exit codes for console commands
162//
163
164#define CMD_EXIT_CONTINUE 0
165#define CMD_EXIT_CLOSE_SESSION 1
166#define CMD_EXIT_SHUTDOWN 2
167
168
169//
170// Network discovery mode
171//
172
173#define DISCOVERY_DISABLED 0
174#define DISCOVERY_PASSIVE_ONLY 1
175#define DISCOVERY_ACTIVE 2
176
177
178//
179// Client session flags
180//
181
5039dede
AK
182#define CSF_EPP_LOCKED ((DWORD)0x0002)
183#define CSF_PACKAGE_DB_LOCKED ((DWORD)0x0004)
184#define CSF_USER_DB_LOCKED ((DWORD)0x0008)
185#define CSF_EPP_UPLOAD ((DWORD)0x0010)
200d662d 186#define CSF_CONSOLE_OPEN ((DWORD)0x0020)
5039dede 187#define CSF_AUTHENTICATED ((DWORD)0x0080)
5039dede
AK
188#define CSF_RECEIVING_MAP_DATA ((DWORD)0x0200)
189#define CSF_SYNC_OBJECT_COMMENTS ((DWORD)0x0400)
190
191
192//
193// Client session states
194//
195
196#define SESSION_STATE_INIT 0
197#define SESSION_STATE_IDLE 1
198#define SESSION_STATE_PROCESSING 2
199
200
201//
202// Information categories for UPDATE_INFO structure
203//
204
205#define INFO_CAT_EVENT 1
206#define INFO_CAT_OBJECT_CHANGE 2
207#define INFO_CAT_ALARM 3
208#define INFO_CAT_ACTION 4
209#define INFO_CAT_SYSLOG_MSG 5
210#define INFO_CAT_SNMP_TRAP 6
211#define INFO_CAT_AUDIT_RECORD 7
212#define INFO_CAT_SITUATION 8
624f1165 213#define INFO_CAT_LIBRARY_IMAGE 9
5039dede
AK
214
215
216//
217// Certificate types
218//
219
220#define CERT_TYPE_TRUSTED_CA 0
221#define CERT_TYPE_USER 1
222
223
224//
225// Audit subsystems
226//
227
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
233
234//
235// Event handling subsystem definitions
236//
237
238#include "nms_events.h"
239#include "nms_actions.h"
240#include "nms_alarm.h"
241
242
243//
244// New node information
245//
246
247typedef struct
248{
249 DWORD dwIpAddr;
250 DWORD dwNetMask;
dc25b21c 251 DWORD zoneId;
5039dede
AK
252 BOOL ignoreFilter;
253} NEW_NODE;
254
255
256//
257// New node flags
258//
259
260#define NNF_IS_SNMP 0x0001
261#define NNF_IS_AGENT 0x0002
262#define NNF_IS_ROUTER 0x0004
263#define NNF_IS_BRIDGE 0x0008
264#define NNF_IS_PRINTER 0x0010
265#define NNF_IS_CDP 0x0020
266#define NNF_IS_SONMP 0x0040
267#define NNF_IS_LLDP 0x0080
268
269
270//
271// Node information for autodiscovery filter
272//
273
274typedef struct
275{
276 DWORD dwIpAddr;
277 DWORD dwNetMask;
278 DWORD dwSubnetAddr;
279 DWORD dwFlags;
280 int nSNMPVersion;
35f836fe
VK
281 TCHAR szObjectId[MAX_OID_LEN * 4]; // SNMP OID
282 TCHAR szAgentVersion[MAX_AGENT_VERSION_LEN];
283 TCHAR szPlatform[MAX_PLATFORM_NAME_LEN];
5039dede
AK
284} DISCOVERY_FILTER_DATA;
285
286
287//
288// Data update structure for client sessions
289//
290
291typedef struct
292{
293 DWORD dwCategory; // Data category - event, network object, etc.
294 DWORD dwCode; // Data-specific update code
295 void *pData; // Pointer to data block
296} UPDATE_INFO;
297
298
299//
300// Extended agent connection
301//
302
303class AgentConnectionEx : public AgentConnection
304{
305protected:
f480bdd4
VK
306 virtual void onTrap(CSCPMessage *msg);
307 virtual void onDataPush(CSCPMessage *msg);
5039dede
AK
308
309public:
5039dede
AK
310 AgentConnectionEx(DWORD dwAddr, WORD wPort = AGENT_LISTEN_PORT,
311 int iAuthMethod = AUTH_NONE, TCHAR *pszSecret = NULL) :
312 AgentConnection(dwAddr, wPort, iAuthMethod, pszSecret) { }
313 virtual ~AgentConnectionEx();
45d84f8a
VK
314
315 DWORD deployPolicy(AgentPolicy *policy);
93599cfd 316 DWORD uninstallPolicy(AgentPolicy *policy);
5039dede
AK
317};
318
319
320//
321// Client session
322//
323
324#define DECLARE_THREAD_STARTER(func) static THREAD_RESULT THREAD_CALL ThreadStarter_##func(void *);
325
a0e3917e 326class NXCORE_EXPORTABLE ClientSession
5039dede
AK
327{
328private:
329 SOCKET m_hSocket;
330 Queue *m_pSendQueue;
331 Queue *m_pMessageQueue;
332 Queue *m_pUpdateQueue;
333 DWORD m_dwIndex;
334 int m_iState;
335 WORD m_wCurrentCmd;
336 DWORD m_dwUserId;
337 DWORD m_dwSystemAccess; // User's system access rights
338 DWORD m_dwFlags; // Session flags
339 CSCP_BUFFER *m_pMsgBuffer;
98abc9f1 340 NXCPEncryptionContext *m_pCtx;
5039dede
AK
341 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
342 THREAD m_hWriteThread;
343 THREAD m_hProcessingThread;
344 THREAD m_hUpdateThread;
d3a7cf4c 345 MUTEX m_mutexSocketWrite;
5039dede
AK
346 MUTEX m_mutexSendEvents;
347 MUTEX m_mutexSendSyslog;
348 MUTEX m_mutexSendTrapLog;
349 MUTEX m_mutexSendObjects;
350 MUTEX m_mutexSendAlarms;
351 MUTEX m_mutexSendActions;
352 MUTEX m_mutexSendAuditLog;
353 MUTEX m_mutexSendSituations;
354 MUTEX m_mutexPollerInit;
60557d06
VK
355 struct sockaddr *m_clientAddr;
356 TCHAR m_szWorkstation[256]; // IP address of name of conneced host in textual form
5039dede
AK
357 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
358 TCHAR m_szClientInfo[96]; // Client app info string
359 DWORD m_dwOpenDCIListSize; // Number of open DCI lists
360 DWORD *m_pOpenDCIList; // List of nodes with DCI lists open
361 DWORD m_dwNumRecordsToUpload; // Number of records to be uploaded
362 DWORD m_dwRecordsUploaded;
363 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
364 int m_hCurrFile;
365 DWORD m_dwFileRqId;
366 DWORD m_dwUploadCommand;
367 DWORD m_dwUploadData;
368 TCHAR m_szCurrFileName[MAX_PATH];
369 DWORD m_dwRefCount;
370 DWORD m_dwEncryptionRqId;
371 DWORD m_dwEncryptionResult;
372 CONDITION m_condEncryptionSetup;
373 DWORD m_dwActiveChannels; // Active data channels
200d662d 374 CONSOLE_CTX m_console; // Server console context
5039dede
AK
375
376 static THREAD_RESULT THREAD_CALL ReadThreadStarter(void *);
377 static THREAD_RESULT THREAD_CALL WriteThreadStarter(void *);
378 static THREAD_RESULT THREAD_CALL ProcessingThreadStarter(void *);
379 static THREAD_RESULT THREAD_CALL UpdateThreadStarter(void *);
380 static THREAD_RESULT THREAD_CALL PollerThreadStarter(void *);
381
382 DECLARE_THREAD_STARTER(GetCollectedData)
383 DECLARE_THREAD_STARTER(ClearDCIData)
adac28be
VK
384 DECLARE_THREAD_STARTER(queryParameter)
385 DECLARE_THREAD_STARTER(queryAgentTable)
5039dede
AK
386 DECLARE_THREAD_STARTER(QueryL2Topology)
387 DECLARE_THREAD_STARTER(SendEventLog)
388 DECLARE_THREAD_STARTER(SendSyslog)
1da08bc6
VK
389 DECLARE_THREAD_STARTER(createObject)
390 DECLARE_THREAD_STARTER(getServerFile)
6f16f12d 391 DECLARE_THREAD_STARTER(getAgentFile)
e05b1945
VK
392 DECLARE_THREAD_STARTER(queryServerLog)
393 DECLARE_THREAD_STARTER(getServerLogQueryData)
e31c8e60 394 DECLARE_THREAD_STARTER(executeAction)
630e15d6 395 DECLARE_THREAD_STARTER(findNodeConnection)
06a93345 396 DECLARE_THREAD_STARTER(findMacAddress)
200d662d 397 DECLARE_THREAD_STARTER(processConsoleCommand)
b08d31f4 398 DECLARE_THREAD_STARTER(sendMib)
e12e1422 399 DECLARE_THREAD_STARTER(getReportResults)
3932fde6 400 DECLARE_THREAD_STARTER(deleteReportResults)
e12e1422 401 DECLARE_THREAD_STARTER(renderReport)
6d069676 402 DECLARE_THREAD_STARTER(getNetworkPath)
5039dede 403
62768df3
VK
404 void readThread();
405 void writeThread();
406 void processingThread();
407 void updateThread();
408 void pollerThread(Node *pNode, int iPollType, DWORD dwRqId);
5039dede 409
e05b1945 410 void setupEncryption(DWORD dwRqId);
5039dede 411 void RespondToKeepalive(DWORD dwRqId);
e05b1945 412 void onFileUpload(BOOL bSuccess);
5039dede
AK
413 void DebugPrintf(int level, const TCHAR *format, ...);
414 void SendServerInfo(DWORD dwRqId);
415 void Login(CSCPMessage *pRequest);
62768df3
VK
416 void sendAllObjects(CSCPMessage *pRequest);
417 void sendSelectedObjects(CSCPMessage *pRequest);
5039dede
AK
418 void SendEventLog(CSCPMessage *pRequest);
419 void SendAllConfigVars(DWORD dwRqId);
420 void SetConfigVariable(CSCPMessage *pRequest);
421 void DeleteConfigVariable(CSCPMessage *pRequest);
422 void SendUserDB(DWORD dwRqId);
1add6d73 423 void sendAllAlarms(DWORD dwRqId);
5039dede
AK
424 void CreateUser(CSCPMessage *pRequest);
425 void UpdateUser(CSCPMessage *pRequest);
426 void DeleteUser(CSCPMessage *pRequest);
427 void SetPassword(CSCPMessage *pRequest);
428 void LockUserDB(DWORD dwRqId, BOOL bLock);
8eb2d92b
VK
429 void sendEventDB(DWORD dwRqId);
430 void modifyEventTemplate(CSCPMessage *pRequest);
431 void deleteEventTemplate(CSCPMessage *pRequest);
432 void generateEventCode(DWORD dwRqId);
5039dede 433 void ModifyObject(CSCPMessage *pRequest);
1da08bc6 434 void changeObjectMgmtStatus(CSCPMessage *pRequest);
5039dede
AK
435 void OpenNodeDCIList(CSCPMessage *pRequest);
436 void CloseNodeDCIList(CSCPMessage *pRequest);
437 void ModifyNodeDCI(CSCPMessage *pRequest);
438 void CopyDCI(CSCPMessage *pRequest);
439 void ApplyTemplate(CSCPMessage *pRequest);
440 void GetCollectedData(CSCPMessage *pRequest);
441 void ClearDCIData(CSCPMessage *pRequest);
442 void ChangeDCIStatus(CSCPMessage *pRequest);
b9a8e081
VK
443 void getLastValues(CSCPMessage *pRequest);
444 void getTableLastValues(CSCPMessage *pRequest);
5039dede
AK
445 void OpenEPP(DWORD dwRqId);
446 void CloseEPP(DWORD dwRqId);
447 void SaveEPP(CSCPMessage *pRequest);
448 void ProcessEPPRecord(CSCPMessage *pRequest);
449 void SendMIBTimestamp(DWORD dwRqId);
b08d31f4 450 void sendMib(CSCPMessage *request);
1da08bc6
VK
451 void createObject(CSCPMessage *pRequest);
452 void changeObjectBinding(CSCPMessage *pRequest, BOOL bBind);
f5d16551 453 void deleteObject(CSCPMessage *pRequest);
4d00760d 454 void getAlarm(CSCPMessage *pRequest);
1add6d73
VK
455 void acknowledgeAlarm(CSCPMessage *pRequest);
456 void terminateAlarm(CSCPMessage *pRequest);
457 void deleteAlarm(CSCPMessage *pRequest);
1b94acbf
VK
458 void getAlarmNotes(CSCPMessage *pRequest);
459 void updateAlarmNote(CSCPMessage *pRequest);
460 void createAction(CSCPMessage *pRequest);
461 void updateAction(CSCPMessage *pRequest);
462 void deleteAction(CSCPMessage *pRequest);
463 void sendAllActions(DWORD dwRqId);
5039dede
AK
464 void SendContainerCategories(DWORD dwRqId);
465 void ForcedNodePoll(CSCPMessage *pRequest);
466 void OnTrap(CSCPMessage *pRequest);
467 void OnWakeUpNode(CSCPMessage *pRequest);
adac28be
VK
468 void queryParameter(CSCPMessage *pRequest);
469 void queryAgentTable(CSCPMessage *pRequest);
5039dede
AK
470 void EditTrap(int iOperation, CSCPMessage *pRequest);
471 void LockTrapCfg(DWORD dwRqId, BOOL bLock);
472 void SendAllTraps(DWORD dwRqId);
473 void SendAllTraps2(DWORD dwRqId);
474 void LockPackageDB(DWORD dwRqId, BOOL bLock);
475 void SendAllPackages(DWORD dwRqId);
476 void InstallPackage(CSCPMessage *pRequest);
477 void RemovePackage(CSCPMessage *pRequest);
478 void DeployPackage(CSCPMessage *pRequest);
479 void SendParametersList(CSCPMessage *pRequest);
480 void GetUserVariable(CSCPMessage *pRequest);
481 void SetUserVariable(CSCPMessage *pRequest);
482 void CopyUserVariable(CSCPMessage *pRequest);
483 void EnumUserVariables(CSCPMessage *pRequest);
484 void DeleteUserVariable(CSCPMessage *pRequest);
4c789f9e 485 void changeObjectZone(CSCPMessage *pRequest);
5039dede
AK
486 void GetAgentConfig(CSCPMessage *pRequest);
487 void UpdateAgentConfig(CSCPMessage *pRequest);
e31c8e60 488 void executeAction(CSCPMessage *pRequest);
0e950f45
VK
489 void sendObjectTools(DWORD dwRqId);
490 void sendObjectToolDetails(CSCPMessage *pRequest);
491 void updateObjectTool(CSCPMessage *pRequest);
492 void deleteObjectTool(CSCPMessage *pRequest);
493 void generateObjectToolId(DWORD dwRqId);
494 void execTableTool(CSCPMessage *pRequest);
5039dede
AK
495 void ChangeSubscription(CSCPMessage *pRequest);
496 void SendSyslog(CSCPMessage *pRequest);
5039dede 497 void SendServerStats(DWORD dwRqId);
0c7aca90
VK
498 void sendScriptList(DWORD dwRqId);
499 void sendScript(CSCPMessage *pRequest);
500 void updateScript(CSCPMessage *pRequest);
501 void renameScript(CSCPMessage *pRequest);
502 void deleteScript(CSCPMessage *pRequest);
5039dede
AK
503 void SendSessionList(DWORD dwRqId);
504 void KillSession(CSCPMessage *pRequest);
505 void SendTrapLog(CSCPMessage *pRequest);
506 void StartSnmpWalk(CSCPMessage *pRequest);
5039dede
AK
507 void ResolveDCINames(CSCPMessage *pRequest);
508 DWORD ResolveDCIName(DWORD dwNode, DWORD dwItem, TCHAR **ppszName);
509 void SendConfigForAgent(CSCPMessage *pRequest);
510 void SendAgentCfgList(DWORD dwRqId);
511 void OpenAgentConfig(CSCPMessage *pRequest);
512 void SaveAgentConfig(CSCPMessage *pRequest);
513 void DeleteAgentConfig(CSCPMessage *pRequest);
514 void SwapAgentConfigs(CSCPMessage *pRequest);
515 void SendObjectComments(CSCPMessage *pRequest);
516 void UpdateObjectComments(CSCPMessage *pRequest);
517 void PushDCIData(CSCPMessage *pRequest);
518 void GetAddrList(CSCPMessage *pRequest);
519 void SetAddrList(CSCPMessage *pRequest);
520 void ResetComponent(CSCPMessage *pRequest);
7a46028e 521 void sendDCIEventList(CSCPMessage *request);
5039dede 522 void SendDCIInfo(CSCPMessage *pRequest);
74526d25 523 void sendPerfTabDCIList(CSCPMessage *pRequest);
a7ff20a5
VK
524 void exportConfiguration(CSCPMessage *pRequest);
525 void importConfiguration(CSCPMessage *pRequest);
5039dede
AK
526 void SendGraphList(DWORD dwRqId);
527 void DefineGraph(CSCPMessage *pRequest);
528 void DeleteGraph(CSCPMessage *pRequest);
529 void AddCACertificate(CSCPMessage *pRequest);
530 void DeleteCertificate(CSCPMessage *pRequest);
531 void UpdateCertificateComments(CSCPMessage *pRequest);
532 void SendCertificateList(DWORD dwRqId);
533 void QueryL2Topology(CSCPMessage *pRequest);
534 void SendSMS(CSCPMessage *pRequest);
535 void SendCommunityList(DWORD dwRqId);
536 void UpdateCommunityList(CSCPMessage *pRequest);
537 void SendSituationList(DWORD dwRqId);
538 void CreateSituation(CSCPMessage *pRequest);
539 void UpdateSituation(CSCPMessage *pRequest);
540 void DeleteSituation(CSCPMessage *pRequest);
541 void DeleteSituationInstance(CSCPMessage *pRequest);
1da08bc6
VK
542 void setConfigCLOB(CSCPMessage *pRequest);
543 void getConfigCLOB(CSCPMessage *pRequest);
1da08bc6
VK
544 void registerAgent(CSCPMessage *pRequest);
545 void getServerFile(CSCPMessage *pRequest);
6f16f12d 546 void getAgentFile(CSCPMessage *pRequest);
1da08bc6 547 void testDCITransformation(CSCPMessage *pRequest);
45d84f8a
VK
548 void sendJobList(DWORD dwRqId);
549 void cancelJob(CSCPMessage *pRequest);
8d9f7450
VK
550 void holdJob(CSCPMessage *pRequest);
551 void unholdJob(CSCPMessage *pRequest);
93599cfd 552 void deployAgentPolicy(CSCPMessage *pRequest, bool uninstallFlag);
d83dc1f0
VK
553 void getUserCustomAttribute(CSCPMessage *request);
554 void setUserCustomAttribute(CSCPMessage *request);
e05b1945
VK
555 void openServerLog(CSCPMessage *request);
556 void closeServerLog(CSCPMessage *request);
557 void queryServerLog(CSCPMessage *request);
558 void getServerLogQueryData(CSCPMessage *request);
df8a4ca2
VK
559 void sendUsmCredentials(DWORD dwRqId);
560 void updateUsmCredentials(CSCPMessage *pRequest);
071fd171 561 void sendDCIThresholds(CSCPMessage *request);
1da08bc6 562 void addClusterNode(CSCPMessage *request);
630e15d6 563 void findNodeConnection(CSCPMessage *request);
06a93345 564 void findMacAddress(CSCPMessage *request);
e6b9439a
AK
565 void sendLibraryImage(CSCPMessage *request);
566 void updateLibraryImage(CSCPMessage *request);
567 void listLibraryImages(CSCPMessage *request);
568 void deleteLibraryImage(CSCPMessage *request);
f69c6203 569 void executeServerCommand(CSCPMessage *request);
619e5c9b 570 void uploadFileToAgent(CSCPMessage *request);
1a5e0c22 571 void listServerFileStore(CSCPMessage *request);
200d662d
VK
572 void processConsoleCommand(CSCPMessage *msg);
573 void openConsole(DWORD rqId);
574 void closeConsole(DWORD rqId);
7f632dfe 575 void getVlans(CSCPMessage *msg);
68f898c9
VK
576 void receiveFile(CSCPMessage *request);
577 void deleteFile(CSCPMessage *request);
8c5b6ed3
VK
578 void executeReport(CSCPMessage *msg);
579 void getReportResults(CSCPMessage *msg);
3932fde6 580 void deleteReportResults(CSCPMessage *msg);
e12e1422 581 void renderReport(CSCPMessage *request);
6d069676 582 void getNetworkPath(CSCPMessage *request);
8836184f 583 void getNodeComponents(CSCPMessage *request);
5039dede
AK
584
585public:
60557d06 586 ClientSession(SOCKET hSocket, struct sockaddr *addr);
5039dede
AK
587 ~ClientSession();
588
e05b1945
VK
589 void incRefCount() { m_dwRefCount++; }
590 void decRefCount() { if (m_dwRefCount > 0) m_dwRefCount--; }
591
592 void run();
593
d3a7cf4c
VK
594 void postMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->CreateMessage()); }
595 void sendMessage(CSCPMessage *pMsg);
e05b1945
VK
596 void sendPollerMsg(DWORD dwRqId, const TCHAR *pszMsg);
597 BOOL sendFile(const TCHAR *file, DWORD dwRqId);
598
f669df41 599 DWORD getIndex() { return m_dwIndex; }
e05b1945 600 void setIndex(DWORD dwIndex) { if (m_dwIndex == INVALID_INDEX) m_dwIndex = dwIndex; }
f669df41 601 int getState() { return m_iState; }
889d7ff7
VK
602 const TCHAR *getUserName() { return m_szUserName; }
603 const TCHAR *getClientInfo() { return m_szClientInfo; }
604 const TCHAR *getWorkstation() { return m_szWorkstation; }
e05b1945
VK
605 DWORD getUserId() { return m_dwUserId; }
606 DWORD getSystemRights() { return m_dwSystemAccess; }
f669df41
VK
607 bool isAuthenticated() { return (m_dwFlags & CSF_AUTHENTICATED) ? true : false; }
608 bool isConsoleOpen() { return (m_dwFlags & CSF_CONSOLE_OPEN) ? true : false; }
609 bool isSubscribed(DWORD dwChannel) { return (m_dwActiveChannels & dwChannel) ? true : false; }
610 WORD getCurrentCmd() { return m_wCurrentCmd; }
98abc9f1 611 int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
e05b1945
VK
612
613 bool checkSysAccessRights(DWORD requiredAccess)
614 {
615 return m_dwUserId == 0 ? true :
616 ((requiredAccess & m_dwSystemAccess) ? true : false);
617 }
618
f669df41 619 void kill();
e05b1945
VK
620 void notify(DWORD dwCode, DWORD dwData = 0);
621
622 void queueUpdate(UPDATE_INFO *pUpdate) { m_pUpdateQueue->Put(pUpdate); }
623 void onNewEvent(Event *pEvent);
e0f99bf0 624 void onSyslogMessage(NX_SYSLOG_RECORD *pRec);
e05b1945
VK
625 void onNewSNMPTrap(CSCPMessage *pMsg);
626 void onObjectChange(NetObj *pObject);
627 void onUserDBUpdate(int code, DWORD id, UserDatabaseObject *user);
628 void onAlarmUpdate(DWORD dwCode, NXC_ALARM *pAlarm);
629 void onActionDBUpdate(DWORD dwCode, NXC_ACTION *pAction);
630 void onSituationChange(CSCPMessage *msg);
624f1165 631 void onLibraryImageChange(uuid_t *guid);
5039dede
AK
632};
633
634
7dad92fb
VK
635//
636// Delayed SQL request
637//
638
639typedef struct
640{
641 TCHAR *query;
642 int bindCount;
643 BYTE *sqlTypes;
644 TCHAR *bindings[1]; /* actual size determined by bindCount field */
645} DELAYED_SQL_REQUEST;
646
647
f68d9eac
VK
648//
649// Delayed request for idata_ INSERT
650//
651
652typedef struct
653{
654 time_t timestamp;
655 DWORD nodeId;
656 DWORD dciId;
657 TCHAR value[MAX_RESULT_LENGTH];
658} DELAYED_IDATA_INSERT;
659
660
5039dede
AK
661//
662// Functions
663//
664
35f836fe
VK
665BOOL NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
666#ifdef UNICODE
667BOOL NXCORE_EXPORTABLE ConfigReadStrA(const WCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
668#else
669#define ConfigReadStrA ConfigReadStr
670#endif
5039dede
AK
671int NXCORE_EXPORTABLE ConfigReadInt(const TCHAR *szVar, int iDefault);
672DWORD NXCORE_EXPORTABLE ConfigReadULong(const TCHAR *szVar, DWORD dwDefault);
673BOOL NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray,
674 int nSize, int nDefault);
675BOOL NXCORE_EXPORTABLE ConfigWriteStr(const TCHAR *szVar, const TCHAR *szValue, BOOL bCreate,
676 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
677BOOL NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, BOOL bCreate,
678 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
679BOOL NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, DWORD dwValue, BOOL bCreate,
680 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
681BOOL NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray,
682 int nSize, BOOL bCreate,
683 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
684TCHAR NXCORE_EXPORTABLE *ConfigReadCLOB(const TCHAR *var, const TCHAR *defValue);
685BOOL NXCORE_EXPORTABLE ConfigWriteCLOB(const TCHAR *var, const TCHAR *value, BOOL bCreate);
686
28f5b9a4
VK
687BOOL NXCORE_EXPORTABLE MetaDataReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
688
35f836fe 689BOOL NXCORE_EXPORTABLE LoadConfig();
5039dede 690
35f836fe
VK
691void NXCORE_EXPORTABLE Shutdown();
692void NXCORE_EXPORTABLE FastShutdown();
693BOOL NXCORE_EXPORTABLE Initialize();
5039dede 694THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *);
35f836fe
VK
695void NXCORE_EXPORTABLE ShutdownDB();
696void InitiateShutdown();
5039dede
AK
697
698BOOL NXCORE_EXPORTABLE SleepAndCheckForShutdown(int iSeconds);
699
35f836fe
VK
700void ConsolePrintf(CONSOLE_CTX pCtx, const TCHAR *pszFormat, ...);
701int ProcessConsoleCommand(const TCHAR *pszCmdLine, CONSOLE_CTX pCtx);
5039dede
AK
702
703void SaveObjects(DB_HANDLE hdb);
704
ce7565e7 705void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query);
7dad92fb 706void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query, int bindCount, int *sqlTypes, const TCHAR **values);
f68d9eac 707void QueueIDataInsert(time_t timestamp, DWORD nodeId, DWORD dciId, const TCHAR *value);
ce7565e7
VK
708void StartDBWriter();
709void StopDBWriter();
5039dede 710
ba89fed2
VK
711bool NXCORE_EXPORTABLE IsDatabaseRecordExist(DB_HANDLE hdb, TCHAR *table, const TCHAR *idColumn, DWORD id);
712
5039dede
AK
713void DecodeSQLStringAndSetVariable(CSCPMessage *pMsg, DWORD dwVarId, TCHAR *pszStr);
714
df8a4ca2 715SNMP_SecurityContext *SnmpCheckCommSettings(SNMP_Transport *pTransport, int *version, SNMP_SecurityContext *originalContext);
35f836fe 716void StrToMac(const TCHAR *pszStr, BYTE *pBuffer);
5039dede 717
f42b8099 718void InitLocalNetInfo();
5039dede 719
f42b8099 720ARP_CACHE *GetLocalArpCache();
5d2c5741 721ARP_CACHE *SnmpGetArpCache(DWORD dwVersion, SNMP_Transport *pTransport);
5039dede 722
98762401 723InterfaceList *GetLocalInterfaceList();
5d2c5741 724int SnmpGetInterfaceStatus(DWORD dwVersion, SNMP_Transport *pTransport, DWORD dwIfIndex);
5039dede 725
5d2c5741 726ROUTING_TABLE *SnmpGetRoutingTable(DWORD dwVersion, SNMP_Transport *pTransport);
5039dede 727
9796ce45 728void LoadNetworkDeviceDrivers();
21254a93 729NetworkDeviceDriver *FindDriverForNode(Node *node, SNMP_Transport *pTransport);
9796ce45 730
5ad2167d 731void WatchdogInit();
5039dede
AK
732DWORD WatchdogAddThread(const TCHAR *szName, time_t tNotifyInterval);
733void WatchdogNotify(DWORD dwId);
734void WatchdogPrintStatus(CONSOLE_CTX pCtx);
735
5ad2167d 736void CheckForMgmtNode();
07f6978d 737Node *PollNewNode(DWORD dwIpAddr, DWORD dwNetMask, DWORD dwCreationFlags,
588f7351 738 TCHAR *pszName, DWORD dwProxyNode, DWORD dwSNMPProxy, Cluster *pCluster,
a749a70a 739 DWORD zoneId, bool doConfPoll, bool discoveredNode);
5039dede
AK
740
741void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg);
742void NXCORE_EXPORTABLE NotifyClientSessions(DWORD dwCode, DWORD dwData);
5ad2167d 743int GetSessionCount();
5039dede 744
35f836fe
VK
745void GetSysInfoStr(TCHAR *pszBuffer, int nMaxSize);
746DWORD GetLocalIpAddr();
f7694811 747TCHAR *GetLocalHostName(TCHAR *buffer, size_t bufSize);
5039dede 748
35f836fe 749BOOL ExecCommand(TCHAR *pszCommand);
5039dede
AK
750BOOL SendMagicPacket(DWORD dwIpAddr, BYTE *pbMacAddr, int iNumPackets);
751
35f836fe 752BOOL InitIdTable();
5039dede 753DWORD CreateUniqueId(int iGroup);
35f836fe 754QWORD CreateUniqueEventId();
5039dede 755
35f836fe
VK
756void InitMailer();
757void ShutdownMailer();
758void NXCORE_EXPORTABLE PostMail(const TCHAR *pszRcpt, const TCHAR *pszSubject, const TCHAR *pszText);
5039dede 759
35f836fe
VK
760void InitSMSSender();
761void ShutdownSMSSender();
762void NXCORE_EXPORTABLE PostSMS(const TCHAR *pszRcpt, const TCHAR *pszText);
5039dede 763
35f836fe 764void InitTraps();
5039dede
AK
765void SendTrapsToClient(ClientSession *pSession, DWORD dwRqId);
766void CreateTrapCfgMessage(CSCPMessage &msg);
767DWORD CreateNewTrap(DWORD *pdwTrapId);
768DWORD CreateNewTrap(NXC_TRAP_CFG_ENTRY *pTrap);
769DWORD UpdateTrapFromMsg(CSCPMessage *pMsg);
770DWORD DeleteTrap(DWORD dwId);
771void CreateNXMPTrapRecord(String &str, DWORD dwId);
772
773BOOL IsTableTool(DWORD dwToolId);
774BOOL CheckObjectToolAccess(DWORD dwToolId, DWORD dwUserId);
775DWORD ExecuteTableTool(DWORD dwToolId, Node *pNode, DWORD dwRqId, ClientSession *pSession);
776DWORD DeleteObjectToolFromDB(DWORD dwToolId);
777DWORD UpdateObjectToolFromMessage(CSCPMessage *pMsg);
778
e0f99bf0 779void CreateMessageFromSyslogMsg(CSCPMessage *pMsg, NX_SYSLOG_RECORD *pRec);
4262c0dc 780void ReinitializeSyslogParser();
5039dede
AK
781
782void EscapeString(String &str);
783
ce7565e7
VK
784void InitAuditLog();
785void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, BOOL isSuccess, DWORD userId,
786 const TCHAR *workstation, DWORD objectId,
787 const TCHAR *format, ...);
5039dede 788
a65c1819
VK
789bool ValidateConfig(Config *config, DWORD flags, TCHAR *errorText, int errorTextLen);
790DWORD ImportConfig(Config *config, DWORD flags);
5039dede
AK
791
792#ifdef _WITH_ENCRYPTION
793X509 *CertificateFromLoginMessage(CSCPMessage *pMsg);
a50eaebe 794BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChallenge,
5039dede 795 BYTE *pSignature, DWORD dwSigLen, int nMappingMethod,
a50eaebe 796 const TCHAR *pszMappingData);
9796ce45 797void ReloadCertificates();
5039dede
AK
798#endif
799
800#ifndef _WIN32
801THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL SignalHandler(void *);
802#endif /* not _WIN32 */
803
5039dede
AK
804void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX pCtx);
805void DumpSessions(CONSOLE_CTX pCtx);
806void ShowPollerState(CONSOLE_CTX pCtx);
35f836fe 807void SetPollerInfo(int nIdx, const TCHAR *pszMsg);
5039dede 808void ShowServerStats(CONSOLE_CTX pCtx);
35f836fe 809void ShowQueueStats(CONSOLE_CTX pCtx, Queue *pQueue, const TCHAR *pszName);
5039dede
AK
810void DumpProcess(CONSOLE_CTX pCtx);
811
812
813//
814// Global variables
815//
816
817extern TCHAR NXCORE_EXPORTABLE g_szConfigFile[];
818extern TCHAR NXCORE_EXPORTABLE g_szLogFile[];
4f8998ca
VK
819extern DWORD g_dwLogRotationMode;
820extern DWORD g_dwMaxLogSize;
821extern DWORD g_dwLogHistorySize;
822extern TCHAR g_szDailyLogFileSuffix[64];
5039dede
AK
823extern TCHAR NXCORE_EXPORTABLE g_szDumpDir[];
824extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
825#ifndef _WIN32
826extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
827#endif
828extern TCHAR g_szDataDir[];
9796ce45 829extern TCHAR g_szLibDir[];
712dd47d 830extern TCHAR g_szJavaLibDir[];
73869331 831extern DWORD NXCORE_EXPORTABLE g_processAffinityMask;
5039dede
AK
832extern QWORD g_qwServerId;
833extern RSA *g_pServerKey;
834extern DWORD g_dwPingSize;
835extern DWORD g_dwAuditFlags;
836extern time_t g_tServerStartTime;
837extern DWORD g_dwLockTimeout;
5039dede
AK
838extern DWORD g_dwAgentCommandTimeout;
839extern DWORD g_dwThresholdRepeatInterval;
840extern int g_nRequiredPolls;
52c75f5c 841extern DWORD g_dwSlmPollingInterval;
5039dede 842
b8c1ec69
VK
843extern TCHAR g_szDbDriver[];
844extern TCHAR g_szDbDrvParams[];
845extern TCHAR g_szDbServer[];
846extern TCHAR g_szDbLogin[];
847extern TCHAR g_szDbPassword[];
848extern TCHAR g_szDbName[];
f3c30cf5 849extern TCHAR g_szDbSchema[];
712dd47d 850extern TCHAR NXCORE_EXPORTABLE g_szJavaPath[];
b8c1ec69 851extern DB_DRIVER g_dbDriver;
5039dede
AK
852extern DB_HANDLE NXCORE_EXPORTABLE g_hCoreDB;
853extern Queue *g_pLazyRequestQueue;
c9a9601c 854extern Queue *g_pIDataInsertQueue;
5039dede 855
28f5b9a4 856extern int NXCORE_EXPORTABLE g_nDBSyntax;
5039dede
AK
857
858#endif /* _nms_core_h_ */