874b9781999d804629f4528ea81d3fba9f1ad0bb
[public/netxms.git] / src / console / win32 / nxcon.cpp
1 // nxcon.cpp : Defines the class behaviors for the application.
2 //
3
4 #include "stdafx.h"
5 #include "nxcon.h"
6
7 #include "MainFrm.h"
8 #include "LoginDialog.h"
9 #include "CreateContainerDlg.h"
10 #include "CreateNodeDlg.h"
11 #include "CreateTemplateDlg.h"
12 #include "CreateTGDlg.h"
13 #include "CreateNetSrvDlg.h"
14 #include "CreateVPNConnDlg.h"
15 #include "NodePoller.h"
16 #include "MIBBrowserDlg.h"
17 #include "NetSrvPropsGeneral.h"
18 #include "NodePropsPolling.h"
19 #include "DeploymentView.h"
20 #include "LastValuesView.h"
21 #include "ObjectPropsRelations.h"
22 #include "VPNCPropsGeneral.h"
23 #include "RemoveTemplateDlg.h"
24 #include "AddrChangeDlg.h"
25 #include "AgentCfgEditor.h"
26 #include "TableView.h"
27 #include "WebBrowser.h"
28 #include "ObjectPropsStatus.h"
29
30 #ifdef _DEBUG
31 #define new DEBUG_NEW
32 #undef THIS_FILE
33 static char THIS_FILE[] = __FILE__;
34 #endif
35
36
37 //
38 // Wrapper for client library debug callback
39 //
40
41 static void ClientDebugCallback(char *pszMsg)
42 {
43 theApp.DebugCallback(pszMsg);
44 }
45
46
47 //
48 // CConsoleApp
49 //
50
51 BEGIN_MESSAGE_MAP(CConsoleApp, CWinApp)
52 //{{AFX_MSG_MAP(CConsoleApp)
53 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
54 ON_COMMAND(ID_VIEW_CONTROLPANEL, OnViewControlpanel)
55 ON_COMMAND(ID_VIEW_EVENTS, OnViewEvents)
56 ON_COMMAND(ID_VIEW_MAP, OnViewMap)
57 ON_COMMAND(ID_CONNECT_TO_SERVER, OnConnectToServer)
58 ON_COMMAND(ID_VIEW_OBJECTBROWSER, OnViewObjectbrowser)
59 ON_COMMAND(ID_CONTROLPANEL_EVENTS, OnControlpanelEvents)
60 ON_COMMAND(ID_VIEW_DEBUG, OnViewDebug)
61 ON_COMMAND(ID_CONTROLPANEL_USERS, OnControlpanelUsers)
62 ON_COMMAND(ID_VIEW_NETWORKSUMMARY, OnViewNetworksummary)
63 ON_COMMAND(ID_TOOLS_MIBBROWSER, OnToolsMibbrowser)
64 ON_COMMAND(ID_CONTROLPANEL_EVENTPOLICY, OnControlpanelEventpolicy)
65 ON_COMMAND(ID_VIEW_ALARMS, OnViewAlarms)
66 ON_COMMAND(ID_FILE_SETTINGS, OnFileSettings)
67 ON_COMMAND(ID_CONTROLPANEL_ACTIONS, OnControlpanelActions)
68 ON_COMMAND(ID_TOOLS_ADDNODE, OnToolsAddnode)
69 ON_COMMAND(ID_CONTROLPANEL_SNMPTRAPS, OnControlpanelSnmptraps)
70 ON_COMMAND(ID_CONTROLPANEL_AGENTPKG, OnControlpanelAgentpkg)
71 ON_COMMAND(ID_CONTROLPANEL_SERVERCFG, OnControlpanelServercfg)
72 ON_COMMAND(ID_VIEW_SYSLOG, OnViewSyslog)
73 ON_COMMAND(ID_CONTROLPANEL_LOGPROCESSING, OnControlpanelLogprocessing)
74 //}}AFX_MSG_MAP
75 END_MESSAGE_MAP()
76
77
78 //
79 // CConsoleApp construction
80 //
81
82 CConsoleApp::CConsoleApp()
83 {
84 m_bActionEditorActive = FALSE;
85 m_bTrapEditorActive = FALSE;
86 m_bCtrlPanelActive = FALSE;
87 m_bAlarmBrowserActive = FALSE;
88 m_bEventBrowserActive = FALSE;
89 m_bSyslogBrowserActive = FALSE;
90 m_bEventEditorActive = FALSE;
91 m_bUserEditorActive = FALSE;
92 m_bObjectBrowserActive = FALSE;
93 m_bDebugWindowActive = FALSE;
94 m_bNetSummaryActive = FALSE;
95 m_bEventPolicyEditorActive = FALSE;
96 m_bLPPEditorActive = FALSE;
97 m_bPackageMgrActive = FALSE;
98 m_bServerCfgEditorActive = FALSE;
99 m_dwClientState = STATE_DISCONNECTED;
100 m_hwndEventBrowser = NULL;
101 memset(m_openDCEditors, 0, sizeof(DC_EDITOR) * MAX_DC_EDITORS);
102 }
103
104
105 //
106 // CConsoleApp destruction
107 //
108
109 CConsoleApp::~CConsoleApp()
110 {
111 }
112
113
114 //
115 // The one and only CConsoleApp object
116 //
117
118 CConsoleApp theApp;
119
120
121 //
122 // Setup working directory
123 //
124
125 BOOL CConsoleApp::SetupWorkDir()
126 {
127 int iLastChar;
128
129 // Get path to user's "Application Data" folder
130 if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, g_szWorkDir) != S_OK)
131 {
132 AfxMessageBox(IDS_GETFOLDERPATH_FAILED, MB_OK | MB_ICONSTOP);
133 return FALSE;
134 }
135
136 // Create working directory root
137 strcat(g_szWorkDir, "\\NetXMS Console");
138 if (!CreateDirectory(g_szWorkDir, NULL))
139 if (GetLastError() != ERROR_ALREADY_EXISTS)
140 {
141 AfxMessageBox(IDS_WORKDIR_CREATION_FAILED, MB_OK | MB_ICONSTOP);
142 return FALSE;
143 }
144 iLastChar = strlen(g_szWorkDir);
145
146 // Create MIB cache directory
147 strcpy(&g_szWorkDir[iLastChar], WORKDIR_MIBCACHE);
148 if (!CreateDirectory(g_szWorkDir, NULL))
149 if (GetLastError() != ERROR_ALREADY_EXISTS)
150 {
151 AfxMessageBox(IDS_WORKDIR_CREATION_FAILED, MB_OK | MB_ICONSTOP);
152 return FALSE;
153 }
154
155 // Create image cache directory
156 strcpy(&g_szWorkDir[iLastChar], WORKDIR_IMAGECACHE);
157 if (!CreateDirectory(g_szWorkDir, NULL))
158 if (GetLastError() != ERROR_ALREADY_EXISTS)
159 {
160 AfxMessageBox(IDS_WORKDIR_CREATION_FAILED, MB_OK | MB_ICONSTOP);
161 return FALSE;
162 }
163
164 // Success
165 g_szWorkDir[iLastChar] = 0;
166 return TRUE;
167 }
168
169
170 //
171 // CConsoleApp initialization
172 //
173
174 BOOL CConsoleApp::InitInstance()
175 {
176 BOOL bSetWindowPos;
177 DWORD dwBytes;
178 BYTE *pData;
179 HMENU hMenu;
180
181 // Setup our working directory
182 if (!SetupWorkDir())
183 return FALSE;
184
185 if (!AfxSocketInit())
186 {
187 AfxMessageBox(IDP_SOCKETS_INIT_FAILED, MB_OK | MB_ICONSTOP);
188 return FALSE;
189 }
190
191 if (!NXCInitialize())
192 {
193 AfxMessageBox(IDS_NXC_INIT_FAILED, MB_OK | MB_ICONSTOP);
194 return FALSE;
195 }
196
197 AfxEnableControlContainer();
198
199 // Standard initialization
200 // If you are not using these features and wish to reduce the size
201 // of your final executable, you should remove from the following
202 // the specific initialization routines you do not need.
203
204 #ifdef _AFXDLL
205 Enable3dControls(); // Call this when using MFC in a shared DLL
206 #else
207 Enable3dControlsStatic(); // Call this when linking to MFC statically
208 #endif
209
210 // Change the registry key under which our settings are stored.
211 SetRegistryKey(_T("NetXMS"));
212
213 // Load configuration from registry
214 dwBytes = sizeof(WINDOWPLACEMENT);
215 bSetWindowPos = GetProfileBinary(_T("General"), _T("WindowPlacement"),
216 &pData, (UINT *)&dwBytes);
217 g_dwOptions = GetProfileInt(_T("General"), _T("Options"), 0);
218 strcpy(g_szServer, (LPCTSTR)GetProfileString(_T("Connection"), _T("Server"), _T("localhost")));
219 strcpy(g_szLogin, (LPCTSTR)GetProfileString(_T("Connection"), _T("Login"), NULL));
220
221 // Create mutex for action list access
222 g_mutexActionListAccess = CreateMutex(NULL, FALSE, NULL);
223
224 // To create the main window, this code creates a new frame window
225 // object and then sets it as the application's main window object.
226 CMDIFrameWnd* pFrame = new CMainFrame;
227 m_pMainWnd = pFrame;
228
229 // create main MDI frame window
230 if (!pFrame->LoadFrame(IDR_MAINFRAME))
231 return FALSE;
232
233 // Load context menus
234 if (!m_ctxMenu.LoadMenu(IDM_CONTEXT))
235 MessageBox(NULL, "FAILED", "", 0);
236
237 // Load shared MDI menus and accelerator table
238 HINSTANCE hInstance = AfxGetResourceHandle();
239
240 hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDM_VIEW_SPECIFIC));
241
242 // Modify application menu as needed
243 if (g_dwOptions & UI_OPT_EXPAND_CTRLPANEL)
244 {
245 pFrame->GetMenu()->RemoveMenu(ID_VIEW_CONTROLPANEL, MF_BYCOMMAND);
246 pFrame->GetMenu()->InsertMenu(ID_VIEW_DEBUG, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 8), "&Control panel");
247 }
248
249 m_hMDIMenu = LoadAppMenu(hMenu);
250 InsertMenu(m_hMDIMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
251
252 m_hEventBrowserMenu = LoadAppMenu(hMenu);
253 InsertMenu(m_hEventBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
254 InsertMenu(m_hEventBrowserMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 1), "&Event");
255
256 m_hObjectBrowserMenu = LoadAppMenu(hMenu);
257 InsertMenu(m_hObjectBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
258 InsertMenu(m_hObjectBrowserMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 2), "&Object");
259
260 m_hUserEditorMenu = LoadAppMenu(hMenu);
261 InsertMenu(m_hUserEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
262 InsertMenu(m_hUserEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 3), "&User");
263
264 m_hDCEditorMenu = LoadAppMenu(hMenu);
265 InsertMenu(m_hDCEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
266 InsertMenu(m_hDCEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 4), "&Item");
267
268 m_hPolicyEditorMenu = LoadAppMenu(hMenu);
269 InsertMenu(m_hPolicyEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
270 InsertMenu(m_hPolicyEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 5), "&Policy");
271
272 m_hAlarmBrowserMenu = LoadAppMenu(hMenu);
273 InsertMenu(m_hAlarmBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
274 InsertMenu(m_hAlarmBrowserMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 6), "&Alarm");
275
276 m_hMapMenu = LoadAppMenu(hMenu);
277 InsertMenu(m_hMapMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
278 InsertMenu(m_hMapMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 9), "&Object");
279
280 m_hEventEditorMenu = LoadAppMenu(hMenu);
281 InsertMenu(m_hEventEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
282 InsertMenu(m_hEventEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 10), "&Event");
283
284 m_hActionEditorMenu = LoadAppMenu(hMenu);
285 InsertMenu(m_hActionEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
286 InsertMenu(m_hActionEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 11), "&Action");
287
288 m_hTrapEditorMenu = LoadAppMenu(hMenu);
289 InsertMenu(m_hTrapEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
290 InsertMenu(m_hTrapEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 12), "T&rap");
291
292 m_hGraphMenu = LoadAppMenu(hMenu);
293 InsertMenu(m_hGraphMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
294 InsertMenu(m_hGraphMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 13), "&Graph");
295
296 m_hPackageMgrMenu = LoadAppMenu(hMenu);
297 InsertMenu(m_hPackageMgrMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
298 InsertMenu(m_hPackageMgrMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 14), "&Package");
299
300 m_hLastValuesMenu = LoadAppMenu(hMenu);
301 InsertMenu(m_hLastValuesMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
302 InsertMenu(m_hLastValuesMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 15), "&Item");
303
304 m_hServerCfgEditorMenu = LoadAppMenu(hMenu);
305 InsertMenu(m_hServerCfgEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
306 InsertMenu(m_hServerCfgEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 16), "V&ariable");
307
308 m_hAgentCfgEditorMenu = LoadAppMenu(hMenu);
309 InsertMenu(m_hAgentCfgEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
310 InsertMenu(m_hAgentCfgEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 17), "&Edit");
311 InsertMenu(m_hAgentCfgEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 18), "&Config");
312
313 m_hLPPEditorMenu = LoadAppMenu(hMenu);
314 InsertMenu(m_hDCEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
315 //InsertMenu(m_hDCEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 4), "&Item");
316
317 m_hMDIAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
318 m_hAlarmBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_ALARM_BROWSER));
319 m_hEventBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
320 m_hObjectBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_OBJECT_BROWSER));
321 m_hEventEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_EVENT_EDITOR));
322 m_hUserEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
323 m_hDCEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_DC_EDITOR));
324 m_hPolicyEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_EPP));
325 m_hMapAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_NETMAP));
326 m_hActionEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_ACTION_EDITOR));
327 m_hTrapEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_TRAP_EDITOR));
328 m_hGraphAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_GRAPH));
329 m_hPackageMgrAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_PACKAGE_MGR));
330 m_hLastValuesAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_LAST_VALUES));
331 m_hServerCfgEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_SERVER_CFG_EDITOR));
332 m_hAgentCfgEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_AGENT_CFG_EDITOR));
333 m_hLPPEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
334
335 // The main window has been initialized, so show and update it.
336 if (bSetWindowPos)
337 {
338 pFrame->SetWindowPlacement((WINDOWPLACEMENT *)pData);
339 if (pFrame->IsIconic())
340 pFrame->ShowWindow(SW_RESTORE);
341 }
342 else
343 {
344 pFrame->ShowWindow(m_nCmdShow);
345 }
346 pFrame->UpdateWindow();
347 //pFrame->PostMessage(WM_COMMAND, ID_VIEW_DEBUG, 0);
348 pFrame->PostMessage(WM_COMMAND, ID_CONNECT_TO_SERVER, 0);
349
350 return TRUE;
351 }
352
353 /////////////////////////////////////////////////////////////////////////////
354 // CConsoleApp message handlers
355
356 int CConsoleApp::ExitInstance()
357 {
358 TCHAR szBuffer[MAX_PATH + 32];
359 BYTE bsServerId[8];
360
361 if (g_hSession != NULL)
362 {
363 if (!(g_dwOptions & OPT_DONT_CACHE_OBJECTS))
364 {
365 NXCGetServerID(g_hSession, bsServerId);
366 _tcscpy(szBuffer, g_szWorkDir);
367 _tcscat(szBuffer, WORKFILE_OBJECTCACHE);
368 BinToStr(bsServerId, 8, &szBuffer[_tcslen(szBuffer)]);
369 _tcscat(szBuffer, _T("."));
370 _tcscat(szBuffer, g_szLogin);
371 NXCSaveObjectCache(g_hSession, szBuffer);
372 }
373
374 NXCSetDebugCallback(NULL);
375 NXCDisconnect(g_hSession);
376 NXCShutdown();
377 NXCDestroyCCList(g_pCCList);
378 }
379
380 // Save configuration
381 WriteProfileInt(_T("General"), _T("Options"), g_dwOptions);
382
383 // Free resources
384 SafeFreeResource(m_hMDIMenu);
385 SafeFreeResource(m_hMDIAccel);
386 SafeFreeResource(m_hAlarmBrowserMenu);
387 SafeFreeResource(m_hAlarmBrowserAccel);
388 SafeFreeResource(m_hEventBrowserMenu);
389 SafeFreeResource(m_hEventBrowserAccel);
390 SafeFreeResource(m_hUserEditorMenu);
391 SafeFreeResource(m_hUserEditorAccel);
392 SafeFreeResource(m_hDCEditorMenu);
393 SafeFreeResource(m_hDCEditorAccel);
394 SafeFreeResource(m_hEventEditorMenu);
395 SafeFreeResource(m_hEventEditorAccel);
396 SafeFreeResource(m_hActionEditorMenu);
397 SafeFreeResource(m_hActionEditorAccel);
398 SafeFreeResource(m_hTrapEditorMenu);
399 SafeFreeResource(m_hTrapEditorAccel);
400 SafeFreeResource(m_hGraphMenu);
401 SafeFreeResource(m_hGraphAccel);
402 SafeFreeResource(m_hPackageMgrMenu);
403 SafeFreeResource(m_hPackageMgrAccel);
404 SafeFreeResource(m_hLastValuesMenu);
405 SafeFreeResource(m_hLastValuesAccel);
406 SafeFreeResource(m_hServerCfgEditorMenu);
407 SafeFreeResource(m_hServerCfgEditorAccel);
408 SafeFreeResource(m_hAgentCfgEditorMenu);
409 SafeFreeResource(m_hAgentCfgEditorAccel);
410 SafeFreeResource(m_hLPPEditorMenu);
411 SafeFreeResource(m_hLPPEditorAccel);
412
413 CloseHandle(g_mutexActionListAccess);
414
415 return CWinApp::ExitInstance();
416 }
417
418
419 /////////////////////////////////////////////////////////////////////////////
420 // CAboutDlg dialog used for App About
421
422 class CAboutDlg : public CDialog
423 {
424 public:
425 CAboutDlg();
426
427 // Dialog Data
428 //{{AFX_DATA(CAboutDlg)
429 enum { IDD = IDD_ABOUTBOX };
430 CStatic m_wndVersion;
431 //}}AFX_DATA
432
433 // ClassWizard generated virtual function overrides
434 //{{AFX_VIRTUAL(CAboutDlg)
435 protected:
436 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
437 //}}AFX_VIRTUAL
438
439 // Implementation
440 protected:
441 //{{AFX_MSG(CAboutDlg)
442 virtual BOOL OnInitDialog();
443 //}}AFX_MSG
444 DECLARE_MESSAGE_MAP()
445 };
446
447 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
448 {
449 //{{AFX_DATA_INIT(CAboutDlg)
450 //}}AFX_DATA_INIT
451 }
452
453 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
454 {
455 CDialog::DoDataExchange(pDX);
456 //{{AFX_DATA_MAP(CAboutDlg)
457 DDX_Control(pDX, IDC_VERSION, m_wndVersion);
458 //}}AFX_DATA_MAP
459 }
460
461 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
462 //{{AFX_MSG_MAP(CAboutDlg)
463 //}}AFX_MSG_MAP
464 END_MESSAGE_MAP()
465
466 BOOL CAboutDlg::OnInitDialog()
467 {
468 CDialog::OnInitDialog();
469
470 m_wndVersion.SetWindowText(_T("NetXMS Console Version ") NETXMS_VERSION_STRING);
471 return TRUE;
472 }
473
474 // App command to run the dialog
475 void CConsoleApp::OnAppAbout()
476 {
477 CAboutDlg aboutDlg;
478 aboutDlg.DoModal();
479 }
480
481 /////////////////////////////////////////////////////////////////////////////
482 // CConsoleApp message handlers
483
484
485 void CConsoleApp::OnViewControlpanel()
486 {
487 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
488
489 // create a new MDI child window or open existing
490 if (m_bCtrlPanelActive)
491 m_pwndCtrlPanel->BringWindowToTop();
492 else
493 pFrame->CreateNewChild(
494 RUNTIME_CLASS(CControlPanel), IDR_CTRLPANEL, m_hMDIMenu, m_hMDIAccel);
495 }
496
497
498 //
499 // This method called when new view is created
500 //
501
502 void CConsoleApp::OnViewCreate(DWORD dwView, CWnd *pWnd, DWORD dwArg)
503 {
504 DWORD i;
505
506 switch(dwView)
507 {
508 case IDR_CTRLPANEL:
509 m_bCtrlPanelActive = TRUE;
510 m_pwndCtrlPanel = pWnd;
511 break;
512 case IDR_ALARMS:
513 m_bAlarmBrowserActive = TRUE;
514 m_pwndAlarmBrowser = (CAlarmBrowser *)pWnd;
515 break;
516 case IDR_EVENTS:
517 m_bEventBrowserActive = TRUE;
518 m_pwndEventBrowser = (CEventBrowser *)pWnd;
519 m_hwndEventBrowser = pWnd->m_hWnd;
520 break;
521 case IDR_SYSLOG_BROWSER:
522 m_bSyslogBrowserActive = TRUE;
523 m_pwndSyslogBrowser = (CSyslogBrowser *)pWnd;
524 m_hwndSyslogBrowser = pWnd->m_hWnd;
525 break;
526 case IDR_OBJECTS:
527 m_bObjectBrowserActive = TRUE;
528 m_pwndObjectBrowser = (CObjectBrowser *)pWnd;
529 break;
530 case IDR_EVENT_EDITOR:
531 m_bEventEditorActive = TRUE;
532 m_pwndEventEditor = (CEventEditor *)pWnd;
533 break;
534 case IDR_ACTION_EDITOR:
535 m_bActionEditorActive = TRUE;
536 m_pwndActionEditor = (CActionEditor *)pWnd;
537 break;
538 case IDR_TRAP_EDITOR:
539 m_bTrapEditorActive = TRUE;
540 m_pwndTrapEditor = (CTrapEditor *)pWnd;
541 break;
542 case IDR_USER_EDITOR:
543 m_bUserEditorActive = TRUE;
544 m_pwndUserEditor = (CUserEditor *)pWnd;
545 break;
546 case IDR_DEBUG_WINDOW:
547 m_bDebugWindowActive = TRUE;
548 m_pwndDebugWindow = (CDebugFrame *)pWnd;
549 NXCSetDebugCallback(ClientDebugCallback);
550 break;
551 case IDR_NETWORK_SUMMARY:
552 m_bNetSummaryActive = TRUE;
553 m_pwndNetSummary = (CNetSummaryFrame *)pWnd;
554 break;
555 case IDR_DC_EDITOR:
556 // Register new DC editor
557 for(i = 0; i < MAX_DC_EDITORS; i++)
558 if (m_openDCEditors[i].pWnd == NULL)
559 {
560 m_openDCEditors[i].pWnd = pWnd;
561 m_openDCEditors[i].dwNodeId = dwArg;
562 break;
563 }
564 break;
565 case IDR_EPP_EDITOR:
566 m_bEventPolicyEditorActive = TRUE;
567 m_pwndEventPolicyEditor = (CEventPolicyEditor *)pWnd;
568 break;
569 case IDR_PACKAGE_MGR:
570 m_bPackageMgrActive = TRUE;
571 m_pwndPackageMgr = (CPackageMgr *)pWnd;
572 break;
573 case IDR_SERVER_CFG_EDITOR:
574 m_bServerCfgEditorActive = TRUE;
575 m_pwndServerCfgEditor = (CServerCfgEditor *)pWnd;
576 break;
577 case IDR_LPP_EDITOR:
578 m_bLPPEditorActive = TRUE;
579 m_pwndLPPEditor = (CLPPList *)pWnd;
580 break;
581 default:
582 break;
583 }
584 }
585
586
587 //
588 // This method called when view is destroyed
589 //
590
591 void CConsoleApp::OnViewDestroy(DWORD dwView, CWnd *pWnd, DWORD dwArg)
592 {
593 DWORD i;
594
595 switch(dwView)
596 {
597 case IDR_CTRLPANEL:
598 m_bCtrlPanelActive = FALSE;
599 break;
600 case IDR_ALARMS:
601 m_bAlarmBrowserActive = FALSE;
602 break;
603 case IDR_EVENTS:
604 m_bEventBrowserActive = FALSE;
605 m_hwndEventBrowser = NULL;
606 break;
607 case IDR_SYSLOG_BROWSER:
608 m_bSyslogBrowserActive = FALSE;
609 m_hwndSyslogBrowser = NULL;
610 break;
611 case IDR_OBJECTS:
612 m_bObjectBrowserActive = FALSE;
613 break;
614 case IDR_EVENT_EDITOR:
615 m_bEventEditorActive = FALSE;
616 break;
617 case IDR_ACTION_EDITOR:
618 m_bActionEditorActive = FALSE;
619 break;
620 case IDR_TRAP_EDITOR:
621 m_bTrapEditorActive = FALSE;
622 break;
623 case IDR_USER_EDITOR:
624 m_bUserEditorActive = FALSE;
625 break;
626 case IDR_DEBUG_WINDOW:
627 m_bDebugWindowActive = FALSE;
628 NXCSetDebugCallback(NULL);
629 break;
630 case IDR_NETWORK_SUMMARY:
631 m_bNetSummaryActive = FALSE;
632 break;
633 case IDR_DC_EDITOR:
634 // Unregister DC editor
635 for(i = 0; i < MAX_DC_EDITORS; i++)
636 if (m_openDCEditors[i].pWnd == pWnd)
637 {
638 m_openDCEditors[i].pWnd = NULL;
639 m_openDCEditors[i].dwNodeId = 0;
640 break;
641 }
642 break;
643 case IDR_EPP_EDITOR:
644 m_bEventPolicyEditorActive = FALSE;
645 break;
646 case IDR_PACKAGE_MGR:
647 m_bPackageMgrActive = FALSE;
648 break;
649 case IDR_SERVER_CFG_EDITOR:
650 m_bServerCfgEditorActive = FALSE;
651 break;
652 case IDR_LPP_EDITOR:
653 m_bLPPEditorActive = FALSE;
654 break;
655 default:
656 break;
657 }
658 }
659
660
661 //
662 // Show event browser window
663 //
664
665 CMDIChildWnd *CConsoleApp::ShowEventBrowser(void)
666 {
667 CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
668 CMDIChildWnd *pWnd;
669
670 // create a new MDI child window or open existing
671 if (m_bEventBrowserActive)
672 {
673 m_pwndEventBrowser->BringWindowToTop();
674 pWnd = m_pwndEventBrowser;
675 }
676 else
677 {
678 pWnd = pFrame->CreateNewChild(RUNTIME_CLASS(CEventBrowser), IDR_EVENTS,
679 m_hEventBrowserMenu, m_hEventBrowserAccel);
680 }
681 return pWnd;
682 }
683
684
685 //
686 // Show syslog browser window
687 //
688
689 CMDIChildWnd *CConsoleApp::ShowSyslogBrowser(void)
690 {
691 CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
692 CMDIChildWnd *pWnd;
693
694 // create a new MDI child window or open existing
695 if (m_bSyslogBrowserActive)
696 {
697 m_pwndSyslogBrowser->BringWindowToTop();
698 pWnd = m_pwndSyslogBrowser;
699 }
700 else
701 {
702 pWnd = pFrame->CreateNewChild(RUNTIME_CLASS(CSyslogBrowser), IDR_SYSLOG_BROWSER,
703 m_hMDIMenu, m_hMDIAccel);
704 }
705 return pWnd;
706 }
707
708
709 //
710 // WM_COMMAND::ID_VIEW_EVENTS message handler
711 //
712
713 void CConsoleApp::OnViewEvents()
714 {
715 ShowEventBrowser();
716 }
717
718
719 //
720 // WM_COMMAND::ID_VIEW_SYSLOG message handler
721 //
722
723 void CConsoleApp::OnViewSyslog()
724 {
725 ShowSyslogBrowser();
726 }
727
728
729 //
730 // WM_COMMAND::ID_VIEW_MAP message handler
731 //
732
733 void CConsoleApp::OnViewMap()
734 {
735 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
736
737 // create a new MDI child window
738 pFrame->CreateNewChild(RUNTIME_CLASS(CMapFrame), IDR_MAPFRAME, m_hMapMenu, m_hMapAccel);
739 }
740
741
742 //
743 // WM_COMMAND::ID_CONNECT_TO_SERVER message handler
744 //
745
746 void CConsoleApp::OnConnectToServer()
747 {
748 CLoginDialog dlgLogin;
749 DWORD dwResult;
750
751 dlgLogin.m_szServer = g_szServer;
752 dlgLogin.m_szLogin = g_szLogin;
753 dlgLogin.m_bEncrypt = (g_dwOptions & OPT_ENCRYPT_CONNECTION) ? TRUE : FALSE;
754 dlgLogin.m_bNoCache = FALSE;
755 dlgLogin.m_bClearCache = FALSE;
756 dlgLogin.m_bMatchVersion = (g_dwOptions & OPT_MATCH_SERVER_VERSION) ? TRUE : FALSE;
757 do
758 {
759 if (dlgLogin.DoModal() != IDOK)
760 {
761 PostQuitMessage(1);
762 break;
763 }
764 strcpy(g_szServer, (LPCTSTR)dlgLogin.m_szServer);
765 strcpy(g_szLogin, (LPCTSTR)dlgLogin.m_szLogin);
766 strcpy(g_szPassword, (LPCTSTR)dlgLogin.m_szPassword);
767 if (dlgLogin.m_bEncrypt)
768 g_dwOptions |= OPT_ENCRYPT_CONNECTION;
769 else
770 g_dwOptions &= ~OPT_ENCRYPT_CONNECTION;
771 if (dlgLogin.m_bMatchVersion)
772 g_dwOptions |= OPT_MATCH_SERVER_VERSION;
773 else
774 g_dwOptions &= ~OPT_MATCH_SERVER_VERSION;
775 if (dlgLogin.m_bNoCache)
776 g_dwOptions |= OPT_DONT_CACHE_OBJECTS;
777 else
778 g_dwOptions &= ~OPT_DONT_CACHE_OBJECTS;
779
780 // Save last connection parameters
781 WriteProfileString(_T("Connection"), _T("Server"), g_szServer);
782 WriteProfileString(_T("Connection"), _T("Login"), g_szLogin);
783
784 // Initiate connection
785 dwResult = DoLogin(dlgLogin.m_bClearCache);
786 if (dwResult != RCC_SUCCESS)
787 ErrorBox(dwResult, "Unable to connect: %s", "Connection error");
788 }
789 while(dwResult != RCC_SUCCESS);
790 }
791
792
793 //
794 // WM_COMMAND::ID_VIEW_OBJECTBROWSER message handler
795 //
796
797 void CConsoleApp::OnViewObjectbrowser()
798 {
799 ShowObjectBrowser();
800 }
801
802
803 //
804 // Event handler for client libray events
805 //
806
807 void CConsoleApp::EventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
808 {
809 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
810 NXC_DEPLOYMENT_STATUS *pStatus;
811
812 switch(dwEvent)
813 {
814 case NXC_EVENT_NEW_ELOG_RECORD:
815 if (m_bEventBrowserActive)
816 {
817 void *pData;
818
819 pData = nx_memdup(pArg, sizeof(NXC_EVENT));
820 if (!PostMessage(m_hwndEventBrowser, WM_NETXMS_EVENT, 0, (LPARAM)pData))
821 free(pData);
822 }
823 break;
824 case NXC_EVENT_NEW_SYSLOG_RECORD:
825 if (m_bSyslogBrowserActive)
826 {
827 NXC_SYSLOG_RECORD *pRec;
828
829 pRec = (NXC_SYSLOG_RECORD *)nx_memdup(pArg, sizeof(NXC_SYSLOG_RECORD));
830 pRec->pszText = _tcsdup(((NXC_SYSLOG_RECORD *)pArg)->pszText);
831 if (!PostMessage(m_hwndSyslogBrowser, WM_SYSLOG_RECORD, 0, (LPARAM)pRec))
832 {
833 safe_free(pRec->pszText);
834 free(pRec);
835 }
836 }
837 break;
838 case NXC_EVENT_OBJECT_CHANGED:
839 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_OBJECT_CHANGE, dwCode, (LPARAM)pArg);
840 break;
841 case NXC_EVENT_USER_DB_CHANGED:
842 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_USERDB_CHANGE, dwCode, (LPARAM)pArg);
843 break;
844 case NXC_EVENT_DEPLOYMENT_STATUS:
845 pStatus = (NXC_DEPLOYMENT_STATUS *)nx_memdup(pArg, sizeof(NXC_DEPLOYMENT_STATUS));
846 pStatus->pszErrorMessage = _tcsdup(pStatus->pszErrorMessage);
847 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_DEPLOYMENT_INFO, dwCode, (LPARAM)pStatus);
848 break;
849 case NXC_EVENT_NOTIFICATION:
850 switch(dwCode)
851 {
852 case NX_NOTIFY_SHUTDOWN:
853 m_pMainWnd->MessageBox(_T("Server was shutdown"), _T("Warning"), MB_OK | MB_ICONSTOP);
854 m_pMainWnd->PostMessage(WM_CLOSE, 0, 0);
855 break;
856 case NX_NOTIFY_EVENTDB_CHANGED:
857 m_pMainWnd->PostMessage(WM_UPDATE_EVENT_LIST);
858 break;
859 case NX_NOTIFY_NEW_ALARM:
860 case NX_NOTIFY_ALARM_DELETED:
861 case NX_NOTIFY_ALARM_ACKNOWLEGED:
862 m_pMainWnd->PostMessage(WM_ALARM_UPDATE, dwCode,
863 (LPARAM)nx_memdup(pArg, sizeof(NXC_ALARM)));
864 break;
865 case NX_NOTIFY_ACTION_CREATED:
866 case NX_NOTIFY_ACTION_MODIFIED:
867 case NX_NOTIFY_ACTION_DELETED:
868 UpdateActions(dwCode, (NXC_ACTION *)pArg);
869 break;
870 default:
871 break;
872 }
873 break;
874 default:
875 break;
876 }
877 }
878
879
880 //
881 // Handler for WM_COMMAND(ID_CONTROLPANEL_EVENTS) message
882 //
883
884 void CConsoleApp::OnControlpanelEvents()
885 {
886 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
887
888 // create a new MDI child window or open existing
889 if (m_bEventEditorActive)
890 m_pwndEventEditor->BringWindowToTop();
891 else
892 {
893 DWORD dwResult;
894
895 dwResult = DoRequestArg1(NXCLockEventDB, g_hSession, "Locking event configuration database...");
896 if (dwResult == RCC_SUCCESS)
897 {
898 pFrame->CreateNewChild(
899 RUNTIME_CLASS(CEventEditor), IDR_EVENT_EDITOR, m_hEventEditorMenu, m_hEventEditorAccel);
900 }
901 else
902 {
903 ErrorBox(dwResult, "Unable to open event configuration database:\n%s");
904 }
905 }
906 }
907
908
909 //
910 // Handler for WM_COMMAND::ID_CONTROLPANEL_USERS message
911 //
912
913 void CConsoleApp::OnControlpanelUsers()
914 {
915 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
916
917 // create a new MDI child window or open existing
918 if (m_bUserEditorActive)
919 m_pwndUserEditor->BringWindowToTop();
920 else
921 {
922 DWORD dwResult;
923
924 dwResult = DoRequestArg1(NXCLockUserDB, g_hSession, "Locking user database...");
925 if (dwResult == RCC_SUCCESS)
926 {
927 pFrame->CreateNewChild(
928 RUNTIME_CLASS(CUserEditor), IDR_USER_EDITOR, m_hUserEditorMenu, m_hUserEditorAccel);
929 }
930 else
931 {
932 ErrorBox(dwResult, "Unable to lock user database:\n%s");
933 }
934 }
935 }
936
937
938 //
939 // Handler for WM_COMMAND::ID_VIEW_DEBUG message
940 //
941
942 void CConsoleApp::OnViewDebug()
943 {
944 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
945
946 // create a new MDI child window or open existing
947 if (m_bDebugWindowActive)
948 m_pwndDebugWindow->BringWindowToTop();
949 else
950 pFrame->CreateNewChild(
951 RUNTIME_CLASS(CDebugFrame), IDR_DEBUG_WINDOW, m_hMDIMenu, m_hMDIAccel);
952 }
953
954
955 //
956 // Print debug information
957 //
958
959 void CConsoleApp::DebugPrintf(char *szFormat, ...)
960 {
961 if (m_bDebugWindowActive)
962 {
963 char szBuffer[1024];
964 va_list args;
965
966 va_start(args, szFormat);
967 vsprintf(szBuffer, szFormat, args);
968 va_end(args);
969
970 m_pwndDebugWindow->AddMessage(szBuffer);
971 }
972 }
973
974
975 //
976 // Edit properties of specific object
977 //
978
979 void CConsoleApp::ObjectProperties(DWORD dwObjectId)
980 {
981 CObjectPropSheet wndPropSheet("Object Properties", GetMainWnd(), 0);
982 CNodePropsGeneral wndNodeGeneral;
983 CNetSrvPropsGeneral wndNetSrvGeneral;
984 CObjectPropsGeneral wndObjectGeneral;
985 CObjectPropCaps wndObjectCaps;
986 CObjectPropsSecurity wndObjectSecurity;
987 CObjectPropsPresentation wndObjectPresentation;
988 CObjectPropsRelations wndObjectRelations;
989 CNodePropsPolling wndNodePolling;
990 CVPNCPropsGeneral wndVPNCGeneral;
991 CObjectPropsStatus wndStatus;
992 NXC_OBJECT *pObject;
993
994 pObject = NXCFindObjectById(g_hSession, dwObjectId);
995 if (pObject != NULL)
996 {
997 // Create "General" tab and class-specific tabs
998 switch(pObject->iClass)
999 {
1000 case OBJECT_NODE:
1001 wndNodeGeneral.m_dwObjectId = dwObjectId;
1002 wndNodeGeneral.m_strName = pObject->szName;
1003 wndNodeGeneral.m_strOID = pObject->node.szObjectId;
1004 wndNodeGeneral.m_dwIpAddr = pObject->dwIpAddr;
1005 wndNodeGeneral.m_iAgentPort = (int)pObject->node.wAgentPort;
1006 wndNodeGeneral.m_strCommunity = pObject->node.szCommunityString;
1007 wndNodeGeneral.m_iAuthType = pObject->node.wAuthMethod;
1008 wndNodeGeneral.m_strSecret = pObject->node.szSharedSecret;
1009 wndNodeGeneral.m_iSNMPVersion = (pObject->node.wSNMPVersion == SNMP_VERSION_1) ? 0 : 1;
1010 wndPropSheet.AddPage(&wndNodeGeneral);
1011
1012 // Create "Polling" tab
1013 wndNodePolling.m_dwPollerNode = pObject->node.dwPollerNode;
1014 wndPropSheet.AddPage(&wndNodePolling);
1015
1016 // Create "Capabilities" tab
1017 wndObjectCaps.m_pObject = pObject;
1018 wndPropSheet.AddPage(&wndObjectCaps);
1019 break;
1020 case OBJECT_NETWORKSERVICE:
1021 wndNetSrvGeneral.m_pObject = pObject;
1022 wndNetSrvGeneral.m_dwObjectId = dwObjectId;
1023 wndNetSrvGeneral.m_strName = pObject->szName;
1024 wndNetSrvGeneral.m_iServiceType = pObject->netsrv.iServiceType;
1025 wndNetSrvGeneral.m_iPort = pObject->netsrv.wPort;
1026 wndNetSrvGeneral.m_iProto = pObject->netsrv.wProto;
1027 wndNetSrvGeneral.m_strRequest = pObject->netsrv.pszRequest;
1028 wndNetSrvGeneral.m_strResponse = pObject->netsrv.pszResponse;
1029 wndNetSrvGeneral.m_dwIpAddr = pObject->dwIpAddr;
1030 wndNetSrvGeneral.m_dwPollerNode = pObject->netsrv.dwPollerNode;
1031 wndPropSheet.AddPage(&wndNetSrvGeneral);
1032 break;
1033 case OBJECT_VPNCONNECTOR:
1034 wndVPNCGeneral.m_pObject = pObject;
1035 wndVPNCGeneral.m_dwObjectId = dwObjectId;
1036 wndVPNCGeneral.m_strName = pObject->szName;
1037 wndVPNCGeneral.m_dwPeerGateway = pObject->vpnc.dwPeerGateway;
1038 wndPropSheet.AddPage(&wndVPNCGeneral);
1039 break;
1040 default:
1041 wndObjectGeneral.m_dwObjectId = dwObjectId;
1042 wndObjectGeneral.m_strClass = g_szObjectClass[pObject->iClass];
1043 wndObjectGeneral.m_strName = pObject->szName;
1044 wndPropSheet.AddPage(&wndObjectGeneral);
1045 break;
1046 }
1047
1048 // Create "Relations" tab
1049 wndObjectRelations.m_pObject = pObject;
1050 wndPropSheet.AddPage(&wndObjectRelations);
1051
1052 // Create "Status Calculation" tab
1053 if ((pObject->iClass != OBJECT_TEMPLATEROOT) &&
1054 (pObject->iClass != OBJECT_TEMPLATEGROUP) &&
1055 (pObject->iClass != OBJECT_TEMPLATE))
1056 {
1057 wndPropSheet.AddPage(&wndStatus);
1058 }
1059
1060 // Create "Security" tab
1061 wndObjectSecurity.m_pObject = pObject;
1062 wndObjectSecurity.m_bInheritRights = pObject->bInheritRights;
1063 wndPropSheet.AddPage(&wndObjectSecurity);
1064
1065 // Create "Presentation" tab
1066 wndObjectPresentation.m_dwImageId = pObject->dwImage;
1067 wndObjectPresentation.m_bUseDefaultImage = (pObject->dwImage == IMG_DEFAULT);
1068 wndPropSheet.AddPage(&wndObjectPresentation);
1069
1070 wndPropSheet.SetObject(pObject);
1071 if (wndPropSheet.DoModal() == IDOK)
1072 wndPropSheet.SaveObjectChanges();
1073 }
1074 }
1075
1076
1077 //
1078 // Get context menu
1079 //
1080
1081 CMenu *CConsoleApp::GetContextMenu(int iIndex)
1082 {
1083 return m_ctxMenu.GetSubMenu(iIndex);
1084 }
1085
1086
1087 //
1088 // Start data collection editor for specific object
1089 //
1090
1091 void CConsoleApp::StartObjectDCEditor(NXC_OBJECT *pObject)
1092 {
1093 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1094 NXC_DCI_LIST *pItemList;
1095 DWORD dwResult;
1096 CDataCollectionEditor *pWnd;
1097
1098 pWnd = (CDataCollectionEditor *)FindOpenDCEditor(pObject->dwId);
1099 if (pWnd == NULL)
1100 {
1101 dwResult = DoRequestArg3(NXCOpenNodeDCIList, g_hSession, (void *)pObject->dwId,
1102 &pItemList, "Loading node's data collection information...");
1103 if (dwResult == RCC_SUCCESS)
1104 {
1105 CreateChildFrameWithSubtitle(new CDataCollectionEditor(pItemList), IDR_DC_EDITOR,
1106 pObject->szName, m_hDCEditorMenu, m_hDCEditorAccel);
1107 }
1108 else
1109 {
1110 ErrorBox(dwResult, "Unable to load data collection information for node:\n%s");
1111 }
1112 }
1113 else
1114 {
1115 // Data collection editor already open, activate it
1116 pWnd->BringWindowToTop();
1117 }
1118 }
1119
1120
1121 //
1122 // Show network summary view
1123 //
1124
1125 void CConsoleApp::OnViewNetworksummary()
1126 {
1127 ShowNetworkSummary();
1128 }
1129
1130
1131 //
1132 // Set object's management status
1133 //
1134
1135 void CConsoleApp::SetObjectMgmtStatus(NXC_OBJECT *pObject, BOOL bIsManaged)
1136 {
1137 DWORD dwResult;
1138
1139 dwResult = DoRequestArg3(NXCSetObjectMgmtStatus, g_hSession, (void *)pObject->dwId,
1140 (void *)bIsManaged, "Changing object status...");
1141 if (dwResult != RCC_SUCCESS)
1142 {
1143 char szBuffer[256];
1144
1145 sprintf(szBuffer, "Unable to change management status for object %s:\n%s",
1146 pObject->szName, NXCGetErrorText(dwResult));
1147 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
1148 }
1149 }
1150
1151
1152 //
1153 // Find open data collection editor for given node, if any
1154 //
1155
1156 CWnd *CConsoleApp::FindOpenDCEditor(DWORD dwNodeId)
1157 {
1158 DWORD i;
1159
1160 for(i = 0; i < MAX_DC_EDITORS; i++)
1161 if (m_openDCEditors[i].dwNodeId == dwNodeId)
1162 return m_openDCEditors[i].pWnd;
1163 return NULL;
1164 }
1165
1166
1167 //
1168 // Display message box with error text from client library
1169 //
1170
1171 void CConsoleApp::ErrorBox(DWORD dwError, TCHAR *pszMessage, TCHAR *pszTitle)
1172 {
1173 TCHAR szBuffer[512];
1174
1175 _sntprintf(szBuffer, 512, (pszMessage != NULL) ? pszMessage : _T("Error: %s"),
1176 NXCGetErrorText(dwError));
1177 m_pMainWnd->MessageBox(szBuffer, (pszTitle != NULL) ? pszTitle : _T("Error"), MB_ICONSTOP);
1178 }
1179
1180
1181 //
1182 // Show window with DCI's data
1183 //
1184
1185 CMDIChildWnd *CConsoleApp::ShowDCIData(DWORD dwNodeId, DWORD dwItemId, char *pszItemName, TCHAR *pszParams)
1186 {
1187 CDCIDataView *pWnd;
1188
1189 if (pszParams == NULL)
1190 {
1191 pWnd = new CDCIDataView(dwNodeId, dwItemId, pszItemName);
1192 }
1193 else
1194 {
1195 pWnd = new CDCIDataView(pszParams);
1196 }
1197 CreateChildFrameWithSubtitle(pWnd, IDR_DCI_DATA_VIEW,
1198 pWnd->GetItemName(), m_hMDIMenu, m_hMDIAccel);
1199 return pWnd;
1200 }
1201
1202
1203 //
1204 // Show graph for collected data
1205 //
1206
1207 CMDIChildWnd *CConsoleApp::ShowDCIGraph(DWORD dwNodeId, DWORD dwNumItems,
1208 NXC_DCI **ppItemList, TCHAR *pszItemName,
1209 TCHAR *pszParams)
1210 {
1211 CGraphFrame *pWnd;
1212 DWORD i, dwCurrTime;
1213
1214 pWnd = new CGraphFrame;
1215 if (pszParams == NULL)
1216 {
1217 for(i = 0; i < dwNumItems; i++)
1218 if (ppItemList[i] != NULL)
1219 pWnd->AddItem(dwNodeId, ppItemList[i]);
1220 dwCurrTime = time(NULL);
1221 pWnd->SetTimeFrame(dwCurrTime - 3600, dwCurrTime); // Last hour
1222 pWnd->SetSubTitle(pszItemName);
1223 }
1224 else
1225 {
1226 // Restore desktop
1227 pWnd->RestoreFromServer(pszParams);
1228 }
1229
1230 CreateChildFrameWithSubtitle(pWnd, IDR_DCI_HISTORY_GRAPH,
1231 pWnd->GetSubTitle(), m_hGraphMenu, m_hGraphAccel);
1232 return pWnd;
1233 }
1234
1235
1236 //
1237 // WM_COMMAND::ID_TOOLS_MIBBROWSER message handler
1238 //
1239
1240 void CConsoleApp::OnToolsMibbrowser()
1241 {
1242 CMIBBrowserDlg dlg;
1243 dlg.DoModal();
1244 }
1245
1246
1247 //
1248 // WM_COMMAND::ID_CONTROLPANEL_EVENTPOLICY message handler
1249 //
1250
1251 void CConsoleApp::OnControlpanelEventpolicy()
1252 {
1253 // create a new MDI child window or open existing
1254 if (m_bEventPolicyEditorActive)
1255 {
1256 m_pwndEventPolicyEditor->BringWindowToTop();
1257 }
1258 else
1259 {
1260 CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1261 DWORD dwResult;
1262
1263 dwResult = DoRequestArg2(NXCOpenEventPolicy, g_hSession, &m_pEventPolicy,
1264 _T("Loading event processing policy..."));
1265 if (dwResult == RCC_SUCCESS)
1266 {
1267 pFrame->CreateNewChild(RUNTIME_CLASS(CEventPolicyEditor), IDR_EPP_EDITOR,
1268 m_hPolicyEditorMenu, m_hPolicyEditorAccel);
1269 }
1270 else
1271 {
1272 ErrorBox(dwResult, "Unable to load event processing policy:\n%s");
1273 }
1274 }
1275 }
1276
1277
1278 //
1279 // Show log processing policy list
1280 //
1281
1282 void CConsoleApp::OnControlpanelLogprocessing()
1283 {
1284 // create a new MDI child window or open existing
1285 if (m_bLPPEditorActive)
1286 {
1287 m_pwndLPPEditor->BringWindowToTop();
1288 }
1289 else
1290 {
1291 CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1292
1293 pFrame->CreateNewChild(RUNTIME_CLASS(CLPPList), IDR_LPP_EDITOR,
1294 m_hLPPEditorMenu, m_hLPPEditorAccel);
1295 }
1296 }
1297
1298
1299 //
1300 // Show alarm browser window
1301 //
1302
1303 CMDIChildWnd *CConsoleApp::ShowAlarmBrowser(TCHAR *pszParams)
1304 {
1305 CMDIChildWnd *pWnd;
1306
1307 // create a new MDI child window or open existing
1308 if (m_bAlarmBrowserActive)
1309 {
1310 m_pwndAlarmBrowser->BringWindowToTop();
1311 pWnd = m_pwndAlarmBrowser;
1312 }
1313 else
1314 {
1315 CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1316
1317 if (pszParams == NULL)
1318 {
1319 pWnd = pFrame->CreateNewChild(RUNTIME_CLASS(CAlarmBrowser), IDR_ALARMS,
1320 m_hAlarmBrowserMenu, m_hAlarmBrowserAccel);
1321 }
1322 else
1323 {
1324 pWnd = new CAlarmBrowser(pszParams);
1325 CreateChildFrameWithSubtitle(pWnd, IDR_ALARMS, NULL, m_hAlarmBrowserMenu, m_hAlarmBrowserAccel);
1326 }
1327 }
1328 return pWnd;
1329 }
1330
1331
1332 //
1333 // WM_COMMAND::ID_VIEW_ALARMS message handler
1334 //
1335
1336 void CConsoleApp::OnViewAlarms()
1337 {
1338 ShowAlarmBrowser();
1339 }
1340
1341
1342 //
1343 // WM_COMMAND::ID_FILE_SETTINGS message handler
1344 //
1345
1346 void CConsoleApp::OnFileSettings()
1347 {
1348 CPropertySheet wndPropSheet("Settings", GetMainWnd(), 0);
1349 CConsolePropsGeneral wndGeneral;
1350
1351 // "General" page
1352 wndGeneral.m_bExpandCtrlPanel = (g_dwOptions & UI_OPT_EXPAND_CTRLPANEL) ? TRUE : FALSE;
1353 wndGeneral.m_bShowGrid = (g_dwOptions & UI_OPT_SHOW_GRID) ? TRUE : FALSE;
1354 wndPropSheet.AddPage(&wndGeneral);
1355
1356 if (wndPropSheet.DoModal() == IDOK)
1357 {
1358 if (wndGeneral.m_bExpandCtrlPanel)
1359 g_dwOptions |= UI_OPT_EXPAND_CTRLPANEL;
1360 else
1361 g_dwOptions &= ~UI_OPT_EXPAND_CTRLPANEL;
1362
1363 if (wndGeneral.m_bShowGrid)
1364 g_dwOptions |= UI_OPT_SHOW_GRID;
1365 else
1366 g_dwOptions &= ~UI_OPT_SHOW_GRID;
1367 }
1368 }
1369
1370
1371 //
1372 // WM_COMMAND::ID_CONTROLPANEL_ACTIONS message handler
1373 //
1374
1375 void CConsoleApp::OnControlpanelActions()
1376 {
1377 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1378
1379 // create a new MDI child window or open existing
1380 if (m_bActionEditorActive)
1381 {
1382 m_pwndActionEditor->BringWindowToTop();
1383 }
1384 else
1385 {
1386 DWORD dwResult;
1387
1388 dwResult = DoRequestArg1(NXCLockActionDB, g_hSession, "Locking action configuration database...");
1389 if (dwResult == RCC_SUCCESS)
1390 {
1391 pFrame->CreateNewChild(
1392 RUNTIME_CLASS(CActionEditor), IDR_ACTION_EDITOR, m_hActionEditorMenu, m_hActionEditorAccel);
1393 }
1394 else
1395 {
1396 ErrorBox(dwResult, "Unable to lock action configuration database:\n%s");
1397 }
1398 }
1399 }
1400
1401
1402 //
1403 // WM_COMMAND::ID_CONTROLPANEL_SNMPTRAPS message handler
1404 //
1405
1406 void CConsoleApp::OnControlpanelSnmptraps()
1407 {
1408 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1409
1410 // create a new MDI child window or open existing
1411 if (m_bTrapEditorActive)
1412 {
1413 m_pwndTrapEditor->BringWindowToTop();
1414 }
1415 else
1416 {
1417 DWORD dwResult;
1418
1419 dwResult = DoRequestArg1(NXCLockTrapCfg, g_hSession, "Locking SNMP trap configuration database...");
1420 if (dwResult == RCC_SUCCESS)
1421 {
1422 pFrame->CreateNewChild(
1423 RUNTIME_CLASS(CTrapEditor), IDR_TRAP_EDITOR, m_hTrapEditorMenu, m_hTrapEditorAccel);
1424 }
1425 else
1426 {
1427 ErrorBox(dwResult, "Unable to lock SNMP trap configuration database:\n%s");
1428 }
1429 }
1430 }
1431
1432
1433 //
1434 // WM_COMMAND::ID_CONTROLPANEL_AGENTPKG message handler
1435 //
1436
1437 void CConsoleApp::OnControlpanelAgentpkg()
1438 {
1439 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1440
1441 // create a new MDI child window or open existing
1442 if (m_bPackageMgrActive)
1443 {
1444 m_pwndPackageMgr->BringWindowToTop();
1445 }
1446 else
1447 {
1448 DWORD dwResult;
1449
1450 dwResult = DoRequestArg1(NXCLockPackageDB, g_hSession, "Locking package database...");
1451 if (dwResult == RCC_SUCCESS)
1452 {
1453 pFrame->CreateNewChild(
1454 RUNTIME_CLASS(CPackageMgr), IDR_PACKAGE_MGR, m_hPackageMgrMenu, m_hPackageMgrAccel);
1455 }
1456 else
1457 {
1458 ErrorBox(dwResult, "Unable to lock package database:\n%s");
1459 }
1460 }
1461 }
1462
1463
1464 //
1465 // Load application menu from resources and modify it as needed
1466 //
1467
1468 HMENU CConsoleApp::LoadAppMenu(HMENU hViewMenu)
1469 {
1470 HMENU hMenu;
1471
1472 hMenu = ::LoadMenu(m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
1473
1474 if (g_dwOptions & UI_OPT_EXPAND_CTRLPANEL)
1475 {
1476 RemoveMenu(hMenu, ID_VIEW_CONTROLPANEL, MF_BYCOMMAND);
1477 InsertMenu(hMenu, ID_VIEW_DEBUG, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)GetSubMenu(hViewMenu, 8), "&Control panel");
1478 }
1479
1480 return hMenu;
1481 }
1482
1483
1484 //
1485 // Create new object
1486 //
1487
1488 void CConsoleApp::CreateObject(NXC_OBJECT_CREATE_INFO *pInfo)
1489 {
1490 DWORD dwResult, dwObjectId;
1491
1492 dwResult = DoRequestArg3(NXCCreateObject, g_hSession, pInfo, &dwObjectId, "Creating object...");
1493 if (dwResult != RCC_SUCCESS)
1494 {
1495 ErrorBox(dwResult, "Error creating object: %s");
1496 }
1497 }
1498
1499
1500 //
1501 // Create container object
1502 //
1503
1504 void CConsoleApp::CreateContainer(DWORD dwParent)
1505 {
1506 NXC_OBJECT_CREATE_INFO ci;
1507 CCreateContainerDlg dlg;
1508
1509 dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
1510 if (dlg.m_pParentObject != NULL)
1511 if ((dlg.m_pParentObject->iClass != OBJECT_CONTAINER) &&
1512 (dlg.m_pParentObject->iClass != OBJECT_SERVICEROOT))
1513 dlg.m_pParentObject = NULL;
1514 if (dlg.DoModal() == IDOK)
1515 {
1516 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1517 ci.iClass = OBJECT_CONTAINER;
1518 ci.pszName = (TCHAR *)((LPCTSTR)dlg.m_strObjectName);
1519 ci.cs.container.dwCategory = 1;
1520 ci.cs.container.pszDescription = (TCHAR *)((LPCTSTR)dlg.m_strDescription);
1521 CreateObject(&ci);
1522 }
1523 }
1524
1525
1526 //
1527 // Create node object
1528 //
1529
1530 void CConsoleApp::CreateNode(DWORD dwParent)
1531 {
1532 NXC_OBJECT_CREATE_INFO ci;
1533 CCreateNodeDlg dlg;
1534
1535 dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
1536 if (dlg.m_pParentObject != NULL)
1537 if ((dlg.m_pParentObject->iClass != OBJECT_CONTAINER) &&
1538 (dlg.m_pParentObject->iClass != OBJECT_SERVICEROOT))
1539 dlg.m_pParentObject = NULL;
1540 if (dlg.DoModal() == IDOK)
1541 {
1542 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1543 ci.iClass = OBJECT_NODE;
1544 ci.pszName = (TCHAR *)((LPCTSTR)dlg.m_strObjectName);
1545 ci.cs.node.dwIpAddr = dlg.m_dwIpAddr;
1546 ci.cs.node.dwNetMask = 0;
1547 CreateObject(&ci);
1548 }
1549 }
1550
1551
1552 //
1553 // Create network service object
1554 //
1555
1556 void CConsoleApp::CreateNetworkService(DWORD dwParent)
1557 {
1558 NXC_OBJECT_CREATE_INFO ci;
1559 CCreateNetSrvDlg dlg;
1560
1561 dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
1562 if (dlg.m_pParentObject != NULL)
1563 if (dlg.m_pParentObject->iClass != OBJECT_NODE)
1564 dlg.m_pParentObject = NULL;
1565 dlg.m_iServiceType = NETSRV_HTTP;
1566 dlg.m_iPort = 80;
1567 dlg.m_iProtocolNumber = 6;
1568 dlg.m_iProtocolType = 0;
1569 if (dlg.DoModal() == IDOK)
1570 {
1571 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1572 ci.iClass = OBJECT_NETWORKSERVICE;
1573 ci.pszName = (TCHAR *)((LPCTSTR)dlg.m_strObjectName);
1574 ci.cs.netsrv.iServiceType = dlg.m_iServiceType;
1575 ci.cs.netsrv.wPort = (WORD)dlg.m_iPort;
1576 ci.cs.netsrv.wProto = (WORD)dlg.m_iProtocolNumber;
1577 ci.cs.netsrv.pszRequest = (TCHAR *)((LPCTSTR)dlg.m_strRequest);
1578 ci.cs.netsrv.pszResponse = (TCHAR *)((LPCTSTR)dlg.m_strResponse);
1579 CreateObject(&ci);
1580 }
1581 }
1582
1583
1584 //
1585 // Create template object
1586 //
1587
1588 void CConsoleApp::CreateTemplate(DWORD dwParent)
1589 {
1590 NXC_OBJECT_CREATE_INFO ci;
1591 CCreateTemplateDlg dlg;
1592
1593 dlg.m_iObjectClass = OBJECT_TEMPLATE;
1594 dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
1595 if (dlg.m_pParentObject != NULL)
1596 if ((dlg.m_pParentObject->iClass != OBJECT_TEMPLATEGROUP) &&
1597 (dlg.m_pParentObject->iClass != OBJECT_TEMPLATEROOT))
1598 dlg.m_pParentObject = NULL;
1599 if (dlg.DoModal() == IDOK)
1600 {
1601 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1602 ci.iClass = OBJECT_TEMPLATE;
1603 ci.pszName = (char *)((LPCTSTR)dlg.m_strObjectName);
1604 CreateObject(&ci);
1605 }
1606 }
1607
1608
1609 //
1610 // Create template group object
1611 //
1612
1613 void CConsoleApp::CreateTemplateGroup(DWORD dwParent)
1614 {
1615 NXC_OBJECT_CREATE_INFO ci;
1616 CCreateTGDlg dlg;
1617
1618 dlg.m_iObjectClass = OBJECT_TEMPLATEGROUP;
1619 dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
1620 if (dlg.m_pParentObject != NULL)
1621 if ((dlg.m_pParentObject->iClass != OBJECT_TEMPLATEGROUP) &&
1622 (dlg.m_pParentObject->iClass != OBJECT_TEMPLATEROOT))
1623 dlg.m_pParentObject = NULL;
1624 if (dlg.DoModal() == IDOK)
1625 {
1626 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1627 ci.iClass = OBJECT_TEMPLATEGROUP;
1628 ci.pszName = (char *)((LPCTSTR)dlg.m_strObjectName);
1629 ci.cs.templateGroup.pszDescription = (char *)((LPCTSTR)dlg.m_strDescription);
1630 CreateObject(&ci);
1631 }
1632 }
1633
1634
1635 //
1636 // Create VPN connector object
1637 //
1638
1639 void CConsoleApp::CreateVPNConnector(DWORD dwParent)
1640 {
1641 NXC_OBJECT_CREATE_INFO ci;
1642 CCreateVPNConnDlg dlg;
1643
1644 dlg.m_iObjectClass = OBJECT_VPNCONNECTOR;
1645 dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
1646 if (dlg.m_pParentObject != NULL)
1647 if (dlg.m_pParentObject->iClass != OBJECT_NODE)
1648 dlg.m_pParentObject = NULL;
1649 if (dlg.DoModal() == IDOK)
1650 {
1651 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1652 ci.iClass = OBJECT_VPNCONNECTOR;
1653 ci.pszName = (char *)((LPCTSTR)dlg.m_strObjectName);
1654 CreateObject(&ci);
1655 }
1656 }
1657
1658
1659 //
1660 // Delete object on server
1661 //
1662
1663 void CConsoleApp::DeleteNetXMSObject(NXC_OBJECT *pObject)
1664 {
1665 DWORD dwResult;
1666
1667 dwResult = DoRequestArg2(NXCDeleteObject, g_hSession, (void *)pObject->dwId, "Deleting object...");
1668 if (dwResult != RCC_SUCCESS)
1669 ErrorBox(dwResult, "Unable to delete object: %s");
1670 }
1671
1672
1673 //
1674 // Perform forced poll on a node
1675 //
1676
1677 void CConsoleApp::PollNode(DWORD dwObjectId, int iPollType)
1678 {
1679 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1680 CNodePoller *pWnd;
1681
1682 pWnd = (CNodePoller *)pFrame->CreateNewChild(
1683 RUNTIME_CLASS(CNodePoller), IDR_NODE_POLLER, m_hMDIMenu, m_hMDIAccel);
1684 if (pWnd != NULL)
1685 {
1686 pWnd->m_dwObjectId = dwObjectId;
1687 pWnd->m_iPollType = iPollType;
1688 pWnd->PostMessage(WM_COMMAND, ID_POLL_RESTART, 0);
1689 }
1690 }
1691
1692
1693 //
1694 // WM_COMMAND::ID_TOOLS_ADDNODE message handler
1695 //
1696
1697 void CConsoleApp::OnToolsAddnode()
1698 {
1699 CreateNode(0);
1700 }
1701
1702
1703 //
1704 // Wake up node
1705 //
1706
1707 void CConsoleApp::WakeUpNode(DWORD dwObjectId)
1708 {
1709 DWORD dwResult;
1710
1711 dwResult = DoRequestArg2(NXCWakeUpNode, g_hSession, (void *)dwObjectId, _T("Sending Wake-On-LAN magic packet to node..."));
1712 if (dwResult != RCC_SUCCESS)
1713 ErrorBox(dwResult, _T("Unable to send WOL magic packet: %s"));
1714 else
1715 m_pMainWnd->MessageBox(_T("Wake-On-LAN magic packet was successfully sent to node"),
1716 _T("Information"), MB_ICONINFORMATION | MB_OK);
1717 }
1718
1719
1720 //
1721 // Deploy package to nodes
1722 //
1723
1724 void CConsoleApp::DeployPackage(DWORD dwPkgId, DWORD dwNumObjects, DWORD *pdwObjectList)
1725 {
1726 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1727 CMDIChildWnd *pWnd;
1728
1729 pWnd = pFrame->CreateNewChild(
1730 RUNTIME_CLASS(CDeploymentView), IDR_DEPLOYMENT_VIEW, m_hMDIMenu, m_hMDIAccel);
1731 if (pWnd != NULL)
1732 {
1733 DEPLOYMENT_JOB *pJob;
1734
1735 pJob = (DEPLOYMENT_JOB *)malloc(sizeof(DEPLOYMENT_JOB));
1736 pJob->dwPkgId = dwPkgId;
1737 pJob->dwNumObjects = dwNumObjects;
1738 pJob->pdwObjectList = (DWORD *)nx_memdup(pdwObjectList, sizeof(DWORD) * dwNumObjects);
1739 pWnd->PostMessage(WM_START_DEPLOYMENT, 0, (LPARAM)pJob);
1740 }
1741 }
1742
1743
1744 //
1745 // Show last collected DCI values
1746 //
1747
1748 CMDIChildWnd *CConsoleApp::ShowLastValues(NXC_OBJECT *pObject, TCHAR *pszParams)
1749 {
1750 CLastValuesView *pWnd;
1751
1752 if (pObject != NULL)
1753 {
1754 if (pObject->iClass != OBJECT_NODE)
1755 return NULL;
1756
1757 pWnd = new CLastValuesView(pObject->dwId);
1758 }
1759 else
1760 {
1761 pWnd = new CLastValuesView(pszParams);
1762 pObject = NXCFindObjectById(g_hSession, pWnd->GetObjectId());
1763 }
1764 CreateChildFrameWithSubtitle(pWnd, IDR_LAST_VALUES_VIEW,
1765 (pObject != NULL) ? pObject->szName : _T("unknown object"),
1766 m_hLastValuesMenu, m_hLastValuesAccel);
1767 return pWnd;
1768 }
1769
1770
1771 //
1772 // Create child frame and add subtitle (- [<text>]) to it
1773 //
1774
1775 void CConsoleApp::CreateChildFrameWithSubtitle(CMDIChildWnd *pWnd, UINT nId,
1776 TCHAR *pszSubTitle, HMENU hMenu, HACCEL hAccel)
1777 {
1778 CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1779 CCreateContext context;
1780
1781 // load the frame
1782 context.m_pCurrentFrame = pFrame;
1783
1784 if (pWnd->LoadFrame(nId, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
1785 {
1786 CString strFullString, strTitle;
1787
1788 if (strFullString.LoadString(nId))
1789 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
1790
1791 // add frame subtitle
1792 if (pszSubTitle != NULL)
1793 {
1794 strTitle += " - [";
1795 strTitle += pszSubTitle;
1796 strTitle += "]";
1797 }
1798
1799 // set the handles and redraw the frame and parent
1800 pWnd->SetHandles(hMenu, hAccel);
1801 pWnd->SetTitle(strTitle);
1802 pWnd->InitialUpdateFrame(NULL, TRUE);
1803 }
1804 else
1805 {
1806 delete pWnd;
1807 }
1808 }
1809
1810
1811 //
1812 // Apply template worker function
1813 //
1814
1815 static DWORD ApplyTemplateToNodes(DWORD dwTemplateId, DWORD dwNumNodes, DWORD *pdwNodeList)
1816 {
1817 DWORD i, dwResult = RCC_SUCCESS;
1818
1819 for(i = 0; (i < dwNumNodes) && (dwResult == RCC_SUCCESS); i++)
1820 dwResult = NXCApplyTemplate(g_hSession, dwTemplateId, pdwNodeList[i]);
1821 return dwResult;
1822 }
1823
1824
1825 //
1826 // Apply template object to node(s)
1827 //
1828
1829 void CConsoleApp::ApplyTemplate(NXC_OBJECT *pObject)
1830 {
1831 CObjectSelDlg dlg;
1832 DWORD dwResult;
1833
1834 dlg.m_dwAllowedClasses = SCL_NODE;
1835 if (dlg.DoModal() == IDOK)
1836 {
1837 dwResult = DoRequestArg3(ApplyTemplateToNodes, (void *)pObject->dwId,
1838 (void *)dlg.m_dwNumObjects, dlg.m_pdwObjectList,
1839 _T("Applying template..."));
1840 if (dwResult != RCC_SUCCESS)
1841 ErrorBox(dwResult, _T("Error applying template: %s"));
1842 }
1843 }
1844
1845
1846 //
1847 // Show network summary window
1848 //
1849
1850 CMDIChildWnd *CConsoleApp::ShowNetworkSummary(void)
1851 {
1852 CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1853 CMDIChildWnd *pWnd;
1854
1855 // create a new MDI child window or open existing
1856 if (m_bNetSummaryActive)
1857 {
1858 m_pwndNetSummary->BringWindowToTop();
1859 pWnd = m_pwndNetSummary;
1860 }
1861 else
1862 {
1863 pWnd = pFrame->CreateNewChild(RUNTIME_CLASS(CNetSummaryFrame),
1864 IDR_NETWORK_SUMMARY, m_hMDIMenu, m_hMDIAccel);
1865 }
1866 return pWnd;
1867 }
1868
1869
1870 //
1871 // Object binding worker function
1872 //
1873
1874 static DWORD DoObjectBinding(DWORD dwCmd, DWORD dwParent, DWORD dwNumChilds,
1875 DWORD *pdwChildList, BOOL bRemoveDCI)
1876 {
1877 DWORD i, dwResult;
1878
1879 switch(dwCmd)
1880 {
1881 case 0: // Bind object
1882 for(i = 0; i < dwNumChilds; i++)
1883 {
1884 dwResult = NXCBindObject(g_hSession, dwParent, pdwChildList[i]);
1885 if (dwResult != RCC_SUCCESS)
1886 break;
1887 }
1888 break;
1889 case 1: // Unbind object
1890 for(i = 0; i < dwNumChilds; i++)
1891 {
1892 dwResult = NXCUnbindObject(g_hSession, dwParent, pdwChildList[i]);
1893 if (dwResult != RCC_SUCCESS)
1894 break;
1895 }
1896 break;
1897 case 2: // Unbind node from template (remove template)
1898 for(i = 0; i < dwNumChilds; i++)
1899 {
1900 dwResult = NXCRemoveTemplate(g_hSession, dwParent, pdwChildList[i], bRemoveDCI);
1901 if (dwResult != RCC_SUCCESS)
1902 break;
1903 }
1904 break;
1905 default:
1906 break;
1907 }
1908 return dwResult;
1909 }
1910
1911
1912 //
1913 // Bind new object(s) to current
1914 //
1915
1916 void CConsoleApp::BindObject(NXC_OBJECT *pObject)
1917 {
1918 CObjectSelDlg dlg;
1919 DWORD dwResult;
1920
1921 dlg.m_dwAllowedClasses = SCL_NODE | SCL_CONTAINER | SCL_SUBNET | SCL_ZONE;
1922 if (dlg.DoModal() == IDOK)
1923 {
1924 dwResult = DoRequestArg5(DoObjectBinding, (void *)0, (void *)pObject->dwId,
1925 (void *)dlg.m_dwNumObjects, dlg.m_pdwObjectList,
1926 (void *)0, _T("Binding objects..."));
1927 if (dwResult != RCC_SUCCESS)
1928 ErrorBox(dwResult, _T("Cannot bind object: %s"));
1929 }
1930 }
1931
1932
1933 //
1934 // Unbind object(s) from current
1935 //
1936
1937 void CConsoleApp::UnbindObject(NXC_OBJECT *pObject)
1938 {
1939 CObjectSelDlg dlg;
1940 DWORD dwResult, dwCmd = 1;
1941 BOOL bRun = TRUE, bRemoveDCI = FALSE;
1942
1943 dlg.m_dwAllowedClasses = SCL_NODE | SCL_CONTAINER | SCL_SUBNET | SCL_ZONE;
1944 dlg.m_dwParentObject = pObject->dwId;
1945 if (dlg.DoModal() == IDOK)
1946 {
1947 if (pObject->iClass == OBJECT_TEMPLATE)
1948 {
1949 CRemoveTemplateDlg dlgRemove;
1950
1951 dlgRemove.m_iRemoveDCI = 0;
1952 if (dlgRemove.DoModal() == IDOK)
1953 {
1954 bRemoveDCI = dlgRemove.m_iRemoveDCI;
1955 dwCmd = 2;
1956 }
1957 else
1958 {
1959 bRun = FALSE; // Cancel unbind
1960 }
1961 }
1962
1963 if (bRun)
1964 {
1965 dwResult = DoRequestArg5(DoObjectBinding, (void *)dwCmd, (void *)pObject->dwId,
1966 (void *)dlg.m_dwNumObjects, dlg.m_pdwObjectList,
1967 (void *)bRemoveDCI, _T("Unbinding objects..."));
1968 if (dwResult != RCC_SUCCESS)
1969 ErrorBox(dwResult, _T("Cannot unbind object: %s"));
1970 }
1971 }
1972 }
1973
1974
1975 //
1976 // Change IP address for node
1977 //
1978
1979 void CConsoleApp::ChangeNodeAddress(DWORD dwNodeId)
1980 {
1981 CAddrChangeDlg dlg;
1982 DWORD dwResult;
1983
1984 if (dlg.DoModal() == IDOK)
1985 {
1986 dwResult = DoRequestArg3(NXCChangeNodeIP, g_hSession, (void *)dwNodeId,
1987 (void *)dlg.m_dwIpAddr, _T("Changing node's IP address..."));
1988 if (dwResult != RCC_SUCCESS)
1989 ErrorBox(dwResult, _T("Error changing IP address for node: %s"));
1990 }
1991 }
1992
1993 CMDIChildWnd *CConsoleApp::ShowObjectBrowser(TCHAR *pszParams)
1994 {
1995 CMDIChildWnd *pWnd;
1996
1997 // create a new MDI child window or open existing
1998 if (m_bObjectBrowserActive)
1999 {
2000 m_pwndObjectBrowser->BringWindowToTop();
2001 pWnd = m_pwndObjectBrowser;
2002 }
2003 else
2004 {
2005 CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
2006
2007 if (pszParams == NULL)
2008 {
2009 pWnd = pFrame->CreateNewChild(RUNTIME_CLASS(CObjectBrowser), IDR_OBJECTS,
2010 m_hObjectBrowserMenu, m_hObjectBrowserAccel);
2011 }
2012 else
2013 {
2014 pWnd = new CObjectBrowser(pszParams);
2015 CreateChildFrameWithSubtitle(pWnd, IDR_OBJECTS, NULL, m_hObjectBrowserMenu, m_hObjectBrowserAccel);
2016 }
2017 }
2018 return pWnd;
2019 }
2020
2021
2022 //
2023 // Edit agent's configuration file
2024 //
2025
2026 void CConsoleApp::EditAgentConfig(NXC_OBJECT *pNode)
2027 {
2028 CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
2029 CAgentCfgEditor *pWnd;
2030
2031 pWnd = new CAgentCfgEditor(pNode->dwId);
2032 CreateChildFrameWithSubtitle(pWnd, IDR_AGENT_CFG_EDITOR, pNode->szName,
2033 m_hAgentCfgEditorMenu, m_hAgentCfgEditorAccel);
2034 }
2035
2036
2037 //
2038 // Worker function for DCI data export
2039 //
2040
2041 static DWORD DoDataExport(DWORD dwNodeId, DWORD dwItemId, DWORD dwTimeFrom,
2042 DWORD dwTimeTo, int iSeparator, int iTimeStampFormat,
2043 const TCHAR *pszFile)
2044 {
2045 DWORD i, dwResult;
2046 NXC_DCI_DATA *pData;
2047 NXC_DCI_ROW *pRow;
2048 int hFile;
2049 char szBuffer[MAX_DB_STRING];
2050 static char separator[4] = { '\t', ' ', ',', ';' };
2051
2052 dwResult = NXCGetDCIData(g_hSession, dwNodeId, dwItemId, 0, dwTimeFrom,
2053 dwTimeTo, &pData);
2054 if (dwResult == RCC_SUCCESS)
2055 {
2056 hFile = _topen(pszFile, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, S_IREAD | S_IWRITE);
2057 if (hFile != -1)
2058 {
2059 pRow = pData->pRows;
2060 for(i = 0; i < pData->dwNumRows; i++)
2061 {
2062 switch(iTimeStampFormat)
2063 {
2064 case 0: // RAW
2065 sprintf(szBuffer, "%lu", pRow->dwTimeStamp);
2066 break;
2067 case 1: // Text
2068 FormatTimeStamp(pRow->dwTimeStamp, szBuffer, TS_LONG_DATE_TIME);
2069 break;
2070 default:
2071 strcpy(szBuffer, "<internal error>");
2072 break;
2073 }
2074 write(hFile, szBuffer, strlen(szBuffer));
2075 write(hFile, &separator[iSeparator], 1);
2076 switch(pData->wDataType)
2077 {
2078 case DCI_DT_STRING:
2079 write(hFile, pRow->value.szString, strlen(pRow->value.szString));
2080 break;
2081 case DCI_DT_INT:
2082 sprintf(szBuffer, "%ld", pRow->value.dwInt32);
2083 write(hFile, szBuffer, strlen(szBuffer));
2084 break;
2085 case DCI_DT_UINT:
2086 sprintf(szBuffer, "%lu", pRow->value.dwInt32);
2087 write(hFile, szBuffer, strlen(szBuffer));
2088 break;
2089 case DCI_DT_INT64:
2090 sprintf(szBuffer, "%I64d", pRow->value.qwInt64);
2091 write(hFile, szBuffer, strlen(szBuffer));
2092 break;
2093 case DCI_DT_UINT64:
2094 sprintf(szBuffer, "%I64u", pRow->value.qwInt64);
2095 write(hFile, szBuffer, strlen(szBuffer));
2096 break;
2097 case DCI_DT_FLOAT:
2098 sprintf(szBuffer, "%f", pRow->value.dFloat);
2099 write(hFile, szBuffer, strlen(szBuffer));
2100 break;
2101 default:
2102 break;
2103 }
2104 write(hFile, "\r\n", 2);
2105 inc_ptr(pRow, pData->wRowSize, NXC_DCI_ROW);
2106 }
2107 close(hFile);
2108 }
2109 else
2110 {
2111 dwResult = RCC_IO_ERROR;
2112 }
2113 NXCDestroyDCIData(pData);
2114 }
2115 return dwResult;
2116 }
2117
2118
2119 //
2120 // Export DCI's data
2121 //
2122
2123 void CConsoleApp::ExportDCIData(DWORD dwNodeId, DWORD dwItemId,
2124 DWORD dwTimeFrom, DWORD dwTimeTo,
2125 int iSeparator, int iTimeStampFormat,
2126 const TCHAR *pszFile)
2127 {
2128 DWORD dwResult;
2129
2130 dwResult = DoRequestArg7(DoDataExport, (void *)dwNodeId, (void *)dwItemId,
2131 (void *)dwTimeFrom, (void *)dwTimeTo,
2132 (void *)iSeparator, (void *)iTimeStampFormat,
2133 (void *)pszFile, _T("Exporting data..."));
2134 if (dwResult == RCC_SUCCESS)
2135 m_pMainWnd->MessageBox(_T("Collected DCI data was successfuly exported."),
2136 _T("Information"), MB_OK | MB_ICONINFORMATION);
2137 else
2138 ErrorBox(dwResult, _T("Error exporting DCI data: %s"));
2139 }
2140
2141
2142 //
2143 // WM_COMMAND::ID_CONTROLPANEL_SERVERCFG message handler
2144 //
2145
2146 void CConsoleApp::OnControlpanelServercfg()
2147 {
2148 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
2149
2150 // create a new MDI child window or open existing
2151 if (m_bServerCfgEditorActive)
2152 {
2153 m_pwndServerCfgEditor->BringWindowToTop();
2154 }
2155 else
2156 {
2157 pFrame->CreateNewChild(
2158 RUNTIME_CLASS(CServerCfgEditor), IDR_SERVER_CFG_EDITOR, m_hServerCfgEditorMenu, m_hServerCfgEditorAccel);
2159 }
2160 }
2161
2162
2163 //
2164 // Execute object tool
2165 //
2166
2167 void CConsoleApp::ExecuteObjectTool(NXC_OBJECT *pObject, DWORD dwIndex)
2168 {
2169 DWORD dwResult;
2170
2171 if ((dwIndex >= g_dwNumObjectTools) ||
2172 (pObject->iClass != OBJECT_NODE))
2173 return;
2174
2175 switch(g_pObjectToolList[dwIndex].wType)
2176 {
2177 case TOOL_TYPE_INTERNAL:
2178 if (!_tcsicmp(g_pObjectToolList[dwIndex].pszData, _T("wakeup")))
2179 {
2180 WakeUpNode(pObject->dwId);
2181 }
2182 else
2183 {
2184 m_pMainWnd->MessageBox(_T("This type of tool is not implemented yet"), _T("Warning"), MB_OK | MB_ICONSTOP);
2185 }
2186 break;
2187 case TOOL_TYPE_ACTION:
2188 if (pObject->node.dwFlags & NF_IS_NATIVE_AGENT)
2189 {
2190 dwResult = DoRequestArg3(NXCExecuteAction, g_hSession, (void *)pObject->dwId,
2191 g_pObjectToolList[dwIndex].pszData,
2192 _T("Executing action on agent..."));
2193 if (dwResult == RCC_SUCCESS)
2194 {
2195 m_pMainWnd->MessageBox(_T("Action executed successfully"), _T("Information"), MB_OK | MB_ICONINFORMATION);
2196 }
2197 else
2198 {
2199 ErrorBox(dwResult, _T("Error executing action on agent: %s"));
2200 }
2201 }
2202 else
2203 {
2204 m_pMainWnd->MessageBox(_T("Node doesn't have NetXMS agent"), _T("Error"), MB_OK | MB_ICONSTOP);
2205 }
2206 break;
2207 case TOOL_TYPE_TABLE_AGENT:
2208 if (pObject->node.dwFlags & NF_IS_NATIVE_AGENT)
2209 {
2210 ExecuteTableTool(pObject, g_pObjectToolList[dwIndex].dwId);
2211 }
2212 else
2213 {
2214 m_pMainWnd->MessageBox(_T("Node doesn't have NetXMS agent"), _T("Error"), MB_OK | MB_ICONSTOP);
2215 }
2216 break;
2217 case TOOL_TYPE_TABLE_SNMP:
2218 if (pObject->node.dwFlags & NF_IS_SNMP)
2219 {
2220 ExecuteTableTool(pObject, g_pObjectToolList[dwIndex].dwId);
2221 }
2222 else
2223 {
2224 m_pMainWnd->MessageBox(_T("Node doesn't have SNMP agent"), _T("Error"), MB_OK | MB_ICONSTOP);
2225 }
2226 break;
2227 case TOOL_TYPE_URL:
2228 ExecuteWebTool(pObject, g_pObjectToolList[dwIndex].pszData);
2229 break;
2230 default:
2231 m_pMainWnd->MessageBox(_T("This type of tool is not implemented yet"), _T("Warning"), MB_OK | MB_ICONSTOP);
2232 break;
2233 }
2234 }
2235
2236
2237 //
2238 // Execute table tool on given node
2239 //
2240
2241 void CConsoleApp::ExecuteTableTool(NXC_OBJECT *pNode, DWORD dwToolId)
2242 {
2243 CTableView *pWnd;
2244
2245 pWnd = new CTableView(pNode->dwId, dwToolId);
2246 CreateChildFrameWithSubtitle(pWnd, IDR_TABLE_VIEW,
2247 pNode->szName, m_hMDIMenu, m_hMDIAccel);
2248 // return pWnd;
2249 }
2250
2251
2252 //
2253 // Execute web tool (open specified URL)
2254 //
2255
2256 void CConsoleApp::ExecuteWebTool(NXC_OBJECT *pObject, TCHAR *pszURL)
2257 {
2258 TCHAR szRealURL[4096];
2259
2260 _stprintf(szRealURL, _T("%lu"), pObject->dwId);
2261 SetEnvironmentVariable(_T("OBJECT_ID"), szRealURL);
2262 SetEnvironmentVariable(_T("OBJECT_IP_ADDR"), IpToStr(pObject->dwIpAddr, szRealURL));
2263 SetEnvironmentVariable(_T("OBJECT_NAME"), pObject->szName);
2264 ExpandEnvironmentStrings(pszURL, szRealURL, 4096);
2265 StartWebBrowser(szRealURL);
2266 }
2267
2268
2269 //
2270 // Start embedded web browser
2271 //
2272
2273 void CConsoleApp::StartWebBrowser(TCHAR *pszURL)
2274 {
2275 CWebBrowser *pWnd;
2276
2277 pWnd = new CWebBrowser(pszURL);
2278 CreateChildFrameWithSubtitle(pWnd, IDR_WEB_BROWSER, pszURL, m_hMDIMenu, m_hMDIAccel);
2279 }
2280
2281
2282 //
2283 // Execute object move
2284 //
2285
2286 static DWORD DoObjectMove(DWORD dwObject, DWORD dwOldParent, DWORD dwNewParent)
2287 {
2288 DWORD dwResult;
2289
2290 dwResult = NXCBindObject(g_hSession, dwNewParent, dwObject);
2291 if (dwResult == RCC_SUCCESS)
2292 {
2293 dwResult = NXCUnbindObject(g_hSession, dwOldParent, dwObject);
2294 if (dwResult != RCC_SUCCESS)
2295 NXCUnbindObject(g_hSession, dwNewParent, dwObject); // Undo binding to new parent
2296 }
2297 return dwResult;
2298 }
2299
2300
2301 //
2302 // Move object between containers
2303 //
2304
2305 void CConsoleApp::MoveObject(DWORD dwObjectId, DWORD dwParentId)
2306 {
2307 CObjectSelDlg dlg;
2308 DWORD dwResult;
2309
2310 dlg.m_dwAllowedClasses = SCL_CONTAINER | SCL_SERVICEROOT;
2311 dlg.m_bSingleSelection = TRUE;
2312 if (dlg.DoModal() == IDOK)
2313 {
2314 dwResult = DoRequestArg3(DoObjectMove, (void *)dwObjectId, (void *)dwParentId,
2315 (void *)dlg.m_pdwObjectList[0], _T("Moving object..."));
2316 if (dwResult != RCC_SUCCESS)
2317 ErrorBox(dwResult, _T("Error moving object: %s"));
2318 }
2319 }