private Guid?GetUserAgentId(CcmDbContext db, string userAgent) { userAgent = (userAgent ?? string.Empty).Trim(); var allUserAgents = db.UserAgents .Where(ua => !string.IsNullOrEmpty(ua.Identifier)) .Select(ua => new UserAgentInfo { UserAgentId = ua.Id, MatchType = ua.MatchType, Identifier = ua.Identifier }) .ToList(); var dbUserAgent = allUserAgents.FirstOrDefault(u => u.MatchType == MatchType.BeginsWith && userAgent.StartsWith(u.Identifier)); if (dbUserAgent != null) { return(dbUserAgent.UserAgentId); } dbUserAgent = allUserAgents.FirstOrDefault(u => u.MatchType == MatchType.EndsWith && userAgent.EndsWith(u.Identifier)); if (dbUserAgent != null) { return(dbUserAgent.UserAgentId); } dbUserAgent = allUserAgents.FirstOrDefault(u => u.MatchType == MatchType.Contains && userAgent.Contains(u.Identifier)); return(dbUserAgent?.UserAgentId); }
private void GetProfileEntitiesFromProfiles(CcmDbContext db, UserAgentEntity userAgent, IEnumerable <Profile> profiles) { userAgent.OrderedProfiles = userAgent.OrderedProfiles ?? new Collection <UserAgentProfileOrderEntity>(); userAgent.OrderedProfiles.Clear(); int sortIndex = 0; foreach (Profile profile in profiles) { var dbProfile = db.Profiles.SingleOrDefault(p => p.Id == profile.Id); if (dbProfile == null) { continue; } userAgent.OrderedProfiles.Add(new UserAgentProfileOrderEntity() { Profile = dbProfile, UserAgent = userAgent, SortIndex = sortIndex }); sortIndex++; } }
private void CcmUserToUser(CcmDbContext cxt, CcmUser ccmUser, UserEntity dbUser, bool currentUserLocalAdmin = false) { dbUser.RadiusId = ccmUser.RadiusId; dbUser.Comment = ccmUser.Comment; dbUser.DisplayName = ccmUser.DisplayName; dbUser.FirstName = ccmUser.FirstName; dbUser.LastName = ccmUser.LastName; dbUser.Id = new Guid(ccmUser.Id); dbUser.UserName = ccmUser.UserName; dbUser.UserType = ccmUser.UserType; dbUser.Owner = ccmUser.Owner != null?cxt.Owners.SingleOrDefault(o => o.Id == ccmUser.Owner.Id) : null; dbUser.LocalUser = ccmUser.LocalUser; dbUser.CodecType = ccmUser.CodecType != null?cxt.CodecTypes.SingleOrDefault(c => c.Id == ccmUser.CodecType.Id) : null; dbUser.AccountLocked = ccmUser.AccountLocked; dbUser.UpdatedBy = ccmUser.UpdatedBy; dbUser.UpdatedOn = DateTime.UtcNow; ccmUser.UpdatedOn = dbUser.UpdatedOn; var role = string.IsNullOrWhiteSpace(ccmUser.RoleId) ? null : cxt.Roles.SingleOrDefault(r => r.Id == new Guid(ccmUser.RoleId)); // Only admins allowed to assign admin role to account if (currentUserLocalAdmin || role == null || role.Name != ApplicationConstants.Admin) { dbUser.Role = role; } }
public static string GetRandomLocationIpAddress() { var locations = new CcmDbContext(null).Locations.Select(l => l.Net_Address_v4).ToList(); int randomIndex = new Random().Next(0, locations.Count); var locationAddress = locations[randomIndex]; return(locationAddress); }
public static string GetRandomUserName() { var users = new CcmDbContext(null).SipAccounts.Select(u => u.UserName).ToList(); int randomIndex = new Random().Next(0, users.Count); var userName = users[randomIndex]; return(userName); }
private void AddCallInfoToCachedRegisteredSip(CcmDbContext db, IEnumerable <RegisteredSipDto> registeredSips) { var sipDomain = SettingsManager.SipDomain; var dbCalls = db.Calls .Include(c => c.FromSip) .Include(c => c.FromSip.Location) .Include(c => c.FromSip.UserAgent) .Include(c => c.ToSip) .Include(c => c.ToSip.Location) .Include(c => c.ToSip.UserAgent) .Where(call => !call.Closed) .ToList(); foreach (var item in registeredSips) { var sip = item; var call = dbCalls.FirstOrDefault(c => c.ToUsername == sip.Sip || c.FromUsername == sip.Sip); if (call == null) { sip.InCall = false; continue; } sip.InCall = true; sip.IsPhoneCall = sip.IsPhoneCall; sip.CallStartedAt = call.Started; if (call.FromUsername == sip.Sip) { sip.InCallWithId = GuidHelper.GuidString(call.ToId); sip.InCallWithName = CallDisplayNameHelper.GetDisplayName(call.ToSip, call.ToDisplayName, call.ToUsername, sipDomain); sip.InCallWithSip = call.ToUsername; sip.InCallWithLocation = call.ToSip != null && call.ToSip.Location != null ? call.ToSip.Location.Name : string.Empty; sip.InCallWithHasGpo = call.ToSip != null && call.ToSip.UserAgent != null && !string.IsNullOrEmpty(call.ToSip.UserAgent.GpoNames); sip.IsCallingPart = true; } else { sip.InCallWithId = GuidHelper.GuidString(call.FromId); sip.InCallWithName = CallDisplayNameHelper.GetDisplayName(call.FromSip, call.FromDisplayName, call.FromUsername, sipDomain); sip.InCallWithSip = call.FromUsername; sip.InCallWithLocation = call.FromSip != null && call.FromSip.Location != null ? call.FromSip.Location.Name : string.Empty; sip.InCallWithHasGpo = call.FromSip != null && call.FromSip.UserAgent != null && !string.IsNullOrEmpty(call.FromSip.UserAgent.GpoNames); sip.IsCallingPart = false; } } }
private void DeleteRegisteredSip(Expression <Func <RegisteredSipEntity, bool> > expression) { using (var db = new CcmDbContext(new CachingService())) { var regSip = db.RegisteredSips.SingleOrDefault(expression); if (regSip != null) { db.RegisteredSips.Remove(regSip); db.SaveChanges(); } } }
private void GetDbCodecPresetsFromCodecPresets(CcmDbContext db, UserAgentEntity userAgent, IEnumerable <CodecPreset> codecPresets) { userAgent.CodecPresets = userAgent.CodecPresets ?? new Collection <CodecPresetEntity>(); userAgent.CodecPresets.Clear(); foreach (var codecPreset in codecPresets) { var dbCodecPreset = db.CodecPresets.SingleOrDefault(c => c.Id == codecPreset.Id); if (dbCodecPreset == null) { continue; } userAgent.CodecPresets.Add(dbCodecPreset); } }
private void SetEntityFromSipAccount(CcmDbContext cxt, SipAccount account, SipAccountEntity dbAccount) { dbAccount.Id = account.Id; dbAccount.UserName = account.UserName; dbAccount.Comment = account.Comment; dbAccount.ExtensionNumber = account.ExtensionNumber; dbAccount.DisplayName = account.DisplayName; dbAccount.Owner = account.Owner != null?cxt.Owners.SingleOrDefault(o => o.Id == account.Owner.Id) : null; dbAccount.CodecType = account.CodecType != null?cxt.CodecTypes.SingleOrDefault(c => c.Id == account.CodecType.Id) : null; dbAccount.AccountLocked = account.AccountLocked; dbAccount.AccountType = account.AccountType; if (!string.IsNullOrEmpty(account.Password)) { dbAccount.Password = account.Password; } }
private KamailioMessageChangeStatus GetChangeStatus(CcmDbContext cxt, Entities.RegisteredSipEntity dbSip) { var entry = cxt.Entry(dbSip); if (entry.State == EntityState.Added || CodecWasExpired(entry)) { return(KamailioMessageChangeStatus.CodecAdded); } if (entry.State == EntityState.Modified && dbSip.Expires == 0) { return(KamailioMessageChangeStatus.CodecRemoved); } if (entry.State == EntityState.Modified && HasRelevantChange(entry)) { return(KamailioMessageChangeStatus.CodecUpdated); } return(KamailioMessageChangeStatus.NothingChanged); }
private void MapUserEntity(CcmDbContext cxt, CcmUser ccmUser, UserEntity dbUser) { dbUser.UserName = ccmUser.UserName; dbUser.FirstName = ccmUser.FirstName; dbUser.LastName = ccmUser.LastName; dbUser.Comment = ccmUser.Comment; var role = string.IsNullOrWhiteSpace(ccmUser.RoleId) ? null : cxt.Roles.SingleOrDefault(r => r.Id == new Guid(ccmUser.RoleId)); // Only admins allowed to assign admin role to account if (CurrentUserIsAdmin() || role == null || role.Name != Roles.Admin) { dbUser.Role = role; } if (!string.IsNullOrEmpty(ccmUser.Password)) { var saltBytes = CryptoHelper.GenerateSaltBytes(); dbUser.PasswordHash = CryptoHelper.Md5HashSaltedPassword(ccmUser.Password, saltBytes); dbUser.Salt = Convert.ToBase64String(saltBytes); } }