Leaked source code of windows server 2003
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.

405 lines
13 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. 'Response.Buffer = True
  5. '-------------------------------------------------------------------------
  6. ' site_delete.asp: site delete page - deletes the selected site
  7. '
  8. ' Copyright (c) Microsoft Corporation. All rights reserved.
  9. '
  10. ' Date Description
  11. '03-Oct-00 Creation date
  12. '25-Jan-01 Modified for new framework
  13. '-------------------------------------------------------------------------
  14. %>
  15. <!-- #include virtual="/admin/inc_framework.asp"--->
  16. <!-- #include file="resources.asp" -->
  17. <!-- #include file="inc_wsa.asp" -->
  18. <%
  19. '-----------------------------------------------------------------------------------
  20. ' Global Variables
  21. '-----------------------------------------------------------------------------------
  22. Dim G_strSiteID 'To save site name
  23. Dim G_strDirRoot 'To hold Dir root
  24. Dim G_strSysName 'To hold system name globally
  25. Dim G_strDir 'To hold Dir globally
  26. Dim F_strSiteID 'To hold site identifier
  27. Dim rc 'To hold return code
  28. Dim page 'To hold page object
  29. 'Create property page
  30. rc=SA_CreatePage(L_TASKTITLE,"",PT_PROPERTY,page)
  31. 'Serve the page
  32. If(rc=0) then
  33. SA_ShowPage(Page)
  34. End if
  35. '--------------------------------------------------------------------------
  36. ' Function name: OnInitPage
  37. ' Description: Called to signal first time processing for this page.
  38. ' Input Variables: PageIn and EventArg
  39. ' Output Variables: None
  40. ' Return Values: TRUE to indicate initialization was successful. FALSE to indicate
  41. ' errors. Returning FALSE will cause the page to be abandoned.
  42. ' Global Variables: None
  43. ' Called to signal first time processing for this page.
  44. '--------------------------------------------------------------------------
  45. Public Function OnInitPage(ByRef PageIn,ByRef EventArg)
  46. SetVariablesFromSystem()
  47. OnInitPage = True
  48. End Function
  49. '-------------------------------------------------------------------------
  50. 'Function: OnServePropertyPage()
  51. ' Description: Called when the page needs to be served.
  52. ' Input Variables: PageIn, EventArg
  53. ' Output Variables: None
  54. ' Return Values: TRUE to indicate no problems occured. FALSE to indicate errors.
  55. ' Returning FALSE will cause the page to be abandoned.
  56. ' Global Variables: None
  57. 'Called when the page needs to be served. Use this method to serve content.
  58. '---------------------------------------------------------------------
  59. Public Function OnServePropertyPage(ByRef PageIn,Byref EventArg)
  60. Call ServeCommonJavaScript()
  61. Call ServePage()
  62. OnServePropertyPage = True
  63. End Function
  64. '-------------------------------------------------------------------------
  65. 'Function: OnPostBackPage()
  66. 'Description: Called to signal that the page has been posted-back.
  67. 'Input Variables: PageIn,EventArg
  68. 'Output Variables: None
  69. 'Returns: True/False
  70. 'Global Variables: None
  71. '-------------------------------------------------------------------------
  72. Public Function OnPostBackPage(ByRef PageIn ,ByRef EventArg)
  73. OnPostBackPage = True
  74. End Function
  75. '-------------------------------------------------------------------------
  76. 'Function: OnSubmitPage()
  77. 'Description: Called when the page has been submitted for processing.
  78. ' Use this method to process the submit request.
  79. 'Input Variables: PageIn,EventArg
  80. 'Output Variables: None
  81. 'Returns: True/False
  82. 'Global Variables: None
  83. '-------------------------------------------------------------------------
  84. Public Function OnSubmitPage(ByRef PageIn ,ByRef EventArg)
  85. OnSubmitPage = ServeVariablesFromForm()
  86. End Function
  87. '-------------------------------------------------------------------------
  88. 'Function: OnClosePage()
  89. 'Description: Called when the page is about closed.Use this method
  90. ' to perform clean-up processing
  91. 'Input Variables: PageIn,EventArg
  92. 'Output Variables: None
  93. 'Returns: True/False
  94. 'Global Variables: None
  95. '-------------------------------------------------------------------------
  96. Public Function OnClosePage(ByRef PageIn ,ByRef EventArg)
  97. OnClosePage = TRUE
  98. End Function
  99. '-------------------------------------------------------------------------
  100. 'Function: ServeCommonJavaScript
  101. 'Description: Serves in initialiging the values,setting the form
  102. ' data and validating the form values
  103. 'Input Variables: None
  104. 'Output Variables: None
  105. 'Returns: True/False
  106. 'Global Variables: None
  107. '-------------------------------------------------------------------------
  108. Function ServeCommonJavaScript()
  109. %>
  110. <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js"></script>
  111. <script language="JavaScript">
  112. //Init Function
  113. function Init()
  114. {
  115. //do initialization
  116. return true;
  117. }
  118. // validates user entry
  119. function ValidatePage()
  120. {
  121. return true;
  122. }
  123. //Sets data into the form variable
  124. function SetData()
  125. {
  126. return true;
  127. }
  128. </script>
  129. <% End Function
  130. '-------------------------------------------------------------------------
  131. 'Function: ServePage()
  132. 'Description: For displaying outputs HTML to the user
  133. 'Input Variables: None
  134. 'Output Variables: None
  135. 'Returns: None
  136. 'Global Variables: None
  137. '-------------------------------------------------------------------------
  138. Function ServePage
  139. %>
  140. <TABLE WIDTH=618 VALIGN=middle ALIGN=left BORDER=0 CELLSPACING=0 CELLPADDING=2 class="TasksBody">
  141. <tr>
  142. <td class=TasksBody>
  143. <%=Server.HTMLEncode(GetLocString("sitearea.dll","40420012",Array(F_strSiteID)))%>
  144. </td>
  145. </tr>
  146. <tr>
  147. <td class=TasksBody colspan=2>
  148. &nbsp
  149. </td>
  150. </tr>
  151. <tr>
  152. <td class=TasksBody>
  153. <%=Server.HTMLEncode(L_NOTE)%>
  154. </td>
  155. </tr>
  156. </TABLE>
  157. <input type=hidden name="hdnSiteName" value="<%=Server.HTMLEncode(F_strSiteID)%>">
  158. <input type=hidden name="hdnSiteId" value="<%=Server.HTMLEncode(G_strSiteID)%>">
  159. <%
  160. End Function
  161. '-------------------------------------------------------------------------
  162. 'Function name: ServeVariablesFromForm()
  163. 'Description: Serves in getting the data from Client
  164. 'Input Variables: None
  165. 'Output Variables: None
  166. 'Returns: True/False
  167. 'Global Variables: None
  168. '-------------------------------------------------------------------------
  169. Function ServeVariablesFromForm()
  170. 'delete the site
  171. F_strSiteID = Request.Form("hdnSiteName")
  172. G_strSiteID = Request.Form("hdnSiteId")
  173. If blnDeleteSite()then
  174. ServeVariablesFromForm = true
  175. else
  176. ServeVariablesFromForm = false
  177. end if
  178. End Function
  179. '-------------------------------------------------------------------------
  180. 'Procedure name: SetVariablesFromSystem
  181. 'Description: Serves in Getting the data from System
  182. 'Input Variables: None
  183. 'Output Variables: None
  184. 'Returns: None
  185. 'Global Variables:
  186. ' Out:G_strSiteID - site identifier
  187. ' Out:G_strSiteID -site identifier
  188. '-------------------------------------------------------------------------
  189. Sub SetVariablesFromSystem()
  190. 'Initial values of the form data
  191. G_strSiteID = Request.QueryString("PKey")
  192. F_strSiteID = GetWebSiteName(G_strSiteID)
  193. End Sub
  194. '-------------------------------------------------------------------------
  195. 'Procedure name: InitObjects
  196. 'Description: Initialization of global variables is done
  197. 'Input Variables: None
  198. 'Output Variables: None
  199. 'Returns: None
  200. 'Global Variables: G_strDirRoot, G_strSysName
  201. '--------------------------------------------------------------------------
  202. Sub InitObjects()
  203. Err.Clear
  204. on error resume next
  205. Call GetDomainRole( G_strDirRoot, G_strSysName )
  206. End Sub
  207. '----------------------------------------------------------------------------
  208. 'Function name :blnDeleteSite
  209. 'Description :Deletes the site from the IIS
  210. 'Input Variables :None
  211. 'Output Variables :None
  212. 'Returns :Boolean (True if the site is deleted else returns False)
  213. 'Global Variables :G_strSiteID
  214. '----------------------------------------------------------------------------
  215. Function blnDeleteSite()
  216. On Error Resume Next
  217. Err.Clear
  218. Dim objSite ' To hold sites object
  219. Dim objService ' To hold WMI connection object
  220. Dim blnUsers ' To hold users object
  221. Dim strObjPath ' To hold object path as string
  222. Dim strDomain
  223. Dim strUser
  224. Dim arrID
  225. Dim strAdminName
  226. Set objService = getWMIConnection(CONST_WMI_IIS_NAMESPACE)
  227. Call GetWebAdministrtorRole(objService, G_strSiteID, strAdminName)
  228. arrID = split(strAdminName,"\")
  229. strDomain = arrID(0)
  230. strUser = arrID(1)
  231. '
  232. ' Delete FrontPage extensions
  233. Call UpdateFrontPage("false", G_strSiteID, strUser)
  234. 'get the web site dir
  235. strObjPath = GetIISWMIProviderClassName("IIs_WebVirtualDirSetting") & ".Name=" & chr(34) & G_strSiteID & "/Root" & chr(34)
  236. Set objSite = objService.Get(strObjPath)
  237. G_strDir = objSite.Path
  238. '1) Delete web site
  239. strObjPath = GetIISWMIProviderClassName("IIs_WebServer") & ".Name=" & chr(34) & G_strSiteID & chr(34)
  240. Set objSite = objService.Get(strObjPath)
  241. if Err.number = 424 or Err.number <> 0 then
  242. ' if object not found
  243. SetErrMsg L_OBJECTNOTFOUND_ERRORMESSAGE
  244. exit function
  245. elseif Err.number = 0 then
  246. objSite.delete_
  247. end if
  248. '2) delete users
  249. Call blnDeleteUsers(strDomain,strUser)
  250. '3) delete virtual FTP site
  251. If IsUserVirFTPInstalled(objService, strUser) Then
  252. Call DeleteVirFTPSite(objService, strUser)
  253. End If
  254. 'release objects
  255. set objService = nothing
  256. set objSite = nothing
  257. blnDeleteSite = TRUE
  258. End function
  259. '----------------------------------------------------------------------------
  260. 'Function name :blnDeleteUsers
  261. 'Description :Deletes the anon and admin user from the system associated
  262. ' with the site
  263. 'Input Variables :None
  264. 'Output Variables :None
  265. 'Returns :Boolean (True if users are deleted else returns False)
  266. 'Global Variables :G_strDir, F_strSiteID, G_strDirRoot
  267. '----------------------------------------------------------------------------
  268. Function blnDeleteUsers(strDomain, strUser)
  269. Err.Clear
  270. on error resume next
  271. Dim strAnonName ' To hold Anon name
  272. Dim nretval ' To hold Return value
  273. Dim objComputer ' To hold computer object
  274. Dim strSiteID ' To site id as string
  275. Dim oRoot ' To hold root object
  276. Dim oOUWebSites ' To hold websites OU object
  277. Dim oOUSiteID ' To hold site OU object
  278. Dim ouObject ' To hold OU object
  279. Dim QuotaState
  280. '1)Initialize the objects
  281. InitObjects()
  282. '2) Delete the folder
  283. if not blnDeleteFolder(G_strDir) then
  284. SetErrMsg L_UNABLETO_DELETEFOLDER_ERRORMESSAGE
  285. end if
  286. '3) delete the user
  287. If (UCase(strDomain) = UCase(G_strSysName)) Then
  288. ' Delete users in SAM database
  289. Set objComputer = GetObject("WinNT://" & strDomain)
  290. If Err.number <> 0 Then
  291. blnDeleteUsers = FALSE
  292. exit Function
  293. End if
  294. 'get the site-identifier(NUMBER) from the format W3SVC/NUMBER
  295. strSiteID = F_strSiteID
  296. strAnonName = strSiteID & "_Anon"
  297. 'deletes the anonuser from the System
  298. nretval = objComputer.Delete("user" , strAnonName)
  299. If Err.Number <> 0 Then
  300. Err.Clear
  301. 'this case may be that the user is existed user
  302. blnDeleteUsers = TRUE
  303. exit Function
  304. End If
  305. If InStr(strUser,"_Admin") <> 0 Then
  306. 'deletes the adminuser from the System
  307. nretval = objComputer.Delete("user" , strUser)
  308. If Err.Number <> 0 Then
  309. Err.Clear
  310. End If
  311. End If
  312. 'Release the object
  313. set objComputer = nothing
  314. End If
  315. blnDeleteUsers = TRUE
  316. SA_TraceOut "site_delete", "Delete users, workgroup succeed"
  317. end function
  318. '----------------------------------------------------------------------------
  319. 'Function name :blnDeleteFolder
  320. 'Description :Delete Directory after deleting users
  321. 'Input Variables :Directory path
  322. 'Output Variables :None
  323. 'Returns :Boolean
  324. 'Global Variables :None
  325. '----------------------------------------------------------------------------
  326. Function blnDeleteFolder(strDir)
  327. Dim objFso ' To hold File system object
  328. blnDeleteFolder = false
  329. Set objFso = server.CreateObject("Scripting.FileSystemObject")
  330. if Err.number <> 0 then
  331. SA_TraceOut "site_delete", "Getting the file system object failed."
  332. SetErrMsg L_UNABLETO_DELETEFOLDER_ERRORMESSAGE
  333. exit function
  334. end if
  335. objFso.DeleteFolder(strDir)
  336. if Err.number <> 0 then
  337. SetErrMsg L_UNABLETO_DELETEFOLDER_ERRORMESSAGE
  338. exit function
  339. end if
  340. SA_TraceOut "site_delete", "Deleting folders succeeded."
  341. blnDeleteFolder = true
  342. 'Release the Object
  343. set objFso = nothing
  344. end function
  345. %>