Пример #1
0
        public bool DomainExists(string domainName)
        {
            Tree      config    = AMSHelper.GetDomainsConfig();
            AmsDomain amsDomain = new AmsDomain(domainName);

            return(amsDomain.Load(config));
        }
Пример #2
0
        public void AddDomainAlias(string domainName, string aliasName)
        {
            Tree      domains = AMSHelper.GetDomainsConfig();
            AmsDomain alias   = new AmsDomain(aliasName);

            if (!alias.Load(domains))
            {
                alias.DomainConfig["enabled"]          = "1";
                alias.DomainConfig["domain"]           = aliasName;
                alias.DomainConfig["mode"]             = "1";     // alias mode
                alias.DomainConfig["useconvertdomain"] = "1";
                alias.DomainConfig["convertdomain"]    = domainName;

                if (!alias.Save(domains))
                {
                    Log.WriteInfo("Couldn't save domains configuration.");
                    throw new Exception("Couldn't add domain alias.");
                }
            }
            else
            {
                Log.WriteInfo("Alias already exists.");
                throw new Exception("Alias already exists.");
            }
        }
Пример #3
0
        public MailDomain GetDomain(string domainName)
        {
            Tree      config    = AMSHelper.GetDomainsConfig();
            AmsDomain amsDomain = new AmsDomain(domainName);

            if (amsDomain.Load(config))
            {
                return(amsDomain.ToMailDomain());
            }

            return(null);
        }
Пример #4
0
        public bool DomainAliasExists(string domainName, string aliasName)
        {
            Tree      config   = AMSHelper.GetDomainsConfig();
            AmsDomain amsAlias = new AmsDomain(aliasName);

            if (amsAlias.Load(config))
            {
                if (string.Compare(amsAlias.DomainConfig["convertdomain"], domainName, true) == 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #5
0
        public void CreateDomain(MailDomain domain)
        {
            Tree      domains   = AMSHelper.GetDomainsConfig();
            AmsDomain amsDomain = new AmsDomain(domain.Name);

            if (amsDomain.Load(domains))
            {
                throw new Exception("Domain is already registered.");
            }

            amsDomain.Read(domain);

            if (!amsDomain.Save(domains))
            {
                throw new Exception("Couldn't create a domain.");
            }
        }
Пример #6
0
        public void DeleteDomain(string domainName)
        {
            Tree      config    = AMSHelper.GetDomainsConfig();
            AmsDomain amsDomain = new AmsDomain(domainName);

            if (amsDomain.Load(config))
            {
                if (!amsDomain.Delete(config))
                {
                    throw new Exception("Couldn't delete specified domain.");
                }
            }
            else
            {
                throw new Exception("Couldn't find specified domain.");
            }
        }
Пример #7
0
        public void UpdateDomain(MailDomain domain)
        {
            Tree      config    = AMSHelper.GetDomainsConfig();
            AmsDomain amsDomain = new AmsDomain(domain.Name);

            if (amsDomain.Load(config))
            {
                amsDomain.Read(domain);

                if (!amsDomain.Save(config))
                {
                    throw new Exception("Couldn't update specified domain.");
                }
            }
            else
            {
                throw new Exception("Couldn't find specified domain.");
            }
        }
Пример #8
0
        public void DeleteDomainAlias(string domainName, string aliasName)
        {
            Tree      config   = AMSHelper.GetDomainsConfig();
            AmsDomain amsAlias = new AmsDomain(aliasName);

            if (amsAlias.Load(config))
            {
                string amsDomain = amsAlias.DomainConfig["convertdomain"];
                if (string.Compare(amsDomain, domainName, true) == 0)
                {
                    if (!amsAlias.DeleteAlias(config))
                    {
                        throw new Exception("Couldn't delete alias.");
                    }
                }
            }
            else
            {
                throw new Exception("Couldn't find specified alias.");
            }
        }