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.

309 lines
8.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // serverprop.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the classes that make up the RADIUS Server property sheet.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/27/2000 Original version.
  16. // 04/19/2000 Marshall SDOs across apartments.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <proxypch.h>
  20. #include <serverprop.h>
  21. #include <resolver.h>
  22. // Fake secret used for populating the edit control.
  23. const WCHAR FAKE_SECRET[] = L"\b\b\b\b\b\b\b\b";
  24. ServerNamePage::ServerNamePage(Sdo& serverSdo)
  25. : SnapInPropertyPage(IDD_SERVER_NAME),
  26. server(serverSdo)
  27. {
  28. server.getValue(PROPERTY_RADIUSSERVER_ADDRESS, address, L"");
  29. }
  30. void ServerNamePage::onResolve()
  31. {
  32. // Get the address.
  33. getValue(IDC_EDIT_NAME, address);
  34. // Pass it to the resolver.
  35. Resolver resolver(address);
  36. if (resolver.DoModal() == IDOK)
  37. {
  38. // The user clicked OK, so save his choice.
  39. setValue(IDC_EDIT_NAME, resolver.getChoice());
  40. }
  41. }
  42. void ServerNamePage::getData()
  43. {
  44. // Get the address.
  45. getValue(IDC_EDIT_NAME, address);
  46. // The address can't be empty.
  47. if (address.Length() == 0)
  48. {
  49. fail(IDC_EDIT_NAME, IDS_SERVER_E_NAME_EMPTY);
  50. }
  51. }
  52. void ServerNamePage::setData()
  53. {
  54. setValue(IDC_EDIT_NAME, address);
  55. }
  56. void ServerNamePage::saveChanges()
  57. {
  58. server.setValue(PROPERTY_RADIUSSERVER_ADDRESS, address);
  59. }
  60. BEGIN_MESSAGE_MAP(ServerNamePage, SnapInPropertyPage)
  61. ON_EN_CHANGE(IDC_EDIT_NAME, onChange)
  62. ON_BN_CLICKED(IDC_BUTTON_VERIFY, onResolve)
  63. END_MESSAGE_MAP()
  64. ServerAuthPage::ServerAuthPage(Sdo& serverSdo)
  65. : SnapInPropertyPage(IDD_SERVER_AUTH),
  66. server(serverSdo),
  67. authSecretDirty(false),
  68. acctSecretDirty(false)
  69. {
  70. server.getValue(PROPERTY_RADIUSSERVER_AUTH_PORT, authPort, 1812);
  71. server.getValue(PROPERTY_RADIUSSERVER_AUTH_SECRET, authSecret, L"");
  72. server.getValue(PROPERTY_RADIUSSERVER_ACCT_PORT, acctPort, 1813);
  73. server.getValue(PROPERTY_RADIUSSERVER_ACCT_SECRET, acctSecret, NULL);
  74. useSameSecret = !acctSecret;
  75. server.getValue(PROPERTY_RADIUSSERVER_FORWARD_ACCT_ONOFF, acctOnOff, true);
  76. }
  77. void ServerAuthPage::onChangeAuthSecret()
  78. {
  79. authSecretDirty = true;
  80. SetModified();
  81. }
  82. void ServerAuthPage::onChangeAcctSecret()
  83. {
  84. acctSecretDirty = true;
  85. SetModified();
  86. }
  87. void ServerAuthPage::onCheckSameSecret()
  88. {
  89. // Get the checkbox state.
  90. getValue(IDC_CHECK_SAME_SECRET, useSameSecret);
  91. // Update the edit box accordingly.
  92. enableControl(IDC_EDIT_ACCT_SECRET1, !useSameSecret);
  93. enableControl(IDC_EDIT_ACCT_SECRET2, !useSameSecret);
  94. // We've been modified.
  95. SetModified();
  96. }
  97. void ServerAuthPage::getData()
  98. {
  99. getValue(IDC_EDIT_AUTH_PORT, authPort, IDS_SERVER_E_AUTH_PORT_EMPTY);
  100. if (authSecretDirty)
  101. {
  102. // Get the authentication secret ...
  103. getValue(IDC_EDIT_AUTH_SECRET1, authSecret, false);
  104. // ... and make sure it matches the confirmation.
  105. CComBSTR confirm;
  106. getValue(IDC_EDIT_AUTH_SECRET2, confirm, false);
  107. if (wcscmp(confirm, authSecret))
  108. {
  109. fail(IDC_EDIT_AUTH_SECRET1, IDS_SERVER_E_SECRET_MATCH);
  110. }
  111. authSecretDirty = false;
  112. }
  113. getValue(IDC_EDIT_ACCT_PORT, acctPort, IDS_SERVER_E_ACCT_PORT_EMPTY);
  114. getValue(IDC_CHECK_SAME_SECRET, useSameSecret);
  115. if (!useSameSecret && acctSecretDirty)
  116. {
  117. // Get the accounting secret ...
  118. getValue(IDC_EDIT_ACCT_SECRET1, acctSecret);
  119. // ... and make sure it matches the confirmation.
  120. CComBSTR confirm;
  121. getValue(IDC_EDIT_ACCT_SECRET2, confirm);
  122. if (wcscmp(confirm, acctSecret))
  123. {
  124. fail(IDC_EDIT_ACCT_SECRET1, IDS_SERVER_E_SECRET_MATCH);
  125. }
  126. acctSecretDirty = false;
  127. }
  128. getValue(IDC_CHECK_ACCT_ONOFF, acctOnOff);
  129. }
  130. void ServerAuthPage::setData()
  131. {
  132. setValue(IDC_EDIT_AUTH_PORT, authPort);
  133. setValue(IDC_EDIT_AUTH_SECRET1, FAKE_SECRET);
  134. setValue(IDC_EDIT_AUTH_SECRET2, FAKE_SECRET);
  135. setValue(IDC_EDIT_ACCT_PORT, acctPort);
  136. setValue(IDC_CHECK_SAME_SECRET, useSameSecret);
  137. setValue(IDC_EDIT_ACCT_SECRET1, FAKE_SECRET);
  138. setValue(IDC_EDIT_ACCT_SECRET2, FAKE_SECRET);
  139. setValue(IDC_CHECK_ACCT_ONOFF, acctOnOff);
  140. // Update the edit box state.
  141. enableControl(IDC_EDIT_ACCT_SECRET1, !useSameSecret);
  142. enableControl(IDC_EDIT_ACCT_SECRET2, !useSameSecret);
  143. }
  144. void ServerAuthPage::saveChanges()
  145. {
  146. server.setValue(PROPERTY_RADIUSSERVER_AUTH_PORT, authPort);
  147. server.setValue(PROPERTY_RADIUSSERVER_AUTH_SECRET, authSecret);
  148. server.setValue(PROPERTY_RADIUSSERVER_ACCT_PORT, acctPort);
  149. if (useSameSecret)
  150. {
  151. server.clearValue(PROPERTY_RADIUSSERVER_ACCT_SECRET);
  152. }
  153. else
  154. {
  155. server.setValue(PROPERTY_RADIUSSERVER_ACCT_SECRET, acctSecret);
  156. }
  157. server.setValue(PROPERTY_RADIUSSERVER_FORWARD_ACCT_ONOFF, acctOnOff);
  158. }
  159. BEGIN_MESSAGE_MAP(ServerAuthPage, SnapInPropertyPage)
  160. ON_EN_CHANGE(IDC_EDIT_AUTH_PORT, onChange)
  161. ON_EN_CHANGE(IDC_EDIT_AUTH_SECRET1, onChangeAuthSecret)
  162. ON_EN_CHANGE(IDC_EDIT_AUTH_SECRET2, onChangeAuthSecret)
  163. ON_BN_CLICKED(IDC_CHECK_SAME_SECRET, onCheckSameSecret)
  164. ON_BN_CLICKED(IDC_CHECK_ACCT_ONOFF, onChange)
  165. ON_EN_CHANGE(IDC_EDIT_ACCT_PORT, onChange)
  166. ON_EN_CHANGE(IDC_EDIT_ACCT_SECRET1, onChangeAcctSecret)
  167. ON_EN_CHANGE(IDC_EDIT_ACCT_SECRET2, onChangeAcctSecret)
  168. END_MESSAGE_MAP()
  169. ServerFTLBPage::ServerFTLBPage(Sdo& serverSdo)
  170. : SnapInPropertyPage(IDD_SERVER_FTLB),
  171. server(serverSdo)
  172. {
  173. server.getValue(PROPERTY_RADIUSSERVER_PRIORITY, priority, 1);
  174. server.getValue(PROPERTY_RADIUSSERVER_WEIGHT, weight, 50);
  175. server.getValue(PROPERTY_RADIUSSERVER_TIMEOUT, timeout, 3);
  176. server.getValue(PROPERTY_RADIUSSERVER_MAX_LOST, maxLost, 5);
  177. server.getValue(PROPERTY_RADIUSSERVER_BLACKOUT, blackout, 10 * timeout);
  178. }
  179. void ServerFTLBPage::getData()
  180. {
  181. getValue(IDC_EDIT_PRIORITY, priority, IDS_SERVER_E_PRIORITY_EMPTY);
  182. if (priority < 1 || priority > 65535)
  183. {
  184. fail(IDC_EDIT_PRIORITY, IDS_SERVER_E_PRIORITY_RANGE);
  185. }
  186. getValue(IDC_EDIT_WEIGHT, weight, IDS_SERVER_E_WEIGHT_EMPTY);
  187. if (weight < 1 || weight > 65535)
  188. {
  189. fail(IDC_EDIT_WEIGHT, IDS_SERVER_E_WEIGHT_RANGE);
  190. }
  191. getValue(IDC_EDIT_TIMEOUT, timeout, IDS_SERVER_E_TIMEOUT_EMPTY);
  192. if (timeout < 1)
  193. {
  194. fail(IDC_EDIT_TIMEOUT, IDS_SERVER_E_TIMEOUT_RANGE);
  195. }
  196. getValue(IDC_EDIT_MAX_LOST, maxLost, IDS_SERVER_E_MAXLOST_EMPTY);
  197. if (maxLost < 1)
  198. {
  199. fail(IDC_EDIT_MAX_LOST, IDS_SERVER_E_MAXLOST_RANGE);
  200. }
  201. getValue(IDC_EDIT_BLACKOUT, blackout, IDS_SERVER_E_BLACKOUT_EMPTY);
  202. if (blackout < timeout)
  203. {
  204. fail(IDC_EDIT_BLACKOUT, IDS_SERVER_E_BLACKOUT_RANGE);
  205. }
  206. }
  207. void ServerFTLBPage::setData()
  208. {
  209. setValue(IDC_EDIT_PRIORITY, priority);
  210. setValue(IDC_EDIT_WEIGHT, weight);
  211. setValue(IDC_EDIT_TIMEOUT, timeout);
  212. setValue(IDC_EDIT_MAX_LOST, maxLost);
  213. setValue(IDC_EDIT_BLACKOUT, blackout);
  214. }
  215. void ServerFTLBPage::saveChanges()
  216. {
  217. server.setValue(PROPERTY_RADIUSSERVER_PRIORITY, priority);
  218. server.setValue(PROPERTY_RADIUSSERVER_WEIGHT, weight);
  219. server.setValue(PROPERTY_RADIUSSERVER_TIMEOUT, timeout);
  220. server.setValue(PROPERTY_RADIUSSERVER_MAX_LOST, maxLost);
  221. server.setValue(PROPERTY_RADIUSSERVER_BLACKOUT, blackout);
  222. }
  223. BEGIN_MESSAGE_MAP(ServerFTLBPage, SnapInPropertyPage)
  224. ON_EN_CHANGE(IDC_EDIT_PRIORITY, onChange)
  225. ON_EN_CHANGE(IDC_EDIT_WEIGHT, onChange)
  226. ON_EN_CHANGE(IDC_EDIT_TIMEOUT, onChange)
  227. ON_EN_CHANGE(IDC_EDIT_MAX_LOST, onChange)
  228. ON_EN_CHANGE(IDC_EDIT_BLACKOUT, onChange)
  229. END_MESSAGE_MAP()
  230. ServerProperties::ServerProperties(Sdo& sdo, UINT nIDCaption, CWnd* parent)
  231. : CPropertySheet(nIDCaption, parent),
  232. server(sdo),
  233. serverStream(server),
  234. name(sdo),
  235. auth(sdo),
  236. ftlb(sdo)
  237. {
  238. // Add the property pages.
  239. AddPage(&name);
  240. AddPage(&auth);
  241. AddPage(&ftlb);
  242. }
  243. INT_PTR ServerProperties::DoModal()
  244. {
  245. CPropertySheet::DoModal();
  246. if (name.hasApplied() ||
  247. auth.hasApplied() ||
  248. ftlb.hasApplied())
  249. {
  250. return IDOK;
  251. }
  252. else
  253. {
  254. return IDCANCEL;
  255. }
  256. }
  257. BOOL ServerProperties::OnInitDialog()
  258. {
  259. // Unmarshal the SDOs.
  260. serverStream.get(server);
  261. BOOL bResult = CPropertySheet::OnInitDialog();
  262. ModifyStyleEx(0, WS_EX_CONTEXTHELP);
  263. return bResult;
  264. }