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.

322 lines
8.3 KiB

  1. /*++
  2. Copyright (c) 1994-2000 Microsoft Corporation
  3. Module Name :
  4. app_app_pool.cpp
  5. Abstract:
  6. Add new IIS Application Pool node
  7. Author:
  8. Sergei Antonov (sergeia)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. 12/26/2000 sergeia Initial creation
  13. --*/
  14. #include "stdafx.h"
  15. #include "common.h"
  16. #include "resource.h"
  17. #include "inetprop.h"
  18. #include "InetMgrApp.h"
  19. #include "iisobj.h"
  20. #include "add_app_pool.h"
  21. #include "shts.h"
  22. #include "app_sheet.h"
  23. #include "app_pool_sheet.h"
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char BASED_CODE THIS_FILE[] = __FILE__;
  27. #endif
  28. #define new DEBUG_NEW
  29. extern CInetmgrApp theApp;
  30. CAddAppPoolDlg::CAddAppPoolDlg(
  31. CAppPoolsContainer * pCont,
  32. CPoolList * pools,
  33. CWnd * pParent)
  34. : CDialog(CAddAppPoolDlg::IDD, pParent),
  35. m_pCont(pCont),
  36. m_pool_list(pools),
  37. m_fUseMaster(TRUE)
  38. {
  39. }
  40. CAddAppPoolDlg::~CAddAppPoolDlg()
  41. {
  42. }
  43. void
  44. CAddAppPoolDlg::DoDataExchange(CDataExchange * pDX)
  45. {
  46. CDialog::DoDataExchange(pDX);
  47. //{{AFX_DATA_MAP(CAddAppPoolDlg)
  48. DDX_Control(pDX, IDC_EDIT_POOL_ID, m_edit_PoolId);
  49. DDX_Control(pDX, IDC_USE_MASTER, m_button_UseMaster);
  50. DDX_Control(pDX, IDC_USE_POOL, m_button_UsePool);
  51. DDX_Control(pDX, IDC_POOLS, m_combo_Pool);
  52. DDX_CBIndex(pDX, IDC_POOLS, m_PoolIdx);
  53. //}}AFX_DATA_MAP
  54. DDX_Text(pDX, IDC_EDIT_POOL_ID, m_strPoolId);
  55. if (pDX->m_bSaveAndValidate)
  56. {
  57. TCHAR bad_chars[] = _T("\\/");
  58. if (m_strPoolId.GetLength() != _tcscspn(m_strPoolId, bad_chars))
  59. {
  60. DDV_ShowBalloonAndFail(pDX, IDS_ERR_INVALID_POOLID_CHARS);
  61. }
  62. // bug:629607 don't do this check htere
  63. // check that pool id is unique
  64. //if (!IsUniqueId(m_strPoolId)){DDV_ShowBalloonAndFail(pDX, IDS_ERR_DUP_POOLID);}
  65. }
  66. }
  67. void
  68. CAddAppPoolDlg::OnOK()
  69. {
  70. if (UpdateData(TRUE))
  71. {
  72. // bug:629607 do this check htere
  73. if (!IsUniqueId(m_strPoolId,TRUE))
  74. {
  75. //::AfxMessageBox(IDS_ERR_DUP_POOLID,MB_ICONEXCLAMATION);
  76. DoHelpMessageBox(m_hWnd,IDS_ERR_DUP_POOLID, MB_APPLMODAL | MB_OK | MB_ICONEXCLAMATION, 0);
  77. }
  78. else
  79. {
  80. CDialog::OnOK();
  81. }
  82. }
  83. }
  84. //
  85. // Message Map
  86. //
  87. BEGIN_MESSAGE_MAP(CAddAppPoolDlg, CDialog)
  88. //{{AFX_MSG_MAP(CAddAppPoolDlg)
  89. ON_BN_CLICKED(IDC_USE_MASTER, OnButtonUseMaster)
  90. ON_BN_CLICKED(IDC_USE_POOL, OnButtonUsePool)
  91. ON_BN_CLICKED(ID_HELP, OnHelp)
  92. ON_EN_CHANGE(IDC_EDIT_POOL_ID, OnItemChanged)
  93. ON_CBN_SELCHANGE(IDC_POOLS, OnItemChanged)
  94. //}}AFX_MSG_MAP
  95. END_MESSAGE_MAP()
  96. void
  97. CAddAppPoolDlg::OnItemChanged()
  98. {
  99. SetControlStates();
  100. }
  101. void
  102. CAddAppPoolDlg::OnButtonUseMaster()
  103. {
  104. m_fUseMaster = TRUE;
  105. SetControlStates();
  106. }
  107. void
  108. CAddAppPoolDlg::OnButtonUsePool()
  109. {
  110. m_fUseMaster = FALSE;
  111. SetControlStates();
  112. }
  113. void
  114. CAddAppPoolDlg::SetControlStates()
  115. {
  116. m_button_UseMaster.SetCheck(m_fUseMaster);
  117. m_button_UsePool.SetCheck(!m_fUseMaster);
  118. m_combo_Pool.EnableWindow(!m_fUseMaster);
  119. UpdateData();
  120. BOOL fGoodData =
  121. !m_strPoolId.IsEmpty()
  122. && IsUniqueId(m_strPoolId, FALSE);
  123. GetDlgItem(IDOK)->EnableWindow(fGoodData);
  124. }
  125. BOOL
  126. CAddAppPoolDlg::OnInitDialog()
  127. {
  128. CDialog::OnInitDialog();
  129. CString def_pool;
  130. m_pCont->QueryDefaultPoolId(def_pool);
  131. CAppPoolNode * pDefPool = NULL;
  132. POSITION pos = m_pool_list->GetHeadPosition();
  133. int sel_idx = 0;
  134. while (pos != NULL)
  135. {
  136. CAppPoolNode * pPool = m_pool_list->GetNext(pos);
  137. int i = m_combo_Pool.AddString(pPool->QueryDisplayName());
  138. if (def_pool.CompareNoCase(pPool->QueryNodeName()) == 0)
  139. {
  140. sel_idx = i;
  141. pDefPool = pPool;
  142. }
  143. if (i != CB_ERR)
  144. {
  145. m_combo_Pool.SetItemDataPtr(i, pPool);
  146. }
  147. }
  148. m_combo_Pool.SetCurSel(sel_idx);
  149. m_strPoolId.LoadString(IDS_DEFAULT_APP_POOL);
  150. MakeUniquePoolId(m_strPoolId);
  151. UpdateData(FALSE);
  152. SetControlStates();
  153. return TRUE;
  154. }
  155. BOOL
  156. CAddAppPoolDlg::IsUniqueId(CString& id, BOOL bCheckMetabase)
  157. {
  158. BOOL bRes = TRUE;
  159. POSITION pos = m_pool_list->GetHeadPosition();
  160. while (pos != NULL)
  161. {
  162. CAppPoolNode * pPool = m_pool_list->GetNext(pos);
  163. if (id.CompareNoCase(pPool->QueryNodeName()) == 0)
  164. {
  165. bRes = FALSE;
  166. break;
  167. }
  168. }
  169. // check the metabase when asked to.
  170. if (bRes)
  171. {
  172. if (bCheckMetabase)
  173. {
  174. if (m_pCont)
  175. {
  176. CComBSTR cont_path;
  177. CMetaInterface * pInterface = NULL;
  178. CError err;
  179. m_pCont->BuildMetaPath(cont_path);
  180. CMetabasePath path(FALSE, cont_path, id);
  181. // check if path exists...
  182. pInterface = m_pCont->QueryInterface();
  183. if (pInterface)
  184. {
  185. CMetaKey mk(pInterface, path, METADATA_PERMISSION_READ);
  186. err = mk.QueryResult();
  187. if (err.Succeeded())
  188. {
  189. bRes = FALSE;
  190. }
  191. }
  192. }
  193. }
  194. }
  195. return bRes;
  196. }
  197. void
  198. CAddAppPoolDlg::MakeUniquePoolId(CString& id)
  199. {
  200. TCHAR fmt[] = _T("%s #%d");
  201. CString unique;
  202. for (int n = 1; n < 100; n++)
  203. {
  204. unique.Format(fmt, id, n);
  205. if (IsUniqueId(unique,FALSE))
  206. break;
  207. }
  208. id = unique;
  209. }
  210. void
  211. CAddAppPoolDlg::OnHelp()
  212. {
  213. WinHelpDebug(0x20000 + CAddAppPoolDlg::IDD);
  214. ::WinHelp(m_hWnd, theApp.m_pszHelpFilePath, HELP_CONTEXT, 0x20000 + CAddAppPoolDlg::IDD);
  215. }
  216. ///////////////////////////////////////////////////////////////
  217. HRESULT
  218. CIISMBNode::AddAppPool(
  219. const CSnapInObjectRootBase * pObj,
  220. DATA_OBJECT_TYPES type,
  221. CAppPoolsContainer * pCont,
  222. CString& name
  223. )
  224. {
  225. AFX_MANAGE_STATE(::AfxGetStaticModuleState());
  226. HRESULT hr = S_OK;
  227. IConsoleNameSpace2 * pConsole
  228. = (IConsoleNameSpace2 *)GetOwner()->GetConsoleNameSpace();
  229. ASSERT(pConsole != NULL);
  230. HSCOPEITEM hChild = NULL, hCurrent;
  231. LONG_PTR cookie;
  232. hr = pConsole->Expand(pCont->QueryScopeItem());
  233. if (SUCCEEDED(hr))
  234. {
  235. pConsole->GetChildItem(pCont->QueryScopeItem(), &hChild, &cookie);
  236. CAppPoolNode * pPool;
  237. CPoolList pool_list;
  238. while (SUCCEEDED(hr) && hChild != NULL)
  239. {
  240. pPool = (CAppPoolNode *)cookie;
  241. ASSERT(pPool != NULL);
  242. pool_list.AddTail(pPool);
  243. hCurrent = hChild;
  244. hr = pConsole->GetNextItem(hCurrent, &hChild, &cookie);
  245. }
  246. CThemeContextActivator activator(theApp.GetFusionInitHandle());
  247. CAddAppPoolDlg dlg(pCont, &pool_list, GetMainWindow(GetConsole()));
  248. if (dlg.DoModal() == IDOK)
  249. {
  250. CComBSTR cont_path;
  251. pCont->BuildMetaPath(cont_path);
  252. CMetabasePath path(FALSE, cont_path, dlg.m_strPoolId);
  253. CIISAppPool pool(QueryAuthInfo(), path);
  254. if (SUCCEEDED(hr = pool.QueryResult()))
  255. {
  256. hr = pool.Create();
  257. if (SUCCEEDED(hr))
  258. {
  259. name = dlg.m_strPoolId;
  260. if (!dlg.UseMaster())
  261. {
  262. POSITION pos = pool_list.FindIndex(dlg.m_PoolIdx);
  263. CMetabasePath model_path(FALSE, cont_path,
  264. pool_list.GetAt(pos)->QueryNodeName());
  265. CAppPoolProps model(QueryAuthInfo(), model_path, FALSE);
  266. if (SUCCEEDED(hr = model.LoadData()))
  267. {
  268. CAppPoolProps new_pool(QueryAuthInfo(), path);
  269. new_pool.InitFromModel(model);
  270. hr = new_pool.WriteDirtyProps();
  271. }
  272. }
  273. else
  274. {
  275. CAppPoolProps new_pool(QueryAuthInfo(), path);
  276. hr = new_pool.WriteDirtyProps();
  277. }
  278. }
  279. }
  280. }
  281. else
  282. {
  283. hr = CError::HResult(ERROR_CANCELLED);
  284. }
  285. }
  286. return hr;
  287. }