Exemplo n.º 1
0
        public static PackageResult UpdatePackage(PackageInfo package)
        {
            TaskManager.StartTask("HOSTING_SPACE", "UPDATE", package.PackageName);

            PackageResult result = new PackageResult();

            try
            {
                // check account
                result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                    | DemandAccount.IsReseller);
                if (result.Result < 0) return result;

                // load package
                PackageInfo originalPackage = GetPackage(package.PackageId);
                if (originalPackage == null)
                {
                    result.Result = BusinessErrorCodes.ERROR_PACKAGE_NOT_FOUND;
                    return result;
                }

                string quotasXml = BuildPlanQuotasXml(package.Groups, package.Quotas);

                // update package
                result.ExceedingQuotas = DataProvider.UpdatePackage(SecurityContext.User.UserId,
                    package.PackageId, package.PlanId, package.PackageName, package.PackageComments, package.StatusId,
                    package.PurchaseDate, package.OverrideQuotas, quotasXml);

                if (result.ExceedingQuotas.Tables[0].Rows.Count > 0)
                    result.Result = BusinessErrorCodes.ERROR_PACKAGE_QUOTA_EXCEED;
            }
            finally
            {
                TaskManager.CompleteTask();
            }

            return result;
        }
Exemplo n.º 2
0
        public static PackageResult UpdatePackageAddon(PackageAddonInfo addon)
        {
            PackageResult result = new PackageResult();

            // check account
            result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                | DemandAccount.IsReseller);
            if (result.Result < 0) return result;

            result.ExceedingQuotas = DataProvider.UpdatePackageAddon(SecurityContext.User.UserId, addon.PackageAddonId,
                addon.PlanId, addon.Quantity, addon.StatusId, addon.PurchaseDate, addon.Comments);

            if (result.ExceedingQuotas.Tables[0].Rows.Count > 0)
                result.Result = BusinessErrorCodes.ERROR_PACKAGE_QUOTA_EXCEED;

            return result;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds hosting package(space) to the user.
        /// </summary>
        /// <remarks>Modified as a fix for #1084 item.</remarks>
        /// <param name="userId">User id</param>
        /// <param name="planId">Hosting plan id</param>
        /// <param name="packageName">Hosting package(space) name</param>
        /// <param name="packageComments">Hosting package(space) comments</param>
        /// <param name="statusId">Hosting package(space) initial status</param>
        /// <param name="purchaseDate">Date purchased</param>
        /// <param name="sendLetter">Inidicates whether to send e-mail notification or not</param>
        /// <param name="signup">Used for external clients to set #Signup# variable in e-mail notification template</param>
        /// <returns>Hosting package(space) creation result</returns>
        public static PackageResult AddPackage(int userId, int planId, string packageName,
            string packageComments, int statusId, DateTime purchaseDate, bool sendLetter, bool signup)
        {
            TaskManager.StartTask("HOSTING_SPACE", "ADD", packageName);

            PackageResult result = new PackageResult();

            try
            {
                // check account
                result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                    | DemandAccount.IsReseller);
                if (result.Result < 0) return result;

                int packageId = -1;

                result.ExceedingQuotas = DataProvider.AddPackage(SecurityContext.User.UserId, out packageId,
                    userId, planId, packageName, packageComments, statusId, purchaseDate);

                if (result.ExceedingQuotas.Tables[0].Rows.Count > 0)
                {
                    result.Result = BusinessErrorCodes.ERROR_PACKAGE_QUOTA_EXCEED;
                    return result;
                }

                result.Result = packageId;

                // allocate "Web Sites" IP addresses
                int webServiceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.Web);
                StringDictionary webSettings = ServerController.GetServiceSettings(webServiceId);
                if (Utils.ParseBool(webSettings["AutoAssignDedicatedIP"], true))
                    ServerController.AllocateMaximumPackageIPAddresses(packageId, ResourceGroups.Web, IPAddressPool.WebSites);

                // allocate "VPS" IP addresses
                int vpsServiceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.VPS);
                StringDictionary vpsSettings = ServerController.GetServiceSettings(vpsServiceId);
                if (Utils.ParseBool(vpsSettings["AutoAssignExternalIP"], true))
                    ServerController.AllocateMaximumPackageIPAddresses(packageId, ResourceGroups.VPS, IPAddressPool.VpsExternalNetwork);

                // load hosting plan
                HostingPlanInfo plan = GetHostingPlan(planId);

                // create home folder
                int homeId = CreatePackageHome(plan.PackageId, packageId, userId);
                if (homeId < 0)
                    result.Result = homeId;

                TaskManager.ItemId = result.Result;
                TaskManager.TaskParameters["Signup"] = signup;
                TaskManager.TaskParameters["UserId"] = userId;
                TaskManager.TaskParameters["SendLetter"] = sendLetter;
            }
            finally
            {
                TaskManager.CompleteTask();
            }

            return result;
        }
