Leaked source code of windows server 2003
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.

228 lines
5.3 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: DomainPage.cpp
  4. //
  5. // Synopsis: Defines the DNS forwarder page used in the
  6. // Express path for the CYS Wizard
  7. //
  8. // History: 05/17/2001 JeffJon Created
  9. #include "pch.h"
  10. #include "resource.h"
  11. #include "InstallationUnitProvider.h"
  12. #include "DnsForwarderPage.h"
  13. static PCWSTR FORWARDER_PAGE_HELP = L"cys.chm::/typical_setup.htm#typicaldnsforwarder";
  14. DNSForwarderPage::DNSForwarderPage()
  15. :
  16. CYSWizardPage(
  17. IDD_DNS_FORWARDER_PAGE,
  18. IDS_DNS_FORWARDER_TITLE,
  19. IDS_DNS_FORWARDER_SUBTITLE,
  20. FORWARDER_PAGE_HELP)
  21. {
  22. LOG_CTOR(DNSForwarderPage);
  23. }
  24. DNSForwarderPage::~DNSForwarderPage()
  25. {
  26. LOG_DTOR(DNSForwarderPage);
  27. }
  28. void
  29. DNSForwarderPage::OnInit()
  30. {
  31. LOG_FUNCTION(DNSForwarderPage::OnInit);
  32. CYSWizardPage::OnInit();
  33. Win::SetDlgItemText(
  34. hwnd,
  35. IDC_TOO_LONG_STATIC,
  36. IDS_FORWARDER_STATIC_TEXT);
  37. // Set the Yes radio by default
  38. Win::Button_SetCheck(
  39. Win::GetDlgItem(hwnd, IDC_YES_RADIO),
  40. BST_CHECKED);
  41. Win::Button_SetCheck(
  42. Win::GetDlgItem(hwnd, IDC_NO_RADIO),
  43. BST_UNCHECKED);
  44. }
  45. void
  46. DNSForwarderPage::SetWizardButtons()
  47. {
  48. // LOG_FUNCTION(DNSForwarderPage::SetWizardButtons);
  49. // NTRAID#NTBUG9-461109-2001/08/28-sburns
  50. Win::PropSheet_SetWizButtons(
  51. Win::GetParent(hwnd),
  52. PSWIZB_NEXT | PSWIZB_BACK);
  53. // NTRAID#NTBUG9-503691-2001/12/06-JeffJon
  54. // The Next button should only be enabled if the user
  55. // chose the No radio button or they have entered
  56. // an IP and chose the Yes radio button
  57. bool yesChecked = Win::Button_GetCheck(
  58. Win::GetDlgItem(hwnd, IDC_YES_RADIO));
  59. if (yesChecked)
  60. {
  61. // Get the IP address from the control
  62. DWORD forwarder = 0;
  63. LRESULT forwarderResult = Win::SendMessage(
  64. Win::GetDlgItem(hwnd, IDC_FORWARDER_IPADDRESS),
  65. IPM_GETADDRESS,
  66. 0,
  67. (LPARAM)&forwarder);
  68. if (!forwarderResult || forwarder == 0)
  69. {
  70. // User hasn't entered an IP address so disable the Next button
  71. Win::PropSheet_SetWizButtons(
  72. Win::GetParent(hwnd),
  73. PSWIZB_BACK);
  74. }
  75. }
  76. }
  77. bool
  78. DNSForwarderPage::OnSetActive()
  79. {
  80. LOG_FUNCTION(DNSForwarderPage::OnSetActive);
  81. SetWizardButtons();
  82. return true;
  83. }
  84. bool
  85. DNSForwarderPage::OnNotify(
  86. HWND /*windowFrom*/,
  87. UINT_PTR controlIDFrom,
  88. UINT code,
  89. LPARAM /*lParam*/)
  90. {
  91. // LOG_FUNCTION(DNSForwarderPage::OnCommand);
  92. bool result = false;
  93. if (controlIDFrom == IDC_FORWARDER_IPADDRESS &&
  94. code == IPN_FIELDCHANGED)
  95. {
  96. SetWizardButtons();
  97. }
  98. return result;
  99. }
  100. bool
  101. DNSForwarderPage::OnCommand(
  102. HWND /* windowFrom */ ,
  103. unsigned controlIDFrom,
  104. unsigned code)
  105. {
  106. // LOG_FUNCTION(DNSForwarderPage::OnCommand);
  107. switch (controlIDFrom)
  108. {
  109. case IDC_YES_RADIO:
  110. if (code == BN_CLICKED)
  111. {
  112. Win::EnableWindow(
  113. Win::GetDlgItem(hwnd, IDC_FORWARDER_IPADDRESS),
  114. true);
  115. SetWizardButtons();
  116. }
  117. break;
  118. case IDC_NO_RADIO:
  119. if (code == BN_CLICKED)
  120. {
  121. Win::EnableWindow(
  122. Win::GetDlgItem(hwnd, IDC_FORWARDER_IPADDRESS),
  123. false);
  124. SetWizardButtons();
  125. }
  126. break;
  127. default:
  128. {
  129. // do nothing
  130. break;
  131. }
  132. }
  133. return false;
  134. }
  135. int
  136. DNSForwarderPage::Validate()
  137. {
  138. LOG_FUNCTION(DNSForwarderPage::Validate);
  139. int nextPage = IDD_MILESTONE_PAGE;
  140. if (Win::Button_GetCheck(
  141. Win::GetDlgItem(hwnd, IDC_YES_RADIO)))
  142. {
  143. // Get the IP address from the control
  144. LOG(L"User chose to forward queries");
  145. DWORD forwarder = 0;
  146. LRESULT forwarderResult = Win::SendMessage(
  147. Win::GetDlgItem(hwnd, IDC_FORWARDER_IPADDRESS),
  148. IPM_GETADDRESS,
  149. 0,
  150. (LPARAM)&forwarder);
  151. if (!forwarderResult || forwarder == 0)
  152. {
  153. LOG(L"User didn't enter IP address so we will gripe at them");
  154. String message = String::load(IDS_FORWARDER_IPADDRESS_REQUIRED);
  155. popup.Gripe(hwnd, IDC_FORWARDER_IPADDRESS, message);
  156. nextPage = -1;
  157. }
  158. else
  159. {
  160. DWORD networkOrderForwarder = ConvertIPAddressOrder(forwarder);
  161. LOG(String::format(
  162. L"Setting new forwarder: 0x%1!x!",
  163. networkOrderForwarder));
  164. InstallationUnitProvider::GetInstance().GetDNSInstallationUnit().SetForwarder(
  165. networkOrderForwarder);
  166. }
  167. }
  168. else
  169. {
  170. // Set an empty value so that we know it was set manually but they chose
  171. // not to forward
  172. LOG(L"User chose not to forward queries");
  173. InstallationUnitProvider::GetInstance().GetDNSInstallationUnit().SetForwarder(0);
  174. }
  175. return nextPage;
  176. }