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.

564 lines
19 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' Openfiles_OpenFiles.asp: Shutdown_OpenFiles page - lists all the Shared Open Files
  6. ' of the appliance
  7. '
  8. ' Copyright (c) Microsoft Corporation. All rights reserved.
  9. '
  10. ' Date Description
  11. ' 28-Feb-00 Creation date
  12. ' 23-Mar-01 Modified date
  13. '-------------------------------------------------------------------------
  14. %>
  15. <!-- #include virtual="/admin/inc_framework.asp" -->
  16. <!-- #include virtual="/admin/ots_main.asp" -->
  17. <!-- #include file="loc_OpenFiles_msg.asp" -->
  18. <%
  19. '-------------------------------------------------------------------------
  20. ' Global Variables
  21. '-------------------------------------------------------------------------
  22. Dim page 'Variable that receives the output page object when
  23. 'creating a page
  24. Dim rc 'Return value for CreatePage
  25. Dim g_bSearchRequested
  26. Dim g_iSearchCol
  27. Dim g_sSearchColValue
  28. Dim g_bPageChangeRequested
  29. Dim g_sPageAction
  30. Dim g_iPageMin
  31. Dim g_iPageMax
  32. Dim g_iPageCurrent
  33. Dim g_bPagingInitialized
  34. Dim g_iSortCol
  35. Dim g_sSortSequence
  36. Dim g_bSortRequested
  37. 'This variable is defined to care of the problem arised using masterReturnURL
  38. Dim g_strReturnURL 'to hold masterReturnURL concatenated with '../'
  39. '-------------------------------------------------------------------------
  40. ' Entry Point
  41. '-------------------------------------------------------------------------
  42. ' Create Area Page
  43. rc = SA_CreatePage(L_PAGETITLE_OPENFILESDETAILS_TEXT, "", PT_AREA, page )
  44. If (rc=0) Then
  45. 'Serve the page
  46. SA_ShowPage(page)
  47. End If
  48. '---------------------------------------------------------------------
  49. ' Function name: OnInitPage
  50. ' Description: Called to signal first time processing for this page.
  51. ' Input Variables: PageIn and EventArg
  52. ' Output Variables: None
  53. ' Return Values: TRUE to indicate initialization was successful.
  54. ' Global Variables: None
  55. ' Called to signal first time processing for this page. Use this method
  56. ' to do first time initialization tasks.
  57. '---------------------------------------------------------------------
  58. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  59. g_bPagingInitialized = FALSE
  60. g_iPageCurrent = 1
  61. 'g_iSortCol = 1
  62. 'g_sSortSequence = "A"
  63. g_strReturnURL = m_VirtualRoot & mstrReturnURL 'Managing return URL
  64. OnInitPage = TRUE
  65. End Function
  66. '---------------------------------------------------------------------
  67. ' Function name: OnServeAreaPage
  68. ' Description: Called when the page needs to be served.
  69. ' Input Variables: PageIn, EventArg
  70. ' Output Variables: None
  71. ' Return Values: None
  72. ' Global Variables: None
  73. 'Called when the page needs to be served. Use this method to serve content.
  74. '---------------------------------------------------------------------
  75. Public Function OnServeAreaPage(ByRef PageIn, ByRef EventArg)
  76. Call ServeCommonJavascript()
  77. OnServeAreaPage = getOpenFiles()
  78. End Function
  79. '---------------------------------------------------------------------
  80. ' Function: ServeCommonJavascript
  81. '
  82. ' Synopsis: Serve common javascript that is required for this page type.
  83. '
  84. '---------------------------------------------------------------------
  85. Private Function ServeCommonJavascript()
  86. %>
  87. <script language='JavaScript'>
  88. function Init()
  89. {
  90. }
  91. </script>
  92. <%
  93. End Function
  94. '---------------------------------------------------------------------
  95. ' Function: OnSearchNotify()
  96. '
  97. ' Synopsis: Search notification event handler. When one or more columns are
  98. ' marked with the OTS_COL_SEARCH flag, the Web Framework fires
  99. ' this event in the following scenarios:
  100. '
  101. ' 1) The user presses the search Go button.
  102. ' 2) The user requests a table column sort
  103. ' 3) The user presses either the page next or page previous buttons
  104. '
  105. ' The EventArg indicates the source of this notification event which can
  106. ' be either a search change event (scenario 1) or a post back event
  107. ' (scenarios 2 or 3)
  108. '
  109. ' Returns: Always returns TRUE
  110. '
  111. '---------------------------------------------------------------------
  112. Public Function OnSearchNotify(ByRef PageIn, _
  113. ByRef EventArg, _
  114. ByRef sItem, _
  115. ByRef sValue )
  116. OnSearchNotify = TRUE
  117. '
  118. ' User pressed the search GO button
  119. '
  120. If SA_IsChangeEvent(EventArg) Then
  121. Call SA_TraceOut("Openfiles_Openfiles.asp", "OnSearchNotify() Change Event Fired")
  122. g_bSearchRequested = TRUE
  123. g_iSearchCol = Int(sItem)
  124. g_sSearchColValue = CStr(sValue)
  125. '
  126. ' User clicked a column sort, OR clicked either the page next or page prev button
  127. ElseIf SA_IsPostBackEvent(EventArg) Then
  128. Call SA_TraceOut("Openfiles_Openfiles.asp", "OnSearchNotify() Postback Event Fired")
  129. g_bSearchRequested = FALSE
  130. g_iSearchCol = Int(sItem)
  131. g_sSearchColValue = CStr(sValue)
  132. '
  133. ' Unknown event source
  134. Else
  135. Call SA_TraceOut("Openfiles_Openfiles.asp", "Unrecognized Event in OnSearchNotify()")
  136. End IF
  137. End Function
  138. '---------------------------------------------------------------------
  139. ' Function: OnPagingNotify()
  140. '
  141. ' Synopsis: Paging notification event handler. This event is triggered in one of
  142. ' the following scenarios:
  143. '
  144. ' 1) The user presses either the page next or page previous buttons
  145. ' 2) The user presses the search Go button.
  146. ' 3) The user requests a table column sort
  147. '
  148. ' The EventArg indicates the source of this notification event which can
  149. ' be either a paging change event (scenario 1) or a post back event
  150. ' (scenarios 2 or 3)
  151. '
  152. ' The iPageCurrent argument indicates which page the user has requested.
  153. ' This is an integer value between iPageMin and iPageMax.
  154. '
  155. ' Returns: Always returns TRUE
  156. '
  157. '---------------------------------------------------------------------
  158. Public Function OnPagingNotify(ByRef PageIn, _
  159. ByRef EventArg, _
  160. ByVal sPageAction, _
  161. ByVal iPageMin, _
  162. ByVal iPageMax, _
  163. ByVal iPageCurrent )
  164. OnPagingNotify = TRUE
  165. g_bPagingInitialized = TRUE
  166. '
  167. ' User pressed either page next or page previous
  168. '
  169. If SA_IsChangeEvent(EventArg) Then
  170. Call SA_TraceOut("Openfiles_Openfiles.asp", "OnPagingNotify() Change Event Fired")
  171. g_bPageChangeRequested = TRUE
  172. g_sPageAction = CStr(sPageAction)
  173. g_iPageMin = iPageMin
  174. g_iPageMax = iPageMax
  175. g_iPageCurrent = iPageCurrent
  176. '
  177. ' User clicked a column sort OR the search GO button
  178. ElseIf SA_IsPostBackEvent(EventArg) Then
  179. Call SA_TraceOut("Openfiles_Openfiles.asp", "OnPagingNotify() Postback Event Fired")
  180. g_bPageChangeRequested = FALSE
  181. g_sPageAction = CStr(sPageAction)
  182. g_iPageMin = iPageMin
  183. g_iPageMax = iPageMax
  184. g_iPageCurrent = iPageCurrent
  185. '
  186. ' Unknown event source
  187. Else
  188. Call SA_TraceOut("Openfiles_Openfiles.asp", "Unrecognized Event in OnPagingNotify()")
  189. End IF
  190. End Function
  191. '---------------------------------------------------------------------
  192. ' Function: OnSortNotify()
  193. '
  194. ' Synopsis: Sorting notification event handler. This event is triggered in one of
  195. ' the following scenarios:
  196. '
  197. ' 1) The user presses the search Go button.
  198. ' 2) The user presses either the page next or page previous buttons
  199. ' 3) The user requests a table column sort
  200. '
  201. ' The EventArg indicates the source of this notification event which can
  202. ' be either a sorting change event (scenario 1) or a post back event
  203. ' (scenarios 2 or 3)
  204. '
  205. ' The sortCol argument indicated which column the user would like to sort
  206. ' and the sortSeq argument indicates the desired sort sequence which can
  207. ' be either ascending or descending.
  208. '
  209. ' Returns: Always returns TRUE
  210. '
  211. '---------------------------------------------------------------------
  212. Public Function OnSortNotify(ByRef PageIn, _
  213. ByRef EventArg, _
  214. ByVal sortCol, _
  215. ByVal sortSeq )
  216. OnSortNotify = TRUE
  217. '
  218. ' User pressed column sort
  219. '
  220. If SA_IsChangeEvent(EventArg) Then
  221. Call SA_TraceOut("Openfiles_Openfiles.asp", "OnSortNotify() Change Event Fired")
  222. g_iSortCol = sortCol
  223. g_sSortSequence = sortSeq
  224. g_bSortRequested = TRUE
  225. '
  226. ' User presed the search GO button OR clicked either the page next or page prev button
  227. ElseIf SA_IsPostBackEvent(EventArg) Then
  228. Call SA_TraceOut("Openfiles_Openfiles.asp", "OnSortNotify() Postback Event Fired")
  229. g_iSortCol = sortCol
  230. g_sSortSequence = sortSeq
  231. g_bSortRequested = TRUE
  232. '
  233. ' Unknown event source
  234. Else
  235. Call SA_TraceOut("Openfiles_Openfiles.asp", "Unrecognized Event in OnSearchNotify()")
  236. End IF
  237. End Function
  238. '----------------------------------------------------------------------------
  239. ' Function name: LocalizeMode
  240. ' Description: Gets the localized version of the mode string returned
  241. ' from the OpenFiles control.
  242. ' Input Variables: Mode returned from the control
  243. ' Output Variables: None
  244. ' Return Values: The localized version of the mode
  245. ' Global Variables: None
  246. '---------------------------------------------------------------------
  247. Private Function LocalizeMode(ByRef strRawMode)
  248. Select Case strRawMode
  249. Case "READ"
  250. LocalizeMode = L_OPENMODE_READ
  251. Case "WRITE"
  252. LocalizeMode = L_OPENMODE_WRITE
  253. Case "CREATE"
  254. LocalizeMode = L_OPENMODE_CREATE
  255. Case "READ+WRITE"
  256. LocalizeMode = L_OPENMODE_READWRITE
  257. Case "READ+CREATE"
  258. LocalizeMode = L_OPENMODE_READCREATE
  259. Case "WRITE+CREATE"
  260. LocalizeMode = L_OPENMODE_WRITECREATE
  261. Case "NOACCESS"
  262. LocalizeMode = L_OPENMODE_NOACCESS
  263. Case Else
  264. ' We can't localize the string
  265. Call SA_TraceOut("Openfiles_Openfiles.asp", "LocalizeMode() Unrecognized mode")
  266. LocalizeMode = strRawMode
  267. End Select
  268. End Function
  269. '----------------------------------------------------------------------------
  270. ' Function name: getOpenFiles
  271. ' Description: To get the list Shared Open Files, Accessed By, Open Mode
  272. ' Input Variables: None
  273. ' Output Variables: None
  274. ' Return Values: TRUE to indicate no problems occured. FALSE to indicate errors.
  275. ' Returning FALSE will display error message.
  276. ' Global Variables:
  277. ' In:g_iPageCurrent,g_bPagingInitialized,g_iSortCol
  278. ' g_bSearchRequested,g_iSearchCol,g_sSearchColValue
  279. ' L_(*)-Localization Strings g_strReturnURL,OPENFILES_PER_PAGE
  280. ' Called to display shared open files in OTS table.
  281. '---------------------------------------------------------------------
  282. Function getOpenFiles()
  283. Err.Clear
  284. On Error Resume Next
  285. Dim objTableLog 'Array Object to store attributes of the table
  286. Dim nReturnValue 'Return value when creating OTS Table
  287. Dim nOpenFilesCt 'Value to indicate the row of the table
  288. Dim nCount 'Count variable
  289. Dim colflags 'colflags value
  290. Dim nHiddenOpenFile 'holds hidden column index
  291. Dim nAccessedBy 'opened file accessed by
  292. Dim nOpenMode 'file open mode
  293. Dim nOpenFile 'opened file
  294. Dim nOpenFilePath 'open file path
  295. Dim strOpenFile 'open file path
  296. Dim strPath 'open file full path
  297. Dim strMode 'localized file open mode
  298. Dim strHiddenVal 'Hidden value
  299. Dim objOpenFiles 'openfiles object
  300. Dim arrOpFiles 'array of openfiles
  301. Const OPENFILES_PER_PAGE = 100
  302. nOpenFilesCt = 0
  303. 'Creating an Activex Object for Openfiles
  304. Set objOpenFiles = CreateObject("Openfiles.Openf")
  305. If Err.number <> 0 then
  306. Call SA_ServeFailurePageEx(L_OBJECT_CREATION_ERRORMESSAGE, g_strReturnURL)
  307. Exit Function
  308. End If
  309. 'The method of the object which returns a two dimentional array
  310. arrOpFiles = objOpenFiles.getOpenFiles()
  311. 'Create Open Files table with 3 coloumns
  312. objTableLog = OTS_CreateTable(L_PAGETITLE_OPENFILESDETAILS_TEXT, L_DESCRIPTION_HEADING_TEXT)
  313. '
  314. ' If the search criteria changed then we need to recompute the paging range
  315. If ( TRUE = g_bSearchRequested ) Then
  316. '
  317. ' Need to recalculate the paging range
  318. g_bPagingInitialized = FALSE
  319. '
  320. ' Restarting on page #1
  321. g_iPageCurrent = 1
  322. End If
  323. '
  324. ' Create the OpenFile column
  325. nHiddenOpenFile = 0
  326. colflags = (OTS_COL_FLAG_HIDDEN OR OTS_COL_KEY)
  327. call OTS_AddTableColumn(objTableLog, OTS_CreateColumn( L_OPENFILE_TEXT, "left", colflags))
  328. ' Create the OpenFile column
  329. nOpenFile = 1
  330. colflags = (OTS_COL_SEARCH OR OTS_COL_SORT)
  331. If ( g_iSortCol = nOpenFile ) Then
  332. colflags = colflags OR OTS_COL_SORT
  333. End If
  334. call OTS_AddTableColumn(objTableLog, OTS_CreateColumn( L_OPENFILE_TEXT, "left", colflags))
  335. '
  336. ' Create the OpenMode column
  337. nOpenMode = 2
  338. colflags = (OTS_COL_SEARCH OR OTS_COL_SORT)
  339. If ( g_iSortCol = nOpenMode ) Then
  340. colflags = colflags OR OTS_COL_SORT
  341. End If
  342. call OTS_AddTableColumn(objTableLog, OTS_CreateColumn( L_OPENMODE_TEXT, "left", colflags))
  343. '
  344. ' Create the AccessedBy column
  345. nAccessedBy = 3
  346. colflags = (OTS_COL_SEARCH OR OTS_COL_SORT)
  347. If ( g_iSortCol = nAccessedBy ) Then
  348. colflags = colflags OR OTS_COL_SORT
  349. End If
  350. call OTS_AddTableColumn(objTableLog, OTS_CreateColumn( L_ACCESSEDBY_TEXT, "left", colflags))
  351. ' Create the OpenMode column
  352. nOpenFilePath = 4
  353. colflags = (OTS_COL_SEARCH OR OTS_COL_SORT)
  354. If ( g_iSortCol = nOpenFilePath ) Then
  355. colflags = colflags OR OTS_COL_SORT
  356. End If
  357. call OTS_AddTableColumn(objTableLog, OTS_CreateColumn( L_PATH_TEXT, "left", colflags))
  358. 'Adding items to the OTS table
  359. For nCount = 0 to ubound(arrOpFiles)
  360. ' Localize the mode string.
  361. strMode = LocalizeMode(arrOpFiles(nCount, 2))
  362. strOpenFile = right(arrOpFiles(nCount,0),instr(1,StrReverse(arrOpFiles(nCount,0)),"\",1)-1)
  363. strPath = left(arrOpFiles(nCount,0),len(arrOpFiles(nCount,0))-len(strOpenFile)-1)
  364. strHiddenVal = strOpenFile & chr(1) & replace(strPath,"\","/") & chr(1) & strMode & chr(1) & arrOpFiles(nCount,1)
  365. If ( g_bSearchRequested ) Then
  366. ' Search criteria blank, select all rows
  367. If ( Len( g_sSearchColValue ) <= 0 ) Then
  368. nOpenFilesCt=nOpenFilesCt+1
  369. ' Verify that the current user part of the current page
  370. If ( IsItemOnPage( nOpenFilesCt, g_iPageCurrent, OPENFILES_PER_PAGE) ) Then
  371. call OTS_AddTableRow( objTableLog, Array( strHiddenVal, strOpenFile , _
  372. strMode ,arrOpFiles(nCount,1),strPath ) )
  373. End If
  374. Else
  375. Select Case (g_iSearchCol)
  376. Case nOpenMode
  377. If ( ucase(left(strMode, len(g_sSearchColValue))) = ucase(g_sSearchColValue)) Then
  378. nOpenFilesCt=nOpenFilesCt+1
  379. ' Verify that the current user part of the current page
  380. If ( IsItemOnPage( nOpenFilesCt, g_iPageCurrent, OPENFILES_PER_PAGE) ) Then
  381. call OTS_AddTableRow( objTableLog, Array( strHiddenVal, strOpenFile , _
  382. strMode ,arrOpFiles(nCount,1),strPath ) )
  383. End If
  384. End If
  385. Case nAccessedBy
  386. If ( ucase(left(arrOpFiles(nCount,1), len(g_sSearchColValue))) = ucase(g_sSearchColValue)) Then
  387. nOpenFilesCt=nOpenFilesCt+1
  388. ' Verify that the current user part of the current page
  389. If ( IsItemOnPage( nOpenFilesCt, g_iPageCurrent, OPENFILES_PER_PAGE) ) Then
  390. call OTS_AddTableRow( objTableLog, Array( strHiddenVal, strOpenFile , _
  391. strMode ,arrOpFiles(nCount,1),strPath ) )
  392. End If
  393. End If
  394. Case nOpenFile
  395. If ( ucase(left(strOpenFile, len(g_sSearchColValue))) = ucase(g_sSearchColValue)) Then
  396. nOpenFilesCt=nOpenFilesCt+1
  397. ' Verify that the current user part of the current page
  398. If ( IsItemOnPage( nOpenFilesCt, g_iPageCurrent, OPENFILES_PER_PAGE) ) Then
  399. call OTS_AddTableRow( objTableLog, Array( strHiddenVal, strOpenFile , _
  400. strMode ,arrOpFiles(nCount,1),strPath ) )
  401. End If
  402. End If
  403. Case nOpenFilePath
  404. If ( ucase(left(strPath, len(g_sSearchColValue))) = ucase(g_sSearchColValue)) Then
  405. nOpenFilesCt=nOpenFilesCt+1
  406. ' Verify that the current user part of the current page
  407. If ( IsItemOnPage( nOpenFilesCt, g_iPageCurrent, OPENFILES_PER_PAGE) ) Then
  408. call OTS_AddTableRow( objTableLog, Array( strHiddenVal, strOpenFile , _
  409. strMode ,arrOpFiles(nCount,1),strPath ) )
  410. End If
  411. End If
  412. Case Else
  413. Call SA_TraceOut("Openfiles_Openfiles.asp", "Unrecognized search column: " + CStr(g_iSearchCol))
  414. nOpenFilesCt=nOpenFilesCt+1
  415. ' Verify that the current user part of the current page
  416. If ( IsItemOnPage( nOpenFilesCt, g_iPageCurrent, OPENFILES_PER_PAGE) ) Then
  417. call OTS_AddTableRow( objTableLog, Array( strHiddenVal, strOpenFile , _
  418. strMode ,arrOpFiles(nCount,1),strPath ) )
  419. End If
  420. End Select
  421. End If
  422. Else
  423. '
  424. ' Search not enabled, select all rows
  425. nOpenFilesCt=nOpenFilesCt+1
  426. ' Verify that the current user part of the current page
  427. If ( IsItemOnPage( nOpenFilesCt, g_iPageCurrent, OPENFILES_PER_PAGE) ) Then
  428. call OTS_AddTableRow( objTableLog, Array( strHiddenVal, strOpenFile , _
  429. strMode ,arrOpFiles(nCount,1),strPath ) )
  430. End If
  431. End If
  432. Next
  433. 'Set Task title
  434. call OTS_SetTableTasksTitle(objTableLog, L_TASKS_TEXT)
  435. 'Details Task
  436. Call OTS_AddTableTask( objTableLog, OTS_CreateTaskEx(L_DETAILS_TEXT, _
  437. L_DETAILS_TEXT, _
  438. "Openfiles/Openfiles_OpenFilesDetails.asp",_
  439. OTS_PT_AREA,_
  440. "OTS_TaskOne") )
  441. '
  442. ' Enable paging feature
  443. '
  444. Call OTS_EnablePaging(objTableLog, TRUE)
  445. '
  446. ' If paging range needs to be initialised then
  447. ' we need to figure out how many pages we are going to display
  448. If ( FALSE = g_bPagingInitialized ) Then
  449. g_iPageMin = 1
  450. g_iPageMax = Int(nOpenFilesCt / OPENFILES_PER_PAGE )
  451. If ( (nOpenFilesCt MOD OPENFILES_PER_PAGE) > 0 ) Then
  452. g_iPageMax = g_iPageMax + 1
  453. End If
  454. g_iPageCurrent = 1
  455. Call OTS_SetPagingRange(objTableLog, g_iPageMin, g_iPageMax, g_iPageCurrent)
  456. End If
  457. ' Sort the table
  458. Call OTS_SortTable(objTableLog, g_iSortCol, g_sSortSequence, SA_RESERVED)
  459. ' If multiselection was requested then use multiselect OTS table
  460. Call OTS_SetTableMultiSelection(objTableLog, false)
  461. 'Render the table
  462. call OTS_ServeTable(objTableLog)
  463. 'Set to nothing
  464. set objOpenFiles = nothing
  465. getOpenFiles = True
  466. End Function
  467. '---------------------------------------------------------------------
  468. ' Function: IsItemOnPage()
  469. ' Description: Verify that the current user part of the current page.
  470. ' Input Variables: iCurrentItem
  471. ' Output Variables: None
  472. ' Return Values: TRUE or FALSE
  473. ' Global Variables: None
  474. '---------------------------------------------------------------------
  475. Private Function IsItemOnPage(ByVal iCurrentItem, iCurrentPage, iItemsPerPage)
  476. Dim iLowerLimit
  477. Dim iUpperLimit
  478. iLowerLimit = ((iCurrentPage - 1) * iItemsPerPage )
  479. iUpperLimit = iLowerLimit + iItemsPerPage + 1
  480. If ( iCurrentItem > iLowerLimit AND iCurrentItem < iUpperLimit ) Then
  481. IsItemOnPage = TRUE
  482. Else
  483. IsItemOnPage = FALSE
  484. End If
  485. End Function
  486. %>