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.

274 lines
9.5 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit
  3. '-------------------------------------------------------------------------
  4. ' service_dispatch.asp This is the customised page which acts as a
  5. ' intemediate page for redirecting to respective pages
  6. ' (with task that to be done)
  7. '
  8. ' Copyright (c) Microsoft Corporation. All rights reserved.
  9. '
  10. ' Date Description
  11. ' 09 Aug 2000 Creation Date
  12. ' 15 mar 2001 Creation Date
  13. '-------------------------------------------------------------------------
  14. %>
  15. <!-- #include virtual="/admin/inc_framework.asp" -->
  16. <!-- #include file="loc_services.asp" -->
  17. <%
  18. '-------------------------------------------------------------------------
  19. 'Global Variables
  20. '-------------------------------------------------------------------------
  21. Dim G_strURL 'url obtained
  22. Dim G_strPageType 'page type to get from registry
  23. Dim G_FlagNotDisable 'flag value for not disable key
  24. Dim G_arrPkeyvalue 'pkey array
  25. Dim G_strPkeyValue 'pKey value
  26. Dim G_PageTitle 'page title on browser that has to be passed through query string
  27. Const CONST_SERVICES_CONTAINER = "SERVICES"
  28. Const CONST_FLAGNOTDISABLE = 1 'notdisable reg key value - service cannot disable
  29. G_arrPkeyvalue = split(Request.QueryString("Pkey") ,"~")
  30. G_strPkeyValue = G_arrPkeyvalue(0)
  31. 'to get url,page type from registry
  32. Call GetServicePropertyURL(G_strPkeyValue, G_strURL, G_strPageType)
  33. G_strURL = m_VirtualRoot + G_strURL
  34. 'page url is set and redirecting to the respective page depending on the request
  35. Call setPageURL()
  36. '-------------------------------------------------------------------------
  37. ' Function name: setPageURL
  38. ' Description: page url is set and redirecting to the respective
  39. ' page depending on the request
  40. ' Input Variables: None
  41. ' Output Variables: None
  42. ' Return Values: None
  43. ' Global Variables: strReturnUrl,strPageRedirectURL
  44. '-------------------------------------------------------------------------
  45. Sub setPageURL()
  46. Dim strPkeyvalue 'pkey value
  47. Dim strReturnUrl 'return url
  48. Dim tab1 'tab1
  49. Dim tab2 'tab2
  50. 'getting tab 1 and tab2 values
  51. tab1 = GetTab1()
  52. tab2 = GetTab2()
  53. 'obtaining qurystring variables
  54. strPkeyvalue = G_strPkeyValue
  55. 'return url obtained from previous page- query string
  56. strReturnUrl = Request.QueryString("ReturnUrl")
  57. Call SA_MungeURL(strReturnUrl, "service", "")
  58. 'properties page -- on clicking properties page
  59. 'Frame set url
  60. If ( 0 = StrComp(UCase(G_strPageType), "FRAMESET", vbTextCompare)) Then
  61. Dim strFrameSetURL
  62. ' URL for requested page
  63. If ( Len(strPkeyvalue ) > 0 ) Then
  64. Call SA_MungeURL(G_strURL, "PKey", strPkeyvalue)
  65. End If
  66. Call SA_MungeURL(G_strURL, SAI_FLD_PAGEKEY, SAI_GetPageKey())
  67. '
  68. ' Frameset for this page
  69. strFrameSetURL = m_VirtualRoot + "sh_taskframes.asp"
  70. 'appending the title to the url
  71. Call SA_MungeURL(strFrameSetURL, "Title", G_PageTitle)
  72. Call SA_MungeURL(strFrameSetURL, "URL", G_strURL)
  73. If ( Len(tab1) > 0 ) Then
  74. Call SA_MungeURL(strFrameSetURL, "Tab1", tab1)
  75. End If
  76. If ( Len(tab2) > 0 ) Then
  77. Call SA_MungeURL(strFrameSetURL, "Tab2", tab2)
  78. End If
  79. Call SA_MungeURL(strFrameSetURL, "ReturnUrl", strReturnUrl)
  80. Call SA_MungeURL(strFrameSetURL, SAI_FLD_PAGEKEY, SAI_GetPageKey())
  81. SA_TraceOut "SERVICE_DISPATCH", "Redirect to frameset URL: " + strFrameSetURL
  82. 'redirecting to properties page
  83. Response.Redirect ( strFrameSetURL )
  84. Else
  85. 'appending the title to the url
  86. Call SA_MungeURL(G_strURL, "Title", G_PageTitle)
  87. Call SA_MungeURL(G_strURL, "PKey", strPkeyvalue)
  88. SA_TraceOut "SERVICE_DISPATCH", "Redirect to normal page URL: " + G_strURL
  89. 'adding the return url content
  90. Call SA_MungeURL(G_strURL, "ReturnUrl", strReturnUrl)
  91. Call SA_MungeURL(G_strURL, SAI_FLD_PAGEKEY, SAI_GetPageKey())
  92. 'redirecting to no properties page --when there no configuration properties for the selected service
  93. Response.Redirect( G_strURL )
  94. End If
  95. End Sub
  96. '-------------------------------------------------------------------------
  97. ' Function name: IsSameElementID
  98. ' Description: Compares 2 service names and returns true if they are
  99. ' same else false
  100. ' Input Variables: sElementID1 - System Service
  101. ' sElementID2 - Manged service
  102. ' Output Variables: None
  103. ' Return Values: True if equals else false
  104. ' Global Variables: None
  105. '-------------------------------------------------------------------------
  106. Function IsSameElementID(ByVal sElementID1, ByVal sElementID2)
  107. Err.Clear
  108. on error resume next
  109. Dim s1, s2
  110. s1 = LCase(Trim(sElementID1))
  111. s2 = LCase(Trim(sElementID2))
  112. IsSameElementID = CBool(s1 = s2)
  113. End Function
  114. '-------------------------------------------------------------------------
  115. ' Function name: GetServicePropertyURL
  116. ' Description: Serves in getting the Service URL from Registry.
  117. ' Input Variables: strServiceName,strServicePropURL,G_strPageType
  118. ' Output Variables: strServicePropURL,G_strPageType
  119. ' Return Values: None
  120. ' Global Variables: 1/0
  121. '-------------------------------------------------------------------------
  122. Function GetServicePropertyURL(ByVal strServiceName, ByRef strServicePropURL, ByRef G_strPageType)
  123. Dim sElementID 'element id
  124. Dim objElement 'element object
  125. Dim objManagedServices 'services obtained from registry
  126. Err.Clear
  127. on error resume next
  128. GetServicePropertyURL = 0
  129. strServicePropURL = ""
  130. Set objManagedServices = SA_GetElements(CONST_SERVICES_CONTAINER)
  131. For Each objElement In objManagedServices
  132. sElementID = objElement.GetProperty("ServiceName")
  133. If IsSameElementID(sElementID, strServiceName) Then
  134. strServicePropURL = objElement.GetProperty("URL")
  135. G_strPageType = objElement.GetProperty("PageType")
  136. If ( Err.Number <> 0 ) Then
  137. SA_TraceOut "SERVICE_DISPATCH", "GetServicePropertyURL encountered error: " + CStr(Hex(Err.Number))
  138. End If
  139. GetServicePropertyURL = 1
  140. 'getting the flag for cannot disable the service
  141. G_FlagNotDisable = objElement.GetProperty("NotDisable")
  142. 'getting the title
  143. G_PageTitle = SA_GetLocString(objElement.GetProperty("Source"), objElement.GetProperty("ServiceNameRID"), "") & " " & L_TASKTITLE_TEXT
  144. Exit For
  145. End If
  146. Next
  147. Set objManagedServices = nothing
  148. If GetServicePropertyURL <> 1 Then
  149. SA_TraceOut "SERVICE_DISPATCH", "Cound not locate Service Specific URL for service: " + strServiceName
  150. End If
  151. End Function
  152. '-------------------------------------------------------------------------
  153. ' Function name: GetServiceState
  154. ' Description: Serves in getting the Service status
  155. ' Input Variables: strServiceName
  156. ' Output Variables: None
  157. ' Return Values: Returns the state of the service
  158. ' Global Variables: None
  159. '-------------------------------------------------------------------------
  160. Function GetServiceState(strServicename)
  161. Err.Clear
  162. On Error Resume Next
  163. Dim objService 'services list
  164. Dim strWMIPath 'wmi path
  165. Dim objWMIService 'wmi object
  166. GetServiceState = ""
  167. strWMIPath = "Win32_Service.Name=" & chr(34) & strServicename & chr(34)
  168. 'connecting to WMI
  169. Set objWMIService = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  170. If ( Err.Number <> 0 ) Then
  171. Call SA_TraceOut(SA_GetScriptFileName(), "WMI Connection error: " & Hex(Err.Number) & " " & Err.Description)
  172. Exit Function
  173. End If
  174. set objService = objWMIService.get(strWMIPath)
  175. If ( Err.Number <> 0 ) Then
  176. Call SA_TraceOut(SA_GetScriptFileName(), "WMI.get(" & strWMIPath & " ) error: " & Hex(Err.Number) & " " & Err.Description)
  177. Exit Function
  178. End If
  179. GetServiceState = objService.StartMode
  180. If ( Err.Number <> 0 ) Then
  181. Call SA_TraceOut(SA_GetScriptFileName(), "objService.StartMode error: " & Hex(Err.Number) & " " & Err.Description)
  182. Exit Function
  183. End If
  184. Set objService = Nothing
  185. Set objWMIService = Nothing
  186. End Function
  187. '-------------------------------------------------------------------------
  188. ' Function name: CheckServiceStatus
  189. ' Description: Serves in getting the Service status
  190. ' Input Variables: strRequest,strService
  191. ' Output Variables: None
  192. ' Return Values: True- when present service status is the same as requested.
  193. ' False- when present service status is not the same as requested.
  194. ' Global Variables: None
  195. '-------------------------------------------------------------------------
  196. Function CheckServiceStatus(Byval strRequest,Byval strService)
  197. Dim strServiceStatus 'service state variable
  198. Const CONST_ENABLE = "Enable"
  199. Const CONST_DISABLE = "Disable"
  200. Const CONST_AUTO = "Auto"
  201. Const CONST_DISABLED = "Disabled"
  202. 'services status is obtained by given input
  203. If lcase(strRequest) = lcase(CONST_ENABLE) then
  204. strRequest = CONST_AUTO
  205. Else IF lcase(strRequest) = lcase(CONST_DISABLE) then
  206. strRequest = CONST_DISABLED
  207. End IF
  208. End If
  209. 'gets the service state
  210. strServiceStatus = GetServiceState(strService)
  211. 'check if the present service status is the same as requested.
  212. If lcase(strRequest) = lcase(strServiceStatus) then
  213. CheckServiceStatus = True
  214. Else
  215. CheckServiceStatus = False
  216. End if
  217. End Function
  218. %>