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