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.

1247 lines
32 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. DDV_Url(pDX, m_strRedirectPath);
  112. // We could have only absolute URLs here
  113. // Nope, we allow relative URL's...
  114. if (IsRelURLPath(m_strRedirectPath))
  115. {
  116. }
  117. else
  118. {
  119. if (!PathIsURL(m_strRedirectPath) || m_strRedirectPath.GetLength() <= lstrlen(_T("http://")))
  120. {
  121. DDV_ShowBalloonAndFail(pDX, IDS_BAD_URL_PATH);
  122. }
  123. }
  124. if (m_strRedirectPath.Find(_T(",")) > 0)
  125. {
  126. DDV_ShowBalloonAndFail(pDX, IDS_ERR_COMMA_IN_REDIRECT);
  127. }
  128. }
  129. else // Local directory
  130. {
  131. m_strRedirectPath.Empty();
  132. }
  133. if (!m_fCompatibilityMode)
  134. {
  135. // Check what AppPoolID is assigned
  136. CString str, strSel;
  137. str.LoadString(IDS_INVALID_POOL_ID);
  138. int idx = m_combo_Process.GetCurSel();
  139. ASSERT(idx != CB_ERR);
  140. m_combo_Process.GetLBText(idx, strSel);
  141. if (strSel.Compare(str) == 0)
  142. {
  143. HWND hWndCtrl = pDX->PrepareCtrl(IDC_COMBO_PROCESS);
  144. // Force user to input a valid app pool
  145. // even if the control is diabled!!!
  146. DDV_ShowBalloonAndFail(pDX, IDS_MUST_SELECT_APP_POOL);
  147. }
  148. }
  149. }
  150. else
  151. {
  152. DDX_Text(pDX, IDC_EDIT_REDIRECT, m_strRedirectPath);
  153. }
  154. }
  155. //
  156. // Message Map
  157. //
  158. BEGIN_MESSAGE_MAP(CW3DirPage, CInetPropertyPage)
  159. //{{AFX_MSG_MAP(CW3DirPage)
  160. ON_BN_CLICKED(IDC_CHECK_AUTHOR, OnCheckAuthor)
  161. ON_BN_CLICKED(IDC_CHECK_READ, OnCheckRead)
  162. ON_BN_CLICKED(IDC_CHECK_WRITE, OnCheckWrite)
  163. ON_BN_CLICKED(IDC_RADIO_DIR, OnRadioDir)
  164. ON_BN_CLICKED(IDC_RADIO_REDIRECT, OnRadioRedirect)
  165. ON_EN_CHANGE(IDC_EDIT_REDIRECT, OnItemChanged)
  166. ON_BN_CLICKED(IDC_CHECK_LOG_ACCESS, OnItemChanged)
  167. ON_BN_CLICKED(IDC_CHECK_DIRECTORY_BROWSING_ALLOWED, OnItemChanged)
  168. ON_BN_CLICKED(IDC_CHECK_INDEX, OnItemChanged)
  169. ON_BN_CLICKED(IDC_CHECK_CHILD, OnItemChanged)
  170. ON_BN_CLICKED(IDC_CHECK_EXACT, OnItemChanged)
  171. ON_BN_CLICKED(IDC_CHECK_PERMANENT, OnItemChanged)
  172. ON_BN_CLICKED(IDC_BUTTON_CREATE_REMOVE_APP, OnButtonCreateRemoveApp)
  173. ON_BN_CLICKED(IDC_BUTTON_UNLOAD_APP, OnButtonUnloadApp)
  174. ON_BN_CLICKED(IDC_APP_CONFIGURATION, OnButtonConfiguration)
  175. ON_CBN_SELCHANGE(IDC_COMBO_PERMISSIONS, OnSelchangeComboPermissions)
  176. ON_CBN_SELCHANGE(IDC_COMBO_PROCESS, OnSelchangeComboProcess)
  177. ON_EN_CHANGE(IDC_EDIT_APPLICATION, OnItemChanged)
  178. ON_WM_DESTROY()
  179. //}}AFX_MSG_MAP
  180. END_MESSAGE_MAP()
  181. void
  182. CW3DirPage::ChangeTypeTo(int nNewType)
  183. {
  184. int nOldType = m_nPathType;
  185. m_nPathType = nNewType;
  186. if (nOldType == m_nPathType)
  187. {
  188. return;
  189. }
  190. OnItemChanged();
  191. SetStateByType();
  192. int nID = -1;
  193. CEdit * pPath = NULL;
  194. LPCTSTR lpKeepPath = NULL;
  195. switch(m_nPathType)
  196. {
  197. case RADIO_DIRECTORY:
  198. break;
  199. case RADIO_REDIRECT:
  200. if (!m_strRedirectPath.IsEmpty())
  201. {
  202. //
  203. // The old path info is acceptable, propose it
  204. // as a default
  205. //
  206. lpKeepPath = m_strRedirectPath;
  207. }
  208. nID = IDS_REDIRECT_MASK;
  209. pPath = &m_edit_Redirect;
  210. break;
  211. default:
  212. ASSERT(FALSE);
  213. return;
  214. }
  215. //
  216. // Load mask resource, and display
  217. // this in the directory
  218. //
  219. if (pPath != NULL)
  220. {
  221. if (lpKeepPath != NULL)
  222. {
  223. pPath->SetWindowText(lpKeepPath);
  224. }
  225. else
  226. {
  227. CString str;
  228. VERIFY(str.LoadString(nID));
  229. pPath->SetWindowText(str);
  230. }
  231. pPath->SetSel(0,-1);
  232. pPath->SetFocus();
  233. }
  234. SetAuthoringState(FALSE);
  235. }
  236. void
  237. CW3DirPage::ShowControl(CWnd * pWnd, BOOL fShow)
  238. {
  239. ASSERT(pWnd != NULL);
  240. pWnd->EnableWindow(fShow);
  241. pWnd->ShowWindow(fShow ? SW_SHOW : SW_HIDE);
  242. }
  243. void
  244. CW3DirPage::SetStateByType()
  245. /*++
  246. Routine Description:
  247. Set the state of the dialog by the path type currently selected
  248. Arguments:
  249. None
  250. Return Value:
  251. None
  252. --*/
  253. {
  254. BOOL fShowDirFlags;
  255. BOOL fShowRedirectFlags;
  256. BOOL fShowScript;
  257. switch(m_nPathType)
  258. {
  259. case RADIO_DIRECTORY:
  260. ShowControl(&m_edit_Path, fShowDirFlags = TRUE);
  261. m_edit_Path.EnableWindow(FALSE);
  262. ShowControl(&m_edit_Redirect, fShowRedirectFlags = FALSE);
  263. fShowScript = TRUE;
  264. break;
  265. case RADIO_REDIRECT:
  266. ShowControl(&m_edit_Path, fShowDirFlags = FALSE);
  267. ShowControl(&m_edit_Redirect, fShowRedirectFlags = TRUE);
  268. fShowScript = FALSE;
  269. break;
  270. default:
  271. ASSERT(FALSE && "Invalid Selection");
  272. return;
  273. }
  274. ShowControl(IDC_CHECK_READ, fShowDirFlags);
  275. ShowControl(IDC_CHECK_WRITE, fShowDirFlags);
  276. ShowControl(IDC_CHECK_DIRECTORY_BROWSING_ALLOWED, fShowDirFlags);
  277. ShowControl(IDC_CHECK_INDEX, fShowDirFlags);
  278. ShowControl(IDC_CHECK_LOG_ACCESS, fShowDirFlags);
  279. ShowControl(IDC_CHECK_AUTHOR, fShowDirFlags);
  280. ShowControl(IDC_STATIC_DIRFLAGS_LARGE, fShowDirFlags);
  281. ShowControl(IDC_STATIC_APPLICATION_SETTINGS, fShowDirFlags);
  282. ShowControl(IDC_STATIC_APP_PROMPT, fShowDirFlags);
  283. ShowControl(&m_edit_AppFriendlyName, fShowDirFlags);
  284. ShowControl(IDC_STATIC_SP_PROMPT, fShowDirFlags);
  285. ShowControl(IDC_STATIC_PERMISSIONS, fShowDirFlags);
  286. ShowControl(IDC_COMBO_PERMISSIONS, fShowDirFlags);
  287. ShowControl(IDC_STATIC_PROTECTION, fShowDirFlags);
  288. ShowControl(IDC_COMBO_PROCESS, fShowDirFlags);
  289. ShowControl(IDC_BUTTON_CREATE_REMOVE_APP, fShowDirFlags);
  290. ShowControl(IDC_APP_CONFIGURATION, fShowDirFlags);
  291. ShowControl(IDC_BUTTON_UNLOAD_APP, fShowDirFlags);
  292. ShowControl(IDC_STATIC_STARTING_POINT, fShowDirFlags);
  293. ShowControl(IDC_STATIC_APPLICATIONS, fShowDirFlags);
  294. ShowControl(IDC_CHECK_EXACT, fShowRedirectFlags);
  295. ShowControl(IDC_CHECK_CHILD, fShowRedirectFlags);
  296. ShowControl(IDC_CHECK_PERMANENT, fShowRedirectFlags);
  297. ShowControl(IDC_STATIC_REDIRECT_PROMPT, fShowRedirectFlags);
  298. ShowControl(IDC_STATIC_REDIRFLAGS, fShowRedirectFlags);
  299. ShowControl(&m_check_Author, fShowScript);
  300. //
  301. // Enable/Disable must come after the showcontrols
  302. //
  303. m_static_PathPrompt.SetWindowText(m_strPrompt[m_nPathType]);
  304. SetApplicationState();
  305. }
  306. void
  307. CW3DirPage::SaveAuthoringState()
  308. {
  309. if (m_check_Write.m_hWnd)
  310. {
  311. //
  312. // Controls initialized -- store live data
  313. //
  314. m_fOriginalWrite = m_check_Write.GetCheck() > 0;
  315. m_fOriginalRead = m_check_Read.GetCheck() > 0;
  316. }
  317. else
  318. {
  319. //
  320. // Controls not yet initialized, store original data
  321. //
  322. m_fOriginalWrite = m_fWrite;
  323. m_fOriginalRead = m_fRead;
  324. }
  325. }
  326. void
  327. CW3DirPage::RestoreAuthoringState()
  328. {
  329. m_fWrite = m_fOriginalWrite;
  330. m_fRead = m_fOriginalRead;
  331. }
  332. void
  333. CW3DirPage::SetAuthoringState(BOOL fAlterReadAndWrite)
  334. {
  335. if (fAlterReadAndWrite)
  336. {
  337. if (m_fAuthor)
  338. {
  339. //
  340. // Remember previous setting to undo
  341. // this thing.
  342. //
  343. SaveAuthoringState();
  344. m_fRead = m_fWrite = TRUE;
  345. }
  346. else
  347. {
  348. //
  349. // Restore previous defaults
  350. //
  351. RestoreAuthoringState();
  352. }
  353. m_check_Read.SetCheck(m_fRead);
  354. m_check_Write.SetCheck(m_fWrite);
  355. }
  356. m_check_Author.EnableWindow((m_fRead || m_fWrite)
  357. && HasAdminAccess()
  358. );
  359. // m_check_Read.EnableWindow(!m_fAuthor && HasAdminAccess());
  360. // m_check_Write.EnableWindow(!m_fAuthor && HasAdminAccess());
  361. }
  362. void
  363. CW3DirPage::SetPathType()
  364. {
  365. if (!m_strRedirectPath.IsEmpty())
  366. {
  367. m_nPathType = RADIO_REDIRECT;
  368. m_radio_Dir.SetCheck(0);
  369. m_radio_Redirect.SetCheck(1);
  370. }
  371. else
  372. {
  373. m_nPathType = RADIO_DIRECTORY;
  374. m_radio_Redirect.SetCheck(0);
  375. m_radio_Dir.SetCheck(1);
  376. }
  377. m_static_PathPrompt.SetWindowText(m_strPrompt[m_nPathType]);
  378. }
  379. //
  380. // Message Handlers
  381. //
  382. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  383. void
  384. CW3DirPage::OnItemChanged()
  385. {
  386. if (m_fRecordChanges)
  387. {
  388. SetModified(TRUE);
  389. }
  390. }
  391. BOOL
  392. CW3DirPage::OnInitDialog()
  393. {
  394. CInetPropertyPage::OnInitDialog();
  395. m_fCompatibilityMode = ((CW3Sheet *)GetSheet())->InCompatibilityMode();
  396. // Disable/hide irrelevant items
  397. GetDlgItem(IDC_RADIO_UNC)->EnableWindow(FALSE);
  398. ShowControl(GetDlgItem(IDC_BUTTON_CONNECT_AS), FALSE);
  399. ShowControl(GetDlgItem(IDC_BUTTON_BROWSE), FALSE);
  400. ShowControl(GetDlgItem(IDC_STATIC_DIRFLAGS_SMALL), FALSE);
  401. // Set appropriate prompt
  402. CString str;
  403. VERIFY(str.LoadString(IDS_RADIO_DIR));
  404. m_radio_Dir.SetWindowText(str);
  405. //
  406. // Fill permissions combo box.
  407. //
  408. AddStringToComboBox(m_combo_Permissions, IDS_PERMISSIONS_NONE);
  409. AddStringToComboBox(m_combo_Permissions, IDS_PERMISSIONS_SCRIPT);
  410. AddStringToComboBox(m_combo_Permissions, IDS_PERMISSIONS_EXECUTE);
  411. m_combo_Permissions.SetCurSel(m_nPermissions);
  412. ASSERT(m_pApplication != NULL);
  413. if (m_fCompatibilityMode)
  414. {
  415. m_nSelInProc = AddStringToComboBox(m_combo_Process, IDS_COMBO_INPROC);
  416. if (m_pApplication->SupportsPooledProc())
  417. {
  418. m_nSelPooledProc = AddStringToComboBox(m_combo_Process, IDS_COMBO_POOLEDPROC);
  419. }
  420. else
  421. {
  422. m_nSelPooledProc = -1; // N/A
  423. }
  424. m_nSelOutOfProc = AddStringToComboBox(m_combo_Process, IDS_COMBO_OUTPROC);
  425. }
  426. else
  427. {
  428. CString buf;
  429. buf.LoadString(IDS_APPLICATION_POOL);
  430. m_static_ProtectionPrompt.SetWindowText(buf);
  431. CStringListEx pools;
  432. CError err = ((CW3Sheet *)GetSheet())->EnumAppPools(pools);
  433. int idx_sel = CB_ERR;
  434. int idx_def = CB_ERR;
  435. if (err.Succeeded())
  436. {
  437. ASSERT(pools.GetCount() > 0);
  438. POSITION pos = pools.GetHeadPosition();
  439. CString pool_id;
  440. while (pos != NULL)
  441. {
  442. pool_id = pools.GetNext(pos);
  443. int idx = m_combo_Process.AddString(pool_id);
  444. if (0 == m_pApplication->m_strAppPoolId.CompareNoCase(pool_id))
  445. {
  446. idx_sel = idx;
  447. }
  448. if (0 == buf.CompareNoCase(pool_id))
  449. {
  450. idx_def = idx;
  451. }
  452. }
  453. }
  454. // select the app pool which has an id the same as in current application
  455. // It could be new app created in compatibility mode, no app pool is default app pool
  456. if (CB_ERR == idx_sel)
  457. {
  458. if (m_pApplication->m_strAppPoolId.IsEmpty())
  459. {
  460. idx_sel = idx_def;
  461. }
  462. else
  463. {
  464. CString str;
  465. str.LoadString(IDS_INVALID_POOL_ID);
  466. m_combo_Process.InsertString(0, str);
  467. idx_sel = 0;
  468. }
  469. }
  470. m_combo_Process.SetCurSel(idx_sel);
  471. }
  472. // It is enough to set file alias once -- we cannot change it here
  473. CString buf1, buf2, strAlias;
  474. CMetabasePath::GetRootPath(m_strFullMetaPath, buf1, &buf2);
  475. strAlias = _T("\\");
  476. strAlias += buf2;
  477. CvtPathToDosStyle(strAlias);
  478. m_edit_Path.SetWindowText(strAlias);
  479. SetPathType();
  480. SetStateByType();
  481. SetAuthoringState(FALSE);
  482. #ifdef SUPPORT_SLASH_SLASH_QUESTIONMARK_SLASH_TYPE_PATHS
  483. LimitInputPath(CONTROL_HWND(IDC_EDIT_PATH),TRUE);
  484. #else
  485. LimitInputPath(CONTROL_HWND(IDC_EDIT_PATH),FALSE);
  486. #endif
  487. return TRUE;
  488. }
  489. void
  490. CW3DirPage::OnDestroy()
  491. {
  492. //int count = m_combo_Process.GetCount();
  493. //if (count != CB_ERR)
  494. //{
  495. // for (int i = 0; i < count; i++)
  496. // {
  497. // void * p = m_combo_Process.GetItemDataPtr(i);
  498. // LocalFree(p);
  499. // m_combo_Process.SetItemDataPtr(i, NULL);
  500. // }
  501. //}
  502. }
  503. /* virtual */
  504. HRESULT
  505. CW3DirPage::FetchLoadedValues()
  506. {
  507. CError err;
  508. BEGIN_META_DIR_READ(CW3Sheet)
  509. //
  510. // Use m_ notation because the message crackers require it
  511. //
  512. BOOL m_fDontLog;
  513. FETCH_DIR_DATA_FROM_SHEET(m_strFullMetaPath);
  514. FETCH_DIR_DATA_FROM_SHEET(m_strRedirectPath);
  515. FETCH_DIR_DATA_FROM_SHEET(m_dwAccessPerms);
  516. FETCH_DIR_DATA_FROM_SHEET(m_dwDirBrowsing);
  517. FETCH_DIR_DATA_FROM_SHEET(m_fDontLog);
  518. FETCH_DIR_DATA_FROM_SHEET(m_fIndexed);
  519. FETCH_DIR_DATA_FROM_SHEET(m_fExact);
  520. FETCH_DIR_DATA_FROM_SHEET(m_fChild);
  521. FETCH_DIR_DATA_FROM_SHEET(m_fPermanent);
  522. m_fRead = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_READ);
  523. m_fWrite = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_WRITE);
  524. m_fAuthor = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_SOURCE);
  525. m_fBrowsingAllowed = IS_FLAG_SET(m_dwDirBrowsing, MD_DIRBROW_ENABLED);
  526. m_fLogAccess = !m_fDontLog;
  527. SaveAuthoringState();
  528. if (!m_fIsAppRoot)
  529. {
  530. m_dwAppState = APPSTATUS_NOTDEFINED;
  531. }
  532. FETCH_DIR_DATA_FROM_SHEET(m_strUserName);
  533. FETCH_DIR_DATA_FROM_SHEET_PASSWORD(m_strPassword);
  534. FETCH_DIR_DATA_FROM_SHEET(m_strAlias);
  535. END_META_DIR_READ(err)
  536. m_nPermissions = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_EXECUTE)
  537. ? COMBO_EXECUTE : IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_SCRIPT)
  538. ? COMBO_SCRIPT : COMBO_NONE;
  539. BeginWaitCursor();
  540. m_pApplication = new CIISApplication(QueryAuthInfo(), QueryMetaPath());
  541. err = m_pApplication != NULL
  542. ? m_pApplication->QueryResult() : ERROR_NOT_ENOUGH_MEMORY;
  543. if (err.Win32Error() == ERROR_PATH_NOT_FOUND)
  544. {
  545. //
  546. // No app information; that's ok in cases of file system directories
  547. // that don't exist in the metabase yet.
  548. //
  549. err.Reset();
  550. }
  551. if (err.Succeeded())
  552. {
  553. //
  554. // CODEWORK: RefreshAppState should be split up into two
  555. // different methods: one that fetches the data, and one
  556. // that moves the data to the UI controls on this page.
  557. //
  558. RefreshAppState();
  559. }
  560. EndWaitCursor();
  561. return err;
  562. }
  563. DWORD
  564. CW3DirPage::GetAppStateFromComboSelection() const
  565. /*++
  566. Routine Description:
  567. Get the app state DWORD that coresponds to the current combo
  568. box list selection
  569. Arguments:
  570. None
  571. Return Value:
  572. App state DWORD or 0xffffffff;
  573. --*/
  574. {
  575. int nSel = m_combo_Process.GetCurSel();
  576. if (nSel == m_nSelOutOfProc)
  577. {
  578. return CWamInterface::APP_OUTOFPROC;
  579. }
  580. if (nSel == m_nSelPooledProc)
  581. {
  582. ASSERT(m_pApplication->SupportsPooledProc());
  583. return CWamInterface::APP_POOLEDPROC;
  584. }
  585. if (nSel == m_nSelInProc)
  586. {
  587. return CWamInterface::APP_INPROC;
  588. }
  589. ASSERT(FALSE && "Invalid application state");
  590. return 0xffffffff;
  591. }
  592. /* virtual */
  593. HRESULT
  594. CW3DirPage::SaveInfo()
  595. {
  596. ASSERT(IsDirty());
  597. CError err;
  598. SET_FLAG_IF(m_fBrowsingAllowed, m_dwDirBrowsing, MD_DIRBROW_ENABLED);
  599. SET_FLAG_IF(m_fRead, m_dwAccessPerms, MD_ACCESS_READ);
  600. SET_FLAG_IF(m_fWrite, m_dwAccessPerms, MD_ACCESS_WRITE);
  601. SET_FLAG_IF(m_fAuthor, m_dwAccessPerms, MD_ACCESS_SOURCE);
  602. SET_FLAG_IF((m_nPermissions == COMBO_EXECUTE), m_dwAccessPerms, MD_ACCESS_EXECUTE);
  603. //
  604. // script is set on EXECUTE as well "Execute (including script)"
  605. //
  606. SET_FLAG_IF(((m_nPermissions == COMBO_SCRIPT) || (m_nPermissions == COMBO_EXECUTE)),
  607. m_dwAccessPerms, MD_ACCESS_SCRIPT);
  608. BOOL m_fDontLog = !m_fLogAccess;
  609. BOOL bRedirectDirty = FALSE;
  610. BeginWaitCursor();
  611. if (m_fCompatibilityMode)
  612. {
  613. DWORD dwAppProtection = GetAppStateFromComboSelection();
  614. if (dwAppProtection != m_dwAppProtection && m_fAppEnabled)
  615. {
  616. //
  617. // Isolation state has changed; recreate the application
  618. //
  619. CError err2(m_pApplication->RefreshAppState());
  620. if (err2.Succeeded())
  621. {
  622. err2 = m_pApplication->Create(m_strAppFriendlyName, dwAppProtection);
  623. //
  624. // Remember the new state, so we don't do this again
  625. // the next time the guy hits "apply"
  626. //
  627. if (err2.Succeeded())
  628. {
  629. m_dwAppProtection = dwAppProtection;
  630. }
  631. }
  632. err2.MessageBoxOnFailure(m_hWnd);
  633. }
  634. }
  635. BEGIN_META_DIR_WRITE(CW3Sheet)
  636. INIT_DIR_DATA_MASK(m_dwAccessPerms, m_dwBitRangePermissions)
  637. INIT_DIR_DATA_MASK(m_dwDirBrowsing, m_dwBitRangeDirBrowsing)
  638. STORE_DIR_DATA_ON_SHEET(m_fDontLog)
  639. STORE_DIR_DATA_ON_SHEET(m_fIndexed)
  640. STORE_DIR_DATA_ON_SHEET(m_fChild);
  641. STORE_DIR_DATA_ON_SHEET(m_fExact);
  642. STORE_DIR_DATA_ON_SHEET(m_fPermanent);
  643. //
  644. // CODEWORK: Not an elegant solution
  645. //
  646. if (m_nPathType == RADIO_REDIRECT)
  647. {
  648. bRedirectDirty =
  649. pSheet->GetDirectoryProperties().m_strRedirectPath.CompareNoCase(m_strRedirectPath) != 0;
  650. pSheet->GetDirectoryProperties().MarkRedirAsInherit(!m_fChild);
  651. STORE_DIR_DATA_ON_SHEET(m_strRedirectPath)
  652. }
  653. else
  654. {
  655. CString buf = m_strRedirectPath;
  656. m_strRedirectPath.Empty();
  657. bRedirectDirty = pSheet->GetDirectoryProperties().m_strRedirectPath.CompareNoCase(m_strRedirectPath) != 0;
  658. STORE_DIR_DATA_ON_SHEET(m_strRedirectPath)
  659. m_strRedirectPath = buf;
  660. }
  661. STORE_DIR_DATA_ON_SHEET(m_dwAccessPerms)
  662. STORE_DIR_DATA_ON_SHEET(m_dwDirBrowsing)
  663. END_META_DIR_WRITE(err)
  664. if (err.Succeeded() && m_pApplication->IsEnabledApplication())
  665. {
  666. CString OldFriendlyName;
  667. OldFriendlyName = m_pApplication->m_strFriendlyName;
  668. err = m_pApplication->WriteFriendlyName(m_strAppFriendlyName);
  669. if (!m_fCompatibilityMode)
  670. {
  671. INT iRefreshMMCObjects = 0;
  672. // get app pool id from the combo,
  673. // check if it was changed and reassign to application
  674. // get app pool id from the combo,
  675. // check if it was changed and reassign to application
  676. CString id, idOld;
  677. int idx = m_combo_Process.GetCurSel();
  678. ASSERT(idx != CB_ERR);
  679. m_combo_Process.GetLBText(idx, id);
  680. idOld = m_pApplication->m_strAppPoolId;
  681. m_pApplication->WritePoolId(id);
  682. if (0 != idOld.CompareNoCase(id))
  683. {
  684. iRefreshMMCObjects = 1;
  685. } else if (0 != OldFriendlyName.Compare(m_strAppFriendlyName))
  686. {
  687. iRefreshMMCObjects = 2;
  688. }
  689. // Refresh the applications node in the MMC...
  690. if (iRefreshMMCObjects)
  691. {
  692. CIISMBNode * pNode = (CIISMBNode *) GetSheet()->GetParameter();
  693. if (pNode)
  694. {
  695. // this CAppPoolsContainer will only be here if it's iis6
  696. CIISMachine * pOwner = pNode->GetOwner();
  697. if (pOwner)
  698. {
  699. CAppPoolsContainer * pPools = pOwner->QueryAppPoolsContainer();
  700. if (pPools)
  701. {
  702. if (pPools->IsExpanded())
  703. {
  704. pPools->RefreshData();
  705. if (1 == iRefreshMMCObjects)
  706. {
  707. // refresh the old AppID, because this one needs to be removed
  708. pPools->RefreshDataChildren(idOld,FALSE);
  709. // fresh the new AppID, this one needs to be added
  710. pPools->RefreshDataChildren(id,FALSE);
  711. }
  712. else
  713. {
  714. // friendly name changed
  715. pPools->RefreshDataChildren(id,FALSE);
  716. }
  717. }
  718. }
  719. }
  720. }
  721. }
  722. }
  723. }
  724. if (err.Succeeded())
  725. {
  726. SaveAuthoringState();
  727. err = ((CW3Sheet *)GetSheet())->SetKeyType();
  728. NotifyMMC( bRedirectDirty ? PROP_CHANGE_REENUM_FILES //|PROP_CHANGE_REENUM_VDIR
  729. : PROP_CHANGE_DISPLAY_ONLY);
  730. }
  731. EndWaitCursor();
  732. return err;
  733. }
  734. void
  735. CW3DirPage::RefreshAppState()
  736. {
  737. ASSERT(m_pApplication != NULL);
  738. CError err(m_pApplication->RefreshAppState());
  739. if (err.Failed())
  740. {
  741. m_dwAppState = APPSTATUS_NOTDEFINED;
  742. if (err.Win32Error() == ERROR_PATH_NOT_FOUND)
  743. {
  744. //
  745. // Ignore this error, it really just means the path
  746. // doesn't exist in the metabase, which is true for most
  747. // file and directory properties, and not an error
  748. // condition.
  749. //
  750. err.Reset();
  751. }
  752. }
  753. else
  754. {
  755. m_dwAppState = m_pApplication->QueryAppState();
  756. }
  757. if (err.Succeeded())
  758. {
  759. //
  760. // Get metabase information
  761. //
  762. m_strAppRoot = m_pApplication->m_strAppRoot;
  763. m_dwAppProtection = m_pApplication->m_dwProcessProtection;
  764. m_strAppFriendlyName = m_pApplication->m_strFriendlyName;
  765. m_fIsAppRoot
  766. = (m_strFullMetaPath.CompareNoCase(m_strAppRoot) == 0);
  767. }
  768. else
  769. {
  770. //
  771. // Display error information
  772. //
  773. err.MessageBoxFormat(m_hWnd, IDS_ERR_APP, MB_OK, NO_HELP_CONTEXT);
  774. }
  775. }
  776. CString&
  777. CW3DirPage::FriendlyAppRoot(LPCTSTR lpAppRoot, CString& strFriendly)
  778. {
  779. if (lpAppRoot != NULL && *lpAppRoot != 0)
  780. {
  781. strFriendly.Empty();
  782. CInstanceProps prop(QueryAuthInfo(), lpAppRoot);
  783. HRESULT hr = prop.LoadData();
  784. if (SUCCEEDED(hr))
  785. {
  786. CString root, tail;
  787. strFriendly.Format(m_strWebFmt, prop.GetDisplayText(root));
  788. CMetabasePath::GetRootPath(lpAppRoot, root, &tail);
  789. if (!tail.IsEmpty())
  790. {
  791. //
  792. // Add rest of dir path
  793. //
  794. strFriendly += _T("/");
  795. strFriendly += tail;
  796. }
  797. //
  798. // Now change forward slashes in the path to backward slashes
  799. //
  800. CvtPathToDosStyle(strFriendly);
  801. return strFriendly;
  802. }
  803. }
  804. //
  805. // Bogus
  806. //
  807. VERIFY(strFriendly.LoadString(IDS_APPROOT_UNKNOWN));
  808. return strFriendly;
  809. }
  810. void
  811. CW3DirPage::SetApplicationState()
  812. {
  813. //
  814. // SetWindowText causes a dirty marker
  815. //
  816. BOOL fOld = m_fRecordChanges;
  817. m_fRecordChanges = FALSE;
  818. m_fAppEnabled = FALSE;
  819. if (m_pApplication != NULL)
  820. {
  821. m_pApplication->RefreshAppState();
  822. m_fAppEnabled = m_fIsAppRoot && m_pApplication->IsEnabledApplication();
  823. }
  824. BOOL fVisible = m_nPathType == RADIO_DIRECTORY;
  825. m_button_CreateRemove.EnableWindow(fVisible && HasAdminAccess());
  826. m_button_CreateRemove.SetWindowText(m_fAppEnabled ? m_strRemove : m_strCreate);
  827. m_static_ProtectionPrompt.EnableWindow(fVisible && m_fAppEnabled && HasAdminAccess());
  828. if (m_fCompatibilityMode)
  829. {
  830. //
  831. // Set selection in combo box to match current app state
  832. //
  833. int nSel = -1;
  834. switch(m_dwAppProtection)
  835. {
  836. case CWamInterface::APP_INPROC:
  837. nSel = m_nSelInProc;
  838. break;
  839. case CWamInterface::APP_POOLEDPROC:
  840. ASSERT(m_pApplication->SupportsPooledProc());
  841. nSel = m_nSelPooledProc;
  842. break;
  843. case CWamInterface::APP_OUTOFPROC:
  844. nSel = m_nSelOutOfProc;
  845. break;
  846. default:
  847. ASSERT("Bogus app protection level");
  848. }
  849. ASSERT(nSel >= 0);
  850. m_combo_Process.SetCurSel(nSel);
  851. }
  852. else
  853. {
  854. // Set selection in combo box to match current app
  855. CString strOurEntry = m_pApplication->m_strAppPoolId;
  856. CString strCurrentSelection;
  857. int idx = m_combo_Process.GetCurSel();
  858. ASSERT(idx != CB_ERR);
  859. m_combo_Process.GetLBText(idx, strCurrentSelection);
  860. if (0 != strOurEntry.CompareNoCase(strCurrentSelection))
  861. {
  862. // it's not pointing to our AppPoolID
  863. // loop thru the combo box to make sure it points to our AppPoolID.
  864. if ((idx = m_combo_Process.FindString(-1, strOurEntry)) == LB_ERR)
  865. {
  866. CString strBadPoolID;
  867. strBadPoolID.LoadString(IDS_INVALID_POOL_ID);
  868. if ((idx = m_combo_Process.FindString(-1, strBadPoolID)) == LB_ERR)
  869. {
  870. // could not find this "invalid pool" entry
  871. // let's add it and select it.
  872. m_combo_Process.InsertString(0, strBadPoolID);
  873. idx = 0;
  874. }
  875. }
  876. }
  877. m_combo_Process.SetCurSel(idx);
  878. }
  879. m_combo_Process.EnableWindow(fVisible && m_fAppEnabled && HasAdminAccess());
  880. GetDlgItem(IDC_STATIC_PERMISSIONS)->EnableWindow(fVisible && HasAdminAccess());
  881. m_combo_Permissions.EnableWindow(fVisible && HasAdminAccess());
  882. GetDlgItem(IDC_STATIC_APP_PROMPT)->EnableWindow(fVisible && m_fIsAppRoot && HasAdminAccess());
  883. m_edit_AppFriendlyName.EnableWindow(fVisible && m_fIsAppRoot && HasAdminAccess());
  884. m_button_Configuration.EnableWindow(fVisible && m_fAppEnabled);
  885. //
  886. // Write out the verbose starting point.
  887. //
  888. CString str;
  889. FriendlyAppRoot(m_strAppRoot, str);
  890. CWnd * pWnd = CWnd::FromHandle(GetDlgItem(IDC_STATIC_STARTING_POINT)->m_hWnd);
  891. FitPathToControl(*pWnd, str, FALSE);
  892. m_edit_AppFriendlyName.SetWindowText(m_strAppFriendlyName);
  893. m_button_Unload.EnableWindow(fVisible && m_dwAppState == APPSTATUS_RUNNING);
  894. //
  895. // Restore (see note on top)
  896. //
  897. m_fRecordChanges = fOld;
  898. }
  899. void
  900. CW3DirPage::OnCheckRead()
  901. {
  902. m_fRead = !m_fRead;
  903. SetAuthoringState(FALSE);
  904. OnItemChanged();
  905. }
  906. void
  907. CW3DirPage::OnCheckWrite()
  908. {
  909. m_fWrite = !m_fWrite;
  910. if (!CheckWriteAndExecWarning())
  911. {
  912. //
  913. // Undo
  914. //
  915. m_fWrite = FALSE;
  916. m_check_Write.SetCheck(m_fWrite);
  917. }
  918. else
  919. {
  920. SetAuthoringState(FALSE);
  921. OnItemChanged();
  922. }
  923. }
  924. void
  925. CW3DirPage::OnCheckAuthor()
  926. {
  927. m_fAuthor = !m_fAuthor;
  928. SetAuthoringState(FALSE);
  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::OnRadioDir()
  940. {
  941. ChangeTypeTo(RADIO_DIRECTORY);
  942. }
  943. void
  944. CW3DirPage::OnRadioRedirect()
  945. {
  946. ChangeTypeTo(RADIO_REDIRECT);
  947. }
  948. void
  949. CW3DirPage::OnButtonCreateRemoveApp()
  950. {
  951. BeginWaitCursor();
  952. CError err(m_pApplication->RefreshAppState());
  953. if (m_fAppEnabled)
  954. {
  955. //
  956. // App currently exists -- delete it
  957. //
  958. err = m_pApplication->Delete();
  959. }
  960. else
  961. {
  962. CString strAppName = m_strAlias;
  963. DWORD dwAppProtState =
  964. m_pApplication->SupportsPooledProc() ?
  965. CWamInterface::APP_POOLEDPROC : CWamInterface::APP_INPROC;
  966. if (m_fCompatibilityMode)
  967. {
  968. //
  969. // Attempt to create a pooled-proc by default; failing
  970. // that if it's not supported, create it in proc
  971. //
  972. err = m_pApplication->Create(strAppName, dwAppProtState);
  973. }
  974. else
  975. {
  976. CString pool;
  977. err = ((CW3Sheet *)GetSheet())->QueryDefaultPoolId(pool);
  978. if (err.Succeeded())
  979. {
  980. err = m_pApplication->CreatePooled(strAppName, dwAppProtState, pool, FALSE);
  981. }
  982. }
  983. }
  984. if (err.Succeeded())
  985. {
  986. RefreshAppState();
  987. NotifyMMC(PROP_CHANGE_DISPLAY_ONLY);
  988. GetSheet()->NotifyMMC();
  989. }
  990. //
  991. // Move app data to the controls
  992. //
  993. UpdateData(FALSE);
  994. EndWaitCursor();
  995. ASSERT(err.Succeeded());
  996. err.MessageBoxOnFailure(m_hWnd);
  997. if (err.Succeeded())
  998. {
  999. SetApplicationState();
  1000. // Don't set this because Creating/Removing App
  1001. // already committed the changes...
  1002. // we need to write the KeyType out
  1003. ((CW3Sheet *)GetSheet())->SetKeyType();
  1004. // nope, we need this to write the KeyType out
  1005. //OnItemChanged();
  1006. }
  1007. // SetApplicationState will enable/disable
  1008. // a lot of controls, make sure we are on a control
  1009. // that is enabled. if we are on a control which is not enabled
  1010. // then user will lose ability to use hotkeys.
  1011. if (!::GetFocus())
  1012. {
  1013. m_button_CreateRemove.SetFocus();
  1014. }
  1015. }
  1016. extern HRESULT
  1017. AppConfigSheet(CIISMBNode * pNode, CIISMBNode * pNodeParent, LPCTSTR metapath, CWnd * pParent);
  1018. void
  1019. CW3DirPage::OnButtonConfiguration()
  1020. /*++
  1021. Routine Description:
  1022. Pass on "configuration" button click to the ocx.
  1023. Arguments:
  1024. None
  1025. Return Value:
  1026. None
  1027. --*/
  1028. {
  1029. CIISMBNode * pTheObject = (CIISMBNode *) GetSheet()->GetParameter();
  1030. if (pTheObject)
  1031. {
  1032. CError err = AppConfigSheet(
  1033. pTheObject,
  1034. pTheObject->GetParentNode(),
  1035. QueryMetaPath(),
  1036. this
  1037. );
  1038. }
  1039. }
  1040. void
  1041. CW3DirPage::OnSelchangeComboProcess()
  1042. {
  1043. OnItemChanged();
  1044. }
  1045. void
  1046. CW3DirPage::OnSelchangeComboPermissions()
  1047. {
  1048. m_nPermissions = m_combo_Permissions.GetCurSel();
  1049. ASSERT(m_nPermissions >= COMBO_NONE && m_nPermissions <= COMBO_EXECUTE);
  1050. if (!CheckWriteAndExecWarning())
  1051. {
  1052. //
  1053. // Undo -- set script instead
  1054. //
  1055. m_combo_Permissions.SetCurSel(m_nPermissions = COMBO_SCRIPT);
  1056. }
  1057. OnItemChanged();
  1058. }
  1059. void
  1060. CW3DirPage::OnButtonUnloadApp()
  1061. {
  1062. }
  1063. BOOL
  1064. CW3DirPage::CheckWriteAndExecWarning()
  1065. {
  1066. if (m_nPermissions == COMBO_EXECUTE && m_fWrite)
  1067. {
  1068. if (::AfxMessageBox(IDS_WRN_WRITE_EXEC, MB_YESNO | MB_DEFBUTTON2 ) != IDYES)
  1069. {
  1070. return FALSE;
  1071. }
  1072. }
  1073. OnItemChanged();
  1074. return TRUE;
  1075. }