Exemplo n.º 4
0
        public static PackageResult AddPackageWithResources(int userId, int planId, string spaceName,
            int statusId, bool sendLetter,
            bool createResources, string domainName, bool createInstantAlias, bool createWebSite,
            bool createFtpAccount, string ftpAccountName, bool createMailAccount)
        {
            try
            {
                TaskManager.StartTask("HOSTING_SPACE_WR", "ADD", spaceName);

                PackageResult result = new PackageResult();

                // check account
                result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                    | DemandAccount.IsReseller);
                if (result.Result < 0) return result;

                // check if domain exists
                result.Result = ServerController.CheckDomain(domainName);
                if (result.Result < 0)
                    return result;

                // load user info
                UserInfo user = UserController.GetUser(userId);

                if (createFtpAccount)
                {
                    // check if FTP account exists
                    if (String.IsNullOrEmpty(ftpAccountName))
                        ftpAccountName = user.Username;

                    if (FtpServerController.FtpAccountExists(ftpAccountName))
                    {
                        result.Result = BusinessErrorCodes.ERROR_ACCOUNT_WIZARD_FTP_ACCOUNT_EXISTS;
                        return result;
                    }
                }

                // load hosting plan
                HostingPlanInfo plan = PackageController.GetHostingPlan(planId);

                string packageName = spaceName;
                if (String.IsNullOrEmpty(packageName) || packageName.Trim() == "")
                    packageName = plan.PlanName;

                // create package
                int packageId = -1;
                try
                {
                    result = PackageController.AddPackage(
                        userId, planId, packageName, "", statusId, DateTime.Now, false);
                }
                catch (Exception ex)
                {
                    // error while adding package
                    throw ex;
                }

                if (result.Result < 0)
                    return result;

                packageId = result.Result;

                // create domain
                if (createResources)
                {
                    int domainId = 0;
                    if (!String.IsNullOrEmpty(domainName))
                    {
                        try
                        {
                            DomainInfo domain = new DomainInfo();
                            domain.PackageId = packageId;
                            domain.DomainName = domainName;
                            domain.HostingAllowed = false;
                            domainId = ServerController.AddDomain(domain, createInstantAlias);
                            if (domainId < 0)
                            {
                                result.Result = domainId;
                                DeletePackage(packageId);
                                return result;
                            }
                        }
                        catch (Exception ex)
                        {
                            // error while adding domain
                            DeletePackage(packageId);
                            throw new Exception("Could not add domain", ex);
                        }
                    }

                    if (createWebSite && !String.IsNullOrEmpty(domainName))
                    {
                        // create web site
                        try
                        {
                            int webSiteId = WebServerController.AddWebSite(
                                packageId, domainId, 0, true);
                            if (webSiteId < 0)
                            {
                                result.Result = webSiteId;
                                DeletePackage(packageId);
                                return result;
                            }
                        }
                        catch (Exception ex)
                        {
                            // error while creating web site
                            DeletePackage(packageId);
                            throw new Exception("Could not create web site", ex);
                        }
                    }

                    // create FTP account
                    if (createFtpAccount)
                    {
                        try
                        {
                            FtpAccount ftpAccount = new FtpAccount();
                            ftpAccount.PackageId = packageId;
                            ftpAccount.Name = ftpAccountName;
                            ftpAccount.Password = user.Password;
                            ftpAccount.Folder = "\\";
                            ftpAccount.CanRead = true;
                            ftpAccount.CanWrite = true;

                            int ftpAccountId = FtpServerController.AddFtpAccount(ftpAccount);
                            if (ftpAccountId < 0)
                            {
                                result.Result = ftpAccountId;
                                DeletePackage(packageId);
                                return result;
                            }
                        }
                        catch (Exception ex)
                        {
                            // error while creating ftp account
                            DeletePackage(packageId);
                            throw new Exception("Could not create FTP account", ex);
                        }
                    }

                    if (createMailAccount && !String.IsNullOrEmpty(domainName))
                    {
                        // create default mailbox
                        try
                        {
                            // load mail policy
                            UserSettings settings = UserController.GetUserSettings(userId, UserSettings.MAIL_POLICY);
                            string catchAllName = !String.IsNullOrEmpty(settings["CatchAllName"])
                                ? settings["CatchAllName"] : "mail";

                            MailAccount mailbox = new MailAccount();
                            mailbox.Name = catchAllName + "@" + domainName;
                            mailbox.PackageId = packageId;

                            // gather information from the form
                            mailbox.Enabled = true;

                            mailbox.ResponderEnabled = false;
                            mailbox.ReplyTo = "";
                            mailbox.ResponderSubject = "";
                            mailbox.ResponderMessage = "";

                            // password
                            mailbox.Password = user.Password;

                            // redirection
                            mailbox.ForwardingAddresses = new string[] { };
                            mailbox.DeleteOnForward = false;
                            mailbox.MaxMailboxSize = 0;

                            int mailAccountId = MailServerController.AddMailAccount(mailbox);

                            if (mailAccountId < 0)
                            {
                                result.Result = mailAccountId;
                                DeletePackage(packageId);
                                return result;
                            }

                            // set catch-all account
                            MailDomain mailDomain = MailServerController.GetMailDomain(packageId, domainName);
                            mailDomain.CatchAllAccount = catchAllName;
                            mailDomain.PostmasterAccount = "mail";
                            mailDomain.AbuseAccount = "mail";
                            MailServerController.UpdateMailDomain(mailDomain);

                            int mailDomainId = mailDomain.Id;

                            // set mail domain pointer
                            // load domain instant alias
                            string instantAlias = ServerController.GetDomainAlias(packageId, domainName);
                            DomainInfo instantDomain = ServerController.GetDomain(instantAlias);
                            if (instantDomain == null || instantDomain.MailDomainId > 0)
                                instantAlias = "";

                            if (!String.IsNullOrEmpty(instantAlias))
                                MailServerController.AddMailDomainPointer(mailDomainId, instantDomain.DomainId);
                        }
                        catch (Exception ex)
                        {
                            // error while creating mail account
                            DeletePackage(packageId);
                            throw new Exception("Could not create mail account", ex);
                        }
                    }
                }

                TaskManager.ItemId = result.Result;
                TaskManager.TaskParameters["SendLetter"] = sendLetter;

                return result;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemplo n.º 5
0
        public static PackageResult UpdateHostingPlan(HostingPlanInfo plan)
        {
            PackageResult result = new PackageResult();

            // check account
            result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                | DemandAccount.IsReseller);
            if (result.Result < 0) return result;

            string quotasXml = BuildPlanQuotasXml(plan.Groups, plan.Quotas);

            result.ExceedingQuotas = DataProvider.UpdateHostingPlan(SecurityContext.User.UserId,
                plan.PlanId, plan.PackageId, plan.ServerId, plan.PlanName,
                plan.PlanDescription, plan.Available, plan.SetupPrice, plan.RecurringPrice,
                plan.RecurrenceUnit, plan.RecurrenceLength, quotasXml);

            if (result.ExceedingQuotas.Tables[0].Rows.Count > 0)
                result.Result = BusinessErrorCodes.ERROR_PACKAGE_QUOTA_EXCEED;

            return result;
        }
