public bool Copy() { var guid = ConfigurationManager.AppSettings["ComServerUniqueId"]; _thisComServer = new ServiceClientComServer().GetServerByGuid(guid); if (_thisComServer == null) { Logger.Error($"Com Server With Guid {guid} Not Found"); return(false); } if (string.IsNullOrEmpty(_thisComServer.TftpPath)) { Logger.Error($"Com Server With Guid {guid} Does Not Have A Valid Tftp Path"); return(false); } _sourceRootPath = _thisComServer.TftpPath + "static" + Path.DirectorySeparatorChar; var copyResult = ServiceSetting.GetSettingValue(SettingStrings.ProxyDhcpEnabled) == "Yes" ? CopyFilesForProxy() : CopyFilesForNonProxy(); return(copyResult); }
public byte [] RunAllServers(DtoIsoGenOptions isoOptions) { var uow = new UnitOfWork(); var tftpComServers = uow.ClientComServerRepository.Get(x => x.IsTftpServer); EntityClientComServer tftpInfoServer; if (tftpComServers.Count == 0) { Logger.Error("No Tftp Servers Are Currently Enabled To Generate ISO"); return(null); } if (tftpComServers.Count > 1) { tftpInfoServer = tftpComServers.Where(x => x.IsTftpInfoServer).FirstOrDefault(); if (tftpInfoServer == null) { Logger.Error("No Tftp Servers Are Currently Set As The Information Server. Unable To Generate ISO"); return(null); } } else { tftpInfoServer = tftpComServers.First(); } //Connect To Client Com Server var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var result = new APICall().ClientComServerApi.GenerateISO(tftpInfoServer.Url, "", decryptedKey, isoOptions); return(result); }
private bool Shutdown(int computerId, string delay) { var computer = _uow.ComputerRepository.GetById(computerId); if (computer == null) { return(false); } if (computer.CertificateId == -1) { return(false); } var compPreventShutdownGroups = _uow.ComputerRepository.GetComputerPreventShutdownGroups(computerId); if (compPreventShutdownGroups.Count > 0) { return(true); //computer is in a prevent shutdown group continue on } var socket = _uow.ActiveSocketRepository.GetFirstOrDefault(x => x.ComputerId == computer.Id); if (socket != null) { var deviceCertEntity = _uow.CertificateRepository.GetById(computer.CertificateId); var deviceCert = new X509Certificate2(deviceCertEntity.PfxBlob, new EncryptionServices().DecryptText(deviceCertEntity.Password), X509KeyStorageFlags.Exportable); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var socketRequest = new DtoSocketRequest(); socketRequest.connectionIds.Add(socket.ConnectionId); socketRequest.action = "Shutdown"; socketRequest.message = delay; new APICall().ClientComServerApi.SendAction(socket.ComServer, "", decryptedKey, socketRequest); } return(true); }
public void WriteString(string key, string value) { lock (_staticLock) { var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var settings = configFile.AppSettings.Settings; string fileKey = GetFileKey(key); if (settings[fileKey] == null) { settings.Add(fileKey, value); } else { if (settings[fileKey].Value == value) { return; } settings[fileKey].Value = value; } configFile.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); ServiceSetting setting = ServiceSettings.GetServiceSetting(_loginUser, _serviceID, key, ""); setting.SettingValue = value; setting.Collection.Save(); } }
public bool TestBind() { try { _basePath = "LDAP://" + ServiceSetting.GetSettingValue(SettingStrings.LdapServer) + ":" + ServiceSetting.GetSettingValue(SettingStrings.LdapPort) + "/"; _username = ServiceSetting.GetSettingValue(SettingStrings.LdapBindUsername); _password = new EncryptionServices().DecryptText(ServiceSetting.GetSettingValue(SettingStrings.LdapBindPassword)); _baseDn = ServiceSetting.GetSettingValue(SettingStrings.LdapBaseDN); var entry = InitializeEntry(); var searcher = new DirectorySearcher(entry); searcher.Filter = "(objectCategory=organizationalUnit)"; searcher.PropertiesToLoad.Add("ou"); searcher.PropertiesToLoad.Add("distinguishedName"); searcher.SizeLimit = 0; searcher.PageSize = 500; searcher.FindOne(); return(true); } catch (Exception ex) { Logger.Debug("Active Directory Bind Failed."); Logger.Error(ex.Message); return(false); } }
public List <string> Run() { var uow = new UnitOfWork(); var tftpComServers = uow.ClientComServerRepository.Get(x => x.IsTftpServer); EntityClientComServer tftpInfoServer; if (tftpComServers.Count == 0) { Logger.Error("No Tftp Servers Are Currently Enabled To Retrieve Kernel Listing"); return(null); } if (tftpComServers.Count > 1) { tftpInfoServer = tftpComServers.Where(x => x.IsTftpInfoServer).FirstOrDefault(); if (tftpInfoServer == null) { Logger.Error("No Tftp Servers Are Currently Set As The Information Server. Unable To Retrieve Kernel Listing"); return(null); } } else { tftpInfoServer = tftpComServers.First(); } //Connect To Client Com Server var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); return(new APICall().ClientComServerApi.GetKernels(tftpInfoServer.Url, "", decryptedKey)); }
public string FormatServiceSettingDisplay(ServiceSetting setting) { StringAndFormattingUtilities.ResponseFormatter formatter = this.GetFormatter(); this.FormatServiceSetting(setting, formatter); return(formatter.ToString()); }
public bool Run() { Logger.Debug("Starting Active Directory Sync"); if (ServiceSetting.GetSettingValue(SettingStrings.LdapEnabled) != "1") { Logger.Debug("LDAP integration is not enabled. Skipping"); return(true); } if (string.IsNullOrEmpty(ServiceSetting.GetSettingValue(SettingStrings.LdapServer))) { Logger.Debug("LDAP values not populated. Skipping"); return(true); } _basePath = "LDAP://" + ServiceSetting.GetSettingValue(SettingStrings.LdapServer) + ":" + ServiceSetting.GetSettingValue(SettingStrings.LdapPort) + "/"; _username = ServiceSetting.GetSettingValue(SettingStrings.LdapBindUsername); _password = new EncryptionServices().DecryptText(ServiceSetting.GetSettingValue(SettingStrings.LdapBindPassword)); _baseDn = ServiceSetting.GetSettingValue(SettingStrings.LdapBaseDN); var ous = GetOUs(); var parents = GetParentOU(ous); CreateOuGroups(ous, parents); SyncComputers(); UpdateMemberships(); Logger.Debug("Finished Active Directory Sync"); return(true); }
private void AddComputerToToemsGroup(EntityComputer computer) { if (string.IsNullOrEmpty(ServiceSetting.GetSettingValue(SettingStrings.NewProvisionDefaultGroup))) { Logger.Debug("New Provision default group is not enabled. Skipping"); return; } var group = _groupService.GetGroupByName(ServiceSetting.GetSettingValue(SettingStrings.NewProvisionDefaultGroup)); if (group == null) { return; } if (group.Type.Equals("Dynamic")) { return; } var groupMembership = new EntityGroupMembership(); groupMembership.ComputerId = computer.Id; groupMembership.GroupId = group.Id; _groupMemberships.Add(groupMembership); _groupMembershipService.AddMembership(_groupMemberships); }
private CRMResponse OnpremTest(JObject entityObj) { if (!ValidateInput(entityObj)) { return(OutputHelper.InvalidResponse(entityObj)); } try { ServiceSetting setting = new ServiceSetting(); setting.CRMVersion = "onprem"; setting.MicrosoftAccountEnabled = false; setting.CrmResourceURL = "https://azcrmuextwb01.partners.extranet.microsoft.com/OnePayrollUAT041115"; setting.User = "******"; setting.Password = "******"; var crmRepositry = RepositryBase.CreateRepositry(setting); crmRepositry.Execute(entityObj); return(OutputHelper.SuccessResponse(entityObj)); } catch (Exception ex) { return(OutputHelper.FailedResponse(entityObj, ex)); } }
public ServiceSettingControl(ServiceSetting setting) : this() { _serverSetting = setting ?? throw new ArgumentNullException(nameof(setting)); lblName.Text = setting.Name; CreatePropertyControl(); }
private CRMResponse OnlineTest(JObject entityObj) { if (!ValidateInput(entityObj)) { return(OutputHelper.InvalidResponse(entityObj)); } try { ServiceSetting setting = new ServiceSetting(); setting.CRMVersion = "online"; setting.MicrosoftAccountEnabled = true; setting.CrmResourceURL = "https://mpctest.crm.dynamics.com/"; setting.User = "******"; setting.Password = "******"; setting.CacheAccountId = WebApiApplication.accountId; var crmRepositry = RepositryBase.CreateRepositry(setting); //crmRepositry.AssociateAccountId = WebApiApplication.accountId; crmRepositry.Execute(entityObj); WebApiApplication.accountId = crmRepositry.AssociateAccountId; return(OutputHelper.SuccessResponse(entityObj)); } catch (Exception ex) { return(OutputHelper.FailedResponse(entityObj, ex)); } }
private void OnClientCommandReceived(NamedPipeConnection <BeSafePipeCommand, BeSafePipeCommand> connection, BeSafePipeCommand command) { try { switch (command.Command) { case PipeCommands.ComponentConfiguration: { bool sotreSettingResult = new ServiceSetting().StoreConfigFilePath(command.ConfigFilePath); if (sotreSettingResult) { ConfigApplier(); } } break; case PipeCommands.ReloadPlugins: { } break; case PipeCommands.Notification: { } break; } } catch (Exception ex) { ex.Log(); } }
public bool RunAllServers(EntityComputer computer, EntityImageProfile imageProfile) { _uow = new UnitOfWork(); var comServers = new Workflows.GetCompTftpServers().Run(computer.Id); if (comServers == null) { log.Error("Could Not Determine Tftp Com Servers For Computer: " + computer.Name); return(false); } if (comServers.Count == 0) { log.Error("Could Not Determine Tftp Com Servers For Computer: " + computer.Name); return(false); } var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var NoErrors = true; var dtoTaskBootFile = new DtoTaskBootFile(); dtoTaskBootFile.Computer = computer; dtoTaskBootFile.ImageProfile = imageProfile; foreach (var com in comServers) { if (!new APICall().ClientComServerApi.CreateTaskBootFiles(com.Url, "", decryptedKey, dtoTaskBootFile)) { NoErrors = false; } } return(NoErrors); }
public string GetHdFileSize(string imageName, string hd) { var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); using (var unc = new UncServices()) { if ( unc.NetUseWithCredentials() || unc.LastError == 1219) { try { var imagePath = basePath + "images" + Path.DirectorySeparatorChar + imageName + Path.DirectorySeparatorChar + "hd" + hd; var size = GetDirectorySize(new DirectoryInfo(imagePath)) / 1024f / 1024f / 1024f; return(Math.Abs(size) < 0.1f ? "< 100M" : size.ToString("#.##") + " GB"); } catch { return("N/A"); } } else { log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); return("N/A"); } } }
public bool Reset(string key, string thumbprint) { Logger.Info("Resetting Server Key"); var entropy = new byte[16]; new RNGCryptoServiceProvider().GetBytes(entropy); var serverKeyBytes = Encoding.ASCII.GetBytes(key); var encryptedKey = ServiceDP.EncryptData(serverKeyBytes, true, entropy); var serviceSetting = new ServiceSetting(); var serverKeyEntropy = serviceSetting.GetSetting("server_key_entropy"); serverKeyEntropy.Value = Convert.ToBase64String(entropy); serviceSetting.UpdateSettingValue(serverKeyEntropy); var serverKey = serviceSetting.GetSetting("server_key"); serverKey.Value = Convert.ToBase64String(encryptedKey); serviceSetting.UpdateSettingValue(serverKey); var caThumbprint = serviceSetting.GetSetting("ca_thumbprint"); caThumbprint.Value = thumbprint; serviceSetting.UpdateSettingValue(caThumbprint); Logger.Info("Resetting Server Key Finished"); return(true); }
protected override bool MessageServerAllowConnect(string ipAddress) { ServiceSetting ipSetting = _serviceSettings.Find(Constants.Settings.ConnectionIP); if (ipSetting == null) { return(true); } string[] ipAddresses = ipSetting.Value.Split(Constants.Other.SemiColon); foreach (string address in ipAddresses) { string allowedIPAddresses = address; int wildCard = allowedIPAddresses.IndexOf(Constants.Other.Asterix); if (wildCard >= 0) { allowedIPAddresses = allowedIPAddresses.Substring(0, wildCard); } if (String.IsNullOrEmpty(allowedIPAddresses) || ipAddress.StartsWith(allowedIPAddresses)) { return(true); } } return(base.MessageServerAllowConnect(ipAddress)); }
private bool GetMsiArgs() { var certEntity = _uow.CertificateRepository.GetFirstOrDefault(x => x.Type == EnumCertificate.CertificateType.Authority); if (certEntity == null) { return(false); } var pfx = new X509Certificate2(certEntity.PfxBlob, new EncryptionServices().DecryptText(certEntity.Password), X509KeyStorageFlags.Exportable); _thumbprint = pfx.Thumbprint; var provisionKeyEncrypted = ServiceSetting.GetSettingValue(SettingStrings.ProvisionKeyEncrypted); _serverKey = new EncryptionServices().DecryptText(provisionKeyEncrypted); var defaultCluster = _uow.ComServerClusterRepository.GetFirstOrDefault(x => x.IsDefault); var clusterServers = _uow.ComServerClusterServerRepository.Get(x => x.ComServerClusterId == defaultCluster.Id); _comServers = ""; foreach (var s in clusterServers) { var comServer = _uow.ClientComServerRepository.GetById(s.ComServerId); _comServers += comServer.Url + ","; } _comServers = _comServers.Trim(','); return(true); }
private void SendMailAsync() { try { var message = new MailMessage(ServiceSetting.GetSettingValue(SettingStrings.SmtpMailFrom), MailTo) { Subject = "Toems " + "(" + Subject + ")", Body = Body }; var client = new SmtpClient(ServiceSetting.GetSettingValue(SettingStrings.SmtpServer), Convert.ToInt32(ServiceSetting.GetSettingValue(SettingStrings.SmtpPort))) { Credentials = new NetworkCredential(ServiceSetting.GetSettingValue(SettingStrings.SmtpUsername), new EncryptionServices().DecryptText( ServiceSetting.GetSettingValue(SettingStrings.SmtpPassword))), EnableSsl = ServiceSetting.GetSettingValue(SettingStrings.SmtpSsl) == "Yes" }; client.Send(message); } catch (Exception ex) { log.Error(ex.Message); } }
public bool Sync() { if (!ServiceSetting.GetSettingValue(SettingStrings.StorageType).Equals("SMB")) { return(true); } using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { RoboCommand backup = new RoboCommand(); // events backup.OnFileProcessed += backup_OnFileProcessed; backup.OnCommandCompleted += backup_OnCommandCompleted; // copy options backup.CopyOptions.Source = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); backup.CopyOptions.Destination = ConfigurationManager.AppSettings["LocalStoragePath"].Trim('\\'); backup.CopyOptions.CopySubdirectories = true; backup.CopyOptions.UseUnbufferedIo = true; // select options //backup.SelectionOptions.OnlyCopyArchiveFilesAndResetArchiveFlag = true; backup.CopyOptions.Mirror = true; backup.CopyOptions.Purge = false; backup.SelectionOptions.ExcludeOlder = true; backup.LoggingOptions.VerboseOutput = true; // retry options backup.RetryOptions.RetryCount = 1; backup.RetryOptions.RetryWaitTime = 2; backup.Start(); return(true); } return(false); } }
public DtoClientStartupInfo GetStartupInfo() { var settingService = new ServiceSetting(); var startupInfo = new DtoClientStartupInfo(); startupInfo.DelayType = (EnumStartupDelay.DelayType) Convert.ToInt16(settingService.GetSetting(SettingStrings.StartupDelayType).Value); startupInfo.SubDelay = settingService.GetSetting(SettingStrings.StartupDelaySub).Value; startupInfo.ThresholdWindow = settingService.GetSetting(SettingStrings.ThresholdWindow).Value; var versions = new ServiceVersion().GetVersions(); if (versions == null) { startupInfo.IsError = true; startupInfo.ErrorMessage = "Could Not Determine Server Version"; return(startupInfo); } if (!versions.ExpectedToecApiVersion.Equals(ToecApiStrings.ToecApiVersion)) { startupInfo.IsError = true; startupInfo.ErrorMessage = "Toec Api Version And Database Version Do Not Match. The Toec Api Server May Need Updated."; return(startupInfo); } startupInfo.ExpectedClientVersion = versions.LatestClientVersion; return(startupInfo); }
public bool DeleteModuleDirectory(string moduleGuid) { if (string.IsNullOrEmpty(moduleGuid) || moduleGuid == Path.DirectorySeparatorChar.ToString()) { return(false); } var basePath = Path.Combine(ServiceSetting.GetSettingValue(SettingStrings.StoragePath), "software_uploads"); var fullPath = Path.Combine(basePath, moduleGuid); using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { if (!Directory.Exists(fullPath)) { return(true); } try { Directory.Delete(fullPath, true); return(true); } catch (Exception ex) { log.Error(ex.Message); return(false); } } else { log.Error("Could Not Reach Storage Path"); return(false); } } }
public UploadController() { Context = HttpContext.Current; Request = HttpContext.Current.Request; Response = HttpContext.Current.Response; _basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); }
public bool DeleteImageFolders(string imageName) { //Check again if (string.IsNullOrEmpty(imageName)) { return(false); } var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); using (var unc = new UncServices()) { if ( unc.NetUseWithCredentials() || unc.LastError == 1219) { try { Directory.Delete(basePath + @"\images" + @"\" + imageName, true); return(true); } catch (Exception ex) { log.Error(ex.Message); return(false); } } else { log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); return(false); } } }
private void UpdateComServers(List <DtoClientComServers> comServers) { var settingService = new ServiceSetting(); var activeString = ""; foreach (var server in comServers.Where(x => x.Role.Equals("Active"))) { activeString += server.Url + ","; } var trimmedActive = activeString.Trim(','); var passiveString = ""; foreach (var server in comServers.Where(x => x.Role.Equals("Passive"))) { passiveString += server.Url + ","; } var trimmedPassive = passiveString.Trim(','); if (!string.IsNullOrEmpty(trimmedActive)) { var currentActive = settingService.GetSetting("active_com_servers"); currentActive.Value = trimmedActive; settingService.UpdateSettingValue(currentActive); } if (!string.IsNullOrEmpty(trimmedPassive)) { var currentPassive = settingService.GetSetting("passive_com_servers"); currentPassive.Value = trimmedPassive; settingService.UpdateSettingValue(currentPassive); } }
public bool RenameImageFolder(string oldName, string newName) { //Check again if (string.IsNullOrEmpty(oldName) || string.IsNullOrEmpty(newName)) { return(false); } var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); using (var unc = new UncServices()) { if ( unc.NetUseWithCredentials() || unc.LastError == 1219) { try { var imagePath = basePath + @"\images\"; Directory.Move(imagePath + oldName, imagePath + newName); return(true); } catch (Exception ex) { log.Error(ex.Message); return(false); } } else { log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); return(false); } } }
public TClass ExecuteSymKeyEncryption <TClass>(RestRequest request, string body) where TClass : new() { request.AddHeader("client", DtoGobalSettings.ClientIdentity.Name); request.AddHeader("identifier", DtoGobalSettings.ClientIdentity.Guid); var serviceSetting = new ServiceSetting(); var entropy = serviceSetting.GetSetting("entropy"); var encryptedKey = serviceSetting.GetSetting("encryption_key"); var decryptedKey = ServiceDP.DecryptData(Convert.FromBase64String(encryptedKey.Value), true, Convert.FromBase64String(entropy.Value)); if (!string.IsNullOrEmpty(body)) { var encryptedContent = new ServiceSymmetricEncryption().EncryptData(decryptedKey, body); request.AddParameter("text/xml", encryptedContent, ParameterType.RequestBody); } var deviceThumbprint = new ServiceSetting().GetSetting("device_thumbprint"); var deviceCert = ServiceCertificate.GetCertificateFromStore(deviceThumbprint.Value, StoreName.My); if (deviceCert == null) { return(default(TClass)); } var encryptedCert = new ServiceSymmetricEncryption().EncryptData(decryptedKey, Convert.ToBase64String(deviceCert.RawData)); request.AddHeader("device_cert", Convert.ToBase64String(encryptedCert)); return(SubmitRequest <TClass>(request, decryptedKey)); }
public string ReadSchemaFile(string imageName) { var schemaText = ""; var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); var path = basePath + "images" + Path.DirectorySeparatorChar + imageName + Path.DirectorySeparatorChar + "schema"; using (var unc = new UncServices()) { if ( unc.NetUseWithCredentials() || unc.LastError == 1219) { try { using (var reader = new StreamReader(path)) { schemaText = reader.ReadLine() ?? ""; } } catch (Exception ex) { log.Error("Could Not Read Schema File."); log.Error(ex.Message); } } else { log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); return(null); } } return(schemaText); }
public bool RebootComputer(int computerId) { Logger.Debug("Starting Reboot Task"); var shutdownDelay = ServiceSetting.GetSettingValue(SettingStrings.ShutdownDelay); return(Reboot(computerId, shutdownDelay)); }
public string GenerateTrayAppPort() { var trayPort = GetOpenPort(); var activeTrayPorts = new ServiceSetting().GetSetting("active_login_ports"); if (!string.IsNullOrEmpty(trayPort)) { var trayPortsInUse = new List <string>(); if (string.IsNullOrEmpty(activeTrayPorts.Value)) { activeTrayPorts.Value = trayPort; new ServiceSetting().UpdateSettingValue(activeTrayPorts); } else { //check if tray ports are still in use trayPortsInUse.AddRange(activeTrayPorts.Value.Split(',').Where(p => IsPortInUse(Convert.ToInt32(p)))); var updatedPorts = trayPort + ","; foreach (var p in trayPortsInUse) { updatedPorts += p + ","; } activeTrayPorts.Value = updatedPorts.Trim(','); new ServiceSetting().UpdateSettingValue(activeTrayPorts); } } return(trayPort); }