コード例 #1
0
        public int DeletePackage(int packageId)
        {
            List <string> usersList   = new List <string>();
            List <string> domainsList = new List <string>();

            PackageInfo package = PackageController.GetPackage(packageId);

            // get package service items
            List <ServiceProviderItem> items = PackageController.GetServiceItemsForStatistics(
                0, package.PackageId, false, false, false, true); // disposable items

            // order items by service
            Dictionary <int, List <ServiceProviderItem> > orderedItems =
                PackageController.OrderServiceItemsByServices(items);

            int  maxItems          = 100000000;
            bool mailFilterEnabled = false;

            // delete service items by service sets
            foreach (int serviceId in orderedItems.Keys)
            {
                ServiceInfo service = ServerController.GetServiceInfo(serviceId);
                //Delete Exchange Organization
                if (service.ProviderId == 103 /*Organizations*/)
                {
                    int itemid = orderedItems[serviceId][0].Id;
                    OrganizationUsersPaged users    = OrganizationController.GetOrganizationUsersPaged(itemid, null, null, null, 0, maxItems);
                    StringDictionary       settings = ServerController.GetServiceSettings(serviceId);
                    if (settings != null && Convert.ToBoolean(settings["EnableMailFilter"]))
                    {
                        mailFilterEnabled = true;
                        foreach (OrganizationUser user in users.PageUsers)
                        {
                            SpamExpertsController.DeleteEmailFilter(packageId, user.PrimaryEmailAddress);
                        }
                    }
                }
            }
            if (mailFilterEnabled)
            {
                List <DomainInfo> domains = ServerController.GetDomains(packageId);
                foreach (DomainInfo domain in domains)
                {
                    SpamExpertsController.DeleteDomainFilter(domain);
                }
            }

            //Get VPS Package IPs
            PackageIPAddress[] ips = ServerController.GetPackageIPAddresses(packageId, 0,
                                                                            IPAddressPool.VpsExternalNetwork, "", "", "", 0, maxItems, true).Items;
            List <int> ipsIdList = new List <int>();

            foreach (PackageIPAddress ip in ips)
            {
                ipsIdList.Add(ip.AddressID);
            }

            //Delete Package
            int res = PackageController.DeletePackage(packageId);

            if (res >= 0)
            {
                // users
                //foreach (string user in usersList)
                //SEPlugin.SE.DeleteEmail(user);

                //domain
                //foreach (string domain in domainsList)
                //SEPlugin.SE.DeleteDomain(domain);

                //return IPs back to ParentPackage
                if (package.ParentPackageId != 1) // 1 is System (serveradmin), we don't want assign IP to the serveradmin.
                {
                    ServerController.AllocatePackageIPAddresses(package.ParentPackageId, ipsIdList.ToArray());
                }
            }

            return(res);
        }
コード例 #2
0
 public int UpdateService(ServiceInfo service)
 {
     return(ServerController.UpdateService(service));
 }
コード例 #3
0
        public override void DoWork()
        {
            // Input parameters:
            //  - FILE_PATH
            //  - FTP_SERVER
            //  - FTP_USERNAME
            //  - FTP_PASSWORD
            //  - FTP_FOLDER

            BackgroundTask topTask = TaskManager.TopTask;

            // get input parameters
            string filePath    = (string)topTask.GetParamValue("FILE_PATH");
            string ftpServer   = (string)topTask.GetParamValue("FTP_SERVER");
            string ftpUsername = (string)topTask.GetParamValue("FTP_USERNAME");
            string ftpPassword = (string)topTask.GetParamValue("FTP_PASSWORD");
            string ftpFolder   = (string)topTask.GetParamValue("FTP_FOLDER");

            // check input parameters
            if (String.IsNullOrEmpty(filePath))
            {
                TaskManager.WriteWarning("Specify 'File' task parameter");
                return;
            }

            if (String.IsNullOrEmpty(ftpServer))
            {
                TaskManager.WriteWarning("Specify 'FTP Server' task parameter");
                return;
            }

            // substitute parameters
            DateTime d    = DateTime.Now;
            string   date = d.ToString("yyyyMMdd");
            string   time = d.ToString("HHmm");

            filePath = Utils.ReplaceStringVariable(filePath, "date", date);
            filePath = Utils.ReplaceStringVariable(filePath, "time", time);

            // build FTP command file
            StringBuilder sb     = new StringBuilder();
            StringWriter  writer = new StringWriter(sb);

            // FTP server
            writer.WriteLine("open " + ftpServer);

            // check if anonymous mode
            if (String.IsNullOrEmpty(ftpUsername))
            {
                ftpUsername = "******";
                ftpPassword = "******";
            }

            // FTP username/password
            writer.WriteLine(ftpUsername);
            writer.WriteLine(ftpPassword);

            // check if we need to change remote folder
            if (!String.IsNullOrEmpty(ftpFolder))
            {
                writer.WriteLine("cd " + ftpFolder.Replace("\\", "/"));
            }

            // file to send
            writer.WriteLine("binary");
            writer.WriteLine("put " + FilesController.GetFullPackagePath(topTask.PackageId, filePath));

            // bye
            writer.WriteLine("bye");

            string cmdBatch = sb.ToString();

            // create temp file in user space
            string cmdPath     = Utils.GetRandomString(10) + ".txt";
            string fullCmdPath = FilesController.GetFullPackagePath(topTask.PackageId, cmdPath);

            // upload batch
            FilesController.UpdateFileBinaryContent(topTask.PackageId, cmdPath, Encoding.UTF8.GetBytes(cmdBatch));

            // execute system command
            // load OS service
            int serviceId = PackageController.GetPackageServiceId(topTask.PackageId, ResourceGroups.Os);

            // load service
            ServiceInfo service = ServerController.GetServiceInfo(serviceId);

            if (service == null)
            {
                return;
            }

            WindowsServer winServer = new WindowsServer();

            ServiceProviderProxy.ServerInit(winServer, service.ServerId);
            TaskManager.Write(winServer.ExecuteSystemCommand("ftp.exe", "-s:" + fullCmdPath));

            // delete batch file
            FilesController.DeleteFiles(topTask.PackageId, new string[] { cmdPath });
        }
