home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_03.cab / iiputls.asp < prev    next >
Text File  |  1997-11-16  |  9KB  |  372 lines

  1. <%@ LANGUAGE=VBScript %>
  2. <%'Option Explicit %>
  3. <% Response.Expires = 0 %>
  4.  
  5. <%
  6. Const ADS_PROPERTY_CLEAR = 1
  7. Const L_ADMINISTRATORS_TEXT = "Administrators"
  8.  
  9. On Error Resume Next 
  10.  
  11. Dim path, currentobj, SpecObject, lasterr, key, changed, clearPaths
  12.  
  13. lasterr=""
  14. changed = false
  15. path=Session("path")
  16. Set currentobj=GetObject(path)
  17. if Session("clearPathsOneTime") <> "" then 
  18.     clearPaths = Session("clearPathsOneTime")
  19. else
  20.     clearPaths = (Session("clearPaths") <> "")
  21. end if
  22.  
  23. SpecObject = ""
  24. SpecObject = GetObjectType(SpecObject, Session("SpecObj"),"Filters")
  25. SpecObject = GetObjectType(SpecObject, Session("SpecObj"),"Mime")
  26. SpecObject = GetObjectType(SpecObject, Session("SpecObj"),"IPSecurity")
  27. SpecObject = GetObjectType(SpecObject, Session("SpecObj"),"Operators")
  28.  
  29. Select Case SpecObject
  30.     Case "Filters"
  31.         saveFilters        
  32.     Case "Mime"
  33.         saveMIMEs    
  34.     Case "IPSecurity"
  35.         saveIPSecurity
  36.     Case "Operators"
  37.         saveOperators
  38.     Case Else
  39.         saveGenericLists        
  40. End Select
  41.  
  42.  
  43. Function getObjectType(SpecObject,SpecObjString,ObjType)
  44.         
  45.     If InStr(SpecObjString,ObjType) > 0 then
  46.         getObjectType = ObjType
  47.     Else
  48.         getObjectType = SpecObject
  49.     End If
  50.  
  51. End Function
  52.  
  53. Sub killChildPaths(key, thisobj)
  54.  
  55.     dim aSetChildPaths, childpath, child
  56.     
  57.     if clearPaths then
  58.         aSetChildPaths = thisobj.GetDataPaths(key,IIS_DATA_INHERIT) 
  59.         For Each childpath in aSetChildPaths
  60.             childPath = cleanPath(childPath)
  61.             
  62.             Set child = GetObject(childpath)
  63.             if child.ADSPath <> thisobj.ADSPath then
  64.                 if (instr(LCase(child.ADSPath), "IIS://localhost/w3svc/info") > 0) OR (instr(LCase(child.ADSPath), "IIS://localhost/msftpsvc/info") > 0) then        
  65.                 else
  66.                     child.PutEx ADS_PROPERTY_CLEAR, key, ""
  67.                     child.SetInfo
  68.                 end if
  69.             end if
  70.         Next    
  71.     end if
  72.     Session("clearPathsOneTime") = ""
  73. End Sub
  74.  
  75. Function cleanPath(pathstr)
  76.     if Right(pathstr,1) = "/" then
  77.         pathstr = Mid(pathstr, 1,len(pathstr)-1)
  78.     end if
  79.     cleanPath = pathstr
  80. End Function
  81.  
  82. Sub saveGenericLists()
  83.  
  84. dim proparray, oldarray
  85.         proparray=Array()
  86.  
  87.         For Each key In Request.Form
  88.  
  89.             if (key="DELETED" or key="NEWITEM") then
  90.             else                
  91.                 proparray = setPropArray()                            
  92.                 oldarray=currentobj.Get(key)
  93.  
  94.                 Response.write "New Array" & "<BR>"
  95.                 printarray(proparray)
  96.                 Response.write "Old Array" & "<BR>"
  97.                 printarray(oldarray)                                                
  98.                 if chkUpdated(oldarray,proparray) then
  99.                     currentobj.Put key, (proparray)
  100.                     killChildPaths key, currentobj
  101.                 end if
  102.             end if
  103.         Next
  104.         currentobj.SetInfo
  105. End Sub
  106.  
  107. Sub saveOperators()
  108.     dim currentobj, secdes, dacl, Ace, NewAce, Trustee
  109.     dim proparray
  110.     
  111.     proparray=Array()
  112.     key = "Trustee"
  113.     Set currentobj = GetObject(path)
  114.     Set secdes = currentobj.Get("AdminACL")
  115.     Set dacl = secdes.DiscretionaryACL    
  116.  
  117.     proparray = setPropArray()            
  118.  
  119.     'First, clear down our control list...
  120.     currentobj.PutEx ADS_PROPERTY_CLEAR, "AdminACL", ""
  121.     currentobj.SetInfo
  122.     Set currentobj = GetObject(path)
  123.     Set secdes = currentobj.Get("AdminACL")
  124.     Set dacl = secdes.DiscretionaryACL    
  125.     
  126.     For Each Trustee in proparray        
  127.         if Trustee <> L_ADMINISTRATORS_TEXT then
  128.             ' Set up the ACEs
  129.             Set NewAce = CreateObject("AccessControlEntry")
  130.             NewAce.Trustee = Trustee        
  131.             NewAce.AccessMask = 11
  132.             dacl.AddAce NewAce        
  133.         
  134.         end if
  135.     Next
  136.     secdes.DiscretionaryACL = (dacl)
  137.     currentobj.AdminACL = secdes
  138.     currentobj.SetInfo
  139.     killChildPaths "AdminACL", currentobj 
  140. End Sub
  141.  
  142. Sub saveIPSecurity()
  143.  
  144.     Dim sobj, specprops, dd
  145.     Dim proparray, oldarray
  146.         response.write currentobj.ADsPath
  147.         Set sobj=currentobj.Get(Session("SpecObj"))    
  148.         specprops=UCase(Session("SpecProps"))
  149.     
  150.         proparray=Array()
  151.     
  152.         For Each key In Request.Form
  153.             if (key="DELETED" or key="NEWITEM") then
  154.             else
  155.                 proparray = setPropArray()        
  156.                 Select Case UCase(key)
  157.                 Case "IPGRANT" 
  158.                         oldarray=sobj.IPGrant
  159.                 Case "IPDENY" 
  160.                         oldarray=sobj.IPDeny
  161.                 Case "DOMAINGRANT" 
  162.                         oldarray=sobj.DomainGrant
  163.                 Case "DOMAINDENY" 
  164.                         oldarray=sobj.DomainDeny
  165.                 End Select
  166.  
  167.                 if chkUpdated(oldarray,proparray) then
  168.                     Select Case UCase(key)
  169.                     Case "IPGRANT"  
  170.                         sobj.IPGrant=(proparray)
  171.                     Case "IPDENY" 
  172.                         sobj.IPDeny=(proparray)
  173.                     Case "DOMAINGRANT" 
  174.                         sobj.DomainGrant=(proparray)
  175.                     Case "DOMAINDENY" 
  176.                         sobj.DomainDeny=(proparray)
  177.                     End Select
  178.                 end if                            
  179.             end if
  180.         Next
  181.  
  182.         if Session("SpecObj")="IPSecurity" then
  183.             currentobj.IPSecurity=sobj
  184.         end if 
  185.         
  186.         currentobj.SetInfo
  187.         killChildPaths "IPSecurity", currentobj 
  188.  
  189. End Sub
  190.  
  191. Sub saveFilters()
  192.  
  193.     Dim filterspath, filterCol, loadOrder, formsize, filtername,fltrObj, fltr,i
  194.  
  195.         filterspath = path & "/Filters"
  196.     
  197.         if isObject(filterspath) then
  198.             Set filterCol = GetObject(filterspath)
  199.         else
  200.             Set filterCol=currentobj.Create("IIsFilters","Filters")
  201.         end if
  202.  
  203.                 
  204.         loadOrder = Request.Form("FilterName")
  205.         filterCol.FilterLoadOrder = (loadOrder)
  206.         filterCol.KeyType = "IIsFilters"    
  207.         filterCol.SetInfo
  208.  
  209.         formsize=Request.Form("FilterName").Count-1
  210.         For i=0 to formsize
  211.             filtername = Request.Form("FilterName")(i+1)
  212.         
  213.             if filtername <> "" then                
  214.                 if isObject(filterspath & "/" & filtername) then
  215.                     Set fltrObj = GetObject(filterspath & "/" & filtername)
  216.                 else
  217.                     Set fltrObj=filterCol.Create("IIsFilter",filtername)
  218.                 end if            
  219.                 fltrObj.FilterPath = (Request.Form("FilterPath")(i+1))
  220.                 fltrObj.SetInfo
  221.             end if
  222.         Next
  223.  
  224.         'now, make sure we haven't deleted or renamed any...
  225.         For Each fltr in filterCol
  226.             filtername = fltr.Name
  227.             if InStr(loadOrder,filtername) = 0 then                
  228.                 filterCol.Delete "IIsFilter", filtername
  229.             end if        
  230.         Next    
  231.         filterCol.SetInfo
  232. End Sub
  233.  
  234. Sub saveMIMES()
  235.     
  236.     Dim MIMEpath, MimeMaps, formsize, i, Map
  237.     Dim aMimeMap
  238.  
  239.     if Session("vtype") = "comp" then
  240.         MIMEpath = path & "/MimeMap"
  241.     else
  242.         MIMEpath = path
  243.     end if     
  244.         
  245.  
  246.     if isObject(MIMEpath) then
  247.         Set MimeMaps = GetObject(MIMEpath)
  248.     else
  249.         Set MimeMaps=currentobj.Create("IIsMimeMap","MimeMap")
  250.         MimeMaps.KeyType = "IIsMimeMap"            
  251.         MimeMaps.SetInfo            
  252.     end if
  253.  
  254.     aMimeMap = MimeMaps.MimeMap
  255.     formsize=Request.Form("ext").Count-1    
  256.     ReDim aMimeMap(formsize)
  257.     i = 0
  258.     if (formsize = 0 and Request.Form("ext")(1) <> "") or formsize > 0 then
  259.         For i = 0 to formsize
  260.             Set Map = CreateObject("Mimemap")
  261.             Map.Extension=Request.Form("ext")(i+1) 
  262.             Map.MimeType=Request.Form("app")(i+1) 
  263.             Set aMimeMap(i) = Map
  264.         Next
  265.         MimeMaps.Mimemap = aMimeMap
  266.     else
  267.         MimeMaps.PutEx ADS_PROPERTY_CLEAR, "MimeMap", ""
  268.         MimeMaps.GetInfo
  269.     end if    
  270.     MimeMaps.SetInfo
  271.  
  272. End Sub
  273.  
  274. Function setPropArray()
  275.     
  276.     dim formsize,arraysize,i, j
  277.     dim proparray
  278.  
  279.     'key is global
  280.     formsize=Request.Form(key).Count-1
  281.     arraysize=0
  282.     for i=0 to formsize
  283.     if Request.Form(key)(i+1) <> "" then
  284.         arraysize=arraysize + 1
  285.     end if
  286.     Next
  287.  
  288.     if arraysize=0 then
  289.         ReDim proparray(0)        
  290.         if (Request.Form(key)(1) <> "") then
  291.             proparray(0)=Request.Form(key)(1)
  292.         else
  293.             proparray = Array()
  294.         end if
  295.     else
  296.         ReDim proparray(arraysize-1)    
  297.         j=0
  298.  
  299.         for i=0 to formsize
  300.             
  301.             if Request.Form(key)(i+1) <> "" then        
  302.                 proparray(j)=Request.Form(key)(i+1)
  303.                 j=j+1                
  304.             end if
  305.         Next
  306.     end if    
  307.     
  308.     setPropArray = proparray
  309.     
  310. End Function
  311.  
  312. Function chkUpdated(oldarray,proparray)
  313.  
  314.     dim proparraybound,arrayWasUpdated, i
  315.     
  316.     if IsArray(oldarray) then
  317.         proparraybound=UBound(proparray)
  318.         if UBound(oldarray) <> proparraybound then
  319.             arrayWasUpdated=true
  320.         else
  321.             for i=0 to proparraybound
  322.                 if oldarray(i) <> proparray(i) then                    
  323.                     arrayWasUpdated=true
  324.                 end if
  325.             Next
  326.         end if
  327.     else        
  328.         if proparraybound > 0 then
  329.             arrayWasUpdated=true
  330.         else
  331.             arrayWasUpdated=(proparray(0) <> oldarray)            
  332.         end if
  333.     end if
  334.     
  335.     'set our global changed var
  336.     changed = arrayWasUpdated
  337.     
  338.     chkUpdated = arrayWasUpdated
  339.     
  340. End Function
  341.  
  342. Function printarray(aprop)
  343.     Dim prop
  344.     for each prop in aprop
  345.         response.write prop & "<BR>"
  346.     next
  347. End Function 
  348.  
  349. Function isObject(path)
  350.     On Error Resume Next
  351.     Dim testObj
  352.     set testObj = GetObject(path)
  353.     isObject = (err = 0)
  354.     err = 0
  355. End Function
  356.  
  357. %>
  358.  
  359. <SCRIPT LANGUAGE="JavaScript">
  360.         parentdoc = parent.location.href;
  361.         if (parentdoc.indexOf("pop") != -1){
  362.             top.location.href="iipopcl.asp";
  363.         }
  364. </SCRIPT>
  365. <HTML>
  366. <BODY BGCOLOR="#000000" TEXT="#FFCC00" TOPMARGIN=0 LEFTMARGIN=0>
  367. </BODY>
  368. </HTML>
  369.  
  370.  
  371.  
  372.