Add real ssh actions and host

This commit is contained in:
lemoer 2025-07-06 00:26:40 +02:00
parent d05aede7e7
commit 6c51928b98

View File

@ -100,27 +100,31 @@ class _MyHomePageState extends State<MyHomePage> {
String _output = '';
String key = '';
Future<void> doSSH() async {
Future<void> doSSH(String user) async {
SSHSocket? socket;
print("Connecting to SSH server...");
try {
socket = await SSHSocket.connect(
'192.168.2.123',
'192.168.0.15',
22,
timeout: const Duration(seconds: 0, milliseconds: 500),
);
final client = SSHClient(
socket,
username: 'test',
username: user,
identities: List.of(keyPair != null ? [keyPair!] : []),
);
final uptime = await client.run('uptime');
print(uptime);
setState(() {
_output = utf8.decode(uptime);
});
} catch (e) {
print("Error: $e");
setState(() {
_output = "Error: $e";
});
@ -190,8 +194,78 @@ class _MyHomePageState extends State<MyHomePage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Current output:'),
Text(outputText, style: Theme.of(context).textTheme.headlineMedium),
Padding(
padding: EdgeInsets.all(20),
child: Card(
child: Column(
children: [
Padding(
padding: EdgeInsets.all(20),
child: Text(
"Hauptraum (oben)",
style: TextStyle(fontSize: 25),
),
),
Padding(
padding: EdgeInsets.fromLTRB(20, 0, 20, 20),
child: Wrap(
spacing:
8.0, // horizontaler Abstand zwischen den Elementen
runSpacing: 4.0, // vertikaler Abstand zwischen den Zeilen
children: [
TextButton(
onPressed: () => doSSH("innentuer-open"),
child: const Text('Open Inside Door'),
),
TextButton(
onPressed: () => doSSH("aussentuer-open"),
child: const Text('Open Outdoor'),
),
TextButton(
onPressed: () => doSSH("lab-close"),
child: const Text('Close All Doors'),
),
],
),
),
],
),
),
),
Padding(
padding: EdgeInsets.all(20),
child: Card(
child: Column(
children: [
Padding(
padding: EdgeInsets.all(20),
child: Text(
"Werkstatt (oben)",
style: TextStyle(fontSize: 25),
),
),
Padding(
padding: EdgeInsets.fromLTRB(20, 0, 20, 20),
child: Wrap(
spacing:
8.0, // horizontaler Abstand zwischen den Elementen
runSpacing: 4.0, // vertikaler Abstand zwischen den Zeilen
children: [
TextButton(
onPressed: () => doSSH("werkstatt-open"),
child: const Text('Open'),
),
TextButton(
onPressed: () => doSSH("werkstatt-close"),
child: const Text('Close'),
),
],
),
),
],
),
),
),
],
),
);
@ -240,12 +314,6 @@ class _MyHomePageState extends State<MyHomePage> {
),
);
final actionButtonMain = FloatingActionButton(
onPressed: doSSH,
tooltip: 'Do SSH',
child: const Icon(Icons.computer),
);
final actionButtonInfo = FloatingActionButton(
onPressed: () => obtainKeyPair(regenerate: true),
tooltip: 'Regenerate Key',
@ -253,12 +321,12 @@ class _MyHomePageState extends State<MyHomePage> {
);
var bodyComponent = bodyComponentMain;
var actionButton = actionButtonMain;
Widget? actionButton;
if (navIndex == 0) {
// Main page
bodyComponent = bodyComponentMain;
actionButton = actionButtonMain;
actionButton = null;
} else if (navIndex == 1) {
// Info page
bodyComponent = bodyComponentInfo;