opt. for ssh

This commit is contained in:
lollipopkit
2023-01-29 00:09:20 +08:00
parent e6458a1d7f
commit 923667d57c
7 changed files with 39 additions and 49 deletions

View File

@@ -34,11 +34,14 @@ Especially thanks to <a href="https://github.com/TerminalStudio/dartssh2">dartss
<img width="200px" src="screenshots/server.jpg">
</td>
<td>
<img width="200px" src="screenshots/server_detail.png">
<img width="200px" src="screenshots/detail.jpg">
</td>
<td>
<img width="200px" src="screenshots/ssh.jpg">
</td>
<td>
<img width="200px" src="screenshots/apt.png">
</td>
</tr>
</table>
<table>
@@ -52,6 +55,9 @@ Especially thanks to <a href="https://github.com/TerminalStudio/dartssh2">dartss
<td>
<img width="200px" src="screenshots/docker.jpg">
</td>
<td>
<img width="200px" src="screenshots/convert.png">
</td>
</tr>
</table>

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 191;
static const int build = 193;
static const String engine =
"Flutter 3.7.0 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision b06b8b2710 (5 days ago) • 2023-01-23 16:55:55 -0800\nEngine • revision b24591ed32\nTools • Dart 2.19.0 • DevTools 2.20.1\n";
static const String buildAt = "2023-01-28 22:51:04.087758";
static const int modifications = 3;
static const String buildAt = "2023-01-28 23:51:19.423469";
static const int modifications = 2;
}

View File

@@ -177,15 +177,6 @@ class _PkgManagePageState extends State<PkgManagePage>
return ListView(
padding: const EdgeInsets.all(13),
children: [
Padding(
padding: const EdgeInsets.all(17),
child: UrlText(
text:
'${_s.experimentalFeature}\n${_s.reportBugsOnGithubIssue(issueUrl)}',
replace: 'Github Issue',
textAlign: TextAlign.center,
),
),
_buildUpdatePanel(apt)
].map((e) => RoundRectCard(e)).toList(),
);
@@ -203,10 +194,7 @@ class _PkgManagePageState extends State<PkgManagePage>
subtitle: const Text('>_<', textAlign: TextAlign.center),
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ExpansionTile(
return ExpansionTile(
title: Text(_s.foundNUpdate(apt.upgradeable!.length)),
subtitle: Text(
apt.upgradeable!.map((e) => e.package).join(', '),
@@ -221,32 +209,18 @@ class _PkgManagePageState extends State<PkgManagePage>
onPressed: () {
apt.upgrade();
}),
SizedBox(
height: _media.size.height * 0.73,
child: ListView(
controller: _scrollController,
children: apt.upgradeable!
...apt.upgradeable!
.map((e) => _buildUpdateItem(e, apt))
.toList(),
),
)
.toList()
]
: [
SizedBox(
height: _media.size.height * 0.7,
child: ConstrainedBox(
constraints: const BoxConstraints.expand(),
child: SingleChildScrollView(
SingleChildScrollView(
padding: const EdgeInsets.all(18),
controller: _scrollController,
child: Text(apt.upgradeLog!),
),
),
)
)
],
)
],
);
);
}
Widget _buildUpdateItem(UpgradePkgInfo info, PkgProvider apt) {

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:dartssh2/dartssh2.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:toolbox/data/store/setting.dart';
@@ -11,6 +12,7 @@ import '../../core/utils.dart';
import '../../data/model/server/server_private_info.dart';
import '../../data/provider/server.dart';
import '../../data/res/terminal_theme.dart';
import '../../data/store/private_key.dart';
import '../../locator.dart';
class SSHPage extends StatefulWidget {
@@ -23,7 +25,7 @@ class SSHPage extends StatefulWidget {
class _SSHPageState extends State<SSHPage> {
late final terminal = Terminal(inputHandler: keyboard);
late final SSHSession session;
late final SSHClient client;
final keyboard = VirtualKeyboard(defaultInputHandler);
late double _screenWidth;
@@ -44,23 +46,14 @@ class _SSHPageState extends State<SSHPage> {
@override
void dispose() {
session.close();
client.close();
super.dispose();
}
Future<void> initTerminal() async {
terminal.write('Connecting...\r\n');
final client = locator<ServerProvider>()
.servers
.where((e) => e.spi.id == widget.spi.id)
.first
.client;
if (client == null) {
terminal.write('Failed to connect\r\n');
return;
}
client = await genClient(widget.spi);
terminal.write('Connected\r\n');
final wxh = locator<SettingStore>().sshTermSize.fetch()!;
@@ -69,7 +62,7 @@ class _SSHPageState extends State<SSHPage> {
final h = int.parse(split.last);
terminal.resize(w, h);
session = await client.shell(
final session = await client.shell(
pty: SSHPtyConfig(
width: terminal.viewWidth,
height: terminal.viewHeight,
@@ -191,6 +184,23 @@ class _SSHPageState extends State<SSHPage> {
}
}
Future<SSHClient> genClient(ServerPrivateInfo spi) async {
final socket = await SSHSocket.connect(spi.ip, spi.port);
if (spi.pubKeyId == null) {
return SSHClient(
socket,
username: spi.user,
onPasswordRequest: () => spi.pwd,
);
}
final key = locator<PrivateKeyStore>().get(spi.pubKeyId!);
return SSHClient(
socket,
username: spi.user,
identities: await compute(loadIndentity, key.privateKey),
);
}
class VirtualKey {
final TerminalKey key;
final String text;

BIN
screenshots/detail.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 KiB

After

Width:  |  Height:  |  Size: 224 KiB