private DtoValidationResult ValidateUserGroup(EntityToemsUserGroup userGroup, bool isNewUserGroup) { var validationResult = new DtoValidationResult { Success = true }; if (isNewUserGroup) { if (_uow.UserGroupRepository.Exists(h => h.Name == userGroup.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This User Group Already Exists"; return(validationResult); } } else { var originalUserGroup = _uow.UserGroupRepository.GetById(userGroup.Id); if (originalUserGroup.Name != userGroup.Name) { if (_uow.UserGroupRepository.Exists(h => h.Name == userGroup.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This User Group Already Exists"; return(validationResult); } } } return(validationResult); }
private DtoValidationResult ValidateCertificateEntity(EntityCertificate certificate, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; return(validationResult); //todo: add validation }
public DtoValidationResult Validate(EntitySchedule schedule, bool isNew) { if (schedule.Hour < 0 || schedule.Hour > 23) { return new DtoValidationResult() { ErrorMessage = "Hour Was Not Valid", Success = false } } ; if (schedule.Minute != 0 && schedule.Minute != 15 && schedule.Minute != 30 && schedule.Minute != 45) { return new DtoValidationResult() { ErrorMessage = "Minute Was Not Valid", Success = false } } ; var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(schedule.Name) || !schedule.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ' || c == '.')) { validationResult.Success = false; validationResult.ErrorMessage = "Schedule Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.ScheduleRepository.Exists(h => h.Name == schedule.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Schedule With This Name Already Exists"; return(validationResult); } } else { var original = _uow.ScheduleRepository.GetById(schedule.Id); if (original.Name != schedule.Name) { if (_uow.ScheduleRepository.Exists(h => h.Name == schedule.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Schedule With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
private DtoValidationResult Validate(EntitySmartGroupQuery query, bool isNew) { //todo: add validation var validationResult = new DtoValidationResult { Success = true }; return(validationResult); }
private DtoValidationResult ValidateComputer(EntityComputer computer, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; return(validationResult); }
public DtoValidationResult Validate(EntityImageProfile imageProfile, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(imageProfile.Name) || !imageProfile.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ')) { validationResult.Success = false; validationResult.ErrorMessage = "Image Profile Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.ImageProfileRepository.Exists(h => h.Name == imageProfile.Name && h.ImageId == imageProfile.ImageId)) { validationResult.Success = false; validationResult.ErrorMessage = "An Image Profile With This Name Already Exists"; return(validationResult); } } else { var original = _uow.ImageProfileRepository.GetById(imageProfile.Id); if (original.Name != imageProfile.Name) { if (_uow.ImageProfileRepository.Exists(h => h.Name == imageProfile.Name && h.ImageId == imageProfile.ImageId)) { validationResult.Success = false; validationResult.ErrorMessage = "An Image Profile With This Name Already Exists"; return(validationResult); } } } if (!string.IsNullOrEmpty(imageProfile.ModelMatch)) { var profilesWithModelMatch = _uow.ImageProfileRepository.Get(x => x.ModelMatch.Equals(imageProfile.ModelMatch.ToLower()) && x.Id != imageProfile.Id); if (profilesWithModelMatch.Any()) { var image = _uow.ImageRepository.GetById(profilesWithModelMatch.First().ImageId); validationResult.Success = false; validationResult.ErrorMessage = "This Model Match Already Exists On Image: " + image.Name; } } return(validationResult); }
public DtoValidationResult Validate(EntityWolRelay relay, bool isNew) { IPAddress gateway; if (!IPAddress.TryParse(relay.Gateway, out gateway)) { return new DtoValidationResult() { ErrorMessage = "Invalid Gateway Address", Success = false } } ; var validationResult = new DtoValidationResult(); if (isNew) { if (_uow.WolRelayRepository.Exists(h => h.Gateway == relay.Gateway)) { validationResult.Success = false; validationResult.ErrorMessage = "A Relay With This Gateway Already Exists"; return(validationResult); } } else { var originalRelay = _uow.WolRelayRepository.GetById(relay.Id); if (originalRelay.Gateway != relay.Gateway) { if (_uow.WolRelayRepository.Exists(h => h.Gateway == relay.Gateway)) { validationResult.Success = false; validationResult.ErrorMessage = "A Relay With This Gateway Already Exists"; return(validationResult); } } } return(new DtoValidationResult() { Success = true }); } }
private DtoValidationResult ValidateUser(EntityToemsUser user, bool isNewUser) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(user.Name) || !user.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-')) { validationResult.Success = false; validationResult.ErrorMessage = "User Name Is Not Valid"; return(validationResult); } if (isNewUser) { if (string.IsNullOrEmpty(user.Password)) { validationResult.Success = false; validationResult.ErrorMessage = "Password Is Not Valid"; return(validationResult); } if (_uow.UserRepository.Exists(h => h.Name == user.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A User With This Name Already Exists"; return(validationResult); } } else { var originalUser = _uow.UserRepository.GetById(user.Id); if (originalUser.Name != user.Name) { if (_uow.UserRepository.Exists(h => h.Name == user.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A User With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
private DtoValidationResult ValidateModule(EntitySysprepModule module, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; int value; if (string.IsNullOrEmpty(module.Name) || !module.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ' || c == '.')) { validationResult.Success = false; validationResult.ErrorMessage = "Module Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.SysprepModuleRepository.Exists(h => h.Name == module.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Module With This Name Already Exists"; return(validationResult); } } else { var originalModule = _uow.SysprepModuleRepository.GetById(module.Id); if (originalModule.Name != module.Name) { if (_uow.SysprepModuleRepository.Exists(h => h.Name == module.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Module With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
private DtoValidationResult ValidatePolicy(EntityPolicy policy, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(policy.Name) || !policy.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ' || c == '.')) { validationResult.Success = false; validationResult.ErrorMessage = "Policy Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.PolicyRepository.Exists(h => h.Name == policy.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Policy With This Name Already Exists"; return(validationResult); } } else { var originalPolicy = _uow.PolicyRepository.GetById(policy.Id); if (originalPolicy.Name != policy.Name) { if (_uow.PolicyRepository.Exists(h => h.Name == policy.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Policy With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
public DtoValidationResult Validate(EntityAsset asset, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(asset.DisplayName) || !asset.DisplayName.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ' || c == '.')) { validationResult.Success = false; validationResult.ErrorMessage = "Asset Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.AssetRepository.Exists(h => h.DisplayName == asset.DisplayName)) { validationResult.Success = false; validationResult.ErrorMessage = "An Asset With This Name Already Exists"; return(validationResult); } } else { var original = _uow.AssetRepository.GetById(asset.Id); if (original.DisplayName != asset.DisplayName) { if (_uow.AssetRepository.Exists(h => h.DisplayName == asset.DisplayName)) { validationResult.Success = false; validationResult.ErrorMessage = "An Asset With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
public DtoValidationResult Validate(EntityImpersonationAccount account, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(account.Username)) { validationResult.Success = false; validationResult.ErrorMessage = "Account Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.ImpersonationAccountRepository.Exists(h => h.Username == account.Username)) { validationResult.Success = false; validationResult.ErrorMessage = "An Account With This Name Already Exists"; return(validationResult); } } else { var original = _uow.ImpersonationAccountRepository.GetById(account.Id); if (original.Username != account.Username) { if (_uow.ImpersonationAccountRepository.Exists(h => h.Username == account.Username)) { validationResult.Success = false; validationResult.ErrorMessage = "An Account With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
public DtoValidationResult Validate(EntityCustomBootMenu customBootMenu, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(customBootMenu.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "Custom Boot Menu Entry Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.CustomBootMenuRepository.Exists(h => h.Name == customBootMenu.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Custom Boot Menu Entry With This Name Already Exists"; return(validationResult); } } else { var original = _uow.CustomBootMenuRepository.GetById(customBootMenu.Id); if (original.Name != customBootMenu.Name) { if (_uow.CustomBootMenuRepository.Exists(h => h.Name == customBootMenu.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Custom Boot Menu Entry With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
private DtoValidationResult ValidateGroup(EntityGroup group, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(group.Name) || !group.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ')) { validationResult.Success = false; validationResult.ErrorMessage = "Group Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.GroupRepository.Exists(h => h.Name == group.Name && h.IsOu == false)) { validationResult.Success = false; validationResult.ErrorMessage = "A Group With This Name Already Exists"; return(validationResult); } } else { var originalGroup = _uow.GroupRepository.GetById(group.Id); if (originalGroup.Name != group.Name) { if (_uow.GroupRepository.Exists(h => h.Name == group.Name && h.IsOu == false)) { validationResult.Success = false; validationResult.ErrorMessage = "A Group With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
public DtoValidationResult Validate(EntityCustomAttribute customAttribute, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(customAttribute.Name) || !customAttribute.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-')) { validationResult.Success = false; validationResult.ErrorMessage = "Custom Attribute Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.CustomAttributeRepository.Exists(h => h.Name == customAttribute.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Custom Attribute With This Name Already Exists"; return(validationResult); } } else { var original = _uow.CustomAttributeRepository.GetById(customAttribute.Id); if (original.Name != customAttribute.Name) { if (_uow.CategoryRepository.Exists(h => h.Name == customAttribute.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Custom Attribute With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
public DtoValidationResult Validate(EntityClientComServer comServer, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(comServer.DisplayName) || !comServer.DisplayName.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ')) { validationResult.Success = false; validationResult.ErrorMessage = "Com Server Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.ClientComServerRepository.Exists(h => h.DisplayName == comServer.DisplayName)) { validationResult.Success = false; validationResult.ErrorMessage = "A Com Server With This Name Already Exists"; return(validationResult); } } else { var original = _uow.ClientComServerRepository.GetById(comServer.Id); if (original.DisplayName != comServer.DisplayName) { if (_uow.ClientComServerRepository.Exists(h => h.DisplayName == comServer.DisplayName)) { validationResult.Success = false; validationResult.ErrorMessage = "A Com Server With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
public DtoValidationResult Validate(EntityImage image, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(image.Name) || !image.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ')) { validationResult.Success = false; validationResult.ErrorMessage = "Image Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.ImageRepository.Exists(h => h.Name == image.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Image With This Name Already Exists"; return(validationResult); } } else { var original = _uow.ImageRepository.GetById(image.Id); if (original.Name != image.Name) { if (_uow.ImageRepository.Exists(h => h.Name == image.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Image With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
public DtoValidationResult GlobalLogin(string userName, string password, string loginType) { var validationResult = new DtoValidationResult { ErrorMessage = "Incorrect Username Or Password", Success = false }; var auditLog = new EntityAuditLog(); var auditLogService = new ServiceAuditLog(); auditLog.ObjectId = -1; auditLog.ObjectName = userName; auditLog.UserId = -1; auditLog.ObjectType = "User"; auditLog.AuditType = EnumAuditEntry.AuditType.FailedLogin; //Check if user exists in database var user = _userServices.GetUser(userName); if (user == null) { //Check For a first time LDAP User Group Login if (ServiceSetting.GetSettingValue(SettingStrings.LdapEnabled) == "1") { foreach (var ldapGroup in _userGroupServices.GetLdapGroups()) { if (new LdapServices().Authenticate(userName, password, ldapGroup.GroupLdapName)) { //user is a valid ldap user via ldap group that has not yet logged in. //Add the user and allow login. var cdUser = new EntityToemsUser { Name = userName, Salt = Utility.CreateSalt(64), IsLdapUser = 1, Membership = "User", Theme = "dark", }; //Create a local random db pass, should never actually be possible to use. cdUser.Password = Utility.CreatePasswordHash(Utility.GenerateKey(), cdUser.Salt); if (_userServices.AddUser(cdUser).Success) { //add user to group var newUser = _userServices.GetUser(userName); _userGroupServices.AddNewGroupMember(ldapGroup.Id, newUser.Id); auditLog.UserId = newUser.Id; auditLog.ObjectId = newUser.Id; validationResult.Success = true; auditLog.AuditType = EnumAuditEntry.AuditType.SuccessfulLogin; break; } } } } auditLogService.AddAuditLog(auditLog); return(validationResult); } if (_userLockoutServices.AccountIsLocked(user.Id)) { _userLockoutServices.ProcessBadLogin(user.Id); validationResult.ErrorMessage = "Account Is Locked"; auditLog.UserId = user.Id; auditLog.ObjectId = user.Id; auditLogService.AddAuditLog(auditLog); return(validationResult); } //Check against AD if (user.IsLdapUser == 1 && ServiceSetting.GetSettingValue(SettingStrings.LdapEnabled) == "1") { //Check if user is authenticated against an ldap group if (user.UserGroupId != -1) { //user is part of a group, is the group an ldap group? var userGroup = _userGroupServices.GetUserGroup(user.UserGroupId); if (userGroup != null) { if (userGroup.IsLdapGroup == 1) { //the group is an ldap group //make sure user is still in that ldap group if (new LdapServices().Authenticate(userName, password, userGroup.GroupLdapName)) { validationResult.Success = true; } else { //user is either not in that group anymore, not in the directory, or bad password validationResult.Success = false; if (new LdapServices().Authenticate(userName, password)) { //password was good but user is no longer in the group //delete the user _userServices.DeleteUser(user.Id); } } } else { //the group is not an ldap group //still need to check creds against directory if (new LdapServices().Authenticate(userName, password)) { validationResult.Success = true; } } } else { //group didn't exist for some reason //still need to check creds against directory if (new LdapServices().Authenticate(userName, password)) { validationResult.Success = true; } } } else { //user is not part of a group, check creds against directory if (new LdapServices().Authenticate(userName, password)) { validationResult.Success = true; } } } else if (user.IsLdapUser == 1 && ServiceSetting.GetSettingValue(SettingStrings.LdapEnabled) != "1") { //prevent ldap user from logging in with local pass if ldap auth gets turned off validationResult.Success = false; } //Check against local DB else { var hash = Utility.CreatePasswordHash(password, user.Salt); if (user.Password == hash) { validationResult.Success = true; } } if (validationResult.Success) { auditLog.AuditType = EnumAuditEntry.AuditType.SuccessfulLogin; auditLog.UserId = user.Id; auditLog.ObjectId = user.Id; auditLogService.AddAuditLog(auditLog); _userLockoutServices.DeleteUserLockouts(user.Id); return(validationResult); } auditLog.AuditType = EnumAuditEntry.AuditType.FailedLogin; auditLog.UserId = user.Id; auditLog.ObjectId = user.Id; auditLogService.AddAuditLog(auditLog); _userLockoutServices.ProcessBadLogin(user.Id); return(validationResult); }
private DtoValidationResult ValidateModule(EntitySoftwareModule module, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; int value; if (!int.TryParse(module.Timeout.ToString(), out value)) { validationResult.Success = false; validationResult.ErrorMessage = "Invalid Timeout"; return(validationResult); } try { if (string.IsNullOrEmpty(module.SuccessCodes)) { validationResult.Success = false; validationResult.ErrorMessage = "Invalid Success Code"; return(validationResult); } if (module.SuccessCodes.Split(',').Any(code => !int.TryParse(code, out value))) { validationResult.Success = false; validationResult.ErrorMessage = "Invalid Success Code"; return(validationResult); } } catch { validationResult.Success = false; validationResult.ErrorMessage = "Invalid Success Code"; return(validationResult); } if (module.Timeout < 0) { module.Timeout = 0; } if (string.IsNullOrEmpty(module.Name) || !module.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ' || c == '.')) { validationResult.Success = false; validationResult.ErrorMessage = "Module Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.SoftwareModuleRepository.Exists(h => h.Name == module.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Module With This Name Already Exists"; return(validationResult); } } else { var originalModule = _uow.SoftwareModuleRepository.GetById(module.Id); if (originalModule.Name != module.Name) { if (_uow.SoftwareModuleRepository.Exists(h => h.Name == module.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Module With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
public DtoValidationResult Validate(EntityClientComServer comServer, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(comServer.DisplayName) || !comServer.DisplayName.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ')) { validationResult.Success = false; validationResult.ErrorMessage = "Com Server Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.ClientComServerRepository.Exists(h => h.DisplayName == comServer.DisplayName)) { validationResult.Success = false; validationResult.ErrorMessage = "A Com Server With This Name Already Exists"; return(validationResult); } } else { var original = _uow.ClientComServerRepository.GetById(comServer.Id); if (original.DisplayName != comServer.DisplayName) { if (_uow.ClientComServerRepository.Exists(h => h.DisplayName == comServer.DisplayName)) { validationResult.Success = false; validationResult.ErrorMessage = "A Com Server With This Name Already Exists"; return(validationResult); } } } //remove for now, it's possible that you might want to com servers on the same server and still wouldn't need smb /* * var comServerCount = Convert.ToInt32(TotalCount()); * if(comServerCount > 0) * { * //verify storage type before allowing more than one com server * var storageType = ServiceSetting.GetSettingValue(SettingStrings.StorageType); * if(storageType.Equals("Local")) * { * validationResult.Success = false; * validationResult.ErrorMessage = "Could Not Add Server. If Using More Than 1 Com Server, The Storage Type Must Be Set To SMB In Admin Settings->Storage Location"; * return validationResult; * } * }*/ if (string.IsNullOrEmpty(comServer.LocalStoragePath)) { validationResult.Success = false; validationResult.ErrorMessage = "Local Storage Path Must Be Populated. If Global Storage is set to Local, verify Admin Settings-> Storage Location is populated."; return(validationResult); } Regex r = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/", RegexOptions.None, TimeSpan.FromMilliseconds(150)); Match m = r.Match(comServer.Url); if (m.Success) { var port = r.Match(comServer.Url).Result("${port}"); if (string.IsNullOrEmpty(port)) { validationResult.Success = false; validationResult.ErrorMessage = "The URL Must Include The Port Number"; return(validationResult); } } else { validationResult.Success = false; validationResult.ErrorMessage = "The URL Is Invalid"; return(validationResult); } return(validationResult); }