using Azylee.Core.AppUtils.AppConfigUtils.AppConfigInterfaces;
using Azylee.Core.DataUtils.EncryptUtils;
using Azylee.Core.DataUtils.StringUtils;
using Azylee.Core.DbUtils;
using Azylee.Core.DbUtils.DbModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Azylee.Core.AppUtils.AppConfigUtils.AppConfigModels
{
///
/// 数据库配置信息
///
public class AppConfigSshItem : IAppConfigItemModel
{
private string PASSWORD_ENC_SIGN = "ENC:::";
private string PASSWORD_ENC_PWD = "app.db.pwd.20211202";
///
/// 序号
///
public int Number { get; set; }
///
/// 唯一名称
///
public string Name { get; set; }
///
/// 服务器IP地址
///
public string Server { get; set; }
///
/// 服务器端口号
///
public string Port { get; set; }
///
/// 登录用户
///
public string Username { get; set; }
///
/// 登录用户密码
///
public string Password { get; set; }
///
/// 高权限用户
///
public string SuUsername { get; set; }
///
/// 高权限用户密码
///
public string SuPassword { get; set; }
///
/// 登陆后自动AutoSu
///
public bool AutoSu { get; set; }
///
/// 获取数字格式的端口号
///
///
public int GetPort()
{
if (int.TryParse(Port, out int pt)) return pt;
return 22;
}
///
/// 设置密码并加密存储
///
///
public void SetPasswordEnc(string value)
{
if (Str.Ok(value) && !value.StartsWith(PASSWORD_ENC_SIGN))
{
Password = PASSWORD_ENC_SIGN + AesTool.Encrypt(value, PASSWORD_ENC_PWD);
}
else
{
Password = value ?? "";
}
}
///
/// 获取真实密码
///
///
public string GetPasswordEnc()
{
if (Str.Ok(Password) && Password.StartsWith(PASSWORD_ENC_SIGN))
{
return AesTool.Decrypt(Password.Substring(PASSWORD_ENC_SIGN.Length), PASSWORD_ENC_PWD);
}
else
{
return Password;
}
}
///
/// 设置密码并加密存储
///
///
public void SetSuPasswordEnc(string value)
{
if (Str.Ok(value) && !value.StartsWith(PASSWORD_ENC_SIGN))
{
SuPassword = PASSWORD_ENC_SIGN + AesTool.Encrypt(value, PASSWORD_ENC_PWD);
}
else
{
SuPassword = value ?? "";
}
}
///
/// 获取真实密码
///
///
public string GetSuPasswordEnc()
{
if (Str.Ok(SuPassword) && SuPassword.StartsWith(PASSWORD_ENC_SIGN))
{
return AesTool.Decrypt(SuPassword.Substring(PASSWORD_ENC_SIGN.Length), PASSWORD_ENC_PWD);
}
else
{
return SuPassword;
}
}
///
/// 全参数构造函数
///
///
///
///
///
///
///
///
///
///
public AppConfigSshItem(int number, string name, string server, string port, string username, string password, bool autoSu = false, string suusername = "", string supassword = "")
{
Number = number;
Name = name;
Server = server;
Port = port;
Username = username;
SetPasswordEnc(password);
AutoSu = autoSu;
SuUsername = suusername;
SetSuPasswordEnc(supassword);
}
///
/// 排序序号
///
///
public int GetOrderNumber()
{
return this.Number;
}
///
/// 唯一名称
///
///
public string GetUniqueName()
{
return this.Name;
}
}
}