Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

502 lines
12 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // groupwiz.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the classes that implement the new RADIUS server group wizard.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 03/07/2000 Original version.
  16. // 04/19/2000 Marshall SDOs across apartments.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <proxypch.h>
  20. #include <groupwiz.h>
  21. #include <resolver.h>
  22. NewGroupStartPage::NewGroupStartPage(NewGroupWizard& wizard)
  23. : SnapInPropertyPage(IDD_NEWGROUP_WELCOME, 0, 0, false),
  24. parent(wizard)
  25. {
  26. }
  27. BOOL NewGroupStartPage::OnInitDialog()
  28. {
  29. SnapInPropertyPage::OnInitDialog();
  30. setLargeFont(IDC_STATIC_LARGE);
  31. return TRUE;
  32. }
  33. BOOL NewGroupStartPage::OnSetActive()
  34. {
  35. SnapInPropertyPage::OnSetActive();
  36. parent.SetWizardButtons(PSWIZB_NEXT);
  37. return TRUE;
  38. }
  39. NewGroupNamePage::NewGroupNamePage(NewGroupWizard& wizard)
  40. : SnapInPropertyPage(
  41. IDD_NEWGROUP_NAME,
  42. IDS_NEWGROUP_NAME_TITLE,
  43. IDS_NEWGROUP_NAME_SUBTITLE,
  44. false
  45. ),
  46. parent(wizard)
  47. {
  48. }
  49. LRESULT NewGroupNamePage::OnWizardBack()
  50. {
  51. // Save the state of the radio button.
  52. getRadio(IDC_RADIO_TYPICAL, IDC_RADIO_CUSTOM, parent.advanced);
  53. return 0;
  54. }
  55. LRESULT NewGroupNamePage::OnWizardNext()
  56. {
  57. if (!parent.group.setName(name))
  58. {
  59. failNoThrow(IDC_EDIT_NAME, IDS_GROUP_E_NOT_UNIQUE);
  60. return -1;
  61. }
  62. getRadio(IDC_RADIO_TYPICAL, IDC_RADIO_CUSTOM, parent.advanced);
  63. return parent.advanced ? IDD_NEWGROUP_SERVERS : IDD_NEWGROUP_NOVICE;
  64. }
  65. void NewGroupNamePage::onChangeName()
  66. {
  67. getValue(IDC_EDIT_NAME, name);
  68. setButtons();
  69. }
  70. void NewGroupNamePage::setData()
  71. {
  72. setValue(IDC_EDIT_NAME, name);
  73. setRadio(IDC_RADIO_TYPICAL, IDC_RADIO_CUSTOM, parent.advanced);
  74. setButtons();
  75. }
  76. void NewGroupNamePage::setButtons()
  77. {
  78. parent.SetWizardButtons(
  79. name.Length() ? (PSWIZB_BACK | PSWIZB_NEXT) : PSWIZB_BACK
  80. );
  81. }
  82. BEGIN_MESSAGE_MAP(NewGroupNamePage, SnapInPropertyPage)
  83. ON_EN_CHANGE(IDC_EDIT_NAME, onChangeName)
  84. END_MESSAGE_MAP()
  85. NewGroupNovicePage::NewGroupNovicePage(NewGroupWizard& wizard)
  86. : SnapInPropertyPage(
  87. IDD_NEWGROUP_NOVICE,
  88. IDS_NEWGROUP_NOVICE_TITLE,
  89. IDS_NEWGROUP_NOVICE_SUBTITLE,
  90. false
  91. ),
  92. parent(wizard)
  93. {
  94. }
  95. LRESULT NewGroupNovicePage::OnWizardBack()
  96. {
  97. // Save the secrets.
  98. getValue(IDC_EDIT_AUTH_SECRET1, secret);
  99. getValue(IDC_EDIT_AUTH_SECRET2, confirm);
  100. return 0;
  101. }
  102. LRESULT NewGroupNovicePage::OnWizardNext()
  103. {
  104. // Get the secret.
  105. getValue(IDC_EDIT_AUTH_SECRET1, secret);
  106. // Make sure the confirmation matches the secret.
  107. getValue(IDC_EDIT_AUTH_SECRET2, confirm);
  108. if (wcscmp(secret, confirm))
  109. {
  110. failNoThrow(IDC_EDIT_AUTH_SECRET1, IDS_SERVER_E_SECRET_MATCH);
  111. return -1;
  112. }
  113. // Get the servers collection.
  114. SdoCollection servers;
  115. parent.group.getValue(
  116. PROPERTY_RADIUSSERVERGROUP_SERVERS_COLLECTION,
  117. servers
  118. );
  119. // Remove any exisiting servers.
  120. servers.removeAll();
  121. // Create the primary server.
  122. Sdo primarySdo = servers.create();
  123. primarySdo.setValue(PROPERTY_RADIUSSERVER_ADDRESS, primary);
  124. primarySdo.setValue(PROPERTY_RADIUSSERVER_AUTH_SECRET, secret);
  125. if (hasBackup)
  126. {
  127. // Create the backup server.
  128. Sdo backupSdo = servers.create();
  129. backupSdo.setValue(PROPERTY_RADIUSSERVER_ADDRESS, backup);
  130. backupSdo.setValue(PROPERTY_RADIUSSERVER_AUTH_SECRET, secret);
  131. backupSdo.setValue(PROPERTY_RADIUSSERVER_PRIORITY, 2L);
  132. }
  133. return IDD_NEWGROUP_COMPLETION;
  134. }
  135. void NewGroupNovicePage::onChangePrimary()
  136. {
  137. getValue(IDC_EDIT_PRIMARY, primary);
  138. setControlState();
  139. }
  140. void NewGroupNovicePage::onChangeHasBackup()
  141. {
  142. getValue(IDC_CHECK_BACKUP, hasBackup);
  143. setControlState();
  144. }
  145. void NewGroupNovicePage::onChangeBackup()
  146. {
  147. getValue(IDC_EDIT_BACKUP, backup);
  148. setControlState();
  149. }
  150. void NewGroupNovicePage::onVerifyPrimary()
  151. {
  152. Resolver resolver(primary);
  153. if (resolver.DoModal() == IDOK)
  154. {
  155. primary = resolver.getChoice();
  156. setValue(IDC_EDIT_PRIMARY, primary);
  157. setControlState();
  158. }
  159. }
  160. void NewGroupNovicePage::onVerifyBackup()
  161. {
  162. Resolver resolver(backup);
  163. if (resolver.DoModal() == IDOK)
  164. {
  165. backup = resolver.getChoice();
  166. setValue(IDC_EDIT_BACKUP, backup);
  167. setControlState();
  168. }
  169. }
  170. void NewGroupNovicePage::setData()
  171. {
  172. setValue(IDC_EDIT_PRIMARY, primary);
  173. setValue(IDC_CHECK_BACKUP, hasBackup);
  174. setValue(IDC_EDIT_BACKUP, backup);
  175. setValue(IDC_EDIT_AUTH_SECRET1, secret);
  176. setValue(IDC_EDIT_AUTH_SECRET2, confirm);
  177. setControlState();
  178. }
  179. void NewGroupNovicePage::setControlState()
  180. {
  181. enableControl(IDC_EDIT_BACKUP, hasBackup);
  182. enableControl(IDC_BUTTON_VERIFY_BACKUP, hasBackup);
  183. DWORD buttons = PSWIZB_BACK;
  184. // We always require a primary. We also require a backup if the box is
  185. // checked.
  186. if (primary.Length() && (!hasBackup || backup.Length()))
  187. {
  188. buttons |= PSWIZB_NEXT;
  189. }
  190. parent.SetWizardButtons(buttons);
  191. }
  192. BEGIN_MESSAGE_MAP(NewGroupNovicePage, SnapInPropertyPage)
  193. ON_EN_CHANGE(IDC_EDIT_PRIMARY, onChangePrimary)
  194. ON_EN_CHANGE(IDC_EDIT_BACKUP, onChangeBackup)
  195. ON_BN_CLICKED(IDC_CHECK_BACKUP, onChangeHasBackup)
  196. ON_BN_CLICKED(IDC_BUTTON_VERIFY_PRIMARY, onVerifyPrimary)
  197. ON_BN_CLICKED(IDC_BUTTON_VERIFY_BACKUP, onVerifyBackup)
  198. END_MESSAGE_MAP()
  199. NewGroupServersPage::NewGroupServersPage(NewGroupWizard& wizard)
  200. : SnapInPropertyPage(
  201. IDD_NEWGROUP_SERVERS,
  202. IDS_NEWGROUP_SERVERS_TITLE,
  203. IDS_NEWGROUP_SERVERS_SUBTITLE,
  204. false
  205. ),
  206. parent(wizard)
  207. {
  208. }
  209. BOOL NewGroupServersPage::OnInitDialog()
  210. {
  211. servers.onInitDialog(m_hWnd, parent.group);
  212. return SnapInPropertyPage::OnInitDialog();
  213. }
  214. void NewGroupServersPage::OnSysColorChange()
  215. {
  216. servers.onSysColorChange();
  217. }
  218. LRESULT NewGroupServersPage::OnWizardBack()
  219. {
  220. return IDD_NEWGROUP_NAME;
  221. }
  222. void NewGroupServersPage::onAdd()
  223. {
  224. if (servers.onAdd())
  225. {
  226. // If the user makes any changes to the server list, we put him in
  227. // advanced mode.
  228. parent.advanced = 1;
  229. setButtons();
  230. }
  231. }
  232. void NewGroupServersPage::onEdit()
  233. {
  234. if (servers.onEdit())
  235. {
  236. // If the user makes any changes to the server list, we put him in
  237. // advanced mode.
  238. parent.advanced = 1;
  239. }
  240. }
  241. void NewGroupServersPage::onRemove()
  242. {
  243. if (servers.onRemove())
  244. {
  245. // If the user makes any changes to the server list, we put him in
  246. // advanced mode.
  247. parent.advanced = 1;
  248. setButtons();
  249. }
  250. }
  251. void NewGroupServersPage::onColumnClick(NMLISTVIEW* listView, LRESULT* result)
  252. {
  253. servers.onColumnClick(listView->iSubItem);
  254. }
  255. void NewGroupServersPage::onItemActivate(
  256. NMITEMACTIVATE* itemActivate,
  257. LRESULT* result
  258. )
  259. {
  260. onEdit();
  261. }
  262. void NewGroupServersPage::onServerChanged(
  263. NMLISTVIEW* listView,
  264. LRESULT* result
  265. )
  266. {
  267. servers.onServerChanged();
  268. }
  269. void NewGroupServersPage::getData()
  270. {
  271. servers.saveChanges(false);
  272. }
  273. void NewGroupServersPage::setData()
  274. {
  275. servers.setData();
  276. setButtons();
  277. }
  278. void NewGroupServersPage::setButtons()
  279. {
  280. parent.SetWizardButtons(
  281. servers.isEmpty() ? PSWIZB_BACK : (PSWIZB_BACK | PSWIZB_NEXT)
  282. );
  283. }
  284. BEGIN_MESSAGE_MAP(NewGroupServersPage, SnapInPropertyPage)
  285. ON_BN_CLICKED(IDC_BUTTON_ADD, onAdd)
  286. ON_BN_CLICKED(IDC_BUTTON_EDIT, onEdit)
  287. ON_BN_CLICKED(IDC_BUTTON_REMOVE, onRemove)
  288. ON_EN_CHANGE(IDC_EDIT_NAME, onChange)
  289. ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_SERVERS, onColumnClick)
  290. ON_NOTIFY(LVN_ITEMACTIVATE, IDC_LIST_SERVERS, onItemActivate)
  291. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_SERVERS, onServerChanged)
  292. END_MESSAGE_MAP()
  293. NewGroupFinishPage::NewGroupFinishPage(
  294. NewGroupWizard& wizard,
  295. bool promptForNewPolicy
  296. )
  297. : SnapInPropertyPage(IDD_NEWGROUP_COMPLETION, 0, 0, false),
  298. parent(wizard),
  299. allowCreate(promptForNewPolicy),
  300. createPolicy(true)
  301. {
  302. }
  303. BOOL NewGroupFinishPage::OnInitDialog()
  304. {
  305. setLargeFont(IDC_STATIC_LARGE);
  306. initControl(IDC_STATIC_FINISH, text);
  307. showControl(IDC_STATIC_CREATE_POLICY, allowCreate);
  308. showControl(IDC_CHECK_CREATE_POLICY, allowCreate);
  309. return SnapInPropertyPage::OnInitDialog();
  310. }
  311. LRESULT NewGroupFinishPage::OnWizardBack()
  312. {
  313. return parent.advanced ? IDD_NEWGROUP_SERVERS : IDD_NEWGROUP_NOVICE;
  314. }
  315. void NewGroupFinishPage::setData()
  316. {
  317. setValue(IDC_CHECK_CREATE_POLICY, createPolicy);
  318. parent.SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
  319. text.SetWindowText(parent.getFinishText());
  320. }
  321. void NewGroupFinishPage::saveChanges()
  322. {
  323. // This is a good time to get the status of the check box.
  324. getValue(IDC_CHECK_CREATE_POLICY, createPolicy);
  325. // We have to persist the group first. The SDOs won't let you persist a
  326. // child if the parent doesn't exist.
  327. parent.group.apply();
  328. // Get the servers collection.
  329. SdoCollection servers;
  330. parent.group.getValue(
  331. PROPERTY_RADIUSSERVERGROUP_SERVERS_COLLECTION,
  332. servers
  333. );
  334. // Persist each server.
  335. Sdo server;
  336. SdoEnum sdoEnum = servers.getNewEnum();
  337. while (sdoEnum.next(server))
  338. {
  339. server.apply();
  340. }
  341. }
  342. NewGroupWizard::NewGroupWizard(
  343. SdoConnection& connection,
  344. SnapInView* snapInView,
  345. bool promptForNewPolicy
  346. )
  347. : CPropertySheetEx(
  348. (UINT)0,
  349. NULL,
  350. 0,
  351. LoadBitmapW(
  352. AfxGetResourceHandle(),
  353. MAKEINTRESOURCEW(IDB_PROXY_SERVER_WATERMARK)
  354. ),
  355. NULL,
  356. LoadBitmapW(
  357. AfxGetResourceHandle(),
  358. MAKEINTRESOURCEW(IDB_PROXY_SERVER_HEADER)
  359. )
  360. ),
  361. advanced(0),
  362. cxn(connection),
  363. view(snapInView),
  364. start(*this),
  365. name(*this),
  366. novice(*this),
  367. servers(*this),
  368. finish(*this, promptForNewPolicy)
  369. {
  370. m_psh.dwFlags |= PSH_WIZARD97;
  371. AddPage(&start);
  372. AddPage(&name);
  373. AddPage(&novice);
  374. AddPage(&servers);
  375. AddPage(&finish);
  376. }
  377. INT_PTR NewGroupWizard::DoModal()
  378. {
  379. int retval = CPropertySheetEx::DoModal();
  380. if (retval == IDCANCEL)
  381. {
  382. // User cancelled, so remove the group.
  383. groupStream.get(group);
  384. cxn.getServerGroups().remove(group);
  385. }
  386. else if (view)
  387. {
  388. // User created a group, so send a propertyChanged notification.
  389. cxn.propertyChanged(
  390. *view,
  391. PROPERTY_IAS_RADIUSSERVERGROUPS_COLLECTION
  392. );
  393. }
  394. return retval;
  395. }
  396. CString NewGroupWizard::getFinishText()
  397. {
  398. CString text;
  399. if (!advanced)
  400. {
  401. if (novice.getBackupServer())
  402. {
  403. text.FormatMessage(
  404. IDS_NEWGROUP_FINISH_TYPICAL,
  405. name.getName(),
  406. novice.getPrimaryServer(),
  407. novice.getBackupServer()
  408. );
  409. }
  410. else
  411. {
  412. text.FormatMessage(
  413. IDS_NEWGROUP_FINISH_TYPICAL,
  414. name.getName(),
  415. novice.getPrimaryServer(),
  416. ResourceString(IDS_NEWGROUP_NO_BACKUP)
  417. );
  418. }
  419. }
  420. else
  421. {
  422. text.FormatMessage(
  423. IDS_NEWGROUP_FINISH_CUSTOM,
  424. name.getName()
  425. );
  426. }
  427. return text;
  428. }
  429. BOOL NewGroupWizard::OnInitDialog()
  430. {
  431. // Create a new group.
  432. group = cxn.getServerGroups().create();
  433. // Save it in a stream, so we can access it from DoModal.
  434. groupStream.marshal(group);
  435. return CPropertySheetEx::OnInitDialog();
  436. }