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.

767 lines
17 KiB

  1. <%@ Language=JavaScript%>
  2. <!--
  3. RemoteDataCollection.htm: This is the Remote Control File transfer implementation.
  4. History:
  5. Sudha Srinivasan - created 07/28/2000
  6. -->
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  10. <meta http-equiv="Content-Language" content="en-us">
  11. <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
  12. <meta name="ProgId" content="FrontPage.Editor.Document">
  13. <OBJECT ID=pchealth classid=CLSID:FC7D9E02-3F9E-11d3-93C0-00C04F72DAF7></OBJECT>
  14. <title>Windows Remote Data Collection</title>
  15. </HEAD>
  16. <!--
  17. Scripts to handle UI
  18. -->
  19. <script>
  20. //
  21. // Constants
  22. //
  23. var c_szRCCommand = "RCCOMMAND";
  24. var c_szRCCommandName = "NAME";
  25. var c_szFileXfer = "FILEXFER";
  26. var c_szFileName = "FILENAME";
  27. var c_szFileSize = "FILESIZE";
  28. var c_szChannelId = "CHANNELID";
  29. var c_szFileXferACK = "FILEXFERACK";
  30. var c_MAXFILEXFERSIZE = 10240;
  31. var c_szRemoteDataCollection = "REMOTEDATACOLLECTION";
  32. var c_szRemoteDataCollectMode = "REMOTEDATACOLLECTIONMODE";
  33. var c_szRDCResponse = "DATARESPONSE";
  34. var c_szRDCRequest = "DATAREQUEST";
  35. var c_szFileEND = "FILEXFEREND";
  36. //
  37. // Globals
  38. //
  39. var root = null;
  40. var vArgs = null
  41. var Mode = null;
  42. var g_oControlChannel = null;
  43. var g_oDataChannel = null;
  44. var g_oDataChannelRDC = null;
  45. var g_oSAFRemoteDesktopChannelMgr = null;
  46. var g_iFileSize = 0;
  47. var g_iSentCtr = 0;
  48. var g_iRecvdCtr = 0;
  49. var g_szFileName = null;
  50. var g_szChannelId = null;
  51. var fso = null;
  52. var fileHandle = null;
  53. var file = null;
  54. var tFileName = null;
  55. var tProgBarCounter = 0;
  56. //var objDataCol = null; // The Data Collection object.
  57. //
  58. // Error Messages
  59. //
  60. var L_ERRRCFILEXFERINITFAILS_MSG = "Initialization of RDC File Xfer fails";
  61. var L_ERRFILEXFERINITFAILED_MSG = "Failed to initialize data channel for file transfer";
  62. var L_ERROPENINGFILEFORREAD_MSG = "Error Opening File for reading: ";
  63. var L_ERRFAILDATACHANNELCREATION_MSG = "Failed to Create Data Channel";
  64. var L_ERRDATACHANNELSEND_MSG = "Unable to send file on data channel";
  65. var L_ERRINVALIDFILEHANDLE_MSG = "Invalid File Handle";
  66. var L_ERRTEMPFILENAME_MSG = "Temp Filename not defined";
  67. var L_ERRNOTIMPL_MSG = "Not implemented";
  68. //*****************************************************************************
  69. //
  70. // InitRemoteDataCollection: Routine that initializes File Xfer and determines what
  71. // screen to show
  72. //
  73. function InitRemoteDataCollection()
  74. {
  75. try
  76. {
  77. vArgs = window.dialogArguments;
  78. Mode = vArgs[0]; // Mode=0: Source, Mode=1: Data Request, Mode=2: Data Response
  79. g_oControlChannel = vArgs[1];
  80. g_oSAFRemoteDesktopChannelMgr = vArgs[2];
  81. //alert( "mode :" + Mode );
  82. if( 0 == Mode)
  83. {
  84. //
  85. // File Transfer source mode
  86. //
  87. RemoteDataCollectionSrc.style.visibility = "visible";
  88. RemoteDataCollectionDestn.style.visibility = "hidden";
  89. g_szChannelId = vArgs[3];
  90. //alert("g_szChannelID: " + g_szChannelId);
  91. }
  92. else if(1 == Mode)
  93. {
  94. // alert("In the remotedatacollection with mode as 2");
  95. //
  96. // File Transfer destination mode
  97. //
  98. RemoteDataCollectionSrc.style.visibility = "hidden";
  99. RemoteDataCollectionDestn.style.visibility = "visible";
  100. g_szFileName = vArgs[3]; // FILENAME
  101. g_iFileSize = vArgs[4]; // FILESIZE
  102. g_szChannelId = vArgs[5]; // CHANNELID
  103. //
  104. // Update filename and filesize in UI
  105. //
  106. FileNameId.innerText = g_szFileName;
  107. g_iRecvdCtr = 0;
  108. tProgBarCounter = Math.ceil(g_iFileSize/c_MAXFILEXFERSIZE);
  109. try
  110. {
  111. //
  112. // Create the data channel for file transfer if necessary
  113. //
  114. if(null == g_oDataChannel)
  115. {
  116. // alert("The Channel is already lost. Need to open a new one for receiving data");
  117. alert("g_szChannelId : " + g_szChannelId );
  118. g_oDataChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( g_szChannelId );
  119. //
  120. // Bind the OnChannelDataReady event handler
  121. //
  122. g_oDataChannel.OnChannelDataReady = function()
  123. { DestnDataChannelDataReadyHandler(); }
  124. }
  125. }
  126. catch(error)
  127. {
  128. alert( L_ERRFAILDATACHANNELCREATION_MSG );
  129. //
  130. // Todo: Add code to handle error here
  131. //
  132. }
  133. //
  134. // Create temp file for staging while file is XFered
  135. //
  136. // alert( "creating file system object" );
  137. fso = new ActiveXObject("Scripting.FileSystemObject");
  138. var tFolder = fso.GetSpecialFolder(2); // Get Path to temp directory
  139. tFileName = tFolder + "\\" + g_szFileName;
  140. alert( "tFileName: " + tFileName );
  141. // alert( "creating text file: " + tFileName );
  142. fileHandle = fso.CreateTextFile( tFileName );
  143. //
  144. // Send ACK to source to make it begin pumping data on the data channel
  145. //
  146. // alert( c_szFileXferACK );
  147. g_oDataChannel.SendChannelData( c_szFileXferACK );
  148. }
  149. }
  150. catch(error)
  151. {
  152. alert( L_ERRRCFILEXFERINITFAILS_MSG );
  153. }
  154. return;
  155. }
  156. //
  157. // onSend: This routine is fired when the "Send File" button is clicked
  158. //
  159. function onSend()
  160. {
  161. var fileName = attfile.value;
  162. var ForReading = 1, ForWriting = 2, ForAppending = 8;
  163. var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
  164. var Doc = null;
  165. var RCCommand = null;
  166. //
  167. // Open the File for reading
  168. //
  169. try
  170. {
  171. //
  172. // Create the filesystem object
  173. //
  174. fso = new ActiveXObject("Scripting.FileSystemObject");
  175. //
  176. // Open the file
  177. //
  178. file = fso.GetFile(fileName);
  179. fileHandle = file.OpenAsTextStream(ForReading,TristateUseDefault);
  180. }
  181. catch(error)
  182. {
  183. alert( L_ERROPENINGFILEFORREAD_MSG + fileName );
  184. }
  185. //
  186. // Initiate File Xfer
  187. //
  188. try
  189. {
  190. //
  191. // Create an XML document
  192. //
  193. Doc = new ActiveXObject("microsoft.XMLDOM");
  194. }
  195. catch (err)
  196. {
  197. alert("new object: " + err);
  198. }
  199. try {
  200. //
  201. // Create the RCCOMMAND root node
  202. //
  203. RCCommand = Doc.createElement( c_szRCCommand );
  204. }
  205. catch (err)
  206. {
  207. alert("create element :" + err);
  208. }
  209. try {
  210. //
  211. // Set the NAME attribute to FILEXFER
  212. //
  213. RCCommand.setAttribute( c_szRCCommandName, c_szRemoteDataCollection );
  214. }
  215. catch (err)
  216. {
  217. alert("setAttribute for datacollection :" + err);
  218. }
  219. try {
  220. //
  221. // Set the DATA COLLECTION MODE attribute
  222. //
  223. RCCommand.setAttribute( c_szRemoteDataCollectMode, c_szRDCRequest );
  224. }
  225. catch (err)
  226. {
  227. alert("set attribute for RDCRequest: " + err );
  228. }
  229. try {
  230. //
  231. // Set the FILENAME attribute
  232. //
  233. RCCommand.setAttribute( c_szFileName, file.Name );
  234. }
  235. catch(err)
  236. {
  237. alert("set attribute file name :" + err);
  238. }
  239. try {
  240. //
  241. // Set the FILESIZE attribute
  242. //
  243. RCCommand.setAttribute( c_szFileSize, file.size );
  244. }
  245. catch(err)
  246. {
  247. alert("set attribute for file size : " + err );
  248. }
  249. try {
  250. //
  251. // Set the CHANNELID attribute
  252. //
  253. // alert( " channel id is : " + g_szChannelId );
  254. RCCommand.setAttribute( c_szChannelId, g_szChannelId );
  255. }
  256. catch(err)
  257. {
  258. alert("set attribute channel id: " + err);
  259. }
  260. try {
  261. //
  262. // Send the XML across
  263. //
  264. // alert("the xml sent across is :" + RCCommand.xml);
  265. g_oControlChannel.SendChannelData( RCCommand.xml );
  266. }
  267. catch(error)
  268. {
  269. alert ( L_ERRFILEXFERINITFAILED_MSG );
  270. }
  271. //
  272. // Create the data channel for Filetransfer
  273. //
  274. try
  275. {
  276. if(null == g_oDataChannel)
  277. {
  278. // alert( " g_szChannelId :" + g_szChannelId );
  279. g_oDataChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( g_szChannelId );
  280. //
  281. // Bind the OnChannelDataReady event handler
  282. //
  283. g_oDataChannel.OnChannelDataReady = function()
  284. { SrcDataChannelDataReadyHandler(); }
  285. }
  286. }
  287. catch(error)
  288. {
  289. alert( L_ERRFAILDATACHANNELCREATION_MSG );
  290. }
  291. //
  292. // Enable progress bar
  293. //
  294. FileSizeSrcId.style.visibility = "visible";
  295. return;
  296. }
  297. //
  298. // onSend: This routine is fired when the "Send File" button is clicked
  299. //
  300. function SendDataCollected( filename )
  301. {
  302. var fileName = filename;
  303. var ForReading = 1, ForWriting = 2, ForAppending = 8;
  304. var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
  305. var Doc = null;
  306. var RCCommand = null;
  307. // alert("Inside the SendDataCollected func.");
  308. //
  309. // Open the File for reading
  310. //
  311. try
  312. {
  313. //
  314. // Create the filesystem object
  315. //
  316. fso = new ActiveXObject("Scripting.FileSystemObject");
  317. //
  318. // Open the file
  319. //
  320. file = fso.GetFile(fileName);
  321. fileHandle = file.OpenAsTextStream(ForReading,TristateUseDefault);
  322. }
  323. catch(error)
  324. {
  325. alert( L_ERROPENINGFILEFORREAD_MSG + fileName );
  326. }
  327. //
  328. // Initiate File Xfer
  329. //
  330. try
  331. {
  332. //
  333. // Create an XML document
  334. //
  335. Doc = new ActiveXObject("microsoft.XMLDOM");
  336. //
  337. // Create the RCCOMMAND root node
  338. //
  339. // alert("creating the RCCommand");
  340. RCCommand = Doc.createElement( c_szRCCommand );
  341. //
  342. // Set the NAME attribute to FILEXFER
  343. //
  344. // alert("Set the attribute for command name :" + c_szRemoteDataCollection);
  345. RCCommand.setAttribute( c_szRCCommandName, c_szRemoteDataCollection );
  346. //
  347. // Set the FILENAME attribute
  348. //
  349. // alert("Set the attribute filename name :" + file.Name);
  350. RCCommand.setAttribute( c_szFileName, file.Name );
  351. //
  352. // Set the FILESIZE attribute
  353. //
  354. // alert("Set the attribute filename size :" + file.size);
  355. RCCommand.setAttribute( c_szFileSize, file.size );
  356. //
  357. // Set the CHANNELID attribute
  358. //
  359. // alert("Set the attribute channel id :" + g_szChannelId);
  360. RCCommand.setAttribute( c_szChannelId, g_szChannelId );
  361. //
  362. // Set the RDC Mode
  363. //
  364. // alert("Set the attribute mode :" + c_szRDCResponse);
  365. RCCommand.setAttribute( c_szRemoteDataCollectMode, c_szRDCResponse);
  366. //
  367. // Send the XML across
  368. //
  369. // alert("the text that's sent across: " + RCCommand.xml );
  370. g_oControlChannel.SendChannelData( RCCommand.xml );
  371. }
  372. catch(error)
  373. {
  374. alert ( L_ERRFILEXFERINITFAILED_MSG );
  375. }
  376. //
  377. // Create the data channel for Filetransfer
  378. //
  379. try
  380. {
  381. if(null == g_oDataChannel)
  382. {
  383. g_oDataChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( g_szChannelId );
  384. //
  385. // Bind the OnChannelDataReady event handler
  386. //
  387. g_oDataChannel.OnChannelDataReady = function()
  388. { SrcDataChannelDataReadyHandler(); }
  389. }
  390. }
  391. catch(error)
  392. {
  393. alert( L_ERRFAILDATACHANNELCREATION_MSG );
  394. }
  395. //
  396. // Enable progress bar
  397. //
  398. FileSizeSrcId.style.visibility = "visible";
  399. return;
  400. }
  401. //
  402. // SrcDataChannelDataReadyHandler: Fired when file Xfer src receives data from
  403. // the file Xfer destn on the data channel
  404. //
  405. function SrcDataChannelDataReadyHandler()
  406. {
  407. //alert("Start sending data");
  408. //
  409. // Start sending data
  410. //
  411. SendFileData();
  412. //
  413. // We are done. Close the window
  414. //
  415. window.close();
  416. return;
  417. }
  418. //
  419. // DestnDataChannelDataReadyHandler(): Fired when file Xfer destn receives data from
  420. // the file Xfer src on the data channel
  421. //
  422. function DestnDataChannelDataReadyHandler()
  423. {
  424. var str = null;
  425. // alert("Recvd data");
  426. //
  427. // receiving incoming data
  428. //
  429. str = g_oDataChannel.ReceiveChannelData();
  430. // alert(str);
  431. if ( c_szFileEND != str )
  432. {
  433. //
  434. // Update UI
  435. //
  436. g_iRecvdCtr += str.length;
  437. // alert("g_iRecvdCtr : " + g_iRecvdCtr);
  438. //
  439. // Write str to open temp file
  440. //
  441. fileHandle.Write( str );
  442. if ( tProgBarCounter > 0 )
  443. {
  444. // ProgressBar1.Value = (100/tProgBarCounter);
  445. tProgBarCounter--;
  446. }
  447. }
  448. //
  449. // If g_iRecvdCtr == g_iFileSize;
  450. // - launch File Open/Save dialog
  451. // - close data connection
  452. if( (g_iRecvdCtr == g_iFileSize) || (str==c_szFileEND) )
  453. {
  454. // alert( "File received" );
  455. alert(g_iRecvdCtr +"is the size received and " + g_iFileSize);
  456. //
  457. // Close open temp file handle
  458. //
  459. fileHandle.Close();
  460. //
  461. // Show the File Open/Save dialog
  462. //
  463. OpenTempFile();
  464. alert("Open the WMI Viewer and show the data to the user.");
  465. //
  466. // We are done. Close the window
  467. //
  468. window.close();
  469. // Open the WMI Viewer and show the data to the user.
  470. }
  471. return;
  472. }
  473. function ResetUIForRDC()
  474. {
  475. alert("Reseting the UI for sending the data collected");
  476. RemoteDataCollectionSrc.style.visibility = "hidden";
  477. RemoteDataCollectionDestn.style.visibility = "hidden";
  478. tProgBarCounter = Math.ceil(g_iFileSize/c_MAXFILEXFERSIZE);
  479. }
  480. //
  481. // SendFileData: Sends currently open file to destination
  482. //
  483. function SendFileData()
  484. {
  485. var stream = null;
  486. if ( fileHandle!= null )
  487. {
  488. //
  489. // Enable display of file xfer status in the UI
  490. //
  491. FileSizeSrcId.style.visibility = "visible";
  492. g_iSentCtr = 0;
  493. //
  494. // While there is data to send
  495. //
  496. tProgBarCounter = Math.ceil((file.size)/c_MAXFILEXFERSIZE);
  497. while (!fileHandle.AtEndOfStream)
  498. {
  499. try
  500. {
  501. stream = null;
  502. //
  503. // Read File
  504. //
  505. stream = fileHandle.Read( c_MAXFILEXFERSIZE );
  506. //
  507. // Update UI
  508. //
  509. g_iSentCtr+= stream.length;
  510. //
  511. // Send data over the data channel
  512. //
  513. g_oDataChannel.SendChannelData( stream );
  514. //alert("Sent data");
  515. if ( tProgBarCounter > 0 )
  516. {
  517. ProgressBar2.Value = (100/tProgBarCounter);
  518. tProgBarCounter--;
  519. }
  520. }
  521. catch(error)
  522. {
  523. alert( L_ERRDATACHANNELSEND_MSG );
  524. }
  525. }
  526. //
  527. // Close the file
  528. //
  529. fileHandle.Close();
  530. }
  531. else
  532. {
  533. alert( L_ERRINVALIDFILEHANDLE_MSG );
  534. }
  535. return;
  536. }
  537. //
  538. // OpenTempFile: Opens the currently download temp file
  539. //
  540. function OpenTempFile()
  541. {
  542. if(null != tFileName )
  543. {
  544. window.open( tFileName );
  545. }
  546. else
  547. {
  548. alert( L_ERRTEMPFILENAME_MSG );
  549. }
  550. }
  551. function onok()
  552. {
  553. if (radio1.checked)
  554. {
  555. OpenTempFile();
  556. }
  557. else
  558. {
  559. alert ( L_ERRNOTIMPL_MSG );
  560. }
  561. }
  562. function oncancel()
  563. {
  564. alert ( L_ERRNOTIMPL_MSG );
  565. }
  566. </script>
  567. <body id="RemoteDataCollectionBody" bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload=InitRemoteDataCollection()><!--
  568. File Transfer Source
  569. -->
  570. <div id=RemoteDataCollectionSrc STYLE="LEFT: 50px; POSITION: absolute; TOP: 50px; VISIBILITY: hidden">
  571. <table id="table1" width="495" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#ffffff" height="400">
  572. <tr>
  573. <td align="middle" bgcolor="#99ccff"><font face="Verdana, Arial, Helvetica, sans-serif" color="#000000"> Remote Data
  574. Collection</font>
  575. </td>
  576. </tr>
  577. <tr>
  578. <td>
  579. <table id="table2" border="0">
  580. <tr>
  581. <td>
  582. <ol>
  583. <LI>Click the <B>Browse</B> button to select the file that you want to transfer, or type the path to the file in the box below.<BR>
  584. <center>
  585. <nobr>
  586. Attach File: <input name="attfile" type="file" LANGUAGE=javascript>
  587. </nobr>
  588. </center>
  589. <p></p>
  590. <LI>Click the <B>Send File</B> button to transfer the file.<BR>
  591. The transfer of an attached file may require 30 seconds to up to 10 minutes.<BR>
  592. <center>
  593. <input type="button" id="btnSendFileId" value="Send File" style="HEIGHT: 24px; WIDTH: 100px" onclick=onSend()></button>
  594. </center></LI>
  595. </ol>
  596. </td>
  597. </tr>
  598. <tr>
  599. <td>
  600. <div id="FileSizeSrcId" align="center" style="visibility: hidden">
  601. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  602. <OBJECT classid=clsid:0713E8D2-850A-101B-AFC0-4210102A8DA7 id=ProgressBar2
  603. style="HEIGHT: 25px; LEFT: 173px; TOP: 2px; WIDTH: 144px" VIEWASTEXT>
  604. <PARAM NAME="_ExtentX" VALUE="3810">
  605. <PARAM NAME="_ExtentY" VALUE="661">
  606. <PARAM NAME="_Version" VALUE="327682">
  607. <PARAM NAME="BorderStyle" VALUE="0">
  608. <PARAM NAME="Appearance" VALUE="1">
  609. <PARAM NAME="MousePointer" VALUE="0">
  610. <PARAM NAME="Enabled" VALUE="1">
  611. <PARAM NAME="OLEDropMode" VALUE="0">
  612. <PARAM NAME="Min" VALUE="0">
  613. <PARAM NAME="Max" VALUE="100">
  614. </OBJECT>
  615. </div>
  616. </td>
  617. </tr>
  618. </table> <!-- End of table2 -->
  619. </td>
  620. </tr>
  621. </table>
  622. </div><!-- End of RemoteDataCollectionSrc div --><!--
  623. File Transfer Destination
  624. -->
  625. <div id=RemoteDataCollectionDestn STYLE="LEFT: 50px; POSITION: absolute; TOP: 50px; VISIBILITY: hidden">
  626. <table width="495" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#ffffff" height="400">
  627. <tr>
  628. <td align="middle" bgcolor="#99ccff"><font face="Verdana, Arial, Helvetica, sans-serif" color="#000000"> Remote Data
  629. Collection </font>
  630. </td>
  631. </tr>
  632. <tr>
  633. <td align="middle">
  634. <table border="0">
  635. <tr>
  636. <td align="middle"> Receiving File: <div id="FileNameId"> &nbsp; </div> </td>
  637. </tr>
  638. <tr>
  639. <td align="middle">
  640. <div id="FileSizeDestnId">
  641. <OBJECT classid=clsid:0713E8D2-850A-101B-AFC0-4210102A8DA7 id=ProgressBar3
  642. style="HEIGHT: 26px; LEFT: 171px; TOP: -3px; WIDTH: 148px" VIEWASTEXT>
  643. <PARAM NAME="_ExtentX" VALUE="3916">
  644. <PARAM NAME="_ExtentY" VALUE="688">
  645. <PARAM NAME="_Version" VALUE="327682">
  646. <PARAM NAME="BorderStyle" VALUE="0">
  647. <PARAM NAME="Appearance" VALUE="1">
  648. <PARAM NAME="MousePointer" VALUE="0">
  649. <PARAM NAME="Enabled" VALUE="1">
  650. <PARAM NAME="OLEDropMode" VALUE="0">
  651. <PARAM NAME="Min" VALUE="0">
  652. <PARAM NAME="Max" VALUE="100">
  653. </OBJECT>
  654. </div>
  655. </td>
  656. </tr>
  657. </table>
  658. </td>
  659. </tr>
  660. </table>
  661. </div><!-- End of RemoteDataCollectionDestn div -->
  662. </body>
  663. </html>