home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2000 March / VPR0003B.ISO / alpha / iiaction.asp < prev    next >
Text File  |  1999-10-14  |  12KB  |  471 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="アクセスは拒否されました"
  18. Const L_OBJEXISTS_ERR="指定したオブジェクトは既に存在します。違う名前のオブジェクトを指定してください。" 
  19. Const L_UNKNOWN_ERR="原因不明のエラーが発生しました。"
  20. Const L_START_ERR="正しく構成されていないのでサービスを開始できませんでした。同じマシン上の他のサーバーとサーバー結合の競合がないことを確認してください。"
  21. Const L_NOBINDINGS_ERR = "開始する前に、このサイトへの結合を割り当てなければなりません。"
  22. Const L_STOP_ERR="サイトを停止できませんでした。"
  23. Const L_CONT_ERR="サイトを再開できませんでした。"
  24. Const L_PAUSE_ERR="サイトを一時停止できませんでした。"
  25. Const L_DELETE_ERR="オブジェクトを削除できませんでした。"
  26. Const L_APPCREATE_ERR="アプリケーションを作成できませんでした。"
  27. Const L_APPREMOVE_ERR="アプリケーションを削除できませんでした。"
  28. Const L_APPUNLOAD_ERR="アプリケーションをアンロードできませんでした。"
  29. Const L_BACKUP_ERR = "バックアップに失敗しました。"
  30. Const L_BACKUPRMV_ERR = "バックアップを削除できませんでした。"
  31. Const L_DEFAULTAPP_TEXT = "既定のアプリケーション"
  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.                 if cint(inst.name) > Nextinst then
  75.                     Nextinst=cint(inst.name)
  76.                 end if
  77.             end if
  78.         Next
  79.         newname=Nextinst+1
  80.     end if 
  81.  
  82.     Set currentobj=GetObject(baseobj)
  83.     'if currentobj can't be set due to path not found,
  84.     'we need to set our parenttype var manually
  85.     if err <> 0 then            
  86.         parenttype = ""
  87.     else
  88.         parenttype=currentobj.KeyType
  89.     end if     
  90.  
  91.  
  92.     if Instr(parenttype,"Server") <> 0 then
  93.         baseobj=baseobj & "/Root"
  94.         Set currentobj=GetObject(baseobj)
  95.         parenttype=currentobj.KeyType
  96.     end if
  97.     
  98.     'The physical directory may not currently
  99.     'exist in the metabase, so we have
  100.     'to find the parent vdir associated with
  101.     'the dir and build the path from there.    
  102.  
  103.  
  104.     if (vtype="dir") then
  105.         
  106.         Do Until Instr(parenttype, "VirtualDir") <> 0
  107.             'we need clear our path not found error..
  108.             err = 0            
  109.             
  110.             'add our initial whack...
  111.             newname = "/" + newname
  112.             
  113.             'and cyle through the baseobj till we find the next whack,
  114.             'building up the path in new name as we go
  115.             Do Until Right(baseobj,1) = "/"
  116.                 newname = Right(baseobj,1) & newname         
  117.                 baseobj = Mid(baseobj,1,Len(baseobj)-1)
  118.             Loop
  119.             
  120.             'once we're out, we need to lop off the last whack...
  121.             baseobj = Mid(baseobj,1,Len(baseobj)-1)
  122.             
  123.             'and try to set the object again...
  124.             Set currentobj=GetObject(baseobj)
  125.             
  126.             if err <> 0 then            
  127.                 parenttype = ""
  128.             else
  129.                 parenttype=currentobj.KeyType
  130.             end if                             
  131.         Loop    
  132.         
  133.     end if
  134.  
  135.     Set newobj=currentobj.Create(keytype, newname)
  136.  
  137.     if err=0 then    
  138.     
  139.         if (vtype="dir") then
  140.             dirpath = currentobj.Path & "\" & Replace(newname,"/","\")
  141.             FileSystem.CreateFolder(dirpath)
  142.             
  143.             'now, we need to reset our newname to the actual title...
  144.             newname = dirname
  145.  
  146.         elseif (vtype="vdir") then
  147.             if currentobj.Path <> "" then
  148.                  newobj.Path=currentobj.Path            
  149.             end if
  150.  
  151.         elseif (vtype="server") then
  152.             Set DefaultInst=GetObject("IIS://localhost/" & svc & "/1/Root")
  153.             Set rootobj=newobj.Create(vdir,"Root")
  154.             rootobj.Path = DefaultInst.Path
  155.             rootobj.AccessRead=True
  156.             if stype = "www" then
  157.                 rootobj.AppFriendlyName = L_DEFAULTAPP_TEXT
  158.  
  159.                 rootobj.AccessScript=True            
  160.                 rootobj.AppCreate "TRUE"
  161.             end if 
  162.             rootobj.SetInfo            
  163.                                             
  164.             if stype = "www" then
  165.                 Set admininst=GetObject("IIS://localhost/w3svc/" & Request.ServerVariables("INSTANCE_ID") & "/Root/IISADMIN")                        
  166.                 Set adminobj=rootobj.Create("IIsWebVirtualDir","IISADMIN")
  167.                 adminobj.Path=admininst.Path
  168.                 adminobj.AuthNTLM=True
  169.                 adminobj.AuthAnonymous=False
  170.                 adminobj.AccessRead=True
  171.                 adminobj.AccessScript=True
  172.                 adminobj.SetInfo
  173.             end if 
  174.             
  175.             newobj.ServerComment=newADspath            
  176.  
  177.         end if
  178.         
  179.         if err=0 then
  180.             newobj.SetInfo
  181.         else
  182.             'unknown error
  183.             objerr=L_UNKNOWN_ERR & "(" & err & "(" & Hex(err) & ") -" & err.description & ")"
  184.         end if
  185.  
  186.     else        
  187.         ' Object exisits error
  188.         if err=-2147024713 then
  189.             err=0
  190.             objerr=L_OBJEXISTS_ERR
  191.         else
  192.             'unknown error
  193.             objerr=L_UNKNOWN_ERR & "(" & err & "-" & err.description & ")"
  194.             err=0
  195.         end if
  196.     end if
  197.     
  198. Case "del"
  199.     path=Request.QueryString("path")
  200.     getTypes
  201.     delmetanode = True
  202.     Set FileSystem=CreateObject("Scripting.FileSystemObject")
  203.     Set currentobj=GetObject(baseobj)
  204.     
  205.     newname = dirname
  206.     
  207.     'The physical directory may not currently
  208.     'exist in the metabase, so we have
  209.     'to find the parent vdir associated with
  210.     'the dir and build the path from there.    
  211.     
  212.     if (vtype="dir") then
  213.  
  214.     
  215.         'if currentobj can't be set due to path not found,
  216.         'we need to set our parenttype var manually
  217.         if err <> 0 then            
  218.             parenttype = ""
  219.             delmetanode = False
  220.         else
  221.             parenttype=currentobj.KeyType
  222.         end if     
  223.         
  224.  
  225.         Do Until Instr(parenttype, "VirtualDir") <> 0
  226.             'we need clear our path not found error..
  227.             err = 0            
  228.             
  229.             'add our initial whack...
  230.             newname = "/" + newname
  231.             
  232.             'and cyle through the baseobj till we find the next whack,
  233.             'building up the path in new name as we go
  234.             Do Until Right(baseobj,1) = "/"
  235.                 newname = Right(baseobj,1) & newname         
  236.                 baseobj = Mid(baseobj,1,Len(baseobj)-1)
  237.             Loop
  238.             
  239.             'once we're out, we need to lop off the last whack...
  240.             baseobj = Mid(baseobj,1,Len(baseobj)-1)
  241.             
  242.             'and try to set the object again...
  243.             Set currentobj=GetObject(baseobj)
  244.             
  245.             if err <> 0 then            
  246.                 parenttype = ""
  247.             else
  248.                 parenttype=currentobj.KeyType
  249.             end if                             
  250.         Loop        
  251.         
  252.         delpath=currentobj.Path & "\" & Replace(newname,"/","\")
  253.         FileSystem.DeleteFolder delpath                
  254.     end if
  255.     
  256.     if Instr(currentobj.KeyType, "Server") <> 0 then
  257.         baseobj=path & "/Root"
  258.         Set currentobj=GetObject(baseobj)
  259.     end if
  260.  
  261.     if delmetanode then
  262.         currentobj.Delete keytype, newname
  263.         currentobj.SetInfo
  264.     end if
  265.     
  266.     if err.Number <> 0 then
  267.         objerr=L_DELETE_ERR & "(" & err & "-" & err.description & ")"
  268.     end if    
  269.  
  270. Case CSTART 
  271.     action = "setstate"
  272.     path=Request.QueryString("path")
  273.     Set currentobj=GetObject(path)
  274.     bindings = currentobj.ServerBindings
  275.     if UBound(bindings) < 1 and bindings(0) = "" then
  276.         objerr = L_NOBINDINGS_ERR
  277.     else
  278.         currentobj.Start
  279.         if err.Number <> 0 then
  280.             objerr=L_START_ERR & "(" & err & "-" & err.description & ")"
  281.         end if
  282.     end if
  283.     
  284. Case CSTOP
  285.     action = "setstate"
  286.     path=Request.QueryString("path")
  287.     Set currentobj=GetObject(path)
  288.     currentobj.Stop
  289.     if err.Number <> 0 then
  290.         objerr=L_STOP_ERR & "(" & err & "-" & err.description & ")"
  291.     end if
  292.     
  293. Case CPAUSE
  294.     action = "setstate"
  295.     path=Request.QueryString("path")
  296.     Set currentobj=GetObject(path)
  297.     currentobj.Pause
  298.     if err.Number <> 0 then
  299.         objerr=L_PAUSE_ERR & "(" & err & "-" & err.description & ")"
  300.     end if    
  301.     
  302. Case CCONT
  303.     action = "setstate"
  304.     path=Request.QueryString("path")
  305.     Set currentobj=GetObject(path)
  306.     currentobj.Continue
  307.     if err.Number <> 0 then
  308.         objerr=L_CONT_ERR & "(" & err & "-" & err.description & ")"
  309.     end if    
  310.     
  311.     
  312. Case "CreateApp"
  313.     path=Session("path")
  314.     if Right(path,1) = "/" then
  315.         path = Mid(path,1,Len(path)-1)
  316.     end if
  317.     Set currentobj=GetObject(path)
  318.     Response.write currentobj.KeyType & "<BR>"
  319.     currentobj.AppCreate "TRUE"
  320.     
  321.     if err.Number <> 0 then
  322.         objerr=L_APPCREATE_ERR & "(" & err & "-" & err.description & ")"
  323.     end if        
  324.     currentobj.SetInfo
  325.     Response.write currentobj.Get("AppRoot")
  326.     
  327. Case "RemoveApp"
  328.     path=Session("approot")
  329.     if Right(path,1) = "/" then
  330.         path = Mid(path,1,Len(path)-1)
  331.     end if        
  332.     Set currentobj = GetObject(path)
  333.     currentobj.AppDeleteRecursive
  334.     if err.Number <> 0 then
  335.         objerr=L_APPREMOVE_ERR & "(" & err & "-" & err.description & ")"
  336.     end if
  337.  
  338.     
  339. Case "UnloadApp"
  340.     path=Session("approot")
  341.     if Right(path,1) = "/" then
  342.         path = Mid(path,1,Len(path)-1)
  343.     end if        
  344.     Set currentobj=GetObject(path)
  345.     if Session("setProcOpts") then
  346.         currentobj.AppUnLoadRecursive
  347.     end if
  348.     if err.Number <> 0 then
  349.         objerr=L_APPUNLOAD_ERR & "(" & err & "-" & err.description & ")"
  350.     end if
  351.  
  352. Case "Backup"
  353.  
  354.     dim vVersionOut, vLocationOut, vDateOut, i
  355.     
  356.     bkupName = Request.Querystring("bkupName")
  357.     Set currentobj=GetObject("IIS://localhost")
  358.     
  359.     currentobj.Backup bkupName, MD_BACKUP_NEXT_VERSION, "1"
  360.     if err.Number <> 0 then
  361.         objerr=L_BACKUP_ERR & "(" & err & "-" & err.description & ")"
  362.     end if
  363.  
  364. Case "BackupRmv"
  365.     
  366.     bkupName = Request.Querystring("bkupName")
  367.     bkupVer = Request.Querystring("bkupVer")    
  368.     if bkupVer = "" then
  369.         bkupVer = "0"
  370.     end if
  371.     Response.Write bkupname & " " & bkupVer
  372.     Set currentobj=GetObject("IIS://localhost")
  373.     
  374.     currentobj.DeleteBackup bkupName, cLng(bkupVer)
  375.     if err.Number <> 0 then
  376.         objerr=L_BACKUPRMV_ERR & "(" & err & "-" & err.description & ")"
  377.     end if                                    
  378.     
  379. Case Else
  380.     Response.Write "No Action"    
  381.     Response.write Request.Querystring
  382. End Select
  383.  
  384.  
  385. Sub getTypes()
  386.     vtype=Request.QueryString("vtype")
  387.     stype=Request.QueryString("stype")
  388.     pos=InStr(7, path, "/")
  389.     newADspath=Mid(path, Pos + 1)
  390.     dirname=newADsPath
  391.     Do While InStr(dirname,"/")
  392.         dirname=Mid(dirname,InStr(dirname,"/")+1)
  393.     Loop
  394.     
  395.     dirnamelen=len(dirname)+1
  396.     baseobj=Mid(path,1,len(path)-dirnamelen)
  397.     
  398.     if stype="www" then
  399.         svc="w3svc"
  400.         key="Web"
  401.     elseif stype="ftp" then
  402.         svc="msftpsvc"
  403.         key="Ftp"    
  404.     end if
  405.     
  406.     Select Case vtype
  407.          Case "dir" 
  408.             keytype="IIs" & key & "Directory"
  409.             newname=dirname
  410.         Case "vdir"
  411.             keytype="IIs" & key & "VirtualDir"
  412.             newname=dirname
  413.         Case "server"
  414.             keytype="IIs" & key & "Server"        
  415.     End Select
  416.     
  417.     vdir="IIs" & key & "VirtualDir"
  418.  
  419. End Sub
  420.  
  421. Sub print(str)
  422.     Response.Write str
  423.     if err <> 0 and err <> "" then
  424.         Response.Write "<FONT COLOR=red> (" & err & ":" & err.description & ")</FONT>"
  425.     end if 
  426.     Response.Write "<P>"
  427. End Sub
  428.  
  429.                                 
  430.  %>
  431.  
  432. <BODY BGCOLOR="#000000" TEXT="#FFCC00" TOPMARGIN=0 LEFTMARGIN=0>
  433. <SCRIPT LANGUAGE="JavaScript">
  434.  
  435.     // Now that we've set it in the object, we need to update our client cachedList:
  436.         
  437.     <% if objerr="" then %>
  438.     <% Select Case action %>
  439.         <% Case "add" %>
  440.             if (!top.title.nodeList[<%= sel %>].isCached){
  441.                 top.title.nodeList[<%= sel %>].cache(<%= sel %>);
  442.             }
  443.             else{
  444.                 top.title.nodeList[<%= sel %>].insertNode("<%= newname %>","<%= dirname %>",<%= sel %>,"<%= vtype %>","<%= stype %>");
  445.             }
  446.  
  447.         <% Case "del" %>
  448.                 top.title.nodeList[<%= sel %>].deleteItem();
  449.                                 
  450.         <% Case "setstate" %>
  451.                 top.title.nodeList[<%= sel %>].displaystate=top.title.Global.displaystate[<%= a %>];                
  452.                 top.title.nodeList[<%= sel %>].state=<%= a %>;
  453.                 top.body.list.location.href=top.body.list.location.href;
  454.         <% Case "Backup" %>                
  455.                 top.main.head.location.href = top.main.head.location.href;
  456.         <% Case "BackupRmv" %>                
  457.                 top.main.head.location.href = top.main.head.location.href;                                
  458.  
  459.     <% End Select %>
  460.         
  461.     <% else %>
  462.         alert("<%= objerr%>");
  463.     <% end if %>
  464.  
  465.     if (top.body != null){
  466.         top.body.iisstatus.location.href="iistat.asp?thisState=";
  467.     }
  468.  
  469. </SCRIPT>
  470. </BODY>
  471. </HTML>