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