Leaked source code of windows server 2003
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.

592 lines
13 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. RAClient.js
  5. Abstract:
  6. Contains Javascript code common to both client and server side UI
  7. Author:
  8. Rajesh Soy 10/00
  9. Revision History:
  10. Rajesh Soy - created 10/25/2000
  11. --*/
  12. #include "debug_decl.inc"
  13. #include "constants.inc"
  14. /*
  15. * Localizable Constants, text and messages
  16. */
  17. var L_SAYS_Text = " says: ";
  18. var L_INITIALHELPERCHAT1_Text = "----------<BR>Welcome to Remote Assistance.<BR>To explore your options, click Help.<P>";
  19. var L_INITIALHELPERCHAT2_Text = " is connected to <BR>";
  20. var L_RCCTL_Text = "Remote Assistance failed. Please try again. ";
  21. var L_NOIP_Text = "There is no Internet connection. To use Remote Assistance, please connect to the Internet. ";
  22. //
  23. // Configuration stuff
  24. //
  25. #ifdef _VOIPENABLED
  26. var g_bVoIPEnabled = true; // JPEREZ: Enabled March 1, 2001 - // ADHOC, Disabling VoIP for the moment.
  27. #else
  28. var g_bVoIPEnabled = false;
  29. #endif
  30. //
  31. // Globals
  32. //
  33. var g_szLocalUser = null;
  34. var g_oShell = null;
  35. var g_oEnv = null;
  36. #ifdef _BVT
  37. var g_szExpertComputer = null;
  38. var g_szNoviceComputer = null;
  39. var g_szNoviceCredentials = null;
  40. var g_szBVTDir = null;
  41. var g_iTest = 0;
  42. var g_szBuild = null;
  43. var g_bBVT = false;
  44. function TestInfo()
  45. {
  46. this.TEST = null;
  47. this.BUILD = null;
  48. this.MACHINE = null;
  49. this.RESULT = null;
  50. this.CONTACT = null;
  51. this.MGR_CONTACT = null;
  52. this.DEV_PRIME = null;
  53. this.DEV_ALT = null;
  54. this.TEST_PRIME = null;
  55. this.TEST_ALT = null;
  56. this.START_TIME = null;
  57. this.END_TIME = null;
  58. }
  59. #define szCONTACT "David Holcomb (dholcomb), x6-9764"
  60. #define szMGR_CONTACT "Mazhar Mohammad (mazharm), x6-7103"
  61. #define szDEV_PRIME "Rajesh Soy (nsoy), x3-9938"
  62. #define szDEV_ALT "Steve Shih (steveshi), x3-3498"
  63. #define szTEST_PRIME "Miguel Lacouture-Amaya (miguell), x5-3510"
  64. #define szTEST_ALT "Dave Ferguson (WIMME) (dferg), 5-7079"
  65. var g_oBVT = new Array( 7 );
  66. function InitBVT()
  67. {
  68. var iRetVal = 0;
  69. try
  70. {
  71. if( null == g_oShell) { g_oShell = new ActiveXObject("WScript.Shell"); }
  72. if(null == g_oEnv) { g_oEnv = g_oShell.Environment("process"); }
  73. g_szNoviceComputer = g_oEnv("NOVICECOMPUTER");
  74. g_szNoviceCredentials = g_oEnv("NOVICEUSERID");
  75. g_szBVTDir = g_oEnv("RABVTDIR");
  76. g_szExpertComputer = g_oEnv("COMPUTERNAME");
  77. g_szBuild = g_oEnv( "BUILD" );
  78. for( var i = 0; i < 7; i++)
  79. {
  80. g_oBVT[ i ] = new TestInfo();
  81. g_oBVT[ i ].BUILD = g_szBuild;
  82. g_oBVT[ i ].MACHINE = g_szExpertComputer;
  83. g_oBVT[ i ].CONTACT = szCONTACT;
  84. g_oBVT[ i ].MGR_CONTACT = szMGR_CONTACT;
  85. g_oBVT[ i ].DEV_PRIME = szDEV_PRIME;
  86. g_oBVT[ i ].DEV_ALT = szDEV_ALT;
  87. g_oBVT[ i ].TEST_PRIME = szTEST_PRIME;
  88. g_oBVT[ i ].TEST_ALT = szTEST_ALT;
  89. }
  90. g_bBVT = true;
  91. }
  92. catch(error)
  93. {
  94. iRetVal = error.number;
  95. }
  96. return iRetVal;
  97. }
  98. function ReportBVTResult( szResult )
  99. {
  100. var iRetVal = 0;
  101. try
  102. {
  103. var oDate = new Date();
  104. g_oBVT[ g_iTest ].END_TIME = oDate.toLocaleString();
  105. if( szResult == c_szBVTPASS )
  106. {
  107. g_oBVT[ g_iTest ].RESULT = c_szPASS;
  108. }
  109. else
  110. {
  111. g_oBVT[ g_iTest ].RESULT = c_szFAIL;
  112. }
  113. g_iTest++;
  114. }
  115. catch(error)
  116. {
  117. iRetVal = error.number;
  118. }
  119. return iRetVal;
  120. }
  121. function ShutDownBVT()
  122. {
  123. try
  124. {
  125. var Fso = new ActiveXObject("Scripting.FileSystemObject");
  126. var FileName = g_szBVTDir + "\\RABVTResult.txt";
  127. var fileHandle = Fso.OpenTextFile( FileName, 2, -2 );
  128. for (var i=0; i < 7; i++)
  129. {
  130. if( null != g_oBVT[ i ].TEST )
  131. {
  132. fileHandle.WriteLine( "[TESTRESULT]");
  133. fileHandle.WriteLine( " ");
  134. fileHandle.WriteLine( "TEST: " + g_oBVT[ i ].TEST );
  135. fileHandle.WriteLine( "BUILD: " + g_oBVT[ i ].BUILD );
  136. fileHandle.WriteLine( "MACHINE: " + g_oBVT[ i ].MACHINE );
  137. fileHandle.WriteLine( "RESULT: " + g_oBVT[i].RESULT );
  138. fileHandle.WriteLine( "CONTACT: " + g_oBVT[ i ].CONTACT);
  139. fileHandle.WriteLine( "MGR CONTACT: " + g_oBVT[ i ].MGR_CONTACT );
  140. fileHandle.WriteLine( "DEV PRIME: " + g_oBVT[ i ].DEV_PRIME );
  141. fileHandle.WriteLine( "DEV ALT: " + g_oBVT[ i ].DEV_ALT );
  142. fileHandle.WriteLine( "TEST PRIME: " + g_oBVT[ i ].TEST_PRIME );
  143. fileHandle.WriteLine( "TEST ALT: " + g_oBVT[ i ].TEST_ALT );
  144. fileHandle.WriteLine( "START TIME: " + g_oBVT[ i ].START_TIME);
  145. fileHandle.WriteLine( "END TIME: " + g_oBVT[ i ].END_TIME );
  146. fileHandle.WriteLine( " ");
  147. fileHandle.WriteLine( "[/TESTRESULT]");
  148. fileHandle.WriteLine( " ");
  149. fileHandle.WriteLine( " ");
  150. fileHandle.WriteLine( " ");
  151. }
  152. }
  153. fileHandle.Close();
  154. }
  155. catch(error)
  156. {
  157. alert("Error: " + error.description);
  158. }
  159. }
  160. #endif
  161. function DisplayMessage( szMsg )
  162. {
  163. TraceFunctEnter( "DisplayMessage" );
  164. try
  165. {
  166. var vArgs = new Array(1);
  167. vArgs[0] = szMsg; // Message
  168. var vRetVal = window.showModelessDialog( c_szMsgURL, vArgs, c_szMsgSpecs );
  169. }
  170. catch(error)
  171. {
  172. FatalError( error.description, error );
  173. }
  174. TraceFunctLeave();
  175. }
  176. function SoundBeep()
  177. {
  178. TraceFunctEnter("SoundBeep");
  179. #ifdef _BEEP
  180. try
  181. {
  182. if( null == g_oShell) { g_oShell = new ActiveXObject("WScript.Shell"); }
  183. g_oShell.SendKeys("%c");
  184. }
  185. catch(error)
  186. {
  187. FatalError( error.description );
  188. }
  189. #endif
  190. TraceFunctLeave();
  191. return g_szLocalUser;
  192. }
  193. //
  194. // GetLocalUser: Obtains the domain\username of local user
  195. //
  196. function GetLocalUser()
  197. {
  198. TraceFunctEnter("GetLocalUser");
  199. try
  200. {
  201. if( null == g_oShell) { g_oShell = new ActiveXObject("WScript.Shell"); }
  202. if(null == g_oEnv) { g_oEnv = g_oShell.Environment("process"); }
  203. var szTmp = g_oEnv("USERNAME");
  204. if( szTmp.length < 20 )
  205. {
  206. g_szLocalUser = szTmp;
  207. }
  208. else
  209. {
  210. g_szLocalUser = szTmp.slice(0, 20) + "...";
  211. }
  212. g_szLocalUser = EscapedName( g_szLocalUser );
  213. }
  214. catch(error)
  215. {
  216. FatalError( error.description );
  217. }
  218. TraceFunctLeave();
  219. return g_szLocalUser;
  220. }
  221. //
  222. // GetLocalIPAddr: Fetch the IP address of the local machine
  223. //
  224. function GetLocalIPAddr()
  225. {
  226. var oSetting = null;
  227. var ip = null;
  228. try
  229. {
  230. oSetting = new ActiveXObject( szProgIDEscalationSetting );
  231. ip = oSetting.GetIPAddress;
  232. if (ip.length == 0) {
  233. alert(L_NOIP_Text);
  234. return ip;
  235. }
  236. oSetting = null;
  237. }
  238. catch(e)
  239. {
  240. FatalError(L_RCCTL_Text, e);
  241. return ip;
  242. }
  243. return ip;
  244. }
  245. //
  246. // ChangeHCToKioskMode: Changes from full HC view to kiosk mode view
  247. //
  248. function ChangeHCToKioskMode(left, top, width, height)
  249. {
  250. TraceFunctEnter("ChangeHCToKioskMode");
  251. try
  252. {
  253. DebugTrace("Changing to kioskmode");
  254. //
  255. // In order to use this, include the following in your HTM file:
  256. // <HTML XMLNS:helpcenter>
  257. // <style>
  258. // helpcenter\:context
  259. // {
  260. // behavior : url(#default#pch_context);
  261. // }
  262. // </style>
  263. //
  264. // <helpcenter:context id=idCtx />
  265. //
  266. idCtx.ChangeContext( "kioskmode", "");
  267. idCtx.setWindowDimensions( left, top, width, height);
  268. }
  269. catch(error)
  270. {
  271. FatalError( L_RCCTL_Text, error );
  272. }
  273. TraceFunctLeave();
  274. }
  275. //
  276. // GetWinDir: Returns path to SystemRoot
  277. //
  278. function GetWinDir()
  279. {
  280. TraceFunctEnter("GetWinDir");
  281. var szWinDir = null;
  282. try
  283. {
  284. if( null == g_oShell) { g_oShell = new ActiveXObject("WScript.Shell"); }
  285. if(null == g_oEnv) { g_oEnv = g_oShell.Environment("process"); }
  286. szWinDir = g_oEnv("SystemRoot");
  287. }
  288. catch(error)
  289. {
  290. FatalError(error.description, error);
  291. }
  292. TraceFunctLeave();
  293. return szWinDir;
  294. }
  295. //
  296. // LaunchHelp: Launches Help topic in kioskmode Helpctr
  297. //
  298. function LaunchHelp( nTopicId )
  299. {
  300. TraceFunctEnter("LaunchHelp");
  301. try
  302. {
  303. var szURL = 'hcp://CN=Microsoft%20Corporation,L=Redmond,S=Washington,C=US/Remote%20Assistance/Common/RAHelp.htm?' + nTopicId;
  304. var szWinDir = GetWinDir();
  305. window.showModelessDialog( szURL, szWinDir, "dialogHeight:400px;dialogWidth:550px;status:no;resizable:yes;help:no" );
  306. }
  307. catch(error)
  308. {
  309. FatalError(error.description, error);
  310. }
  311. TraceFunctLeave();
  312. return;
  313. }
  314. function LaunchHelpEx( nTopicId )
  315. {
  316. TraceFunctEnter("LaunchHelp");
  317. try
  318. {
  319. var szURL = 'hcp://system/Remote%20Assistance/Common/RAHelp.htm?' + nTopicId;
  320. var szWinDir = GetWinDir();
  321. window.showModelessDialog( szURL, szWinDir, "dialogHeight:440px;dialogWidth:385px;status:no;resizable:no;help:no" );
  322. }
  323. catch(error)
  324. {
  325. FatalError(error.description, error);
  326. }
  327. TraceFunctLeave();
  328. return;
  329. }
  330. function FatalError( szMessage, error, bClose)
  331. {
  332. try
  333. {
  334. var szMsg = null;
  335. #ifdef _BVT
  336. if( true == g_bBVT )
  337. {
  338. if( (szMessage == null) || (szMessage.length < 5))
  339. {
  340. szMessage = L_RCCTL_Text;
  341. }
  342. var vArgs = new Array(1);
  343. vArgs[0] = szMessage;
  344. DebugTrace( "Function: " + g_szFuncName + "\nError Message: " + szMessage + "\nError Description: " + error.description + "\nError Number: " + error.number);
  345. var vRetVal = window.showModalDialog( c_szMsgURL + '?' + szMessage, vArgs, c_szMsgSpecs );
  346. AddOpenSubWin( vRetVal );
  347. ShutDownBVT();
  348. }
  349. else
  350. {
  351. if( (szMessage == null) || (szMessage.length < 5))
  352. {
  353. szMessage = L_RCCTL_Text;
  354. }
  355. var vArgs = new Array(1);
  356. vArgs[0] = szMessage;
  357. DebugTrace( "Function: " + g_szFuncName + "\nError Message: " + szMessage + "\nError Description: " + error.description + "\nError Number: " + error.number);
  358. var vRetVal = window.showModalDialog( c_szMsgURL + '?' + szMessage, vArgs, c_szMsgSpecs );
  359. AddOpenSubWin( vRetVal );
  360. }
  361. #else
  362. if( (szMessage == null) || (szMessage.length < 5))
  363. {
  364. szMessage = L_RCCTL_Text;
  365. }
  366. var vArgs = new Array(1);
  367. vArgs[0] = szMessage;
  368. DebugTrace( "Function: " + g_szFuncName + "\nError Message: " + szMessage + "\nError Description: " + error.description + "\nError Number: " + error.number);
  369. var vRetVal = window.showModalDialog( c_szMsgURL + '?' + szMessage, vArgs, c_szMsgSpecs );
  370. AddOpenSubWin( vRetVal );
  371. #endif
  372. }
  373. catch(x)
  374. {
  375. // ...
  376. }
  377. }
  378. //
  379. // Collection of open sub-windows
  380. //
  381. var openWins = new Array(10); // Hope not to open more than 10 sub-windows at any given time
  382. var openWinCnt = 0; // Count of open windows
  383. function AddOpenSubWin( win )
  384. {
  385. try
  386. {
  387. openWins[openWinCnt%10] = win;
  388. openWinCnt++;
  389. }
  390. catch(error)
  391. {
  392. // Ignore
  393. }
  394. }
  395. function CloseOpenSubWin()
  396. {
  397. var i = 0;
  398. for ( i=0; i< 10; i++)
  399. {
  400. if(null != openWins[i])
  401. {
  402. try
  403. {
  404. if(openWins[i].closed == false)
  405. {
  406. openWins[i].close();
  407. }
  408. }
  409. catch(error)
  410. {
  411. // Ignore
  412. }
  413. }
  414. }
  415. }
  416. //
  417. // Chat Stuff
  418. //
  419. function FormatChatMsg( szMsg )
  420. {
  421. var szNewText = '<BR><font id="MsgTxt" name="MsgTxt" class="sys-font-body sys-color-body-helper">' + szMsg + '</font><P>';
  422. return szNewText;
  423. }
  424. function CreateChatGreeting( szLocalUser, szRemoteUser )
  425. {
  426. szLocalUser = EscapedName( szLocalUser );
  427. szRemoteUser = EscapedName( szRemoteUser );
  428. var szNewText = FormatChatMsg( L_INITIALHELPERCHAT1_Text + "<P>" + szLocalUser + L_INITIALHELPERCHAT2_Text + szRemoteUser + ".<P>" + L_INITIALHELPERCHAT3_Text );
  429. return szNewText;
  430. }
  431. function FormatSendChatText( szUser, szChatText )
  432. {
  433. var szNewText = '<BR><font id="MsgTxt" name="MsgTxt" class="styChatColorBlue styText">' + szUser + L_SAYS_Text + '</font><BR>&nbsp;&nbsp;&nbsp;&nbsp;<font class="styText styBlack">' + szChatText + '</font>';
  434. return szNewText;
  435. }
  436. //
  437. // Key tracking
  438. //
  439. var iKeyCode = new Array(3);
  440. var iKeyCnt = 0;
  441. function IsAlpha( keyCode )
  442. {
  443. var fRetVal = false;
  444. alert("keyCode: " + keyCode);
  445. if( ( 64 < keyCode) && ( keyCode < 91) )
  446. {
  447. fRetVal = true;
  448. }
  449. return fRetVal;
  450. }
  451. //
  452. // Escape funny characters in name
  453. //
  454. var L_DOTS_Text = "...";
  455. function EscapedName( szName )
  456. {
  457. TraceFunctEnter("EscapeName");
  458. try
  459. {
  460. var szTmp = new String( szName );
  461. var re = /&/g;
  462. var szEscapedName = szTmp.replace( re, "&amp;" );
  463. var re = /</g;
  464. szEscapedName = szEscapedName.replace( re, "&lt;" );
  465. re = />/g;
  466. szEscapedName = szEscapedName.replace( re, "&gt;" );
  467. #if 0
  468. if( szEscapedName.length > 60 )
  469. {
  470. szEscapedName = szEscapedName.slice(0, 60) + L_DOTS_Text;
  471. }
  472. #endif
  473. }
  474. catch(error)
  475. {
  476. alert(parent.parent.L_RCCTL_Text);
  477. return;
  478. }
  479. TraceFunctLeave();
  480. return szEscapedName;
  481. }