初始化提交
仓库转移到Gitea,初始化提交,可能丢失以前的git版本日志
This commit is contained in:
505
UTS_Core/UTSModule/License/License.vb
Normal file
505
UTS_Core/UTSModule/License/License.vb
Normal file
@@ -0,0 +1,505 @@
|
||||
Imports System.IO
|
||||
Imports System.Text
|
||||
Imports UTS_Core.DebugLog
|
||||
Imports UTS_Core.Security
|
||||
|
||||
Namespace UTSModule.License
|
||||
|
||||
Public Class License
|
||||
''' <summary> License文件字段枚举 </summary>
|
||||
Private Enum LicenseKeyEnum
|
||||
''' <summary>索引</summary>
|
||||
ID
|
||||
|
||||
''' <summary>客户名</summary>
|
||||
VendorName
|
||||
|
||||
''' <summary>注册日期</summary>
|
||||
AuthorizationDate
|
||||
|
||||
''' <summary>截止日期</summary>
|
||||
ExpirationDate
|
||||
|
||||
''' <summary>管理员账号</summary>
|
||||
DefaultUser
|
||||
|
||||
''' <summary>管理员密码</summary>
|
||||
DefaultPassword
|
||||
|
||||
''' <summary>远程数据库URL或IP</summary>
|
||||
MysqlServer
|
||||
|
||||
''' <summary>远程数据库连接端口</summary>
|
||||
MysqlPort
|
||||
|
||||
''' <summary>远程数据库账号</summary>
|
||||
MysqlUserID
|
||||
|
||||
''' <summary>远程数据库密码</summary>
|
||||
MysqlPassword
|
||||
|
||||
''' <summary>远程数据库私有操作库</summary>
|
||||
MysqlDatabase
|
||||
|
||||
''' <summary>远程数据库共有操作库</summary>
|
||||
PublicDb
|
||||
|
||||
''' <summary>本地数据库存放文件夹</summary>
|
||||
SqliteDir
|
||||
|
||||
''' <summary>本地数据库文件名</summary>
|
||||
SqliteName
|
||||
|
||||
''' <summary>本地数据库密码</summary>
|
||||
SqlitePassword
|
||||
|
||||
''' <summary>Ftp服务器</summary>
|
||||
FtpHost
|
||||
|
||||
''' <summary>Ftp通讯端口</summary>
|
||||
FtpPort
|
||||
|
||||
''' <summary>Ftp通讯账号</summary>
|
||||
FtpUser
|
||||
|
||||
''' <summary>Ftp通讯密码</summary>
|
||||
FtpPwd
|
||||
|
||||
''' <summary>客户MAC地址,锁定|MAC时使用</summary>
|
||||
MAC
|
||||
|
||||
''' <summary>备注</summary>
|
||||
Remark
|
||||
|
||||
''' <summary>UTS版本号</summary>
|
||||
UtsVersion
|
||||
|
||||
''' <summary>签名</summary>
|
||||
Signature
|
||||
End Enum
|
||||
|
||||
''' <summary> License文件校验返回枚举值</summary>
|
||||
Public Enum LicenseCheckCodeEnum
|
||||
|
||||
''' <summary>未找到License</summary>
|
||||
NoLicense
|
||||
|
||||
''' <summary>无法打开License</summary>
|
||||
CantOpenLicense
|
||||
|
||||
''' <summary>无效的License</summary>
|
||||
InvalidLicense
|
||||
|
||||
''' <summary>校验通过</summary>
|
||||
CheckPass
|
||||
End Enum
|
||||
|
||||
|
||||
''' <summary>License校验结果</summary>
|
||||
Public Enum EnLicenseCheckCode
|
||||
''' <summary>校验通过</summary>
|
||||
CheckPass
|
||||
|
||||
''' <summary>无效的客户</summary>
|
||||
InvalidCustomer
|
||||
|
||||
''' <summary>无效的注册日期</summary>
|
||||
InvalidAuthorizationDate
|
||||
|
||||
''' <summary>无效的截止日期</summary>
|
||||
InvalidExpirationDate
|
||||
|
||||
''' <summary>无效的用户</summary>
|
||||
InvalidDefaultUser
|
||||
|
||||
''' <summary>无效的用户密码</summary>
|
||||
InvalidDefaultPassword
|
||||
|
||||
''' <summary>无效的MAC地址</summary>
|
||||
InvalidMac
|
||||
|
||||
''' <summary>无效的UTS版本</summary>
|
||||
InvalidUtsVersion
|
||||
|
||||
''' <summary>无效的签名</summary>
|
||||
InvalidSignature
|
||||
|
||||
''' <summary>无效的数据库地址</summary>
|
||||
InvalidDatabaseServer
|
||||
|
||||
''' <summary>无效的数据库名</summary>
|
||||
InvalidDatabaseName
|
||||
|
||||
''' <summary>无效的数据库用户</summary>
|
||||
InvalidDatabaseUserID
|
||||
|
||||
''' <summary>无效的数据库密码</summary>
|
||||
InvalidDatabaseUserPassword
|
||||
|
||||
''' <summary>无效的数据库端口号</summary>
|
||||
InvalidDatabaseUserPort
|
||||
|
||||
''' <summary>无效的数据库名(sqlite)</summary>
|
||||
InvalidDatabaseFileName
|
||||
|
||||
''' <summary>无效的数据库文件夹名(sqlite)</summary>
|
||||
InvalidDatabaseDirName
|
||||
End Enum
|
||||
|
||||
|
||||
''' <summary>存储License签名校验值</summary>
|
||||
Private ReadOnly _standardSignature As String = "this is a valid license data"
|
||||
|
||||
''' <summary>License密钥</summary>
|
||||
Private ReadOnly _licenseAesKey As String = "8h(*H&-987OygO8yg*yS$&G&aG9*&6g96*&7^RA65s76r*&&G(*(7(Gyg7#7Ff7F*&(*&&^5GHo96tr5ff&*Hphg7665^fyu&uOhj0j[0[(jOIhI&g77FgghO*hhHY"
|
||||
|
||||
Sub New()
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Sub New(licensePath As String)
|
||||
ReadLicenseFile(licensePath)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 索引
|
||||
''' </summary>
|
||||
''' <returns>索引</returns>
|
||||
Public Property ID() As String
|
||||
|
||||
''' <summary>
|
||||
''' 获取客户名
|
||||
''' </summary>
|
||||
''' <returns>客户名</returns>
|
||||
Public Property VendorName As String
|
||||
|
||||
''' <summary>
|
||||
''' 获取注册日期
|
||||
''' </summary>
|
||||
''' <returns>注册日期</returns>
|
||||
Public Property AuthorizationDate() As String
|
||||
|
||||
''' <summary>
|
||||
''' 获取截止日期
|
||||
''' </summary>
|
||||
''' <returns>截止日期</returns>
|
||||
Public Property ExpirationDate() As String
|
||||
|
||||
''' <summary>
|
||||
''' 获取管理员账号
|
||||
''' </summary>
|
||||
''' <returns>管理员账号</returns>
|
||||
Public Property DefaultUser() As String
|
||||
|
||||
''' <summary>
|
||||
''' 获取管理员密码
|
||||
''' </summary>
|
||||
''' <returns>管理员密码</returns>
|
||||
Public Property DefaultPassword() As String
|
||||
|
||||
''' <summary>
|
||||
''' 远程数据库URL或IP(待删除字段)
|
||||
''' </summary>
|
||||
''' <returns>远程数据库URL或IP</returns>
|
||||
Public Property MysqlServer() As String
|
||||
|
||||
''' <summary>
|
||||
''' 远程数据库连接端口
|
||||
''' </summary>
|
||||
''' <returns>远程数据库连接端口</returns>
|
||||
Public Property MysqlPort() As String
|
||||
|
||||
''' <summary>
|
||||
''' 远程数据库账号
|
||||
''' </summary>
|
||||
''' <returns>远程数据库账号</returns>
|
||||
Public Property MysqlUserID() As String
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 远程数据库密码
|
||||
''' </summary>
|
||||
''' <returns>远程数据库密码</returns>
|
||||
Public Property MysqlPassword() As String
|
||||
|
||||
''' <summary>
|
||||
''' 远程数据库操作库
|
||||
''' </summary>
|
||||
''' <returns>远程数据库操作库</returns>
|
||||
Public Property MysqlDatabase() As String
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 远程数据库公开库
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property PublicDb() As String
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 本地数据库存放文件夹
|
||||
''' </summary>
|
||||
''' <returns>本地数据库存放文件夹</returns>
|
||||
Public Property SqliteDir() As String
|
||||
|
||||
''' <summary>
|
||||
''' 本地数据库文件名
|
||||
''' </summary>
|
||||
''' <returns>本地数据库文件名</returns>
|
||||
Public Property SqliteName() As String
|
||||
|
||||
''' <summary>
|
||||
''' 本地数据库密码
|
||||
''' </summary>
|
||||
''' <returns>本地数据库密码</returns>
|
||||
Public Property SqlitePassword() As String
|
||||
|
||||
''' <summary>
|
||||
''' Ftp服务器地址(待删除字段)
|
||||
''' </summary>
|
||||
''' <returns>Ftp服务器地址</returns>
|
||||
Public Property FtpHost() As String
|
||||
|
||||
''' <summary>
|
||||
''' Ftp服务器端口
|
||||
''' </summary>
|
||||
''' <returns>Ftp服务器端口</returns>
|
||||
Public Property FtpPort() As String
|
||||
|
||||
''' <summary>
|
||||
''' Ftp服务器用户
|
||||
''' </summary>
|
||||
''' <returns>Ftp服务器用户</returns>
|
||||
Public Property FtpUser() As String
|
||||
|
||||
''' <summary>
|
||||
''' Ftp服务器密码
|
||||
''' </summary>
|
||||
''' <returns>Ftp服务器密码</returns>
|
||||
Public Property FtpPwd() As String
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 获取客户MAC地址
|
||||
''' </summary>
|
||||
''' <returns>客户MAC地址</returns>
|
||||
Public Property Mac() As String
|
||||
|
||||
''' <summary>
|
||||
''' 获取备注
|
||||
''' </summary>
|
||||
''' <returns>备注</returns>
|
||||
Public Property Remark() As String
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 获取UTS版本号
|
||||
''' </summary>
|
||||
''' <returns>UTS版本号</returns>
|
||||
Public Property UtsVersion() As String
|
||||
|
||||
''' <summary>
|
||||
''' 获取签名
|
||||
''' </summary>
|
||||
''' <returns>签名</returns>
|
||||
Public Property Signature() As String
|
||||
|
||||
|
||||
Public Function DealLicenseString(strLicense As String) As Boolean
|
||||
strLicense = strLicense.Replace(vbLf, String.Empty)
|
||||
|
||||
Dim lines() As String = strLicense.Split(Chr(13))
|
||||
For Each line As String In lines
|
||||
If String.IsNullOrWhiteSpace(line) Then Continue For
|
||||
Dim keyValues As String() = line.Split("="c)
|
||||
If keyValues.Length = 2 Then
|
||||
keyValues(0) = keyValues(0).Trim()
|
||||
keyValues(1) = keyValues(1).Trim()
|
||||
InitLicenseField(keyValues(0), keyValues(1))
|
||||
Else
|
||||
Throw New Exception($"ReadLicense Error:{LicenseCheckCodeEnum.InvalidLicense}")
|
||||
End If
|
||||
Next
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Private Sub InitLicenseField(key As String, value As String)
|
||||
Dim field As LicenseKeyEnum
|
||||
If [Enum].TryParse(key, field) = False Then
|
||||
ApplicationLog.WriteLog(ApplicationLog.LogTypes.Error, $"Error LicenseField,Key:{key},Value:{value}")
|
||||
Return
|
||||
End If
|
||||
|
||||
Select Case field
|
||||
Case LicenseKeyEnum.ID
|
||||
ID = value
|
||||
Case LicenseKeyEnum.AuthorizationDate
|
||||
AuthorizationDate = value
|
||||
Case LicenseKeyEnum.DefaultPassword
|
||||
DefaultPassword = value
|
||||
Case LicenseKeyEnum.DefaultUser
|
||||
DefaultUser = value
|
||||
Case LicenseKeyEnum.ExpirationDate
|
||||
ExpirationDate = value
|
||||
Case LicenseKeyEnum.MAC
|
||||
Mac = value
|
||||
Case LicenseKeyEnum.Remark
|
||||
Remark = value
|
||||
Case LicenseKeyEnum.Signature
|
||||
Signature = value
|
||||
Case LicenseKeyEnum.UtsVersion
|
||||
UtsVersion = value
|
||||
Case LicenseKeyEnum.VendorName
|
||||
VendorName = value
|
||||
Case LicenseKeyEnum.MysqlServer
|
||||
MysqlServer = value
|
||||
Case LicenseKeyEnum.MysqlPort
|
||||
MysqlPort = value
|
||||
Case LicenseKeyEnum.MysqlUserID
|
||||
MysqlUserID = value
|
||||
Case LicenseKeyEnum.MysqlPassword
|
||||
MysqlPassword = value
|
||||
Case LicenseKeyEnum.MysqlDatabase
|
||||
MysqlDatabase = value
|
||||
Case LicenseKeyEnum.PublicDb
|
||||
PublicDb = value
|
||||
Case LicenseKeyEnum.SqliteDir
|
||||
SqliteDir = value
|
||||
Case LicenseKeyEnum.SqliteName
|
||||
SqliteName = value
|
||||
Case LicenseKeyEnum.SqlitePassword
|
||||
SqlitePassword = value
|
||||
Case LicenseKeyEnum.FtpHost
|
||||
FtpHost = value
|
||||
Case LicenseKeyEnum.FtpPort
|
||||
FtpPort = value
|
||||
Case LicenseKeyEnum.FtpUser
|
||||
FtpUser = value
|
||||
Case LicenseKeyEnum.FtpPwd
|
||||
FtpPwd = value
|
||||
Case Else
|
||||
ApplicationLog.WriteLog(ApplicationLog.LogTypes.Warn, $"Untreated,Key:{key},Value:{value}")
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 读取License文件所有内容,并进行解密,将解密后的内容存入License字典中
|
||||
''' </summary>
|
||||
''' <param name="licensePath">License文件完整路径(含文件名)</param>
|
||||
Public Sub ReadLicenseFile(licensePath As String)
|
||||
If File.Exists(licensePath) = False Then
|
||||
Throw New Exception($"ReadLicense Error:{LicenseCheckCodeEnum.NoLicense}")
|
||||
End If
|
||||
|
||||
Dim strLicense As String = Aes128.DecryptStr(File.ReadAllText(licensePath), _licenseAesKey)
|
||||
DealLicenseString(strLicense)
|
||||
End Sub
|
||||
|
||||
|
||||
Public Function CheckLicense() As Boolean
|
||||
'检测ID字段
|
||||
If String.IsNullOrWhiteSpace(ID) Then
|
||||
Throw New Exception($"Not Found License ID.")
|
||||
End If
|
||||
|
||||
'校验注册日期
|
||||
Dim nowDate As String = Format(Now.Date, "yyyy-MM-dd") & " " & Format(TimeOfDay, "HH:mm:ss")
|
||||
If String.Compare(nowDate, AuthorizationDate, StringComparison.OrdinalIgnoreCase) < 0 Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidAuthorizationDate}")
|
||||
End If
|
||||
|
||||
'校验截止日期
|
||||
If String.Compare(nowDate, ExpirationDate, StringComparison.OrdinalIgnoreCase) > 0 Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidExpirationDate}")
|
||||
End If
|
||||
|
||||
'默认用户
|
||||
If String.IsNullOrWhiteSpace(DefaultUser) Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidDefaultUser}")
|
||||
End If
|
||||
|
||||
'默认用户密码
|
||||
If String.IsNullOrWhiteSpace(DefaultPassword) Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidDefaultPassword}")
|
||||
End If
|
||||
|
||||
'校验签名
|
||||
If String.Compare(Signature, _standardSignature, True) <> 0 Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidSignature}")
|
||||
End If
|
||||
|
||||
'校验数据库URL或IP
|
||||
If String.IsNullOrEmpty(MysqlServer) Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidDatabaseServer}")
|
||||
End If
|
||||
|
||||
If String.IsNullOrEmpty(MysqlDatabase) Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidDatabaseName}")
|
||||
End If
|
||||
|
||||
If String.IsNullOrEmpty(MysqlPort) Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidDatabaseUserPort}")
|
||||
End If
|
||||
|
||||
If String.IsNullOrEmpty(MysqlUserID) Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidDatabaseUserID}")
|
||||
End If
|
||||
|
||||
|
||||
If String.IsNullOrEmpty(MysqlPassword) Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidDatabaseUserPassword}")
|
||||
End If
|
||||
|
||||
If String.IsNullOrEmpty(SqliteDir) Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidDatabaseDirName}")
|
||||
End If
|
||||
|
||||
If String.IsNullOrEmpty(SqliteName) Then
|
||||
Throw New Exception($"{EnLicenseCheckCode.InvalidDatabaseFileName}")
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Sub SaveLicenseFile(licensePath As String)
|
||||
Dim builder As New StringBuilder
|
||||
builder.Append($"{LicenseKeyEnum.ID} = {ID}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.VendorName} = {VendorName}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.AuthorizationDate} = {AuthorizationDate}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.ExpirationDate} = {ExpirationDate}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.DefaultUser} = {DefaultUser}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.DefaultPassword} = {DefaultPassword}{vbCrLf}")
|
||||
|
||||
builder.Append($"{LicenseKeyEnum.MysqlServer} = {MysqlServer }{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.MysqlPort} = {MysqlPort}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.MysqlUserID} = {MysqlUserID}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.MysqlPassword} = {MysqlPassword}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.MysqlDatabase} = {MysqlDatabase}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.PublicDb} = {PublicDb}{vbCrLf}")
|
||||
|
||||
builder.Append($"{LicenseKeyEnum.SqliteDir} = {SqliteDir}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.SqliteName} = {SqliteName}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.SqlitePassword} = {SqlitePassword}{vbCrLf}")
|
||||
|
||||
builder.Append($"{LicenseKeyEnum.FtpHost} = {FtpHost}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.FtpPort} = {FtpPort}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.FtpUser} = {FtpUser}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.FtpPwd} = {FtpPwd}{vbCrLf}")
|
||||
|
||||
builder.Append($"{LicenseKeyEnum.MAC} = {Mac}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.Remark} = {Remark}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.UtsVersion} = {UtsVersion}{vbCrLf}")
|
||||
builder.Append($"{LicenseKeyEnum.Signature} = {Signature }{vbCrLf}")
|
||||
|
||||
Dim strLicense As String = Aes128.EncryptStr(builder.ToString(), _licenseAesKey)
|
||||
|
||||
File.WriteAllText(licensePath, strLicense)
|
||||
'File.WriteAllText(licensePath, licenseString.ToString())
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
237
UTS_Core/UTSModule/License/Server.vb
Normal file
237
UTS_Core/UTSModule/License/Server.vb
Normal file
@@ -0,0 +1,237 @@
|
||||
Imports System.IO
|
||||
Imports UTS_Core.Security
|
||||
|
||||
Namespace UTSModule.License
|
||||
|
||||
''' <summary>
|
||||
''' 类的作用:获取服务器信息
|
||||
''' 创建人员:ML
|
||||
''' Log编号:1
|
||||
''' 修改描述:创建
|
||||
''' 修改日期:2019-10-15
|
||||
''' 修改人员:ML
|
||||
''' </summary>
|
||||
Public Class Server
|
||||
|
||||
''' <summary> Server文件字段枚举 </summary>
|
||||
Private Enum ServerKeyEnum
|
||||
|
||||
''' <summary>客户名</summary>
|
||||
VendorName
|
||||
|
||||
''' <summary>数据库服务器地址</summary>
|
||||
DataSource
|
||||
|
||||
''' <summary>数据库服务器端口</summary>
|
||||
DbPort
|
||||
|
||||
''' <summary>数据库名</summary>
|
||||
Database
|
||||
|
||||
''' <summary>数据库用户名</summary>
|
||||
DbUser
|
||||
|
||||
''' <summary>数据库用户密码</summary>
|
||||
DbPassword
|
||||
|
||||
''' <summary>Ftp地址</summary>
|
||||
FtpHost
|
||||
|
||||
''' <summary>Ftp端口</summary>
|
||||
FtpPort
|
||||
|
||||
''' <summary>Ftp用户名</summary>
|
||||
FtpUser
|
||||
|
||||
''' <summary>Ftp用户密码</summary>
|
||||
FtpPassword
|
||||
|
||||
End Enum
|
||||
|
||||
''' <summary> Server文件校验返回枚举值</summary>
|
||||
Public Enum ServerCheckCodeEnum
|
||||
|
||||
''' <summary>未找到Server</summary>
|
||||
NoServer
|
||||
|
||||
''' <summary>无法打开Server</summary>
|
||||
CantOpenServer
|
||||
|
||||
''' <summary>无效的Server</summary>
|
||||
InvalidServer
|
||||
|
||||
''' <summary>校验通过</summary>
|
||||
CheckPass
|
||||
|
||||
End Enum
|
||||
|
||||
''' <summary>存储Server校验返回值</summary>
|
||||
Private _checkCode As ServerCheckCodeEnum
|
||||
|
||||
''' <summary>存储Server所有信息</summary>
|
||||
Private _server As Dictionary(Of String, String)
|
||||
|
||||
''' <summary>服务器密钥</summary>
|
||||
Private ReadOnly _serverAesKey As String = "^5GHo96tr5ff&*Hphg7665^fyu&uOhj0j[0[(jOIhI&g77FgghO*hhHY8h(*H&-987OygO8yg*yS$&G&aG9*&6g96*&7^RA65s76r*&&G(*(7(Gyg7#7Ff7F*&(*&&^"
|
||||
|
||||
'''<summary>Server所有可用字段</summary>
|
||||
Private ReadOnly _serverKey() As String = {"VendorName", "DataSource", "DataPort", "Database", "DbUser", "DbPassword", "FtpHost", "FtpPort", "FtpUser", "FtpPassword"}
|
||||
|
||||
''' <summary>
|
||||
''' 获取客户名
|
||||
''' </summary>
|
||||
''' <returns>客户名</returns>
|
||||
Public ReadOnly Property VendorName() As String
|
||||
Get
|
||||
Return _server.Item(_serverKey(ServerKeyEnum.VendorName))
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 获取服务器名
|
||||
''' </summary>
|
||||
''' <returns>服务器名</returns>
|
||||
Public ReadOnly Property DataSource() As String
|
||||
Get
|
||||
Return _server.Item(_serverKey(ServerKeyEnum.DataSource))
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 获取服务器端口
|
||||
''' </summary>
|
||||
''' <returns>服务器端口</returns>
|
||||
Public ReadOnly Property DatabasePort() As String
|
||||
Get
|
||||
Return _server.Item(_serverKey(ServerKeyEnum.DbPort))
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 获取数据库名
|
||||
''' </summary>
|
||||
''' <returns>数据库名</returns>
|
||||
Public ReadOnly Property Database() As String
|
||||
Get
|
||||
Return _server.Item(_serverKey(ServerKeyEnum.Database))
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 获取数据库用户名
|
||||
''' </summary>
|
||||
''' <returns>数据库用户名</returns>
|
||||
Public ReadOnly Property DatabaseUser() As String
|
||||
Get
|
||||
Return _server.Item(_serverKey(ServerKeyEnum.DbUser))
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 获取数据库用户密码
|
||||
''' </summary>
|
||||
''' <returns>数据库用户密码</returns>
|
||||
Public ReadOnly Property DatabasePassword() As String
|
||||
Get
|
||||
Return _server.Item(_serverKey(ServerKeyEnum.DbPassword))
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 获取服务器端口
|
||||
''' </summary>
|
||||
''' <returns>服务器端口</returns>
|
||||
Public ReadOnly Property FtpPort() As String
|
||||
Get
|
||||
Return _server.Item(_serverKey(ServerKeyEnum.FtpPort))
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 获取数据库名
|
||||
''' </summary>
|
||||
''' <returns>数据库名</returns>
|
||||
Public ReadOnly Property FtpHost() As String
|
||||
Get
|
||||
Return _server.Item(_serverKey(ServerKeyEnum.FtpHost))
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 获取数据库用户名
|
||||
''' </summary>
|
||||
''' <returns>数据库用户名</returns>
|
||||
Public ReadOnly Property FtpUser() As String
|
||||
Get
|
||||
Return _server.Item(_serverKey(ServerKeyEnum.FtpUser))
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 获取数据库用户密码
|
||||
''' </summary>
|
||||
''' <returns>数据库用户密码</returns>
|
||||
Public ReadOnly Property FtpPassword() As String
|
||||
Get
|
||||
Return _server.Item(_serverKey(ServerKeyEnum.FtpPassword))
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 读取Server文件所有内容,并进行解密,将解密后的内容存入Server字典中
|
||||
''' </summary>
|
||||
''' <param name="serverPath">Server文件完整路径(含文件名)</param>
|
||||
''' <returns>读取Server文件的状态</returns>
|
||||
Public Function ReadServerFile(ByVal serverPath As String) As ServerCheckCodeEnum
|
||||
Dim tmp As String
|
||||
Dim fm As FileStream
|
||||
Dim sr As StreamReader
|
||||
If File.Exists(serverPath) Then
|
||||
fm = New FileStream(serverPath, FileMode.Open)
|
||||
sr = New StreamReader(fm)
|
||||
_checkCode = ServerCheckCodeEnum.CheckPass
|
||||
_server = New Dictionary(Of String, String)
|
||||
Try
|
||||
tmp = Aes128.DecryptStr(sr.ReadToEnd, _serverAesKey) 'utf8解密字符串
|
||||
' tmp = ClsAes128.DecryptStr(sr.ReadToEnd, _serverAesKey, Unicode) 'Unicode解密字符串
|
||||
Dim lines() As String = tmp.Split(Chr(13))‘回车切割
|
||||
For i As Integer = 0 To lines.Length - 1
|
||||
tmp = lines(i).Trim(Chr(10))'去除换行
|
||||
Dim str As String() = tmp.Split("="c)
|
||||
If str.Length = 2 Then
|
||||
_server.Add(Trim(str(0)), Trim(str(1)))
|
||||
Debug.Print($"Keys : {_server.Keys.ElementAt(_server.Count - 1)} Value : {_server.Values.ElementAt(_server.Count - 1)}")
|
||||
Else
|
||||
_checkCode = ServerCheckCodeEnum.InvalidServer
|
||||
End If
|
||||
Next
|
||||
Catch ex As Exception
|
||||
_checkCode = ServerCheckCodeEnum.InvalidServer
|
||||
Finally
|
||||
fm.Dispose()
|
||||
sr.Close()
|
||||
End Try
|
||||
Else
|
||||
_checkCode = ServerCheckCodeEnum.NoServer
|
||||
End If
|
||||
Return _checkCode
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 校验Server
|
||||
''' </summary>
|
||||
''' <param name="serverPath">Server文件完整路径(含文件名)</param>
|
||||
''' <returns>校验是否通过</returns>
|
||||
Public Function CheckoutServer(ByVal serverPath As String) As ServerCheckCodeEnum
|
||||
If ReadServerFile(serverPath) = ServerCheckCodeEnum.CheckPass Then
|
||||
'校验厂商(根据是否存在厂商数据库校验)
|
||||
If My.Computer.Network.Ping(_server.Item(_serverKey(ServerKeyEnum.DataSource))) Then
|
||||
|
||||
End If
|
||||
|
||||
End If
|
||||
Return _checkCode
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user