public void SendTaskErrorEmail(ActiveImagingTaskEntity task, string error) { //Mail not enabled if (SettingServices.GetSettingValue(SettingStrings.SmtpEnabled) == "0") { return; } var computer = new ComputerServices().GetComputer(task.ComputerId); foreach ( var user in _userServices.SearchUsers("").Where(x => x.NotifyError == 1 && !string.IsNullOrEmpty(x.Email))) { if (task.UserId == user.Id) { if (computer == null) { computer = new ComputerEntity(); computer.Name = "Unknown Computer"; } var mail = new MailServices { MailTo = user.Email, Body = computer.Name + " Image Task Has Failed. " + error, Subject = "Task Failed" }; mail.Send(); } } }
public string AddComputer(string name, string mac, string clientIdentifier) { clientIdentifier = clientIdentifier.ToUpper(); var existingComputer = new ComputerServices().GetComputerFromClientIdentifier(clientIdentifier); if (existingComputer != null) { return (JsonConvert.SerializeObject(new ActionResultDTO { Success = false, ErrorMessage = "A Computer With This Client Id Already Exists" })); } var computer = new ComputerEntity { Name = name, Mac = mac, ClientIdentifier = clientIdentifier, SiteId = -1, BuildingId = -1, RoomId = -1, ImageId = -1, ImageProfileId = -1, ClusterGroupId = -1 }; var result = new ComputerServices().AddComputer(computer); return(JsonConvert.SerializeObject(result)); }
public bool ToggleProxyReservation(int computerId, bool enable) { var computerServices = new ComputerServices(); var computer = computerServices.GetComputer(computerId); computer.ProxyReservation = Convert.ToInt16(enable); computerServices.UpdateComputer(computer); return(true); }
public string GetAllClusterDps(int computerId) { var rnd = new Random(); var computerServices = new ComputerServices(); var computer = computerServices.GetComputer(computerId); if (SettingServices.ServerIsNotClustered) { return("single"); } var clusterServices = new ClusterGroupServices(); ClusterGroupEntity clusterGroup; if (computer != null) { clusterGroup = new ComputerServices().GetClusterGroup(computer.Id); } else { //on demand computer might be null //use default cluster group clusterGroup = clusterServices.GetDefaultClusterGroup(); } //Something went wrong if (clusterGroup == null) { return("false"); } var clusterDps = clusterServices.GetClusterDps(clusterGroup.Id); var dpList = clusterDps.Select(clusterDp => clusterDp.DistributionPointId).ToList(); var randomDpList = new List <int>(); try { randomDpList = dpList.OrderBy(x => rnd.Next()).ToList(); } catch (Exception ex) { log.Error("Could Not Select Random Distribution Point"); log.Error(ex.Message); return("false"); } var result = ""; foreach (var dpId in randomDpList) { result += dpId + " "; } return(result); }
public TftpServerDTO GetComputerTftpServers(string mac) { var tftpDto = new TftpServerDTO(); tftpDto.TftpServers = new List <string>(); if (SettingServices.ServerIsNotClustered) { tftpDto.TftpServers.Add( StringManipulationServices.PlaceHolderReplace( SettingServices.GetSettingValue(SettingStrings.TftpServerIp))); } else { var clusterServices = new ClusterGroupServices(); var secondaryServerServices = new SecondaryServerServices(); List <ClusterGroupServerEntity> clusterServers; var computer = new ComputerServices().GetComputerFromMac(mac); if (computer == null) { var cg = new ClusterGroupServices().GetDefaultClusterGroup(); clusterServers = clusterServices.GetActiveClusterServers(cg.Id); } else { var cg = new ComputerServices().GetClusterGroup(computer.Id); clusterServers = clusterServices.GetActiveClusterServers(cg.Id); } foreach (var tftpServer in clusterServers.Where(x => x.TftpRole == 1)) { if (tftpServer.ServerId == -1) { tftpDto.TftpServers.Add( StringManipulationServices.PlaceHolderReplace( SettingServices.GetSettingValue(SettingStrings.TftpServerIp))); } else { var serverIdentifier = secondaryServerServices.GetSecondaryServer(tftpServer.ServerId).Name; var tServer = new APICall(new SecondaryServerServices().GetToken(serverIdentifier)).ServiceAccountApi .GetTftpServer(); if (tServer != null) { tftpDto.TftpServers.Add(tServer); } } } } return(tftpDto); }
public string DetermineTask(string idType, string id) { var determineTaskDto = new DetermineTaskDTO(); var computerServices = new ComputerServices(); ComputerEntity computer; if (idType == "mac") { //When searching for computer by mac, that means the first check of searching by cliend id //did not yield any results. Fall back to mac only for legacy support, but don't include computers //that have a valid client id. computer = computerServices.GetComputerFromMac(id); if (computer != null) { if (!string.IsNullOrEmpty(computer.ClientIdentifier)) { //act like a computer wasn't found computer = null; } } } else { id = id.ToUpper(); computer = computerServices.GetComputerFromClientIdentifier(id); } if (computer == null) { determineTaskDto.task = "ond"; determineTaskDto.computerId = "false"; return(JsonConvert.SerializeObject(determineTaskDto)); } var computerTask = computerServices.GetTaskForComputerCheckin(computer.Id); if (computerTask == null) { determineTaskDto.computerId = computer.Id.ToString(); determineTaskDto.task = "ond"; } else { determineTaskDto.computerId = computer.Id.ToString(); determineTaskDto.task = computerTask.Type; determineTaskDto.taskId = computerTask.Id.ToString(); } return(JsonConvert.SerializeObject(determineTaskDto)); }
public ActionResultDTO UpdateSmartMembership(int groupId) { var group = GetGroup(groupId); DeleteAllMembershipsForGroup(group.Id); var computers = new ComputerServices().SearchComputersByName(group.SmartCriteria, int.MaxValue); var memberships = computers.Select(computer => new GroupMembershipEntity { GroupId = @group.Id, ComputerId = computer.Id }) .ToList(); return(new GroupMembershipServices().AddMembership(memberships)); }
public ActionResultDTO DeleteProfile(int profileId) { var profile = ReadProfile(profileId); if (profile == null) { return new ActionResultDTO { ErrorMessage = "Image Profile Was Not Found", Id = 0 } } ; _uow.ImageProfileRepository.Delete(profileId); _uow.Save(); var computers = _uow.ComputerRepository.Get(x => x.ImageProfileId == profileId); var computerService = new ComputerServices(); foreach (var computer in computers) { computer.ImageProfileId = -1; computerService.UpdateComputer(computer); } var groups = _uow.GroupRepository.Get(x => x.ImageProfileId == profileId); var groupService = new GroupServices(); foreach (var group in groups) { group.ImageProfileId = -1; groupService.UpdateGroup(group); } var groupProperties = _uow.GroupPropertyRepository.Get(x => x.ImageProfileId == profileId); var groupPropertyService = new GroupPropertyServices(); foreach (var groupProperty in groupProperties) { groupProperty.ImageProfileId = -1; groupPropertyService.UpdateGroupProperty(groupProperty); } var actionResult = new ActionResultDTO(); actionResult.Success = true; actionResult.Id = profile.Id; return(actionResult); }
public bool ToggleComputerBootMenu(int computerId, bool enable) { var computerServices = new ComputerServices(); var computer = computerServices.GetComputer(computerId); computer.CustomBootEnabled = Convert.ToInt16(enable); computerServices.UpdateComputer(computer); if (enable) { CreateBootFiles(computer.Id); } return(true); }
public ActionResultDTO DeleteMunkiTemplates(int computerId) { var existingcomputer = new ComputerServices().GetComputer(computerId); if (existingcomputer == null) { return new ActionResultDTO { ErrorMessage = "Computer Not Found", Id = 0 } } ; var actionResult = new ActionResultDTO(); _uow.ComputerMunkiRepository.DeleteRange(x => x.ComputerId == computerId); _uow.Save(); actionResult.Success = true; actionResult.Id = computerId; return(actionResult); }
public bool ComputerManagement(int computerId) { if (_cloneDeployUser.Membership == "Administrator") { return(true); } //All user rights don't have the required right. No need to check group membership. if (_currentUserRights.All(right => right != _requiredRight)) { return(false); } if (_cloneDeployUser.GroupManagementEnabled == 1) { var computers = new ComputerServices().SearchComputersForUser(_cloneDeployUser.Id, int.MaxValue); return(computers.Any(x => x.Id == computerId)); } return(IsAuthorized()); }
public ActionResultDTO DeleteSite(int siteId) { var site = GetSite(siteId); if (site == null) { return new ActionResultDTO { ErrorMessage = "Site Not Found", Id = 0 } } ; _uow.SiteRepository.Delete(siteId); _uow.Save(); var computers = _uow.ComputerRepository.Get(x => x.SiteId == siteId); var computerService = new ComputerServices(); foreach (var computer in computers) { computer.SiteId = -1; computerService.UpdateComputer(computer); } var groupProperties = _uow.GroupPropertyRepository.Get(x => x.SiteId == siteId); var groupPropertyService = new GroupPropertyServices(); foreach (var groupProperty in groupProperties) { groupProperty.SiteId = -1; groupPropertyService.UpdateGroupProperty(groupProperty); } var actionResult = new ActionResultDTO(); actionResult.Success = true; actionResult.Id = site.Id; return(actionResult); }
public List <ImageEntity> FilterForOnDemandList(int computerId, List <ImageEntity> listImages) { if (computerId == 0) { return(listImages); } var filteredImageList = new List <ImageEntity>(); var imageClassifications = new ComputerServices().GetComputerImageClassifications(computerId); if (imageClassifications == null) { return(listImages); } if (imageClassifications.Count == 0) { return(listImages); } foreach (var image in listImages) { if (image.ClassificationId == -1) { //Image has no classification, add it filteredImageList.Add(image); continue; } foreach (var classification in imageClassifications) { if (image.ClassificationId == classification.ImageClassificationId) { filteredImageList.Add(image); break; } } } return(filteredImageList); }
public ActionResultDTO DeleteRoom(int roomId) { var room = GetRoom(roomId); if (room == null) { return new ActionResultDTO { ErrorMessage = "Room Not Found", Id = 0 } } ; _uow.RoomRepository.Delete(roomId); _uow.Save(); var computers = _uow.ComputerRepository.Get(x => x.RoomId == roomId); var computerService = new ComputerServices(); foreach (var computer in computers) { computer.RoomId = -1; computerService.UpdateComputer(computer); } var groupProperties = _uow.GroupPropertyRepository.Get(x => x.RoomId == roomId); var groupPropertyService = new GroupPropertyServices(); foreach (var groupProperty in groupProperties) { groupProperty.RoomId = -1; groupPropertyService.UpdateGroupProperty(groupProperty); } var actionResult = new ActionResultDTO(); actionResult.Success = true; actionResult.Id = room.Id; return(actionResult); }
public ActionResultDTO DeleteBuilding(int buildingId) { var actionResult = new ActionResultDTO(); var building = GetBuilding(buildingId); if (building == null) { return new ActionResultDTO { ErrorMessage = "Building Not Found", Id = 0 } } ; _uow.BuildingRepository.Delete(buildingId); _uow.Save(); var computers = _uow.ComputerRepository.Get(x => x.BuildingId == buildingId); var computerService = new ComputerServices(); foreach (var computer in computers) { computer.BuildingId = -1; computerService.UpdateComputer(computer); } var groupProperties = _uow.GroupPropertyRepository.Get(x => x.BuildingId == buildingId); var groupPropertyService = new GroupPropertyServices(); foreach (var groupProperty in groupProperties) { groupProperty.BuildingId = -1; groupPropertyService.UpdateGroupProperty(groupProperty); } actionResult.Success = true; actionResult.Id = buildingId; return(actionResult); }
public ActionResultDTO DeleteAlternateServerIp(int alternateServerIpId) { var alternateServerIp = GetAlternateServerIp(alternateServerIpId); if (alternateServerIp == null) { return new ActionResultDTO { ErrorMessage = "Alternate Server Ip Not Found", Id = 0 } } ; _uow.AlternateServerIpRepository.Delete(alternateServerIpId); _uow.Save(); var computers = _uow.ComputerRepository.Get(x => x.AlternateServerIpId == alternateServerIpId); var computerService = new ComputerServices(); foreach (var computer in computers) { computer.AlternateServerIpId = -1; computerService.UpdateComputer(computer); } var groupProperties = _uow.GroupPropertyRepository.Get(x => x.AlternateServerIpId == alternateServerIpId); var groupPropertyService = new GroupPropertyServices(); foreach (var groupProperty in groupProperties) { groupProperty.AlternateServerIpId = -1; groupPropertyService.UpdateGroupProperty(groupProperty); } var actionResult = new ActionResultDTO(); actionResult.Success = true; actionResult.Id = alternateServerIp.Id; return(actionResult); }
public List <ImageWithDate> FilterClassifications(int computerId, List <ImageWithDate> listImages) { var filteredImageList = new List <ImageWithDate>(); var imageClassifications = new ComputerServices().GetComputerImageClassifications(computerId); if (imageClassifications == null) { return(listImages); } if (imageClassifications.Count == 0) { return(listImages); } foreach (var image in listImages) { //Debatable - Should computers with image classifications be able to see unclassified images - Currently no /*if (image.ClassificationId == -1 || image.ClassificationId == 0) * { * //Image has no classification, add it * filteredImageList.Add(image); * continue; * }*/ foreach (var classification in imageClassifications) { if (image.ClassificationId == classification.ImageClassificationId) { filteredImageList.Add(image); break; } } } return(filteredImageList); }
public string CheckQueue(int taskId) { var queueStatus = new QueueStatus(); var activeImagingTaskServices = new ActiveImagingTaskServices(); var thisComputerTask = activeImagingTaskServices.GetTask(taskId); var computer = new ComputerServices().GetComputer(thisComputerTask.ComputerId); //Check if already part of the queue if (thisComputerTask.Status == "2") { //Check if the queue is open yet var inUse = activeImagingTaskServices.GetCurrentQueue(thisComputerTask); var totalCapacity = 0; var dp = new DistributionPointServices().GetDistributionPoint(thisComputerTask.DpId); totalCapacity = dp.QueueSize; if (inUse < totalCapacity) { //queue is open, is this computer next var firstTaskInQueue = activeImagingTaskServices.GetNextComputerInQueue(thisComputerTask); if (firstTaskInQueue.ComputerId == computer.Id) { ChangeStatusInProgress(taskId); queueStatus.Result = "true"; queueStatus.Position = "0"; return(JsonConvert.SerializeObject(queueStatus)); } //not time for this computer yet queueStatus.Result = "false"; queueStatus.Position = activeImagingTaskServices.GetQueuePosition(thisComputerTask); return(JsonConvert.SerializeObject(queueStatus)); } //queue not open yet queueStatus.Result = "false"; queueStatus.Position = activeImagingTaskServices.GetQueuePosition(thisComputerTask); return(JsonConvert.SerializeObject(queueStatus)); } else { //New computer checking queue for the first time var inUse = activeImagingTaskServices.GetCurrentQueue(thisComputerTask); var totalCapacity = 0; var dp = new DistributionPointServices().GetDistributionPoint(thisComputerTask.DpId); totalCapacity = dp.QueueSize; if (inUse < totalCapacity) { ChangeStatusInProgress(taskId); queueStatus.Result = "true"; queueStatus.Position = "0"; return(JsonConvert.SerializeObject(queueStatus)); } //place into queue var lastQueuedTask = activeImagingTaskServices.GetLastQueuedTask(thisComputerTask); if (lastQueuedTask == null) { thisComputerTask.QueuePosition = 1; } else { thisComputerTask.QueuePosition = lastQueuedTask.QueuePosition + 1; } thisComputerTask.Status = "2"; activeImagingTaskServices.UpdateActiveImagingTask(thisComputerTask); queueStatus.Result = "false"; queueStatus.Position = activeImagingTaskServices.GetQueuePosition(thisComputerTask); return(JsonConvert.SerializeObject(queueStatus)); } }
public ActionResultDTO DeleteClusterGroup(int clusterGroupId) { var clusterGroup = GetClusterGroup(clusterGroupId); if (clusterGroup == null) { return new ActionResultDTO { ErrorMessage = "Cluster Group Not Found", Id = 0 } } ; _uow.ClusterGroupRepository.Delete(clusterGroupId); _uow.Save(); var sites = _uow.SiteRepository.Get(x => x.ClusterGroupId == clusterGroupId); var siteService = new SiteServices(); foreach (var site in sites) { site.ClusterGroupId = -1; siteService.UpdateSite(site); } var buildings = _uow.BuildingRepository.Get(x => x.ClusterGroupId == clusterGroupId); var buildingService = new BuildingServices(); foreach (var building in buildings) { building.ClusterGroupId = -1; buildingService.UpdateBuilding(building); } var rooms = _uow.RoomRepository.Get(x => x.ClusterGroupId == clusterGroupId); var roomService = new RoomServices(); foreach (var room in rooms) { room.ClusterGroupId = -1; roomService.UpdateRoom(room); } var computers = _uow.ComputerRepository.Get(x => x.ClusterGroupId == clusterGroupId); var computerService = new ComputerServices(); foreach (var computer in computers) { computer.ClusterGroupId = -1; computerService.UpdateComputer(computer); } var groups = _uow.GroupRepository.Get(x => x.ClusterGroupId == clusterGroupId); var groupService = new GroupServices(); foreach (var group in groups) { group.ClusterGroupId = -1; groupService.UpdateGroup(group); } var groupProperties = _uow.GroupPropertyRepository.Get(x => x.ClusterGroupId == clusterGroupId); var groupPropertyService = new GroupPropertyServices(); foreach (var groupProperty in groupProperties) { groupProperty.ClusterGroupId = -1; groupPropertyService.UpdateGroupProperty(groupProperty); } var actionResult = new ActionResultDTO(); actionResult.Success = true; actionResult.Id = clusterGroup.Id; return(actionResult); }
public ActionResultDTO DeleteImage(int imageId) { var image = GetImage(imageId); if (image == null) { return new ActionResultDTO { ErrorMessage = "Image Not Found", Id = 0 } } ; var result = new ActionResultDTO(); if (Convert.ToBoolean(image.Protected)) { result.ErrorMessage = "This Image Is Protected And Cannot Be Deleted"; return(result); } _uow.ImageRepository.Delete(image.Id); _uow.Save(); result.Id = imageId; //Check if image name is empty or null, return if so or something will be deleted that shouldn't be if (string.IsNullOrEmpty(image.Name)) { return(result); } var computers = _uow.ComputerRepository.Get(x => x.ImageId == imageId); var computerService = new ComputerServices(); foreach (var computer in computers) { computer.ImageId = -1; computer.ImageProfileId = -1; computerService.UpdateComputer(computer); } var groups = _uow.GroupRepository.Get(x => x.ImageId == imageId); var groupService = new GroupServices(); foreach (var group in groups) { group.ImageId = -1; group.ImageProfileId = -1; groupService.UpdateGroup(group); } var groupProperties = _uow.GroupPropertyRepository.Get(x => x.ImageId == imageId); var groupPropertyService = new GroupPropertyServices(); foreach (var groupProperty in groupProperties) { groupProperty.ImageId = -1; groupProperty.ImageProfileId = -1; groupPropertyService.UpdateGroupProperty(groupProperty); } var delDirectoryResult = new FilesystemServices().DeleteImageFolders(image.Name); result.Success = delDirectoryResult; return(result); }
public string CheckIn(string taskId) { var checkIn = new CheckIn(); var computerServices = new ComputerServices(); var task = new ActiveImagingTaskServices().GetTask(Convert.ToInt32(taskId)); if (task == null) { checkIn.Result = "false"; checkIn.Message = "Could Not Find Task With Id" + taskId; return(JsonConvert.SerializeObject(checkIn)); } var computer = computerServices.GetComputer(task.ComputerId); if (computer == null) { checkIn.Result = "false"; checkIn.Message = "The Computer Assigned To This Task Was Not Found"; return(JsonConvert.SerializeObject(checkIn)); } var imageDistributionPoint = new GetImageServer(computer, task.Type).Run(); task.Status = "1"; task.DpId = imageDistributionPoint; ImageEntity image = null; if (task.Type == "multicast") { var mcTask = new ActiveMulticastSessionServices().Get(task.MulticastId); var group = new GroupServices().GetGroupByName(mcTask.Name); image = new ImageServices().GetImage(group.ImageId); } else { image = new ImageServices().GetImage(computer.ImageId); } if (image.Protected == 1 && task.Type.Contains("upload")) { checkIn.Result = "false"; checkIn.Message = "This Image Is Protected"; return(JsonConvert.SerializeObject(checkIn)); } if (new ActiveImagingTaskServices().UpdateActiveImagingTask(task)) { checkIn.Result = "true"; if (image != null) { if (image.Environment == "") { image.Environment = "linux"; } checkIn.ImageEnvironment = image.Environment; } if (image.Environment == "winpe") { checkIn.TaskArguments = task.Arguments + "dp_id=\"" + imageDistributionPoint + "\"\r\n"; } else { checkIn.TaskArguments = task.Arguments + " dp_id=\"" + imageDistributionPoint + "\""; } return(JsonConvert.SerializeObject(checkIn)); } checkIn.Result = "false"; checkIn.Message = "Could Not Update Task Status"; return(JsonConvert.SerializeObject(checkIn)); }
public bool CreateBootFiles(int id) { var computer = GetComputer(id); if (new ComputerServices().IsComputerActive(computer.Id)) { return(false); //Files Will Be Processed When task is done } var bootMenu = new ComputerServices().GetComputerBootMenu(computer.Id); if (bootMenu == null) { return(false); } var pxeMac = StringManipulationServices.MacToPxeMac(computer.Mac); string path; if (SettingServices.GetSettingValue(SettingStrings.ProxyDhcp) == "Yes") { var list = new List <Tuple <string, string, string> > { Tuple.Create("bios", "", bootMenu.BiosMenu), Tuple.Create("bios", ".ipxe", bootMenu.BiosMenu), Tuple.Create("efi32", "", bootMenu.Efi32Menu), Tuple.Create("efi32", ".ipxe", bootMenu.Efi32Menu), Tuple.Create("efi64", "", bootMenu.Efi64Menu), Tuple.Create("efi64", ".ipxe", bootMenu.Efi64Menu), Tuple.Create("efi64", ".cfg", bootMenu.Efi64Menu) }; if (SettingServices.ServerIsNotClustered) { foreach (var tuple in list) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + tuple.Item1 + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac + tuple.Item2; if (!string.IsNullOrEmpty(tuple.Item3)) { new FileOpsServices().WritePath(path, tuple.Item3); } } } else { if (SettingServices.TftpServerRole) { foreach (var tuple in list) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + tuple.Item1 + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac + tuple.Item2; if (!string.IsNullOrEmpty(tuple.Item3)) { new FileOpsServices().WritePath(path, tuple.Item3); } } } var secondaryServers = new SecondaryServerServices().SearchSecondaryServers().Where(x => x.TftpRole == 1 && x.IsActive == 1); foreach (var server in secondaryServers) { var tftpPath = new APICall(new SecondaryServerServices().GetToken(server.Name)) .SettingApi.GetSetting("Tftp Path").Value; foreach (var tuple in list) { path = tftpPath + "proxy" + Path.DirectorySeparatorChar + tuple.Item1 + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac + tuple.Item2; new APICall(new SecondaryServerServices().GetToken(server.Name)) .ServiceAccountApi.WriteTftpFile(new TftpFileDTO { Path = path, Contents = tuple.Item3 }); } } } } else { var mode = SettingServices.GetSettingValue(SettingStrings.PxeMode); path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac; if (SettingServices.ServerIsNotClustered) { if (mode.Contains("ipxe")) { path += ".ipxe"; } else if (mode.Contains("grub")) { path += ".cfg"; } if (!string.IsNullOrEmpty(bootMenu.BiosMenu)) { new FileOpsServices().WritePath(path, bootMenu.BiosMenu); } } else { if (SettingServices.TftpServerRole) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac; if (mode.Contains("ipxe")) { path += ".ipxe"; } else if (mode.Contains("grub")) { path += ".cfg"; } if (!string.IsNullOrEmpty(bootMenu.BiosMenu)) { new FileOpsServices().WritePath(path, bootMenu.BiosMenu); } } var secondaryServers = new SecondaryServerServices().SearchSecondaryServers().Where(x => x.TftpRole == 1 && x.IsActive == 1); foreach (var server in secondaryServers) { var tftpPath = new APICall(new SecondaryServerServices().GetToken(server.Name)) .SettingApi.GetSetting("Tftp Path").Value; path = tftpPath + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac; if (mode.Contains("ipxe")) { path += ".ipxe"; } else if (mode.Contains("grub")) { path += ".cfg"; } new APICall(new SecondaryServerServices().GetToken(server.Name)) .ServiceAccountApi.WriteTftpFile(new TftpFileDTO { Path = path, Contents = bootMenu.BiosMenu }); } } } return(true); }
public string OnDemandCheckIn(string mac, int objectId, string task, string userId, string computerId) { var checkIn = new CheckIn(); var computerServices = new ComputerServices(); if (userId != null) //on demand { //Check permissions if (task.Contains("deploy")) { if ( !new AuthorizationServices(Convert.ToInt32(userId), AuthorizationStrings.ImageDeployTask) .IsAuthorized()) { checkIn.Result = "false"; checkIn.Message = "This User Is Not Authorized To Deploy Images"; return(JsonConvert.SerializeObject(checkIn)); } } if (task.Contains("upload")) { if ( !new AuthorizationServices(Convert.ToInt32(userId), AuthorizationStrings.ImageUploadTask) .IsAuthorized()) { checkIn.Result = "false"; checkIn.Message = "This User Is Not Authorized To Upload Images"; return(JsonConvert.SerializeObject(checkIn)); } } if (task.Contains("multicast")) { if ( !new AuthorizationServices(Convert.ToInt32(userId), AuthorizationStrings.ImageMulticastTask) .IsAuthorized()) { checkIn.Result = "false"; checkIn.Message = "This User Is Not Authorized To Multicast Images"; return(JsonConvert.SerializeObject(checkIn)); } } } ComputerEntity computer = null; if (computerId != "false") { computer = computerServices.GetComputer(Convert.ToInt32(computerId)); } ImageProfileWithImage imageProfile; var arguments = ""; if (task == "deploy" || task == "upload" || task == "clobber" || task == "ondupload" || task == "onddeploy" || task == "unregupload" || task == "unregdeploy" || task == "modelmatchdeploy") { imageProfile = new ImageProfileServices().ReadProfile(objectId); arguments = new CreateTaskArguments(computer, imageProfile, task).Execute(); } else //Multicast { var multicast = new ActiveMulticastSessionServices().GetFromPort(objectId); imageProfile = new ImageProfileServices().ReadProfile(multicast.ImageProfileId); arguments = new CreateTaskArguments(computer, imageProfile, task).Execute(objectId.ToString()); } var imageDistributionPoint = new GetImageServer(computer, task).Run(); if (imageProfile.Image.Protected == 1 && (task == "upload" || task == "ondupload" || task == "unregupload")) { checkIn.Result = "false"; checkIn.Message = "This Image Is Protected"; return(JsonConvert.SerializeObject(checkIn)); } if (imageProfile.Image.Environment == "") { imageProfile.Image.Environment = "linux"; } checkIn.ImageEnvironment = imageProfile.Image.Environment; if (imageProfile.Image.Environment == "winpe") { arguments += "dp_id=\"" + imageDistributionPoint + "\"\r\n"; } else { arguments += " dp_id=\"" + imageDistributionPoint + "\""; } var activeTask = new ActiveImagingTaskEntity(); activeTask.Direction = task; activeTask.UserId = Convert.ToInt32(userId); activeTask.Type = task; activeTask.DpId = imageDistributionPoint; activeTask.Status = "1"; if (computer == null) { //Create Task for an unregistered on demand computer var rnd = new Random(DateTime.Now.Millisecond); var newComputerId = rnd.Next(-200000, -100000); if (imageProfile.Image.Environment == "winpe") { arguments += "computer_id=" + newComputerId + "\r\n"; } else { arguments += " computer_id=" + newComputerId; } activeTask.ComputerId = newComputerId; activeTask.Arguments = mac; } else { //Create Task for a registered on demand computer activeTask.ComputerId = computer.Id; activeTask.Arguments = arguments; } new ActiveImagingTaskServices().AddActiveImagingTask(activeTask); var auditLog = new AuditLogEntity(); switch (task) { case "ondupload": case "unregupload": case "upload": auditLog.AuditType = AuditEntry.Type.OndUpload; break; default: auditLog.AuditType = AuditEntry.Type.OndDeploy; break; } try { auditLog.ObjectId = activeTask.ComputerId; var user = new UserServices().GetUser(activeTask.UserId); if (user != null) { auditLog.UserName = user.Name; } auditLog.ObjectName = computer != null ? computer.Name : mac; auditLog.Ip = ""; auditLog.UserId = activeTask.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); } catch { //Do Nothing } checkIn.Result = "true"; checkIn.TaskArguments = arguments; checkIn.TaskId = activeTask.Id.ToString(); return(JsonConvert.SerializeObject(checkIn)); }
public void UpdateComputerProperties(GroupPropertyEntity groupProperty) { if (groupProperty == null) { return; } var groupImageClassifications = new List <GroupImageClassificationEntity>(); if (Convert.ToBoolean(groupProperty.ImageClassificationsEnabled)) { groupImageClassifications = new GroupServices().GetGroupImageClassifications(groupProperty.GroupId); } foreach (var computer in new GroupServices().GetGroupMembersWithImages(groupProperty.GroupId)) { if (Convert.ToBoolean(groupProperty.ImageEnabled)) { computer.ImageId = groupProperty.ImageId; } if (Convert.ToBoolean(groupProperty.ImageProfileEnabled)) { computer.ImageProfileId = groupProperty.ImageProfileId; } if (Convert.ToBoolean(groupProperty.DescriptionEnabled)) { computer.Description = groupProperty.Description; } if (Convert.ToBoolean(groupProperty.SiteEnabled)) { computer.SiteId = groupProperty.SiteId; } if (Convert.ToBoolean(groupProperty.BuildingEnabled)) { computer.BuildingId = groupProperty.BuildingId; } if (Convert.ToBoolean(groupProperty.RoomEnabled)) { computer.RoomId = groupProperty.RoomId; } if (Convert.ToBoolean(groupProperty.CustomAttribute1Enabled)) { computer.CustomAttribute1 = groupProperty.CustomAttribute1; } if (Convert.ToBoolean(groupProperty.CustomAttribute2Enabled)) { computer.CustomAttribute2 = groupProperty.CustomAttribute2; } if (Convert.ToBoolean(groupProperty.CustomAttribute3Enabled)) { computer.CustomAttribute3 = groupProperty.CustomAttribute3; } if (Convert.ToBoolean(groupProperty.CustomAttribute4Enabled)) { computer.CustomAttribute4 = groupProperty.CustomAttribute4; } if (Convert.ToBoolean(groupProperty.CustomAttribute5Enabled)) { computer.CustomAttribute5 = groupProperty.CustomAttribute5; } if (Convert.ToBoolean(groupProperty.ProxyEnabledEnabled)) { computer.ProxyReservation = groupProperty.ProxyEnabled; } if (Convert.ToBoolean(groupProperty.ClusterGroupEnabled)) { computer.ClusterGroupId = groupProperty.ClusterGroupId; } if (Convert.ToBoolean(groupProperty.AlternateServerIpEnabled)) { computer.AlternateServerIpId = groupProperty.AlternateServerIpId; } if (Convert.ToBoolean(groupProperty.ImageClassificationsEnabled)) { var computerImageClassifications = new List <ComputerImageClassificationEntity>(); if (new ComputerServices().DeleteComputerImageClassifications(computer.Id)) { foreach (var imageClass in groupImageClassifications) { computerImageClassifications.Add( new ComputerImageClassificationEntity { ComputerId = computer.Id, ImageClassificationId = imageClass.ImageClassificationId }); } } new ComputerImageClassificationServices().AddClassifications(computerImageClassifications); } var computerServices = new ComputerServices(); computerServices.UpdateComputer(computer); if (Convert.ToBoolean(groupProperty.TftpServerEnabled) || Convert.ToBoolean(groupProperty.BootFileEnabled)) { var proxyServices = new ComputerProxyReservationServices(); var computerProxy = computerServices.GetComputerProxyReservation(computer.Id); if (computerProxy == null) { computerProxy = new ComputerProxyReservationEntity(); computerProxy.ComputerId = computer.Id; } if (Convert.ToBoolean(groupProperty.TftpServerEnabled)) { computerProxy.NextServer = groupProperty.TftpServer; } if (Convert.ToBoolean(groupProperty.BootFileEnabled)) { computerProxy.BootFile = groupProperty.BootFile; } proxyServices.UpdateComputerProxyReservation(computerProxy); } } }
public ProxyReservationDTO GetProxyReservation(string mac) { var bootClientReservation = new ProxyReservationDTO(); var computer = new ComputerServices().GetComputerFromMac(mac); if (computer == null) { bootClientReservation.BootFile = "NotFound"; return(bootClientReservation); } if (computer.ProxyReservation == 0) { bootClientReservation.BootFile = "NotEnabled"; return(bootClientReservation); } var computerReservation = new ComputerServices().GetComputerProxyReservation(computer.Id); if (!string.IsNullOrEmpty(computerReservation.NextServer)) { bootClientReservation.NextServer = StringManipulationServices.PlaceHolderReplace(computerReservation.NextServer); } switch (computerReservation.BootFile) { case "bios_pxelinux": bootClientReservation.BootFile = @"proxy/bios/pxelinux.0"; break; case "bios_ipxe": bootClientReservation.BootFile = @"proxy/bios/undionly.kpxe"; break; case "bios_x86_winpe": bootClientReservation.BootFile = @"proxy/bios/pxeboot.n12"; bootClientReservation.BcdFile = @"/boot/BCDx86"; break; case "bios_x64_winpe": bootClientReservation.BootFile = @"proxy/bios/pxeboot.n12"; bootClientReservation.BcdFile = @"/boot/BCDx64"; break; case "efi_x86_syslinux": bootClientReservation.BootFile = @"proxy/efi32/syslinux.efi"; break; case "efi_x86_ipxe": bootClientReservation.BootFile = @"proxy/efi32/ipxe.efi"; break; case "efi_x86_winpe": bootClientReservation.BootFile = @"proxy/efi32/bootmgfw.efi"; bootClientReservation.BcdFile = @"/boot/BCDx86"; break; case "efi_x64_syslinux": bootClientReservation.BootFile = @"proxy/efi64/syslinux.efi"; break; case "efi_x64_ipxe": bootClientReservation.BootFile = @"proxy/efi64/ipxe.efi"; break; case "efi_x64_winpe": bootClientReservation.BootFile = @"proxy/efi64/bootmgfw.efi"; bootClientReservation.BcdFile = @"/boot/BCDx64"; break; case "efi_x64_grub": bootClientReservation.BootFile = @"proxy/efi64/bootx64.efi"; break; } return(bootClientReservation); }