mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 15:54:35 +01:00
fix: ssh alter url (#554)
This commit is contained in:
@@ -23,7 +23,6 @@ import 'package:server_box/view/page/storage/local.dart';
|
||||
import 'package:server_box/data/model/server/snippet.dart';
|
||||
import 'package:server_box/view/page/editor.dart';
|
||||
import 'package:server_box/view/page/process.dart';
|
||||
import 'package:server_box/view/page/server/edit.dart';
|
||||
import 'package:server_box/view/page/server/tab.dart';
|
||||
import 'package:server_box/view/page/setting/entry.dart';
|
||||
import 'package:server_box/view/page/setting/seq/srv_detail_seq.dart';
|
||||
@@ -66,13 +65,6 @@ class AppRoutes {
|
||||
return AppRoutes(ServerPage(key: key), 'server_tab');
|
||||
}
|
||||
|
||||
static AppRoutes serverEdit({Key? key, Spi? spi}) {
|
||||
return AppRoutes(
|
||||
ServerEditPage(spi: spi),
|
||||
'server_${spi == null ? 'add' : 'edit'}',
|
||||
);
|
||||
}
|
||||
|
||||
static AppRoutes keyEdit({Key? key, PrivateKeyInfo? pki}) {
|
||||
return AppRoutes(
|
||||
PrivateKeyEditPage(pki: pki),
|
||||
|
||||
@@ -93,8 +93,8 @@ Future<SSHClient> genClient(
|
||||
spi.port,
|
||||
timeout: timeout,
|
||||
);
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('genClient', e, s);
|
||||
} catch (e) {
|
||||
Loggers.app.warning('genClient', e);
|
||||
if (spi.alterUrl == null) rethrow;
|
||||
try {
|
||||
final res = spi.fromStringUrl();
|
||||
@@ -104,8 +104,8 @@ Future<SSHClient> genClient(
|
||||
res.$3,
|
||||
timeout: timeout,
|
||||
);
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('genClient alterUrl', e, s);
|
||||
} catch (e) {
|
||||
Loggers.app.warning('genClient alterUrl', e);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,13 +107,13 @@ extension Spix on Spi {
|
||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no @');
|
||||
}
|
||||
final usr = splited[0];
|
||||
final splited2 = splited[1].split(':');
|
||||
if (splited2.length != 2) {
|
||||
final idx = splited[1].lastIndexOf(':');
|
||||
if (idx == -1) {
|
||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no :');
|
||||
}
|
||||
final ip_ = splited2[0];
|
||||
final port_ = int.tryParse(splited2[1]) ?? 22;
|
||||
if (port <= 0 || port > 65535) {
|
||||
final ip_ = splited[1].substring(0, idx);
|
||||
final port_ = int.tryParse(splited[1].substring(idx + 1));
|
||||
if (port_ == null || port_ <= 0 || port_ > 65535) {
|
||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl port error');
|
||||
}
|
||||
return (ip_, usr, port_);
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 1070;
|
||||
static const int build = 1076;
|
||||
static const int script = 58;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import 'package:server_box/data/model/server/sensors.dart';
|
||||
import 'package:server_box/data/model/server/server_private_info.dart';
|
||||
import 'package:server_box/data/model/server/system.dart';
|
||||
import 'package:server_box/data/res/store.dart';
|
||||
import 'package:server_box/view/page/server/edit.dart';
|
||||
import 'package:server_box/view/widget/server_func_btns.dart';
|
||||
|
||||
import 'package:server_box/core/route.dart';
|
||||
@@ -125,7 +126,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
onPressed: () async {
|
||||
final delete = await AppRoutes.serverEdit(spi: si.spi).go(context);
|
||||
final delete = await ServerEditPage.route.go(context, args: si.spi);
|
||||
if (delete == true) {
|
||||
context.pop();
|
||||
}
|
||||
|
||||
@@ -15,15 +15,21 @@ import 'package:server_box/data/model/server/server_private_info.dart';
|
||||
import 'package:server_box/data/provider/private_key.dart';
|
||||
|
||||
class ServerEditPage extends StatefulWidget {
|
||||
const ServerEditPage({super.key, this.spi});
|
||||
final Spi? args;
|
||||
|
||||
final Spi? spi;
|
||||
const ServerEditPage({super.key, this.args});
|
||||
|
||||
static const route = AppRoute<bool, Spi>(
|
||||
page: ServerEditPage.new,
|
||||
path: '/server_edit',
|
||||
);
|
||||
|
||||
@override
|
||||
State<ServerEditPage> createState() => _ServerEditPageState();
|
||||
}
|
||||
|
||||
class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
late final spi = widget.args;
|
||||
final _nameController = TextEditingController();
|
||||
final _ipController = TextEditingController();
|
||||
final _altUrlController = TextEditingController();
|
||||
@@ -47,6 +53,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
|
||||
late FocusScopeNode _focusScope;
|
||||
|
||||
/// -1: non selected, null: password, others: index of private key
|
||||
final _keyIdx = ValueNotifier<int?>(null);
|
||||
final _autoConnect = ValueNotifier(true);
|
||||
final _jumpServer = nvn<String?>();
|
||||
@@ -88,7 +95,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final actions = <Widget>[];
|
||||
if (widget.spi != null) actions.add(_buildDelBtn());
|
||||
if (spi != null) actions.add(_buildDelBtn());
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => _focusScope.unfocus(),
|
||||
@@ -277,7 +284,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
onTap: () async {
|
||||
final res = await KvEditor.route.go(
|
||||
context,
|
||||
args: KvEditorArgs(data: widget.spi?.envs ?? {}),
|
||||
KvEditorArgs(data: spi?.envs ?? {}),
|
||||
);
|
||||
if (res == null) return;
|
||||
_env.value = res;
|
||||
@@ -409,7 +416,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
onTap: () async {
|
||||
final res = await KvEditor.route.go(
|
||||
context,
|
||||
args: KvEditorArgs(data: _customCmds.value),
|
||||
KvEditorArgs(data: _customCmds.value),
|
||||
);
|
||||
if (res == null) return;
|
||||
_customCmds.value = res;
|
||||
@@ -477,7 +484,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
final srvs = ServerProvider.servers.values
|
||||
.map((e) => e.value)
|
||||
.where((e) => e.spi.jumpId == null)
|
||||
.where((e) => e.spi.id != widget.spi?.id)
|
||||
.where((e) => e.spi.id != spi?.id)
|
||||
.toList();
|
||||
final choice = _jumpServer.listenVal(
|
||||
(val) {
|
||||
@@ -602,10 +609,10 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
envs: _env.value.isEmpty ? null : _env.value,
|
||||
);
|
||||
|
||||
if (widget.spi == null) {
|
||||
if (this.spi == null) {
|
||||
ServerProvider.addServer(spi);
|
||||
} else {
|
||||
ServerProvider.updateServer(widget.spi!, spi);
|
||||
ServerProvider.updateServer(this.spi!, spi);
|
||||
}
|
||||
|
||||
context.pop();
|
||||
@@ -613,9 +620,8 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
|
||||
@override
|
||||
void afterFirstLayout(BuildContext context) {
|
||||
final spi = widget.spi;
|
||||
if (spi != null) {
|
||||
_initWithSpi(spi);
|
||||
_initWithSpi(spi!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,7 +634,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
_passwordController.text = spi.pwd ?? '';
|
||||
} else {
|
||||
_keyIdx.value = PrivateKeyProvider.pkis.value.indexWhere(
|
||||
(e) => e.id == widget.spi!.keyId,
|
||||
(e) => e.id == spi.keyId,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -705,15 +711,13 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
onPressed: () {
|
||||
context.showRoundDialog(
|
||||
title: libL10n.attention,
|
||||
child: StatefulBuilder(builder: (ctx, setState) {
|
||||
return Text(libL10n.askContinue(
|
||||
'${libL10n.delete} ${l10n.server}(${widget.spi!.name})',
|
||||
));
|
||||
}),
|
||||
child: Text(libL10n.askContinue(
|
||||
'${libL10n.delete} ${l10n.server}(${spi!.name})',
|
||||
)),
|
||||
actions: Btn.ok(
|
||||
onTap: () async {
|
||||
context.pop();
|
||||
ServerProvider.delServer(widget.spi!.id);
|
||||
ServerProvider.delServer(spi!.id);
|
||||
context.pop(true);
|
||||
},
|
||||
red: true,
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:server_box/core/extension/ssh_client.dart';
|
||||
import 'package:server_box/data/model/app/shell_func.dart';
|
||||
import 'package:server_box/data/model/server/try_limiter.dart';
|
||||
import 'package:server_box/data/res/store.dart';
|
||||
import 'package:server_box/view/page/server/edit.dart';
|
||||
import 'package:server_box/view/widget/percent_circle.dart';
|
||||
|
||||
import 'package:server_box/core/route.dart';
|
||||
@@ -107,7 +108,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
controller: _scrollController,
|
||||
child: FloatingActionButton(
|
||||
heroTag: 'addServer',
|
||||
onPressed: () => AppRoutes.serverEdit().go(context),
|
||||
onPressed: () => ServerEditPage.route.go(context),
|
||||
tooltip: libL10n.add,
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
@@ -259,7 +260,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
if (srv.canViewDetails) {
|
||||
AppRoutes.serverDetail(spi: srv.spi).go(context);
|
||||
} else {
|
||||
AppRoutes.serverEdit(spi: srv.spi).go(context);
|
||||
ServerEditPage.route.go(context, args: srv.spi);
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
@@ -270,7 +271,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
flip: !cardStatus.value.flip,
|
||||
);
|
||||
} else {
|
||||
AppRoutes.serverEdit(spi: srv.spi).go(context);
|
||||
ServerEditPage.route.go(context, args: srv.spi);
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
@@ -384,7 +385,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
textStyle: textStyle,
|
||||
),
|
||||
Btn.column(
|
||||
onTap: () => AppRoutes.serverEdit(spi: srv.spi).go(context),
|
||||
onTap: () => ServerEditPage.route.go(context, args: srv.spi),
|
||||
icon: const Icon(Icons.edit, color: Colors.grey),
|
||||
text: libL10n.edit,
|
||||
textStyle: textStyle,
|
||||
|
||||
@@ -64,7 +64,7 @@ class _AndroidSettingsPageState extends State<AndroidSettingsPage> {
|
||||
}
|
||||
final result = await KvEditor.route.go(
|
||||
context,
|
||||
args: KvEditorArgs(data: data, prefix: 'widget_'),
|
||||
KvEditorArgs(data: data, prefix: 'widget_'),
|
||||
);
|
||||
if (result != null) {
|
||||
_saveWidgetSP(result, data);
|
||||
|
||||
@@ -111,7 +111,7 @@ class _IOSSettingsPageState extends State<IOSSettingsPage> {
|
||||
final urls = Map<String, String>.from(map['urls'] as Map? ?? {});
|
||||
final result = await KvEditor.route.go(
|
||||
context,
|
||||
args: KvEditorArgs(data: urls),
|
||||
KvEditorArgs(data: urls),
|
||||
);
|
||||
if (result == null) return;
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:icons_plus/icons_plus.dart';
|
||||
import 'package:server_box/core/extension/context/locale.dart';
|
||||
import 'package:server_box/core/route.dart';
|
||||
import 'package:server_box/data/model/server/server_private_info.dart';
|
||||
import 'package:server_box/data/provider/server.dart';
|
||||
import 'package:server_box/view/page/server/edit.dart';
|
||||
import 'package:server_box/view/page/ssh/page.dart';
|
||||
|
||||
class SSHTabPage extends StatefulWidget {
|
||||
@@ -48,7 +48,7 @@ class _SSHTabPageState extends State<SSHTabPage>
|
||||
if (idx != 0) return const SizedBox();
|
||||
return FloatingActionButton(
|
||||
heroTag: 'sshAddServer',
|
||||
onPressed: () => AppRoutes.serverEdit().go(context),
|
||||
onPressed: () => ServerEditPage.route.go(context),
|
||||
tooltip: libL10n.add,
|
||||
child: const Icon(Icons.add),
|
||||
);
|
||||
|
||||
@@ -21,7 +21,7 @@ final class SystemdPage extends StatefulWidget {
|
||||
required this.args,
|
||||
});
|
||||
|
||||
static const route = AppRoute<void, SystemdPageArgs>(
|
||||
static const route = AppRouteArg<void, SystemdPageArgs>(
|
||||
page: SystemdPage.new,
|
||||
path: '/systemd',
|
||||
);
|
||||
|
||||
@@ -165,10 +165,7 @@ void _onTapMoreBtns(
|
||||
);
|
||||
break;
|
||||
case ServerFuncBtn.systemd:
|
||||
SystemdPage.route.go(
|
||||
context,
|
||||
args: SystemdPageArgs(spi: spi),
|
||||
);
|
||||
SystemdPage.route.go(context, SystemdPageArgs(spi: spi));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user