Esempio n. 1
0
        public void Create(CompanyPlanObject plan)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                Plans_Organization newPlan = new Plans_Organization();
                newPlan.OrgPlanName                  = plan.CompanyPlanName;
                newPlan.MaxUsers                     = plan.MaxUser;
                newPlan.MaxDomains                   = plan.MaxDomains;
                newPlan.MaxExchangeMailboxes         = plan.MaxExchangeMailboxes;
                newPlan.MaxExchangeContacts          = plan.MaxExchangeContacts;
                newPlan.MaxExchangeDistLists         = plan.MaxExchangeDistributionGroups;
                newPlan.MaxExchangeResourceMailboxes = plan.MaxExchangeResourceMailboxes;
                newPlan.MaxExchangeMailPublicFolders = plan.MaxExchangeMailPublicFolders;

                database.Plans_Organization.Add(newPlan);
                database.SaveChanges();
            }
            catch (Exception ex)
            {
                this.logger.Error("Error saving new company plan " + plan.CompanyPlanName + " to the database.", ex);
                ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 2
0
        public void ResetPassword(string userPrincipalName, string newPassword, string companyCode)
        {
            ADUser     user     = null;
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var sqlUser = (from u in database.Users
                               where u.UserPrincipalName == userPrincipalName
                               select u).First();

                if (sqlUser.CompanyCode.Equals(companyCode, StringComparison.CurrentCultureIgnoreCase))
                {
                    user = new ADUser(StaticSettings.Username, StaticSettings.DecryptedPassword, StaticSettings.PrimaryDC);
                    user.ResetPassword(userPrincipalName, newPassword);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("Error resetting password for " + userPrincipalName, ex);
                ThrowEvent(AlertID.FAILED, ex.Message);
            }
            finally
            {
                if (user != null)
                {
                    user.Dispose();
                }
            }
        }
Esempio n. 3
0
        public void UpdateCompanyPlan(string companyCode, int planID)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var foundCompany = (from c in database.Companies
                                    where !c.IsReseller
                                    where c.CompanyCode == companyCode
                                    select c).FirstOrDefault();

                if (foundCompany != null)
                {
                    foundCompany.OrgPlanID = planID;
                    database.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("Error changing company " + companyCode + "'s plan ID to " + planID.ToString(), ex);
                ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 4
0
        public void DeleteUser(string userPrincipalName)
        {
            CPDatabase database = null;
            ADUser     ldapUser = null;

            try
            {
                ldapUser = new ADUser(StaticSettings.Username, StaticSettings.DecryptedPassword, StaticSettings.PrimaryDC);
                ldapUser.DeleteUser(userPrincipalName);

                // Delete from database
                database = new CPDatabase();
                database.DeleteUser(userPrincipalName);
            }
            catch (Exception ex)
            {
                ThrowEvent(AlertID.FAILED, ex.Message);
            }
            finally
            {
                if (ldapUser != null)
                {
                    ldapUser.Dispose();
                }

                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 5
0
        private void Delete_CompanyFromDatabase(string companyCode)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var foundCompany = (from c in database.Companies
                                    where !c.IsReseller
                                    where c.CompanyCode == companyCode
                                    select c).FirstOrDefault();

                if (foundCompany != null)
                {
                    database.Companies.Remove(foundCompany);
                    database.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("Failed to roll back action... Deleting company from database " + companyCode, ex);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
        public void DisableExchange(string companyCode)
        {
            ExchangePowershell powershell = null;
            CPDatabase         database   = null;

            try
            {
                powershell = new ExchangePowershell(StaticSettings.ExchangeURI, StaticSettings.Username, StaticSettings.DecryptedPassword, StaticSettings.ExchangeUseKerberos, StaticSettings.PrimaryDC);

                // Disable all exchange objects
                powershell.DeleteAllMailboxes(companyCode);
                powershell.DeleteAllContacts(companyCode);
                powershell.DeleteAllGroups(companyCode);
                powershell.DeleteAddressBookPolicy(companyCode + " ABP");
                powershell.DeleteOfflineAddressBook(companyCode + " OAL");
                powershell.DeleteAddressList(companyCode + " - All Rooms");
                powershell.DeleteAddressList(companyCode + " - All Contacts");
                powershell.DeleteAddressList(companyCode + " - All Groups");
                powershell.DeleteAddressList(companyCode + " - All Users");
                powershell.DeleteGlobalAddressList(companyCode + " - GAL");

                // Get all accepted domains
                this.logger.Debug("Retrieving list of accepted domains for " + companyCode);

                database = new CPDatabase();
                var domains = from d in database.Domains
                              where d.IsAcceptedDomain
                              where d.CompanyCode == companyCode
                              select d;

                if (domains != null)
                {
                    foreach (Domain d in domains)
                    {
                        powershell.DeleteDomain(d.Domain1);
                    }
                }

                // Now update the database
                int r = database.DisableExchange(companyCode);
                this.logger.Debug("Total count returned when calling DisableExchange stored procedure: " + r.ToString());
            }
            catch (Exception ex)
            {
                this.logger.Error("Error disabling Exchange for company " + companyCode, ex);
                ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }

                if (powershell != null)
                {
                    powershell.Dispose();
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Checks if a company code exists in the database (reseller or company)
        /// </summary>
        /// <param name="companyCode"></param>
        /// <returns></returns>
        public static bool DoesCompanyCodeExist(string companyCode)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var exists = (from c in database.Companies
                              where c.CompanyCode == companyCode
                              select c.CompanyCode).FirstOrDefault();

                if (!string.IsNullOrEmpty(exists))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 8
0
        private string GetResellerCode(string usersCompanyCode)
        {
            CPDatabase database = null;

            try
            {
                var resellerCode = (from c in database.Companies
                                    where c.CompanyCode == usersCompanyCode
                                    select c.ResellerCode).FirstOrDefault();

                if (resellerCode == null)
                {
                    throw new Exception("Unable to retrieve the reseller code for company " + usersCompanyCode);
                }
                else
                {
                    return(resellerCode);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 9
0
        private bool IsDomainInUse(string domainName)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var domainCount = (from d in database.Domains
                                   where d.Domain1 == domainName
                                   select d).Count();

                if (domainCount > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("Error checking if domain " + domainName + " is in use.", ex);

                throw;
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 10
0
        private void AuditLogin(string username, string ipAddress, bool isValidLogin)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                // Audit login
                AuditLogin audit = new AuditLogin();
                audit.IPAddress      = ipAddress;
                audit.Username       = username;
                audit.LoginStatus    = isValidLogin;
                audit.AuditTimeStamp = DateTime.Now;

                database.AuditLogins.Add(audit);
                database.SaveChanges();

                this.logger.Debug(username + "attempted to login to CloudPanel. Is valid login? " + isValidLogin.ToString());
            }
            catch (Exception ex)
            {
                this.logger.Error("Error adding entry to the login audit table.", ex);

                throw;
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 11
0
        private int?NumberOfTimesPlanInUse(int planID)
        {
            CPDatabase database = null;

            try
            {
                this.logger.Debug("Checking if plan is in use: " + planID.ToString());

                database = new CPDatabase();

                var findPlan = (from p in database.Companies
                                where p.OrgPlanID == planID
                                select p).Count();

                return(findPlan);
            }
            catch (Exception ex)
            {
                this.logger.Error("Error counting the number of times plan " + planID.ToString() + " is in use.", ex);
                ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 12
0
        public static void AddAudit(string companyCode, string username, ActionID actionID, string variable1, string variable2 = null)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                Audit newAudit = new Audit();
                newAudit.CompanyCode = companyCode;
                newAudit.Username    = username;
                newAudit.Date        = DateTime.Now;
                newAudit.ActionID    = (int)actionID;
                newAudit.Variable1   = variable1;
                newAudit.Variable2   = variable2;

                database.Audits.Add(newAudit);
                database.SaveChanges();
            }
            catch (Exception ex)
            {
                logger.Info("Failed to add audit to database: " + actionID.ToString(), ex);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 13
0
        public UsersObject GetUser(string userPrincipalName)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                // Get from the database
                var findUser = (from u in database.Users
                                from p in database.UserPermissions.Where(m => m.UserID == u.ID).DefaultIfEmpty()
                                where u.UserPrincipalName == userPrincipalName
                                orderby u.DisplayName
                                select new UsersObject()
                {
                    UserGuid = u.UserGuid,
                    CompanyCode = u.CompanyCode,
                    sAMAccountName = u.sAMAccountName,
                    UserPrincipalName = u.UserPrincipalName,
                    Firstname = u.Firstname,
                    Middlename = u.Middlename,
                    Lastname = u.Lastname,
                    DisplayName = u.DisplayName,
                    Department = u.Department,
                    DistinguishedName = u.DistinguishedName,
                    Created = u.Created,
                    IsEnabled = u.IsEnabled == null ? true : (bool)u.IsEnabled,
                    IsCompanyAdmin = u.IsCompanyAdmin == null ? false : (bool)u.IsCompanyAdmin,
                    IsResellerAdmin = u.IsResellerAdmin == null ? false : (bool)u.IsResellerAdmin,
                    MailboxPlan = u.MailboxPlan == null ? 0 : (int)u.MailboxPlan,
                    AdditionalMB = u.AdditionalMB == null ? 0 : (int)u.AdditionalMB,
                    ActiveSyncPlan = u.ActiveSyncPlan == null ? 0 : (int)u.ActiveSyncPlan,
                    EnableExchangePerm = p.EnableExchange == null ? false : p.EnableExchange,
                    DisableExchangePerm = p.DisableExchange == null ? false : p.DisableExchange,
                    AddDomainPerm = p.AddDomain == null ? false : p.AddDomain,
                    DeleteDomainPerm = p.DeleteDomain == null ? false : p.DeleteDomain,
                    EnableAcceptedDomainPerm = p.EnableAcceptedDomain == null ? false : p.EnableAcceptedDomain,
                    DisableAcceptedDomainPerm = p.DisableAcceptedDomain == null ? false : p.DisableAcceptedDomain
                }).FirstOrDefault();

                return(findUser);
            }
            catch (Exception ex)
            {
                this.logger.Error("Failed to retrieve user " + userPrincipalName, ex);
                ThrowEvent(AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 14
0
        public void DisableMailbox(string userPrincipalName)
        {
            CPDatabase         database   = null;
            ExchangePowershell powershell = null;

            try
            {
                database = new CPDatabase();

                // Get the user from the database
                var foundUser = (from u in database.Users
                                 where u.UserPrincipalName == userPrincipalName
                                 select u).FirstOrDefault();

                if (foundUser == null)
                {
                    ThrowEvent(AlertID.FAILED, "Unable to find user " + userPrincipalName);
                }
                else
                {
                    this.logger.Debug("Found user " + foundUser.UserPrincipalName + " in the database. Continuing...");

                    if (foundUser.MailboxPlan < 1)
                    {
                        this.logger.Debug("User " + foundUser.UserPrincipalName + " does not have a mailbox. Skipping...");
                    }
                    else
                    {
                        powershell = new ExchangePowershell(StaticSettings.ExchangeURI, StaticSettings.Username, StaticSettings.DecryptedPassword, StaticSettings.ExchangeUseKerberos, StaticSettings.PrimaryDC);
                        powershell.DeleteMailbox(foundUser.UserPrincipalName);

                        int r = database.DisableMailbox(foundUser.UserPrincipalName);

                        this.logger.Debug("Returned a total of " + r.ToString() + " records when calling DisableMailbox stored procedure for " + foundUser.UserPrincipalName);
                    }
                }
            }
            catch (Exception ex)
            {
                this.logger.Debug("Error deleting mailbox for " + userPrincipalName, ex);
                ThrowEvent(AlertID.FAILED, ex.Message);
            }
            finally
            {
                if (powershell != null)
                {
                    powershell.Dispose();
                }

                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Gets a list of resellers from the database
        /// </summary>
        /// <returns></returns>
        public List <ResellerObject> GetResellers()
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var resellersDb = from r in database.Companies
                                  where r.IsReseller
                                  orderby r.CompanyName
                                  select r;

                List <ResellerObject> resellers = new List <ResellerObject>();

                if (resellersDb != null)
                {
                    foreach (var reseller in resellersDb)
                    {
                        ResellerObject tmp = new ResellerObject();
                        tmp.CompanyID         = reseller.CompanyId;
                        tmp.CompanyName       = reseller.CompanyName;
                        tmp.CompanyCode       = reseller.CompanyCode;
                        tmp.Street            = reseller.Street;
                        tmp.City              = reseller.City;
                        tmp.State             = reseller.State;
                        tmp.ZipCode           = reseller.ZipCode;
                        tmp.Country           = reseller.Country;
                        tmp.Telephone         = reseller.PhoneNumber;
                        tmp.Description       = reseller.Description;
                        tmp.AdminName         = reseller.AdminName;
                        tmp.AdminEmail        = reseller.AdminEmail;
                        tmp.DistinguishedName = reseller.DistinguishedName;
                        tmp.Created           = reseller.Created;

                        resellers.Add(tmp);
                    }
                }

                return(resellers);
            }
            catch (Exception ex)
            {
                ThrowEvent(AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Gets a specific company
        /// </summary>
        /// <param name="companyCode"></param>
        /// <returns></returns>
        public CompanyObject GetCompany(string companyCode)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var company = (from c in database.Companies
                               from d in database.Domains.Where(a => a.CompanyCode == c.CompanyCode).DefaultIfEmpty()
                               where !c.IsReseller
                               where c.CompanyCode == companyCode
                               orderby c.CompanyName
                               select new CompanyObject()
                {
                    CompanyID = c.CompanyId,
                    CompanyName = c.CompanyName,
                    CompanyCode = c.CompanyCode,
                    Street = c.Street,
                    City = c.City,
                    State = c.State,
                    ZipCode = c.ZipCode,
                    Country = c.Country,
                    Telephone = c.PhoneNumber,
                    Description = c.Description,
                    AdminName = c.AdminName,
                    AdminEmail = c.AdminEmail,
                    DistinguishedName = c.DistinguishedName,
                    Created = c.Created
                }).FirstOrDefault();

                var domains = from d in database.Domains
                              where d.CompanyCode == company.CompanyCode
                              select d;

                company.Domains = (from d in domains select d.Domain1).ToArray();

                return(company);
            }
            catch (Exception ex)
            {
                this.logger.Error("Error retrieving company " + companyCode, ex);

                ThrowEvent(AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 17
0
        public bool UpdatePlan(MailboxPlanObject obj)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var plan = (from p in database.Plans_ExchangeMailbox
                            where p.MailboxPlanID == obj.MailboxPlanID
                            select p).First();

                plan.MailboxPlanName     = obj.MailboxPlanName;
                plan.CompanyCode         = obj.CompanyCode;
                plan.MailboxPlanDesc     = obj.MailboxPlanDescription;
                plan.MaxRecipients       = obj.MaxRecipients;
                plan.MaxKeepDeletedItems = obj.MaxKeepDeletedItemsInDays;
                plan.MailboxSizeMB       = obj.MailboxSizeInMB;
                plan.MaxMailboxSizeMB    = obj.MaxMailboxSizeInMB;
                plan.MaxSendKB           = obj.MaxSendInKB;
                plan.MaxReceiveKB        = obj.MaxReceiveInKB;
                plan.EnablePOP3          = obj.EnablePOP3;
                plan.EnableIMAP          = obj.EnableIMAP;
                plan.EnableOWA           = obj.EnableOWA;
                plan.EnableMAPI          = obj.EnableMAPI;
                plan.EnableAS            = obj.EnableAS;
                plan.EnableECP           = obj.EnableECP;
                plan.Cost              = obj.Cost;
                plan.Price             = obj.Price;
                plan.AdditionalGBPrice = obj.AdditionalGBPrice;

                database.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                this.logger.Error("Error saving mailbox plan id " + obj.MailboxPlanID, ex);
                ThrowEvent(AlertID.FAILED, ex.Message);

                return(false);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 18
0
        public UsersObject[] Search(string searchResult)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                // Compile a list of companies
                var companies = from c in database.Companies
                                select c;

                // Compile a list of users
                var users = from u in database.Users
                            from c in database.Companies.Where(cc => cc.CompanyCode == u.CompanyCode).DefaultIfEmpty()
                            where u.UserPrincipalName.Contains(searchResult) || u.Firstname.Contains(searchResult) || u.Lastname.Contains(searchResult)
                            select new UsersObject
                {
                    UserPrincipalName = u.UserPrincipalName,
                    Firstname         = u.Firstname,
                    Lastname          = u.Lastname,
                    CompanyCode       = u.CompanyCode,
                    CompanyName       = c.CompanyName,
                    ResellerCode      = c.ResellerCode
                };

                if (users != null)
                {
                    return(users.ToArray());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                ThrowEvent(AlertID.FAILED, ex.Message);
                this.logger.Error("Error searching for " + searchResult, ex);

                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 19
0
        public MailboxPlanObject GetPlan(int planID)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var plan = (from p in database.Plans_ExchangeMailbox
                            where p.MailboxPlanID == planID
                            select new MailboxPlanObject()
                {
                    MailboxPlanID = p.MailboxPlanID,
                    MailboxPlanName = p.MailboxPlanName,
                    CompanyCode = p.CompanyCode,
                    MailboxPlanDescription = p.MailboxPlanDesc,
                    MaxRecipients = p.MaxRecipients,
                    MaxKeepDeletedItemsInDays = p.MaxKeepDeletedItems,
                    MailboxSizeInMB = p.MailboxSizeMB,
                    MaxMailboxSizeInMB = p.MaxMailboxSizeMB == null ? p.MailboxSizeMB : (int)p.MaxMailboxSizeMB,
                    MaxSendInKB = p.MaxSendKB,
                    MaxReceiveInKB = p.MaxReceiveKB,
                    EnablePOP3 = p.EnablePOP3,
                    EnableIMAP = p.EnableIMAP,
                    EnableOWA = p.EnableOWA,
                    EnableMAPI = p.EnableMAPI,
                    EnableAS = p.EnableAS,
                    EnableECP = p.EnableECP,
                    Cost = p.Cost,
                    Price = p.Price,
                    AdditionalGBPrice = p.AdditionalGBPrice
                }).First();

                return(plan);
            }
            catch (Exception ex)
            {
                this.logger.Error("Error retrieving mailbox plans", ex);
                ThrowEvent(AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 20
0
        public MailboxPlanObject GetMailboxPlan(int planID)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var foundPlan = (from p in database.Plans_ExchangeMailbox
                                 where p.MailboxPlanID == planID
                                 orderby p.MailboxPlanName
                                 select new MailboxPlanObject()
                {
                    MailboxPlanID = p.MailboxPlanID,
                    MailboxPlanName = p.MailboxPlanName,
                    MailboxPlanDescription = p.MailboxPlanDesc,
                    CompanyCode = p.CompanyCode,
                    Cost = string.IsNullOrEmpty(p.Cost) ? "0.00" : p.Cost,
                    Price = string.IsNullOrEmpty(p.Price) ? "0.00" : p.Price,
                    AdditionalGBPrice = string.IsNullOrEmpty(p.AdditionalGBPrice) ? "0.00" : p.AdditionalGBPrice,
                    MailboxSizeInMB = p.MailboxSizeMB,
                    MaxMailboxSizeInMB = p.MaxMailboxSizeMB == null ? p.MailboxSizeMB : (int)p.MaxMailboxSizeMB,
                    MaxSendInKB = p.MaxSendKB,
                    MaxReceiveInKB = p.MaxReceiveKB,
                    MaxRecipients = p.MaxRecipients,
                    EnablePOP3 = p.EnablePOP3,
                    EnableIMAP = p.EnableIMAP,
                    EnableOWA = p.EnableOWA,
                    EnableAS = p.EnableAS,
                    EnableECP = p.EnableECP,
                    MaxKeepDeletedItemsInDays = p.MaxKeepDeletedItems
                }).First();

                return(foundPlan);
            }
            catch (Exception ex)
            {
                this.logger.Error("Error trying to retrieve mailbox plan " + planID.ToString(), ex);
                ThrowEvent(AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 21
0
        public List <UsersObject> GetUsers(string companyCode)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var foundUsers = from u in database.Users
                                 where u.CompanyCode == companyCode
                                 orderby u.DisplayName
                                 select new UsersObject()
                {
                    CompanyCode       = u.CompanyCode,
                    sAMAccountName    = u.sAMAccountName,
                    UserPrincipalName = u.UserPrincipalName,
                    DisplayName       = u.DisplayName,
                    Department        = u.Department,
                    IsEnabled         = u.IsEnabled == null ? true : (bool)u.IsEnabled,
                    IsResellerAdmin   = u.IsResellerAdmin == null ? false : (bool)u.IsResellerAdmin,
                    IsCompanyAdmin    = u.IsCompanyAdmin == null ? false : (bool)u.IsCompanyAdmin,
                    MailboxPlan       = u.MailboxPlan == null ? 0 : (int)u.MailboxPlan,
                    LyncPlan          = u.LyncPlan == null ? 0 : (int)u.LyncPlan
                };

                if (foundUsers != null)
                {
                    return(foundUsers.ToList());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("Failed to retrieve users for company " + companyCode, ex);
                ThrowEvent(AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 22
0
        private bool IsBlockedFromBruteForce(string ipAddress)
        {
            CPDatabase database = null;

            try
            {
                if (StaticSettings.IPBlockingEnabled)
                {
                    database = new CPDatabase();

                    var isBlocked = from b in database.AuditLogins
                                    where b.IPAddress == ipAddress
                                    where b.AuditTimeStamp >= DbFunctions.AddMinutes(DateTime.Now, -StaticSettings.IPBlockingLockedInMinutes)
                                    where b.LoginStatus == false
                                    orderby b.AuditTimeStamp descending
                                    select b;

                    if (isBlocked == null)
                    {
                        return(false);
                    }
                    else
                    {
                        logger.Debug("Found a total of " + isBlocked.Count() + " entries in the database for IP Address " + ipAddress);

                        if (isBlocked.Count() >= StaticSettings.IPBlockingFailedCount)
                        {
                            ThrowEvent(AlertID.FAILED, ipAddress + " is blocked due to too many failed login attempts");
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                ThrowEvent(AlertID.FAILED, ex.Message);
                return(true);
            }
        }
Esempio n. 23
0
        public List <MailboxPlanObject> GetMailboxPlans(string companyCode)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var foundPlans = from p in database.Plans_ExchangeMailbox
                                 where p.CompanyCode == companyCode || string.IsNullOrEmpty(p.CompanyCode)
                                 orderby p.MailboxPlanName
                                 select new MailboxPlanObject()
                {
                    MailboxPlanID          = p.MailboxPlanID,
                    MailboxPlanName        = p.MailboxPlanName,
                    MailboxPlanDescription = p.MailboxPlanDesc,
                    CompanyCode            = p.CompanyCode,
                    Cost               = string.IsNullOrEmpty(p.Cost) ? "0.00" : p.Cost,
                    Price              = string.IsNullOrEmpty(p.Price) ? "0.00": p.Price,
                    AdditionalGBPrice  = string.IsNullOrEmpty(p.AdditionalGBPrice) ? "0.00" : p.AdditionalGBPrice,
                    MailboxSizeInMB    = p.MailboxSizeMB,
                    MaxMailboxSizeInMB = p.MaxMailboxSizeMB == null ? p.MailboxSizeMB : (int)p.MaxMailboxSizeMB
                };

                if (foundPlans != null)
                {
                    return(foundPlans.ToList());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("Error trying to retrieve mailbox plans for company " + companyCode, ex);
                ThrowEvent(AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
        public List <ApplicationsObject> GetCitrixApplications(string companyCode)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var foundApplications = (from a in database.Plans_Citrix
                                         where a.CompanyCode == null || a.CompanyCode == companyCode
                                         orderby a.Name
                                         select new ApplicationsObject()
                {
                    CitrixPlanID = a.CitrixPlanID,
                    DisplayName = a.Name,
                    GroupName = a.GroupName,
                    Description = a.Description,
                    IsServer = a.IsServer,
                    CompanyCode = a.CompanyCode,
                    Price = a.Price,
                    Cost = a.Cost,
                    PictureURL = a.PictureURL
                });

                if (foundApplications != null)
                {
                    return(foundApplications.ToList());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("Error retrieving Citrix applications for company " + companyCode, ex);
                ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 25
0
        public CompanyPlanObject GetPlan(int planID)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var foundPlans = (from a in database.Plans_Organization
                                  where a.OrgPlanID == planID
                                  select new CompanyPlanObject()
                {
                    CompanyPlanID = a.OrgPlanID,
                    CompanyPlanName = a.OrgPlanName,
                    MaxUser = a.MaxUsers,
                    MaxDomains = a.MaxDomains,
                    MaxExchangeMailboxes = a.MaxExchangeMailboxes,
                    MaxExchangeContacts = a.MaxExchangeContacts,
                    MaxExchangeDistributionGroups = a.MaxExchangeDistLists,
                    MaxExchangeMailPublicFolders = a.MaxExchangeMailPublicFolders,
                    MaxExchangeResourceMailboxes = a.MaxExchangeResourceMailboxes == null ? 0 : (int)a.MaxExchangeResourceMailboxes
                }).FirstOrDefault();

                if (foundPlans != null)
                {
                    return(foundPlans);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("Error retrieving organization plan " + planID.ToString(), ex);
                ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 26
0
        public List <CompanyPlanObject> GetAllPlans()
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var foundPlans = (from a in database.Plans_Organization
                                  orderby a.OrgPlanName
                                  select new CompanyPlanObject()
                {
                    CompanyPlanID = a.OrgPlanID,
                    CompanyPlanName = a.OrgPlanName,
                    MaxUser = a.MaxUsers,
                    MaxDomains = a.MaxDomains,
                    MaxExchangeMailboxes = a.MaxExchangeMailboxes,
                    MaxExchangeContacts = a.MaxExchangeContacts,
                    MaxExchangeDistributionGroups = a.MaxExchangeDistLists,
                    MaxExchangeMailPublicFolders = a.MaxExchangeMailPublicFolders,
                    MaxExchangeResourceMailboxes = a.MaxExchangeResourceMailboxes == null ? 0 : (int)a.MaxExchangeResourceMailboxes
                });

                if (foundPlans != null)
                {
                    return(foundPlans.ToList());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("Error retrieving organization plans from the database", ex);
                ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Gets a specific reseller
        /// </summary>
        /// <param name="companyCode"></param>
        /// <returns></returns>
        public ResellerObject GetReseller(string companyCode)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var reseller = (from r in database.Companies
                                where r.IsReseller
                                where r.CompanyCode == companyCode
                                orderby r.CompanyName
                                select r).FirstOrDefault();

                ResellerObject tmp = new ResellerObject();
                tmp.CompanyID         = reseller.CompanyId;
                tmp.CompanyName       = reseller.CompanyName;
                tmp.CompanyCode       = reseller.CompanyCode;
                tmp.Street            = reseller.Street;
                tmp.City              = reseller.City;
                tmp.State             = reseller.State;
                tmp.ZipCode           = reseller.ZipCode;
                tmp.Country           = reseller.Country;
                tmp.Telephone         = reseller.PhoneNumber;
                tmp.Description       = reseller.Description;
                tmp.AdminName         = reseller.AdminName;
                tmp.AdminEmail        = reseller.AdminEmail;
                tmp.DistinguishedName = reseller.DistinguishedName;
                tmp.Created           = reseller.Created;

                return(tmp);
            }
            catch (Exception ex)
            {
                ThrowEvent(AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 28
0
        public List <DomainsObject> GetDomains(string companyCode)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                var foundDomains = from d in database.Domains
                                   where d.CompanyCode == companyCode
                                   orderby d.Domain1
                                   select new DomainsObject()
                {
                    DomainID         = d.DomainID,
                    CompanyCode      = d.CompanyCode,
                    DomainName       = d.Domain1,
                    IsSubDomain      = d.IsSubDomain == null ? false : (bool)d.IsSubDomain,
                    IsDefault        = d.IsDefault,
                    IsAcceptedDomain = d.IsAcceptedDomain,
                    TypeOfDomain     = d.DomainType == null ? DomainType.Unknown : (DomainType)d.DomainType
                };

                if (foundDomains != null)
                {
                    return(foundDomains.ToList());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("Error trying to retrieve domains for company " + companyCode, ex);
                ThrowEvent(AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 29
0
        public OverallStats GetCompanyStats(string companyCode)
        {
            CPDatabase database = null;

            try
            {
                database = new CPDatabase();

                OverallStats companyStats = new OverallStats();

                companyStats.TotalUsers = (from s in database.Users
                                           where s.CompanyCode == companyCode
                                           select s.UserPrincipalName).Count();

                companyStats.TotalDomains = (from d in database.Domains
                                             where d.CompanyCode == companyCode
                                             select d.Domain1).Count();

                companyStats.TotalMailboxes = (from m in database.Users
                                               where m.CompanyCode == companyCode
                                               where m.MailboxPlan > 0
                                               select m.UserPrincipalName).Count();

                companyStats.TotalLyncUsers = (from l in database.Users
                                               where l.CompanyCode == companyCode
                                               where l.LyncPlan > 0
                                               select l.UserPrincipalName).Count();


                return(companyStats);
            }
            catch (Exception ex)
            {
                this.logger.Error("Error retrieving company statistics from the database for " + companyCode, ex);
                ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message);
                return(null);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 30
0
        public void NewContact(string companyCode, MailContactObject mailContact)
        {
            ExchangePowershell powershell = null;
            CPDatabase         database   = null;

            try
            {
                // Get company distinguished name
                database = new CPDatabase();
                var dn = (from c in database.Companies
                          where !c.IsReseller
                          where c.CompanyCode == companyCode
                          select c.DistinguishedName).First();

                powershell = new ExchangePowershell(StaticSettings.ExchangeURI, StaticSettings.Username, StaticSettings.DecryptedPassword, StaticSettings.ExchangeUseKerberos, StaticSettings.PrimaryDC);
                string distinguishedName = powershell.NewContact(mailContact.DisplayName, mailContact.Email, mailContact.Hidden, companyCode, "OU=Exchange," + dn);

                // Add contact to database
                Contact newContact = new Contact();
                newContact.DisplayName       = mailContact.DisplayName;
                newContact.CompanyCode       = companyCode;
                newContact.DistinguishedName = distinguishedName;
                newContact.Email             = mailContact.Email;
                newContact.Hidden            = mailContact.Hidden;
                database.Contacts.Add(newContact);
                database.SaveChanges();
            }
            catch (Exception ex)
            {
                ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message);
            }
            finally
            {
                if (database != null)
                {
                    database.Dispose();
                }

                if (powershell != null)
                {
                    powershell.Dispose();
                }
            }
        }