1 // nxconfig.cpp : Defines the class behaviors for the application.
8 #include "ConfigWizard.h"
10 #include "DBSelectPage.h"
12 #include "PollCfgPage.h"
14 #include "SummaryPage.h"
15 #include "ProcessingPage.h"
16 #include "ConfigFilePage.h"
17 #include "LoggingPage.h"
18 #include "FinishPage.h"
27 static char THIS_FILE
[] = __FILE__
;
30 /////////////////////////////////////////////////////////////////////////////
33 BEGIN_MESSAGE_MAP(CNxconfigApp
, CWinApp
)
34 //{{AFX_MSG_MAP(CNxconfigApp)
35 ON_COMMAND(ID_FILE_CFG_WIZARD
, OnFileCfgWizard
)
39 /////////////////////////////////////////////////////////////////////////////
40 // CNxconfigApp construction
42 CNxconfigApp::CNxconfigApp()
44 // TODO: add construction code here,
45 // Place all significant initialization in InitInstance
48 /////////////////////////////////////////////////////////////////////////////
49 // The one and only CNxconfigApp object
53 /////////////////////////////////////////////////////////////////////////////
54 // CNxconfigApp initialization
56 BOOL
CNxconfigApp::InitInstance()
59 DWORD dwSize
, dwData
= 0;
63 AfxMessageBox(IDP_SOCKETS_INIT_FAILED
);
67 // Read installation data from registry
68 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
, _T("Software\\NetXMS\\Server"), 0,
69 KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
71 dwSize
= sizeof(DWORD
);
72 RegQueryValueEx(hKey
, _T("ServerIsConfigured"), NULL
, NULL
, (BYTE
*)&dwData
, &dwSize
);
74 dwSize
= (MAX_PATH
- 16) * sizeof(TCHAR
);
75 if (RegQueryValueEx(hKey
, _T("InstallPath"), NULL
, NULL
,
76 (BYTE
*)m_szInstallDir
, &dwSize
) != ERROR_SUCCESS
)
78 AfxMessageBox(_T("Unable to determine NetXMS installation directory"));
79 m_szInstallDir
[0] = 0;
86 if (!_tcsicmp(m_lpCmdLine
, _T("--create-agent-config")))
92 // Check if server is already configured or we cannot determine
93 // installation directory
94 if ((dwData
!= 0) || (m_szInstallDir
[0] == 0))
97 AfxMessageBox(_T("Server already configured"));
101 AfxEnableControlContainer();
103 // Standard initialization
104 // If you are not using these features and wish to reduce the size
105 // of your final executable, you should remove from the following
106 // the specific initialization routines you do not need.
109 Enable3dControls(); // Call this when using MFC in a shared DLL
111 Enable3dControlsStatic(); // Call this when linking to MFC statically
114 // Change the registry key under which our settings are stored.
115 // TODO: You should modify this string to be something appropriate
116 // such as the name of your company or organization.
117 SetRegistryKey(_T("Local AppWizard-Generated Applications"));
120 // To create the main window, this code creates a new frame window
121 // object and then sets it as the application's main window object.
123 CMainFrame
* pFrame
= new CMainFrame
;
126 // create and load the frame with its resources
128 pFrame
->LoadFrame(IDR_MAINFRAME
,
129 WS_OVERLAPPEDWINDOW
| FWS_ADDTOTITLE
, NULL
,
135 // The one and only window has been initialized, so show and update it.
136 //pFrame->ShowWindow(SW_SHOW);
137 //pFrame->UpdateWindow();
139 pFrame
->PostMessage(WM_COMMAND
, ID_FILE_CFG_WIZARD
);
144 /////////////////////////////////////////////////////////////////////////////
145 // CNxconfigApp message handlers
147 void CNxconfigApp::OnFileCfgWizard()
149 CConfigWizard
dlg(_T("Configure NetXMS Server"), m_pMainWnd
, 0);
151 CConfigFilePage pgConfigFile
;
152 CDBSelectPage pgSelectDB
;
153 CODBCPage pgCheckODBC
;
154 CPollCfgPage pgPollConfig
;
156 CLoggingPage pgLogging
;
157 CSummaryPage pgSummary
;
158 CProcessingPage pgProcessing
;
159 CFinishPage pgFinish
;
161 dlg
.m_psh
.dwFlags
|= PSH_WIZARD
;
162 dlg
.AddPage(&pgIntro
);
163 dlg
.AddPage(&pgConfigFile
);
164 dlg
.AddPage(&pgSelectDB
);
165 dlg
.AddPage(&pgCheckODBC
);
166 dlg
.AddPage(&pgPollConfig
);
167 dlg
.AddPage(&pgSMTP
);
168 dlg
.AddPage(&pgLogging
);
169 dlg
.AddPage(&pgSummary
);
170 dlg
.AddPage(&pgProcessing
);
171 dlg
.AddPage(&pgFinish
);
173 if (dlg
.DoModal() == ID_WIZFINISH
)
178 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
, _T("Software\\NetXMS\\Server"), 0,
179 KEY_ALL_ACCESS
, &hKey
) == ERROR_SUCCESS
)
181 RegSetValueEx(hKey
, _T("ServerIsConfigured"), 0, REG_DWORD
, (BYTE
*)&dwData
, sizeof(DWORD
));
186 m_pMainWnd
->PostMessage(WM_COMMAND
, ID_APP_EXIT
);
191 // Create configuration file for local agent
194 void CNxconfigApp::CreateAgentConfig()
199 IP_ADAPTER_INFO
*pBuffer
, *pInfo
;
200 IP_ADDR_STRING
*pAddr
;
201 TCHAR szAddrList
[4096], szFile
[MAX_PATH
];
203 if (_taccess(_T("nxagentd.conf"), 0) == 0)
204 return; // File already exist, we shouldn't overwrite it
206 // Get local interface list
208 if (GetAdaptersInfo(NULL
, &dwSize
) == ERROR_BUFFER_OVERFLOW
)
210 pBuffer
= (IP_ADAPTER_INFO
*)malloc(dwSize
);
211 if (GetAdaptersInfo(pBuffer
, &dwSize
) == ERROR_SUCCESS
)
213 for(pInfo
= pBuffer
; pInfo
!= NULL
; pInfo
= pInfo
->Next
)
215 // Read all IP addresses for adapter
216 for(pAddr
= &pInfo
->IpAddressList
; pAddr
!= NULL
; pAddr
= pAddr
->Next
)
218 if (_tcscmp(pAddr
->IpAddress
.String
, _T("0.0.0.0")))
220 if (szAddrList
[0] != 0)
221 _tcscat(szAddrList
, _T(", "));
222 _tcscat(szAddrList
, pAddr
->IpAddress
.String
);
230 _sntprintf(szFile
, MAX_PATH
, _T("%s\\etc\\nxagentd.conf"), m_szInstallDir
);
231 fp
= _tfopen(szFile
, _T("w"));
234 currTime
= time(NULL
);
235 _ftprintf(fp
, _T("#\n# NetXMS agent configuration file\n# Created by server installer at %s#\n\n"),
237 _ftprintf(fp
, _T("LogFile = {syslog}\nServers = 127.0.0.1\n"));
238 if (szAddrList
[0] != 0)
239 _ftprintf(fp
, _T("InstallationServers = %s\n"), szAddrList
);
240 _ftprintf(fp
, _T("FileStore = %s\\var\n"), m_szInstallDir
);
241 _ftprintf(fp
, _T("RequireAuthentication = no\n"));
242 _ftprintf(fp
, _T("SubAgent = winperf.nsm\nSubAgent = portcheck.nsm\n"));