Exemplo n.º 6
0
        public static PackageResult UpdatePackageAddon(PackageAddonInfo addon)
        {
            PackageResult result = new PackageResult();

            // check account
            result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                | DemandAccount.IsReseller);

            if (result.Result < 0)
                result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                | DemandAccount.IsPlatformCSR);

            if (result.Result < 0)
                result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                | DemandAccount.IsResellerCSR);

            if (result.Result < 0) return result;

            result.ExceedingQuotas = DataProvider.UpdatePackageAddon(SecurityContext.User.UserId, addon.PackageAddonId,
                addon.PlanId, addon.Quantity, addon.StatusId, addon.PurchaseDate, addon.Comments);

            if (result.ExceedingQuotas.Tables[0].Rows.Count > 0)
                result.Result = BusinessErrorCodes.ERROR_PACKAGE_QUOTA_EXCEED;

            // Update the Hard quota on home folder in case it was enabled and in case there was a change in disk space
            UpdatePackageHardQuota(addon.PackageId);
            return result;
        }
Exemplo n.º 7
0
        public int CreateUserAccountInternal(int parentPackageId, string username, string password,
                                             int roleId, string firstName, string lastName, string email, string secondaryEmail, bool htmlMail,
                                             bool sendAccountLetter,
                                             bool createPackage, int planId, bool sendPackageLetter,
                                             string domainName, bool tempDomain, bool createWebSite,
                                             bool createFtpAccount, string ftpAccountName, bool createMailAccount)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                                                            | DemandAccount.IsReseller);

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

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

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

            // check if username exists
            if (UserController.UserExists(username))
            {
                return(BusinessErrorCodes.ERROR_ACCOUNT_WIZARD_USER_EXISTS);
            }

            // check if domain exists
            int checkDomainResult = ServerController.CheckDomain(domainName);

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

            // check if FTP account exists
            if (String.IsNullOrEmpty(ftpAccountName))
            {
                ftpAccountName = username;
            }

            if (FtpServerController.FtpAccountExists(ftpAccountName))
            {
                return(BusinessErrorCodes.ERROR_ACCOUNT_WIZARD_FTP_ACCOUNT_EXISTS);
            }

            // load parent package
            PackageInfo parentPackage = PackageController.GetPackage(parentPackageId);

            /********************************************
             *  CREATE USER ACCOUNT
             * *****************************************/
            UserInfo user = new UserInfo();

            user.RoleId   = roleId;
            user.StatusId = (int)UserStatus.Active;
            user.OwnerId  = parentPackage.UserId;
            user.IsDemo   = false;
            user.IsPeer   = false;

            // account info
            user.FirstName      = firstName;
            user.LastName       = lastName;
            user.Email          = email;
            user.SecondaryEmail = secondaryEmail;
            user.Username       = username;
            user.Password       = password;
            user.HtmlMail       = htmlMail;

            // add a new user
            createdUserId = UserController.AddUser(user, false);
            if (createdUserId < 0)
            {
                // exit
                return(createdUserId);
            }
            userCreated = true;

            // create package
            // load hosting plan
            createdPackageId = -1;
            if (createPackage)
            {
                try
                {
                    HostingPlanInfo plan = PackageController.GetHostingPlan(planId);

                    PackageResult packageResult = PackageController.AddPackage(
                        createdUserId, planId, plan.PlanName, "", (int)PackageStatus.Active, DateTime.Now, false);
                    createdPackageId = packageResult.Result;
                }
                catch (Exception ex)
                {
                    // error while adding package

                    // remove user account
                    UserController.DeleteUser(createdUserId);

                    throw ex;
                }

                if (createdPackageId < 0)
                {
                    // rollback wizard
                    Rollback();

                    // return code
                    return(createdPackageId);
                }

                // create domain
                int domainId = 0;
                if ((createWebSite || createMailAccount) && !String.IsNullOrEmpty(domainName))
                {
                    try
                    {
                        DomainInfo domain = new DomainInfo();
                        domain.PackageId      = createdPackageId;
                        domain.DomainName     = domainName;
                        domain.HostingAllowed = false;
                        domainId = ServerController.AddDomain(domain, !tempDomain);
                        if (domainId < 0)
                        {
                            // rollback wizard
                            Rollback();

                            // return
                            return(domainId);
                        }
                    }
                    catch (Exception ex)
                    {
                        // rollback wizard
                        Rollback();

                        // error while adding domain
                        throw new Exception("Could not add domain", ex);
                    }
                }

                if (createWebSite && !String.IsNullOrEmpty(domainName))
                {
                    // create web site
                    try
                    {
                        int webSiteId = WebServerController.AddWebSite(
                            createdPackageId, domainId, 0, true);
                        if (webSiteId < 0)
                        {
                            // rollback wizard
                            Rollback();

                            // return
                            return(webSiteId);
                        }
                    }
                    catch (Exception ex)
                    {
                        // rollback wizard
                        Rollback();

                        // error while creating web site
                        throw new Exception("Could not create web site", ex);
                    }
                }

                // create FTP account
                if (createFtpAccount)
                {
                    try
                    {
                        FtpAccount ftpAccount = new FtpAccount();
                        ftpAccount.PackageId = createdPackageId;
                        ftpAccount.Name      = ftpAccountName;
                        ftpAccount.Password  = password;
                        ftpAccount.Folder    = "\\";
                        ftpAccount.CanRead   = true;
                        ftpAccount.CanWrite  = true;

                        int ftpAccountId = FtpServerController.AddFtpAccount(ftpAccount);
                        if (ftpAccountId < 0)
                        {
                            // rollback wizard
                            Rollback();

                            // return
                            return(ftpAccountId);
                        }
                    }
                    catch (Exception ex)
                    {
                        // rollback wizard
                        Rollback();

                        // error while creating ftp account
                        throw new Exception("Could not create FTP account", ex);
                    }
                }

                if (createMailAccount && !String.IsNullOrEmpty(domainName))
                {
                    // create default mailbox
                    try
                    {
                        // load mail policy
                        UserSettings settings     = UserController.GetUserSettings(createdUserId, UserSettings.MAIL_POLICY);
                        string       catchAllName = !String.IsNullOrEmpty(settings["CatchAllName"])
                            ? settings["CatchAllName"] : "mail";

                        MailAccount mailbox = new MailAccount();
                        mailbox.Name      = catchAllName + "@" + domainName;
                        mailbox.PackageId = createdPackageId;

                        // gather information from the form
                        mailbox.Enabled = true;

                        mailbox.ResponderEnabled = false;
                        mailbox.ReplyTo          = "";
                        mailbox.ResponderSubject = "";
                        mailbox.ResponderMessage = "";

                        // password
                        mailbox.Password = password;

                        // redirection
                        mailbox.ForwardingAddresses = new string[] { };
                        mailbox.DeleteOnForward     = false;
                        mailbox.MaxMailboxSize      = 0;

                        int mailAccountId = MailServerController.AddMailAccount(mailbox);

                        if (mailAccountId < 0)
                        {
                            // rollback wizard
                            Rollback();

                            // return
                            return(mailAccountId);
                        }

                        // set catch-all account
                        MailDomain mailDomain = MailServerController.GetMailDomain(createdPackageId, domainName);
                        mailDomain.CatchAllAccount   = "mail";
                        mailDomain.PostmasterAccount = "mail";
                        mailDomain.AbuseAccount      = "mail";
                        MailServerController.UpdateMailDomain(mailDomain);

                        int mailDomainId = mailDomain.Id;

                        // set mail domain pointer
                        // load domain instant alias
                        string     instantAlias  = ServerController.GetDomainAlias(createdPackageId, domainName);
                        DomainInfo instantDomain = ServerController.GetDomain(instantAlias);
                        if (instantDomain == null || instantDomain.MailDomainId > 0)
                        {
                            instantAlias = "";
                        }

                        if (!String.IsNullOrEmpty(instantAlias))
                        {
                            MailServerController.AddMailDomainPointer(mailDomainId, instantDomain.DomainId);
                        }
                    }
                    catch (Exception ex)
                    {
                        // rollback wizard
                        Rollback();

                        // error while creating mail account
                        throw new Exception("Could not create mail account", ex);
                    }
                }
            }

            // send welcome letters
            if (sendAccountLetter)
            {
                int result = PackageController.SendAccountSummaryLetter(createdUserId, null, null, true);
                if (result < 0)
                {
                    // rollback wizard
                    Rollback();

                    // return
                    return(result);
                }
            }

            if (createPackage && sendPackageLetter)
            {
                int result = PackageController.SendPackageSummaryLetter(createdPackageId, null, null, true);
                if (result < 0)
                {
                    // rollback wizard
                    Rollback();

                    // return
                    return(result);
                }
            }

            return(createdUserId);
        }