/// <summary> /// Loads the options from the XML node. /// </summary> public void LoadFromXml(XmlNode xmlNode) { if (xmlNode == null) { throw new ArgumentNullException(nameof(xmlNode)); } Name = xmlNode.GetChildAsString("Name"); Host = xmlNode.GetChildAsString("Host"); Port = xmlNode.GetChildAsInt("Port", Port); User = xmlNode.GetChildAsString("User"); Password = ScadaUtils.Decrypt(xmlNode.GetChildAsString("Password")); Instance = xmlNode.GetChildAsString("Instance"); Timeout = xmlNode.GetChildAsInt("Timeout", Timeout); string secretKeyStr = xmlNode.GetChildAsString("SecretKey"); if (string.IsNullOrEmpty(secretKeyStr)) { SecretKey = null; } else { SecretKey = ScadaUtils.HexToBytes(secretKeyStr); if (SecretKey.Length != ScadaUtils.SecretKeySize) { throw new ScadaException(CommonPhrases.InvalidParamVal, "SecretKey"); } } }
/// <summary> /// Загрузить конфигурацию из файла /// </summary> public bool Load(string fileName, out string errMsg) { SetToDefault(); try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); XmlElement rootElem = xmlDoc.DocumentElement; Host = rootElem.GetChildAsString("Host"); Port = rootElem.GetChildAsInt("Port"); User = rootElem.GetChildAsString("User"); Password = ScadaUtils.Decrypt(rootElem.GetChildAsString("Password")); EnableSsl = rootElem.GetChildAsBool("EnableSsl"); SenderAddress = rootElem.GetChildAsString("SenderAddress", User); string userDisplayName = rootElem.GetChildAsString("UserDisplayName"); // for backward compatibility SenderDisplayName = rootElem.GetChildAsString("SenderDisplayName", userDisplayName); errMsg = ""; return(true); } catch (Exception ex) { errMsg = CommPhrases.LoadKpSettingsError + ":" + Environment.NewLine + ex.Message; return(false); } }
/// <summary> /// Initializes a new instance of the class. /// </summary> public OpcUaServerDSO(OptionList options) { AutoAccept = options.GetValueAsBool("AutoAccept"); Username = options.GetValueAsString("Username"); Password = ScadaUtils.Decrypt(options.GetValueAsString("Password")); ConfigFileName = options.GetValueAsString("ConfigFileName"); DeviceFilter = new List <int>(); DeviceFilter.AddRange(ScadaUtils.ParseRange(options.GetValueAsString("DeviceFilter"), true, true)); }
/// <summary> /// Loads the configuration from the XML node. /// </summary> public void LoadFromXml(XmlNode xmlNode) { if (xmlNode == null) { throw new ArgumentNullException(nameof(xmlNode)); } Username = xmlNode.GetChildAsString("Username"); Password = ScadaUtils.Decrypt(xmlNode.GetChildAsString("Password")); }
/// <summary> /// Initializes a new instance of the class. /// </summary> public MqttConnectionOptions(OptionList options) { Server = options.GetValueAsString("Server"); Port = options.GetValueAsInt("Port", 1883); ClientID = options.GetValueAsString("ClientID"); Username = options.GetValueAsString("Username"); Password = ScadaUtils.Decrypt(options.GetValueAsString("Password")); Timeout = options.GetValueAsInt("Timeout", 10000); ProtocolVersion = options.GetValueAsEnum("ProtocolVersion", MqttProtocolVersion.Unknown); }
/// <summary> /// Загрузить настройки из заданного XML-узла. /// </summary> public void LoadFromXml(XmlNode xmlNode) { if (xmlNode == null) { throw new ArgumentNullException("xmlNode"); } if (Format == XmlFormat.Attr) { XmlNodeList xmlNodeList = xmlNode.SelectNodes("Param"); foreach (XmlElement xmlElement in xmlNodeList) { string name = xmlElement.GetAttribute("name").Trim(); string nameL = name.ToLowerInvariant(); string val = xmlElement.GetAttribute("value"); try { if (nameL == "serverhost") { ServerHost = val; } else if (nameL == "serverport") { ServerPort = int.Parse(val); } else if (nameL == "serveruser") { ServerUser = val; } else if (nameL == "serverpwd") { ServerPwd = val; } else if (nameL == "servertimeout") { ServerTimeout = int.Parse(val); } } catch { throw new ScadaException(string.Format(CommonPhrases.IncorrectXmlParamVal, name)); } } } else { ServerHost = xmlNode.GetChildAsString("Host"); ServerPort = xmlNode.GetChildAsInt("Port"); ServerUser = xmlNode.GetChildAsString("User"); ServerPwd = ScadaUtils.Decrypt(xmlNode.GetChildAsString("Password")); ServerTimeout = xmlNode.GetChildAsInt("Timeout"); } }
/// <summary> /// Loads the options from the XML node. /// </summary> public void LoadFromXml(XmlNode xmlNode) { if (xmlNode == null) { throw new ArgumentNullException(nameof(xmlNode)); } RequireCaptcha = xmlNode.GetChildAsBool("RequireCaptcha", RequireCaptcha); AllowRememberMe = xmlNode.GetChildAsBool("AllowRememberMe", AllowRememberMe); RememberMeExpires = xmlNode.GetChildAsInt("RememberMeExpires", RememberMeExpires); AutoLoginUsername = xmlNode.GetChildAsString("AutoLoginUsername"); AutoLoginPassword = ScadaUtils.Decrypt(xmlNode.GetChildAsString("AutoLoginPassword")); }
/// <summary> /// Loads the settings from the XML node. /// </summary> public void LoadFromXml(XmlNode xmlNode) { if (xmlNode == null) { throw new ArgumentNullException("xmlNode"); } Server = xmlNode.GetChildAsString("Server"); Database = xmlNode.GetChildAsString("Database"); User = xmlNode.GetChildAsString("User"); Password = ScadaUtils.Decrypt(xmlNode.GetChildAsString("Password")); ConnectionString = xmlNode.GetChildAsString("ConnectionString"); }
/// <summary> /// Loads the options from the XML node. /// </summary> public void LoadFromXml(XmlNode xmlNode) { if (xmlNode == null) { throw new ArgumentNullException("xmlNode"); } ServerUrl = xmlNode.GetChildAsString("ServerUrl"); SecurityMode = xmlNode.GetChildAsEnum("SecurityMode", MessageSecurityMode.None); SecurityPolicy = xmlNode.GetChildAsEnum <SecurityPolicy>("SecurityPolicy"); AuthenticationMode = xmlNode.GetChildAsEnum <AuthenticationMode>("AuthenticationMode"); Username = xmlNode.GetChildAsString("Username"); Password = ScadaUtils.Decrypt(xmlNode.GetChildAsString("Password")); }
public XElement Decrypt(XElement encryptedElement) { ArgumentNullException.ThrowIfNull(encryptedElement, nameof(encryptedElement)); try { string decryptedValue = ScadaUtils.Decrypt(encryptedElement.Value); return(XElement.Parse(decryptedValue)); } catch (Exception ex) { log.WriteError(ex); throw; } }
/// <summary> /// Loads the configuration from the specified reader. /// </summary> protected override void Load(TextReader reader) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(reader); XmlElement rootElem = xmlDoc.DocumentElement; Host = rootElem.GetChildAsString("Host"); Port = rootElem.GetChildAsInt("Port"); Username = rootElem.GetChildAsString("Username", rootElem.GetChildAsString("User")); Password = ScadaUtils.Decrypt(rootElem.GetChildAsString("Password")); EnableSsl = rootElem.GetChildAsBool("EnableSsl"); SenderAddress = rootElem.GetChildAsString("SenderAddress", Username); SenderDisplayName = rootElem.GetChildAsString("SenderDisplayName"); }
/// <summary> /// Loads the settings from the XML node. /// </summary> public void LoadFromXml(XmlNode xmlNode) { if (xmlNode == null) { throw new ArgumentNullException("xmlNode"); } Host = xmlNode.GetChildAsString("Host"); Port = xmlNode.GetChildAsInt("Port", 10002); Username = xmlNode.GetChildAsString("Username", "admin"); string encryptedPassword = xmlNode.GetChildAsString("Password"); Password = string.IsNullOrEmpty(encryptedPassword) ? "" : ScadaUtils.Decrypt(encryptedPassword); ScadaInstance = xmlNode.GetChildAsString("ScadaInstance"); SecretKey = ScadaUtils.HexToBytes(xmlNode.GetChildAsString("SecretKey")); }
/// <summary> /// Loads settings from Web.config. /// </summary> public bool Load(out string errMsg) { try { SetToDefault(); NameValueCollection settings = ConfigurationManager.AppSettings; ServerHost = GetParameter(settings, "serverHost"); ServerPort = Convert.ToInt32(GetParameter(settings, "serverPort")); ServerUser = GetParameter(settings, "serverUser"); ServerPwd = ScadaUtils.Decrypt(GetParameter(settings, "Password")); ServerTimeout = Convert.ToInt32(GetParameter(settings, "serverTimeout")); errMsg = ""; return(true); } catch (Exception ex) { errMsg = "Error loading application settings: " + ex.Message; return(false); } }
/// <summary> /// Decrypts the password. /// </summary> public static string DecryptPassword(string encryptedPassword, long sessionID, byte[] secretKey) { return(secretKey == null ? encryptedPassword : ScadaUtils.Decrypt(encryptedPassword, secretKey, CreateIV(sessionID))); }
/// <summary> /// Загрузить конфигурацию модуля /// </summary> public bool Load(out string errMsg) { SetToDefault(); try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(FileName); // загрузка назначений экспорта XmlNode expDestsNode = xmlDoc.DocumentElement.SelectSingleNode("ExportDestinations"); if (expDestsNode != null) { XmlNodeList expDestNodeList = expDestsNode.SelectNodes("ExportDestination"); foreach (XmlElement expDestElem in expDestNodeList) { // загрузка источника данных DataSource dataSource = null; if (expDestElem.SelectSingleNode("DataSource") is XmlNode dataSourceNode) { // получение типа источника данных if (!Enum.TryParse(dataSourceNode.GetChildAsString("DBType"), out DBType dbType)) { dbType = DBType.Undefined; } // создание источника данных switch (dbType) { case DBType.MSSQL: dataSource = new SqlDataSource(); break; case DBType.Oracle: dataSource = new OraDataSource(); break; case DBType.PostgreSQL: dataSource = new PgSqlDataSource(); break; case DBType.MySQL: dataSource = new MySqlDataSource(); break; case DBType.OLEDB: dataSource = new OleDbDataSource(); break; default: dataSource = null; break; } if (dataSource != null) { dataSource.Server = dataSourceNode.GetChildAsString("Server"); dataSource.Database = dataSourceNode.GetChildAsString("Database"); dataSource.User = dataSourceNode.GetChildAsString("User"); dataSource.Password = ScadaUtils.Decrypt(dataSourceNode.GetChildAsString("Password")); dataSource.ConnectionString = dataSourceNode.GetChildAsString("ConnectionString"); if (string.IsNullOrEmpty(dataSource.ConnectionString)) { dataSource.ConnectionString = dataSource.BuildConnectionString(); } } } if (dataSource != null && expDestElem.SelectSingleNode("ExportParams") is XmlNode exportParamsNode) { // загрузка параметров экспорта ExportParams exportParams = new ExportParams(); exportParams.LoadFromXml(exportParamsNode); // создание назначения экспорта ExportDestination expDest = new ExportDestination(dataSource, exportParams); ExportDestinations.Add(expDest); } } // сортировка назначений экспорта ExportDestinations.Sort(); } // загрузка номеров каналов управления для экспорта в ручном режиме if (xmlDoc.DocumentElement.SelectSingleNode("ManualExport") is XmlNode manExpNode) { CurDataCtrlCnlNum = manExpNode.GetChildAsInt("CurDataCtrlCnlNum"); ArcDataCtrlCnlNum = manExpNode.GetChildAsInt("ArcDataCtrlCnlNum"); EventsCtrlCnlNum = manExpNode.GetChildAsInt("EventsCtrlCnlNum"); } errMsg = ""; return(true); } catch (FileNotFoundException ex) { errMsg = ModPhrases.LoadModSettingsError + ": " + ex.Message + Environment.NewLine + ModPhrases.ConfigureModule; return(false); } catch (Exception ex) { errMsg = ModPhrases.LoadModSettingsError + ": " + ex.Message; return(false); } }