opt.: sftp home & back (#533)

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-08-14 19:01:44 +08:00
committed by GitHub
parent 41e3fcb23a
commit 267b0b0a69
59 changed files with 466 additions and 477 deletions

View File

@@ -1,7 +1,7 @@
import 'package:server_box/core/extension/context/locale.dart';
import '../../res/build_data.dart';
import '../server/system.dart';
import 'package:server_box/data/res/build_data.dart';
import 'package:server_box/data/model/server/system.dart';
enum ShellFunc {
status,
@@ -47,11 +47,11 @@ enum ShellFunc {
static String getInstallShellCmd(String id) {
final scriptDir = getScriptDir(id);
final scriptPath = '$scriptDir/$scriptFile';
return """
return '''
mkdir -p $scriptDir
cat > $scriptPath
chmod 744 $scriptPath
""";
''';
}
String get flag => switch (this) {

View File

@@ -45,21 +45,21 @@ final class PodmanImg implements ContainerImg {
String toRawJson() => json.encode(toJson());
factory PodmanImg.fromJson(Map<String, dynamic> json) => PodmanImg(
repository: json["repository"],
tag: json["tag"],
id: json["Id"],
created: json["Created"],
size: json["Size"],
containers: json["Containers"],
repository: json['repository'],
tag: json['tag'],
id: json['Id'],
created: json['Created'],
size: json['Size'],
containers: json['Containers'],
);
Map<String, dynamic> toJson() => {
"repository": repository,
"tag": tag,
"Id": id,
"Created": created,
"Size": size,
"Containers": containers,
'repository': repository,
'tag': tag,
'Id': id,
'Created': created,
'Size': size,
'Containers': containers,
};
}
@@ -96,36 +96,36 @@ final class DockerImg implements ContainerImg {
String toRawJson() => json.encode(toJson());
factory DockerImg.fromJson(Map<String, dynamic> json) {
final containers = switch (json["Containers"]) {
final containers = switch (json['Containers']) {
final String a => a,
final Object? a => a.toString(),
};
final repo = switch (json["Repository"] ?? json["Names"]) {
final repo = switch (json['Repository'] ?? json['Names']) {
final String a => a,
final List a => a.firstOrNull.toString(),
final Object? a => a.toString(),
};
final size = switch (json["Size"]) {
final size = switch (json['Size']) {
final String a => a,
final int a => a.bytes2Str,
final Object? a => a.toString(),
};
return DockerImg(
containers: containers,
createdAt: json["CreatedAt"],
id: json["ID"] ?? json["Id"] ?? '',
createdAt: json['CreatedAt'],
id: json['ID'] ?? json['Id'] ?? '',
repository: repo,
size: size,
tag: json["Tag"],
tag: json['Tag'],
);
}
Map<String, dynamic> toJson() => {
"Containers": containers,
"CreatedAt": createdAt,
"ID": id,
"Repository": repository,
"Size": size,
"Tag": tag,
'Containers': containers,
'CreatedAt': createdAt,
'ID': id,
'Repository': repository,
'Size': size,
'Tag': tag,
};
}

View File

@@ -84,29 +84,29 @@ final class PodmanPs implements ContainerPs {
String toRawJson() => json.encode(toJson());
factory PodmanPs.fromJson(Map<String, dynamic> json) => PodmanPs(
command: json["Command"] == null
command: json['Command'] == null
? []
: List<String>.from(json["Command"]!.map((x) => x)),
: List<String>.from(json['Command']!.map((x) => x)),
created:
json["Created"] == null ? null : DateTime.parse(json["Created"]),
exited: json["Exited"],
id: json["Id"],
image: json["Image"],
names: json["Names"] == null
json['Created'] == null ? null : DateTime.parse(json['Created']),
exited: json['Exited'],
id: json['Id'],
image: json['Image'],
names: json['Names'] == null
? []
: List<String>.from(json["Names"]!.map((x) => x)),
startedAt: json["StartedAt"],
: List<String>.from(json['Names']!.map((x) => x)),
startedAt: json['StartedAt'],
);
Map<String, dynamic> toJson() => {
"Command":
'Command':
command == null ? [] : List<dynamic>.from(command!.map((x) => x)),
"Created": created?.toIso8601String(),
"Exited": exited,
"Id": id,
"Image": image,
"Names": names == null ? [] : List<dynamic>.from(names!.map((x) => x)),
"StartedAt": startedAt,
'Created': created?.toIso8601String(),
'Exited': exited,
'Id': id,
'Image': image,
'Names': names == null ? [] : List<dynamic>.from(names!.map((x) => x)),
'StartedAt': startedAt,
};
}

View File

@@ -34,9 +34,9 @@ class UpgradePkgInfo {
}
void _parseApt(String raw) {
final split1 = raw.split("/");
final split1 = raw.split('/');
package = split1[0];
final split2 = split1[1].split(" ");
final split2 = split1[1].split(' ');
newVersion = split2[1];
arch = split2[2];
nowVersion = split2[5].replaceFirst(']', '');
@@ -53,7 +53,7 @@ class UpgradePkgInfo {
}
void _parseZypper(String raw) {
final cols = raw.split("|");
final cols = raw.split('|');
package = cols[2].trim();
nowVersion = cols[3].trim();
newVersion = cols[4].trim();

View File

@@ -1,4 +1,4 @@
import '../../res/misc.dart';
import 'package:server_box/data/res/misc.dart';
class Conn {
final int maxConn;

View File

@@ -30,11 +30,11 @@ final class ServerCustom {
static ServerCustom fromJson(Map<String, dynamic> json) {
//final temperature = json["temperature"] as String?;
final pveAddr = json["pveAddr"] as String?;
final pveIgnoreCert = json["pveIgnoreCert"] as bool;
final cmds = json["cmds"] as Map<String, dynamic>?;
final preferTempDev = json["preferTempDev"] as String?;
final logoUrl = json["logoUrl"] as String?;
final pveAddr = json['pveAddr'] as String?;
final pveIgnoreCert = json['pveIgnoreCert'] as bool;
final cmds = json['cmds'] as Map<String, dynamic>?;
final preferTempDev = json['preferTempDev'] as String?;
final logoUrl = json['logoUrl'] as String?;
return ServerCustom(
//temperature: temperature,
pveAddr: pveAddr,
@@ -51,18 +51,18 @@ final class ServerCustom {
// json["temperature"] = temperature;
// }
if (pveAddr != null) {
json["pveAddr"] = pveAddr;
json['pveAddr'] = pveAddr;
}
json["pveIgnoreCert"] = pveIgnoreCert;
json['pveIgnoreCert'] = pveIgnoreCert;
if (cmds != null) {
json["cmds"] = cmds;
json['cmds'] = cmds;
}
if (preferTempDev != null) {
json["preferTempDev"] = preferTempDev;
json['preferTempDev'] = preferTempDev;
}
if (logoUrl != null) {
json["logoUrl"] = logoUrl;
json['logoUrl'] = logoUrl;
}
return json;
}

View File

@@ -1,7 +1,7 @@
import 'package:fl_lib/fl_lib.dart';
import 'package:server_box/data/model/server/time_seq.dart';
import '../../res/misc.dart';
import 'package:server_box/data/res/misc.dart';
class Disk {
final String fs;

View File

@@ -1,6 +1,6 @@
import 'package:fl_lib/fl_lib.dart';
import 'time_seq.dart';
import 'package:server_box/data/model/server/time_seq.dart';
class NetSpeedPart extends TimeSeqIface<NetSpeedPart> {
final String device;

View File

@@ -28,13 +28,13 @@ class PrivateKeyInfo {
}
PrivateKeyInfo.fromJson(Map<String, dynamic> json)
: id = json["id"].toString(),
key = json["private_key"].toString();
: id = json['id'].toString(),
key = json['private_key'].toString();
Map<String, dynamic> toJson() {
final data = <String, String>{};
data["id"] = id;
data["private_key"] = key;
data['id'] = id;
data['private_key'] = key;
return data;
}
}

View File

@@ -1,6 +1,6 @@
import 'package:fl_lib/fl_lib.dart';
import '../../../data/res/misc.dart';
import 'package:server_box/data/res/misc.dart';
class _ProcValIdxMap {
final int pid;
@@ -58,7 +58,7 @@ class Proc {
required this.command,
});
factory Proc.parse(String raw, _ProcValIdxMap map) {
factory Proc._parse(String raw, _ProcValIdxMap map) {
final parts = raw.split(RegExp(r'\s+'));
return Proc(
user: map.user == null ? null : parts[map.user!],
@@ -139,7 +139,7 @@ class PsResult {
final line = lines[i];
if (line.isEmpty) continue;
try {
procs.add(Proc.parse(line, map));
procs.add(Proc._parse(line, map));
} catch (e, trace) {
errs.add('$line: $e');
Loggers.app.warning('Process failed', e, trace);

View File

@@ -90,5 +90,5 @@ enum ServerConn {
/// Status parsing finished
finished;
operator <(ServerConn other) => index < other.index;
bool operator <(ServerConn other) => index < other.index;
}

View File

@@ -6,7 +6,7 @@ import 'package:server_box/data/model/server/server.dart';
import 'package:server_box/data/model/server/wol_cfg.dart';
import 'package:server_box/data/res/provider.dart';
import '../app/error.dart';
import 'package:server_box/data/model/app/error.dart';
part 'server_private_info.g.dart';
@@ -67,23 +67,23 @@ class ServerPrivateInfo {
}) : id = '$user@$ip:$port';
static ServerPrivateInfo fromJson(Map<String, dynamic> json) {
final ip = json["ip"] as String? ?? '';
final port = json["port"] as int? ?? 22;
final user = json["user"] as String? ?? 'root';
final name = json["name"] as String? ?? '';
final pwd = json["pwd"] as String? ?? json["authorization"] as String?;
final keyId = json["pubKeyId"] as String?;
final tags = (json["tags"] as List?)?.cast<String>();
final alterUrl = json["alterUrl"] as String?;
final autoConnect = json["autoConnect"] as bool?;
final jumpId = json["jumpId"] as String?;
final custom = json["customCmd"] == null
final ip = json['ip'] as String? ?? '';
final port = json['port'] as int? ?? 22;
final user = json['user'] as String? ?? 'root';
final name = json['name'] as String? ?? '';
final pwd = json['pwd'] as String? ?? json['authorization'] as String?;
final keyId = json['pubKeyId'] as String?;
final tags = (json['tags'] as List?)?.cast<String>();
final alterUrl = json['alterUrl'] as String?;
final autoConnect = json['autoConnect'] as bool?;
final jumpId = json['jumpId'] as String?;
final custom = json['customCmd'] == null
? null
: ServerCustom.fromJson(json["custom"].cast<String, dynamic>());
final wolCfg = json["wolCfg"] == null
: ServerCustom.fromJson(json['custom'].cast<String, dynamic>());
final wolCfg = json['wolCfg'] == null
? null
: WakeOnLanCfg.fromJson(json["wolCfg"].cast<String, dynamic>());
final envs_ = json["envs"] as Map<String, dynamic>?;
: WakeOnLanCfg.fromJson(json['wolCfg'].cast<String, dynamic>());
final envs_ = json['envs'] as Map<String, dynamic>?;
final envs = <String, String>{};
if (envs_ != null) {
envs_.forEach((key, value) {
@@ -112,36 +112,36 @@ class ServerPrivateInfo {
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data["name"] = name;
data["ip"] = ip;
data["port"] = port;
data["user"] = user;
data['name'] = name;
data['ip'] = ip;
data['port'] = port;
data['user'] = user;
if (pwd != null) {
data["pwd"] = pwd;
data['pwd'] = pwd;
}
if (keyId != null) {
data["pubKeyId"] = keyId;
data['pubKeyId'] = keyId;
}
if (tags != null) {
data["tags"] = tags;
data['tags'] = tags;
}
if (alterUrl != null) {
data["alterUrl"] = alterUrl;
data['alterUrl'] = alterUrl;
}
if (autoConnect != null) {
data["autoConnect"] = autoConnect;
data['autoConnect'] = autoConnect;
}
if (jumpId != null) {
data["jumpId"] = jumpId;
data['jumpId'] = jumpId;
}
if (custom != null) {
data["custom"] = custom?.toJson();
data['custom'] = custom?.toJson();
}
if (wolCfg != null) {
data["wolCfg"] = wolCfg?.toJson();
data['wolCfg'] = wolCfg?.toJson();
}
if (envs != null) {
data["envs"] = envs;
data['envs'] = envs;
}
return data;
}
@@ -160,7 +160,7 @@ class ServerPrivateInfo {
custom?.cmds != old.custom?.cmds;
}
_IpPort fromStringUrl() {
IpPort fromStringUrl() {
if (alterUrl == null) {
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl is null');
}
@@ -177,7 +177,7 @@ class ServerPrivateInfo {
if (port <= 0 || port > 65535) {
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl port error');
}
return _IpPort(ip_, port_);
return IpPort(ip_, port_);
}
@override
@@ -208,9 +208,9 @@ class ServerPrivateInfo {
);
}
class _IpPort {
class IpPort {
final String ip;
final int port;
_IpPort(this.ip, this.port);
IpPort(this.ip, this.port);
}

View File

@@ -5,12 +5,12 @@ import 'package:server_box/data/model/server/sensors.dart';
import 'package:server_box/data/model/server/server.dart';
import 'package:server_box/data/model/server/system.dart';
import '../app/shell_func.dart';
import 'cpu.dart';
import 'disk.dart';
import 'memory.dart';
import 'net_speed.dart';
import 'conn.dart';
import 'package:server_box/data/model/app/shell_func.dart';
import 'package:server_box/data/model/server/cpu.dart';
import 'package:server_box/data/model/server/disk.dart';
import 'package:server_box/data/model/server/memory.dart';
import 'package:server_box/data/model/server/net_speed.dart';
import 'package:server_box/data/model/server/conn.dart';
class ServerStatusUpdateReq {
final ServerStatus ss;

View File

@@ -5,7 +5,7 @@ import 'package:hive_flutter/hive_flutter.dart';
import 'package:server_box/data/model/server/server_private_info.dart';
import 'package:xterm/core.dart';
import '../app/tag_pickable.dart';
import 'package:server_box/data/model/app/tag_pickable.dart';
part 'snippet.g.dart';

View File

@@ -2,12 +2,14 @@ import 'package:fl_lib/fl_lib.dart';
class AbsolutePath {
String _path;
final _prePath = <String>[];
AbsolutePath(this._path);
String get path => _path;
final List<String> _prePath;
AbsolutePath(this._path) : _prePath = ['/'];
void update(String newPath) {
/// Update path, not set path
set path(String newPath) {
_prePath.add(_path);
if (newPath == '..') {
_path = _path.substring(0, _path.lastIndexOf('/'));
@@ -16,10 +18,6 @@ class AbsolutePath {
}
return;
}
if (newPath == '/') {
_path = '/';
return;
}
if (newPath.startsWith('/')) {
_path = newPath;
return;

View File

@@ -2,9 +2,11 @@ import 'package:dartssh2/dartssh2.dart';
import 'package:server_box/data/model/sftp/absolute_path.dart';
class SftpBrowserStatus {
List<SftpName>? files;
AbsolutePath? path;
final List<SftpName> files = [];
final AbsolutePath path = AbsolutePath('/');
SftpClient? client;
SftpBrowserStatus();
SftpBrowserStatus(SSHClient client) {
client.sftp().then((value) => this.client = value);
}
}

View File

@@ -70,7 +70,7 @@ class ContainerProvider extends ChangeNotifier {
}
final res = await client?.run(_wrap(ContainerCmdType.images.exec(type)));
if (res?.string.toLowerCase().contains("permission denied") ?? false) {
if (res?.string.toLowerCase().contains('permission denied') ?? false) {
return sudoCompleter.complete(true);
}
return sudoCompleter.complete(false);

View File

@@ -104,7 +104,7 @@ final class PveProvider extends ChangeNotifier {
socket.cast<List<int>>().pipe(forward.sink);
});*/
if (url.isScheme("https")) {
if (url.isScheme('https')) {
return SecureSocket.startConnect('localhost', _localPort,
onBadCertificate: (_) => true);
} else {

View File

@@ -14,12 +14,12 @@ import 'package:server_box/data/model/server/system.dart';
// import 'package:server_box/data/res/provider.dart';
import 'package:server_box/data/res/store.dart';
import '../../core/utils/server.dart';
import '../model/server/server.dart';
import '../model/server/server_private_info.dart';
import '../model/server/server_status_update_req.dart';
import '../model/server/try_limiter.dart';
import '../res/status.dart';
import 'package:server_box/core/utils/server.dart';
import 'package:server_box/data/model/server/server.dart';
import 'package:server_box/data/model/server/server_private_info.dart';
import 'package:server_box/data/model/server/server_status_update_req.dart';
import 'package:server_box/data/model/server/try_limiter.dart';
import 'package:server_box/data/res/status.dart';
class ServerProvider extends ChangeNotifier {
final Map<String, Server> _servers = {};

View File

@@ -1,7 +1,7 @@
// This file is generated by fl_build. Do not edit.
class BuildData {
static const String name = "ServerBox";
static const String name = 'ServerBox';
static const int build = 1058;
static const int script = 56;
}

View File

@@ -1,12 +1,12 @@
import 'package:server_box/data/model/server/server.dart';
import 'package:server_box/data/model/server/temp.dart';
import '../model/server/cpu.dart';
import '../model/server/disk.dart';
import '../model/server/memory.dart';
import '../model/server/net_speed.dart';
import '../model/server/conn.dart';
import '../model/server/system.dart';
import 'package:server_box/data/model/server/cpu.dart';
import 'package:server_box/data/model/server/disk.dart';
import 'package:server_box/data/model/server/memory.dart';
import 'package:server_box/data/model/server/net_speed.dart';
import 'package:server_box/data/model/server/conn.dart';
import 'package:server_box/data/model/server/system.dart';
abstract final class InitStatus {
static SingleCpuCore get _initOneTimeCpuStatus => SingleCpuCore(

View File

@@ -1,6 +1,6 @@
import 'package:fl_lib/fl_lib.dart';
import '../model/server/private_key_info.dart';
import 'package:server_box/data/model/server/private_key_info.dart';
class PrivateKeyStore extends PersistentStore {
PrivateKeyStore() : super('key');

View File

@@ -1,6 +1,6 @@
import 'package:fl_lib/fl_lib.dart';
import '../model/server/server_private_info.dart';
import 'package:server_box/data/model/server/server_private_info.dart';
class ServerStore extends PersistentStore {
ServerStore() : super('server');

View File

@@ -3,8 +3,8 @@ import 'package:server_box/data/model/app/menu/server_func.dart';
import 'package:server_box/data/model/app/server_detail_card.dart';
import 'package:server_box/data/model/ssh/virtual_key.dart';
import '../model/app/net_view.dart';
import '../res/default.dart';
import 'package:server_box/data/model/app/net_view.dart';
import 'package:server_box/data/res/default.dart';
class SettingStore extends PersistentStore {
SettingStore() : super('setting');

View File

@@ -1,6 +1,6 @@
import 'package:fl_lib/fl_lib.dart';
import '../model/server/snippet.dart';
import 'package:server_box/data/model/server/snippet.dart';
class SnippetStore extends PersistentStore {
SnippetStore() : super('snippet');