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 _________________________________________________________________
18 #include <afs/param.h>
25 #include "admin_info_dlg.h"
26 #include "get_cur_config.h"
30 * DEFINITIONS _________________________________________________________________
34 static BOOL bSettingScMachine
;
36 // These indicate if the named service is currently running, and if the user wants it on
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
))
97 OnInitDialog(hwndDlg
);
101 switch (LOWORD(wParam
)) {
123 if (HIWORD(wParam
) == EN_CHANGE
) {
142 * STATIC FUNCTIONS _________________________________________________________________
145 static void OnInitDialog(HWND hwndDlg
)
149 // Show the initial services config
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()
173 bFsRunning
= Configured(g_CfgData
.configFS
);
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
);
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
);
187 Set2State(hDlg
, IDC_DB_SERVICE
);
189 bDbRunning
= Configured(g_CfgData
.configDB
);
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
);
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
);
209 bBakRunning
= Configured(g_CfgData
.configBak
);
210 SetEnable(hDlg
, IDC_BK_SERVICE
, ES_ENABLE
);
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
);
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
;
224 bScsRunning
= Configured(g_CfgData
.configSCS
);
225 SetEnable(hDlg
, IDC_SCS
, ES_ENABLE
);
227 SetCheck(hDlg
, IDC_SCS
);
228 SetWndText(hDlg
, IDC_SCS_ACTION_MSG
, IDS_SCS_HOW_TO_STOP
);
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
;
238 bSccRunning
= Configured(g_CfgData
.configSCC
);
239 SetEnable(hDlg
, IDC_SCC
, ES_ENABLE
);
241 SetCheck(hDlg
, IDC_SCC
);
242 SetWndText(hDlg
, IDC_SCC_ACTION_MSG
, IDS_SCC_HOW_TO_STOP
);
244 lstrcpy(szScMachine
, g_CfgData
.szSysControlMachine
);
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()
260 SetWndText(hDlg
, IDC_FS_ACTION_MSG
, IDS_FS_HOW_TO_STOP
);
262 SetWndText(hDlg
, IDC_FS_ACTION_MSG
, IDS_FS_WILL_RUN
);
265 SetWndText(hDlg
, IDC_FS_ACTION_MSG
, IDS_FS_WILL_STOP
);
267 SetWndText(hDlg
, IDC_FS_ACTION_MSG
, IDS_FS_HOW_TO_RUN
);
271 switch (GetButtonState(hDlg
, IDC_DB_SERVICE
)) {
274 SetWndText(hDlg
, IDC_DB_ACTION_MSG
, IDS_DB_HOW_TO_STOP
);
276 SetWndText(hDlg
, IDC_DB_ACTION_MSG
, IDS_DB_WILL_RUN
);
281 SetWndText(hDlg
, IDC_DB_ACTION_MSG
, IDS_DB_WILL_STOP
);
283 SetWndText(hDlg
, IDC_DB_ACTION_MSG
, IDS_DB_HOW_TO_RUN
);
286 case BST_INDETERMINATE
:
287 SetWndText(hDlg
, IDC_DB_ACTION_MSG
, IDS_DB_DETAILS
);
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-
299 if (IsButtonChecked(hDlg
, IDC_BK_SERVICE
)) {
301 SetWndText(hDlg
, IDC_BK_STATUS_MSG
, IDS_BK_RUNNING
);
302 SetWndText(hDlg
, IDC_BK_ACTION_MSG
, IDS_BK_HOW_TO_STOP
);
304 SetWndText(hDlg
, IDC_BK_STATUS_MSG
, IDS_BK_STOPPED
);
305 SetWndText(hDlg
, IDC_BK_ACTION_MSG
, IDS_BK_WILL_RUN
);
309 SetWndText(hDlg
, IDC_BK_STATUS_MSG
, IDS_BK_RUNNING
);
310 SetWndText(hDlg
, IDC_BK_ACTION_MSG
, IDS_BK_WILL_STOP
);
312 SetWndText(hDlg
, IDC_BK_STATUS_MSG
, IDS_BK_STOPPED
);
313 SetWndText(hDlg
, IDC_BK_ACTION_MSG
, IDS_BK_HOW_TO_RUN
);
321 if (bFsOn
|| bDbOn
&& !bSccOn
) {
324 SetWndText(hDlg
, IDC_SCS_STATUS_MSG
, IDS_SCS_RUNNING
);
325 SetWndText(hDlg
, IDC_SCS_ACTION_MSG
, IDS_SCS_HOW_TO_STOP
);
327 SetWndText(hDlg
, IDC_SCS_STATUS_MSG
, IDS_SCS_STOPPED
);
328 SetWndText(hDlg
, IDC_SCS_ACTION_MSG
, IDS_SCS_WILL_RUN
);
332 SetWndText(hDlg
, IDC_SCS_STATUS_MSG
, IDS_SCS_RUNNING
);
333 SetWndText(hDlg
, IDC_SCS_ACTION_MSG
, IDS_SCS_WILL_STOP
);
335 SetWndText(hDlg
, IDC_SCS_STATUS_MSG
, IDS_SCS_STOPPED
);
336 SetWndText(hDlg
, IDC_SCS_ACTION_MSG
, IDS_SCS_HOW_TO_RUN
);
342 if (bFsOn
|| bDbOn
&& !bScsOn
) {
345 SetWndText(hDlg
, IDC_SCC_STATUS_MSG
, IDS_SCC_RUNNING
);
346 SetWndText(hDlg
, IDC_SCC_ACTION_MSG
, IDS_SCC_HOW_TO_STOP
);
348 SetWndText(hDlg
, IDC_SCC_STATUS_MSG
, IDS_SCC_STOPPED
);
349 SetWndText(hDlg
, IDC_SCC_ACTION_MSG
, IDS_SCC_WILL_RUN
);
353 SetWndText(hDlg
, IDC_SCC_STATUS_MSG
, IDS_SCC_RUNNING
);
354 SetWndText(hDlg
, IDC_SCC_ACTION_MSG
, IDS_SCC_WILL_STOP
);
356 SetWndText(hDlg
, IDC_SCC_STATUS_MSG
, IDS_SCC_STOPPED
);
357 SetWndText(hDlg
, IDC_SCC_ACTION_MSG
, IDS_SCC_HOW_TO_RUN
);
365 static void OnDbService()
367 bDbOn
= GetButtonState(hDlg
, IDC_DB_SERVICE
) == BST_CHECKED
;
375 static void OnBakService()
382 static void OnFsService()
391 static void CheckEnableBak()
393 // Enable/disable bk service based on db service.
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
);
400 SetCheck(hDlg
, IDC_BK_SERVICE
, bBakOn
);
401 SetEnable(hDlg
, IDC_BK_SERVICE
, ES_ENABLE
);
405 static void CheckEnableSc()
407 BOOL bSccEnable
= TRUE
;
410 BOOL bScsEnable
= TRUE
;
414 // Disable SCS and SCC?
415 if (!bFsOn
&& !bDbOn
) {
417 uiScsStatusMsg
= IDS_SC_DISABLED
;
418 uiScsActionMsg
= IDS_SC_ENABLE
;
421 uiSccStatusMsg
= IDS_SC_DISABLED
;
422 uiSccActionMsg
= IDS_SC_ENABLE
;
426 uiScsStatusMsg
= IDS_SC_DISABLED
;
427 uiScsActionMsg
= IDS_SCS_ENABLE
;
431 uiSccStatusMsg
= IDS_SC_DISABLED
;
432 uiSccActionMsg
= IDS_SCC_ENABLE
;
435 // Enable the sc server GUI
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
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()
467 static void OnScClient()
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.
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
);
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
);
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?
555 lstrcpy(g_CfgData
.szSysControlMachine
, g_CfgData
.szHostname
);
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
))
565 // Use the admin info to get new handles
566 if (!GetHandles(hDlg
))
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
) {
585 g_CfgData
.bReuseAdminInfo
= TRUE
;
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
) {
594 ErrorDialog(dwStatus
, IDS_CONFIG_CHECK_FAILED
);
597 // Show the initial services config
604 static void CheckEnableApply()
606 BOOL bEnable
= FALSE
;
608 bEnable
= (bFsRunning
!= bFsOn
) || (bDbRunning
!= bDbOn
) || (bBakRunning
!= bBakOn
) ||
609 (bScsRunning
!= bScsOn
) || (bSccRunning
!= bSccOn
);
612 PropSheet_Changed(GetParent(hDlg
), hDlg
);
614 PropSheet_UnChanged(GetParent(hDlg
), hDlg
);