public DnsData GetDnsRecords(int id)
        {
            if (!IsAdmin)
            {
                throw new SecurityException("Need admin privileges.");
            }

            if (id < 0)
            {
                throw new ArgumentException(@"Invalid domain id.", "id");
            }

            var domain = MailServer.GetWebDomain(id, MailServerFactory);

            var dns = domain.GetDns(MailServerFactory);

            if (dns == null)
            {
                return(new DnsData());
            }

            var isVerified = dns.CheckDnsStatus();

            if (domain.IsVerified != isVerified)
            {
                domain.SetVerified(isVerified);
            }

            return(dns.ToDnsData());
        }
Exemple #2
0
        public MailGroupData CreateMailGroup(string name, int domain_id, List <int> address_ids)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Invalid mailgroup name.", "name");
            }

            if (domain_id < 0)
            {
                throw new ArgumentException("Invalid domain id.", "domain_id");
            }

            if (name.Length > 64)
            {
                throw new ArgumentException("Local part of mailgroup exceed limitation of 64 characters.", "name");
            }

            if (!Parser.IsEmailLocalPartValid(name))
            {
                throw new ArgumentException("Incorrect group name.", "name");
            }

            if (!address_ids.Any())
            {
                throw new ArgumentException("Empty collection of address_ids.", "address_ids");
            }

            var domain = MailServer.GetWebDomain(domain_id, MailServerFactory);

            var mailgroup_name = name.ToLowerInvariant();

            var mailgroup = MailServer.CreateMailGroup(mailgroup_name, domain, address_ids, MailServerFactory);

            return(mailgroup.ToMailGroupData());
        }
Exemple #3
0
        public MailboxData CreateMailbox(string name, int domain_id, string user_id)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Invalid mailbox name.", "name");
            }

            if (domain_id < 0)
            {
                throw new ArgumentException("Invalid domain id.", "domain_id");
            }

            Guid user;

            if (!Guid.TryParse(user_id, out user))
            {
                throw new ArgumentException("Invalid user id.", "user_id");
            }

            var teamlab_account = CoreContext.Authentication.GetAccountByID(user);

            if (teamlab_account == null)
            {
                throw new InvalidDataException("Unknown user.");
            }

            if (name.Length > 64)
            {
                throw new ArgumentException("Local part of mailbox localpart exceed limitation of 64 characters.", "name");
            }

            if (!Parser.IsEmailLocalPartValid(name))
            {
                throw new ArgumentException("Incorrect mailbox name.");
            }

            var mailbox_name = name.ToLowerInvariant();

            var domain = MailServer.GetWebDomain(domain_id, MailServerFactory);

            var login = string.Format("{0}@{1}", mailbox_name, domain.Name);

            var rand     = new Random();
            var password = Membership.GeneratePassword(12, 0);

            password = Regex.Replace(password, @"[^a-zA-Z0-9]", m => rand.Next(10).ToString());

            var account = MailServerFactory.CreateMailAccount(teamlab_account, login);

            var mailbox = MailServer.CreateMailbox(mailbox_name, password, domain, account, MailServerFactory);

            return(mailbox.ToMailboxData());
        }
        public int RemoveDomain(int id)
        {
            if (id < 0)
            {
                throw new ArgumentException("Invalid domain id.", "id");
            }

            var domain = MailServer.GetWebDomain(id, MailServerFactory);

            MailServer.DeleteWebDomain(domain, MailServerFactory);

            return(id);
        }
        public NotificationAddressData CreateNotificationAddress(string name, string password, int domain_id)
        {
            if (!IsAdmin)
            {
                throw new SecurityException("Need admin privileges.");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name", @"Invalid address username.");
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password", @"Invalid password.");
            }

            if (name.Length > 64)
            {
                throw new ArgumentException(@"Local part of address exceed limitation of 64 characters.", "name");
            }

            if (!Parser.IsEmailLocalPartValid(name))
            {
                throw new ArgumentException(@"Incorrect address username.", "name");
            }

            if (!Parser.IsPasswordValid(password))
            {
                throw new ArgumentException(
                          @"Incorrect password. The password's first character must be a letter," +
                          @" it must contain at least 6 characters and no more than 15 characters " +
                          @"and no characters other than letters, numbers and the underscore may be used",
                          "password");
            }

            var localPart = name.ToLowerInvariant();

            if (domain_id < 0)
            {
                throw new ArgumentException(@"Invalid domain id.", "domain_id");
            }

            var domain = MailServer.GetWebDomain(domain_id, MailServerFactory);

            var notificationAddress = MailServer.CreateNotificationAddress(localPart, password, domain, MailServerFactory);

            return(notificationAddress.ToNotificationAddressData());
        }
