Exemplo n.º 1
0
    protected void SubmitButton_Click(object sender, System.EventArgs e)
    {
        bool flag = false;

        try
        {
            AdminPanelSettings apSettings = new AdminPanelSettings().Load();

            string licenseKeyFromForm = txtLicenseKey.Value ?? string.Empty;

            if (string.IsNullOrEmpty(licenseKeyFromForm))
            {
                apSettings.LicenseKey = licenseKeyFromForm;
                flag = false;
            }
            else
            {
                try
                {
                    Pop3.LicenseKey = licenseKeyFromForm.Substring(0, 39);
                    Pop3 pop = new Pop3();
                    flag = true;
                }
                catch (Exception error)
                {
                    Log.WriteException(error);
                    _errorMessage         = "License Key is invalid";
                    GetLicenseUrl.Visible = true;
                    flag = false;
                }
                apSettings.LicenseKey = licenseKeyFromForm;
            }
            if (File.Exists(Path.Combine(AdminPanelUtils.GetWebMailDataFolder(), @"settings\settings.xml")))
            {
                WebmailSettings settings = new WebmailSettings().CreateInstance(AdminPanelUtils.GetWebMailDataFolder());
                settings.LicenseKey = licenseKeyFromForm;
                settings.SaveWebmailSettings(AdminPanelUtils.GetWebMailDataFolder());
            }

            apSettings.Save();
            _errorMessage = Constants.mailAdmSaveSuccess;

            if (flag == true)
            {
                Session["LicenseKey"] = txtLicenseKey.Value;
                Response.Redirect("install.aspx?mode=db", true);
            }
            else
            {
                _errorMessage = "Please specify valid license key.";
            }
        }
        catch (Exception error)
        {
            Log.WriteException(error);
            _errorMessage = Constants.mailAdmSaveUnsuccess;
        }
    }
 public void SaveSettings(object sender, System.EventArgs e)
 {
     if (txtPassword.Text.Trim() != AdminPanelConstants.DummyPassword)
     {
         apSettings.Pass = txtPassword.Text;
     }
     try
     {
         apSettings.Save();
         AdminPanelUtils.SetPageReportMessage(Page, "Settings are successfully saved!");
         Response.Redirect("install.aspx?mode=connection", true);
     }
     catch (Exception ex)
     {
         Log.WriteException(ex);
         AdminPanelUtils.SetPageErrorMessage(Page, (ex.InnerException != null ? ex.InnerException.Message : ex.Message));
     }
 }
    public void SaveSettings(object sender, System.EventArgs e)
    {
        bool flag = false;

        this.Context.Application.Remove(AdminPanelConstants.serverSettings);
        this.Context.Application.Remove(Constants.sessionSettings);

        string     adminpanelxml        = Path.Combine(AdminPanelUtils.GetAdminPanelDataFolderPath(), @"adminpanel.xml");
        bool       isAdminpanelxmlWrite = false;
        FileStream fs;

        try
        {
            fs = File.Open(adminpanelxml, FileMode.Open, FileAccess.Write);
            fs.Close();
            isAdminpanelxmlWrite = true;
        }
        catch (UnauthorizedAccessException)
        {
            isAdminpanelxmlWrite = false;
        }

        if (isAdminpanelxmlWrite)
        {
            if (txtSecurityPassword.Text.Trim() != AdminPanelConstants.DummyPassword)
            {
                if (_isServerExist)
                {
                    try
                    {
                        if (AdminPanelControlAccounts.IsControlAccountExist(UserName))
                        {
                            AdminPanelControlAccounts.SetControlAccountPassword(UserName, txtSecurityPassword.Text);
                        }
                        else
                        {
                            AdminPanelControlAccounts.AdminPanelControlAccount ca = new AdminPanelControlAccounts.AdminPanelControlAccount();
                            ca.Name     = UserName;
                            ca.Password = txtSecurityPassword.Text;
                            AdminPanelControlAccounts.AddControlAccount(ca);
                        }
                        flag = true;
                    }
                    catch (Exception ex)
                    {
                        flag = false;
                        AdminPanelUtils.SetPageErrorMessage(Page, ex.Message);
                    }
                    if (flag)
                    {
                        apSettings.Pass = txtSecurityPassword.Text;
                    }
                }
                else
                {
                    apSettings.Pass = txtSecurityPassword.Text;
                }
            }
            if (_isServerExist)
            {
                apSettings.Host = txtHost.Value;
                apSettings.Port = txtPort.Value;
            }
            try
            {
                apSettings.Save();
                AdminPanelUtils.SetPageReportMessage(Page, "Settings are successfully saved!");
            }
            catch (Exception ex)
            {
                AdminPanelUtils.SetPageErrorMessage(Page, ex.Message);
            }
        }
        else
        {
            AdminPanelUtils.SetPageErrorMessage(Page, "Failed to access \"adminpanel.xml\" config file.");
        }
    }