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 TftpServerDTO GetAllTftpServers() { var tftpDto = new TftpServerDTO(); tftpDto.TftpServers = new List <string>(); if (SettingServices.ServerIsNotClustered) { tftpDto.TftpServers.Add( StringManipulationServices.PlaceHolderReplace( SettingServices.GetSettingValue(SettingStrings.TftpServerIp))); } else { if (SettingServices.TftpServerRole) { tftpDto.TftpServers.Add( StringManipulationServices.PlaceHolderReplace( SettingServices.GetSettingValue(SettingStrings.TftpServerIp))); } var tftpServers = new SecondaryServerServices().SearchSecondaryServers().Where(x => x.TftpRole == 1 && x.IsActive == 1); foreach (var tftpServer in tftpServers) { var tServer = new APICall(new SecondaryServerServices().GetToken(tftpServer.Name)).ServiceAccountApi .GetTftpServer(); if (!string.IsNullOrEmpty(tServer)) { tftpDto.TftpServers.Add(tServer); } } } return(tftpDto); }
public static string PlaceHolderReplace(string parameter) { if (string.IsNullOrEmpty(parameter)) { return(parameter); } var start = parameter.IndexOf("[", StringComparison.Ordinal); var to = parameter.IndexOf("]", start + "[".Length, StringComparison.Ordinal); if (start < 0 || to < 0) { return(parameter); } var s = parameter.Substring( start + "[".Length, to - start - "[".Length); if (s == "server-ip") { return(parameter.Replace("[server-ip]", SettingServices.GetSettingValue(SettingStrings.ServerIp))); } if (s == "tftp-server-ip") { return(parameter.Replace("[tftp-server-ip]", SettingServices.GetSettingValue(SettingStrings.TftpServerIp))); } return(s); }
public ActionResultDTO CheckApprovalAndChecksum(ImageEntity image, int userId) { var actionResult = new ActionResultDTO(); if (image == null) { actionResult.Success = false; actionResult.ErrorMessage = "Image Does Not Exist"; return(actionResult); } if (image.Enabled == 0) { actionResult.Success = false; actionResult.ErrorMessage = "Image Is Not Enabled"; return(actionResult); } if (SettingServices.GetSettingValue(SettingStrings.RequireImageApproval).ToLower() == "true") { var user = _userServices.GetUser(userId); if (user.Membership != "Administrator") //administrators don't need image approval { if (!Convert.ToBoolean(image.Approved)) { actionResult.Success = false; actionResult.ErrorMessage = "Image Has Not Been Approved"; return(actionResult); } } } actionResult.Success = true; return(actionResult); }
public void DeleteBootFiles(ComputerEntity computer) { if (new ComputerServices().IsComputerActive(computer.Id)) { return; //Files Will Be Processed When task is done } var pxeMac = StringManipulationServices.MacToPxeMac(computer.Mac); var list = new List <Tuple <string, string> > { Tuple.Create("bios", ""), Tuple.Create("bios", ".ipxe"), Tuple.Create("efi32", ""), Tuple.Create("efi32", ".ipxe"), Tuple.Create("efi64", ""), Tuple.Create("efi64", ".ipxe"), Tuple.Create("efi64", ".cfg") }; foreach (var tuple in list) { new FileOpsServices().DeletePath(SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + tuple.Item1 + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac + tuple.Item2); } foreach (var ext in new[] { "", ".ipxe", ".cfg" }) { new FileOpsServices().DeletePath(SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac + ext); } }
public void SendLockOutEmail(int userId) { //Mail not enabled if (SettingServices.GetSettingValue(SettingStrings.SmtpEnabled) == "0") { return; } var lockedUser = GetUser(userId); foreach (var user in SearchUsers("").Where(x => x.NotifyLockout == 1 && !string.IsNullOrEmpty(x.Email))) { if (user.Membership != "Administrator" && user.Id != userId) { continue; } var mail = new MailServices { MailTo = user.Email, Body = lockedUser.Name + " Has Been Locked For 15 Minutes Because Of Too Many Failed Login Attempts", Subject = "User Locked" }; mail.Send(); } }
public int GetNextPort() { var lastPort = new PortEntity(); var nextPort = new PortEntity(); lastPort = _uow.PortRepository.GetFirstOrDefault(orderBy: q => q.OrderByDescending(p => p.Id)); if (lastPort == null) { nextPort.Number = Convert.ToInt32(SettingServices.GetSettingValue(SettingStrings.StartPort)); } else if (nextPort.Number >= Convert.ToInt32(SettingServices.GetSettingValue(SettingStrings.EndPort))) { nextPort.Number = Convert.ToInt32(SettingServices.GetSettingValue(SettingStrings.StartPort)); } else { nextPort.Number = lastPort.Number + 2; } AddPort(nextPort); return(nextPort.Number); }
public string IsLoginRequired(string task) { switch (task) { case "ond": return(SettingServices.GetSettingValue(SettingStrings.OnDemandRequiresLogin)); case "debug": return(SettingServices.GetSettingValue(SettingStrings.DebugRequiresLogin)); case "register": return(SettingServices.GetSettingValue(SettingStrings.RegisterRequiresLogin)); case "clobber": return(SettingServices.GetSettingValue(SettingStrings.ClobberRequiresLogin)); case "deploy": case "permanentdeploy": case "upload": case "multicast": case "modelmatchdeploy": return(SettingServices.GetSettingValue(SettingStrings.WebTaskRequiresLogin)); default: return("Yes"); } }
public string GetRegistrationSettings() { var regDto = new RegistrationDTO(); regDto.registrationEnabled = SettingServices.GetSettingValue(SettingStrings.RegistrationEnabled); regDto.keepNamePrompt = SettingServices.GetSettingValue(SettingStrings.OnDemandNamePrompt); return(JsonConvert.SerializeObject(regDto)); }
public bool Authenticate(string username, string pwd, string ldapGroup = null) { if (SettingServices.GetSettingValue(SettingStrings.LdapEnabled) != "1") { return(false); } var path = "LDAP://" + SettingServices.GetSettingValue(SettingStrings.LdapServer) + ":" + SettingServices.GetSettingValue(SettingStrings.LdapPort) + "/" + SettingServices.GetSettingValue(SettingStrings.LdapBaseDN); string _filterAttribute = null; var entry = new DirectoryEntry(path, username, pwd); if (SettingServices.GetSettingValue(SettingStrings.LdapAuthType) == "Basic") { entry.AuthenticationType = AuthenticationTypes.None; } else if (SettingServices.GetSettingValue(SettingStrings.LdapAuthType) == "Secure") { entry.AuthenticationType = AuthenticationTypes.Secure; } else if (SettingServices.GetSettingValue(SettingStrings.LdapAuthType) == "SSL") { entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer; } try { // Bind to the native AdsObject to force authentication. var obj = entry.NativeObject; var search = new DirectorySearcher(entry); search.Filter = "(" + SettingServices.GetSettingValue(SettingStrings.LdapAuthAttribute) + "=" + username + ")"; search.PropertiesToLoad.Add("cn"); search.PropertiesToLoad.Add("memberOf"); var result = search.FindOne(); if (null == result) { return(false); } // Update the new path to the user in the directory path = result.Path; _filterAttribute = (string)result.Properties["cn"][0]; } catch (Exception ex) { log.Error("Could Not Authenticate User: "******" " + ex.Message); return(false); } if (ldapGroup != null) { return(GetGroups(_filterAttribute, path, ldapGroup)); } return(true); }
public List <ImageEntity> GetOnDemandImageList(string task, int userId = 0) { if (userId == 0) { return(_uow.ImageRepository.Get(i => i.IsVisible == 1 && i.Enabled == 1, q => q.OrderBy(p => p.Name))); } if (_userServices.GetUser(userId).Membership == "Administrator") { return(_uow.ImageRepository.Get(i => i.IsVisible == 1 && i.Enabled == 1, q => q.OrderBy(p => p.Name))); } var user = _userServices.GetUser(userId); var requireImageApproval = new SettingServices().GetSetting(SettingStrings.RequireImageApproval).Value; if (user.ImageManagementEnabled == 0) { if (requireImageApproval == "True" && !task.Contains("upload")) { return(_uow.ImageRepository.Get(i => i.IsVisible == 1 && i.Enabled == 1 && i.Approved == 1, q => q.OrderBy(p => p.Name))); } else { return(_uow.ImageRepository.Get(i => i.IsVisible == 1 && i.Enabled == 1, q => q.OrderBy(p => p.Name))); } } var userManagedImages = _userServices.GetUserImageManagements(userId); var listOfImages = new List <ImageEntity>(); if (requireImageApproval == "True" && !task.Contains("upload")) { foreach (var userManagedImage in userManagedImages) { var image = _uow.ImageRepository.GetFirstOrDefault( i => i.IsVisible == 1 && i.Id == userManagedImage.ImageId && i.Enabled == 1 && i.Approved == 1); if (image != null) { listOfImages.Add(image); } } } else { foreach (var userManagedImage in userManagedImages) { var image = _uow.ImageRepository.GetFirstOrDefault( i => i.IsVisible == 1 && i.Id == userManagedImage.ImageId && i.Enabled == 1); if (image != null) { listOfImages.Add(image); } } } return(listOfImages); }
public List <FileInfo> GetMunkiResources(string type) { FileInfo[] directoryFiles = null; var pkgInfoFiles = SettingServices.GetSettingValue(SettingStrings.MunkiBasePath) + Path.DirectorySeparatorChar + type + Path.DirectorySeparatorChar; if (SettingServices.GetSettingValue(SettingStrings.MunkiPathType) == "Local") { var di = new DirectoryInfo(pkgInfoFiles); try { directoryFiles = di.GetFiles("*.*"); } catch (Exception ex) { log.Error(ex.Message); } } else { using (var unc = new UncServices()) { var smbPassword = new EncryptionServices().DecryptText( SettingServices.GetSettingValue(SettingStrings.MunkiSMBPassword)); var smbDomain = string.IsNullOrEmpty(SettingServices.GetSettingValue(SettingStrings.MunkiSMBDomain)) ? "" : SettingServices.GetSettingValue(SettingStrings.MunkiSMBDomain); if ( unc.NetUseWithCredentials(SettingServices.GetSettingValue(SettingStrings.MunkiBasePath), SettingServices.GetSettingValue(SettingStrings.MunkiSMBUsername), smbDomain, smbPassword) || unc.LastError == 1219) { var di = new DirectoryInfo(pkgInfoFiles); try { directoryFiles = di.GetFiles("*.*"); } catch (Exception ex) { log.Error(ex.Message); } } else { log.Error("Failed to connect to " + SettingServices.GetSettingValue(SettingStrings.MunkiBasePath) + "\r\nLastError = " + unc.LastError); } } } return(directoryFiles.ToList()); }
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 bool Authorize(string token) { if (token == SettingServices.GetSettingValue(SettingStrings.UniversalToken) && !string.IsNullOrEmpty(SettingServices.GetSettingValue(SettingStrings.UniversalToken))) { return(true); } var user = new UserServices().GetUserByToken(token); if (user != null) { return(true); } return(false); }
public bool DeleteTftpFile(string path) { if (path.StartsWith(SettingServices.GetSettingValue(SettingStrings.TftpPath))) { try { File.Delete(path); return(true); } catch (Exception ex) { log.Error(ex.Message); return(false); } } log.Error("Could Not Delete Tftp File " + path + " It Is Not A Sub Directory Of The Base Tftp Path"); return(false); }
private bool WebDownload(OnlineKernel onlineKernel) { var baseUrl = "http://files.clonedeploy.org/kernels/"; using (var wc = new WebClient()) { try { wc.DownloadFile(new Uri(baseUrl + onlineKernel.BaseVersion + "/" + onlineKernel.FileName), SettingServices.GetSettingValue(SettingStrings.TftpPath) + "kernels" + Path.DirectorySeparatorChar + onlineKernel.FileName); return(true); } catch (Exception ex) { log.Error(ex.Message); return(false); } } }
public string GetComputerNonProxyPath(int computerId, bool isActiveOrCustom) { var computer = GetComputer(computerId); var mode = SettingServices.GetSettingValue(SettingStrings.PxeMode); var pxeComputerMac = StringManipulationServices.MacToPxeMac(computer.Mac); string path; var fileName = isActiveOrCustom ? pxeComputerMac : "default"; if (mode.Contains("ipxe")) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" + Path.DirectorySeparatorChar + fileName + ".ipxe"; } else if (mode.Contains("grub")) { if (isActiveOrCustom) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeComputerMac + ".cfg"; } else { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "grub" + Path.DirectorySeparatorChar + "grub.cfg"; } } else { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" + Path.DirectorySeparatorChar + fileName; } return(path); }
public static List <string> GetBootImages() { var bootImagePath = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "images" + Path.DirectorySeparatorChar; var bootImageFiles = new List <string>(); try { var files = Directory.GetFiles(bootImagePath, "*.*"); for (var x = 0; x < files.Length; x++) { bootImageFiles.Add(Path.GetFileName(files[x])); } } catch (Exception ex) { log.Error(ex.Message); } return(bootImageFiles); }
public static List <string> GetKernels() { var kernelPath = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "kernels" + Path.DirectorySeparatorChar; var result = new List <string>(); try { var kernelFiles = Directory.GetFiles(kernelPath, "*.*"); for (var x = 0; x < kernelFiles.Length; x++) { result.Add(Path.GetFileName(kernelFiles[x])); } } catch (Exception ex) { log.Error(ex.Message); } return(result); }
public string IpxeLogin(string username, string password, string kernel, string bootImage, string task) { var webPath = SettingServices.GetSettingValue(SettingStrings.WebPath) + "api/ClientImaging/"; var newLineChar = "\n"; string userToken; if (SettingServices.GetSettingValue(SettingStrings.DebugRequiresLogin) == "No" || SettingServices.GetSettingValue(SettingStrings.OnDemandRequiresLogin) == "No" || SettingServices.GetSettingValue(SettingStrings.RegisterRequiresLogin) == "No" || SettingServices.GetSettingValue(SettingStrings.WebTaskRequiresLogin) == "No") { userToken = SettingServices.GetSettingValue(SettingStrings.UniversalToken); } else { userToken = ""; } var globalComputerArgs = SettingServices.GetSettingValue(SettingStrings.GlobalComputerArgs); var validationResult = GlobalLogin(username, password, "iPXE"); if (!validationResult.Success) { return("goto Menu"); } var lines = "#!ipxe" + newLineChar; lines += "kernel " + webPath + "IpxeBoot?filename=" + kernel + "&type=kernel" + " initrd=" + bootImage + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" + webPath + " USER_TOKEN=" + userToken + " consoleblank=0 " + globalComputerArgs + newLineChar; lines += "imgfetch --name " + bootImage + " " + webPath + "IpxeBoot?filename=" + bootImage + "&type=bootimage" + newLineChar; lines += "boot"; return(lines); }
public void CancelTimedOutTasks() { var timeout = SettingServices.GetSettingValue(SettingStrings.TaskTimeout); if (string.IsNullOrEmpty(timeout)) { return; } if (timeout == "0") { return; } var tasks = GetAll(); foreach (var task in tasks.Where(task => task.Status == "3" && !task.Type.ToLower().Contains("upload"))) { if (DateTime.Now > task.LastUpdateTime.AddMinutes(Convert.ToInt32(timeout))) { DeleteActiveImagingTask(task.Id); log.Debug("Task Timeout Hit. Task " + task.Id + "Cancelled. Computer Id " + task.ComputerId); } } }
public void SendMulticastCompletedEmail(ActiveMulticastSessionEntity session) { //Mail not enabled if (SettingServices.GetSettingValue(SettingStrings.SmtpEnabled) == "0") { return; } foreach ( var user in _userServices.SearchUsers("").Where(x => x.NotifyComplete == 1 && !string.IsNullOrEmpty(x.Email))) { if (session.UserId == user.Id) { var mail = new MailServices { MailTo = user.Email, Body = session.Name + " Multicast Task Has Completed.", Subject = "Multicast Completed" }; mail.Send(); } } }
public void SendImageApprovedEmail(int imageId) { //Mail not enabled if (SettingServices.GetSettingValue(SettingStrings.SmtpEnabled) == "0") { return; } var image = GetImage(imageId); foreach ( var user in _userServices.SearchUsers("") .Where(x => x.NotifyImageApproved == 1 && !string.IsNullOrEmpty(x.Email))) { var mail = new MailServices { MailTo = user.Email, Body = image.Name + " Has Been Approved", Subject = "Image Approved" }; mail.Send(); } }
public string GetDefaultBootMenuPath(string type) { string path = null; var tftpPath = SettingServices.GetSettingValue(SettingStrings.TftpPath); var mode = SettingServices.GetSettingValue(SettingStrings.PxeMode); var proxyDhcp = SettingServices.GetSettingValue(SettingStrings.ProxyDhcp); if (proxyDhcp == "Yes") { var biosFile = SettingServices.GetSettingValue(SettingStrings.ProxyBiosFile); var efi32File = SettingServices.GetSettingValue(SettingStrings.ProxyEfi32File); var efi64File = SettingServices.GetSettingValue(SettingStrings.ProxyEfi64File); if (type == "bios") { if (biosFile.Contains("ipxe")) { path = tftpPath + "proxy" + Path.DirectorySeparatorChar + type + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default.ipxe"; } else { path = tftpPath + "proxy" + Path.DirectorySeparatorChar + type + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default"; } } if (type == "efi32") { if (efi32File.Contains("ipxe")) { path = tftpPath + "proxy" + Path.DirectorySeparatorChar + type + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default.ipxe"; } else { path = tftpPath + "proxy" + Path.DirectorySeparatorChar + type + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default"; } } if (type == "efi64") { if (efi64File.Contains("ipxe")) { path = tftpPath + "proxy" + Path.DirectorySeparatorChar + type + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default.ipxe"; } else if (mode.Contains("grub")) { path = tftpPath + "grub" + Path.DirectorySeparatorChar + "grub.cfg"; } else { path = tftpPath + "proxy" + Path.DirectorySeparatorChar + type + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default"; } } } else { if (mode.Contains("ipxe")) { path = tftpPath + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default.ipxe"; } else if (mode.Contains("grub")) { path = tftpPath + "grub" + Path.DirectorySeparatorChar + "grub.cfg"; } else { path = tftpPath + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default"; } } return(path); }
public string CheckTaskAuth(string task, string token) { var userServices = new UserServices(); //only check ond and debug because web tasks can't even be started if user isn't authorized if (task == "ond" && SettingServices.GetSettingValue(SettingStrings.OnDemand) != "Enabled") { log.Debug("A client tried to image with on demand mode, but it is not enabled on the server"); return("false"); } if (task == "clobber" && SettingServices.GetSettingValue(SettingStrings.ClobberEnabled) != "1") { log.Debug("A client tried to image with clobber mode, but it is not enabled on the server"); return("false"); } if (task == "ond" && SettingServices.GetSettingValue(SettingStrings.OnDemandRequiresLogin) == "No") { if (token == SettingServices.GetSettingValue(SettingStrings.UniversalToken) && !string.IsNullOrEmpty(SettingServices.GetSettingValue(SettingStrings.UniversalToken))) { return("true"); } } else if (task == "ond" && SettingServices.GetSettingValue(SettingStrings.OnDemandRequiresLogin) == "Yes") { var user = userServices.GetUserByToken(token); if (user != null) { if (new AuthorizationServices(user.Id, AuthorizationStrings.AllowOnd).IsAuthorized()) { return("true"); } } } else if (task == "debug" && SettingServices.GetSettingValue(SettingStrings.DebugRequiresLogin) == "No") { if (token == SettingServices.GetSettingValue(SettingStrings.UniversalToken) && !string.IsNullOrEmpty(SettingServices.GetSettingValue(SettingStrings.UniversalToken))) { return("true"); } } else if (task == "debug" && SettingServices.GetSettingValue(SettingStrings.DebugRequiresLogin) == "Yes") { var user = userServices.GetUserByToken(token); if (user != null) { if (new AuthorizationServices(user.Id, AuthorizationStrings.AllowDebug).IsAuthorized()) { return("true"); } } } else if (task == "clobber" && SettingServices.GetSettingValue(SettingStrings.ClobberRequiresLogin) == "No") { if (token == SettingServices.GetSettingValue(SettingStrings.UniversalToken) && !string.IsNullOrEmpty(SettingServices.GetSettingValue(SettingStrings.UniversalToken))) { return("true"); } } else if (task == "clobber" && SettingServices.GetSettingValue(SettingStrings.ClobberRequiresLogin) == "Yes") { var user = userServices.GetUserByToken(token); if (user != null) { if (new AuthorizationServices(user.Id, AuthorizationStrings.ImageDeployTask).IsAuthorized()) { return("true"); } } } return("false"); }
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 GetComputerProxyPath(int computerId, bool isActiveOrCustom, string proxyType) { var computer = GetComputer(computerId); var pxeComputerMac = StringManipulationServices.MacToPxeMac(computer.Mac); string path = null; var biosFile = SettingServices.GetSettingValue(SettingStrings.ProxyBiosFile); var efi32File = SettingServices.GetSettingValue(SettingStrings.ProxyEfi32File); var efi64File = SettingServices.GetSettingValue(SettingStrings.ProxyEfi64File); var fileName = isActiveOrCustom ? pxeComputerMac : "default"; switch (proxyType) { case "bios": if (biosFile.Contains("ipxe")) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + proxyType + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + fileName + ".ipxe"; } else { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + proxyType + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + fileName; } break; case "efi32": if (efi32File.Contains("ipxe")) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + proxyType + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + fileName + ".ipxe"; } else { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + proxyType + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + fileName; } break; case "efi64": if (efi64File.Contains("ipxe")) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + proxyType + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + fileName + ".ipxe"; } else if (efi64File.Contains("grub")) { if (isActiveOrCustom) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + proxyType + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeComputerMac + ".cfg"; } else { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "grub" + Path.DirectorySeparatorChar + "grub.cfg"; } } else { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + proxyType + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + fileName; } break; } return(path); }
public ValidationResultDTO GlobalLogin(string userName, string password, string loginType) { var validationResult = new ValidationResultDTO { ErrorMessage = "Incorrect Username Or Password", Success = false }; var auditLog = new AuditLogEntity(); var auditLogService = new AuditLogServices(); auditLog.ObjectId = -1; auditLog.ObjectName = userName; auditLog.Ip = IpServices.GetIPAddress(); auditLog.UserId = -1; auditLog.ObjectType = "User"; auditLog.AuditType = AuditEntry.Type.FailedLogin; //Check if user exists in Clone Deploy var user = _userServices.GetUser(userName); if (user == null) { //Check For a first time LDAP User Group Login if (SettingServices.GetSettingValue(SettingStrings.LdapEnabled) == "1") { foreach (var ldapGroup in _userGroupServices.GetLdapGroups()) { if (new LdapServices().Authenticate(userName, password, ldapGroup.GroupLdapName)) { //user is a valid ldap user via ldap group that has not yet logged in. //Add the user and allow login. var cdUser = new CloneDeployUserEntity { Name = userName, Salt = Utility.CreateSalt(64), Token = Utility.GenerateKey(), IsLdapUser = 1 }; //Create a local random db pass, should never actually be possible to use. cdUser.Password = Utility.CreatePasswordHash(Utility.GenerateKey(), cdUser.Salt); if (_userServices.AddUser(cdUser).Success) { //add user to group var newUser = _userServices.GetUser(userName); _userGroupServices.AddNewGroupMember(ldapGroup.Id, newUser.Id); auditLog.UserId = newUser.Id; auditLog.ObjectId = newUser.Id; validationResult.Success = true; auditLog.AuditType = AuditEntry.Type.SuccessfulLogin; break; } } } } auditLogService.AddAuditLog(auditLog); return(validationResult); } if (_userLockoutServices.AccountIsLocked(user.Id)) { _userLockoutServices.ProcessBadLogin(user.Id); validationResult.ErrorMessage = "Account Is Locked"; auditLog.UserId = user.Id; auditLog.ObjectId = user.Id; auditLogService.AddAuditLog(auditLog); return(validationResult); } //Check against AD if (user.IsLdapUser == 1 && SettingServices.GetSettingValue(SettingStrings.LdapEnabled) == "1") { //Check if user is authenticated against an ldap group if (user.UserGroupId != -1) { //user is part of a group, is the group an ldap group? var userGroup = _userGroupServices.GetUserGroup(user.UserGroupId); if (userGroup != null) { if (userGroup.IsLdapGroup == 1) { //the group is an ldap group //make sure user is still in that ldap group if (new LdapServices().Authenticate(userName, password, userGroup.GroupLdapName)) { validationResult.Success = true; } else { //user is either not in that group anymore, not in the directory, or bad password validationResult.Success = false; if (new LdapServices().Authenticate(userName, password)) { //password was good but user is no longer in the group //delete the user _userServices.DeleteUser(user.Id); } } } else { //the group is not an ldap group //still need to check creds against directory if (new LdapServices().Authenticate(userName, password)) { validationResult.Success = true; } } } else { //group didn't exist for some reason //still need to check creds against directory if (new LdapServices().Authenticate(userName, password)) { validationResult.Success = true; } } } else { //user is not part of a group, check creds against directory if (new LdapServices().Authenticate(userName, password)) { validationResult.Success = true; } } } else if (user.IsLdapUser == 1 && SettingServices.GetSettingValue(SettingStrings.LdapEnabled) != "1") { //prevent ldap user from logging in with local pass if ldap auth gets turned off validationResult.Success = false; } //Check against local DB else { var hash = Utility.CreatePasswordHash(password, user.Salt); if (user.Password == hash) { validationResult.Success = true; } } if (validationResult.Success) { auditLog.AuditType = AuditEntry.Type.SuccessfulLogin; auditLog.UserId = user.Id; auditLog.ObjectId = user.Id; auditLogService.AddAuditLog(auditLog); _userLockoutServices.DeleteUserLockouts(user.Id); return(validationResult); } auditLog.AuditType = AuditEntry.Type.FailedLogin; auditLog.UserId = user.Id; auditLog.ObjectId = user.Id; auditLogService.AddAuditLog(auditLog); _userLockoutServices.ProcessBadLogin(user.Id); return(validationResult); }
public static string GetSettingValue(string settingName) { var setting = new SettingServices().GetSetting(settingName); return(setting != null ? setting.Value : string.Empty); }
public ActionResultDTO AddSecondaryServer(SecondaryServerEntity secondaryServer) { var actionResult = new ActionResultDTO(); //Verify connection to secondary server //Get token var customApiCall = new CustomApiCallDTO(); customApiCall.BaseUrl = new Uri(secondaryServer.ApiURL); var token = new APICall(customApiCall).TokenApi.Get(secondaryServer.ServiceAccountName, secondaryServer.ServiceAccountPassword); var serverRoles = new ServerRoleDTO(); if (token != null) { if (!string.IsNullOrEmpty(token.error_description)) { actionResult.ErrorMessage = token.error_description; return(actionResult); } customApiCall.Token = token.access_token; serverRoles = new APICall(customApiCall).ServiceAccountApi.GetServerRoles(); if (serverRoles.OperationMode != "Cluster Secondary") { actionResult.ErrorMessage = "Could Not Add Secondary Server. It's Operation Mode Must First Be Changed To Cluster Secondary."; return(actionResult); } if (!serverRoles.IsImageServer && !serverRoles.IsTftpServer && !serverRoles.IsMulticastServer) { actionResult.ErrorMessage = "Could Not Add Secondary Server. You Must First Assign Roles To The Server"; return(actionResult); } if (serverRoles.Identifier == SettingServices.GetSettingValue(SettingStrings.ServerIdentifier)) { actionResult.ErrorMessage = "Could Not Add Secondary Server. Server Identifiers Must Be Different"; return(actionResult); } } else { actionResult.ErrorMessage = "Unknown Error While Attempting To Contact Secondary Server"; return(actionResult); } secondaryServer.Name = serverRoles.Identifier; secondaryServer.TftpRole = Convert.ToInt16(serverRoles.IsTftpServer); secondaryServer.MulticastRole = Convert.ToInt16(serverRoles.IsMulticastServer); secondaryServer.ServiceAccountPassword = new EncryptionServices().EncryptText(secondaryServer.ServiceAccountPassword); var validationResult = ValidateSecondaryServer(secondaryServer, true); if (validationResult.Success) { _uow.SecondaryServerRepository.Insert(secondaryServer); _uow.Save(); actionResult.Success = true; actionResult.Id = secondaryServer.Id; } else { actionResult.ErrorMessage = validationResult.ErrorMessage; } return(actionResult); }