opt.: alterUrl (#550)

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-08-25 22:52:47 +08:00
parent bcbf1fbc17
commit 931c5f0bf6
2 changed files with 15 additions and 8 deletions

View File

@@ -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<SSHClient> genClient(
}) async {
onStatus?.call(GenSSHClientStatus.socket);
String? alterUser;
final socket = await () async {
// Proxy
final jumpSpi_ = () {
@@ -90,16 +93,19 @@ Future<SSHClient> 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<SSHClient> genClient(
onStatus?.call(GenSSHClientStatus.pwd);
return SSHClient(
socket,
username: spi.user,
username: alterUser ?? spi.user,
onPasswordRequest: () => spi.pwd,
onUserInfoRequest: onKeyboardInteractive,
// printDebug: debugPrint,

View File

@@ -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(