public string GetMunkiBasicAuth(int profileId) { var imageProfile = new ImageProfileServices().ReadProfile(profileId); var authString = imageProfile.MunkiAuthUsername + ":" + imageProfile.MunkiAuthPassword; return(StringManipulationServices.Encode(authString)); }
public string GetOriginalLvm(int profileId, string clientHd, string hdToGet, string partitionPrefix) { string result = null; var imageProfile = new ImageProfileServices().ReadProfile(profileId); var hdNumberToGet = Convert.ToInt32(hdToGet); var partitionHelper = new ClientPartitionHelper(imageProfile); var imageSchema = partitionHelper.GetImageSchema(); foreach (var part in from part in imageSchema.HardDrives[hdNumberToGet].Partitions where part.Active where part.VolumeGroup != null where part.VolumeGroup.LogicalVolumes != null select part) { result = "pvcreate -u " + part.Uuid + " --norestorefile -yf " + clientHd + partitionPrefix + part.VolumeGroup.PhysicalVolume[part.VolumeGroup.PhysicalVolume.Length - 1] + "\r\n"; result += "vgcreate " + part.VolumeGroup.Name + " " + clientHd + partitionPrefix + part.VolumeGroup.PhysicalVolume[part.VolumeGroup.PhysicalVolume.Length - 1] + " -yf" + "\r\n"; result += "echo \"" + part.VolumeGroup.Uuid + "\" >>/tmp/vg-" + part.VolumeGroup.Name + "\r\n"; foreach (var lv in part.VolumeGroup.LogicalVolumes.Where(lv => lv.Active)) { result += "lvcreate --yes -L " + lv.Size + "s -n " + lv.Name + " " + lv.VolumeGroup + "\r\n"; var uuid = lv.FsType == "swap" ? lv.Uuid.Split('#')[0] : lv.Uuid; result += "echo \"" + uuid + "\" >>/tmp/" + lv.VolumeGroup + "-" + lv.Name + "\r\n"; } result += "vgcfgbackup -f /tmp/lvm-" + part.VolumeGroup.Name + "\r\n"; } return(result); }
public string UpdateGuid(int profileId) { var imageProfile = new ImageProfileServices().ReadProfile(profileId); var imageServices = new ImageServices(); var image = imageServices.GetImage(imageProfile.ImageId); var guid = Guid.NewGuid().ToString(); image.LastUploadGuid = guid; imageServices.UpdateImage(image); return(guid); }
public string CheckModelMatch(string environment, string systemModel) { var modelTask = new ModelTaskDTO(); //Check for model match var modelMatchProfile = new ImageProfileServices().GetModelMatch(systemModel, environment); if (modelMatchProfile != null) { var image = new ImageServices().GetImage(modelMatchProfile.ImageId); if (image != null) { modelTask.imageName = image.Name; } modelTask.imageProfileId = modelMatchProfile.Id.ToString(); modelTask.imageProfileName = modelMatchProfile.Name; return(JsonConvert.SerializeObject(modelTask)); } return(JsonConvert.SerializeObject(new ModelTaskDTO())); }
public void DeleteImage(int profileId) { var profile = new ImageProfileServices().ReadProfile(profileId); if (string.IsNullOrEmpty(profile.Image.Name)) { return; } //Remove existing custom deploy schema, it may not match newly updated image profile.CustomSchema = string.Empty; new ImageProfileServices().UpdateProfile(profile); var delResult = new FilesystemServices().DeleteImageFolders(profile.Image.Name); if (delResult) { new FilesystemServices().CreateNewImageFolders(profile.Image.Name); } }
public string CheckHdRequirements(int profileId, int clientHdNumber, string newHdSize, string imageSchemaDrives, int clientLbs) { var result = new HardDriveSchema(); var imageProfile = new ImageProfileServices().ReadProfile(profileId); var partitionHelper = new ClientPartitionHelper(imageProfile); var imageSchema = partitionHelper.GetImageSchema(); if (clientHdNumber > imageSchema.HardDrives.Count()) { result.IsValid = "false"; result.Message = "No Image Exists To Download To This Hard Drive. There Are More" + "Hard Drive's Than The Original Image"; return(JsonConvert.SerializeObject(result)); } var listSchemaDrives = new List <int>(); if (!string.IsNullOrEmpty(imageSchemaDrives)) { listSchemaDrives.AddRange(imageSchemaDrives.Split(' ').Select(hd => Convert.ToInt32(hd))); } result.SchemaHdNumber = partitionHelper.NextActiveHardDrive(listSchemaDrives, clientHdNumber); if (result.SchemaHdNumber == -1) { result.IsValid = "false"; result.Message = "No Active Hard Drive Images Were Found To Deploy."; return(JsonConvert.SerializeObject(result)); } var newHdBytes = Convert.ToInt64(newHdSize); var minimumSize = partitionHelper.HardDrive(result.SchemaHdNumber, newHdBytes); if (clientLbs != 0) //if zero should be from the osx imaging environment or winpe { if (imageProfile.Image.Type != "File") { if (clientLbs != imageSchema.HardDrives[result.SchemaHdNumber].Lbs) { log.Error("Error: The Logical Block Size Of This Hard Drive " + clientLbs + " Does Not Match The Original Image" + imageSchema.HardDrives[result.SchemaHdNumber].Lbs); result.IsValid = "false"; result.Message = "The Logical Block Size Of This Hard Drive " + clientLbs + " Does Not Match The Original Image" + imageSchema.HardDrives[result.SchemaHdNumber].Lbs; return(JsonConvert.SerializeObject(result)); } } } if (minimumSize > newHdBytes) { log.Error("Error: " + newHdBytes / 1024 / 1024 + " MB Is Less Than The Minimum Required HD Size For This Image(" + minimumSize / 1024 / 1024 + " MB)"); result.IsValid = "false"; result.Message = newHdBytes / 1024 / 1024 + " MB Is Less Than The Minimum Required HD Size For This Image(" + minimumSize / 1024 / 1024 + " MB)"; return(JsonConvert.SerializeObject(result)); } if (minimumSize == newHdBytes) { result.IsValid = "original"; result.PhysicalPartitions = partitionHelper.GetActivePartitions(result.SchemaHdNumber, imageProfile); result.PhysicalPartitionCount = partitionHelper.GetActivePartitionCount(result.SchemaHdNumber); result.PartitionType = imageSchema.HardDrives[result.SchemaHdNumber].Table; result.BootPartition = imageSchema.HardDrives[result.SchemaHdNumber].Boot; result.UsesLvm = partitionHelper.CheckForLvm(result.SchemaHdNumber); result.Guid = imageSchema.HardDrives[result.SchemaHdNumber].Guid; return(JsonConvert.SerializeObject(result)); } result.IsValid = "true"; result.PhysicalPartitions = partitionHelper.GetActivePartitions(result.SchemaHdNumber, imageProfile); result.PhysicalPartitionCount = partitionHelper.GetActivePartitionCount(result.SchemaHdNumber); result.PartitionType = imageSchema.HardDrives[result.SchemaHdNumber].Table; result.BootPartition = imageSchema.HardDrives[result.SchemaHdNumber].Boot; result.UsesLvm = partitionHelper.CheckForLvm(result.SchemaHdNumber); result.Guid = imageSchema.HardDrives[result.SchemaHdNumber].Guid; return(JsonConvert.SerializeObject(result)); }
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)); }