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.

1786 lines
27 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. wizard.cpp
  5. Abstract:
  6. FTP Wizards pages
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. //
  14. // Include Files
  15. //
  16. #include "stdafx.h"
  17. #include "fscfg.h"
  18. #include "dirbrows.h"
  19. #include "wizard.h"
  20. #define DEF_PORT (21)
  21. #define MAX_ALIAS_NAME (240) // Ref Bug 241148
  22. CIISFtpWizSettings::CIISFtpWizSettings(
  23. IN HANDLE hServer,
  24. IN LPCTSTR lpszService,
  25. IN DWORD dwInstance, OPTIONAL
  26. IN LPCTSTR lpszParent OPTIONAL
  27. )
  28. /*++
  29. Routine Description:
  30. FTP Wizard Constructor
  31. Arguments:
  32. HANDLE hServer : Server handle
  33. LPCTSTR lpszService : Service name
  34. DWORD dwInstance : Instance number
  35. LPCTSTR lpszParent : Parent path
  36. Return Value:
  37. N/A
  38. --*/
  39. : m_hrResult(S_OK),
  40. m_pKey(NULL),
  41. m_fLocal(FALSE),
  42. m_fUNC(FALSE),
  43. m_fRead(FALSE),
  44. m_fWrite(FALSE),
  45. m_strServerName(),
  46. m_strService(),
  47. m_strParent(),
  48. m_dwInstance(dwInstance)
  49. {
  50. m_pKey = GetMetaKeyFromHandle(hServer);
  51. LPCTSTR lpszServer = GetServerNameFromHandle(hServer);
  52. ASSERT(lpszServer != NULL);
  53. m_strServerName = lpszServer;
  54. m_fLocal = IsServerLocal(m_strServerName);
  55. if (lpszService)
  56. {
  57. m_strService = lpszService;
  58. }
  59. if (lpszParent)
  60. {
  61. m_strParent = lpszParent;
  62. }
  63. }
  64. //
  65. // New Virtual Server Wizard Description Page
  66. //
  67. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  68. IMPLEMENT_DYNCREATE(CVDWPDescription, CIISWizardPage)
  69. CVDWPDescription::CVDWPDescription(
  70. IN OUT CIISFtpWizSettings * pwsSettings
  71. )
  72. /*++
  73. Routine Description:
  74. Constructor
  75. Arguments:
  76. CString & strServerName : Server name
  77. Return Value:
  78. None
  79. --*/
  80. : CIISWizardPage(
  81. CVDWPDescription::IDD, // Template
  82. IDS_NEW_SITE_WIZARD, // Caption
  83. HEADER_PAGE
  84. ),
  85. m_pwsSettings(pwsSettings)
  86. {
  87. #if 0 // Keep Class Wizard Happy
  88. //{{AFX_DATA_INIT(CVDWPDescription)
  89. m_strDescription = _T("");
  90. //}}AFX_DATA_INIT
  91. #endif // 0
  92. }
  93. CVDWPDescription::~CVDWPDescription()
  94. /*++
  95. Routine Description:
  96. Destructor
  97. Arguments:
  98. N/A
  99. Return Value:
  100. N/A
  101. --*/
  102. {
  103. }
  104. void
  105. CVDWPDescription::DoDataExchange(
  106. IN CDataExchange * pDX
  107. )
  108. /*++
  109. Routine Description:
  110. Initialise/Store control data
  111. Arguments:
  112. CDataExchange * pDX - DDX/DDV control structure
  113. Return Value:
  114. None
  115. --*/
  116. {
  117. CIISWizardPage::DoDataExchange(pDX);
  118. //{{AFX_DATA_MAP(CVDWPDescription)
  119. DDX_Control(pDX, IDC_EDIT_DESCRIPTION, m_edit_Description);
  120. //}}AFX_DATA_MAP
  121. }
  122. void
  123. CVDWPDescription::SetControlStates()
  124. /*++
  125. Routine Description:
  126. Set the state of the control data
  127. Arguments:
  128. None
  129. Return Value:
  130. None
  131. --*/
  132. {
  133. DWORD dwFlags = PSWIZB_BACK;
  134. if (m_edit_Description.GetWindowTextLength() > 0)
  135. {
  136. dwFlags |= PSWIZB_NEXT;
  137. }
  138. SetWizardButtons(dwFlags);
  139. }
  140. LRESULT
  141. CVDWPDescription::OnWizardNext()
  142. /*++
  143. Routine Description:
  144. 'next' handler. This is where validation is done,
  145. because DoDataExchange() gets called every time
  146. the dialog is exited, and this is not valid for
  147. wizards
  148. Arguments:
  149. None
  150. Return Value:
  151. 0 to proceed, -1 to fail
  152. --*/
  153. {
  154. if (!ValidateString(
  155. m_edit_Description,
  156. m_pwsSettings->m_strDescription,
  157. 1,
  158. MAX_PATH
  159. ))
  160. {
  161. return -1;
  162. }
  163. return CIISWizardPage::OnWizardNext();
  164. }
  165. //
  166. // Message Map
  167. //
  168. BEGIN_MESSAGE_MAP(CVDWPDescription, CIISWizardPage)
  169. //{{AFX_MSG_MAP(CVDWPDescription)
  170. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnChangeEditDescription)
  171. //}}AFX_MSG_MAP
  172. END_MESSAGE_MAP()
  173. //
  174. // Message Handlers
  175. //
  176. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  177. BOOL
  178. CVDWPDescription::OnSetActive()
  179. /*++
  180. Routine Description:
  181. Activation handler
  182. Arguments:
  183. None
  184. Return Value:
  185. TRUE for success, FALSE for failure
  186. --*/
  187. {
  188. SetControlStates();
  189. return CIISWizardPage::OnSetActive();
  190. }
  191. void
  192. CVDWPDescription::OnChangeEditDescription()
  193. /*++
  194. Routine Description:
  195. 'edit change' handler
  196. Arguments:
  197. None
  198. Return Value:
  199. None
  200. --*/
  201. {
  202. SetControlStates();
  203. }
  204. //
  205. // New Virtual Server Wizard Bindings Page
  206. //
  207. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  208. IMPLEMENT_DYNCREATE(CVDWPBindings, CIISWizardPage)
  209. CVDWPBindings::CVDWPBindings(
  210. IN OUT CIISFtpWizSettings * pwsSettings
  211. )
  212. /*++
  213. Routine Description:
  214. Constructor
  215. Arguments:
  216. CString & strServerName : Server name
  217. Return Value:
  218. None
  219. --*/
  220. : CIISWizardPage(
  221. CVDWPBindings::IDD, // Template
  222. IDS_NEW_SITE_WIZARD, // Page Caption
  223. HEADER_PAGE // Header page
  224. ),
  225. m_pwsSettings(pwsSettings),
  226. m_iaIpAddress(),
  227. m_oblIpAddresses()
  228. {
  229. //{{AFX_DATA_INIT(CVDWPBindings)
  230. m_nTCPPort = DEF_PORT;
  231. m_nIpAddressSel = -1;
  232. //}}AFX_DATA_INIT
  233. }
  234. CVDWPBindings::~CVDWPBindings()
  235. /*++
  236. Routine Description:
  237. Destructor
  238. Arguments:
  239. N/A
  240. Return Value:
  241. N/A
  242. --*/
  243. {
  244. }
  245. void
  246. CVDWPBindings::DoDataExchange(
  247. IN CDataExchange * pDX
  248. )
  249. /*++
  250. Routine Description:
  251. Initialise/Store control data
  252. Arguments:
  253. CDataExchange * pDX - DDX/DDV control structure
  254. Return Value:
  255. None
  256. --*/
  257. {
  258. CIISWizardPage::DoDataExchange(pDX);
  259. //{{AFX_DATA_MAP(CVDWPBindings)
  260. DDX_Control(pDX, IDC_COMBO_IP_ADDRESSES, m_combo_IpAddresses);
  261. DDX_Text(pDX, IDC_EDIT_TCP_PORT, m_nTCPPort);
  262. DDV_MinMaxUInt(pDX, m_nTCPPort, 1, 65535);
  263. //}}AFX_DATA_MAP
  264. DDX_CBIndex(pDX, IDC_COMBO_IP_ADDRESSES, m_nIpAddressSel);
  265. if (pDX->m_bSaveAndValidate)
  266. {
  267. if (!FetchIpAddressFromCombo(
  268. m_combo_IpAddresses,
  269. m_oblIpAddresses,
  270. m_iaIpAddress
  271. ))
  272. {
  273. pDX->Fail();
  274. }
  275. CString strDomain;
  276. CInstanceProps::BuildBinding(
  277. m_pwsSettings->m_strBinding,
  278. m_iaIpAddress,
  279. m_nTCPPort,
  280. strDomain
  281. );
  282. }
  283. }
  284. void
  285. CVDWPBindings::SetControlStates()
  286. /*++
  287. Routine Description:
  288. Set the state of the control data
  289. Arguments:
  290. None
  291. Return Value:
  292. None
  293. --*/
  294. {
  295. SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
  296. }
  297. //
  298. // Message Map
  299. //
  300. BEGIN_MESSAGE_MAP(CVDWPBindings, CIISWizardPage)
  301. //{{AFX_MSG_MAP(CVDWPBindings)
  302. //}}AFX_MSG_MAP
  303. END_MESSAGE_MAP()
  304. //
  305. // Message Handlers
  306. //
  307. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  308. BOOL
  309. CVDWPBindings::OnInitDialog()
  310. /*++
  311. Routine Description:
  312. WM_INITDIALOG handler. Initialize the dialog.
  313. Arguments:
  314. None.
  315. Return Value:
  316. TRUE if no focus is to be set automatically, FALSE if the focus
  317. is already set.
  318. --*/
  319. {
  320. CIISWizardPage::OnInitDialog();
  321. BeginWaitCursor();
  322. PopulateComboWithKnownIpAddresses(
  323. m_pwsSettings->m_strServerName,
  324. m_combo_IpAddresses,
  325. m_iaIpAddress,
  326. m_oblIpAddresses,
  327. m_nIpAddressSel
  328. );
  329. EndWaitCursor();
  330. return TRUE;
  331. }
  332. BOOL
  333. CVDWPBindings::OnSetActive()
  334. /*++
  335. Routine Description:
  336. Activation handler
  337. Arguments:
  338. None
  339. Return Value:
  340. TRUE for success, FALSE for failure
  341. --*/
  342. {
  343. SetControlStates();
  344. return CIISWizardPage::OnSetActive();
  345. }
  346. //
  347. // New Virtual Directory Wizard Alias Page
  348. //
  349. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  350. IMPLEMENT_DYNCREATE(CVDWPAlias, CIISWizardPage)
  351. CVDWPAlias::CVDWPAlias(
  352. IN OUT CIISFtpWizSettings * pwsSettings
  353. )
  354. /*++
  355. Routine Description:
  356. Constructor
  357. Arguments:
  358. CString & strServerName : Server name
  359. Return Value:
  360. None
  361. --*/
  362. : CIISWizardPage(
  363. CVDWPAlias::IDD, // Template
  364. IDS_NEW_VDIR_WIZARD, // Caption
  365. HEADER_PAGE
  366. ),
  367. m_pwsSettings(pwsSettings)
  368. //m_strAlias()
  369. {
  370. #if 0 // Keep Class Wizard Happy
  371. //{{AFX_DATA_INIT(CVDWPAlias)
  372. m_strAlias = _T("");
  373. //}}AFX_DATA_INIT
  374. #endif // 0
  375. }
  376. CVDWPAlias::~CVDWPAlias()
  377. /*++
  378. Routine Description:
  379. Destructor
  380. Arguments:
  381. N/A
  382. Return Value:
  383. N/A
  384. --*/
  385. {
  386. }
  387. void
  388. CVDWPAlias::DoDataExchange(
  389. IN CDataExchange * pDX
  390. )
  391. /*++
  392. Routine Description:
  393. Initialise/Store control data
  394. Arguments:
  395. CDataExchange * pDX - DDX/DDV control structure
  396. Return Value:
  397. None
  398. --*/
  399. {
  400. CIISWizardPage::DoDataExchange(pDX);
  401. //{{AFX_DATA_MAP(CVDWPAlias)
  402. DDX_Control(pDX, IDC_EDIT_ALIAS, m_edit_Alias);
  403. //}}AFX_DATA_MAP
  404. }
  405. LRESULT
  406. CVDWPAlias::OnWizardNext()
  407. /*++
  408. Routine Description:
  409. prevent the / and \ characters from being in the alias name
  410. Arguments:
  411. None
  412. Return Value:
  413. None
  414. --*/
  415. {
  416. if (!ValidateString(
  417. m_edit_Alias,
  418. m_pwsSettings->m_strAlias,
  419. 1,
  420. MAX_ALIAS_NAME
  421. ))
  422. {
  423. return -1;
  424. }
  425. //
  426. // Find the illegal characters. If they exist tell
  427. // the user and don't go on.
  428. //
  429. if (m_pwsSettings->m_strAlias.FindOneOf(_T("/\\?*")) >= 0)
  430. {
  431. AfxMessageBox(IDS_ILLEGAL_ALIAS_CHARS);
  432. m_edit_Alias.SetFocus();
  433. m_edit_Alias.SetSel(0, -1);
  434. //
  435. // prevent the wizard page from changing
  436. //
  437. return -1;
  438. }
  439. //
  440. // Allow the wizard to continue
  441. //
  442. return CIISWizardPage::OnWizardNext();
  443. }
  444. void
  445. CVDWPAlias::SetControlStates()
  446. /*++
  447. Routine Description:
  448. Set the state of the control data
  449. Arguments:
  450. None
  451. Return Value:
  452. None
  453. --*/
  454. {
  455. DWORD dwFlags = PSWIZB_BACK;
  456. if (m_edit_Alias.GetWindowTextLength() > 0)
  457. {
  458. dwFlags |= PSWIZB_NEXT;
  459. }
  460. SetWizardButtons(dwFlags);
  461. }
  462. //
  463. // Message Map
  464. //
  465. BEGIN_MESSAGE_MAP(CVDWPAlias, CIISWizardPage)
  466. //{{AFX_MSG_MAP(CVDWPAlias)
  467. ON_EN_CHANGE(IDC_EDIT_ALIAS, OnChangeEditAlias)
  468. //}}AFX_MSG_MAP
  469. END_MESSAGE_MAP()
  470. //
  471. // Message Handlers
  472. //
  473. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  474. BOOL
  475. CVDWPAlias::OnSetActive()
  476. /*++
  477. Routine Description:
  478. Activation handler
  479. Arguments:
  480. None
  481. Return Value:
  482. TRUE for success, FALSE for failure
  483. --*/
  484. {
  485. SetControlStates();
  486. return CIISWizardPage::OnSetActive();
  487. }
  488. void
  489. CVDWPAlias::OnChangeEditAlias()
  490. /*++
  491. Routine Description:
  492. 'edit change' handler
  493. Arguments:
  494. None
  495. Return Value:
  496. None
  497. --*/
  498. {
  499. SetControlStates();
  500. }
  501. //
  502. // Wizard Path Page
  503. //
  504. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  505. IMPLEMENT_DYNCREATE(CVDWPPath, CIISWizardPage)
  506. CVDWPPath::CVDWPPath(
  507. IN OUT CIISFtpWizSettings * pwsSettings,
  508. IN BOOL bVDir
  509. )
  510. /*++
  511. Routine Description:
  512. Constructor
  513. Arguments:
  514. CString & strServerName : Server name
  515. BOOL bVDir : TRUE if this is for a vdir,
  516. FALSE if this is an instance
  517. Return Value:
  518. None
  519. --*/
  520. : CIISWizardPage(
  521. (bVDir ? IDD_NEW_DIR_PATH : IDD_NEW_INST_HOME), // Template
  522. (bVDir ? IDS_NEW_VDIR_WIZARD : IDS_NEW_SITE_WIZARD), // Caption
  523. HEADER_PAGE // Header page
  524. ),
  525. m_pwsSettings(pwsSettings)
  526. {
  527. #if 0 // Keep ClassWizard happy
  528. //{{AFX_DATA_INIT(CVDWPPath)
  529. m_strPath = _T("");
  530. //}}AFX_DATA_INIT
  531. #endif // 0
  532. }
  533. CVDWPPath::~CVDWPPath()
  534. /*++
  535. Routine Description:
  536. Destructor
  537. Arguments:
  538. N/A
  539. Return Value:
  540. N/A
  541. --*/
  542. {
  543. }
  544. void
  545. CVDWPPath::DoDataExchange(
  546. IN CDataExchange * pDX
  547. )
  548. /*++
  549. Routine Description:
  550. Initialise/Store control data
  551. Arguments:
  552. CDataExchange * pDX - DDX/DDV control structure
  553. Return Value:
  554. None
  555. --*/
  556. {
  557. CIISWizardPage::DoDataExchange(pDX);
  558. //{{AFX_DATA_MAP(CVDWPPath)
  559. DDX_Control(pDX, IDC_BUTTON_BROWSE, m_button_Browse);
  560. DDX_Control(pDX, IDC_EDIT_PATH, m_edit_Path);
  561. //}}AFX_DATA_MAP
  562. DDX_Text(pDX, IDC_EDIT_PATH, m_pwsSettings->m_strPath);
  563. DDV_MaxChars(pDX, m_pwsSettings->m_strPath, MAX_PATH);
  564. }
  565. void
  566. CVDWPPath::SetControlStates()
  567. /*++
  568. Routine Description:
  569. Set the state of the control data
  570. Arguments:
  571. None
  572. Return Value:
  573. None
  574. --*/
  575. {
  576. DWORD dwFlags = PSWIZB_BACK;
  577. if (m_edit_Path.GetWindowTextLength() > 0)
  578. {
  579. dwFlags |= PSWIZB_NEXT;
  580. }
  581. SetWizardButtons(dwFlags);
  582. }
  583. //
  584. // Message Map
  585. //
  586. BEGIN_MESSAGE_MAP(CVDWPPath, CIISWizardPage)
  587. //{{AFX_MSG_MAP(CVDWPPath)
  588. ON_EN_CHANGE(IDC_EDIT_PATH, OnChangeEditPath)
  589. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  590. //}}AFX_MSG_MAP
  591. END_MESSAGE_MAP()
  592. //
  593. // Message Handlers
  594. //
  595. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  596. BOOL
  597. CVDWPPath::OnSetActive()
  598. /*++
  599. Routine Description:
  600. Activation handler
  601. Arguments:
  602. None
  603. Return Value:
  604. TRUE for success, FALSE for failure
  605. --*/
  606. {
  607. SetControlStates();
  608. return CIISWizardPage::OnSetActive();
  609. }
  610. LRESULT
  611. CVDWPPath::OnWizardNext()
  612. /*++
  613. Routine Description:
  614. 'next' handler. This is where validation is done,
  615. because DoDataExchange() gets called every time
  616. the dialog is exited, and this is not valid for
  617. wizards
  618. Arguments:
  619. None
  620. Return Value:
  621. 0 to proceed, -1 to fail
  622. --*/
  623. {
  624. if (!ValidateString(m_edit_Path, m_pwsSettings->m_strPath, 1, MAX_PATH))
  625. {
  626. return -1;
  627. }
  628. m_pwsSettings->m_fUNC = IsUNCName(m_pwsSettings->m_strPath);
  629. if (!m_pwsSettings->m_fUNC)
  630. {
  631. if (!IsFullyQualifiedPath(m_pwsSettings->m_strPath)
  632. && !IsDevicePath(m_pwsSettings->m_strPath)
  633. )
  634. {
  635. m_edit_Path.SetSel(0,-1);
  636. m_edit_Path.SetFocus();
  637. ::AfxMessageBox(IDS_ERR_BAD_PATH);
  638. return -1;
  639. }
  640. if (m_pwsSettings->m_fLocal)
  641. {
  642. DWORD dwAttr = GetFileAttributes(m_pwsSettings->m_strPath);
  643. if (dwAttr == 0xffffffff ||
  644. (dwAttr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  645. {
  646. m_edit_Path.SetSel(0,-1);
  647. m_edit_Path.SetFocus();
  648. ::AfxMessageBox(IDS_ERR_PATH_NOT_FOUND);
  649. return -1;
  650. }
  651. }
  652. }
  653. return CIISWizardPage::OnWizardNext();
  654. }
  655. void
  656. CVDWPPath::OnChangeEditPath()
  657. /*++
  658. Routine Description:
  659. 'edit change' handler
  660. Arguments:
  661. None
  662. Return Value:
  663. None
  664. --*/
  665. {
  666. SetControlStates();
  667. }
  668. void
  669. CVDWPPath::OnButtonBrowse()
  670. /*++
  671. Routine Description:
  672. Handle 'browsing' for directory path -- local system only
  673. Arguments:
  674. None
  675. Return Value:
  676. None
  677. --*/
  678. {
  679. ASSERT(m_pwsSettings->m_fLocal);
  680. CString str;
  681. m_edit_Path.GetWindowText(str);
  682. CDirBrowseDlg dlgBrowse(this, str);
  683. if (dlgBrowse.DoModal() == IDOK)
  684. {
  685. m_edit_Path.SetWindowText(
  686. dlgBrowse.GetFullPath(m_pwsSettings->m_strPath)
  687. );
  688. SetControlStates();
  689. }
  690. }
  691. BOOL
  692. CVDWPPath::OnInitDialog()
  693. /*++
  694. Routine Description:
  695. WM_INITDIALOG handler. Initialize the dialog.
  696. Arguments:
  697. None.
  698. Return Value:
  699. TRUE if no focus is to be set automatically, FALSE if the focus
  700. is already set.
  701. --*/
  702. {
  703. CIISWizardPage::OnInitDialog();
  704. m_button_Browse.EnableWindow(m_pwsSettings->m_fLocal);
  705. return TRUE;
  706. }
  707. //
  708. // Wizard User/Password Page
  709. //
  710. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  711. IMPLEMENT_DYNCREATE(CVDWPUserName, CIISWizardPage)
  712. CVDWPUserName::CVDWPUserName(
  713. IN OUT CIISFtpWizSettings * pwsSettings,
  714. IN BOOL bVDir
  715. )
  716. /*++
  717. Routine Description:
  718. Constructor
  719. Arguments:
  720. CString & strServerName : Server name
  721. BOOL bVDir : TRUE if this is for a vdir,
  722. FALSE if this is an instance
  723. Return Value:
  724. None
  725. --*/
  726. : CIISWizardPage(
  727. CVDWPUserName::IDD, // Templ.
  728. (bVDir ? IDS_NEW_VDIR_WIZARD : IDS_NEW_SITE_WIZARD), // Caption
  729. HEADER_PAGE, // Header
  730. (bVDir ? USE_DEFAULT_CAPTION : IDS_SITE_SECURITY_TITLE), // Title
  731. (bVDir ? USE_DEFAULT_CAPTION : IDS_SITE_SECURITY_SUBTITLE) // Subtitle
  732. ),
  733. m_pwsSettings(pwsSettings)
  734. {
  735. #if 0 // Keep Class Wizard Happy
  736. //{{AFX_DATA_INIT(CVDWPUserName)
  737. //}}AFX_DATA_INIT
  738. #endif // 0
  739. }
  740. CVDWPUserName::~CVDWPUserName()
  741. /*++
  742. Routine Description:
  743. Destructor
  744. Arguments:
  745. N/A
  746. Return Value:
  747. N/A
  748. --*/
  749. {
  750. }
  751. void
  752. CVDWPUserName::DoDataExchange(
  753. IN CDataExchange * pDX
  754. )
  755. /*++
  756. Routine Description:
  757. Initialise/Store control data
  758. Arguments:
  759. CDataExchange * pDX - DDX/DDV control structure
  760. Return Value:
  761. None
  762. --*/
  763. {
  764. CIISWizardPage::DoDataExchange(pDX);
  765. //{{AFX_DATA_MAP(CVDWPUserName)
  766. DDX_Control(pDX, IDC_EDIT_USERNAME, m_edit_UserName);
  767. DDX_Control(pDX, IDC_EDIT_PASSWORD, m_edit_Password);
  768. //}}AFX_DATA_MAP
  769. //
  770. // Private DDX/DDV Routines
  771. //
  772. DDX_Text(pDX, IDC_EDIT_USERNAME, m_pwsSettings->m_strUserName);
  773. DDV_MaxChars(pDX, m_pwsSettings->m_strUserName, UNLEN);
  774. //
  775. // Some people have a tendency to add "\\" before
  776. // the computer name in user accounts. Fix this here.
  777. //
  778. m_pwsSettings->m_strUserName.TrimLeft();
  779. while (*m_pwsSettings->m_strUserName == '\\')
  780. {
  781. m_pwsSettings->m_strUserName = m_pwsSettings->m_strUserName.Mid(2);
  782. }
  783. DDX_Password(pDX, IDC_EDIT_PASSWORD, m_pwsSettings->m_strPassword, g_lpszDummyPassword);
  784. DDV_MaxChars(pDX, m_pwsSettings->m_strPassword, PWLEN);
  785. }
  786. void
  787. CVDWPUserName::SetControlStates()
  788. /*++
  789. Routine Description:
  790. Set the state of the control data
  791. Arguments:
  792. None
  793. Return Value:
  794. None
  795. --*/
  796. {
  797. DWORD dwFlags = PSWIZB_BACK;
  798. if (m_edit_UserName.GetWindowTextLength() > 0)
  799. {
  800. dwFlags |= PSWIZB_NEXT;
  801. }
  802. SetWizardButtons(dwFlags);
  803. }
  804. //
  805. // Message Map
  806. //
  807. BEGIN_MESSAGE_MAP(CVDWPUserName, CIISWizardPage)
  808. //{{AFX_MSG_MAP(CVDWPUserName)
  809. ON_BN_CLICKED(IDC_BUTTON_BROWSE_USERS, OnButtonBrowseUsers)
  810. ON_EN_CHANGE(IDC_EDIT_USERNAME, OnChangeEditUsername)
  811. ON_BN_CLICKED(IDC_BUTTON_CHECK_PASSWORD, OnButtonCheckPassword)
  812. //}}AFX_MSG_MAP
  813. END_MESSAGE_MAP()
  814. //
  815. // Message Handlers
  816. //
  817. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  818. BOOL
  819. CVDWPUserName::OnSetActive()
  820. /*++
  821. Routine Description:
  822. Activation handler
  823. Arguments:
  824. None
  825. Return Value:
  826. TRUE for success, FALSE for failure
  827. --*/
  828. {
  829. if (!m_pwsSettings->m_fUNC)
  830. {
  831. return 0;
  832. }
  833. SetControlStates();
  834. return CIISWizardPage::OnSetActive();
  835. }
  836. BOOL
  837. CVDWPUserName::OnInitDialog()
  838. /*++
  839. Routine Description:
  840. WM_INITDIALOG handler. Initialize the dialog.
  841. Arguments:
  842. None.
  843. Return Value:
  844. TRUE if no focus is to be set automatically, FALSE if the focus
  845. is already set.
  846. --*/
  847. {
  848. CIISWizardPage::OnInitDialog();
  849. return TRUE;
  850. }
  851. LRESULT
  852. CVDWPUserName::OnWizardNext()
  853. /*++
  854. Routine Description:
  855. 'next' handler. This is where validation is done,
  856. because DoDataExchange() gets called every time
  857. the dialog is exited, and this is not valid for
  858. wizards
  859. Arguments:
  860. None
  861. Return Value:
  862. 0 to proceed, -1 to fail
  863. --*/
  864. {
  865. if (!ValidateString(
  866. m_edit_UserName,
  867. m_pwsSettings->m_strUserName,
  868. 1,
  869. UNLEN
  870. ))
  871. {
  872. return -1;
  873. }
  874. return CIISWizardPage::OnWizardNext();
  875. }
  876. void
  877. CVDWPUserName::OnButtonBrowseUsers()
  878. /*++
  879. Routine Description:
  880. 'browse' for users handler
  881. Arguments:
  882. None
  883. Return Value:
  884. None
  885. --*/
  886. {
  887. CString str;
  888. if (GetIUsrAccount(m_pwsSettings->m_strServerName, this, str))
  889. {
  890. //
  891. // If a name was selected, blank
  892. // out the password
  893. //
  894. m_edit_UserName.SetWindowText(str);
  895. m_edit_Password.SetFocus();
  896. }
  897. }
  898. void
  899. CVDWPUserName::OnChangeEditUsername()
  900. /*++
  901. Routine Description:
  902. 'edit change' in user name notification handler
  903. Arguments:
  904. None
  905. Return Value:
  906. None
  907. --*/
  908. {
  909. m_edit_Password.SetWindowText(_T(""));
  910. SetControlStates();
  911. }
  912. void
  913. CVDWPUserName::OnButtonCheckPassword()
  914. /*++
  915. Routine Description:
  916. 'Check Password' has been pressed. Try to validate
  917. the password that has been entered
  918. Arguments:
  919. None
  920. Return Value:
  921. None
  922. --*/
  923. {
  924. if (!UpdateData(TRUE))
  925. {
  926. return;
  927. }
  928. CError err(VerifyUserPassword(
  929. m_pwsSettings->m_strUserName,
  930. m_pwsSettings->m_strPassword
  931. ));
  932. if (!err.MessageBoxOnFailure())
  933. {
  934. ::AfxMessageBox(IDS_PASSWORD_OK);
  935. }
  936. }
  937. //
  938. // Wizard Permissions Page
  939. //
  940. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  941. IMPLEMENT_DYNCREATE(CVDWPPermissions, CIISWizardPage)
  942. CVDWPPermissions::CVDWPPermissions(
  943. IN OUT CIISFtpWizSettings * pwsSettings,
  944. IN BOOL bVDir
  945. )
  946. /*++
  947. Routine Description:
  948. Constructor
  949. Arguments:
  950. CString & strServerName : Server name
  951. BOOL bVDir : TRUE if this is a vdir page,
  952. FALSE if this is an instance page
  953. Return Value:
  954. None
  955. --*/
  956. : CIISWizardPage(
  957. IDD_NEW_PERMS, // Templ.
  958. (bVDir ? IDS_NEW_VDIR_WIZARD : IDS_NEW_SITE_WIZARD), // Caption
  959. HEADER_PAGE, // Header
  960. (bVDir ? USE_DEFAULT_CAPTION : IDS_SITE_PERMS_TITLE), // Title
  961. (bVDir ? USE_DEFAULT_CAPTION : IDS_SITE_PERMS_SUBTITLE) // Subtitle
  962. ),
  963. m_bVDir(bVDir),
  964. m_pwsSettings(pwsSettings)
  965. {
  966. //{{AFX_DATA_INIT(CVDWPPermissions)
  967. //}}AFX_DATA_INIT
  968. m_pwsSettings->m_fRead = TRUE;
  969. m_pwsSettings->m_fWrite = FALSE;
  970. }
  971. CVDWPPermissions::~CVDWPPermissions()
  972. /*++
  973. Routine Description:
  974. Destructor
  975. Arguments:
  976. None
  977. Return Value:
  978. None
  979. --*/
  980. {
  981. }
  982. void
  983. CVDWPPermissions::DoDataExchange(
  984. IN CDataExchange * pDX
  985. )
  986. /*++
  987. Routine Description:
  988. Initialise/Store control data
  989. Arguments:
  990. CDataExchange * pDX - DDX/DDV control structure
  991. Return Value:
  992. None
  993. --*/
  994. {
  995. CIISWizardPage::DoDataExchange(pDX);
  996. //{{AFX_DATA_MAP(CVDWPPermissions)
  997. //}}AFX_DATA_MAP
  998. DDX_Check(pDX, IDC_CHECK_READ, m_pwsSettings->m_fRead);
  999. DDX_Check(pDX, IDC_CHECK_WRITE, m_pwsSettings->m_fWrite);
  1000. }
  1001. void
  1002. CVDWPPermissions::SetControlStates()
  1003. /*++
  1004. Routine Description:
  1005. Set the state of the control data
  1006. Arguments:
  1007. None
  1008. Return Value:
  1009. None
  1010. --*/
  1011. {
  1012. SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
  1013. }
  1014. //
  1015. // Message Map
  1016. //
  1017. BEGIN_MESSAGE_MAP(CVDWPPermissions, CIISWizardPage)
  1018. //{{AFX_MSG_MAP(CVDWPPermissions)
  1019. //}}AFX_MSG_MAP
  1020. END_MESSAGE_MAP()
  1021. //
  1022. // Message Handlers
  1023. //
  1024. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  1025. BOOL
  1026. CVDWPPermissions::OnSetActive()
  1027. /*++
  1028. Routine Description:
  1029. Activation handler
  1030. Arguments:
  1031. None
  1032. Return Value:
  1033. TRUE for success, FALSE for failure
  1034. --*/
  1035. {
  1036. SetControlStates();
  1037. return CIISWizardPage::OnSetActive();
  1038. }
  1039. LRESULT
  1040. CVDWPPermissions::OnWizardNext()
  1041. /*++
  1042. Routine Description:
  1043. 'next' handler. Complete the wizard
  1044. Arguments:
  1045. None
  1046. Return Value:
  1047. 0 to proceed, -1 to fail
  1048. --*/
  1049. {
  1050. if (!UpdateData(TRUE))
  1051. {
  1052. return -1;
  1053. }
  1054. ASSERT(m_pwsSettings != NULL);
  1055. CWaitCursor wait;
  1056. //
  1057. // Build permissions DWORD
  1058. //
  1059. DWORD dwPermissions = 0L;
  1060. SET_FLAG_IF(m_pwsSettings->m_fRead, dwPermissions, MD_ACCESS_READ);
  1061. SET_FLAG_IF(m_pwsSettings->m_fWrite, dwPermissions, MD_ACCESS_WRITE);
  1062. if (m_bVDir)
  1063. {
  1064. //
  1065. // First see if by any chance this name already exists
  1066. //
  1067. ISMCHILDINFO ii;
  1068. ii.dwSize = sizeof(ii);
  1069. CError err;
  1070. //
  1071. // Reconnect if necessary.
  1072. //
  1073. BEGIN_ASSURE_BINDING_SECTION
  1074. err = ::ISMQueryChildInfo(
  1075. m_pwsSettings->m_pKey,
  1076. WITHOUT_INHERITANCE,
  1077. &ii,
  1078. m_pwsSettings->m_dwInstance,
  1079. m_pwsSettings->m_strParent,
  1080. m_pwsSettings->m_strAlias
  1081. );
  1082. END_ASSURE_BINDING_SECTION(err, m_pwsSettings->m_pKey, ERROR_CANCELLED);
  1083. if (err.Succeeded())
  1084. {
  1085. BOOL fNotUnique = TRUE;
  1086. //
  1087. // If the item existed without a VrPath, we'll just blow it
  1088. // away, as a vdir takes presedence over a directory/file.
  1089. //
  1090. if (!*ii.szPath)
  1091. {
  1092. ASSERT(FALSE && "Not possible in FTP!");
  1093. err = ::ISMDeleteChild(
  1094. m_pwsSettings->m_pKey,
  1095. m_pwsSettings->m_dwInstance,
  1096. m_pwsSettings->m_strParent,
  1097. m_pwsSettings->m_strAlias
  1098. );
  1099. if (err.Succeeded())
  1100. {
  1101. //
  1102. // Successfully deleted -- continue as normal.
  1103. //
  1104. fNotUnique = FALSE;
  1105. }
  1106. }
  1107. //
  1108. // This one already exists and exists as a virtual
  1109. // directory, so away with it.
  1110. //
  1111. if (fNotUnique)
  1112. {
  1113. ::AfxMessageBox(IDS_ERR_ALIAS_NOT_UNIQUE);
  1114. return IDD_NEW_DIR_ALIAS;
  1115. }
  1116. }
  1117. //
  1118. // Create new vdir
  1119. //
  1120. BEGIN_ASSURE_BINDING_SECTION
  1121. err = CChildNodeProps::Add(
  1122. m_pwsSettings->m_pKey,
  1123. m_pwsSettings->m_strService, // Service name
  1124. m_pwsSettings->m_dwInstance, // Instance
  1125. m_pwsSettings->m_strParent, // Parent path
  1126. m_pwsSettings->m_strAlias, // Desired alias name
  1127. m_pwsSettings->m_strAlias, // Name returned here (may differ)
  1128. &dwPermissions, // Permissions
  1129. NULL, // dir browsing N/A
  1130. m_pwsSettings->m_strPath, // Physical path of this directory
  1131. (m_pwsSettings->m_fUNC ? (LPCTSTR)m_pwsSettings->m_strUserName : NULL),
  1132. (m_pwsSettings->m_fUNC ? (LPCTSTR)m_pwsSettings->m_strPassword : NULL),
  1133. TRUE // Name must be unique
  1134. );
  1135. END_ASSURE_BINDING_SECTION(err, m_pwsSettings->m_pKey, ERROR_CANCELLED);
  1136. m_pwsSettings->m_hrResult = err;
  1137. }
  1138. else
  1139. {
  1140. //
  1141. // Create new instance
  1142. //
  1143. CError err;
  1144. BEGIN_ASSURE_BINDING_SECTION
  1145. err = CInstanceProps::Add(
  1146. m_pwsSettings->m_pKey,
  1147. m_pwsSettings->m_strService, // Service name
  1148. m_pwsSettings->m_strPath, // Physical path of this directory
  1149. (m_pwsSettings->m_fUNC ? (LPCTSTR)m_pwsSettings->m_strUserName : NULL),
  1150. (m_pwsSettings->m_fUNC ? (LPCTSTR)m_pwsSettings->m_strPassword : NULL),
  1151. m_pwsSettings->m_strDescription,
  1152. m_pwsSettings->m_strBinding,
  1153. NULL, // No secure bindings on FTP
  1154. &dwPermissions,
  1155. NULL, // dir browsing N/A
  1156. NULL, // Auth flags
  1157. &m_pwsSettings->m_dwInstance
  1158. );
  1159. END_ASSURE_BINDING_SECTION(err, m_pwsSettings->m_pKey, ERROR_CANCELLED);
  1160. m_pwsSettings->m_hrResult = err;
  1161. }
  1162. return CIISWizardPage::OnWizardNext();
  1163. }