mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
opt.: alterUrl (#550)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:dartssh2/dartssh2.dart';
|
import 'package:dartssh2/dartssh2.dart';
|
||||||
|
import 'package:fl_lib/fl_lib.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:server_box/data/model/app/error.dart';
|
import 'package:server_box/data/model/app/error.dart';
|
||||||
import 'package:server_box/data/res/store.dart';
|
import 'package:server_box/data/res/store.dart';
|
||||||
@@ -62,6 +63,8 @@ Future<SSHClient> genClient(
|
|||||||
}) async {
|
}) async {
|
||||||
onStatus?.call(GenSSHClientStatus.socket);
|
onStatus?.call(GenSSHClientStatus.socket);
|
||||||
|
|
||||||
|
String? alterUser;
|
||||||
|
|
||||||
final socket = await () async {
|
final socket = await () async {
|
||||||
// Proxy
|
// Proxy
|
||||||
final jumpSpi_ = () {
|
final jumpSpi_ = () {
|
||||||
@@ -90,16 +93,19 @@ Future<SSHClient> genClient(
|
|||||||
spi.port,
|
spi.port,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e, s) {
|
||||||
|
Loggers.app.warning('genClient', e, s);
|
||||||
if (spi.alterUrl == null) rethrow;
|
if (spi.alterUrl == null) rethrow;
|
||||||
try {
|
try {
|
||||||
final ipPort = spi.fromStringUrl();
|
final res = spi.fromStringUrl();
|
||||||
|
alterUser = res.$2;
|
||||||
return await SSHSocket.connect(
|
return await SSHSocket.connect(
|
||||||
ipPort.$1,
|
res.$1,
|
||||||
ipPort.$2,
|
res.$3,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e, s) {
|
||||||
|
Loggers.app.warning('genClient alterUrl', e, s);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,7 +116,7 @@ Future<SSHClient> genClient(
|
|||||||
onStatus?.call(GenSSHClientStatus.pwd);
|
onStatus?.call(GenSSHClientStatus.pwd);
|
||||||
return SSHClient(
|
return SSHClient(
|
||||||
socket,
|
socket,
|
||||||
username: spi.user,
|
username: alterUser ?? spi.user,
|
||||||
onPasswordRequest: () => spi.pwd,
|
onPasswordRequest: () => spi.pwd,
|
||||||
onUserInfoRequest: onKeyboardInteractive,
|
onUserInfoRequest: onKeyboardInteractive,
|
||||||
// printDebug: debugPrint,
|
// printDebug: debugPrint,
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ extension Spix on Spi {
|
|||||||
custom?.cmds != old.custom?.cmds;
|
custom?.cmds != old.custom?.cmds;
|
||||||
}
|
}
|
||||||
|
|
||||||
(String, int) fromStringUrl() {
|
(String ip, String usr, int port) fromStringUrl() {
|
||||||
if (alterUrl == null) {
|
if (alterUrl == null) {
|
||||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl is null');
|
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl is null');
|
||||||
}
|
}
|
||||||
@@ -106,6 +106,7 @@ extension Spix on Spi {
|
|||||||
if (splited.length != 2) {
|
if (splited.length != 2) {
|
||||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no @');
|
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no @');
|
||||||
}
|
}
|
||||||
|
final usr = splited[0];
|
||||||
final splited2 = splited[1].split(':');
|
final splited2 = splited[1].split(':');
|
||||||
if (splited2.length != 2) {
|
if (splited2.length != 2) {
|
||||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no :');
|
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no :');
|
||||||
@@ -115,7 +116,7 @@ extension Spix on Spi {
|
|||||||
if (port <= 0 || port > 65535) {
|
if (port <= 0 || port > 65535) {
|
||||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl port error');
|
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl port error');
|
||||||
}
|
}
|
||||||
return (ip_, port_);
|
return (ip_, usr, port_);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const example = Spi(
|
static const example = Spi(
|
||||||
|
|||||||
Reference in New Issue
Block a user