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 "WinSrvPage.h"
18 #include "LoggingPage.h"
19 #include "FinishPage.h"
28 static char THIS_FILE
[] = __FILE__
;
31 /////////////////////////////////////////////////////////////////////////////
34 BEGIN_MESSAGE_MAP(CNxconfigApp
, CWinApp
)
35 //{{AFX_MSG_MAP(CNxconfigApp)
36 ON_COMMAND(ID_FILE_CFG_WIZARD
, OnFileCfgWizard
)
40 /////////////////////////////////////////////////////////////////////////////
41 // CNxconfigApp construction
43 CNxconfigApp::CNxconfigApp()
45 // TODO: add construction code here,
46 // Place all significant initialization in InitInstance
49 /////////////////////////////////////////////////////////////////////////////
50 // The one and only CNxconfigApp object
54 /////////////////////////////////////////////////////////////////////////////
55 // CNxconfigApp initialization
57 BOOL
CNxconfigApp::InitInstance()
60 DWORD dwSize
, dwData
= 0;
64 AfxMessageBox(IDP_SOCKETS_INIT_FAILED
);
68 // Read installation data from registry
69 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
, _T("Software\\NetXMS\\Server"), 0,
70 KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
72 dwSize
= sizeof(DWORD
);
73 RegQueryValueEx(hKey
, _T("ServerIsConfigured"), NULL
, NULL
, (BYTE
*)&dwData
, &dwSize
);
75 dwSize
= (MAX_PATH
- 16) * sizeof(TCHAR
);
76 if (RegQueryValueEx(hKey
, _T("InstallPath"), NULL
, NULL
,
77 (BYTE
*)m_szInstallDir
, &dwSize
) != ERROR_SUCCESS
)
79 AfxMessageBox(_T("Unable to determine NetXMS installation directory"));
80 m_szInstallDir
[0] = 0;
87 if (!_tcsicmp(m_lpCmdLine
, _T("--create-agent-config")))
93 // Check if server is already configured or we cannot determine
94 // installation directory
95 if ((dwData
!= 0) || (m_szInstallDir
[0] == 0))
98 AfxMessageBox(_T("Server already configured"));
102 AfxEnableControlContainer();
104 // Standard initialization
105 // If you are not using these features and wish to reduce the size
106 // of your final executable, you should remove from the following
107 // the specific initialization routines you do not need.
110 Enable3dControls(); // Call this when using MFC in a shared DLL
112 Enable3dControlsStatic(); // Call this when linking to MFC statically
115 // Change the registry key under which our settings are stored.
116 // TODO: You should modify this string to be something appropriate
117 // such as the name of your company or organization.
118 SetRegistryKey(_T("Local AppWizard-Generated Applications"));
121 // To create the main window, this code creates a new frame window
122 // object and then sets it as the application's main window object.
124 CMainFrame
* pFrame
= new CMainFrame
;
127 // create and load the frame with its resources
129 pFrame
->LoadFrame(IDR_MAINFRAME
,
130 WS_OVERLAPPEDWINDOW
| FWS_ADDTOTITLE
, NULL
,
136 // The one and only window has been initialized, so show and update it.
137 //pFrame->ShowWindow(SW_SHOW);
138 //pFrame->UpdateWindow();
140 pFrame
->PostMessage(WM_COMMAND
, ID_FILE_CFG_WIZARD
);
145 /////////////////////////////////////////////////////////////////////////////
146 // CNxconfigApp message handlers
148 void CNxconfigApp::OnFileCfgWizard()
150 CConfigWizard
dlg(_T("Configure NetXMS Server"), m_pMainWnd
, 0);
152 CConfigFilePage pgConfigFile
;
153 CDBSelectPage pgSelectDB
;
154 CODBCPage pgCheckODBC
;
155 CPollCfgPage pgPollConfig
;
157 CLoggingPage pgLogging
;
158 CWinSrvPage pgWinSrv
;
159 CSummaryPage pgSummary
;
160 CProcessingPage pgProcessing
;
161 CFinishPage pgFinish
;
163 dlg
.m_psh
.dwFlags
|= PSH_WIZARD
;
164 dlg
.AddPage(&pgIntro
);
165 dlg
.AddPage(&pgConfigFile
);
166 dlg
.AddPage(&pgSelectDB
);
167 dlg
.AddPage(&pgCheckODBC
);
168 dlg
.AddPage(&pgPollConfig
);
169 dlg
.AddPage(&pgSMTP
);
170 dlg
.AddPage(&pgLogging
);
171 dlg
.AddPage(&pgWinSrv
);
172 dlg
.AddPage(&pgSummary
);
173 dlg
.AddPage(&pgProcessing
);
174 dlg
.AddPage(&pgFinish
);
176 if (dlg
.DoModal() == ID_WIZFINISH
)
181 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
, _T("Software\\NetXMS\\Server"), 0,
182 KEY_ALL_ACCESS
, &hKey
) == ERROR_SUCCESS
)
184 RegSetValueEx(hKey
, _T("ServerIsConfigured"), 0, REG_DWORD
, (BYTE
*)&dwData
, sizeof(DWORD
));
189 m_pMainWnd
->PostMessage(WM_COMMAND
, ID_APP_EXIT
);
194 // Create configuration file for local agent
197 void CNxconfigApp::CreateAgentConfig()
202 IP_ADAPTER_INFO
*pBuffer
, *pInfo
;
203 IP_ADDR_STRING
*pAddr
;
204 TCHAR szAddrList
[4096], szFile
[MAX_PATH
];
206 if (_taccess(_T("nxagentd.conf"), 0) == 0)
207 return; // File already exist, we shouldn't overwrite it
209 // Get local interface list
211 if (GetAdaptersInfo(NULL
, &dwSize
) == ERROR_BUFFER_OVERFLOW
)
213 pBuffer
= (IP_ADAPTER_INFO
*)malloc(dwSize
);
214 if (GetAdaptersInfo(pBuffer
, &dwSize
) == ERROR_SUCCESS
)
216 for(pInfo
= pBuffer
; pInfo
!= NULL
; pInfo
= pInfo
->Next
)
218 // Read all IP addresses for adapter
219 for(pAddr
= &pInfo
->IpAddressList
; pAddr
!= NULL
; pAddr
= pAddr
->Next
)
221 if (_tcscmp(pAddr
->IpAddress
.String
, _T("0.0.0.0")))
223 if (szAddrList
[0] != 0)
224 _tcscat(szAddrList
, _T(", "));
225 _tcscat(szAddrList
, pAddr
->IpAddress
.String
);
233 _sntprintf(szFile
, MAX_PATH
, _T("%s\\etc\\nxagentd.conf"), m_szInstallDir
);
234 fp
= _tfopen(szFile
, _T("w"));
237 currTime
= time(NULL
);
238 _ftprintf(fp
, _T("#\n# NetXMS agent configuration file\n# Created by server installer at %s#\n\n"),
240 _ftprintf(fp
, _T("LogFile = {syslog}\nServers = 127.0.0.1\n"));
241 if (szAddrList
[0] != 0)
242 _ftprintf(fp
, _T("InstallationServers = %s\n"), szAddrList
);
243 _ftprintf(fp
, _T("FileStore = %s\\var\n"), m_szInstallDir
);
244 _ftprintf(fp
, _T("RequireAuthentication = no\n"));
245 _ftprintf(fp
, _T("SubAgent = winperf.nsm\nSubAgent = portcheck.nsm\n"));