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.

1880 lines
49 KiB

  1. #include "diagnostics.h"
  2. //#include <netsh.h>
  3. #include <netshp.h>
  4. #include "Dglogs.h"
  5. #include "DglogsCom.h"
  6. #include "Commdlg.h"
  7. #include "oe.h"
  8. extern PrintMessage22 PrintMessage2;
  9. #undef PrintMessage
  10. #define PrintMessage PrintMessage2
  11. // Wbem Repositories
  12. //
  13. #define TXT_WBEM_REP_CIMV2 L"\\root\\cimv2"
  14. // Wbem Namespaces
  15. //
  16. #define TXT_WBEM_NS_COMPUTER L"win32_computersystem"
  17. #define TXT_WBEM_NS_OS L"win32_operatingsystem"
  18. #define TXT_WBEM_NS_NETWORK L"win32_networkadapterconfiguration"
  19. #define TXT_WBEM_NS_CLIENT L"win32_networkclient"
  20. #define TXT_WBEM_NS_WMI L"win32_wmisetting"
  21. #define TXT_WBEM_NS_NETDIAG L"netdiagnostics"
  22. #define TXT_WBEM_NS_MODEM L"win32_potsmodem"
  23. // Captions for the different catagories
  24. //
  25. #define TXT_ADAPTER_CAPTION L"Caption"
  26. #define TXT_CLIENT_CAPTION L"Name"
  27. #define TXT_MAIL_CAPTION L"InBoundMailServer"
  28. #define TXT_NEWS_CAPTION L"NewsServer"
  29. #define TXT_PROXY_CAPTION L"IEProxy"
  30. #define TXT_COMPUTER_CAPTION L"Caption"
  31. #define TXT_OS_CAPTION L"Caption"
  32. #define TXT_VERSION_CAPTION L"Version"
  33. #define TXT_MODEM_CAPTION L"Caption"
  34. #define TXT_LOOPBACK_CAPTION L"Loopback"
  35. enum MAIL_TYPE
  36. {
  37. MAIL_NONE,
  38. MAIL_SMTP,
  39. MAIL_SMTP2,
  40. MAIL_IMAP,
  41. MAIL_POP3,
  42. MAIL_HTTP,
  43. };
  44. /*++
  45. Routine Description
  46. The worker thread uses this function to check if the main thread has canceled the worker thread.
  47. i.e. the work thread should abort what ever it is doing, clean up and terminate.
  48. Arguments
  49. none
  50. Return Value
  51. TRUE the worker thread has been terminated
  52. FALSE the worker thread has not been terminated
  53. --*/
  54. inline BOOL CDiagnostics::ShouldTerminate()
  55. {
  56. if( m_bTerminate )
  57. {
  58. // The worker thread already has been canceled.
  59. //
  60. return TRUE;
  61. }
  62. if (WaitForSingleObject(m_hTerminateThread, 0) == WAIT_OBJECT_0)
  63. {
  64. // Worker thread has been canceled
  65. //
  66. m_bTerminate = FALSE;
  67. return TRUE;
  68. }
  69. else
  70. {
  71. // Worker thread has not yet been canceled.
  72. //
  73. return FALSE;
  74. }
  75. }
  76. /*++
  77. Routine Description
  78. Initialize the Diagnostics Object
  79. Arguments
  80. none
  81. Return Value
  82. --*/
  83. CDiagnostics::CDiagnostics()
  84. {
  85. m_bFlags = 0;
  86. m_bInterface = NO_INTERFACE;
  87. lstrcpy(m_szwStatusReport,L"");
  88. m_bReportStatus = FALSE;
  89. m_lWorkDone = 0;
  90. m_lTotalWork = 0;
  91. ClearQuery();
  92. }
  93. /*++
  94. Routine Description
  95. Uniniailize the Diagnostics object
  96. Arguments
  97. none
  98. Return Value
  99. --*/
  100. CDiagnostics::~CDiagnostics()
  101. {
  102. // Close the winsock
  103. //
  104. WSACleanup();
  105. }
  106. /*++
  107. Routine Description
  108. Set the interface i.e. Netsh or COM
  109. Arguments
  110. bInterface -- Interface used to access the data
  111. Return Value
  112. --*/
  113. void CDiagnostics::SetInterface(INTERFACE_TYPE bInterface)
  114. {
  115. m_bInterface = bInterface;
  116. }
  117. /*++
  118. Routine Description
  119. Iniatilze the Diagnostics object
  120. Arguments
  121. Return Value
  122. TRUE -- Successfully
  123. else FALSE
  124. --*/
  125. BOOLEAN CDiagnostics::Initialize(INTERFACE_TYPE bInterface)
  126. {
  127. int iRetVal;
  128. WSADATA wsa;
  129. m_bInterface = bInterface;
  130. // Initialize the WmiGateway object
  131. //
  132. if( FALSE == m_WmiGateway.WbemInitialize(bInterface) )
  133. {
  134. return FALSE;
  135. }
  136. // Initialize Winsock
  137. //
  138. iRetVal = WSAStartup(MAKEWORD(2,1), &wsa);
  139. if( iRetVal )
  140. {
  141. return FALSE;
  142. }
  143. return TRUE;
  144. }
  145. /*++
  146. Routine Description
  147. Sends an event to client informing the client of its progress.
  148. Arguments
  149. pszwStatusReport -- Message telling the client what it CDiagnostics is currently doing
  150. lPercent -- A percentage indicating its progress.
  151. Return Value
  152. error code
  153. --*/
  154. void CDiagnostics::EventCall(LPCTSTR pszwStatusReport, LONG lPercent)
  155. {
  156. if( m_pDglogsCom )
  157. {
  158. // Alocate memory for the message and send it to the client
  159. //
  160. BSTR bstrResult = SysAllocString(pszwStatusReport);
  161. m_pDglogsCom->Fire_ProgressReport(&bstrResult,lPercent);
  162. }
  163. }
  164. /*++
  165. Routine Description
  166. Sends an event to client informing the client of its progress.
  167. Arguments
  168. pszwMsg -- Message telling the client what it CDiagnostics is currently doing
  169. lValue -- A percentage indicating its progress.
  170. Return Value
  171. void
  172. Note:
  173. If lValue is -1 then send the finished message
  174. --*/
  175. void CDiagnostics::ReportStatus(LPCTSTR pszwMsg, LONG lValue)
  176. {
  177. // Check if the client requested the Status report option
  178. //
  179. if( m_bReportStatus )
  180. {
  181. if( lValue == -1 )
  182. {
  183. // Send the finished message. 100% complete and the final XML result
  184. //
  185. EventCall(ids(IDS_FINISHED_STATUS), 100);
  186. EventCall(pszwMsg, lValue);
  187. m_lWorkDone = 0;
  188. m_lTotalWork = 0;
  189. }
  190. else
  191. {
  192. // Compute the total percentage completed. Make sure we never go over 100%
  193. //
  194. m_lWorkDone += m_lWorkDone+lValue < 100?lValue:0;
  195. EventCall(pszwMsg, m_lWorkDone);
  196. }
  197. }
  198. }
  199. /*++
  200. Routine Description
  201. Counts the occurance of chars in a string
  202. Arguments
  203. pszw -- String to search
  204. c -- Char to count the occurnce of
  205. Return Value
  206. number of time c occured in pszw
  207. Note:
  208. If lValue is -1 then send the finished message
  209. --*/
  210. int wcscount(LPCTSTR pszw, WCHAR c)
  211. {
  212. int n =0;
  213. for(int i=0; pszw[i]!=L'\0'; i++)
  214. {
  215. if( pszw[i] == c )
  216. {
  217. if( i > 0 && pszw[i-1]!=c) n++;
  218. }
  219. }
  220. return n;
  221. }
  222. /*++
  223. Routine Description
  224. Set the query information
  225. Arguments
  226. pszwCatagory -- Catagory
  227. bFlag -- Flags (Show, PING, Connect)
  228. pszwParam1 -- Instance | iphost
  229. pszwParam2 -- Port number
  230. Return Value
  231. void
  232. --*/
  233. void CDiagnostics::SetQuery(WCHAR *pszwCatagory, BOOL bFlag, WCHAR *pszwParam1, WCHAR *pszwParam2)
  234. {
  235. if( pszwCatagory )
  236. {
  237. // Set the catagory. Need to make a copy of the Catagory since the string might disapper i.e. threads
  238. //
  239. m_wstrCatagories = pszwCatagory;
  240. m_pszwCatagory = (PWCHAR)m_wstrCatagories.c_str();
  241. }
  242. if( bFlag )
  243. {
  244. m_bFlags = bFlag;
  245. }
  246. if( pszwParam1 )
  247. {
  248. m_pszwParam1 = pszwParam1;
  249. }
  250. if( pszwParam2 )
  251. {
  252. m_pszwParam2 = pszwParam2;
  253. }
  254. }
  255. /*++
  256. Routine Description
  257. Clears the Set query information
  258. Arguments
  259. void
  260. Return Value
  261. void
  262. --*/
  263. void CDiagnostics::ClearQuery()
  264. {
  265. m_pszwCatagory = NULL;
  266. m_bFlags = NULL;
  267. m_pszwParam1 = NULL;
  268. m_pszwParam2 = NULL;
  269. }
  270. /*++
  271. Routine Description
  272. Execute the query
  273. Arguments
  274. Return Value
  275. void
  276. --*/
  277. BOOLEAN CDiagnostics::ExecQuery(WCHAR *pszwCatagory, BOOL bFlags, WCHAR *pszwParam1, WCHAR *pszwParam2)
  278. {
  279. WCHAR *pszw;
  280. BOOL bAll = FALSE;
  281. SetQuery(pszwCatagory,bFlags,pszwParam1,pszwParam2);
  282. m_WmiGateway.SetCancelOption(m_hTerminateThread);
  283. m_bTerminate = FALSE;
  284. m_lWorkDone = 0;
  285. m_lTotalWork = 0;
  286. m_bstrCaption = L"";
  287. if( m_pszwParam1 && !wcsstr(m_pszwParam1,L"*") )
  288. {
  289. if( m_bFlags & FLAG_VERBOSE_LOW )
  290. {
  291. m_bFlags &= ~FLAG_VERBOSE_LOW;
  292. m_bFlags |= FLAG_VERBOSE_MEDIUM;
  293. }
  294. }
  295. if( !m_pszwCatagory )
  296. {
  297. ClearQuery();
  298. return FALSE;
  299. }
  300. ReportStatus(ids(IDS_COLLECTINGINFO_STATUS),3);
  301. if( wcsstr(m_pszwCatagory,L"test") )
  302. {
  303. if( (m_bFlags & FLAG_VERBOSE_LOW) )
  304. {
  305. m_bFlags &= ~FLAG_CMD_SHOW;
  306. }
  307. else
  308. {
  309. m_bFlags |= FLAG_CMD_SHOW;
  310. }
  311. if( m_bFlags & FLAG_VERBOSE_LOW )
  312. {
  313. m_bFlags &= ~FLAG_VERBOSE_LOW;
  314. m_bFlags |= FLAG_VERBOSE_MEDIUM;
  315. }
  316. m_bFlags |= FLAG_CMD_PING | FLAG_CMD_CONNECT;
  317. bAll = TRUE;
  318. }
  319. if( wcsstr(m_pszwCatagory,L"all") )
  320. {
  321. bAll = TRUE;
  322. }
  323. pszw = new WCHAR[lstrlen(m_pszwCatagory) + 3];
  324. if( !pszw )
  325. {
  326. ClearQuery();
  327. return FALSE;
  328. }
  329. wsprintf(pszw,L";%s;",m_pszwCatagory);
  330. ToLowerStr(pszw);
  331. m_nCatagoriesRequested = wcscount(pszw,L';') - 1;
  332. XMLNetdiag(TRUE);
  333. NetShNetdiag(TRUE);
  334. if( ShouldTerminate() ) goto End;
  335. if( wcsstr(pszw,L";iphost;") )
  336. {
  337. ExecIPHost(m_pszwParam1,m_pszwParam2);
  338. }
  339. if( ShouldTerminate() ) goto End;
  340. if( bAll || wcsstr(pszw,L";mail;") )
  341. {
  342. ExecMailQuery();
  343. }
  344. if( ShouldTerminate() ) goto End;
  345. if( bAll || wcsstr(pszw,L";news;") )
  346. {
  347. ExecNewsQuery();
  348. }
  349. if( ShouldTerminate() ) goto End;
  350. if( bAll || wcsstr(pszw,L";ieproxy;") )
  351. {
  352. ExecProxyQuery();
  353. }
  354. if( ShouldTerminate() ) goto End;
  355. if( bAll || wcsstr(pszw,L";loopback;") )
  356. {
  357. ExecLoopbackQuery();
  358. }
  359. if( ShouldTerminate() ) goto End;
  360. if( bAll || wcsstr(pszw,L";computer;") )
  361. {
  362. ExecComputerQuery();
  363. }
  364. if( ShouldTerminate() ) goto End;
  365. if( bAll || wcsstr(pszw,L";os;") )
  366. {
  367. ExecOSQuery();
  368. }
  369. if( ShouldTerminate() ) goto End;
  370. if( bAll || wcsstr(pszw,L";version;") )
  371. {
  372. ExecVersionQuery();
  373. }
  374. if( ShouldTerminate() ) goto End;
  375. if( bAll || wcsstr(pszw,L";modem;") )
  376. {
  377. ExecModemQuery(m_pszwParam1);
  378. }
  379. if( ShouldTerminate() ) goto End;
  380. if( bAll || wcsstr(pszw,L";adapter;") )
  381. {
  382. ExecAdapterQuery(m_pszwParam1);
  383. }
  384. {
  385. BOOL bFlagSave = m_bFlags;
  386. m_bFlags &= ~FLAG_VERBOSE_LOW;
  387. m_bFlags &= ~FLAG_VERBOSE_HIGH;
  388. m_bFlags |= FLAG_VERBOSE_MEDIUM;
  389. if( ShouldTerminate() ) goto End;
  390. if( wcsstr(pszw,L";dns;") )
  391. {
  392. ExecDNSQuery(m_pszwParam1);
  393. }
  394. if( ShouldTerminate() ) goto End;
  395. if( wcsstr(pszw,L";gateway;") )
  396. {
  397. ExecGatewayQuery(m_pszwParam1);
  398. }
  399. if( ShouldTerminate() ) goto End;
  400. if( wcsstr(pszw,L";dhcp;") )
  401. {
  402. ExecDhcpQuery(m_pszwParam1);
  403. }
  404. if( ShouldTerminate() ) goto End;
  405. if( wcsstr(pszw,L";ip;") )
  406. {
  407. ExecIPQuery(m_pszwParam1);
  408. }
  409. if( ShouldTerminate() ) goto End;
  410. if( wcsstr(pszw,L";wins;") )
  411. {
  412. ExecWinsQuery(m_pszwParam1);
  413. }
  414. m_bFlags = bFlagSave;
  415. }
  416. if( ShouldTerminate() ) goto End;
  417. if( bAll || wcsstr(pszw,L";client;") )
  418. {
  419. ExecClientQuery(m_pszwParam1);
  420. }
  421. End:
  422. delete pszw;
  423. if( ShouldTerminate() ) return FALSE;
  424. XMLNetdiag(FALSE);
  425. NetShNetdiag(FALSE);
  426. Sleep(50);
  427. ReportStatus(m_wstrXML.c_str(),-1);
  428. ClearQuery();
  429. return TRUE;
  430. }
  431. wstring &CDiagnostics::Escape(LPCTSTR pszw)
  432. {
  433. m_wstrEscapeXml = L"";
  434. if( !pszw )
  435. {
  436. return m_wstrEscapeXml;
  437. }
  438. for(int i=0; pszw[i]!=L'\0'; i++)
  439. {
  440. switch(pszw[i])
  441. {
  442. case L'&':
  443. m_wstrEscapeXml += L"&amp;";
  444. break;
  445. case L'\'':
  446. m_wstrEscapeXml += L"&apos;";
  447. break;
  448. case L'\"':
  449. m_wstrEscapeXml += L"&quot;";
  450. break;
  451. case L'<':
  452. m_wstrEscapeXml += L"&lt;";
  453. break;
  454. case L'>':
  455. m_wstrEscapeXml += L"&gt;";
  456. break;
  457. default:
  458. m_wstrEscapeXml += pszw[i];
  459. }
  460. }
  461. return m_wstrEscapeXml;
  462. }
  463. void CDiagnostics::XMLNetdiag(BOOLEAN bStartTag, LPCTSTR pszwValue)
  464. {
  465. if( m_bInterface == COM_INTERFACE )
  466. {
  467. if( bStartTag )
  468. {
  469. m_wstrXML = wstring(L"<Netdiag Name = \"Network Diagnostics\">\n");
  470. }
  471. else
  472. {
  473. m_wstrXML += wstring(L"<Status Value = \"") + Escape(pszwValue) + wstring(L"\"> </Status>\n");
  474. m_wstrXML += wstring(L"</Netdiag>\n");
  475. }
  476. }
  477. }
  478. void CDiagnostics::XMLHeader(BOOLEAN bStartTag, WCHAR *pszwHeader, WCHAR *pszwCaption, WCHAR *pszwCategory)
  479. {
  480. if( m_bInterface == COM_INTERFACE )
  481. {
  482. if( bStartTag )
  483. {
  484. m_wstrXML += wstring(L"<Container Name = \"") + Escape(pszwHeader) + wstring(L"\" ");
  485. m_wstrXML += wstring(L"Category = \"") + Escape(pszwCategory) + wstring(L"\" ");
  486. m_wstrXML += wstring(L"Caption = \"") + Escape(pszwCaption) + wstring(L"\">\n");
  487. }
  488. else
  489. {
  490. m_wstrXML += wstring(L"<Status Value = \"") + Escape(pszwHeader) + wstring(L"\"> </Status>\n");
  491. m_wstrXML += wstring(L"</Container>");
  492. }
  493. }
  494. }
  495. void CDiagnostics::XMLCaption(BOOLEAN bStartTag, WCHAR *pszwCaption)
  496. {
  497. if( m_bInterface == COM_INTERFACE )
  498. {
  499. if( bStartTag )
  500. {
  501. pszwCaption = (m_nInstance == 1)?NULL:pszwCaption;
  502. if( m_bCaptionDisplayed == FALSE )
  503. {
  504. m_wstrXML += wstring(L"<ClassObjectEnum Name = \"") + Escape(pszwCaption) + wstring(L"\">\n");
  505. m_bCaptionDisplayed = TRUE;
  506. m_IsPropertyListDisplayed = TRUE;
  507. }
  508. }
  509. else
  510. {
  511. if( m_IsPropertyListDisplayed )
  512. {
  513. m_wstrXML += wstring(L"<Status Value = \"") + Escape(pszwCaption) + wstring(L"\"> </Status>\n");
  514. m_wstrXML += wstring(L"</ClassObjectEnum>\n");
  515. }
  516. m_IsPropertyListDisplayed = FALSE;
  517. //m_bCaptionDisplayed = FALSE;
  518. }
  519. }
  520. }
  521. void CDiagnostics::XMLField(BOOLEAN bStartTag, WCHAR *pszwField)
  522. {
  523. if( m_bInterface == COM_INTERFACE )
  524. {
  525. if( bStartTag )
  526. {
  527. m_wstrXML += wstring(L"<Property Name = \"") + Escape(pszwField) + wstring(L"\">\n");
  528. }
  529. else
  530. {
  531. m_wstrXML += wstring(L"<Status Value = \"") + Escape(pszwField) + wstring(L"\"> </Status>\n");
  532. m_wstrXML += wstring(L"</Property>\n");
  533. }
  534. }
  535. }
  536. void CDiagnostics::XMLProperty(BOOLEAN bStartTag, WCHAR *pszwProperty, LPCTSTR pszwData, LPCTSTR pszwComment)
  537. {
  538. if( m_bInterface == COM_INTERFACE )
  539. {
  540. if( bStartTag )
  541. {
  542. m_wstrXML += wstring(L"<PropertyValue ");
  543. m_wstrXML += wstring(L"Value = \"") + Escape(pszwProperty) + wstring(L"\" ");
  544. m_wstrXML += wstring(L"Data = \"") + Escape(pszwData) + wstring(L"\" ");
  545. m_wstrXML += wstring(L"Comment = \"") + Escape(pszwComment) + wstring(L"\" ");
  546. m_wstrXML += wstring(L">\n");
  547. }
  548. else
  549. {
  550. m_wstrXML += Escape(pszwProperty);
  551. m_wstrXML += wstring(L"</PropertyValue>\n");
  552. //m_bCaptionDisplayed = FALSE;
  553. }
  554. }
  555. }
  556. BOOLEAN CDiagnostics::Filter(_variant_t &vValue, BOOLEAN bFlags)
  557. {
  558. BOOLEAN retVal;
  559. BOOLEAN bShow = (m_bFlags & FLAG_CMD_SHOW);
  560. BOOLEAN bPing = (m_bFlags & FLAG_CMD_PING) && (bFlags & TYPE_PING);
  561. BOOLEAN bConnect = (m_bFlags & FLAG_CMD_CONNECT) && (bFlags & TYPE_CONNECT);
  562. if( m_bFlags & FLAG_VERBOSE_LOW )
  563. {
  564. return FALSE;
  565. }
  566. if( bFlags & TYPE_HIDE )
  567. {
  568. return FALSE;
  569. }
  570. if( (m_bFlags & FLAG_VERBOSE_HIGH)==0 && (retVal = IsVariantEmpty(vValue)) )
  571. {
  572. return FALSE;
  573. }
  574. if( (bFlags & TYPE_IP) && !m_bAdaterHasIPAddress )
  575. {
  576. return FALSE;
  577. }
  578. if( !bShow )
  579. {
  580. if( bPing || bConnect)
  581. {
  582. return TRUE;
  583. }
  584. return FALSE;
  585. }
  586. return TRUE;
  587. }
  588. template<class t>
  589. _variant_t *Get(list<t> &l, WCHAR *pszwName, DWORD nInstance)
  590. {
  591. list<t>::iterator iter;
  592. if( l.empty() )
  593. {
  594. return NULL;
  595. }
  596. for( iter = l.begin(); iter != l.end(); iter++)
  597. {
  598. if( lstrcmp(iter->pszwName,pszwName) == 0 )
  599. {
  600. if( nInstance < iter->Value.size() )
  601. {
  602. return &iter->Value[nInstance];
  603. }
  604. else
  605. {
  606. return NULL;
  607. }
  608. }
  609. }
  610. return NULL;
  611. }
  612. template<class t>
  613. BOOLEAN RemoveInstance(list<t> &l, DWORD nInstance)
  614. {
  615. list<t>::iterator iter;
  616. //vector<t>::iterator iterVector;
  617. // DWORD i=0;
  618. for( iter = l.begin(); iter != l.end(); iter++)
  619. {
  620. //iterVector = iter
  621. iter->Value.erase(iter->Value.begin() + nInstance);
  622. /* if( nInstance == i )
  623. {
  624. l.erase(iter);
  625. return TRUE;
  626. }
  627. i++;
  628. */
  629. }
  630. return FALSE;
  631. }
  632. template<class t>
  633. void Set(list<t> &l, WCHAR *pszwName, BOOLEAN bFlags, _variant_t &vValue)
  634. {
  635. list<t>::iterator iter;
  636. for( iter = l.begin(); iter != l.end(); iter++)
  637. {
  638. if( lstrcmp(iter->pszwName,pszwName) == 0 )
  639. {
  640. iter->Value.push_back(vValue);
  641. return;
  642. }
  643. }
  644. l.push_back(Property(pszwName,bFlags));
  645. iter = l.end();
  646. iter--;
  647. iter->Value.push_back(vValue);
  648. return;
  649. }
  650. BOOLEAN CDiagnostics::FormatPing(WCHAR * pszwText)
  651. {
  652. if( m_bInterface == NETSH_INTERFACE )
  653. {
  654. if( pszwText )
  655. {
  656. LONG nIndent = m_IsNetdiagDisplayed + m_IsContainerDisplayed + m_IsPropertyListDisplayed + m_IsPropertyDisplayed + m_IsValueDisplayed;
  657. DisplayMessageT(L"%1!s!%2!s!\n",Indent(nIndent),pszwText);
  658. return TRUE;
  659. }
  660. }
  661. if( m_bInterface == COM_INTERFACE )
  662. {
  663. if( !pszwText )
  664. {
  665. m_wstrPing.erase(m_wstrPing.begin(),m_wstrPing.end());
  666. }
  667. else if( m_wstrPing.empty() )
  668. {
  669. m_wstrPing = pszwText;
  670. }
  671. else
  672. {
  673. m_wstrPing += wstring(L"|") + pszwText;
  674. }
  675. return TRUE;
  676. }
  677. return FALSE;
  678. }
  679. BOOLEAN CDiagnostics::ExecClientQuery(WCHAR *pszwInstance)
  680. {
  681. if( !(m_bFlags & FLAG_CMD_SHOW) )
  682. {
  683. return FALSE;
  684. }
  685. EnumWbemProperty PropList;
  686. m_pszwCaption = TXT_CLIENT_CAPTION;
  687. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_NETWORKADAPTERS));
  688. lstrcpy(m_szwHeader,ids(IDS_CLIENT_HEADER));
  689. PropList.push_back(WbemProperty(NULL,0,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_CLIENT));
  690. m_WmiGateway.GetWbemProperties(PropList);
  691. FormatEnum(PropList,pszwInstance);
  692. return TRUE;
  693. }
  694. BOOLEAN CDiagnostics::ExecModemQuery(WCHAR *pszwInstance)
  695. {
  696. EnumWbemProperty PropList;
  697. m_pszwCaption = TXT_MODEM_CAPTION;
  698. lstrcpy(m_szwHeader,ids(IDS_MODEM_HEADER));
  699. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_MODEM));
  700. PropList.push_back(WbemProperty(NULL,0,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_MODEM));
  701. m_WmiGateway.GetWbemProperties(PropList);
  702. FormatEnum(PropList,pszwInstance);
  703. return TRUE;
  704. }
  705. BOOLEAN CDiagnostics::RemoveInvalidAdapters(EnumWbemProperty & PropList)
  706. {
  707. DWORD i = 0;
  708. _variant_t *pvIPEnabled;
  709. do
  710. {
  711. pvIPEnabled = Get(PropList,L"IPEnabled",i);
  712. if( pvIPEnabled )
  713. {
  714. if( pvIPEnabled->vt == VT_BOOL && pvIPEnabled->boolVal!=-1 )
  715. {
  716. RemoveInstance(PropList,i);
  717. }
  718. else
  719. {
  720. i++;
  721. }
  722. }
  723. }
  724. while(pvIPEnabled);
  725. return TRUE;
  726. }
  727. BOOLEAN CDiagnostics::ExecAdapterQuery(WCHAR *pszwInstance)
  728. {
  729. EnumWbemProperty PropList;
  730. EnumWbemProperty::iterator iter;
  731. m_pszwCaption = TXT_ADAPTER_CAPTION;
  732. lstrcpy(m_szwHeader,ids(IDS_ADAPTER_HEADER));
  733. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_NETWORKADAPTERS));
  734. PropList.push_back(WbemProperty(NULL,0,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  735. m_WmiGateway.GetWbemProperties(PropList);
  736. for(iter = PropList.begin(); iter != PropList.end(); iter++)
  737. {
  738. if( 0 == lstrcmp(iter->pszwName, L"DNSServerSearchOrder") ||
  739. 0 == lstrcmp(iter->pszwName, L"IPAddress") ||
  740. 0 == lstrcmp(iter->pszwName, L"WINSPrimaryServer") ||
  741. 0 == lstrcmp(iter->pszwName, L"WINSSecondaryServer") ||
  742. 0 == lstrcmp(iter->pszwName, L"DHCPServer") )
  743. {
  744. iter->bFlags = TYPE_PING | TYPE_IP;
  745. }
  746. if( 0 == lstrcmp(iter->pszwName, L"DefaultIPGateway") )
  747. {
  748. iter->bFlags = TYPE_PING | TYPE_SUBNET | TYPE_IP;
  749. }
  750. }
  751. if( !(m_bFlags & FLAG_VERBOSE_HIGH) )
  752. {
  753. RemoveInvalidAdapters(PropList);
  754. /*
  755. DWORD i = 0;
  756. _variant_t *pvIPEnabled;
  757. do
  758. {
  759. pvIPEnabled = Get(PropList,L"IPEnabled",i);
  760. if( pvIPEnabled )
  761. {
  762. if( pvIPEnabled->vt == VT_BOOL && pvIPEnabled->boolVal!=-1 )
  763. {
  764. RemoveInstance(PropList,i);
  765. }
  766. else
  767. {
  768. i++;
  769. }
  770. }
  771. }
  772. while(pvIPEnabled);
  773. */
  774. }
  775. FormatEnum(PropList,pszwInstance);
  776. return TRUE;
  777. }
  778. BOOLEAN CDiagnostics::ExecDNSQuery(WCHAR *pszwInstance)
  779. {
  780. EnumWbemProperty PropList;
  781. m_pszwCaption = TXT_ADAPTER_CAPTION;
  782. lstrcpy(m_szwHeader,ids(IDS_DNS_HEADER));
  783. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_NETWORKADAPTERS));
  784. PropList.push_back(WbemProperty(L"DNSServerSearchOrder",TYPE_PING | TYPE_IP ,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  785. PropList.push_back(WbemProperty(m_pszwCaption,TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  786. PropList.push_back(WbemProperty(L"IPAddress",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  787. PropList.push_back(WbemProperty(L"IPEnabled",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  788. m_WmiGateway.GetWbemProperties(PropList);
  789. if( !(m_bFlags & FLAG_VERBOSE_HIGH) )
  790. {
  791. RemoveInvalidAdapters(PropList);
  792. }
  793. FormatEnum(PropList,pszwInstance);
  794. return TRUE;
  795. }
  796. BOOLEAN CDiagnostics::ExecIPQuery(WCHAR *pszwInstance)
  797. {
  798. EnumWbemProperty PropList;
  799. m_pszwCaption = TXT_ADAPTER_CAPTION;
  800. lstrcpy(m_szwHeader,ids(IDS_IP_HEADER));
  801. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_NETWORKADAPTERS));
  802. PropList.push_back(WbemProperty(L"IPAddress",TYPE_PING | TYPE_IP,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  803. PropList.push_back(WbemProperty(m_pszwCaption,TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  804. PropList.push_back(WbemProperty(L"IPAddress",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  805. PropList.push_back(WbemProperty(L"IPEnabled",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  806. m_WmiGateway.GetWbemProperties(PropList);
  807. if( !(m_bFlags & FLAG_VERBOSE_HIGH) )
  808. {
  809. RemoveInvalidAdapters(PropList);
  810. }
  811. FormatEnum(PropList,pszwInstance);
  812. return TRUE;
  813. }
  814. BOOLEAN CDiagnostics::ExecWinsQuery(WCHAR *pszwInstance)
  815. {
  816. EnumWbemProperty PropList;
  817. m_pszwCaption = TXT_ADAPTER_CAPTION;
  818. lstrcpy(m_szwHeader,ids(IDS_WINS_HEADER));
  819. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_NETWORKADAPTERS));
  820. PropList.push_back(WbemProperty(L"WINSPrimaryServer",TYPE_PING | TYPE_IP,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  821. PropList.push_back(WbemProperty(L"WINSSecondaryServer",TYPE_PING | TYPE_IP,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  822. PropList.push_back(WbemProperty(m_pszwCaption,TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  823. PropList.push_back(WbemProperty(L"IPAddress",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  824. PropList.push_back(WbemProperty(L"IPEnabled",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  825. m_WmiGateway.GetWbemProperties(PropList);
  826. if( !(m_bFlags & FLAG_VERBOSE_HIGH) )
  827. {
  828. RemoveInvalidAdapters(PropList);
  829. }
  830. FormatEnum(PropList,pszwInstance);
  831. return TRUE;
  832. }
  833. BOOLEAN CDiagnostics::ExecGatewayQuery(WCHAR *pszwInstance)
  834. {
  835. EnumWbemProperty PropList;
  836. m_pszwCaption = TXT_ADAPTER_CAPTION;
  837. lstrcpy(m_szwHeader,ids(IDS_GATEWAY_HEADER));
  838. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_NETWORKADAPTERS));
  839. PropList.push_back(WbemProperty(L"DefaultIPGateway",TYPE_PING | TYPE_IP | TYPE_SUBNET,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  840. PropList.push_back(WbemProperty(L"IPAddress",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  841. PropList.push_back(WbemProperty(L"IPSubnet",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  842. PropList.push_back(WbemProperty(m_pszwCaption,TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  843. PropList.push_back(WbemProperty(L"IPEnabled",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  844. m_WmiGateway.GetWbemProperties(PropList);
  845. if( !(m_bFlags & FLAG_VERBOSE_HIGH) )
  846. {
  847. RemoveInvalidAdapters(PropList);
  848. }
  849. FormatEnum(PropList,pszwInstance);
  850. return TRUE;
  851. }
  852. BOOLEAN CDiagnostics::ExecDhcpQuery(WCHAR *pszwInstance)
  853. {
  854. EnumWbemProperty PropList;
  855. m_pszwCaption = TXT_ADAPTER_CAPTION;
  856. lstrcpy(m_szwHeader,ids(IDS_DHCP_HEADER));
  857. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_NETWORKADAPTERS));
  858. PropList.push_back(WbemProperty(L"DHCPServer",TYPE_PING | TYPE_IP,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  859. PropList.push_back(WbemProperty(m_pszwCaption,TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  860. PropList.push_back(WbemProperty(L"IPAddress",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETWORK));
  861. m_WmiGateway.GetWbemProperties(PropList);
  862. if( !(m_bFlags & FLAG_VERBOSE_HIGH) )
  863. {
  864. RemoveInvalidAdapters(PropList);
  865. }
  866. FormatEnum(PropList,pszwInstance);
  867. return TRUE;
  868. }
  869. BOOLEAN CDiagnostics::ExecComputerQuery()
  870. {
  871. if( !(m_bFlags & FLAG_CMD_SHOW) )
  872. {
  873. return FALSE;
  874. }
  875. EnumWbemProperty PropList;
  876. m_pszwCaption = TXT_COMPUTER_CAPTION;
  877. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_SYSTEMINFO));
  878. lstrcpy(m_szwHeader,ids(IDS_COMPUTER_HEADER));
  879. PropList.push_back(WbemProperty(NULL,0,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_COMPUTER));
  880. m_WmiGateway.GetWbemProperties(PropList);
  881. FormatEnum(PropList);
  882. return TRUE;
  883. }
  884. BOOLEAN CDiagnostics::ExecOSQuery()
  885. {
  886. if( !(m_bFlags & FLAG_CMD_SHOW) )
  887. {
  888. return FALSE;
  889. }
  890. EnumWbemProperty PropList;
  891. m_pszwCaption = TXT_OS_CAPTION;
  892. lstrcpy(m_szwHeader,ids(IDS_OS_HEADER));
  893. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_SYSTEMINFO));
  894. PropList.push_back(WbemProperty(NULL,0,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_OS));
  895. m_WmiGateway.GetWbemProperties(PropList);
  896. FormatEnum(PropList);
  897. return TRUE;
  898. }
  899. BOOLEAN CDiagnostics::ExecVersionQuery()
  900. {
  901. if( !(m_bFlags & FLAG_CMD_SHOW) )
  902. {
  903. return FALSE;
  904. }
  905. EnumWbemProperty PropList;
  906. m_pszwCaption = TXT_VERSION_CAPTION;
  907. lstrcpy(m_szwHeader,ids(IDS_VERSION_HEADER));
  908. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_SYSTEMINFO));
  909. PropList.push_back(WbemProperty(L"Version",0,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_OS));
  910. PropList.push_back(WbemProperty(L"BuildVersion",0,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_WMI));
  911. m_WmiGateway.GetWbemProperties(PropList);
  912. FormatEnum(PropList);
  913. return TRUE;
  914. }
  915. LPWSTR GetMailType(DWORD dwType)
  916. {
  917. switch(dwType)
  918. {
  919. case MAIL_SMTP:
  920. return ids(IDS_SMTP);
  921. case MAIL_SMTP2:
  922. return ids(IDS_SMTP);
  923. case MAIL_POP3:
  924. return ids(IDS_POP3);
  925. case MAIL_IMAP:
  926. return ids(IDS_IMAP);
  927. case MAIL_HTTP:
  928. return ids(IDS_HTTP);
  929. default:
  930. return ids(IDS_UNKNOWN);
  931. }
  932. }
  933. BOOLEAN CDiagnostics::ExecNewsQuery()
  934. {
  935. HRESULT hr;
  936. INETSERVER rNewsServer;
  937. EnumProperty PropList;
  938. BOOLEAN bConnect = 2;
  939. m_pszwCaption = TXT_NEWS_CAPTION;
  940. lstrcpy(m_szwHeader,ids(IDS_NEWS_HEADER));
  941. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_INTERNET));
  942. hr = GetOEDefaultNewsServer2(rNewsServer);
  943. if( SUCCEEDED(hr) )
  944. {
  945. if( strcmp(rNewsServer.szServerName,"") != 0 )
  946. {
  947. Property Prop;
  948. m_bstrCaption = rNewsServer.szServerName;
  949. Prop.Clear();
  950. Prop.SetProperty(L"NewsNNTPPort",TYPE_CONNECT);
  951. Prop.Value.push_back(_variant_t((LONG)rNewsServer.dwPort));
  952. PropList.push_back(Prop);
  953. Prop.Clear();
  954. Prop.SetProperty(L"NewsServer",TYPE_PING | TYPE_CONNECT);
  955. Prop.Value.push_back(_variant_t(rNewsServer.szServerName));
  956. PropList.push_back(Prop);
  957. if( (m_bFlags & FLAG_CMD_CONNECT) )
  958. {
  959. _bstr_t bstrServer = rNewsServer.szServerName;
  960. WCHAR wszConnect[MAX_PATH*10];
  961. if( Connect((LPWSTR)bstrServer,rNewsServer.dwPort) )
  962. {
  963. //L"Successfully connected to %hs port %d"
  964. swprintf(wszConnect,ids(IDS_CONNECTEDTOSERVERSUCCESS),rNewsServer.szServerName,rNewsServer.dwPort);
  965. bConnect = TRUE;
  966. }
  967. else
  968. {
  969. //"Unable to connect to %hs port %d"
  970. wsprintf(wszConnect,ids(IDS_CONNECTEDTOSERVERFAILED),rNewsServer.szServerName,rNewsServer.dwPort);
  971. bConnect = FALSE;
  972. }
  973. PropList.push_back(Property(wszConnect,TYPE_TEXT | TYPE_CONNECT));
  974. }
  975. }
  976. }
  977. else
  978. {
  979. m_bstrCaption = ids(IDS_NOTCONFIGURED);
  980. PropList.push_back(Property((WCHAR*)m_bstrCaption,TYPE_TEXT));
  981. }
  982. FormatEnum(PropList, NULL, bConnect);
  983. m_bstrCaption = L"";
  984. return TRUE;
  985. }
  986. BOOLEAN CDiagnostics::ExecMailQuery()
  987. {
  988. EnumProperty PropList;
  989. INETSERVER rInBoundMailServer;
  990. INETSERVER rOutBoundMailServer;
  991. DWORD dwInBoundMailType;
  992. DWORD dwOutBoundMailType;
  993. HRESULT hr;
  994. WCHAR szw[1000];
  995. BOOLEAN bConnect = 2;
  996. BOOLEAN bMailConfigured = FALSE;
  997. // Set the caption, header and category information (describes this object)
  998. //
  999. m_pszwCaption = TXT_MAIL_CAPTION;
  1000. lstrcpy(m_szwHeader,ids(IDS_MAIL_HEADER));
  1001. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_INTERNET));
  1002. hr = GetOEDefaultMailServer2(rInBoundMailServer,
  1003. dwInBoundMailType,
  1004. rOutBoundMailServer,
  1005. dwOutBoundMailType);
  1006. if( SUCCEEDED(hr) )
  1007. {
  1008. if( strcmp(rInBoundMailServer.szServerName,"") != 0 )
  1009. {
  1010. Property Prop;
  1011. _variant_t varValue;
  1012. m_bstrCaption = rInBoundMailServer.szServerName;
  1013. Prop.Clear();
  1014. Prop.SetProperty(L"InBoundMailPort",TYPE_CONNECT);
  1015. Prop.Value.push_back(_variant_t((LONG)rInBoundMailServer.dwPort));
  1016. PropList.push_back(Prop);
  1017. Prop.Clear();
  1018. Prop.SetProperty(L"InBoundMailServer",TYPE_CONNECT | (dwInBoundMailType!=MAIL_HTTP ? TYPE_PING : 0));
  1019. Prop.Value.push_back(_variant_t(rInBoundMailServer.szServerName));
  1020. PropList.push_back(Prop);
  1021. Prop.Clear();
  1022. Prop.SetProperty(L"InBoundMailType",0);
  1023. Prop.Value.push_back(_variant_t(GetMailType(dwInBoundMailType)));
  1024. PropList.push_back(Prop);
  1025. if( (m_bFlags & FLAG_CMD_CONNECT) && dwInBoundMailType != MAIL_HTTP)
  1026. {
  1027. _bstr_t bstrServer = rInBoundMailServer.szServerName;
  1028. WCHAR wszConnect[MAX_PATH*10];
  1029. if( Connect((LPWSTR)bstrServer,rInBoundMailServer.dwPort) )
  1030. {
  1031. swprintf(wszConnect,ids(IDS_CONNECTEDTOSERVERSUCCESS),rInBoundMailServer.szServerName,rInBoundMailServer.dwPort);
  1032. bConnect = TRUE;
  1033. }
  1034. else
  1035. {
  1036. wsprintf(wszConnect,ids(IDS_CONNECTEDTOSERVERFAILED),rInBoundMailServer.szServerName,rInBoundMailServer.dwPort);
  1037. bConnect = FALSE;
  1038. }
  1039. PropList.push_back(Property(wszConnect,TYPE_TEXT | TYPE_CONNECT));
  1040. }
  1041. bMailConfigured = TRUE;
  1042. }
  1043. if( strcmp(rOutBoundMailServer.szServerName,"") != 0 )
  1044. {
  1045. Property Prop;
  1046. _variant_t varValue;
  1047. if( bMailConfigured )
  1048. {
  1049. m_bstrCaption += L" / ";
  1050. }
  1051. m_bstrCaption += rOutBoundMailServer.szServerName;
  1052. Prop.Clear();
  1053. Prop.SetProperty(L"OutBoundMailPort",TYPE_CONNECT);
  1054. Prop.Value.push_back(_variant_t((LONG)rOutBoundMailServer.dwPort));
  1055. PropList.push_back(Prop);
  1056. Prop.Clear();
  1057. Prop.SetProperty(L"OutBoundMailServer",TYPE_PING | TYPE_CONNECT);
  1058. Prop.Value.push_back(_variant_t(rOutBoundMailServer.szServerName));
  1059. PropList.push_back(Prop);
  1060. Prop.Clear();
  1061. Prop.SetProperty(L"OutBoundMailType",0);
  1062. Prop.Value.push_back(_variant_t(GetMailType(dwOutBoundMailType)));
  1063. PropList.push_back(Prop);
  1064. if( (m_bFlags & FLAG_CMD_CONNECT) && dwOutBoundMailType != MAIL_HTTP)
  1065. {
  1066. _bstr_t bstrServer = rOutBoundMailServer.szServerName;
  1067. WCHAR wszConnect[MAX_PATH*10];
  1068. if( Connect((LPWSTR)bstrServer,rOutBoundMailServer.dwPort) )
  1069. {
  1070. swprintf(wszConnect,ids(IDS_CONNECTEDTOSERVERSUCCESS),rOutBoundMailServer.szServerName,rOutBoundMailServer.dwPort);
  1071. bConnect = TRUE;
  1072. }
  1073. else
  1074. {
  1075. wsprintf(wszConnect,ids(IDS_CONNECTEDTOSERVERFAILED),rOutBoundMailServer.szServerName,rOutBoundMailServer.dwPort);
  1076. bConnect = FALSE;
  1077. }
  1078. PropList.push_back(Property(wszConnect,TYPE_TEXT | TYPE_CONNECT));
  1079. }
  1080. bMailConfigured = TRUE;
  1081. }
  1082. if( !bMailConfigured )
  1083. {
  1084. m_bstrCaption = ids(IDS_NOTCONFIGURED);
  1085. PropList.push_back(Property((WCHAR*)m_bstrCaption,TYPE_TEXT));
  1086. }
  1087. }
  1088. else
  1089. {
  1090. m_bstrCaption = ids(IDS_NOTCONFIGURED);
  1091. PropList.push_back(Property((WCHAR*)m_bstrCaption,TYPE_TEXT));
  1092. }
  1093. FormatEnum(PropList, NULL, bConnect);
  1094. m_bstrCaption = L"";
  1095. return TRUE;
  1096. }
  1097. /*
  1098. BOOLEAN CDiagnostics::ExecMailQuery()
  1099. {
  1100. EnumWbemProperty PropList;
  1101. _variant_t *pvPort, *pvServer, *pvType;
  1102. WCHAR szw[MAX_PATH];
  1103. BOOL bFlag;
  1104. BOOLEAN bConnectPass = 2;
  1105. ULONG ulFail = 0;
  1106. HRESULT hr;
  1107. INETSERVER rInBoundMailServer;
  1108. INETSERVER rOutBoundMailServer;
  1109. DWORD dwInBoundMailType;
  1110. DWORD dwOutBoundMailType;
  1111. WCHAR wsz[1000];
  1112. hr = GetOEDefaultMailServer2(rInBoundMailServer,
  1113. dwInBoundMailType,
  1114. rOutBoundMailServer,
  1115. dwOutBoundMailType);
  1116. if( SUCCEEDED(hr) )
  1117. {
  1118. wsprintf(wsz,L"Inbound Mail Server %hs Port %d Type %d\nOutbound Mail Server %hs Port %d Type %d\n",
  1119. rInBoundMailServer.szServerName,rInBoundMailServer.dwPort,dwInBoundMailType,
  1120. rOutBoundMailServer.szServerName,rOutBoundMailServer.dwPort,dwOutBoundMailType);
  1121. OutputDebugString(wsz);
  1122. }
  1123. else
  1124. {
  1125. wsprintf(wsz,L"Unable to get Mail server %X\n",hr);
  1126. OutputDebugString(wsz);
  1127. }
  1128. m_pszwCaption = TXT_MAIL_CAPTION;
  1129. lstrcpy(m_szwHeader,ids(IDS_MAIL_HEADER));
  1130. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_INTERNET));
  1131. PropList.push_back(WbemProperty(L"InBoundMailPort",TYPE_CONNECT,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1132. PropList.push_back(WbemProperty(L"InBoundMailServer",TYPE_PING | TYPE_CONNECT,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1133. PropList.push_back(WbemProperty(L"InBoundMailType",0,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1134. PropList.push_back(WbemProperty(L"OutBoundMailPort",TYPE_CONNECT,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1135. PropList.push_back(WbemProperty(L"OutBoundMailServer",TYPE_PING | TYPE_CONNECT,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1136. PropList.push_back(WbemProperty(L"OutBoundMailType",0,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1137. int i;
  1138. //TryAgain:
  1139. m_WmiGateway.GetWbemProperties(PropList);
  1140. i = 0;
  1141. for(i=0; i<2; i++)
  1142. {
  1143. switch(i)
  1144. {
  1145. case 0:
  1146. pvServer = Get(PropList,L"InBoundMailServer",0);
  1147. pvPort = Get(PropList,L"InBoundMailPort",0);
  1148. pvType = Get(PropList,L"InBoundMailType",0);
  1149. break;
  1150. case 1:
  1151. pvServer = Get(PropList,L"OutBoundMailServer",0);
  1152. pvPort = Get(PropList,L"OutBoundMailPort",0);
  1153. pvType = Get(PropList,L"InBoundMailType",0);
  1154. break;
  1155. }
  1156. if( pvServer == NULL || pvPort == NULL ||
  1157. pvServer->vt != VT_BSTR ||
  1158. pvPort->vt != VT_I4 ||
  1159. lstrcmp(pvServer->bstrVal,L"") == 0)
  1160. {
  1161. //HideAll(PropList);
  1162. //lstrcpy(szw,ids(IDS_NOTCONFIGURED));
  1163. //m_pszwCaption = szw;
  1164. //PropList.push_back(WbemProperty(szw,TYPE_TEXT));
  1165. ulFail++;
  1166. //if( ulFail % 2 == 0 && ulFail < 10) goto TryAgain;
  1167. }
  1168. else
  1169. {
  1170. WCHAR *pszwType = (WCHAR *)pvType->bstrVal;
  1171. WCHAR *pszw = (WCHAR *)pvServer->bstrVal;
  1172. LONG dwPort = pvPort->lVal;
  1173. if( (lstrcmp(pszwType,L"SMTP")==0 || lstrcmp(pszwType,L"SMTP2")==0) && dwPort!=110 )
  1174. {
  1175. // Not standard SMTP port
  1176. }
  1177. if( lstrcmp(pszwType,L"POP3")==0 && dwPort!=25)
  1178. {
  1179. // Not standard POP3 port
  1180. }
  1181. if( lstrcmp(pszwType,L"IMAP")==0 && dwPort==143)
  1182. {
  1183. // Not standard IMAP port
  1184. }
  1185. if( lstrcmp(pszwType,L"HTTP")==0 && dwPort!=0)
  1186. {
  1187. // Not standard HTTP port. Should not have a port number
  1188. }
  1189. if( (m_bFlags & FLAG_CMD_CONNECT) )
  1190. {
  1191. WCHAR szwConnect[MAX_PATH];
  1192. DWORD nConnect = 0;
  1193. WCHAR szw[MAX_PATH];
  1194. WCHAR szwLastPort[MAX_PATH] = L"";
  1195. if( lstrlen(pszw) > 200 )
  1196. {
  1197. WCHAR cTmp = pszw[200];
  1198. pszw[200] = L'\0';
  1199. wsprintf(szw,L"Connecting to %s port %d",pszw,dwPort);
  1200. pszw[200] = cTmp;
  1201. }
  1202. else
  1203. {
  1204. wsprintf(szw,L"Connecting to %s port %d",pszw,dwPort);
  1205. }
  1206. ReportStatus(szw,0);
  1207. bConnectPass = TRUE;
  1208. if( Connect(pszw,dwPort) )
  1209. {
  1210. wsprintf(szwConnect,L"Successfully connected to %s port %d",pszw,dwPort);
  1211. bConnectPass = TRUE;
  1212. }
  1213. else
  1214. {
  1215. wsprintf(szwConnect,L"Unable to connect to %s port %d",pszw,dwPort);
  1216. bConnectPass = FALSE;
  1217. }
  1218. PropList.push_back(WbemProperty(szwConnect,TYPE_TEXT | TYPE_CONNECT));
  1219. }
  1220. }
  1221. }
  1222. FormatEnum(PropList, NULL, bConnectPass);
  1223. return TRUE;
  1224. }
  1225. */
  1226. /*
  1227. BOOLEAN CDiagnostics::ExecNewsQuery()
  1228. {
  1229. EnumWbemProperty PropList;
  1230. _variant_t *pvPort, *pvServer;
  1231. WCHAR szw[MAX_PATH];
  1232. BOOLEAN bConnectPass = 2;
  1233. m_pszwCaption = TXT_NEWS_CAPTION;
  1234. lstrcpy(m_szwHeader,ids(IDS_NEWS_HEADER));
  1235. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_INTERNET));
  1236. PropList.push_back(WbemProperty(L"NewsNNTPPort",TYPE_CONNECT,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1237. PropList.push_back(WbemProperty(L"NewsServer",TYPE_PING | TYPE_CONNECT,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1238. m_WmiGateway.GetWbemProperties(PropList);
  1239. pvServer = Get(PropList,L"NewsServer",0);
  1240. pvPort = Get(PropList,L"NewsNNTPPort",0);
  1241. if( !pvServer || !pvPort ||
  1242. pvServer->vt != VT_BSTR ||
  1243. pvPort->vt != VT_I4 ||
  1244. lstrcmp(pvServer->bstrVal,L"") == 0)
  1245. {
  1246. HideAll(PropList);
  1247. lstrcpy(szw,ids(IDS_NOTCONFIGURED));
  1248. m_pszwCaption = szw;
  1249. PropList.push_back(WbemProperty(szw,TYPE_TEXT));
  1250. }
  1251. else
  1252. if( (m_bFlags & FLAG_CMD_CONNECT) )
  1253. {
  1254. WCHAR szwConnect[MAX_PATH];
  1255. DWORD nConnect = 0;
  1256. WCHAR *pszw = (WCHAR *)pvServer->bstrVal;
  1257. LONG dwPort = pvPort->lVal;
  1258. WCHAR szw[MAX_PATH];
  1259. if( lstrlen(pszw) > 200 )
  1260. {
  1261. WCHAR cTmp = pszw[200];
  1262. pszw[200] = L'\0';
  1263. wsprintf(szw,L"Connecting to %s port %d",pszw,dwPort);
  1264. pszw[200] = cTmp;
  1265. }
  1266. else
  1267. {
  1268. wsprintf(szw,L"Connecting to %s port %d",pszw,dwPort);
  1269. }
  1270. ReportStatus(szw,0);
  1271. wsprintf(szwConnect,ids(IDS_SERVERCONNECTSTART));
  1272. if( Connect(pszw,dwPort) )
  1273. {
  1274. wsprintf(szwConnect,L"%s%s%d",szwConnect,nConnect?L",":L"",dwPort);
  1275. nConnect++;
  1276. }
  1277. if( !nConnect )
  1278. {
  1279. wsprintf(szwConnect,L"%s%s",szwConnect,ids(IDS_NONE));
  1280. bConnectPass = FALSE;
  1281. }
  1282. else
  1283. {
  1284. bConnectPass = TRUE;
  1285. }
  1286. wsprintf(szwConnect,L"%s%s",szwConnect,ids(IDS_SERVERCONNECTEND));
  1287. PropList.push_back(WbemProperty(szwConnect,TYPE_TEXT | TYPE_CONNECT));
  1288. }
  1289. FormatEnum(PropList,NULL,bConnectPass);
  1290. return TRUE;
  1291. }
  1292. */
  1293. BOOLEAN CDiagnostics::ExecProxyQuery()
  1294. {
  1295. EnumWbemProperty PropList;
  1296. _variant_t *pvPort, *pvServer, *pvUsed;
  1297. WCHAR szw[MAX_PATH];
  1298. BOOLEAN bConnectPass = 2;
  1299. m_pszwCaption = TXT_PROXY_CAPTION;
  1300. lstrcpy(m_szwHeader,ids(IDS_PROXY_HEADER));
  1301. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_INTERNET));
  1302. PropList.push_back(WbemProperty(L"IEProxyPort",TYPE_CONNECT,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1303. PropList.push_back(WbemProperty(L"IEProxy",TYPE_PING | TYPE_CONNECT,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1304. PropList.push_back(WbemProperty(L"bIEProxy",TYPE_HIDE,TXT_WBEM_REP_CIMV2,TXT_WBEM_NS_NETDIAG));
  1305. m_WmiGateway.GetWbemProperties(PropList);
  1306. pvServer = Get(PropList,L"IEProxy",0);
  1307. pvPort = Get(PropList,L"IEProxyPort",0);
  1308. pvUsed = Get(PropList,L"bIEProxy",0);
  1309. if( !pvServer || !pvPort || !pvUsed ||
  1310. pvServer->vt != VT_BSTR ||
  1311. pvPort->vt != VT_I4 ||
  1312. lstrcmp(pvServer->bstrVal,L"") == 0)
  1313. {
  1314. HideAll(PropList);
  1315. m_bstrCaption = ids(IDS_NOTCONFIGURED);
  1316. //PropList.push_back(Property((WCHAR*)m_bstrCaption,TYPE_TEXT));
  1317. lstrcpy(szw,ids(IDS_NOTCONFIGURED));
  1318. m_pszwCaption = szw;
  1319. //PropList.push_back(WbemProperty(szw,TYPE_TEXT));
  1320. }
  1321. else
  1322. if( pvUsed->boolVal )
  1323. {
  1324. if( (m_bFlags & FLAG_CMD_CONNECT) )
  1325. {
  1326. WCHAR szwConnect[MAX_PATH];
  1327. DWORD nConnect = 0;
  1328. WCHAR *pszw = (WCHAR *)pvServer->bstrVal;
  1329. LONG dwPort = pvPort->lVal;
  1330. WCHAR szw[MAX_PATH];
  1331. if( lstrlen(pszw) > 200 )
  1332. {
  1333. WCHAR cTmp = pszw[200];
  1334. pszw[200] = L'\0';
  1335. wsprintf(szw,ids(IDS_CONNECTINGTOSERVER_STATUS),pszw,dwPort);
  1336. pszw[200] = cTmp;
  1337. }
  1338. else
  1339. {
  1340. wsprintf(szw,ids(IDS_CONNECTINGTOSERVER_STATUS),pszw,dwPort);
  1341. }
  1342. ReportStatus(szw,0);
  1343. wsprintf(szwConnect,ids(IDS_SERVERCONNECTSTART));
  1344. if( Connect(pszw,dwPort) )
  1345. {
  1346. wsprintf(szwConnect,L"%s%s%d",szwConnect,nConnect?L",":L"",dwPort);
  1347. nConnect++;
  1348. }
  1349. if( !nConnect )
  1350. {
  1351. wsprintf(szwConnect,L"%s%s",szwConnect,ids(IDS_NONE));
  1352. bConnectPass = FALSE;
  1353. }
  1354. else
  1355. {
  1356. bConnectPass = TRUE;
  1357. }
  1358. wsprintf(szwConnect,L"%s%s",szwConnect,ids(IDS_SERVERCONNECTEND));
  1359. PropList.push_back(WbemProperty(szwConnect,TYPE_TEXT | TYPE_CONNECT));
  1360. }
  1361. }
  1362. else
  1363. {
  1364. HideAll(PropList);
  1365. lstrcpy(szw,ids(IDS_IEPROXYNOTUSED));
  1366. m_pszwCaption = szw;
  1367. //PropList.push_back(WbemProperty(szw,TYPE_TEXT));
  1368. m_bstrCaption = ids(IDS_NOTCONFIGURED);
  1369. }
  1370. FormatEnum(PropList,NULL, bConnectPass);
  1371. m_bstrCaption = L"";
  1372. return TRUE;
  1373. }
  1374. BOOLEAN CDiagnostics::ExecLoopbackQuery()
  1375. {
  1376. EnumWbemProperty PropList;
  1377. EnumWbemProperty::iterator iter;
  1378. _variant_t vLoopback = L"127.0.0.1";
  1379. m_pszwCaption = TXT_LOOPBACK_CAPTION;
  1380. lstrcpy(m_szwHeader,ids(IDS_LOOPBACK_HEADER));
  1381. lstrcpy(m_szwCategory,ids(IDS_CATEGORY_INTERNET));
  1382. PropList.push_back(WbemProperty(L"Loopback",TYPE_PING));
  1383. iter = PropList.begin();
  1384. iter->Value.push_back(vLoopback);
  1385. FormatEnum(PropList);
  1386. return TRUE;
  1387. }
  1388. BOOLEAN CDiagnostics::ExecIPHost(WCHAR *pszwHostName,WCHAR *pszwHostPort)
  1389. {
  1390. EnumProperty PropList;
  1391. WCHAR szw[MAX_PATH];
  1392. BOOL bFlag;
  1393. m_pszwCaption = L"IPHost";
  1394. lstrcpy(m_szwHeader,L"IPHost");
  1395. Set(PropList, L"IPHost",TYPE_CONNECT | TYPE_PING,_variant_t(pszwHostName));
  1396. if( m_bFlags & FLAG_CMD_CONNECT )
  1397. {
  1398. WCHAR szw[MAX_PATH];
  1399. WCHAR szwConnect[MAX_PATH];
  1400. Set(PropList, L"Port",TYPE_CONNECT,_variant_t(pszwHostPort));
  1401. wsprintf(szw,L"Connecting to %s port %s",pszwHostName,pszwHostPort);
  1402. ReportStatus(szw,0);
  1403. wsprintf(szwConnect,ids(IDS_SERVERCONNECTSTART));
  1404. if( IsNumber(pszwHostPort) && Connect(pszwHostName,wcstol(pszwHostPort,NULL,10)) )
  1405. {
  1406. wsprintf(szwConnect,L"%s%s",szwConnect,pszwHostPort);
  1407. }
  1408. else
  1409. {
  1410. wsprintf(szwConnect,L"%s%s",szwConnect,ids(IDS_NONE));
  1411. }
  1412. wsprintf(szwConnect,L"%s%s",szwConnect,ids(IDS_SERVERCONNECTEND));
  1413. PropList.push_back(Property(szwConnect,TYPE_TEXT | TYPE_CONNECT));
  1414. }
  1415. FormatEnum(PropList);
  1416. return TRUE;
  1417. }
  1418. BOOLEAN CDiagnostics::GetXMLResult(BSTR *pbstr)
  1419. {
  1420. if( m_wstrXML.empty() )
  1421. {
  1422. return FALSE;
  1423. }
  1424. *pbstr = SysAllocString(m_wstrXML.c_str());
  1425. if( pbstr == NULL )
  1426. {
  1427. return FALSE;
  1428. }
  1429. return TRUE;
  1430. }
  1431. void CDiagnostics::NetShNetdiag(BOOLEAN bStartTag, LPCTSTR pszwValue)
  1432. {
  1433. if( m_bInterface == NETSH_INTERFACE )
  1434. {
  1435. m_nIndent = 0;
  1436. m_IsNetdiagDisplayed = FALSE;
  1437. }
  1438. }
  1439. void CDiagnostics::NetShHeader(BOOLEAN bStartTag,LPCTSTR pszwValue,LPCTSTR pszwCaption)
  1440. {
  1441. if( m_bInterface == NETSH_INTERFACE )
  1442. {
  1443. if( bStartTag )
  1444. {
  1445. DisplayMessageT(L"\n");
  1446. if( pszwValue )
  1447. {
  1448. LONG nIndent = m_IsNetdiagDisplayed;
  1449. DisplayMessageT(L"%1!s!%2!s!",Indent(nIndent),pszwValue);
  1450. if( pszwCaption )
  1451. {
  1452. DisplayMessageT(L" (%1!s!)",pszwCaption);
  1453. }
  1454. DisplayMessageT(L"\n");
  1455. m_IsContainerDisplayed = TRUE;
  1456. }
  1457. else
  1458. {
  1459. m_IsContainerDisplayed = FALSE;
  1460. }
  1461. }
  1462. else
  1463. {
  1464. m_IsContainerDisplayed = FALSE;
  1465. }
  1466. }
  1467. }
  1468. void CDiagnostics::NetShCaption(BOOLEAN bStartTag,LPCTSTR pszwValue)
  1469. {
  1470. if( m_bInterface == NETSH_INTERFACE )
  1471. {
  1472. if( bStartTag )
  1473. {
  1474. if( m_nInstance > 1 )
  1475. {
  1476. if( m_bCaptionDisplayed == FALSE )
  1477. {
  1478. if( pszwValue )
  1479. {
  1480. LONG nIndent = m_IsNetdiagDisplayed + m_IsContainerDisplayed;
  1481. DisplayMessageT(L"%1!s!%2!2d!. %3!s!\n",Indent(nIndent),m_nIndex, pszwValue);
  1482. m_IsPropertyListDisplayed = TRUE;
  1483. }
  1484. else
  1485. {
  1486. m_IsPropertyListDisplayed = FALSE;
  1487. }
  1488. m_bCaptionDisplayed = TRUE;
  1489. }
  1490. }
  1491. }
  1492. else
  1493. {
  1494. m_IsPropertyListDisplayed = FALSE;
  1495. //m_bCaptionDisplayed = FALSE;
  1496. }
  1497. }
  1498. }
  1499. void CDiagnostics::NetShField(BOOLEAN bStartTag,LPCTSTR pszwValue)
  1500. {
  1501. if( m_bInterface == NETSH_INTERFACE )
  1502. {
  1503. if( bStartTag )
  1504. {
  1505. m_nPropertyLegth = 0;
  1506. LONG nIndent = m_IsNetdiagDisplayed + m_IsContainerDisplayed + m_IsPropertyListDisplayed;
  1507. if( pszwValue )
  1508. {
  1509. m_nPropertyLegth = DisplayMessageT(L"%1!s!%2!s! = ",Indent(nIndent),pszwValue);
  1510. }
  1511. else
  1512. {
  1513. m_nPropertyLegth = DisplayMessageT(L"%1!s!",Indent(nIndent));
  1514. }
  1515. m_nValueIndex = 0;
  1516. m_IsPropertyDisplayed = TRUE;
  1517. }
  1518. else
  1519. {
  1520. m_IsPropertyDisplayed = FALSE;
  1521. }
  1522. }
  1523. }
  1524. void CDiagnostics::NetShProperty(BOOLEAN bStartTag,LPCTSTR pszwValue,LPCTSTR pszwComment,BOOL bFlags)
  1525. {
  1526. if( m_bInterface == NETSH_INTERFACE )
  1527. {
  1528. if( bStartTag )
  1529. {
  1530. if( (bFlags & TYPE_PING) )
  1531. {
  1532. LONG nIndent = m_IsNetdiagDisplayed + m_IsContainerDisplayed + m_IsPropertyListDisplayed + m_IsPropertyDisplayed;
  1533. if( m_nValueIndex == 0 )
  1534. {
  1535. DisplayMessageT(L"\n");
  1536. }
  1537. DisplayMessageT(L"%1!s!%2!s! %3!s!\n",Indent(nIndent),pszwValue?pszwValue:L"",pszwComment?pszwComment:L"");
  1538. m_nValueIndex++;
  1539. }
  1540. else
  1541. {
  1542. DisplayMessageT(L"%1!s!%2!s! %3!s!\n",m_nValueIndex++?Space(m_nPropertyLegth):L"",pszwValue?pszwValue:L"",pszwComment?pszwComment:L"");
  1543. }
  1544. m_IsValueDisplayed = TRUE;
  1545. }
  1546. else
  1547. {
  1548. m_IsValueDisplayed = FALSE;
  1549. }
  1550. }
  1551. }