Exemple #6
0
        public MailGroupData CreateMailGroup(string name, int domain_id, List <int> address_ids)
        {
            if (!IsAdmin)
            {
                throw new SecurityException("Need admin privileges.");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(@"Invalid mailgroup name.", "name");
            }

            if (domain_id < 0)
            {
                throw new ArgumentException(@"Invalid domain id.", "domain_id");
            }

            if (name.Length > 64)
            {
                throw new ArgumentException(@"Local part of mailgroup exceed limitation of 64 characters.", "name");
            }

            if (!Parser.IsEmailLocalPartValid(name))
            {
                throw new ArgumentException(@"Incorrect group name.", "name");
            }

            if (!address_ids.Any())
            {
                throw new ArgumentException(@"Empty collection of address_ids.", "address_ids");
            }

            var domain = MailServer.GetWebDomain(domain_id, MailServerFactory);

            if (domain.Tenant == Defines.SHARED_TENANT_ID)
            {
                throw new InvalidOperationException("Creating mail group is not allowed for shared domain.");
            }

            var mailgroupName = name.ToLowerInvariant();

            var mailgroup = MailServer.CreateMailGroup(mailgroupName, domain, address_ids, MailServerFactory);

            MailBoxManager.CachedAccounts.ClearAll();

            return(mailgroup.ToMailGroupData());
        }
        public DnsData GetDnsRecords(int id)
        {
            if (id < 0)
            {
                throw new ArgumentException("Invalid domain id.", "id");
            }

            var domain = MailServer.GetWebDomain(id, MailServerFactory);

            var dns = domain.GetDns(MailServerFactory);

            if (dns == null)
            {
                return(new DnsData());
            }

            dns.CheckDnsStatus();

            return(dns.ToDnsData());
        }
        public int RemoveDomain(int id)
        {
            if (!IsAdmin)
            {
                throw new SecurityException("Need admin privileges.");
            }

            if (id < 0)
            {
                throw new ArgumentException(@"Invalid domain id.", "id");
            }

            var domain = MailServer.GetWebDomain(id, MailServerFactory);

            if (domain.Tenant == Defines.SHARED_TENANT_ID)
            {
                throw new SecurityException("Can not remove shared domain.");
            }

            MailServer.DeleteWebDomain(domain, MailServerFactory);

            return(id);
        }
        public MailboxData CreateMailbox(string name, string local_part, int domain_id, string user_id)
        {
            var domain         = MailServer.GetWebDomain(domain_id, MailServerFactory);
            var isSharedDomain = domain.Tenant == Defines.SHARED_TENANT_ID;

            if (!IsAdmin && !isSharedDomain)
            {
                throw new SecurityException("Need admin privileges.");
            }

            if (string.IsNullOrEmpty(local_part))
            {
                throw new ArgumentException(@"Invalid local part.", "local_part");
            }

            if (domain_id < 0)
            {
                throw new ArgumentException(@"Invalid domain id.", "domain_id");
            }

            if (name.Length > 255)
            {
                throw new ArgumentException(@"Sender name exceed limitation of 64 characters.", "name");
            }

            Guid user;

            if (!Guid.TryParse(user_id, out user))
            {
                throw new ArgumentException(@"Invalid user id.", "user_id");
            }

            if (isSharedDomain && !IsAdmin && user != SecurityContext.CurrentAccount.ID)
            {
                throw new SecurityException("Creation of a shared mailbox is allowed only for the current account if user is not admin.");
            }

            var teamlabAccount = CoreContext.Authentication.GetAccountByID(user);

            if (teamlabAccount == null)
            {
                throw new InvalidDataException("Unknown user.");
            }

            var userInfo = CoreContext.UserManager.GetUsers(user);

            if (userInfo.IsVisitor())
            {
                throw new InvalidDataException("User is visitor.");
            }

            if (local_part.Length > 64)
            {
                throw new ArgumentException(@"Local part of mailbox exceed limitation of 64 characters.", "local_part");
            }

            if (!Parser.IsEmailLocalPartValid(local_part))
            {
                throw new ArgumentException("Incorrect local part of mailbox.");
            }

            var mailboxLocalPart = local_part.ToLowerInvariant();

            var login = string.Format("{0}@{1}", mailboxLocalPart, domain.Name);

            var password = PasswordGenerator.GenerateNewPassword(12);

            var account = MailServerFactory.CreateMailAccount(teamlabAccount, login);

            var mailbox = MailServer.CreateMailbox(name, mailboxLocalPart, password, domain, account, MailServerFactory);

            MailBoxManager.CachedAccounts.Clear(mailbox.Account.TeamlabAccount.ID.ToString());

            return(mailbox.ToMailboxData());
        }