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

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