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.

468 lines
14 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. PrHsmCom.cpp
  5. Abstract:
  6. Implements all the property page interface to the individual nodes,
  7. including creating the property page, and adding it to the property sheet.
  8. Author:
  9. Rohde Wakefield [rohde] 08-Aug-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "HsmCom.h"
  14. #include "PrHsmCom.h"
  15. #include "ca.h"
  16. #include "intshcut.h"
  17. static DWORD pHelpIds[] =
  18. {
  19. IDC_SNAPIN_TITLE, idh_instance,
  20. IDC_STATIC_STATUS, idh_status,
  21. IDC_STATIC_STATUS_LABEL, idh_status,
  22. IDC_STATIC_MANAGED_VOLUMES, idh_total_managed_volumes,
  23. IDC_STATIC_MANAGED_VOLUMES_LABEL, idh_total_managed_volumes,
  24. IDC_STATIC_CARTS_USED, idh_total_cartridges_used,
  25. IDC_STATIC_CARTS_USED_LABEL, idh_total_cartridges_used,
  26. IDC_STATIC_DATA_IN_RS, idh_total_data_remote_storage,
  27. IDC_STATIC_DATA_IN_RS_LABEL, idh_total_data_remote_storage,
  28. IDC_STATIC_GROUP, idh_version,
  29. IDC_STATIC_BUILD_LABEL_HSM, idh_version,
  30. IDC_STATIC_ENGINE_BUILD_HSM, idh_version,
  31. 0, 0
  32. };
  33. CPropHsmComStat::CPropHsmComStat() : CSakPropertyPage(CPropHsmComStat::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CPropHsmComStat)
  36. //}}AFX_DATA_INIT
  37. m_hConsoleHandle = 0;
  38. m_pParent = 0;
  39. m_bUpdate = FALSE;
  40. m_pHelpIds = pHelpIds;
  41. }
  42. CPropHsmComStat::~CPropHsmComStat()
  43. {
  44. }
  45. BOOL CPropHsmComStat::OnInitDialog()
  46. {
  47. WsbTraceIn( L"CPropHsmComStat::OnInitDialog", L"" );
  48. HRESULT hr = S_OK;
  49. ULONG volCount = 0; // number of managed Resources in server
  50. LONGLONG totalTotal = 0;
  51. LONGLONG totalFree = 0;
  52. LONGLONG totalUsed = 0;
  53. LONGLONG totalPremigrated = 0;
  54. LONGLONG totalTruncated = 0;
  55. LONGLONG remoteStorage = 0;
  56. LONGLONG total = 0;
  57. LONGLONG free = 0;
  58. LONGLONG premigrated = 0;
  59. LONGLONG truncated = 0;
  60. CMediaInfoObject mio;
  61. int i;
  62. int mediaCount = 0;
  63. CComPtr<IWsbIndexedCollection> pManResCollection;
  64. CComPtr<IHsmServer> pHsmServer;
  65. CComPtr<IFsaServer> pFsaServer;
  66. CComPtr<IRmsServer> pRmsServer;
  67. CComPtr<IFsaResource> pFsaRes;
  68. CComPtr<IUnknown> pUnkFsaRes; // unknown pointer to managed resource list
  69. CComPtr<IHsmManagedResource> pHsmManRes;
  70. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  71. try {
  72. #if DBG
  73. //
  74. // For checked builds, make visible the version info
  75. //
  76. GetDlgItem( IDC_STATIC_GROUP )->ShowWindow( SW_SHOWNA );
  77. GetDlgItem( IDC_STATIC_BUILD_LABEL_HSM )->ShowWindow( SW_SHOWNA );
  78. GetDlgItem( IDC_STATIC_ENGINE_BUILD_HSM )->ShowWindow( SW_SHOWNA );
  79. #endif
  80. //
  81. // Put the title up
  82. //
  83. SetDlgItemText( IDC_SNAPIN_TITLE, m_NodeTitle );
  84. //
  85. // Show service status
  86. //
  87. GetAndShowServiceStatus();
  88. //
  89. // Contact the engine
  90. //
  91. HRESULT hrInternal = m_pParent->GetHsmServer( &pHsmServer );
  92. if( hrInternal == S_OK ) {
  93. //
  94. // The engine is up
  95. //
  96. WsbAffirmHr ( ( (CUiHsmComSheet *)m_pParent )->GetRmsServer( &pRmsServer ) );
  97. WsbAffirmHr ( ( (CUiHsmComSheet *)m_pParent )->GetFsaServer( &pFsaServer ) );
  98. //
  99. // Get the number of managed volumes
  100. //
  101. WsbAffirmHr( pHsmServer->GetManagedResources( &pManResCollection ) );
  102. WsbAffirmHr( pManResCollection->GetEntries( &volCount ));
  103. //
  104. // Iterate through the collection
  105. //
  106. for( i = 0; i < (int)volCount; i++ ) {
  107. //
  108. // Protect against bad volumes with try statement.
  109. // Otherwise we bail initializing whole dialog
  110. //
  111. HRESULT hrLocal = S_OK;
  112. try {
  113. //
  114. // Get the FsaResource
  115. //
  116. pHsmManRes.Release( );
  117. pUnkFsaRes.Release( );
  118. pFsaRes.Release( );
  119. WsbAffirmHr( pManResCollection->At( i, IID_IHsmManagedResource, ( void** ) &pHsmManRes ) );
  120. WsbAffirmHr( pHsmManRes->GetFsaResource( &pUnkFsaRes ) );
  121. WsbAffirmHr( RsQueryInterface( pUnkFsaRes, IFsaResource, pFsaRes ) );
  122. // Total up statistics
  123. WsbAffirmHr( pFsaRes->GetSizes( &total, &free, &premigrated, &truncated ) );
  124. totalPremigrated += premigrated;
  125. totalTruncated += truncated;
  126. remoteStorage = totalPremigrated + totalTruncated;
  127. } WsbCatch( hrLocal );
  128. }
  129. HRESULT hrLocal = S_OK;
  130. try {
  131. //
  132. // Count the number of media used
  133. // Initialize media object
  134. //
  135. WsbAffirmHr( mio.Initialize( GUID_NULL, pHsmServer, pRmsServer ) );
  136. // Did we get a node?
  137. if( mio.m_MediaId != GUID_NULL ) {
  138. HRESULT hrEnum = S_OK;
  139. while( SUCCEEDED( hrEnum ) ) {
  140. if( S_OK == mio.DoesMasterExist( ) ) {
  141. mediaCount++;
  142. }
  143. for( INT index = 0; index < mio.m_NumMediaCopies; index++ ) {
  144. if( S_OK == mio.DoesCopyExist( index ) ) {
  145. mediaCount++;
  146. }
  147. }
  148. hrEnum = mio.Next();
  149. }
  150. }
  151. } WsbCatch( hrLocal );
  152. CString sText;
  153. // Set number of managed volumes
  154. SetDlgItemInt( IDC_STATIC_MANAGED_VOLUMES, volCount, FALSE );
  155. // Show data in Remote Storage - text is same for singular and plural
  156. CString sFormattedNumber;
  157. RsGuiFormatLongLong4Char (remoteStorage, sFormattedNumber );
  158. SetDlgItemText( IDC_STATIC_DATA_IN_RS, sFormattedNumber );
  159. SetDlgItemInt( IDC_STATIC_CARTS_USED, mediaCount, FALSE );
  160. CWsbStringPtr pNtProductVersionHsm;
  161. ULONG buildVersionHsm;
  162. ULONG ntProductBuildHsm;
  163. //
  164. // Get service versions
  165. // Note: Fsa version is NOT in use at the moment, it may be used as an HSM
  166. // client version in a future C/S HSM
  167. //
  168. {
  169. CComPtr <IWsbServer> pWsbHsmServer;
  170. WsbAffirmHr( RsQueryInterface( pHsmServer, IWsbServer, pWsbHsmServer ) );
  171. WsbAffirmHr( pWsbHsmServer->GetNtProductBuild( &ntProductBuildHsm ) );
  172. WsbAffirmHr( pWsbHsmServer->GetNtProductVersion( &pNtProductVersionHsm, 0 ) );
  173. WsbAffirmHr( pWsbHsmServer->GetBuildVersion( &buildVersionHsm ) );
  174. }
  175. sText.Format( L"%ls.%d [%ls]", (WCHAR*)pNtProductVersionHsm, ntProductBuildHsm, RsBuildVersionAsString( buildVersionHsm ) );
  176. SetDlgItemText( IDC_STATIC_ENGINE_BUILD_HSM, sText );
  177. //
  178. // The engine is up. Show the controls
  179. //
  180. GetDlgItem( IDC_STATIC_MANAGED_VOLUMES_LABEL )->ShowWindow( SW_SHOW );
  181. GetDlgItem( IDC_STATIC_MANAGED_VOLUMES )->ShowWindow( SW_SHOW );
  182. GetDlgItem( IDC_STATIC_DATA_IN_RS_LABEL )->ShowWindow( SW_SHOW );
  183. GetDlgItem( IDC_STATIC_DATA_IN_RS )->ShowWindow( SW_SHOW );
  184. GetDlgItem( IDC_STATIC_CARTS_USED_LABEL )->ShowWindow( SW_SHOW );
  185. GetDlgItem( IDC_STATIC_CARTS_USED )->ShowWindow( SW_SHOW );
  186. GetDlgItem( IDC_STATIC_GROUP )->ShowWindow( SW_SHOW );
  187. GetDlgItem( IDC_STATIC_BUILD_LABEL_HSM )->ShowWindow( SW_SHOW );
  188. GetDlgItem( IDC_STATIC_ENGINE_BUILD_HSM )->ShowWindow( SW_SHOW );
  189. } else {
  190. // The engine is down. Hide the controls
  191. GetDlgItem( IDC_STATIC_MANAGED_VOLUMES_LABEL )->ShowWindow( SW_HIDE );
  192. GetDlgItem( IDC_STATIC_MANAGED_VOLUMES )->ShowWindow( SW_HIDE );
  193. GetDlgItem( IDC_STATIC_DATA_IN_RS )->ShowWindow( SW_HIDE );
  194. GetDlgItem( IDC_STATIC_DATA_IN_RS_LABEL )->ShowWindow( SW_HIDE );
  195. GetDlgItem( IDC_STATIC_CARTS_USED_LABEL )->ShowWindow( SW_HIDE );
  196. GetDlgItem( IDC_STATIC_CARTS_USED )->ShowWindow( SW_HIDE );
  197. GetDlgItem( IDC_STATIC_GROUP )->ShowWindow( SW_HIDE );
  198. GetDlgItem( IDC_STATIC_BUILD_LABEL_HSM )->ShowWindow( SW_HIDE );
  199. GetDlgItem( IDC_STATIC_ENGINE_BUILD_HSM )->ShowWindow( SW_HIDE );
  200. }
  201. } WsbCatch( hr );
  202. CSakPropertyPage::OnInitDialog();
  203. WsbTraceOut( L"CPropHsmComStat::OnInitDialog", L"" );
  204. return TRUE;
  205. }
  206. BOOL CPropHsmComStat::OnCommand(WPARAM wParam, LPARAM lParam)
  207. {
  208. // Page is dirty, mark it.
  209. // SetModified();
  210. // m_bUpdate = TRUE;
  211. return CSakPropertyPage::OnCommand(wParam, lParam);
  212. }
  213. void CPropHsmComStat::DoDataExchange(CDataExchange* pDX)
  214. {
  215. WsbTraceIn( L"CPropHsmComStat::DoDataExchange", L"" );
  216. CSakPropertyPage::DoDataExchange(pDX);
  217. //{{AFX_DATA_MAP(CPropHsmComStat)
  218. //}}AFX_DATA_MAP
  219. WsbTraceOut( L"CPropHsmComStat::DoDataExchange", L"" );
  220. }
  221. BEGIN_MESSAGE_MAP(CPropHsmComStat, CSakPropertyPage)
  222. //{{AFX_MSG_MAP(CPropHsmComStat)
  223. ON_WM_DESTROY()
  224. ON_WM_DRAWITEM()
  225. //}}AFX_MSG_MAP
  226. END_MESSAGE_MAP()
  227. /////////////////////////////////////////////////////////////////////////////
  228. // CPropHsmComStat message handlers
  229. BOOL CPropHsmComStat::OnApply()
  230. {
  231. if (m_bUpdate == TRUE)
  232. {
  233. // Do the work of making the change here.
  234. m_bUpdate = FALSE;
  235. }
  236. return CSakPropertyPage::OnApply();
  237. }
  238. HRESULT CPropHsmComStat::GetAndShowServiceStatus()
  239. {
  240. WsbTraceIn( L"CPropHsmComStat::GetAndShowServiceStatus", L"" );
  241. HRESULT hr = S_OK;
  242. try {
  243. //
  244. // Get and display service statuses
  245. //
  246. DWORD serviceStatus;
  247. CString sStatus;
  248. // Engine
  249. HRESULT hrSetup = S_FALSE;
  250. WsbAffirmHr( WsbGetServiceStatus( m_pszName, APPID_RemoteStorageEngine, &serviceStatus ) );
  251. if( SERVICE_RUNNING == serviceStatus ) {
  252. CComPtr<IHsmServer> pHsmServer;
  253. hr = ( m_pParent->GetHsmServer( &pHsmServer ) );
  254. if ( hr == RS_E_NOT_CONFIGURED ) {
  255. hrSetup = S_FALSE;
  256. }
  257. else {
  258. hrSetup = S_OK;
  259. WsbAffirmHr( hr );
  260. }
  261. }
  262. RsGetStatusString( serviceStatus, hrSetup, sStatus );
  263. SetDlgItemText( IDC_STATIC_STATUS, sStatus );
  264. } WsbCatch( hr );
  265. WsbTraceOut( L"CPropHsmComStat::GetAndShowServiceStatus", L"hr = <%ls>", WsbHrAsString( hr ) );
  266. return( hr );
  267. }
  268. /////////////////////////////////////////////////////////////////////////////
  269. // CRsWebLink
  270. CRsWebLink::CRsWebLink()
  271. {
  272. }
  273. CRsWebLink::~CRsWebLink()
  274. {
  275. }
  276. BEGIN_MESSAGE_MAP(CRsWebLink, CStatic)
  277. //{{AFX_MSG_MAP(CRsWebLink)
  278. ON_WM_LBUTTONDOWN()
  279. ON_WM_CTLCOLOR_REFLECT()
  280. //}}AFX_MSG_MAP
  281. END_MESSAGE_MAP()
  282. /////////////////////////////////////////////////////////////////////////////
  283. // CRsWebLink message handlers
  284. void CRsWebLink::PreSubclassWindow()
  285. {
  286. //
  287. // Need to set up font correctly
  288. //
  289. LOGFONT logfont;
  290. CFont* tempFont = GetFont( );
  291. tempFont->GetLogFont( &logfont );
  292. // logfont.lfWeight = FW_BOLD;
  293. logfont.lfUnderline = TRUE;
  294. m_Font.CreateFontIndirect( &logfont );
  295. SetFont( &m_Font );
  296. //
  297. // Resize based on font
  298. //
  299. CRect rect;
  300. CWindowDC dc( this );
  301. CString title;
  302. GetClientRect( rect );
  303. GetWindowText( title );
  304. dc.SelectObject( m_Font );
  305. CSize size = dc.GetTextExtent( title );
  306. SetWindowPos( 0, 0, 0, size.cx, rect.bottom, SWP_NOMOVE | SWP_NOZORDER );
  307. //
  308. // And set the class cursor
  309. //
  310. HCURSOR hCur = AfxGetApp( )->LoadStandardCursor( IDC_HAND );
  311. SetClassLongPtr( GetSafeHwnd( ), GCLP_HCURSOR, (LONG_PTR)hCur );
  312. CStatic::PreSubclassWindow();
  313. }
  314. void CRsWebLink::OnLButtonDown(UINT nFlags, CPoint point)
  315. {
  316. WsbTraceIn( L"CRsWebLink::OnLButtonDown", L"" );
  317. CString caption;
  318. CString addr;
  319. GetWindowText( caption );
  320. addr = TEXT( "http://" );
  321. addr += caption;
  322. AfxGetApp()->BeginWaitCursor( );
  323. OpenURL( addr );
  324. AfxGetApp( )->EndWaitCursor( );
  325. CStatic::OnLButtonDown( nFlags, point );
  326. WsbTraceOut( L"CRsWebLink::OnLButtonDown", L"" );
  327. }
  328. HRESULT CRsWebLink::OpenURL(CString &Url)
  329. {
  330. HRESULT hr = S_OK;
  331. try {
  332. CComPtr<IUniformResourceLocator> pURL;
  333. WsbAffirmHr( CoCreateInstance( CLSID_InternetShortcut, 0, CLSCTX_ALL, IID_IUniformResourceLocator, (void**)&pURL ) );
  334. WsbAffirmHr( pURL->SetURL( Url, IURL_SETURL_FL_GUESS_PROTOCOL ) );
  335. //
  336. // Open the URL by calling InvokeCommand
  337. //
  338. URLINVOKECOMMANDINFO ivci;
  339. ivci.dwcbSize = sizeof( URLINVOKECOMMANDINFO );
  340. ivci.dwFlags = IURL_INVOKECOMMAND_FL_ALLOW_UI;
  341. ivci.hwndParent = 0;
  342. ivci.pcszVerb = TEXT( "open" );
  343. WsbAffirmHr( pURL->InvokeCommand( &ivci ) );
  344. } WsbCatch( hr );
  345. return( hr );
  346. }
  347. HBRUSH CRsWebLink::CtlColor(CDC* pDC, UINT /* nCtlColor */ )
  348. {
  349. HBRUSH hBrush = (HBRUSH)GetStockObject( HOLLOW_BRUSH );
  350. pDC->SetTextColor( RGB( 0, 0, 255 ) );
  351. pDC->SetBkMode( TRANSPARENT );
  352. return( hBrush );
  353. }