2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * INCLUDES _________________________________________________________________
15 #include <afs/param.h>
22 #include "admin_info_dlg.h"
23 #include "get_cur_config.h"
27 * DEFINITIONS _________________________________________________________________
31 static BOOL bSettingScMachine;
33 // These indicate if the named service is currently running, and if the user wants it on
35 static BOOL bFsRunning = FALSE;
36 static BOOL bFsOn = FALSE;
38 static BOOL bDbRunning = TRUE;
39 static BOOL bDbOn = FALSE;
40 static BOOL bDbParial = FALSE;
42 static BOOL bBakRunning = FALSE;
43 static BOOL bBakOn = FALSE;
45 static BOOL bScsRunning = FALSE;
46 static BOOL bScsOn = FALSE;
48 static BOOL bSccRunning = FALSE;
49 static BOOL bSccOn = FALSE;
51 static TCHAR szScMachine[MAX_MACHINE_NAME_LEN + 1];
55 * PROTOTYPES _________________________________________________________________
58 // From config_server_page.cpp
59 BOOL Configure(HWND hParent, BOOL& bMustExit);
61 static void OnInitDialog(HWND hwndDlg);
62 static void ShowInitialConfig();
63 static void ShowServiceStates();
64 static void OnDbService();
65 static void OnBakService();
66 static void OnFsService();
67 static void OnScServer();
68 static void OnScClient();
69 static void CheckEnableSc();
70 static void EnableScMachine(BOOL bEnable = TRUE);
71 static void OnScMachineChange();
72 static void CheckEnableBak();
73 static void PrepareToConfig(CONFIG_STATE& state, BOOL bRunning, BOOL bOn);
74 static BOOL PrepareToConfig();
75 static void CheckEnableApply();
79 * EXPORTED FUNCTIONS _________________________________________________________________
84 * Dialog Proc _________________________________________________________________
87 BOOL CALLBACK ServicesPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
89 if (AfsAppLib_HandleHelp(IDD_SERVICES_PAGE, hwndDlg, uMsg, wParam, lParam))
93 case WM_INITDIALOG: OnInitDialog(hwndDlg);
96 case WM_COMMAND: switch (LOWORD(wParam)) {
97 case IDC_DB_SERVICE: OnDbService();
100 case IDC_BK_SERVICE: OnBakService();
103 case IDC_FS_SERVICE: OnFsService();
106 case IDC_SCC: OnScClient();
109 case IDC_SCS: OnScServer();
112 case IDC_SC_MACHINE: if (HIWORD(wParam) == EN_CHANGE) {
117 case IDAPPLY: PrepareToConfig();
130 * STATIC FUNCTIONS _________________________________________________________________
133 static void OnInitDialog(HWND hwndDlg)
137 // Show the initial services config
141 MakeBold(hDlg, IDC_DB_SERVICE);
142 MakeBold(hDlg, IDC_FS_SERVICE);
143 MakeBold(hDlg, IDC_BK_SERVICE);
144 MakeBold(hDlg, IDC_SCC);
145 MakeBold(hDlg, IDC_SCS);
148 static void EnableScMachine(BOOL bEnable)
150 SetEnable(hDlg, IDC_SC_MACHINE_LABEL, (ENABLE_STATE)bEnable);
151 SetEnable(hDlg, IDC_SC_MACHINE, (ENABLE_STATE)bEnable);
153 bSettingScMachine = TRUE;
154 SetWndText(hDlg, IDC_SC_MACHINE, bEnable ? szScMachine : TEXT(""));
155 bSettingScMachine = FALSE;
158 static void ShowInitialConfig()
161 bFsRunning = Configured(g_CfgData.configFS);
163 SetCheck(hDlg, IDC_FS_SERVICE);
164 SetWndText(hDlg, IDC_FS_STATUS_MSG, IDS_FS_RUNNING);
165 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_HOW_TO_STOP);
167 SetCheck(hDlg, IDC_FS_SERVICE, FALSE);
168 SetWndText(hDlg, IDC_FS_STATUS_MSG, IDS_FS_STOPPED);
169 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_HOW_TO_RUN);
175 Set2State(hDlg, IDC_DB_SERVICE);
177 bDbRunning = Configured(g_CfgData.configDB);
179 SetCheck(hDlg, IDC_DB_SERVICE);
180 SetWndText(hDlg, IDC_DB_STATUS_MSG, IDS_DB_RUNNING);
181 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_HOW_TO_STOP);
182 } else if (bDbParial) {
183 SetCheck(hDlg, IDC_DB_SERVICE, BST_INDETERMINATE);
184 SetWndText(hDlg, IDC_DB_STATUS_MSG, IDS_DB_PARTIAL_CONFIG);
185 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_DETAILS);
186 ShowWnd(hDlg, IDC_DB_DETAILS);
187 Set3State(hDlg, IDC_DB_SERVICE);
189 SetCheck(hDlg, IDC_DB_SERVICE, FALSE);
190 SetWndText(hDlg, IDC_DB_STATUS_MSG, IDS_DB_STOPPED);
191 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_HOW_TO_RUN);
197 bBakRunning = Configured(g_CfgData.configBak);
198 SetEnable(hDlg, IDC_BK_SERVICE, ES_ENABLE);
200 SetCheck(hDlg, IDC_BK_SERVICE);
201 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_RUNNING);
202 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_HOW_TO_STOP);
204 SetCheck(hDlg, IDC_BK_SERVICE, FALSE);
205 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_STOPPED);
206 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_HOW_TO_RUN);
209 bBakOn = bBakRunning;
212 bScsRunning = Configured(g_CfgData.configSCS);
213 SetEnable(hDlg, IDC_SCS, ES_ENABLE);
215 SetCheck(hDlg, IDC_SCS);
216 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_HOW_TO_STOP);
218 SetCheck(hDlg, IDC_SCS, FALSE);
219 SetWndText(hDlg, IDC_SCS_STATUS_MSG, IDS_SCS_STOPPED);
220 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_HOW_TO_RUN);
223 bScsOn = bScsRunning;
226 bSccRunning = Configured(g_CfgData.configSCC);
227 SetEnable(hDlg, IDC_SCC, ES_ENABLE);
229 SetCheck(hDlg, IDC_SCC);
230 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_HOW_TO_STOP);
232 lstrcpy(szScMachine, g_CfgData.szSysControlMachine);
234 SetCheck(hDlg, IDC_SCC, FALSE);
235 SetWndText(hDlg, IDC_SCC_STATUS_MSG, IDS_SCC_STOPPED);
236 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_HOW_TO_RUN);
237 EnableScMachine(FALSE);
240 bSccOn = bSccRunning;
243 static void ShowServiceStates()
248 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_HOW_TO_STOP);
250 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_WILL_RUN);
253 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_WILL_STOP);
255 SetWndText(hDlg, IDC_FS_ACTION_MSG, IDS_FS_HOW_TO_RUN);
259 switch (GetButtonState(hDlg, IDC_DB_SERVICE)) {
262 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_HOW_TO_STOP);
264 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_WILL_RUN);
269 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_WILL_STOP);
271 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_HOW_TO_RUN);
274 case BST_INDETERMINATE:
275 SetWndText(hDlg, IDC_DB_ACTION_MSG, IDS_DB_DETAILS);
279 // For the ones below, in addition to setting the action message, we also
280 // set the status message. This is because the status can change to the
281 // disabled state depending on how other servers are configured. The
282 // servers before this cannot have their status change except by re-
287 if (IsButtonChecked(hDlg, IDC_BK_SERVICE)) {
289 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_RUNNING);
290 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_HOW_TO_STOP);
292 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_STOPPED);
293 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_WILL_RUN);
297 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_RUNNING);
298 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_WILL_STOP);
300 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_STOPPED);
301 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_HOW_TO_RUN);
309 if (bFsOn || bDbOn && !bSccOn) {
312 SetWndText(hDlg, IDC_SCS_STATUS_MSG, IDS_SCS_RUNNING);
313 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_HOW_TO_STOP);
315 SetWndText(hDlg, IDC_SCS_STATUS_MSG, IDS_SCS_STOPPED);
316 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_WILL_RUN);
320 SetWndText(hDlg, IDC_SCS_STATUS_MSG, IDS_SCS_RUNNING);
321 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_WILL_STOP);
323 SetWndText(hDlg, IDC_SCS_STATUS_MSG, IDS_SCS_STOPPED);
324 SetWndText(hDlg, IDC_SCS_ACTION_MSG, IDS_SCS_HOW_TO_RUN);
330 if (bFsOn || bDbOn && !bScsOn) {
333 SetWndText(hDlg, IDC_SCC_STATUS_MSG, IDS_SCC_RUNNING);
334 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_HOW_TO_STOP);
336 SetWndText(hDlg, IDC_SCC_STATUS_MSG, IDS_SCC_STOPPED);
337 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_WILL_RUN);
341 SetWndText(hDlg, IDC_SCC_STATUS_MSG, IDS_SCC_RUNNING);
342 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_WILL_STOP);
344 SetWndText(hDlg, IDC_SCC_STATUS_MSG, IDS_SCC_STOPPED);
345 SetWndText(hDlg, IDC_SCC_ACTION_MSG, IDS_SCC_HOW_TO_RUN);
355 static void OnDbService()
357 bDbOn = GetButtonState(hDlg, IDC_DB_SERVICE) == BST_CHECKED;
365 static void OnBakService()
372 static void OnFsService()
381 static void CheckEnableBak()
383 // Enable/disable bk service based on db service.
385 SetCheck(hDlg, IDC_BK_SERVICE, FALSE);
386 SetEnable(hDlg, IDC_BK_SERVICE, ES_DISABLE);
387 SetWndText(hDlg, IDC_BK_STATUS_MSG, IDS_BK_DISABLED);
388 SetWndText(hDlg, IDC_BK_ACTION_MSG, IDS_BK_ENABLE);
390 SetCheck(hDlg, IDC_BK_SERVICE, bBakOn);
391 SetEnable(hDlg, IDC_BK_SERVICE, ES_ENABLE);
395 static void CheckEnableSc()
404 // Disable SCS and SCC?
405 if (!bFsOn && !bDbOn) {
407 uiScsStatusMsg = IDS_SC_DISABLED;
408 uiScsActionMsg = IDS_SC_ENABLE;
411 uiSccStatusMsg = IDS_SC_DISABLED;
412 uiSccActionMsg = IDS_SC_ENABLE;
416 uiScsStatusMsg = IDS_SC_DISABLED;
417 uiScsActionMsg = IDS_SCS_ENABLE;
421 uiSccStatusMsg = IDS_SC_DISABLED;
422 uiSccActionMsg = IDS_SCC_ENABLE;
425 // Enable the sc server GUI
427 SetEnable(hDlg, IDC_SCS, ES_ENABLE);
428 SetCheck(hDlg, IDC_SCS, bScsOn);
429 } else { // Disable the sc server gui
430 SetEnable(hDlg, IDC_SCS, ES_DISABLE);
431 SetCheck(hDlg, IDC_SCS, FALSE);
432 SetWndText(hDlg, IDC_SCS_STATUS_MSG, uiScsStatusMsg);
433 SetWndText(hDlg, IDC_SCS_ACTION_MSG, uiScsActionMsg);
436 // Enable the sc client GUI
438 SetEnable(hDlg, IDC_SCC, ES_ENABLE);
439 SetCheck(hDlg, IDC_SCC, bSccOn);
440 EnableScMachine(bSccOn);
441 } else { // Disable the sc client gui
442 SetEnable(hDlg, IDC_SCC, ES_DISABLE);
443 SetCheck(hDlg, IDC_SCC, FALSE);
444 SetWndText(hDlg, IDC_SCC_STATUS_MSG, uiSccStatusMsg);
445 SetWndText(hDlg, IDC_SCC_ACTION_MSG, uiSccActionMsg);
446 EnableScMachine(FALSE);
450 static void OnScServer()
457 static void OnScClient()
464 static void OnScMachineChange()
466 if (!bSettingScMachine && IsButtonChecked(hDlg, IDC_SCC))
467 GetWndText(hDlg, IDC_SC_MACHINE, szScMachine, sizeof(szScMachine) / sizeof(szScMachine[0]));
470 static BOOL PrepareToConfig(CONFIG_STATE& state, BOOL bRunning, BOOL bOn, UINT uiCtrlID)
472 BOOL bEnabled = IsWindowEnabled(GetDlgItem(hDlg, uiCtrlID));
474 if (bRunning && (!bOn || !bEnabled))
475 state = CS_UNCONFIGURE;
476 else if (!bRunning && (bOn && bEnabled))
477 state = CS_CONFIGURE;
479 return (state == CS_UNCONFIGURE) || (state == CS_CONFIGURE);
482 static BOOL PrepareToConfig()
484 BOOL bMustExit = FALSE;
486 // Use a local copy of the config info to decide what should be configured
487 // or unconfigured. We do this so that if the user cancels for some reason,
488 // the real config state will still be what the user expects (what was
489 // previously read from the system plus the user's changes).
490 CONFIG_STATE configFS = g_CfgData.configFS; // File server
491 CONFIG_STATE configDB = g_CfgData.configDB; // Database server
492 CONFIG_STATE configBak = g_CfgData.configBak; // Backup server
493 CONFIG_STATE configSCS = g_CfgData.configSCS; // System Control server
494 CONFIG_STATE configSCC = g_CfgData.configSCC; // System Control client
496 BOOL bWorkToDo = FALSE;
498 bWorkToDo |= PrepareToConfig(configFS, bFsRunning, bFsOn, IDC_FS_SERVICE);
499 bWorkToDo |= PrepareToConfig(configDB, bDbRunning, bDbOn, IDC_DB_SERVICE);
500 bWorkToDo |= PrepareToConfig(configBak, bBakRunning, bBakOn, IDC_BK_SERVICE);
501 bWorkToDo |= PrepareToConfig(configSCS, bScsRunning, bScsOn, IDC_SCS);
502 bWorkToDo |= PrepareToConfig(configSCC, bSccRunning, bSccOn, IDC_SCC);
504 // If there is nothing to do, then just return TRUE.
508 // If we are unconfiguring the last DB server:
509 // 1) Warn user and ask for confirmation
510 // 2) Unconfigure all other servers that are running on this machine
511 // 3) Tell them (after unconfiguring) that they must run the Wizard if they
512 // wish to reconfigure the machine, then exit the program.
513 if (configDB == CS_UNCONFIGURE) {
514 if (g_CfgData.bLastDBServer) {
515 int nChoice = MsgBox(hDlg, IDS_LAST_DB_SERVER, GetAppTitleID(), MB_YESNO | MB_ICONEXCLAMATION);
519 // Make sure these all get unconfigured as well. If they are not configured, then
520 // nothing bad will happen because the config calls are idempotent.
521 configFS = CS_UNCONFIGURE;
522 configBak = CS_UNCONFIGURE;
523 configSCS = CS_UNCONFIGURE;
524 configSCC = CS_UNCONFIGURE;
528 // Get additional needed information from the user
529 GET_ADMIN_INFO_OPTIONS eOptions;
530 BOOL bDB = (ShouldConfig(configDB) || ShouldUnconfig(configDB));
532 // Use this as our default
533 eOptions = GAIO_LOGIN_ONLY;
535 // If we already have a sys control machine, then we don't need to ask for it
536 if (ShouldConfig(configSCC)) {
537 if (szScMachine[0] == 0) {
538 ShowWarning(hDlg, IDS_MUST_ENTER_SCS_NAME);
541 lstrcpy(g_CfgData.szSysControlMachine, szScMachine);
542 } else if (bDB && !g_CfgData.bLastDBServer) {
543 // We need to know the name of the SCM machine. Are we the SCM machine?
545 lstrcpy(g_CfgData.szSysControlMachine, g_CfgData.szHostname);
547 eOptions = GAIO_GET_SCS;
550 // If doing a login only and the admin info is reusable
551 if ((eOptions != GAIO_LOGIN_ONLY) || !g_CfgData.bReuseAdminInfo) {
552 if (!GetAdminInfo(hDlg, eOptions))
555 // Use the admin info to get new handles
556 if (!GetHandles(hDlg))
560 // Now that we are ready to configure, copy our local config info
561 // into the structure that the config engine uses.
562 g_CfgData.configFS = configFS;
563 g_CfgData.configDB = configDB;
564 g_CfgData.configBak = configBak;
565 g_CfgData.configSCS = configSCS;
566 g_CfgData.configSCC = configSCC;
568 // Configure the server
569 BOOL bConfigSucceeded = Configure(hDlg, bMustExit);
570 if (bConfigSucceeded) {
575 g_CfgData.bReuseAdminInfo = TRUE;
577 g_CfgData.szAdminPW[0] = 0;
579 // Get current config status
580 BOOL bCanceled = FALSE;
581 DWORD dwStatus = GetCurrentConfig(hDlg, bCanceled);
582 if (dwStatus || bCanceled) {
584 ErrorDialog(dwStatus, IDS_CONFIG_CHECK_FAILED);
587 // Show the initial services config
594 static void CheckEnableApply()
596 BOOL bEnable = FALSE;
598 bEnable = (bFsRunning != bFsOn) || (bDbRunning != bDbOn) || (bBakRunning != bBakOn) ||
599 (bScsRunning != bScsOn) || (bSccRunning != bSccOn);
602 PropSheet_Changed(GetParent(hDlg), hDlg);
604 PropSheet_UnChanged(GetParent(hDlg), hDlg);