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.

1119 lines
26 KiB

  1. /*++
  2. Copyright (c) 1994-2001 Microsoft Corporation
  3. Module Name :
  4. wdir.cpp
  5. Abstract:
  6. WWW Directory (non-virtual) Properties Page
  7. Author:
  8. Sergei Antonov (sergeia)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. 10/03/2001 sergeia Created from wvdir.cpp / wfile.cpp
  13. --*/
  14. //
  15. // Include Files
  16. //
  17. #include "stdafx.h"
  18. #include "resource.h"
  19. #include "common.h"
  20. #include "inetprop.h"
  21. #include "InetMgrApp.h"
  22. #include "supdlgs.h"
  23. #include "shts.h"
  24. #include "w3sht.h"
  25. #include "wdir.h"
  26. #include "dirbrows.h"
  27. #include "iisobj.h"
  28. #include <lmcons.h>
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. LPCTSTR CvtPathToDosStyle(CString & strPath);
  35. IMPLEMENT_DYNCREATE(CW3DirPage, CInetPropertyPage)
  36. CW3DirPage::CW3DirPage(CInetPropertySheet * pSheet)
  37. : CInetPropertyPage(CW3DirPage::IDD, pSheet, IDS_TAB_DIR),
  38. //
  39. // Assign the range of bits in m_dwAccessPermissions that
  40. // we manage. This is important, because another page
  41. // manages other bits, and we don't want to screw up
  42. // the master value bits when our changes collide (it
  43. // will mark the original bits as dirty, because we're not
  44. // notified when the change is made...
  45. //
  46. m_dwBitRangePermissions(MD_ACCESS_EXECUTE |
  47. MD_ACCESS_SCRIPT |
  48. MD_ACCESS_WRITE |
  49. MD_ACCESS_SOURCE |
  50. MD_ACCESS_READ),
  51. m_dwBitRangeDirBrowsing(MD_DIRBROW_ENABLED),
  52. m_pApplication(NULL),
  53. m_fRecordChanges(TRUE),
  54. m_fCompatibilityMode(FALSE)
  55. {
  56. VERIFY(m_strPrompt[RADIO_DIRECTORY].LoadString(IDS_PROMPT_DIR));
  57. VERIFY(m_strPrompt[RADIO_REDIRECT].LoadString(IDS_PROMPT_REDIRECT));
  58. VERIFY(m_strRemove.LoadString(IDS_BUTTON_REMOVE));
  59. VERIFY(m_strCreate.LoadString(IDS_BUTTON_CREATE));
  60. VERIFY(m_strEnable.LoadString(IDS_BUTTON_ENABLE));
  61. VERIFY(m_strDisable.LoadString(IDS_BUTTON_DISABLE));
  62. VERIFY(m_strWebFmt.LoadString(IDS_APPROOT_FMT));
  63. }
  64. CW3DirPage::~CW3DirPage()
  65. {
  66. SAFE_DELETE(m_pApplication);
  67. }
  68. void
  69. CW3DirPage::DoDataExchange(CDataExchange * pDX)
  70. {
  71. CInetPropertyPage::DoDataExchange(pDX);
  72. //{{AFX_DATA_MAP(CW3DirPage)
  73. // DDX_Radio(pDX, IDC_RADIO_DIR, m_nPathType);
  74. DDX_Control(pDX, IDC_RADIO_DIR, m_radio_Dir);
  75. DDX_Control(pDX, IDC_RADIO_REDIRECT, m_radio_Redirect);
  76. DDX_Control(pDX, IDC_EDIT_PATH, m_edit_Path);
  77. DDX_Check(pDX, IDC_CHECK_AUTHOR, m_fAuthor);
  78. DDX_Control(pDX, IDC_CHECK_AUTHOR, m_check_Author);
  79. DDX_Check(pDX, IDC_CHECK_READ, m_fRead);
  80. DDX_Control(pDX, IDC_CHECK_READ, m_check_Read);
  81. DDX_Check(pDX, IDC_CHECK_WRITE, m_fWrite);
  82. DDX_Control(pDX, IDC_CHECK_WRITE, m_check_Write);
  83. DDX_Check(pDX, IDC_CHECK_DIRECTORY_BROWSING_ALLOWED, m_fBrowsingAllowed);
  84. DDX_Control(pDX, IDC_CHECK_DIRECTORY_BROWSING_ALLOWED, m_check_DirBrowse);
  85. DDX_Check(pDX, IDC_CHECK_LOG_ACCESS, m_fLogAccess);
  86. DDX_Control(pDX, IDC_CHECK_LOG_ACCESS, m_check_LogAccess);
  87. DDX_Check(pDX, IDC_CHECK_INDEX, m_fIndexed);
  88. DDX_Control(pDX, IDC_CHECK_INDEX, m_check_Index);
  89. DDX_Control(pDX, IDC_EDIT_REDIRECT, m_edit_Redirect);
  90. DDX_Check(pDX, IDC_CHECK_CHILD, m_fChild);
  91. DDX_Check(pDX, IDC_CHECK_EXACT, m_fExact);
  92. DDX_Check(pDX, IDC_CHECK_PERMANENT, m_fPermanent);
  93. DDX_Control(pDX, IDC_CHECK_CHILD, m_check_Child);
  94. DDX_Control(pDX, IDC_STATIC_PATH_PROMPT, m_static_PathPrompt);
  95. DDX_Control(pDX, IDC_BUTTON_UNLOAD_APP, m_button_Unload);
  96. DDX_Control(pDX, IDC_BUTTON_CREATE_REMOVE_APP, m_button_CreateRemove);
  97. DDX_Control(pDX, IDC_APP_CONFIGURATION, m_button_Configuration);
  98. DDX_CBIndex(pDX, IDC_COMBO_PERMISSIONS, m_nPermissions);
  99. DDX_Control(pDX, IDC_COMBO_PERMISSIONS, m_combo_Permissions);
  100. DDX_Control(pDX, IDC_STATIC_PROTECTION, m_static_ProtectionPrompt);
  101. DDX_Control(pDX, IDC_COMBO_PROCESS, m_combo_Process);
  102. DDX_Control(pDX, IDC_EDIT_APPLICATION, m_edit_AppFriendlyName);
  103. DDX_Text(pDX, IDC_EDIT_APPLICATION, m_strAppFriendlyName);
  104. DDV_MinMaxChars(pDX, m_strAppFriendlyName, 0, MAX_PATH); /// ?
  105. //}}AFX_DATA_MAP
  106. if (pDX->m_bSaveAndValidate)
  107. {
  108. if (m_nPathType == RADIO_REDIRECT)
  109. {
  110. DDX_Text(pDX, IDC_EDIT_REDIRECT, m_strRedirectPath);
  111. m_strRedirectPath.TrimLeft();
  112. DDV_MinMaxChars(pDX, m_strRedirectPath, 0, 2 * MAX_PATH);
  113. if (!IsRelURLPath(m_strRedirectPath)
  114. && !IsWildcardedRedirectPath(m_strRedirectPath)
  115. && !IsURLName(m_strRedirectPath))
  116. {
  117. ::AfxMessageBox(IDS_BAD_URL_PATH);
  118. pDX->Fail();
  119. }
  120. }
  121. else // Local directory
  122. {
  123. m_strRedirectPath.Empty();
  124. }
  125. }
  126. else
  127. {
  128. DDX_Text(pDX, IDC_EDIT_REDIRECT, m_strRedirectPath);
  129. }
  130. }
  131. //
  132. // Message Map
  133. //
  134. BEGIN_MESSAGE_MAP(CW3DirPage, CInetPropertyPage)
  135. //{{AFX_MSG_MAP(CW3DirPage)
  136. ON_BN_CLICKED(IDC_CHECK_AUTHOR, OnCheckAuthor)
  137. ON_BN_CLICKED(IDC_CHECK_READ, OnCheckRead)
  138. ON_BN_CLICKED(IDC_CHECK_WRITE, OnCheckWrite)
  139. ON_BN_CLICKED(IDC_RADIO_DIR, OnRadioDir)
  140. ON_BN_CLICKED(IDC_RADIO_REDIRECT, OnRadioRedirect)
  141. ON_EN_CHANGE(IDC_EDIT_REDIRECT, OnItemChanged)
  142. ON_BN_CLICKED(IDC_CHECK_LOG_ACCESS, OnItemChanged)
  143. ON_BN_CLICKED(IDC_CHECK_DIRECTORY_BROWSING_ALLOWED, OnItemChanged)
  144. ON_BN_CLICKED(IDC_CHECK_INDEX, OnItemChanged)
  145. ON_BN_CLICKED(IDC_CHECK_CHILD, OnItemChanged)
  146. ON_BN_CLICKED(IDC_CHECK_EXACT, OnItemChanged)
  147. ON_BN_CLICKED(IDC_CHECK_PERMANENT, OnItemChanged)
  148. ON_BN_CLICKED(IDC_BUTTON_CREATE_REMOVE_APP, OnButtonCreateRemoveApp)
  149. ON_BN_CLICKED(IDC_BUTTON_UNLOAD_APP, OnButtonUnloadApp)
  150. ON_BN_CLICKED(IDC_APP_CONFIGURATION, OnButtonConfiguration)
  151. ON_CBN_SELCHANGE(IDC_COMBO_PERMISSIONS, OnSelchangeComboPermissions)
  152. ON_CBN_SELCHANGE(IDC_COMBO_PROCESS, OnSelchangeComboProcess)
  153. ON_EN_CHANGE(IDC_EDIT_APPLICATION, OnItemChanged)
  154. ON_WM_DESTROY()
  155. //}}AFX_MSG_MAP
  156. END_MESSAGE_MAP()
  157. void
  158. CW3DirPage::ChangeTypeTo(int nNewType)
  159. {
  160. int nOldType = m_nPathType;
  161. m_nPathType = nNewType;
  162. if (nOldType == m_nPathType)
  163. {
  164. return;
  165. }
  166. OnItemChanged();
  167. SetStateByType();
  168. int nID = -1;
  169. CEdit * pPath = NULL;
  170. LPCTSTR lpKeepPath = NULL;
  171. switch(m_nPathType)
  172. {
  173. case RADIO_DIRECTORY:
  174. break;
  175. case RADIO_REDIRECT:
  176. if (!m_strRedirectPath.IsEmpty())
  177. {
  178. //
  179. // The old path info is acceptable, propose it
  180. // as a default
  181. //
  182. lpKeepPath = m_strRedirectPath;
  183. }
  184. nID = IDS_REDIRECT_MASK;
  185. pPath = &m_edit_Redirect;
  186. break;
  187. default:
  188. ASSERT(FALSE);
  189. return;
  190. }
  191. //
  192. // Load mask resource, and display
  193. // this in the directory
  194. //
  195. if (pPath != NULL)
  196. {
  197. if (lpKeepPath != NULL)
  198. {
  199. pPath->SetWindowText(lpKeepPath);
  200. }
  201. else
  202. {
  203. CString str;
  204. VERIFY(str.LoadString(nID));
  205. pPath->SetWindowText(str);
  206. }
  207. pPath->SetSel(0,-1);
  208. pPath->SetFocus();
  209. }
  210. }
  211. void
  212. CW3DirPage::ShowControl(CWnd * pWnd, BOOL fShow)
  213. {
  214. ASSERT(pWnd != NULL);
  215. pWnd->EnableWindow(fShow);
  216. pWnd->ShowWindow(fShow ? SW_SHOW : SW_HIDE);
  217. }
  218. void
  219. CW3DirPage::SetStateByType()
  220. /*++
  221. Routine Description:
  222. Set the state of the dialog by the path type currently selected
  223. Arguments:
  224. None
  225. Return Value:
  226. None
  227. --*/
  228. {
  229. BOOL fShowDirFlags;
  230. BOOL fShowRedirectFlags;
  231. BOOL fShowDAV;
  232. switch(m_nPathType)
  233. {
  234. case RADIO_DIRECTORY:
  235. ShowControl(&m_edit_Path, fShowDirFlags = TRUE);
  236. m_edit_Path.EnableWindow(FALSE);
  237. ShowControl(&m_edit_Redirect, fShowRedirectFlags = FALSE);
  238. fShowDAV = TRUE;
  239. break;
  240. case RADIO_REDIRECT:
  241. ShowControl(&m_edit_Path, fShowDirFlags = FALSE);
  242. ShowControl(&m_edit_Redirect, fShowRedirectFlags = TRUE);
  243. fShowDAV = FALSE;
  244. break;
  245. default:
  246. ASSERT(FALSE && "Invalid Selection");
  247. return;
  248. }
  249. ShowControl(IDC_CHECK_READ, fShowDirFlags);
  250. ShowControl(IDC_CHECK_WRITE, fShowDirFlags);
  251. ShowControl(IDC_CHECK_DIRECTORY_BROWSING_ALLOWED, fShowDirFlags);
  252. ShowControl(IDC_CHECK_INDEX, fShowDirFlags);
  253. ShowControl(IDC_CHECK_LOG_ACCESS, fShowDirFlags);
  254. ShowControl(IDC_CHECK_AUTHOR, fShowDirFlags);
  255. ShowControl(IDC_STATIC_DIRFLAGS_LARGE, fShowDirFlags);
  256. ShowControl(IDC_STATIC_APPLICATION_SETTINGS, fShowDirFlags);
  257. ShowControl(IDC_STATIC_APP_PROMPT, fShowDirFlags);
  258. ShowControl(&m_edit_AppFriendlyName, fShowDirFlags);
  259. ShowControl(IDC_STATIC_SP_PROMPT, fShowDirFlags);
  260. ShowControl(IDC_STATIC_PERMISSIONS, fShowDirFlags);
  261. ShowControl(IDC_COMBO_PERMISSIONS, fShowDirFlags);
  262. ShowControl(IDC_STATIC_PROTECTION, fShowDirFlags);
  263. ShowControl(IDC_COMBO_PROCESS, fShowDirFlags);
  264. ShowControl(IDC_BUTTON_CREATE_REMOVE_APP, fShowDirFlags);
  265. ShowControl(IDC_APP_CONFIGURATION, fShowDirFlags);
  266. ShowControl(IDC_BUTTON_UNLOAD_APP, fShowDirFlags);
  267. ShowControl(IDC_STATIC_STARTING_POINT, fShowDirFlags);
  268. ShowControl(IDC_STATIC_APPLICATIONS, fShowDirFlags);
  269. ShowControl(IDC_CHECK_EXACT, fShowRedirectFlags);
  270. ShowControl(IDC_CHECK_CHILD, fShowRedirectFlags);
  271. ShowControl(IDC_CHECK_PERMANENT, fShowRedirectFlags);
  272. ShowControl(IDC_STATIC_REDIRECT_PROMPT, fShowRedirectFlags);
  273. ShowControl(IDC_STATIC_REDIRFLAGS, fShowRedirectFlags);
  274. ShowControl(&m_check_Author, fShowDAV);
  275. //
  276. // Enable/Disable must come after the showcontrols
  277. //
  278. m_static_PathPrompt.SetWindowText(m_strPrompt[m_nPathType]);
  279. SetApplicationState();
  280. }
  281. void
  282. CW3DirPage::SaveAuthoringState()
  283. {
  284. if (m_check_Write.m_hWnd)
  285. {
  286. //
  287. // Controls initialized -- store live data
  288. //
  289. m_fOriginalWrite = m_check_Write.GetCheck() > 0;
  290. m_fOriginalRead = m_check_Read.GetCheck() > 0;
  291. }
  292. else
  293. {
  294. //
  295. // Controls not yet initialized, store original data
  296. //
  297. m_fOriginalWrite = m_fWrite;
  298. m_fOriginalRead = m_fRead;
  299. }
  300. }
  301. void
  302. CW3DirPage::RestoreAuthoringState()
  303. {
  304. m_fWrite = m_fOriginalWrite;
  305. m_fRead = m_fOriginalRead;
  306. }
  307. void
  308. CW3DirPage::SetAuthoringState(BOOL fAlterReadAndWrite)
  309. {
  310. if (fAlterReadAndWrite)
  311. {
  312. if (m_fAuthor)
  313. {
  314. //
  315. // Remember previous setting to undo
  316. // this thing.
  317. //
  318. SaveAuthoringState();
  319. m_fRead = m_fWrite = TRUE;
  320. }
  321. else
  322. {
  323. //
  324. // Restore previous defaults
  325. //
  326. RestoreAuthoringState();
  327. }
  328. m_check_Read.SetCheck(m_fRead);
  329. m_check_Write.SetCheck(m_fWrite);
  330. }
  331. m_check_Author.EnableWindow((m_fRead || m_fWrite)
  332. && HasAdminAccess()
  333. && HasDAV()
  334. );
  335. // m_check_Read.EnableWindow(!m_fAuthor && HasAdminAccess());
  336. // m_check_Write.EnableWindow(!m_fAuthor && HasAdminAccess());
  337. }
  338. void
  339. CW3DirPage::SetPathType()
  340. {
  341. if (!m_strRedirectPath.IsEmpty())
  342. {
  343. m_nPathType = RADIO_REDIRECT;
  344. m_radio_Dir.SetCheck(0);
  345. m_radio_Redirect.SetCheck(1);
  346. }
  347. else
  348. {
  349. m_nPathType = RADIO_DIRECTORY;
  350. m_radio_Redirect.SetCheck(0);
  351. m_radio_Dir.SetCheck(1);
  352. }
  353. m_static_PathPrompt.SetWindowText(m_strPrompt[m_nPathType]);
  354. }
  355. //
  356. // Message Handlers
  357. //
  358. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  359. void
  360. CW3DirPage::OnItemChanged()
  361. {
  362. if (m_fRecordChanges)
  363. {
  364. SetModified(TRUE);
  365. }
  366. }
  367. BOOL
  368. CW3DirPage::OnInitDialog()
  369. {
  370. CInetPropertyPage::OnInitDialog();
  371. m_fCompatibilityMode = ((CW3Sheet *)GetSheet())->InCompatibilityMode();
  372. // Disable/hide irrelevant items
  373. GetDlgItem(IDC_RADIO_UNC)->EnableWindow(FALSE);
  374. ShowControl(GetDlgItem(IDC_BUTTON_CONNECT_AS), FALSE);
  375. ShowControl(GetDlgItem(IDC_BUTTON_BROWSE), FALSE);
  376. ShowControl(GetDlgItem(IDC_STATIC_DIRFLAGS_SMALL), FALSE);
  377. // Set appropriate prompt
  378. CString str;
  379. VERIFY(str.LoadString(IDS_RADIO_DIR));
  380. m_radio_Dir.SetWindowText(str);
  381. //
  382. // Fill permissions combo box.
  383. //
  384. AddStringToComboBox(m_combo_Permissions, IDS_PERMISSIONS_NONE);
  385. AddStringToComboBox(m_combo_Permissions, IDS_PERMISSIONS_SCRIPT);
  386. AddStringToComboBox(m_combo_Permissions, IDS_PERMISSIONS_EXECUTE);
  387. m_combo_Permissions.SetCurSel(m_nPermissions);
  388. ASSERT(m_pApplication != NULL);
  389. if (m_fCompatibilityMode)
  390. {
  391. m_nSelInProc = AddStringToComboBox(m_combo_Process, IDS_COMBO_INPROC);
  392. if (m_pApplication->SupportsPooledProc())
  393. {
  394. m_nSelPooledProc = AddStringToComboBox(m_combo_Process, IDS_COMBO_POOLEDPROC);
  395. }
  396. else
  397. {
  398. m_nSelPooledProc = -1; // N/A
  399. }
  400. m_nSelOutOfProc = AddStringToComboBox(m_combo_Process, IDS_COMBO_OUTPROC);
  401. }
  402. else
  403. {
  404. CString buf;
  405. buf.LoadString(IDS_APPLICATION_POOL);
  406. m_static_ProtectionPrompt.SetWindowText(buf);
  407. CMapStringToString pools;
  408. CError err = ((CW3Sheet *)GetSheet())->EnumAppPools(pools);
  409. int idx_sel = CB_ERR;
  410. int idx_def = CB_ERR;
  411. if (err.Succeeded())
  412. {
  413. ASSERT(pools.GetCount() > 0);
  414. POSITION pos = pools.GetStartPosition();
  415. CString pool_id, pool_name;
  416. while (pos != NULL)
  417. {
  418. pools.GetNextAssoc(pos, pool_name, pool_id);
  419. int idx = m_combo_Process.AddString(pool_name);
  420. m_combo_Process.SetItemDataPtr(idx, StrDup(pool_id));
  421. if (0 == m_pApplication->m_strAppPoolId.CompareNoCase(pool_id))
  422. {
  423. idx_sel = idx;
  424. }
  425. if (0 == buf.CompareNoCase(pool_id))
  426. {
  427. idx_def = idx;
  428. }
  429. }
  430. }
  431. // select the app pool which has an id the same as in current application
  432. // It could be new app created in compatibility mode, no app pool is default app pool
  433. if (CB_ERR == idx_sel)
  434. {
  435. idx_sel = idx_def;
  436. }
  437. m_combo_Process.SetCurSel(idx_sel);
  438. }
  439. // It is enough to set file alias once -- we cannot change it here
  440. CString buf1, buf2, strAlias;
  441. CMetabasePath::GetRootPath(m_strFullMetaPath, buf1, &buf2);
  442. strAlias = _T("\\");
  443. strAlias += buf2;
  444. CvtPathToDosStyle(strAlias);
  445. m_edit_Path.SetWindowText(strAlias);
  446. SetPathType();
  447. SetStateByType();
  448. SetAuthoringState(FALSE);
  449. return TRUE;
  450. }
  451. void
  452. CW3DirPage::OnDestroy()
  453. {
  454. int count = m_combo_Process.GetCount();
  455. if (count != CB_ERR)
  456. {
  457. for (int i = 0; i < count; i++)
  458. {
  459. void * p = m_combo_Process.GetItemDataPtr(i);
  460. LocalFree(p);
  461. m_combo_Process.SetItemDataPtr(i, NULL);
  462. }
  463. }
  464. }
  465. /* virtual */
  466. HRESULT
  467. CW3DirPage::FetchLoadedValues()
  468. {
  469. CError err;
  470. BEGIN_META_DIR_READ(CW3Sheet)
  471. //
  472. // Use m_ notation because the message crackers require it
  473. //
  474. BOOL m_fDontLog;
  475. FETCH_DIR_DATA_FROM_SHEET(m_strFullMetaPath);
  476. FETCH_DIR_DATA_FROM_SHEET(m_strRedirectPath);
  477. FETCH_DIR_DATA_FROM_SHEET(m_dwAccessPerms);
  478. FETCH_DIR_DATA_FROM_SHEET(m_dwDirBrowsing);
  479. FETCH_DIR_DATA_FROM_SHEET(m_fDontLog);
  480. FETCH_DIR_DATA_FROM_SHEET(m_fIndexed);
  481. FETCH_DIR_DATA_FROM_SHEET(m_fExact);
  482. FETCH_DIR_DATA_FROM_SHEET(m_fChild);
  483. FETCH_DIR_DATA_FROM_SHEET(m_fPermanent);
  484. m_fRead = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_READ);
  485. m_fWrite = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_WRITE);
  486. m_fAuthor = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_SOURCE);
  487. m_fBrowsingAllowed = IS_FLAG_SET(m_dwDirBrowsing, MD_DIRBROW_ENABLED);
  488. m_fLogAccess = !m_fDontLog;
  489. SaveAuthoringState();
  490. if (!m_fIsAppRoot)
  491. {
  492. m_dwAppState = APPSTATUS_NOTDEFINED;
  493. }
  494. FETCH_DIR_DATA_FROM_SHEET(m_strUserName);
  495. FETCH_DIR_DATA_FROM_SHEET(m_strPassword);
  496. FETCH_DIR_DATA_FROM_SHEET(m_strAlias);
  497. END_META_DIR_READ(err)
  498. m_nPermissions = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_EXECUTE)
  499. ? COMBO_EXECUTE : IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_SCRIPT)
  500. ? COMBO_SCRIPT : COMBO_NONE;
  501. BeginWaitCursor();
  502. m_pApplication = new CIISApplication(QueryAuthInfo(), QueryMetaPath());
  503. err = m_pApplication != NULL
  504. ? m_pApplication->QueryResult() : ERROR_NOT_ENOUGH_MEMORY;
  505. if (err.Win32Error() == ERROR_PATH_NOT_FOUND)
  506. {
  507. //
  508. // No app information; that's ok in cases of file system directories
  509. // that don't exist in the metabase yet.
  510. //
  511. err.Reset();
  512. }
  513. if (err.Succeeded())
  514. {
  515. //
  516. // CODEWORK: RefreshAppState should be split up into two
  517. // different methods: one that fetches the data, and one
  518. // that moves the data to the UI controls on this page.
  519. //
  520. RefreshAppState();
  521. }
  522. EndWaitCursor();
  523. return err;
  524. }
  525. DWORD
  526. CW3DirPage::GetAppStateFromComboSelection() const
  527. /*++
  528. Routine Description:
  529. Get the app state DWORD that coresponds to the current combo
  530. box list selection
  531. Arguments:
  532. None
  533. Return Value:
  534. App state DWORD or 0xffffffff;
  535. --*/
  536. {
  537. int nSel = m_combo_Process.GetCurSel();
  538. if (nSel == m_nSelOutOfProc)
  539. {
  540. return CWamInterface::APP_OUTOFPROC;
  541. }
  542. if (nSel == m_nSelPooledProc)
  543. {
  544. ASSERT(m_pApplication->SupportsPooledProc());
  545. return CWamInterface::APP_POOLEDPROC;
  546. }
  547. if (nSel == m_nSelInProc)
  548. {
  549. return CWamInterface::APP_INPROC;
  550. }
  551. ASSERT(FALSE && "Invalid application state");
  552. return 0xffffffff;
  553. }
  554. /* virtual */
  555. HRESULT
  556. CW3DirPage::SaveInfo()
  557. {
  558. ASSERT(IsDirty());
  559. CError err;
  560. SET_FLAG_IF(m_fBrowsingAllowed, m_dwDirBrowsing, MD_DIRBROW_ENABLED);
  561. SET_FLAG_IF(m_fRead, m_dwAccessPerms, MD_ACCESS_READ);
  562. SET_FLAG_IF(m_fWrite, m_dwAccessPerms, MD_ACCESS_WRITE);
  563. SET_FLAG_IF(m_fAuthor, m_dwAccessPerms, MD_ACCESS_SOURCE);
  564. SET_FLAG_IF((m_nPermissions == COMBO_EXECUTE), m_dwAccessPerms, MD_ACCESS_EXECUTE);
  565. //
  566. // script is set on EXECUTE as well "Execute (including script)"
  567. //
  568. SET_FLAG_IF(((m_nPermissions == COMBO_SCRIPT) || (m_nPermissions == COMBO_EXECUTE)),
  569. m_dwAccessPerms, MD_ACCESS_SCRIPT);
  570. BOOL m_fDontLog = !m_fLogAccess;
  571. BeginWaitCursor();
  572. if (m_fCompatibilityMode)
  573. {
  574. DWORD dwAppProtection = GetAppStateFromComboSelection();
  575. if (dwAppProtection != m_dwAppProtection && m_fAppEnabled)
  576. {
  577. //
  578. // Isolation state has changed; recreate the application
  579. //
  580. CError err2(m_pApplication->RefreshAppState());
  581. if (err2.Succeeded())
  582. {
  583. err2 = m_pApplication->Create(m_strAppFriendlyName, dwAppProtection);
  584. //
  585. // Remember the new state, so we don't do this again
  586. // the next time the guy hits "apply"
  587. //
  588. if (err2.Succeeded())
  589. {
  590. m_dwAppProtection = dwAppProtection;
  591. }
  592. }
  593. err2.MessageBoxOnFailure();
  594. }
  595. }
  596. BEGIN_META_DIR_WRITE(CW3Sheet)
  597. INIT_DIR_DATA_MASK(m_dwAccessPerms, m_dwBitRangePermissions)
  598. INIT_DIR_DATA_MASK(m_dwDirBrowsing, m_dwBitRangeDirBrowsing)
  599. STORE_DIR_DATA_ON_SHEET(m_fDontLog)
  600. STORE_DIR_DATA_ON_SHEET(m_fIndexed)
  601. STORE_DIR_DATA_ON_SHEET(m_fChild);
  602. STORE_DIR_DATA_ON_SHEET(m_fExact);
  603. STORE_DIR_DATA_ON_SHEET(m_fPermanent);
  604. //
  605. // CODEWORK: Not an elegant solution
  606. //
  607. pSheet->GetDirectoryProperties().MarkRedirAsInherit(!m_fChild);
  608. STORE_DIR_DATA_ON_SHEET(m_strRedirectPath)
  609. STORE_DIR_DATA_ON_SHEET(m_dwAccessPerms)
  610. STORE_DIR_DATA_ON_SHEET(m_dwDirBrowsing)
  611. END_META_DIR_WRITE(err)
  612. if (err.Succeeded() && m_pApplication->IsEnabledApplication())
  613. {
  614. err = m_pApplication->WriteFriendlyName(m_strAppFriendlyName);
  615. if (!m_fCompatibilityMode)
  616. {
  617. // get app pool id from the combo,
  618. // check if it was changed and reassign to application
  619. // get app pool id from the combo,
  620. // check if it was changed and reassign to application
  621. CString id;
  622. int idx = m_combo_Process.GetCurSel();
  623. ASSERT(idx != CB_ERR);
  624. id = (LPCTSTR)m_combo_Process.GetItemDataPtr(idx);
  625. m_pApplication->WritePoolId(id);
  626. }
  627. }
  628. if (err.Succeeded())
  629. {
  630. SaveAuthoringState();
  631. err = ((CW3Sheet *)GetSheet())->SetKeyType();
  632. }
  633. EndWaitCursor();
  634. return err;
  635. }
  636. void
  637. CW3DirPage::RefreshAppState()
  638. {
  639. ASSERT(m_pApplication != NULL);
  640. CError err(m_pApplication->RefreshAppState());
  641. if (err.Failed())
  642. {
  643. m_dwAppState = APPSTATUS_NOTDEFINED;
  644. if (err.Win32Error() == ERROR_PATH_NOT_FOUND)
  645. {
  646. //
  647. // Ignore this error, it really just means the path
  648. // doesn't exist in the metabase, which is true for most
  649. // file and directory properties, and not an error
  650. // condition.
  651. //
  652. err.Reset();
  653. }
  654. }
  655. else
  656. {
  657. m_dwAppState = m_pApplication->QueryAppState();
  658. }
  659. if (err.Succeeded())
  660. {
  661. //
  662. // Get metabase information
  663. //
  664. m_strAppRoot = m_pApplication->m_strAppRoot;
  665. m_dwAppProtection = m_pApplication->m_dwProcessProtection;
  666. m_strAppFriendlyName = m_pApplication->m_strFriendlyName;
  667. m_fIsAppRoot
  668. = (m_strFullMetaPath.CompareNoCase(m_strAppRoot) == 0);
  669. }
  670. else
  671. {
  672. //
  673. // Display error information
  674. //
  675. err.MessageBoxFormat(IDS_ERR_APP, MB_OK, NO_HELP_CONTEXT);
  676. }
  677. }
  678. CString&
  679. CW3DirPage::FriendlyAppRoot(LPCTSTR lpAppRoot, CString& strFriendly)
  680. {
  681. if (lpAppRoot != NULL && *lpAppRoot != 0)
  682. {
  683. strFriendly.Empty();
  684. CInstanceProps prop(QueryAuthInfo(), lpAppRoot);
  685. HRESULT hr = prop.LoadData();
  686. if (SUCCEEDED(hr))
  687. {
  688. CString root, tail;
  689. strFriendly.Format(m_strWebFmt, prop.GetDisplayText(root));
  690. CMetabasePath::GetRootPath(lpAppRoot, root, &tail);
  691. if (!tail.IsEmpty())
  692. {
  693. //
  694. // Add rest of dir path
  695. //
  696. strFriendly += _T("/");
  697. strFriendly += tail;
  698. }
  699. //
  700. // Now change forward slashes in the path to backward slashes
  701. //
  702. CvtPathToDosStyle(strFriendly);
  703. return strFriendly;
  704. }
  705. }
  706. //
  707. // Bogus
  708. //
  709. VERIFY(strFriendly.LoadString(IDS_APPROOT_UNKNOWN));
  710. return strFriendly;
  711. }
  712. void
  713. CW3DirPage::SetApplicationState()
  714. {
  715. //
  716. // SetWindowText causes a dirty marker
  717. //
  718. BOOL fOld = m_fRecordChanges;
  719. m_fRecordChanges = FALSE;
  720. m_fAppEnabled = FALSE;
  721. if (m_pApplication != NULL)
  722. {
  723. m_pApplication->RefreshAppState();
  724. m_fAppEnabled = m_fIsAppRoot && m_pApplication->IsEnabledApplication();
  725. }
  726. BOOL fVisible = m_nPathType == RADIO_DIRECTORY;
  727. m_button_CreateRemove.EnableWindow(fVisible && HasAdminAccess());
  728. m_button_CreateRemove.SetWindowText(m_fAppEnabled ? m_strRemove : m_strCreate);
  729. m_static_ProtectionPrompt.EnableWindow(fVisible && m_fAppEnabled && HasAdminAccess());
  730. if (m_fCompatibilityMode)
  731. {
  732. //
  733. // Set selection in combo box to match current app state
  734. //
  735. int nSel = -1;
  736. switch(m_dwAppProtection)
  737. {
  738. case CWamInterface::APP_INPROC:
  739. nSel = m_nSelInProc;
  740. break;
  741. case CWamInterface::APP_POOLEDPROC:
  742. ASSERT(m_pApplication->SupportsPooledProc());
  743. nSel = m_nSelPooledProc;
  744. break;
  745. case CWamInterface::APP_OUTOFPROC:
  746. nSel = m_nSelOutOfProc;
  747. break;
  748. default:
  749. ASSERT("Bogus app protection level");
  750. }
  751. ASSERT(nSel >= 0);
  752. m_combo_Process.SetCurSel(nSel);
  753. }
  754. else
  755. {
  756. }
  757. m_combo_Process.EnableWindow(fVisible && m_fAppEnabled && HasAdminAccess());
  758. GetDlgItem(IDC_STATIC_PERMISSIONS)->EnableWindow(fVisible && HasAdminAccess());
  759. m_combo_Permissions.EnableWindow(fVisible && HasAdminAccess());
  760. GetDlgItem(IDC_STATIC_APP_PROMPT)->EnableWindow(fVisible && m_fIsAppRoot && HasAdminAccess());
  761. m_edit_AppFriendlyName.EnableWindow(fVisible && m_fIsAppRoot && HasAdminAccess());
  762. m_button_Configuration.EnableWindow(fVisible && m_fAppEnabled);
  763. //
  764. // Write out the verbose starting point.
  765. //
  766. CString str;
  767. FriendlyAppRoot(m_strAppRoot, str);
  768. CWnd * pWnd = CWnd::FromHandle(GetDlgItem(IDC_STATIC_STARTING_POINT)->m_hWnd);
  769. FitPathToControl(*pWnd, str);
  770. m_edit_AppFriendlyName.SetWindowText(m_strAppFriendlyName);
  771. m_button_Unload.EnableWindow(fVisible && m_dwAppState == APPSTATUS_RUNNING);
  772. //
  773. // Restore (see note on top)
  774. //
  775. m_fRecordChanges = fOld;
  776. }
  777. void
  778. CW3DirPage::OnCheckRead()
  779. {
  780. m_fRead = !m_fRead;
  781. SetAuthoringState(FALSE);
  782. OnItemChanged();
  783. }
  784. void
  785. CW3DirPage::OnCheckWrite()
  786. {
  787. m_fWrite = !m_fWrite;
  788. if (!CheckWriteAndExecWarning())
  789. {
  790. //
  791. // Undo
  792. //
  793. m_fWrite = FALSE;
  794. m_check_Write.SetCheck(m_fWrite);
  795. }
  796. else
  797. {
  798. SetAuthoringState(FALSE);
  799. OnItemChanged();
  800. }
  801. }
  802. void
  803. CW3DirPage::OnCheckAuthor()
  804. {
  805. m_fAuthor = !m_fAuthor;
  806. SetAuthoringState(FALSE);
  807. if (!CheckWriteAndExecWarning())
  808. {
  809. //
  810. // Undo -- set script instead
  811. //
  812. m_combo_Permissions.SetCurSel(m_nPermissions = COMBO_SCRIPT);
  813. }
  814. OnItemChanged();
  815. }
  816. void
  817. CW3DirPage::OnRadioDir()
  818. {
  819. ChangeTypeTo(RADIO_DIRECTORY);
  820. }
  821. void
  822. CW3DirPage::OnRadioRedirect()
  823. {
  824. ChangeTypeTo(RADIO_REDIRECT);
  825. }
  826. void
  827. CW3DirPage::OnButtonCreateRemoveApp()
  828. {
  829. BeginWaitCursor();
  830. CError err(m_pApplication->RefreshAppState());
  831. if (m_fAppEnabled)
  832. {
  833. //
  834. // App currently exists -- delete it
  835. //
  836. err = m_pApplication->Delete();
  837. }
  838. else
  839. {
  840. CString strAppName = m_strAlias;
  841. DWORD dwAppProtState =
  842. m_pApplication->SupportsPooledProc() ?
  843. CWamInterface::APP_POOLEDPROC : CWamInterface::APP_INPROC;
  844. if (m_fCompatibilityMode)
  845. {
  846. //
  847. // Attempt to create a pooled-proc by default; failing
  848. // that if it's not supported, create it in proc
  849. //
  850. err = m_pApplication->Create(strAppName, dwAppProtState);
  851. }
  852. else
  853. {
  854. CString pool;
  855. err = ((CW3Sheet *)GetSheet())->QueryDefaultPoolId(pool);
  856. if (err.Succeeded())
  857. {
  858. err = m_pApplication->CreatePooled(strAppName, dwAppProtState, pool, FALSE);
  859. }
  860. }
  861. }
  862. if (err.Succeeded())
  863. {
  864. RefreshAppState();
  865. NotifyMMC();
  866. }
  867. //
  868. // Move app data to the controls
  869. //
  870. UpdateData(FALSE);
  871. EndWaitCursor();
  872. ASSERT(err.Succeeded());
  873. err.MessageBoxOnFailure();
  874. if (err.Succeeded())
  875. {
  876. SetApplicationState();
  877. OnItemChanged();
  878. }
  879. }
  880. #include "..\AppConfig\AppConfig.h"
  881. extern CInetmgrApp theApp;
  882. void
  883. CW3DirPage::OnButtonConfiguration()
  884. /*++
  885. Routine Description:
  886. Pass on "configuration" button click to the ocx.
  887. Arguments:
  888. None
  889. Return Value:
  890. None
  891. --*/
  892. {
  893. IIISAppConfig * pAppConfig = NULL;
  894. CLSID clsID;
  895. HRESULT hr;
  896. if ( SUCCEEDED(hr = CLSIDFromProgID(OLESTR("AppConfig.IISAppConfig"), &clsID))
  897. && SUCCEEDED(hr = ::CoCreateInstance(clsID,
  898. NULL,
  899. CLSCTX_ALL,
  900. __uuidof(IIISAppConfig),
  901. (void **)&pAppConfig)))
  902. {
  903. pAppConfig->put_ComputerName((LPTSTR)(LPCTSTR)QueryServerName());
  904. pAppConfig->put_MetaPath((LPTSTR)QueryMetaPath());
  905. pAppConfig->put_HelpPath((LPTSTR)theApp.m_pszHelpFilePath);
  906. pAppConfig->put_UserName((LPTSTR)(LPCTSTR)m_strUserName);
  907. pAppConfig->put_UserPassword((LPTSTR)(LPCTSTR)m_strPassword);
  908. DWORD version = MAKELONG(
  909. GetSheet()->QueryMajorVersion(),
  910. GetSheet()->QueryMinorVersion());
  911. pAppConfig->put_ServiceVersion(version);
  912. BOOL mode = ((CW3Sheet *)GetSheet())->InCompatibilityMode();
  913. pAppConfig->put_ServiceCompatMode(mode);
  914. pAppConfig->Run();
  915. pAppConfig->Release();
  916. OnItemChanged();
  917. }
  918. }
  919. void
  920. CW3DirPage::OnSelchangeComboProcess()
  921. {
  922. OnItemChanged();
  923. }
  924. void
  925. CW3DirPage::OnSelchangeComboPermissions()
  926. {
  927. m_nPermissions = m_combo_Permissions.GetCurSel();
  928. ASSERT(m_nPermissions >= COMBO_NONE && m_nPermissions <= COMBO_EXECUTE);
  929. if (!CheckWriteAndExecWarning())
  930. {
  931. //
  932. // Undo -- set script instead
  933. //
  934. m_combo_Permissions.SetCurSel(m_nPermissions = COMBO_SCRIPT);
  935. }
  936. OnItemChanged();
  937. }
  938. void
  939. CW3DirPage::OnButtonUnloadApp()
  940. {
  941. }
  942. BOOL
  943. CW3DirPage::CheckWriteAndExecWarning()
  944. {
  945. if (m_nPermissions == COMBO_EXECUTE && m_fWrite)
  946. {
  947. if (::AfxMessageBox(IDS_WRN_WRITE_EXEC, MB_YESNO | MB_DEFBUTTON2 ) != IDYES)
  948. {
  949. return FALSE;
  950. }
  951. }
  952. OnItemChanged();
  953. return TRUE;
  954. }