home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 9 / IOPROG_9.ISO / contrib / iis4 / iis4_03.cab / iiaction.asp < prev    next >
Encoding:
Text File  |  1997-08-29  |  11.7 KB  |  464 lines

  1. <%@ LANGUAGE=VBScript %>
  2. <% Option Explicit %>
  3.  
  4. <%
  5.  
  6.     ' This script adds, deletes, and sets state on adsi objects, as appropriate,
  7.     ' based upon the value of the action parameter.
  8.     ' It does some error checking...
  9.     ' Only instance may be started, stopped, paused or resumed.
  10.     
  11.  
  12. %>
  13.  
  14.  
  15. <% 
  16. Const L_ACCESSDENIED_TEXT="Access Denied"
  17. Const L_OBJEXISTS_ERR="An object with the name you specifed already exists. Specify a different object name." 
  18. Const L_UNKNOWN_ERR="An unknown error occured."
  19. Const L_START_ERR="The site could not be started at this time."
  20. Const L_NOBINDINGS_ERR = "You must assign a binding to this site before starting."
  21. Const L_STOP_ERR="The site could not be stopped at this time."
  22. Const L_CONT_ERR="The site could not resume at this time."
  23. Const L_PAUSE_ERR="The site could not be paused at this time."
  24. Const L_DELETE_ERR="The object could not be deleted."
  25. Const L_APPCREATE_ERR="The application could not be created."
  26. Const L_APPREMOVE_ERR="The application could not be removed."
  27. Const L_APPUNLOAD_ERR="The application could not be unloaded."
  28. Const L_BACKUP_ERR = "The backup was not successful."
  29. Const L_BACKUPRMV_ERR = "The backup was not deleted."
  30.  
  31.  
  32. Const CSTART="2"
  33. Const CSTOP="4"
  34. Const CPAUSE="6"
  35. Const CCONT="0"
  36.  
  37. Const MD_BACKUP_NEXT_VERSION =  &HFFFFFFFF
  38. %>
  39.  
  40. <HTML>
  41.  
  42. <%
  43. On Error Resume Next 
  44.  
  45. Dim action, path, vtype,stype,sel,pos,newADspath, dirname, keytype
  46. Dim dirnamelen, baseobj, svc,key, keyname, newname, vdir, sname
  47. Dim service, inst, nextinst, FileSystem, parenttype, newobj
  48. Dim currentobj, rootobj, adminobj, objerr, delmetanode, bindings
  49. Dim defaultinst, admininst, isolated,a
  50. Dim bkupName,bkupVer, dirpath
  51.  
  52.  
  53. action=Request.QueryString("a")
  54. sel=Request.QueryString("sel")
  55. path = Request.QueryString("path")
  56. 'save off our original action...
  57. a = action
  58.  
  59. Select Case action
  60. Case "add"
  61.     getTypes
  62.  
  63.     Set FileSystem=CreateObject("Scripting.FileSystemObject")
  64.     
  65.     if vtype="server" then 
  66.         sname=Mid(path, 1, pos) & svc
  67.         Set service=GetObject(sname)
  68.         baseobj=service.ADsPath
  69.         For Each inst In service
  70.             if isNumeric(inst.name) then
  71.                 Nextinst=inst.name
  72.             end if
  73.         Next
  74.         response.write nextinst
  75.         newname=Nextinst+1
  76.     end if 
  77.  
  78.     Set currentobj=GetObject(baseobj)
  79.     
  80.     'if currentobj can't be set due to path not found,
  81.     'we need to set our parenttype var manually
  82.     if err <> 0 then            
  83.         parenttype = ""
  84.     else
  85.         parenttype=currentobj.KeyType
  86.     end if     
  87.  
  88.  
  89.     if Instr(parenttype,"Server") <> 0 then
  90.         baseobj=baseobj & "/Root"
  91.         Set currentobj=GetObject(baseobj)
  92.         parenttype=currentobj.KeyType
  93.     end if
  94.     
  95.     'The physical directory may not currently
  96.     'exist in the metabase, so we have
  97.     'to find the parent vdir associated with
  98.     'the dir and build the path from there.    
  99.  
  100.  
  101.     if (vtype="dir") then
  102.         
  103.         Do Until Instr(parenttype, "VirtualDir") <> 0
  104.             'we need clear our path not found error..
  105.             err = 0            
  106.             
  107.             'add our initial whack...
  108.             newname = "/" + newname
  109.             
  110.             'and cyle through the baseobj till we find the next whack,
  111.             'building up the path in new name as we go
  112.             Do Until Right(baseobj,1) = "/"
  113.                 newname = Right(baseobj,1) & newname         
  114.                 baseobj = Mid(baseobj,1,Len(baseobj)-1)
  115.             Loop
  116.             
  117.             'once we're out, we need to lop off the last whack...
  118.             baseobj = Mid(baseobj,1,Len(baseobj)-1)
  119.             
  120.             'and try to set the object again...
  121.             Set currentobj=GetObject(baseobj)
  122.             
  123.             if err <> 0 then            
  124.                 parenttype = ""
  125.             else
  126.                 parenttype=currentobj.KeyType
  127.             end if                             
  128.         Loop    
  129.         
  130.     end if
  131.  
  132.     Response.write keytype & "  " & newname
  133.     Set newobj=currentobj.Create(keytype, newname)
  134.  
  135.     if err=0 then    
  136.     
  137.         if (vtype="dir") then
  138.             dirpath = currentobj.Path & "\" & Replace(newname,"/","\")
  139.             FileSystem.CreateFolder(dirpath)
  140.             
  141.             'now, we need to reset our newname to the actual title...
  142.             newname = dirname
  143.  
  144.         elseif (vtype="vdir") then
  145.             if currentobj.Path <> "" then
  146.                  newobj.Path=currentobj.Path
  147.             end if
  148.  
  149.         elseif (vtype="server") then
  150.             Set DefaultInst=GetObject("IIS://localhost/" & svc & "/1/Root")
  151.             Set rootobj=newobj.Create(vdir,"Root")
  152.             rootobj.Path = DefaultInst.Path
  153.             rootobj.SetInfo
  154.                                             
  155.             if stype = "www" then
  156.                 Set admininst=GetObject("IIS://localhost/w3svc/" & Request.ServerVariables("INSTANCE_ID") & "/Root/IISADMIN")                        
  157.                 Set adminobj=rootobj.Create("IIsWebVirtualDir","IISADMIN")
  158.                 adminobj.Path=admininst.Path
  159.                 adminobj.AuthNTLM=True
  160.                 adminobj.AuthAnonymous=False
  161.                 adminobj.AccessRead=True
  162.                 adminobj.AccessScript=True
  163.                 adminobj.SetInfo
  164.             end if 
  165.             
  166.             newobj.ServerComment=newADspath            
  167.  
  168.         end if
  169.         
  170.         if err=0 then
  171.             newobj.SetInfo
  172.         else
  173.             'unknown error
  174.             objerr=L_UNKNOWN_ERR & "(" & err & "-" & err.description & ")"
  175.         end if
  176.  
  177.     else        
  178.         ' Object exisits error
  179.         if err=-2147024713 then
  180.             err=0
  181.             objerr=L_OBJEXISTS_ERR
  182.         else
  183.             'unknown error
  184.             objerr=L_UNKNOWN_ERR & "(" & err & "-" & err.description & ")"
  185.             err=0
  186.         end if
  187.     end if
  188.     
  189. Case "del"
  190.     path=Request.QueryString("path")
  191.     getTypes
  192.     delmetanode = True
  193.     Set FileSystem=CreateObject("Scripting.FileSystemObject")
  194.     Set currentobj=GetObject(baseobj)
  195.     
  196.     newname = dirname
  197.     
  198.     'The physical directory may not currently
  199.     'exist in the metabase, so we have
  200.     'to find the parent vdir associated with
  201.     'the dir and build the path from there.    
  202.     
  203.     if (vtype="dir") then
  204.  
  205.     
  206.         'if currentobj can't be set due to path not found,
  207.         'we need to set our parenttype var manually
  208.         if err <> 0 then            
  209.             parenttype = ""
  210.             delmetanode = False
  211.         else
  212.             parenttype=currentobj.KeyType
  213.         end if     
  214.         
  215.  
  216.         Do Until Instr(parenttype, "VirtualDir") <> 0
  217.             'we need clear our path not found error..
  218.             err = 0            
  219.             
  220.             'add our initial whack...
  221.             newname = "/" + newname
  222.             
  223.             'and cyle through the baseobj till we find the next whack,
  224.             'building up the path in new name as we go
  225.             Do Until Right(baseobj,1) = "/"
  226.                 newname = Right(baseobj,1) & newname         
  227.                 baseobj = Mid(baseobj,1,Len(baseobj)-1)
  228.             Loop
  229.             
  230.             'once we're out, we need to lop off the last whack...
  231.             baseobj = Mid(baseobj,1,Len(baseobj)-1)
  232.             
  233.             'and try to set the object again...
  234.             Set currentobj=GetObject(baseobj)
  235.             
  236.             if err <> 0 then            
  237.                 parenttype = ""
  238.             else
  239.                 parenttype=currentobj.KeyType
  240.             end if                             
  241.         Loop        
  242.         
  243.         delpath=currentobj.Path & "\" & Replace(newname,"/","\")
  244.         FileSystem.DeleteFolder delpath                
  245.     end if
  246.     
  247.     if Instr(currentobj.KeyType, "Server") <> 0 then
  248.         baseobj=path & "/Root"
  249.         Set currentobj=GetObject(baseobj)
  250.     end if
  251.  
  252.     if delmetanode then
  253.         currentobj.Delete keytype, newname
  254.         currentobj.SetInfo
  255.     end if
  256.     
  257.     if err.Number <> 0 then
  258.         objerr=L_DELETE_ERR & "(" & err & "-" & err.description & ")"
  259.     end if    
  260.  
  261. Case CSTART 
  262.     action = "setstate"
  263.     path=Request.QueryString("path")
  264.     Set currentobj=GetObject(path)
  265.     bindings = currentobj.ServerBindings
  266.     if UBound(bindings) < 1 and bindings(0) = "" then
  267.         objerr = L_NOBINDINGS_ERR
  268.     else
  269.         currentobj.Start
  270.         if err.Number <> 0 then
  271.             objerr=L_START_ERR & "(" & err & "-" & err.description & ")"
  272.         end if
  273.     end if
  274.     
  275. Case CSTOP
  276.     action = "setstate"
  277.     path=Request.QueryString("path")
  278.     Set currentobj=GetObject(path)
  279.     currentobj.Stop
  280.     if err.Number <> 0 then
  281.         objerr=L_STOP_ERR & "(" & err & "-" & err.description & ")"
  282.     end if
  283.     
  284. Case CPAUSE
  285.     action = "setstate"
  286.     path=Request.QueryString("path")
  287.     Set currentobj=GetObject(path)
  288.     currentobj.Pause
  289.     if err.Number <> 0 then
  290.         objerr=L_PAUSE_ERR & "(" & err & "-" & err.description & ")"
  291.     end if    
  292.     
  293. Case CCONT
  294.     action = "setstate"
  295.     path=Request.QueryString("path")
  296.     Set currentobj=GetObject(path)
  297.     currentobj.Continue
  298.     if err.Number <> 0 then
  299.         objerr=L_CONT_ERR & "(" & err & "-" & err.description & ")"
  300.     end if    
  301.     
  302.     
  303. Case "CreateApp"
  304.     path=Session("path")
  305.     Response.write path & "<BR>"
  306.     Set currentobj=GetObject(path)
  307.     Response.write currentobj.KeyType & "<BR>"
  308.     currentobj.AppCreate "TRUE"
  309.     
  310.     if err.Number <> 0 then
  311.         objerr=L_APPCREATE_ERR & "(" & err & "-" & err.description & ")"
  312.     end if        
  313.     currentobj.SetInfo
  314.     Response.write currentobj.Get("AppRoot")
  315.     
  316. Case "RemoveApp"
  317.     path=Session("approot")
  318.     Response.write path & "<BR>"
  319.     Set currentobj = GetObject(path)
  320.     Response.write currentobj.ADsPath
  321.     currentobj.AppDeleteRecursive
  322.     if err.Number <> 0 then
  323.         objerr=L_APPREMOVE_ERR & "(" & err & "-" & err.description & ")"
  324.     end if
  325.  
  326.     
  327. Case "UnloadApp"
  328.     path=Session("approot")
  329.     Set currentobj=GetObject(path)
  330.     if Session("setProcOpts") then
  331.         currentobj.AppUnLoadRecursive
  332.     end if
  333.     if err.Number <> 0 then
  334.         objerr=L_APPUNLOAD_ERR & "(" & err & "-" & err.description & ")"
  335.     end if
  336.  
  337. Case "Backup"
  338.  
  339.     dim vVersionOut, vLocationOut, vDateOut, i
  340.     
  341.     bkupName = Request.Querystring("bkupName")
  342.     Set currentobj=GetObject("IIS://localhost")
  343.     
  344.     'get our next backup version # for this bkupName
  345.     i = 0
  346.     do while err.Number = 0     
  347.         currentobj.EnumBackups bkupName, i, vDateOut, vLocationOut, vVersionOut    
  348.         i = i + 1            
  349.     loop
  350.     err = 0
  351.  
  352.     currentobj.Backup bkupName, MD_BACKUP_NEXT_VERSION, "1"
  353.     if err.Number <> 0 then
  354.         objerr=L_BACKUP_ERR & "(" & err & "-" & err.description & ")"
  355.     end if
  356.  
  357. Case "BackupRmv"
  358.     
  359.     bkupName = Request.Querystring("bkupName")
  360.     bkupVer = Request.Querystring("bkupVer")    
  361.     if bkupVer = "" then
  362.         bkupVer = "0"
  363.     end if
  364.     Response.Write bkupname & " " & bkupVer
  365.     Set currentobj=GetObject("IIS://localhost")
  366.     
  367.     currentobj.DeleteBackup bkupName, cLng(bkupVer)
  368.     if err.Number <> 0 then
  369.         objerr=L_BACKUPRMV_ERR & "(" & err & "-" & err.description & ")"
  370.     end if                                    
  371.     
  372. Case Else
  373.     Response.Write "No Action"    
  374.     Response.write Request.Querystring
  375. End Select
  376.  
  377.  
  378. Sub getTypes()
  379.     vtype=Request.QueryString("vtype")
  380.     stype=Request.QueryString("stype")
  381.     pos=InStr(7, path, "/")
  382.     newADspath=Mid(path, Pos + 1)
  383.     dirname=newADsPath
  384.     Do While InStr(dirname,"/")
  385.         dirname=Mid(dirname,InStr(dirname,"/")+1)
  386.     Loop
  387.     
  388.     dirnamelen=len(dirname)+1
  389.     baseobj=Mid(path,1,len(path)-dirnamelen)
  390.     
  391.     if stype="www" then
  392.         svc="w3svc"
  393.         key="Web"
  394.     elseif stype="ftp" then
  395.         svc="msftpsvc"
  396.         key="Ftp"    
  397.     end if
  398.     
  399.     Select Case vtype
  400.          Case "dir" 
  401.             keytype="IIs" & key & "Directory"
  402.             newname=dirname
  403.         Case "vdir"
  404.             keytype="IIs" & key & "VirtualDir"
  405.             newname=dirname
  406.         Case "server"
  407.             keytype="IIs" & key & "Server"        
  408.     End Select
  409.     
  410.     vdir="IIs" & key & "VirtualDir"
  411.  
  412. End Sub
  413.  
  414. Sub print(str)
  415.     Response.Write str
  416.     if err <> 0 and err <> "" then
  417.         Response.Write "<FONT COLOR=red> (" & err & ":" & err.description & ")</FONT>"
  418.     end if 
  419.     Response.Write "<P>"
  420. End Sub
  421.  
  422.                                 
  423.  %>
  424.  
  425. <BODY BGCOLOR="#000000" TEXT="#FFCC00" TOPMARGIN=0 LEFTMARGIN=0>
  426. <SCRIPT LANGUAGE="JavaScript">
  427.  
  428.     // Now that we've set it in the object, we need to update our client cachedList:
  429.         
  430.     <% if objerr="" then %>
  431.     <% Select Case action %>
  432.         <% Case "add" %>
  433.             if (!top.head.nodeList[<%= sel %>].isCached){
  434.                 top.head.nodeList[<%= sel %>].cache(<%= sel %>);
  435.             }
  436.             else{
  437.                 top.head.nodeList[<%= sel %>].insertNode("<%= newname %>","<%= dirname %>",<%= sel %>,"<%= vtype %>","<%= stype %>");
  438.             }
  439.  
  440.         <% Case "del" %>
  441.                 top.head.nodeList[<%= sel %>].deleteItem();
  442.                                 
  443.         <% Case "setstate" %>
  444.                 top.head.nodeList[<%= sel %>].displaystate=top.head.Global.displaystate[<%= a %>];                
  445.                 top.head.nodeList[<%= sel %>].state=<%= a %>;
  446.                 top.body.list.location.href=top.body.list.location.href;
  447.         <% Case "Backup" %>                
  448.                 top.main.head.location.href = top.main.head.location.href;
  449.         <% Case "BackupRmv" %>                
  450.                 top.main.head.location.href = top.main.head.location.href;                                
  451.  
  452.     <% End Select %>
  453.         
  454.     <% else %>
  455.         alert("<%= objerr%>");
  456.     <% end if %>
  457.  
  458.     if (top.body != null){
  459.         top.body.iisstatus.location.href="iistat.asp?thisState=";
  460.     }
  461.  
  462. </SCRIPT>
  463. </BODY>
  464. </HTML>