예제 #1
0
        public static int DeleteWebSite(int siteItemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // load web site item
            WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteItemId);
            if (siteItem == null)
                return BusinessErrorCodes.ERROR_WEB_SITE_PACKAGE_ITEM_NOT_FOUND;

            // place log record
            TaskManager.StartTask("WEB_SITE", "DELETE", siteItem.Name);
            TaskManager.ItemId = siteItemId;

            // delete web site
            try
            {
				// remove all web site pointers
				List<DomainInfo> pointers = GetWebSitePointers(siteItemId);
				foreach (DomainInfo pointer in pointers)
					DeleteWebSitePointer(siteItemId, pointer.DomainId, false);

				// remove web site main pointer
				DomainInfo domain = ServerController.GetDomain(siteItem.Name);
				if(domain != null)
					DeleteWebSitePointer(siteItemId, domain.DomainId, false);

				// delete web site
                WebServer web = new WebServer();
                ServiceProviderProxy.Init(web, siteItem.ServiceId);

				#region Fix for bug #710
				//
				if (web.IsFrontPageSystemInstalled() && web.IsFrontPageInstalled(siteItem.SiteId))
				{
					web.UninstallFrontPage(siteItem.SiteId, siteItem.FrontPageAccount);
				} 
				#endregion

				//
                web.DeleteSite(siteItem.SiteId);

                // delete service item
                PackageController.DeletePackageItem(siteItemId);

                return 0;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static int DeleteWebSite(int siteItemId, bool deleteWebsiteDirectory)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // load web site item
            WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteItemId);
            if (siteItem == null)
                return BusinessErrorCodes.ERROR_WEB_SITE_PACKAGE_ITEM_NOT_FOUND;

            // place log record
            TaskManager.StartTask("WEB_SITE", "DELETE", siteItem.Name, siteItemId);

            // delete web site
            try
            {
				//cleanup certificates
                //cleanup certificates
                List<SSLCertificate> certificates = GetCertificatesForSite(siteItemId);
                foreach (SSLCertificate c in certificates)
                {
                    DeleteCertificate(siteItemId, c);
                }
                
                // remove all web site pointers
				List<DomainInfo> pointers = GetWebSitePointers(siteItemId);
				foreach (DomainInfo pointer in pointers)
					DeleteWebSitePointer(siteItemId, pointer.DomainId, false, true, true);

				// remove web site main pointer
				DomainInfo domain = ServerController.GetDomain(siteItem.Name);
				if(domain != null)
					DeleteWebSitePointer(siteItemId, domain.DomainId, false, true, true);

                List<WebSite> sites = WebServerController.GetWebSites(domain.PackageId, false);
                bool oneSiteOnly = (sites.Count == 1);

                if (oneSiteOnly)
                {
                    // load site item
                    IPAddressInfo ip = ServerController.GetIPAddress(sites[0].SiteIPAddressId);

                    string serviceIp = (ip != null) ? ip.ExternalIP : null;

                    if (string.IsNullOrEmpty(serviceIp))
                    {
                        StringDictionary settings = ServerController.GetServiceSettings(sites[0].ServiceId);
                        if (settings["PublicSharedIP"] != null)
                            serviceIp = settings["PublicSharedIP"].ToString();
                    }

                    ServerController.RemoveServiceDNSRecords(domain.PackageId, ResourceGroups.Web, domain, serviceIp, true);
                }




				// delete web site
                WebServer web = new WebServer();
                ServiceProviderProxy.Init(web, siteItem.ServiceId);

				//
				if (web.IsFrontPageSystemInstalled() && web.IsFrontPageInstalled(siteItem.SiteId))
				{
					web.UninstallFrontPage(siteItem.SiteId, siteItem.FrontPageAccount);
				} 

				//
                web.DeleteSite(siteItem.SiteId);

                // Delete WebManagementAccess Account
                WebServerController.RevokeWebManagementAccess(siteItemId);

                if (deleteWebsiteDirectory)
                {
                    // Delete website directory from file server
                    // This will remove the hard quota as well
                    FilesController.DeleteDirectoryRecursive(siteItem.PackageId, new DirectoryInfo(siteItem.DataPath).Parent.FullName);

                }
                // delete service item
                PackageController.DeletePackageItem(siteItemId);

                return 0;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }