Exemplo n.º 1
0
    public void UpdateXMailDomain()
    {
        try
        {
            XMLayer xmLayer = XMServer.CreateXMLayer();
            xmLayer.Login();

            if (Int32.Parse(hidCustomDomain.Value) == 1)
            {
                // edit custom domain
                StringBuilder redirect = new StringBuilder("redirect");

/*
 *              if (Request.Params[RedirectionsListDDL.UniqueID] != null)
 *              {
 *                  string[] RedirectionsList = Request.Params[RedirectionsListDDL.UniqueID].ToString().Split(',');
 *                  for (int i = 0; i < RedirectionsList.Length; i++)
 *                      redirect.AppendFormat("\t\"{0}\"", RedirectionsList[i]);
 *              }
 */
                StringBuilder lredirect = new StringBuilder("lredirect");
                if (Request.Params[LRedirectionsListDDL.UniqueID] != null)
                {
                    string[] LRedirectionsList = Request.Params[LRedirectionsListDDL.UniqueID].ToString().Split(',');
                    for (int i = 0; i < LRedirectionsList.Length; i++)
                    {
                        lredirect.AppendFormat("\t\"{0}\"", LRedirectionsList[i]);
                    }
                }
                string data = string.Format("{0}\r\n{1}\r\n{2}\r\n.\r\n", redirect.ToString(), lredirect.ToString(), AdvancedID.Text);
                xmLayer.SetCustomDomainTab(textDomainName.Value.Trim(), data);
            }

            xmLayer.Logout();
        }
        catch (Exception ex)
        {
            Log.WriteException(ex);
            AdminPanelUtils.SetPageErrorMessage(this.Page, ex.Message);
        }
    }
Exemplo n.º 2
0
    public bool AddNewXMailDomain()
    {
        string domainName = textDomainName.Value;
        bool   result     = false;

        AdminPanelUtils.SaveState("selectedDomain", null, Page.Session);
        XMLayer xmLayer = XMServer.CreateXMLayer();

        if (_domainType == "vir")
        {
            try
            {
                xmLayer.Login();
                // create custom domain
                StringBuilder redirect = new StringBuilder("redirect");
                if (Request.Params[RedirectionsListDDL.UniqueID] != null)
                {
                    string[] RedirectionsList = Request.Params[RedirectionsListDDL.UniqueID].ToString().Split(',');
                    for (int i = 0; i < RedirectionsList.Length; i++)
                    {
                        redirect.AppendFormat("\t\"{0}\"", RedirectionsList[i]);
                    }
                }

                StringBuilder lredirect = new StringBuilder("lredirect");
                if (Request.Params[LRedirectionsListDDL.UniqueID] != null)
                {
                    string[] LRedirectionsList = Request.Params[LRedirectionsListDDL.UniqueID].ToString().Split(',');
                    for (int i = 0; i < LRedirectionsList.Length; i++)
                    {
                        lredirect.AppendFormat("\t\"{0}\"", LRedirectionsList[i]);
                    }
                }
                string data = string.Format("{0}\r\n{1}\r\n{2}\r\n.\r\n", redirect.ToString(), lredirect.ToString(), AdvancedID.Text);
                xmLayer.SetCustomDomainTab(domainName, data);
                xmLayer.Logout();
                result = true;
            }
            catch (XMailException error)
            {
                Log.WriteException(error);
                AdminPanelUtils.SetPageErrorMessage(this.Page, (error.InnerException != null ? error.InnerException.Message : error.Message));
            }
        }
        else
        {
            try
            {
                xmLayer.Login();
                if (!xmLayer.DomainExist(domainName))
                {
                    xmLayer.AddDomain(domainName);
                }
                xmLayer.Logout();
                result = true;
            }
            catch (XMailException error)
            {
                Log.WriteException(error);
                AdminPanelUtils.SetPageErrorMessage(this.Page, error.Message);
            }

            // create webmail domain
            if (_isWebMailExist && result)
            {
                WebmailSettings wmSettings = (new WebMailSettingsCreator()).CreateWebMailSettings(AdminPanelUtils.GetWebMailDataFolder());

                try
                {
                    Domain dom = Domain.GetDomain(domainName);
                    if (dom == null)
                    {
                        int    SmtpPort = wmSettings.XMailSmtpPort;
                        string SmtpHost = wmSettings.WmServerHost;
                        int    ImapPort = 143;
                        string ImapHost = wmSettings.WmServerHost;
                        Domain new_dom  = new Domain(0, domainName, IncomingMailProtocol.WMServer, ImapHost, ImapPort, SmtpHost, SmtpPort, false);


                        new_dom.Global_addr_book = false;

                        new_dom.Save();
                        result = true;
                    }
                    else
                    {
                        result = false;
                        AdminPanelUtils.SaveState("SessPageErrorMessage", "Such domain already exists.", Page.Session);
                    }
                }
                catch (Exception error)
                {
                    result = false;
                    Log.WriteException(error);
                    AdminPanelUtils.SetPageErrorMessage(this.Page, (error.InnerException != null ? error.InnerException.Message : error.Message));
                }
            }
        }
        if (result == false)
        {
            try
            {
                xmLayer.Login();
                xmLayer.DeleteDomain(domainName);
                xmLayer.Logout();
            }
            catch (Exception error)
            {
                Log.WriteException(error);
            }
        }
        return(result);
    }