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.

563 lines
38 KiB

  1. ��<HTML>
  2. <!-- Copyright (c) Microsoft Corporation. All rights reserved.-->
  3. <HEAD>
  4. <TITLE>Hostname Setting Page</TITLE>
  5. <SCRIPT LANGUAGE="VBScript">
  6. <!--
  7. Option Explicit
  8. 'Windows constants for key codes
  9. Public Const RightArrow = 39
  10. Public Const LeftArrow = 37
  11. Public Const EnterKey = 13
  12. Public Const EscapeKey = 27
  13. Public Const UpArrow = 38
  14. Public Const DownArrow = 40
  15. 'Timer for idle timeout
  16. Dim iIdleTimeOut
  17. 'Flag for errors
  18. Dim bInErrorMode
  19. 'Reboot confirmation mode
  20. Dim bInConfirmationMode
  21. 'Domain error text
  22. Dim strDomainErrorText
  23. 'Unknown error text
  24. Dim strUnknownErrorText
  25. 'Reboot confirmation text
  26. Dim strRebootConfirmationText
  27. 'Duplicate machine name error text
  28. Dim strDuplicateErrorText
  29. 'Password reset error text
  30. Dim strRebootErrorText
  31. 'Confirmation text for resetting password
  32. Dim strConfirmRebootText
  33. 'Shutdown text
  34. Dim strShutdownText
  35. 'Header for computer name
  36. Dim strComputerNameHeader
  37. 'Is machine part of domain
  38. Dim bPartOfDomain
  39. 'Is the name entered duplicate
  40. Dim bInDuplicateMode
  41. 'Flag for status of the page
  42. Dim bRebootingMachine
  43. '----------------------------------------------------------------------------
  44. ' Function: Window_OnLoad
  45. ' Description: Initialization routine for the page
  46. ' Input Variables: None
  47. ' Output Variables: None
  48. ' Return Values: None
  49. ' Global Variables: iIdleTimeOut,strWaitText,bInErrorMode,strIpAddressInvalidText
  50. '----------------------------------------------------------------------------
  51. Sub Window_OnLoad()
  52. 'Localization manager object
  53. Dim objLocMgr
  54. 'Replacement strings
  55. Dim varReplacementStrings
  56. 'SaHelper component object
  57. Dim objSaHelper
  58. 'Current hostname
  59. Dim strHostname
  60. 'Resource ID for unknown error text
  61. Const UNKNOWN_ERROR_TEXT = "&H40020004"
  62. 'Resource ID for reboot error text
  63. Const REBOOT_CONFIRMATION_TEXT = "&H40020003"
  64. 'Resource ID for domain error text
  65. Const DOMAIN_ERROR_TEXT = "&H40020001"
  66. 'Resource ID for duplicate machine name error text
  67. Const DUPLICATE_ERROR_TEXT = "&H40020002"
  68. 'Resource ID for reboot error text
  69. Const REBOOT_ERROR_TEXT = "&H4002000E"
  70. 'Resource ID for shutting down text
  71. Const SHUTTINGDOWN_TEXT = "&H40020011"
  72. 'Resource ID for computer name header
  73. Const COMPNAMEHEADER_TEXT = "&H40020014"
  74. On Error Resume Next
  75. Err.Clear
  76. bInErrorMode = false
  77. bInConfirmationMode = false
  78. bInDuplicateMode = false
  79. bRebootingMachine = false
  80. 'Set the max size for computer name
  81. HostNameEntry.MaxSize = 16
  82. 'Set the char set
  83. HostNameEntry.TextCharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "
  84. Err.Clear
  85. 'Create the localization manager
  86. Set objLocMgr = CreateObject("ServerAppliance.LocalizationManager")
  87. If Err.number = 0 Then
  88. 'Get the strings
  89. strUnknownErrorText = objLocMgr.GetString("salocaluimsg.dll",UNKNOWN_ERROR_TEXT,varReplacementStrings)
  90. strRebootConfirmationText = objLocMgr.GetString("salocaluimsg.dll",REBOOT_CONFIRMATION_TEXT,varReplacementStrings)
  91. strDomainErrorText = objLocMgr.GetString("salocaluimsg.dll",DOMAIN_ERROR_TEXT,varReplacementStrings)
  92. strDuplicateErrorText = objLocMgr.GetString("salocaluimsg.dll",DUPLICATE_ERROR_TEXT,varReplacementStrings)
  93. strRebootErrorText = objLocMgr.GetString("salocaluimsg.dll",REBOOT_ERROR_TEXT,varReplacementStrings)
  94. strShutdownText = objLocMgr.GetString("salocaluimsg.dll",SHUTTINGDOWN_TEXT,varReplacementStrings)
  95. strComputerNameHeader = objLocMgr.GetString("salocaluimsg.dll",COMPNAMEHEADER_TEXT,varReplacementStrings)
  96. Set objLocMgr = Nothing
  97. End If
  98. Err.Clear
  99. 'get the current configuration
  100. Set objSaHelper = CreateObject("ServerAppliance.SAHelper")
  101. If Err.number = 0 Then
  102. bPartOfDomain = objSaHelper.IsPartOfDomain
  103. If Err.number <> 0 Then
  104. InformationText.innerText = strUnknownErrorText
  105. InformationText.style.display = ""
  106. bInErrorMode = true
  107. ElseIf bPartOfDomain = true Then
  108. InformationText.innerText = strDomainErrorText
  109. InformationText.style.display = ""
  110. Else
  111. Err.Clear
  112. strHostname = objSaHelper.HostName
  113. If Err.number = 0 Then
  114. HostNameEntry.TextValue = strHostname
  115. HostNameEntry.style.display = ""
  116. HeaderText.innerText = strComputerNameHeader
  117. HeaderText.style.display = ""
  118. HostNameEntry.focus
  119. Else
  120. InformationText.innerText = strUnknownErrorText
  121. InformationText.style.display = ""
  122. bInErrorMode = true
  123. End If
  124. End If
  125. Set objSaHelper = Nothing
  126. Else
  127. InformationText.innerText = strUnknownErrorText
  128. InformationText.style.display = ""
  129. bInErrorMode = true
  130. End If
  131. 'set the information to display during reboot
  132. ServeLocalUILogo
  133. SaShutdownText.innerText = strShutdownText
  134. 'start the timer for idle timeout
  135. iIdleTimeOut = window.SetTimeOut("IdleHandler()",300000)
  136. On Error Resume Next
  137. Err.Clear
  138. 'set the key codes for the page
  139. Dim objKeypad
  140. Set objKeypad = CreateObject("Ldm.SAKeypadController")
  141. If Err.number = 0 Then
  142. objKeypad.Setkey 0,UpArrow,TRUE
  143. objKeypad.Setkey 1,DownArrow,FALSE
  144. objKeypad.Setkey 2,LeftArrow,FALSE
  145. objKeypad.Setkey 3,RightArrow,FALSE
  146. objKeypad.Setkey 4,EscapeKey,FALSE
  147. objKeypad.Setkey 5,EnterKey,FALSE
  148. Set objKeypad = Nothing
  149. End If
  150. End Sub
  151. '----------------------------------------------------------------------------
  152. ' Function: IdleHandler
  153. ' Description: Goes back to main page when timeout expires
  154. ' Input Variables: None
  155. ' Output Variables: None
  156. ' Return Values: None
  157. ' Global Variables: None
  158. '----------------------------------------------------------------------------
  159. Sub IdleHandler()
  160. window.history.go(-2)
  161. End Sub
  162. '----------------------------------------------------------------------------
  163. ' Function: ServerLocalUILogo
  164. ' Description: Gets the name of the logo file from elementmgr
  165. ' Input Variables: None
  166. ' Output Variables: None
  167. ' Return Values: None
  168. ' Global Variables: salogo
  169. '----------------------------------------------------------------------------
  170. Sub ServerLocalUILogo()
  171. Dim objLogoElementCol
  172. Dim objLogoElement
  173. Dim objRetriever
  174. Dim strLogoFileName
  175. Dim iSmallestMerit
  176. Dim iCurrentMerit
  177. On Error Resume Next
  178. 'Merit for our localui logo
  179. iSmallestMerit = 300
  180. strLogoFileName = ""
  181. 'Create elementmgr and get resource elements
  182. Set objRetriever = CreateObject("Elementmgr.ElementRetriever")
  183. If Err.Number = 0 Then
  184. Set objLogoElementCol = objRetriever.GetElements(1, "OemLocalUILogo")
  185. If Err.Number = 0 Then
  186. 'count the icon and text resources
  187. For Each objLogoElement in objLogoElementCol
  188. iCurrentMerit = CInt(objLogoElement.GetProperty("Merit"))
  189. If iCurrentMerit <= iSmallestMerit Then
  190. iSmallestMerit = iCurrentMerit
  191. strLogoFileName = objLogoElement.GetProperty("ElementGraphic")
  192. End If
  193. Next
  194. End If
  195. End If
  196. Err.Clear
  197. 'Set the logo file
  198. If strLogoFileName <> "" Then
  199. SaLogo.src = strLogoFileName
  200. End If
  201. Set objRetriever = Nothing
  202. Set objLogoElement = Nothing
  203. Set objLogoElementCol = Nothing
  204. End Sub
  205. '----------------------------------------------------------------------------
  206. ' Function: HostNameEntry_OperationCanceled
  207. ' Description: Handles escape key press for hostname entry control
  208. ' Goes back to tasks page
  209. ' Input Variables: None
  210. ' Output Variables: None
  211. ' Return Values: None
  212. ' Global Variables: None
  213. '----------------------------------------------------------------------------
  214. Sub HostNameEntry_OperationCanceled()
  215. If bInDuplicateMode = true Then
  216. bInDuplicateMode = false
  217. Exit Sub
  218. End If
  219. window.history.go(-1)
  220. End Sub
  221. '----------------------------------------------------------------------------
  222. ' Function: HostNameEntry_KeyPressed
  223. ' Description: Handles any key press for hostname entry control
  224. ' Resets the idle timeout timer
  225. ' Input Variables: None
  226. ' Output Variables: None
  227. ' Return Values: None
  228. ' Global Variables: None
  229. '----------------------------------------------------------------------------
  230. Sub HostNameEntry_KeyPressed()
  231. window.clearTimeOut(iIdleTimeOut)
  232. iIdleTimeOut = window.SetTimeOut("IdleHandler()",300000)
  233. End Sub
  234. '----------------------------------------------------------------------------
  235. ' Function: HostNameEntry_DataEntered
  236. ' Description: Handles enter key press for hostname entry control
  237. ' Displays confirmation for reboot
  238. ' Input Variables: None
  239. ' Output Variables: None
  240. ' Return Values: None
  241. ' Global Variables: None
  242. '----------------------------------------------------------------------------
  243. Sub HostNameEntry_DataEntered()
  244. 'SaHelper component object
  245. Dim objSaHelper
  246. If bInDuplicateMode = true Then
  247. bInDuplicateMode = false
  248. Exit Sub
  249. End If
  250. On Error Resume Next
  251. Err.Clear
  252. 'Hide the data entry control
  253. HostNameEntry.style.display ="none"
  254. HeaderText.style.display ="none"
  255. Set objSaHelper = CreateObject("ServerAppliance.SAHelper")
  256. If Err.number = 0 Then
  257. bInDuplicateMode = objSaHelper.IsDuplicateMachineName(HostNameEntry.TextValue)
  258. If Err.number <> 0 Then
  259. InformationText.innerText = strUnknownErrorText
  260. InformationText.style.display = ""
  261. bInErrorMode = true
  262. ElseIf bInDuplicateMode = true Then
  263. InformationText.innerText = strDuplicateErrorText
  264. InformationText.style.display = ""
  265. Else
  266. 'Display the confirmation text
  267. InformationText.innerText = strRebootConfirmationText
  268. InformationText.style.display = ""
  269. InformationText.focus
  270. bInConfirmationMode = true
  271. End If
  272. Set objSaHelper = Nothing
  273. Else
  274. InformationText.innerText = strUnknownErrorText
  275. InformationText.style.display = ""
  276. bInErrorMode = true
  277. End If
  278. End Sub
  279. '----------------------------------------------------------------------------
  280. ' Function: KeyDown
  281. ' Description: Handles key presses
  282. ' Input Variables: None
  283. ' Output Variables: None
  284. ' Return Values: None
  285. ' Global Variables: None
  286. '----------------------------------------------------------------------------
  287. Sub KeyDown()
  288. 'SaHelper component object
  289. Dim objSaHelper
  290. On Error Resume Next
  291. Err.Clear
  292. 'clear the timeout and restart it
  293. window.clearTimeOut(iIdleTimeOut)
  294. iIdleTimeOut = window.SetTimeOut("IdleHandler()",300000)
  295. 'if we are rebooting, ignore all of the keys
  296. If bRebootingMachine = false Then
  297. 'If we are in error mode go to tasks page
  298. If bInErrorMode = true or bPartOfDomain = true Then
  299. If window.event.keycode = EscapeKey or window.event.keycode = EnterKey Then
  300. window.history.go(-1)
  301. End If
  302. End If
  303. 'If the name entered is duplicate, display the data entry component
  304. If bInDuplicateMode = true Then
  305. If window.event.keycode = EscapeKey or window.event.keycode = EnterKey Then
  306. InformationText.style.display = "none"
  307. HostNameEntry.style.display =""
  308. HeaderText.style.display =""
  309. HostNameEntry.focus
  310. End If
  311. End If
  312. If bInConfirmationMode = true Then
  313. 'User canceled go back to hostname data control
  314. If window.event.keycode = EscapeKey Then
  315. window.history.go(-1)
  316. End If
  317. If window.event.keycode = EnterKey Then
  318. Set objSaHelper = CreateObject("ServerAppliance.SAHelper")
  319. If Err.number = 0 Then
  320. objSaHelper.HostName = HostNameEntry.TextValue
  321. If Err.number <> 0 Then
  322. bInConfirmationMode = false
  323. InformationText.innerText = strUnknownErrorText
  324. bInErrorMode = true
  325. Else
  326. bInConfirmationMode = false
  327. bRebootingMachine = true
  328. RebootTheMachine
  329. End If
  330. Set objSaHelper = Nothing
  331. Else
  332. bInConfirmationMode = false
  333. InformationText.innerText = strUnknownErrorText
  334. bInErrorMode = true
  335. End If
  336. End If
  337. End If
  338. End If
  339. End Sub
  340. '----------------------------------------------------------------------------
  341. ' Function: RebootTheMachine
  342. ' Description: Reboots the machine
  343. ' Input Variables: None
  344. ' Output Variables: None
  345. ' Return Values: None
  346. ' Global Variables: None
  347. '----------------------------------------------------------------------------
  348. Sub RebootTheMachine
  349. 'TaskContext component
  350. Dim objTaskContext
  351. 'ApplianceServices component
  352. Dim objAS
  353. 'result of the execution
  354. Dim rc
  355. 'SAHelper component
  356. Dim objSAHelper
  357. 'result of privilege operation
  358. Dim bModifiedPrivilege
  359. 'privilege to modify
  360. Const CONST_SHUTDOWNPRIVILEGE = "SeShutdownPrivilege"
  361. bModifiedPrivilege = FALSE
  362. 'shutdown method name
  363. Const strMethodName = "ShutdownAppliance"
  364. 'hide the confirmation text and display the shutdown page
  365. InformationText.style.display = "none"
  366. SaLogo.style.display = ""
  367. SaShutdownText.style.display = ""
  368. SaDownArrow.style.display = ""
  369. On Error Resume Next
  370. Err.Clear
  371. 'Create SAHelper object
  372. Set objSAHelper = CreateObject("ServerAppliance.SAHelper")
  373. If err.number = 0 Then
  374. bModifiedPrivilege = objSAHelper.SAModifyUserPrivilege(CONST_SHUTDOWNPRIVILEGE, TRUE)
  375. End If
  376. bInErrorMode = true
  377. Set objTaskContext = CreateObject("Taskctx.TaskContext")
  378. If Err.Number = 0 Then
  379. Set objAS = CreateObject("Appsrvcs.ApplianceServices")
  380. If Err.Number = 0 Then
  381. 'set the parameters
  382. objTaskContext.SetParameter "Method Name", strMethodName
  383. objTaskContext.SetParameter "SleepDuration", 2000
  384. objTaskContext.SetParameter "PowerOff", "0"
  385. If Err.Number = 0 Then
  386. 'initialize the component
  387. objAS.Initialize()
  388. If Err.Number = 0 Then
  389. bInErrorMode = false
  390. 'execute the task
  391. rc = objAS.ExecuteTaskAsync("ApplianceShutdownTask", objTaskContext)
  392. End If
  393. End If
  394. Set objAS = Nothing
  395. End If
  396. Set objTaskContext = Nothing
  397. End If
  398. 'revert back the privilege
  399. If (bModifiedPrivilege) Then
  400. bModifiedPrivilege = objSAHelper.SAModifyUserPrivilege(CONST_SHUTDOWNPRIVILEGE, FALSE)
  401. End If
  402. Set objSAHelper = Nothing
  403. If bInErrorMode = true Then
  404. bRebootingMachine = false
  405. InformationText.innerText = strRebootErrorText
  406. 'display error text
  407. InformationText.style.display = ""
  408. 'hide the shutdown page
  409. SaLogo.style.display = "none"
  410. SaShutdownText.style.display = "none"
  411. SaDownArrow.style.display = "none"
  412. End If
  413. End Sub
  414. -->
  415. </SCRIPT>
  416. </HEAD>
  417. <BODY RIGHTMARGIN=0 LEFTMARGIN=0 OnKeydown="KeyDown">
  418. <OBJECT STYLE="position:absolute; top:32; left=0; WIDTH=128; HEIGHT=32; display=none;"
  419. ID="HostNameEntry" CLASSID="CLSID:538D1B58-8D5A-47C5-9867-4B6230A94EAC" VIEWASTEXT>
  420. </OBJECT>
  421. <IMG ID="SaLogo" STYLE="position:absolute; top:0; left=0; display:none"
  422. SRC="localui_salogo.bmp" BORDER=0>
  423. <A ID="HeaderText" OnKeydown="KeyDown"
  424. STYLE="position:absolute; top:16; left:0; font-size:10; font-family=arial; display=none;" >
  425. </A>
  426. <A ID="InformationText" OnKeydown="KeyDown"
  427. STYLE="position:absolute; top:0; left:0; font-size:10; font-family=arial; display=none;" >
  428. </A>
  429. <A ID="SaShutdownText" STYLE="position:absolute; top:36; left:0;
  430. font-size:10; font-family=arial; display:none">
  431. </A>
  432. <IMG ID="SaDownArrow" STYLE="position:absolute; top:48; left=0; display:none"
  433. SRC="localui_shutting_down.bmp" BORDER=0>
  434. </BODY>
  435. </HTML>