Add real ssh actions and host
This commit is contained in:
parent
d05aede7e7
commit
6c51928b98
@ -100,27 +100,31 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
String _output = '';
|
String _output = '';
|
||||||
String key = '';
|
String key = '';
|
||||||
|
|
||||||
Future<void> doSSH() async {
|
Future<void> doSSH(String user) async {
|
||||||
SSHSocket? socket;
|
SSHSocket? socket;
|
||||||
|
|
||||||
|
print("Connecting to SSH server...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
socket = await SSHSocket.connect(
|
socket = await SSHSocket.connect(
|
||||||
'192.168.2.123',
|
'192.168.0.15',
|
||||||
22,
|
22,
|
||||||
timeout: const Duration(seconds: 0, milliseconds: 500),
|
timeout: const Duration(seconds: 0, milliseconds: 500),
|
||||||
);
|
);
|
||||||
|
|
||||||
final client = SSHClient(
|
final client = SSHClient(
|
||||||
socket,
|
socket,
|
||||||
username: 'test',
|
username: user,
|
||||||
identities: List.of(keyPair != null ? [keyPair!] : []),
|
identities: List.of(keyPair != null ? [keyPair!] : []),
|
||||||
);
|
);
|
||||||
|
|
||||||
final uptime = await client.run('uptime');
|
final uptime = await client.run('uptime');
|
||||||
|
print(uptime);
|
||||||
setState(() {
|
setState(() {
|
||||||
_output = utf8.decode(uptime);
|
_output = utf8.decode(uptime);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
print("Error: $e");
|
||||||
setState(() {
|
setState(() {
|
||||||
_output = "Error: $e";
|
_output = "Error: $e";
|
||||||
});
|
});
|
||||||
@ -190,8 +194,78 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text('Current output:'),
|
Padding(
|
||||||
Text(outputText, style: Theme.of(context).textTheme.headlineMedium),
|
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(
|
final actionButtonInfo = FloatingActionButton(
|
||||||
onPressed: () => obtainKeyPair(regenerate: true),
|
onPressed: () => obtainKeyPair(regenerate: true),
|
||||||
tooltip: 'Regenerate Key',
|
tooltip: 'Regenerate Key',
|
||||||
@ -253,12 +321,12 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var bodyComponent = bodyComponentMain;
|
var bodyComponent = bodyComponentMain;
|
||||||
var actionButton = actionButtonMain;
|
Widget? actionButton;
|
||||||
|
|
||||||
if (navIndex == 0) {
|
if (navIndex == 0) {
|
||||||
// Main page
|
// Main page
|
||||||
bodyComponent = bodyComponentMain;
|
bodyComponent = bodyComponentMain;
|
||||||
actionButton = actionButtonMain;
|
actionButton = null;
|
||||||
} else if (navIndex == 1) {
|
} else if (navIndex == 1) {
|
||||||
// Info page
|
// Info page
|
||||||
bodyComponent = bodyComponentInfo;
|
bodyComponent = bodyComponentInfo;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user