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.

469 lines
16 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: servmon.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "preDNSsn.h"
  11. #include <SnapBase.h>
  12. #include "resource.h"
  13. #include "dnsutil.h"
  14. #include "DNSSnap.h"
  15. #include "snapdata.h"
  16. #include "server.h"
  17. #include "serverui.h"
  18. #ifdef DEBUG_ALLOCATOR
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. #endif
  25. #define CDNSServerMonitoringPageHolder CDNSServerPropertyPageHolder
  26. #define MAX_STATISTICS_LINE_LEN 256
  27. /////////////////////////////////////////////////////////////////////////////
  28. int FormatDate(SYSTEMTIME* p, LPWSTR lpsz, int nCharMax)
  29. {
  30. return ::GetDateFormat(LOCALE_USER_DEFAULT,
  31. DATE_SHORTDATE,
  32. p,
  33. NULL,
  34. lpsz,
  35. nCharMax);
  36. }
  37. int FormatTime(SYSTEMTIME* p, LPWSTR lpsz, int nCharMax)
  38. {
  39. return ::GetTimeFormat(LOCALE_USER_DEFAULT,
  40. 0,
  41. p,
  42. NULL,
  43. lpsz,
  44. nCharMax);
  45. }
  46. UINT LoadLabelsBlock(UINT nStringID, CString& szLabels, LPWSTR* szLabelArray)
  47. {
  48. UINT nLabelCount = 0;
  49. if (szLabels.LoadString(nStringID))
  50. {
  51. ParseNewLineSeparatedString(szLabels.GetBuffer(1),szLabelArray, &nLabelCount);
  52. szLabels.ReleaseBuffer();
  53. }
  54. return nLabelCount;
  55. }
  56. ///////////////////////////////////////////////////////////////////////////////
  57. // CDNSServer_TestPropertyPage
  58. CDNSServer_PollingIntervalEditGroup::
  59. CDNSServer_PollingIntervalEditGroup(UINT nMinVal, UINT nMaxVal)
  60. : CDNSTimeIntervalEditGroup(nMinVal, nMaxVal)
  61. {
  62. }
  63. void CDNSServer_PollingIntervalEditGroup::OnEditChange()
  64. {
  65. m_pPage->SetDirty(TRUE);
  66. }
  67. void CTestResultsListCtrl::Initialize()
  68. {
  69. // get size of control to help set the column widths
  70. CRect controlRect;
  71. GetClientRect(controlRect);
  72. // get width of control, width of potential scrollbar, width needed for sub-item
  73. // string
  74. int controlWidth = controlRect.Width();
  75. int scrollThumbWidth = ::GetSystemMetrics(SM_CXHTHUMB);
  76. // clean net width
  77. int nNetControlWidth = controlWidth - scrollThumbWidth - 12 * ::GetSystemMetrics(SM_CXBORDER);
  78. // fields widths
  79. int nWidth = nNetControlWidth/SVR_TEST_RESULT_LISTVIEW_NCOLS;
  80. // set up columns
  81. CString szHeaders;
  82. {
  83. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  84. szHeaders.LoadString(IDS_TEST_LISTVIEW_HEADERS);
  85. }
  86. ASSERT(!szHeaders.IsEmpty());
  87. LPWSTR lpszArr[SVR_TEST_RESULT_LISTVIEW_NCOLS];
  88. UINT n;
  89. ParseNewLineSeparatedString(szHeaders.GetBuffer(1), lpszArr, &n);
  90. szHeaders.ReleaseBuffer();
  91. ASSERT(n == SVR_TEST_RESULT_LISTVIEW_NCOLS);
  92. for (int k=0; k<SVR_TEST_RESULT_LISTVIEW_NCOLS; k++)
  93. {
  94. InsertColumn(k+1, lpszArr[k], LVCFMT_LEFT, nWidth, k+1);
  95. }
  96. // Set full row select
  97. ListView_SetExtendedListViewStyle(GetSafeHwnd(), LVS_EX_FULLROWSELECT);
  98. }
  99. void CTestResultsListCtrl::InsertEntry(CDNSServerTestQueryResult* pTestResult,
  100. int nItemIndex)
  101. {
  102. WCHAR szDate[256];
  103. WCHAR szTime[256];
  104. FormatDate(pTestResult, szDate, 256);
  105. FormatTime(pTestResult, szTime, 256);
  106. BOOL bPlainQuery, bRecursiveQuery;
  107. CDNSServerTestQueryResult::Unpack(pTestResult->m_dwQueryFlags, &bPlainQuery, &bRecursiveQuery);
  108. UINT nState = 0;
  109. if (nItemIndex == 0 )
  110. nState = LVIS_SELECTED | LVIS_FOCUSED; // have at least one item, select it
  111. VERIFY(-1 != InsertItem(LVIF_TEXT , nItemIndex,
  112. szDate,
  113. nState, 0, 0, NULL));
  114. SetItemText(nItemIndex, 1, szTime); // TIME
  115. {
  116. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  117. if (pTestResult->m_dwAddressResolutionResult != 0)
  118. {
  119. CString szFailedOnNameResolution;
  120. szFailedOnNameResolution.LoadString(IDS_SERVER_TEST_RESULT_FAIL_ON_NAME_RES);
  121. if (bPlainQuery)
  122. SetItemText(nItemIndex, 2, szFailedOnNameResolution);
  123. if (bRecursiveQuery)
  124. SetItemText(nItemIndex, 3, szFailedOnNameResolution);
  125. }
  126. else
  127. {
  128. CString szFail;
  129. szFail.LoadString(IDS_SERVER_TEST_RESULT_FAIL);
  130. CString szPass;
  131. szPass.LoadString(IDS_SERVER_TEST_RESULT_PASS);
  132. if (bPlainQuery)
  133. SetItemText(nItemIndex, 2,
  134. (pTestResult->m_dwPlainQueryResult == 0)? szPass : szFail);
  135. if (bRecursiveQuery)
  136. SetItemText(nItemIndex, 3,
  137. (pTestResult->m_dwRecursiveQueryResult == 0)? szPass : szFail);
  138. }
  139. }
  140. }
  141. void CTestResultsListCtrl::UpdateEntry(CDNSServerTestQueryResult* pTestResult,
  142. int nItemIndex)
  143. {
  144. // have to update DATE and TIME
  145. WCHAR szDate[256];
  146. WCHAR szTime[256];
  147. FormatDate(pTestResult, szDate, 256);
  148. FormatTime(pTestResult, szTime, 256);
  149. VERIFY(SetItem(nItemIndex, // nItem
  150. 0, // nSubItem
  151. LVIF_TEXT, // nMask
  152. szDate, // lpszItem
  153. 0, // nImage
  154. 0, // nState
  155. 0, // nStateMask
  156. NULL // lParam
  157. ));
  158. CString szTemp;
  159. SetItemText(nItemIndex, 1, szTime);
  160. }
  161. void CTestResultsListCtrl::FormatDate(CDNSServerTestQueryResult* pTestResult,
  162. LPWSTR lpsz, int nCharMax)
  163. {
  164. VERIFY( nCharMax > ::FormatDate(
  165. &(pTestResult->m_queryTime),
  166. lpsz,
  167. nCharMax));
  168. }
  169. void CTestResultsListCtrl::FormatTime(CDNSServerTestQueryResult* pTestResult,
  170. LPWSTR lpsz, int nCharMax)
  171. {
  172. VERIFY( nCharMax > ::FormatTime(
  173. &(pTestResult->m_queryTime),
  174. lpsz,
  175. nCharMax));
  176. }
  177. BEGIN_MESSAGE_MAP(CDNSServer_TestPropertyPage, CPropertyPageBase)
  178. ON_BN_CLICKED(IDC_ENABLE_TESTING_CHECK, OnEnableTestingCheck)
  179. ON_BN_CLICKED(IDC_SIMPLE_QUERY_CHECK, OnQueryCheck)
  180. ON_BN_CLICKED(IDC_RECURSIVE_QUERY_CHECK, OnQueryCheck)
  181. ON_BN_CLICKED(IDC_TEST_NOW_BUTTON, OnTestNow)
  182. END_MESSAGE_MAP()
  183. CDNSServer_TestPropertyPage::CDNSServer_TestPropertyPage()
  184. : CPropertyPageBase(IDD_SERVMON_TEST_PAGE),
  185. m_pollingIntervalEditGroup(MIN_SERVER_TEST_INTERVAL, MAX_SERVER_TEST_INTERVAL)
  186. {
  187. }
  188. BOOL CDNSServer_TestPropertyPage::OnInitDialog()
  189. {
  190. CPropertyPageBase::OnInitDialog();
  191. m_pollingIntervalEditGroup.m_pPage = this;
  192. VERIFY(m_pollingIntervalEditGroup.Initialize(this,
  193. IDC_POLLING_INT_EDIT, IDC_POLLING_INT_COMBO,IDS_TIME_INTERVAL_UNITS));
  194. HWND hWnd = ::GetDlgItem(GetSafeHwnd(), IDC_POLLING_INT_EDIT);
  195. // Disable IME support on the controls
  196. ImmAssociateContext(hWnd, NULL);
  197. VERIFY(m_listCtrl.SubclassDlgItem(IDC_RESULTS_LIST, this));
  198. m_listCtrl.Initialize();
  199. SetUIData();
  200. return TRUE;
  201. }
  202. void CDNSServer_TestPropertyPage::SetUIData()
  203. {
  204. CDNSServerMonitoringPageHolder* pHolder = (CDNSServerMonitoringPageHolder*)GetHolder();
  205. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  206. pServerNode->GetTestOptions(&m_testOptions);
  207. GetSimpleQueryCheck()->SetCheck(m_testOptions.m_bSimpleQuery);
  208. GetRecursiveQueryCheck()->SetCheck(m_testOptions.m_bRecursiveQuery);
  209. //
  210. // Check to see if this is a root server
  211. //
  212. BOOL bRoot = FALSE;
  213. DNS_STATUS err = ::ServerHasRootZone(pServerNode->GetRPCName(), &bRoot);
  214. if (err == 0 && bRoot)
  215. {
  216. //
  217. // Disable recursive queries on root server
  218. //
  219. GetRecursiveQueryCheck()->EnableWindow(FALSE);
  220. GetRecursiveQueryCheck()->SetCheck(FALSE);
  221. }
  222. CButton* pEnableTestingCheck = GetEnableTestingCheck();
  223. if (!(m_testOptions.m_bSimpleQuery || m_testOptions.m_bRecursiveQuery))
  224. {
  225. GetTestNowButton()->EnableWindow(FALSE);
  226. pEnableTestingCheck->EnableWindow(FALSE);
  227. pEnableTestingCheck->SetCheck(FALSE);
  228. m_pollingIntervalEditGroup.EnableUI(FALSE);
  229. }
  230. else
  231. {
  232. pEnableTestingCheck->SetCheck(m_testOptions.m_bEnabled);
  233. }
  234. m_pollingIntervalEditGroup.SetVal(m_testOptions.m_dwInterval);
  235. EnableControlsHelper(m_testOptions.m_bEnabled);
  236. PopulateList();
  237. }
  238. void CDNSServer_TestPropertyPage::EnableControlsHelper(BOOL bEnable)
  239. {
  240. //GetSimpleQueryCheck()->EnableWindow(bEnable);
  241. //GetRecursiveQueryCheck()->EnableWindow(bEnable);
  242. m_pollingIntervalEditGroup.EnableUI(bEnable);
  243. }
  244. BOOL CDNSServer_TestPropertyPage::OnApply()
  245. {
  246. if (!IsDirty())
  247. return TRUE;
  248. CDNSServerTestOptions newTestOptions;
  249. newTestOptions.m_bEnabled = GetEnableTestingCheck()->GetCheck();
  250. newTestOptions.m_bSimpleQuery = GetSimpleQueryCheck()->GetCheck();
  251. newTestOptions.m_bRecursiveQuery = GetRecursiveQueryCheck()->GetCheck();
  252. newTestOptions.m_dwInterval = m_pollingIntervalEditGroup.GetVal();
  253. if (newTestOptions == m_testOptions)
  254. return TRUE; // no need to update
  255. m_testOptions = newTestOptions;
  256. DNS_STATUS err = GetHolder()->NotifyConsole(this);
  257. if (err != 0)
  258. {
  259. DNSErrorDialog(err, IDS_MSG_SERVER_TEST_OPTIONS_UPDATE_FAILED);
  260. return FALSE;
  261. }
  262. else
  263. {
  264. SetDirty(FALSE);
  265. }
  266. return TRUE;
  267. }
  268. BOOL CDNSServer_TestPropertyPage::OnPropertyChange(BOOL, long*)
  269. {
  270. CDNSServerMonitoringPageHolder* pHolder = (CDNSServerMonitoringPageHolder*)GetHolder();
  271. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  272. pServerNode->ResetTestOptions(&m_testOptions);
  273. //if (err != 0)
  274. // pHolder->SetError(err);
  275. //return (err == 0);
  276. return FALSE; // no need to UI changes on this
  277. }
  278. void CDNSServer_TestPropertyPage::OnEnableTestingCheck()
  279. {
  280. SetDirty(TRUE);
  281. EnableControlsHelper(GetEnableTestingCheck()->GetCheck());
  282. }
  283. void CDNSServer_TestPropertyPage::OnQueryCheck()
  284. {
  285. SetDirty(TRUE);
  286. BOOL bCanQuery = GetSimpleQueryCheck()->GetCheck() ||
  287. GetRecursiveQueryCheck()->GetCheck();
  288. GetTestNowButton()->EnableWindow(bCanQuery);
  289. CButton* pEnableTestingCheck = GetEnableTestingCheck();
  290. pEnableTestingCheck->EnableWindow(bCanQuery);
  291. if (!bCanQuery)
  292. {
  293. GetTestNowButton()->EnableWindow(FALSE);
  294. pEnableTestingCheck->EnableWindow(FALSE);
  295. pEnableTestingCheck->SetCheck(FALSE);
  296. m_pollingIntervalEditGroup.EnableUI(FALSE);
  297. }
  298. }
  299. void CDNSServer_TestPropertyPage::OnTestNow()
  300. {
  301. CDNSServerMonitoringPageHolder* pHolder = (CDNSServerMonitoringPageHolder*)GetHolder();
  302. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  303. BOOL bSimpleQuery = GetSimpleQueryCheck()->GetCheck();
  304. BOOL bRecursiveQuery = GetRecursiveQueryCheck()->GetCheck();
  305. pHolder->GetComponentData()->PostMessageToTimerThread(
  306. WM_TIMER_THREAD_SEND_QUERY_TEST_NOW,
  307. (WPARAM)pServerNode,
  308. CDNSServerTestQueryResult::Pack(bSimpleQuery, bRecursiveQuery));
  309. }
  310. void CDNSServer_TestPropertyPage::OnHaveTestData(LPARAM lParam)
  311. {
  312. TRACE(_T("CDNSServer_TestPropertyPage::OnHaveTestData(LPARAM lParam = %d)\n"), lParam);
  313. if (m_hWnd == NULL)
  314. return; // not page not created yet
  315. AddEntryToList((CDNSServerTestQueryResultList::addAction)lParam);
  316. SetFocus();
  317. }
  318. void CDNSServer_TestPropertyPage::AddEntryToList(CDNSServerTestQueryResultList::addAction action)
  319. {
  320. CDNSServerMonitoringPageHolder* pHolder = (CDNSServerMonitoringPageHolder*)GetHolder();
  321. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  322. CDNSServerTestQueryResultList* pResultList = &(pServerNode->m_testResultList);
  323. int nCount = m_listCtrl.GetItemCount();
  324. switch (action)
  325. {
  326. case CDNSServerTestQueryResultList::added:
  327. case CDNSServerTestQueryResultList::addedAndRemoved:
  328. {
  329. if (action == CDNSServerTestQueryResultList::addedAndRemoved)
  330. {
  331. ASSERT(nCount > 0);
  332. m_listCtrl.DeleteItem(nCount-1);
  333. }
  334. pResultList->Lock();
  335. CDNSServerTestQueryResult* pTestResult = pResultList->GetHead();
  336. m_listCtrl.InsertEntry(pTestResult, 0);
  337. pResultList->Unlock();
  338. }
  339. break;
  340. case CDNSServerTestQueryResultList::changed:
  341. {
  342. ASSERT(nCount > 0);
  343. // for the moment just remove and add again
  344. pResultList->Lock();
  345. CDNSServerTestQueryResult* pTestResult = pResultList->GetHead();
  346. m_listCtrl.UpdateEntry(pTestResult, 0);
  347. pResultList->Unlock();
  348. }
  349. break;
  350. };
  351. }
  352. void CDNSServer_TestPropertyPage::PopulateList()
  353. {
  354. m_listCtrl.DeleteAllItems();
  355. CDNSServerMonitoringPageHolder* pHolder = (CDNSServerMonitoringPageHolder*)GetHolder();
  356. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  357. CDNSServerTestQueryResultList* pResultList = &(pServerNode->m_testResultList);
  358. pResultList->Lock();
  359. int k = 0;
  360. POSITION pos;
  361. for( pos = pResultList->GetHeadPosition(); pos != NULL; )
  362. {
  363. CDNSServerTestQueryResult* pTestResult = pResultList->GetNext(pos);
  364. m_listCtrl.InsertEntry(pTestResult, k++);
  365. }
  366. pResultList->Unlock();
  367. }
  368. /*
  369. ///////////////////////////////////////////////////////////////////////////////
  370. // CDNSServerMonitoringPageHolder
  371. CDNSServerMonitoringPageHolder::CDNSServerMonitoringPageHolder(CDNSRootData* pRootDataNode,
  372. CDNSServerNode* pServerNode, CComponentDataObject* pComponentData)
  373. : CPropertyPageHolderBase(pRootDataNode, pServerNode, pComponentData)
  374. {
  375. ASSERT(pRootDataNode == GetContainerNode());
  376. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  377. AddPageToList((CPropertyPageBase*)&m_statisticsPage);
  378. AddPageToList((CPropertyPageBase*)&m_testPage);
  379. }
  380. */