コード例 #4
0
 public int AddService(ServiceInfo service)
 {
     return(ServerController.AddService(service));
 }
コード例 #5
0
        public static int AddSite(SharePointSite item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // check quota
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.SHAREPOINT_SITES);

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_QUOTA_LIMIT);
            }

            // check if stats resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.SharePoint);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE);
            }

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SharePointSite)) != null)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_EXISTS);
            }

            // place log record
            TaskManager.StartTask("SHAREPOINT", "ADD_SITE", item.Name);
            TaskManager.WriteParameter("Database group", item.DatabaseGroupName);
            TaskManager.WriteParameter("Database name", item.DatabaseName);
            TaskManager.WriteParameter("Database user", item.DatabaseUser);

            int databaseItemId     = 0;
            int databaseUserItemId = 0;

            try
            {
                // load web site
                WebSite siteItem = (WebSite)PackageController.GetPackageItemByName(item.PackageId,
                                                                                   item.Name, typeof(WebSite));

                if (siteItem == null)
                {
                    return(BusinessErrorCodes.ERROR_WEB_SITE_SERVICE_UNAVAILABLE);
                }

                // get service web site
                WebServer web = new WebServer();
                ServiceProviderProxy.Init(web, siteItem.ServiceId);
                WebSite site = web.GetSite(siteItem.SiteId);

                /////////////////////////////////////////
                //
                //  PREPARE SHAREPOINT SITE INSTALLATION
                //

                ServiceInfo wssService = ServerController.GetServiceInfo(serviceId);
                bool        wss30      = (wssService.ProviderId == 23);     // WSS 3.0

                // remember original web site bindings
                ServerBinding[] bindings = site.Bindings;

                // set application pool and root folder
                item.ApplicationPool = site.ApplicationPool;
                item.RootFolder      = site.ContentPath;

                // change web site .NET framework if required
                bool siteUpdated = false;
                if (!wss30 && (site.AspNetInstalled != "1" ||
                               site.DedicatedApplicationPool))
                {
                    site.AspNetInstalled          = "1";
                    site.DedicatedApplicationPool = false;
                    web.UpdateSite(site);

                    siteUpdated = true;
                }

                if (wss30 && site.AspNetInstalled != "2")
                {
                    site.AspNetInstalled = "2";
                    web.UpdateSite(site);

                    siteUpdated = true;
                }

                if (siteUpdated)
                {
                    site = web.GetSite(siteItem.SiteId);
                    item.ApplicationPool = site.ApplicationPool;
                }

                if (site.FrontPageInstalled)
                {
                    // remove FrontPage
                    web.UninstallFrontPage(siteItem.SiteId, siteItem.FrontPageAccount);
                }

                // create SQL database
                SqlDatabase database = new SqlDatabase();
                database.PackageId = item.PackageId;
                database.Name      = item.DatabaseName;
                databaseItemId     = DatabaseServerController.AddSqlDatabase(database, item.DatabaseGroupName);
                if (databaseItemId < 0)
                {
                    return(databaseItemId);
                }

                // create SQL user
                SqlUser dbUser = new SqlUser();
                dbUser.PackageId   = item.PackageId;
                dbUser.Name        = item.DatabaseUser;
                dbUser.Password    = item.DatabasePassword;
                databaseUserItemId = DatabaseServerController.AddSqlUser(dbUser, item.DatabaseGroupName);
                if (databaseUserItemId < 0)
                {
                    return(databaseUserItemId);
                }

                // delete SQL database from service
                // and change database user role
                int sqlServiceId = PackageController.GetPackageServiceId(item.PackageId, item.DatabaseGroupName);
                if (sqlServiceId < 0)
                {
                    return(BusinessErrorCodes.ERROR_MSSQL_RESOURCE_UNAVAILABLE);
                }

                // load server settings
                StringDictionary sqlSettings = ServerController.GetServiceSettings(sqlServiceId);
                item.DatabaseServer = sqlSettings["ExternalAddress"];

                DatabaseServer dbServer = new DatabaseServer();
                ServiceProviderProxy.Init(dbServer, sqlServiceId);

                // delete database from service
                dbServer.DeleteDatabase(database.Name);

                // give SQL user "db_creator" role
                dbServer.ExecuteSqlNonQuery("master", String.Format(
                                                "sp_addsrvrolemember '{0}', 'dbcreator'\nGO", dbUser.Name));

                // install SharePoint site
                SharePointServer sps = GetSharePoint(serviceId);
                sps.ExtendVirtualServer(item);

                // remove SQL user from "db_creator" role
                dbServer.ExecuteSqlNonQuery("master", String.Format(
                                                "sp_dropsrvrolemember '{0}', 'dbcreator'\nGO", dbUser.Name));

                // restore original web site bindings
                web.UpdateSiteBindings(site.SiteId, bindings, false);

                // save statistics item
                item.ServiceId = serviceId;
                int itemId = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;

                return(itemId);
            }
            catch (Exception ex)
            {
                // delete database if required
                if (databaseItemId > 0)
                {
                    DatabaseServerController.DeleteSqlDatabase(databaseItemId);
                }

                // delete user if required
                if (databaseUserItemId > 0)
                {
                    DatabaseServerController.DeleteSqlUser(databaseUserItemId);
                }

                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }