- Finished migration to new client library model
[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 "NodePoller.h"
14 #include "MIBBrowserDlg.h"
15
16 #ifdef _DEBUG
17 #define new DEBUG_NEW
18 #undef THIS_FILE
19 static char THIS_FILE[] = __FILE__;
20 #endif
21
22
23 //
24 // Constants
25 //
26
27 #define LAST_APP_MENU 3
28
29
30 //
31 // Wrapper for client library debug callback
32 //
33
34 static void ClientDebugCallback(char *pszMsg)
35 {
36 theApp.DebugCallback(pszMsg);
37 }
38
39
40 //
41 // CConsoleApp
42 //
43
44 BEGIN_MESSAGE_MAP(CConsoleApp, CWinApp)
45 //{{AFX_MSG_MAP(CConsoleApp)
46 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
47 ON_COMMAND(ID_VIEW_CONTROLPANEL, OnViewControlpanel)
48 ON_COMMAND(ID_VIEW_EVENTS, OnViewEvents)
49 ON_COMMAND(ID_VIEW_MAP, OnViewMap)
50 ON_COMMAND(ID_CONNECT_TO_SERVER, OnConnectToServer)
51 ON_COMMAND(ID_VIEW_OBJECTBROWSER, OnViewObjectbrowser)
52 ON_COMMAND(ID_CONTROLPANEL_EVENTS, OnControlpanelEvents)
53 ON_COMMAND(ID_VIEW_DEBUG, OnViewDebug)
54 ON_COMMAND(ID_CONTROLPANEL_USERS, OnControlpanelUsers)
55 ON_COMMAND(ID_VIEW_NETWORKSUMMARY, OnViewNetworksummary)
56 ON_COMMAND(ID_TOOLS_MIBBROWSER, OnToolsMibbrowser)
57 ON_COMMAND(ID_CONTROLPANEL_EVENTPOLICY, OnControlpanelEventpolicy)
58 ON_COMMAND(ID_VIEW_ALARMS, OnViewAlarms)
59 ON_COMMAND(ID_FILE_SETTINGS, OnFileSettings)
60 ON_COMMAND(ID_CONTROLPANEL_ACTIONS, OnControlpanelActions)
61 ON_COMMAND(ID_TOOLS_ADDNODE, OnToolsAddnode)
62 ON_COMMAND(ID_CONTROLPANEL_SNMPTRAPS, OnControlpanelSnmptraps)
63 //}}AFX_MSG_MAP
64 END_MESSAGE_MAP()
65
66
67 //
68 // CConsoleApp construction
69 //
70
71 CConsoleApp::CConsoleApp()
72 {
73 m_bActionEditorActive = FALSE;
74 m_bTrapEditorActive = FALSE;
75 m_bCtrlPanelActive = FALSE;
76 m_bAlarmBrowserActive = FALSE;
77 m_bEventBrowserActive = FALSE;
78 m_bEventEditorActive = FALSE;
79 m_bUserEditorActive = FALSE;
80 m_bObjectBrowserActive = FALSE;
81 m_bDebugWindowActive = FALSE;
82 m_bNetSummaryActive = FALSE;
83 m_bEventPolicyEditorActive = FALSE;
84 m_dwClientState = STATE_DISCONNECTED;
85 memset(m_openDCEditors, 0, sizeof(DC_EDITOR) * MAX_DC_EDITORS);
86 }
87
88
89 //
90 // CConsoleApp destruction
91 //
92
93 CConsoleApp::~CConsoleApp()
94 {
95 }
96
97
98 //
99 // The one and only CConsoleApp object
100 //
101
102 CConsoleApp theApp;
103
104
105 //
106 // Setup working directory
107 //
108
109 BOOL CConsoleApp::SetupWorkDir()
110 {
111 int iLastChar;
112
113 // Get path to user's "Application Data" folder
114 if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, g_szWorkDir) != S_OK)
115 {
116 AfxMessageBox(IDS_GETFOLDERPATH_FAILED, MB_OK | MB_ICONSTOP);
117 return FALSE;
118 }
119
120 // Create working directory root
121 strcat(g_szWorkDir, "\\NetXMS Console");
122 if (!CreateDirectory(g_szWorkDir, NULL))
123 if (GetLastError() != ERROR_ALREADY_EXISTS)
124 {
125 AfxMessageBox(IDS_WORKDIR_CREATION_FAILED, MB_OK | MB_ICONSTOP);
126 return FALSE;
127 }
128 iLastChar = strlen(g_szWorkDir);
129
130 // Create MIB cache directory
131 strcpy(&g_szWorkDir[iLastChar], WORKDIR_MIBCACHE);
132 if (!CreateDirectory(g_szWorkDir, NULL))
133 if (GetLastError() != ERROR_ALREADY_EXISTS)
134 {
135 AfxMessageBox(IDS_WORKDIR_CREATION_FAILED, MB_OK | MB_ICONSTOP);
136 return FALSE;
137 }
138
139 // Create image cache directory
140 strcpy(&g_szWorkDir[iLastChar], WORKDIR_IMAGECACHE);
141 if (!CreateDirectory(g_szWorkDir, NULL))
142 if (GetLastError() != ERROR_ALREADY_EXISTS)
143 {
144 AfxMessageBox(IDS_WORKDIR_CREATION_FAILED, MB_OK | MB_ICONSTOP);
145 return FALSE;
146 }
147
148 // Success
149 g_szWorkDir[iLastChar] = 0;
150 return TRUE;
151 }
152
153
154 //
155 // CConsoleApp initialization
156 //
157
158 BOOL CConsoleApp::InitInstance()
159 {
160 BOOL bSetWindowPos;
161 DWORD dwBytes;
162 BYTE *pData;
163 HMENU hMenu;
164
165 // Setup our working directory
166 if (!SetupWorkDir())
167 return FALSE;
168
169 if (!AfxSocketInit())
170 {
171 AfxMessageBox(IDP_SOCKETS_INIT_FAILED, MB_OK | MB_ICONSTOP);
172 return FALSE;
173 }
174
175 if (!NXCInitialize())
176 {
177 AfxMessageBox(IDS_NXC_INIT_FAILED, MB_OK | MB_ICONSTOP);
178 return FALSE;
179 }
180
181 AfxEnableControlContainer();
182
183 // Standard initialization
184 // If you are not using these features and wish to reduce the size
185 // of your final executable, you should remove from the following
186 // the specific initialization routines you do not need.
187
188 #ifdef _AFXDLL
189 Enable3dControls(); // Call this when using MFC in a shared DLL
190 #else
191 Enable3dControlsStatic(); // Call this when linking to MFC statically
192 #endif
193
194 // Change the registry key under which our settings are stored.
195 SetRegistryKey(_T("NetXMS"));
196
197 // Load configuration from registry
198 dwBytes = sizeof(WINDOWPLACEMENT);
199 bSetWindowPos = GetProfileBinary(_T("General"), _T("WindowPlacement"),
200 &pData, (UINT *)&dwBytes);
201 g_dwOptions = GetProfileInt(_T("General"), _T("Options"), 0);
202 strcpy(g_szServer, (LPCTSTR)GetProfileString(_T("Connection"), _T("Server"), _T("localhost")));
203 strcpy(g_szLogin, (LPCTSTR)GetProfileString(_T("Connection"), _T("Login"), NULL));
204 g_dwEncryptionMethod = GetProfileInt(_T("Connection"), _T("Encryption"), CSCP_ENCRYPTION_NONE);
205
206 // Create mutex for action list access
207 g_mutexActionListAccess = CreateMutex(NULL, FALSE, NULL);
208
209 // To create the main window, this code creates a new frame window
210 // object and then sets it as the application's main window object.
211 CMDIFrameWnd* pFrame = new CMainFrame;
212 m_pMainWnd = pFrame;
213
214 // create main MDI frame window
215 if (!pFrame->LoadFrame(IDR_MAINFRAME))
216 return FALSE;
217
218 // Load context menus
219 if (!m_ctxMenu.LoadMenu(IDM_CONTEXT))
220 MessageBox(NULL, "FAILED", "", 0);
221
222 // Load shared MDI menus and accelerator table
223 HINSTANCE hInstance = AfxGetResourceHandle();
224
225 hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDM_VIEW_SPECIFIC));
226
227 // Modify application menu as needed
228 if (g_dwOptions & UI_OPT_EXPAND_CTRLPANEL)
229 {
230 pFrame->GetMenu()->RemoveMenu(ID_VIEW_CONTROLPANEL, MF_BYCOMMAND);
231 pFrame->GetMenu()->InsertMenu(ID_VIEW_DEBUG, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 8), "&Control panel");
232 }
233
234 m_hMDIMenu = LoadAppMenu(hMenu);
235 InsertMenu(m_hMDIMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
236
237 m_hEventBrowserMenu = LoadAppMenu(hMenu);
238 InsertMenu(m_hEventBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
239 InsertMenu(m_hEventBrowserMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 1), "&Event");
240
241 m_hObjectBrowserMenu = LoadAppMenu(hMenu);
242 InsertMenu(m_hObjectBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
243 InsertMenu(m_hObjectBrowserMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 2), "&Object");
244
245 m_hUserEditorMenu = LoadAppMenu(hMenu);
246 InsertMenu(m_hUserEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
247 InsertMenu(m_hUserEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 3), "&User");
248
249 m_hDCEditorMenu = LoadAppMenu(hMenu);
250 InsertMenu(m_hDCEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
251 InsertMenu(m_hDCEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 4), "&Item");
252
253 m_hPolicyEditorMenu = LoadAppMenu(hMenu);
254 InsertMenu(m_hPolicyEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
255 InsertMenu(m_hPolicyEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 5), "&Policy");
256
257 m_hAlarmBrowserMenu = LoadAppMenu(hMenu);
258 InsertMenu(m_hAlarmBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
259 InsertMenu(m_hAlarmBrowserMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 6), "&Alarm");
260
261 m_hMapMenu = LoadAppMenu(hMenu);
262 InsertMenu(m_hMapMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
263 InsertMenu(m_hMapMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 9), "&Object");
264
265 m_hEventEditorMenu = LoadAppMenu(hMenu);
266 InsertMenu(m_hEventEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
267 InsertMenu(m_hEventEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 10), "&Event");
268
269 m_hActionEditorMenu = LoadAppMenu(hMenu);
270 InsertMenu(m_hActionEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
271 InsertMenu(m_hActionEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 11), "&Action");
272
273 m_hTrapEditorMenu = LoadAppMenu(hMenu);
274 InsertMenu(m_hTrapEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
275 InsertMenu(m_hTrapEditorMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 12), "T&rap");
276
277 m_hGraphMenu = LoadAppMenu(hMenu);
278 InsertMenu(m_hGraphMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
279 InsertMenu(m_hGraphMenu, LAST_APP_MENU - 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 13), "&Graph");
280
281 m_hMDIAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
282 m_hAlarmBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_ALARM_BROWSER));
283 m_hEventBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
284 m_hObjectBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_OBJECT_BROWSER));
285 m_hEventEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_EVENT_EDITOR));
286 m_hUserEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
287 m_hDCEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
288 m_hPolicyEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_EPP));
289 m_hMapAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_NETMAP));
290 m_hActionEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_ACTION_EDITOR));
291 m_hTrapEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_TRAP_EDITOR));
292 m_hGraphAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_GRAPH));
293
294 // The main window has been initialized, so show and update it.
295 if (bSetWindowPos)
296 {
297 pFrame->SetWindowPlacement((WINDOWPLACEMENT *)pData);
298 if (pFrame->IsIconic())
299 pFrame->ShowWindow(SW_RESTORE);
300 }
301 else
302 {
303 pFrame->ShowWindow(m_nCmdShow);
304 }
305 pFrame->UpdateWindow();
306 pFrame->PostMessage(WM_COMMAND, ID_VIEW_DEBUG, 0);
307 pFrame->PostMessage(WM_COMMAND, ID_CONNECT_TO_SERVER, 0);
308
309 return TRUE;
310 }
311
312 /////////////////////////////////////////////////////////////////////////////
313 // CConsoleApp message handlers
314
315 int CConsoleApp::ExitInstance()
316 {
317 NXCSetDebugCallback(NULL);
318 NXCDisconnect(g_hSession);
319 NXCShutdown();
320 NXCDestroyCCList(g_pCCList);
321
322 // Save configuration
323 WriteProfileInt(_T("General"), _T("Options"), g_dwOptions);
324
325 // Free resources
326 SafeFreeResource(m_hMDIMenu);
327 SafeFreeResource(m_hMDIAccel);
328 SafeFreeResource(m_hAlarmBrowserMenu);
329 SafeFreeResource(m_hAlarmBrowserAccel);
330 SafeFreeResource(m_hEventBrowserMenu);
331 SafeFreeResource(m_hEventBrowserAccel);
332 SafeFreeResource(m_hUserEditorMenu);
333 SafeFreeResource(m_hUserEditorAccel);
334 SafeFreeResource(m_hDCEditorMenu);
335 SafeFreeResource(m_hDCEditorAccel);
336 SafeFreeResource(m_hEventEditorMenu);
337 SafeFreeResource(m_hEventEditorAccel);
338 SafeFreeResource(m_hActionEditorMenu);
339 SafeFreeResource(m_hActionEditorAccel);
340 SafeFreeResource(m_hTrapEditorMenu);
341 SafeFreeResource(m_hTrapEditorAccel);
342 SafeFreeResource(m_hGraphMenu);
343 SafeFreeResource(m_hGraphAccel);
344
345 CloseHandle(g_mutexActionListAccess);
346
347 return CWinApp::ExitInstance();
348 }
349
350
351 /////////////////////////////////////////////////////////////////////////////
352 // CAboutDlg dialog used for App About
353
354 class CAboutDlg : public CDialog
355 {
356 public:
357 CAboutDlg();
358
359 // Dialog Data
360 //{{AFX_DATA(CAboutDlg)
361 enum { IDD = IDD_ABOUTBOX };
362 CStatic m_wndVersion;
363 //}}AFX_DATA
364
365 // ClassWizard generated virtual function overrides
366 //{{AFX_VIRTUAL(CAboutDlg)
367 protected:
368 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
369 //}}AFX_VIRTUAL
370
371 // Implementation
372 protected:
373 //{{AFX_MSG(CAboutDlg)
374 virtual BOOL OnInitDialog();
375 //}}AFX_MSG
376 DECLARE_MESSAGE_MAP()
377 };
378
379 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
380 {
381 //{{AFX_DATA_INIT(CAboutDlg)
382 //}}AFX_DATA_INIT
383 }
384
385 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
386 {
387 CDialog::DoDataExchange(pDX);
388 //{{AFX_DATA_MAP(CAboutDlg)
389 DDX_Control(pDX, IDC_VERSION, m_wndVersion);
390 //}}AFX_DATA_MAP
391 }
392
393 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
394 //{{AFX_MSG_MAP(CAboutDlg)
395 //}}AFX_MSG_MAP
396 END_MESSAGE_MAP()
397
398 BOOL CAboutDlg::OnInitDialog()
399 {
400 CDialog::OnInitDialog();
401
402 m_wndVersion.SetWindowText(_T("NetXMS Console Version ") NETXMS_VERSION_STRING);
403 return TRUE;
404 }
405
406 // App command to run the dialog
407 void CConsoleApp::OnAppAbout()
408 {
409 CAboutDlg aboutDlg;
410 aboutDlg.DoModal();
411 }
412
413 /////////////////////////////////////////////////////////////////////////////
414 // CConsoleApp message handlers
415
416
417 void CConsoleApp::OnViewControlpanel()
418 {
419 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
420
421 // create a new MDI child window or open existing
422 if (m_bCtrlPanelActive)
423 m_pwndCtrlPanel->BringWindowToTop();
424 else
425 pFrame->CreateNewChild(
426 RUNTIME_CLASS(CControlPanel), IDR_CTRLPANEL, m_hMDIMenu, m_hMDIAccel);
427 }
428
429
430 //
431 // This method called when new view is created
432 //
433
434 void CConsoleApp::OnViewCreate(DWORD dwView, CWnd *pWnd, DWORD dwArg)
435 {
436 DWORD i;
437
438 switch(dwView)
439 {
440 case IDR_CTRLPANEL:
441 m_bCtrlPanelActive = TRUE;
442 m_pwndCtrlPanel = pWnd;
443 break;
444 case IDR_ALARMS:
445 m_bAlarmBrowserActive = TRUE;
446 m_pwndAlarmBrowser = (CAlarmBrowser *)pWnd;
447 break;
448 case IDR_EVENTS:
449 m_bEventBrowserActive = TRUE;
450 m_pwndEventBrowser = (CEventBrowser *)pWnd;
451 break;
452 case IDR_OBJECTS:
453 m_bObjectBrowserActive = TRUE;
454 m_pwndObjectBrowser = pWnd;
455 break;
456 case IDR_EVENT_EDITOR:
457 m_bEventEditorActive = TRUE;
458 m_pwndEventEditor = (CEventEditor *)pWnd;
459 break;
460 case IDR_ACTION_EDITOR:
461 m_bActionEditorActive = TRUE;
462 m_pwndActionEditor = (CActionEditor *)pWnd;
463 break;
464 case IDR_TRAP_EDITOR:
465 m_bTrapEditorActive = TRUE;
466 m_pwndTrapEditor = (CTrapEditor *)pWnd;
467 break;
468 case IDR_USER_EDITOR:
469 m_bUserEditorActive = TRUE;
470 m_pwndUserEditor = (CUserEditor *)pWnd;
471 break;
472 case IDR_DEBUG_WINDOW:
473 m_bDebugWindowActive = TRUE;
474 m_pwndDebugWindow = (CDebugFrame *)pWnd;
475 NXCSetDebugCallback(ClientDebugCallback);
476 break;
477 case IDR_NETWORK_SUMMARY:
478 m_bNetSummaryActive = TRUE;
479 m_pwndNetSummary = (CNetSummaryFrame *)pWnd;
480 break;
481 case IDR_DC_EDITOR:
482 // Register new DC editor
483 for(i = 0; i < MAX_DC_EDITORS; i++)
484 if (m_openDCEditors[i].pWnd == NULL)
485 {
486 m_openDCEditors[i].pWnd = pWnd;
487 m_openDCEditors[i].dwNodeId = dwArg;
488 break;
489 }
490 break;
491 case IDR_EPP_EDITOR:
492 m_bEventPolicyEditorActive = TRUE;
493 m_pwndEventPolicyEditor = (CEventPolicyEditor *)pWnd;
494 break;
495 default:
496 break;
497 }
498 }
499
500
501 //
502 // This method called when view is destroyed
503 //
504
505 void CConsoleApp::OnViewDestroy(DWORD dwView, CWnd *pWnd, DWORD dwArg)
506 {
507 DWORD i;
508
509 switch(dwView)
510 {
511 case IDR_CTRLPANEL:
512 m_bCtrlPanelActive = FALSE;
513 break;
514 case IDR_ALARMS:
515 m_bAlarmBrowserActive = FALSE;
516 break;
517 case IDR_EVENTS:
518 m_bEventBrowserActive = FALSE;
519 break;
520 case IDR_OBJECTS:
521 m_bObjectBrowserActive = FALSE;
522 break;
523 case IDR_EVENT_EDITOR:
524 m_bEventEditorActive = FALSE;
525 break;
526 case IDR_ACTION_EDITOR:
527 m_bActionEditorActive = FALSE;
528 break;
529 case IDR_TRAP_EDITOR:
530 m_bTrapEditorActive = FALSE;
531 break;
532 case IDR_USER_EDITOR:
533 m_bUserEditorActive = FALSE;
534 break;
535 case IDR_DEBUG_WINDOW:
536 m_bDebugWindowActive = FALSE;
537 NXCSetDebugCallback(NULL);
538 break;
539 case IDR_NETWORK_SUMMARY:
540 m_bNetSummaryActive = FALSE;
541 break;
542 case IDR_DC_EDITOR:
543 // Unregister DC editor
544 for(i = 0; i < MAX_DC_EDITORS; i++)
545 if (m_openDCEditors[i].pWnd == pWnd)
546 {
547 m_openDCEditors[i].pWnd = NULL;
548 m_openDCEditors[i].dwNodeId = 0;
549 break;
550 }
551 break;
552 case IDR_EPP_EDITOR:
553 m_bEventPolicyEditorActive = FALSE;
554 break;
555 default:
556 break;
557 }
558 }
559
560
561 //
562 // WM_COMMAND::ID_VIEW_EVENTS message handler
563 //
564
565 void CConsoleApp::OnViewEvents()
566 {
567 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
568
569 // create a new MDI child window or open existing
570 if (m_bEventBrowserActive)
571 m_pwndEventBrowser->BringWindowToTop();
572 else
573 pFrame->CreateNewChild(
574 RUNTIME_CLASS(CEventBrowser), IDR_EVENTS, m_hEventBrowserMenu, m_hEventBrowserAccel);
575 }
576
577
578 //
579 // WM_COMMAND::ID_VIEW_MAP message handler
580 //
581
582 void CConsoleApp::OnViewMap()
583 {
584 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
585
586 // create a new MDI child window
587 pFrame->CreateNewChild(RUNTIME_CLASS(CMapFrame), IDR_MAPFRAME, m_hMapMenu, m_hMapAccel);
588 }
589
590
591 //
592 // WM_COMMAND::ID_CONNECT_TO_SERVER message handler
593 //
594
595 void CConsoleApp::OnConnectToServer()
596 {
597 CLoginDialog dlgLogin;
598 DWORD dwResult;
599
600 dlgLogin.m_szServer = g_szServer;
601 dlgLogin.m_szLogin = g_szLogin;
602 dlgLogin.m_iEncryption = g_dwEncryptionMethod;
603 do
604 {
605 if (dlgLogin.DoModal() != IDOK)
606 {
607 PostQuitMessage(1);
608 break;
609 }
610 strcpy(g_szServer, (LPCTSTR)dlgLogin.m_szServer);
611 strcpy(g_szLogin, (LPCTSTR)dlgLogin.m_szLogin);
612 strcpy(g_szPassword, (LPCTSTR)dlgLogin.m_szPassword);
613 g_dwEncryptionMethod = dlgLogin.m_iEncryption;
614
615 // Save last connection parameters
616 WriteProfileString(_T("Connection"), _T("Server"), g_szServer);
617 WriteProfileString(_T("Connection"), _T("Login"), g_szLogin);
618 WriteProfileInt(_T("Connection"), _T("Encryption"), g_dwEncryptionMethod);
619
620 // Initiate connection
621 dwResult = DoLogin();
622 if (dwResult != RCC_SUCCESS)
623 ErrorBox(dwResult, "Unable to connect: %s", "Connection error");
624 }
625 while(dwResult != RCC_SUCCESS);
626 }
627
628
629 //
630 // WM_COMMAND::ID_VIEW_OBJECTBROWSER message handler
631 //
632
633 void CConsoleApp::OnViewObjectbrowser()
634 {
635 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
636
637 // create a new MDI child window or open existing
638 if (m_bObjectBrowserActive)
639 m_pwndObjectBrowser->BringWindowToTop();
640 else
641 pFrame->CreateNewChild(
642 RUNTIME_CLASS(CObjectBrowser), IDR_OBJECTS, m_hObjectBrowserMenu, m_hObjectBrowserAccel);
643 }
644
645
646 //
647 // Event handler for client libray events
648 //
649
650 void CConsoleApp::EventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
651 {
652 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
653
654 switch(dwEvent)
655 {
656 case NXC_EVENT_NEW_ELOG_RECORD:
657 if (m_bEventBrowserActive)
658 m_pwndEventBrowser->AddEvent((NXC_EVENT *)pArg);
659 free(pArg);
660 break;
661 case NXC_EVENT_OBJECT_CHANGED:
662 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_OBJECT_CHANGE, dwCode, (LPARAM)pArg);
663 break;
664 case NXC_EVENT_USER_DB_CHANGED:
665 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_USERDB_CHANGE, dwCode, (LPARAM)pArg);
666 break;
667 case NXC_EVENT_NOTIFICATION:
668 switch(dwCode)
669 {
670 case NX_NOTIFY_SHUTDOWN:
671 m_pMainWnd->MessageBox("Server was shutdown", "Warning", MB_OK | MB_ICONSTOP);
672 PostQuitMessage(0);
673 break;
674 case NX_NOTIFY_EVENTDB_CHANGED:
675 m_pMainWnd->PostMessage(WM_COMMAND, ID_UPDATE_EVENT_LIST, 0);
676 break;
677 case NX_NOTIFY_NEW_ALARM:
678 case NX_NOTIFY_ALARM_DELETED:
679 case NX_NOTIFY_ALARM_ACKNOWLEGED:
680 m_pMainWnd->PostMessage(WM_ALARM_UPDATE, dwCode,
681 (LPARAM)nx_memdup(pArg, sizeof(NXC_ALARM)));
682 break;
683 case NX_NOTIFY_ACTION_CREATED:
684 case NX_NOTIFY_ACTION_MODIFIED:
685 case NX_NOTIFY_ACTION_DELETED:
686 UpdateActions(dwCode, (NXC_ACTION *)pArg);
687 break;
688 default:
689 break;
690 }
691 break;
692 default:
693 break;
694 }
695 }
696
697
698 //
699 // Handler for WM_COMMAND(ID_CONTROLPANEL_EVENTS) message
700 //
701
702 void CConsoleApp::OnControlpanelEvents()
703 {
704 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
705
706 // create a new MDI child window or open existing
707 if (m_bEventEditorActive)
708 m_pwndEventEditor->BringWindowToTop();
709 else
710 {
711 DWORD dwResult;
712
713 dwResult = DoRequestArg1(NXCLockEventDB, g_hSession, "Locking event configuration database...");
714 if (dwResult == RCC_SUCCESS)
715 {
716 pFrame->CreateNewChild(
717 RUNTIME_CLASS(CEventEditor), IDR_EVENT_EDITOR, m_hEventEditorMenu, m_hEventEditorAccel);
718 }
719 else
720 {
721 ErrorBox(dwResult, "Unable to open event configuration database:\n%s");
722 }
723 }
724 }
725
726
727 //
728 // Handler for WM_COMMAND::ID_CONTROLPANEL_USERS message
729 //
730
731 void CConsoleApp::OnControlpanelUsers()
732 {
733 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
734
735 // create a new MDI child window or open existing
736 if (m_bUserEditorActive)
737 m_pwndUserEditor->BringWindowToTop();
738 else
739 {
740 DWORD dwResult;
741
742 dwResult = DoRequestArg1(NXCLockUserDB, g_hSession, "Locking user database...");
743 if (dwResult == RCC_SUCCESS)
744 {
745 pFrame->CreateNewChild(
746 RUNTIME_CLASS(CUserEditor), IDR_USER_EDITOR, m_hUserEditorMenu, m_hUserEditorAccel);
747 }
748 else
749 {
750 ErrorBox(dwResult, "Unable to lock user database:\n%s");
751 }
752 }
753 }
754
755
756 //
757 // Handler for WM_COMMAND::ID_VIEW_DEBUG message
758 //
759
760 void CConsoleApp::OnViewDebug()
761 {
762 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
763
764 // create a new MDI child window or open existing
765 if (m_bDebugWindowActive)
766 m_pwndDebugWindow->BringWindowToTop();
767 else
768 pFrame->CreateNewChild(
769 RUNTIME_CLASS(CDebugFrame), IDR_DEBUG_WINDOW, m_hMDIMenu, m_hMDIAccel);
770 }
771
772
773 //
774 // Print debug information
775 //
776
777 void CConsoleApp::DebugPrintf(char *szFormat, ...)
778 {
779 if (m_bDebugWindowActive)
780 {
781 char szBuffer[1024];
782 va_list args;
783
784 va_start(args, szFormat);
785 vsprintf(szBuffer, szFormat, args);
786 va_end(args);
787
788 m_pwndDebugWindow->AddMessage(szBuffer);
789 }
790 }
791
792
793 //
794 // Edit properties of specific object
795 //
796
797 void CConsoleApp::ObjectProperties(DWORD dwObjectId)
798 {
799 CObjectPropSheet wndPropSheet("Object Properties", GetMainWnd(), 0);
800 CNodePropsGeneral wndNodeGeneral;
801 CObjectPropsGeneral wndObjectGeneral;
802 CObjectPropCaps wndObjectCaps;
803 CObjectPropsSecurity wndObjectSecurity;
804 CObjectPropsPresentation wndObjectPresentation;
805 NXC_OBJECT *pObject;
806 char szBuffer[32];
807
808 pObject = NXCFindObjectById(g_hSession, dwObjectId);
809 if (pObject != NULL)
810 {
811 // Create "General" tab
812 if (pObject->iClass == OBJECT_NODE)
813 {
814 wndNodeGeneral.m_dwObjectId = dwObjectId;
815 wndNodeGeneral.m_strName = pObject->szName;
816 wndNodeGeneral.m_strOID = pObject->node.szObjectId;
817 wndNodeGeneral.m_strPrimaryIp = IpToStr(pObject->dwIpAddr, szBuffer);
818 wndNodeGeneral.m_iAgentPort = (int)pObject->node.wAgentPort;
819 wndNodeGeneral.m_strCommunity = pObject->node.szCommunityString;
820 wndNodeGeneral.m_iAuthType = pObject->node.wAuthMethod;
821 wndNodeGeneral.m_strSecret = pObject->node.szSharedSecret;
822 wndNodeGeneral.m_iSNMPVersion = (pObject->node.wSNMPVersion == SNMP_VERSION_1) ? 0 : 1;
823 wndPropSheet.AddPage(&wndNodeGeneral);
824 }
825 else
826 {
827 wndObjectGeneral.m_dwObjectId = dwObjectId;
828 wndObjectGeneral.m_strClass = g_szObjectClass[pObject->iClass];
829 wndObjectGeneral.m_strName = pObject->szName;
830 wndPropSheet.AddPage(&wndObjectGeneral);
831 }
832
833 // Create tabs specific for node objects
834 if (pObject->iClass == OBJECT_NODE)
835 {
836 // Create "Capabilities" tab
837 wndObjectCaps.m_pObject = pObject;
838 wndPropSheet.AddPage(&wndObjectCaps);
839 }
840
841 // Create "Security" tab
842 wndObjectSecurity.m_pObject = pObject;
843 wndObjectSecurity.m_bInheritRights = pObject->bInheritRights;
844 wndPropSheet.AddPage(&wndObjectSecurity);
845
846 // Create "Presentation" tab
847 wndObjectPresentation.m_dwImageId = pObject->dwImage;
848 wndObjectPresentation.m_bUseDefaultImage = (pObject->dwImage == IMG_DEFAULT);
849 wndPropSheet.AddPage(&wndObjectPresentation);
850
851 wndPropSheet.SetObject(pObject);
852 if (wndPropSheet.DoModal() == IDOK)
853 wndPropSheet.SaveObjectChanges();
854 }
855 }
856
857
858 //
859 // Get context menu
860 //
861
862 CMenu *CConsoleApp::GetContextMenu(int iIndex)
863 {
864 return m_ctxMenu.GetSubMenu(iIndex);
865 }
866
867
868 //
869 // Start data collection editor for specific object
870 //
871
872 void CConsoleApp::StartObjectDCEditor(NXC_OBJECT *pObject)
873 {
874 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
875 NXC_DCI_LIST *pItemList;
876 DWORD dwResult;
877 CDataCollectionEditor *pWnd;
878
879 pWnd = (CDataCollectionEditor *)FindOpenDCEditor(pObject->dwId);
880 if (pWnd == NULL)
881 {
882 dwResult = DoRequestArg3(NXCOpenNodeDCIList, g_hSession, (void *)pObject->dwId,
883 &pItemList, "Loading node's data collection information...");
884 if (dwResult == RCC_SUCCESS)
885 {
886 CCreateContext context;
887
888 pWnd = new CDataCollectionEditor(pItemList);
889
890 // load the frame
891 context.m_pCurrentFrame = pFrame;
892
893 if (pWnd->LoadFrame(IDR_DC_EDITOR, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
894 {
895 CString strFullString, strTitle;
896
897 if (strFullString.LoadString(IDR_DC_EDITOR))
898 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
899
900 // add node name to title
901 strTitle += " - [";
902 strTitle += pObject->szName;
903 strTitle += "]";
904
905 // set the handles and redraw the frame and parent
906 pWnd->SetHandles(m_hDCEditorMenu, m_hDCEditorAccel);
907 pWnd->SetTitle(strTitle);
908 pWnd->InitialUpdateFrame(NULL, TRUE);
909 }
910 else
911 {
912 delete pWnd;
913 }
914 }
915 else
916 {
917 ErrorBox(dwResult, "Unable to load data collection information for node:\n%s");
918 }
919 }
920 else
921 {
922 // Data collection editor already open, activate it
923 pWnd->BringWindowToTop();
924 }
925 }
926
927
928 //
929 // Show network summary view
930 //
931
932 void CConsoleApp::OnViewNetworksummary()
933 {
934 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
935
936 // create a new MDI child window or open existing
937 if (m_bNetSummaryActive)
938 m_pwndNetSummary->BringWindowToTop();
939 else
940 pFrame->CreateNewChild(
941 RUNTIME_CLASS(CNetSummaryFrame), IDR_NETWORK_SUMMARY, m_hMDIMenu, m_hMDIAccel);
942 }
943
944
945 //
946 // Set object's management status
947 //
948
949 void CConsoleApp::SetObjectMgmtStatus(NXC_OBJECT *pObject, BOOL bIsManaged)
950 {
951 DWORD dwResult;
952
953 dwResult = DoRequestArg3(NXCSetObjectMgmtStatus, g_hSession, (void *)pObject->dwId,
954 (void *)bIsManaged, "Changing object status...");
955 if (dwResult != RCC_SUCCESS)
956 {
957 char szBuffer[256];
958
959 sprintf(szBuffer, "Unable to change management status for object %s:\n%s",
960 pObject->szName, NXCGetErrorText(dwResult));
961 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
962 }
963 }
964
965
966 //
967 // Find open data collection editor for given node, if any
968 //
969
970 CWnd *CConsoleApp::FindOpenDCEditor(DWORD dwNodeId)
971 {
972 DWORD i;
973
974 for(i = 0; i < MAX_DC_EDITORS; i++)
975 if (m_openDCEditors[i].dwNodeId == dwNodeId)
976 return m_openDCEditors[i].pWnd;
977 return NULL;
978 }
979
980
981 //
982 // Display message box with error text from client library
983 //
984
985 void CConsoleApp::ErrorBox(DWORD dwError, TCHAR *pszMessage, TCHAR *pszTitle)
986 {
987 TCHAR szBuffer[512];
988
989 _sntprintf(szBuffer, 512, (pszMessage != NULL) ? pszMessage : _T("Error: %s"),
990 NXCGetErrorText(dwError));
991 m_pMainWnd->MessageBox(szBuffer, (pszTitle != NULL) ? pszTitle : _T("Error"), MB_ICONSTOP);
992 }
993
994
995 //
996 // Show window with DCI's data
997 //
998
999 void CConsoleApp::ShowDCIData(DWORD dwNodeId, DWORD dwItemId, char *pszItemName)
1000 {
1001 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1002 CCreateContext context;
1003 CDCIDataView *pWnd;
1004
1005 pWnd = new CDCIDataView(dwNodeId, dwItemId);
1006
1007 // load the frame
1008 context.m_pCurrentFrame = pFrame;
1009
1010 if (pWnd->LoadFrame(IDR_DCI_DATA_VIEW, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
1011 {
1012 CString strFullString, strTitle;
1013
1014 if (strFullString.LoadString(IDR_DCI_DATA_VIEW))
1015 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
1016
1017 // add node name to title
1018 strTitle += " - [";
1019 strTitle += pszItemName;
1020 strTitle += "]";
1021
1022 // set the handles and redraw the frame and parent
1023 pWnd->SetHandles(m_hMDIMenu, m_hMDIAccel);
1024 pWnd->SetTitle(strTitle);
1025 pWnd->InitialUpdateFrame(NULL, TRUE);
1026 }
1027 else
1028 {
1029 delete pWnd;
1030 }
1031 }
1032
1033
1034 //
1035 // Show graph for collected data
1036 //
1037
1038 void CConsoleApp::ShowDCIGraph(DWORD dwNodeId, DWORD dwItemId, char *pszItemName)
1039 {
1040 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1041 CCreateContext context;
1042 CGraphFrame *pWnd;
1043 DWORD dwCurrTime;
1044
1045 pWnd = new CGraphFrame;
1046 pWnd->AddItem(dwNodeId, dwItemId);
1047 dwCurrTime = time(NULL);
1048 pWnd->SetTimeFrame(dwCurrTime - 3600, dwCurrTime); // Last hour
1049
1050 // load the frame
1051 context.m_pCurrentFrame = pFrame;
1052
1053 if (pWnd->LoadFrame(IDR_DCI_HISTORY_GRAPH, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
1054 {
1055 CString strFullString, strTitle;
1056
1057 if (strFullString.LoadString(IDR_DCI_HISTORY_GRAPH))
1058 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
1059
1060 // add item name to title
1061 strTitle += " - [";
1062 strTitle += pszItemName;
1063 strTitle += "]";
1064
1065 // set the handles and redraw the frame and parent
1066 pWnd->SetHandles(m_hGraphMenu, m_hGraphAccel);
1067 pWnd->SetTitle(strTitle);
1068 pWnd->InitialUpdateFrame(NULL, TRUE);
1069 }
1070 else
1071 {
1072 delete pWnd;
1073 }
1074 }
1075
1076
1077 //
1078 // WM_COMMAND::ID_TOOLS_MIBBROWSER message handler
1079 //
1080
1081 void CConsoleApp::OnToolsMibbrowser()
1082 {
1083 CMIBBrowserDlg dlg;
1084 dlg.DoModal();
1085 }
1086
1087
1088 //
1089 // WM_COMMAND::ID_CONTROLPANEL_EVENTPOLICY message handler
1090 //
1091
1092 void CConsoleApp::OnControlpanelEventpolicy()
1093 {
1094 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1095
1096 // create a new MDI child window or open existing
1097 if (m_bEventPolicyEditorActive)
1098 {
1099 m_pwndEventPolicyEditor->BringWindowToTop();
1100 }
1101 else
1102 {
1103 DWORD dwResult;
1104
1105 dwResult = DoRequestArg2(NXCOpenEventPolicy, g_hSession, &m_pEventPolicy, "Loading event processing policy...");
1106 if (dwResult == RCC_SUCCESS)
1107 {
1108 pFrame->CreateNewChild(
1109 RUNTIME_CLASS(CEventPolicyEditor), IDR_EPP_EDITOR, m_hPolicyEditorMenu, m_hPolicyEditorAccel);
1110 }
1111 else
1112 {
1113 ErrorBox(dwResult, "Unable to load event processing policy:\n%s");
1114 }
1115 }
1116 }
1117
1118
1119 //
1120 // WM_COMMAND::ID_VIEW_ALARMS message handler
1121 //
1122
1123 void CConsoleApp::OnViewAlarms()
1124 {
1125 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1126
1127 // create a new MDI child window or open existing
1128 if (m_bAlarmBrowserActive)
1129 m_pwndAlarmBrowser->BringWindowToTop();
1130 else
1131 pFrame->CreateNewChild(
1132 RUNTIME_CLASS(CAlarmBrowser), IDR_ALARMS, m_hAlarmBrowserMenu, m_hAlarmBrowserAccel);
1133 }
1134
1135
1136 //
1137 // WM_COMMAND::ID_FILE_SETTINGS message handler
1138 //
1139
1140 void CConsoleApp::OnFileSettings()
1141 {
1142 CPropertySheet wndPropSheet("Settings", GetMainWnd(), 0);
1143 CConsolePropsGeneral wndGeneral;
1144
1145 // "General" page
1146 wndGeneral.m_bExpandCtrlPanel = (g_dwOptions & UI_OPT_EXPAND_CTRLPANEL) ? TRUE : FALSE;
1147 wndGeneral.m_bShowGrid = (g_dwOptions & UI_OPT_SHOW_GRID) ? TRUE : FALSE;
1148 wndPropSheet.AddPage(&wndGeneral);
1149
1150 if (wndPropSheet.DoModal() == IDOK)
1151 {
1152 if (wndGeneral.m_bExpandCtrlPanel)
1153 g_dwOptions |= UI_OPT_EXPAND_CTRLPANEL;
1154 else
1155 g_dwOptions &= ~UI_OPT_EXPAND_CTRLPANEL;
1156
1157 if (wndGeneral.m_bShowGrid)
1158 g_dwOptions |= UI_OPT_SHOW_GRID;
1159 else
1160 g_dwOptions &= ~UI_OPT_SHOW_GRID;
1161 }
1162 }
1163
1164
1165 //
1166 // WM_COMMAND::ID_CONTROLPANEL_ACTIONS message handler
1167 //
1168
1169 void CConsoleApp::OnControlpanelActions()
1170 {
1171 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1172
1173 // create a new MDI child window or open existing
1174 if (m_bActionEditorActive)
1175 {
1176 m_pwndActionEditor->BringWindowToTop();
1177 }
1178 else
1179 {
1180 DWORD dwResult;
1181
1182 dwResult = DoRequestArg1(NXCLockActionDB, g_hSession, "Locking action configuration database...");
1183 if (dwResult == RCC_SUCCESS)
1184 {
1185 pFrame->CreateNewChild(
1186 RUNTIME_CLASS(CActionEditor), IDR_ACTION_EDITOR, m_hActionEditorMenu, m_hActionEditorAccel);
1187 }
1188 else
1189 {
1190 ErrorBox(dwResult, "Unable to lock action configuration database:\n%s");
1191 }
1192 }
1193 }
1194
1195
1196 //
1197 // WM_COMMAND::ID_CONTROLPANEL_SNMPTRAPS message handler
1198 //
1199
1200 void CConsoleApp::OnControlpanelSnmptraps()
1201 {
1202 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1203
1204 // create a new MDI child window or open existing
1205 if (m_bTrapEditorActive)
1206 {
1207 m_pwndTrapEditor->BringWindowToTop();
1208 }
1209 else
1210 {
1211 DWORD dwResult;
1212
1213 dwResult = DoRequestArg1(NXCLockTrapCfg, g_hSession, "Locking SNMP trap configuration database...");
1214 if (dwResult == RCC_SUCCESS)
1215 {
1216 pFrame->CreateNewChild(
1217 RUNTIME_CLASS(CTrapEditor), IDR_TRAP_EDITOR, m_hTrapEditorMenu, m_hTrapEditorAccel);
1218 }
1219 else
1220 {
1221 ErrorBox(dwResult, "Unable to lock SNMP trap configuration database:\n%s");
1222 }
1223 }
1224 }
1225
1226
1227 //
1228 // Load application menu from resources and modify it as needed
1229 //
1230
1231 HMENU CConsoleApp::LoadAppMenu(HMENU hViewMenu)
1232 {
1233 HMENU hMenu;
1234
1235 hMenu = ::LoadMenu(m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
1236
1237 if (g_dwOptions & UI_OPT_EXPAND_CTRLPANEL)
1238 {
1239 RemoveMenu(hMenu, ID_VIEW_CONTROLPANEL, MF_BYCOMMAND);
1240 InsertMenu(hMenu, ID_VIEW_DEBUG, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)GetSubMenu(hViewMenu, 8), "&Control panel");
1241 }
1242
1243 return hMenu;
1244 }
1245
1246
1247 //
1248 // Create new object
1249 //
1250
1251 void CConsoleApp::CreateObject(NXC_OBJECT_CREATE_INFO *pInfo)
1252 {
1253 DWORD dwResult, dwObjectId;
1254
1255 dwResult = DoRequestArg3(NXCCreateObject, g_hSession, pInfo, &dwObjectId, "Creating object...");
1256 if (dwResult != RCC_SUCCESS)
1257 {
1258 ErrorBox(dwResult, "Error creating object: %s");
1259 }
1260 }
1261
1262
1263 //
1264 // Create container object
1265 //
1266
1267 void CConsoleApp::CreateContainer(DWORD dwParent)
1268 {
1269 NXC_OBJECT_CREATE_INFO ci;
1270 CCreateContainerDlg dlg;
1271
1272 dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
1273 if (dlg.m_pParentObject != NULL)
1274 if ((dlg.m_pParentObject->iClass != OBJECT_CONTAINER) &&
1275 (dlg.m_pParentObject->iClass != OBJECT_SERVICEROOT))
1276 dlg.m_pParentObject = NULL;
1277 if (dlg.DoModal() == IDOK)
1278 {
1279 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1280 ci.iClass = OBJECT_CONTAINER;
1281 ci.pszName = (char *)((LPCTSTR)dlg.m_strObjectName);
1282 ci.cs.container.dwCategory = 1;
1283 ci.cs.container.pszDescription = (char *)((LPCTSTR)dlg.m_strDescription);
1284 CreateObject(&ci);
1285 }
1286 }
1287
1288
1289 //
1290 // Create node object
1291 //
1292
1293 void CConsoleApp::CreateNode(DWORD dwParent)
1294 {
1295 NXC_OBJECT_CREATE_INFO ci;
1296 CCreateNodeDlg dlg;
1297
1298 dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
1299 if (dlg.m_pParentObject != NULL)
1300 if ((dlg.m_pParentObject->iClass != OBJECT_CONTAINER) &&
1301 (dlg.m_pParentObject->iClass != OBJECT_SERVICEROOT))
1302 dlg.m_pParentObject = NULL;
1303 if (dlg.DoModal() == IDOK)
1304 {
1305 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1306 ci.iClass = OBJECT_NODE;
1307 ci.pszName = (char *)((LPCTSTR)dlg.m_strObjectName);
1308 ci.cs.node.dwIpAddr = dlg.m_dwIpAddr;
1309 ci.cs.node.dwNetMask = 0;
1310 CreateObject(&ci);
1311 }
1312 }
1313
1314
1315 //
1316 // Create template object
1317 //
1318
1319 void CConsoleApp::CreateTemplate(DWORD dwParent)
1320 {
1321 NXC_OBJECT_CREATE_INFO ci;
1322 CCreateTemplateDlg dlg;
1323
1324 dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
1325 if (dlg.m_pParentObject != NULL)
1326 if ((dlg.m_pParentObject->iClass != OBJECT_TEMPLATEGROUP) &&
1327 (dlg.m_pParentObject->iClass != OBJECT_TEMPLATEROOT))
1328 dlg.m_pParentObject = NULL;
1329 if (dlg.DoModal() == IDOK)
1330 {
1331 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1332 ci.iClass = OBJECT_TEMPLATE;
1333 ci.pszName = (char *)((LPCTSTR)dlg.m_strObjectName);
1334 CreateObject(&ci);
1335 }
1336 }
1337
1338
1339 //
1340 // Create template group object
1341 //
1342
1343 void CConsoleApp::CreateTemplateGroup(DWORD dwParent)
1344 {
1345 NXC_OBJECT_CREATE_INFO ci;
1346 CCreateTGDlg dlg;
1347
1348 dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
1349 if (dlg.m_pParentObject != NULL)
1350 if ((dlg.m_pParentObject->iClass != OBJECT_TEMPLATEGROUP) &&
1351 (dlg.m_pParentObject->iClass != OBJECT_TEMPLATEROOT))
1352 dlg.m_pParentObject = NULL;
1353 if (dlg.DoModal() == IDOK)
1354 {
1355 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1356 ci.iClass = OBJECT_TEMPLATEGROUP;
1357 ci.pszName = (char *)((LPCTSTR)dlg.m_strObjectName);
1358 ci.cs.templateGroup.pszDescription = (char *)((LPCTSTR)dlg.m_strDescription);
1359 CreateObject(&ci);
1360 }
1361 }
1362
1363
1364 //
1365 // Delete object on server
1366 //
1367
1368 void CConsoleApp::DeleteNetXMSObject(NXC_OBJECT *pObject)
1369 {
1370 DWORD dwResult;
1371
1372 dwResult = DoRequestArg2(NXCDeleteObject, g_hSession, (void *)pObject->dwId, "Deleting object...");
1373 if (dwResult != RCC_SUCCESS)
1374 ErrorBox(dwResult, "Unable to delete object: %s");
1375 }
1376
1377
1378 //
1379 // Perform forced poll on a node
1380 //
1381
1382 void CConsoleApp::PollNode(DWORD dwObjectId, int iPollType)
1383 {
1384 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1385 CNodePoller *pWnd;
1386
1387 pWnd = (CNodePoller *)pFrame->CreateNewChild(
1388 RUNTIME_CLASS(CNodePoller), IDR_NODE_POLLER, m_hMDIMenu, m_hMDIAccel);
1389 if (pWnd != NULL)
1390 {
1391 pWnd->m_dwObjectId = dwObjectId;
1392 pWnd->m_iPollType = iPollType;
1393 pWnd->PostMessage(WM_COMMAND, ID_POLL_RESTART, 0);
1394 }
1395 }
1396
1397
1398 //
1399 // WM_COMMAND::ID_TOOLS_ADDNODE message handler
1400 //
1401
1402 void CConsoleApp::OnToolsAddnode()
1403 {
1404 CreateNode(0);
1405 }
1406
1407
1408 //
1409 // Wake up node
1410 //
1411
1412 void CConsoleApp::WakeUpNode(DWORD dwObjectId)
1413 {
1414 DWORD dwResult;
1415
1416 dwResult = DoRequestArg2(NXCWakeUpNode, g_hSession, (void *)dwObjectId, _T("Sending Wake-On-LAN magic packet to node..."));
1417 if (dwResult != RCC_SUCCESS)
1418 ErrorBox(dwResult, _T("Unable to send WOL magic packet: %s"));
1419 else
1420 m_pMainWnd->MessageBox(_T("Wake-On-LAN magic packet was successfully sent to node"),
1421 _T("Information"), MB_ICONINFORMATION | MB_OK);
1422 }