public DtoActionResult Delete(int id) { var group = _groupServices.GetGroup(id); var result = _groupServices.DeleteGroup(id); if (result == null) { return new DtoActionResult() { ErrorMessage = "Result Was Null" } } ; if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "Group"; auditLog.ObjectId = result.Id; auditLog.ObjectName = group.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(group); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Delete; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Post(EntityClientComServer server) { var result = _clientComService.Add(server); if (result == null) { return new DtoActionResult() { ErrorMessage = "Result Was Null" } } ; if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "ClientComServer"; auditLog.ObjectId = result.Id; auditLog.ObjectName = server.DisplayName; auditLog.ObjectJson = JsonConvert.SerializeObject(server); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Create; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Post(EntityImageProfile imageProfile) { var result = _imageProfileService.Add(imageProfile); if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "ImageProfile"; auditLog.ObjectId = result.Id; auditLog.ObjectName = imageProfile.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(imageProfile); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Create; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Post(EntityPolicy policy) { var result = _policyServices.AddPolicy(policy); if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "Policy"; auditLog.ObjectId = result.Id; auditLog.ObjectName = policy.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(policy); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Create; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Post(EntityComServerCluster cluster) { var result = _comServerClusterService.Add(cluster); if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "ComServerCluster"; auditLog.ObjectId = result.Id; auditLog.ObjectName = cluster.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(cluster); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Create; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Post(EntityMessageModule module) { var result = _messageModuleServices.AddModule(module); if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "MessageModule"; auditLog.ObjectId = result.Id; auditLog.ObjectName = module.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(module); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Create; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoApiBoolResponse Wakeup(int id) { var computer = _computerServices.GetComputer(id); if (computer != null) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "Computer"; auditLog.ObjectId = id; auditLog.ObjectName = computer.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(computer); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Wakeup; _auditLogService.AddAuditLog(auditLog); } return(new DtoApiBoolResponse() { Value = _computerServices.Wakeup(id) }); }
public DtoApiBoolResponse Wakeup(int id) { var group = _groupServices.GetGroup(id); if (group != null) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "Group"; auditLog.ObjectId = id; auditLog.ObjectName = group.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(group); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Wakeup; _auditLogService.AddAuditLog(auditLog); } return(new DtoApiBoolResponse() { Value = _groupServices.Wakeup(id) }); }
public DtoApiBoolResponse SendMessage(int id, DtoMessage message) { var response = new DtoApiBoolResponse() { Value = _computerServices.SendMessage(id, message) }; var computer = _computerServices.GetComputer(id); if (computer != null) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "Computer"; auditLog.ObjectId = id; auditLog.ObjectName = computer.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(message); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Message; _auditLogService.AddAuditLog(auditLog); } return(response); }
public DtoActionResult Delete(int id) { var image = _imageProfileService.GetImageProfile(id); var result = _imageProfileService.Delete(id); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } else { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "ImageProfile"; auditLog.ObjectId = result.Id; auditLog.ObjectName = image.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(image); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Delete; _auditLogService.AddAuditLog(auditLog); return(result); } }
public DtoActionResult Put(int id, EntityComServerCluster cluster) { cluster.Id = id; var result = _comServerClusterService.Update(cluster); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "ComServerCluster"; auditLog.ObjectId = result.Id; auditLog.ObjectName = cluster.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(cluster); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Update; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Restore(int id) { var policy = _policyServices.GetPolicy(id); var result = _policyServices.RestorePolicy(id); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "Policy"; auditLog.ObjectId = result.Id; auditLog.ObjectName = policy.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(policy); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Restore; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Delete(int id) { var module = _messageModuleServices.GetModule(id); var result = _messageModuleServices.DeleteModule(id); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "MessageModule"; auditLog.ObjectId = result.Id; auditLog.ObjectName = module.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(module); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Delete; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Archive(int id) { var computer = _computerServices.GetComputer(id); var result = _computerServices.ArchiveComputer(id); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "Computer"; auditLog.ObjectId = result.Id; auditLog.ObjectName = computer.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(computer); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Archive; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Put(int id, EntityScriptModule module) { module.Id = id; var result = _scriptModuleServices.UpdateModule(module); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "ScriptModule"; auditLog.ObjectId = result.Id; auditLog.ObjectName = module.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(module); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Update; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Approve(int id) { var result = _approvalRequestService.ApproveRequest(id); if (result.Success) { var computer = new ServiceComputer().GetComputer(id); if (computer == null) { return(result); } var auditLog = new EntityAuditLog(); auditLog.ObjectType = "ApprovalRequest"; auditLog.ObjectId = result.Id; auditLog.ObjectName = computer.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(computer); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.ApproveProvision; _auditLogService.AddAuditLog(auditLog); } return(result); }
public void AddAuditLog(EntityAuditLog auditLog) { _uow.AuditLogRepository.Insert(auditLog); _uow.Save(); }
public string Create() { _imageProfile = new ServiceImageProfile().ReadProfile(_group.ImageProfileId); if (_imageProfile == null) { return("The Image Profile Does Not Exist"); } if (_imageProfile.Image == null) { return("The Image Does Not Exist"); } _multicastServerId = _isOnDemand ? _comServerId : new GetMulticastServer(_group).Run(); if (_multicastServerId == null) { return("Could Not Find Any Available Multicast Servers"); } var comServer = new ServiceClientComServer().GetServer(Convert.ToInt32(_multicastServerId)); if (string.IsNullOrEmpty(comServer.MulticastInterfaceIp)) { return("The Com Server's Multicast Interface IP Address Is Not Populated"); } _multicastSession.Port = new ServicePort().GetNextPort(_multicastServerId); if (_multicastSession.Port == 0) { return("Could Not Determine Current Port Base"); } _multicastSession.ComServerId = Convert.ToInt32(_multicastServerId); _multicastSession.UserId = _userId; if (_isOnDemand) { if (string.IsNullOrEmpty(_multicastSession.Name)) { _multicastSession.Name = _multicastSession.Port.ToString(); } if (string.IsNullOrEmpty(_multicastSession.Name) || !_multicastSession.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-')) { return("Multicast Session Name Is Not Valid"); } _group.Name = _multicastSession.Name; var onDemandprocessArguments = GenerateProcessArguments(); if (onDemandprocessArguments == 0) { return("Could Not Start The Multicast Application"); } var ondAuditLog = new EntityAuditLog(); ondAuditLog.AuditType = EnumAuditEntry.AuditType.OnDemandMulticast; ondAuditLog.ObjectId = _imageProfile.ImageId; var ondUser = new ServiceUser().GetUser(_userId); if (ondUser != null) { ondAuditLog.UserName = ondUser.Name; } ondAuditLog.ObjectName = _imageProfile.Image.Name; ondAuditLog.UserId = _userId; ondAuditLog.ObjectType = "Image"; ondAuditLog.ObjectJson = JsonConvert.SerializeObject(_multicastSession); new ServiceAuditLog().AddAuditLog(ondAuditLog); return("Successfully Started Multicast " + _group.Name); } //End of the road for starting an on demand multicast //Continue On If multicast is for a group _multicastSession.Name = _group.Name; _computers = new ServiceGroup().GetGroupMembers(_group.Id); if (_computers.Count < 1) { return("The Group Does Not Have Any Members"); } var activeMulticastSessionServices = new ServiceActiveMulticastSession(); if (!activeMulticastSessionServices.AddActiveMulticastSession(_multicastSession)) { return("Could Not Create Multicast Database Task. An Existing Task May Be Running."); } if (!CreateComputerTasks()) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Create Computer Database Tasks. A Computer May Have An Existing Task."); } if (!CreatePxeFiles()) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Create Computer Boot Files"); } if (!CreateTaskArguments()) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Create Computer Task Arguments"); } var processArguments = GenerateProcessArguments(); if (processArguments == 0) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Start The Multicast Application"); } foreach (var computer in _computers) { _computerServices.Wakeup(computer.Id); } var auditLog = new EntityAuditLog(); auditLog.AuditType = EnumAuditEntry.AuditType.Multicast; auditLog.ObjectId = _group.Id; var user = new ServiceUser().GetUser(_userId); if (user != null) { auditLog.UserName = user.Name; } auditLog.ObjectName = _group.Name; auditLog.UserId = _userId; auditLog.ObjectType = "Group"; auditLog.ObjectJson = JsonConvert.SerializeObject(_multicastSession); new ServiceAuditLog().AddAuditLog(auditLog); auditLog.ObjectId = _imageProfile.ImageId; auditLog.ObjectName = _imageProfile.Image.Name; auditLog.ObjectType = "Image"; new ServiceAuditLog().AddAuditLog(auditLog); return("Successfully Started Multicast " + _group.Name); }
public DtoActionResult Restore(int moduleId, EnumModule.ModuleType moduleType) { var result = _moduleServices.RestoreModule(moduleId, moduleType); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } if (result.Success) { var auditLog = new EntityAuditLog(); switch (moduleType) { case EnumModule.ModuleType.Command: var cModule = new ServiceCommandModule().GetModule(moduleId); auditLog.ObjectName = cModule.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(cModule); break; case EnumModule.ModuleType.FileCopy: var fModule = new ServiceFileCopyModule().GetModule(moduleId); auditLog.ObjectName = fModule.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(fModule); break; case EnumModule.ModuleType.Printer: var pModule = new ServicePrinterModule().GetModule(moduleId); auditLog.ObjectName = pModule.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(pModule); break; case EnumModule.ModuleType.Script: var scModule = new ServiceScriptModule().GetModule(moduleId); auditLog.ObjectName = scModule.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(scModule); break; case EnumModule.ModuleType.Software: var sModule = new ServiceSoftwareModule().GetModule(moduleId); auditLog.ObjectName = sModule.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(sModule); break; case EnumModule.ModuleType.Wupdate: var uModule = new ServiceWuModule().GetModule(moduleId); auditLog.ObjectName = uModule.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(uModule); break; case EnumModule.ModuleType.Message: var messageModule = new ServiceMessageModule().GetModule(moduleId); auditLog.ObjectName = messageModule.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(messageModule); break; } auditLog.ObjectType = moduleType.ToString(); auditLog.ObjectId = result.Id; auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Restore; _auditLogService.AddAuditLog(auditLog); } return(result); }
public string Start() { if (_computer == null) { return("The Computer Does Not Exist"); } if (_group != null) { //unicast started via group, use that groups assigned image _imageProfile = new ServiceImageProfile().ReadProfile(_group.ImageProfileId); if (_imageProfile == null) { return("The Image Profile Doesn't Exist"); } } else { _imageProfile = new ServiceComputer().GetEffectiveImage(_computer.Id); } if (_imageProfile == null) { return("No Image Has Been Selected"); } if (_imageProfile.Image == null) { return("The Image Does Not Exist"); } if (new ServiceComputer().IsComputerActive(_computer.Id)) { return("This Computer Is Already Part Of An Active Task"); } _activeTask = new EntityActiveImagingTask { ComputerId = _computer.Id, Direction = _direction, UserId = _userId, ImageProfileId = _imageProfile.Id }; _activeTask.Type = _direction; var activeImagingTaskServices = new ServiceActiveImagingTask(); if (!activeImagingTaskServices.AddActiveImagingTask(_activeTask)) { return("Could Not Create The Database Entry For This Task"); } if (!new TaskBootMenu().RunAllServers(_computer, _imageProfile)) { activeImagingTaskServices.DeleteActiveImagingTask(_activeTask.Id); return("Could Not Create PXE Boot File"); } _activeTask.Arguments = new CreateTaskArguments(_computer, _imageProfile, _direction).Execute(); if (!activeImagingTaskServices.UpdateActiveImagingTask(_activeTask)) { activeImagingTaskServices.DeleteActiveImagingTask(_activeTask.Id); return("Could Not Create Task Arguments"); } new ServiceComputer().Wakeup(_computer.Id); var auditLog = new EntityAuditLog(); switch (_direction) { case "deploy": auditLog.AuditType = EnumAuditEntry.AuditType.Deploy; break; default: auditLog.AuditType = EnumAuditEntry.AuditType.Upload; break; } auditLog.ObjectId = _computer.Id; var user = new ServiceUser().GetUser(_userId); if (user != null) { auditLog.UserName = user.Name; } auditLog.ObjectName = _computer.Name; auditLog.UserId = _userId; auditLog.ObjectType = "Computer"; auditLog.ObjectJson = JsonConvert.SerializeObject(_activeTask); new ServiceAuditLog().AddAuditLog(auditLog); auditLog.ObjectId = _imageProfile.ImageId; auditLog.ObjectName = _imageProfile.Image.Name; auditLog.ObjectType = "Image"; new ServiceAuditLog().AddAuditLog(auditLog); return("Successfully Started Task For " + _computer.Name); }
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); }