Exemplo n.º 1
0
 public CreateTaskArguments(Models.Computer computer, Models.ImageProfile imageProfile, string direction)
 {
     _computer = computer;
     _imageProfile = imageProfile;
     _direction = direction;
     _activeTaskArguments = new StringBuilder();
 }
Exemplo n.º 2
0
 public CreateTaskArguments(Models.Computer computer, Models.ImageProfile imageProfile, string direction)
 {
     _computer            = computer;
     _imageProfile        = imageProfile;
     _direction           = direction;
     _activeTaskArguments = new StringBuilder();
 }
Exemplo n.º 3
0
        public static Models.ImageProfile SeedDefaultImageProfile(Models.Image image)
        {
            var imageProfile = new Models.ImageProfile();

            imageProfile.Kernel              = Settings.DefaultKernel32;
            imageProfile.BootImage           = "initrd.xz";
            imageProfile.Name                = "default";
            imageProfile.Description         = "Auto Generated Via New Image.";
            imageProfile.SkipCore            = 0;
            imageProfile.SkipClock           = 0;
            imageProfile.RemoveGPT           = 0;
            imageProfile.SkipShrinkVolumes   = 0;
            imageProfile.SkipShrinkLvm       = 0;
            imageProfile.SkipExpandVolumes   = 0;
            imageProfile.FixBcd              = 0;
            imageProfile.FixBootloader       = 1;
            imageProfile.PartitionMethod     = "Dynamic";
            imageProfile.Compression         = "lz4";
            imageProfile.CompressionLevel    = "1";
            imageProfile.TaskCompletedAction = "Reboot";
            imageProfile.ChangeName          = 1;
            if (image.Environment == "macOS")
            {
                imageProfile.OsxTargetVolume = "Macintosh HD";
            }

            return(imageProfile);
        }
Exemplo n.º 4
0
 //Constructor For Starting Multicast For On Demand
 public Multicast(Models.ImageProfile imageProfile, string clientCount, int userId)
 {
     _multicastSession = new Models.ActiveMulticastSession();
     _isOnDemand = true;
     _imageProfile = imageProfile;
     _clientCount = clientCount;
     _group = new Models.Group{ImageProfileId = _imageProfile.Id};
     _userId = userId;
     _multicastSession.ImageProfileId = imageProfile.Id;
 }
Exemplo n.º 5
0
 //Constructor For Starting Multicast For On Demand
 public Multicast(Models.ImageProfile imageProfile, string clientCount, int userId)
 {
     _multicastSession = new Models.ActiveMulticastSession();
     _isOnDemand       = true;
     _imageProfile     = imageProfile;
     _clientCount      = clientCount;
     _group            = new Models.Group {
         ImageProfileId = _imageProfile.Id
     };
     _userId = userId;
     _multicastSession.ImageProfileId = imageProfile.Id;
 }
Exemplo n.º 6
0
        public string Start()
        {
            if (_computer == null)
                return "The Computer Does Not Exist";

            _imageProfile = ImageProfile.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 == "push" || _direction == "permanent_push")
            {
                var validation = Image.CheckApprovalAndChecksum(_imageProfile.Image,_userId);
                if (!validation.IsValid) return validation.Message;
            }

            var dp = BLL.DistributionPoint.GetPrimaryDistributionPoint();
            if (dp == null) return "Could Not Find A Primary Distribution Point";

            if (ActiveImagingTask.IsComputerActive(_computer.Id))
                return "This Computer Is Already Part Of An Active Task";

            _activeTask = new Models.ActiveImagingTask
            {
                ComputerId = _computer.Id,
                Direction = _direction,
                UserId = _userId
            };

            _activeTask.Type = _direction == "permanent_push" ? "permanent_push" : "unicast";

            if (!ActiveImagingTask.AddActiveImagingTask(_activeTask))
                return "Could Not Create The Database Entry For This Task";

            if (!new TaskBootMenu(_computer, _imageProfile, _direction).CreatePxeBootFiles())
            {
                ActiveImagingTask.DeleteActiveImagingTask(_activeTask.Id);
                return "Could Not Create PXE Boot File";
            }

            _activeTask.Arguments = new CreateTaskArguments(_computer, _imageProfile, _direction).Run();
            if (!ActiveImagingTask.UpdateActiveImagingTask(_activeTask))
            {
                ActiveImagingTask.DeleteActiveImagingTask(_activeTask.Id);
                return "Could Not Create Task Arguments";
            }

            Utility.WakeUp(_computer.Mac);

            return "Successfully Started Task For " + _computer.Name;
        }
