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.

636 lines
14 KiB

  1. <%@ Language=JavaScript%>
  2. <!--
  3. RCFileXfer.htm: This is the Remote Control File transfer implementation.
  4. History:
  5. Rajesh Soy (nsoy), Sudha Srinivasan - created 07/18/2000
  6. Rajesh Soy (nsoy) - updated for new UI 08/18/2000
  7. -->
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  11. <meta http-equiv="Content-Language" content="en-us">
  12. <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
  13. <meta name="ProgId" content="FrontPage.Editor.Document">
  14. <title>Windows Remote Control File Transfer</title>
  15. <LINK id="UI_StyleSheet" REL="stylesheet" TYPE="text/css" HREF="../rcbuddy/rc.css">
  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_szFileXferREJECT = "FILEXFERREJECT";
  31. var c_MAXFILEXFERSIZE = 10240;
  32. //
  33. // Globals
  34. //
  35. var root = null;
  36. var vArgs = null
  37. var Mode = null;
  38. var g_oControlChannel = null;
  39. var g_oDataChannel = null;
  40. var g_oSAFRemoteDesktopChannelMgr = null;
  41. var g_iFileSize = 0;
  42. var g_iSentCtr = 0;
  43. var g_iRecvdCtr = 0;
  44. var g_szFileName = null;
  45. var g_szChannelId = null;
  46. var fso = null;
  47. var fileHandle = null;
  48. var file = null;
  49. var tFileName = null;
  50. var tProgBarCounter = 0;
  51. //
  52. // Error Messages
  53. //
  54. var L_ERRRCFILEXFERINITFAILS_MSG = "Initialization of RC File Xfer fails";
  55. var L_ERRFILEXFERINITFAILED_MSG = "Failed to initialize data channel for file transfer";
  56. var L_ERROPENINGFILEFORREAD_MSG = "Error Opening File for reading: ";
  57. var L_ERRFAILDATACHANNELCREATION_MSG = "Failed to Create Data Channel";
  58. var L_ERRDATACHANNELSEND_MSG = "Unable to send file on data channel";
  59. var L_ERRINVALIDFILEHANDLE_MSG = "Invalid File Handle";
  60. var L_ERRTEMPFILENAME_MSG = "Temp Filename not defined";
  61. var L_ERRNOTIMPL_MSG = "Not implemented";
  62. var L_SUCCESSFILEXFER_MSG = "File successfully transmitted";
  63. var L_REJECTFILEXFER_MSG = "Request for File transfer was rejected by buddy";
  64. //
  65. // InitFileXfer: Routine that initializes File Xfer and determines what
  66. // screen to show
  67. //
  68. function InitFileXfer()
  69. {
  70. try
  71. {
  72. vArgs = window.dialogArguments;
  73. Mode = vArgs[0]; // Mode=0: Source, Mode=1: Destination
  74. g_oControlChannel = vArgs[1];
  75. g_oSAFRemoteDesktopChannelMgr = vArgs[2];
  76. if( 0 == Mode)
  77. {
  78. //
  79. // File Transfer source mode
  80. //
  81. FileXFerSrc.style.visibility = "visible";
  82. FileXFerDestn.style.visibility = "hidden";
  83. g_szChannelId = vArgs[3];
  84. //alert("g_szChannelID: " + g_szChannelId);
  85. }
  86. else
  87. {
  88. //
  89. // File Transfer destination mode
  90. //
  91. //alert("Destination");
  92. FileXFerSrc.style.visibility = "hidden";
  93. FileXFerDestn.style.visibility = "visible";
  94. g_szFileName = vArgs[3]; // FILENAME
  95. g_iFileSize = vArgs[4]; // FILESIZE
  96. g_szChannelId = vArgs[5]; // CHANNELID
  97. //
  98. // Update filename and filesize in UI
  99. //
  100. FileNameId.innerText = g_szFileName;
  101. // RecvdCtrId.innerText = 0;
  102. g_iRecvdCtr = 0;
  103. // FileSizeId.innerText = g_iFileSize;
  104. //FileSizeDestnId.style.visibility = "visible";
  105. //tProgBarCounter = Math.ceil(g_iFileSize/c_MAXFILEXFERSIZE);
  106. //alert("Create data channel");
  107. try
  108. {
  109. //
  110. // Create the data channel for file transfer if necessary
  111. //
  112. if(null == g_oDataChannel)
  113. {
  114. g_oDataChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( g_szChannelId );
  115. //
  116. // Bind the OnChannelDataReady event handler
  117. //
  118. g_oDataChannel.OnChannelDataReady = function()
  119. { DestnDataChannelDataReadyHandler(); }
  120. }
  121. }
  122. catch(error)
  123. {
  124. alert( L_ERRFAILDATACHANNELCREATION_MSG );
  125. //
  126. // Todo: Add code to handle error here
  127. //
  128. }
  129. }
  130. }
  131. catch(error)
  132. {
  133. alert( L_ERRRCFILEXFERINITFAILS_MSG );
  134. }
  135. return;
  136. }
  137. //
  138. // onAcceptFileXfer: Routine sets up file xfer
  139. //
  140. function onAcceptFileXfer()
  141. {
  142. //
  143. // Create temp file for staging while file is XFered
  144. //
  145. //alert("Inside onAcceptFileXfer");
  146. fso = new ActiveXObject("Scripting.FileSystemObject");
  147. var tFolder = fso.GetSpecialFolder(2); // Get Path to temp directory
  148. tFileName = tFolder + "\\" + g_szFileName;
  149. //alert( "tFileName: " + tFileName );
  150. fileHandle = fso.CreateTextFile( tFileName );
  151. //
  152. // Send ACK to source to make it begin pumping data on the data channel
  153. //
  154. g_oDataChannel.SendChannelData( c_szFileXferACK );
  155. }
  156. //
  157. // OnCancelFileXfer: Sends rejection to source of file xfer
  158. //
  159. function OnCancelFileXfer()
  160. {
  161. g_oDataChannel.SendChannelData( c_szFileXferREJECT );
  162. window.close();
  163. }
  164. //
  165. // onSend: This routine is fired when the "Send File" button is clicked
  166. //
  167. function onSend()
  168. {
  169. var fileName = attfile.value;
  170. var ForReading = 1, ForWriting = 2, ForAppending = 8;
  171. var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
  172. var Doc = null;
  173. var RCCommand = null;
  174. FileXFerSrc.innerHTML = "<table style=\"position:ABSOLUTE;top:30;left:90\"><tr><td align=left class=\"styText\"><STRONG> Status: </STRONG> Waiting for other end to respond</td></tr><tr><td align=center><button class=\"styButton\" onclick=onCancel()> Cancel </button></td></tr></table>";
  175. //
  176. // Open the File for reading
  177. //
  178. try
  179. {
  180. //
  181. // Create the filesystem object
  182. //
  183. fso = new ActiveXObject("Scripting.FileSystemObject");
  184. //
  185. // Open the file
  186. //
  187. file = fso.GetFile(fileName);
  188. fileHandle = file.OpenAsTextStream(ForReading,TristateUseDefault);
  189. }
  190. catch(error)
  191. {
  192. alert( L_ERROPENINGFILEFORREAD_MSG + fileName );
  193. }
  194. //
  195. // Initiate File Xfer
  196. //
  197. try
  198. {
  199. //
  200. // Create an XML document
  201. //
  202. Doc = new ActiveXObject("microsoft.XMLDOM");
  203. //
  204. // Create the RCCOMMAND root node
  205. //
  206. RCCommand = Doc.createElement( c_szRCCommand );
  207. //
  208. // Set the NAME attribute to FILEXFER
  209. //
  210. RCCommand.setAttribute( c_szRCCommandName, c_szFileXfer );
  211. //
  212. // Set the FILENAME attribute
  213. //
  214. RCCommand.setAttribute( c_szFileName, file.Name );
  215. //
  216. // Set the FILESIZE attribute
  217. //
  218. RCCommand.setAttribute( c_szFileSize, file.size );
  219. //
  220. // Set the CHANNELID attribute
  221. //
  222. RCCommand.setAttribute( c_szChannelId, g_szChannelId );
  223. //
  224. // Send the XML across
  225. //
  226. g_oControlChannel.SendChannelData( RCCommand.xml );
  227. }
  228. catch(error)
  229. {
  230. alert ( L_ERRFILEXFERINITFAILED_MSG );
  231. }
  232. //
  233. // Create the data channel for Filetransfer
  234. //
  235. try
  236. {
  237. if(null == g_oDataChannel)
  238. {
  239. g_oDataChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( g_szChannelId );
  240. //
  241. // Bind the OnChannelDataReady event handler
  242. //
  243. g_oDataChannel.OnChannelDataReady = function()
  244. { SrcDataChannelDataReadyHandler(); }
  245. }
  246. }
  247. catch(error)
  248. {
  249. alert( L_ERRFAILDATACHANNELCREATION_MSG );
  250. }
  251. //
  252. // ToDo: Enable progress bar
  253. //
  254. //FileSizeSrcId.style.visibility = "visible";
  255. window.FileXFerSrc.style.visiblity = "hidden";
  256. return;
  257. }
  258. //
  259. // SrcDataChannelDataReadyHandler: Fired when file Xfer src receives data from
  260. // the file Xfer destn on the data channel
  261. //
  262. function SrcDataChannelDataReadyHandler()
  263. {
  264. //alert("Start sending data");
  265. var str = g_oDataChannel.ReceiveChannelData();
  266. //
  267. // Check if Accept or Reject
  268. //
  269. if(str == c_szFileXferACK)
  270. {
  271. //
  272. // Start sending data
  273. //
  274. FileXFerSrc.style.visibility = "hidden";
  275. filexferstatid.style.visibility = "visible";
  276. SendFileData();
  277. filexferstatid.innerHTML = "<table style=\"position:ABSOLUTE;top:30;left:90\"><tr><td align=left class=\"styText\"><STRONG> Status: </STRONG>" + L_SUCCESSFILEXFER_MSG + "</td></tr><tr><td align=center><button class=\"styButton\" onClick=\"ExitFileXfer()\" id=button2 name=button2> OK </button></td></tr></table>";
  278. }
  279. else if(str == c_szFileXferREJECT)
  280. {
  281. FileXFerSrc.innerHTML = "<table style=\"position:ABSOLUTE;top:30;left:90\"><tr><td align=left class=\"styText\"><STRONG> Status: </STRONG>" + L_REJECTFILEXFER_MSG + "</td></tr><tr><td align=center><button class=\"styButton\" onClick=\"ExitFileXfer()\" id=button2 name=button2> OK </button></td></tr></table>";
  282. }
  283. return;
  284. }
  285. //
  286. // ExitFileXfer: Close down file xfer
  287. function ExitFileXfer()
  288. {
  289. //
  290. // Close the file
  291. //
  292. fileHandle.Close();
  293. //
  294. // We are done. Close the window
  295. //
  296. window.close();
  297. }
  298. //
  299. // DestnDataChannelDataReadyHandler(): Fired when file Xfer destn receives data from
  300. // the file Xfer src on the data channel
  301. //
  302. function DestnDataChannelDataReadyHandler()
  303. {
  304. var str = null;
  305. //alert("Recvd data");
  306. //
  307. // receiving incoming data
  308. //
  309. str = g_oDataChannel.ReceiveChannelData();
  310. //
  311. // Update UI
  312. //
  313. g_iRecvdCtr += str.length;
  314. // RecvdCtrId.innerText = g_iRecvdCtr;
  315. //
  316. // Write str to open temp file
  317. //
  318. fileHandle.Write( str );
  319. if ( tProgBarCounter > 0 )
  320. {
  321. ProgressBar1.Value = (100/tProgBarCounter);
  322. tProgBarCounter--;
  323. }
  324. //
  325. // If g_iRecvdCtr == g_iFileSize;
  326. // - launch File Open/Save dialog
  327. // - close data connection
  328. if( g_iRecvdCtr == g_iFileSize )
  329. {
  330. //alert( "File received" );
  331. //
  332. // Close open temp file handle
  333. //
  334. fileHandle.Close();
  335. //
  336. // Show the File Open/Save dialog
  337. //
  338. OpenTempFile();
  339. //
  340. // We are done. Close the window
  341. //
  342. window.close();
  343. }
  344. return;
  345. }
  346. //
  347. // SendFileData: Sends currently open file to destination
  348. //
  349. function SendFileData()
  350. {
  351. var stream = null;
  352. if ( fileHandle!= null )
  353. {
  354. //
  355. // Enable display of file xfer status in the UI
  356. //
  357. FileXFerSrc.style.visibility = "hidden";
  358. filexferstatid.style.visibility = "visible";
  359. g_iSentCtr = 0;
  360. TotalSizeId.innerText = file.size;
  361. NameId.innerText = file.Name;
  362. SentCtrId.innerText = 0;
  363. //
  364. // While there is data to send
  365. //
  366. //tProgBarCounter = Math.ceil((file.size)/c_MAXFILEXFERSIZE);
  367. while (!fileHandle.AtEndOfStream)
  368. {
  369. try
  370. {
  371. stream = null;
  372. //
  373. // Read File
  374. //
  375. stream = fileHandle.Read( c_MAXFILEXFERSIZE );
  376. //
  377. // Update UI
  378. //
  379. g_iSentCtr+= stream.length;
  380. SentCtrId.innerText = g_iSentCtr;
  381. //
  382. // Send data over the data channel
  383. //
  384. g_oDataChannel.SendChannelData( stream );
  385. //alert("Sent data");
  386. /*
  387. if ( tProgBarCounter > 0 )
  388. {
  389. ProgressBar2.Value = (100/tProgBarCounter);
  390. tProgBarCounter--;
  391. }
  392. */
  393. }
  394. catch(error)
  395. {
  396. alert( L_ERRDATACHANNELSEND_MSG );
  397. }
  398. }
  399. //
  400. // Close the file
  401. //
  402. //fileHandle.Close();
  403. }
  404. else
  405. {
  406. alert( L_ERRINVALIDFILEHANDLE_MSG );
  407. }
  408. return;
  409. }
  410. //
  411. // OpenTempFile: Opens the currently download temp file
  412. //
  413. function OpenTempFile()
  414. {
  415. if(null != tFileName )
  416. {
  417. window.open( tFileName );
  418. }
  419. else
  420. {
  421. alert( L_ERRTEMPFILENAME_MSG );
  422. }
  423. }
  424. function onok()
  425. {
  426. if (radio1.checked)
  427. {
  428. OpenTempFile();
  429. }
  430. else
  431. {
  432. alert ( L_ERRNOTIMPL_MSG );
  433. }
  434. }
  435. function onCancel()
  436. {
  437. //
  438. // Close the window
  439. //
  440. window.close();
  441. }
  442. </script>
  443. <body id="RCFileXferBody" class="styHelpBackGround" onload=InitFileXfer() scroll="no">
  444. <!--
  445. File Transfer Source
  446. -->
  447. <div style="position: absolute; top:0; left:0 " id=FileXFerSrc>
  448. <table id="table2" border="0">
  449. <tr>
  450. <td class="styText" align=left>
  451. Select a File to Send
  452. </td>
  453. </tr>
  454. <tr>
  455. <td align=right>
  456. <div>
  457. <input name="attfile" type="file" LANGUAGE=javascript style="WIDTH: 350px" width=350>
  458. </div>
  459. </td>
  460. </tr>
  461. <tr>
  462. <td align=right>
  463. <input class="styButton" type="button" id="btnSendFileId" value="Send" onclick=onSend()>
  464. <input class="styButton" type="button" id="btnSendFileId" value="Cancel" onclick=onCancel()>
  465. </td>
  466. </tr>
  467. </table><!-- End of table2 -->
  468. </div><!-- End of FileXFerSrc div -->
  469. <div id="filexferstatid" align="center" style="position: absolute; top:20; left:50; VISIBILITY: hidden">
  470. <table>
  471. <tr>
  472. <td class="styText">
  473. Transmitting:
  474. </td>
  475. <td class="styText">
  476. <div id="NameId" class="styText"> &nbsp; </div>
  477. </td>
  478. <tr>
  479. <tr>
  480. <td class="styText">
  481. Sent
  482. </td>
  483. <td class="styText">
  484. <div id="SentCtrId"> &nbsp; </div>
  485. </td>
  486. <td class="styText">
  487. of
  488. </td>
  489. <td class="styText">
  490. <div id="TotalSizeId"> &nbsp; </div>
  491. </td>
  492. <td class="styText">
  493. BYTES
  494. </td>
  495. </tr>
  496. </table>
  497. </div>
  498. <!--
  499. File Transfer Destination
  500. -->
  501. <div id=FileXFerDestn STYLE="LEFT: 50px; POSITION: absolute; TOP: 50px; VISIBILITY: hidden">
  502. <table border="0">
  503. <tr>
  504. <td align=top class="styText">
  505. <img style="width:20px;height=20px" src="../rcbuddy/alert.gif">
  506. <td>
  507. <td>
  508. <table border="0">
  509. <tr>
  510. <td> &nbsp; </td>
  511. <td class="styText"> Receiving: </td>
  512. </tr>
  513. <tr>
  514. <td> &nbsp; </td>
  515. <td align="left">
  516. <div id="FileNameId" class="styText"> </div>
  517. </td>
  518. </tr>
  519. <tr>
  520. <td> &nbsp; </td>
  521. <td> <hr> </td>
  522. </tr>
  523. <tr>
  524. <td> &nbsp; </td>
  525. <td class="styText">WARNING: Web pages, executable, and other files may contain viruses or scripts that can be harmful
  526. to your computer. It is important that you be certain that you want to receive this file from your buddy.
  527. </td>
  528. </tr>
  529. <!--
  530. TODO: Add radio buttons that allow the user to either open the recieved file or save it to disk
  531. - implement SaveAs control
  532. -->
  533. <tr>
  534. <td> &nbsp; </td>
  535. <td align=right>
  536. <table>
  537. <tr>
  538. <td align=right> <button id="OkId" class="styButton" onClick="onAcceptFileXfer()"> OK </button> </td>
  539. <td align=right> <button id="CancelId" class="styButton" onClick="OnCancelFileXfer()"> Cancel </button> </td>
  540. </tr>
  541. </table>
  542. </td>
  543. </tr>
  544. </table>
  545. </td>
  546. </tr>
  547. </table>
  548. </div><!-- End of FileXferDestn div -->
  549. </body>
  550. </html>