Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

359 lines
8.8 KiB

  1. <%@ LANGUAGE = VBScript %>
  2. <% Option Explicit %>
  3. <!-- #include file="directives.inc" -->
  4. <%
  5. ' This script adds, deletes, and sets state on adsi objects, as appropriate,
  6. ' based upon the value of the action parameter.
  7. ' It does some error checking...
  8. ' Only instance may be started, stopped, paused or resumed.
  9. %>
  10. <!--#include file="iiaction.str"-->
  11. <%
  12. Const CSTART="2"
  13. Const CSTOP="4"
  14. Const CPAUSE="6"
  15. Const CCONT="0"
  16. Const MD_BACKUP_NEXT_VERSION = &HFFFFFFFF
  17. Const MD_PATH_NOT_FOUND = &H80070003
  18. Const IISAO_APPROT_POOL = 2
  19. %>
  20. <HTML>
  21. <%
  22. On Error Resume Next
  23. Dim action, path, vtype,stype,sel,pos,newADspath, dirname, keytype
  24. Dim dirnamelen, baseobj, svc,key, keyname, newname, vdir, sname
  25. Dim service, inst, nextinst, FileSystem, parenttype, newobj
  26. Dim currentobj, rootobj, adminobj, objerr, delmetanode, bindings
  27. Dim defaultinst, admininst, a
  28. Dim bkupName, bkupVer, dirpath, delpath
  29. Dim isolateCreateApp
  30. action=Request.QueryString("a")
  31. sel=Request.QueryString("sel")
  32. path = Request.QueryString("path")
  33. 'save off our original action...
  34. a = action
  35. Select Case action
  36. Case "del"
  37. path=Request.QueryString("path")
  38. getTypes
  39. ' path - the path of the node we want to delete
  40. ' baseobject - the path of our parent node
  41. ' stype - "ftp" or "www"
  42. ' vtype - "server", "vdir", "dir"
  43. ' dirname - the last part of this node's path
  44. ' keytype - admin KeyType for this node
  45. delmetanode = True
  46. ' Special case dir, because this is the only instance when
  47. ' we remove directories from the server. At the end of of these
  48. ' blocks currentobj keytype and dirname should be set correctly to do
  49. ' the delete.
  50. if vtype = "dir" then
  51. ' Directories may not be in the metabase
  52. Set currentobj = GetObject( path )
  53. if err.Number = MD_PATH_NOT_FOUND then
  54. delmetanode = False
  55. err.Clear
  56. end if
  57. ' Do the file system delete
  58. delpath = strMBPathToFSPath( baseobj )
  59. if delpath <> "" then
  60. delpath = delpath & "\" & dirname
  61. Set FileSystem=CreateObject("Scripting.FileSystemObject")
  62. FileSystem.DeleteFolder delpath
  63. end if
  64. elseif vtype = "server" and stype = "www" then
  65. ' Special case for web servers, they support NotDeletable so that
  66. ' we don't do something foolish and wack the Admin site.
  67. Set currentobj = GetObject( path )
  68. if currentobj.NotDeletable = True or err.Number <> 0 then
  69. objerr=L_NOTDELETABLE_ERR
  70. delmetanode = False
  71. end if
  72. end if
  73. if delmetanode then
  74. ' Delete called from parent of the object that we want to delete
  75. Set currentobj = GetObject(baseobj)
  76. currentobj.Delete keytype, dirname
  77. currentobj.SetInfo
  78. end if
  79. if err.Number <> 0 then
  80. objerr=L_DELETE_ERR & "(" & err & "-" & err.description & ")"
  81. end if
  82. ' End of Case "del"
  83. Case CSTART
  84. action = "setstate"
  85. path=Request.QueryString("path")
  86. Set currentobj=GetObject(path)
  87. bindings = currentobj.ServerBindings
  88. if UBound(bindings) < 1 and bindings(0) = "" then
  89. objerr = L_NOBINDINGS_ERR
  90. else
  91. currentobj.Start
  92. if err.Number <> 0 then
  93. objerr= L_CANTSTART_TEXT
  94. end if
  95. end if
  96. Case CSTOP
  97. action = "setstate"
  98. path=Request.QueryString("path")
  99. Set currentobj=GetObject(path)
  100. currentobj.Stop
  101. if err.Number <> 0 then
  102. objerr=L_STOP_ERR & "(" & err & "-" & err.description & ")"
  103. end if
  104. Case CPAUSE
  105. action = "setstate"
  106. path=Request.QueryString("path")
  107. Set currentobj=GetObject(path)
  108. currentobj.Pause
  109. if err.Number <> 0 then
  110. objerr=L_PAUSE_ERR & "(" & err & "-" & err.description & ")"
  111. end if
  112. Case CCONT
  113. action = "setstate"
  114. path=Request.QueryString("path")
  115. Set currentobj=GetObject(path)
  116. currentobj.Continue
  117. if err.Number <> 0 then
  118. objerr=L_CONT_ERR & "(" & err & "-" & err.description & ")"
  119. end if
  120. Case "CreateApp"
  121. path=Session("path")
  122. if Right(path,1) = "/" then
  123. path = Mid(path,1,Len(path)-1)
  124. end if
  125. Set currentobj=GetObject(path)
  126. ' Response.write currentobj.ADsPath & "<BR>"
  127. ' Response.write currentobj.Class & "<BR>"
  128. isolateCreateApp = Request.QueryString("isolate")
  129. if isolateCreateApp = "" then
  130. isolateCreateApp = IISAO_APPROT_POOL
  131. end if
  132. currentobj.AppCreate2 CInt(isolateCreateApp)
  133. ' Response.write "currentobj.AppCreate2" & isolateCreateApp & "<BR>"
  134. if err.Number <> 0 then
  135. objerr=L_APPCREATE_ERR & "(" & err & "-" & err.description & ")"
  136. end if
  137. currentobj.SetInfo
  138. ' Response.write currentobj.Get("AppRoot") & "<BR>"
  139. Case "RemoveApp"
  140. path=Session("approot")
  141. if Right(path,1) = "/" then
  142. path = Mid(path,1,Len(path)-1)
  143. end if
  144. Set currentobj = GetObject(path)
  145. ' Response.write currentobj.ADsPath & "<BR>"
  146. ' Response.write currentobj.Class & "<BR>"
  147. currentobj.AppDeleteRecursive
  148. ' Response.write "currentobj.AppCreate2" & isolateCreateApp & "<BR>"
  149. if err.Number <> 0 then
  150. objerr=L_APPREMOVE_ERR & "(" & err & "-" & err.description & ")"
  151. end if
  152. Case "Backup"
  153. dim vVersionOut, vLocationOut, vDateOut, i
  154. bkupName = Request.Querystring("bkupName")
  155. Set currentobj=GetObject("IIS://localhost")
  156. currentobj.Backup bkupName, MD_BACKUP_NEXT_VERSION, "1"
  157. if err.Number <> 0 then
  158. objerr=L_BACKUP_ERR
  159. end if
  160. Case "BackupRmv"
  161. bkupName = Request.Querystring("bkupName")
  162. bkupVer = Request.Querystring("bkupVer")
  163. if bkupVer = "" then
  164. bkupVer = "0"
  165. end if
  166. ' Response.Write bkupname & " " & bkupVer
  167. Set currentobj=GetObject("IIS://localhost")
  168. currentobj.DeleteBackup bkupName, cLng(bkupVer)
  169. if err.Number <> 0 then
  170. objerr=L_BACKUPRMV_ERR & "(" & err & "-" & err.description & ")"
  171. end if
  172. Case Else
  173. 'debug only.. no need to localize...
  174. ' Response.Write "No Action"
  175. ' Response.write Request.Querystring
  176. End Select
  177. Sub getTypes()
  178. vtype=Request.QueryString("vtype")
  179. stype=Request.QueryString("stype")
  180. pos=InStr(7, path, "/")
  181. newADspath=Mid(path, Pos + 1)
  182. dirname=newADsPath
  183. Do While InStr(dirname,"/")
  184. dirname=Mid(dirname,InStr(dirname,"/")+1)
  185. Loop
  186. dirnamelen=len(dirname)+1
  187. baseobj=Mid(path,1,len(path)-dirnamelen)
  188. if stype="www" then
  189. svc="w3svc"
  190. key="Web"
  191. elseif stype="ftp" then
  192. svc="msftpsvc"
  193. key="Ftp"
  194. end if
  195. Select Case vtype
  196. Case "dir"
  197. keytype="IIs" & key & "Directory"
  198. newname=dirname
  199. Case "vdir"
  200. keytype="IIs" & key & "VirtualDir"
  201. newname=dirname
  202. Case "server"
  203. keytype="IIs" & key & "Server"
  204. End Select
  205. vdir="IIs" & key & "VirtualDir"
  206. End Sub
  207. ' Converts a metabase path to the approprate file system path
  208. '
  209. ' We kinda assume that strMBPath is a valid metabase path and that the
  210. ' MB contains a vdir entry somewhere along the path, these should
  211. ' be safe assumptions for paths that are being displayed in the
  212. ' treeview, but error handling should work in case we are passed somthing
  213. ' wierd
  214. Function strMBPathToFSPath( strMBPath )
  215. On Error Resume Next
  216. Dim strFSPath, intSlashPos, strParentPath, strSubDir, strKeyType, bFoundMBDir
  217. Dim objCurrent
  218. strFSPath = ""
  219. strParentPath = strMBPath
  220. strSubDir = ""
  221. bFoundMBDir = False
  222. ' We need to travel up the strMBPath until we hit a virtual directory,
  223. ' that's where our file system base path is stored.
  224. do
  225. Set objCurrent = GetObject( strParentPath )
  226. if err.Number = 0 then
  227. strKeyType = objCurrent.KeyType
  228. elseif err.Number = MD_PATH_NOT_FOUND then
  229. strKeyType = ""
  230. err.Clear
  231. else
  232. ' Some unexpected ADSI/MB error
  233. exit do
  234. end if
  235. if Instr( strKeyType, "VirtualDir" ) = 0 then
  236. ' Get the parent MB path and the sub directory
  237. intSlashPos = InStrRev( strParentPath, "/" )
  238. if intSlashPos = 0 then
  239. ' We ran out of path. strMBPath was not valid
  240. ' Should set an error here but we need a description
  241. exit do
  242. end if
  243. strSubDir = "\" & Mid( strParentPath, intSlashPos + 1 ) & strSubDir
  244. strParentPath = Left( strParentPath, intSlashPos - 1 )
  245. else
  246. ' We found a VirtualDir parent
  247. bFoundMBDir = True
  248. err.Clear
  249. strFSPath = objCurrent.Path & strSubDir
  250. end if
  251. loop until bFoundMBDir = True
  252. strMBPathToFSPath = strFSPath
  253. End Function
  254. 'debug only
  255. Sub print(str)
  256. ' Response.Write str
  257. if err <> 0 and err <> "" then
  258. ' Response.Write "<FONT COLOR=red> (" & err & ":" & err.description & ")</FONT>"
  259. end if
  260. Response.Write "<P>"
  261. End Sub
  262. %>
  263. <BODY TEXT="#FFCC00" TOPMARGIN=0 LEFTMARGIN=0>
  264. <SCRIPT LANGUAGE="JavaScript">
  265. // Now that we've set it in the object, we need to update our client cachedList:
  266. <% if objerr="" then %>
  267. <% Select Case action %>
  268. <% Case "del" %>
  269. top.title.nodeList[<%= sel %>].deleteItem();
  270. top.title.Global.selId = 0;
  271. <% Case "setstate" %>
  272. top.title.nodeList[<%= sel %>].displaystate=top.title.Global.displaystate[<%= a %>];
  273. top.title.nodeList[<%= sel %>].state=<%= a %>;
  274. top.body.list.location.href="iisrvls.asp";
  275. <% Case "Backup" %>
  276. top.main.head.location.href = top.main.head.location.href;
  277. <% Case "BackupRmv" %>
  278. top.main.head.location.href = top.main.head.location.href;
  279. <% End Select %>
  280. <% else %>
  281. alert("<%= objerr%>");
  282. <% end if %>
  283. if (top.body != null){
  284. top.body.iisstatus.location.href="iistat.asp?thisState=";
  285. }
  286. </SCRIPT>
  287. </BODY>
  288. </HTML>