private bool CreateComputerTasks() { var error = false; var activeTaskIds = new List <int>(); var activeImagingTaskServices = new ActiveImagingTaskServices(); foreach (var computer in _computers) { if (_computerServices.IsComputerActive(computer.Id)) { return(false); } var activeTask = new ActiveImagingTaskEntity { Type = "multicast", ComputerId = computer.Id, Direction = "deploy", MulticastId = _multicastSession.Id, UserId = _userId }; if (activeImagingTaskServices.AddActiveImagingTask(activeTask)) { activeTaskIds.Add(activeTask.Id); } else { error = true; break; } } if (error) { foreach (var taskId in activeTaskIds) { activeImagingTaskServices.DeleteActiveImagingTask(taskId); } return(false); } return(true); }
public ActiveImagingTaskController() { _activeImagingTaskServices = new ActiveImagingTaskServices(); _userId = Convert.ToInt32(((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == "user_id") .Select(c => c.Value).SingleOrDefault()); }
public string Start() { if (string.IsNullOrEmpty(SettingServices.GetSettingValue(SettingStrings.ServerIdentifier))) { return("The Server Identifier Must Be Set Before Tasks Can Be Started"); } if (_computer == null) { return("The Computer Does Not Exist"); } _imageProfile = new ImageProfileServices().ReadProfile(_computer.ImageProfileId); if (_imageProfile == null) { return("The Image Profile Does Not Exist"); } if (_imageProfile.Image == null) { return("The Image Does Not Exist"); } if (_direction == "deploy" || _direction == "permanentdeploy") { var validation = new ImageServices().CheckApprovalAndChecksum(_imageProfile.Image, _userId); if (!validation.Success) { return(validation.ErrorMessage); } } var dp = new DistributionPointServices().GetPrimaryDistributionPoint(); if (dp == null) { return("Could Not Find A Primary Distribution Point"); } if (SettingServices.ServerIsClusterPrimary) { var clusterGroup = new ComputerServices().GetClusterGroup(_computer.Id); if (clusterGroup == null) { return("Could Not Find A Cluster Group For This Computer"); } } if (new ComputerServices().IsComputerActive(_computer.Id)) { return("This Computer Is Already Part Of An Active Task"); } _activeTask = new ActiveImagingTaskEntity { ComputerId = _computer.Id, Direction = _direction, UserId = _userId }; _activeTask.Type = _direction; var activeImagingTaskServices = new ActiveImagingTaskServices(); if (!activeImagingTaskServices.AddActiveImagingTask(_activeTask)) { return("Could Not Create The Database Entry For This Task"); } if (!new TaskBootMenu(_computer, _imageProfile).CreatePxeBootFiles()) { 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"); } IpServices.WakeUp(_computer.Mac); var auditLog = new AuditLogEntity(); switch (_direction) { case "deploy": auditLog.AuditType = AuditEntry.Type.Deploy; break; case "permanentdeploy": auditLog.AuditType = AuditEntry.Type.PermanentPush; break; default: auditLog.AuditType = AuditEntry.Type.Upload; break; } auditLog.ObjectId = _computer.Id; var user = new UserServices().GetUser(_userId); if (user != null) { auditLog.UserName = user.Name; } auditLog.ObjectName = _computer.Name; auditLog.Ip = _ipAddress; auditLog.UserId = _userId; auditLog.ObjectType = "Computer"; auditLog.ObjectJson = JsonConvert.SerializeObject(_activeTask); new AuditLogServices().AddAuditLog(auditLog); auditLog.ObjectId = _imageProfile.ImageId; auditLog.ObjectName = _imageProfile.Image.Name; auditLog.ObjectType = "Image"; new AuditLogServices().AddAuditLog(auditLog); return("Successfully Started Task For " + _computer.Name); }
public override void OnAuthorization(HttpActionContext actionContext) { _log.Debug(actionContext.Request.RequestUri); base.OnAuthorization(actionContext); var identity = (ClaimsPrincipal)Thread.CurrentPrincipal; var userId = identity.Claims.Where(c => c.Type == "user_id") .Select(c => c.Value).SingleOrDefault(); if (userId == null) { return; } var authorized = false; switch (Permission) { case AuthorizationStrings.SearchComputer: case AuthorizationStrings.CreateComputer: case AuthorizationStrings.SearchGroup: case AuthorizationStrings.CreateGroup: case AuthorizationStrings.CreateSmart: case AuthorizationStrings.SearchImage: case AuthorizationStrings.CreateImage: case AuthorizationStrings.SearchProfile: case AuthorizationStrings.CreateProfile: case AuthorizationStrings.ReadAdmin: case AuthorizationStrings.UpdateAdmin: case AuthorizationStrings.Administrator: case AuthorizationStrings.ReadGlobal: case AuthorizationStrings.UpdateGlobal: case AuthorizationStrings.CreateGlobal: case AuthorizationStrings.DeleteGlobal: case AuthorizationStrings.AllowOnd: case AuthorizationStrings.ServiceAccount: if (new AuthorizationServices(Convert.ToInt32(userId), Permission).IsAuthorized()) { authorized = true; } break; case AuthorizationStrings.DeleteComputer: case AuthorizationStrings.UpdateComputer: case AuthorizationStrings.ReadComputer: case AuthorizationStrings.ImageDeployTask: case AuthorizationStrings.ImageUploadTask: var computerId = Convert.ToInt32(actionContext.ControllerContext.RouteData.Values["id"]); if (new AuthorizationServices(Convert.ToInt32(userId), Permission).ComputerManagement(computerId)) { authorized = true; } break; case AuthorizationStrings.DeleteGroup: case AuthorizationStrings.UpdateGroup: case AuthorizationStrings.ReadGroup: case AuthorizationStrings.UpdateSmart: case AuthorizationStrings.ImageMulticastTask: var groupId = Convert.ToInt32(actionContext.ControllerContext.RouteData.Values["id"]); if (new AuthorizationServices(Convert.ToInt32(userId), Permission).GroupManagement(groupId)) { authorized = true; } break; case AuthorizationStrings.ImageTaskDeployGroup: var groupId_a = Convert.ToInt32(actionContext.ControllerContext.RouteData.Values["id"]); if ( new AuthorizationServices(Convert.ToInt32(userId), AuthorizationStrings.ImageDeployTask) .GroupManagement(groupId_a)) { authorized = true; } break; case AuthorizationStrings.DeleteImage: case AuthorizationStrings.UpdateImage: case AuthorizationStrings.ReadImage: case AuthorizationStrings.ApproveImage: var imageId = Convert.ToInt32(actionContext.ControllerContext.RouteData.Values["id"]); if (new AuthorizationServices(Convert.ToInt32(userId), Permission).ImageManagement(imageId)) { authorized = true; } break; case AuthorizationStrings.DeleteProfile: case AuthorizationStrings.UpdateProfile: case AuthorizationStrings.ReadProfile: var profileId = Convert.ToInt32(actionContext.ControllerContext.RouteData.Values["id"]); var profile = new ImageProfileServices().ReadProfile(profileId); if (profile == null) { authorized = true; break; } var profileImageId = profile.ImageId; if ( new AuthorizationServices(Convert.ToInt32(userId), Permission).ImageManagement( profileImageId)) { authorized = true; } break; case AuthorizationStrings.ImageDeleteTask: var objectId = Convert.ToInt32(actionContext.ControllerContext.RouteData.Values["id"]); var activeImagingTask = new ActiveImagingTaskServices().GetTask(objectId); var computer = new ComputerServices().GetComputer(activeImagingTask.ComputerId); if ( new AuthorizationServices(Convert.ToInt32(userId), AuthorizationStrings.ImageDeployTask) .ComputerManagement( computer.Id)) { authorized = true; } break; } if (!authorized) { var response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden, new ValidationResultDTO { Success = false, ErrorMessage = "Forbidden" }); throw new HttpResponseException(response); } }