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.

1164 lines
39 KiB

  1. /*---------------------------------------------------------------------------
  2. File: AgentDetailDlg.cpp
  3. Comments: This dialog shows the status of the agent on a single machine:
  4. It can work in one of 3 ways:
  5. 1) COM connection to the running agent on the local machine
  6. 2) DCOM connection to a running agent on another machine (this is done
  7. with help from the agent service)
  8. 3) For a remote agent that has finished, it can show the final stats,
  9. as recorded in the agent's result file.
  10. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  11. Proprietary and confidential to Mission Critical Software, Inc.
  12. REVISION LOG ENTRY
  13. Revision By: Christy Boles
  14. ---------------------------------------------------------------------------
  15. */// AgentDetail.cpp : implementation file
  16. //
  17. #include "stdafx.h"
  18. #include "resource.h"
  19. #include "DetDlg.h"
  20. #include "Common.hpp"
  21. #include "AgRpcUtl.h"
  22. #include "Monitor.h"
  23. #include "ResStr.h"
  24. //#include "..\AgtSvc\AgSvc.h"
  25. #include "AgSvc.h"
  26. #include "AgSvc_c.c"
  27. //#import "\bin\McsEADCTAgent.tlb" no_namespace , named_guids
  28. //#import "\bin\McsVarSetMin.tlb" no_namespace
  29. //#import "Engine.tlb" no_namespace, named_guids //already #imported via DetDlg.h
  30. #import "VarSet.tlb" no_namespace rename("property", "aproperty")
  31. #ifdef _DEBUG
  32. #define new DEBUG_NEW
  33. #undef THIS_FILE
  34. static char THIS_FILE[] = __FILE__;
  35. #endif
  36. HWND gSubWnd = NULL;
  37. BOOL bDetailDone = FALSE;
  38. int detailInterval = 0;
  39. extern BOOL gbCancelled;
  40. TCHAR* GetSystemDirectoryHelper()
  41. {
  42. const DWORD iSize = GetSystemDirectory(NULL, 0);
  43. TCHAR* buffer = NULL;
  44. DWORD dwTemp = 0;
  45. if(iSize == 0)
  46. {
  47. return NULL;
  48. }
  49. buffer = new TCHAR[iSize + _tcslen(__TEXT("\\"))]; // iSize includes the NULL terminiator
  50. if(!buffer)
  51. {
  52. return NULL;
  53. }
  54. dwTemp = GetSystemDirectory(buffer, iSize);
  55. if(dwTemp == 0)
  56. {
  57. if(buffer)
  58. {
  59. delete [] buffer;
  60. return NULL;
  61. }
  62. }
  63. _tcscat(buffer, __TEXT("\\"));
  64. return buffer;
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CAgentDetailDlg dialog
  68. CAgentDetailDlg::CAgentDetailDlg(CWnd* pParent /*=NULL*/)
  69. : CDialog(CAgentDetailDlg::IDD, pParent)
  70. {
  71. //{{AFX_DATA_INIT(CAgentDetailDlg)
  72. m_Current = _T("");
  73. m_Status = _T("");
  74. m_FilesChanged = _T("0");
  75. m_FilesExamined = _T("0");
  76. m_FilesUnchanged = _T("0");
  77. m_DirectoriesChanged = _T("0");
  78. m_DirectoriesExamined = _T("0");
  79. m_DirectoriesUnchanged = _T("0");
  80. m_SharesChanged = _T("0");
  81. m_SharesExamined = _T("0");
  82. m_SharesUnchanged = _T("0");
  83. m_Operation = _T("");
  84. m_RefreshRate = _T("5");
  85. //}}AFX_DATA_INIT
  86. m_DirectoryLabelText.LoadString(IDS_DirectoriesLabel);
  87. m_FilesLabelText.LoadString(IDS_FilesLabel);
  88. m_SharesLabelText.LoadString(IDS_SharesLabel);
  89. m_ChangedLabel.LoadString(IDS_ChangedLabel);
  90. m_ExaminedLabel.LoadString(IDS_ExaminedLabel);
  91. m_UnchangedLabel.LoadString(IDS_UnchangedLabel);
  92. m_pNode = NULL;
  93. detailInterval = _wtoi(m_RefreshRate);
  94. m_bCoInitialized = FALSE;
  95. m_format = 0;
  96. m_AgentAlive = FALSE;
  97. m_StatusUnknown = FALSE;
  98. m_hBinding = 0;
  99. m_pStats = NULL;
  100. m_bGatheringInfo = FALSE;
  101. m_bAutoHide = FALSE;
  102. m_bAutoClose = FALSE;
  103. m_bAlwaysEnableClose = TRUE;
  104. m_LogFileIsValid = TRUE;
  105. }
  106. ULONG __stdcall RefreshThread(void * arg)
  107. {
  108. do {
  109. PostMessage(gSubWnd,DCT_DETAIL_REFRESH,NULL,NULL);
  110. Sleep(detailInterval*1000);
  111. }
  112. while (! bDetailDone);
  113. return 0;
  114. }
  115. void CAgentDetailDlg::DoDataExchange(CDataExchange* pDX)
  116. {
  117. CDialog::DoDataExchange(pDX);
  118. //{{AFX_DATA_MAP(CAgentDetailDlg)
  119. DDX_Control(pDX, IDC_STOPAGENT, m_StopAgentButton);
  120. DDX_Control(pDX, IDC_BTNREFRESH, m_RefreshButton);
  121. DDX_Control(pDX, IDC_VIEW_LOG, m_ViewLogButton);
  122. DDX_Control(pDX, IDC_PLUG_IN_RESULTS, m_PlugInButton);
  123. DDX_Control(pDX, IDOK, m_OKButton);
  124. DDX_Control(pDX, IDC_UnchangedLabel, m_UnchangedLabelStatic);
  125. DDX_Control(pDX, IDC_SharesLabel, m_SharesStatic);
  126. DDX_Control(pDX, IDC_FilesLabel, m_FilesStatic);
  127. DDX_Control(pDX, IDC_ExaminedLabel, m_ExaminedStatic);
  128. DDX_Control(pDX, IDC_DirectoriesLabel, m_DirStatic);
  129. DDX_Control(pDX, IDC_ChangedLabel, m_ChangedStatic);
  130. DDX_Text(pDX, IDC_CURRENT, m_Current);
  131. DDX_Text(pDX, IDC_STATUS, m_Status);
  132. DDX_Text(pDX, IDC_FilesChanged, m_FilesChanged);
  133. DDX_Text(pDX, IDC_FilesExamined, m_FilesExamined);
  134. DDX_Text(pDX, IDC_FilesU, m_FilesUnchanged);
  135. DDX_Text(pDX, IDC_DirsChanged, m_DirectoriesChanged);
  136. DDX_Text(pDX, IDC_DirsExamined, m_DirectoriesExamined);
  137. DDX_Text(pDX, IDC_DirsU, m_DirectoriesUnchanged);
  138. DDX_Text(pDX, IDC_SharesChanged, m_SharesChanged);
  139. DDX_Text(pDX, IDC_SharesExamined, m_SharesExamined);
  140. DDX_Text(pDX, IDC_SharesU, m_SharesUnchanged);
  141. DDX_Text(pDX, IDC_DirectoriesLabel, m_DirectoryLabelText);
  142. DDX_Text(pDX, IDC_FilesLabel, m_FilesLabelText);
  143. DDX_Text(pDX, IDC_OPERATION, m_Operation);
  144. DDX_Text(pDX, IDC_SharesLabel, m_SharesLabelText);
  145. DDX_Text(pDX, IDC_ChangedLabel, m_ChangedLabel);
  146. DDX_Text(pDX, IDC_ExaminedLabel, m_ExaminedLabel);
  147. DDX_Text(pDX, IDC_UnchangedLabel, m_UnchangedLabel);
  148. DDX_Text(pDX, IDC_EDIT2, m_RefreshRate);
  149. //}}AFX_DATA_MAP
  150. }
  151. BEGIN_MESSAGE_MAP(CAgentDetailDlg, CDialog)
  152. //{{AFX_MSG_MAP(CAgentDetailDlg)
  153. ON_WM_NCPAINT()
  154. ON_BN_CLICKED(IDC_BTNREFRESH, OnRefresh)
  155. ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
  156. ON_BN_CLICKED(IDC_STOPAGENT, OnStopAgent)
  157. ON_BN_CLICKED(IDC_VIEW_LOG, OnViewLog)
  158. ON_BN_CLICKED(IDC_PLUG_IN_RESULTS, OnPlugInResults)
  159. ON_WM_CLOSE()
  160. //}}AFX_MSG_MAP
  161. ON_MESSAGE(DCT_DETAIL_REFRESH, DoRefresh)
  162. END_MESSAGE_MAP()
  163. /////////////////////////////////////////////////////////////////////////////
  164. // CAgentDetailDlg message handlers
  165. BOOL CAgentDetailDlg::OnInitDialog()
  166. {
  167. CDialog::OnInitDialog();
  168. HRESULT hr = CoInitialize(NULL);
  169. if (SUCCEEDED(hr))
  170. m_bCoInitialized = TRUE;
  171. CString title;
  172. if ( m_JobGuid.length() )
  173. {
  174. // connect to local agent
  175. title.LoadString(IDS_PROGRESS_TITLE);
  176. }
  177. else
  178. {
  179. // connect to agent service on remote machine
  180. if ( ! m_pNode )
  181. {
  182. // if not auto closing display message box
  183. if (!m_bAutoClose)
  184. {
  185. CString message;
  186. message.LoadString(IDS_ServerNotFound);
  187. MessageBox(message);
  188. }
  189. OnOK();
  190. }
  191. m_ServerName = m_pNode->GetServer();
  192. title.FormatMessage(IDS_ServerAgentProgressTitle,m_ServerName);
  193. }
  194. SetWindowText(title);
  195. UpdateData(FALSE);
  196. //If not AR operation, set the flag to enable the close button
  197. if (m_format != 1)
  198. m_bAlwaysEnableClose = TRUE;
  199. else
  200. m_bAlwaysEnableClose = FALSE;
  201. switch (m_format)
  202. {
  203. // set the format to -1 to force a change
  204. case -1: m_format = -2; SetupOtherFormat(); break;
  205. case 0: m_format = -2; SetupFSTFormat();break;
  206. case 1: m_format = -2; SetupAcctReplFormat(); break;
  207. case 2: m_format = -2; SetupESTFormat(); break;
  208. };
  209. gSubWnd = m_hWnd;
  210. if ( m_pStats && (m_format>0) )
  211. {
  212. bDetailDone = TRUE;
  213. GetDlgItem(IDC_BTNREFRESH)->EnableWindow(FALSE);
  214. GetDlgItem(IDC_EDIT2)->EnableWindow(FALSE);
  215. GetDlgItem(IDC_REFRESH_LABEL)->EnableWindow(FALSE);
  216. GetDlgItem(IDC_STOPAGENT)->EnableWindow(FALSE);
  217. m_OKButton.EnableWindow(TRUE);
  218. // the agent has finished, show files, directories, and shares
  219. m_FilesExamined.Format(L"%ld",m_pStats->filesExamined);
  220. m_FilesChanged.Format(L"%ld",m_pStats->filesChanged);
  221. m_FilesUnchanged.Format(L"%ld",m_pStats->filesUnchanged);
  222. m_DirectoriesExamined.Format(L"%ld",m_pStats->directoriesExamined);
  223. m_DirectoriesChanged.Format(L"%ld",m_pStats->directoriesChanged);
  224. m_DirectoriesUnchanged.Format(L"%ld",m_pStats->directoriesUnchanged);
  225. m_SharesExamined.Format(L"%ld",m_pStats->sharesExamined);
  226. m_SharesChanged.Format(L"%ld",m_pStats->sharesChanged);
  227. m_SharesUnchanged.Format(L"%ld",m_pStats->sharesUnchanged);
  228. m_Status.LoadString(IDS_StatusCompleted);
  229. if ( m_PlugInText.GetLength() )
  230. {
  231. //Permanently hide the plug-in button, since our plug-ins
  232. // don't show any useful text
  233. // m_PlugInButton.ShowWindow(SW_SHOW);
  234. }
  235. UpdateData(FALSE);
  236. // if auto closing dialog
  237. if (m_bAutoClose)
  238. {
  239. OnOK();
  240. }
  241. }
  242. else
  243. {
  244. bDetailDone = FALSE;
  245. m_hBinding = NULL;
  246. DWORD threadID;
  247. HANDLE h = CreateThread(NULL,0,&RefreshThread,NULL,0,&threadID);
  248. CloseHandle(h);
  249. //hide the close button until the agent is done or stopped unless the flag is set
  250. //due to running this dialog for account replication
  251. if (m_bAlwaysEnableClose)
  252. m_OKButton.EnableWindow(TRUE);
  253. else
  254. m_OKButton.EnableWindow(FALSE);
  255. }
  256. return TRUE; // return TRUE unless you set the focus to a control
  257. // EXCEPTION: OCX Property Pages should return FALSE
  258. }
  259. DWORD
  260. DoRpcQuery(
  261. HANDLE hBinding, // in - handle to RPC binding
  262. LPUNKNOWN * ppUnk // out- pointer to remote agent COM object
  263. )
  264. {
  265. DWORD rc = 0;
  266. RpcTryExcept
  267. {
  268. rc = EaxcQueryInterface(hBinding,ppUnk);
  269. }
  270. RpcExcept(1)
  271. {
  272. rc = RpcExceptionCode();
  273. }
  274. RpcEndExcept
  275. if ( rc )
  276. {
  277. (*ppUnk ) = NULL;
  278. }
  279. return rc;
  280. }
  281. void CAgentDetailDlg::SetupAcctReplFormat()
  282. {
  283. // Changes the labels to reflect pertinent information when copying accounts
  284. UpdateData(TRUE);
  285. if ( m_format != 1 )
  286. {
  287. m_ChangedLabel.LoadString(IDS_AccountCopiedLabel);
  288. m_UnchangedLabel.LoadString(IDS_AccountErrorsLabel);
  289. m_FilesLabelText.LoadString(IDS_AccountUsersLabel);
  290. m_DirectoryLabelText.LoadString(IDS_AccountGroupsLabel);
  291. m_SharesLabelText.LoadString(IDS_AccountComputersLabel);
  292. m_format = 1;
  293. }
  294. UpdateData(FALSE);
  295. }
  296. void CAgentDetailDlg::SetupFSTFormat()
  297. {
  298. // Changes the labels to reflect pertinent information when translating security
  299. UpdateData(TRUE);
  300. if ( m_format != 0 )
  301. {
  302. if ( m_bGatheringInfo )
  303. {
  304. m_ChangedLabel.LoadString(IDS_Affected);
  305. m_UnchangedLabel.LoadString(IDS_Unaffected);
  306. }
  307. else
  308. {
  309. m_ChangedLabel.LoadString(IDS_ChangedLabel);
  310. m_UnchangedLabel.LoadString(IDS_UnchangedLabel);
  311. }
  312. m_FilesLabelText.LoadString(IDS_FilesLabel);
  313. m_DirectoryLabelText.LoadString(IDS_DirectoriesLabel);
  314. m_SharesLabelText.LoadString(IDS_SharesLabel);
  315. m_format = 0;
  316. }
  317. UpdateData(FALSE);
  318. }
  319. void CAgentDetailDlg::SetupESTFormat()
  320. {
  321. // Changes the labels to reflect pertinent information when translating exchange security
  322. UpdateData(TRUE);
  323. if ( m_format != 2 )
  324. {
  325. m_ChangedLabel.LoadString(IDS_ChangedLabel);
  326. m_UnchangedLabel.LoadString(IDS_UnchangedLabel);
  327. m_FilesLabelText.LoadString(IDS_MailboxesLabel);
  328. m_DirectoryLabelText.Empty();
  329. m_SharesLabelText.Empty();
  330. m_format = 2;
  331. }
  332. UpdateData(FALSE);
  333. }
  334. void CAgentDetailDlg::SetupOtherFormat()
  335. {
  336. // Changes the labels to reflect pertinent information when translating exchange security
  337. UpdateData(TRUE);
  338. if ( m_format != -1 )
  339. {
  340. m_ExaminedLabel.Empty();
  341. m_ChangedLabel.Empty();
  342. m_UnchangedLabel.Empty();
  343. m_FilesLabelText.Empty();
  344. m_DirectoryLabelText.Empty();
  345. m_SharesLabelText.Empty();
  346. m_FilesExamined.Empty();
  347. m_DirectoriesExamined.Empty();
  348. m_SharesExamined.Empty();
  349. m_FilesChanged.Empty();
  350. m_DirectoriesChanged.Empty();
  351. m_SharesChanged.Empty();
  352. m_FilesUnchanged.Empty();
  353. m_DirectoriesUnchanged.Empty();
  354. m_SharesUnchanged.Empty();
  355. m_format = -1;
  356. }
  357. UpdateData(FALSE);
  358. }
  359. void CAgentDetailDlg::OnRefresh()
  360. {
  361. DWORD rc = 0;
  362. HRESULT hr = S_OK;
  363. WCHAR * sBinding = NULL;
  364. IUnknown * pUnk = NULL;
  365. IVarSetPtr pVarSet;
  366. _bstr_t jobID;
  367. if (m_bCoInitialized)
  368. {
  369. try {
  370. if ( m_pNode )
  371. {
  372. jobID = m_pNode->GetJobID();
  373. }
  374. else
  375. {
  376. jobID = m_JobGuid;
  377. }
  378. m_AgentAlive = FALSE;
  379. m_StatusUnknown = FALSE;
  380. UpdateData(TRUE);
  381. if ( m_pAgent == NULL )
  382. {
  383. if ( m_pNode )
  384. {
  385. WCHAR server[MAX_PATH];
  386. server[0] = L'\\';
  387. server[1] = L'\\';
  388. UStrCpy(server+2,m_pNode->GetServer());
  389. rc = EaxBindCreate(server,&m_hBinding,&sBinding,TRUE);
  390. if ( ! rc )
  391. {
  392. pUnk = NULL;
  393. rc = DoRpcQuery(m_hBinding,&pUnk);
  394. if ( (!rc) && pUnk )
  395. {
  396. try {
  397. m_pAgent = pUnk;
  398. }
  399. catch(_com_error * e)
  400. {
  401. m_StatusUnknown = TRUE;
  402. // if not auto closing display message box
  403. if (!m_bAutoClose)
  404. {
  405. MessageBox(e->Description());
  406. }
  407. }
  408. catch(...)
  409. {
  410. pUnk = NULL;
  411. }
  412. if ( pUnk )
  413. pUnk->Release();
  414. }
  415. else
  416. {
  417. if ( rc == RPC_S_SERVER_UNAVAILABLE )
  418. {
  419. m_Status.LoadString(IDS_AgentNotRunning);
  420. }
  421. else if ( rc == E_NOTIMPL )
  422. {
  423. m_StatusUnknown = TRUE;
  424. m_Status.LoadString(IDS_CantMonitorOnNt351);
  425. }
  426. else
  427. {
  428. m_StatusUnknown = TRUE;
  429. m_Status.LoadString(IDS_CannotConnectToAgent);
  430. }
  431. }
  432. }
  433. else
  434. {
  435. m_StatusUnknown = TRUE;
  436. m_Status.LoadString(IDS_RPCBindFailed);
  437. }
  438. if ( m_StatusUnknown || rc )
  439. {
  440. // if we couldn't connect to the agent, check to see if there is a result file
  441. // we can get our data from instead
  442. BOOL bNoMoreRefresh = FALSE;
  443. if (m_pNode->HasFailed() && !m_pNode->IsInstalled())
  444. {
  445. bNoMoreRefresh = TRUE;
  446. m_Status.LoadString(IDS_Status_InstallFailed);
  447. UpdateData(FALSE);
  448. }
  449. else if (m_pNode->IsInstalled() && m_pNode->HasFailed())
  450. {
  451. bNoMoreRefresh = TRUE;
  452. m_Status.LoadString(IDS_Status_DidNotStart);
  453. UpdateData(FALSE);
  454. }
  455. else if (m_pNode->IsFinished() && *m_pNode->GetJobFile() && m_pNode->IsResultPullingTried()
  456. && m_pNode->HasResult())
  457. {
  458. DetailStats detailStats;
  459. WCHAR directory[MAX_PATH];
  460. WCHAR filename[MAX_PATH];
  461. CString plugInText;
  462. gData.GetResultDir(directory);
  463. memset(&detailStats,0,(sizeof detailStats));
  464. swprintf(filename,GET_STRING(IDS_AgentResultFileFmt),m_pNode->GetJobFile());
  465. if ( ReadResults(m_pNode,directory,filename,&detailStats,plugInText,FALSE) )
  466. {
  467. SetStats(&detailStats);
  468. SetPlugInText(plugInText);
  469. SetLogFile(m_pNode->GetLogPath());
  470. SetLogFileValid(m_pNode->GetLogPathValid());
  471. bNoMoreRefresh = TRUE;
  472. // the agent has finished, show files, directories, and shares
  473. if (m_format != -1)
  474. {
  475. m_FilesExamined.Format(L"%ld",m_pStats->filesExamined);
  476. m_FilesChanged.Format(L"%ld",m_pStats->filesChanged);
  477. m_FilesUnchanged.Format(L"%ld",m_pStats->filesUnchanged);
  478. m_DirectoriesExamined.Format(L"%ld",m_pStats->directoriesExamined);
  479. m_DirectoriesChanged.Format(L"%ld",m_pStats->directoriesChanged);
  480. m_DirectoriesUnchanged.Format(L"%ld",m_pStats->directoriesUnchanged);
  481. m_SharesExamined.Format(L"%ld",m_pStats->sharesExamined);
  482. m_SharesChanged.Format(L"%ld",m_pStats->sharesChanged);
  483. m_SharesUnchanged.Format(L"%ld",m_pStats->sharesUnchanged);
  484. }
  485. m_Status.LoadString(IDS_StatusCompleted);
  486. if ( m_PlugInText.GetLength() )
  487. {
  488. // Permanently hide the plug-in button, because our plug-ins don't
  489. // show any useful text.
  490. // m_PlugInButton.ShowWindow(SW_SHOW);
  491. }
  492. UpdateData(FALSE);
  493. }
  494. }
  495. else if (m_pNode->IsDoneMonitoring()) // we should let the main monitoring thread
  496. // do the job
  497. {
  498. // if we have result, use the last logic
  499. if (!m_pNode->HasResult())
  500. {
  501. bNoMoreRefresh = TRUE;
  502. if (m_pNode->QueryFailed())
  503. m_Status.LoadString(IDS_Status_Unknown);
  504. else
  505. m_Status = GET_WSTR(IDS_DCT_Status_Completed_With_Errors);
  506. UpdateData(FALSE);
  507. }
  508. }
  509. if (bNoMoreRefresh)
  510. {
  511. bDetailDone = TRUE;
  512. GetDlgItem(IDC_BTNREFRESH)->EnableWindow(FALSE);
  513. GetDlgItem(IDC_EDIT2)->EnableWindow(FALSE);
  514. GetDlgItem(IDC_REFRESH_LABEL)->EnableWindow(FALSE);
  515. GetDlgItem(IDC_STOPAGENT)->EnableWindow(FALSE);
  516. }
  517. }
  518. }
  519. else
  520. {
  521. hr = m_pAgent.GetActiveObject(CLSID_DCTAgent);
  522. if ( FAILED(hr) )
  523. {
  524. if ( hr == MK_E_UNAVAILABLE )
  525. {
  526. m_Status.LoadString(IDS_AgentNotRunning);
  527. }
  528. else
  529. {
  530. m_Status.FormatMessage(IDS_NoActiveAgent,hr);
  531. }
  532. }
  533. }
  534. }
  535. if ( m_pAgent != NULL )
  536. {
  537. hr = m_pAgent->raw_QueryJobStatus(jobID,&pUnk);
  538. if ( SUCCEEDED(hr) && pUnk )
  539. {
  540. m_AgentAlive = TRUE;
  541. pVarSet = pUnk;
  542. pUnk->Release();
  543. _bstr_t text = pVarSet->get(GET_BSTR(DCTVS_JobStatus));
  544. m_Status = (LPCWSTR)text;
  545. text = pVarSet->get(GET_BSTR(DCTVS_CurrentPath));
  546. m_Current = (LPCWSTR)text;
  547. text = pVarSet->get(GET_BSTR(DCTVS_CurrentOperation));
  548. m_Operation = (LPCWSTR)text;
  549. // Get the stats
  550. LONG num1,num2,num3,num4;
  551. UpdateData(FALSE);
  552. if ( !UStrICmp(m_Operation,GET_STRING(IDS_ACCT_REPL_OPERATION_TEXT)) )
  553. {
  554. // Set up the labels for account replication
  555. SetupAcctReplFormat();
  556. }
  557. else if ( !UStrICmp(m_Operation,GET_STRING(IDS_FST_OPERATION_TEXT)) )
  558. {
  559. SetupFSTFormat();
  560. }
  561. else if ( ! UStrICmp(m_Operation,GET_STRING(IDS_EST_OPERATION_TEXT)) )
  562. {
  563. SetupESTFormat();
  564. }
  565. else
  566. {
  567. if ( m_Current.GetLength() &&
  568. ( _wtoi(m_FilesExamined) + _wtoi(m_DirectoriesExamined) + _wtoi(m_SharesExamined)) == 0 )
  569. {
  570. // unless some stats have already been collected, hide the stats, if the operation
  571. // is not one that we have detailed stats for.
  572. SetupOtherFormat();
  573. }
  574. }
  575. switch ( m_format )
  576. {
  577. case 0: // FST
  578. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Files_Examined));
  579. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Files_Changed));
  580. m_FilesExamined.Format(L"%ld",num1);
  581. if ( ! m_bGatheringInfo )
  582. {
  583. m_FilesChanged.Format(L"%ld",num2);
  584. m_FilesUnchanged.Format(L"%ld",num1-num2);
  585. }
  586. else
  587. {
  588. m_FilesChanged.Empty();
  589. m_FilesUnchanged.Empty();
  590. }
  591. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Directories_Examined));
  592. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Directories_Changed));
  593. m_DirectoriesExamined.Format(L"%ld",num1);
  594. if ( ! m_bGatheringInfo )
  595. {
  596. m_DirectoriesChanged.Format(L"%ld",num2);
  597. m_DirectoriesUnchanged.Format(L"%ld",num1-num2);
  598. }
  599. else
  600. {
  601. m_DirectoriesChanged.Empty();
  602. m_DirectoriesUnchanged.Empty();
  603. }
  604. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Shares_Examined));
  605. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Shares_Changed));
  606. m_SharesExamined.Format(L"%ld",num1);
  607. if ( ! m_bGatheringInfo )
  608. {
  609. m_SharesChanged.Format(L"%ld",num2);
  610. m_SharesUnchanged.Format(L"%ld",num1-num2);
  611. }
  612. else
  613. {
  614. m_SharesChanged.Empty();
  615. m_SharesUnchanged.Empty();
  616. }
  617. break;
  618. case 1: // AcctRepl
  619. // files = user accounts
  620. // dirs = global groups + local groups
  621. // shares = computer accounts
  622. // examined = processed
  623. // changed = created + replaced
  624. // unchanged = errors
  625. // User stats
  626. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Users_Examined));
  627. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Users_Created));
  628. num3 = pVarSet->get(GET_BSTR(DCTVS_Stats_Users_Replaced));
  629. num4 = pVarSet->get(GET_BSTR(DCTVS_Stats_Users_Errors));
  630. m_FilesExamined.Format(L"%ld",num1);
  631. m_FilesChanged.Format(L"%ld",num2+num3);
  632. m_FilesUnchanged.Format(L"%ld",num4);
  633. // Global group stats
  634. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_GlobalGroups_Examined));
  635. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_GlobalGroups_Created));
  636. num3 = pVarSet->get(GET_BSTR(DCTVS_Stats_GlobalGroups_Replaced));
  637. num4 = pVarSet->get(GET_BSTR(DCTVS_Stats_GlobalGroups_Errors));
  638. // local group stats
  639. LONG num5, num6,num7, num8;
  640. num5 = pVarSet->get(GET_BSTR(DCTVS_Stats_LocalGroups_Examined));
  641. num6 = pVarSet->get(GET_BSTR(DCTVS_Stats_LocalGroups_Created));
  642. num7 = pVarSet->get(GET_BSTR(DCTVS_Stats_LocalGroups_Replaced));
  643. num8 = pVarSet->get(GET_BSTR(DCTVS_Stats_LocalGroups_Errors));
  644. m_DirectoriesExamined.Format(L"%ld",num1 + num5);
  645. m_DirectoriesChanged.Format(L"%ld",num2+num3 + num6+num7);
  646. m_DirectoriesUnchanged.Format(L"%ld",num4 + num8);
  647. // computer account stats
  648. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Computers_Examined));
  649. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Computers_Created));
  650. num3 = pVarSet->get(GET_BSTR(DCTVS_Stats_Computers_Replaced));
  651. num4 = pVarSet->get(GET_BSTR(DCTVS_Stats_Computers_Errors));
  652. m_SharesExamined.Format(L"%ld",num1);
  653. m_SharesChanged.Format(L"%ld",num2+num3);
  654. m_SharesUnchanged.Format(L"%ld",num4);
  655. break;
  656. case 2: // EST
  657. num1 = pVarSet->get(GET_BSTR(DCTVS_Stats_Mailboxes_Examined));
  658. num2 = pVarSet->get(GET_BSTR(DCTVS_Stats_Mailboxes_Changed));
  659. m_FilesExamined.Format(L"%ld",num1);
  660. m_FilesChanged.Format(L"%ld",num2);
  661. m_FilesUnchanged.Format(L"%ld",num1-num2);
  662. // since we are not doing anything with containers
  663. // we empty those field as well
  664. m_DirectoriesExamined.Empty();
  665. m_DirectoriesChanged.Empty();
  666. m_DirectoriesUnchanged.Empty();
  667. m_SharesExamined.Empty();
  668. m_SharesChanged.Empty();
  669. m_SharesUnchanged.Empty();
  670. break;
  671. case -1: // default (empty)
  672. m_FilesExamined.Empty();
  673. m_FilesChanged.Empty();
  674. m_FilesUnchanged.Empty();
  675. m_DirectoriesExamined.Empty();
  676. m_DirectoriesChanged.Empty();
  677. m_DirectoriesUnchanged.Empty();
  678. m_SharesExamined.Empty();
  679. m_SharesChanged.Empty();
  680. m_SharesUnchanged.Empty();
  681. break;
  682. }
  683. }
  684. else
  685. {
  686. if ( hr == DISP_E_UNKNOWNNAME )
  687. {
  688. m_StatusUnknown = TRUE;
  689. m_Status.FormatMessage(IDS_AgentJobNotFound,(WCHAR*)jobID);
  690. }
  691. else if ( hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE) )
  692. {
  693. if (m_pNode && m_pNode->IsJoinDomainWithRename())
  694. {
  695. m_pAgent = NULL; // this way, we will use the logic for m_pAgent == NULL
  696. }
  697. else
  698. m_Status.LoadString(IDS_AgentNoLongerRunning);
  699. }
  700. else
  701. {
  702. m_StatusUnknown = TRUE;
  703. m_Status.FormatMessage(IDS_QueryJobStatusFailed,hr);
  704. }
  705. }
  706. }
  707. }
  708. catch ( ... )
  709. {
  710. m_StatusUnknown = TRUE;
  711. m_Status.FormatMessage(IDS_ExceptionConnectingToAgent);
  712. //m_Current = step;
  713. }
  714. }
  715. if ( m_PlugInText.GetLength() )
  716. {
  717. // permanently hide the plug-in button, because our plug-ins
  718. // don't show any useful text
  719. //m_PlugInButton.ShowWindow(SW_SHOW);
  720. }
  721. //get the job log file when agent is done
  722. if ((!m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed))
  723. || !m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed_With_Errors)))
  724. && (m_pNode))
  725. {
  726. SetLogFile(m_pNode->GetLogPath());
  727. SetLogFileValid(m_pNode->GetLogPathValid());
  728. }
  729. if ( m_LogFile.GetLength() )
  730. {
  731. m_ViewLogButton.ShowWindow(SW_SHOW);
  732. if ( ! m_AgentAlive || !m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed))
  733. || !m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed_With_Errors)))
  734. {
  735. m_ViewLogButton.EnableWindow(TRUE);
  736. }
  737. else
  738. {
  739. m_ViewLogButton.EnableWindow(FALSE);
  740. }
  741. }
  742. else
  743. {
  744. m_ViewLogButton.ShowWindow(SW_HIDE);
  745. }
  746. if ( ! m_AgentAlive || !m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed))
  747. || !m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed_With_Errors)))
  748. {
  749. // Disable the refresh button when the status changes to Completed.
  750. if ( !m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed))
  751. || !m_Status.CompareNoCase(GET_STRING(IDS_DCT_Status_Completed_With_Errors)))
  752. {
  753. if ( GetDefID() == IDC_BTNREFRESH )
  754. {
  755. SetDefID(IDOK);
  756. }
  757. m_RefreshButton.EnableWindow(FALSE);
  758. }
  759. // disable the stop agent button any time the agent is not running
  760. m_StopAgentButton.EnableWindow(FALSE);
  761. //enable the close button any time the agent is not running
  762. m_OKButton.EnableWindow(TRUE);
  763. // if auto closing dialog
  764. if (m_bAutoClose)
  765. {
  766. OnOK();
  767. }
  768. }
  769. else
  770. {
  771. // enable the refresh and stop agent buttons when the agent is alive and running
  772. m_RefreshButton.EnableWindow(TRUE);
  773. m_StopAgentButton.EnableWindow(TRUE);
  774. }
  775. UpdateData(FALSE);
  776. }
  777. void CAgentDetailDlg::OnOK()
  778. {
  779. UpdateData(TRUE);
  780. if (!m_bAutoClose)
  781. {
  782. CString str;
  783. CString title;
  784. str = GET_STRING(IDS_DCT_Status_InProgress);
  785. title.LoadString(IDS_MessageTitle);
  786. if ( ! m_hBinding ) // only show the warning for the local agent
  787. {
  788. if ( str == m_Status )
  789. {
  790. str.LoadString(IDS_CannotCloseWhileAgentIsRunning);
  791. MessageBox(str,title,MB_ICONHAND | MB_OK);
  792. return;
  793. }
  794. }
  795. }
  796. bDetailDone = TRUE;
  797. if ( m_pAgent )
  798. {
  799. m_pAgent = NULL;
  800. }
  801. if (m_bCoInitialized)
  802. {
  803. CoUninitialize();
  804. m_bCoInitialized = FALSE;
  805. }
  806. CDialog::OnOK();
  807. }
  808. void CAgentDetailDlg::OnChangeEdit2()
  809. {
  810. UpdateData(TRUE);
  811. detailInterval = _wtoi(m_RefreshRate);
  812. if ( detailInterval <= 0 )
  813. {
  814. detailInterval = 1;
  815. }
  816. }
  817. LRESULT CAgentDetailDlg::DoRefresh(UINT nID, long x)
  818. {
  819. OnRefresh();
  820. return 0;
  821. }
  822. void CAgentDetailDlg::OnStopAgent()
  823. {
  824. DWORD rc = 0;
  825. HRESULT hr = S_OK;
  826. CString message;
  827. CString title;
  828. if (!m_bCoInitialized)
  829. return;
  830. title.LoadString(IDS_MessageTitle);
  831. if ( m_hBinding )
  832. {
  833. message.LoadString(IDS_ConfirmStopAgent);
  834. if ( MessageBox(message,title,MB_ICONQUESTION | MB_YESNO) == IDYES )
  835. {
  836. _bstr_t jobID = m_pNode->GetJobID();
  837. if ( m_pAgent )
  838. {
  839. hr = m_pAgent->raw_CancelJob(jobID);
  840. m_pAgent = NULL;
  841. }
  842. else
  843. {
  844. message.LoadString(IDS_AgentNotRunning);
  845. MessageBox(message,NULL,MB_OK);
  846. }
  847. if ( FAILED(hr) )
  848. {
  849. message.FormatMessage(IDS_CancelJobFailed,hr);
  850. MessageBox(message,NULL,MB_ICONERROR | MB_OK);
  851. }
  852. if ( rc )
  853. {
  854. message.FormatMessage(IDS_StopAgentFailed,rc);
  855. MessageBox(message,NULL,MB_ICONERROR|MB_OK);
  856. }
  857. if ( SUCCEEDED(hr) && !rc )
  858. {
  859. OnOK();
  860. }
  861. }
  862. }
  863. else
  864. {
  865. // Local agent here
  866. if ( m_pAgent )
  867. {
  868. message.LoadString(IDS_ConfirmCancelJob);
  869. if ( MessageBox(message,NULL,MB_ICONQUESTION | MB_YESNO) == IDYES )
  870. {
  871. hr = m_pAgent->raw_CancelJob(m_JobGuid);
  872. if ( FAILED(hr) )
  873. {
  874. message.FormatMessage(IDS_StopAgentFailedHexResult,hr);
  875. MessageBox(message,NULL,MB_ICONERROR | MB_OK);
  876. }
  877. else
  878. {
  879. gbCancelled = TRUE;
  880. }
  881. }
  882. }
  883. else
  884. {
  885. // TODO:error message
  886. }
  887. }
  888. }
  889. void CAgentDetailDlg::OnViewLog()
  890. {
  891. UpdateData(TRUE);
  892. if ( ! m_LogFile.IsEmpty() )
  893. {
  894. if (m_LogFileIsValid)
  895. {
  896. // Launch the logfile
  897. CString cmd;
  898. STARTUPINFO startupInfo;
  899. PROCESS_INFORMATION processInfo;
  900. TCHAR* pszSystemDirectoryName = NULL;
  901. CString message;
  902. CString title;
  903. pszSystemDirectoryName = GetSystemDirectoryHelper();
  904. if(!pszSystemDirectoryName)
  905. {
  906. // we could not get the system directory name, we should bail out, otherwise we might launch
  907. // malicious process
  908. title.LoadString(IDS_MessageTitle);
  909. message.LoadString(IDS_LaunchNotePadFailed);
  910. MessageBox(message, title, MB_ICONERROR | MB_OK);
  911. return;
  912. }
  913. memset(&startupInfo,0,(sizeof startupInfo));
  914. startupInfo.cb = (sizeof startupInfo);
  915. cmd.FormatMessage(IDS_NotepadCommandLine,pszSystemDirectoryName,m_LogFile);
  916. delete [] pszSystemDirectoryName;
  917. CreateProcess(NULL,cmd.GetBuffer(0),NULL,NULL,TRUE,0,NULL,NULL,&startupInfo,&processInfo);
  918. }
  919. else
  920. {
  921. CString title;
  922. CString message;
  923. title.LoadString(IDS_MessageTitle);
  924. message.FormatMessage(IDS_LogfileIsInvalid,m_LogFile,m_ServerName);
  925. MessageBox(message,title,MB_ICONERROR | MB_OK);
  926. }
  927. }
  928. }
  929. void CAgentDetailDlg::OnPlugInResults()
  930. {
  931. UpdateData(TRUE);
  932. MessageBox(m_PlugInText);
  933. }
  934. void CAgentDetailDlg::OnClose()
  935. {
  936. UpdateData(TRUE);
  937. CString str;
  938. CString title;
  939. str = GET_STRING(IDS_DCT_Status_InProgress);
  940. title.LoadString(IDS_MessageTitle);
  941. if ( ! m_hBinding ) // only show the warning for the local agent
  942. {
  943. if ( str == m_Status )
  944. {
  945. str.LoadString(IDS_ConfirmCloseWhileAgentIsRunning);
  946. if ( IDYES != MessageBox(str,title,MB_ICONQUESTION | MB_YESNO) )
  947. return;
  948. }
  949. }
  950. bDetailDone = TRUE;
  951. if ( m_pAgent )
  952. {
  953. m_pAgent = NULL;
  954. }
  955. if (m_bCoInitialized)
  956. {
  957. CoUninitialize();
  958. m_bCoInitialized = FALSE;
  959. }
  960. CDialog::OnClose();
  961. }
  962. BOOL CAgentDetailDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  963. {
  964. // TODO: Add your specialized code here and/or call the base class
  965. TRACE(L"Command(%lx,%lx)\n",wParam,lParam);
  966. if ( wParam == WM_DESTROY )
  967. {
  968. CString str;
  969. CString title;
  970. CString str2;
  971. str = GET_STRING(IDS_DCT_Status_InProgress);
  972. str2 = GET_STRING(IDS_DCT_Status_NotStarted);
  973. title.LoadString(IDS_MessageTitle);
  974. if ( ! m_hBinding ) // only show the warning for the local agent
  975. {
  976. if ( str == m_Status )
  977. {
  978. str.LoadString(IDS_ConfirmCloseWhileAgentIsRunning);
  979. if ( IDYES != MessageBox(str,title,MB_ICONQUESTION | MB_YESNO) )
  980. return 0;
  981. }
  982. }
  983. bDetailDone = TRUE;
  984. if ( m_pAgent )
  985. {
  986. m_pAgent = NULL;
  987. }
  988. if (m_bCoInitialized)
  989. {
  990. CoUninitialize();
  991. m_bCoInitialized = FALSE;
  992. }
  993. return CDialog::OnCommand(wParam, lParam);
  994. }
  995. else
  996. {
  997. return CDialog::OnCommand(wParam, lParam);
  998. }
  999. }
  1000. // OnNcPaint Handler
  1001. //
  1002. // This handler is being overridden to handle hiding of the dialog.
  1003. // This prevents initial painting of the dialog which causes a flash
  1004. // if the dialog is hidden after this message. This is the first message
  1005. // where the dialog can be hidden. Trying to hide the dialog before this
  1006. // point gets overridden.
  1007. void CAgentDetailDlg::OnNcPaint()
  1008. {
  1009. if (m_bAutoHide)
  1010. {
  1011. if (IsWindowVisible())
  1012. {
  1013. ShowWindow(SW_HIDE);
  1014. }
  1015. }
  1016. else
  1017. {
  1018. CDialog::OnNcPaint();
  1019. }
  1020. }