Exemplo n.º 7
0
        public static Models.ValidationResult AddProfile(Models.ImageProfile profile)
        {
            using (var uow = new DAL.UnitOfWork())
            {
                var validationResult = ValidateImageProfile(profile, true);
                if (validationResult.IsValid)
                {
                    uow.ImageProfileRepository.Insert(profile);
                    validationResult.IsValid = uow.Save();
                }

                return(validationResult);
            }
        }
Exemplo n.º 8
0
        public static Models.ValidationResult UpdateProfile(Models.ImageProfile profile)
        {
            using (var uow = new DAL.UnitOfWork())
            {
                var validationResult = ValidateImageProfile(profile, false);
                if (validationResult.IsValid)
                {
                    uow.ImageProfileRepository.Update(profile, profile.Id);
                    validationResult.IsValid = uow.Save();
                }

                return(validationResult);
            }
        }
Exemplo n.º 9
0
        public ImageSchema(Models.ImageProfile imageProfile, string schemaType, Models.Image image = null)
        {
            string schema = null;

            //Only To display the main image specs file when not using a profile.
            if (image != null)
            {
                var path = Settings.PrimaryStoragePath + "images" + Path.DirectorySeparatorChar + image.Name + Path.DirectorySeparatorChar + "schema";
                if (File.Exists(path))
                {
                    using (StreamReader reader = new StreamReader(path))
                    {
                        schema = reader.ReadLine() ?? "";
                    }
                }
            }

            if (imageProfile != null)
            {
                if (!string.IsNullOrEmpty(imageProfile.CustomSchema) && schemaType == "deploy")
                {
                    schema = imageProfile.CustomSchema;
                }
                else if (!string.IsNullOrEmpty(imageProfile.CustomUploadSchema) && schemaType == "upload")
                {
                    schema = imageProfile.CustomUploadSchema;
                }
                else
                {
                    var path = Settings.PrimaryStoragePath + "images" + Path.DirectorySeparatorChar + imageProfile.Image.Name + Path.DirectorySeparatorChar +
                               "schema";
                    if (File.Exists(path))
                    {
                        using (StreamReader reader = new StreamReader(path))
                        {
                            schema = reader.ReadLine() ?? "";
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(schema))
            {
                _imageSchema = JsonConvert.DeserializeObject <Models.ImageSchema.GridView.ImageSchemaGridView>(schema);
            }
        }
Exemplo n.º 10
0
        public static Models.ValidationResult ValidateImageProfile(Models.ImageProfile imageProfile, bool isNewImageProfile)
        {
            var validationResult = new Models.ValidationResult();

            if (string.IsNullOrEmpty(imageProfile.Name) || !imageProfile.Name.All(c => char.IsLetterOrDigit(c) || c == '_'))
            {
                validationResult.IsValid = false;
                validationResult.Message = "Image Profile Name Is Not Valid";
                return(validationResult);
            }

            if (isNewImageProfile)
            {
                using (var uow = new DAL.UnitOfWork())
                {
                    if (uow.ImageProfileRepository.Exists(h => h.Name == imageProfile.Name && h.ImageId == imageProfile.ImageId))
                    {
                        validationResult.IsValid = false;
                        validationResult.Message = "This Image Profile Already Exists";
                        return(validationResult);
                    }
                }
            }
            else
            {
                using (var uow = new DAL.UnitOfWork())
                {
                    var originalImageProfile = uow.ImageProfileRepository.GetById(imageProfile.Id);
                    if (originalImageProfile.Name != imageProfile.Name)
                    {
                        if (uow.ImageProfileRepository.Exists(h => h.Name == imageProfile.Name && h.ImageId == imageProfile.ImageId))
                        {
                            validationResult.IsValid = false;
                            validationResult.Message = "This Image Profile Already Exists";
                            return(validationResult);
                        }
                    }
                }
            }

            return(validationResult);
        }
Exemplo n.º 11
0
        public static void CloneProfile(Models.ImageProfile imageProfile)
        {
            var originalName = imageProfile.Name;

            using (var uow = new DAL.UnitOfWork())
            {
                for (int c = 1; c <= 100; c++)
                {
                    var newProfileName = imageProfile.Name + "_" + c;
                    if (uow.ImageProfileRepository.Exists(h => h.Name == newProfileName))
                    {
                        continue;
                    }

                    var clonedProfile = imageProfile;
                    clonedProfile.Name        = newProfileName;
                    clonedProfile.Description = "Cloned From " + originalName;
                    AddProfile(clonedProfile);
                    break;
                }
            }
        }
Exemplo n.º 12
0
        public string GeneratePartitionScript()
        {
            imageProfile = BLL.ImageProfile.ReadProfile(profileId);
            ImageSchema  = new ClientPartitionHelper(imageProfile).GetImageSchema();


            clientSchema = new ClientPartition(HdNumberToGet, NewHdSize, imageProfile, partitionPrefix).GenerateClientSchema();
            if (clientSchema == null)
            {
                return("failed");
            }

            //Handle moving from / to hard drives with different sector sizes ie 512 / 4096
            var activeCounter = HdNumberToGet;

            //Look for first active hd
            if (!ImageSchema.HardDrives[HdNumberToGet].Active)
            {
                while (activeCounter <= ImageSchema.HardDrives.Count())
                {
                    if (ImageSchema.HardDrives[activeCounter - 1].Active)
                    {
                        HdNumberToGet = activeCounter - 1;
                    }
                    activeCounter++;
                }
            }
            var LbsByte = Convert.ToInt32(ImageSchema.HardDrives[HdNumberToGet].Lbs); //logical block size in bytes

            if (LbsByte == 512 && clientBlockSize == 4096)
            {
                //fix calculations from 512 to 4096
                clientSchema.FirstPartitionStartSector             = clientSchema.FirstPartitionStartSector / 8;
                clientSchema.ExtendedPartitionHelper.AgreedSizeBlk = clientSchema.ExtendedPartitionHelper.AgreedSizeBlk /
                                                                     8;
                foreach (var partition in clientSchema.PrimaryAndExtendedPartitions)
                {
                    //efi partition on 4k drive cannot be smaller than this, and it is smaller on a 512 drive
                    if (partition.FsId.ToLower() == "ef00")
                    {
                        partition.Size = 66560;
                    }
                    else
                    {
                        partition.Size = partition.Size / 8;
                    }
                    partition.Start = partition.Size / 8;
                }

                foreach (var partition in clientSchema.LogicalPartitions)
                {
                    partition.Size  = partition.Size / 8;
                    partition.Start = partition.Size / 8;
                }

                foreach (var lv in clientSchema.LogicalVolumes)
                {
                    lv.Size = lv.Size / 8;
                }
            }
            else if (LbsByte == 4096 && clientBlockSize == 512)
            {
                //fix calculations from 4096 to 512
                clientSchema.FirstPartitionStartSector             = clientSchema.FirstPartitionStartSector * 8;
                clientSchema.ExtendedPartitionHelper.AgreedSizeBlk = clientSchema.ExtendedPartitionHelper.AgreedSizeBlk *
                                                                     8;
                foreach (var partition in clientSchema.PrimaryAndExtendedPartitions)
                {
                    partition.Size  = partition.Size * 8;
                    partition.Start = partition.Size * 8;
                }

                foreach (var partition in clientSchema.LogicalPartitions)
                {
                    partition.Size  = partition.Size * 8;
                    partition.Start = partition.Size * 8;
                }

                foreach (var lv in clientSchema.LogicalVolumes)
                {
                    lv.Size = lv.Size * 8;
                }
            }

            //otherwise both the original image block size and the destination hard block size are the same, no changes needed
            //End Handle moving from / to hard drives with different sector sizes


            if (imageProfile.Image.Environment == "linux" || string.IsNullOrEmpty(imageProfile.Image.Environment))
            {
                return(LinuxLayout());
            }
            else if (imageProfile.Image.Environment == "macOS")
            {
                return(OsxNbiLayout());
            }
            else if (imageProfile.Image.Environment == "winpe")
            {
                return(WinPELayout());
            }
            else
            {
                return("failed");
            }
        }
Exemplo n.º 13
0
        public string Create()
        {
            _imageProfile = ImageProfile.ReadProfile(_group.ImageProfileId);
            if (_imageProfile == null)
            {
                return("The Image Profile Does Not Exist");
            }

            if (_imageProfile.Image == null)
            {
                return("The Image Does Not Exist");
            }

            var validation = Image.CheckApprovalAndChecksum(_imageProfile.Image, _userId);

            if (!validation.IsValid)
            {
                return(validation.Message);
            }

            _multicastSession.Port = Port.GetNextPort();
            if (_multicastSession.Port == 0)
            {
                return("Could Not Determine Current Port Base");
            }

            var dp = BLL.DistributionPoint.GetPrimaryDistributionPoint();

            if (dp == null)
            {
                return("Could Not Find A Primary Distribution Point");
            }

            _multicastSession.UserId = _userId;
            //End of the road for starting an on demand multicast
            if (_isOnDemand)
            {
                _multicastSession.Name = _group.Name;
                _group.Name            = _multicastSession.Port.ToString();
                if (!StartMulticastSender())
                {
                    return("Could Not Start The Multicast Application");
                }
                else
                {
                    return("Successfully Started Multicast " + _group.Name);
                }
            }

            //Continue On If multicast is for a group
            _multicastSession.Name = _group.Name;
            _computers             = Group.GetGroupMembers(_group.Id);
            if (_computers.Count < 1)
            {
                return("The group Does Not Have Any Members");
            }

            if (!ActiveMulticastSession.AddActiveMulticastSession(_multicastSession))
            {
                return("Could Not Create Multicast Database Task.  An Existing Task May Be Running.");
            }

            if (!CreateComputerTasks())
            {
                ActiveMulticastSession.Delete(_multicastSession.Id);
                return("Could Not Create Computer Database Tasks.  A Computer May Have An Existing Task.");
            }

            if (!CreatePxeFiles())
            {
                ActiveMulticastSession.Delete(_multicastSession.Id);
                return("Could Not Create Computer Boot Files");
            }

            if (!CreateTaskArguments())
            {
                ActiveMulticastSession.Delete(_multicastSession.Id);
                return("Could Not Create Computer Task Arguments");
            }

            if (!StartMulticastSender())
            {
                ActiveMulticastSession.Delete(_multicastSession.Id);
                return("Could Not Start The Multicast Application");
            }

            foreach (var computer in _computers)
            {
                Utility.WakeUp(computer.Mac);
            }

            return("Successfully Started Multicast " + _group.Name);
        }
Exemplo n.º 14
0
        public string Create()
        {
            _imageProfile = ImageProfile.ReadProfile(_group.ImageProfileId);
            if (_imageProfile == null) return "The Image Profile Does Not Exist";

            if (_imageProfile.Image == null) return "The Image Does Not Exist";

            var validation = Image.CheckApprovalAndChecksum(_imageProfile.Image,_userId);
            if (!validation.IsValid) return validation.Message;

            _multicastSession.Port = Port.GetNextPort();
            if (_multicastSession.Port == 0)
            {
                return "Could Not Determine Current Port Base";
            }

            var dp = BLL.DistributionPoint.GetPrimaryDistributionPoint();
            if (dp == null) return "Could Not Find A Primary Distribution Point";

            _multicastSession.UserId = _userId;
            //End of the road for starting an on demand multicast
            if (_isOnDemand)
            {
                _multicastSession.Name = _group.Name;
                _group.Name =_multicastSession.Port.ToString();
                if (!StartMulticastSender())
                    return "Could Not Start The Multicast Application";
                else
                    return "Successfully Started Multicast " + _group.Name;
            }

            //Continue On If multicast is for a group
            _multicastSession.Name = _group.Name;
            _computers = Group.GetGroupMembers(_group.Id);
            if (_computers.Count < 1)
            {
                return "The group Does Not Have Any Members";
            }

            if (!ActiveMulticastSession.AddActiveMulticastSession(_multicastSession))
            {
                return "Could Not Create Multicast Database Task.  An Existing Task May Be Running.";
            }

            if (!CreateComputerTasks())
            {
                ActiveMulticastSession.Delete(_multicastSession.Id);
                return "Could Not Create Computer Database Tasks.  A Computer May Have An Existing Task.";
            }

            if (!CreatePxeFiles())
            {
                ActiveMulticastSession.Delete(_multicastSession.Id);
                return "Could Not Create Computer Boot Files";
            }

            if (!CreateTaskArguments())
            {
                ActiveMulticastSession.Delete(_multicastSession.Id);
                return "Could Not Create Computer Task Arguments";
            }

            if (!StartMulticastSender())
            {
                ActiveMulticastSession.Delete(_multicastSession.Id);
                return "Could Not Start The Multicast Application";
            }

            foreach (var computer in _computers)
                Utility.WakeUp(computer.Mac);

            return "Successfully Started Multicast " + _group.Name;
        }
Exemplo n.º 15
0
        public string Start()
        {
            if (_computer == null)
            {
                return("The Computer Does Not Exist");
            }

            _imageProfile = ImageProfile.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 == "push" || _direction == "permanent_push")
            {
                var validation = Image.CheckApprovalAndChecksum(_imageProfile.Image, _userId);
                if (!validation.IsValid)
                {
                    return(validation.Message);
                }
            }

            var dp = BLL.DistributionPoint.GetPrimaryDistributionPoint();

            if (dp == null)
            {
                return("Could Not Find A Primary Distribution Point");
            }

            if (ActiveImagingTask.IsComputerActive(_computer.Id))
            {
                return("This Computer Is Already Part Of An Active Task");
            }

            _activeTask = new Models.ActiveImagingTask
            {
                ComputerId = _computer.Id,
                Direction  = _direction,
                UserId     = _userId
            };

            _activeTask.Type = _direction == "permanent_push" ? "permanent_push" : "unicast";

            if (!ActiveImagingTask.AddActiveImagingTask(_activeTask))
            {
                return("Could Not Create The Database Entry For This Task");
            }

            if (!new TaskBootMenu(_computer, _imageProfile, _direction).CreatePxeBootFiles())
            {
                ActiveImagingTask.DeleteActiveImagingTask(_activeTask.Id);
                return("Could Not Create PXE Boot File");
            }

            _activeTask.Arguments = new CreateTaskArguments(_computer, _imageProfile, _direction).Run();
            if (!ActiveImagingTask.UpdateActiveImagingTask(_activeTask))
            {
                ActiveImagingTask.DeleteActiveImagingTask(_activeTask.Id);
                return("Could Not Create Task Arguments");
            }

            Utility.WakeUp(_computer.Mac);

            return("Successfully Started Task For " + _computer.Name);
        }
Exemplo n.º 16
0
 public static Models.ImageProfile SeedDefaultImageProfile()
 {
     var imageProfile = new Models.ImageProfile();
     imageProfile.Kernel = Settings.DefaultKernel32;
     imageProfile.BootImage = "initrd.xz";
     imageProfile.Name = "default";
     imageProfile.Description = "Auto Generated Via New Image.";
     imageProfile.SkipCore = 0;
     imageProfile.SkipClock = 0;
     imageProfile.RemoveGPT = 0;
     imageProfile.SkipShrinkVolumes = 0;
     imageProfile.SkipShrinkLvm = 0;
     imageProfile.SkipExpandVolumes = 0;
     imageProfile.FixBcd = 0;
     imageProfile.FixBootloader = 1;
     imageProfile.PartitionMethod = "Dynamic";
     imageProfile.Compression = "lz4";
     imageProfile.CompressionLevel = "1";
     imageProfile.TaskCompletedAction = "Reboot";
     imageProfile.ChangeName = 1;
     return imageProfile;
 }
Exemplo n.º 17
0
 public TaskBootMenu(Models.Computer computer, Models.ImageProfile imageProfile, string direction)
 {
     _computer     = computer;
     _direction    = direction;
     _imageProfile = imageProfile;
 }
Exemplo n.º 18
0
        public string GeneratePartitionScript()
        {
            imageProfile = BLL.ImageProfile.ReadProfile(profileId);
            ImageSchema = new ClientPartitionHelper(imageProfile).GetImageSchema();

            clientSchema = new ClientPartition(HdNumberToGet, NewHdSize, imageProfile, partitionPrefix).GenerateClientSchema();
            if (clientSchema == null) return "failed";

            //Handle moving from / to hard drives with different sector sizes ie 512 / 4096
            var activeCounter = HdNumberToGet;
            //Look for first active hd
            if (!ImageSchema.HardDrives[HdNumberToGet].Active)
            {
                while (activeCounter <= ImageSchema.HardDrives.Count())
                {
                    if (ImageSchema.HardDrives[activeCounter - 1].Active)
                    {
                        HdNumberToGet = activeCounter - 1;
                    }
                    activeCounter++;
                }
            }
            var LbsByte = Convert.ToInt32(ImageSchema.HardDrives[HdNumberToGet].Lbs); //logical block size in bytes
            if (LbsByte == 512 && clientBlockSize == 4096)
            {

                //fix calculations from 512 to 4096
                clientSchema.FirstPartitionStartSector = clientSchema.FirstPartitionStartSector/8;
                clientSchema.ExtendedPartitionHelper.AgreedSizeBlk = clientSchema.ExtendedPartitionHelper.AgreedSizeBlk/
                                                                     8;
                foreach (var partition in clientSchema.PrimaryAndExtendedPartitions)
                {
                    //efi partition on 4k drive cannot be smaller than this, and it is smaller on a 512 drive
                    if (partition.FsId.ToLower() == "ef00")
                        partition.Size = 66560;
                    else
                        partition.Size = partition.Size/8;
                    partition.Start = partition.Size/8;
                }

                foreach (var partition in clientSchema.LogicalPartitions)
                {
                    partition.Size = partition.Size / 8;
                    partition.Start = partition.Size / 8;
                }

                foreach (var lv in clientSchema.LogicalVolumes)
                {
                    lv.Size = lv.Size / 8;
                }

            }
            else if (LbsByte == 4096 && clientBlockSize == 512)
            {
                //fix calculations from 4096 to 512
                clientSchema.FirstPartitionStartSector = clientSchema.FirstPartitionStartSector * 8;
                clientSchema.ExtendedPartitionHelper.AgreedSizeBlk = clientSchema.ExtendedPartitionHelper.AgreedSizeBlk *
                                                                     8;
                foreach (var partition in clientSchema.PrimaryAndExtendedPartitions)
                {
                    partition.Size = partition.Size * 8;
                    partition.Start = partition.Size * 8;
                }

                foreach (var partition in clientSchema.LogicalPartitions)
                {
                    partition.Size = partition.Size * 8;
                    partition.Start = partition.Size * 8;
                }

                foreach (var lv in clientSchema.LogicalVolumes)
                {
                    lv.Size = lv.Size * 8;
                }
            }

            //otherwise both the original image block size and the destination hard block size are the same, no changes needed
            //End Handle moving from / to hard drives with different sector sizes

            if (imageProfile.Image.Environment == "linux" || string.IsNullOrEmpty(imageProfile.Image.Environment))
            {
                return LinuxLayout();
            }
            else if(imageProfile.Image.Environment == "macOS")
            {
                return OsxNbiLayout();
            }
            else if (imageProfile.Image.Environment == "winpe")
            {
                return WinPELayout();
            }
            else
            {
                return "failed";
            }
        }
Exemplo n.º 19
0
 public TaskBootMenu(Models.Computer computer, Models.ImageProfile imageProfile, string direction)
 {
     _computer = computer;
     _direction = direction;
     _imageProfile = imageProfile;
 }
Exemplo n.º 20
0
 public ClobberBootMenu(Models.ImageProfile imageProfile, bool promptComputerName)
 {
     _promptComputerName = promptComputerName;
     _imageProfile = imageProfile;
 }
Exemplo n.º 21
0
 public ClobberBootMenu(Models.ImageProfile imageProfile, bool promptComputerName)
 {
     _promptComputerName = promptComputerName;
     _imageProfile       = imageProfile;
 }