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.

435 lines
13 KiB

  1. // ChooseServerSitePages.cpp: implementation of the CChooseServerSitePages class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "certwiz.h"
  6. #include "Certificat.h"
  7. #include "Certutil.h"
  8. #include "ChooseServerSite.h"
  9. #include "ChooseServerSitePages.h"
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char THIS_FILE[]=__FILE__;
  13. #define new DEBUG_NEW
  14. #endif
  15. static BOOL
  16. AnswerIsYes3(UINT id)
  17. {
  18. CString strMessage;
  19. strMessage.LoadString(id);
  20. return (IDYES == AfxMessageBox(strMessage, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2));
  21. }
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CChooseServerSitePages property page
  24. IMPLEMENT_DYNCREATE(CChooseServerSitePages, CIISWizardPage)
  25. CChooseServerSitePages::CChooseServerSitePages(CCertificate * pCert)
  26. : CIISWizardPage(CChooseServerSitePages::IDD, IDS_CERTWIZ, TRUE),
  27. m_pCert(pCert)
  28. {
  29. //{{AFX_DATA_INIT(CChooseServerSitePages)
  30. m_ServerSiteInstance = 0;
  31. m_ServerSiteInstancePath = _T("");
  32. m_ServerSiteDescription = _T("");
  33. //}}AFX_DATA_INIT
  34. }
  35. CChooseServerSitePages::~CChooseServerSitePages()
  36. {
  37. }
  38. void CChooseServerSitePages::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CIISWizardPage::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CChooseServerSitePages)
  42. DDX_Text(pDX, IDC_SERVER_SITE_NAME, m_ServerSiteInstance);
  43. //}}AFX_DATA_MAP
  44. }
  45. LRESULT
  46. CChooseServerSitePages::OnWizardBack()
  47. /*++
  48. Routine Description:
  49. Prev button handler
  50. Arguments:
  51. None
  52. Return Value:
  53. 0 to automatically advance to the prev page;
  54. 1 to prevent the page from changing.
  55. To jump to a page other than the prev one,
  56. return the identifier of the dialog to be displayed.
  57. --*/
  58. {
  59. return IDD_PAGE_PREV;
  60. }
  61. LRESULT
  62. CChooseServerSitePages::OnWizardNext()
  63. {
  64. LRESULT lres = 1;
  65. BOOL bCertificateExists = FALSE;
  66. CString csInstanceName;
  67. CString UserPassword_Remote;
  68. m_ServerSiteInstance = -1;
  69. UpdateData(TRUE);
  70. m_pCert->m_UserPassword_Remote.CopyTo(UserPassword_Remote);
  71. if (m_ServerSiteInstance != -1)
  72. {
  73. // Get the site # and create an instance path
  74. csInstanceName = ReturnGoodMetabaseServerPath(m_pCert->m_WebSiteInstanceName);
  75. csInstanceName += _T("/%d");
  76. m_ServerSiteInstancePath.Format(csInstanceName,m_ServerSiteInstance);
  77. m_pCert->m_WebSiteInstanceName_Remote = m_ServerSiteInstancePath;
  78. // Check if this is a local to local copy that
  79. // we are not copy/moving to the same local site that we're on!
  80. if (TRUE == IsMachineLocal(m_pCert->m_MachineName_Remote, m_pCert->m_UserName_Remote, UserPassword_Remote))
  81. {
  82. CString SiteToExclude = m_pCert->m_WebSiteInstanceName;
  83. CString SiteToLookAt = m_ServerSiteInstancePath;
  84. // We are on the local machine!!!
  85. // make sure it's not the same web site
  86. // if it is then popup a msgbox!!!!!!
  87. if (SiteToLookAt.Left(1) == _T("/"))
  88. {
  89. if (SiteToExclude.Left(1) != _T("/"))
  90. {SiteToExclude = _T("/") + SiteToExclude;}
  91. }
  92. if (SiteToLookAt.Right(1) == _T("/"))
  93. {
  94. if (SiteToExclude.Right(1) != _T("/"))
  95. {SiteToExclude = SiteToExclude + _T("/");}
  96. }
  97. if (0 == _tcsicmp(SiteToLookAt,SiteToExclude))
  98. {
  99. // Cannot do this, popup messagebox
  100. AfxMessageBox(IDS_NOT_TO_ITSELF);
  101. lres = 1;
  102. goto CChooseServerSitePages_OnWizardNext_Exit;
  103. }
  104. }
  105. // Check if the specified path actually exists!!!!!!!
  106. if (FALSE == IsWebSiteExistRemote(m_pCert->m_MachineName_Remote, m_pCert->m_UserName_Remote, UserPassword_Remote, m_ServerSiteInstancePath, &bCertificateExists))
  107. {
  108. AfxMessageBox(IDS_SITE_NOT_EXIST);
  109. lres = 1;
  110. }
  111. else
  112. {
  113. // Check if Certificate Exist...
  114. if (!bCertificateExists)
  115. {
  116. AfxMessageBox(IDS_CERT_NOT_EXIST_ON_SITE);
  117. lres = 1;
  118. }
  119. else
  120. {
  121. if (m_pCert->m_DeleteAfterCopy)
  122. {
  123. lres = IDD_PAGE_NEXT2;
  124. }
  125. else
  126. {
  127. lres = IDD_PAGE_NEXT;
  128. }
  129. // Get info for that cert from remote site...
  130. CERT_DESCRIPTION desc;
  131. CString MachineName_Remote = m_pCert->m_MachineName_Remote;
  132. CString UserName_Remote = m_pCert->m_UserName_Remote;
  133. GetCertDescInfo(MachineName_Remote,UserName_Remote,UserPassword_Remote,m_ServerSiteInstancePath,&desc);
  134. m_pCert->m_CommonName = desc.m_CommonName;
  135. m_pCert->m_FriendlyName = desc.m_FriendlyName;
  136. m_pCert->m_Country = desc.m_Country;
  137. m_pCert->m_State = desc.m_State;
  138. m_pCert->m_Locality = desc.m_Locality;
  139. m_pCert->m_Organization = desc.m_Organization;
  140. m_pCert->m_OrganizationUnit = desc.m_OrganizationUnit;
  141. m_pCert->m_CAName = desc.m_CAName;
  142. m_pCert->m_ExpirationDate = desc.m_ExpirationDate;
  143. m_pCert->m_Usage = desc.m_Usage;
  144. }
  145. }
  146. }
  147. CChooseServerSitePages_OnWizardNext_Exit:
  148. return lres;
  149. }
  150. BOOL
  151. CChooseServerSitePages::OnSetActive()
  152. {
  153. ASSERT(m_pCert != NULL);
  154. m_ServerSiteInstancePath = m_pCert->m_WebSiteInstanceName_Remote;
  155. m_ServerSiteInstance = CMetabasePath::GetInstanceNumber(m_ServerSiteInstancePath);
  156. UpdateData(FALSE);
  157. SetWizardButtons(m_ServerSiteInstance <=0 ? PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  158. return CIISWizardPage::OnSetActive();
  159. }
  160. BOOL
  161. CChooseServerSitePages::OnKillActive()
  162. {
  163. //UpdateData();
  164. m_pCert->m_WebSiteInstanceName_Remote = m_ServerSiteInstancePath;
  165. return CIISWizardPage::OnKillActive();
  166. }
  167. BEGIN_MESSAGE_MAP(CChooseServerSitePages, CIISWizardPage)
  168. //{{AFX_MSG_MAP(CChooseServerSitePages)
  169. ON_EN_CHANGE(IDC_SERVER_SITE_NAME, OnEditchangeServerSiteName)
  170. ON_BN_CLICKED(IDC_BROWSE_BTN, OnBrowseForMachineWebSite)
  171. //}}AFX_MSG_MAP
  172. END_MESSAGE_MAP()
  173. /////////////////////////////////////////////////////////////////////////////
  174. // CSiteNamePage message handlers
  175. void CChooseServerSitePages::OnEditchangeServerSiteName()
  176. {
  177. UpdateData(TRUE);
  178. SetWizardButtons(m_ServerSiteInstance <=0 ?
  179. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  180. CString str;
  181. SetDlgItemText(IDC_ERROR_TEXT, str);
  182. }
  183. void CChooseServerSitePages::OnBrowseForMachineWebSite()
  184. {
  185. CString strWebSite;
  186. CChooseServerSite dlg(TRUE,strWebSite,m_pCert);
  187. if (dlg.DoModal() == IDOK)
  188. {
  189. // Get the one that they selected...
  190. strWebSite = dlg.m_strSiteReturned;
  191. m_ServerSiteInstancePath = strWebSite;
  192. m_ServerSiteInstance = CMetabasePath::GetInstanceNumber(m_ServerSiteInstancePath);
  193. CString Temp;
  194. Temp.Format(_T("%d"),m_ServerSiteInstance);
  195. SetDlgItemText(IDC_SERVER_SITE_NAME, Temp);
  196. }
  197. return;
  198. }
  199. /////////////////////////////////////////////////////////////////////////////
  200. // CChooseServerSitePages property page
  201. IMPLEMENT_DYNCREATE(CChooseServerSitePagesTo, CIISWizardPage)
  202. CChooseServerSitePagesTo::CChooseServerSitePagesTo(CCertificate * pCert)
  203. : CIISWizardPage(CChooseServerSitePagesTo::IDD, IDS_CERTWIZ, TRUE),
  204. m_pCert(pCert)
  205. {
  206. //{{AFX_DATA_INIT(CChooseServerSitePagesTo)
  207. m_ServerSiteInstance = 0;
  208. m_ServerSiteInstancePath = _T("");
  209. m_ServerSiteDescription = _T("");
  210. //}}AFX_DATA_INIT
  211. }
  212. CChooseServerSitePagesTo::~CChooseServerSitePagesTo()
  213. {
  214. }
  215. void CChooseServerSitePagesTo::DoDataExchange(CDataExchange* pDX)
  216. {
  217. CIISWizardPage::DoDataExchange(pDX);
  218. //{{AFX_DATA_MAP(CChooseServerSitePagesTo)
  219. DDX_Text(pDX, IDC_SERVER_SITE_NAME, m_ServerSiteInstance);
  220. //}}AFX_DATA_MAP
  221. }
  222. LRESULT
  223. CChooseServerSitePagesTo::OnWizardBack()
  224. /*++
  225. Routine Description:
  226. Prev button handler
  227. Arguments:
  228. None
  229. Return Value:
  230. 0 to automatically advance to the prev page;
  231. 1 to prevent the page from changing.
  232. To jump to a page other than the prev one,
  233. return the identifier of the dialog to be displayed.
  234. --*/
  235. {
  236. return IDD_PAGE_PREV;
  237. }
  238. LRESULT
  239. CChooseServerSitePagesTo::OnWizardNext()
  240. {
  241. LRESULT lres = 1;
  242. BOOL bCertificateExists = FALSE;
  243. CString csInstanceName;
  244. CString UserPassword_Remote;
  245. m_ServerSiteInstance = -1;
  246. UpdateData(TRUE);
  247. m_pCert->m_UserPassword_Remote.CopyTo(UserPassword_Remote);
  248. if (m_ServerSiteInstance != -1)
  249. {
  250. lres = IDD_PAGE_NEXT;
  251. // Get the site # and create an instance path
  252. csInstanceName = ReturnGoodMetabaseServerPath(m_pCert->m_WebSiteInstanceName);
  253. csInstanceName += _T("/%d");
  254. m_ServerSiteInstancePath.Format(csInstanceName,m_ServerSiteInstance);
  255. m_pCert->m_WebSiteInstanceName_Remote = m_ServerSiteInstancePath;
  256. // Check if this is a local to local copy that
  257. // we are not copy/moving to the same local site that we're on!
  258. if (TRUE == IsMachineLocal(m_pCert->m_MachineName_Remote, m_pCert->m_UserName_Remote, UserPassword_Remote))
  259. {
  260. CString SiteToExclude = m_pCert->m_WebSiteInstanceName;
  261. CString SiteToLookAt = m_ServerSiteInstancePath;
  262. // We are on the local machine!!!
  263. // make sure it's not the same web site
  264. // if it is then popup a msgbox!!!!!!
  265. if (SiteToLookAt.Left(1) == _T("/"))
  266. {
  267. if (SiteToExclude.Left(1) != _T("/"))
  268. {SiteToExclude = _T("/") + SiteToExclude;}
  269. }
  270. if (SiteToLookAt.Right(1) == _T("/"))
  271. {
  272. if (SiteToExclude.Right(1) != _T("/"))
  273. {SiteToExclude = SiteToExclude + _T("/");}
  274. }
  275. if (0 == _tcsicmp(SiteToLookAt,SiteToExclude))
  276. {
  277. // Cannot do this, popup messagebox
  278. AfxMessageBox(IDS_NOT_TO_ITSELF);
  279. lres = 1;
  280. goto CChooseServerSitePagesTo_OnWizardNext_Exit;
  281. }
  282. }
  283. // Check if the specified path actually exists!!!!!!!
  284. if (FALSE == IsWebSiteExistRemote(m_pCert->m_MachineName_Remote, m_pCert->m_UserName_Remote, UserPassword_Remote, m_ServerSiteInstancePath, &bCertificateExists))
  285. {
  286. AfxMessageBox(IDS_SITE_NOT_EXIST);
  287. lres = 1;
  288. }
  289. else
  290. {
  291. lres = 1;
  292. BOOL ProceedWithCopyMove = FALSE;
  293. // Check if Certificate Exist...
  294. if (bCertificateExists)
  295. {
  296. if (TRUE == AnswerIsYes3(IDS_CERT_EXISTS_OVERWRITE))
  297. {
  298. ProceedWithCopyMove = TRUE;
  299. }
  300. else
  301. {
  302. ProceedWithCopyMove = FALSE;
  303. }
  304. }
  305. else
  306. {
  307. ProceedWithCopyMove = TRUE;
  308. }
  309. if (TRUE == ProceedWithCopyMove)
  310. {
  311. if (m_pCert->m_DeleteAfterCopy)
  312. {
  313. lres = IDD_PAGE_NEXT2;
  314. }
  315. else
  316. {
  317. lres = IDD_PAGE_NEXT;
  318. }
  319. }
  320. }
  321. }
  322. CChooseServerSitePagesTo_OnWizardNext_Exit:
  323. return lres;
  324. }
  325. BOOL
  326. CChooseServerSitePagesTo::OnSetActive()
  327. {
  328. ASSERT(m_pCert != NULL);
  329. m_ServerSiteInstancePath = m_pCert->m_WebSiteInstanceName_Remote;
  330. m_ServerSiteInstance = CMetabasePath::GetInstanceNumber(m_ServerSiteInstancePath);
  331. UpdateData(FALSE);
  332. SetWizardButtons(m_ServerSiteInstance <=0 ? PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  333. return CIISWizardPage::OnSetActive();
  334. }
  335. BOOL
  336. CChooseServerSitePagesTo::OnKillActive()
  337. {
  338. //UpdateData();
  339. m_pCert->m_WebSiteInstanceName_Remote = m_ServerSiteInstancePath;
  340. return CIISWizardPage::OnKillActive();
  341. }
  342. BEGIN_MESSAGE_MAP(CChooseServerSitePagesTo, CIISWizardPage)
  343. //{{AFX_MSG_MAP(CChooseServerSitePagesTo)
  344. ON_EN_CHANGE(IDC_SERVER_SITE_NAME, OnEditchangeServerSiteName)
  345. ON_BN_CLICKED(IDC_BROWSE_BTN, OnBrowseForMachineWebSite)
  346. //}}AFX_MSG_MAP
  347. END_MESSAGE_MAP()
  348. /////////////////////////////////////////////////////////////////////////////
  349. // CSiteNamePage message handlers
  350. void CChooseServerSitePagesTo::OnEditchangeServerSiteName()
  351. {
  352. UpdateData(TRUE);
  353. SetWizardButtons(m_ServerSiteInstance <=0 ?
  354. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  355. CString str;
  356. SetDlgItemText(IDC_ERROR_TEXT, str);
  357. }
  358. void CChooseServerSitePagesTo::OnBrowseForMachineWebSite()
  359. {
  360. CString strWebSite;
  361. CChooseServerSite dlg(FALSE,strWebSite,m_pCert);
  362. if (dlg.DoModal() == IDOK)
  363. {
  364. // Get the one that they selected...
  365. strWebSite = dlg.m_strSiteReturned;
  366. m_ServerSiteInstancePath = strWebSite;
  367. m_ServerSiteInstance = CMetabasePath::GetInstanceNumber(m_ServerSiteInstancePath);
  368. CString Temp;
  369. Temp.Format(_T("%d"),m_ServerSiteInstance);
  370. SetDlgItemText(IDC_SERVER_SITE_NAME, Temp);
  371. }
  372. return;
  373. }