#78 new: alter host
This commit is contained in:
@@ -35,15 +35,31 @@ Future<SSHClient> genClient(
|
||||
ServerPrivateInfo spi, {
|
||||
void Function(GenSSHClientStatus)? onStatus,
|
||||
}) async {
|
||||
final onStatus_ = onStatus ?? (_) {};
|
||||
onStatus_(GenSSHClientStatus.socket);
|
||||
final socket = await SSHSocket.connect(
|
||||
spi.ip,
|
||||
spi.port,
|
||||
timeout: const Duration(seconds: 5),
|
||||
);
|
||||
onStatus?.call(GenSSHClientStatus.socket);
|
||||
late SSHSocket socket;
|
||||
try {
|
||||
socket = await SSHSocket.connect(
|
||||
spi.ip,
|
||||
spi.port,
|
||||
timeout: const Duration(seconds: 5),
|
||||
);
|
||||
} catch (e) {
|
||||
try {
|
||||
socket = await SSHSocket.connect(
|
||||
spi.alterHost!,
|
||||
spi.port,
|
||||
timeout: const Duration(seconds: 5),
|
||||
);
|
||||
} catch (e) {
|
||||
throw SSHErr(
|
||||
type: SSHErrType.connect,
|
||||
message: e.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (spi.pubKeyId == null) {
|
||||
onStatus_(GenSSHClientStatus.pwd);
|
||||
onStatus?.call(GenSSHClientStatus.pwd);
|
||||
return SSHClient(
|
||||
socket,
|
||||
username: spi.user,
|
||||
@@ -57,7 +73,7 @@ Future<SSHClient> genClient(
|
||||
message: 'key [${spi.pubKeyId}] not found',
|
||||
);
|
||||
}
|
||||
onStatus_(GenSSHClientStatus.key);
|
||||
onStatus?.call(GenSSHClientStatus.key);
|
||||
return SSHClient(
|
||||
socket,
|
||||
username: spi.user,
|
||||
|
||||
@@ -17,6 +17,7 @@ abstract class Err<T> {
|
||||
|
||||
enum SSHErrType {
|
||||
unknown,
|
||||
connect,
|
||||
noPrivateKey;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ class ServerPrivateInfo {
|
||||
String? pubKeyId;
|
||||
@HiveField(6)
|
||||
List<String>? tags;
|
||||
@HiveField(7)
|
||||
String? alterHost;
|
||||
|
||||
late String id;
|
||||
|
||||
@@ -29,6 +31,7 @@ class ServerPrivateInfo {
|
||||
required this.pwd,
|
||||
this.pubKeyId,
|
||||
this.tags,
|
||||
this.alterHost,
|
||||
}) : id = '$user@$ip:$port';
|
||||
|
||||
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
|
||||
@@ -40,6 +43,7 @@ class ServerPrivateInfo {
|
||||
pubKeyId = json["pubKeyId"]?.toString();
|
||||
id = '$user@$ip:$port';
|
||||
tags = json["tags"]?.cast<String>();
|
||||
alterHost = json["alterHost"]?.toString();
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
@@ -51,11 +55,15 @@ class ServerPrivateInfo {
|
||||
data["authorization"] = pwd;
|
||||
data["pubKeyId"] = pubKeyId;
|
||||
data["tags"] = tags;
|
||||
data["alterHost"] = alterHost;
|
||||
return data;
|
||||
}
|
||||
|
||||
bool shouldReconnect(ServerPrivateInfo old) {
|
||||
return id != old.id || pwd != old.pwd || pubKeyId != old.pubKeyId;
|
||||
return id != old.id ||
|
||||
pwd != old.pwd ||
|
||||
pubKeyId != old.pubKeyId ||
|
||||
alterHost != old.alterHost;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -24,13 +24,14 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
||||
pwd: fields[4] as String,
|
||||
pubKeyId: fields[5] as String?,
|
||||
tags: (fields[6] as List?)?.cast<String>(),
|
||||
alterHost: fields[7] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ServerPrivateInfo obj) {
|
||||
writer
|
||||
..writeByte(7)
|
||||
..writeByte(8)
|
||||
..writeByte(0)
|
||||
..write(obj.name)
|
||||
..writeByte(1)
|
||||
@@ -44,7 +45,9 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
||||
..writeByte(5)
|
||||
..write(obj.pubKeyId)
|
||||
..writeByte(6)
|
||||
..write(obj.tags);
|
||||
..write(obj.tags)
|
||||
..writeByte(7)
|
||||
..write(obj.alterHost);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 388;
|
||||
static const int build = 389;
|
||||
static const String engine = "3.10.6";
|
||||
static const String buildAt = "2023-07-27 13:03:33.193528";
|
||||
static const int modifications = 16;
|
||||
static const String buildAt = "2023-07-28 13:50:35.251988";
|
||||
static const int modifications = 17;
|
||||
}
|
||||
|
||||
@@ -14,4 +14,5 @@ const thanksMap = {
|
||||
'wxdjs': 'https://github.com/wxdjs',
|
||||
'Aeorq': 'https://github.com/Aeorq',
|
||||
'jaychoubaby': 'https://github.com/jaychoubaby',
|
||||
'allonmymind': 'https://github.com/allonmymind',
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"added2List": "Zur Aufgabenliste hinzugefügt",
|
||||
"all": "Alle",
|
||||
"alreadyLastDir": "Bereits im letzten Verzeichnis.",
|
||||
"alterHost": "Alternative Gastgeber",
|
||||
"attention": "Achtung",
|
||||
"auto": "System folgen",
|
||||
"autoUpdateHomeWidget": "Home-Widget automatisch aktualisieren",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"added2List": "Added to task list",
|
||||
"all": "All",
|
||||
"alreadyLastDir": "Already in last directory.",
|
||||
"alterHost": "Alter host",
|
||||
"attention": "Attention",
|
||||
"auto": "Auto",
|
||||
"autoUpdateHomeWidget": "Auto update home widget",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"added2List": "已添加至任务列表",
|
||||
"all": "所有",
|
||||
"alreadyLastDir": "已经是最上层目录了",
|
||||
"alterHost": "备选主机",
|
||||
"attention": "注意",
|
||||
"auto": "自动",
|
||||
"autoUpdateHomeWidget": "自动更新桌面小部件",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"added2List": "已添加至任務列表",
|
||||
"all": "所有",
|
||||
"alreadyLastDir": "已經是最上層目錄了",
|
||||
"alterHost": "備選主機",
|
||||
"attention": "注意",
|
||||
"auto": "自動",
|
||||
"autoUpdateHomeWidget": "自動更新桌面小部件",
|
||||
|
||||
@@ -30,11 +30,13 @@ class ServerEditPage extends StatefulWidget {
|
||||
class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
final _nameController = TextEditingController();
|
||||
final _ipController = TextEditingController();
|
||||
final _alterHostController = TextEditingController();
|
||||
final _portController = TextEditingController();
|
||||
final _usernameController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
final _nameFocus = FocusNode();
|
||||
final _ipFocus = FocusNode();
|
||||
final _alterHostFocus = FocusNode();
|
||||
final _portFocus = FocusNode();
|
||||
final _usernameFocus = FocusNode();
|
||||
|
||||
@@ -118,12 +120,20 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
Input(
|
||||
controller: _ipController,
|
||||
type: TextInputType.text,
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_portFocus),
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_alterHostFocus),
|
||||
node: _ipFocus,
|
||||
label: _s.host,
|
||||
icon: Icons.storage,
|
||||
icon: Icons.computer,
|
||||
hint: 'example.com',
|
||||
),
|
||||
Input(
|
||||
controller: _alterHostController,
|
||||
type: TextInputType.text,
|
||||
node: _alterHostFocus,
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_portFocus),
|
||||
label: _s.alterHost,
|
||||
icon: Icons.computer,
|
||||
),
|
||||
Input(
|
||||
controller: _portController,
|
||||
type: TextInputType.number,
|
||||
@@ -280,6 +290,9 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
pwd: authorization,
|
||||
pubKeyId: usePublicKey ? _keyInfo!.id : null,
|
||||
tags: _tags,
|
||||
alterHost: _alterHostController.text == ''
|
||||
? null
|
||||
: _alterHostController.text,
|
||||
);
|
||||
|
||||
if (widget.spi == null) {
|
||||
@@ -321,6 +334,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
if (widget.spi?.tags != null) {
|
||||
_tags = widget.spi!.tags!;
|
||||
}
|
||||
_alterHostController.text = widget.spi?.alterHost ?? '';
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -869,7 +869,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
Widget _buildAndroidWidgetSharedPreference() {
|
||||
return ListTile(
|
||||
title: Text(_s.homeWidgetUrlConfig),
|
||||
trailing: const Icon(Icons.arrow_forward_ios, size: 13),
|
||||
trailing: const Icon(Icons.keyboard_arrow_right),
|
||||
onTap: () {
|
||||
final data = <String, String>{};
|
||||
_sp.getKeys().forEach((key) {
|
||||
|
||||
Reference in New Issue
Block a user