mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
#78 opt.: alter url
This commit is contained in:
@@ -146,11 +146,11 @@ abstract class S {
|
|||||||
/// **'Already in last directory.'**
|
/// **'Already in last directory.'**
|
||||||
String get alreadyLastDir;
|
String get alreadyLastDir;
|
||||||
|
|
||||||
/// No description provided for @alterHost.
|
/// No description provided for @alterUrl.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
/// **'Alter host'**
|
/// **'Alter url'**
|
||||||
String get alterHost;
|
String get alterUrl;
|
||||||
|
|
||||||
/// No description provided for @attention.
|
/// No description provided for @attention.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class SDe extends S {
|
|||||||
String get alreadyLastDir => 'Bereits im letzten Verzeichnis.';
|
String get alreadyLastDir => 'Bereits im letzten Verzeichnis.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get alterHost => 'Alternative Gastgeber';
|
String get alterUrl => 'Url ändern';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get attention => 'Achtung';
|
String get attention => 'Achtung';
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class SEn extends S {
|
|||||||
String get alreadyLastDir => 'Already in last directory.';
|
String get alreadyLastDir => 'Already in last directory.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get alterHost => 'Alter host';
|
String get alterUrl => 'Alter url';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get attention => 'Attention';
|
String get attention => 'Attention';
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class SId extends S {
|
|||||||
String get alreadyLastDir => 'Sudah di direktori terakhir.';
|
String get alreadyLastDir => 'Sudah di direktori terakhir.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get alterHost => 'Alter host';
|
String get alterUrl => 'Alter url';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get attention => 'Perhatian';
|
String get attention => 'Perhatian';
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class SZh extends S {
|
|||||||
String get alreadyLastDir => '已经是最上层目录了';
|
String get alreadyLastDir => '已经是最上层目录了';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get alterHost => '备选主机';
|
String get alterUrl => '备选链接';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get attention => '注意';
|
String get attention => '注意';
|
||||||
@@ -711,7 +711,7 @@ class SZhTw extends SZh {
|
|||||||
String get alreadyLastDir => '已經是最上層目錄了';
|
String get alreadyLastDir => '已經是最上層目錄了';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get alterHost => '備選主機';
|
String get alterUrl => '備選鏈接';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get attention => '注意';
|
String get attention => '注意';
|
||||||
|
|||||||
@@ -57,16 +57,14 @@ Future<SSHClient> genClient(
|
|||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
try {
|
try {
|
||||||
|
spi.fromStringUrl();
|
||||||
socket = await SSHSocket.connect(
|
socket = await SSHSocket.connect(
|
||||||
spi.alterHost!,
|
spi.ip,
|
||||||
spi.port,
|
spi.port,
|
||||||
timeout: const Duration(seconds: 5),
|
timeout: const Duration(seconds: 5),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw SSHErr(
|
rethrow;
|
||||||
type: SSHErrType.connect,
|
|
||||||
message: e.toString(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
|
|
||||||
|
import '../app/error.dart';
|
||||||
|
|
||||||
part 'server_private_info.g.dart';
|
part 'server_private_info.g.dart';
|
||||||
|
|
||||||
@HiveType(typeId: 3)
|
@HiveType(typeId: 3)
|
||||||
@@ -19,7 +21,7 @@ class ServerPrivateInfo {
|
|||||||
@HiveField(6)
|
@HiveField(6)
|
||||||
List<String>? tags;
|
List<String>? tags;
|
||||||
@HiveField(7)
|
@HiveField(7)
|
||||||
String? alterHost;
|
String? alterUrl;
|
||||||
|
|
||||||
late String id;
|
late String id;
|
||||||
|
|
||||||
@@ -31,7 +33,7 @@ class ServerPrivateInfo {
|
|||||||
required this.pwd,
|
required this.pwd,
|
||||||
this.pubKeyId,
|
this.pubKeyId,
|
||||||
this.tags,
|
this.tags,
|
||||||
this.alterHost,
|
this.alterUrl,
|
||||||
}) : id = '$user@$ip:$port';
|
}) : id = '$user@$ip:$port';
|
||||||
|
|
||||||
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
|
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
|
||||||
@@ -43,7 +45,7 @@ class ServerPrivateInfo {
|
|||||||
pubKeyId = json["pubKeyId"]?.toString();
|
pubKeyId = json["pubKeyId"]?.toString();
|
||||||
id = '$user@$ip:$port';
|
id = '$user@$ip:$port';
|
||||||
tags = json["tags"]?.cast<String>();
|
tags = json["tags"]?.cast<String>();
|
||||||
alterHost = json["alterHost"]?.toString();
|
alterUrl = json["alterHost"]?.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
@@ -55,7 +57,7 @@ class ServerPrivateInfo {
|
|||||||
data["authorization"] = pwd;
|
data["authorization"] = pwd;
|
||||||
data["pubKeyId"] = pubKeyId;
|
data["pubKeyId"] = pubKeyId;
|
||||||
data["tags"] = tags;
|
data["tags"] = tags;
|
||||||
data["alterHost"] = alterHost;
|
data["alterHost"] = alterUrl;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +65,31 @@ class ServerPrivateInfo {
|
|||||||
return id != old.id ||
|
return id != old.id ||
|
||||||
pwd != old.pwd ||
|
pwd != old.pwd ||
|
||||||
pubKeyId != old.pubKeyId ||
|
pubKeyId != old.pubKeyId ||
|
||||||
alterHost != old.alterHost;
|
alterUrl != old.alterUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fromStringUrl() {
|
||||||
|
if (alterUrl == null) {
|
||||||
|
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl is null');
|
||||||
|
}
|
||||||
|
final splited = alterUrl!.split('@');
|
||||||
|
if (splited.length != 2) {
|
||||||
|
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no @');
|
||||||
|
}
|
||||||
|
user = splited[0];
|
||||||
|
final splited2 = splited[1].split(':');
|
||||||
|
if (splited2.length != 2) {
|
||||||
|
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no :');
|
||||||
|
}
|
||||||
|
ip = splited2[0];
|
||||||
|
port = int.tryParse(splited2[1]) ?? 22;
|
||||||
|
if (port <= 0 || port > 65535) {
|
||||||
|
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl port error');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not update [id]
|
||||||
|
// Because [id] is the identity which is used to find the [SSHClient]
|
||||||
|
// id = '$user@$ip:$port';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
|||||||
pwd: fields[4] as String,
|
pwd: fields[4] as String,
|
||||||
pubKeyId: fields[5] as String?,
|
pubKeyId: fields[5] as String?,
|
||||||
tags: (fields[6] as List?)?.cast<String>(),
|
tags: (fields[6] as List?)?.cast<String>(),
|
||||||
alterHost: fields[7] as String?,
|
alterUrl: fields[7] as String?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
|||||||
..writeByte(6)
|
..writeByte(6)
|
||||||
..write(obj.tags)
|
..write(obj.tags)
|
||||||
..writeByte(7)
|
..writeByte(7)
|
||||||
..write(obj.alterHost);
|
..write(obj.alterUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"added2List": "Zur Aufgabenliste hinzugefügt",
|
"added2List": "Zur Aufgabenliste hinzugefügt",
|
||||||
"all": "Alle",
|
"all": "Alle",
|
||||||
"alreadyLastDir": "Bereits im letzten Verzeichnis.",
|
"alreadyLastDir": "Bereits im letzten Verzeichnis.",
|
||||||
"alterHost": "Alternative Gastgeber",
|
"alterUrl": "Url ändern",
|
||||||
"attention": "Achtung",
|
"attention": "Achtung",
|
||||||
"auto": "System folgen",
|
"auto": "System folgen",
|
||||||
"autoUpdateHomeWidget": "Home-Widget automatisch aktualisieren",
|
"autoUpdateHomeWidget": "Home-Widget automatisch aktualisieren",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"added2List": "Added to task list",
|
"added2List": "Added to task list",
|
||||||
"all": "All",
|
"all": "All",
|
||||||
"alreadyLastDir": "Already in last directory.",
|
"alreadyLastDir": "Already in last directory.",
|
||||||
"alterHost": "Alter host",
|
"alterUrl": "Alter url",
|
||||||
"attention": "Attention",
|
"attention": "Attention",
|
||||||
"auto": "Auto",
|
"auto": "Auto",
|
||||||
"autoUpdateHomeWidget": "Auto update home widget",
|
"autoUpdateHomeWidget": "Auto update home widget",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"added2List": "Ditambahkan ke Daftar Tugas",
|
"added2List": "Ditambahkan ke Daftar Tugas",
|
||||||
"all": "Semua",
|
"all": "Semua",
|
||||||
"alreadyLastDir": "Sudah di direktori terakhir.",
|
"alreadyLastDir": "Sudah di direktori terakhir.",
|
||||||
"alterHost": "Alter host",
|
"alterUrl": "Alter url",
|
||||||
"attention": "Perhatian",
|
"attention": "Perhatian",
|
||||||
"auto": "Auto",
|
"auto": "Auto",
|
||||||
"autoUpdateHomeWidget": "Widget Rumah Pembaruan Otomatis",
|
"autoUpdateHomeWidget": "Widget Rumah Pembaruan Otomatis",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"added2List": "已添加至任务列表",
|
"added2List": "已添加至任务列表",
|
||||||
"all": "所有",
|
"all": "所有",
|
||||||
"alreadyLastDir": "已经是最上层目录了",
|
"alreadyLastDir": "已经是最上层目录了",
|
||||||
"alterHost": "备选主机",
|
"alterUrl": "备选链接",
|
||||||
"attention": "注意",
|
"attention": "注意",
|
||||||
"auto": "自动",
|
"auto": "自动",
|
||||||
"autoUpdateHomeWidget": "自动更新桌面小部件",
|
"autoUpdateHomeWidget": "自动更新桌面小部件",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"added2List": "已添加至任務列表",
|
"added2List": "已添加至任務列表",
|
||||||
"all": "所有",
|
"all": "所有",
|
||||||
"alreadyLastDir": "已經是最上層目錄了",
|
"alreadyLastDir": "已經是最上層目錄了",
|
||||||
"alterHost": "備選主機",
|
"alterUrl": "備選鏈接",
|
||||||
"attention": "注意",
|
"attention": "注意",
|
||||||
"auto": "自動",
|
"auto": "自動",
|
||||||
"autoUpdateHomeWidget": "自動更新桌面小部件",
|
"autoUpdateHomeWidget": "自動更新桌面小部件",
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ class ServerEditPage extends StatefulWidget {
|
|||||||
class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||||
final _nameController = TextEditingController();
|
final _nameController = TextEditingController();
|
||||||
final _ipController = TextEditingController();
|
final _ipController = TextEditingController();
|
||||||
final _alterHostController = TextEditingController();
|
final _alterUrlController = TextEditingController();
|
||||||
final _portController = TextEditingController();
|
final _portController = TextEditingController();
|
||||||
final _usernameController = TextEditingController();
|
final _usernameController = TextEditingController();
|
||||||
final _passwordController = TextEditingController();
|
final _passwordController = TextEditingController();
|
||||||
final _nameFocus = FocusNode();
|
final _nameFocus = FocusNode();
|
||||||
final _ipFocus = FocusNode();
|
final _ipFocus = FocusNode();
|
||||||
final _alterHostFocus = FocusNode();
|
final _alterUrlFocus = FocusNode();
|
||||||
final _portFocus = FocusNode();
|
final _portFocus = FocusNode();
|
||||||
final _usernameFocus = FocusNode();
|
final _usernameFocus = FocusNode();
|
||||||
|
|
||||||
@@ -120,20 +120,12 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
Input(
|
Input(
|
||||||
controller: _ipController,
|
controller: _ipController,
|
||||||
type: TextInputType.text,
|
type: TextInputType.text,
|
||||||
onSubmitted: (_) => _focusScope.requestFocus(_alterHostFocus),
|
onSubmitted: (_) => _focusScope.requestFocus(_portFocus),
|
||||||
node: _ipFocus,
|
node: _ipFocus,
|
||||||
label: _s.host,
|
label: _s.host,
|
||||||
icon: Icons.computer,
|
icon: Icons.computer,
|
||||||
hint: 'example.com',
|
hint: 'example.com',
|
||||||
),
|
),
|
||||||
Input(
|
|
||||||
controller: _alterHostController,
|
|
||||||
type: TextInputType.text,
|
|
||||||
node: _alterHostFocus,
|
|
||||||
onSubmitted: (_) => _focusScope.requestFocus(_portFocus),
|
|
||||||
label: _s.alterHost,
|
|
||||||
icon: Icons.computer,
|
|
||||||
),
|
|
||||||
Input(
|
Input(
|
||||||
controller: _portController,
|
controller: _portController,
|
||||||
type: TextInputType.number,
|
type: TextInputType.number,
|
||||||
@@ -147,10 +139,19 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
controller: _usernameController,
|
controller: _usernameController,
|
||||||
type: TextInputType.text,
|
type: TextInputType.text,
|
||||||
node: _usernameFocus,
|
node: _usernameFocus,
|
||||||
|
onSubmitted: (_) => _focusScope.requestFocus(_alterUrlFocus),
|
||||||
label: _s.user,
|
label: _s.user,
|
||||||
icon: Icons.account_box,
|
icon: Icons.account_box,
|
||||||
hint: 'root',
|
hint: 'root',
|
||||||
),
|
),
|
||||||
|
Input(
|
||||||
|
controller: _alterUrlController,
|
||||||
|
type: TextInputType.text,
|
||||||
|
node: _alterUrlFocus,
|
||||||
|
label: _s.alterUrl,
|
||||||
|
icon: Icons.computer,
|
||||||
|
hint: 'user@ip:port',
|
||||||
|
),
|
||||||
TagEditor(
|
TagEditor(
|
||||||
tags: _tags,
|
tags: _tags,
|
||||||
onChanged: (p0) => setState(() {
|
onChanged: (p0) => setState(() {
|
||||||
@@ -290,9 +291,9 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
pwd: authorization,
|
pwd: authorization,
|
||||||
pubKeyId: usePublicKey ? _keyInfo!.id : null,
|
pubKeyId: usePublicKey ? _keyInfo!.id : null,
|
||||||
tags: _tags,
|
tags: _tags,
|
||||||
alterHost: _alterHostController.text == ''
|
alterUrl: _alterUrlController.text == ''
|
||||||
? null
|
? null
|
||||||
: _alterHostController.text,
|
: _alterUrlController.text,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (widget.spi == null) {
|
if (widget.spi == null) {
|
||||||
@@ -334,7 +335,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
if (widget.spi?.tags != null) {
|
if (widget.spi?.tags != null) {
|
||||||
_tags = widget.spi!.tags!;
|
_tags = widget.spi!.tags!;
|
||||||
}
|
}
|
||||||
_alterHostController.text = widget.spi?.alterHost ?? '';
|
_alterUrlController.text = widget.spi?.alterUrl ?? '';
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user