Show dialog for ssh output
This commit is contained in:
parent
4a41bad5b6
commit
171831994a
@ -81,12 +81,23 @@ class MyHomePage extends StatefulWidget {
|
|||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
int navIndex = 0;
|
int navIndex = 0;
|
||||||
OpenSSHEd25519KeyPair? keyPair;
|
OpenSSHEd25519KeyPair? keyPair;
|
||||||
String _output = '';
|
String? _output;
|
||||||
|
SSHClient? client;
|
||||||
String key = '';
|
String key = '';
|
||||||
|
|
||||||
Future<void> doSSH(String user) async {
|
Future<void> doSSH(String user) async {
|
||||||
SSHSocket? socket;
|
SSHSocket? socket;
|
||||||
|
|
||||||
|
if (client != null) {
|
||||||
|
// If we already have a client, close it
|
||||||
|
client!.close();
|
||||||
|
client = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_output = null;
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
socket = await SSHSocket.connect(
|
socket = await SSHSocket.connect(
|
||||||
'192.168.0.15',
|
'192.168.0.15',
|
||||||
@ -94,17 +105,48 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
timeout: const Duration(seconds: 0, milliseconds: 500),
|
timeout: const Duration(seconds: 0, milliseconds: 500),
|
||||||
);
|
);
|
||||||
|
|
||||||
final client = SSHClient(
|
client = SSHClient(
|
||||||
socket,
|
socket,
|
||||||
username: user,
|
username: user,
|
||||||
identities: List.of(keyPair != null ? [keyPair!] : []),
|
identities: List.of(keyPair != null ? [keyPair!] : []),
|
||||||
);
|
);
|
||||||
|
|
||||||
final uptime = await client.run('uptime');
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_output = utf8.decode(uptime);
|
_output = 'Connecting to SSH server...\n\n';
|
||||||
|
});
|
||||||
|
|
||||||
|
if (client == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final shell = await client!.shell();
|
||||||
|
|
||||||
|
shell.stdout.listen((data) {
|
||||||
|
setState(() {
|
||||||
|
if (_output == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_output = _output! + utf8.decode(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (client == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await shell.done;
|
||||||
|
|
||||||
|
if (client == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
client!.close();
|
||||||
|
setState(() {
|
||||||
|
_output = null;
|
||||||
});
|
});
|
||||||
} on SSHAuthError catch (_) {
|
} on SSHAuthError catch (_) {
|
||||||
|
setState(() {
|
||||||
|
_output = null;
|
||||||
|
});
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
@ -115,6 +157,9 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} on SocketException catch (_) {
|
} on SocketException catch (_) {
|
||||||
|
setState(() {
|
||||||
|
_output = null;
|
||||||
|
});
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
@ -382,11 +427,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (authentikApiState.isClosed()) {
|
Widget? title;
|
||||||
return mainPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget title;
|
|
||||||
var children = <Widget>[];
|
var children = <Widget>[];
|
||||||
var actions = [
|
var actions = [
|
||||||
TextButton(onPressed: authentikApiState.exit, child: Text("Cancel")),
|
TextButton(onPressed: authentikApiState.exit, child: Text("Cancel")),
|
||||||
@ -394,7 +435,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
|
|
||||||
switch (authentikApiState.status) {
|
switch (authentikApiState.status) {
|
||||||
case AuthentikUserSettingsChangeDialogStatus.closed:
|
case AuthentikUserSettingsChangeDialogStatus.closed:
|
||||||
return mainPage;
|
break;
|
||||||
case AuthentikUserSettingsChangeDialogStatus.waitingForOAuth:
|
case AuthentikUserSettingsChangeDialogStatus.waitingForOAuth:
|
||||||
title = Text("Waiting for OAuth");
|
title = Text("Waiting for OAuth");
|
||||||
children = [Text("Please complete the OAuth flow in your browser.")];
|
children = [Text("Please complete the OAuth flow in your browser.")];
|
||||||
@ -429,6 +470,31 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
children = [Text("Saving...")];
|
children = [Text("Saving...")];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_output != null) {
|
||||||
|
title = Text("SSH Output");
|
||||||
|
children.add(Text(_output!, style: TextStyle(fontSize: 12)));
|
||||||
|
// TODO: fix action.
|
||||||
|
actions = [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_output = null;
|
||||||
|
if (client != null) {
|
||||||
|
client!.close();
|
||||||
|
client = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Text("Cancel"),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (title == null) {
|
||||||
|
// If we have no title, just return the main page
|
||||||
|
return mainPage;
|
||||||
|
}
|
||||||
|
|
||||||
final dialog = AlertDialog(
|
final dialog = AlertDialog(
|
||||||
title: title,
|
title: title,
|
||||||
content: SingleChildScrollView(child: Column(children: children)),
|
content: SingleChildScrollView(child: Column(children: children)),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user