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.

358 lines
12 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' RebootSys.asp :Page for Rebooting the system when Device Name or
  6. ' Domain or Workgroup Name or DNS Suffix has changed.
  7. '
  8. ' Copyright (c) Microsoft Corporation. All rights reserved.
  9. '
  10. ' Date Description
  11. ' 22/01/2001 Created Date
  12. '-------------------------------------------------------------------------
  13. %>
  14. <!-- #include virtual="/admin/inc_framework.asp" -->
  15. <!-- #include file="loc_deviceid.asp" -->
  16. <%
  17. '-------------------------------------------------------------------------
  18. ' Global Variables
  19. '-------------------------------------------------------------------------
  20. Dim rc
  21. Dim page
  22. CONST CONST_DELAYBEFORESHUTDOWN=17000
  23. '======================================================
  24. ' Entry point
  25. '======================================================
  26. ' Create a Property Page
  27. rc = SA_CreatePage(L_TASKTITLE_REBOOT_TEXT, "", PT_PROPERTY, page )
  28. If rc = SA_NO_ERROR Then
  29. ' Serve the page
  30. SA_ShowPage( page )
  31. End If
  32. '======================================================
  33. ' Web Framework Event Handlers
  34. '======================================================
  35. '---------------------------------------------------------------------
  36. 'Function name: OnInitPage
  37. 'Description: Called to signal first time processing for this page.
  38. ' Used to do first time initialization tasks.
  39. 'Input Variables: PageIn, EventArg
  40. 'Output Variables: None
  41. 'Return Values: TRUE to indicate initialization was successful. FALSE to indicate
  42. ' errors. Returning FALSE will cause the page to be abandoned.
  43. 'Global Variables: In: None
  44. ' Out: None
  45. '---------------------------------------------------------------------
  46. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  47. OnInitPage = TRUE
  48. End Function
  49. '---------------------------------------------------------------------
  50. 'Function name: OnServePropertyPage
  51. 'Description: Called when the page needs to be served. Used to
  52. ' serve content.
  53. 'Input Variables: PageIn, EventArg
  54. 'Output Variables: None
  55. 'Return Values: TRUE to indicate success. FALSE to indicate
  56. ' errors. Returning FALSE will cause the page to be abandoned.
  57. 'Global Variables: In:None
  58. '---------------------------------------------------------------------
  59. Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  60. ' Emit Javascript functions required by Web Framework
  61. Call ServeCommonJavaScript()
  62. %>
  63. <table border="0" cellspacing="0" cellpadding="0" >
  64. <tr>
  65. <td class="TasksBody" ><%= L_RESTART_ALERT_TEXT %></td>
  66. </tr>
  67. <tr>
  68. <td class="TasksBody" ><%= L_RESTART_ALERT_CONTD_TEXT %></td>
  69. </tr>
  70. </table>
  71. <%
  72. OnServePropertyPage = TRUE
  73. End Function
  74. '---------------------------------------------------------------------
  75. 'Function name: OnSubmitPage
  76. 'Description: Called when the page has been submitted for processing. Use
  77. ' this method to process the submit request.
  78. 'Input Variables: PageIn, EventArg
  79. 'Output Variables: None
  80. 'Return Values: TRUE if the submit was successful, FALSE to indicate error(s).
  81. ' Returning FALSE will cause the page to be served again using
  82. ' a call to OnServePropertyPage.
  83. 'Global Variables: In: None
  84. ' Out: None
  85. '---------------------------------------------------------------------
  86. Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  87. OnSubmitPage = RebootComputer()
  88. End Function
  89. '---------------------------------------------------------------------
  90. 'Function name: OnClosePage
  91. 'Description: Called when the page is about to be closed.
  92. ' Used to perform clean-up processing.
  93. 'Input Variables: PageIn, EventArg
  94. 'Output Variables: None
  95. 'Return Values: TRUE to allow close, FALSE to prevent close. Returning FALSE
  96. ' will result in a call to OnServePropertyPage.
  97. 'Global Variables: In: None
  98. ' Out: None
  99. '---------------------------------------------------------------------
  100. Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  101. OnClosePage = TRUE
  102. End Function
  103. '---------------------------------------------------------------------
  104. 'Function: OnPostBackPage
  105. 'Description: Called to signal that the page has been posted-back.
  106. 'Input Variables: PageIn,EventArg
  107. 'Output Variables: None
  108. 'Returns: True/False
  109. 'Global Variables: None
  110. '---------------------------------------------------------------------
  111. Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  112. OnPostBackPage = TRUE
  113. End Function
  114. '======================================================
  115. ' Private Functions
  116. '======================================================
  117. '---------------------------------------------------------------------
  118. 'Function name: ServeCommonJavaScript
  119. 'Description: Serve common javascript that is required for this page type.
  120. 'Input Variables: None
  121. 'Output Variables: None
  122. 'Return Values: TRUE / FALSE
  123. 'Global Variables: In:None
  124. ' Out:None
  125. '---------------------------------------------------------------------
  126. Function ServeCommonJavaScript()
  127. %>
  128. <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  129. </script>
  130. <script language="JavaScript">
  131. //
  132. // Microsoft Server Appliance Web Framework Support Functions
  133. // Copyright (c) Microsoft Corporation. All rights reserved.
  134. //
  135. // Init Function
  136. // -----------
  137. // This function is called by the Web Framework to allow the page
  138. // to perform first time initialization.
  139. //
  140. // This function must be included or a javascript runtime error will occur.
  141. //
  142. function Init()
  143. {
  144. // no initializations required presently
  145. }
  146. // ValidatePage Function
  147. // ------------------
  148. // This function is called by the Web Framework as part of the
  149. // submit processing. Used to validate user input. Returning
  150. // false will cause the submit to abort.
  151. //
  152. // This function must be included or a javascript runtime error will occur.
  153. //
  154. // Returns: True if the page is OK, false if error(s) exist.
  155. function ValidatePage()
  156. {
  157. // no validations required presently. return true to submit.
  158. return true;
  159. }
  160. // SetData Function
  161. // --------------
  162. // This function is called by the Web Framework and is called
  163. // only if ValidatePage returned a success (true) code. Typically
  164. // hidden form fields are modified at this point.
  165. //
  166. // This function must be included or a javascript runtime error will occur.
  167. //
  168. function SetData()
  169. {
  170. // no data to be set presently
  171. }
  172. </script>
  173. <%
  174. End Function
  175. '---------------------------------------------------------------------
  176. 'Function name : RebootComputer
  177. 'Description : Reboots the computer
  178. 'Input Variables : None
  179. 'Output Variables : None
  180. 'Return Values : Returns True/False
  181. 'Global Variables: In:None
  182. ' Out:None
  183. '---------------------------------------------------------------------
  184. Function RebootComputer()
  185. On Error Resume Next
  186. Err.Clear
  187. Dim objSAHelper
  188. Dim bModifiedPrivilege
  189. Const CONST_SHUTDOWNPRIVILEGE = "SeShutdownPrivilege"
  190. bModifiedPrivilege = FALSE
  191. 'Create SAHelper object
  192. Set objSAHelper = Server.CreateObject("ServerAppliance.SAHelper")
  193. if err.number <> 0 Then
  194. SA_TraceOut "Create object failed for SAHelper object", err.description
  195. else
  196. 'enable shutdown privilege
  197. bModifiedPrivilege = objSAHelper.SAModifyUserPrivilege(CONST_SHUTDOWNPRIVILEGE, TRUE)
  198. if err.number <> 0 Then
  199. SA_TraceOut "Enable privilege failed", err.description
  200. exit function
  201. end if
  202. end if
  203. RebootComputer = FALSE ' initialize to false
  204. ' Restart requested
  205. ' Invoke shutdown task
  206. If ( ExecuteShutdownTask("0") ) Then
  207. ' Serve the restaring page which will wait for the appliance to restart
  208. Call SA_ServeRestartingPage("Restart", SA_DEFAULT, SA_DEFAULT, SA_DEFAULT, SA_DEFAULT, SA_DEFAULT)
  209. RebootComputer = TRUE
  210. End If
  211. if ( bModifiedPrivilege ) then
  212. 'revert back to disabled state
  213. bModifiedPrivilege = objSAHelper.SAModifyUserPrivilege(CONST_SHUTDOWNPRIVILEGE, FALSE)
  214. if err.number <> 0 Then
  215. SA_TraceOut "Disable privilege failed", err.description
  216. exit function
  217. end if
  218. end if
  219. set objSAHelper = Nothing
  220. End Function
  221. '----------------------------------------------------------------------------
  222. ' Function : ExecuteShutdownTask
  223. ' Description: Executes the Shutdown task
  224. ' Input Variables: powerOff - bool indicating power off or restart
  225. ' OutputVariables: None
  226. ' Returns: True/False for success/failure
  227. '
  228. '----------------------------------------------------------------------------
  229. Public Function ExecuteShutdownTask(ByVal powerOff )
  230. Err.Clear
  231. On Error Resume Next
  232. Dim delayBeforeShutdown
  233. Dim objTaskContext ' to hold taskcontext object
  234. Dim objAS ' to hold ApplianceServices object
  235. Const CONST_METHODNAME = "ShutdownAppliance"
  236. 'Function call to get the delay
  237. delayBeforeShutdown = GetShutdownDelay()
  238. 'Initialize to default
  239. ExecuteShutdownTask = FALSE
  240. Set objTaskContext = CreateObject("Taskctx.TaskContext")
  241. If Err.Number <> 0 Then
  242. SA_SetErrMsg L_TASKCTX_FAILED_ERRORMESSAGE & "(" & Hex(Err.Number) & ")"
  243. Exit Function
  244. End If
  245. Set objAS = CreateObject("Appsrvcs.ApplianceServices")
  246. If Err.Number <> 0 Then
  247. SA_SetErrMsg L_CREATEAPPLIANCE_FAILED_ERRORMESSAGE & "(" & Hex(Err.Number) & ")"
  248. Exit Function
  249. End If
  250. '
  251. ' Set task parameters
  252. '
  253. objTaskContext.SetParameter "Method Name", CONST_METHODNAME
  254. objTaskContext.SetParameter "SleepDuration", delayBeforeShutdown
  255. objTaskContext.SetParameter "PowerOff", powerOff
  256. If Err.Number <> 0 Then
  257. SA_SetErrMsg L_SETPARAMETER_FAILED_ERRORMESSAGE & "(" & Hex(Err.Number) & ")"
  258. Exit Function
  259. End If
  260. ' Initialize the task
  261. objAS.Initialize()
  262. If Err.Number <> 0 Then
  263. SA_SetErrMsg L_INITIALIZATION_FAILED_ERRORMESSAGE & "(" & Hex(Err.Number) & ")"
  264. Exit Function
  265. End If
  266. Call objAS.ExecuteTaskAsync("ApplianceShutdownTask", objTaskContext)
  267. If Err.Number <> 0 Then
  268. SA_SetErrMsg L_EXECUTETASK_FAILED_ERRORMESSAGE & "(" & Hex(Err.Number) & ")"
  269. Exit Function
  270. End If
  271. 'Release the objects
  272. Set objAS = Nothing
  273. Set objTaskContext = Nothing
  274. ExecuteShutdownTask = TRUE
  275. End Function
  276. '----------------------------------------------------------------------------
  277. ' Function : GetShutdownDelay
  278. ' Description : support function for getting the no of seconds
  279. ' Input Variables : None
  280. ' OutputVariables : None
  281. ' Returns : int-delay in seconds
  282. ' Global Variables : In:CONST_DELAYBEFORESHUTDOWN
  283. '----------------------------------------------------------------------------
  284. Private Function GetShutdownDelay()
  285. On error resume Next
  286. Dim objRegistry
  287. Dim nShutdownDelay
  288. Set objRegistry = RegConnection()
  289. 'Function call to get the required value from the registry
  290. nShutdownDelay = GetRegkeyValue( objRegistry, _
  291. "SOFTWARE\Microsoft\ServerAppliance\WebFramework",_
  292. "RestartTaskDelay", CONST_DWORD)
  293. 'Cheking for non numeric
  294. If ( not IsNumeric(nShutdownDelay)) Then
  295. nShutdownDelay = CONST_DELAYBEFORESHUTDOWN 'Assign to default
  296. ElseIf nShutdownDelay=0 or nShutdownDelay < CONST_DELAYBEFORESHUTDOWN then
  297. nShutdownDelay = CONST_DELAYBEFORESHUTDOWN 'Assign to default
  298. End If
  299. 'Set to nothing
  300. Set objRegistry = Nothing
  301. GetShutdownDelay=nShutdownDelay
  302. If Err.Number <> 0 Then
  303. Call SA_TraceOut(SA_GetScriptFileName , "error in getting delay")
  304. End If
  305. End Function
  306. %>