mirror of
https://github.com/MoxiFoxi411/QuickSSH.git
synced 2026-11-08 19:34:55 +00:00
Completed basic functionality
This commit is contained in:
1 parent
922f26310a
commit
78f2dfa742
55 files changed
+1399
-101
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import 'dart:convert';
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:QuickSSH/classes/ServerCommand.dart';
|
||||
|
||||
class SSHService {
|
||||
static Future<String> execute(ServerCommand server) async {
|
||||
try {
|
||||
// 1. Connect to the IP and Port
|
||||
final socket = await SSHSocket.connect(
|
||||
server.ip,
|
||||
22,
|
||||
timeout: const Duration(seconds: 10),
|
||||
);
|
||||
|
||||
// 2. Authenticate
|
||||
final client = SSHClient(
|
||||
socket,
|
||||
username: server.username,
|
||||
onPasswordRequest: () => server.password,
|
||||
);
|
||||
|
||||
// 3. Run the specific command
|
||||
final result = await client.run(server.command);
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
|
||||
// 4. Return the server's response
|
||||
return utf8.decode(result);
|
||||
} catch (e) {
|
||||
return "Error: $e";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'dart:convert';
|
||||
import 'package:QuickSSH/classes/ServerCommand.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
class SecureStorageService {
|
||||
static const _storage = FlutterSecureStorage();
|
||||
static const _key = 'mc_commands_list';
|
||||
|
||||
// SAVE: Converts list to JSON, then encrypts and stores it
|
||||
static Future<void> saveCommands(List<ServerCommand> commands) async {
|
||||
final String jsonData = jsonEncode(commands.map((c) => c.toMap()).toList());
|
||||
await _storage.write(key: _key, value: jsonData);
|
||||
}
|
||||
|
||||
// LOAD: Decrypts data, then converts JSON back to Objects
|
||||
static Future<List<ServerCommand>> loadCommands() async {
|
||||
final String? encryptedData = await _storage.read(key: _key);
|
||||
|
||||
if (encryptedData == null) return [];
|
||||
|
||||
final List<dynamic> decodedData = jsonDecode(encryptedData);
|
||||
return decodedData.map((item) => ServerCommand.fromMap(item)).toList();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user