protected void btnUpdateSettings_OnClick(object sender, EventArgs e) { RequiresAuthorization(AuthorizationStrings.UpdateAdmin); var secondaryServer = new SecondaryServerEntity { ApiURL = txtApi.Text, ServiceAccountName = txtAccountName.Text, ServiceAccountPassword = txtAccountPassword.Text, IsActive = chkActive.Checked ? 1 : 0 }; var result = Call.SecondaryServerApi.Put(SecondaryServer.Id, secondaryServer); if (result.Success) { EndUserMessage = "Successfully Updated Secondary Server"; PopulateForm(); } else { EndUserMessage = result.ErrorMessage; } }
private void UpdateServer(SecondaryServerEntity server) { //without this the password will try and be updated without being decrypted first causing an incorrect password. //this prevents the password from being updated. server.ServiceAccountPassword = new EncryptionServices().DecryptText(server.ServiceAccountPassword); _secondaryServerServices.UpdateSecondaryServer(server); SendNotificationEmail(server); }
public ActionResultDTO Put(int id, SecondaryServerEntity secondaryServer) { secondaryServer.Id = id; var result = _secondaryServerServices.UpdateSecondaryServer(secondaryServer); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(result); }
public ActionResultDTO Put(int id, SecondaryServerEntity tObject) { Request.Method = Method.PUT; Request.AddJsonBody(tObject); Request.Resource = string.Format("api/{0}/Put/{1}", Resource, id); var response = _apiRequest.Execute <ActionResultDTO>(Request); if (response.Id == 0) { response.Success = false; } return(response); }
protected void PopulateGrid() { var secondaryServers = Call.SecondaryServerApi.Get(int.MaxValue, ""); if (GetSetting(SettingStrings.OperationMode) == "Cluster Primary") { var primary = new SecondaryServerEntity(); primary.Id = -1; primary.Name = GetSetting(SettingStrings.ServerIdentifier); primary.TftpRole = Convert.ToBoolean(Convert.ToInt16(GetSetting(SettingStrings.TftpServerRole))) ? 1 : 0; primary.MulticastRole = Convert.ToBoolean(Convert.ToInt16(GetSetting(SettingStrings.MulticastServerRole))) ? 1 : 0; secondaryServers.Insert(0, primary); } gvServers.DataSource = secondaryServers; gvServers.DataBind(); foreach (GridViewRow row in gvServers.Rows) { var cbTftp = (CheckBox)row.FindControl("chkTftp"); var cbMulticast = (CheckBox)row.FindControl("chkMulticast"); var dataKey = gvServers.DataKeys[row.RowIndex]; if (dataKey == null) { continue; } if (Convert.ToInt32(dataKey.Value) == -1) { cbTftp.Visible = Convert.ToBoolean(Convert.ToInt16(GetSetting(SettingStrings.TftpServerRole))); cbMulticast.Visible = Convert.ToBoolean(Convert.ToInt16(GetSetting(SettingStrings.MulticastServerRole))); } else { var secondaryServer = Call.SecondaryServerApi.Get(Convert.ToInt32(dataKey.Value)); if (secondaryServer.TftpRole != 1) { cbTftp.Visible = false; } if (secondaryServer.MulticastRole != 1) { cbMulticast.Visible = false; } } } gvDps.DataSource = Call.DistributionPointApi.Get(int.MaxValue, ""); gvDps.DataBind(); }
private ValidationResultDTO ValidateSecondaryServer(SecondaryServerEntity secondaryServer, bool isNewSecondaryServer) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(secondaryServer.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "Secondary Server Name Is Not Valid"; return(validationResult); } if (isNewSecondaryServer) { if (_uow.SecondaryServerRepository.Exists(h => h.Name == secondaryServer.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Secondary Server Already Exists"; return(validationResult); } } else { var originalSecondaryServer = _uow.SecondaryServerRepository.GetById(secondaryServer.Id); if (originalSecondaryServer.Name != secondaryServer.Name) { if (_uow.SecondaryServerRepository.Exists(h => h.Name == secondaryServer.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Secondary Server Already Exists"; return(validationResult); } } } return(validationResult); }
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(); } }
protected void btnUpdateSettings_OnClick(object sender, EventArgs e) { RequiresAuthorization(AuthorizationStrings.UpdateAdmin); var secondaryServer = new SecondaryServerEntity { ApiURL = txtApi.Text, ServiceAccountName = txtAccountName.Text, ServiceAccountPassword = txtAccountPassword.Text, IsActive = 1 }; var result = Call.SecondaryServerApi.Post(secondaryServer); if (result.Success) { EndUserMessage = "Successfully Created Secondary Server"; Response.Redirect("~/views/admin/cluster/editsecondary.aspx?cat=sub1&ssid=" + result.Id); } else { EndUserMessage = result.ErrorMessage; } }
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); }
public ActionResultDTO Post(SecondaryServerEntity secondaryServer) { return(_secondaryServerServices.AddSecondaryServer(secondaryServer)); }
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); }
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); }
protected void PopulateForm() { txtClusterName.Text = ClusterGroup.Name; chkDefault.Checked = ClusterGroup.Default == 1; var secondaryServers = Call.SecondaryServerApi.Get(int.MaxValue, ""); if (GetSetting(SettingStrings.OperationMode) == "Cluster Primary") { var primary = new SecondaryServerEntity(); primary.Id = -1; primary.Name = GetSetting(SettingStrings.ServerIdentifier); primary.TftpRole = Convert.ToBoolean(Convert.ToInt16(GetSetting(SettingStrings.TftpServerRole))) ? 1 : 0; primary.MulticastRole = Convert.ToBoolean(Convert.ToInt16(GetSetting(SettingStrings.MulticastServerRole))) ? 1 : 0; secondaryServers.Insert(0, primary); } gvServers.DataSource = secondaryServers; gvServers.DataBind(); foreach (GridViewRow row in gvServers.Rows) { var cb = (CheckBox)row.FindControl("chkSelector"); var cbTftp = (CheckBox)row.FindControl("chkTftp"); var cbMulticast = (CheckBox)row.FindControl("chkMulticast"); var dataKey = gvServers.DataKeys[row.RowIndex]; if (dataKey == null) { continue; } if (Convert.ToInt32(dataKey.Value) == -1) { cbTftp.Visible = Convert.ToBoolean(Convert.ToInt16(GetSetting(SettingStrings.TftpServerRole))); cbMulticast.Visible = Convert.ToBoolean(Convert.ToInt16(GetSetting(SettingStrings.MulticastServerRole))); } else { var secondaryServer = Call.SecondaryServerApi.Get(Convert.ToInt32(dataKey.Value)); if (secondaryServer.TftpRole != 1) { cbTftp.Visible = false; } if (secondaryServer.MulticastRole != 1) { cbMulticast.Visible = false; } } foreach (var clusterServer in Call.ClusterGroupApi.GetClusterServers(ClusterGroup.Id)) { if (clusterServer.ServerId == Convert.ToInt32(dataKey.Value)) { cb.Checked = true; cbTftp.Checked = clusterServer.TftpRole == 1; cbMulticast.Checked = clusterServer.MulticastRole == 1; } } } gvDps.DataSource = Call.DistributionPointApi.Get(int.MaxValue, ""); gvDps.DataBind(); foreach (GridViewRow row in gvDps.Rows) { var cb = (CheckBox)row.FindControl("chkSelector"); var dataKey = gvDps.DataKeys[row.RowIndex]; if (dataKey == null) { continue; } foreach (var clusterDp in Call.ClusterGroupApi.GetClusterDistributionPoints(ClusterGroup.Id)) { if (clusterDp.DistributionPointId == Convert.ToInt32(dataKey.Value)) { cb.Checked = true; } } } }