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.

384 lines
10 KiB

  1. /*++
  2. Copyright (c) 1994-2000 Microsoft Corporation
  3. Module Name :
  4. W3PropPage.cpp
  5. Abstract:
  6. IIS Shell extension PropertyPage class implementation
  7. Author:
  8. Sergei Antonov (sergeia)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "W3PropPage.h"
  15. #include "w3ext.h"
  16. #include "PropShellExt.h"
  17. #include "EditAlias.h"
  18. #define SZ_SERVER_KEYTYPE _T("IIsWebServer")
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CW3PropPage
  21. LRESULT
  22. CW3PropPage::OnInitDialog(HWND hDlg, LPARAM lParam)
  23. {
  24. // subclass dialog controls
  25. DoDataExchange();
  26. ASSERT(m_pParentExt != NULL);
  27. CMetaEnumerator en(LOCAL_KEY, CMetabasePath(SZ_MBN_WEB));
  28. ASSERT(en.Succeeded());
  29. if (en.Succeeded())
  30. {
  31. DWORD di;
  32. int i = -1;
  33. CString inst;
  34. HRESULT hr = S_OK;
  35. while (SUCCEEDED(hr))
  36. {
  37. if (SUCCEEDED(hr = en.Next(di, inst)))
  38. {
  39. CString cmt;
  40. if (SUCCEEDED(hr = en.QueryValue(MD_SERVER_COMMENT, cmt, NULL, inst)))
  41. {
  42. if (cmt.IsEmpty())
  43. {
  44. cmt.Format(_Module.GetResourceInstance(),
  45. IDS_DEFAULT_SERVER_COMMENT, di);
  46. }
  47. if (CB_ERR != (i = m_servers_list.AddString(cmt)))
  48. {
  49. m_servers_list.SetItemDataPtr(i, StrDup(inst));
  50. }
  51. }
  52. }
  53. }
  54. if (i >= 0)
  55. m_servers_list.SetCurSel(0);
  56. m_ShareThis = 0;
  57. // Fill shares list box for selected server
  58. OnServerChange(0, 0, NULL);
  59. }
  60. return 1;
  61. }
  62. void
  63. CW3PropPage::OnDestroy()
  64. {
  65. ATLTRACE("In OnDestroy handler\n");
  66. // DebugBreak();
  67. }
  68. HRESULT GetKeyNames(CMetaEnumerator& en, std::set<CString>& keys)
  69. {
  70. CString key;
  71. HRESULT hr;
  72. if (SUCCEEDED(hr = en.Next(key)))
  73. {
  74. keys.insert(key);
  75. }
  76. return hr;
  77. }
  78. void
  79. CW3PropPage::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  80. {
  81. CEditAlias dlg;
  82. int index = m_servers_list.GetCurSel();
  83. LPCTSTR p = (LPCTSTR)m_servers_list.GetItemData(index);
  84. dlg.m_instance = p;
  85. p = m_pParentExt->GetPath();
  86. ::StrCpy(dlg.m_path, p);
  87. dlg.m_new = TRUE;
  88. if (p == PathFindFileName(p))
  89. {
  90. /* No file name -- could be root directory like c:\ */
  91. dlg.m_alias[0] = 0;
  92. }
  93. else
  94. {
  95. TCHAR buf[MAX_PATH];
  96. StrCpy(buf, PathFindFileName(p));
  97. PathMakePretty(buf);
  98. StrCpy(dlg.m_alias, buf);
  99. // Now we need to generate unique prompt for this new alias
  100. CMetaEnumerator en(LOCAL_KEY,
  101. CMetabasePath(TRUE, SZ_MBN_WEB, dlg.m_instance, SZ_MBN_ROOT));
  102. ASSERT(en.Succeeded());
  103. if (en.Succeeded())
  104. {
  105. std::set<CString> keys;
  106. if (SUCCEEDED(GetKeyNames(en, keys)) && !keys.empty())
  107. {
  108. int i = 0;
  109. while (keys.find(buf) != keys.end())
  110. {
  111. wsprintf(buf, _T("%s%d"), dlg.m_alias, ++i);
  112. }
  113. StrCpy(dlg.m_alias, buf);
  114. }
  115. }
  116. }
  117. if (IDOK == dlg.DoModal())
  118. {
  119. OnServerChange(0, 0, NULL);
  120. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  121. }
  122. }
  123. void
  124. CW3PropPage::OnRemove(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  125. {
  126. CString cap, msg;
  127. int index = m_servers_list.GetCurSel();
  128. LPCTSTR p = (LPCTSTR)m_servers_list.GetItemData(index);
  129. cap.LoadString(_Module.GetResourceInstance(), IDS_PAGE_TITLE);
  130. index = m_share_list.GetCurSel();
  131. TCHAR buf[MAX_PATH];
  132. m_share_list.GetText(index, buf);
  133. msg.Format(_Module.GetResourceInstance(), IDS_CONFIRM_REMOVE, buf);
  134. CError err;
  135. if (IDYES == MessageBox(msg, cap, MB_YESNO|MB_ICONQUESTION))
  136. {
  137. CWaitCursor wait;
  138. do
  139. {
  140. CIISApplication app(NULL, CMetabasePath(TRUE, SZ_MBN_WEB, p, SZ_MBN_ROOT, buf));
  141. err = app.QueryResult();
  142. BREAK_ON_ERR_FAILURE(err)
  143. err = app.Delete(TRUE);
  144. } while (FALSE);
  145. if (err.Succeeded())
  146. {
  147. CMetaKey mk(LOCAL_KEY,
  148. CMetabasePath(TRUE, SZ_MBN_WEB, p, SZ_MBN_ROOT),
  149. METADATA_PERMISSION_WRITE);
  150. err = mk.DeleteKey(buf);
  151. if (err.Succeeded())
  152. {
  153. m_share_list.DeleteString(index);
  154. int count = m_share_list.GetCount();
  155. m_ShareThis = count > 0 ? 1 : 0;
  156. if (m_ShareThis)
  157. {
  158. m_share_list.SetCurSel(index >= count ? count - 1 : index);
  159. }
  160. EnableOnShare();
  161. CheckDlgButton(IDC_SHARE_ON, m_ShareThis);
  162. CheckDlgButton(IDC_SHARE_OFF, !m_ShareThis);
  163. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  164. }
  165. else
  166. {
  167. err.MessageBox();
  168. }
  169. }
  170. else
  171. {
  172. err.MessageBox();
  173. }
  174. }
  175. }
  176. void
  177. CW3PropPage::OnEdit(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  178. {
  179. CEditAlias dlg;
  180. int index = m_servers_list.GetCurSel();
  181. LPCTSTR p = (LPCTSTR)m_servers_list.GetItemData(index);
  182. dlg.m_instance = p;
  183. p = m_pParentExt->GetPath();
  184. ::StrCpy(dlg.m_path, p);
  185. index = m_share_list.GetCurSel();
  186. TCHAR buf[MAX_PATH];
  187. m_share_list.GetText(index, buf);
  188. ::StrCpy(dlg.m_alias, buf);
  189. dlg.m_new = FALSE;
  190. if (IDOK == dlg.DoModal())
  191. {
  192. OnServerChange(0, 0, NULL);
  193. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  194. }
  195. }
  196. void
  197. CW3PropPage::OnServerChange(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  198. {
  199. // get selected server instance number
  200. int index = m_servers_list.GetCurSel();
  201. if (LB_ERR != index)
  202. {
  203. LPTSTR p = (LPTSTR)m_servers_list.GetItemDataPtr(index);
  204. CMetabasePath path(TRUE, SZ_MBN_WEB, p, SZ_MBN_ROOT);
  205. CMetaEnumerator en(LOCAL_KEY, path);
  206. ASSERT(en.Succeeded());
  207. m_share_list.ResetContent();
  208. if (en.Succeeded())
  209. {
  210. RecurseVDirs(en, NULL);
  211. }
  212. m_ShareThis = m_share_list.GetCount() > 0 ? 1 : 0;
  213. }
  214. if (m_ShareThis)
  215. {
  216. m_share_list.SetCurSel(0);
  217. }
  218. EnableOnShare();
  219. CheckDlgButton(IDC_SHARE_ON, m_ShareThis);
  220. CheckDlgButton(IDC_SHARE_OFF, !m_ShareThis);
  221. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  222. }
  223. void
  224. CW3PropPage::RecurseVDirs(CMetaEnumerator& en, LPCTSTR path)
  225. {
  226. CString vrpath;
  227. BOOL bInheritOverride = FALSE;
  228. if (SUCCEEDED(en.QueryValue(MD_VR_PATH, vrpath, &bInheritOverride, path)))
  229. {
  230. if (vrpath.CompareNoCase(m_pParentExt->GetPath()) == 0)
  231. {
  232. CMetabasePath mpath(FALSE, path);
  233. CMetabasePath::CleanMetaPath(mpath);
  234. m_share_list.AddString(path == NULL ?
  235. SZ_MBN_SEP_STR : mpath.QueryMetaPath());
  236. }
  237. }
  238. CString vdir;
  239. while (SUCCEEDED(en.Next(vdir, path)))
  240. {
  241. CString next_vdir;
  242. if (path != NULL)
  243. next_vdir += path;
  244. next_vdir += vdir;
  245. next_vdir += SZ_MBN_SEP_STR;
  246. en.Push();
  247. en.Reset();
  248. RecurseVDirs(en, next_vdir);
  249. en.Pop();
  250. }
  251. }
  252. void
  253. CW3PropPage::OnShareYesNo(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  254. {
  255. int count = m_share_list.GetCount();
  256. m_ShareThis = IsDlgButtonChecked(IDC_SHARE_ON);
  257. if (m_ShareThis)
  258. {
  259. if (count <= 0)
  260. {
  261. OnAdd(0, 0, NULL);
  262. m_ShareThis = (m_share_list.GetCount() > 0);
  263. }
  264. }
  265. else
  266. {
  267. if (count > 0)
  268. {
  269. CString cap, msg;
  270. int index = m_servers_list.GetCurSel();
  271. LPCTSTR p = (LPCTSTR)m_servers_list.GetItemData(index);
  272. cap.LoadString(_Module.GetResourceInstance(), IDS_PAGE_TITLE);
  273. msg.LoadString(_Module.GetResourceInstance(), IDS_CONFIRM_REMOVE_ALL);
  274. CError err;
  275. if (IDYES == MessageBox(msg, cap, MB_YESNO))
  276. {
  277. CWaitCursor wait;
  278. TCHAR alias[MAX_PATH];
  279. int del_idx = 0;
  280. for (index = 0; err.Succeeded() && index < count; index++)
  281. {
  282. m_share_list.GetText(del_idx, alias);
  283. if (0 == StrCmp(alias, SZ_MBN_SEP_STR))
  284. {
  285. // Do not remove sites! Skip it.
  286. del_idx++;
  287. continue;
  288. }
  289. do
  290. {
  291. CIISApplication app(NULL, CMetabasePath(TRUE, SZ_MBN_WEB, p, SZ_MBN_ROOT, alias));
  292. err = app.QueryResult();
  293. BREAK_ON_ERR_FAILURE(err)
  294. err = app.Delete(TRUE);
  295. BREAK_ON_ERR_FAILURE(err)
  296. CMetaKey mk(LOCAL_KEY,
  297. CMetabasePath(TRUE, SZ_MBN_WEB, p, SZ_MBN_ROOT),
  298. METADATA_PERMISSION_WRITE);
  299. err = mk.DeleteKey(alias);
  300. BREAK_ON_ERR_FAILURE(err)
  301. } while (FALSE);
  302. BREAK_ON_ERR_FAILURE(err)
  303. m_share_list.DeleteString(del_idx);
  304. }
  305. if (err.Failed() || del_idx > 0)
  306. {
  307. // BUGBUG: we have AV when preparing message box text here
  308. // err.MessageBox();
  309. m_ShareThis = TRUE;
  310. }
  311. }
  312. else
  313. {
  314. m_ShareThis = TRUE;
  315. }
  316. }
  317. }
  318. CheckDlgButton(IDC_SHARE_ON, m_ShareThis);
  319. CheckDlgButton(IDC_SHARE_OFF, !m_ShareThis);
  320. EnableOnShare();
  321. ::SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
  322. }
  323. void
  324. CW3PropPage::EnableOnShare()
  325. {
  326. m_share_list.EnableWindow(m_ShareThis);
  327. ::EnableWindow(GetDlgItem(IDC_ADD), m_ShareThis);
  328. ::EnableWindow(GetDlgItem(IDC_EDIT), m_ShareThis
  329. && m_share_list.GetCurSel() != LB_ERR);
  330. ::EnableWindow(GetDlgItem(IDC_REMOVE), m_ShareThis
  331. && m_share_list.GetCurSel() != LB_ERR);
  332. if (m_ShareThis)
  333. {
  334. EnableEditRemove();
  335. }
  336. }
  337. void
  338. CW3PropPage::OnVDirChange(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  339. {
  340. EnableEditRemove();
  341. }
  342. void
  343. CW3PropPage::EnableEditRemove()
  344. {
  345. // We are disabling Edit and Remove buttons when user
  346. // select root alias, i.e. user cannot delete or edit sites
  347. int index = m_share_list.GetCurSel();
  348. BOOL bEnable = index != LB_ERR;
  349. if (bEnable)
  350. {
  351. TCHAR alias[MAX_PATH];
  352. m_share_list.GetText(index, alias);
  353. bEnable = (0 != StrCmp(alias, SZ_MBN_SEP_STR));
  354. }
  355. ::EnableWindow(GetDlgItem(IDC_EDIT), bEnable);
  356. ::EnableWindow(GetDlgItem(IDC_REMOVE), bEnable);
  357. }