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.

1874 lines
43 KiB

  1. <HTML>
  2. <HEAD>
  3. <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
  4. <TITLE>Remote Control Chat Server</TITLE>
  5. <OBJECT ID=pchealth classid=CLSID:FC7D9E02-3F9E-11d3-93C0-00C04F72DAF7></OBJECT>
  6. </HEAD>
  7. <!--
  8. Test
  9. <BODY id="ChatServerId" onload=TransmitScreenInfo()>
  10. -->
  11. <BODY id="ChatServerId" onload=InitiateRCSession() bgcolor="#4a8ece" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
  12. <!--
  13. <BODY onUnload=cleanUp() id="ChatServerId" onload=InitiateRCSession() bgcolor="#4a8ece" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
  14. -->
  15. <!--
  16. Title and control panel
  17. -->
  18. <div id=ChatServer STYLE="LEFT: 50px; POSITION: absolute; TOP: 50px; VISIBILITY: hidden">
  19. <table width="700" border="0" cellspacing="0" cellpadding="2" bgcolor="#4a8ece">
  20. <tr bgcolor="#4a8ece">
  21. <td>
  22. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  23. <tr>
  24. <td width="42%" height="30"><img src="WinRCTitleChat.gif" width="290" height="33"></td>
  25. <td width="9%" valign="middle" height="30">
  26. <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#FFFFFF">
  27. <tr bgcolor="#4a8ece">
  28. <td><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"><b>MODE:</b><br>
  29. <font size="1"> <div id=StatusID> </div></font></font></td>
  30. </tr>
  31. </table>
  32. <font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">
  33. </font></td>
  34. <td width="49%" valign="middle" height="30">
  35. <div align="right">
  36. <input type="button" id=AbortConnection value="Quit Session" onclick=AbortConnection()>
  37. <input type="button" id="FileXferId" value="File Transfer" onclick=LaunchFileXfer(0)>
  38. <!--
  39. <input type="button" id="RemoteDataCollectionId" value="Remote Data Collection" onclick=LaunchRemoteDataCollection(0) -->
  40. <!--input type="button" id=HideChat onclick=HideChatBox()-->
  41. &nbsp;&nbsp;&nbsp; </div>
  42. </td>
  43. </tr>
  44. </table>
  45. </td>
  46. </tr>
  47. <tr>
  48. <TABLE>
  49. <TR>
  50. <!--
  51. Incoming chat display area
  52. -->
  53. <TD>
  54. <TEXTAREA wrap="VIRTUAL" cols="85" rows="15" id=incomingChatText name=incomingChatText readOnly multiline="true"></TEXTAREA>
  55. </TD>
  56. </TR>
  57. <TR>
  58. <!--
  59. Chat text box
  60. -->
  61. <TD><TEXTAREA id=chatText name=chatText cols="60" wrap="VIRTUAL" rows="4" onkeypress=OnEnter()></TEXTAREA>&nbsp;&nbsp;&nbsp;
  62. <input type="submit" id=sendChatButton name=sendChatButton onclick=SendChatButtonHandler() value="Submit Message ^">
  63. </TR>
  64. </TABLE>
  65. </tr>
  66. </table>
  67. </div><!-- End of Chat Server div -->
  68. <!--
  69. //************************************************************************************
  70. // Screens of Remote Data Collection
  71. //************************************************************************************
  72. -->
  73. <div id=RemoteDataCollectionSrc STYLE="LEFT: 50px; POSITION: absolute; TOP: 50px; VISIBILITY: hidden">
  74. <table id="table1" width="495" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#ffffff" height="400">
  75. <tr>
  76. <td align="middle" bgcolor="#99ccff"><font face="Verdana, Arial, Helvetica, sans-serif" color="#000000"> Remote Data
  77. Collection</font>
  78. </td>
  79. </tr>
  80. <tr>
  81. <td>
  82. <table id="table2" border="0">
  83. <tr>
  84. <td>
  85. <ol>
  86. <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>
  87. <center>
  88. <nobr>
  89. Attach File: <input name="attfile" type="file" LANGUAGE=javascript>
  90. </nobr>
  91. </center>
  92. <p></p>
  93. <LI>Click the <B>Send File</B> button to transfer the file.<BR>
  94. The transfer of an attached file may require 30 seconds to up to 10 minutes.<BR>
  95. <center>
  96. <input type="button" id="btnSendFileId" value="Send File" style="HEIGHT: 24px; WIDTH: 100px" onclick=onSend()></button>
  97. </center></LI>
  98. </ol>
  99. </td>
  100. </tr>
  101. <tr>
  102. <td>
  103. <div id="FileSizeSrcId" align="center" style="visibility: hidden">
  104. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  105. <OBJECT classid=clsid:0713E8D2-850A-101B-AFC0-4210102A8DA7 id=ProgressBar2
  106. style="HEIGHT: 25px; LEFT: 173px; TOP: 2px; WIDTH: 144px" VIEWASTEXT>
  107. <PARAM NAME="_ExtentX" VALUE="3810">
  108. <PARAM NAME="_ExtentY" VALUE="661">
  109. <PARAM NAME="_Version" VALUE="327682">
  110. <PARAM NAME="BorderStyle" VALUE="0">
  111. <PARAM NAME="Appearance" VALUE="1">
  112. <PARAM NAME="MousePointer" VALUE="0">
  113. <PARAM NAME="Enabled" VALUE="1">
  114. <PARAM NAME="OLEDropMode" VALUE="0">
  115. <PARAM NAME="Min" VALUE="0">
  116. <PARAM NAME="Max" VALUE="100">
  117. </OBJECT>
  118. </div>
  119. </td>
  120. </tr>
  121. </table> <!-- End of table2 -->
  122. </td>
  123. </tr>
  124. </table>
  125. </div><!-- End of RemoteDataCollectionSrc div --><!--
  126. File Transfer Destination
  127. -->
  128. <div id=RemoteDataCollectionDestn STYLE="LEFT: 50px; POSITION: absolute; TOP: 50px; VISIBILITY: hidden">
  129. <table width="495" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#ffffff" height="400">
  130. <tr>
  131. <td align="middle" bgcolor="#99ccff"><font face="Verdana, Arial, Helvetica, sans-serif" color="#000000"> Remote Data
  132. Collection </font>
  133. </td>
  134. </tr>
  135. <tr>
  136. <td align="middle">
  137. <table border="0">
  138. <tr>
  139. <td align="middle"> <div id="Action"> </div> <div id="FileNameId"> &nbsp; </div> </td>
  140. </tr>
  141. <tr>
  142. <td align="middle">
  143. <div id="FileSizeDestnId">
  144. <OBJECT classid=clsid:0713E8D2-850A-101B-AFC0-4210102A8DA7 id=ProgressBar3
  145. style="HEIGHT: 26px; LEFT: 171px; TOP: -3px; WIDTH: 148px" VIEWASTEXT>
  146. <PARAM NAME="_ExtentX" VALUE="3916">
  147. <PARAM NAME="_ExtentY" VALUE="688">
  148. <PARAM NAME="_Version" VALUE="327682">
  149. <PARAM NAME="BorderStyle" VALUE="0">
  150. <PARAM NAME="Appearance" VALUE="1">
  151. <PARAM NAME="MousePointer" VALUE="0">
  152. <PARAM NAME="Enabled" VALUE="1">
  153. <PARAM NAME="OLEDropMode" VALUE="0">
  154. <PARAM NAME="Min" VALUE="0">
  155. <PARAM NAME="Max" VALUE="100">
  156. </OBJECT>
  157. </div>
  158. </td>
  159. </tr>
  160. </table>
  161. </td>
  162. </tr>
  163. </table>
  164. </div><!-- End of RemoteDataCollectionDestn div -->
  165. <!--
  166. File Transfer Destination of the Data Collected RemoteDataCollectedDestn
  167. -->
  168. <div id=RemoteDataCollectedDestn STYLE="LEFT: 50px; POSITION: absolute; TOP: 50px; VISIBILITY: hidden">
  169. <table width="495" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#ffffff" height="400">
  170. <tr>
  171. <td align="middle" bgcolor="#99ccff"><font face="Verdana, Arial, Helvetica, sans-serif" color="#000000"> Remote Data
  172. Collection </font>
  173. </td>
  174. </tr>
  175. <tr>
  176. <td align="middle">
  177. <table border="0">
  178. <tr>
  179. <td align="middle"> Sending File: <div id="RDCFileNameId"> &nbsp; </div> </td>
  180. </tr>
  181. <tr>
  182. <td align="middle">
  183. <div id="FileSizeColDestnId">
  184. <OBJECT classid=clsid:0713E8D2-850A-101B-AFC0-4210102A8DA7 id=ProgressBar1
  185. style="HEIGHT: 26px; LEFT: 171px; TOP: -3px; WIDTH: 148px" VIEWASTEXT>
  186. <PARAM NAME="_ExtentX" VALUE="3916">
  187. <PARAM NAME="_ExtentY" VALUE="688">
  188. <PARAM NAME="_Version" VALUE="327682">
  189. <PARAM NAME="BorderStyle" VALUE="0">
  190. <PARAM NAME="Appearance" VALUE="1">
  191. <PARAM NAME="MousePointer" VALUE="0">
  192. <PARAM NAME="Enabled" VALUE="1">
  193. <PARAM NAME="OLEDropMode" VALUE="0">
  194. <PARAM NAME="Min" VALUE="0">
  195. <PARAM NAME="Max" VALUE="100">
  196. </OBJECT>
  197. </div>
  198. </td>
  199. </tr>
  200. </table>
  201. </td>
  202. </tr>
  203. </table>
  204. </div><!-- End of RemoteDataCollectedDestn div -->
  205. <!--
  206. //************************************************************************************
  207. // End of Remote Data Collection
  208. //************************************************************************************
  209. -->
  210. <SCRIPT Language="JScript">
  211. //
  212. // Salem objects.
  213. //
  214. var vArgs = null;
  215. var g_oSAFRemoteDesktopSession = null;
  216. var g_oSAFRemoteDesktopChannelMgr = null;
  217. var g_oChatChannel = null;
  218. var g_oControlChannel = null;
  219. var g_oDataChannel = null;
  220. var g_oDataChannelRDC = null;
  221. if(null == parent.oRCSession)
  222. {
  223. //alert("Dialog");
  224. vArgs = window.dialogArguments;
  225. g_oSAFRemoteDesktopSession = vArgs;
  226. }
  227. else
  228. {
  229. //alert("not a dialog");
  230. g_oSAFRemoteDesktopSession = parent.oRCSession;
  231. }
  232. //
  233. // Globals
  234. //
  235. var g_bChatBoxHidden = false;
  236. var g_bNewBinaries = false;
  237. var g_bUserDisconnect = true;
  238. //
  239. // Constants
  240. //
  241. var c_szChatChannelID = "70";
  242. var c_szControlChannelID = "71";
  243. var c_szHomePage = "hcp://system/HomePage.htm";
  244. var c_szRCCommand = "RCCOMMAND";
  245. var c_szRCCommandName = "NAME";
  246. var c_szScreenInfo = "SCREENINFO";
  247. var c_szWidth = "WIDTH";
  248. var c_szHeight = "HEIGHT";
  249. var c_szColorDepth = "COLORDEPTH";
  250. var c_szDisconnectRC = "DISCONNECTRC";
  251. var c_szFileXfer = "FILEXFER";
  252. var c_szFileName = "FILENAME";
  253. var c_szFileSize = "FILESIZE";
  254. var c_szChannelId = "CHANNELID";
  255. var c_szRemoteCtrlStart = "REMOTECTRLSTART";
  256. var c_szRemoteCtrlEnd = "REMOTECTRLEND";
  257. var c_szRCMODE = "REMOTE CONTROL";
  258. var c_szCHATMODE = "CHAT";
  259. var c_szRemoteDataCollection = "REMOTEDATACOLLECTION";
  260. var c_szRemoteDataCollectMode = "REMOTEDATACOLLECTIONMODE";
  261. var c_szRDCResponse = "DATARESPONSE";
  262. var c_szRDCRequest = "DATAREQUEST";
  263. var c_MAXFILEXFERSIZE = 10240;
  264. var c_szFileXferACK = "FILEXFERACK";
  265. var c_szFileEND = "FILEXFEREND";
  266. //
  267. // Desktop Control Permissions
  268. //
  269. var DESKTOPSHARING_DEFAULT = 0x0000;
  270. var NO_DESKTOP_SHARING = 0x0001;
  271. var VIEWDESKTOP_PERMISSION_REQUIRE = 0x0002;
  272. var VIEWDESKTOP_PERMISSION_NOT_REQUIRE = 0x0004;
  273. var CONTROLDESKTOP_PERMISSION_REQUIRE = 0x0008;
  274. var CONTROLDESKTOP_PERMISSION_NOT_REQUIRE = 0x00010;
  275. //
  276. // Localizable contants
  277. //
  278. var L_cszExpertID = "\n Helper> ";
  279. var L_cszUserID = "\n Helpee> ";
  280. var L_HIDECHAT = "Hide Chat Boxes";
  281. var L_SHOWCHAT = "Show Chat Boxes";
  282. //
  283. // Messages
  284. //
  285. var L_EXPERTDISCONNECT_MSG = "Helper disconnected.";
  286. var L_EXPERTCONNECTED_MSG = "Helper connected.";
  287. var L_ABORTINGCONNECTION_MSG = "Terminating Remote control connection from Helper";
  288. var L_USECHATBOX_MSG = "1. Your Helper will now taken Remote control of your Computer.\n2. Both you and your helper can control your computer at the same time.\n3. You can still use your chat window to communicate with your helper. \n4. However, your helper would need to use your chat window to communicate with you. \n";
  289. //
  290. // Error Messages
  291. //
  292. var L_ERRNULLRCSESSION = "RCSession object is not defined";
  293. //********************************************************************
  294. //*****************************************************************************
  295. // constants for the data collection
  296. //*****************************************************************************
  297. // variables to track event notification and other tasks
  298. //
  299. var iMessageCount = 0;
  300. var strTestReport = "Data Collection results\n"; // string containig the test results
  301. // Data Collection Object (DC OBj) related variables.
  302. //
  303. var objDataColl; // The Data Collection object.
  304. var strDataSpecFile; // The dataspec.xml file.
  305. // constant declarations according to DC Obj Status property
  306. //
  307. var DC_NOTACTIVE = 0;
  308. var DC_COLLECTING = 1;
  309. var DC_FAILED = 2;
  310. var DC_COMPLETED = 3;
  311. var DC_NODELTA = 4;
  312. var DC_COMPARING = 5;
  313. // System Folders.
  314. //
  315. var strWindowsTempDir;
  316. var strMachineFileName;
  317. var strLogFile;
  318. var g_iFileSize = 0;
  319. var g_iSentCtr = 0;
  320. var g_iRecvdCtr = 0;
  321. var g_szFileName = null;
  322. var g_szChannelId = null;
  323. var fso = null;
  324. var fileHandle = null;
  325. var file = null;
  326. var tFileName = null;
  327. var tProgBarCounter = 0;
  328. var tFileSize = 0;
  329. //*****************************************************************************
  330. //
  331. // InitiateRCSession: Initiates the RC Session
  332. //
  333. function InitiateRCSession()
  334. {
  335. SetUIForChat();
  336. g_bNewBinaries = true;
  337. if(null == g_oSAFRemoteDesktopSession)
  338. {
  339. alert( L_ERRNULLRCSESSION );
  340. }
  341. else
  342. {
  343. var x;
  344. try
  345. {
  346. if (false == g_bNewBinaries)
  347. {
  348. //
  349. // Using Old interface
  350. //
  351. //
  352. // Add the chat channel
  353. //
  354. g_oSAFRemoteDesktopSession.AddChannels( c_szChatChannelID );
  355. //
  356. // Add the control channel
  357. //
  358. g_oSAFRemoteDesktopSession.AddChannels( c_szControlChannelID );
  359. //
  360. // Bind OnChannelDataReady callback
  361. //
  362. g_oSAFRemoteDesktopSession.OnChannelDataReady = function(channelID)
  363. { OnChannelDataReadyEvent(channelID); }
  364. }
  365. else
  366. {
  367. //
  368. // Use new interface
  369. //
  370. //
  371. // Get the Channel Manager
  372. //
  373. //alert("Getting ChannelManager");
  374. g_oSAFRemoteDesktopChannelMgr = g_oSAFRemoteDesktopSession.ChannelManager;
  375. //
  376. // Open the Chat channel
  377. //
  378. //alert("Opening ChatChannel");
  379. g_oChatChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( c_szChatChannelID );
  380. //
  381. // Open the Control Channel
  382. //
  383. //alert("Opening Control Channel");
  384. g_oControlChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( c_szControlChannelID );
  385. //
  386. // Setup the ChannelDataReady handlers
  387. //
  388. //alert("Binding Events");
  389. g_oChatChannel.OnChannelDataReady = function()
  390. { ChatChannelDataReadyEvent(); }
  391. g_oControlChannel.OnChannelDataReady = function()
  392. { ControlChannelDataReadyEvent(); }
  393. HideChat.value = L_HIDECHAT;
  394. }
  395. }
  396. catch(x)
  397. {
  398. // no big deal ... it just means that the channel was added
  399. // by a previous instance.
  400. }
  401. //
  402. // Setup the OnDisconnected event callback
  403. //
  404. g_oSAFRemoteDesktopSession.OnDisconnected = function()
  405. { OnClientDisconnected(); }
  406. }
  407. try
  408. {
  409. //
  410. // Also, Enable Remote Control
  411. //
  412. //alert("Enabling Remote Control");
  413. EnableRemoteControl();
  414. //
  415. // Transmit screen resolution to Expert, so that
  416. // he has the right screen size to see in the RC Tool
  417. //
  418. //alert("Transmitting screen info");
  419. TransmitScreenInfo();
  420. StatusID.innerText = c_szCHATMODE;
  421. }
  422. catch(error)
  423. {
  424. alert(error);
  425. }
  426. }
  427. //
  428. // TransmitScreenInfo: Sends the user's screen resolution to the expert
  429. //
  430. function TransmitScreenInfo()
  431. {
  432. var Doc = null;
  433. var RCCommand = null;
  434. try
  435. {
  436. //
  437. // Create an XML document
  438. //
  439. Doc = new ActiveXObject("microsoft.XMLDOM");
  440. //
  441. // Create the RCCOMMAND root node
  442. //
  443. RCCommand = Doc.createElement( c_szRCCommand );
  444. //
  445. // Set the NAME attribute to SCREENINFO
  446. //
  447. RCCommand.setAttribute( c_szRCCommandName, c_szScreenInfo );
  448. //
  449. // Set the WIDTH attribute
  450. //
  451. RCCommand.setAttribute( c_szWidth, screen.width );
  452. //
  453. // Set the HEIGHT attribute
  454. //
  455. RCCommand.setAttribute( c_szHeight, screen.height );
  456. //
  457. // Set the COLORDEPTH attribute
  458. //
  459. RCCommand.setAttribute( c_szColorDepth, screen.colorDepth );
  460. //
  461. // Send the XML across
  462. //
  463. if (false == g_bNewBinaries)
  464. {
  465. //
  466. // Using Old interface
  467. //
  468. g_oSAFRemoteDesktopSession.SendChannelData( c_szControlChannelID, RCCommand.xml );
  469. }
  470. else
  471. {
  472. //
  473. // Use new interface
  474. //
  475. g_oControlChannel.SendChannelData( RCCommand.xml );
  476. }
  477. }
  478. catch(error)
  479. {
  480. alert( error );
  481. }
  482. }
  483. //
  484. // EnableRemoteControl: This routine enables remote control
  485. //
  486. function EnableRemoteControl()
  487. {
  488. if(null != g_oSAFRemoteDesktopSession)
  489. {
  490. if (false == g_bNewBinaries)
  491. {
  492. //
  493. // Using Old interface
  494. //
  495. g_oSAFRemoteDesktopSession.EnableRemoteControl( "" );
  496. }
  497. else
  498. {
  499. //
  500. // Use the new interface
  501. //
  502. //alert("remote control permissions: ");
  503. //alert("Existing: " + g_oSAFRemoteDesktopSession.SharingClass);
  504. g_oSAFRemoteDesktopSession.SharingClass = CONTROLDESKTOP_PERMISSION_NOT_REQUIRE;
  505. }
  506. }
  507. }
  508. //
  509. // DisableRemoteControl: Routine to disable Remote Control
  510. //
  511. function DisableRemoteControl()
  512. {
  513. if(null != g_oSAFRemoteDesktopSession)
  514. {
  515. if (false == g_bNewBinaries)
  516. {
  517. //
  518. // Using Old interface
  519. //
  520. g_oSAFRemoteDesktopSession.DisableRemoteControl( "" );
  521. }
  522. else
  523. {
  524. //
  525. // Use the new interface
  526. //
  527. g_oSAFRemoteDesktopSession.RemoteControlPermissions = NO_DESKTOP_SHARING;
  528. }
  529. }
  530. }
  531. //
  532. // AbortConnection: Routine that disconnects the session
  533. //
  534. function AbortConnection()
  535. {
  536. if (false == g_bNewBinaries)
  537. {
  538. //
  539. // Using Old interface
  540. //
  541. if (g_oSAFRemoteDesktopSession != null)
  542. {
  543. g_oSAFRemoteDesktopSession.StopListening();
  544. }
  545. //
  546. // Remove the chat channel
  547. //
  548. g_oSAFRemoteDesktopSession.RemoveChannels( c_szChatChannelID );
  549. //
  550. // Remove the control channel
  551. //
  552. g_oSAFRemoteDesktopSession.RemoveChannels( c_szControlChannelID );
  553. }
  554. else
  555. {
  556. //
  557. // Using New interfaces
  558. //
  559. //
  560. // Disconnect the connection to Helper, if the connection is broken by the Helpee
  561. //
  562. if(true == g_bUserDisconnect)
  563. {
  564. DisconnectRC();
  565. }
  566. }
  567. //
  568. // Close this window
  569. //
  570. //window.close();
  571. //
  572. // Close the session
  573. //
  574. //alert("Closing Session");
  575. try
  576. {
  577. g_oSAFRemoteDesktopSession.CloseRemoteDesktopSession();
  578. }
  579. catch(error)
  580. {
  581. alert(error);
  582. }
  583. parent.navigate( c_szHomePage );
  584. return;
  585. }
  586. //
  587. // SendChatButtonHandler: Routine to send chat data
  588. //
  589. function SendChatButtonHandler()
  590. {
  591. if (g_oSAFRemoteDesktopSession != null)
  592. {
  593. if (StatusID.innerText == c_szCHATMODE)
  594. {
  595. //
  596. // If We are in Chat Mode. Only then send the data across
  597. //
  598. if (false == g_bNewBinaries)
  599. {
  600. //
  601. // Using Old interface
  602. //
  603. //
  604. // Send data on the chat channel
  605. //
  606. g_oSAFRemoteDesktopSession.SendChannelData(c_szChatChannelID, chatText.value);
  607. }
  608. else
  609. {
  610. //
  611. // Use the new interface
  612. //
  613. g_oChatChannel.SendChannelData( chatText.value );
  614. }
  615. //
  616. // Update user's chat history window
  617. //
  618. incomingChatText.value = incomingChatText.value + L_cszUserID + chatText.value;
  619. }
  620. else
  621. {
  622. //
  623. // This is remote control Mode
  624. //
  625. //
  626. // Update user's chat history window
  627. //
  628. incomingChatText.value = incomingChatText.value + "\n> " + chatText.value;
  629. }
  630. //
  631. // Clear up the chat message window
  632. //
  633. chatText.value="";
  634. incomingChatText.doScroll("scrollbarPageDown");
  635. }
  636. }
  637. //
  638. // OnChannelDataReadyEvent: Call back to handle data from expert
  639. //
  640. function OnChannelDataReadyEvent(channelID)
  641. {
  642. var str = null;
  643. if (channelID == c_szChatChannelID)
  644. {
  645. //
  646. // Data on chat channel
  647. //
  648. str = g_oSAFRemoteDesktopSession.ReceiveChannelData(channelID)
  649. //
  650. // Update chat history window with incoming data
  651. //
  652. incomingChatText.value = incomingChatText.value + L_cszExpertID + str;
  653. incomingChatText.doScroll("scrollbarPageDown");
  654. }
  655. else if (channelID == c_szControlChannelID)
  656. {
  657. //
  658. // Incoming data on the control channel
  659. //
  660. }
  661. }
  662. //
  663. // ChatChannelDataReadyEvent: Call back to handle data from expert
  664. //
  665. function ChatChannelDataReadyEvent()
  666. {
  667. var str = null;
  668. //
  669. // Data on chat channel
  670. //
  671. str = g_oChatChannel.ReceiveChannelData();
  672. //
  673. // Update chat history window with incoming data
  674. //
  675. incomingChatText.value = incomingChatText.value + L_cszExpertID + str;
  676. incomingChatText.doScroll("scrollbarPageDown");
  677. return;
  678. }
  679. //
  680. // ControlChannelDataReadyEvent: Call back to handle data from expert
  681. //
  682. function ControlChannelDataReadyEvent()
  683. {
  684. var str = null;
  685. //
  686. // Data on control channel
  687. //
  688. str = g_oControlChannel.ReceiveChannelData();
  689. //
  690. // Parse the data sent on the control channel
  691. //
  692. ParseControlData ( str );
  693. return;
  694. }
  695. //
  696. // ParseControlData: Parse the data sent on the control channel
  697. //
  698. function ParseControlData ( str )
  699. {
  700. var Doc = new ActiveXObject("microsoft.XMLDOM");
  701. var RCCommand = null;
  702. var szCommandName = null;
  703. try
  704. {
  705. if( false == Doc.loadXML( str ))
  706. {
  707. alert ( L_ERRLOADXMLFAIL_MSG );
  708. }
  709. if ( Doc.parseError.reason != "")
  710. {
  711. alert( Doc.parseError.reason);
  712. }
  713. //
  714. // Get the RCCOMMAND node
  715. //
  716. RCCommand = Doc.documentElement;
  717. //
  718. // Get the NAME of the command
  719. //
  720. szCommandName = RCCommand.getAttribute( c_szRCCommandName );
  721. if( szCommandName == c_szFileXfer )
  722. {
  723. //
  724. // File Transfer Initiation
  725. //
  726. var vArgs = new Array(6);
  727. var FileXferWidth = "600";
  728. var FileXferHeight = "500";
  729. vArgs[0] = 1; // Destination Mode
  730. vArgs[1] = g_oControlChannel; // Control Channel
  731. vArgs[2] = g_oSAFRemoteDesktopChannelMgr; // Channel Manager
  732. vArgs[3] = RCCommand.getAttribute( c_szFileName ); // FILENAME
  733. vArgs[4] = RCCommand.getAttribute( c_szFileSize ); // FILESIZE
  734. vArgs[5] = RCCommand.getAttribute( c_szChannelId ); // CHANNELID
  735. window.showModelessDialog("../RCExpert/RCFileXfer.htm", vArgs, "dialogwidth:" + FileXferWidth + "px;dialogHeight:" + FileXferHeight + "px;status:no;resizable:yes");
  736. }
  737. else if ( szCommandName == c_szRemoteCtrlStart )
  738. {
  739. //
  740. // Remote Control initiation
  741. //
  742. //
  743. // Change mode display to "Remote control"
  744. //
  745. StatusID.innerText = c_szRCMODE;
  746. incomingChatText.value = L_USECHATBOX_MSG;
  747. FileXferId.disabled = true;
  748. //AbortConnection.disabled = true;
  749. }
  750. else if ( szCommandName == c_szRemoteCtrlEnd )
  751. {
  752. //
  753. // End of Remote Control
  754. //
  755. //
  756. // Change mode display to "chat"
  757. //
  758. StatusID.innerText = c_szCHATMODE;
  759. incomingChatText.value = "";
  760. FileXferId.disabled = false;
  761. //AbortConnection.disabled = false;
  762. }
  763. else if ( szCommandName == c_szRemoteDataCollection )
  764. {
  765. //
  766. // File Transfer for remote data collection Initiation
  767. //
  768. var RDCMode = RCCommand.getAttribute( c_szRemoteDataCollectMode ) ;
  769. //alert(" the mode received is : " + RDCMode);
  770. g_szFileName = RCCommand.getAttribute( c_szFileName ); // FILENAME
  771. //alert( "filename :"+ g_szFileName );
  772. g_iFileSize = RCCommand.getAttribute( c_szFileSize ); // FILESIZE
  773. //alert( "filesize :"+ g_iFileSize );
  774. g_szChannelId = RCCommand.getAttribute( c_szChannelId ); // CHANNELID
  775. //alert( "ChannelId :"+ g_szChannelId );
  776. if ( c_szRDCRequest == RDCMode )
  777. {
  778. //alert("Creating the pchealth object from chatserver.htm");
  779. try {
  780. objDataColl = pchealth.CreateObject_DataCollection(); // data collection object
  781. }
  782. catch(err)
  783. {
  784. alert("Unable to create Data Collection object: " + err );
  785. }
  786. //
  787. // File Transfer destination mode UI
  788. //
  789. ChatServer.style.visibility = "hidden";
  790. RemoteDataCollectionSrc.style.visibility = "hidden";
  791. RemoteDataCollectionDestn.style.visibility = "visible";
  792. Action.innerText = "Receiving File :";
  793. RemoteDataCollectedDestn.style.visibility = "hidden";
  794. FileSizeSrcId.style.visibility = "hidden";
  795. FileSizeDestnId.style.visibility = "visible";
  796. //
  797. // Update filename and filesize in UI
  798. //
  799. //alert("FileNameId.innerText = g_szFileName");
  800. FileNameId.innerText = g_szFileName;
  801. g_iRecvdCtr = 0;
  802. FileSizeDestnId.style.visibility = "visible";
  803. tProgBarCounter = Math.ceil(g_iFileSize/c_MAXFILEXFERSIZE);
  804. try
  805. {
  806. //
  807. // Create the data channel for file transfer if necessary
  808. //
  809. if(null == g_oDataChannel)
  810. {
  811. //alert(" Initialising the data channel if necessary");
  812. g_oDataChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( g_szChannelId );
  813. //alert(" Created the data channel");
  814. //
  815. // Bind the OnChannelDataReady event handler
  816. //
  817. g_oDataChannel.OnChannelDataReady = function()
  818. { DestnDataChannelDataCollectHandler(); }
  819. //alert(" Associated a func. with the channeldataready event");
  820. }
  821. }
  822. catch(error)
  823. {
  824. alert( L_ERRFAILDATACHANNELCREATION_MSG );
  825. //
  826. // Todo: Add code to handle error here
  827. //
  828. }
  829. //
  830. // Create temp file for staging while file is XFered
  831. //
  832. alert(" Creation of file object");
  833. fso = new ActiveXObject("Scripting.FileSystemObject");
  834. var tFolder = fso.GetSpecialFolder(0); // Get Path to system config directory.
  835. tFileName = tFolder + "\\temp\\" + g_szFileName;
  836. //alert( "Create text file tFileName: " + tFileName );
  837. try {
  838. fileHandle = fso.CreateTextFile( tFileName );
  839. }
  840. catch(err)
  841. {
  842. alert("In mode 1, " + err );
  843. }
  844. //
  845. // Send ACK to source to make it begin pumping data on the data channel
  846. //
  847. //alert(" Sending ACK");
  848. if ( null != g_oDataChannel )
  849. {
  850. g_oDataChannel.SendChannelData( c_szFileXferACK );
  851. }
  852. else
  853. {
  854. alert("Problem in initialising the datachannel");
  855. }
  856. }
  857. }
  858. }
  859. catch(error)
  860. {
  861. alert( error );
  862. }
  863. }
  864. function OnClientConnected() {
  865. StatusID.innerText = c_szCHATMODE;
  866. }
  867. function OnClientDisconnected() {
  868. StatusID.innerText = L_EXPERTDISCONNECT_MSG ;
  869. g_bUserDisconnect = false;
  870. AbortConnection();
  871. }
  872. function OnEnter()
  873. {
  874. if (window.event.keyCode == 13)
  875. {
  876. SendChatButtonHandler();
  877. }
  878. }
  879. //
  880. // HideChatBox: Toggles the chat box controls
  881. //
  882. function HideChatBox()
  883. {
  884. if(false == g_bChatBoxHidden)
  885. {
  886. //
  887. // Chatbox is visible. Hide it
  888. //
  889. chatText.style.visibility = "hidden";
  890. sendChatButton.style.visibility = "hidden";
  891. incomingChatText.style.visibility = "hidden";
  892. g_bChatBoxHidden = true;
  893. HideChat.value = L_SHOWCHAT;
  894. }
  895. else
  896. {
  897. //
  898. // Chatbox is Hidden. Show it
  899. //
  900. chatText.style.visibility = "visible";
  901. sendChatButton.style.visibility = "visible";
  902. incomingChatText.style.visibility = "visible";
  903. g_bChatBoxHidden = false;
  904. HideChat.value = L_HIDECHAT;
  905. }
  906. }
  907. //
  908. // Disconnect: Disconnects the RC Connection made by Expert
  909. //
  910. function DisconnectRC()
  911. {
  912. var Doc = null;
  913. var RCCommand = null;
  914. try
  915. {
  916. //
  917. // Create an XML document
  918. //
  919. Doc = new ActiveXObject("microsoft.XMLDOM");
  920. //
  921. // Create the RCCOMMAND root node
  922. //
  923. RCCommand = Doc.createElement( c_szRCCommand );
  924. //
  925. // Set the NAME attribute to DISCONNECTRC
  926. //
  927. RCCommand.setAttribute( c_szRCCommandName, c_szDisconnectRC );
  928. //
  929. // Send the XML across
  930. //
  931. if (false == g_bNewBinaries)
  932. {
  933. //
  934. // Using Old interface
  935. //
  936. g_oSAFRemoteDesktopSession.SendChannelData( c_szControlChannelID, RCCommand.xml );
  937. }
  938. else
  939. {
  940. //
  941. // Use new interface
  942. //
  943. g_oControlChannel.SendChannelData( RCCommand.xml );
  944. }
  945. }
  946. catch(error)
  947. {
  948. alert( error );
  949. }
  950. }
  951. var g_iChannelId = 1000;
  952. //
  953. // LaunchFileXfer: Launches the File Xfer UI
  954. //
  955. function LaunchFileXfer( mode )
  956. {
  957. var vArgs = new Array(4);
  958. var FileXferWidth = "600";
  959. var FileXferHeight = "500";
  960. if(0 == mode)
  961. {
  962. vArgs[0] = mode; // Source Mode
  963. vArgs[1] = g_oControlChannel; // Control Channel
  964. vArgs[2] = g_oSAFRemoteDesktopChannelMgr; // Channel Manager
  965. vArgs[3] = g_iChannelId++; // Channel ID
  966. window.showModelessDialog("../RCExpert/RCFileXfer.htm", vArgs, "dialogwidth:" + FileXferWidth + "px;dialogHeight:" + FileXferHeight + "px;status:no;resizable:yes");
  967. }
  968. return;
  969. }
  970. //********************************************************************************
  971. // For data collection.
  972. //********************************************************************************
  973. //*****************************************************************************//
  974. // creates a DC Obj and initialize its members.
  975. //
  976. function constructor()
  977. {
  978. if ( null != fso )
  979. {
  980. // if BVT success notification file exists, delete it.
  981. //
  982. //alert("Inside the constructor");
  983. if ( null != objDataColl )
  984. {
  985. //alert("Creation of Data Collection Object already done");
  986. }
  987. //alert("Setup of Machine Data property ");
  988. objDataColl.MachineData_DataSpec = strDataSpecFile;
  989. //alert("Registering For Event Notification ");
  990. objDataColl.onStatusChange = dc_onStatusChange;
  991. objDataColl.onProgress = dc_onProgress;
  992. objDataColl.onComplete = dc_onComplete;
  993. }
  994. }
  995. function dc_onStatusChange( dcObj, Status )
  996. {
  997. }
  998. function dc_onProgress( dcObj, lDone, lTotal )
  999. {
  1000. }
  1001. function dc_onComplete( dcObj, hResult )
  1002. {
  1003. // Print the asynchronous execution result
  1004. // if succeeded, try to save the data
  1005. //
  1006. if ( hResult == 0 )
  1007. {
  1008. var strmMachine; // file streams
  1009. // Asynchronous Data Collection Execution PASSed
  1010. //
  1011. // get dataspec file name
  1012. //
  1013. strMachineFileName = strWindowsTempDir + "\\machineDATA.xml";
  1014. alert("The file to look out for is : " + strMachineFileName);
  1015. // alert("Getting file stream for machine data ");
  1016. strmMachine = dcObj.MachineData_GetStream();
  1017. if( strmMachine == null )
  1018. {
  1019. alert("file stream for machine data FAIL");
  1020. }
  1021. else
  1022. {
  1023. //alert("file stream for machine data PASS");
  1024. if( fso.FileExists( strMachineFileName ) )
  1025. {
  1026. alert("delete the file if it exist");
  1027. fso.DeleteFile( strMachineFileName );
  1028. }
  1029. alert("Attempting to save machine data ");
  1030. try {
  1031. pchealth.CopyStreamToFile( strMachineFileName , strmMachine );
  1032. }
  1033. catch(error)
  1034. {
  1035. alert("Unablr to copy to the file :" + error );
  1036. }
  1037. if( fso.FileExists(strMachineFileName) )
  1038. {
  1039. //alert("Data saved!");
  1040. }
  1041. else
  1042. {
  1043. }
  1044. }
  1045. // Reset UI for sending the data collected.
  1046. //
  1047. // File Transfer destination mode
  1048. //
  1049. ResetUIForRDC();
  1050. // send the data across.
  1051. alert("Sending the " + strMachineFileName + "across");
  1052. SendDataCollected( strMachineFileName );
  1053. }
  1054. else
  1055. {
  1056. // Asynchronous Data Collection Execution FAILed
  1057. //
  1058. alert("Asynchronous Data Collection Execution FAILed");
  1059. }
  1060. // Lets clean up the system (remove temporary files) but don't unload the page
  1061. //
  1062. cleanUp();
  1063. }
  1064. // get the HelpCtr System subdirectories to store temporarily this htm page for the BVT
  1065. // and also get the Config subdir to get the dataspec.xml file from.
  1066. //
  1067. function getHelpCtrDirs()
  1068. {
  1069. var WindowsDir = fso.GetSpecialFolder(0);
  1070. //alert("WindowsDir is " + WindowsDir);
  1071. strWindowsTempDir = WindowsDir + "\\temp";
  1072. strLogFile = strWindowsTempDir + "\\DCObjRDC.log";
  1073. }
  1074. // Prints a message in the html page and update the log file
  1075. //
  1076. function Print( line )
  1077. {
  1078. var strTemp = line.toUpperCase(); // temporary string
  1079. var iStringMaxLength = 42;
  1080. // if not a end line message like "PASS<BR>" add dots at the end of message
  1081. //
  1082. if( strTemp.search("<BR>") == -1 )
  1083. {
  1084. var iAddDots = iStringMaxLength - line.length;
  1085. iMessageCount++;
  1086. for( i = 0; i < iAddDots; i++ )
  1087. {
  1088. line += ".";
  1089. }
  1090. line = iMessageCount + ". " + line;
  1091. }
  1092. var regExpression = /<BR>/g;
  1093. strTestReport += line;
  1094. strTestReport = strTestReport.replace(regExpression, "\n");
  1095. // create the log file, if already done, overwrite it
  1096. //
  1097. var strmLogFile = fso.CreateTextFile( strLogFile , true ); // A stream to the log file.
  1098. strmLogFile.WriteLine(strTestReport);
  1099. strmLogFile.Close();
  1100. out.innerHTML += line;
  1101. }
  1102. // delete data collection files
  1103. //
  1104. function cleanUp()
  1105. {
  1106. // stops data collection if in progress and release the DC Obj.
  1107. //
  1108. if( objDataColl != null && objDataColl.Satus != DC_COLLECTING )
  1109. { objDataColl.Abort(); }
  1110. }
  1111. // close this page and clens up any garbagr the script has generated
  1112. //
  1113. function closeWindow()
  1114. {
  1115. try
  1116. {
  1117. // Print( "<BR>Closing window<BR>" );
  1118. pchealth.Close();
  1119. }
  1120. catch(exception)
  1121. {
  1122. //Print( "Caught exception " + exception + " in closing window<BR>" );
  1123. }
  1124. }
  1125. function ResetUIForRDC()
  1126. {
  1127. //alert("Reseting the UI for sending the data collected");
  1128. RemoteDataCollectionSrc.style.visibility = "hidden";
  1129. RemoteDataCollectionDestn.style.visibility = "hidden";
  1130. RemoteDataCollectedDestn.style.visibility = "visible";
  1131. FileSizeColDestnId.style.visibility = "visible";
  1132. tProgBarCounter = Math.ceil(g_iFileSize/c_MAXFILEXFERSIZE);
  1133. }
  1134. function SetUIForChat()
  1135. {
  1136. ChatServer.style.visibility = "visible";
  1137. RemoteDataCollectionSrc.style.visibility = "hidden";
  1138. RemoteDataCollectionDestn.style.visibility = "hidden";
  1139. RemoteDataCollectedDestn.style.visibility = "hidden";
  1140. FileSizeSrcId.style.visibility = "hidden";
  1141. FileSizeDestnId.style.visibility = "hidden";
  1142. FileSizeColDestnId.style.visibility = "hidden";
  1143. }
  1144. //**************************************************************************
  1145. // the data collection.
  1146. //**************************************************************************
  1147. function CollectData()
  1148. {
  1149. // alert("Getting the helpctr directories");
  1150. getHelpCtrDirs();
  1151. // alert("Getting the dataspec.xml file");
  1152. var tFolder = fso.GetSpecialFolder(0); // Get Path to system config directory.
  1153. tFileName = tFolder + "\\temp\\" + g_szFileName;
  1154. strDataSpecFile = tFileName;
  1155. // alert("strDataSpecFile : " + strDataSpecFile);
  1156. constructor(); // initialize object and properties.
  1157. alert("Executing Asynchronous Data Collection ");
  1158. try {
  1159. Action.innerText = "Executing the following script to collect data :";
  1160. objDataColl.ExecuteAsync();
  1161. }
  1162. catch(err) {
  1163. alert("executeaync as usual fails" + err);
  1164. }
  1165. }
  1166. //********************************************************************************
  1167. //
  1168. // onSend: This routine is fired when the "Send File" button is clicked
  1169. //
  1170. function onSend()
  1171. {
  1172. var fileName = attfile.value;
  1173. var ForReading = 1, ForWriting = 2, ForAppending = 8;
  1174. var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
  1175. var Doc = null;
  1176. var RCCommand = null;
  1177. //
  1178. // Open the File for reading
  1179. //
  1180. try
  1181. {
  1182. //
  1183. // Create the filesystem object
  1184. //
  1185. fso = new ActiveXObject("Scripting.FileSystemObject");
  1186. //
  1187. // Open the file
  1188. //
  1189. file = fso.GetFile(fileName);
  1190. fileHandle = file.OpenAsTextStream(ForReading,TristateUseDefault);
  1191. }
  1192. catch(error)
  1193. {
  1194. alert( L_ERROPENINGFILEFORREAD_MSG + fileName );
  1195. }
  1196. //
  1197. // Initiate File Xfer
  1198. //
  1199. try
  1200. {
  1201. //
  1202. // Create an XML document
  1203. //
  1204. Doc = new ActiveXObject("microsoft.XMLDOM");
  1205. }
  1206. catch (err)
  1207. {
  1208. alert("new object: " + err);
  1209. }
  1210. try {
  1211. //
  1212. // Create the RCCOMMAND root node
  1213. //
  1214. RCCommand = Doc.createElement( c_szRCCommand );
  1215. }
  1216. catch (err)
  1217. {
  1218. alert("create element :" + err);
  1219. }
  1220. try {
  1221. //
  1222. // Set the NAME attribute to FILEXFER
  1223. //
  1224. RCCommand.setAttribute( c_szRCCommandName, c_szRemoteDataCollection );
  1225. }
  1226. catch (err)
  1227. {
  1228. alert("setAttribute for datacollection :" + err);
  1229. }
  1230. try {
  1231. //
  1232. // Set the DATA COLLECTION MODE attribute
  1233. //
  1234. RCCommand.setAttribute( c_szRemoteDataCollectMode, c_szRDCRequest );
  1235. }
  1236. catch (err)
  1237. {
  1238. alert("set attribute for RDCRequest: " + err );
  1239. }
  1240. try {
  1241. //
  1242. // Set the FILENAME attribute
  1243. //
  1244. RCCommand.setAttribute( c_szFileName, file.Name );
  1245. }
  1246. catch(err)
  1247. {
  1248. alert("set attribute file name :" + err);
  1249. }
  1250. try {
  1251. //
  1252. // Set the FILESIZE attribute
  1253. //
  1254. RCCommand.setAttribute( c_szFileSize, file.size );
  1255. }
  1256. catch(err)
  1257. {
  1258. alert("set attribute for file size : " + err );
  1259. }
  1260. try {
  1261. //
  1262. // Set the CHANNELID attribute
  1263. //
  1264. // alert( " channel id is : " + g_iChannelId );
  1265. RCCommand.setAttribute( c_szChannelId, g_iChannelId );
  1266. }
  1267. catch(err)
  1268. {
  1269. alert("set attribute channel id: " + err);
  1270. }
  1271. try {
  1272. //
  1273. // Send the XML across
  1274. //
  1275. // alert("the xml sent across is :" + RCCommand.xml);
  1276. g_oControlChannel.SendChannelData( RCCommand.xml );
  1277. }
  1278. catch(error)
  1279. {
  1280. alert ( L_ERRFILEXFERINITFAILED_MSG );
  1281. }
  1282. //
  1283. // Create the data channel for Filetransfer
  1284. //
  1285. try
  1286. {
  1287. if(null == g_oDataChannel)
  1288. {
  1289. // alert("The data channel is null");
  1290. }
  1291. if ( null == g_oDataChannel )
  1292. {
  1293. g_oDataChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( g_iChannelId );
  1294. }
  1295. }
  1296. catch(error)
  1297. {
  1298. alert( L_ERRFAILDATACHANNELCREATION_MSG );
  1299. }
  1300. try
  1301. {
  1302. if(null != g_oDataChannel)
  1303. {
  1304. //
  1305. // Bind the OnChannelDataReady event handler
  1306. //
  1307. g_oDataChannel.OnChannelDataReady = function()
  1308. { SrcDataChannelDataReadyHandler(); }
  1309. }
  1310. }
  1311. catch(error)
  1312. {
  1313. alert( "Problem in binding the handler");
  1314. }
  1315. //
  1316. // Enable progress bar
  1317. //
  1318. FileSizeSrcId.style.visibility = "visible";
  1319. return;
  1320. }
  1321. //
  1322. // SrcDataChannelDataReadyHandler: Fired when file Xfer src receives data from
  1323. // the file Xfer destn on the data channel
  1324. //
  1325. function SrcDataChannelDataReadyHandler()
  1326. {
  1327. //alert("Start sending data");
  1328. //
  1329. // Start sending data
  1330. //
  1331. SendFileData();
  1332. //
  1333. // We are done. Close the window
  1334. //
  1335. window.close();
  1336. //
  1337. // Create the data channel for Data transfer
  1338. //
  1339. try
  1340. {
  1341. if(null == g_oDataChannelRDC)
  1342. {
  1343. // g_szChannelId;
  1344. Mode = 2;
  1345. g_oDataChannelRDC = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( g_szChannelId );
  1346. //
  1347. // Bind the OnChannelDataReady event handler
  1348. //
  1349. g_oDataChannelRDC.OnChannelDataReady = function()
  1350. { DestnDataChannelDataReadyHandler(); }
  1351. }
  1352. }
  1353. catch(error)
  1354. {
  1355. alert( L_ERRFAILDATACHANNELCREATION_MSG );
  1356. }
  1357. return;
  1358. }
  1359. //
  1360. // SendFileData: Sends currently open file to destination
  1361. //
  1362. function SendFileData()
  1363. {
  1364. var stream = null;
  1365. if ( fileHandle!= null )
  1366. {
  1367. //
  1368. // Enable display of file xfer status in the UI
  1369. //
  1370. FileSizeSrcId.style.visibility = "visible";
  1371. g_iSentCtr = 0;
  1372. //
  1373. // While there is data to send
  1374. //
  1375. tProgBarCounter = Math.ceil((file.size)/c_MAXFILEXFERSIZE);
  1376. tFileSize = file.size;
  1377. while (!fileHandle.AtEndOfStream)
  1378. {
  1379. try
  1380. {
  1381. stream = null;
  1382. //
  1383. // Read File
  1384. //
  1385. stream = fileHandle.Read( c_MAXFILEXFERSIZE );
  1386. //
  1387. // Update UI
  1388. //
  1389. g_iSentCtr+= stream.length;
  1390. //
  1391. // Send data over the data channel
  1392. //
  1393. g_oDataChannel.SendChannelData( stream );
  1394. //alert("Sent data");
  1395. if ( tProgBarCounter > 0 )
  1396. {
  1397. ProgressBar2.Value = (100/tProgBarCounter);
  1398. tProgBarCounter--;
  1399. }
  1400. }
  1401. catch(error)
  1402. {
  1403. alert( L_ERRDATACHANNELSEND_MSG );
  1404. }
  1405. }
  1406. alert("The End of file has been reached with size " + g_iSentCtr);
  1407. if ( g_iSentCtr != tFileSize )
  1408. {
  1409. g_oDataChannel.SendChannelData( c_szFileEND );
  1410. }
  1411. //
  1412. // Close the file
  1413. //
  1414. fileHandle.Close();
  1415. }
  1416. else
  1417. {
  1418. alert( L_ERRINVALIDFILEHANDLE_MSG );
  1419. }
  1420. return;
  1421. }
  1422. function DestnDataChannelDataCollectHandler()
  1423. {
  1424. var str = null;
  1425. // alert("Recvd data");
  1426. //
  1427. // receiving incoming data
  1428. //
  1429. str = g_oDataChannel.ReceiveChannelData();
  1430. // alert(str);
  1431. if ( c_szFileXferACK != str )
  1432. {
  1433. //
  1434. // Update UI
  1435. //
  1436. g_iRecvdCtr += str.length;
  1437. //
  1438. // Write str to open temp file
  1439. //
  1440. fileHandle.Write( str );
  1441. // alert("g_iRecvdCtr :" + g_iRecvdCtr );
  1442. if ( tProgBarCounter > 0 )
  1443. {
  1444. ProgressBar1.Value = (100/tProgBarCounter);
  1445. tProgBarCounter--;
  1446. }
  1447. //
  1448. // If g_iRecvdCtr == g_iFileSize;
  1449. // - launch File Open/Save dialog
  1450. // - close data connection
  1451. if( g_iRecvdCtr == g_iFileSize )
  1452. {
  1453. // alert( "File received" );
  1454. //
  1455. // Close open temp file handle
  1456. //
  1457. fileHandle.Close();
  1458. // run the script. collect data in a file.
  1459. CollectData();
  1460. }
  1461. }
  1462. else
  1463. {
  1464. // alert("Sending the data file");
  1465. SendFileData();
  1466. SetUIForChat();
  1467. }
  1468. return;
  1469. }
  1470. //
  1471. // SendDataCollected: This routine is fired when the "Send File" button is clicked
  1472. //
  1473. function SendDataCollected( filename )
  1474. {
  1475. var fileName = filename;
  1476. var ForReading = 1, ForWriting = 2, ForAppending = 8;
  1477. var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
  1478. var Doc = null;
  1479. var RCCommand = null;
  1480. // alert("Inside the SendDataCollected func.");
  1481. //
  1482. // Open the File for reading
  1483. //
  1484. try
  1485. {
  1486. //
  1487. // Create the filesystem object
  1488. //
  1489. if ( null == fso )
  1490. {
  1491. fso = new ActiveXObject("Scripting.FileSystemObject");
  1492. }
  1493. //
  1494. // Open the file
  1495. //
  1496. // BUG:: The file size varies with the type of file being UNICODE or not.
  1497. // The type needs to be checked before opening it in any particular mode.
  1498. file = fso.GetFile(fileName);
  1499. fileHandle = file.OpenAsTextStream(ForReading,TristateTrue);
  1500. }
  1501. catch(error)
  1502. {
  1503. alert( L_ERROPENINGFILEFORREAD_MSG + fileName );
  1504. }
  1505. //
  1506. // Initiate File Xfer
  1507. //
  1508. try
  1509. {
  1510. //
  1511. // Create an XML document
  1512. //
  1513. Doc = new ActiveXObject("microsoft.XMLDOM");
  1514. //
  1515. // Create the RCCOMMAND root node
  1516. //
  1517. // alert("creating the RCCommand");
  1518. RCCommand = Doc.createElement( c_szRCCommand );
  1519. //
  1520. // Set the NAME attribute to FILEXFER
  1521. //
  1522. // alert("Set the attribute for command name :" + c_szRemoteDataCollection);
  1523. RCCommand.setAttribute( c_szRCCommandName, c_szRemoteDataCollection );
  1524. //
  1525. // Set the FILENAME attribute
  1526. //
  1527. // alert("Set the attribute filename name :" + file.Name);
  1528. RCCommand.setAttribute( c_szFileName, file.Name );
  1529. //
  1530. // Set the FILESIZE attribute
  1531. //
  1532. alert("Set the attribute filename size :" + file.size);
  1533. RCCommand.setAttribute( c_szFileSize, file.size );
  1534. //
  1535. // Set the CHANNELID attribute
  1536. //
  1537. // alert("Set the attribute channel id :" + g_szChannelId);
  1538. RCCommand.setAttribute( c_szChannelId, g_szChannelId );
  1539. //
  1540. // Set the RDC Mode
  1541. //
  1542. // alert("Set the attribute mode :" + c_szRDCResponse);
  1543. RCCommand.setAttribute( c_szRemoteDataCollectMode, c_szRDCResponse);
  1544. //
  1545. // Send the XML across
  1546. //
  1547. // alert("the text that's sent across: " + RCCommand.xml );
  1548. g_oControlChannel.SendChannelData( RCCommand.xml );
  1549. }
  1550. catch(error)
  1551. {
  1552. alert ( L_ERRFILEXFERINITFAILED_MSG );
  1553. }
  1554. //
  1555. // Create the data channel for Filetransfer
  1556. //
  1557. try
  1558. {
  1559. if(null == g_oDataChannel)
  1560. {
  1561. g_oDataChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( g_szChannelId );
  1562. //
  1563. // Bind the OnChannelDataReady event handler
  1564. //
  1565. g_oDataChannel.OnChannelDataReady = function()
  1566. { SrcDataChannelDataReadyHandler(); }
  1567. }
  1568. }
  1569. catch(error)
  1570. {
  1571. alert( L_ERRFAILDATACHANNELCREATION_MSG );
  1572. }
  1573. //
  1574. // Enable progress bar
  1575. //
  1576. FileSizeSrcId.style.visibility = "visible";
  1577. return;
  1578. }
  1579. //
  1580. // SrcDataChannelDataReadyHandler: Fired when file Xfer src receives data from
  1581. // the file Xfer destn on the data channel
  1582. //
  1583. function SrcDataChannelDataReadyHandler()
  1584. {
  1585. //alert("Start sending data");
  1586. //
  1587. // Start sending data
  1588. //
  1589. SendFileData();
  1590. return;
  1591. }
  1592. </SCRIPT>
  1593. </BODY>
  1594. </HTML>