From 931c5f0bf6112989bc2b465ec1db4c5428ba4f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Sun, 25 Aug 2024 22:52:47 +0800 Subject: [PATCH] opt.: alterUrl (#550) --- lib/core/utils/server.dart | 18 ++++++++++++------ lib/data/model/server/server_private_info.dart | 5 +++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/core/utils/server.dart b/lib/core/utils/server.dart index 8d97c14e6..02524c73b 100644 --- a/lib/core/utils/server.dart +++ b/lib/core/utils/server.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:dartssh2/dartssh2.dart'; +import 'package:fl_lib/fl_lib.dart'; import 'package:flutter/foundation.dart'; import 'package:server_box/data/model/app/error.dart'; import 'package:server_box/data/res/store.dart'; @@ -62,6 +63,8 @@ Future genClient( }) async { onStatus?.call(GenSSHClientStatus.socket); + String? alterUser; + final socket = await () async { // Proxy final jumpSpi_ = () { @@ -90,16 +93,19 @@ Future genClient( spi.port, timeout: timeout, ); - } catch (e) { + } catch (e, s) { + Loggers.app.warning('genClient', e, s); if (spi.alterUrl == null) rethrow; try { - final ipPort = spi.fromStringUrl(); + final res = spi.fromStringUrl(); + alterUser = res.$2; return await SSHSocket.connect( - ipPort.$1, - ipPort.$2, + res.$1, + res.$3, timeout: timeout, ); - } catch (e) { + } catch (e, s) { + Loggers.app.warning('genClient alterUrl', e, s); rethrow; } } @@ -110,7 +116,7 @@ Future genClient( onStatus?.call(GenSSHClientStatus.pwd); return SSHClient( socket, - username: spi.user, + username: alterUser ?? spi.user, onPasswordRequest: () => spi.pwd, onUserInfoRequest: onKeyboardInteractive, // printDebug: debugPrint, diff --git a/lib/data/model/server/server_private_info.dart b/lib/data/model/server/server_private_info.dart index df59429e5..2b18f7947 100644 --- a/lib/data/model/server/server_private_info.dart +++ b/lib/data/model/server/server_private_info.dart @@ -98,7 +98,7 @@ extension Spix on Spi { custom?.cmds != old.custom?.cmds; } - (String, int) fromStringUrl() { + (String ip, String usr, int port) fromStringUrl() { if (alterUrl == null) { throw SSHErr(type: SSHErrType.connect, message: 'alterUrl is null'); } @@ -106,6 +106,7 @@ extension Spix on Spi { if (splited.length != 2) { throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no @'); } + final usr = splited[0]; final splited2 = splited[1].split(':'); if (splited2.length != 2) { throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no :'); @@ -115,7 +116,7 @@ extension Spix on Spi { if (port <= 0 || port > 65535) { throw SSHErr(type: SSHErrType.connect, message: 'alterUrl port error'); } - return (ip_, port_); + return (ip_, usr, port_); } static const example = Spi(