From 6c51928b98dbd616ec460cc76028089bcfa28b11 Mon Sep 17 00:00:00 2001 From: lemoer Date: Sun, 6 Jul 2025 00:26:40 +0200 Subject: [PATCH] Add real ssh actions and host --- app/lib/main.dart | 94 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 13 deletions(-) diff --git a/app/lib/main.dart b/app/lib/main.dart index 4b49af2..e54f657 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -100,27 +100,31 @@ class _MyHomePageState extends State { String _output = ''; String key = ''; - Future doSSH() async { + Future 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 { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - 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 { ), ); - 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 { ); 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;