Exemplo n.º 1
0
        private void SaveSpace()
        {
            if (!Page.IsValid)
            {
                return;
            }

            // gather form data
            PackageInfo package = new PackageInfo();

            // load package for update
            if (PanelSecurity.PackageId > 0)
            {
                package = ES.Services.Packages.GetPackage(PanelSecurity.PackageId);
            }

            package.PackageId       = PanelSecurity.PackageId;
            package.PackageName     = txtName.Text;
            package.PackageComments = txtComments.Text;
            package.PlanId          = Utils.ParseInt(ddlPlan.SelectedValue, 0);
            package.PurchaseDate    = PurchaseDate.SelectedDate;

            package.OverrideQuotas = rbPackageQuotas.Checked;
            if (package.OverrideQuotas)
            {
                package.Groups = editPackageQuotas.Groups;
                package.Quotas = editPackageQuotas.Quotas;
            }

            try
            {
                // update existing package
                PackageResult result = ES.Services.Packages.UpdatePackage(package);
                if (result.Result < 0)
                {
                    ShowResultMessage(result.Result);
                    lblMessage.Text = PortalAntiXSS.Encode(GetExceedingQuotasMessage(result.ExceedingQuotas));
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage("PACKAGE_UPDATE_PACKAGE", ex);
                return;
            }

            // return
            RedirectSpaceHomePage();
        }
Exemplo n.º 2
0
        private void BindGroupings()
        {
            DataSet dsUsers = ES.Services.Users.GetUsersSummary(PanelSecurity.SelectedUserId);

            // all customers
            lnkAllCustomers.Text = PortalAntiXSS.Encode(String.Format(GetLocalizedString("AllCustomers.Text"),
                                                                      dsUsers.Tables[0].Rows[0]["UsersNumber"]));

            // by status
            repUserStatuses.DataSource = dsUsers.Tables[1];
            repUserStatuses.DataBind();

            // by role
            repUserRoles.DataSource = dsUsers.Tables[2];
            repUserRoles.DataBind();
        }
        private void BindSummary()
        {
            DataSet ds = ES.Services.Packages.GetPackageDiskspace(PanelSecurity.PackageId);

            long negativeDiskspace = 0;

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                long diskspace = Convert.ToInt64(dr["Diskspace"]);
                DiskspaceTotal += diskspace;

                if (diskspace < 0)
                {
                    negativeDiskspace += diskspace;
                }
            }

            // subtract negative from "Files" and remove negative groups
            DataRowCollection rows = ds.Tables[0].Rows;
            int i = 0;

            while (i < rows.Count)
            {
                int  groupId        = (int)rows[i]["GroupID"];
                long diskspace      = Convert.ToInt64(rows[i]["Diskspace"]);
                long diskspaceBytes = Convert.ToInt64(rows[i]["DiskspaceBytes"]);
                if (groupId == 1)
                {
                    rows[i]["Diskspace"] = diskspace + negativeDiskspace;
                }
                else if (diskspaceBytes < 0)
                {
                    rows.RemoveAt(i);
                    continue;
                }
                i++;
            }

            litTotal.Text = PortalAntiXSS.Encode(DiskspaceTotal.ToString());

            // get summary
            gvSummary.DataSource = ds;
            gvSummary.DataBind();
        }
