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.

463 lines
15 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. InsertColumn(k+1, lpszArr[k], LVCFMT_LEFT, nWidth, k+1);
  94. }
  95. void CTestResultsListCtrl::InsertEntry(CDNSServerTestQueryResult* pTestResult,
  96. int nItemIndex)
  97. {
  98. WCHAR szDate[256];
  99. WCHAR szTime[256];
  100. FormatDate(pTestResult, szDate, 256);
  101. FormatTime(pTestResult, szTime, 256);
  102. BOOL bPlainQuery, bRecursiveQuery;
  103. CDNSServerTestQueryResult::Unpack(pTestResult->m_dwQueryFlags, &bPlainQuery, &bRecursiveQuery);
  104. UINT nState = 0;
  105. if (nItemIndex == 0 )
  106. nState = LVIS_SELECTED | LVIS_FOCUSED; // have at least one item, select it
  107. VERIFY(-1 != InsertItem(LVIF_TEXT , nItemIndex,
  108. szDate,
  109. nState, 0, 0, NULL));
  110. SetItemText(nItemIndex, 1, szTime); // TIME
  111. {
  112. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  113. if (pTestResult->m_dwAddressResolutionResult != 0)
  114. {
  115. CString szFailedOnNameResolution;
  116. szFailedOnNameResolution.LoadString(IDS_SERVER_TEST_RESULT_FAIL_ON_NAME_RES);
  117. if (bPlainQuery)
  118. SetItemText(nItemIndex, 2, szFailedOnNameResolution);
  119. if (bRecursiveQuery)
  120. SetItemText(nItemIndex, 3, szFailedOnNameResolution);
  121. }
  122. else
  123. {
  124. CString szFail;
  125. szFail.LoadString(IDS_SERVER_TEST_RESULT_FAIL);
  126. CString szPass;
  127. szPass.LoadString(IDS_SERVER_TEST_RESULT_PASS);
  128. if (bPlainQuery)
  129. SetItemText(nItemIndex, 2,
  130. (pTestResult->m_dwPlainQueryResult == 0)? szPass : szFail);
  131. if (bRecursiveQuery)
  132. SetItemText(nItemIndex, 3,
  133. (pTestResult->m_dwRecursiveQueryResult == 0)? szPass : szFail);
  134. }
  135. }
  136. }
  137. void CTestResultsListCtrl::UpdateEntry(CDNSServerTestQueryResult* pTestResult,
  138. int nItemIndex)
  139. {
  140. // have to update DATE and TIME
  141. WCHAR szDate[256];
  142. WCHAR szTime[256];
  143. FormatDate(pTestResult, szDate, 256);
  144. FormatTime(pTestResult, szTime, 256);
  145. VERIFY(SetItem(nItemIndex, // nItem
  146. 0, // nSubItem
  147. LVIF_TEXT, // nMask
  148. szDate, // lpszItem
  149. 0, // nImage
  150. 0, // nState
  151. 0, // nStateMask
  152. NULL // lParam
  153. ));
  154. CString szTemp;
  155. SetItemText(nItemIndex, 1, szTime);
  156. }
  157. void CTestResultsListCtrl::FormatDate(CDNSServerTestQueryResult* pTestResult,
  158. LPWSTR lpsz, int nCharMax)
  159. {
  160. VERIFY( nCharMax > ::FormatDate(
  161. &(pTestResult->m_queryTime),
  162. lpsz,
  163. nCharMax));
  164. }
  165. void CTestResultsListCtrl::FormatTime(CDNSServerTestQueryResult* pTestResult,
  166. LPWSTR lpsz, int nCharMax)
  167. {
  168. VERIFY( nCharMax > ::FormatTime(
  169. &(pTestResult->m_queryTime),
  170. lpsz,
  171. nCharMax));
  172. }
  173. BEGIN_MESSAGE_MAP(CDNSServer_TestPropertyPage, CPropertyPageBase)
  174. ON_BN_CLICKED(IDC_ENABLE_TESTING_CHECK, OnEnableTestingCheck)
  175. ON_BN_CLICKED(IDC_SIMPLE_QUERY_CHECK, OnQueryCheck)
  176. ON_BN_CLICKED(IDC_RECURSIVE_QUERY_CHECK, OnQueryCheck)
  177. ON_BN_CLICKED(IDC_TEST_NOW_BUTTON, OnTestNow)
  178. END_MESSAGE_MAP()
  179. CDNSServer_TestPropertyPage::CDNSServer_TestPropertyPage()
  180. : CPropertyPageBase(IDD_SERVMON_TEST_PAGE),
  181. m_pollingIntervalEditGroup(MIN_SERVER_TEST_INTERVAL, MAX_SERVER_TEST_INTERVAL)
  182. {
  183. }
  184. BOOL CDNSServer_TestPropertyPage::OnInitDialog()
  185. {
  186. CPropertyPageBase::OnInitDialog();
  187. m_pollingIntervalEditGroup.m_pPage = this;
  188. VERIFY(m_pollingIntervalEditGroup.Initialize(this,
  189. IDC_POLLING_INT_EDIT, IDC_POLLING_INT_COMBO,IDS_TIME_INTERVAL_UNITS));
  190. HWND hWnd = ::GetDlgItem(GetSafeHwnd(), IDC_POLLING_INT_EDIT);
  191. // Disable IME support on the controls
  192. ImmAssociateContext(hWnd, NULL);
  193. VERIFY(m_listCtrl.SubclassDlgItem(IDC_RESULTS_LIST, this));
  194. m_listCtrl.Initialize();
  195. SetUIData();
  196. return TRUE;
  197. }
  198. void CDNSServer_TestPropertyPage::SetUIData()
  199. {
  200. CDNSServerMonitoringPageHolder* pHolder = (CDNSServerMonitoringPageHolder*)GetHolder();
  201. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  202. pServerNode->GetTestOptions(&m_testOptions);
  203. GetSimpleQueryCheck()->SetCheck(m_testOptions.m_bSimpleQuery);
  204. GetRecursiveQueryCheck()->SetCheck(m_testOptions.m_bRecursiveQuery);
  205. //
  206. // Check to see if this is a root server
  207. //
  208. BOOL bRoot = FALSE;
  209. DNS_STATUS err = ::ServerHasRootZone(pServerNode->GetRPCName(), &bRoot);
  210. if (err == 0 && bRoot)
  211. {
  212. //
  213. // Disable recursive queries on root server
  214. //
  215. GetRecursiveQueryCheck()->EnableWindow(FALSE);
  216. GetRecursiveQueryCheck()->SetCheck(FALSE);
  217. }
  218. CButton* pEnableTestingCheck = GetEnableTestingCheck();
  219. if (!(m_testOptions.m_bSimpleQuery || m_testOptions.m_bRecursiveQuery))
  220. {
  221. GetTestNowButton()->EnableWindow(FALSE);
  222. pEnableTestingCheck->EnableWindow(FALSE);
  223. pEnableTestingCheck->SetCheck(FALSE);
  224. m_pollingIntervalEditGroup.EnableUI(FALSE);
  225. }
  226. else
  227. {
  228. pEnableTestingCheck->SetCheck(m_testOptions.m_bEnabled);
  229. }
  230. m_pollingIntervalEditGroup.SetVal(m_testOptions.m_dwInterval);
  231. EnableControlsHelper(m_testOptions.m_bEnabled);
  232. PopulateList();
  233. }
  234. void CDNSServer_TestPropertyPage::EnableControlsHelper(BOOL bEnable)
  235. {
  236. //GetSimpleQueryCheck()->EnableWindow(bEnable);
  237. //GetRecursiveQueryCheck()->EnableWindow(bEnable);
  238. m_pollingIntervalEditGroup.EnableUI(bEnable);
  239. }
  240. BOOL CDNSServer_TestPropertyPage::OnApply()
  241. {
  242. if (!IsDirty())
  243. return TRUE;
  244. CDNSServerTestOptions newTestOptions;
  245. newTestOptions.m_bEnabled = GetEnableTestingCheck()->GetCheck();
  246. newTestOptions.m_bSimpleQuery = GetSimpleQueryCheck()->GetCheck();
  247. newTestOptions.m_bRecursiveQuery = GetRecursiveQueryCheck()->GetCheck();
  248. newTestOptions.m_dwInterval = m_pollingIntervalEditGroup.GetVal();
  249. if (newTestOptions == m_testOptions)
  250. return TRUE; // no need to update
  251. m_testOptions = newTestOptions;
  252. DNS_STATUS err = GetHolder()->NotifyConsole(this);
  253. if (err != 0)
  254. {
  255. DNSErrorDialog(err, IDS_MSG_SERVER_TEST_OPTIONS_UPDATE_FAILED);
  256. return FALSE;
  257. }
  258. else
  259. {
  260. SetDirty(FALSE);
  261. }
  262. return TRUE;
  263. }
  264. BOOL CDNSServer_TestPropertyPage::OnPropertyChange(BOOL, long*)
  265. {
  266. CDNSServerMonitoringPageHolder* pHolder = (CDNSServerMonitoringPageHolder*)GetHolder();
  267. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  268. pServerNode->ResetTestOptions(&m_testOptions);
  269. //if (err != 0)
  270. // pHolder->SetError(err);
  271. //return (err == 0);
  272. return FALSE; // no need to UI changes on this
  273. }
  274. void CDNSServer_TestPropertyPage::OnEnableTestingCheck()
  275. {
  276. SetDirty(TRUE);
  277. EnableControlsHelper(GetEnableTestingCheck()->GetCheck());
  278. }
  279. void CDNSServer_TestPropertyPage::OnQueryCheck()
  280. {
  281. SetDirty(TRUE);
  282. BOOL bCanQuery = GetSimpleQueryCheck()->GetCheck() ||
  283. GetRecursiveQueryCheck()->GetCheck();
  284. GetTestNowButton()->EnableWindow(bCanQuery);
  285. CButton* pEnableTestingCheck = GetEnableTestingCheck();
  286. pEnableTestingCheck->EnableWindow(bCanQuery);
  287. if (!bCanQuery)
  288. {
  289. GetTestNowButton()->EnableWindow(FALSE);
  290. pEnableTestingCheck->EnableWindow(FALSE);
  291. pEnableTestingCheck->SetCheck(FALSE);
  292. m_pollingIntervalEditGroup.EnableUI(FALSE);
  293. }
  294. }
  295. void CDNSServer_TestPropertyPage::OnTestNow()
  296. {
  297. CDNSServerMonitoringPageHolder* pHolder = (CDNSServerMonitoringPageHolder*)GetHolder();
  298. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  299. BOOL bSimpleQuery = GetSimpleQueryCheck()->GetCheck();
  300. BOOL bRecursiveQuery = GetRecursiveQueryCheck()->GetCheck();
  301. pHolder->GetComponentData()->PostMessageToTimerThread(
  302. WM_TIMER_THREAD_SEND_QUERY_TEST_NOW,
  303. (WPARAM)pServerNode,
  304. CDNSServerTestQueryResult::Pack(bSimpleQuery, bRecursiveQuery));
  305. }
  306. void CDNSServer_TestPropertyPage::OnHaveTestData(LPARAM lParam)
  307. {
  308. TRACE(_T("CDNSServer_TestPropertyPage::OnHaveTestData(LPARAM lParam = %d)\n"), lParam);
  309. if (m_hWnd == NULL)
  310. return; // not page not created yet
  311. AddEntryToList((CDNSServerTestQueryResultList::addAction)lParam);
  312. SetFocus();
  313. }
  314. void CDNSServer_TestPropertyPage::AddEntryToList(CDNSServerTestQueryResultList::addAction action)
  315. {
  316. CDNSServerMonitoringPageHolder* pHolder = (CDNSServerMonitoringPageHolder*)GetHolder();
  317. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  318. CDNSServerTestQueryResultList* pResultList = &(pServerNode->m_testResultList);
  319. int nCount = m_listCtrl.GetItemCount();
  320. switch (action)
  321. {
  322. case CDNSServerTestQueryResultList::added:
  323. case CDNSServerTestQueryResultList::addedAndRemoved:
  324. {
  325. if (action == CDNSServerTestQueryResultList::addedAndRemoved)
  326. {
  327. ASSERT(nCount > 0);
  328. m_listCtrl.DeleteItem(nCount-1);
  329. }
  330. pResultList->Lock();
  331. CDNSServerTestQueryResult* pTestResult = pResultList->GetHead();
  332. m_listCtrl.InsertEntry(pTestResult, 0);
  333. pResultList->Unlock();
  334. }
  335. break;
  336. case CDNSServerTestQueryResultList::changed:
  337. {
  338. ASSERT(nCount > 0);
  339. // for the moment just remove and add again
  340. pResultList->Lock();
  341. CDNSServerTestQueryResult* pTestResult = pResultList->GetHead();
  342. m_listCtrl.UpdateEntry(pTestResult, 0);
  343. pResultList->Unlock();
  344. }
  345. break;
  346. };
  347. }
  348. void CDNSServer_TestPropertyPage::PopulateList()
  349. {
  350. m_listCtrl.DeleteAllItems();
  351. CDNSServerMonitoringPageHolder* pHolder = (CDNSServerMonitoringPageHolder*)GetHolder();
  352. CDNSServerNode* pServerNode = pHolder->GetServerNode();
  353. CDNSServerTestQueryResultList* pResultList = &(pServerNode->m_testResultList);
  354. pResultList->Lock();
  355. int k = 0;
  356. POSITION pos;
  357. for( pos = pResultList->GetHeadPosition(); pos != NULL; )
  358. {
  359. CDNSServerTestQueryResult* pTestResult = pResultList->GetNext(pos);
  360. m_listCtrl.InsertEntry(pTestResult, k++);
  361. }
  362. pResultList->Unlock();
  363. }
  364. /*
  365. ///////////////////////////////////////////////////////////////////////////////
  366. // CDNSServerMonitoringPageHolder
  367. CDNSServerMonitoringPageHolder::CDNSServerMonitoringPageHolder(CDNSRootData* pRootDataNode,
  368. CDNSServerNode* pServerNode, CComponentDataObject* pComponentData)
  369. : CPropertyPageHolderBase(pRootDataNode, pServerNode, pComponentData)
  370. {
  371. ASSERT(pRootDataNode == GetContainerNode());
  372. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  373. AddPageToList((CPropertyPageBase*)&m_statisticsPage);
  374. AddPageToList((CPropertyPageBase*)&m_testPage);
  375. }
  376. */