mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
chore: import CSV with password support
This commit is contained in:
@@ -52,7 +52,7 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val log = LoggerFactory.getLogger(NewHostTree::class.java)
|
private val log = LoggerFactory.getLogger(NewHostTree::class.java)
|
||||||
private val CSV_HEADERS = arrayOf("Folders", "Label", "Hostname", "Port", "Username", "Protocol")
|
private val CSV_HEADERS = arrayOf("Folders", "Label", "Protocol", "Hostname", "Port", "Username", "Password")
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// 基本信息
|
// 基本信息
|
||||||
@@ -577,26 +577,29 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
printer.printRecord(
|
printer.printRecord(
|
||||||
"Projects/Dev",
|
"Projects/Dev",
|
||||||
"Web Server",
|
"Web Server",
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
"192.168.1.1",
|
"192.168.1.1",
|
||||||
"22",
|
"22",
|
||||||
"root",
|
"root",
|
||||||
SSHProtocolProvider.PROTOCOL
|
StringUtils.EMPTY,
|
||||||
)
|
)
|
||||||
printer.printRecord(
|
printer.printRecord(
|
||||||
"Projects/Prod",
|
"Projects/Prod",
|
||||||
"Web Server",
|
"Web Server",
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
"serverhost.com",
|
"serverhost.com",
|
||||||
"2222",
|
"2222",
|
||||||
"root",
|
"root",
|
||||||
SSHProtocolProvider.PROTOCOL
|
StringUtils.EMPTY,
|
||||||
)
|
)
|
||||||
printer.printRecord(
|
printer.printRecord(
|
||||||
StringUtils.EMPTY,
|
StringUtils.EMPTY,
|
||||||
"Web Server",
|
"Web Server",
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
"serverhost.com",
|
"serverhost.com",
|
||||||
"2222",
|
"2222",
|
||||||
"user",
|
"user",
|
||||||
SSHProtocolProvider.PROTOCOL
|
StringUtils.EMPTY,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
OptionPane.openFileInFolder(
|
OptionPane.openFileInFolder(
|
||||||
@@ -683,10 +686,11 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
printer.printRecord(
|
printer.printRecord(
|
||||||
groups.joinToString("/"),
|
groups.joinToString("/"),
|
||||||
label,
|
label,
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
target,
|
target,
|
||||||
port,
|
port,
|
||||||
StringUtils.EMPTY,
|
StringUtils.EMPTY,
|
||||||
SSHProtocolProvider.PROTOCOL
|
StringUtils.EMPTY,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -703,10 +707,11 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
printer.printRecord(
|
printer.printRecord(
|
||||||
StringUtils.EMPTY,
|
StringUtils.EMPTY,
|
||||||
StringUtils.defaultString(entry.host),
|
StringUtils.defaultString(entry.host),
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
StringUtils.defaultString(entry.hostName),
|
StringUtils.defaultString(entry.hostName),
|
||||||
if (entry.port == 0) 22 else entry.port,
|
if (entry.port == 0) 22 else entry.port,
|
||||||
StringUtils.defaultString(entry.username),
|
StringUtils.defaultString(entry.username),
|
||||||
SSHProtocolProvider.PROTOCOL
|
StringUtils.EMPTY,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -746,10 +751,11 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
printer.printRecord(
|
printer.printRecord(
|
||||||
folders.joinToString("/"),
|
folders.joinToString("/"),
|
||||||
label,
|
label,
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
hostname,
|
hostname,
|
||||||
port.toString(),
|
port.toString(),
|
||||||
username,
|
username,
|
||||||
SSHProtocolProvider.PROTOCOL
|
StringUtils.EMPTY,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -776,10 +782,11 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
printer.printRecord(
|
printer.printRecord(
|
||||||
StringUtils.EMPTY,
|
StringUtils.EMPTY,
|
||||||
label,
|
label,
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
hostname,
|
hostname,
|
||||||
port.toString(),
|
port.toString(),
|
||||||
username,
|
username,
|
||||||
SSHProtocolProvider.PROTOCOL
|
StringUtils.EMPTY,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -819,7 +826,15 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
if (segments.first() != "#109#0") continue
|
if (segments.first() != "#109#0") continue
|
||||||
val hostname = segments.getOrNull(1) ?: StringUtils.EMPTY
|
val hostname = segments.getOrNull(1) ?: StringUtils.EMPTY
|
||||||
val port = segments.getOrNull(2) ?: 22
|
val port = segments.getOrNull(2) ?: 22
|
||||||
printer.printRecord(folders, key, hostname, port, StringUtils.EMPTY, SSHProtocolProvider.PROTOCOL)
|
printer.printRecord(
|
||||||
|
folders,
|
||||||
|
key,
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
|
hostname,
|
||||||
|
port,
|
||||||
|
StringUtils.EMPTY,
|
||||||
|
StringUtils.EMPTY
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -848,7 +863,15 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
val label = file.nameWithoutExtension
|
val label = file.nameWithoutExtension
|
||||||
val port = ini.get("CONNECTION", "Port")?.toIntOrNull() ?: 22
|
val port = ini.get("CONNECTION", "Port")?.toIntOrNull() ?: 22
|
||||||
val username = ini.get("CONNECTION:AUTHENTICATION", "UserName") ?: StringUtils.EMPTY
|
val username = ini.get("CONNECTION:AUTHENTICATION", "UserName") ?: StringUtils.EMPTY
|
||||||
printer.printRecord(folders, label, hostname, port, username, SSHProtocolProvider.PROTOCOL)
|
printer.printRecord(
|
||||||
|
folders,
|
||||||
|
label,
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
|
hostname,
|
||||||
|
port,
|
||||||
|
username,
|
||||||
|
StringUtils.EMPTY
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -885,10 +908,11 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
printer.printRecord(
|
printer.printRecord(
|
||||||
folders,
|
folders,
|
||||||
StringUtils.defaultIfBlank(label, host),
|
StringUtils.defaultIfBlank(label, host),
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
username,
|
username,
|
||||||
SSHProtocolProvider.PROTOCOL
|
StringUtils.EMPTY,
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (log.isErrorEnabled) {
|
if (log.isErrorEnabled) {
|
||||||
@@ -940,10 +964,11 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
printer.printRecord(
|
printer.printRecord(
|
||||||
folderNames.joinToString("/"),
|
folderNames.joinToString("/"),
|
||||||
StringUtils.defaultIfBlank(title, hostname),
|
StringUtils.defaultIfBlank(title, hostname),
|
||||||
|
SSHProtocolProvider.PROTOCOL,
|
||||||
hostname,
|
hostname,
|
||||||
port,
|
port,
|
||||||
username,
|
username,
|
||||||
SSHProtocolProvider.PROTOCOL
|
StringUtils.EMPTY,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -975,6 +1000,7 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
val hostname = map["Hostname"] ?: StringUtils.EMPTY
|
val hostname = map["Hostname"] ?: StringUtils.EMPTY
|
||||||
val port = map["Port"]?.toIntOrNull() ?: 22
|
val port = map["Port"]?.toIntOrNull() ?: 22
|
||||||
val username = map["Username"] ?: StringUtils.EMPTY
|
val username = map["Username"] ?: StringUtils.EMPTY
|
||||||
|
val password = map["Password"] ?: StringUtils.EMPTY
|
||||||
val protocol = map["Protocol"] ?: "SSH"
|
val protocol = map["Protocol"] ?: "SSH"
|
||||||
// 仅支持 SSH、RDP 协议
|
// 仅支持 SSH、RDP 协议
|
||||||
if (StringUtils.equalsAnyIgnoreCase(protocol, "SSH", "RDP").not()) continue
|
if (StringUtils.equalsAnyIgnoreCase(protocol, "SSH", "RDP").not()) continue
|
||||||
@@ -1017,6 +1043,15 @@ class NewHostTree : SimpleTree(), Disposable {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (password.isNotBlank()) {
|
||||||
|
n.host = n.host.copy(
|
||||||
|
authentication = Authentication.No.copy(
|
||||||
|
type = AuthenticationType.Password,
|
||||||
|
password = password,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
nodes.add(n)
|
nodes.add(n)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user