Exemplo n.º 4
0
        private void SavePlan()
        {
            if (!Page.IsValid)
            {
                return;
            }

            // gather form info
            HostingPlanInfo plan = new HostingPlanInfo();

            plan.UserId          = PanelSecurity.SelectedUserId;
            plan.PlanId          = PanelRequest.PlanID;
            plan.IsAddon         = false;
            plan.PlanName        = txtPlanName.Text;
            plan.PlanDescription = txtPlanDescription.Text;
            plan.Available       = true; // always available

            plan.SetupPrice       = 0;
            plan.RecurringPrice   = 0;
            plan.RecurrenceLength = 1;
            plan.RecurrenceUnit   = 2; // month

            plan.PackageId = Utils.ParseInt(ddlSpace.SelectedValue, 0);
            plan.ServerId  = Utils.ParseInt(ddlServer.SelectedValue, 0);
            // if this is non-admin
            // get server info from parent package
            if (PanelSecurity.EffectiveUser.Role != UserRole.Administrator)
            {
                try
                {
                    PackageInfo package = ES.Services.Packages.GetPackage(plan.PackageId);
                    if (package != null)
                    {
                        plan.ServerId = package.ServerId;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("PACKAGE_GET_PACKAGE", ex);
                    return;
                }
            }

            plan.Groups = hostingPlansQuotas.Groups;
            plan.Quotas = hostingPlansQuotas.Quotas;

            int planId = PanelRequest.PlanID;

            if ((PanelRequest.PlanID == 0) || ShouldCopyCurrentHostingPlan())
            {
                // new plan
                try
                {
                    planId = ES.Services.Packages.AddHostingPlan(plan);
                    if (planId < 0)
                    {
                        ShowResultMessage(planId);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("PLAN_ADD_PLAN", ex);
                    return;
                }
            }
            else
            {
                // update plan
                try
                {
                    PackageResult result = ES.Services.Packages.UpdateHostingPlan(plan);
                    if (result.Result < 0)
                    {
                        ShowResultMessage(result.Result);
                        lblMessage.Text = PortalAntiXSS.Encode(GetExceedingQuotasMessage(result.ExceedingQuotas));
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("PLAN_UPDATE_PLAN", ex);
                    return;
                }
            }

            // redirect
            RedirectBack();
        }
Exemplo n.º 5
0
        private void CreateHostingSpace()
        {
            if (!Page.IsValid)
            {
                return;
            }

            string spaceName = ddlPlans.SelectedItem.Text;

            string ftpAccount = (rbFtpAccountName.SelectedIndex == 0) ? null : ftpAccountName.Text;

            string domainName = txtDomainName.Text.Trim();

            PackageResult result = null;

            try
            {
                result = ES.Services.Packages.AddPackageWithResources(PanelSecurity.SelectedUserId,
                                                                      Utils.ParseInt(ddlPlans.SelectedValue, 0),
                                                                      spaceName,
                                                                      Utils.ParseInt(ddlStatus.SelectedValue, 0),
                                                                      chkPackageLetter.Checked,
                                                                      chkCreateResources.Checked, domainName, false, chkCreateWebSite.Checked,
                                                                      chkCreateFtpAccount.Checked, ftpAccount, chkCreateMailAccount.Checked, txtHostName.Text);

                if (result.Result < 0)
                {
                    ShowResultMessage(result.Result);
                    lblMessage.Text = PortalAntiXSS.Encode(GetExceedingQuotasMessage(result.ExceedingQuotas));
                    return;
                }
                else
                {
                    if ((chkIntegratedOUProvisioning.Checked) & !string.IsNullOrEmpty(domainName))
                    {
                        UserInfo user = UsersHelper.GetUser(PanelSecurity.SelectedUserId);

                        if (user != null)
                        {
                            if (user.Role != UserRole.Reseller)
                            {
                                UserSettings settings = ES.Services.Users.GetUserSettings(user.UserId, UserSettings.EXCHANGE_POLICY);
                                string       orgId    = domainName.ToLower();

                                if (settings != null && settings["OrgIdPolicy"] != null)
                                {
                                    orgId = GetOrgId(settings["OrgIdPolicy"], domainName, result.Result);
                                }

                                ES.Services.Organizations.CreateOrganization(result.Result, orgId, domainName.ToLower(), domainName.ToLower());

                                if (result.Result < 0)
                                {
                                    ShowErrorMessage("USERWIZARD_CREATE_ACCOUNT");
                                    return;
                                }

                                //Add Mail Cleaner
                                Knom.Helpers.Net.APIMailCleanerHelper.DomainAdd(domainName, Utils.ParseInt(ddlPlans.SelectedValue, 0));
                            }
                        }
                    }
                    if ((chkCreateMailAccount.Checked) & !string.IsNullOrEmpty(domainName))
                    {
                        //Add Mail Cleaner
                        Knom.Helpers.Net.APIMailCleanerHelper.DomainAdd(domainName, Utils.ParseInt(ddlPlans.SelectedValue, 0));
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage("USERWIZARD_CREATE_ACCOUNT", ex);
                return;
            }

            // Save addons
            try
            {
                int spaceId = result.Result;
                foreach (RepeaterItem item in repHostingAddons.Items)
                {
                    PackageAddonInfo addon = new PackageAddonInfo();
                    addon.PackageAddonId = 0;       //PanelRequest.PackageAddonID;
                    addon.PackageId      = spaceId; //PanelSecurity.PackageId;
                    addon.Comments       = "";
                    addon.PlanId         = Utils.ParseInt(GetDropDownListSelectedValue(item, "ddlPlan"), 0);
                    addon.StatusId       = Utils.ParseInt(ddlStatus.SelectedValue, 0);
                    addon.PurchaseDate   = DateTime.Now;
                    addon.Quantity       = Utils.ParseInt(GetTextBoxText(item, "txtQuantity"), 1);
                    PackageResult addonResult = ES.Services.Packages.AddPackageAddon(addon);
                }

                if (rbPackageQuotas.Checked)
                {
                    //TODO: add logic to recalculate quota
                    //If checked rbPackageQuotas take all addons quota, sum it and replace to main hosting quota
                    //You can look the idea from SpaceEditDetails, but in SpaceEditDetails it is manually, need automatic here
                    //At this moment here is a lot of work, maybe later.
                }

                //PackageContext cntx = PackagesHelper.GetCachedPackageContext(spaceId);
                //string resourceGroup = "VPS2012";
                //if (cntx != null && cntx.Groups.ContainsKey(resourceGroup))
                //{
                //    string pageId = "SpaceVPS2012";
                //    string pageUrl = PortalUtils.NavigatePageURL(
                //pageId, PortalUtils.SPACE_ID_PARAM, spaceId.ToString(), null);
                //    Response.Redirect(pageUrl);
                //}
            }
            catch
            {
                //If something happens here, just ignore it. Addons not so important that a Hosting Space
            }

            if (chkRedirectToCreateVPS.Checked)
            {
                string pageId  = "SpaceVPS2012";
                string pageUrl = PortalUtils.NavigatePageURL(
                    pageId, PortalUtils.SPACE_ID_PARAM, result.Result.ToString(), null);
                Response.Redirect(pageUrl);
            }
            else
            {
                // go to space home
                Response.Redirect(PortalUtils.GetSpaceHomePageUrl(result.Result));
            }
        }
Exemplo n.º 6
0
        private void BindAccount()
        {
            // load user
            UserInfo user = UsersHelper.GetUser(PanelSecurity.SelectedUserId);

            if (user != null)
            {
                imgAdmin.Visible    = (user.Role == UserRole.Administrator);
                imgReseller.Visible = (user.Role == UserRole.Reseller);
                imgUser.Visible     = (user.Role == UserRole.User);

                // bind account details
                litUsername.Text         = user.Username;
                litFullName.Text         = Utils.EllipsisString(PortalAntiXSS.Encode(user.FirstName) + " " + PortalAntiXSS.Encode(user.LastName), 25);
                litSubscriberNumber.Text = PortalAntiXSS.Encode(user.SubscriberNumber);
                litRole.Text             = PanelFormatter.GetUserRoleName(user.RoleId);
                litCreated.Text          = user.Created.ToString();
                litUpdated.Text          = user.Changed.ToString();
                lnkEmail.Text            = Utils.EllipsisString(user.Email, 25);
                lnkEmail.NavigateUrl     = "mailto:" + user.Email;

                // load owner account
                //UserInfo owner = UsersHelper.GetUser(user.OwnerId);
                //if(owner != null)
                //{
                //    litReseller.Text = owner.Username;
                //}


                // bind account status
                UserStatus status = user.Status;
                litStatus.Text = PanelFormatter.GetAccountStatusName((int)status);

                cmdActive.Visible  = (status != UserStatus.Active);
                cmdSuspend.Visible = (status == UserStatus.Active);
                cmdCancel.Visible  = (status != UserStatus.Cancelled);

                StatusBlock.Visible = (PanelSecurity.SelectedUserId != PanelSecurity.EffectiveUserId);



                // links
                lnkSummaryLetter.NavigateUrl = EditUrl("UserID", PanelSecurity.SelectedUserId.ToString(), "summary_letter");
                lnkSummaryLetter.Visible     = (PanelSecurity.SelectedUser.Role != UserRole.Administrator);

                lnkEditAccountDetails.NavigateUrl = EditUrl("UserID", PanelSecurity.SelectedUserId.ToString(), "edit_details");

                lnkChangePassword.NavigateUrl = EditUrl("UserID", PanelSecurity.SelectedUserId.ToString(), "change_password");
                lnkChangePassword.Visible     = !((PanelSecurity.SelectedUserId == PanelSecurity.EffectiveUserId) && PanelSecurity.LoggedUser.IsPeer);

                lnkDelete.NavigateUrl = EditUrl("UserID", PanelSecurity.SelectedUserId.ToString(), "delete");

                if (!((PanelSecurity.LoggedUser.Role == UserRole.Reseller) | (PanelSecurity.LoggedUser.Role == UserRole.Administrator)))
                {
                    lnkDelete.Visible = false;
                }
                else
                {
                    lnkDelete.Visible = (PanelSecurity.SelectedUserId != PanelSecurity.EffectiveUserId);
                }
            }
        }
        private void SavePlan()
        {
            if (!Page.IsValid)
            {
                return;
            }

            // gather form info
            HostingPlanInfo plan = new HostingPlanInfo();

            plan.UserId          = PanelSecurity.SelectedUserId;
            plan.PlanId          = PanelRequest.PlanID;
            plan.IsAddon         = true;
            plan.PlanName        = txtPlanName.Text;
            plan.PlanDescription = txtPlanDescription.Text;
            plan.Available       = true; // always available

            plan.SetupPrice       = 0;
            plan.RecurringPrice   = 0;
            plan.RecurrenceLength = 1;
            plan.RecurrenceUnit   = 2; // month

            plan.Groups = hostingPlansQuotas.Groups;
            plan.Quotas = hostingPlansQuotas.Quotas;

            int planId = PanelRequest.PlanID;

            if ((PanelRequest.PlanID == 0) || ShouldCopyCurrentHostingAddon())
            {
                // new plan
                try
                {
                    planId = ES.Services.Packages.AddHostingPlan(plan);
                    if (planId < 0)
                    {
                        ShowResultMessage(planId);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("ADDON_ADD_ADDON", ex);
                    return;
                }
            }
            else
            {
                // update plan
                try
                {
                    PackageResult result = ES.Services.Packages.UpdateHostingPlan(plan);
                    lblMessage.Text = PortalAntiXSS.Encode(GetExceedingQuotasMessage(result.ExceedingQuotas));
                    if (result.Result < 0)
                    {
                        ShowResultMessage(result.Result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("ADDON_UPDATE_ADDON", ex);
                    return;
                }
            }

            // redirect
            RedirectBack();
        }
Exemplo n.º 8
0
        protected void gvFiles_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "browse")
            {
                string fileName = (string)e.CommandArgument;
                litPath.Text += PortalAntiXSS.Encode((litPath.Text != "\\") ? ("\\" + fileName) : fileName);
                BindPath();
            }
            else if (e.CommandName == "download")
            {
                string path = GetFullRelativePath((string)e.CommandArgument);

                Response.Redirect(NavigateURL(PortalUtils.SPACE_ID_PARAM, PanelSecurity.PackageId.ToString(),
                                              "DownloadFile=" + Server.UrlEncode(path)));
            }
            else if (e.CommandName == "edit_file")
            {
                // read file content
                try
                {
                    string path = GetFullRelativePath((string)e.CommandArgument);
                    ViewState["EditFile"] = path;

                    txtEditFileContent.Text = GetFileContent(path, ddlFileEncodings.SelectedValue);

                    // show edit panel
                    EditFileModal.Show();
                }
                catch (Exception ex)
                {
                    messageBox.ShowErrorMessage("FILES_READ_FILE", ex);
                }
            }
            else if (e.CommandName == "edit_permissions")
            {
                // read file content
                try
                {
                    string path = GetFullRelativePath((string)e.CommandArgument);
                    ViewState["EditPermissions"] = path;
                    UserPermission[] users = ES.Services.Files.GetFilePermissions(PanelSecurity.PackageId, path);

                    gvFilePermissions.DataSource = users;
                    gvFilePermissions.DataBind();

                    // show permissions panel
                    PermissionsFileModal.Show();
                }
                catch (Exception ex)
                {
                    messageBox.ShowErrorMessage("FILES_READ_PERMISSIONS", ex);
                }
            }
            else if (e.CommandName == "rename")
            {
                RenameFileModal.Show();

                ViewState["RenameFile"] = (string)e.CommandArgument;
                txtRenameFile.Text      = (string)e.CommandArgument;
            }
        }