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.

985 lines
33 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. alrtactp.cpp
  5. Abstract:
  6. Implementation of the alerts action property page.
  7. --*/
  8. #include "stdafx.h"
  9. #include <assert.h>
  10. #include <common.h>
  11. #include "smcfgmsg.h"
  12. #include "globals.h"
  13. #include "smlogs.h"
  14. #include "smlogqry.h"
  15. #include "smalrtq.h"
  16. #include "alrtcmdd.h"
  17. #include "AlrtActP.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. USE_HANDLE_MACROS("SMLOGCFG(alrtactp.cpp)");
  24. static ULONG
  25. s_aulHelpIds[] =
  26. {
  27. IDC_ACTION_APPLOG_CHK, IDH_ACTION_APPLOG_CHK,
  28. IDC_ACTION_NETMSG_CHK, IDH_ACTION_NETMSG_CHK,
  29. IDC_ACTION_NETMSG_NAME_EDIT, IDH_ACTION_NETMSG_NAME_EDIT,
  30. IDC_ACTION_EXECUTE_CHK, IDH_ACTION_EXECUTE_CHK,
  31. IDC_ACTION_EXECUTE_EDIT, IDH_ACTION_EXECUTE_EDIT,
  32. IDC_ACTION_EXECUTE_BROWSE_BTN, IDH_ACTION_EXECUTE_BROWSE_BTN,
  33. IDC_ACTION_CMD_ARGS_BTN, IDH_ACTION_CMD_ARGS_BTN,
  34. IDC_ACTION_START_LOG_CHK, IDH_ACTION_START_LOG_CHK,
  35. IDC_ACTION_START_LOG_COMBO, IDH_ACTION_START_LOG_COMBO,
  36. IDC_ACTION_CMD_ARGS_DISPLAY, IDH_ACTION_CMD_ARGS_DISPLAY,
  37. 0,0
  38. };
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CAlertActionProp property page
  41. IMPLEMENT_DYNCREATE(CAlertActionProp, CSmPropertyPage)
  42. CAlertActionProp::CAlertActionProp(MMC_COOKIE mmcCookie, LONG_PTR hConsole)
  43. : CSmPropertyPage(CAlertActionProp::IDD, hConsole),
  44. m_pAlertInfo ( NULL )
  45. {
  46. //::OutputDebugStringA("\nCAlertActionProp::CAlertActionProp");
  47. // init variables from arg list
  48. m_pAlertQuery = reinterpret_cast <CSmAlertQuery *>(mmcCookie);
  49. ASSERT ( m_pAlertQuery->CastToAlertQuery() );
  50. m_pQuery = dynamic_cast <CSmLogQuery*> (m_pAlertQuery);
  51. // init AFX data
  52. InitAfxDataItems();
  53. }
  54. CAlertActionProp::CAlertActionProp()
  55. : CSmPropertyPage(CAlertActionProp::IDD),
  56. m_pAlertQuery ( NULL ),
  57. m_pAlertInfo ( NULL )
  58. {
  59. ASSERT (FALSE); // the constructor w/ args should be used instead
  60. // init AFX data
  61. InitAfxDataItems();
  62. }
  63. CAlertActionProp::~CAlertActionProp()
  64. {
  65. if (m_pAlertInfo != NULL) {
  66. delete [] (CHAR*)m_pAlertInfo;
  67. }
  68. }
  69. void CAlertActionProp::InitAfxDataItems ()
  70. {
  71. //{{AFX_DATA_INIT(CAlertActionProp)
  72. m_Action_bLogEvent = TRUE;
  73. m_Action_bExecCmd = FALSE;
  74. m_Action_bSendNetMsg = FALSE;
  75. m_Action_bStartLog = FALSE;
  76. m_Action_strCmdPath = L"";
  77. m_Action_strNetName = L"";
  78. m_CmdArg_bAlertName = FALSE;
  79. m_CmdArg_bDateTime = FALSE;
  80. m_CmdArg_bLimitValue = FALSE;
  81. m_CmdArg_bCounterPath = FALSE;
  82. m_CmdArg_bSingleArg = FALSE;
  83. m_CmdArg_bMeasuredValue = FALSE;
  84. m_CmdArg_bUserText = FALSE;
  85. m_CmdArg_strUserText = L"";
  86. m_nCurLogSel = LB_ERR;
  87. //}}AFX_DATA_INIT
  88. }
  89. void CAlertActionProp::DoDataExchange(CDataExchange* pDX)
  90. {
  91. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  92. CPropertyPage::DoDataExchange(pDX);
  93. //{{AFX_DATA_MAP(CAlertActionProp)
  94. DDX_Control(pDX, IDC_ACTION_START_LOG_COMBO, m_pLogCombo);
  95. DDX_Check(pDX, IDC_ACTION_APPLOG_CHK, m_Action_bLogEvent);
  96. DDX_Check(pDX, IDC_ACTION_EXECUTE_CHK, m_Action_bExecCmd);
  97. DDX_Check(pDX, IDC_ACTION_NETMSG_CHK, m_Action_bSendNetMsg);
  98. DDX_Check(pDX, IDC_ACTION_START_LOG_CHK, m_Action_bStartLog);
  99. DDX_CBIndex(pDX, IDC_ACTION_START_LOG_COMBO, m_nCurLogSel);
  100. DDX_Text(pDX, IDC_ACTION_EXECUTE_EDIT, m_Action_strCmdPath);
  101. DDV_MaxChars(pDX, m_Action_strCmdPath, MAX_PATH );
  102. DDX_Text(pDX, IDC_ACTION_NETMSG_NAME_EDIT, m_Action_strNetName);
  103. DDV_MaxChars(pDX, m_Action_strNetName, MAX_PATH );
  104. //}}AFX_DATA_MAP
  105. }
  106. BEGIN_MESSAGE_MAP(CAlertActionProp, CSmPropertyPage)
  107. //{{AFX_MSG_MAP(CAlertActionProp)
  108. ON_WM_DESTROY()
  109. ON_BN_CLICKED(IDC_ACTION_EXECUTE_BROWSE_BTN, OnActionExecuteBrowseBtn)
  110. ON_BN_CLICKED(IDC_ACTION_APPLOG_CHK, OnActionApplogChk)
  111. ON_BN_CLICKED(IDC_ACTION_NETMSG_CHK, OnActionNetmsgChk)
  112. ON_BN_CLICKED(IDC_ACTION_EXECUTE_CHK, OnActionExecuteChk)
  113. ON_BN_CLICKED(IDC_ACTION_CMD_ARGS_BTN, OnActionCmdArgsBtn)
  114. ON_BN_CLICKED(IDC_ACTION_START_LOG_CHK, OnActionStartLogChk)
  115. ON_EN_CHANGE(IDC_ACTION_NETMSG_NAME_EDIT, OnNetNameTextEditChange)
  116. ON_EN_CHANGE(IDC_ACTION_EXECUTE_EDIT, OnCmdPathTextEditChange)
  117. ON_EN_KILLFOCUS(IDC_ACTION_EXECUTE_EDIT, OnCmdPathTextEditChange)
  118. ON_CBN_SELENDOK(IDC_ACTION_START_LOG_COMBO, OnSelendokStartLogCombo)
  119. //}}AFX_MSG_MAP
  120. END_MESSAGE_MAP()
  121. BOOL
  122. CAlertActionProp::SetControlState()
  123. {
  124. // Net Message items
  125. (GetDlgItem(IDC_ACTION_NETMSG_NAME_EDIT))->EnableWindow(m_Action_bSendNetMsg);
  126. // command line items
  127. if ( !m_Action_bExecCmd ) {
  128. m_Action_strCmdPath.Empty();
  129. SetDlgItemText ( IDC_ACTION_EXECUTE_EDIT, m_Action_strCmdPath );
  130. }
  131. (GetDlgItem(IDC_ACTION_EXECUTE_EDIT))->EnableWindow(m_Action_bExecCmd);
  132. (GetDlgItem(IDC_ACTION_EXECUTE_BROWSE_BTN))->EnableWindow(m_Action_bExecCmd);
  133. (GetDlgItem(IDC_ACTION_CMD_ARGS_BTN))->EnableWindow(m_Action_bExecCmd);
  134. (GetDlgItem(IDC_ACTION_CMD_ARGS_CAPTION))->EnableWindow(m_Action_bExecCmd);
  135. (GetDlgItem(IDC_ACTION_CMD_ARGS_DISPLAY))->EnableWindow(m_Action_bExecCmd);
  136. // perf data Log entries
  137. (GetDlgItem(IDC_ACTION_START_LOG_COMBO))->EnableWindow(m_Action_bStartLog);
  138. return TRUE;
  139. }
  140. BOOL
  141. CAlertActionProp::LoadLogQueries ( DWORD dwLogType )
  142. {
  143. DWORD dwStatus = ERROR_SUCCESS;
  144. DWORD dwQueryIndex = 0;
  145. LONG lEnumStatus = ERROR_SUCCESS;
  146. WCHAR szQueryName[MAX_PATH + 1];
  147. DWORD dwQueryNameSize = MAX_PATH;
  148. LPWSTR szCollectionName = NULL;
  149. UINT uiCollectionNameLen = 0;
  150. FILETIME ftLastWritten;
  151. HKEY hKeyQuery;
  152. HKEY hKeyLogService;
  153. DWORD dwRegValue;
  154. dwStatus = RegOpenKeyExW (
  155. HKEY_LOCAL_MACHINE, // handle of open key
  156. L"System\\CurrentControlSet\\Services\\Sysmonlog\\Log Queries", // address of name of subkey to open
  157. 0L,
  158. KEY_READ, // reserved REGSAM samDesired, // security access mask
  159. &hKeyLogService);
  160. if (dwStatus != ERROR_SUCCESS) return FALSE;
  161. // Load all queries for the specified registry key.
  162. // Enumerate the log names and create a new log object
  163. // for each one found.
  164. while ((lEnumStatus = RegEnumKeyEx (hKeyLogService,
  165. dwQueryIndex, szQueryName, &dwQueryNameSize,
  166. NULL, NULL, NULL, &ftLastWritten)) == ERROR_SUCCESS) {
  167. // open the query specified
  168. dwStatus = RegOpenKeyExW (
  169. hKeyLogService,
  170. szQueryName,
  171. 0,
  172. KEY_READ,
  173. &hKeyQuery);
  174. if ( ERROR_SUCCESS == dwStatus ) {
  175. //
  176. // create a new object and add it to the query list
  177. //
  178. // Determine the log type.
  179. //
  180. dwRegValue = SLQ_LAST_LOG_TYPE + 1;
  181. dwStatus = (DWORD) CSmLogQuery::ReadRegistryDwordValue (
  182. hKeyQuery,
  183. IDS_REG_LOG_TYPE,
  184. SLQ_LAST_LOG_TYPE + 1, // Invalid value
  185. &dwRegValue );
  186. if ( ( ERROR_SUCCESS == dwStatus )
  187. && ( dwLogType == dwRegValue ) )
  188. {
  189. // Query key is Guid if written by post Win2000 snapin.
  190. // Query key is name if written by Win2000 snapin.
  191. dwStatus = CSmLogQuery::SmNoLocReadRegIndStrVal (
  192. hKeyQuery,
  193. IDS_REG_COLLECTION_NAME,
  194. NULL,
  195. &szCollectionName,
  196. &uiCollectionNameLen );
  197. ASSERT ( MAX_PATH >= uiCollectionNameLen );
  198. if ( ERROR_SUCCESS == dwStatus
  199. && NULL != szCollectionName )
  200. {
  201. if ( 0 < lstrlen ( szCollectionName )
  202. && ( MAX_PATH >= lstrlen ( szCollectionName ) ) )
  203. {
  204. // Length of szCollectionName checked above.
  205. lstrcpy ( szQueryName, szCollectionName );
  206. }
  207. G_FREE ( szCollectionName );
  208. szCollectionName = NULL;
  209. }
  210. // add this to the combo box
  211. m_pLogCombo.AddString (szQueryName);
  212. }
  213. RegCloseKey (hKeyQuery);
  214. }
  215. // set up for the next item in the list
  216. dwQueryNameSize = sizeof (szQueryName) / sizeof (szQueryName[0]);
  217. dwQueryIndex++;
  218. memset (szQueryName, 0, sizeof (szQueryName));
  219. }
  220. RegCloseKey (hKeyLogService);
  221. return TRUE;
  222. }
  223. BOOL
  224. CAlertActionProp::IsValidLocalData()
  225. {
  226. BOOL bActionSet = FALSE;
  227. INT iPrevLength = 0;
  228. BOOL bUpdateNetNameUI = FALSE;
  229. ResourceStateManager rsm;
  230. if (m_Action_bLogEvent) {
  231. bActionSet = TRUE;
  232. }
  233. // assumes UpdateData has been called
  234. // Trim text fields before validating.
  235. iPrevLength = m_Action_strCmdPath.GetLength();
  236. m_Action_strCmdPath.TrimLeft();
  237. m_Action_strCmdPath.TrimRight();
  238. if ( iPrevLength != m_Action_strCmdPath.GetLength() ) {
  239. SetDlgItemText ( IDC_ACTION_EXECUTE_EDIT, m_Action_strCmdPath );
  240. }
  241. iPrevLength = m_Action_strNetName.GetLength();
  242. m_Action_strNetName.TrimLeft();
  243. m_Action_strNetName.TrimRight();
  244. if ( iPrevLength != m_Action_strNetName.GetLength() ) {
  245. bUpdateNetNameUI = TRUE;
  246. }
  247. if (m_Action_bSendNetMsg) {
  248. // make sure a net name has been entered
  249. while ( L'\\' == m_Action_strNetName[0] ) {
  250. // NetMessageBufferSend does not understand machine names preceded by "\\"
  251. m_Action_strNetName = m_Action_strNetName.Right( m_Action_strNetName.GetLength() - 1 );
  252. bUpdateNetNameUI = TRUE;
  253. }
  254. if (m_Action_strNetName.GetLength() == 0) {
  255. CString strMessage;
  256. strMessage.LoadString ( IDS_ACTION_ERR_NONETNAME );
  257. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  258. SetFocusAnyPage ( IDC_ACTION_NETMSG_NAME_EDIT );
  259. return FALSE;
  260. }
  261. bActionSet = TRUE;
  262. }
  263. if ( bUpdateNetNameUI ) {
  264. SetDlgItemText ( IDC_ACTION_NETMSG_NAME_EDIT, m_Action_strNetName );
  265. }
  266. if (m_Action_bExecCmd) {
  267. // make sure a command file has been entered
  268. if (m_Action_strCmdPath.GetLength() == 0) {
  269. CString strMessage;
  270. strMessage.LoadString ( IDS_ACTION_ERR_NOCMDFILE );
  271. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  272. SetFocusAnyPage ( IDC_ACTION_EXECUTE_EDIT );
  273. return FALSE;
  274. }
  275. // If on local machine, make sure the command file exists.
  276. if ( m_pAlertQuery->GetLogService()->IsLocalMachine() ) {
  277. DWORD dwStatus;
  278. dwStatus = IsCommandFilePathValid ( m_Action_strCmdPath );
  279. if ( ERROR_SUCCESS != dwStatus ) {
  280. CString strMessage;
  281. FormatSmLogCfgMessage (
  282. strMessage,
  283. m_hModule,
  284. dwStatus );
  285. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  286. SetFocusAnyPage ( IDC_ACTION_EXECUTE_EDIT );
  287. return FALSE;
  288. }
  289. }
  290. bActionSet = TRUE;
  291. }
  292. if (m_Action_bStartLog ) {
  293. // make sure a log has been selected
  294. if (m_pLogCombo.GetCurSel() == CB_ERR) {
  295. CString strMessage;
  296. strMessage.LoadString ( IDS_ACTION_ERR_NOLOGNAME );
  297. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  298. SetFocusAnyPage ( IDC_ACTION_START_LOG_COMBO );
  299. return FALSE;
  300. }
  301. bActionSet = TRUE;
  302. }
  303. if (!bActionSet ) {
  304. // make sure some action has been selected
  305. CString strMessage;
  306. strMessage.LoadString ( IDS_ACTION_ERR_NOACTION );
  307. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  308. return FALSE;
  309. }
  310. return bActionSet;
  311. }
  312. void
  313. CAlertActionProp::UpdateCmdActionBox ()
  314. {
  315. UpdateData(TRUE);
  316. SetControlState();
  317. SetModifiedPage(TRUE);
  318. }
  319. /////////////////////////////////////////////////////////////////////////////
  320. // CAlertActionProp message handlers
  321. BOOL
  322. CAlertActionProp::OnSetActive()
  323. {
  324. BOOL bReturn = TRUE;
  325. bReturn = CSmPropertyPage::OnSetActive();
  326. if ( bReturn ) {
  327. m_pAlertQuery->GetPropPageSharedData ( &m_SharedData );
  328. }
  329. return bReturn;
  330. }
  331. BOOL
  332. CAlertActionProp::OnKillActive()
  333. {
  334. BOOL bContinue = TRUE;
  335. ResourceStateManager rsm;
  336. // Parent class OnKillActive calls UpdateData(TRUE)
  337. bContinue = CPropertyPage::OnKillActive();
  338. if ( bContinue ) {
  339. bContinue = IsValidData(m_pAlertQuery, VALIDATE_FOCUS );
  340. if ( bContinue ) {
  341. // Save property page shared data.
  342. m_pAlertQuery->SetPropPageSharedData ( &m_SharedData );
  343. }
  344. }
  345. if ( bContinue ) {
  346. SetIsActive ( FALSE );
  347. }
  348. return bContinue;
  349. }
  350. BOOL
  351. CAlertActionProp::OnApply()
  352. {
  353. DWORD dwFlags = 0;
  354. DWORD dwBufferSize = sizeof(ALERT_ACTION_INFO);
  355. LPWSTR szNextString;
  356. INT nCurLogSel = CB_ERR;
  357. BOOL bContinue = TRUE;
  358. ResourceStateManager rsm;
  359. // get current settings
  360. bContinue = UpdateData(TRUE);
  361. if ( bContinue ) {
  362. bContinue = IsValidData( m_pAlertQuery, VALIDATE_APPLY );
  363. }
  364. if ( bContinue ) {
  365. bContinue = SampleTimeIsLessThanSessionTime ( m_pAlertQuery );
  366. }
  367. // Write the data to the query.
  368. if ( bContinue ) {
  369. dwFlags |= (m_Action_bLogEvent ? ALRT_ACTION_LOG_EVENT : 0);
  370. dwFlags |= (m_Action_bExecCmd ? ALRT_ACTION_EXEC_CMD : 0);
  371. dwFlags |= (m_Action_bSendNetMsg ? ALRT_ACTION_SEND_MSG : 0);
  372. dwFlags |= (m_Action_bStartLog ? ALRT_ACTION_START_LOG : 0);
  373. if (m_Action_bSendNetMsg) {
  374. dwBufferSize += (m_Action_strNetName.GetLength() + 1) * sizeof (WCHAR);
  375. }
  376. if (m_Action_bExecCmd) {
  377. dwBufferSize += (m_Action_strCmdPath.GetLength() + 1) * sizeof (WCHAR);
  378. dwBufferSize += (m_CmdArg_strUserText .GetLength() + 1) * sizeof (WCHAR);
  379. dwFlags |= (m_CmdArg_bAlertName ? ALRT_CMD_LINE_A_NAME : 0);
  380. dwFlags |= (m_CmdArg_bDateTime ? ALRT_CMD_LINE_D_TIME : 0);
  381. dwFlags |= (m_CmdArg_bLimitValue ? ALRT_CMD_LINE_L_VAL : 0);
  382. dwFlags |= (m_CmdArg_bCounterPath ? ALRT_CMD_LINE_C_NAME : 0);
  383. dwFlags |= (m_CmdArg_bSingleArg ? ALRT_CMD_LINE_SINGLE : 0);
  384. dwFlags |= (m_CmdArg_bMeasuredValue ? ALRT_CMD_LINE_M_VAL : 0);
  385. dwFlags |= (m_CmdArg_bUserText ? ALRT_CMD_LINE_U_TEXT : 0);
  386. }
  387. if (m_Action_bStartLog) {
  388. nCurLogSel = m_pLogCombo.GetCurSel();
  389. if (nCurLogSel != CB_ERR) {
  390. dwBufferSize += (m_pLogCombo.GetLBTextLen(nCurLogSel) + 1) * sizeof(WCHAR);
  391. }
  392. }
  393. if (m_pAlertInfo != NULL) delete [] (CHAR*)(m_pAlertInfo);
  394. MFC_TRY
  395. m_pAlertInfo = (PALERT_ACTION_INFO) new CHAR[dwBufferSize];
  396. MFC_CATCH_MINIMUM
  397. if (m_pAlertInfo != NULL) {
  398. m_pAlertInfo->dwSize = dwBufferSize;
  399. m_pAlertInfo->dwActionFlags = dwFlags;
  400. szNextString = (LPWSTR)&m_pAlertInfo[1];
  401. if ((m_Action_bSendNetMsg) && (m_Action_strNetName.GetLength() > 0)) {
  402. m_pAlertInfo->szNetName = szNextString;
  403. // Length of szNetName calculated from length of m_Action_strNetName
  404. lstrcpyW(m_pAlertInfo->szNetName, (LPCWSTR)m_Action_strNetName);
  405. szNextString += m_Action_strNetName.GetLength() + 1;
  406. } else {
  407. m_pAlertInfo->szNetName = NULL;
  408. }
  409. if (m_Action_bExecCmd) {
  410. if (m_Action_strCmdPath.GetLength() > 0) {
  411. m_pAlertInfo->szCmdFilePath = szNextString;
  412. // Length of szCmdFilePath calculated from length of m_Action_strCmdPath
  413. lstrcpyW (m_pAlertInfo->szCmdFilePath, (LPCWSTR)m_Action_strCmdPath);
  414. szNextString += m_Action_strCmdPath.GetLength() + 1;
  415. } else {
  416. m_pAlertInfo->szCmdFilePath = NULL;
  417. }
  418. if (m_CmdArg_strUserText.GetLength() > 0) {
  419. m_pAlertInfo->szUserText = szNextString;
  420. // Length of szUserText calculated from length of m_CmdArg_strUserText
  421. lstrcpyW (m_pAlertInfo->szUserText, (LPCWSTR)m_CmdArg_strUserText);
  422. szNextString += m_CmdArg_strUserText.GetLength() + 1;
  423. } else {
  424. m_pAlertInfo->szUserText = NULL;
  425. }
  426. } else {
  427. m_pAlertInfo->szCmdFilePath = NULL;
  428. m_pAlertInfo->szUserText = NULL;
  429. }
  430. if ((m_Action_bStartLog) && (nCurLogSel != CB_ERR)) {
  431. // get log name
  432. m_pAlertInfo->szLogName = szNextString; // for now
  433. m_pLogCombo.GetLBText(nCurLogSel, szNextString);
  434. } else {
  435. m_pAlertInfo->szLogName = NULL;
  436. }
  437. }
  438. if ( bContinue ) {
  439. // ApplyRunAs must be called before UpdateService
  440. bContinue = ApplyRunAs(m_pAlertQuery);
  441. }
  442. bContinue = CSmPropertyPage::OnApply();
  443. if ( bContinue ) {
  444. bContinue = ( ERROR_SUCCESS == m_pAlertQuery->SetActionInfo ( m_pAlertInfo ) );
  445. }
  446. if ( bContinue ) {
  447. // Save property page shared data.
  448. m_pAlertQuery->UpdatePropPageSharedData();
  449. bContinue = UpdateService( m_pAlertQuery, FALSE );
  450. }
  451. }
  452. return bContinue;
  453. }
  454. void
  455. CAlertActionProp::OnCancel()
  456. {
  457. CPropertyPage::OnCancel();
  458. }
  459. void
  460. CAlertActionProp::OnActionCmdArgsBtn()
  461. {
  462. DWORD dwStatus = ERROR_SUCCESS;
  463. CAlertCommandArgsDlg dlgCmdArgs;
  464. INT_PTR iResult;
  465. dlgCmdArgs.SetAlertActionPage( this );
  466. dwStatus = m_pAlertQuery->GetLogName ( dlgCmdArgs.m_strAlertName );
  467. if ( ERROR_SUCCESS == dwStatus ) {
  468. MFC_TRY
  469. dlgCmdArgs.m_CmdArg_bAlertName = m_CmdArg_bAlertName;
  470. dlgCmdArgs.m_CmdArg_bDateTime = m_CmdArg_bDateTime;
  471. dlgCmdArgs.m_CmdArg_bLimitValue = m_CmdArg_bLimitValue;
  472. dlgCmdArgs.m_CmdArg_bCounterPath = m_CmdArg_bCounterPath;
  473. dlgCmdArgs.m_CmdArg_bSingleArg = m_CmdArg_bSingleArg;
  474. dlgCmdArgs.m_CmdArg_bMeasuredValue = m_CmdArg_bMeasuredValue;
  475. dlgCmdArgs.m_CmdArg_bUserText = m_CmdArg_bUserText;
  476. dlgCmdArgs.m_CmdArg_strUserText = m_CmdArg_strUserText;
  477. iResult = dlgCmdArgs.DoModal();
  478. if ( IDOK == iResult ) {
  479. if (dlgCmdArgs.m_CmdArg_bAlertName != m_CmdArg_bAlertName ) {
  480. m_CmdArg_bAlertName = dlgCmdArgs.m_CmdArg_bAlertName;
  481. SetModifiedPage ( TRUE );
  482. }
  483. if (dlgCmdArgs.m_CmdArg_bDateTime != m_CmdArg_bDateTime ) {
  484. m_CmdArg_bDateTime = dlgCmdArgs.m_CmdArg_bDateTime;
  485. SetModifiedPage ( TRUE );
  486. }
  487. if (dlgCmdArgs.m_CmdArg_bLimitValue != m_CmdArg_bLimitValue ) {
  488. m_CmdArg_bLimitValue = dlgCmdArgs.m_CmdArg_bLimitValue;
  489. SetModifiedPage ( TRUE );
  490. }
  491. if (dlgCmdArgs.m_CmdArg_bCounterPath != m_CmdArg_bCounterPath ) {
  492. m_CmdArg_bCounterPath = dlgCmdArgs.m_CmdArg_bCounterPath;
  493. SetModifiedPage ( TRUE );
  494. }
  495. if (dlgCmdArgs.m_CmdArg_bSingleArg != m_CmdArg_bSingleArg ) {
  496. m_CmdArg_bSingleArg = dlgCmdArgs.m_CmdArg_bSingleArg;
  497. SetModifiedPage ( TRUE );
  498. }
  499. if (dlgCmdArgs.m_CmdArg_bMeasuredValue != m_CmdArg_bMeasuredValue ) {
  500. m_CmdArg_bMeasuredValue = dlgCmdArgs.m_CmdArg_bMeasuredValue;
  501. SetModifiedPage ( TRUE );
  502. }
  503. if (dlgCmdArgs.m_CmdArg_bUserText != m_CmdArg_bUserText ) {
  504. m_CmdArg_bUserText = dlgCmdArgs.m_CmdArg_bUserText;
  505. SetModifiedPage ( TRUE );
  506. }
  507. if ( 0 != dlgCmdArgs.m_CmdArg_strUserText.CompareNoCase( m_CmdArg_strUserText ) ) {
  508. m_CmdArg_strUserText = dlgCmdArgs.m_CmdArg_strUserText;
  509. SetModifiedPage ( TRUE );
  510. }
  511. m_strCmdArgsExample = dlgCmdArgs.m_strSampleArgList;
  512. SetDlgItemText (IDC_ACTION_CMD_ARGS_DISPLAY, m_strCmdArgsExample);
  513. // Clear the selection
  514. ((CEdit*)GetDlgItem( IDC_ACTION_CMD_ARGS_DISPLAY ))->SetSel ( -1, FALSE );
  515. }
  516. MFC_CATCH_DWSTATUS
  517. }
  518. if ( ERROR_SUCCESS != dwStatus ) {
  519. CString strSysMessage;
  520. CString strMessage;
  521. MFC_TRY
  522. // TODO: Use static string for message in order to display in low memory situations.
  523. strMessage.LoadString ( IDS_ERRMSG_GENERAL );
  524. FormatSystemMessage ( dwStatus, strSysMessage );
  525. strMessage += strSysMessage;
  526. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  527. MFC_CATCH_MINIMUM
  528. (GetDlgItem(IDC_ACTION_CMD_ARGS_BTN))->SetFocus();
  529. }
  530. return;
  531. }
  532. void
  533. CAlertActionProp::OnSelendokStartLogCombo()
  534. {
  535. INT nSel;
  536. nSel = m_pLogCombo.GetCurSel();
  537. if ( nSel != m_nCurLogSel && LB_ERR != nSel ) {
  538. UpdateData ( TRUE );
  539. SetModifiedPage ( TRUE );
  540. }
  541. }
  542. void CAlertActionProp::OnActionExecuteBrowseBtn()
  543. {
  544. CString strCmdPath;
  545. UpdateData (TRUE); // to get the current filename
  546. strCmdPath = m_Action_strCmdPath;
  547. if ( IDOK == BrowseCommandFilename ( this, strCmdPath )) {
  548. // Update the fields with the new information
  549. if ( strCmdPath != m_Action_strCmdPath ) {
  550. m_Action_strCmdPath = strCmdPath;
  551. if (!m_pAlertQuery->m_strUser.IsEmpty() ) {
  552. if( !( m_pAlertQuery->m_strUser.GetAt(0) == L'<' ) ){
  553. m_pAlertQuery->m_fDirtyPassword |= PASSWORD_DIRTY;
  554. }
  555. }
  556. SetModifiedPage();
  557. UpdateData(FALSE);
  558. }
  559. } // else ignore if they canceled out
  560. }
  561. BOOL CAlertActionProp::OnInitDialog()
  562. {
  563. INT nSelLog;
  564. DWORD dwInfoBufSize = 0;
  565. ResourceStateManager rsm;
  566. // Parent OnInitDialog calls UpdateData to initialize combo members.
  567. CSmPropertyPage::OnInitDialog();
  568. SetHelpIds ( (DWORD*)&s_aulHelpIds );
  569. // load service name combo box
  570. LoadLogQueries (SLQ_COUNTER_LOG);
  571. LoadLogQueries (SLQ_TRACE_LOG);
  572. if (m_pAlertInfo == NULL) {
  573. // get alert query info from alert class
  574. // get initial size by passing asking to fill a 0 len buffer
  575. m_pAlertQuery->GetActionInfo (m_pAlertInfo, &dwInfoBufSize);
  576. ASSERT (dwInfoBufSize > 0); // or something is wierd
  577. MFC_TRY;
  578. m_pAlertInfo = (PALERT_ACTION_INFO) new CHAR [dwInfoBufSize];
  579. MFC_CATCH_MINIMUM;
  580. ASSERT (m_pAlertInfo != NULL);
  581. if ( NULL != m_pAlertInfo ) {
  582. memset (m_pAlertInfo, 0, dwInfoBufSize); // init new buffer
  583. if (!m_pAlertQuery->GetActionInfo (m_pAlertInfo, &dwInfoBufSize)) {
  584. // then free the info block and use the defaults
  585. delete [] (CHAR*)m_pAlertInfo;
  586. m_pAlertInfo = NULL;
  587. }
  588. }
  589. }
  590. if (m_pAlertInfo != NULL) {
  591. // then initialize using the settings passed in
  592. m_Action_bLogEvent = ((m_pAlertInfo->dwActionFlags & ALRT_ACTION_LOG_EVENT) != 0);
  593. m_Action_bSendNetMsg = ((m_pAlertInfo->dwActionFlags & ALRT_ACTION_SEND_MSG) != 0);
  594. if (m_pAlertInfo->szNetName != NULL) {
  595. m_Action_strNetName = m_pAlertInfo->szNetName;
  596. } else {
  597. m_Action_strNetName.Empty();
  598. }
  599. m_Action_bExecCmd = ((m_pAlertInfo->dwActionFlags & ALRT_ACTION_EXEC_CMD) != 0);
  600. if (m_pAlertInfo->szCmdFilePath != NULL) {
  601. m_Action_strCmdPath = m_pAlertInfo->szCmdFilePath;
  602. } else {
  603. m_Action_strCmdPath.Empty();
  604. }
  605. if ( m_Action_bExecCmd ) {
  606. m_CmdArg_bAlertName = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_A_NAME) != 0);
  607. m_CmdArg_bDateTime = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_D_TIME) != 0);
  608. m_CmdArg_bLimitValue = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_L_VAL) != 0);
  609. m_CmdArg_bCounterPath = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_C_NAME) != 0);
  610. m_CmdArg_bSingleArg = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_SINGLE) != 0);
  611. m_CmdArg_bMeasuredValue = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_M_VAL) != 0);
  612. m_CmdArg_bUserText = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_U_TEXT) != 0);
  613. } else {
  614. m_CmdArg_bAlertName = TRUE;
  615. m_CmdArg_bDateTime = TRUE;
  616. m_CmdArg_bLimitValue = TRUE;
  617. m_CmdArg_bCounterPath = TRUE;
  618. m_CmdArg_bSingleArg = TRUE;
  619. m_CmdArg_bMeasuredValue = TRUE;
  620. m_CmdArg_bUserText = FALSE;
  621. }
  622. if (m_pAlertInfo->szUserText != NULL) {
  623. m_CmdArg_strUserText = m_pAlertInfo->szUserText;
  624. }
  625. m_Action_bStartLog = ((m_pAlertInfo->dwActionFlags & ALRT_ACTION_START_LOG) != 0);
  626. if (m_pAlertInfo->szLogName != NULL) {
  627. nSelLog = m_pLogCombo.FindString (-1, m_pAlertInfo->szLogName);
  628. if (nSelLog != CB_ERR) {
  629. m_pLogCombo.SetCurSel (nSelLog);
  630. m_nCurLogSel = nSelLog;
  631. }
  632. }
  633. } else {
  634. // initialize using the default values as defined
  635. // in the constructor
  636. }
  637. MakeSampleArgList (
  638. m_strCmdArgsExample,
  639. m_CmdArg_bSingleArg,
  640. m_CmdArg_bAlertName,
  641. m_CmdArg_bDateTime,
  642. m_CmdArg_bCounterPath,
  643. m_CmdArg_bMeasuredValue,
  644. m_CmdArg_bLimitValue,
  645. m_CmdArg_bUserText,
  646. m_CmdArg_strUserText );
  647. SetDlgItemText (IDC_ACTION_CMD_ARGS_DISPLAY, m_strCmdArgsExample);
  648. // Clear the selection
  649. ((CEdit*)GetDlgItem( IDC_ACTION_CMD_ARGS_DISPLAY ))->SetSel ( -1, FALSE );
  650. // Call UpdateData again, after loading data.
  651. UpdateData ( FALSE );
  652. SetControlState();
  653. return TRUE; // return TRUE unless you set the focus to a control
  654. // EXCEPTION: OCX Property Pages should return FALSE
  655. }
  656. void CAlertActionProp::OnActionApplogChk()
  657. {
  658. UpdateData(TRUE);
  659. SetControlState();
  660. SetModifiedPage(TRUE);
  661. }
  662. void CAlertActionProp::OnActionNetmsgChk()
  663. {
  664. UpdateData(TRUE);
  665. SetControlState();
  666. SetModifiedPage(TRUE);
  667. }
  668. void CAlertActionProp::OnActionExecuteChk()
  669. {
  670. UpdateData(TRUE);
  671. SetControlState();
  672. SetModifiedPage(TRUE);
  673. }
  674. void CAlertActionProp::OnActionStartLogChk()
  675. {
  676. UpdateCmdActionBox ();
  677. }
  678. void CAlertActionProp::OnCmdPathTextEditChange()
  679. {
  680. CString strOldText;
  681. // When the user hits OK in the folder browse dialog,
  682. // the folder name might not have changed.
  683. strOldText = m_Action_strCmdPath;
  684. UpdateData( TRUE );
  685. if ( 0 != strOldText.Compare ( m_Action_strCmdPath ) ) {
  686. if (!m_pAlertQuery->m_strUser.IsEmpty() ) {
  687. if( !( m_pAlertQuery->m_strUser.GetAt(0) == L'<' ) ){
  688. m_pAlertQuery->m_fDirtyPassword |= PASSWORD_DIRTY;
  689. }
  690. }
  691. SetModifiedPage(TRUE);
  692. }
  693. }
  694. void CAlertActionProp::OnNetNameTextEditChange()
  695. {
  696. CString strOldText;
  697. // When the user hits OK in the folder browse dialog,
  698. // the folder name might not have changed.
  699. strOldText = m_Action_strNetName;
  700. UpdateData( TRUE );
  701. if ( 0 != strOldText.Compare ( m_Action_strNetName ) ) {
  702. SetModifiedPage(TRUE);
  703. }
  704. }
  705. DWORD
  706. CAlertActionProp::MakeSampleArgList (
  707. CString& rstrResult,
  708. const BOOL bSingleArg,
  709. const BOOL bAlertName,
  710. const BOOL bDateTime,
  711. const BOOL bCounterPath,
  712. const BOOL bMeasuredValue,
  713. const BOOL bLimitValue,
  714. const BOOL bUserText,
  715. const CString& rstrUserText )
  716. {
  717. DWORD dwStatus = ERROR_SUCCESS;
  718. CString strDelim1;
  719. CString strDelim2;
  720. BOOL bFirstArgDone = FALSE;
  721. CString strSampleString;
  722. CString strTimeString;
  723. CString strTemp;
  724. ResourceStateManager rsm;
  725. rstrResult.Empty(); // clear the old path
  726. MFC_TRY
  727. if ( bSingleArg ) {
  728. // then args are comma delimited
  729. strDelim1 = L",";
  730. strDelim2.Empty();
  731. } else {
  732. // for multiple args, they are enclosed in double quotes
  733. // and space delimited
  734. strDelim1 = L" \"";
  735. strDelim2 = L"\"";
  736. }
  737. if ( bAlertName ) {
  738. if (bFirstArgDone) {
  739. strSampleString += strDelim1; // add leading delimiter
  740. } else {
  741. strSampleString += L"\""; // add leading quote
  742. bFirstArgDone = TRUE;
  743. }
  744. strSampleString += m_pAlertQuery->GetLogName();
  745. strSampleString += strDelim2;
  746. }
  747. if ( bDateTime ) {
  748. if (bFirstArgDone) {
  749. strSampleString += strDelim1; // add leading delimiter
  750. } else {
  751. strSampleString += L"\""; // add leading quote
  752. bFirstArgDone = TRUE;
  753. }
  754. MakeTimeString(&strTimeString);
  755. strSampleString += strTimeString;
  756. strSampleString += strDelim2;
  757. }
  758. if ( bCounterPath ) {
  759. strTemp.LoadString ( IDS_SAMPLE_CMD_PATH );
  760. if (bFirstArgDone) {
  761. strSampleString += strDelim1; // add leading delimiter
  762. } else {
  763. strSampleString += L"\""; // add leading quote
  764. bFirstArgDone = TRUE;
  765. }
  766. strSampleString += strTemp;
  767. strSampleString += strDelim2;
  768. }
  769. if ( bMeasuredValue ) {
  770. strTemp.LoadString ( IDS_SAMPLE_CMD_MEAS_VAL );
  771. if (bFirstArgDone) {
  772. strSampleString += strDelim1; // add leading delimiter
  773. } else {
  774. strSampleString += L"\""; // add leading quote
  775. bFirstArgDone = TRUE;
  776. }
  777. strSampleString += strTemp;
  778. strSampleString += strDelim2;
  779. }
  780. if ( bLimitValue ) {
  781. strTemp.LoadString ( IDS_SAMPLE_CMD_LIMIT_VAL );
  782. if (bFirstArgDone) {
  783. strSampleString += strDelim1; // add leading delimiter
  784. } else {
  785. strSampleString += L"\""; // add leading quote
  786. bFirstArgDone = TRUE;
  787. }
  788. strSampleString += strTemp;
  789. strSampleString += strDelim2;
  790. }
  791. if ( bUserText ) {
  792. if (bFirstArgDone) {
  793. strSampleString += strDelim1; // add leading delimiter
  794. } else {
  795. strSampleString += L"\""; // add leading quote
  796. bFirstArgDone = TRUE;
  797. }
  798. strSampleString += rstrUserText;
  799. strSampleString += strDelim2;
  800. }
  801. if ( bFirstArgDone && bSingleArg ) {
  802. // add closing quote if there's at least 1 arg in the command line
  803. strSampleString += L"\"";
  804. }
  805. rstrResult = strSampleString;
  806. MFC_CATCH_DWSTATUS
  807. return dwStatus;
  808. }
  809. void CAlertActionProp::MakeTimeString(CString *pTimeString)
  810. {
  811. SYSTEMTIME st;
  812. pTimeString->Empty();
  813. GetLocalTime(&st);
  814. // Build string
  815. pTimeString->Format (L"%2.2d/%2.2d/%2.2d-%2.2d:%2.2d:%2.2d.%3.3d",
  816. st.wYear, st.wMonth, st.wDay, st.wHour,
  817. st.wMinute, st.wSecond, st.wMilliseconds);
  818. }