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.

328 lines
9.5 KiB

  1. <%
  2. 'Big gnarly function to create a new node of the appropriate type
  3. 'and set the appropriate properties on it.
  4. Const IISAO_APPROT_POOL = 2
  5. Function CreateNewNode()
  6. 'commented out during development. I need to see what's happening if it's busted.
  7. On Error Resume Next
  8. 'dim all are vars, we should have option explicit on
  9. Dim sService, sKeyType, sNodeName, iNodeType, oParentNode, oNewNode, oRootNode, oAdminSite, oAdminRoot
  10. Dim bParentIsSite, iParentID, sPhysPath, oFileSystem, sRootKeyType, iSiteType, sNodeID
  11. Dim thispath, bIsApp
  12. bIsApp = False
  13. 'Grab our parameters and stick 'em in some variables.
  14. 'Also, convert to int for comparsion... all request vars come in as variant/strings
  15. 'in vbscript 0 <> "0"
  16. iNodeType = cInt(Request("NodeType"))
  17. iSiteType = cInt(Request("SiteType"))
  18. 'This is the name of the site, alias of the vdir, or dir name for the directory
  19. sNodeName = Request("NodeName")
  20. thispath = Session("ParentADSPath")
  21. 'Get our parent metabase node. This is where we will be adding a child node.
  22. Set oParentNode = GetObject(thispath)
  23. 'Find out if we are adding onto a site, a vdir or a dir.
  24. 'The type will determine where we add the new node.
  25. bParentIsSite = InStr(oParentNode.KeyType,SSITE) > 0
  26. 'If we are adding on a site...
  27. if InStr(oParentNode.KeyType,SSITE) > 0 then
  28. 'And the type of node we are adding is a site..
  29. if iNodeType = SITE then
  30. 'Then add a sibling to the parent.
  31. Set oParentNode = GetObject(BASEPATH & SERVICES(iSiteType))
  32. 'we will be adding either a vdir or a dir
  33. else
  34. 'so, we need to add it on the Root of the parent node.
  35. Set oParentNode = GetObject(oParentNode.ADsPath & ROOT)
  36. end if
  37. 'If the parent node is the computer node...
  38. elseif InStr(oParentNode.KeyType,SCOMP) > 0 then
  39. 'then we know we are adding a new site, to the Serivce node.
  40. Set oParentNode = GetObject(BASEPATH & SERVICES(iSiteType))
  41. 'The else case here is irrelevant... it means we must be adding
  42. 'a vdir or dir to a vdir or a dir, so we can use our parentpath
  43. 'as is.
  44. 'else
  45. end if
  46. 'If we are adding a site, then we need to find out what the new instance number is...
  47. if iNodeType = SITE then
  48. 'sNodeID will hold the NAME property...
  49. 'sNodeName will be put into the Server Comment property
  50. sNodeID = cInt(sGetNextInstanceName(iSiteType))
  51. 'This is the parent id for the client-side node tree cache.
  52. 'New sites always have a parent id of 0 (ie, the computer node)
  53. iParentID = 0
  54. else
  55. 'The node id will be = to the Alias or Directory name
  56. sNodeID = sNodeName
  57. 'We've stored the currently selected parent id in a Session var...
  58. iParentID = Session("ParentID")
  59. end if
  60. 'Get the properly formatted Keytype for the node we are adding...
  61. sKeyType = sGetKeyType(iSiteType, iNodeType)
  62. '#IFDEF _DEBUG
  63. 'Response.write oParentNode.KeyType & "<BR>"
  64. 'Response.write sKeyType & "<BR>"
  65. 'Response.write sNodeID & "<BR>"
  66. '#ENDDEF _DEBUG
  67. 'MAKE THE NODE! WOO-HOO
  68. set oNewNode = GetObject(oParentNode.ADsPath & "/" & sNodeID)
  69. if err <> 0 then
  70. err.clear
  71. Set oNewNode=oParentNode.Create(sKeyType, sNodeID)
  72. end if
  73. 'Now, we have to set all the required stuff...
  74. if iNodeType = SITE then
  75. 'Sites require a Root node, server comment, server bindings, secure bindings
  76. 'Subsequently, there will be stuff set on this newly created root node.
  77. 'If they don't exist... we don't add the properties.
  78. sRootKeyType = sGetKeyType(iSiteType, VDIR)
  79. Set oRootNode=oNewNode.Create(sRootKeyType, "ROOT")
  80. oNewNode.ServerComment = sNodeName
  81. if Request("TCPPort") <> "" then
  82. oNewNode.ServerBindings= Array(Request("IPAddress") & ":" & Request("TCPPort") & ":")
  83. end if
  84. if Request("SSLPort") <> "" then
  85. oNewNode.SecureBindings= Array(Request("IPAddress") & ":" & Request("SSLPort") & ":")
  86. end if
  87. oNewNode.SetInfo
  88. else
  89. Set oRootNode = oNewNode
  90. end if
  91. if iNodeType = DIR then
  92. 'Directories require a path. We have to build it from the parent's path, as all
  93. 'the user just entered was the new directory name.
  94. sPhysPath = sGetPhysPath(oParentNode, sNodeName)
  95. Set oFileSystem=CreateObject("Scripting.FileSystemObject")
  96. oFileSystem.CreateFolder(sPhysPath)
  97. else
  98. 'Set some vdir stuff. This creates an application, etc.
  99. oRootNode.Path=Request("VRPath")
  100. oRootNode.SetInfo
  101. if iSiteType = WEB then
  102. oRootNode.AuthAnonymous = Request("AllowAnon") = "on"
  103. oRootNode.AppFriendlyName = L_DEFAULTAPP_TEXT
  104. oRootNode.AppCreate2 IISAO_APPROT_POOL
  105. if iNodeType <> SITE then
  106. bIsApp = True
  107. end if
  108. end if
  109. end if
  110. If COMPLETE then
  111. 'Set access permissions.
  112. 'This will always set the bits, and never allow inheritence on these properties.
  113. 'The more sensible solution seems to be that if ANY of them are set, then
  114. 'we set all to True/False based on their selections. Otherwise, we don't set the
  115. 'properties.
  116. oRootNode.AccessRead=Request("AllowRead") = "on"
  117. oRootNode.AccessWrite=Request("AllowWrite") = "on"
  118. if iSiteType = WEB then
  119. oRootNode.EnableDirBrowsing=Request("AllowDirBrowsing") = "on"
  120. oRootNode.AccessScript=Request("AllowScript") = "on"
  121. oRootNode.AccessExecute=Request("AllowExecute") = "on"
  122. end if
  123. End If
  124. 'Commit the changes...
  125. oRootNode.SetInfo
  126. oNewNode.SetInfo
  127. 'Determine if we add the IISADMIN vdir for remote administration, and add it as appropriate.
  128. if iSiteType = WEB and iNodeType = SITE and Request("AllowRemote")= "on" then
  129. 'Create the remoteable vdir
  130. Set oAdminSite=GetObject("IIS://localhost/w3svc/" & Request.ServerVariables("INSTANCE_ID") & "/Root/IISADMIN")
  131. Set oAdminRoot=oRootNode.Create("IIsWebVirtualDir","IISADMIN")
  132. oAdminRoot.Path=oAdminSite.Path
  133. oAdminRoot.SetInfo
  134. oAdminRoot.AuthNTLM=True
  135. oAdminRoot.AuthAnonymous=False
  136. oAdminRoot.AccessRead=True
  137. oAdminRoot.AccessScript=True
  138. oAdminRoot.SetInfo
  139. end if
  140. if err = 0 then
  141. 'Add to client-cached List...
  142. 'To do this, we call a script in a far away frame...
  143. %>
  144. <SCRIPT LANGAUGE="JavaScript">
  145. // Work around for IE3 Instead of doing our work here, we will
  146. // call iiaddnew.asp and do the work in the context of the main
  147. // window.
  148. qstr = "sel=" + "<%=iParentID%>" +
  149. "&nodeId=" + "<%= sNodeId%>" +
  150. "&nodeName=" + escape("<%= sNodeName %>") +
  151. "&nodeType=" + "<%=NODETYPES(iNodeType) %>" +
  152. "&siteType=" + "<%= CACHE_SITETYPES(iSiteType) %>" +
  153. "&isApp=" + "<%= CInt(bIsApp) %>";
  154. top.opener.top.connect.location.href = "iiaddnew.asp?" + qstr;
  155. top.window.close();
  156. </SCRIPT>
  157. <%
  158. else
  159. 'Otherwise, put up a failure message on the completion page.
  160. sHandleErrors(err)
  161. end if
  162. End Function
  163. 'Returns the next available instance number
  164. Function sGetNextInstanceName(iSiteType)
  165. On Error Resume Next
  166. Dim oService,oInst, sInstName
  167. Set oService=GetObject(BASEPATH & SERVICES(iSiteType))
  168. For Each oInst In oService
  169. if isNumeric(oInst.name) then
  170. if cint(oInst.name) > sInstName then
  171. sInstName=cint(oInst.name)
  172. end if
  173. end if
  174. Next
  175. sGetNextInstanceName=cInt(sInstName)+1
  176. End Function
  177. 'Return an appropriately formated keytype
  178. Function sGetKeyType(iSiteType, iNodeType)
  179. On Error Resume Next
  180. Dim sSvcKey
  181. Select Case SERVICES(iSiteType)
  182. Case W3SVC
  183. sSvcKey = SWEB
  184. Case FTPSVC
  185. sSvcKey = SFTP
  186. End Select
  187. Select Case iNodeType
  188. Case SITE
  189. sGetKeyType=IIS & sSvcKey & SSITE
  190. Case VDIR
  191. sGetKeyType=IIS & sSvcKey & SVDIR
  192. Case DIR
  193. sGetKeyType=IIS & sSvcKey & SDIR
  194. End Select
  195. End Function
  196. 'Parse the path to return the appropriate site type (web, ftp, computer) from a path
  197. Function iGetSiteType(sParentPath,sParentKeyType)
  198. dim sSiteType
  199. if InStr(sParentKeyType, COMP) then
  200. sSiteType = Request("SiteType")
  201. if sSiteType = "" then
  202. sSiteType = "0"
  203. end if
  204. iGetSiteType = cInt(sSiteType)
  205. else
  206. 'Response.write sParentKeyType
  207. if InStr(sParentPath,W3SVC) then
  208. iGetSiteType = WEB
  209. elseif InStr(sParentPath,FTPSVC) then
  210. iGetSiteType = FTP
  211. end if
  212. end if
  213. End Function
  214. 'Get the physical path for a directory, based on the parent path
  215. Function sGetPhysPath(oParentNode, sDirName)
  216. Dim sParentType, sNewPath, sBasePath
  217. 'The physical directory may not currently
  218. 'exist in the metabase, so we have
  219. 'to find the parent vdir associated with
  220. 'the dir and build the path from there.
  221. sParentType = oParentNode.KeyType
  222. sNewPath = sDirName
  223. sBasePath = oParentNode.ADsPath
  224. Do Until Instr(sParentType, SVDIR) <> 0
  225. 'we need clear our path not found error..
  226. err = 0
  227. 'add our initial whack...
  228. sNewPath = "/" + sNewPath
  229. 'and cyle through the baseobj till we find the next whack,
  230. 'building up the path in new name as we go
  231. Do Until Right(sBasePath,1) = "/"
  232. sNewPath = Right(sBasePath,1) & sNewPath
  233. sBasePath = Mid(sBasePath,1,Len(sBasePath)-1)
  234. Loop
  235. 'once we're out, we need to lop off the last whack...
  236. sBasePath = Mid(sBasePath,1,Len(sBasePath)-1)
  237. 'and try to set the object again...
  238. Set oParentNode=GetObject(sBasePath)
  239. if err <> 0 then
  240. sParentType = ""
  241. else
  242. sParentType=oParentNode.KeyType
  243. end if
  244. Loop
  245. sGetPhysPath = oParentNode.Path & "\" & sNewPath
  246. err.clear
  247. End Function
  248. 'this is a goofy function to fix the session type we get passed in.
  249. 'these have gotten really out of hand. Should go through entire
  250. 'system and fix this, so that if we are referincing the site type
  251. 'it is ALWAYS W3SVC or MSFTPSVC... not sometimes web, sometimes www
  252. 'and sometimes w3svc... ick. sorry.
  253. Function fixSiteType(sessionSite)
  254. sessionSite = LCase(sessionSite)
  255. if sessionSite = "ftp" then
  256. fixSiteType = 1
  257. end if
  258. if sessionSite = "www" then
  259. fixSiteType = 0
  260. end if
  261. End Function
  262. %>