home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETJSharp / VJREDIST.EXE / jsredist.msi / Binary.BIN_File_138136 < prev    next >
Encoding:
Text File  |  2003-03-19  |  6.9 KB  |  250 lines

  1. REM
  2. REM Script add Script Maps to the IIS MetaBase
  3. REM
  4. REM Partha Pratim Das 02/12/2002
  5. REM (c) Microsoft Corporation
  6. REM
  7. REM Arguments passed as "[DEBUG]|[Add]|[MSNETINSTALLDIR]|"
  8. REM
  9. REM Adding Script Maps for .jsl, .vjsproj, .java to exclude GET, HEAD, POST, DEBUG
  10. REM Example: 1|0|C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\|
  11. REM
  12. REM Options:
  13. REM   1 : The script is allowed to run in directories given Script permission. If
  14. REM       this value is not set, then the script can only be executed in directories
  15. REM       that are flagged for Execute permission.
  16. REM   4 : The server attempts to access the PATH_INFO portion of the URL, as a file,
  17. REM       before starting the scripting engine. If the file canREMt be opened, or
  18. REM       doesn't exist, an error is returned to the client.
  19. REM   5 : Both of the above conditions are TRUE.
  20. REM
  21.  
  22.  
  23. REM Initializations...
  24. ' Please declare before you use
  25. Option Explicit
  26. ' Ignore all errors
  27. On Error Resume Next
  28.  
  29. ' Constants
  30. Const Handler = "aspnet_isapi.dll"
  31. Const IISPath = "IIS://localhost/W3SVC"
  32. Const ExList = "GET,HEAD,POST,DEBUG"
  33. Const Opt = "1"
  34.  
  35.  
  36. REM Parse the arguments
  37. 'For private testing
  38. 'Dim arg : arg = "1|0|C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\|"
  39. ' This is the actual stuff
  40. Dim arg : arg = Session.Property( "CustomActionData" )
  41. Dim argv : argv = Split( arg, "|", -1, 1 )
  42.  
  43. ' Example: .jsl - C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\aspnet_isapi.dll 1 - GET,HEAD,POST,DEBUG
  44. ' Set the debug flag
  45. Dim debug
  46. If ( argv(0) = "0" ) Then
  47.     debug = False
  48. Else
  49.     debug = True
  50. End If
  51.  
  52. ' Register or Unregister the maps...
  53. Dim regSM
  54. If ( argv(1) = "0" ) Then
  55.     regSM = False
  56. Else
  57.     regSM = True
  58. End If
  59.  
  60. ' The stuff to register
  61. Dim extns : extns = Array( ".jsl", ".java", ".vjsproj" )
  62. Dim trailer : trailer = "," & argv(2) & Handler & "," & Opt & "," & ExList
  63. Dim HandlerFullPath : HandlerFullPath = argv(2) & Handler
  64.  
  65. ' Show what we have parsed
  66. Dim Action : Action = "Unregister Script Map"
  67. If debug Then
  68.     If regSM Then Action = "Register Script Map"
  69.     Dim pos, lst
  70.     For pos = LBound( extns ) to UBound( extns )
  71.           lst = lst & " " & extns(pos)
  72.     Next
  73.     lst = lst & " "
  74.     MsgBox "Action : " & Action & vbCrLf & "Script Map : { " & lst & "}" & trailer
  75. End If
  76.  
  77.  
  78. REM Recursively Go Mad
  79. Call RecursivelyGoMad( "w3svc" )
  80.  
  81.  
  82. REM Subroutines and functions...
  83. ' Check is the map for the extension already exists
  84. Function ScriptMapExist( IISObj, ext )
  85.     
  86.     Dim pos, Items, ScriptMaps
  87.  
  88.     ScriptMapExist = false
  89.     ext = UCase( ext )
  90.     ScriptMaps = IISObj.Scriptmaps
  91.     ' Search for the ext in the map set
  92.     For pos = LBound( ScriptMaps ) to UBound( ScriptMaps )
  93.         Items = Split( Scriptmaps(pos), "," )
  94.         If ( UCase( items(0) ) = ext ) Then
  95.             ScriptMapExist = true
  96.             Exit Function
  97.         End If
  98.     Next
  99.     
  100. End Function
  101.  
  102. Function AspnetInstalled( IISObj )
  103.     
  104.     Dim pos, ScriptMaps
  105.  
  106.     AspnetInstalled = false
  107.     ScriptMaps = IISObj.Scriptmaps
  108.     ' Search for the ext in the map set
  109.     For pos = LBound( ScriptMaps ) to UBound( ScriptMaps )
  110.         If ( InStr(UCase(Scriptmaps(pos)), UCase(HandlerFullPath)) > 0 ) Then
  111.             AspnetInstalled = true
  112.             Exit Function
  113.         End If
  114.     Next
  115.     
  116. End Function
  117.  
  118. ' Add a map only if it is not already there
  119. Sub Add( IISObj, ext, map )
  120.     ' Don't add if aspnet_isapi is not installed in the scriptmap
  121.     If ( AspnetInstalled( IISObj ) = false ) Then
  122.         If debug Then
  123.             MsgBox "Aspnet not installed: " & IISObj.AdsPath
  124.         End If
  125.         Exit Sub
  126.     End If
  127.     
  128.     ' Check is the map is already there?
  129.     If ( ScriptMapExist( IISObj, ext ) = true ) Then
  130.         If debug Then
  131.             MsgBox "Map Exists: " & map & vbCrLf & IISObj.AdsPath
  132.         End If
  133.         Exit Sub
  134.     End If
  135.  
  136.     ' Obtain the current set of Script Maps
  137.     Dim NewScriptMaps : NewScriptMaps = IISObj.ScriptMaps
  138.     ReDim Preserve NewScriptMaps( UBound( NewScriptMaps ) + 1 )
  139.     ' Insert the new map
  140.     NewScriptMaps( UBound( NewScriptMaps ) ) = map
  141.     ' Save the new set of script maps
  142.     IISObj.ScriptMaps = NewScriptMaps
  143.     IISObj.SetInfo
  144.  
  145. End Sub
  146.  
  147. ' Delete a map only if it is there
  148. Sub Delete( IISObj, ext )
  149.     
  150.     Dim pos2, Items, found
  151.  
  152.     found = false
  153.     ext = UCase( ext )
  154.     Dim ScriptMaps : ScriptMaps = IISObj.Scriptmaps
  155.     ReDim NewScriptMaps(UBound( ScriptMaps ))
  156.     NewScriptMaps(UBound( ScriptMaps )) = "Null"
  157.     ' Search for the ext in the map set and dont add it to the new set
  158.     pos2 = LBound( ScriptMaps )
  159.     For pos = LBound( ScriptMaps ) to UBound( ScriptMaps )
  160.         Items = Split( Scriptmaps(pos), "," )
  161.         If ( UCase( items(0) ) <> ext ) Then
  162.             NewScriptMaps(pos2) = ScriptMaps(pos)
  163.             pos2 = pos2 + 1
  164.         Else
  165.             found = true
  166.         End If
  167.     Next
  168.  
  169.     ' Don't set any scriptmap property if J# extension isn't found
  170.     If (found = false) Then
  171.         Exit Sub
  172.     End If
  173.     
  174.     ' Remove the last element if it is still "Null"
  175.     If ( NewScriptMaps(UBound( ScriptMaps )) = "Null" ) Then
  176.         ReDim Preserve NewScriptMaps( UBound( NewScriptMaps ) - 1 )
  177.     Else
  178.         If debug Then
  179.             MsgBox "Map doesnt exist for " & ext & vbCrLf & IISObj.AdsPath
  180.         End If
  181.     End If
  182.     ' Save the new set of script maps
  183.     IISObj.ScriptMaps = NewScriptMaps
  184.     IISObj.SetInfo
  185.  
  186. End Sub
  187.  
  188. Sub RecursivelyGoMad( objectPath )
  189.  
  190.     On Error Resume Next
  191.  
  192.     Dim IISObject, IISObjectPath, childObject, childObjectName
  193.  
  194.     Call SanitizePath( objectPath )
  195.     IISObjectPath = "IIS://" & "localhost"
  196.     IISObjectPath = IISObjectPath & "/" & objectPath
  197.  
  198.     ' Instantiate this IIS object
  199.     Set IISObject = GetObject(IISObjectPath)
  200.  
  201.     ' Do the job for this IIS Object: remove/add the script maps
  202.     Dim ext, map, i
  203.     'Do we have to do
  204.     If regSM Then
  205.         ' We have to add the maps
  206.         For i = LBound( extns ) to UBound( extns )
  207.             ext = extns(i)
  208.             map = ext & trailer
  209.             Call Add( IISObject, ext, map )
  210.         Next
  211.         
  212.     Else
  213.         ' We have to remove maps
  214.         For i = LBound( extns ) to UBound( extns )
  215.             ext = extns(i)
  216.             Call Delete( IISObject, ext )
  217.         Next
  218.         
  219.     End If
  220.  
  221.     ' Now, do it for each children..
  222.     For Each childObject In IISObject
  223.         
  224.         'If (Err.Number <> 0) Then Exit For
  225.         
  226.         ' Obtain the name of the child
  227.         childObjectName = Right( childObject.AdsPath, Len( childObject.AdsPath ) - 6 )
  228.         childObjectName = Right( childObjectName, Len( childObjectName ) - InStr( childObjectName, "/" ) + 1 )
  229.         Call RecursivelyGoMad( childObjectName )
  230.         
  231.     Next
  232.  
  233. End Sub
  234.  
  235. ' The insane path...
  236. Sub SanitizePath( objectPath )
  237.  
  238.     ' Remove WhiteSpace, left and right
  239.     Trim( objectPath )
  240.  
  241.     ' Remove back-slash, left and right
  242.     If Left( objectPath, 1 ) = "/" Then
  243.             objectPath = Right( objectPath, Len( objectPath ) - 1 )
  244.     End If
  245.     If Right( objectPath, 1) = "/" Then
  246.             objectPath = Left( objectPath, Len( objectPath ) - 1 )
  247.     End If
  248.  
  249. End Sub
  250.