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.

1233 lines
41 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' shutdown_scheduleProp.asp : Schedule shutdown/restart property page.
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. ' Date Description
  10. ' 02-01-2001 Created Date
  11. ' 28-03-2001 Modified Date
  12. '-------------------------------------------------------------------------
  13. %>
  14. <!--#include virtual="/admin/inc_framework.asp"-->
  15. <!-- #include file="loc_Shutdown_msg.asp" -->
  16. <!-- #include file="inc_Shutdown.asp" -->
  17. <%
  18. '--------------------------------------------------------------------------
  19. 'Global Variables
  20. '--------------------------------------------------------------------------
  21. Dim page 'to hold the output page object when creating a page
  22. Dim rc 'to hold the return value for CreatePage
  23. Dim G_strScheduledTask 'to hold the action whether restart or shutdown
  24. Dim G_strScheduledTaskLoc 'to hold the localization copy of shutdown/restart
  25. Dim g_strWeekDay 'to hold the week day name
  26. Dim g_DaysofWeek 'to hold day of the week
  27. Dim g_intHours 'to hold Hours
  28. Dim g_intMins 'to hold Mins
  29. Dim g_intDays 'to hold Days
  30. Dim g_strTask 'to hold the Task scheduled
  31. Dim g_ScheduledShutdown 'to hold whether shutdown or restart is scheduled
  32. '-----------------------------------------------------------------------------
  33. 'Form Variables
  34. '-----------------------------------------------------------------------------
  35. Dim F_strScheduleAction 'to hold Selected Schedule
  36. Dim F_strScheduledOption 'to hold Schedduled date
  37. Dim F_strMinutes 'to hold Minutes for shutdown/restart
  38. Dim F_strHours 'to hold hour selected for shutdown/restart
  39. Dim F_strDays 'to hold days selected for shutdown/restart
  40. Dim F_DayName 'to hold selected day name
  41. Dim F_chkSendMessage 'to hold checkbox status of send message
  42. Dim F_strScheduledTime 'to hold scheduled time
  43. Dim F_strSelectedWeekDay 'to hold selected week day
  44. Const CONST_RESTART_APPLIANCE = "Restart"
  45. Const CONST_SHUTDOWN_APPLIANCE = "Shutdown"
  46. Const CONST_ACTION_SCHEDULE_CANCEL = 1
  47. Const CONST_ACTION_SCHEDULE_SHUTDOWN = 3
  48. Const CONST_ACTION_SCHEDULE_RESTART = 2
  49. Const CONST_SCHEDULE_DAYS_OPTION = 1
  50. Const CONST_SCHEDULE_WEEKDAYS_OPTION = 2
  51. Const CONST_RAISERESTARTALERT = 1
  52. Const CONST_RAISESHUTDOWNALERT = 1
  53. 'Create a Property Page
  54. rc=SA_CreatePage(L_SCHEDULE_SHUTDOWN_TEXT,"",PT_PROPERTY,page)
  55. If (rc=0) Then
  56. 'Serve the page
  57. SA_ShowPage(page)
  58. End If
  59. '-------------------------------------------------------------------------
  60. 'Function: OnInitPage()
  61. 'Description: Called to signal first time processing for this page.
  62. ' Use this method to do first time initialization tasks
  63. 'Input Variables: PageIn,EventArg
  64. 'Output Variables: PageIn,EventArg
  65. 'Returns: True/False
  66. 'Global Variables: None
  67. '-------------------------------------------------------------------------
  68. Public Function OnInitPage(ByRef PageIn,ByRef EventArg)
  69. Call SA_TraceOut("shutdown_scheduleprop", "OnInitPage")
  70. 'Check whether Shutdown or restart is scheduled
  71. if isScheduleShutdown then
  72. g_ScheduledShutdown = true
  73. 'get the date and time
  74. Call GetDateAndTime()
  75. end if
  76. OnInitPage=true
  77. End Function
  78. '-------------------------------------------------------------------------
  79. 'Function: OnServePropertyPage()
  80. 'Description: Called when the page needs to be served.Use this
  81. ' method to serve content
  82. 'Input Variables: PageIn,EventArg
  83. 'Output Variables: PageIn,EventArg
  84. 'Returns: True/False
  85. 'Global Variables: None
  86. '-------------------------------------------------------------------------
  87. Public Function OnServePropertyPage(ByRef PageIn,ByRef EventArg)
  88. Call SA_TraceOut("shutdown_scheduleprop", "OnServePropertyPage")
  89. If ( FALSE = IsSchedulerRunning() ) Then
  90. Call SA_ServeFailurePage(L_ERROR_SCHEDULER_SERVICE_NOT_RUNNING)
  91. Response.End
  92. OnServePropertyPage = FALSE
  93. Exit Function
  94. End If
  95. 'Serve client side script
  96. Call ServeCommonJavaScript()
  97. 'Serve the HTML content
  98. Call ServeUI()
  99. OnServePropertyPage=TRUE
  100. End Function
  101. '-------------------------------------------------------------------------
  102. 'Function: OnPostBackPage()
  103. 'Description: Called to signal that the page has been posted-back.
  104. 'Input Variables: PageIn,EventArg
  105. 'Output Variables: PageIn,EventArg
  106. 'Returns: True/False
  107. 'Global Variables: None
  108. '-------------------------------------------------------------------------
  109. Public Function OnPostBackPage(ByRef PageIn,ByRef EventArg)
  110. Call SA_TraceOut("shutdown_scheduleprop", "OnPostBackPage")
  111. F_strScheduleAction = trim(request("rdoschedule"))
  112. F_strScheduledOption = trim(request("rdoScheduleDate"))
  113. F_strMinutes = request("optMinutes")
  114. F_strHours = request("optHours")
  115. F_strDays = request("optDays")
  116. F_DayName = Request.Form("DayName")
  117. F_chkSendMessage = Request("chkSendMessage")
  118. F_strScheduledTime = Request("txtAtTime")
  119. F_strSelectedWeekDay = Request.Form("selWeekDay")
  120. OnPostBackPage=TRUE
  121. End Function
  122. '-------------------------------------------------------------------------
  123. 'Function: OnSubmitPage()
  124. 'Description: Called when the page has been submitted for processing.
  125. ' Use this method to process the submit request.
  126. 'Input Variables: PageIn,EventArg
  127. 'Output Variables: PageIn,EventArg
  128. 'Returns: True/False
  129. 'Global Variables/Constants:CONST_*
  130. '-------------------------------------------------------------------------
  131. Public Function OnSubmitPage(ByRef PageIn,ByRef EventArg)
  132. Err.Clear
  133. on error resume next
  134. Dim scheduledDayTime 'holds scheduled day and time
  135. Dim strHour 'holds scheduled time
  136. Dim scheduledOption 'holds scheduled option selected
  137. Dim scheduledMinute 'holds scheduled minute
  138. Dim scheduledHour 'holds scheduled hour
  139. Dim scheduledDay 'holds scheduled day
  140. Dim objFso 'holds filesystemobject
  141. Dim Windirectory 'holds path of windows directory
  142. Dim strPathDay 'holds shutdown executable file path
  143. Dim strPathWeekday
  144. Dim retVal 'holds returnValue
  145. Dim strCommand 'to hold the command to run
  146. Dim arrReplacementString 'to hold replacement string as an array to be passed as argument to raisealert
  147. Dim ScheduleAction 'can be one of Cancel scheduled one, restart or shutdown
  148. Redim arrReplacementString(2) 'dimensioned to hold date and time strings
  149. ScheduleAction = F_strScheduleAction
  150. if ScheduleAction = trim(CONST_ACTION_SCHEDULE_CANCEL) then
  151. 'user wants to delete all the scheduled shutdown or restarts
  152. 'Check whether to remove the pending shutdown /restart
  153. Call SA_TraceOut("shutdown_scheduleprop", "User cancelled the schedule for the shutdown")
  154. if isScheduleShutdown then
  155. DeleteSchedule()
  156. end if
  157. OnSubmitPage = True
  158. Exit Function
  159. end if
  160. 'Get Filesystem object
  161. set objFso = CreateObject("Scripting.FileSystemObject")
  162. Windirectory = objFso.GetSpecialFolder(1)
  163. 'Release the object
  164. set objFso = nothing
  165. ' Use different case to distinguish whether a scheduled job is weekday based or day based
  166. ' For example, if the win32_scheduledJob object.Command contains "TASKSHUTDOWN.EXE", it's day
  167. ' based. The solution is because of the difficulty to At.exe to generate weekday based
  168. ' win32_scheduledJob in localizied environment. Type At.exe/? in cmd line for details.
  169. strPathDay = Windirectory & "\ServerAppliance\Web\admin\shutdown\support\TASKSHUTDOWN.EXE "
  170. strPathWeekday = Windirectory & "\ServerAppliance\Web\admin\shutdown\support\taskshutdown.exe "
  171. 'Check whether to Schedule a Restart
  172. if ScheduleAction = trim(CONST_ACTION_SCHEDULE_RESTART) then
  173. Call SA_TraceOut("shutdown_scheduleprop", "User schedule for the restart")
  174. G_strScheduledTask=CONST_RESTART_APPLIANCE
  175. ' Assign the loc msg to G_strScheduledTaskLoc. We cannot directly assign the loc msg
  176. ' to G_strScheduledTask because it is used as a input for taskshutdown.exe, and
  177. ' taskshutdown.exe does not take shutdown|restart in English.
  178. G_strScheduledTaskLoc = L_RESTART_TEXT
  179. if isScheduleShutdown then
  180. DeleteSchedule()
  181. end if
  182. End if
  183. 'Check whether to Schedule a Shutdown
  184. if ScheduleAction = trim(CONST_ACTION_SCHEDULE_SHUTDOWN) then
  185. Call SA_TraceOut("shutdown_scheduleprop", "User schedule for the shutdown")
  186. G_strScheduledTask=CONST_SHUTDOWN_APPLIANCE
  187. ' Assign the loc msg to G_strScheduledTaskLoc
  188. G_strScheduledTaskLoc = L_SHUTDOWN_TEXT
  189. if isScheduleShutdown then
  190. DeleteSchedule()
  191. end if
  192. End if
  193. 'Get Date
  194. scheduledOption= F_strScheduledOption
  195. 'Get Day,Hour,Minute
  196. If scheduledOption= trim(CONST_SCHEDULE_DAYS_OPTION) then
  197. scheduledMinute=Dateadd("N",F_strMinutes,now())
  198. scheduledHour=Dateadd("H",F_strHours, scheduledMinute)
  199. scheduledDay=Dateadd("D",F_strDays, scheduledHour)
  200. scheduledDayTime=Day(scheduledDay)
  201. strHour= Hour(scheduledDay)&":"&Minute(scheduledDay)&":"&Second(scheduledDay)
  202. End if
  203. 'Form the message to schedule the task using AT command
  204. If scheduledOption=trim(CONST_SCHEDULE_DAYS_OPTION) then
  205. Call SA_TraceOut("shutdown_scheduleprop", "User schedule for the days option")
  206. arrReplacementString = split(cstr(scheduledDay)," ")
  207. if trim(arrReplacementString(2)) <> "" then
  208. arrReplacementString(1) = arrReplacementString(1) & " " & arrReplacementString(2)
  209. end if
  210. strCommand = "cmd.exe /c AT.exe "& replace(FormatDateTime(strHour,vbShortTime)," ","") &" /next:"& int(scheduledDayTime)& " " & strPathDay & " " & G_strScheduledTask
  211. Elseif trim(scheduledOption)=trim(CONST_SCHEDULE_WEEKDAYS_OPTION) then
  212. Call SA_TraceOut("shutdown_scheduleprop", "User schedule for the weedays option")
  213. arrReplacementString(0) = cstr(F_strSelectedWeekDay)
  214. arrReplacementString(1) = cstr(FormatDateTime(F_strScheduledTime,vbLongTime))
  215. If Err.number <> 0 then
  216. SA_SetErrMsg L_INVALID_DATE_FORMAT
  217. Exit Function
  218. End if
  219. ' Get the day for the selected weekday
  220. scheduledDayTime = CINT(GetDayForWeekday(F_strSelectedWeekDay))
  221. strCommand ="cmd.exe /c AT.exe "& replace(FormatDateTime(F_strScheduledTime,vbShortTime)," ","") &" /next:"& int(scheduledDayTime) & " " & strPathWeekday & " " & G_strScheduledTask
  222. 'strCommand ="cmd.exe /c AT.exe "& replace(FormatDateTime(F_strScheduledTime,vbShortTime)," ","") &" /next:"& F_strSelectedWeekDay & " " & strPath & " " & G_strScheduledTask
  223. End if
  224. 'Schedule selected task and raise alert
  225. if TaskSchedule(trim(strCommand),arrReplacementString) = true then
  226. 'Check whether SendMessage Check box is checked
  227. if F_chkSendMessage = "on" then
  228. If scheduledOption=trim(CONST_SCHEDULE_DAYS_OPTION) then
  229. call SendMessage(scheduledDay,G_strScheduledTask)
  230. Elseif scheduledOption=trim(CONST_SCHEDULE_WEEKDAYS_OPTION) then
  231. call SendMessage(Dateadd("d",F_DayName,Date) & " " & FormatDateTime(F_strScheduledTime,vbLongTime),G_strScheduledTask)
  232. end if
  233. end if
  234. OnSubmitPage= true
  235. else
  236. OnSubmitPage= false
  237. end if
  238. End Function
  239. '----------------------------------------------------------------------------------
  240. 'Function: OnClosePage()
  241. 'Description: Called when the page is about to be closed.Use this method
  242. ' to perform clean-up processing
  243. 'Input Variables: PageIn,EventArg
  244. 'Output Variables: PageIn,EventArg
  245. 'Returns: True/False
  246. 'Global Variables: None
  247. '----------------------------------------------------------------------------------
  248. Public Function OnClosePage(ByRef PageIn,ByRef EventArg)
  249. OnClosePage=TRUE
  250. End Function
  251. '-------------------------------------------------------------------------
  252. 'Function: ServeCommonJavaScript
  253. 'Description: Serves in initializing the values,setting the form
  254. ' data and validating the form values
  255. 'Input Variables: None
  256. 'Output Variables: None
  257. 'Returns: True/False
  258. 'Global Variables: None
  259. '-------------------------------------------------------------------------
  260. Function ServeCommonJavaScript()
  261. %>
  262. <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  263. </script>
  264. <script language="JavaScript">
  265. //
  266. // Microsoft Server Appliance Web Framework Support Functions
  267. // Copyright (c) Microsoft Corporation. All rights reserved.
  268. //
  269. // Init Function
  270. // -----------
  271. // This function is called by the Web Framework to allow the page
  272. // to perform first time initialization.
  273. //
  274. // This function must be included or a javascript runtime error will occur.
  275. //
  276. function Init()
  277. {
  278. // This code take care of retaining of state, if any error
  279. // reported in the execution of page
  280. var strScheduledTask = "<%= g_ScheduledShutdown %>";
  281. var strRdoschedule = '<%= SA_EscapeQuotes(F_strScheduleAction) %>';
  282. if (strRdoschedule != "" && strScheduledTask == "")
  283. {
  284. var optScheduledDate = '<%= SA_EscapeQuotes(F_strScheduledOption) %>';
  285. document.frmTask.rdoschedule[strRdoschedule - 1].checked = true;
  286. document.frmTask.rdoScheduleDate[optScheduledDate - 1].checked = true;
  287. // Check which date option is selected
  288. // if selected first date option
  289. if (optScheduledDate == 1)
  290. {
  291. var strDays = '<%=SA_EscapeQuotes(g_intDays)%>';
  292. document.frmTask.optDays.selectedIndex=strDays;
  293. var strHours = '<%=SA_EscapeQuotes(g_intHours)%>';
  294. document.frmTask.optHours.selectedIndex=strHours;
  295. var strMins = '<%=SA_EscapeQuotes(g_intMins)%>';
  296. document.frmTask.optMinutes.selectedIndex=strMins -1;
  297. }
  298. // if selected second date option
  299. if (optScheduledDate == 2)
  300. {
  301. document.frmTask.txtAtTime.value = '<%=SA_EscapeQuotes(F_strScheduledTime)%>';
  302. var strSelectedDay = '<%=SA_EscapeQuotes(F_strSelectedWeekDay)%>';
  303. var intDay = 0;
  304. switch (strSelectedDay)
  305. {
  306. case '<%=SA_EscapeQuotes(L_MONDAYMSG_TEXT)%>':
  307. intDay = 0;
  308. break;
  309. case '<%=SA_EscapeQuotes(L_TUESDAYMSG_TEXT)%>':
  310. intDay = 1;
  311. break;
  312. case '<%=SA_EscapeQuotes(L_WEDNESDAYMSG_TEXT)%>':
  313. intDay = 2;
  314. break;
  315. case '<%=SA_EscapeQuotes(L_THUSDAYMSG_TEXT)%>':
  316. intDay = 3;
  317. break;
  318. case '<%=SA_EscapeQuotes(L_FRIDAYMSG_TEXT)%>':
  319. intDay = 4;
  320. break;
  321. case '<%=SA_EscapeQuotes(L_SATURDAYMSG_TEXT)%>':
  322. intDay = 5;
  323. break;
  324. case '<%=SA_EscapeQuotes(L_SUNDAYMSG_TEXT)%>':
  325. intDay = 6;
  326. break;
  327. default:
  328. intDay = 0;
  329. }
  330. document.frmTask.selWeekDay.selectedIndex = intDay;
  331. }
  332. // Check for send message option
  333. var strSendMessage = '<%=SA_EscapeQuotes(F_chkSendMessage)%>';
  334. if (strSendMessage == "on")
  335. {
  336. document.frmTask.chkSendMessage.checked=true;
  337. }
  338. else
  339. {
  340. document.frmTask.chkSendMessage.checked=false;
  341. }
  342. return true; //exit function
  343. } // End of init function
  344. if (strScheduledTask == "True")
  345. {
  346. var WeekDay = '<%=SA_EscapeQuotes(g_strWeekDay) %>';
  347. document.frmTask.selWeekDay.selectedIndex=WeekDay;
  348. var strScheduleOption = '<%= SA_EscapeQuotes(g_DaysofWeek) %>';
  349. var strTask = '<%=SA_EscapeQuotes(g_strTask) %>';
  350. if (strScheduleOption == "True")
  351. {
  352. var strTime = '<%=SA_EscapeQuotes(g_intHours)%>' + ':' + '<%=SA_EscapeQuotes(g_intMins)%>';
  353. document.frmTask.txtAtTime.value = strTime;
  354. document.frmTask.rdoScheduleDate[1].checked = true;
  355. DisableSecondOption();
  356. }
  357. else
  358. {
  359. var strDays = '<%=SA_EscapeQuotes(g_intDays)%>';
  360. document.frmTask.optDays.selectedIndex=strDays;
  361. var strHours = '<%=SA_EscapeQuotes(g_intHours)%>';
  362. document.frmTask.optHours.selectedIndex=strHours;
  363. var strMins = '<%=SA_EscapeQuotes(g_intMins)%>';
  364. //strMins is set to 1 intentionally as the value in strMins is zero
  365. if (strMins == 0)
  366. strMins = 1;
  367. document.frmTask.optMinutes.selectedIndex=strMins -1;
  368. MakeDisable();
  369. }
  370. if (strTask == "Shutdown")
  371. {
  372. document.frmTask.rdoschedule[2].checked=true;
  373. }
  374. else if(strTask == "Restart")
  375. {
  376. document.frmTask.rdoschedule[1].checked=true;
  377. }
  378. else
  379. {
  380. document.frmTask.rdoschedule[0].checked=true;
  381. }
  382. }
  383. else
  384. {
  385. //function call to disable other controls
  386. document.frmTask.optDays.disabled=true;
  387. document.frmTask.optHours.disabled=true;
  388. document.frmTask.optMinutes.disabled=true;
  389. document.frmTask.rdoScheduleDate[0].checked=false;
  390. document.frmTask.rdoScheduleDate[1].checked=false;
  391. document.frmTask.rdoScheduleDate[0].disabled=true;
  392. document.frmTask.rdoScheduleDate[1].disabled=true;
  393. MakeDisable();
  394. document.frmTask.chkSendMessage.disabled=true;
  395. }
  396. }
  397. function RemoveDisable()
  398. {
  399. document.frmTask.selWeekDay.disabled=false;
  400. document.frmTask.txtAtTime.disabled=false;
  401. }
  402. function MakeDisable()
  403. {
  404. document.frmTask.selWeekDay.disabled=true;
  405. document.frmTask.txtAtTime.disabled=true;
  406. }
  407. function DisableFirstOption()
  408. {
  409. document.frmTask.optDays.disabled=false;
  410. document.frmTask.optHours.disabled=false;
  411. document.frmTask.optMinutes.disabled=false;
  412. }
  413. function DisableSecondOption()
  414. {
  415. document.frmTask.optDays.disabled=true;
  416. document.frmTask.optHours.disabled=true;
  417. document.frmTask.optMinutes.disabled=true;
  418. }
  419. // ValidatePage Function
  420. // ------------------
  421. // This function is called by the Web Framework as part of the
  422. // submit processing. Use this function to validate user input. Returning
  423. // false will cause the submit to abort.
  424. //
  425. // This function must be included or a javascript runtime error will occur.
  426. //
  427. // Returns: True if the page is OK, false if error(s) exist.
  428. function ValidatePage()
  429. {
  430. document.frmTask.DayName.value = (document.frmTask.selWeekDay.selectedIndex) - 1;
  431. document.frmTask.hdnrdoschedule.value = document.frmTask.rdoschedule.checked;
  432. if (document.frmTask.rdoScheduleDate[0].checked == true)
  433. {
  434. document.frmTask.hdnrdoScheduleDate.value = document.frmTask.rdoScheduleDate[0].value;
  435. }
  436. else if (document.frmTask.rdoScheduleDate[1].checked == true)
  437. {
  438. //check whether time at scheduled day is entered
  439. if(document.frmTask.txtAtTime.value == "")
  440. {
  441. DisplayErr('<%= SA_EscapeQuotes(L_INVALID_DATE_FORMAT)%>');
  442. document.frmTask.onkeypress = ClearErr;
  443. return false;
  444. }
  445. document.frmTask.hdnrdoScheduleDate.value = document.frmTask.rdoScheduleDate[1].value;
  446. }
  447. document.frmTask.hdnoptMinutes.value = document.frmTask.optMinutes.selectedIndex;
  448. document.frmTask.hdnoptHours.value = document.frmTask.optHours.selectedIndex;
  449. document.frmTask.hdnoptDays.value = document.frmTask.optDays.selectedIndex;
  450. document.frmTask.hdnchkSendMessage.value = document.frmTask.chkSendMessage.checked
  451. document.frmTask.hdntxtAtTime.value = document.frmTask.txtAtTime.value;
  452. document.frmTask.hdnselWeekDay.value = document.frmTask.selWeekDay.selectedIndex;
  453. return true;
  454. }
  455. // SetData Function
  456. // --------------
  457. // This function is called by the Web Framework and is called
  458. // only if ValidatePage returned a success (true) code. Typically you would
  459. // modify hidden form fields at this point.
  460. //
  461. // This function must be included or a javascript runtime error will occur.
  462. //
  463. function SetData()
  464. {
  465. return true;
  466. }
  467. //Function to disable other controlls when default option is selected
  468. function enableControls()
  469. {
  470. var ScheduleDate = document.frmTask.rdoScheduleDate;
  471. if(ScheduleDate[0].checked == false && ScheduleDate[1].checked == false || ScheduleDate[0].checked == true)
  472. {
  473. document.frmTask.optDays.disabled=false;
  474. document.frmTask.optHours.disabled=false;
  475. document.frmTask.optMinutes.disabled=false;
  476. document.frmTask.chkSendMessage.disabled=false;
  477. ScheduleDate[0].checked = true;
  478. ScheduleDate[0].disabled = false;
  479. ScheduleDate[1].disabled = false;
  480. return true;
  481. }
  482. if(ScheduleDate[1].checked == true)
  483. {
  484. document.frmTask.optDays.disabled=true;
  485. document.frmTask.optHours.disabled=true;
  486. document.frmTask.optMinutes.disabled=true;
  487. document.frmTask.chkSendMessage.disabled=false;
  488. document.frmTask.selWeekDay.disabled=false;
  489. document.frmTask.txtAtTime.disabled=false;
  490. ScheduleDate[1].checked = true;
  491. ScheduleDate[1].disabled = false;
  492. return true;
  493. }
  494. }
  495. function DisableControls()
  496. {
  497. document.frmTask.selWeekDay.disabled=true;
  498. document.frmTask.txtAtTime.disabled=true;
  499. document.frmTask.rdoScheduleDate[1].checked=false;
  500. //document.frmTask.rdoScheduleDate[1].checked=false;
  501. document.frmTask.optDays.disabled=true;
  502. document.frmTask.optHours.disabled=true;
  503. document.frmTask.optMinutes.disabled=true;
  504. document.frmTask.rdoScheduleDate[0].checked=false;
  505. document.frmTask.rdoScheduleDate[0].disabled=true;
  506. document.frmTask.rdoScheduleDate[1].disabled=true;
  507. document.frmTask.chkSendMessage.disabled=true;
  508. }
  509. </script>
  510. <%
  511. End Function
  512. '----------------------------------------------------------------------------------
  513. 'Function: ServeUI()
  514. 'Description: Called to serve UI
  515. 'Input Variables: L_*;
  516. 'Output Variables: None
  517. 'Functions Used: GetListboxvalue()
  518. 'Returns: True/False
  519. 'Global Variables: L_*, F_*
  520. '----------------------------------------------------------------------------------
  521. Function ServeUI()
  522. Call SA_TraceOut("shutdown_scheduleprop", "ServeUI")
  523. %>
  524. <TABLE WIDTH=518 VALIGN=CENTER ALIGN=left BORDER=0 CELLSPACING=0 CELLPADDING=2>
  525. <tr>
  526. <td class="TasksBody" NOWRAP>
  527. <INPUT type="radio" id=rad name=rdoschedule value=1 checked onclick="DisableControls();"> <%=L_NOSCHEDULE_TEXT%>
  528. </td>
  529. </tr>
  530. <tr>
  531. <td class="TasksBody" width=25% NOWRAP>
  532. <INPUT type="radio" id=rad name=rdoschedule value=2 onclick="enableControls();"> <%=L_RESTARTSCHEDULED_TEXT%>
  533. </td>
  534. </tr>
  535. <tr>
  536. <td class="TasksBody" width=25% NOWRAP>
  537. <INPUT type="radio" id=rad name=rdoschedule value=3 onclick="enableControls();"> <%=L_SHUTDOWNSCHEDULED_TEXT%>
  538. </td>
  539. </tr>
  540. <tr>
  541. <td class="TasksBody" width=25% NOWRAP>
  542. <hr>
  543. </td>
  544. </tr>
  545. <tr>
  546. <td class="TasksBody" width=25% >
  547. <INPUT type="radio" name="rdoScheduleDate" value=1 checked OnClick="MakeDisable();DisableFirstOption()">&nbsp;
  548. <SELECT name=optDays >
  549. <%=GetListboxvalue(0,27,"days")%>
  550. </SELECT>&nbsp;<%=L_DAYS_TEXT%>&nbsp;
  551. <SELECT name=optHours>
  552. <%=GetListboxvalue(0,24,"Hrs")%>
  553. </SELECT>&nbsp;<%=L_HOURS_TEXT%>&nbsp;
  554. <SELECT name=optMinutes>
  555. <%=GetListboxvalue(1,60,"Min")%>
  556. </SELECT>&nbsp;<%=L_MINUTESFROMNOW_TEXT%>
  557. </td>
  558. </tr>
  559. <tr>
  560. <td>
  561. &nbsp;
  562. </td>
  563. </tr>
  564. <tr>
  565. <td nowrap width=25% class="TasksBody">
  566. <%=L_OR_TEXT%>
  567. </td>
  568. </tr>
  569. <tr>
  570. <td>
  571. &nbsp;
  572. </td>
  573. </tr>
  574. <tr>
  575. <td width=25% nowrap class="TasksBody">
  576. <INPUT type="radio" name="rdoScheduleDate" value=2 OnClick="RemoveDisable();DisableSecondOption()"><%=L_ONTHENEXT_TEXT%>
  577. <SELECT name=selWeekDay>
  578. <OPTION value="<%=L_MONDAYMSG_TEXT%>"><%=L_MONDAYMSG_TEXT%></OPTION >
  579. <OPTION value="<%=L_TUESDAYMSG_TEXT%>"><%=L_TUESDAYMSG_TEXT%></OPTION >
  580. <OPTION value="<%=L_WEDNESDAYMSG_TEXT%>"><%=L_WEDNESDAYMSG_TEXT%> </OPTION >
  581. <OPTION value="<%=L_THUSDAYMSG_TEXT%>"><%=L_THUSDAYMSG_TEXT%> </OPTION >
  582. <OPTION value="<%=L_FRIDAYMSG_TEXT%>"><%=L_FRIDAYMSG_TEXT%> </OPTION >
  583. <OPTION value="<%=L_SATURDAYMSG_TEXT%>"><%=L_SATURDAYMSG_TEXT%></OPTION>
  584. <OPTION value="<%=L_SUNDAYMSG_TEXT%>"><%=L_SUNDAYMSG_TEXT%></OPTION >
  585. </SELECT>&nbsp;<%=L_AT_TEXT%>&nbsp;
  586. <input type=text name=txtAtTime value="<%= F_strScheduledTime %>" maxlength=12 size=15>
  587. </td>
  588. </tr>
  589. <tr>
  590. <td class="TasksBody">
  591. &nbsp;
  592. </td>
  593. </tr>
  594. <tr>
  595. <td class="TasksBody">
  596. &nbsp;
  597. </td>
  598. </tr>
  599. <tr>
  600. <td class="TasksBody">
  601. <input NAME="chkSendMessage" TYPE="Checkbox" > <%=L_NETSENDWARNING_TEXT%>
  602. </td>
  603. </tr>
  604. </TABLE>
  605. <input type = hidden name = "DayName" value="F_DayName">
  606. <input type = hidden name = "hdnrdoschedule" value="<%=F_strScheduleAction%>">
  607. <input type = hidden name = "hdnrdoScheduleDate" value="<%=F_strScheduledOption%>">
  608. <input type = hidden name = "hdnoptMinutes" value="<%=F_strMinutes%>">
  609. <input type = hidden name = "hdnoptHours" value="<%=F_strHours%>">
  610. <input type = hidden name = "hdnoptDays" value="<%=F_strDays%>">
  611. <input type = hidden name = "hdnchkSendMessage" value="<%=F_chkSendMessage%>">
  612. <input type = hidden name = "hdntxtAtTime" value="<%=F_strScheduledTime%>">
  613. <input type = hidden name = "hdnselWeekDay" value="<%=F_strSelectedWeekDay%>">
  614. <%
  615. End Function
  616. '-------------------------------------------------------------------------
  617. 'Function: GetListboxvalue()
  618. 'Description: Called to get list box value
  619. 'Input Variables: Min,Max
  620. 'Output Variables: None
  621. 'Returns: True/False
  622. 'Global Variables: None
  623. '-------------------------------------------------------------------------
  624. Function GetListboxvalue(Min,Max,Val)
  625. Dim nMaxLoopValue 'hold max value
  626. Dim nMinLoopValue 'hold min value
  627. Call SA_TraceOut("shutdown_scheduleprop", "GetListboxvalue")
  628. For nMaxLoopValue = Min to Max
  629. If nMaxLoopValue <= 9 then
  630. nMinLoopValue = "0" & nMaxLoopValue
  631. Else
  632. nMinLoopValue = nMaxLoopValue
  633. End if
  634. If (Val = "Min") Then
  635. %>
  636. <OPTION value=<%=nMinLoopValue%> ><%=nMinLoopValue%></OPTION>
  637. <%
  638. Else
  639. %>
  640. <OPTION value=<%=nMinLoopValue%> ><%=nMaxLoopValue%></OPTION>
  641. <%
  642. End if
  643. Next
  644. End function
  645. '-------------------------------------------------------------------------
  646. 'Function: TaskSchedule()
  647. 'Description: Function to schedule shutdown /restart
  648. 'Input Variables: strCommand,ReplacementString
  649. 'Output Variables: None
  650. 'Returns: True/False
  651. 'Global Variables: G_*, L_*
  652. '-------------------------------------------------------------------------
  653. Function TaskSchedule(strCommand,ReplacementString)
  654. Err.clear
  655. On Error Resume Next
  656. Dim strCurDir 'holds current directory
  657. Dim returnValue 'holds return value
  658. Dim objFso 'holds File System object
  659. Dim Windirectory 'holds Window directory path
  660. Dim Alertid 'holds the alert ID
  661. Dim arrRepStrings 'holds the replacement strings
  662. redim arrRepStrings(1)
  663. ' Assign a loc msg for output error msg
  664. arrRepStrings(0) = cstr(G_strScheduledTaskLoc)
  665. TaskSchedule=false
  666. Call SA_TraceOut("shutdown_scheduleprop", "calling shutdownraise alert func " + G_strScheduledTask)
  667. set objFso = CreateObject("Scripting.FileSystemObject")
  668. Windirectory = objFso.GetSpecialFolder(0)
  669. strCurDir=left(Windirectory,3)
  670. 'Release the object
  671. set objFso = nothing
  672. returnValue = LaunchProcess(strCommand, strCurDir)
  673. If Err.number<> 0 then
  674. TaskSchedule=False
  675. L_UNABLETOLAUNCHPROCESS_ERRORMESSAGE = SA_GetLocString("sashutdown_msg.dll", "C040001F", arrRepStrings)
  676. SA_SetErrMsg L_UNABLETOLAUNCHPROCESS_ERRORMESSAGE & "(" & Err.number & ")"
  677. Exit function
  678. End if
  679. Alertid = 1
  680. if returnValue = 0 then
  681. Call SA_TraceOut("shutdown_scheduleprop.asp", "calling shutdownraise inside if ")
  682. 'Raise alert for the scheduled task
  683. if UCase(G_strScheduledTask) = ucase(CONST_RESTART_APPLIANCE) then
  684. Call SA_TraceOut("shutdown_scheduleprop.asp","inside if RestartPending")
  685. retval = ShutdownRaiseAlert(Alertid,"RestartPending",ReplacementString)
  686. elseif UCase(G_strScheduledTask) = ucase(CONST_SHUTDOWN_APPLIANCE) then
  687. Call SA_TraceOut("shutdown_scheduleprop.asp","inside if ShutdownPending")
  688. retval = ShutdownRaiseAlert(Alertid,"ShutdownPending",ReplacementString)
  689. end if
  690. Call SA_TraceOut("shutdown_scheduleprop.asp",UCase(G_strScheduledTask) + ucase(CONST_RESTART_APPLIANCE) )
  691. end if
  692. TaskSchedule = true
  693. End Function
  694. '-------------------------------------------------------------------------
  695. 'Function: DeleteSchedule
  696. 'Description: Serves in deleting the scheduled task
  697. 'Input Variables: None
  698. 'Output Variables: None
  699. 'Returns: True/False
  700. 'Global Variables/Constants:L_(*)-Localization Strings, CONST_*
  701. '-------------------------------------------------------------------------
  702. Function DeleteSchedule()
  703. Err.Clear
  704. On Error Resume Next
  705. Dim objWMIConnection 'To get WMI connection
  706. Dim objSchedule 'To get instance of wmi class
  707. Dim strSchedule 'To hold scheduled task instance
  708. Dim strVal 'To get the value of task run(shutdown or restart)
  709. Call SA_TraceOut("shutdown_scheduleprop", "DeleteSchedule")
  710. 'getting wmi connection
  711. set objWMIConnection = getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  712. 'taking the instance of wmi class responsible for scheduling
  713. set objSchedule=objWMIConnection.Instancesof("Win32_ScheduledJob")
  714. 'deleting a scheduled task
  715. for each strSchedule in objSchedule
  716. strVal = Ucase(right(strSchedule.Command,15))
  717. 'Check for restart entry
  718. if instr(1,strVal,Ucase(CONST_RESTART_APPLIANCE),1) > 0 then
  719. strSchedule.Delete()
  720. if Err.number <> 0 then
  721. SA_SetErrMsg L_UNABLETODELETE_SCHEDULEDTASK_ERRORMESSAGE
  722. Else
  723. 'Clear the Restart alert message
  724. DeleteAlert(CONST_RAISERESTARTALERT) ' the arg is alert ID
  725. End if
  726. 'Check for shutdown entry
  727. elseif instr(1,strVal,Ucase(CONST_SHUTDOWN_APPLIANCE),1) > 0 then
  728. strSchedule.Delete()
  729. if Err.number <> 0 then
  730. SA_SetErrMsg L_UNABLETODELETE_SCHEDULEDTASK_ERRORMESSAGE
  731. Else
  732. 'Clear the Shutdown alert message
  733. DeleteAlert(CONST_RAISESHUTDOWNALERT)' the arg is alert ID
  734. End if
  735. end if
  736. next
  737. If Err.number<>0 then
  738. SA_SetErrMsg L_UNABLETODELETE_SCHEDULEDTASK_ERRORMESSAGE
  739. DeleteSchedule=False
  740. Exit Function
  741. End If
  742. DeleteSchedule=True
  743. 'destroying dynamically created objects
  744. Set objWMIConnection=Nothing
  745. Set objSchedule=Nothing
  746. End Function
  747. '-------------------------------------------------------------------------
  748. 'Function: GetDateAndTime
  749. 'Description: gets the date and time
  750. 'Input Variables: None
  751. 'Output Variables: None
  752. 'Returns: Date and Time
  753. 'Global Variables/Constants:L_*, CONST_*, g_*
  754. '-------------------------------------------------------------------------
  755. Function GetDateAndTime()
  756. Err.Clear
  757. on error resume next
  758. Dim objWMIConnection 'To get WMI connection
  759. Dim objSchedule 'To get instance of wmi class
  760. Dim strScheduleType 'To get type of scheduled task
  761. Dim strSchedule 'To get scheduled task results
  762. Dim strHours 'To hold time in hours
  763. Dim strMins 'To hold time in mins
  764. Const CONST_RESTARTAPPLIANCE = "Restart"
  765. Const CONST_SHUTDOWNAPPLIANCE= "Shutdown"
  766. Const CONST_HOURSPERDAY = 24
  767. Call SA_TraceOut("shutdown_scheduleprop", "GetDateAndTime")
  768. 'getting wmi connection
  769. set objWMIConnection = getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  770. 'getting the instance of wmi class responsible for scheduling
  771. set objSchedule=objWMIConnection.Instancesof("Win32_ScheduledJob")
  772. If Err.number <>0 Then
  773. SA_SetErrMsg L_WMICLASSINSTANCEFAILED_ERRORMESSAGE
  774. Exit Function
  775. End If
  776. for each strSchedule in objSchedule
  777. 'getting the type of scheduled task
  778. strScheduleType=Ucase(right(strSchedule.Command,8))
  779. 'checking the scheduled task type
  780. If instr(strScheduleType,Ucase(CONST_RESTARTAPPLIANCE))>0 then
  781. g_strTask = CONST_RESTARTAPPLIANCE
  782. elseIf instr(strScheduleType,Ucase(CONST_SHUTDOWNAPPLIANCE))>0 then
  783. g_strTask = CONST_SHUTDOWNAPPLIANCE
  784. end if
  785. 'check whether shutdown or restart is scheduled already
  786. if g_strTask = CONST_RESTARTAPPLIANCE or g_strTask = CONST_SHUTDOWNAPPLIANCE then
  787. strHours = mid(strSchedule.StartTime,9,2)
  788. strMins = mid(strSchedule.StartTime,11,2)
  789. if inStr(1, trim(strSchedule.Command), "TASKSHUTDOWN.EXE", 0) then 'find whether Days of Month is not null
  790. 'if not isnull(trim(strSchedule.DaysOfMonth)) then 'find whether Days of Month is not null
  791. g_DaysofWeek = false
  792. 'get the date of schedule
  793. Call GetDate(strSchedule.DaysOfMonth,strHours,strMins)
  794. exit function
  795. elseif inStr( trim(strSchedule.Command), "taskshutdown") then
  796. g_DaysofWeek = true
  797. g_intHours = mid(strSchedule.StartTime,9,2)
  798. g_intMins = mid(strSchedule.StartTime,11,2)
  799. 'get the date of schedule
  800. 'Call GetDateforWeek(strSchedule.DaysOfWeek)
  801. Call GetWeekdayForDate(strSchedule.DaysOfMonth)
  802. exit function
  803. end if
  804. end if
  805. Next
  806. 'Release the objects
  807. set objWMIConnection = nothing
  808. set objSchedule = nothing
  809. End function
  810. '-------------------------------------------------------------------------
  811. 'Function: GetDateforWeek
  812. 'Description: gets the date in terms of day
  813. 'Input Variables: intWeek
  814. 'Output Variables: None
  815. 'Returns: Day of the week
  816. 'Global Variables: g_strWeekDay
  817. '-------------------------------------------------------------------------
  818. Function GetDateforWeek(intWeek)
  819. Dim count 'to hold count
  820. Call SA_TraceOut("shutdown_scheduleprop", "GetDateforWeek")
  821. for count = 0 to 6
  822. if 2 ^ count = intWeek then
  823. g_strWeekDay = count
  824. end if
  825. next
  826. End Function
  827. '-------------------------------------------------------------------------
  828. 'Function: GetDate
  829. 'Description: gets the date in terms of day
  830. 'Input Variables: intDays, intHours, intMins
  831. 'Output Variables: None
  832. 'Returns: Day of the week
  833. 'Global Variables: g_*
  834. '-------------------------------------------------------------------------
  835. Function GetDate(intDays,intHours,intMins)
  836. Dim count 'hold the count
  837. Dim strdaysScheduledFor 'hold the days for the task scheduled
  838. Dim strCurrentDate 'hold the current date
  839. Dim strScheduledDate 'hold the scheduled date
  840. Dim strScheduledMonth 'hold the scheduled month
  841. Dim strScheduledYear 'hold the scheduled year
  842. Dim strHours 'hold the hours part
  843. Dim strMinute 'hold the minutes part
  844. CONST CONST_MINUTESPERDAY = 1440
  845. CONST CONST_MAXDAYS = 27
  846. CONST CONST_MAXHOURS = 24
  847. CONST CONST_MINUTESPERHOUR = 60
  848. Call SA_TraceOut("shutdown_scheduleprop", "GetDate")
  849. for count = 0 to 31
  850. if 2 ^ count = intDays then
  851. strdaysScheduledFor = count + 1
  852. end if
  853. next
  854. 'get the current date
  855. strCurrentDate = Date()
  856. if strdaysScheduledFor < day(date()) then
  857. strScheduledMonth = Month(DateAdd("m",1,Date()))
  858. strScheduledYear = year(Date())
  859. else
  860. strScheduledMonth = Month(Date())
  861. strScheduledYear = year(Date())
  862. end if
  863. 'format the scheduled date using the universal format
  864. strScheduledDate = strScheduledYear & "-" & strScheduledMonth & "-" & strdaysScheduledFor
  865. Dim strDate
  866. strDate = strScheduledDate & " " & formatdatetime(intHours & ":" & intMins & ":00",vbLongTime)
  867. ' Format the date to the current localization setting
  868. strDate = formatdatetime(strDate, vbGeneralDate)
  869. 'get the difference in minutes between current date and scheduled date
  870. strMinute = datediff("n",now, strDate)
  871. 'if minutes are more than one day(1440 minutes)
  872. if strMinute > CONST_MINUTESPERDAY then
  873. g_intDays = int(strMinute/CONST_MINUTESPERDAY)
  874. strMinute = strMinute - (g_intDays * CONST_MINUTESPERDAY)
  875. g_intHours = int(strMinute/ CONST_MINUTESPERHOUR)
  876. g_intMins = strMinute mod CONST_MINUTESPERHOUR
  877. else
  878. g_intDays = 0
  879. g_intHours = cint(strMinute) / CONST_MINUTESPERHOUR
  880. g_intMins = strMinute mod CONST_MINUTESPERHOUR
  881. end if
  882. 'Check for the max days(last element in the days dropdown box)
  883. if g_intDays > CONST_MAXDAYS then
  884. g_intdays = CONST_MAXDAYS
  885. g_intHours = CONST_MAXHOURS
  886. g_intMins = strMinute
  887. end if
  888. End Function
  889. '-------------------------------------------------------------------------
  890. 'Function: GetDayForWeekday
  891. 'Description: Get the day for a weekday. For example, if next
  892. ' Monday is 3/20/2002, it returns 20
  893. 'Input Variables: strWeekday
  894. 'Output Variables: None
  895. 'Returns: day
  896. 'Global Variables: None
  897. '-------------------------------------------------------------------------
  898. Function GetDayForWeekday( strWeekday )
  899. Dim iToday
  900. Dim dayInterval
  901. Dim strDate
  902. Dim iWeekday
  903. iWeekday = GetWeekday(strWeekday)
  904. ' Get today's date
  905. iToday = Weekday(date)
  906. dayInterval = iWeekday - iToday
  907. If dayInterval < 1 Then
  908. dayInterval = dayInterval + 7
  909. End If
  910. ' Get the date for the input weekday
  911. strDate = DateAdd("D", dayInterval, date)
  912. GetDayForWeekday = Day(strDate)
  913. End Function
  914. '-------------------------------------------------------------------------
  915. 'Function: GetWeekDay
  916. 'Description: gets the weekday
  917. 'Input Variables: strWeekday
  918. 'Output Variables: None
  919. 'Returns: weekday
  920. 'Global Variables: None
  921. '-------------------------------------------------------------------------
  922. Function GetWeekday(strWeekday)
  923. if ( strWeekday = L_SUNDAYMSG_TEXT ) Then
  924. GetWeekday = vbSunday
  925. elseif ( strWeekday = L_MONDAYMSG_TEXT ) Then
  926. GetWeekday = vbMonday
  927. elseif ( strWeekday = L_TUESDAYMSG_TEXT ) Then
  928. GetWeekday = vbTuesday
  929. elseif ( strWeekday = L_WEDNESDAYMSG_TEXT ) Then
  930. GetWeekday = vbWednesday
  931. elseif ( strWeekday = L_THUSDAYMSG_TEXT ) Then
  932. GetWeekday = vbThursday
  933. elseif ( strWeekday = L_FRIDAYMSG_TEXT ) Then
  934. GetWeekday = vbFriday
  935. elseif ( strWeekday = L_SATURDAYMSG_TEXT ) Then
  936. GetWeekday = vbSaturday
  937. end if
  938. End Function
  939. '-------------------------------------------------------------------------
  940. 'Function: GetWeekdayForDate
  941. 'Description: gets the date in terms of day
  942. 'Input Variables: intDay
  943. 'Output Variables: None
  944. 'Returns: Day of the week
  945. 'Global Variables: g_strWeekday
  946. '-------------------------------------------------------------------------
  947. Function GetWeekdayForDate(intDays)
  948. Dim count 'hold the count
  949. Dim strdaysScheduledFor 'hold the days for the task scheduled
  950. Dim strScheduledMonth 'hold the scheduled month
  951. Dim strScheduledYear 'hold the scheduled year
  952. Dim strScheduledWeekday 'hold the scheduled weekday
  953. for count = 0 to 31
  954. if 2 ^ count = intDays then
  955. strdaysScheduledFor = count + 1
  956. end if
  957. next
  958. if strdaysScheduledFor < day(date()) then
  959. strScheduledMonth = Month(DateAdd("m",1,Date()))
  960. strScheduledYear = year(Date())
  961. else
  962. strScheduledMonth = Month(Date())
  963. strScheduledYear = year(Date())
  964. end if
  965. ' Get the weekday of the date
  966. g_strWeekDay = weekday( strScheduledYear & "-" & strScheduledMonth & "-" & strdaysScheduledFor)
  967. ' Convert it to the index number to select from the weekday list
  968. g_strWeekday = CInt((g_strWeekday + 7 - 2) mod 7)
  969. End function
  970. Public Function IsSchedulerRunning()
  971. Dim oWMI
  972. Dim oService
  973. IsSchedulerRunning = FALSE
  974. Set oWMI = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  975. Set oService = oWMI.Get("Win32_Service.Name='Schedule'")
  976. If ( Err.Number <> 0 ) Then
  977. Exit Function
  978. End If
  979. If ( oService.State = "Running" ) Then
  980. IsSchedulerRunning = TRUE
  981. End If
  982. Set oService = Nothing
  983. Set oWMI = Nothing
  984. End Function
  985. %>