Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrcfg / services_page.cpp
blob85d5672a1bb56aa3eb996b4eca12dbc497e0428b
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
11 * INCLUDES _________________________________________________________________
14 #include <winsock2.h>
15 #include <ws2tcpip.h>
17 extern "C" {
18 #include <afs/param.h>
19 #include <afs/stds.h>
22 #include "afscfg.h"
23 #include "resource.h"
24 #include <stdio.h>
25 #include "admin_info_dlg.h"
26 #include "get_cur_config.h"
30 * DEFINITIONS _________________________________________________________________
33 static HWND hDlg = 0;
34 static BOOL bSettingScMachine;
36 // These indicate if the named service is currently running, and if the user wants it on
37 // or off.
38 static BOOL bFsRunning = FALSE;
39 static BOOL bFsOn = FALSE;
41 static BOOL bDbRunning = TRUE;
42 static BOOL bDbOn = FALSE;
43 static BOOL bDbParial = FALSE;
45 static BOOL bBakRunning = FALSE;
46 static BOOL bBakOn = FALSE;
48 static BOOL bScsRunning = FALSE;
49 static BOOL bScsOn = FALSE;
51 static BOOL bSccRunning = FALSE;
52 static BOOL bSccOn = FALSE;
54 static TCHAR szScMachine[MAX_MACHINE_NAME_LEN + 1];
58 * PROTOTYPES _________________________________________________________________
61 // From config_server_page.cpp
62 BOOL Configure(HWND hParent, BOOL& bMustExit);
64 static void OnInitDialog(HWND hwndDlg);
65 static void ShowInitialConfig();
66 static void ShowServiceStates();
67 static void OnDbService();
68 static void OnBakService();
69 static void OnFsService();
70 static void OnScServer();
71 static void OnScClient();
72 static void CheckEnableSc();
73 static void EnableScMachine(BOOL bEnable = TRUE);
74 static void OnScMachineChange();
75 static void CheckEnableBak();
76 static BOOL PrepareToConfig(CONFIG_STATE& state, BOOL bRunning, BOOL bOn, UINT uiCtrlID);
77 static BOOL PrepareToConfig();
78 static void CheckEnableApply();
82 * EXPORTED FUNCTIONS _________________________________________________________________
87 * Dialog Proc _________________________________________________________________
90 BOOL CALLBACK ServicesPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
92 if (AfsAppLib_HandleHelp(IDD_SERVICES_PAGE, hwndDlg, uMsg, wParam, lParam))
93 return TRUE;
95 switch (uMsg) {
96 case WM_INITDIALOG:
97 OnInitDialog(hwndDlg);
98 break;
100 case WM_COMMAND:
101 switch (LOWORD(wParam)) {
102 case IDC_DB_SERVICE:
103 OnDbService();
104 break;
106 case IDC_BK_SERVICE:
107 OnBakService();
108 break;
110 case IDC_FS_SERVICE:
111 OnFsService();
112 break;
114 case IDC_SCC:
115 OnScClient();
116 break;
118 case IDC_SCS:
119 OnScServer();
120 break;
122 case IDC_SC_MACHINE:
123 if (HIWORD(wParam) == EN_CHANGE) {
124 OnScMachineChange();
126 break;
128 case IDAPPLY:
129 PrepareToConfig();
130 break;
132 break;
135 CheckEnableApply();
137 return FALSE;
142 * STATIC FUNCTIONS _________________________________________________________________
145 static void OnInitDialog(HWND hwndDlg)
147 hDlg = hwndDlg;
149 // Show the initial services config
150 ShowInitialConfig();
151 ShowServiceStates();
153 MakeBold(hDlg, IDC_DB_SERVICE);
154 MakeBold(hDlg, IDC_FS_SERVICE);
155 MakeBold(hDlg, IDC_BK_SERVICE);
156 MakeBold(hDlg, IDC_SCC);
157 MakeBold(hDlg, IDC_SCS);
160 static void EnableScMachine(BOOL bEnable)
162 SetEnable(hDlg, IDC_SC_MACHINE_LABEL, (ENABLE_STATE)bEnable);
163 SetEnable(hDlg, IDC_SC_MACHINE, (ENABLE_STATE)bEnable);
165 bSettingScMachine = TRUE;
166 SetWndText(hDlg, IDC_SC_MACHINE, bEnable ? szScMachine : TEXT(""));
167 bSettingScMachine = FALSE;
170 static void ShowInitialConfig()
172 // FS
173 bFsRunning = Configured(g_CfgData.configFS);
174 if (bFsRunning) {
175 SetCheck(hDlg, IDC_FS_SERVICE);
176 SetWndText(hDlg, IDC_FS_STATUS_MSG, IDS_FS_RUNNING);
177 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_HOW_TO_STOP);
178 } else {
179 SetCheck(hDlg, IDC_FS_SERVICE, FALSE);
180 SetWndText(hDlg, IDC_FS_STATUS_MSG, IDS_FS_STOPPED);
181 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_HOW_TO_RUN);
184 bFsOn = bFsRunning;
186 // DB
187 Set2State(hDlg, IDC_DB_SERVICE);
189 bDbRunning = Configured(g_CfgData.configDB);
190 if (bDbRunning) {
191 SetCheck(hDlg, IDC_DB_SERVICE);
192 SetWndText(hDlg, IDC_DB_STATUS_MSG, IDS_DB_RUNNING);
193 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_HOW_TO_STOP);
194 } else if (bDbParial) {
195 SetCheck(hDlg, IDC_DB_SERVICE, BST_INDETERMINATE);
196 SetWndText(hDlg, IDC_DB_STATUS_MSG, IDS_DB_PARTIAL_CONFIG);
197 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_DETAILS);
198 ShowWnd(hDlg, IDC_DB_DETAILS);
199 Set3State(hDlg, IDC_DB_SERVICE);
200 } else {
201 SetCheck(hDlg, IDC_DB_SERVICE, FALSE);
202 SetWndText(hDlg, IDC_DB_STATUS_MSG, IDS_DB_STOPPED);
203 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_HOW_TO_RUN);
206 bDbOn = bDbRunning;
208 // BK
209 bBakRunning = Configured(g_CfgData.configBak);
210 SetEnable(hDlg, IDC_BK_SERVICE, ES_ENABLE);
211 if (bBakRunning) {
212 SetCheck(hDlg, IDC_BK_SERVICE);
213 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_RUNNING);
214 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_HOW_TO_STOP);
215 } else {
216 SetCheck(hDlg, IDC_BK_SERVICE, FALSE);
217 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_STOPPED);
218 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_HOW_TO_RUN);
221 bBakOn = bBakRunning;
223 // SC Server
224 bScsRunning = Configured(g_CfgData.configSCS);
225 SetEnable(hDlg, IDC_SCS, ES_ENABLE);
226 if (bScsRunning) {
227 SetCheck(hDlg, IDC_SCS);
228 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_HOW_TO_STOP);
229 } else {
230 SetCheck(hDlg, IDC_SCS, FALSE);
231 SetWndText(hDlg, IDC_SCS_STATUS_MSG, IDS_SCS_STOPPED);
232 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_HOW_TO_RUN);
235 bScsOn = bScsRunning;
237 // SC Client
238 bSccRunning = Configured(g_CfgData.configSCC);
239 SetEnable(hDlg, IDC_SCC, ES_ENABLE);
240 if (bSccRunning) {
241 SetCheck(hDlg, IDC_SCC);
242 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_HOW_TO_STOP);
243 EnableScMachine();
244 lstrcpy(szScMachine, g_CfgData.szSysControlMachine);
245 } else {
246 SetCheck(hDlg, IDC_SCC, FALSE);
247 SetWndText(hDlg, IDC_SCC_STATUS_MSG, IDS_SCC_STOPPED);
248 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_HOW_TO_RUN);
249 EnableScMachine(FALSE);
252 bSccOn = bSccRunning;
255 static void ShowServiceStates()
257 // FS
258 if (bFsOn) {
259 if (bFsRunning)
260 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_HOW_TO_STOP);
261 else
262 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_WILL_RUN);
263 } else {
264 if (bFsRunning)
265 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_WILL_STOP);
266 else
267 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_HOW_TO_RUN);
270 // DB
271 switch (GetButtonState(hDlg, IDC_DB_SERVICE)) {
272 case BST_CHECKED:
273 if (bDbRunning)
274 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_HOW_TO_STOP);
275 else
276 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_WILL_RUN);
277 break;
279 case BST_UNCHECKED:
280 if (bDbRunning)
281 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_WILL_STOP);
282 else
283 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_HOW_TO_RUN);
284 break;
286 case BST_INDETERMINATE:
287 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_DETAILS);
288 break;
291 // For the ones below, in addition to setting the action message, we also
292 // set the status message. This is because the status can change to the
293 // disabled state depending on how other servers are configured. The
294 // servers before this cannot have their status change except by re-
295 // configuring them.
297 // BK
298 if (bDbOn) {
299 if (IsButtonChecked(hDlg, IDC_BK_SERVICE)) {
300 if (bBakRunning) {
301 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_RUNNING);
302 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_HOW_TO_STOP);
303 } else {
304 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_STOPPED);
305 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_WILL_RUN);
307 } else {
308 if (bBakRunning) {
309 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_RUNNING);
310 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_WILL_STOP);
311 } else {
312 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_STOPPED);
313 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_HOW_TO_RUN);
318 CheckEnableBak();
320 // SC Server
321 if (bFsOn || bDbOn && !bSccOn) {
322 if (bScsOn) {
323 if (bScsRunning) {
324 SetWndText(hDlg, IDC_SCS_STATUS_MSG, IDS_SCS_RUNNING);
325 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_HOW_TO_STOP);
326 } else {
327 SetWndText(hDlg, IDC_SCS_STATUS_MSG, IDS_SCS_STOPPED);
328 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_WILL_RUN);
330 } else {
331 if (bScsRunning) {
332 SetWndText(hDlg, IDC_SCS_STATUS_MSG, IDS_SCS_RUNNING);
333 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_WILL_STOP);
334 } else {
335 SetWndText(hDlg, IDC_SCS_STATUS_MSG, IDS_SCS_STOPPED);
336 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_HOW_TO_RUN);
341 // SC Client
342 if (bFsOn || bDbOn && !bScsOn) {
343 if (bSccOn) {
344 if (bSccRunning) {
345 SetWndText(hDlg, IDC_SCC_STATUS_MSG, IDS_SCC_RUNNING);
346 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_HOW_TO_STOP);
347 } else {
348 SetWndText(hDlg, IDC_SCC_STATUS_MSG, IDS_SCC_STOPPED);
349 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_WILL_RUN);
351 } else {
352 if (bSccRunning) {
353 SetWndText(hDlg, IDC_SCC_STATUS_MSG, IDS_SCC_RUNNING);
354 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_WILL_STOP);
355 } else {
356 SetWndText(hDlg, IDC_SCC_STATUS_MSG, IDS_SCC_STOPPED);
357 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_HOW_TO_RUN);
362 CheckEnableSc();
365 static void OnDbService()
367 bDbOn = GetButtonState(hDlg, IDC_DB_SERVICE) == BST_CHECKED;
369 CheckEnableBak();
370 CheckEnableSc();
372 ShowServiceStates();
375 static void OnBakService()
377 bBakOn = !bBakOn;
379 ShowServiceStates();
382 static void OnFsService()
384 bFsOn = !bFsOn;
386 CheckEnableSc();
388 ShowServiceStates();
391 static void CheckEnableBak()
393 // Enable/disable bk service based on db service.
394 if (!bDbOn) {
395 SetCheck(hDlg, IDC_BK_SERVICE, FALSE);
396 SetEnable(hDlg, IDC_BK_SERVICE, ES_DISABLE);
397 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_DISABLED);
398 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_ENABLE);
399 } else {
400 SetCheck(hDlg, IDC_BK_SERVICE, bBakOn);
401 SetEnable(hDlg, IDC_BK_SERVICE, ES_ENABLE);
405 static void CheckEnableSc()
407 BOOL bSccEnable = TRUE;
408 UINT uiSccStatusMsg;
409 UINT uiSccActionMsg;
410 BOOL bScsEnable = TRUE;
411 UINT uiScsStatusMsg;
412 UINT uiScsActionMsg;
414 // Disable SCS and SCC?
415 if (!bFsOn && !bDbOn) {
416 bScsEnable = FALSE;
417 uiScsStatusMsg = IDS_SC_DISABLED;
418 uiScsActionMsg = IDS_SC_ENABLE;
420 bSccEnable = FALSE;
421 uiSccStatusMsg = IDS_SC_DISABLED;
422 uiSccActionMsg = IDS_SC_ENABLE;
423 // Disable SCS?
424 } else if (bSccOn) {
425 bScsEnable = FALSE;
426 uiScsStatusMsg = IDS_SC_DISABLED;
427 uiScsActionMsg = IDS_SCS_ENABLE;
428 // Disable SCC
429 } else if (bScsOn) {
430 bSccEnable = FALSE;
431 uiSccStatusMsg = IDS_SC_DISABLED;
432 uiSccActionMsg = IDS_SCC_ENABLE;
435 // Enable the sc server GUI
436 if (bScsEnable) {
437 SetEnable(hDlg, IDC_SCS, ES_ENABLE);
438 SetCheck(hDlg, IDC_SCS, bScsOn);
439 } else { // Disable the sc server gui
440 SetEnable(hDlg, IDC_SCS, ES_DISABLE);
441 SetCheck(hDlg, IDC_SCS, FALSE);
442 SetWndText(hDlg, IDC_SCS_STATUS_MSG, uiScsStatusMsg);
443 SetWndText(hDlg, IDC_SCS_ACTION_MSG, uiScsActionMsg);
446 // Enable the sc client GUI
447 if (bSccEnable) {
448 SetEnable(hDlg, IDC_SCC, ES_ENABLE);
449 SetCheck(hDlg, IDC_SCC, bSccOn);
450 EnableScMachine(bSccOn);
451 } else { // Disable the sc client gui
452 SetEnable(hDlg, IDC_SCC, ES_DISABLE);
453 SetCheck(hDlg, IDC_SCC, FALSE);
454 SetWndText(hDlg, IDC_SCC_STATUS_MSG, uiSccStatusMsg);
455 SetWndText(hDlg, IDC_SCC_ACTION_MSG, uiSccActionMsg);
456 EnableScMachine(FALSE);
460 static void OnScServer()
462 bScsOn = !bScsOn;
464 ShowServiceStates();
467 static void OnScClient()
469 bSccOn = !bSccOn;
471 ShowServiceStates();
474 static void OnScMachineChange()
476 if (!bSettingScMachine && IsButtonChecked(hDlg, IDC_SCC))
477 GetWndText(hDlg, IDC_SC_MACHINE, szScMachine, sizeof(szScMachine) / sizeof(szScMachine[0]));
480 static BOOL PrepareToConfig(CONFIG_STATE& state, BOOL bRunning, BOOL bOn, UINT uiCtrlID)
482 BOOL bEnabled = IsWindowEnabled(GetDlgItem(hDlg, uiCtrlID));
484 if (bRunning && (!bOn || !bEnabled))
485 state = CS_UNCONFIGURE;
486 else if (!bRunning && (bOn && bEnabled))
487 state = CS_CONFIGURE;
489 return (state == CS_UNCONFIGURE) || (state == CS_CONFIGURE);
492 static BOOL PrepareToConfig()
494 BOOL bMustExit = FALSE;
496 // Use a local copy of the config info to decide what should be configured
497 // or unconfigured. We do this so that if the user cancels for some reason,
498 // the real config state will still be what the user expects (what was
499 // previously read from the system plus the user's changes).
500 CONFIG_STATE configFS = g_CfgData.configFS; // File server
501 CONFIG_STATE configDB = g_CfgData.configDB; // Database server
502 CONFIG_STATE configBak = g_CfgData.configBak; // Backup server
503 CONFIG_STATE configSCS = g_CfgData.configSCS; // System Control server
504 CONFIG_STATE configSCC = g_CfgData.configSCC; // System Control client
506 BOOL bWorkToDo = FALSE;
508 bWorkToDo |= PrepareToConfig(configFS, bFsRunning, bFsOn, IDC_FS_SERVICE);
509 bWorkToDo |= PrepareToConfig(configDB, bDbRunning, bDbOn, IDC_DB_SERVICE);
510 bWorkToDo |= PrepareToConfig(configBak, bBakRunning, bBakOn, IDC_BK_SERVICE);
511 bWorkToDo |= PrepareToConfig(configSCS, bScsRunning, bScsOn, IDC_SCS);
512 bWorkToDo |= PrepareToConfig(configSCC, bSccRunning, bSccOn, IDC_SCC);
514 // If there is nothing to do, then just return TRUE.
515 if (!bWorkToDo)
516 return TRUE;
518 // If we are unconfiguring the last DB server:
519 // 1) Warn user and ask for confirmation
520 // 2) Unconfigure all other servers that are running on this machine
521 // 3) Tell them (after unconfiguring) that they must run the Wizard if they
522 // wish to reconfigure the machine, then exit the program.
523 if (configDB == CS_UNCONFIGURE) {
524 if (g_CfgData.bLastDBServer) {
525 int nChoice = MsgBox(hDlg, IDS_LAST_DB_SERVER, GetAppTitleID(), MB_YESNO | MB_ICONEXCLAMATION);
526 if (nChoice == IDNO)
527 return FALSE;
529 // Make sure these all get unconfigured as well. If they are not configured, then
530 // nothing bad will happen because the config calls are idempotent.
531 configFS = CS_UNCONFIGURE;
532 configBak = CS_UNCONFIGURE;
533 configSCS = CS_UNCONFIGURE;
534 configSCC = CS_UNCONFIGURE;
538 // Get additional needed information from the user
539 GET_ADMIN_INFO_OPTIONS eOptions;
540 BOOL bDB = (ShouldConfig(configDB) || ShouldUnconfig(configDB));
542 // Use this as our default
543 eOptions = GAIO_LOGIN_ONLY;
545 // If we already have a sys control machine, then we don't need to ask for it
546 if (ShouldConfig(configSCC)) {
547 if (szScMachine[0] == 0) {
548 ShowWarning(hDlg, IDS_MUST_ENTER_SCS_NAME);
549 return FALSE;
551 lstrcpy(g_CfgData.szSysControlMachine, szScMachine);
552 } else if (bDB && !g_CfgData.bLastDBServer) {
553 // We need to know the name of the SCM machine. Are we the SCM machine?
554 if (bScsRunning)
555 lstrcpy(g_CfgData.szSysControlMachine, g_CfgData.szHostname);
556 else
557 eOptions = GAIO_GET_SCS;
560 // If doing a login only and the admin info is reusable
561 if ((eOptions != GAIO_LOGIN_ONLY) || !g_CfgData.bReuseAdminInfo) {
562 if (!GetAdminInfo(hDlg, eOptions))
563 return FALSE;
565 // Use the admin info to get new handles
566 if (!GetHandles(hDlg))
567 return FALSE;
570 // Now that we are ready to configure, copy our local config info
571 // into the structure that the config engine uses.
572 g_CfgData.configFS = configFS;
573 g_CfgData.configDB = configDB;
574 g_CfgData.configBak = configBak;
575 g_CfgData.configSCS = configSCS;
576 g_CfgData.configSCC = configSCC;
578 // Configure the server
579 BOOL bConfigSucceeded = Configure(hDlg, bMustExit);
580 if (bConfigSucceeded) {
581 if (bMustExit) {
582 PostQuitMessage(0);
583 return TRUE;
585 g_CfgData.bReuseAdminInfo = TRUE;
586 } else
587 g_CfgData.szAdminPW[0] = 0;
589 // Get current config status
590 BOOL bCanceled = FALSE;
591 DWORD dwStatus = GetCurrentConfig(hDlg, bCanceled);
592 if (dwStatus || bCanceled) {
593 if (!bCanceled)
594 ErrorDialog(dwStatus, IDS_CONFIG_CHECK_FAILED);
597 // Show the initial services config
598 ShowInitialConfig();
599 ShowServiceStates();
601 return TRUE;
604 static void CheckEnableApply()
606 BOOL bEnable = FALSE;
608 bEnable = (bFsRunning != bFsOn) || (bDbRunning != bDbOn) || (bBakRunning != bBakOn) ||
609 (bScsRunning != bScsOn) || (bSccRunning != bSccOn);
611 if (bEnable)
612 PropSheet_Changed(GetParent(hDlg), hDlg);
613 else
614 PropSheet_UnChanged(GetParent(hDlg), hDlg);