Example #1
0
 public EffectiveMunkiTemplate()
 {
     _munkiManifestTemplateServices = new MunkiManifestTemplateServices();
     _groupServices         = new GroupServices();
     _groupMunkiServices    = new GroupMunkiServices();
     _computerServices      = new ComputerServices();
     _computerMunkiServices = new ComputerMunkiServices();
 }
Example #2
0
 public CleanTaskBootFiles(ComputerEntity computer)
 {
     _computer                = computer;
     _bootFile                = StringManipulationServices.MacToPxeMac(_computer.Mac);
     _computerServices        = new ComputerServices();
     _clusterGroupServices    = new ClusterGroupServices();
     _secondaryServerServices = new SecondaryServerServices();
 }
Example #3
0
 //Constructor For Starting Multicast For Group
 public Multicast(int groupId, int userId, string userIp)
 {
     _computers        = new List <ComputerEntity>();
     _multicastSession = new ActiveMulticastSessionEntity();
     _isOnDemand       = false;
     _group            = new GroupServices().GetGroup(groupId);
     _userId           = userId;
     _computerServices = new ComputerServices();
     _ipAddress        = userIp;
 }
Example #4
0
 //Constructor For Starting Multicast For On Demand
 public Multicast(int imageProfileId, string clientCount, int userId, string userIp, int clusterId)
 {
     _multicastSession = new ActiveMulticastSessionEntity();
     _isOnDemand       = true;
     _imageProfile     = new ImageProfileServices().ReadProfile(imageProfileId);
     _clientCount      = clientCount;
     _group            = new GroupEntity {
         ImageProfileId = _imageProfile.Id
     };
     _userId = userId;
     _multicastSession.ImageProfileId = _imageProfile.Id;
     _computerServices = new ComputerServices();
     _ipAddress        = userIp;
     _clusterId        = clusterId;
 }
        public ComputerController()
        {
            _computerService = new ComputerServices();
            _auditLogService = new AuditLogServices();
            _userId          = Convert.ToInt32(((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == "user_id")
                                               .Select(c => c.Value).SingleOrDefault());
            _auditLog            = new AuditLogEntity();
            _auditLog.ObjectType = "Computer";
            _auditLog.UserId     = _userId;
            var user = new UserServices().GetUser(_userId);

            if (user != null)
            {
                _auditLog.UserName = user.Name;
            }
        }
Example #6
0
        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);
        }
