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.

1993 lines
50 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*++
  3. Module Name:
  4. MainFrm.cpp
  5. Abstract:
  6. This Module contains the implementation of CMainFrame class
  7. (The Frame Window of the application)
  8. Author:
  9. Arathi Kundapur (v-akunda) 11-Feb-1998
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include <lm.h>
  14. #include "LicMgr.h"
  15. #include "defines.h"
  16. #include "LSServer.h"
  17. #include "MainFrm.h"
  18. #include "RtList.h"
  19. #include "lSmgrdoc.h"
  20. #include "LtView.h"
  21. #include "cntdlg.h"
  22. #include "addkp.h"
  23. #include "treenode.h"
  24. #include "ntsecapi.h"
  25. //#include "lrwizapi.h"
  26. #include "TlsHunt.h"
  27. #include "htmlhelp.h"
  28. #define DELETE_AND_ADDTO_ERROR DeleteServer(pLicServerList,TempPos,pLicServer);\
  29. if(!ErrorServers.IsEmpty()) \
  30. ErrorServers = ErrorServers + _T(","); \
  31. ErrorServers = ErrorServers + Name;
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CMainFrame
  39. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  40. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  41. //{{AFX_MSG_MAP(CMainFrame)
  42. ON_WM_CREATE()
  43. ON_MESSAGE(WM_ENUMERATESERVER, OnEnumerateServer)
  44. ON_MESSAGE(WM_SEL_CHANGE, OnSelChange)
  45. ON_MESSAGE(WM_ADD_ALL_SERVERS, OnAddAllServers)
  46. ON_MESSAGE(WM_ADD_SERVER, OnAddServer)
  47. ON_MESSAGE(WM_ADD_KEYPACK, OnAddKeyPack)
  48. ON_COMMAND(ID_LARGE_ICONS, OnLargeIcons)
  49. ON_COMMAND(ID_SMALL_ICONS, OnSmallIcons)
  50. ON_COMMAND(ID_LIST, OnList)
  51. ON_COMMAND(ID_DETAILS, OnDetails)
  52. ON_COMMAND(ID_EXIT, OnExit)
  53. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  54. ON_COMMAND(ID_HELP_FINDER, OnHelp)
  55. ON_COMMAND(ID_HELP_USING, CFrameWnd::OnHelpUsing)
  56. ON_COMMAND(ID_CONNECT_SERVER, OnConnectServer)
  57. ON_COMMAND(ID_REGISTRATION, OnRegistration)
  58. ON_COMMAND(ID_KEY_HELP , OnHelp )
  59. ON_UPDATE_COMMAND_UI( ID_REGISTRATION, OnUpdateAddNewKeyPack)
  60. ON_UPDATE_COMMAND_UI( ID_ACTION_DOWNLOADLICENSES, OnUpdateDownloadlicenses )
  61. ON_UPDATE_COMMAND_UI( ID_ACTION_ADVANCED_REPEATLASTDOWNLOAD , OnUpdateRepeatLastDownload )
  62. ON_UPDATE_COMMAND_UI( ID_ACTION_ADVANCED_REREGISTERSERVER , OnUpdateReregisterserver )
  63. ON_UPDATE_COMMAND_UI( ID_ACTION_ADVANCED_UNREGISTERSERVER , OnUpdateUnregisterserver )
  64. ON_UPDATE_COMMAND_UI( ID_VIEW_PROPERTIES , OnUpdateProperties )
  65. ON_COMMAND( ID_REFRESH, OnRefreshServer )
  66. ON_COMMAND( ID_VIEW_REFRESHALL , OnRefresh )
  67. ON_UPDATE_COMMAND_UI( ID_REFRESH , OnUpdateRefresh )
  68. ON_COMMAND( ID_ACTION_DOWNLOADLICENSES , OnDownLoadLicenses )
  69. ON_COMMAND( ID_ACTION_ADVANCED_REPEATLASTDOWNLOAD , OnRepeatLastDownLoad )
  70. ON_COMMAND( ID_ACTION_ADVANCED_REREGISTERSERVER , OnReRegisterServer )
  71. ON_COMMAND( ID_ACTION_ADVANCED_UNREGISTERSERVER , OnUnRegisterServer )
  72. ON_COMMAND( ID_VIEW_PROPERTIES , OnProperties )
  73. //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75. static UINT indicators[] =
  76. {
  77. ID_SEPARATOR, // status line indicator
  78. ID_INDICATOR_CAPS,
  79. ID_INDICATOR_NUM,
  80. ID_INDICATOR_SCRL,
  81. };
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CMainFrame construction/destruction
  84. CMainFrame::CMainFrame()
  85. {
  86. m_pRightView= NULL;
  87. m_pLeftView = NULL;
  88. m_pServer = NULL;
  89. }
  90. CMainFrame::~CMainFrame()
  91. {
  92. }
  93. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  94. {
  95. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  96. return -1;
  97. if (!m_wndToolBar.Create(this) ||
  98. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  99. {
  100. TRACE0("Failed to create toolbar\n");
  101. return -1; // fail to create
  102. }
  103. #if 0
  104. if (!m_wndStatusBar.Create(this) ||
  105. !m_wndStatusBar.SetIndicators(indicators,
  106. sizeof(indicators)/sizeof(UINT)))
  107. {
  108. TRACE0("Failed to create status bar\n");
  109. return -1; // fail to create
  110. }
  111. #endif
  112. // Remove this if you don't want tool tips or a resizeable toolbar
  113. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  114. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  115. // Delete these three lines if you don't want the toolbar to be dockable
  116. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  117. EnableDocking(CBRS_ALIGN_ANY);
  118. DockControlBar(&m_wndToolBar);
  119. return 0;
  120. }
  121. void CMainFrame::OnHelp()
  122. {
  123. TCHAR * pHtml = L"ts_lice_topnode.htm";
  124. HtmlHelp(AfxGetMainWnd()->m_hWnd, L"tslic.chm", HH_DISPLAY_TOPIC,(DWORD_PTR)pHtml);
  125. }
  126. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  127. {
  128. cs.style &= ~FWS_ADDTOTITLE;
  129. return CFrameWnd::PreCreateWindow(cs);
  130. }
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CMainFrame diagnostics
  133. #ifdef _DEBUG
  134. void CMainFrame::AssertValid() const
  135. {
  136. CFrameWnd::AssertValid();
  137. }
  138. void CMainFrame::Dump(CDumpContext& dc) const
  139. {
  140. CFrameWnd::Dump(dc);
  141. }
  142. #endif //_DEBUG
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CMainFrame message handlers
  145. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
  146. {
  147. m_SplitterWnd.CreateStatic(this,1,2); //1 row, 2 columns
  148. m_SplitterWnd.CreateView(0,0,(CRuntimeClass *)pContext->m_pNewViewClass,CSize(150,150),pContext);
  149. m_SplitterWnd.CreateView(0,1,RUNTIME_CLASS(CRightList),CSize(0,0),pContext);
  150. m_pRightView = (CView *)m_SplitterWnd.GetPane(0, 1);
  151. m_pLeftView = (CLicMgrLeftView *)m_SplitterWnd.GetPane(0, 0);
  152. return TRUE;
  153. }
  154. LRESULT CMainFrame::OnSelChange(WPARAM wParam, LPARAM lParam)
  155. {
  156. LRESULT lResult = 0;
  157. m_pRightView->SendMessage(WM_SEL_CHANGE,wParam,lParam);
  158. return lResult;
  159. }
  160. void CMainFrame::OnLargeIcons()
  161. {
  162. PressButton(ID_LARGE_ICONS,TRUE);
  163. PressButton(ID_SMALL_ICONS,FALSE);
  164. PressButton(ID_LIST,FALSE);
  165. PressButton(ID_DETAILS,FALSE);
  166. m_pRightView->SendMessage(WM_COMMAND,ID_LARGE_ICONS,0);
  167. }
  168. void CMainFrame::OnSmallIcons()
  169. {
  170. PressButton(ID_LARGE_ICONS,FALSE);
  171. PressButton(ID_SMALL_ICONS,TRUE);
  172. PressButton(ID_LIST,FALSE);
  173. PressButton(ID_DETAILS,FALSE);
  174. m_pRightView->SendMessage(WM_COMMAND,ID_SMALL_ICONS,0);
  175. }
  176. void CMainFrame::OnList()
  177. {
  178. PressButton(ID_LARGE_ICONS,FALSE);
  179. PressButton(ID_SMALL_ICONS,FALSE);
  180. PressButton(ID_LIST,TRUE);
  181. PressButton(ID_DETAILS,FALSE);
  182. m_pRightView->SendMessage(WM_COMMAND,ID_LIST,0);
  183. }
  184. void CMainFrame::OnDetails()
  185. {
  186. PressButton(ID_LARGE_ICONS,FALSE);
  187. PressButton(ID_SMALL_ICONS,FALSE);
  188. PressButton(ID_LIST,FALSE);
  189. PressButton(ID_DETAILS,TRUE);
  190. m_pRightView->SendMessage(WM_COMMAND,ID_DETAILS,0);
  191. }
  192. void CMainFrame::OnExit()
  193. {
  194. SendMessage(WM_CLOSE,0,0);
  195. }
  196. LRESULT CMainFrame::OnAddAllServers(WPARAM wParam, LPARAM lParam)
  197. {
  198. LRESULT lResult = 0;
  199. m_pLeftView->SendMessage(WM_ADD_ALL_SERVERS,wParam,lParam);
  200. return lResult;
  201. }
  202. LRESULT CMainFrame::OnAddServer(WPARAM wParam, LPARAM lParam)
  203. {
  204. LRESULT lResult = 0;
  205. m_pLeftView->SendMessage(WM_ADD_SERVER,wParam,lParam);
  206. m_pRightView->SendMessage(WM_ADD_SERVER,wParam,lParam);
  207. return lResult;
  208. }
  209. LRESULT CMainFrame::OnAddKeyPack(WPARAM wParam, LPARAM lParam)
  210. {
  211. LRESULT lResult = 0;
  212. m_pLeftView->SendMessage(WM_ADD_KEYPACK,wParam,lParam);
  213. m_pRightView->SendMessage(WM_ADD_KEYPACK,wParam,lParam);
  214. return lResult;
  215. }
  216. void CMainFrame::OnAppAbout()
  217. {
  218. CString AppName;
  219. AppName.LoadString(IDS_APP_NAME);
  220. ::ShellAbout((HWND)m_hWnd,(LPCTSTR)AppName,
  221. NULL,NULL);
  222. }
  223. void CMainFrame::OnRegistration()
  224. {
  225. CWnd* cWnd = AfxGetMainWnd();
  226. HWND hWnd=cWnd->GetSafeHwnd();
  227. DWORD status;
  228. CString TempString;
  229. CString Server;
  230. CLicServer* pServer = NULL;
  231. WCHAR szServer[MAX_COMPUTERNAME_LENGTH + 1];
  232. BOOL bRefresh;
  233. try
  234. {
  235. if(ERROR_SUCCESS != GetActiveServer(&pServer))
  236. {
  237. DBGMSG( L"LICMGR : OnRegistration no active servers\n",0 );
  238. return;
  239. }
  240. if(SERVER_TS5_ENFORCED == pServer->GetServerType())
  241. {
  242. DBGMSG( L"LICMGR : OnRegistration on enforced server\n",0 );
  243. if( !pServer->IsUserAdmin( ) )
  244. {
  245. AfxMessageBox( IDS_E_ACCESSDENIED );
  246. // ::MessageBox( GetSafeHwnd( ) , L"Unable to perform operation: Access denied" , L"Terminal Services Licensing" , MB_OK|MB_ICONINFORMATION );
  247. return;
  248. }
  249. if(pServer->UseIpAddress())
  250. {
  251. Server = pServer->GetIpAddress();
  252. }
  253. else
  254. {
  255. Server = pServer->GetName();
  256. }
  257. lstrcpy(szServer, (LPCTSTR)Server);
  258. DWORD dwStatus = pServer->GetServerRegistrationStatus( );
  259. DBGMSG( L"LICMGR:CMainFrame::OnRegistration calling StartWizard\n", 0 );
  260. StartWizard( hWnd , WIZACTION_REGISTERLS , szServer , &bRefresh );
  261. //DBGMSG( L"LICMGR:CMainFrame::OnRegistration - StartWizard returned 0x%x\n" , status );
  262. if( IsLicenseServerRegistered( hWnd , szServer , &status ) == ERROR_SUCCESS )
  263. {
  264. pServer->SetServerRegistrationStatus( status );
  265. }
  266. if( dwStatus != status )
  267. {
  268. RefreshServer(pServer);
  269. }
  270. UpdateWindow();
  271. }
  272. else
  273. {
  274. DBGMSG( L"LICMGR : OnRegistration on non-enforced server\n",0 );
  275. // AddKeyPackDialog(NULL);
  276. }
  277. }
  278. catch (...)
  279. {
  280. // validation failed - user already alerted, fall through
  281. // Note: DELETE_EXCEPTION_(e) not required
  282. }
  283. }
  284. //////////////////////////////////////////////////////////////////////////////
  285. BOOL
  286. CMainFrame::ConnectServer(
  287. LPCTSTR pszServer
  288. )
  289. /*++
  290. ++*/
  291. {
  292. CConnectDialog ConnectDialog;
  293. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  294. ASSERT(pDoc);
  295. if(NULL == pDoc)
  296. return FALSE;
  297. HRESULT hResult = ERROR_SUCCESS;
  298. SERVER_TYPE ServerType;
  299. CString Scope;
  300. if(pszServer == NULL)
  301. {
  302. if(ConnectDialog.DoModal() != IDOK)
  303. {
  304. return FALSE;
  305. }
  306. //
  307. // Empty string - local machine
  308. //
  309. if(ConnectDialog.m_Server.IsEmpty())
  310. {
  311. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  312. DWORD dwBufSize = MAX_COMPUTERNAME_LENGTH + 1;
  313. memset(szComputerName, 0, sizeof(szComputerName));
  314. GetComputerName(szComputerName, &dwBufSize);
  315. ConnectDialog.m_Server = szComputerName;
  316. }
  317. }
  318. else
  319. {
  320. //
  321. // Minimize code change
  322. //
  323. ConnectDialog.m_Server = pszServer;
  324. }
  325. SetCursor(LoadCursor(NULL,IDC_WAIT));
  326. if(TRUE == pDoc->IsServerInList(ConnectDialog.m_Server))
  327. {
  328. //AfxMessageBox(IDS_DUPLICATE_SERVER);
  329. return FALSE;
  330. }
  331. //HUEIHUEI - Check if server is registered
  332. //
  333. // Do a NT4 RPC connect to make sure the license server
  334. // can accept our calls.
  335. //
  336. CString IpAddress(ConnectDialog.m_Server);
  337. hResult = pDoc->ConnectToServer(
  338. ConnectDialog.m_Server,
  339. Scope,
  340. ServerType
  341. );
  342. if(ERROR_SUCCESS != hResult)
  343. {
  344. CDialog ErrorDialog(IDD_CONNECT_ERROR,this);
  345. ErrorDialog.DoModal();
  346. }
  347. else
  348. {
  349. CAllServers * pAllServers = pDoc->GetAllServers();
  350. CLicServer *pServer1 = NULL;
  351. if(IpAddress != ConnectDialog.m_Server)
  352. {
  353. if(TRUE == pDoc->IsServerInList(ConnectDialog.m_Server))
  354. {
  355. return TRUE;
  356. }
  357. pServer1 = new CLicServer(
  358. ConnectDialog.
  359. m_Server,
  360. ServerType,
  361. Scope,
  362. IpAddress
  363. );
  364. }
  365. else
  366. {
  367. pServer1= new CLicServer(
  368. ConnectDialog.
  369. m_Server,
  370. ServerType,
  371. Scope
  372. );
  373. }
  374. if(pServer1)
  375. {
  376. DWORD dwStatus;
  377. // check for admin
  378. pServer1->SetAdmin( IsUserAdmin( pServer1->GetName() ) );
  379. if( pServer1->IsUserAdmin( ) )
  380. {
  381. if( IsLicenseServerRegistered( GetSafeHwnd() , ( LPCTSTR )pServer1->GetName() , &dwStatus ) == ERROR_SUCCESS )
  382. {
  383. pServer1->SetServerRegistrationStatus( dwStatus );
  384. }
  385. }
  386. CLicMgrDoc * pDoc = (CLicMgrDoc *)(GetActiveView()->GetDocument());
  387. pDoc->EnumerateKeyPacks( pServer1 , LSKEYPACK_SEARCH_LANGID , TRUE );
  388. WIZCONNECTION WizConType;
  389. if( GetConnectionType( GetSafeHwnd() , pServer1->GetName() , &WizConType ) == ERROR_SUCCESS )
  390. {
  391. DBGMSG( L"ConnectServer - GetConnectionType obtained %d" , WizConType );
  392. pServer1->SetConType( WizConType );
  393. }
  394. pAllServers->AddLicServer(pServer1);
  395. SendMessage(WM_ADD_SERVER,0,(LPARAM)pServer1);
  396. // after the send message is called all servers will have their keypacks cached.
  397. pServer1->SetDownLoadLics( IsDownLoadedPacks( pServer1 ) );
  398. }
  399. else
  400. {
  401. return FALSE;
  402. }
  403. }
  404. return TRUE;
  405. }
  406. ////////////////////////////////////////////////////////////////////////////
  407. void
  408. CMainFrame::OnConnectServer()
  409. {
  410. ConnectServer();
  411. }
  412. HRESULT CMainFrame::AddKeyPackDialog(CLicServer * pServer)
  413. {
  414. HRESULT hResult = ERROR_SUCCESS;
  415. CString TempString;
  416. CString Server;
  417. //if pServer is null,Then the message is from Listview.
  418. //Get the current server from the treeview.
  419. SetCursor(LoadCursor(NULL,IDC_WAIT));
  420. if(NULL == pServer)
  421. {
  422. if(ERROR_SUCCESS != GetActiveServer(&pServer))
  423. {
  424. hResult = E_FAIL;
  425. return hResult;
  426. }
  427. }
  428. //Server = pServer->GetName();
  429. CLicMgrDoc * pDoc = (CLicMgrDoc *)(GetActiveView()->GetDocument());
  430. ASSERT(pDoc);
  431. if(NULL == pDoc)
  432. {
  433. hResult = E_FAIL;
  434. return hResult;
  435. }
  436. KeyPackList * pKeypackList = pServer->GetKeyPackList();
  437. if(NULL == pKeypackList)
  438. {
  439. hResult = E_FAIL;
  440. return hResult;
  441. }
  442. //If Server is not enumerated enumerate now.
  443. if(!pServer->IsExpanded())
  444. {
  445. HRESULT hResult = pDoc->EnumerateKeyPacks(pServer,LSKEYPACK_SEARCH_LANGID, TRUE);
  446. if(hResult != S_OK)
  447. {
  448. hResult = E_FAIL;
  449. return hResult;
  450. }
  451. POSITION pos1 = pKeypackList->GetHeadPosition();
  452. while(pos1)
  453. {
  454. CKeyPack *pKeyPack = (CKeyPack *)pKeypackList->GetNext(pos1);
  455. hResult = pDoc->EnumerateLicenses(pKeyPack,LSLICENSE_SEARCH_KEYPACKID, TRUE);
  456. if(hResult != S_OK)
  457. {
  458. hResult = E_FAIL;
  459. return hResult;
  460. }
  461. }
  462. }
  463. CAddKeyPack KeyPack(pKeypackList,IsUserAdmin(Server));
  464. KeyPack.DoModal();
  465. return hResult;
  466. }
  467. void CMainFrame::OnUpdateAddNewKeyPack(CCmdUI* pCmdUI)
  468. {
  469. BOOL bEnable = FALSE;
  470. HRESULT hrStatus;
  471. // we have to force another check here
  472. bEnable = IsServerRegistered( &hrStatus );
  473. if( FAILED( hrStatus ) )
  474. {
  475. pCmdUI->Enable(bEnable);
  476. }
  477. else
  478. {
  479. pCmdUI->Enable( !bEnable );
  480. }
  481. }
  482. HRESULT
  483. CMainFrame::AddLicensestoList(
  484. CKeyPack * pKeyPack,
  485. CListCtrl * pListCtrl,
  486. BOOL bRefresh
  487. )
  488. /*++
  489. --*/
  490. {
  491. CLicServer *pServer = NULL;
  492. CString Error;
  493. HRESULT hr;
  494. ASSERT(pKeyPack);
  495. ASSERT(pListCtrl);
  496. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  497. ASSERT(pDoc);
  498. if(NULL == pKeyPack || NULL == pListCtrl || NULL == pDoc)
  499. {
  500. return E_FAIL;
  501. }
  502. if(TRUE == bRefresh)
  503. {
  504. if((hr = pKeyPack->RefreshIssuedLicenses()) != S_OK)
  505. {
  506. EnumFailed(hr,pKeyPack->GetServer());
  507. return E_FAIL;
  508. }
  509. }
  510. IssuedLicenseList * pIssuedLicenseList = pKeyPack->GetIssuedLicenseList();
  511. ASSERT(pIssuedLicenseList);
  512. if(NULL == pIssuedLicenseList)
  513. {
  514. return E_FAIL;
  515. }
  516. LSKeyPack sKeyPack = pKeyPack->GetKeyPackStruct();
  517. int nIndex = 0;
  518. int nSubitemIndex = 1;
  519. CString TempString;
  520. POSITION pos;
  521. LV_ITEM lvI;
  522. lvI.mask = LVIF_TEXT |LVIF_IMAGE |LVIF_STATE | LVIF_PARAM;
  523. lvI.state = 0;
  524. lvI.stateMask =0;
  525. lvI.iSubItem = 0;
  526. lvI.iImage = 2;
  527. pos = pIssuedLicenseList->GetHeadPosition();
  528. while(pos)
  529. {
  530. lvI.iItem = nIndex;
  531. nSubitemIndex = 1;
  532. CLicense * pLicense = pIssuedLicenseList->GetNext(pos);
  533. ASSERT(pLicense);
  534. if(NULL == pLicense)
  535. {
  536. continue;
  537. }
  538. LSLicenseEx sLicense = pLicense->GetLicenseStruct();
  539. lvI.lParam = (LPARAM)pLicense;
  540. TempString = sLicense.szMachineName;
  541. lvI.pszText = TempString.GetBuffer(TempString.GetLength());
  542. lvI.cchTextMax =lstrlen(lvI.pszText + 1);
  543. nIndex = pListCtrl->InsertItem(&lvI);
  544. //Set the Issue date.
  545. pDoc->TimeToString(&sLicense.ftIssueDate, TempString);
  546. if(TempString.IsEmpty())
  547. {
  548. TempString.LoadString(IDS_UNKNOWN);
  549. }
  550. pListCtrl->SetItemText(nIndex,nSubitemIndex,(LPCTSTR)TempString);
  551. nSubitemIndex++;
  552. //Set the expiry date.
  553. if(0x7FFFFFFF != sLicense.ftExpireDate)
  554. {
  555. TempString.LoadString(IDS_DASH);
  556. pDoc->TimeToString(&sLicense.ftExpireDate, TempString);
  557. if(TempString.IsEmpty())
  558. {
  559. TempString.LoadString(IDS_UNKNOWN);
  560. }
  561. }
  562. else
  563. {
  564. TempString.LoadString(IDS_DASH);
  565. }
  566. pListCtrl->SetItemText(nIndex,nSubitemIndex,(LPCTSTR)TempString);
  567. nSubitemIndex++;
  568. // adding status text to license's status column
  569. switch( sLicense.ucLicenseStatus )
  570. {
  571. case LSLICENSE_STATUS_UNKNOWN:
  572. TempString.LoadString( IDS_LICENSESTATUS_UNKNOWN );
  573. break;
  574. case LSLICENSE_STATUS_TEMPORARY:
  575. TempString.LoadString( IDS_LICENSESTATUS_TEMPORARY );
  576. break;
  577. case LSLICENSE_STATUS_ACTIVE:
  578. //case LSLICENSE_STATUS_PENDING_ACTIVE:
  579. case LSLICENSE_STATUS_CONCURRENT:
  580. TempString.LoadString( IDS_LICENSESTATUS_ACTIVE );
  581. break;
  582. case LSLICENSE_STATUS_UPGRADED:
  583. TempString.LoadString( IDS_LICENSESTATUS_UPGRADED );
  584. break;
  585. //case LSLICENSE_STATUS_REVOKE:
  586. //case LSLICENSE_STATUS_REVOKE_PENDING:
  587. // TempString.LoadString( IDS_LICENSESTATUS_REVOKE );
  588. }
  589. if( TempString.IsEmpty() )
  590. {
  591. TempString.LoadString(IDS_UNKNOWN);
  592. }
  593. pListCtrl->SetItemText(nIndex,nSubitemIndex,(LPCTSTR)TempString);
  594. nIndex ++;
  595. }
  596. return S_OK;
  597. }
  598. void CMainFrame :: PressButton(UINT uId, BOOL bPress)
  599. {
  600. CToolBarCtrl& ToolBarCtrl = m_wndToolBar.GetToolBarCtrl();
  601. ToolBarCtrl.PressButton(uId,bPress);
  602. }
  603. /////////////////////////////////////////////////////////////////////
  604. LRESULT
  605. CMainFrame::OnEnumerateServer(WPARAM wParam, LPARAM lParam)
  606. {
  607. CTlsHunt huntDlg;
  608. huntDlg.DoModal();
  609. if( wParam == 0 &&
  610. huntDlg.IsUserCancel() == FALSE &&
  611. huntDlg.GetNumServerFound() == 0 )
  612. {
  613. AfxMessageBox(IDS_NOSERVERINDOMAIN);
  614. }
  615. return 0;
  616. }
  617. /////////////////////////////////////////////////////////////////////
  618. void
  619. CMainFrame :: ConnectAndDisplay()
  620. {
  621. CLicMgrApp *pApp = (CLicMgrApp*)AfxGetApp();
  622. ASSERT(pApp);
  623. CLicMgrDoc *pDoc = (CLicMgrDoc *)(GetActiveView()->GetDocument());
  624. ASSERT(pDoc);
  625. if(NULL == pApp || NULL == pDoc)
  626. return;
  627. HRESULT hResult = ERROR_SUCCESS;
  628. CString LicServer;
  629. CString Server = pApp->m_Server;
  630. if(!Server.IsEmpty())
  631. {
  632. //Server Specified in the command line. Connect to it.
  633. hResult = pDoc->ConnectWithCurrentParams();
  634. }
  635. else
  636. {
  637. ActivateFrame();
  638. //
  639. // Save a copy of what we have.
  640. //
  641. LicServer = pApp->m_Server;
  642. pApp->m_Server = _TEXT("");
  643. hResult = pDoc->ConnectWithCurrentParams();
  644. pApp->m_Server = LicServer;
  645. hResult = ERROR_SUCCESS;
  646. }
  647. switch(hResult)
  648. {
  649. case E_FAIL:
  650. AfxMessageBox(IDS_CONNECT_SERVER_FAILED);
  651. break;
  652. case E_OUTOFMEMORY:
  653. AfxMessageBox(IDS_NO_MEMORY);
  654. SendMessage(WM_CLOSE,0,0);
  655. break;
  656. case E_DUPLICATE:
  657. AfxMessageBox(IDS_DUPLICATE_SERVER);
  658. break;
  659. }
  660. return;
  661. }
  662. HRESULT CMainFrame :: GetLicServer(CString * pLicServer)
  663. {
  664. HRESULT hResult = ERROR_SUCCESS;
  665. if(NULL == pLicServer)
  666. return hResult;
  667. HKEY hKey = NULL;
  668. DWORD lSize = MAX_PATH;
  669. ULONG lDataType = REG_SZ;
  670. TCHAR szString[MAX_PATH] = {0};
  671. long lResult;
  672. lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TERMSERVICE_PARAMETER_KEY,0,KEY_READ,&hKey);
  673. if(ERROR_SUCCESS != lResult)
  674. {
  675. hResult = E_FAIL;
  676. goto cleanup;
  677. }
  678. lResult = RegQueryValueEx(hKey,USE_LICSENSE_SERVER,0,&lDataType,(unsigned char *)szString,&lSize);
  679. if(ERROR_SUCCESS != lResult)
  680. {
  681. hResult = E_FAIL;
  682. goto cleanup;
  683. }
  684. if(szString[0] != 1)
  685. {
  686. hResult = E_FAIL;
  687. goto cleanup;
  688. }
  689. lDataType = REG_SZ;
  690. lSize = MAX_PATH;
  691. lResult = RegQueryValueEx(hKey,LICSENSE_SERVER,0,&lDataType,(unsigned char *)szString,&lSize);
  692. if(ERROR_SUCCESS != lResult)
  693. {
  694. hResult = E_FAIL;
  695. goto cleanup;
  696. }
  697. else
  698. *pLicServer = szString;
  699. cleanup:
  700. if(hKey)
  701. RegCloseKey(hKey);
  702. return hResult;
  703. }
  704. void CMainFrame::OnRefresh()
  705. {
  706. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  707. ASSERT(pDoc);
  708. if(NULL == pDoc)
  709. {
  710. AfxMessageBox(IDS_INTERNAL_ERROR);
  711. return;
  712. }
  713. HRESULT hResult = ERROR_SUCCESS;
  714. CString ErrorServers;
  715. CString Error;
  716. CWaitCursor Wait;
  717. CAllServers *pAllServers = pDoc->GetAllServers();
  718. ASSERT(pAllServers);
  719. if(NULL == pAllServers)
  720. {
  721. AfxMessageBox(IDS_INTERNAL_ERROR);
  722. return;
  723. }
  724. LicServerList * pLicServerList = pAllServers->GetLicServerList();
  725. ASSERT(pLicServerList);
  726. if(NULL == pLicServerList)
  727. {
  728. AfxMessageBox(IDS_INTERNAL_ERROR);
  729. return;
  730. }
  731. POSITION pos = pLicServerList->GetHeadPosition();
  732. OnEnumerateServer(
  733. (pos == NULL) ? 0 : 1, // show error dialog if nothing in the list
  734. 0
  735. );
  736. Wait.Restore();
  737. while(pos)
  738. {
  739. // Connect to each server and check if the information in the cache is current. If not update the information.
  740. // If the connection to the server cannot be establised,add them to the list to display to the user.
  741. POSITION TempPos = pos;
  742. CLicServer * pLicServer = pLicServerList->GetNext(pos);
  743. ASSERT(pLicServer);
  744. if(NULL == pLicServer)
  745. {
  746. continue;
  747. }
  748. CString Name = pLicServer->GetName();
  749. //Call Refresh Server
  750. hResult = RefreshServer(pLicServer);
  751. }
  752. if(!ErrorServers.IsEmpty())
  753. {
  754. Error.LoadString(IDS_REFRESH_SERVERS_ERROR);
  755. Error = Error + ErrorServers;
  756. AfxMessageBox(Error);
  757. }
  758. return;
  759. }
  760. void CMainFrame::DeleteServer(LicServerList * pLicServerList, POSITION TempPos, CLicServer * pLicServer)
  761. {
  762. if(NULL == pLicServerList || NULL == pLicServer)
  763. return;
  764. m_pLeftView->SendMessage(WM_DELETE_SERVER,0,(LPARAM)pLicServer);
  765. m_pRightView->SendMessage(WM_DELETE_SERVER,0,(LPARAM)pLicServer);
  766. pLicServerList->RemoveAt(TempPos);
  767. delete pLicServer;
  768. pLicServer = NULL;
  769. }
  770. void CMainFrame::SetTreeViewSel(LPARAM lParam, NODETYPE NodeType)
  771. {
  772. if(NULL == lParam || NULL == m_pLeftView)
  773. return;
  774. ((CLicMgrLeftView *)m_pLeftView)->SetSelection(lParam, NodeType);
  775. SetActiveView(m_pLeftView);
  776. return;
  777. }
  778. HRESULT CMainFrame::AddLicenses(CKeyPack * pKeyPack,UINT nLicenses)
  779. {
  780. HRESULT hResult = ERROR_SUCCESS;
  781. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  782. ASSERT(pDoc);
  783. if(NULL == pDoc || NULL == pKeyPack)
  784. {
  785. hResult = E_FAIL;
  786. return hResult;
  787. }
  788. LPLSKeyPack psKeyPack;
  789. psKeyPack = &pKeyPack->GetKeyPackStruct();
  790. hResult = pDoc->AddLicenses(pKeyPack->GetServer(),psKeyPack,nLicenses);
  791. if(ERROR_SUCCESS != hResult)
  792. {
  793. return hResult;
  794. }
  795. m_pRightView->SendMessage(WM_UPDATE_SERVER,0,(LPARAM)pKeyPack->GetServer());
  796. return hResult;
  797. }
  798. HRESULT CMainFrame::RemoveLicenses(CKeyPack * pKeyPack,UINT nLicenses)
  799. {
  800. HRESULT hResult = ERROR_SUCCESS;
  801. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  802. ASSERT(pDoc);
  803. if(NULL == pDoc || NULL == pKeyPack)
  804. {
  805. hResult = E_FAIL;
  806. return hResult;
  807. }
  808. LPLSKeyPack psKeyPack;
  809. psKeyPack = &pKeyPack->GetKeyPackStruct();
  810. hResult = pDoc->RemoveLicenses(pKeyPack->GetServer(),psKeyPack,nLicenses);
  811. if(ERROR_SUCCESS != hResult && LSERVER_I_REMOVE_TOOMANY != hResult)
  812. {
  813. return hResult;
  814. }
  815. m_pRightView->SendMessage(WM_UPDATE_SERVER,0,(LPARAM)pKeyPack->GetServer());
  816. return hResult;
  817. }
  818. void InitLsaString(PLSA_UNICODE_STRING LsaString, LPWSTR String )
  819. {
  820. DWORD StringLength;
  821. if (String == NULL)
  822. {
  823. LsaString->Buffer = NULL;
  824. LsaString->Length = 0;
  825. LsaString->MaximumLength = 0;
  826. return;
  827. }
  828. StringLength = lstrlen(String);
  829. LsaString->Buffer = String;
  830. LsaString->Length = (USHORT) StringLength * sizeof(WCHAR);
  831. LsaString->MaximumLength=(USHORT)(StringLength+1) * sizeof(WCHAR);
  832. }
  833. NTSTATUS
  834. OpenPolicy(
  835. LPWSTR ServerName,
  836. DWORD DesiredAccess,
  837. PLSA_HANDLE PolicyHandle
  838. )
  839. /*++
  840. --*/
  841. {
  842. LSA_OBJECT_ATTRIBUTES ObjectAttributes;
  843. LSA_UNICODE_STRING ServerString;
  844. PLSA_UNICODE_STRING Server = NULL;
  845. // Always initialize the object attributes to all zeroes.
  846. ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
  847. if (ServerName != NULL)
  848. {
  849. // Make a LSA_UNICODE_STRING out of the LPWSTR passed in
  850. InitLsaString(&ServerString, ServerName);
  851. Server = &ServerString;
  852. }
  853. // Attempt to open the policy.
  854. return LsaOpenPolicy(Server, &ObjectAttributes, DesiredAccess, PolicyHandle );
  855. }
  856. BOOL CMainFrame::IsUserAdmin(CString& Server)
  857. {
  858. BOOL IsUserAdmin = FALSE;
  859. LSA_HANDLE PolicyHandle = NULL;
  860. NTSTATUS Status;
  861. Status = OpenPolicy(Server.GetBuffer(Server.GetLength()),POLICY_SERVER_ADMIN,&PolicyHandle);
  862. DBGMSG( L"LICMGR@CMainFrame::IsUserAdmin OpenPolicy returned 0x%x\n" , Status );
  863. if(Status == 0)
  864. IsUserAdmin = TRUE;
  865. if(PolicyHandle)
  866. LsaClose(PolicyHandle);
  867. return IsUserAdmin;
  868. }
  869. void CMainFrame::EnumFailed(HRESULT reason, CLicServer * pLicServer)
  870. {
  871. DBGMSG( L"CMainFrame_EnumFailed\n" , 0 );
  872. ASSERT(pLicServer);
  873. if(NULL == pLicServer)
  874. return;
  875. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  876. ASSERT(pDoc);
  877. if(NULL == pDoc)
  878. return;
  879. CString Error;
  880. CString Server;
  881. POSITION pos;
  882. BOOL bFoundServer = FALSE;
  883. LicServerList * pLicServerList = NULL;
  884. POSITION temppos = NULL;
  885. switch(reason)
  886. {
  887. case CONNECTION_FAILED:
  888. DBGMSG( L"\tCONNECTION_FAILED\n" , 0 );
  889. Server = pLicServer->GetName();
  890. Error.Format(IDS_CONNECT_ERROR,Server);
  891. AfxMessageBox(Error);
  892. pLicServerList = (pDoc->GetAllServers())->GetLicServerList();
  893. if(NULL == pLicServerList)
  894. break;
  895. //Find the position of the server in the List;
  896. pos = pLicServerList->GetHeadPosition();
  897. while(pos)
  898. {
  899. temppos = pos;
  900. CLicServer *pServer = (CLicServer *)pLicServerList->GetNext(pos);
  901. ASSERT(pServer);
  902. if(NULL == pServer)
  903. continue;
  904. if((0 == Server.CompareNoCase(pServer->GetName())) || (0 == Server.CompareNoCase(pServer->GetIpAddress())))
  905. {
  906. bFoundServer = TRUE;
  907. break;
  908. }
  909. }
  910. if(bFoundServer)
  911. DeleteServer(pLicServerList,temppos,pLicServer);
  912. break;
  913. case LSERVER_E_SERVER_BUSY:
  914. DBGMSG( L"\tLSERVER_E_SERVER_BUSY\n" , 0 );
  915. AfxMessageBox(IDS_SERVER_BUSY);
  916. break;
  917. case LSERVER_E_OUTOFMEMORY:
  918. DBGMSG( L"\tLSERVER_E_OUTOFMEMORY\n" , 0 );
  919. AfxMessageBox(IDS_SERVER_OUTOFMEMORY);
  920. break;
  921. case LSERVER_E_INTERNAL_ERROR:
  922. DBGMSG( L"\tLSERVER_E_INTERNAL_ERROR\n" , 0 );
  923. AfxMessageBox(IDS_SERVER_INTERNAL_ERROR);
  924. pLicServerList = (pDoc->GetAllServers())->GetLicServerList();
  925. if(NULL == pLicServerList)
  926. break;
  927. //Find the position of the server in the List;
  928. pos = pLicServerList->GetHeadPosition();
  929. while(pos)
  930. {
  931. temppos = pos;
  932. CLicServer *pServer = (CLicServer *)pLicServerList->GetNext(pos);
  933. ASSERT(pServer);
  934. if(NULL == pServer)
  935. continue;
  936. if((0 == Server.CompareNoCase(pServer->GetName())) || (0 == Server.CompareNoCase(pServer->GetIpAddress())))
  937. {
  938. bFoundServer = TRUE;
  939. break;
  940. }
  941. }
  942. if(bFoundServer)
  943. DeleteServer(pLicServerList,temppos,pLicServer);
  944. break;
  945. case E_OUTOFMEMORY:
  946. DBGMSG( L"\tE_OUTOFMEMORY\n" , 0 );
  947. AfxMessageBox(IDS_NO_MEMORY);
  948. break;
  949. default:
  950. break;
  951. }
  952. }
  953. void CMainFrame::SelectView(VIEW view)
  954. {
  955. if(view == TREEVIEW)
  956. {
  957. SetActiveView(m_pLeftView);
  958. }
  959. else
  960. {
  961. SetActiveView(m_pRightView);
  962. }
  963. }
  964. HRESULT CMainFrame::RefreshServer(CLicServer * pLicServer)
  965. {
  966. DWORD dwStatus;
  967. HRESULT hResult = E_FAIL;
  968. CWaitCursor Wait;
  969. if(NULL == pLicServer)
  970. {
  971. return E_INVALIDARG;
  972. }
  973. DBGMSG( L"LICMGR : CMainFrame::RefreshServer %s\n" , pLicServer->GetName( ) );
  974. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  975. ASSERT(pDoc);
  976. if(NULL == pDoc)
  977. {
  978. return ERROR_INTERNAL_ERROR;
  979. }
  980. CString Server;
  981. if(pLicServer->UseIpAddress())
  982. {
  983. Server = pLicServer->GetIpAddress();
  984. }
  985. else
  986. {
  987. Server = pLicServer->GetName();
  988. }
  989. WIZCONNECTION WizConType;
  990. DBGMSG( L"LICMGR:CMainFrame::RefreshServer setting ConnectionType\n" , 0 );
  991. if( GetConnectionType( GetSafeHwnd() , Server , &WizConType ) == ERROR_SUCCESS )
  992. {
  993. pLicServer->SetConType( WizConType );
  994. }
  995. // check for admin
  996. DBGMSG( L"LICMGR:CMainFrame::RefreshServer setting admin priv\n" , 0 );
  997. pLicServer->SetAdmin( IsUserAdmin( Server ) );
  998. if( !pLicServer->IsUserAdmin( ) )
  999. {
  1000. return E_ACCESSDENIED;
  1001. }
  1002. DBGMSG( L"LICMGR:CMainFrame::RefreshServer updating server status\n" , 0 );
  1003. if( IsLicenseServerRegistered( GetSafeHwnd( ) , Server , &dwStatus ) == ERROR_SUCCESS )
  1004. {
  1005. pLicServer->SetServerRegistrationStatus( dwStatus );
  1006. }
  1007. else
  1008. {
  1009. pLicServer->SetServerRegistrationStatus( ( DWORD )-1 );
  1010. }
  1011. //Could connect to the server. check if Info in cache is proper.
  1012. //If server is not expanded leave it like that.
  1013. /*
  1014. if(!pLicServer->IsExpanded())
  1015. {
  1016. DBGMSG( L"LICMGR:Cmainframe licserver not expanded\n" , 0 );
  1017. return S_OK;
  1018. }
  1019. */
  1020. KeyPackList * pkeypackList = pLicServer->GetKeyPackList();
  1021. if(NULL == pkeypackList)
  1022. {
  1023. DBGMSG( L"LICMGR:RefreshServer no keypacklist\n",0 );
  1024. return E_FAIL;
  1025. }
  1026. POSITION pos1 = pkeypackList->GetHeadPosition();
  1027. CKeyPack *pKeyPack = NULL;
  1028. DBGMSG( L"LICMGR:CMainFrame::RefreshServer removing keypacks\n" , 0 );
  1029. while(pos1)
  1030. {
  1031. pKeyPack = (CKeyPack *)pkeypackList->GetNext(pos1);
  1032. ASSERT(pKeyPack);
  1033. if(pKeyPack)
  1034. {
  1035. delete pKeyPack;
  1036. pKeyPack = NULL;
  1037. }
  1038. }
  1039. pkeypackList->RemoveAll();
  1040. pLicServer->Expand(FALSE);
  1041. DBGMSG( L"LICMGR:CMainFrame::RefreshServer enumerating keypacks\n" , 0 );
  1042. hResult = pDoc->EnumerateKeyPacks(
  1043. pLicServer,
  1044. LSKEYPACK_SEARCH_LANGID,
  1045. TRUE
  1046. );
  1047. if(hResult != S_OK)
  1048. {
  1049. EnumFailed( hResult , pLicServer );
  1050. return hResult;
  1051. }
  1052. /*
  1053. pos1 = pkeypackList->GetHeadPosition();
  1054. BOOL bFlag = FALSE;
  1055. while(pos1)
  1056. {
  1057. CKeyPack *pKeyPack = (CKeyPack *)pkeypackList->GetNext(pos1);
  1058. hResult = pDoc->EnumerateLicenses(
  1059. pKeyPack,
  1060. LSLICENSE_SEARCH_KEYPACKID,
  1061. TRUE
  1062. );
  1063. if(hResult != S_OK)
  1064. {
  1065. return hResult;
  1066. }
  1067. }
  1068. */
  1069. DBGMSG( L"LICMGR:CMainFrame::RefreshServer checking for keypacks\n" , 0 );
  1070. pLicServer->SetDownLoadLics( IsDownLoadedPacks( pLicServer ) );
  1071. m_pLeftView->SendMessage(WM_UPDATE_SERVER,0,(LPARAM)pLicServer);
  1072. m_pRightView->SendMessage(WM_UPDATE_SERVER,0,(LPARAM)pLicServer);
  1073. return hResult;
  1074. }
  1075. //--------------------------------------------------------------------
  1076. void CMainFrame::OnUpdateDownloadlicenses( CCmdUI * pCmdUI )
  1077. {
  1078. DBGMSG( L"LICMGR@CMainFrame::OnUpdateDownloadlicenses\n" , 0 );
  1079. CLicServer *pServer = NULL;
  1080. HRESULT hr;
  1081. GetActiveServer( &pServer );
  1082. pCmdUI->Enable( FALSE );
  1083. if( pServer != NULL )
  1084. {
  1085. if( pServer->GetServerType( ) == SERVER_TS5_ENFORCED )
  1086. {
  1087. pCmdUI->Enable( IsServerRegistered( &hr ) );
  1088. }
  1089. else
  1090. {
  1091. pCmdUI->Enable( TRUE );
  1092. }
  1093. }
  1094. else
  1095. {
  1096. pCmdUI->Enable( FALSE );
  1097. }
  1098. }
  1099. //--------------------------------------------------------------------
  1100. void CMainFrame::OnUpdateRepeatLastDownload( CCmdUI * pCmdUI )
  1101. {
  1102. DBGMSG( L"LICMGR@CMainFrame::OnUpdateRepeatLastDownload\n" , 0 );
  1103. HRESULT hr;
  1104. CLicServer * pLicServer = NULL;
  1105. if( SUCCEEDED( GetActiveServer( &pLicServer ) ) )
  1106. {
  1107. if( pLicServer->GetConType( ) != CONNECTION_WWW )
  1108. {
  1109. if( IsServerRegistered( &hr ) )
  1110. {
  1111. pCmdUI->Enable( IsLicensesDownLoaded() );
  1112. return;
  1113. }
  1114. }
  1115. }
  1116. pCmdUI->Enable( FALSE );
  1117. }
  1118. //--------------------------------------------------------------------
  1119. void CMainFrame::OnUpdateReregisterserver( CCmdUI * pCmdUI )
  1120. {
  1121. DBGMSG( L"LICMGR@CMainFrame::OnUpdateReregisterserver\n" , 0 );
  1122. HRESULT hr;
  1123. CLicServer * pLicServer = NULL;
  1124. if( SUCCEEDED( GetActiveServer( &pLicServer ) ) )
  1125. {
  1126. if( pLicServer->GetConType( ) != CONNECTION_WWW )
  1127. {
  1128. pCmdUI->Enable( IsServerRegistered( &hr ) );
  1129. return;
  1130. }
  1131. }
  1132. pCmdUI->Enable( FALSE );
  1133. }
  1134. //--------------------------------------------------------------------
  1135. void CMainFrame::OnUpdateUnregisterserver( CCmdUI * pCmdUI )
  1136. {
  1137. DBGMSG( L"LICMGR@CMainFrame::OnUpdateUnregisterserver\n" , 0 );
  1138. HRESULT hr;
  1139. CLicServer * pLicServer = NULL;
  1140. if( SUCCEEDED( GetActiveServer( &pLicServer ) ) )
  1141. {
  1142. if( pLicServer->GetConType( ) != CONNECTION_WWW )
  1143. {
  1144. pCmdUI->Enable( IsServerRegistered( &hr ) );
  1145. return;
  1146. }
  1147. }
  1148. pCmdUI->Enable( FALSE );
  1149. }
  1150. //--------------------------------------------------------------------
  1151. void CMainFrame::OnUpdateRefresh( CCmdUI *pCmdUI )
  1152. {
  1153. CLicServer * pLicServer = NULL;
  1154. if( FAILED( GetActiveServer( &pLicServer ) ) )
  1155. {
  1156. pCmdUI->Enable( FALSE );
  1157. }
  1158. else
  1159. {
  1160. pCmdUI->Enable( TRUE );
  1161. }
  1162. }
  1163. //--------------------------------------------------------------------
  1164. void CMainFrame::OnUpdateProperties( CCmdUI *pCmdUI )
  1165. {
  1166. CLicServer * pLicServer = NULL;
  1167. GetActiveServer( &pLicServer );
  1168. pCmdUI->Enable( FALSE );
  1169. if( pLicServer != NULL && pLicServer->GetServerType( ) == SERVER_TS5_ENFORCED )
  1170. {
  1171. pCmdUI->Enable( TRUE );
  1172. }
  1173. }
  1174. //--------------------------------------------------------------------
  1175. void CMainFrame::OnRefreshServer( )
  1176. {
  1177. CLicServer * pLicServer = NULL;
  1178. if( FAILED( GetActiveServer( &pLicServer ) ) )
  1179. {
  1180. // nothing to refresh
  1181. return;
  1182. }
  1183. RefreshServer( pLicServer );
  1184. }
  1185. //--------------------------------------------------------------------
  1186. BOOL CMainFrame::IsServerRegistered( HRESULT *phrStatus )
  1187. {
  1188. BOOL bEnable = FALSE;
  1189. ASSERT( phrStatus != NULL );
  1190. DWORD dwServerStatus = ERROR_SUCCESS;
  1191. CLicServer * pLicServer = NULL;
  1192. *phrStatus = GetActiveServer( &pLicServer );
  1193. if( pLicServer != NULL )
  1194. {
  1195. if( pLicServer->GetServerType() == SERVER_TS5_ENFORCED )
  1196. {
  1197. dwServerStatus = pLicServer->GetServerRegistrationStatus( );
  1198. }
  1199. else
  1200. {
  1201. *phrStatus = E_FAIL; // fail all non enforced server
  1202. }
  1203. }
  1204. if( dwServerStatus == LSERVERSTATUS_REGISTER_INTERNET ||
  1205. dwServerStatus == LSERVERSTATUS_REGISTER_OTHER )
  1206. {
  1207. bEnable = TRUE;
  1208. }
  1209. else
  1210. {
  1211. bEnable = FALSE;
  1212. }
  1213. DBGMSG( L"LICMGR@CMainFrame::IsServerRegistered -- status returned 0x%x\n" , dwServerStatus );
  1214. return bEnable;
  1215. }
  1216. //--------------------------------------------------------------------
  1217. // used by views
  1218. //--------------------------------------------------------------------
  1219. void CMainFrame::UI_initmenu( CMenu *pMenu , NODETYPE nt )
  1220. {
  1221. HRESULT hr;
  1222. CLicServer *pServer;
  1223. GetActiveServer( &pServer );
  1224. if( pMenu == NULL )
  1225. {
  1226. return;
  1227. }
  1228. UINT uMF = MF_GRAYED | MF_DISABLED;
  1229. if( pServer != NULL )
  1230. {
  1231. if( pServer->GetConType() != CONNECTION_WWW )
  1232. {
  1233. DBGMSG( L"LICMGR:UI_initmenu server contype is not www\n" , 0 );
  1234. uMF = MF_ENABLED;
  1235. }
  1236. }
  1237. BOOL bEnable = IsServerRegistered( &hr );
  1238. if( nt == NODE_SERVER )
  1239. {
  1240. if( bEnable )
  1241. {
  1242. if( FAILED( hr ) )
  1243. {
  1244. pMenu->EnableMenuItem( ID_SVR_ACTIVATESERVER , MF_ENABLED );
  1245. }
  1246. else
  1247. {
  1248. pMenu->EnableMenuItem( ID_SVR_ACTIVATESERVER , MF_GRAYED | MF_DISABLED );
  1249. }
  1250. pMenu->EnableMenuItem( ID_LPK_ADVANCED_REACTIVATESERVER , uMF );
  1251. pMenu->EnableMenuItem( ID_LPK_ADVANCED_DEACTIVATESERVER , uMF );
  1252. pMenu->EnableMenuItem( ID_LPK_PROPERTIES , MF_ENABLED );
  1253. if( IsLicensesDownLoaded() )
  1254. {
  1255. pMenu->EnableMenuItem( ID_LPK_DOWNLOADLICENSES , MF_ENABLED );
  1256. pMenu->EnableMenuItem( ID_LPK_ADVANCED_REPEATLASTDOWNLOAD , uMF );
  1257. }
  1258. else
  1259. {
  1260. pMenu->EnableMenuItem( ID_LPK_DOWNLOADLICENSES , MF_ENABLED );
  1261. pMenu->EnableMenuItem( ID_LPK_ADVANCED_REPEATLASTDOWNLOAD , MF_GRAYED | MF_DISABLED );
  1262. }
  1263. }
  1264. else
  1265. {
  1266. if( SUCCEEDED( hr ) )
  1267. {
  1268. pMenu->EnableMenuItem( ID_SVR_ACTIVATESERVER , MF_ENABLED );
  1269. }
  1270. else
  1271. {
  1272. pMenu->EnableMenuItem( ID_SVR_ACTIVATESERVER , MF_DISABLED | MF_GRAYED );
  1273. }
  1274. if( pServer != NULL )
  1275. {
  1276. if( pServer->GetServerType( ) == SERVER_TS5_ENFORCED )
  1277. {
  1278. pMenu->EnableMenuItem( ID_LPK_DOWNLOADLICENSES , MF_GRAYED | MF_DISABLED );
  1279. pMenu->EnableMenuItem( ID_LPK_PROPERTIES , MF_ENABLED );
  1280. }
  1281. else
  1282. {
  1283. pMenu->EnableMenuItem( ID_LPK_DOWNLOADLICENSES , MF_ENABLED );
  1284. pMenu->EnableMenuItem( ID_LPK_PROPERTIES , MF_GRAYED | MF_DISABLED );
  1285. }
  1286. }
  1287. pMenu->EnableMenuItem( ID_LPK_ADVANCED_REPEATLASTDOWNLOAD , MF_GRAYED | MF_DISABLED );
  1288. pMenu->EnableMenuItem( ID_LPK_ADVANCED_REACTIVATESERVER , MF_GRAYED | MF_DISABLED );
  1289. pMenu->EnableMenuItem( ID_LPK_ADVANCED_DEACTIVATESERVER , MF_GRAYED | MF_DISABLED );
  1290. }
  1291. }
  1292. else if( nt == NODE_KEYPACK )
  1293. {
  1294. if( bEnable )
  1295. {
  1296. if( IsLicensesDownLoaded() )
  1297. {
  1298. pMenu->EnableMenuItem( ID_LICPAK_DOWNLOADLICENSES , MF_ENABLED );
  1299. pMenu->EnableMenuItem( ID_LICPAK_REPEATDOWNLOAD , uMF );
  1300. }
  1301. else
  1302. {
  1303. pMenu->EnableMenuItem( ID_LICPAK_DOWNLOADLICENSES , MF_ENABLED );
  1304. pMenu->EnableMenuItem( ID_LICPAK_REPEATDOWNLOAD , MF_GRAYED | MF_DISABLED );
  1305. }
  1306. }
  1307. else
  1308. {
  1309. if( pServer != NULL && pServer->GetServerType() == SERVER_TS5_ENFORCED )
  1310. {
  1311. pMenu->EnableMenuItem( ID_LICPAK_DOWNLOADLICENSES , MF_GRAYED | MF_DISABLED );
  1312. }
  1313. else
  1314. {
  1315. pMenu->EnableMenuItem( ID_LICPAK_DOWNLOADLICENSES , MF_ENABLED );
  1316. }
  1317. pMenu->EnableMenuItem( ID_LICPAK_REPEATDOWNLOAD , MF_GRAYED | MF_DISABLED );
  1318. }
  1319. }
  1320. else if( nt == NODE_ALL_SERVERS )
  1321. {
  1322. pMenu->EnableMenuItem( ID_ALLSVR_REFRESHALL , MF_ENABLED );
  1323. }
  1324. /*
  1325. else if( nt == NODE_NONE )
  1326. {
  1327. // this can only mean licenses
  1328. if( !IsLicensesDownLoaded( ) )
  1329. {
  1330. pMenu->EnableMenuItem( ID_LIC_DOWNLOADLICENSES , MF_GRAYED | MF_DISABLED );
  1331. }
  1332. }
  1333. */
  1334. }
  1335. //------------------------------------------------------------------------------------
  1336. void CMainFrame::OnDownLoadLicenses( )
  1337. {
  1338. BOOL bF;
  1339. CLicServer *pLicServer = NULL;
  1340. GetActiveServer( &pLicServer );
  1341. if( pLicServer != NULL )
  1342. {
  1343. if( pLicServer->GetServerType() == SERVER_TS5_ENFORCED )
  1344. {
  1345. DWORD dw = WizardActionOnServer( WIZACTION_DOWNLOADLKP , &bF , NOVIEW );
  1346. DBGMSG( L"LICMGR : OnDownLoadLicenses returned 0x%x\n " , dw );
  1347. }
  1348. else
  1349. {
  1350. AddKeyPackDialog(NULL);
  1351. }
  1352. }
  1353. }
  1354. //------------------------------------------------------------------------------------
  1355. void CMainFrame::OnRepeatLastDownLoad( )
  1356. {
  1357. BOOL bF;
  1358. DWORD dw = WizardActionOnServer( WIZACTION_DOWNLOADLASTLKP , &bF , NOVIEW );
  1359. DBGMSG( L"LICMGR : OnRepeatLastDownLoad returned 0x%x\n " , dw );
  1360. }
  1361. //------------------------------------------------------------------------------------
  1362. void CMainFrame::OnReRegisterServer( )
  1363. {
  1364. BOOL bF;
  1365. DWORD dw = WizardActionOnServer( WIZACTION_REREGISTERLS , &bF , NOVIEW );
  1366. DBGMSG( L"LICMGR : OnReRegisterServer returned 0x%x\n " , dw );
  1367. }
  1368. //------------------------------------------------------------------------------------
  1369. void CMainFrame::OnUnRegisterServer( )
  1370. {
  1371. BOOL bF;
  1372. DWORD dw = WizardActionOnServer( WIZACTION_UNREGISTERLS , &bF , NOVIEW );
  1373. DBGMSG( L"LICMGR : OnUnRegisterServer returned 0x%x\n " , dw );
  1374. }
  1375. //------------------------------------------------------------------------------------
  1376. void CMainFrame::OnProperties( )
  1377. {
  1378. BOOL bF;
  1379. DWORD dw = WizardActionOnServer( WIZACTION_SHOWPROPERTIES , &bF , NOVIEW );
  1380. DBGMSG( L"LICMGR : CMainFrame -- OnProperties returned 0x%x\n", dw );
  1381. }
  1382. //------------------------------------------------------------------------------------
  1383. BOOL CMainFrame::IsLicensesDownLoaded( )
  1384. {
  1385. CLicServer * pLicServer = NULL;
  1386. if( SUCCEEDED( GetActiveServer( &pLicServer ) ) )
  1387. {
  1388. if( pLicServer != NULL )
  1389. {
  1390. if( pLicServer->GetConType( ) != CONNECTION_PHONE )
  1391. {
  1392. DBGMSG( L"Licmgr CMainFrame::IsLicensesDownLoaded GetConnectionType internet - www base\n" , 0 );
  1393. return pLicServer->IsLicsDownloaded( );
  1394. }
  1395. else
  1396. {
  1397. return FALSE;
  1398. }
  1399. }
  1400. }
  1401. return FALSE;
  1402. }
  1403. //------------------------------------------------------------------------------------
  1404. DWORD CMainFrame::WizardActionOnServer( WIZACTION wa , PBOOL pbRefresh , VIEW vt )
  1405. {
  1406. CLicMgrLeftView * pLeftView = (CLicMgrLeftView *)m_pLeftView;
  1407. CTreeCtrl& TreeCtrl = pLeftView->GetTreeCtrl();
  1408. CRightList * pRightView = (CRightList *)m_pRightView;
  1409. CLicServer *pServer = NULL;
  1410. if( vt == TREEVIEW )
  1411. {
  1412. CTreeNode *pNode = (CTreeNode *)TreeCtrl.GetItemData( pLeftView->GetRightClickedItem() );
  1413. if( pNode->GetNodeType() == NODE_SERVER )
  1414. {
  1415. pServer = static_cast< CLicServer * >( pNode->GetTreeObject() );
  1416. }
  1417. else if( pNode->GetNodeType( ) == NODE_KEYPACK )
  1418. {
  1419. CKeyPack *pKeyPack = static_cast< CKeyPack *>( pNode->GetTreeObject() );
  1420. if( pKeyPack != NULL )
  1421. {
  1422. pServer = pKeyPack->GetServer( );
  1423. }
  1424. }
  1425. }
  1426. else if( vt == LISTVIEW )
  1427. {
  1428. CListCtrl& listctrl = pRightView->GetListCtrl();
  1429. CLicMgrDoc * pDoc = ( CLicMgrDoc * )( GetActiveView()->GetDocument( ) );
  1430. ASSERT(pDoc);
  1431. if(NULL == pDoc)
  1432. {
  1433. return ERROR_INVALID_PARAMETER;
  1434. }
  1435. int nSelected = listctrl.GetNextItem(-1, LVNI_SELECTED);
  1436. if( -1 != nSelected)
  1437. {
  1438. DWORD_PTR dCurrSel = listctrl.GetItemData( nSelected );
  1439. if( NODE_ALL_SERVERS == pDoc->GetNodeType() )
  1440. {
  1441. pServer = reinterpret_cast< CLicServer * >( dCurrSel );
  1442. }
  1443. else if( pDoc->GetNodeType() == NODE_SERVER )
  1444. {
  1445. CKeyPack *pKeyPack = reinterpret_cast< CKeyPack *>( dCurrSel );
  1446. if( pKeyPack != NULL )
  1447. {
  1448. pServer = pKeyPack->GetServer( );
  1449. }
  1450. }
  1451. else if( pDoc->GetNodeType( ) == NODE_KEYPACK )
  1452. {
  1453. CLicense * pLicense = reinterpret_cast< CLicense * >( dCurrSel );
  1454. pServer = ( pLicense->GetKeyPack() )->GetServer( );
  1455. }
  1456. }
  1457. }
  1458. else if( vt == NOVIEW )
  1459. {
  1460. CLicServer * pLicServer = NULL;
  1461. if( SUCCEEDED( GetActiveServer( &pLicServer ) ) )
  1462. {
  1463. pServer = pLicServer;
  1464. }
  1465. }
  1466. if( pServer != NULL )
  1467. {
  1468. DWORD dw = ERROR_SUCCESS;
  1469. // check for admin
  1470. if( !pServer->IsUserAdmin( ) )
  1471. {
  1472. AfxMessageBox( IDS_E_ACCESSDENIED );
  1473. //::MessageBox( GetSafeHwnd( ) , L"Unable to perform operation: Access denied" , L"Terminal Services Licensing" , MB_OK|MB_ICONINFORMATION );
  1474. return ERROR_ACCESS_DENIED;
  1475. }
  1476. if( wa != WIZACTION_REGISTERLS )
  1477. {
  1478. if( pServer->GetServerType() == SERVER_TS5_ENFORCED )
  1479. {
  1480. DBGMSG( L"LICMGR:CMainFrame::WizardActionOnServer calling StartWizard\n", 0 );
  1481. dw = StartWizard( GetSafeHwnd( ) , wa , (LPCTSTR)pServer->GetName( ) , pbRefresh );
  1482. DBGMSG( L"StartWizard ( central call ) returned 0x%x\n", dw );
  1483. DBGMSG( L"StartWizard ( central call ) refresh = %s\n", *pbRefresh ? L"true" : L"false" );
  1484. if( *pbRefresh )
  1485. {
  1486. RefreshServer( pServer );
  1487. }
  1488. }
  1489. else
  1490. {
  1491. if( wa == WIZACTION_DOWNLOADLKP )
  1492. {
  1493. AddKeyPackDialog(NULL);
  1494. }
  1495. }
  1496. }
  1497. switch( wa )
  1498. {
  1499. case WIZACTION_REGISTERLS:
  1500. // this handles non-enforced as well.
  1501. OnRegistration( );
  1502. break;
  1503. case WIZACTION_UNREGISTERLS :
  1504. if( dw == ERROR_SUCCESS )
  1505. {
  1506. pServer->SetDownLoadLics( FALSE );
  1507. }
  1508. // FALL THROUGH
  1509. case WIZACTION_REREGISTERLS :
  1510. {
  1511. DWORD dwStatus;
  1512. if( IsLicenseServerRegistered( GetSafeHwnd( ) , (LPCTSTR)pServer->GetName( ) , &dwStatus ) == ERROR_SUCCESS )
  1513. {
  1514. pServer->SetServerRegistrationStatus( dwStatus );
  1515. }
  1516. }
  1517. break;
  1518. }
  1519. return dw;
  1520. }
  1521. return ERROR_INVALID_PARAMETER;
  1522. }
  1523. //------------------------------------------------------------------------------------
  1524. BOOL CMainFrame::IsDownLoadedPacks( CLicServer *pServer )
  1525. {
  1526. UINT counter = 0;
  1527. if( pServer != NULL )
  1528. {
  1529. KeyPackList *pKeyPackList = pServer->GetKeyPackList( );
  1530. if( pKeyPackList != NULL )
  1531. {
  1532. POSITION pos = pKeyPackList->GetHeadPosition();
  1533. while(pos)
  1534. {
  1535. CKeyPack *pKeyPack = (CKeyPack *)pKeyPackList->GetNext(pos);
  1536. if( pKeyPack != NULL )
  1537. {
  1538. if( pKeyPack->GetKeyPackStruct().ucKeyPackType != LSKEYPACKTYPE_TEMPORARY &&
  1539. pKeyPack->GetKeyPackStruct().ucKeyPackType != LSKEYPACKTYPE_FREE )
  1540. {
  1541. counter++;
  1542. DBGMSG( L"LICMGR:CMainFrame found %d keypack(s)\n" , counter );
  1543. }
  1544. }
  1545. }
  1546. if( counter >= 1 )
  1547. {
  1548. DBGMSG( L"LICMGR : CMainFrame IsDownLoadedPacks returns true\n" ,0 );
  1549. return TRUE;
  1550. }
  1551. }
  1552. }
  1553. DBGMSG( L"LICMGR : CMainFrame IsDownLoadedPacks returns false \n" ,0 );
  1554. return FALSE;
  1555. }