protected string GetSocialLinkUrl(string name) { SettingServices settingServices = new SettingServices(); var key = settingServices.GetSocailKey(name); return(key != null ? key.Value : ""); }
public void Configuration(IAppBuilder app) { var OAuthServerOptions = new OAuthAuthorizationServerOptions { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromHours(8), Provider = new SimpleAuthorizationServerProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()); // Hangfire initialization if (SettingServices.GetSettingValue(SettingStrings.OperationMode) == "Cluster Primary") { var stringInterval = SettingServices.GetSettingValue(SettingStrings.SecondaryServerMonitorInterval); int interval = 0; var result = Int32.TryParse(stringInterval, out interval); if (result && interval != 0) { GlobalConfiguration.Configuration.UseMemoryStorage(); app.UseHangfireDashboard(); app.UseHangfireServer(); RecurringJob.AddOrUpdate(() => new SecondaryServerMonitor().Execute(), Cron.MinuteInterval(interval)); } } }
private void SendMailAsync() { try { var message = new MailMessage(SettingServices.GetSettingValue(SettingStrings.SmtpMailFrom), MailTo) { Subject = "CloneDeploy " + "(" + Subject + ")", Body = Body }; var client = new SmtpClient(SettingServices.GetSettingValue(SettingStrings.SmtpServer), Convert.ToInt32(SettingServices.GetSettingValue(SettingStrings.SmtpPort))) { Credentials = new NetworkCredential(SettingServices.GetSettingValue(SettingStrings.SmtpUsername), new EncryptionServices().DecryptText( SettingServices.GetSettingValue(SettingStrings.SmtpPassword))), EnableSsl = SettingServices.GetSettingValue(SettingStrings.SmtpSsl) == "Yes" }; client.Send(message); } catch (Exception ex) { log.Error(ex.Message); } }
private bool CopyCommand(string pxeType, string mode, string sArch, string dArch, string sName, string dName) { var destinationRootPath = SettingServices.GetSettingValue(SettingStrings.TftpPath); if (mode == "proxy" || (pxeType == "grub" && dArch == "efi64") || (pxeType == "winpe" && dArch == "efi64") || (pxeType == "winpe" && dArch == "efi32") || pxeType == "winpe" && dArch == "bios") { destinationRootPath += "proxy" + Path.DirectorySeparatorChar; } try { File.Copy( _sourceRootPath + pxeType + Path.DirectorySeparatorChar + mode + Path.DirectorySeparatorChar + sArch + Path.DirectorySeparatorChar + sName, destinationRootPath + dArch + Path.DirectorySeparatorChar + dName, true); new FileOpsServices().SetUnixPermissions(destinationRootPath + dArch + Path.DirectorySeparatorChar + dName); } catch (Exception ex) { log.Error(ex.Message); return(false); } return(true); }
public IsoGen(IsoGenOptionsDTO isoGenOptions) { _isoOptions = isoGenOptions; if (SettingServices.GetSettingValue(SettingStrings.DebugRequiresLogin) == "No" || SettingServices.GetSettingValue(SettingStrings.OnDemandRequiresLogin) == "No" || SettingServices.GetSettingValue(SettingStrings.RegisterRequiresLogin) == "No" || SettingServices.GetSettingValue(SettingStrings.ClobberRequiresLogin) == "No") { _userToken = SettingServices.GetSettingValue(SettingStrings.UniversalToken); } else { _userToken = ""; } _basePath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "private" + Path.DirectorySeparatorChar; _rootfsPath = _basePath + "client_iso" + Path.DirectorySeparatorChar + "rootfs" + Path.DirectorySeparatorChar; _buildPath = _basePath + "client_iso" + Path.DirectorySeparatorChar + "build-tmp"; _outputPath = _basePath + "client_iso" + Path.DirectorySeparatorChar; _configOutPath = _basePath + "client_iso" + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar; _registration = SettingServices.GetSettingValue(SettingStrings.RegistrationEnabled) == "No" ? " skip_registration=true " : string.Empty; if (SettingServices.GetSettingValue(SettingStrings.ClobberEnabled) == "1") { _isClobber = true; _namePromptArg = SettingServices.GetSettingValue(SettingStrings.ClobberPromptComputerName) == "1" ? " name_prompt=true" : string.Empty; _imageProfileId = Convert.ToInt32(SettingServices.GetSettingValue(SettingStrings.ClobberProfileId)); } }
public DefaultBootMenu(BootMenuGenOptionsDTO defaultBootMenu) { _defaultBoot = defaultBootMenu; _bootEntryServices = new BootEntryServices(); _secondaryServerServices = new SecondaryServerServices(); _registration = SettingServices.GetSettingValue(SettingStrings.RegistrationEnabled) == "No" ? " skip_registration=true " : string.Empty; }
private int GenerateProcessArguments() { var multicastArgs = new MulticastArgsDTO(); multicastArgs.schema = new ClientPartitionHelper(_imageProfile).GetImageSchema(); multicastArgs.Environment = _imageProfile.Image.Environment; multicastArgs.ImageName = _imageProfile.Image.Name; multicastArgs.Port = _multicastSession.Port.ToString(); if (_isOnDemand) { multicastArgs.ExtraArgs = SettingServices.GetSettingValue(SettingStrings.SenderArgs); if (!string.IsNullOrEmpty(_clientCount)) { multicastArgs.clientCount = _clientCount; } } else { multicastArgs.ExtraArgs = string.IsNullOrEmpty(_imageProfile.SenderArguments) ? SettingServices.GetSettingValue(SettingStrings.SenderArgs) : _imageProfile.SenderArguments; multicastArgs.clientCount = _computers.Count.ToString(); } var pid = 0; if (_multicastServerId == -1) { pid = new MulticastArguments().GenerateProcessArguments(multicastArgs); } else { var secondaryServer = new SecondaryServerServices().GetSecondaryServer(_multicastServerId); pid = new APICall(new SecondaryServerServices().GetToken(secondaryServer.Name)) .ServiceAccountApi.GetMulticastSenderArgs(multicastArgs); } if (pid == 0) { return(pid); } var activeMulticastSessionServices = new ActiveMulticastSessionServices(); if (_isOnDemand) { _multicastSession.Pid = pid; _multicastSession.Name = _group.Name; activeMulticastSessionServices.AddActiveMulticastSession(_multicastSession); } else { _multicastSession.Pid = pid; activeMulticastSessionServices.UpdateActiveMulticastSession(_multicastSession); } return(pid); }
private void SaveCurrenTreeViewModel() { if (CurrenTreeViewItem != null) { SettingServices.SaveLastOpenedNavigationTreeViewItem(CurrenTreeViewItem.GetEntityTypeId(), CurrenTreeViewItem.Id); } }
public ApiStringResponseDTO GetTftpServer() { return(new ApiStringResponseDTO { Value = StringManipulationServices.PlaceHolderReplace( SettingServices.GetSettingValue(SettingStrings.TftpServerIp)) }); }
public IActionResult Update([FromBody] SettingModel request, string id) { UserSessionManager usrSession = new UserSessionManager(); var user = User as ClaimsPrincipal; string userId = user.Claims.Where(c => c.Type == "USERID").Select(c => c.Value).SingleOrDefault(); SettingModelOutput settingModelOutput = new SettingModelOutput(); try { _logger.Information("Saving Update setting"); if (ModelState.IsValid) { SettingServices settingServices = new SettingServices { objUser = usrSession.UserLog(userId)._userInfo }; var res = settingServices.Update(request, id); settingModelOutput.IsSuccess = true; settingModelOutput.Message = "Success Update"; settingModelOutput.Code = 200; } else { _logger.Error("Error Update Setting"); string errordetails = ""; var errors = new List <string>(); foreach (var state in ModelState) { foreach (var error in state.Value.Errors) { string p = error.ErrorMessage; errordetails = errordetails + error.ErrorMessage; } } Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("error", errordetails); settingModelOutput.IsSuccess = false; settingModelOutput.Message = "error Update Setting validating"; settingModelOutput.Code = 422; settingModelOutput.CustomField = dict; } } catch (Exception ex) { _logger.Error(ex.Message.ToString()); settingModelOutput.IsSuccess = false; settingModelOutput.Message = "Failed Update Setting" + ex.Message; settingModelOutput.Code = 422; } return(Ok(settingModelOutput)); }
public ApiBoolResponseDTO BootSdiExists() { return(new ApiBoolResponseDTO { Value = new FileOpsServices().FileExists(SettingServices.GetSettingValue(SettingStrings.TftpPath) + Path.DirectorySeparatorChar + "boot" + Path.DirectorySeparatorChar + "boot.sdi") }); }
public DefaultBootMenu(BootMenuGenOptionsDTO defaultBootMenu) { _defaultBoot = defaultBootMenu; _bootEntryServices = new BootEntryServices(); _secondaryServerServices = new SecondaryServerServices(); _registration = SettingServices.GetSettingValue(SettingStrings.RegistrationEnabled) == "No" ? " skip_registration=true " : string.Empty; _keepNamePrompt = SettingServices.GetSettingValue(SettingStrings.OnDemandNamePrompt) == "Yes" ? " keep_name_prompt=true " : string.Empty; }
private void DeleteProxyFile(string architecture, string extension = "") { if (SettingServices.ServerIsNotClustered) { try { File.Delete(SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + architecture + Path.DirectorySeparatorChar + ConfigFolder + Path.DirectorySeparatorChar + _bootFile + extension); } catch (Exception ex) { _log.Error(ex.Message); } } else { var clusterGroup = _computerServices.GetClusterGroup(_computer.Id); foreach (var tftpServer in _clusterGroupServices.GetClusterTftpServers(clusterGroup.Id)) { if (tftpServer.ServerId == -1) { try { File.Delete(SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + architecture + Path.DirectorySeparatorChar + ConfigFolder + Path.DirectorySeparatorChar + _bootFile + extension); } catch (Exception ex) { _log.Error(ex.Message); } } 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 + architecture + Path.DirectorySeparatorChar + ConfigFolder + Path.DirectorySeparatorChar + _bootFile + extension; new APICall(_secondaryServerServices.GetToken(secondaryServer.Name)) .ServiceAccountApi.DeleteTftpFile(path); } } } }
private void InitializeCurrenTreeViewModel() { string stringTreeViewItem = SettingServices.GetLastOpenedNavigationTreeViewItem(); if (!String.IsNullOrEmpty(stringTreeViewItem)) { long id = StringHelper.GetTreeViewItemId(stringTreeViewItem); long entityTypeId = StringHelper.GetTreeViewItemEntityTypeId(stringTreeViewItem); Root.SetSelectItem(entityTypeId, id); } SetDefaultCurrenTreeViewItemIfNecessary(); }
public void Configuration(IAppBuilder app) { var OAuthServerOptions = new OAuthAuthorizationServerOptions { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromHours(8), Provider = new SimpleAuthorizationServerProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions() { AccessTokenProvider = new CustomAuthenticationTokenProvider() }); app.Use(new Func <AppFunc, AppFunc>(next => (env) => { var ctx = new OwinContext(env); if (ctx.Get <bool>("custom.ExpiredToken")) { ctx.Response.StatusCode = 403; ctx.Response.ReasonPhrase = "Expired Token"; return(Task.FromResult(0)); } else { return(next(env)); } })); // Hangfire initialization if (SettingServices.GetSettingValue(SettingStrings.OperationMode) == "Cluster Primary") { var stringInterval = SettingServices.GetSettingValue(SettingStrings.SecondaryServerMonitorInterval); int interval = 0; var result = Int32.TryParse(stringInterval, out interval); if (result && interval != 0) { GlobalConfiguration.Configuration.UseMemoryStorage(); app.UseHangfireDashboard(); app.UseHangfireServer(); RecurringJob.AddOrUpdate(() => new SecondaryServerMonitor().Execute(), Cron.MinuteInterval(interval)); } } }
public bool Generate() { try { if (Directory.Exists(_configOutPath)) { Directory.Delete(_configOutPath, true); } Directory.CreateDirectory(_configOutPath); Directory.CreateDirectory(_configOutPath + "clonedeploy"); Directory.CreateDirectory(_configOutPath + "EFI"); Directory.CreateDirectory(_configOutPath + "EFI" + Path.DirectorySeparatorChar + "boot"); Directory.CreateDirectory(_configOutPath + "syslinux"); File.Copy( SettingServices.GetSettingValue(SettingStrings.TftpPath) + "images" + Path.DirectorySeparatorChar + _isoOptions.bootImage, _configOutPath + "clonedeploy" + Path.DirectorySeparatorChar + _isoOptions.bootImage, true); File.Copy( SettingServices.GetSettingValue(SettingStrings.TftpPath) + "kernels" + Path.DirectorySeparatorChar + _isoOptions.kernel, _configOutPath + "clonedeploy" + Path.DirectorySeparatorChar + _isoOptions.kernel, true); } catch (Exception ex) { log.Error(ex.Message); return(false); } if (_isClobber) { CreateSyslinuxClobber(); CreateGrubClobber(); } else { CreateSyslinuxMenu(); CreateGrubMenu(); } if (_isoOptions.buildType == "ISO") { StartMkIsofs(); } else { CreateUsb(); } return(true); }
public ApiBoolResponseDTO SendEmailTest() { var mail = new MailServices { Subject = "Test Message", Body = "Email Notifications Are Working!", MailTo = SettingServices.GetSettingValue(SettingStrings.SmtpMailTo) }; mail.Send(); return(new ApiBoolResponseDTO { Value = true }); }
public void Execute() { if (SettingServices.GetSettingValue(SettingStrings.MonitorSecondaryServer) == "0") { return; } var secServers = _secondaryServerServices.GetAll(); foreach (var server in secServers) { bool serverIsUp = false; var counter = 1; while (counter <= 3) { var result = _secondaryServerServices.GetToken(server.Name); if (result != null) { if (!string.IsNullOrEmpty(result.Token)) { //connection test passed serverIsUp = true; break; } } counter++; } if (serverIsUp && server.IsActive != 1) { //mark server active server.IsActive = 1; UpdateServer(server); } else if (!serverIsUp && server.IsActive != 0) { //mark sever inactive server.IsActive = 0; UpdateServer(server); } } }
public void IpxeBoot(string filename, string type) { if (type == "kernel") { var path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "kernels" + Path.DirectorySeparatorChar; HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "inline; filename=" + filename); HttpContext.Current.Response.TransmitFile(path + filename); HttpContext.Current.Response.End(); } else { var path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "images" + Path.DirectorySeparatorChar; HttpContext.Current.Response.ContentType = "application/x-gzip"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "inline; filename=" + filename); HttpContext.Current.Response.TransmitFile(path + filename); HttpContext.Current.Response.End(); } }
public IsoGen(IsoGenOptionsDTO isoGenOptions) { _isoOptions = isoGenOptions; if (SettingServices.GetSettingValue(SettingStrings.DebugRequiresLogin) == "No" || SettingServices.GetSettingValue(SettingStrings.OnDemandRequiresLogin) == "No" || SettingServices.GetSettingValue(SettingStrings.RegisterRequiresLogin) == "No") { _userToken = SettingServices.GetSettingValue(SettingStrings.UniversalToken); } else { _userToken = ""; } _basePath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "private" + Path.DirectorySeparatorChar; _rootfsPath = _basePath + "client_iso" + Path.DirectorySeparatorChar + "rootfs" + Path.DirectorySeparatorChar; _buildPath = _basePath + "client_iso" + Path.DirectorySeparatorChar + "build-tmp"; _outputPath = _basePath + "client_iso" + Path.DirectorySeparatorChar; _configOutPath = _basePath + "client_iso" + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar; }
public void Execute() { if (SettingServices.GetSettingValue(SettingStrings.ProxyDhcp) == "Yes") { DeleteProxyFile("bios"); DeleteProxyFile("bios", ".ipxe"); DeleteProxyFile("efi32"); DeleteProxyFile("efi32", ".ipxe"); DeleteProxyFile("efi64"); DeleteProxyFile("efi64", ".ipxe"); DeleteProxyFile("efi64", ".cfg"); } else { var mode = SettingServices.GetSettingValue(SettingStrings.PxeMode); if (mode.Contains("ipxe")) { DeleteStandardFile(".ipxe"); } else if (mode.Contains("grub")) { DeleteStandardFile(".cfg"); } else { DeleteStandardFile(); } } //Custom Boot files for the secondary cluster will be created by the primary //Don't run on secondary if (!SettingServices.ServerIsClusterSecondary) { if (Convert.ToBoolean(_computer.CustomBootEnabled)) { _computerServices.CreateBootFiles(_computer.Id); } } }
public bool Execute() { var copyResult = false; if (SettingServices.ServerIsNotClustered || (SettingServices.ServerIsClusterSecondary && SettingServices.TftpServerRole) || (SettingServices.ServerIsClusterPrimary && SettingServices.TftpServerRole)) { copyResult = SettingServices.GetSettingValue(SettingStrings.ProxyDhcp) == "Yes" ? CopyFilesForProxy() : CopyFilesForNonProxy(); } if (SettingServices.ServerIsClusterPrimary) { foreach (var tftpServer in _secondaryServerServices.GetAllWithTftpRole()) { copyResult = new APICall(_secondaryServerServices.GetToken(tftpServer.Name)) .ServiceAccountApi.CopyPxeBinaries(); } } return(copyResult); }
private void SendNotificationEmail(SecondaryServerEntity server) { //Mail not enabled if (SettingServices.GetSettingValue(SettingStrings.SmtpEnabled) == "0") { return; } var message = server.IsActive == 1 ? " Status Changed To Active" : " Status Changed To Inactive"; foreach ( var user in new UserServices().SearchUsers("") .Where(x => x.NotifyServerStatusChange == 1 && !string.IsNullOrEmpty(x.Email))) { var mail = new MailServices { MailTo = user.Email, Body = server.Name + message, Subject = server.Name }; mail.Send(); } }
public void Execute() { if (SettingServices.GetSettingValue(SettingStrings.DebugRequiresLogin) == "No" || SettingServices.GetSettingValue(SettingStrings.OnDemandRequiresLogin) == "No" || SettingServices.GetSettingValue(SettingStrings.RegisterRequiresLogin) == "No") { _userToken = SettingServices.GetSettingValue(SettingStrings.UniversalToken); } else { _userToken = ""; } var mode = SettingServices.GetSettingValue(SettingStrings.PxeMode); if (_defaultBoot.Type == "standard") { if (mode.Contains("ipxe")) { CreateIpxeMenu(); } else if (mode.Contains("grub")) { CreateGrubMenu(); } else { CreateSyslinuxMenu(); } } else { CreateIpxeMenu(); CreateSyslinuxMenu(); CreateGrubMenu(); } }
public string Execute(string multicastPort = "") { var preScripts = "\""; var postScripts = "\""; foreach (var script in _imageProfileServices.SearchImageProfileScripts(_imageProfile.Id)) { if (Convert.ToBoolean(script.RunPre)) { preScripts += script.ScriptId + " "; } if (Convert.ToBoolean(script.RunPost)) { postScripts += script.ScriptId + " "; } } postScripts += "\""; preScripts += "\""; var sysprepTags = "\""; foreach (var sysprepTag in _imageProfileServices.SearchImageProfileSysprepTags(_imageProfile.Id)) { sysprepTags += sysprepTag.SysprepId + " "; } sysprepTags = sysprepTags.Trim(); sysprepTags += "\""; var areFilesToCopy = _imageProfileServices.SearchImageProfileFileFolders(_imageProfile.Id).Any(); //On demand computer may be null if not registered if (_computer != null) { AppendString("computer_name=" + _computer.Name); //AppendString("computer_id=" + _computer.Id); } AppendString("image_name=" + _imageProfile.Image.Name); AppendString("profile_id=" + _imageProfile.Id); AppendString("server_ip=" + SettingServices.GetSettingValue(SettingStrings.ServerIp)); //AppendString(_direction == "multicast" ? "multicast=true" : "multicast=false"); AppendString("pre_scripts=" + preScripts); AppendString("post_scripts=" + postScripts); AppendString("file_copy=" + areFilesToCopy); AppendString("sysprep_tags=" + sysprepTags); if (Convert.ToBoolean(_imageProfile.SkipCore)) { AppendString("skip_core_download=true"); } if (Convert.ToBoolean(_imageProfile.SkipClock)) { AppendString("skip_clock=true"); } if (Convert.ToBoolean(_imageProfile.WebCancel)) { AppendString("web_cancel=true"); } AppendString("task_completed_action=" + "\"" + _imageProfile.TaskCompletedAction + "\""); if (_direction.Contains("upload")) { AppendString("osx_target_volume=" + "\"" + _imageProfile.OsxTargetVolume + "\""); AppendString("image_type=" + _imageProfile.Image.Type); if (Convert.ToBoolean(_imageProfile.RemoveGPT)) { AppendString("remove_gpt_structures=true"); } if (Convert.ToBoolean(_imageProfile.SkipShrinkVolumes)) { AppendString("skip_shrink_volumes=true"); } if (Convert.ToBoolean(_imageProfile.SkipShrinkLvm)) { AppendString("skip_shrink_lvm=true"); } AppendString("compression_algorithm=" + _imageProfile.Compression); AppendString("compression_level=-" + _imageProfile.CompressionLevel); if (Convert.ToBoolean(_imageProfile.UploadSchemaOnly)) { AppendString("upload_schema_only=true"); } if (Convert.ToBoolean(_imageProfile.SimpleUploadSchema)) { AppendString("simple_upload_schema=true"); } if (_imageProfile.Image.Type == "File" && Convert.ToBoolean(_imageProfile.WimMulticastEnabled)) { AppendString("web_wim_args=--pipable"); } if (!string.IsNullOrEmpty(_imageProfile.CustomUploadSchema)) { AppendString("custom_upload_schema=true"); SetCustomSchemaUpload(); } } else // push or multicast { //Support For on demand if (_computer != null) { if (!string.IsNullOrEmpty(_computer.CustomAttribute1)) { AppendString("cust_attr_1=" + "\"" + _computer.CustomAttribute1 + "\""); } if (!string.IsNullOrEmpty(_computer.CustomAttribute2)) { AppendString("cust_attr_2=" + "\"" + _computer.CustomAttribute2 + "\""); } if (!string.IsNullOrEmpty(_computer.CustomAttribute3)) { AppendString("cust_attr_3=" + "\"" + _computer.CustomAttribute3 + "\""); } if (!string.IsNullOrEmpty(_computer.CustomAttribute4)) { AppendString("cust_attr_4=" + "\"" + _computer.CustomAttribute4 + "\""); } if (!string.IsNullOrEmpty(_computer.CustomAttribute5)) { AppendString("cust_attr_5=" + "\"" + _computer.CustomAttribute5 + "\""); } } if (Convert.ToBoolean(_imageProfile.OsxInstallMunki)) { AppendString("install_munki=true"); } AppendString("osx_target_volume=" + "\"" + _imageProfile.OsxTargetVolume + "\""); AppendString("munki_repo_url=" + "\"" + _imageProfile.MunkiRepoUrl + "\""); if (!string.IsNullOrEmpty(_imageProfile.MunkiAuthUsername) && !string.IsNullOrEmpty(_imageProfile.MunkiAuthPassword)) { AppendString("munki_requires_auth=true"); } if (Convert.ToBoolean(_imageProfile.ChangeName)) { AppendString("change_computer_name=true"); } if (Convert.ToBoolean(_imageProfile.SkipExpandVolumes)) { AppendString("skip_expand_volumes=true"); } if (Convert.ToBoolean(_imageProfile.FixBcd)) { AppendString("fix_bcd=true"); } if (Convert.ToBoolean(_imageProfile.RandomizeGuids)) { AppendString("randomize_guids=true"); } if (Convert.ToBoolean(_imageProfile.ForceStandardLegacy)) { AppendString("force_legacy_layout=true"); } if (Convert.ToBoolean(_imageProfile.ForceStandardEfi)) { AppendString("force_efi_layout=true"); } if (Convert.ToBoolean(_imageProfile.SkipNvramUpdate)) { AppendString("skip_nvram=true"); } if (Convert.ToBoolean(_imageProfile.FixBootloader)) { AppendString("fix_bootloader=true"); } if (Convert.ToBoolean(_imageProfile.ErasePartitions)) { AppendString("erase_partitions=true"); } if (Convert.ToBoolean(_imageProfile.ForceDynamicPartitions)) { AppendString("force_dynamic_partitions=true"); } AppendString(SetPartitionMethod()); if (!string.IsNullOrEmpty(_imageProfile.CustomSchema)) { AppendString("custom_deploy_schema=true"); SetCustomSchemaDeploy(); } if (_direction.Contains("multicast")) { if (SettingServices.GetSettingValue(SettingStrings.MulticastDecompression) == "client") { AppendString("decompress_multicast_on_client=true"); } AppendString("client_receiver_args=" + "\"" + _imageProfile.ReceiverArguments + "\""); AppendString("multicast_port=" + multicastPort); } } return(_activeTaskArguments.ToString()); }
private void CreateGrubMenu() { var customMenuEntries = _bootEntryServices.SearchBootEntrys() .Where(x => x.Type == "grub" && x.Active == 1) .OrderBy(x => x.Order) .ThenBy(x => x.Name); var defaultCustomEntry = customMenuEntries.FirstOrDefault(x => x.Default == 1); var grubMenu = new StringBuilder(); grubMenu.Append("insmod password_pbkdf2" + NewLineChar); grubMenu.Append("insmod regexp" + NewLineChar); grubMenu.Append("set default=0" + NewLineChar); grubMenu.Append("set timeout=10" + NewLineChar); grubMenu.Append("set pager=1" + NewLineChar); if (!string.IsNullOrEmpty(_defaultBoot.GrubUserName) && !string.IsNullOrEmpty(_defaultBoot.GrubPassword)) { grubMenu.Append("set superusers=\"" + _defaultBoot.GrubUserName + "\"" + NewLineChar); string sha = null; try { sha = new WebClient().DownloadString( "http://docs.clonedeploy.org/grub-pass-gen/encrypt.php?password="******"\n \n\n\n", ""); } catch { log.Error("Could not generate sha for grub password. Could not contact http://clonedeploy.org"); } grubMenu.Append("password_pbkdf2 " + _defaultBoot.GrubUserName + " " + sha + "" + NewLineChar); grubMenu.Append("export superusers" + NewLineChar); grubMenu.Append("" + NewLineChar); } grubMenu.Append(@"regexp -s 1:b1 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"regexp -s 2:b2 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"regexp -s 3:b3 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"regexp -s 4:b4 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"regexp -s 5:b5 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"regexp -s 6:b6 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" + NewLineChar); grubMenu.Append(@"mac=01-$b1-$b2-$b3-$b4-$b5-$b6" + NewLineChar); grubMenu.Append("" + NewLineChar); if (_defaultBoot.Type == "standard") { grubMenu.Append("if [ -s /pxelinux.cfg/$mac.cfg ]; then" + NewLineChar); grubMenu.Append("configfile /pxelinux.cfg/$mac.cfg" + NewLineChar); grubMenu.Append("fi" + NewLineChar); } else { grubMenu.Append("if [ -s /proxy/efi64/pxelinux.cfg/$mac.cfg ]; then" + NewLineChar); grubMenu.Append("configfile /proxy/efi64/pxelinux.cfg/$mac.cfg" + NewLineChar); grubMenu.Append("fi" + NewLineChar); } if (defaultCustomEntry != null) { grubMenu.Append("" + NewLineChar); grubMenu.Append("menuentry \"" + _alphaNumericSpace.Replace(defaultCustomEntry.Name, "") + "\" --unrestricted {" + NewLineChar); grubMenu.Append(defaultCustomEntry.Content + NewLineChar); grubMenu.Append("}" + NewLineChar); } grubMenu.Append("" + NewLineChar); grubMenu.Append("menuentry \"Boot To Local Machine\" --unrestricted {" + NewLineChar); grubMenu.Append("exit" + NewLineChar); grubMenu.Append("}" + NewLineChar); grubMenu.Append("" + NewLineChar); grubMenu.Append("menuentry \"CloneDeploy\" --user {" + NewLineChar); grubMenu.Append("echo Please Wait While The Boot Image Is Transferred. This May Take A Few Minutes." + NewLineChar); grubMenu.Append("linux /kernels/" + _defaultBoot.Kernel + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" + _webPath + " USER_TOKEN=" + _userToken + " consoleblank=0 " + _registration + _globalComputerArgs + "" + NewLineChar); grubMenu.Append("initrd /images/" + _defaultBoot.BootImage + "" + NewLineChar); grubMenu.Append("}" + NewLineChar); grubMenu.Append("" + NewLineChar); grubMenu.Append("menuentry \"Client Console\" --user {" + NewLineChar); grubMenu.Append("echo Please Wait While The Boot Image Is Transferred. This May Take A Few Minutes." + NewLineChar); grubMenu.Append("linux /kernels/" + _defaultBoot.Kernel + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" + _webPath + " USER_TOKEN=" + _userToken + " task=debug consoleblank=0 " + _globalComputerArgs + "" + NewLineChar); grubMenu.Append("initrd /images/" + _defaultBoot.BootImage + "" + NewLineChar); grubMenu.Append("}" + NewLineChar); grubMenu.Append("" + NewLineChar); foreach (var customEntry in customMenuEntries) { if (defaultCustomEntry != null && customEntry.Id == defaultCustomEntry.Id) { continue; } grubMenu.Append("" + NewLineChar); grubMenu.Append("menuentry \"" + _alphaNumericSpace.Replace(customEntry.Name, "") + "\" --user {" + NewLineChar); grubMenu.Append(customEntry.Content + NewLineChar); grubMenu.Append("}" + NewLineChar); grubMenu.Append("" + NewLineChar); } var path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "grub" + Path.DirectorySeparatorChar + "grub.cfg"; if (SettingServices.ServerIsNotClustered) { new FileOpsServices().WritePath(path, grubMenu.ToString()); } else { if (SettingServices.TftpServerRole) { new FileOpsServices().WritePath(path, grubMenu.ToString()); } foreach (var tftpServer in _secondaryServerServices.GetAllWithTftpRole()) { var tftpPath = new APICall(_secondaryServerServices.GetToken(tftpServer.Name)) .SettingApi.GetSetting("Tftp Path").Value; var tftpFile = new TftpFileDTO(); tftpFile.Contents = grubMenu.ToString(); tftpFile.Path = tftpPath + "grub" + Path.DirectorySeparatorChar + "grub.cfg"; new APICall(_secondaryServerServices.GetToken(tftpServer.Name)) .ServiceAccountApi.WriteTftpFile(tftpFile); } } }
private void CreateSyslinuxMenu() { var customMenuEntries = _bootEntryServices.SearchBootEntrys() .Where(x => x.Type == "syslinux/pxelinux" && x.Active == 1) .OrderBy(x => x.Order) .ThenBy(x => x.Name); var defaultCustomEntry = customMenuEntries.FirstOrDefault(x => x.Default == 1); var sysLinuxMenu = new StringBuilder(); sysLinuxMenu.Append("DEFAULT vesamenu.c32" + NewLineChar); sysLinuxMenu.Append("MENU TITLE Boot Menu" + NewLineChar); sysLinuxMenu.Append("MENU BACKGROUND bg.png" + NewLineChar); sysLinuxMenu.Append("menu tabmsgrow 22" + NewLineChar); sysLinuxMenu.Append("menu cmdlinerow 22" + NewLineChar); sysLinuxMenu.Append("menu endrow 24" + NewLineChar); sysLinuxMenu.Append("menu color title 1;34;49 #eea0a0ff #cc333355 std" + NewLineChar); sysLinuxMenu.Append("menu color sel 7;37;40 #ff000000 #bb9999aa all" + NewLineChar); sysLinuxMenu.Append("menu color border 30;44 #ffffffff #00000000 std" + NewLineChar); sysLinuxMenu.Append("menu color pwdheader 31;47 #eeff1010 #20ffffff std" + NewLineChar); sysLinuxMenu.Append("menu color hotkey 35;40 #90ffff00 #00000000 std" + NewLineChar); sysLinuxMenu.Append("menu color hotsel 35;40 #90000000 #bb9999aa all" + NewLineChar); sysLinuxMenu.Append("menu color timeout_msg 35;40 #90ffffff #00000000 none" + NewLineChar); sysLinuxMenu.Append("menu color timeout 31;47 #eeff1010 #00000000 none" + NewLineChar); sysLinuxMenu.Append("NOESCAPE 0" + NewLineChar); sysLinuxMenu.Append("ALLOWOPTIONS 0" + NewLineChar); sysLinuxMenu.Append("" + NewLineChar); sysLinuxMenu.Append("LABEL local" + NewLineChar); sysLinuxMenu.Append("localboot 0" + NewLineChar); if (defaultCustomEntry == null) { sysLinuxMenu.Append("MENU DEFAULT" + NewLineChar); } sysLinuxMenu.Append("MENU LABEL Boot To Local Machine" + NewLineChar); sysLinuxMenu.Append("" + NewLineChar); sysLinuxMenu.Append("LABEL CloneDeploy" + NewLineChar); if (!string.IsNullOrEmpty(_defaultBoot.OndPwd) && _defaultBoot.OndPwd != "Error: Empty password") { sysLinuxMenu.Append("MENU PASSWD " + _defaultBoot.OndPwd + "" + NewLineChar); } sysLinuxMenu.Append("kernel kernels" + Path.DirectorySeparatorChar + _defaultBoot.Kernel + "" + NewLineChar); sysLinuxMenu.Append("append initrd=images" + Path.DirectorySeparatorChar + _defaultBoot.BootImage + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" + _webPath + " USER_TOKEN=" + _userToken + " consoleblank=0 " + _registration + _globalComputerArgs + "" + NewLineChar); sysLinuxMenu.Append("MENU LABEL CloneDeploy" + NewLineChar); sysLinuxMenu.Append("" + NewLineChar); sysLinuxMenu.Append("LABEL Client Console" + NewLineChar); if (!string.IsNullOrEmpty(_defaultBoot.DebugPwd) && _defaultBoot.DebugPwd != "Error: Empty password") { sysLinuxMenu.Append("MENU PASSWD " + _defaultBoot.DebugPwd + "" + NewLineChar); } sysLinuxMenu.Append("kernel kernels" + Path.DirectorySeparatorChar + _defaultBoot.Kernel + "" + NewLineChar); sysLinuxMenu.Append("append initrd=images" + Path.DirectorySeparatorChar + _defaultBoot.BootImage + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" + _webPath + " USER_TOKEN=" + _userToken + " task=debug consoleblank=0 " + _globalComputerArgs + "" + NewLineChar); sysLinuxMenu.Append("MENU LABEL Client Console" + NewLineChar); sysLinuxMenu.Append("" + NewLineChar); //Insert active custom boot menu entries foreach (var customEntry in customMenuEntries) { sysLinuxMenu.Append("LABEL " + _alphaNumericSpace.Replace(customEntry.Name, "") + NewLineChar); sysLinuxMenu.Append(customEntry.Content + NewLineChar); if (defaultCustomEntry != null && customEntry.Id == defaultCustomEntry.Id) { sysLinuxMenu.Append("MENU DEFAULT" + NewLineChar); } sysLinuxMenu.Append("MENU LABEL " + _alphaNumericSpace.Replace(customEntry.Name, "") + NewLineChar); sysLinuxMenu.Append("" + NewLineChar); } sysLinuxMenu.Append("PROMPT 0" + NewLineChar); sysLinuxMenu.Append("TIMEOUT 50" + NewLineChar); string path; if (_defaultBoot.Type == "standard") { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default"; } else { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + _defaultBoot.Type + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default"; } if (SettingServices.ServerIsNotClustered) { new FileOpsServices().WritePath(path, sysLinuxMenu.ToString()); } else { if (SettingServices.TftpServerRole) { new FileOpsServices().WritePath(path, sysLinuxMenu.ToString()); } foreach (var tftpServer in _secondaryServerServices.GetAllWithTftpRole()) { var tftpPath = new APICall(_secondaryServerServices.GetToken(tftpServer.Name)) .SettingApi.GetSetting("Tftp Path").Value; var tftpFile = new TftpFileDTO(); tftpFile.Contents = sysLinuxMenu.ToString(); if (_defaultBoot.Type == "standard") { tftpFile.Path = tftpPath + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default"; } else { tftpFile.Path = tftpPath + "proxy" + Path.DirectorySeparatorChar + _defaultBoot.Type + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default"; } new APICall(_secondaryServerServices.GetToken(tftpServer.Name)) .ServiceAccountApi.WriteTftpFile(tftpFile); } } }
private void CreateIpxeMenu() { var customMenuEntries = _bootEntryServices.SearchBootEntrys() .Where(x => x.Type == "ipxe" && x.Active == 1) .OrderBy(x => x.Order) .ThenBy(x => x.Name); var defaultCustomEntry = customMenuEntries.FirstOrDefault(x => x.Default == 1); var ipxeMenu = new StringBuilder(); ipxeMenu.Append("#!ipxe" + NewLineChar); ipxeMenu.Append("chain 01-${net0/mac:hexhyp}.ipxe || chain 01-${net1/mac:hexhyp}.ipxe || goto Menu" + NewLineChar); ipxeMenu.Append("" + NewLineChar); ipxeMenu.Append(":Menu" + NewLineChar); ipxeMenu.Append("menu Boot Menu" + NewLineChar); ipxeMenu.Append("item bootLocal Boot To Local Machine" + NewLineChar); ipxeMenu.Append("item clonedeploy CloneDeploy" + NewLineChar); ipxeMenu.Append("item console Client Console" + NewLineChar); foreach (var customEntry in customMenuEntries) { ipxeMenu.Append("item " + _alphaNumericNoSpace.Replace(customEntry.Name, "") + " " + _alphaNumericSpace.Replace(customEntry.Name, "") + NewLineChar); } if (defaultCustomEntry == null) { ipxeMenu.Append("choose --default bootLocal --timeout 5000 target && goto ${target}" + NewLineChar); } else { ipxeMenu.Append("choose --default " + _alphaNumericNoSpace.Replace(defaultCustomEntry.Name, "") + " --timeout 5000 target && goto ${target}" + NewLineChar); } ipxeMenu.Append("" + NewLineChar); if (SettingServices.GetSettingValue(SettingStrings.IpxeRequiresLogin) == "True") { ipxeMenu.Append(":bootLocal" + NewLineChar); ipxeMenu.Append("exit" + NewLineChar); ipxeMenu.Append("" + NewLineChar); ipxeMenu.Append(":console" + NewLineChar); ipxeMenu.Append("set task debug" + NewLineChar); ipxeMenu.Append("goto login" + NewLineChar); ipxeMenu.Append("" + NewLineChar); ipxeMenu.Append(":clonedeploy" + NewLineChar); ipxeMenu.Append("set task ond" + NewLineChar); ipxeMenu.Append("goto login" + NewLineChar); ipxeMenu.Append("" + NewLineChar); ipxeMenu.Append(":login" + NewLineChar); ipxeMenu.Append("login" + NewLineChar); ipxeMenu.Append("params" + NewLineChar); ipxeMenu.Append("param uname ${username:uristring}" + NewLineChar); ipxeMenu.Append("param pwd ${password:uristring}" + NewLineChar); ipxeMenu.Append("param kernel " + _defaultBoot.Kernel + "" + NewLineChar); ipxeMenu.Append("param bootImage " + _defaultBoot.BootImage + "" + NewLineChar); ipxeMenu.Append("param task " + "${task}" + "" + NewLineChar); ipxeMenu.Append("echo Authenticating" + NewLineChar); ipxeMenu.Append("chain --timeout 15000 " + _webPath + "IpxeLogin##params || goto Menu" + NewLineChar); } else { ipxeMenu.Append(":bootLocal" + NewLineChar); ipxeMenu.Append("exit" + NewLineChar); ipxeMenu.Append("" + NewLineChar); ipxeMenu.Append(":clonedeploy" + NewLineChar); ipxeMenu.Append("kernel " + _webPath + "IpxeBoot?filename=" + _defaultBoot.Kernel + "&type=kernel" + " initrd=" + _defaultBoot.BootImage + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" + _webPath + " USER_TOKEN=" + _userToken + " consoleblank=0 " + _registration + _globalComputerArgs + NewLineChar); ipxeMenu.Append("imgfetch --name " + _defaultBoot.BootImage + " " + _webPath + "IpxeBoot?filename=" + _defaultBoot.BootImage + "&type=bootimage" + NewLineChar); ipxeMenu.Append("boot" + NewLineChar); ipxeMenu.Append("" + NewLineChar); ipxeMenu.Append(":console" + NewLineChar); ipxeMenu.Append("kernel " + _webPath + "IpxeBoot?filename=" + _defaultBoot.Kernel + "&type=kernel" + " initrd=" + _defaultBoot.BootImage + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" + _webPath + " USER_TOKEN=" + _userToken + " task=debug" + " consoleblank=0 " + _globalComputerArgs + NewLineChar); ipxeMenu.Append("imgfetch --name " + _defaultBoot.BootImage + " " + _webPath + "IpxeBoot?filename=" + _defaultBoot.BootImage + "&type=bootimage" + NewLineChar); ipxeMenu.Append("boot" + NewLineChar); ipxeMenu.Append("" + NewLineChar); } //Set Custom Menu Entries foreach (var customEntry in customMenuEntries) { ipxeMenu.Append(":" + _alphaNumericNoSpace.Replace(customEntry.Name, "") + NewLineChar); ipxeMenu.Append(customEntry.Content + NewLineChar); } string path; if (_defaultBoot.Type == "standard") { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default.ipxe"; } else { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + _defaultBoot.Type + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default.ipxe"; } if (SettingServices.ServerIsNotClustered) { new FileOpsServices().WritePath(path, ipxeMenu.ToString()); } else { if (SettingServices.TftpServerRole) { new FileOpsServices().WritePath(path, ipxeMenu.ToString()); } foreach (var tftpServer in _secondaryServerServices.GetAllWithTftpRole()) { var tftpPath = new APICall(_secondaryServerServices.GetToken(tftpServer.Name)) .SettingApi.GetSetting("Tftp Path").Value; var tftpFile = new TftpFileDTO(); tftpFile.Contents = ipxeMenu.ToString(); if (_defaultBoot.Type == "standard") { tftpFile.Path = tftpPath + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default.ipxe"; } else { tftpFile.Path = tftpPath + "proxy" + Path.DirectorySeparatorChar + _defaultBoot.Type + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default.ipxe"; } new APICall(_secondaryServerServices.GetToken(tftpServer.Name)) .ServiceAccountApi.WriteTftpFile(tftpFile); } } }
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); }
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); }