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.

492 lines
12 KiB

  1. //
  2. // Global variables shared with the other pages
  3. //
  4. var g_bOsPersonal = false;
  5. var g_oUserList = null;
  6. var g_oSelectedUser = null;
  7. var g_strLoggedOnUserName = null;
  8. var g_szInitialTask = null;
  9. var g_bInitialTaskCompleted = false;
  10. var g_bRunningAsOwner = false;
  11. // Used when deleting an account
  12. var g_bDeleteFiles = false;
  13. //
  14. // Methods shared with the other pages
  15. //
  16. var g_oShell = null;
  17. function GetShell()
  18. {
  19. if (null == g_oShell)
  20. g_oShell = new ActiveXObject("Shell.Application");
  21. return g_oShell;
  22. }
  23. var g_oWShell = null;
  24. function GetWShell()
  25. {
  26. if (null == g_oWShell)
  27. g_oWShell = new ActiveXObject("WScript.Shell");
  28. return g_oWShell;
  29. }
  30. var g_oLocalMachine = null;
  31. function GetLocalMachine()
  32. {
  33. if (null == g_oLocalMachine)
  34. g_oLocalMachine = new ActiveXObject("Shell.LocalMachine");
  35. return g_oLocalMachine;
  36. }
  37. var g_szAdminAccountName = null;
  38. function GetAdminName()
  39. {
  40. if (!g_szAdminAccountName)
  41. {
  42. g_szAdminAccountName = GetLocalMachine().AccountName(500); // DOMAIN_USER_RID_ADMIN
  43. if (!g_szAdminAccountName)
  44. g_szAdminAccountName = "Administrator";
  45. }
  46. return g_szAdminAccountName;
  47. }
  48. var g_szGuestAccountName = null;
  49. function GetGuestName()
  50. {
  51. if (!g_szGuestAccountName)
  52. {
  53. g_szGuestAccountName = GetLocalMachine().AccountName(501); // DOMAIN_USER_RID_GUEST
  54. if (!g_szGuestAccountName)
  55. g_szGuestAccountName = "Guest";
  56. }
  57. return g_szGuestAccountName;
  58. }
  59. function IsSelf()
  60. {
  61. if (!g_oSelectedUser || !g_strLoggedOnUserName)
  62. return false;
  63. return (g_oSelectedUser.setting("LoginName").toLowerCase() == g_strLoggedOnUserName);
  64. }
  65. function GetUserDisplayName(oUser)
  66. {
  67. var szDisplayName = oUser.setting("DisplayName");
  68. if (!szDisplayName)
  69. szDisplayName = oUser.setting("LoginName");
  70. // Truncate really long names
  71. if (szDisplayName && szDisplayName.length > 20)
  72. {
  73. //var iBreak = szDisplayName.lastIndexOf(' ',17);
  74. //if (-1 == iBreak) iBreak = 17;
  75. //szDisplayName = szDisplayName.substring(0,iBreak) + "...";
  76. szDisplayName = szDisplayName.substring(0,17) + "...";
  77. }
  78. //
  79. // NTRAID#NTBUG9-343499-2001/04/03-jeffreys
  80. //
  81. // Convert '<' to "&gt;" so HTML is displayed as text
  82. //
  83. if (szDisplayName) szDisplayName = szDisplayName.replace(/</g, "&lt;");
  84. return szDisplayName;
  85. }
  86. function CountOwners()
  87. {
  88. // Note that 'Administrator' is not included in the count
  89. // Note also that we don't really need a true count, we only
  90. // need to know whether there is 0, 1, or many. Therefore, we
  91. // always stop counting at 2.
  92. var cOwners = 0;
  93. var cUsers = g_oUserList.length;
  94. var strAdmin = GetAdminName().toLowerCase();
  95. for (var i = 0; i < cUsers && cOwners < 2; i++)
  96. {
  97. var oUser = g_oUserList(i);
  98. if ((3 == oUser.setting("AccountType")) && (oUser.setting("LoginName").toLowerCase() != strAdmin))
  99. ++cOwners;
  100. }
  101. return cOwners;
  102. }
  103. function OnKeySelect(iTab, oEvent)
  104. {
  105. if (null == oEvent)
  106. oEvent = window.event;
  107. if (oEvent.keyCode == 27) // VK_ESCAPE
  108. {
  109. g_Navigator.back();
  110. }
  111. else if (oEvent.keyCode == 32) // VK_SPACE
  112. {
  113. // Make the Space key activate links
  114. oEvent.returnValue = false;
  115. oEvent.srcElement.click();
  116. }
  117. else if (!oEvent.altKey) // ignore navigation shortcuts
  118. {
  119. // Handle arrow key navigation
  120. var oTarget = null;
  121. switch (oEvent.keyCode)
  122. {
  123. case 37: // VK_LEFT
  124. oTarget = oEvent.srcElement.leftElem;
  125. break;
  126. case 38: // VK_UP
  127. oTarget = oEvent.srcElement.upElem;
  128. break;
  129. case 39: // VK_RIGHT
  130. oTarget = oEvent.srcElement.rightElem;
  131. break;
  132. case 40: // VK_DOWN
  133. oTarget = oEvent.srcElement.downElem;
  134. break;
  135. }
  136. if (oTarget != null)
  137. {
  138. oEvent.srcElement.tabIndex = -1;
  139. oTarget.tabIndex = (null != iTab) ? iTab : 0;
  140. oTarget.focus();
  141. oEvent.returnValue = false;
  142. }
  143. }
  144. }
  145. function SetRelativeTasks(aTasks, iTab)
  146. {
  147. var cTasks = aTasks.length;
  148. var oPrevA = null;
  149. for (var i = 0; i < cTasks; i++)
  150. {
  151. var oTask = aTasks[i];
  152. if (oTask.style.display != 'none')
  153. {
  154. // Find the first Anchor tag under this node
  155. var oAnchor = oTask.getElementsByTagName("A")[0];
  156. if (oAnchor)
  157. {
  158. if (oPrevA)
  159. {
  160. oPrevA.downElem = oAnchor;
  161. oAnchor.upElem = oPrevA;
  162. }
  163. else
  164. oAnchor.tabIndex = (null != iTab) ? iTab : 0;
  165. oPrevA = oAnchor;
  166. }
  167. }
  168. }
  169. }
  170. function PopulateLeftPane(szRelatedTasks, szLearnAbout, szDescription)
  171. {
  172. if (szDescription && szDescription.length > 0)
  173. {
  174. idDescription.innerHTML = szDescription;
  175. idDescription.style.display = 'block';
  176. }
  177. else
  178. idDescription.style.display = 'none';
  179. if (szRelatedTasks && szRelatedTasks.length > 0)
  180. {
  181. idRelatedTaskLinks.innerHTML = szRelatedTasks;
  182. idRelatedTasks.style.display = 'block';
  183. SetRelativeTasks(idRelatedTaskLinks.children, 2);
  184. }
  185. else
  186. idRelatedTasks.style.display = 'none';
  187. if (szLearnAbout && szLearnAbout.length > 0)
  188. {
  189. idLearnAboutLinks.innerHTML = szLearnAbout;
  190. idLearnAbout.style.display = 'block';
  191. SetRelativeTasks(idLearnAboutLinks.children, 2);
  192. }
  193. else
  194. idLearnAbout.style.display = 'none';
  195. }
  196. function CreateUserDisplayHTML2(szName, szSubtitle, szPicture)
  197. {
  198. return '<TABLE cellspacing=0 cols=2 cellpadding=0><TD style="width:15mm;padding:1mm;text-align:center;"><IMG src="'+szPicture+'"/></TD><TD style="padding:1mm"><H3>'+szName+'</H3><H4>'+szSubtitle+'</H4></TD></TABLE>';
  199. }
  200. var g_AccountProps = new Array(L_Guest_Property, L_Limited_Property, L_UnknownAcct_Property, L_Owner_Property);
  201. function CreateUserDisplayHTML(oUser, szSubtitle)
  202. {
  203. if (!szSubtitle)
  204. {
  205. szSubtitle = g_AccountProps[oUser.setting("AccountType")];
  206. if (oUser.passwordRequired)
  207. szSubtitle += '<BR>' + L_Password_Property;
  208. }
  209. return CreateUserDisplayHTML2(GetUserDisplayName(oUser), szSubtitle, oUser.setting("Picture"));
  210. }
  211. var g_HelpWindow = null;
  212. var g_szHelpUrl = null;
  213. function LaunchHelp(szHTM)
  214. {
  215. if (szHTM && szHTM.length > 0)
  216. {
  217. if (null == g_HelpWindow)
  218. {
  219. var args = new Object;
  220. args.mainWindow = window;
  221. args.szHTM = szHTM;
  222. if (null == g_szHelpUrl)
  223. g_szHelpUrl = GetWShell().ExpandEnvironmentStrings("MS-ITS:%windir%\\help\\nusrmgr.chm::/");
  224. g_HelpWindow = window.showModelessDialog(g_szHelpUrl + "HelpFrame.htm", args, "border=thick; center=0; dialogWidth=30em; dialogHeight=34em; help=0; minimize=1; maximize=1; resizable=1; status=0;");
  225. }
  226. else
  227. {
  228. try
  229. {
  230. g_HelpWindow.ShowHelp(g_szHelpUrl + szHTM);
  231. }
  232. catch (e)
  233. {
  234. g_HelpWindow.close();
  235. g_HelpWindow = null;
  236. }
  237. }
  238. }
  239. }
  240. function EnableGuest(bEnable)
  241. {
  242. if (!bEnable)
  243. {
  244. var oGuest = g_oUserList(GetGuestName());
  245. if (oGuest && oGuest.isLoggedOn)
  246. {
  247. alert(L_DisableGuestInUse_ErrorMessage);
  248. return false;
  249. }
  250. }
  251. try
  252. {
  253. if (bEnable)
  254. {
  255. GetLocalMachine().EnableGuest(1);
  256. // Force a new enumeration.
  257. g_oSelectedUser = null;
  258. g_oUserList = null;
  259. g_oUserList = new ActiveXObject("Shell.Users");
  260. }
  261. else
  262. GetLocalMachine().DisableGuest(1);
  263. }
  264. catch (e)
  265. {
  266. }
  267. g_Navigator.navigate("mainpage2.htm", true);
  268. }
  269. //
  270. // Methods specific to the main frame
  271. //
  272. function PageInit()
  273. {
  274. // Load shgina. If this fails, we can't do anything at all.
  275. try
  276. {
  277. g_oUserList = new ActiveXObject("Shell.Users");
  278. }
  279. catch (e)
  280. {
  281. alert(L_SHGinaLoad_ErrorMessage);
  282. window.close();
  283. return;
  284. }
  285. // Initialize globals
  286. g_bOsPersonal = GetShell().GetSystemInformation("IsOS_Personal");
  287. g_oSelectedUser = g_oUserList.currentUser;
  288. if (g_oSelectedUser)
  289. {
  290. g_strLoggedOnUserName = g_oSelectedUser.setting("LoginName").toLowerCase();
  291. g_bRunningAsOwner = (3 == g_oSelectedUser.setting("AccountType"));
  292. }
  293. else if (false == g_bOsPersonal)
  294. {
  295. // Running Pro and couldn't get currentUser, therefore
  296. // we've probably just disjoined a domain without rebooting
  297. // and the current user is probably a domain account. That's
  298. // the only scenario I can come up with where we hit this,
  299. // and it has actually happened in the BVT lab.
  300. //
  301. // The fact that they had the ability to disjoin the domain
  302. // implies owner.
  303. g_bRunningAsOwner = true;
  304. }
  305. else
  306. {
  307. // If we're running Personal and can't get currentUser,
  308. // then we're SOL.
  309. alert(L_NoCurrentUser_ErrorMessage);
  310. window.close();
  311. return;
  312. }
  313. // Parse the command line to see if we were given an initial task
  314. if (idUM.commandLine)
  315. {
  316. // It may be necessary in the future to split the command line
  317. // into multiple arguments. But for now this is good enough.
  318. var iInitialTask = idUM.commandLine.indexOf("initialTask=");
  319. if (-1 != iInitialTask)
  320. {
  321. // 12 == strlen("initialTask=")
  322. g_szInitialTask = idUM.commandLine.substring(iInitialTask+12);
  323. }
  324. }
  325. g_Navigator = new Navigator(idContent);
  326. if (g_Navigator)
  327. g_Navigator.navigate(g_bRunningAsOwner ? "mainpage2.htm" : "mainpage.htm");
  328. }
  329. //
  330. // Navigator object implementation
  331. //
  332. var g_Navigator = null;
  333. function push(url)
  334. {
  335. if (url)
  336. {
  337. if (this.current < 0 || url != this.stack[this.current])
  338. this.stack[++this.current] = url;
  339. // Make sure there's nothing left on the stack after this
  340. this.stack.length = this.current + 1;
  341. }
  342. }
  343. function navigate(urlTo, bTrim)
  344. {
  345. // Check for empty stack
  346. if (this.current < 0)
  347. bTrim = false;
  348. if (bTrim)
  349. {
  350. // Look backwards for the page, trimming as we go
  351. while (this.current >= 0)
  352. {
  353. // Trim the stack to the current location
  354. this.stack.length = this.current + 1;
  355. // Is the page here on the stack?
  356. if (urlTo == this.stack[this.current])
  357. break;
  358. if (0 == this.current)
  359. {
  360. // Got all the way back to the beginning and didn't
  361. // find it. Push it and stop.
  362. this.push(urlTo);
  363. break;
  364. }
  365. --this.current;
  366. }
  367. }
  368. else
  369. {
  370. // Normal navigation
  371. this.push(urlTo);
  372. }
  373. this.SetBtnState();
  374. this.frame.navigate(urlTo);
  375. }
  376. function back(nCount)
  377. {
  378. if (this.current > 0)
  379. {
  380. if (!nCount)
  381. nCount = 1;
  382. if (-1 == nCount)
  383. this.current = 0;
  384. else
  385. this.current = Math.max(0, this.current - nCount);
  386. this.frame.navigate(this.stack[this.current]);
  387. }
  388. this.SetBtnState();
  389. }
  390. function forward()
  391. {
  392. if (this.current < this.stack.length - 1)
  393. this.frame.navigate(this.stack[++this.current]);
  394. this.SetBtnState();
  395. }
  396. function SetBtnState()
  397. {
  398. idToolbar.enabled(0) = (this.current > 0);
  399. idToolbar.enabled(1) = (this.current != this.stack.length - 1);
  400. idToolbar.enabled(2) = (this.current > 0);
  401. }
  402. function Navigator(frame)
  403. {
  404. // methods
  405. this.push = push;
  406. this.navigate = navigate;
  407. this.back = back;
  408. this.forward = forward;
  409. this.SetBtnState = SetBtnState;
  410. // properties
  411. this.frame = frame;
  412. this.current = -1;
  413. this.stack = new Array();
  414. this.SetBtnState();
  415. }