Example #7
0
        public bool CreatePxeBootFiles()
        {
            var pxeComputerMac     = StringManipulationServices.MacToPxeMac(_computer.Mac);
            var webPath            = SettingServices.GetSettingValue(SettingStrings.WebPath) + "api/ClientImaging/";
            var globalComputerArgs = SettingServices.GetSettingValue(SettingStrings.GlobalComputerArgs);
            var userToken          = SettingServices.GetSettingValue(SettingStrings.WebTaskRequiresLogin) == "No"
                ? SettingServices.GetSettingValue(SettingStrings.UniversalToken)
                : "";
            const string newLineChar = "\n";

            if (_computer.AlternateServerIpId != -1)
            {
                var altServer = new AlternateServerIpServices().GetAlternateServerIp(_computer.AlternateServerIpId);
                if (altServer != null)
                {
                    webPath = altServer.ApiUrl + "api/ClientImaging/";
                }
            }

            var ipxe = new StringBuilder();

            ipxe.Append("#!ipxe" + newLineChar);
            ipxe.Append("kernel " + webPath + "IpxeBoot?filename=" + _imageProfile.Kernel +
                        "&type=kernel" + " initrd=" + _imageProfile.BootImage +
                        " root=/dev/ram0 rw ramdisk_size=156000" +
                        " consoleblank=0" + " web=" + webPath + " USER_TOKEN=" + userToken + " " + globalComputerArgs +
                        " " + _imageProfile.KernelArguments + newLineChar);
            ipxe.Append("imgfetch --name " + _imageProfile.BootImage + " " + webPath +
                        "IpxeBoot?filename=" + _imageProfile.BootImage + "&type=bootimage" + newLineChar);
            ipxe.Append("boot" + newLineChar);

            var sysLinux = new StringBuilder();

            sysLinux.Append("DEFAULT clonedeploy" + newLineChar);
            sysLinux.Append("LABEL clonedeploy" + newLineChar);
            sysLinux.Append("KERNEL kernels" + Path.DirectorySeparatorChar + _imageProfile.Kernel + newLineChar);
            sysLinux.Append("APPEND initrd=images" + Path.DirectorySeparatorChar + _imageProfile.BootImage +
                            " root=/dev/ram0 rw ramdisk_size=156000" +
                            " consoleblank=0" + " web=" + webPath + " USER_TOKEN=" + userToken + " " +
                            globalComputerArgs +
                            " " + _imageProfile.KernelArguments + newLineChar);

            var grub = new StringBuilder();

            grub.Append("set default=0" + newLineChar);
            grub.Append("set timeout=0" + newLineChar);
            grub.Append("menuentry CloneDeploy --unrestricted {" + newLineChar);
            grub.Append("echo Please Wait While The Boot Image Is Transferred.  This May Take A Few Minutes." +
                        newLineChar);
            grub.Append("linux /kernels/" + _imageProfile.Kernel +
                        " root=/dev/ram0 rw ramdisk_size=156000" + " consoleblank=0" + " web=" + webPath +
                        " USER_TOKEN=" +
                        userToken + " " +
                        globalComputerArgs + " " + _imageProfile.KernelArguments + newLineChar);
            grub.Append("initrd /images/" + _imageProfile.BootImage + newLineChar);
            grub.Append("}" + newLineChar);

            var list = new List <Tuple <string, string, string> >
            {
                Tuple.Create("bios", "", sysLinux.ToString()),
                Tuple.Create("bios", ".ipxe", ipxe.ToString()),
                Tuple.Create("efi32", "", sysLinux.ToString()),
                Tuple.Create("efi32", ".ipxe", ipxe.ToString()),
                Tuple.Create("efi64", "", sysLinux.ToString()),
                Tuple.Create("efi64", ".ipxe", ipxe.ToString()),
                Tuple.Create("efi64", ".cfg", grub.ToString())
            };

            //In proxy mode all boot files are created regardless of the pxe mode, this way computers can be customized
            //to use a specific boot file without affecting all others, using the proxydhcp reservations file.
            if (SettingServices.GetSettingValue(SettingStrings.ProxyDhcp) == "Yes")
            {
                if (SettingServices.ServerIsNotClustered)
                {
                    foreach (var bootMenu in list)
                    {
                        var path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" +
                                   Path.DirectorySeparatorChar + bootMenu.Item1 +
                                   Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar +
                                   pxeComputerMac +
                                   bootMenu.Item2;

                        if (!new FileOpsServices().WritePath(path, bootMenu.Item3))
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    var clusterGroup = new ComputerServices().GetClusterGroup(_computer.Id);
                    foreach (var tftpServer in _clusterGroupServices.GetClusterTftpServers(clusterGroup.Id))
                    {
                        foreach (var bootMenu in list)
                        {
                            if (tftpServer.ServerId == -1)
                            {
                                var path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" +
                                           Path.DirectorySeparatorChar + bootMenu.Item1 +
                                           Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar +
                                           pxeComputerMac +
                                           bootMenu.Item2;

                                if (!new FileOpsServices().WritePath(path, bootMenu.Item3))
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                var secondaryServer = _secondaryServerServices.GetSecondaryServer(tftpServer.ServerId);
                                var tftpPath        =
                                    new APICall(_secondaryServerServices.GetToken(secondaryServer.Name))
                                    .SettingApi.GetSetting("Tftp Path").Value;

                                var path = tftpPath + "proxy" + Path.DirectorySeparatorChar + bootMenu.Item1 +
                                           Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar +
                                           pxeComputerMac +
                                           bootMenu.Item2;

                                if (
                                    !new APICall(_secondaryServerServices.GetToken(secondaryServer.Name))
                                    .ServiceAccountApi.WriteTftpFile(new TftpFileDTO
                                {
                                    Path = path,
                                    Contents = bootMenu.Item3
                                }))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }
            //When not using proxy dhcp, only one boot file is created
            else
            {
                var mode = SettingServices.GetSettingValue(SettingStrings.PxeMode);
                var path = "";
                if (SettingServices.ServerIsNotClustered)
                {
                    path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" +
                           Path.DirectorySeparatorChar + pxeComputerMac;

                    string fileContents = null;
                    if (mode == "pxelinux" || mode == "syslinux_32_efi" || mode == "syslinux_64_efi")
                    {
                        fileContents = sysLinux.ToString();
                    }

                    else if (mode.Contains("ipxe"))
                    {
                        path        += ".ipxe";
                        fileContents = ipxe.ToString();
                    }
                    else if (mode.Contains("grub"))
                    {
                        path        += ".cfg";
                        fileContents = grub.ToString();
                    }

                    if (!new FileOpsServices().WritePath(path, fileContents))
                    {
                        return(false);
                    }
                }
                else
                {
                    var clusterGroup    = new ComputerServices().GetClusterGroup(_computer.Id);
                    var secondaryServer = new SecondaryServerEntity();
                    foreach (var tftpServer in _clusterGroupServices.GetClusterTftpServers(clusterGroup.Id))
                    {
                        if (tftpServer.ServerId == -1)
                        {
                            path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" +
                                   Path.DirectorySeparatorChar + pxeComputerMac;
                        }
                        else
                        {
                            secondaryServer = _secondaryServerServices.GetSecondaryServer(tftpServer.ServerId);
                            var tftpPath =
                                new APICall(_secondaryServerServices.GetToken(secondaryServer.Name)).SettingApi
                                .GetSetting("Tftp Path").Value;

                            path = tftpPath + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeComputerMac;
                        }

                        string fileContents = null;
                        if (mode == "pxelinux" || mode == "syslinux_32_efi" || mode == "syslinux_64_efi")
                        {
                            fileContents = sysLinux.ToString();
                        }

                        else if (mode.Contains("ipxe"))
                        {
                            path        += ".ipxe";
                            fileContents = ipxe.ToString();
                        }
                        else if (mode.Contains("grub"))
                        {
                            path        += ".cfg";
                            fileContents = grub.ToString();
                        }

                        if (tftpServer.ServerId == -1)
                        {
                            if (!new FileOpsServices().WritePath(path, fileContents))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            if (
                                !new APICall(_secondaryServerServices.GetToken(secondaryServer.Name))
                                .ServiceAccountApi.WriteTftpFile(new TftpFileDTO
                            {
                                Path = path,
                                Contents = fileContents
                            }))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Example #8
0
        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);
            }
        }
Example #9
0
        public int Run()
        {
            //Find best distribution point to use

            int dpId;
            var distributionPointServices = new DistributionPointServices();

            if (SettingServices.ServerIsNotClustered)
            {
                var dp = distributionPointServices.GetPrimaryDistributionPoint();
                if (dp != null)
                {
                    return(dp.Id);
                }
                return(-1);
            }

            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(-1);
            }

            var queueSizesDict = new Dictionary <int, int>();
            var toRemove       = new List <DistributionPointEntity>();
            var clusterDps     = clusterServices.GetClusterDps(clusterGroup.Id);
            var aDps           = new List <DistributionPointEntity>();

            foreach (var clusterDp in clusterDps)
            {
                aDps.Add(distributionPointServices.GetDistributionPoint(clusterDp.DistributionPointId));
            }
            var availableDistributionPoints =
                clusterServices.GetClusterDps(clusterGroup.Id)
                .Select(
                    clusterDp => distributionPointServices.GetDistributionPoint(clusterDp.DistributionPointId))
                .ToList();

            //Check if any Distribution point in the cluster group is the primary dp
            foreach (var dp in availableDistributionPoints.Where(dp => dp.IsPrimary == 1))
            {
                //Cluster Group has a primary, always return the primary for an upload, not necessary but saves syncing to the primary later
                if (_task.Contains("upload"))
                {
                    return(dp.Id);
                }
            }

            foreach (var dp in availableDistributionPoints)
            {
                if (dp.QueueSize == 0)
                {
                    toRemove.Add(dp);
                }
                else
                {
                    queueSizesDict.Add(dp.Id, dp.QueueSize);
                }
            }
            availableDistributionPoints = availableDistributionPoints.Except(toRemove).ToList();

            var taskInUseDict = new Dictionary <int, int>();

            foreach (var dp in availableDistributionPoints)
            {
                var counter = 0;
                foreach (var activeTask in new ActiveImagingTaskServices().GetAll().Where(x => x.Status != "0"))
                {
                    if (activeTask.DpId == dp.Id)
                    {
                        counter++;
                    }
                }

                taskInUseDict.Add(dp.Id, counter);
            }

            var freeDps = new List <DistributionPointEntity>();

            foreach (var dp in availableDistributionPoints)
            {
                if (taskInUseDict[dp.Id] < queueSizesDict[dp.Id])
                {
                    freeDps.Add(dp);
                }
            }

            if (freeDps.Count == 1)
            {
                dpId = freeDps.First().Id;
            }

            else if (freeDps.Count > 1)
            {
                var freeDictionary = new Dictionary <int, int>();
                var slotsInUseList = new List <int>();
                foreach (var dp in freeDps)
                {
                    freeDictionary.Add(dp.Id, taskInUseDict[dp.Id]);
                    slotsInUseList.Add(taskInUseDict[dp.Id]);
                }

                if (slotsInUseList.All(x => x == slotsInUseList[0]))
                {
                    //all image servers have equal free slots - randomly choose one.
                    var index = _random.Next(0, freeDps.Count);
                    dpId = freeDps[index].Id;
                }
                else
                {
                    //Just grab the first one with the smallest queue, could be a duplicate but will eventually even out on it's own
                    var orderedInUse = freeDictionary.OrderBy(x => x.Value);
                    dpId = orderedInUse.First().Key;
                }
            }
            else
            {
                //Free image servers count is 0, pick the one with the lowest number of tasks to be added to the queue
                var orderedInUse = taskInUseDict.OrderBy(x => x.Value);
                dpId = orderedInUse.First().Key;
            }

            return(dpId);
        }
 public CancelAllImagingTasks()
 {
     _computerServices        = new ComputerServices();
     _secondaryServerServices = new SecondaryServerServices();
 }
Example #11
0
        public bool CreatePxeBootFiles()
        {
            var pxeComputerMac     = StringManipulationServices.MacToPxeMac(_computer.Mac);
            var webPath            = SettingServices.GetSettingValue(SettingStrings.WebPath) + "api/ClientImaging/";
            var globalComputerArgs = SettingServices.GetSettingValue(SettingStrings.GlobalComputerArgs);
            var userToken          = SettingServices.GetSettingValue(SettingStrings.WebTaskRequiresLogin) == "No"
                ? SettingServices.GetSettingValue(SettingStrings.UniversalToken)
                : "";
            const string newLineChar = "\n";

            if (_computer.AlternateServerIpId != -1)
            {
                var altServer = new AlternateServerIpServices().GetAlternateServerIp(_computer.AlternateServerIpId);
                if (altServer != null)
                {
                    webPath = altServer.ApiUrl + "api/ClientImaging/";
                }
            }

            var replacedPath = webPath;

            if (SettingServices.GetSettingValue(SettingStrings.IpxeSSL).Equals("1"))
            {
                replacedPath = replacedPath.ToLower().Replace("http", "https");
            }
            else
            {
                replacedPath = replacedPath.ToLower().Replace("https", "http");
            }

            var ipxe = new StringBuilder();

            ipxe.Append("#!ipxe" + newLineChar);
            ipxe.Append("kernel " + replacedPath + "IpxeBoot?filename=" + _imageProfile.Kernel +
                        "&type=kernel" + " initrd=" + _imageProfile.BootImage +
                        " root=/dev/ram0 rw ramdisk_size=156000" +
                        " consoleblank=0" + " web=" + webPath + " USER_TOKEN=" + userToken + " " + globalComputerArgs +
                        " " + _imageProfile.KernelArguments + newLineChar);
            ipxe.Append("imgfetch --name " + _imageProfile.BootImage + " " + replacedPath +
                        "IpxeBoot?filename=" + _imageProfile.BootImage + "&type=bootimage" + newLineChar);
            ipxe.Append("boot" + newLineChar);

            var sysLinux = new StringBuilder();

            sysLinux.Append("DEFAULT clonedeploy" + newLineChar);
            sysLinux.Append("LABEL clonedeploy" + newLineChar);
            sysLinux.Append("KERNEL kernels" + Path.DirectorySeparatorChar + _imageProfile.Kernel + newLineChar);
            sysLinux.Append("APPEND initrd=images" + Path.DirectorySeparatorChar + _imageProfile.BootImage +
                            " root=/dev/ram0 rw ramdisk_size=156000" +
                            " consoleblank=0" + " web=" + webPath + " USER_TOKEN=" + userToken + " " +
                            globalComputerArgs +
                            " " + _imageProfile.KernelArguments + newLineChar);

            var grub = new StringBuilder();

            grub.Append("set default=0" + newLineChar);
            grub.Append("set timeout=0" + newLineChar);
            grub.Append("menuentry CloneDeploy --unrestricted {" + newLineChar);
            grub.Append("echo Please Wait While The Boot Image Is Transferred.  This May Take A Few Minutes." +
                        newLineChar);
            grub.Append("linux /kernels/" + _imageProfile.Kernel +
                        " root=/dev/ram0 rw ramdisk_size=156000" + " consoleblank=0" + " web=" + webPath +
                        " USER_TOKEN=" +
                        userToken + " " +
                        globalComputerArgs + " " + _imageProfile.KernelArguments + newLineChar);
            grub.Append("initrd /images/" + _imageProfile.BootImage + newLineChar);
            grub.Append("}" + newLineChar);

            var list = new List <Tuple <string, string, string> >
            {
                Tuple.Create("bios", "", sysLinux.ToString()),
                Tuple.Create("bios", ".ipxe", ipxe.ToString()),
                Tuple.Create("efi32", "", sysLinux.ToString()),
                Tuple.Create("efi32", ".ipxe", ipxe.ToString()),
                Tuple.Create("efi64", "", sysLinux.ToString()),
                Tuple.Create("efi64", ".ipxe", ipxe.ToString()),
                Tuple.Create("efi64", ".cfg", grub.ToString())
            };

            //In proxy mode all boot files are created regardless of the pxe mode, this way computers can be customized
            //to use a specific boot file without affecting all others, using the proxydhcp reservations file.
            if (SettingServices.GetSettingValue(SettingStrings.ProxyDhcp) == "Yes")
            {
                if (SettingServices.ServerIsNotClustered)
                {
                    foreach (var bootMenu in list)
                    {
                        var path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" +
                                   Path.DirectorySeparatorChar + bootMenu.Item1 +
                                   Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar +
                                   pxeComputerMac +
                                   bootMenu.Item2;

                        if (!new FileOpsServices().WritePath(path, bootMenu.Item3))
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    var clusterGroup = new ComputerServices().GetClusterGroup(_computer.Id);
                    var tftpServers  = _clusterGroupServices.GetClusterTftpServers(clusterGroup.Id);  // patch by Diederick Niehorster! See comment below. Ask Diederick
                    if (tftpServers.Count == 0)
                    {
                        // no tftp server found for this cluster. I have seen that happen when using a
                        // fake cluster where both members are different NICs on the same computer. That
                        // means no secondary server can be defined for the cluster, which messes up
                        // defining tftp role for for the cluster group (foreign key constraint failure
                        // because there is no secondary server). Then we get count=0 here. Fall back to
                        // seeing if the server we're on has tftp role defined in its cluster server role
                        // and if so, use it
                        if (SettingServices.GetSettingValue(SettingStrings.TftpServerRole).Equals("1"))
                        {
                            var fakeServer = new ClusterGroupServerEntity();
                            fakeServer.ServerId = -1;    // only thing that needs to be set
                            tftpServers.Add(fakeServer);
                        }
                    }
                    foreach (var tftpServer in tftpServers)
                    {
                        foreach (var bootMenu in list)
                        {
                            if (tftpServer.ServerId == -1)
                            {
                                var path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" +
                                           Path.DirectorySeparatorChar + bootMenu.Item1 +
                                           Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar +
                                           pxeComputerMac +
                                           bootMenu.Item2;

                                if (!new FileOpsServices().WritePath(path, bootMenu.Item3))
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                var secondaryServer = _secondaryServerServices.GetSecondaryServer(tftpServer.ServerId);
                                var tftpPath        =
                                    new APICall(_secondaryServerServices.GetToken(secondaryServer.Name))
                                    .SettingApi.GetSetting("Tftp Path").Value;

                                var path = tftpPath + "proxy" + Path.DirectorySeparatorChar + bootMenu.Item1 +
                                           Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar +
                                           pxeComputerMac +
                                           bootMenu.Item2;

                                if (
                                    !new APICall(_secondaryServerServices.GetToken(secondaryServer.Name))
                                    .ServiceAccountApi.WriteTftpFile(new TftpFileDTO
                                {
                                    Path = path,
                                    Contents = bootMenu.Item3
                                }))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }
            //When not using proxy dhcp, only one boot file is created
            else
            {
                var mode = SettingServices.GetSettingValue(SettingStrings.PxeMode);
                var path = "";
                if (SettingServices.ServerIsNotClustered)
                {
                    path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" +
                           Path.DirectorySeparatorChar + pxeComputerMac;

                    string fileContents = null;
                    if (mode == "pxelinux" || mode == "syslinux_32_efi" || mode == "syslinux_64_efi")
                    {
                        fileContents = sysLinux.ToString();
                    }

                    else if (mode.Contains("ipxe"))
                    {
                        path        += ".ipxe";
                        fileContents = ipxe.ToString();
                    }
                    else if (mode.Contains("grub"))
                    {
                        path        += ".cfg";
                        fileContents = grub.ToString();
                    }

                    if (!new FileOpsServices().WritePath(path, fileContents))
                    {
                        return(false);
                    }
                }
                else
                {
                    var clusterGroup    = new ComputerServices().GetClusterGroup(_computer.Id);
                    var secondaryServer = new SecondaryServerEntity();
                    var tftpServers     = _clusterGroupServices.GetClusterTftpServers(clusterGroup.Id); // patch by Diederick Niehorster! See comment below. Ask Diederick
                    if (tftpServers.Count == 0)
                    {
                        // no tftp server found for this cluster. I have seen that happen when using a
                        // fake cluster where both members are different NICs on the same computer. That
                        // means no secondary server can be defined for the cluster, which messes up
                        // defining tftp role for for the cluster group (foreign key constraint failure
                        // because there is no secondary server). Then we get count=0 here. Fall back to
                        // seeing if the server we're on has tftp role defined in its cluster server role
                        // and if so, use it
                        if (SettingServices.GetSettingValue(SettingStrings.TftpServerRole).Equals("1"))
                        {
                            var fakeServer = new ClusterGroupServerEntity();
                            fakeServer.ServerId = -1;    // only thing that needs to be set
                            tftpServers.Add(fakeServer);
                        }
                    }
                    foreach (var tftpServer in tftpServers)
                    {
                        if (tftpServer.ServerId == -1)
                        {
                            path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" +
                                   Path.DirectorySeparatorChar + pxeComputerMac;
                        }
                        else
                        {
                            secondaryServer = _secondaryServerServices.GetSecondaryServer(tftpServer.ServerId);
                            var tftpPath =
                                new APICall(_secondaryServerServices.GetToken(secondaryServer.Name)).SettingApi
                                .GetSetting("Tftp Path").Value;

                            path = tftpPath + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeComputerMac;
                        }

                        string fileContents = null;
                        if (mode == "pxelinux" || mode == "syslinux_32_efi" || mode == "syslinux_64_efi")
                        {
                            fileContents = sysLinux.ToString();
                        }

                        else if (mode.Contains("ipxe"))
                        {
                            path        += ".ipxe";
                            fileContents = ipxe.ToString();
                        }
                        else if (mode.Contains("grub"))
                        {
                            path        += ".cfg";
                            fileContents = grub.ToString();
                        }

                        if (tftpServer.ServerId == -1)
                        {
                            if (!new FileOpsServices().WritePath(path, fileContents))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            if (
                                !new APICall(_secondaryServerServices.GetToken(secondaryServer.Name))
                                .ServiceAccountApi.WriteTftpFile(new TftpFileDTO
                            {
                                Path = path,
                                Contents = fileContents
                            }))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }