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.

430 lines
12 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' nfslocks_prop.asp: Displays NFS Locks and facilitates for deletion
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. ' Date Description
  10. '21-sep-00 Creation date
  11. '-------------------------------------------------------------------------
  12. %>
  13. <!-- #include virtual="/admin/inc_framework.asp" -->
  14. <!-- #include file="loc_NFSSvc.asp"-->
  15. <%
  16. On Error Resume Next
  17. Err.clear
  18. '-------------------------------------------------------------------------
  19. ' Form Variables
  20. '-------------------------------------------------------------------------
  21. Dim F_nWaitPeriod 'Wait Period for the appliance
  22. Dim F_strClientsToRelease 'Save the clients to be released
  23. '-------------------------------------------------------------------------
  24. ' Global Variables
  25. '-------------------------------------------------------------------------
  26. Dim G_objService 'object to WMI Service
  27. Dim G_strComputerName 'Local machine name
  28. Dim G_objLock
  29. F_nWaitPeriod = 0
  30. F_strClientsToRelease = ""
  31. set G_objService = GetWMIConnection("root\SFUAdmin")
  32. Set G_objLock = Server.CreateObject("NFSLockEnum.1")
  33. '-------------------------------------------------------------------------
  34. ' Create the page and Event handler
  35. '-------------------------------------------------------------------------
  36. Dim page
  37. Dim rc
  38. rc = SA_CreatePage(L_TASKTITLE_LOCKS_TEXT, "", PT_PROPERTY, page)
  39. If rc = 0 Then
  40. SA_ShowPage( page )
  41. End If
  42. Public Function OnInitPage( ByRef PageIn, ByRef EventArg)
  43. SetVariablesFromSystem
  44. OnInitPage = True
  45. End Function
  46. Public Function OnPostBackPage( ByRef PageIn, ByRef EventArg)
  47. SetVariablesFromForm
  48. OnPostBackPage = True
  49. End Function
  50. Public Function OnServePropertyPage( ByRef PageIn, ByRef EventArg)
  51. Err.Clear
  52. On Error Resume Next
  53. Call ServeCommonJavaScript()
  54. if not isServiceInstalled(getWMIConnection(CONST_WMI_WIN32_NAMESPACE),_
  55. "nfssvc") then
  56. SA_ServeFailurePage L_NFSNOTINSTALLED_ERRORMESSAGE
  57. end if
  58. %>
  59. <TABLE WIDTH=500 VALIGN=middle ALIGN=left BORDER=0 CELLSPACING=0
  60. CELLPADDING=2 class="TasksBody">
  61. <TR>
  62. <TD VALIGN=TOP ALIGN=LEFT nowrap>
  63. <%=L_CURRENTLOCKS_TEXT%>
  64. </TD>
  65. <TD>
  66. &nbsp;
  67. </TD>
  68. <TD nowrap>
  69. <%=L_LOCKSELECTHELP_TEXT%>
  70. </TD>
  71. </TR>
  72. <TR>
  73. <TD>
  74. &nbsp;
  75. </TD>
  76. <TD>
  77. &nbsp;
  78. </TD>
  79. <TD>
  80. <SELECT NAME =lstLockedClients class ="FormField"
  81. multiple = true STYLE="WIDTH:180px" SIZE="6" >
  82. <%ServeNFSClients()%>
  83. </SELECT>
  84. </TD>
  85. </TR>
  86. <TR><TD colspan=3>&nbsp;</TD></TR>
  87. <TR>
  88. <TD nowrap>
  89. <%=L_WAITPERIOD_TEXT%>
  90. </TD>
  91. <TD>
  92. &nbsp;
  93. </TD>
  94. <TD>
  95. <INPUT TYPE="TEXT" NAME = txtWaitPeriod VALUE =
  96. "<%=F_nWaitPeriod%>" class ="FormField"
  97. STYLE="WIDTH:120px" OnKeypress=
  98. "javaScript:checkkeyforNumbers(this)" >
  99. </TD>
  100. </TR>
  101. <TR>
  102. <TD>
  103. &nbsp;
  104. </TD>
  105. <TD>
  106. &nbsp;
  107. </TD>
  108. <TD>
  109. <%=L_WAITPERIODHELP_TEXT%><BR>
  110. </TD>
  111. </TR>
  112. </TABLE>
  113. <INPUT NAME="hdnWaitPeriod" TYPE="hidden" VALUE="<%=F_nWaitPeriod%>">
  114. <INPUT NAME="hdnClientsToRelease" TYPE="hidden" VALUE="<%=F_strClientsToRelease%>">
  115. </INPUT>
  116. <%
  117. OnServePropertyPage = True
  118. End Function
  119. Public Function OnSubmitPage( ByRef PageIn, ByRef EventArg)
  120. OnSubmitPage = setNFSLocksProp()
  121. End Function
  122. Public Function OnClosePage( ByRef PageIn, ByRef EventArg)
  123. OnClosePage = True
  124. End Function
  125. Function ServeCommonJavaScript()
  126. %>
  127. <script language = "JavaScript" src = "<%=m_VirtualRoot%>inc_global.js">
  128. </script>
  129. <script language = "JavaScript">
  130. function Init()
  131. {
  132. }
  133. function ValidatePage()
  134. {
  135. var objForm = eval("document.frmTask");
  136. if(objForm.txtWaitPeriod.value > 3600)
  137. {
  138. DisplayErr("<%=Server.HTMLEncode(L_INVALIDWAITPERIOD_ERRORMESSAGE)%>");
  139. return false;
  140. }
  141. return true;
  142. }
  143. function SetData()
  144. {
  145. var strleng;
  146. var strMembers="";
  147. var objForm = eval("document.frmTask");
  148. strleng=objForm.lstLockedClients.length;
  149. for (i=0;i<strleng;i++)
  150. {
  151. if(objForm.lstLockedClients.options[i].selected)
  152. {
  153. if (strMembers == "")
  154. strMembers=objForm.lstLockedClients.options[i].value;
  155. else
  156. strMembers= strMembers + "#" + objForm.lstLockedClients.
  157. options[i].value;
  158. }
  159. }
  160. objForm.hdnClientsToRelease.value=strMembers;
  161. objForm.hdnWaitPeriod.value = objForm.txtWaitPeriod.value;
  162. }
  163. //function to allow only numbers
  164. function checkkeyforNumbers(obj)
  165. {
  166. if (!(window.event.keyCode >=48 && window.event.keyCode <=57))
  167. {
  168. window.event.keyCode = 0;
  169. obj.focus();
  170. }
  171. }
  172. </script>
  173. <%
  174. End Function
  175. '-------------------------------------------------------------------------
  176. ' Function name: SetVariablesFromSystem
  177. ' Description: Serves in Getting the data from System.
  178. ' Input Variables: None
  179. ' Output Variables: None
  180. ' Return Values: None
  181. ' Global Variables:
  182. '-------------------------------------------------------------------------
  183. Function SetVariablesFromSystem
  184. Err.Clear
  185. On Error Resume Next
  186. F_nWaitPeriod = getGracePeriod()
  187. F_strClientsToRelease = ""
  188. End Function
  189. '-------------------------------------------------------------------------
  190. ' Function name: SetVariablesFromForm
  191. ' Description: Serves in Getting the data from Form.
  192. ' Input Variables: None
  193. ' Output Variables: None
  194. ' Return Values: None
  195. ' Global Variables:
  196. '-------------------------------------------------------------------------
  197. Function SetVariablesFromForm
  198. Err.Clear
  199. On Error Resume Next
  200. F_nWaitPeriod = Request.Form ("hdnWaitPeriod")
  201. F_strClientsToRelease = Request.Form ("hdnClientsToRelease")
  202. End Function
  203. '-------------------------------------------------------------------------
  204. ' Function Name: getGracePeriod
  205. ' Description: gets the Grace period from system
  206. ' Input Variables: None
  207. ' Output Variables: None
  208. ' Returns: Graceperiod
  209. ' Global Variables: G_objService - object to WMI service
  210. '-------------------------------------------------------------------------
  211. Function getGracePeriod()
  212. Err.Clear
  213. On Error Resume Next
  214. Dim nfsfiles_case
  215. Dim nfsfiles_settings
  216. Set nfsfiles_case= G_objService.Get( _
  217. "NFSServer_Files.KeyName='parameters'")
  218. Set nfsfiles_settings = G_objService.Get( _
  219. "NFSServer_Files.KeyName='NlmNsm'")
  220. GetGracePeriod = nfsfiles_settings.GracePeriod
  221. End Function
  222. '-------------------------------------------------------------------------
  223. ' Function Name: setGracePeriod
  224. ' Description: sets the grace period into system
  225. ' Input Variables: nNewgracePeriod - New grace period from form
  226. ' Output Variables: None
  227. ' Returns: True on Successfull deletion of locks Otherwise false.
  228. ' Global Variables: In: G_objService - object to WMI service
  229. '-------------------------------------------------------------------------
  230. Function setGracePeriod(nNewgracePeriod)
  231. Err.Clear
  232. On Error Resume Next
  233. Dim nfsfiles_case
  234. Dim nfsfiles_settings
  235. SetGracePeriod = FALSE
  236. Set nfsfiles_case= G_objService.Get( _
  237. "NFSServer_Files.KeyName='parameters'")
  238. Set nfsfiles_settings = G_objService.Get( _
  239. "NFSServer_Files.KeyName='NlmNsm'")
  240. nfsfiles_settings.GracePeriod = nNewgracePeriod
  241. nfsfiles_settings.put_()
  242. If Err.number <> 0 Then
  243. Exit Function
  244. End if
  245. SetGracePeriod = TRUE
  246. End Function
  247. '-------------------------------------------------------------------------
  248. ' Function Name: ServeNFSClients
  249. ' Description: serves NFS clients into listbox
  250. ' Input Variables: None
  251. ' Output Variables: None
  252. ' Returns: None
  253. ' Global Variables:
  254. '-------------------------------------------------------------------------
  255. Function ServeNFSClients()
  256. On Error Resume Next
  257. Err.Clear
  258. Dim objNFSLocks
  259. Set objNFSLocks = Server.CreateObject("NFSLockEnum.1")
  260. objNFSLocks.machine = GetComputerName()
  261. objNFSLocks.listlocks()
  262. objNFSLocks.movefirst()
  263. Dim numCount
  264. Dim i
  265. numCount = objNFSLocks.clientCount
  266. For i = 0 to numCount-1
  267. Response.Write "<OPTION VALUE="""
  268. Response.write objNFSLocks.clientName
  269. Response.write """>"
  270. Response.write objNFSLocks.clientName
  271. Response.Write "</OPTION>"
  272. objNFSLocks.moveNext()
  273. Next
  274. If Err.number <> 0 Then
  275. SA_ServeFailurePage L_RETRIEVELOCKS_ERRORMESSAGE
  276. Exit Function
  277. End if
  278. Set objNFSLocks = nothing
  279. End Function
  280. '-------------------------------------------------------------------------
  281. ' Function Name: ReleaseLocks
  282. ' Description: Deletes the client locks
  283. ' Input Variables: None
  284. ' Output Variables: None
  285. ' Returns: True on Successfull deletion of locks Otherwise false.
  286. ' Global Variables: None
  287. '-------------------------------------------------------------------------
  288. Function ReleaseLocks()
  289. Err.Clear
  290. On Error Resume Next
  291. Dim i
  292. Dim strMembers
  293. strMembers = Split(F_strClientsToRelease,"#")
  294. For i = 0 to ubound(strMembers)
  295. G_objLock.releaseLocks(strMembers(i))
  296. Next
  297. If Err.number <> 0 Then
  298. ReleaseLocks = FALSE
  299. Exit Function
  300. End if
  301. ReleaseLocks = TRUE
  302. End Function
  303. '-------------------------------------------------------------------------
  304. ' Function Name: setNFSLocksProp
  305. ' Description: Deletes the Group name
  306. ' Input Variables: None
  307. ' Output Variables: None
  308. ' Returns: True on Successfull deletion of locks Otherwise false.
  309. ' Global Variables:
  310. '-------------------------------------------------------------------------
  311. Function setNFSLocksProp()
  312. Err.Clear
  313. On Error Resume Next
  314. If not(setGracePeriod(F_nWaitPeriod)) Then
  315. SetErrMsg L_SETWAITPERIOD_ERRORMESSAGE
  316. setNFSLocksProp = FALSE
  317. Exit Function
  318. End if
  319. If Not ReleaseLocks() Then
  320. SetErrMsg L_RELEACELOCKS_ERRORMESSAGE
  321. setNFSLocksProp = FALSE
  322. Exit Function
  323. End if
  324. setNFSLocksProp = TRUE
  325. End function
  326. '-------------------------------------------------------------------------
  327. 'Function name: isServiceInstalled
  328. 'Description:helper Function to chek whether the function is there or not
  329. 'Input Variables: objService - object to WMI
  330. ' strServiceName - Service name
  331. 'Output Variables: None
  332. 'Returns: (True/Flase)
  333. 'GlobalVariables: None
  334. '-------------------------------------------------------------------------
  335. Function isServiceInstalled(ObjWMI,strServiceName)
  336. Err.clear
  337. on error resume next
  338. Dim strService
  339. strService = "name=""" & strServiceName & """"
  340. isServiceInstalled = IsValidWMIInstance(ObjWMI,"Win32_Service", _
  341. strService)
  342. end Function
  343. '-------------------------------------------------------------------------
  344. 'Function name: IsValidWMIInstance
  345. 'Description: Checks the instance for valid ness.
  346. 'Input Variables: objService - object to WMI
  347. ' strClassName - WMI class name
  348. ' strPropertyName - Property name of the class
  349. '
  350. 'Output Variables: None
  351. 'Returns: Returns true on Valid Instance ,
  352. ' False on invalid and also on Error
  353. ' Checks whether the given instance is valid in WMI.Returns true on valid
  354. ' false on invalid or Error.
  355. '-------------------------------------------------------------------------
  356. Function IsValidWMIInstance(objService,strClassName,strPropertyName)
  357. Err.Clear
  358. On Error Resume Next
  359. Dim strInstancePath
  360. Dim objInstance
  361. strInstancePath = strClassName & "." & strPropertyName
  362. Set objInstance = objservice.Get(strInstancePath)
  363. if NOT isObject(objInstance) or Err.number <> 0 Then
  364. IsValidWMIInstance = FALSE
  365. Err.Clear
  366. Else
  367. IsValidWMIInstance = TRUE
  368. End If
  369. 'clean objects
  370. Set objInstance=nothing
  371. End Function
  372. %>