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.

382 lines
10 KiB

  1. // ChooseServerPages.cpp: implementation of the CChooseServerPages class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "certwiz.h"
  6. #include "Certificat.h"
  7. #include "ChooseServerPages.h"
  8. #include "certutil.h"
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[]=__FILE__;
  12. #define new DEBUG_NEW
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CChooseServerPages property page
  16. IMPLEMENT_DYNCREATE(CChooseServerPages, CIISWizardPage)
  17. CChooseServerPages::CChooseServerPages(CCertificate * pCert)
  18. : CIISWizardPage(CChooseServerPages::IDD, IDS_CERTWIZ, TRUE),
  19. m_pCert(pCert)
  20. {
  21. //{{AFX_DATA_INIT(CChooseServerPages)
  22. m_ServerName = _T("");
  23. m_UserName = _T("");
  24. m_UserPassword = _T("");
  25. //}}AFX_DATA_INIT
  26. }
  27. CChooseServerPages::~CChooseServerPages()
  28. {
  29. }
  30. void CChooseServerPages::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CIISWizardPage::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(CChooseServerPages)
  34. DDX_Text(pDX, IDC_SERVER_NAME, m_ServerName);
  35. DDX_Text(pDX, IDC_USER_NAME, m_UserName);
  36. DDX_Text_SecuredString(pDX, IDC_USER_PASSWORD, m_UserPassword);
  37. DDV_MaxChars(pDX, m_ServerName, 64);
  38. //}}AFX_DATA_MAP
  39. }
  40. LRESULT
  41. CChooseServerPages::OnWizardBack()
  42. /*++
  43. Routine Description:
  44. Prev button handler
  45. Arguments:
  46. None
  47. Return Value:
  48. 0 to automatically advance to the prev page;
  49. 1 to prevent the page from changing.
  50. To jump to a page other than the prev one,
  51. return the identifier of the dialog to be displayed.
  52. --*/
  53. {
  54. return IDD_PAGE_PREV;
  55. }
  56. LRESULT
  57. CChooseServerPages::OnWizardNext()
  58. {
  59. LRESULT lResult = 1;
  60. HRESULT hResult = 0;
  61. UpdateData(TRUE);
  62. CString UserPassword_Remote;
  63. if (0 != m_ServerName.Compare(m_pCert->m_MachineName_Remote))
  64. {
  65. m_pCert->m_MachineName_Remote = m_ServerName;
  66. }
  67. m_pCert->m_UserName_Remote = m_UserName;
  68. m_UserPassword.CopyTo(UserPassword_Remote);
  69. m_UserPassword.CopyTo(m_pCert->m_UserPassword_Remote);
  70. // See if we can actually connect to the specified
  71. // server with username/password combination...
  72. hResult = IsWebServerExistRemote(m_pCert->m_MachineName_Remote,m_pCert->m_UserName_Remote,UserPassword_Remote,m_pCert->m_WebSiteInstanceName);
  73. if (SUCCEEDED(hResult))
  74. {
  75. // check if the certobj is available on remote machine...
  76. hResult = IsCertObjExistRemote(m_pCert->m_MachineName_Remote,m_pCert->m_UserName_Remote,UserPassword_Remote);
  77. if (SUCCEEDED(hResult))
  78. {
  79. lResult = IDD_PAGE_NEXT;
  80. }
  81. else
  82. {
  83. // Tell the user somehow that
  84. // the object doesn't exist on the remote system
  85. IISDebugOutput(_T("The object doesn't exist on the specified machine,code=0x%x\n"),hResult);
  86. if (REGDB_E_CLASSNOTREG == hResult)
  87. {
  88. CString buf;
  89. buf.LoadString(IDS_CERTOBJ_NOT_IMPLEMENTED);
  90. AfxMessageBox(buf, MB_OK);
  91. }
  92. else
  93. {
  94. MsgboxPopup(hResult);
  95. }
  96. }
  97. }
  98. else
  99. {
  100. // Tell the user that the remote server
  101. // does not exist, or that they don't have access
  102. //IISDebugOutput(_T("Machine not reachable or bad credentials,code=0x%x\n"),hResult);
  103. MsgboxPopup(hResult);
  104. }
  105. return lResult;
  106. }
  107. BOOL
  108. CChooseServerPages::OnSetActive()
  109. {
  110. ASSERT(m_pCert != NULL);
  111. m_ServerName = m_pCert->m_MachineName_Remote;
  112. m_UserName = m_pCert->m_UserName_Remote;
  113. m_pCert->m_UserPassword_Remote.CopyTo(m_UserPassword);
  114. UpdateData(FALSE);
  115. SetWizardButtons(m_ServerName.IsEmpty() ?
  116. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  117. return CIISWizardPage::OnSetActive();
  118. }
  119. BOOL
  120. CChooseServerPages::OnKillActive()
  121. {
  122. UpdateData();
  123. m_pCert->m_MachineName_Remote = m_ServerName;
  124. m_pCert->m_UserName_Remote = m_UserName;
  125. m_UserPassword.CopyTo(m_pCert->m_UserPassword_Remote);
  126. return CIISWizardPage::OnKillActive();
  127. }
  128. BEGIN_MESSAGE_MAP(CChooseServerPages, CIISWizardPage)
  129. //{{AFX_MSG_MAP(CChooseServerPages)
  130. ON_EN_CHANGE(IDC_SERVER_NAME, OnEditchangeServerName)
  131. ON_EN_CHANGE(IDC_USER_NAME, OnEditchangeUserName)
  132. ON_EN_CHANGE(IDC_USER_PASSWORD, OnEditchangeUserPassword)
  133. ON_BN_CLICKED(IDC_BROWSE_BTN, OnBrowseForMachine)
  134. //}}AFX_MSG_MAP
  135. END_MESSAGE_MAP()
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CSiteNamePage message handlers
  138. void CChooseServerPages::OnEditchangeServerName()
  139. {
  140. UpdateData(TRUE);
  141. SetWizardButtons(m_ServerName.IsEmpty() ?
  142. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  143. CString str;
  144. SetDlgItemText(IDC_ERROR_TEXT, str);
  145. }
  146. void CChooseServerPages::OnEditchangeUserName()
  147. {
  148. UpdateData(TRUE);
  149. SetWizardButtons(m_ServerName.IsEmpty() ?
  150. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  151. CString str;
  152. SetDlgItemText(IDC_ERROR_TEXT, str);
  153. }
  154. void CChooseServerPages::OnEditchangeUserPassword()
  155. {
  156. UpdateData(TRUE);
  157. SetWizardButtons(m_ServerName.IsEmpty() ?
  158. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  159. CString str;
  160. SetDlgItemText(IDC_ERROR_TEXT, str);
  161. }
  162. void CChooseServerPages::OnBrowseForMachine()
  163. {
  164. CGetComputer picker;
  165. if (picker.GetComputer(m_hWnd))
  166. {
  167. SetDlgItemText(IDC_SERVER_NAME, picker.m_strComputerName);
  168. }
  169. return;
  170. }
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CChooseServerPages property page
  173. IMPLEMENT_DYNCREATE(CChooseServerPagesTo, CIISWizardPage)
  174. CChooseServerPagesTo::CChooseServerPagesTo(CCertificate * pCert)
  175. : CIISWizardPage(CChooseServerPagesTo::IDD, IDS_CERTWIZ, TRUE),
  176. m_pCert(pCert)
  177. {
  178. //{{AFX_DATA_INIT(CChooseServerPagesTo)
  179. m_ServerName = _T("");
  180. m_UserName = _T("");
  181. m_UserPassword = _T("");
  182. //}}AFX_DATA_INIT
  183. }
  184. CChooseServerPagesTo::~CChooseServerPagesTo()
  185. {
  186. }
  187. void CChooseServerPagesTo::DoDataExchange(CDataExchange* pDX)
  188. {
  189. CIISWizardPage::DoDataExchange(pDX);
  190. //{{AFX_DATA_MAP(CChooseServerPagesTo)
  191. DDX_Text(pDX, IDC_SERVER_NAME, m_ServerName);
  192. DDX_Text(pDX, IDC_USER_NAME, m_UserName);
  193. DDX_Text_SecuredString(pDX, IDC_USER_PASSWORD, m_UserPassword);
  194. DDV_MaxChars(pDX, m_ServerName, 64);
  195. //}}AFX_DATA_MAP
  196. }
  197. LRESULT
  198. CChooseServerPagesTo::OnWizardBack()
  199. /*++
  200. Routine Description:
  201. Prev button handler
  202. Arguments:
  203. None
  204. Return Value:
  205. 0 to automatically advance to the prev page;
  206. 1 to prevent the page from changing.
  207. To jump to a page other than the prev one,
  208. return the identifier of the dialog to be displayed.
  209. --*/
  210. {
  211. return IDD_PAGE_PREV;
  212. }
  213. LRESULT
  214. CChooseServerPagesTo::OnWizardNext()
  215. {
  216. LRESULT lResult = 1;
  217. HRESULT hResult = 0;
  218. UpdateData(TRUE);
  219. CString UserPassword_Remote;
  220. if (0 != m_ServerName.Compare(m_pCert->m_MachineName_Remote))
  221. {
  222. m_pCert->m_MachineName_Remote = m_ServerName;
  223. }
  224. m_pCert->m_UserName_Remote = m_UserName;
  225. m_UserPassword.CopyTo(UserPassword_Remote);
  226. m_UserPassword.CopyTo(m_pCert->m_UserPassword_Remote);
  227. // See if we can actually connect to the specified
  228. // server with username/password combination...
  229. hResult = IsWebServerExistRemote(m_pCert->m_MachineName_Remote,m_pCert->m_UserName_Remote,UserPassword_Remote,m_pCert->m_WebSiteInstanceName);
  230. if (SUCCEEDED(hResult))
  231. {
  232. // check if the certobj is available on remote machine...
  233. hResult = IsCertObjExistRemote(m_pCert->m_MachineName_Remote,m_pCert->m_UserName_Remote,UserPassword_Remote);
  234. if (SUCCEEDED(hResult))
  235. {
  236. lResult = IDD_PAGE_NEXT;
  237. }
  238. else
  239. {
  240. // Tell the user somehow that
  241. // the object doesn't exist on the remote system
  242. //IISDebugOutput(_T("The object doesn't exist on the specified machine,code=0x%x\n"),hResult);
  243. if (REGDB_E_CLASSNOTREG == hResult)
  244. {
  245. CString buf;
  246. buf.LoadString(IDS_CERTOBJ_NOT_IMPLEMENTED);
  247. AfxMessageBox(buf, MB_OK);
  248. }
  249. else
  250. {
  251. MsgboxPopup(hResult);
  252. }
  253. }
  254. }
  255. else
  256. {
  257. // Tell the user that the remote server
  258. // does not exist, or that they don't have access
  259. //IISDebugOutput(_T("Machine not reachable or bad credentials,code=0x%x\n"),hResult);
  260. MsgboxPopup(hResult);
  261. }
  262. return lResult;
  263. }
  264. BOOL
  265. CChooseServerPagesTo::OnSetActive()
  266. {
  267. ASSERT(m_pCert != NULL);
  268. m_ServerName = m_pCert->m_MachineName_Remote;
  269. m_UserName = m_pCert->m_UserName_Remote;
  270. m_pCert->m_UserPassword_Remote.CopyTo(m_UserPassword);
  271. UpdateData(FALSE);
  272. SetWizardButtons(m_ServerName.IsEmpty() ?
  273. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  274. return CIISWizardPage::OnSetActive();
  275. }
  276. BOOL
  277. CChooseServerPagesTo::OnKillActive()
  278. {
  279. UpdateData();
  280. m_pCert->m_MachineName_Remote = m_ServerName;
  281. m_pCert->m_UserName_Remote = m_UserName;
  282. m_UserPassword.CopyTo(m_pCert->m_UserPassword_Remote);
  283. return CIISWizardPage::OnKillActive();
  284. }
  285. BEGIN_MESSAGE_MAP(CChooseServerPagesTo, CIISWizardPage)
  286. //{{AFX_MSG_MAP(CChooseServerPagesTo)
  287. ON_EN_CHANGE(IDC_SERVER_NAME, OnEditchangeServerName)
  288. ON_EN_CHANGE(IDC_USER_NAME, OnEditchangeUserName)
  289. ON_EN_CHANGE(IDC_USER_PASSWORD, OnEditchangeUserPassword)
  290. ON_BN_CLICKED(IDC_BROWSE_BTN, OnBrowseForMachine)
  291. //}}AFX_MSG_MAP
  292. END_MESSAGE_MAP()
  293. /////////////////////////////////////////////////////////////////////////////
  294. // CSiteNamePage message handlers
  295. void CChooseServerPagesTo::OnEditchangeServerName()
  296. {
  297. UpdateData(TRUE);
  298. SetWizardButtons(m_ServerName.IsEmpty() ?
  299. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  300. CString str;
  301. SetDlgItemText(IDC_ERROR_TEXT, str);
  302. }
  303. void CChooseServerPagesTo::OnEditchangeUserName()
  304. {
  305. UpdateData(TRUE);
  306. SetWizardButtons(m_ServerName.IsEmpty() ?
  307. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  308. CString str;
  309. SetDlgItemText(IDC_ERROR_TEXT, str);
  310. }
  311. void CChooseServerPagesTo::OnEditchangeUserPassword()
  312. {
  313. UpdateData(TRUE);
  314. SetWizardButtons(m_ServerName.IsEmpty() ?
  315. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  316. CString str;
  317. SetDlgItemText(IDC_ERROR_TEXT, str);
  318. }
  319. void CChooseServerPagesTo::OnBrowseForMachine()
  320. {
  321. CGetComputer picker;
  322. if (picker.GetComputer(m_hWnd))
  323. {
  324. SetDlgItemText(IDC_SERVER_NAME, picker.m_strComputerName);
  325. }
  326. return;
  327. }