mirror of
https://github.com/MoxiFoxi411/QuickSSH.git
synced 2026-11-08 19:24:54 +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
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
@@ -0,0 +1,37 @@
|
||||
class ServerCommand {
|
||||
String name;
|
||||
String ip;
|
||||
String username;
|
||||
String password;
|
||||
String command;
|
||||
|
||||
ServerCommand({
|
||||
required this.name,
|
||||
required this.ip,
|
||||
required this.username,
|
||||
required this.password,
|
||||
required this.command,
|
||||
});
|
||||
|
||||
// Convert Object to Map
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'name': name,
|
||||
'ip': ip,
|
||||
'username': username,
|
||||
'password': password,
|
||||
'command': command,
|
||||
};
|
||||
}
|
||||
|
||||
// Create Object from Map
|
||||
factory ServerCommand.fromMap(Map<String, dynamic> map) {
|
||||
return ServerCommand(
|
||||
name: map['name'],
|
||||
ip: map['ip'],
|
||||
username: map['username'],
|
||||
password: map['password'],
|
||||
command: map['command'],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// 2. THE MAIN THEME DEFINITIONS
|
||||
class MyThemes {
|
||||
static final darkTheme = ThemeData(
|
||||
useMaterial3: true,
|
||||
brightness: Brightness.dark,
|
||||
colorScheme: const ColorScheme.dark(
|
||||
primary: Color.fromARGB(255, 30, 90, 173),
|
||||
onPrimary: Color.fromARGB(255, 255, 255, 255),
|
||||
surface: Color.fromARGB(255, 24, 24, 24), // <--- Use this for Card BG
|
||||
onSurface: Color.fromARGB(255, 255, 255, 255), // Card Text
|
||||
onSurfaceVariant: Color.fromARGB(255, 155, 155, 155),
|
||||
primaryContainer: Color.fromARGB(255, 30, 30, 30),
|
||||
error: Color.fromARGB(255, 255, 0, 0),
|
||||
),
|
||||
);
|
||||
|
||||
static final lightTheme = ThemeData(
|
||||
useMaterial3: true,
|
||||
brightness: Brightness.light,
|
||||
colorScheme: const ColorScheme.light(
|
||||
primary: Color.fromARGB(255, 30, 90, 173),
|
||||
onPrimary: Color.fromARGB(255, 15, 15, 15),
|
||||
surface: Color.fromARGB(255, 245, 245, 245), // <--- Use this for Card BG
|
||||
onSurface: Color.fromARGB(255, 19, 19, 19), // Card Text
|
||||
onSurfaceVariant: Color.fromARGB(255, 61, 61, 61),
|
||||
primaryContainer: Color.fromARGB(255, 236, 236, 236),
|
||||
error: Color.fromARGB(255, 255, 0, 0),
|
||||
),
|
||||
);
|
||||
}
|
||||
+11
-22
@@ -1,36 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'screens/home_screen.dart';
|
||||
import 'package:QuickSSH/classes/theme_provider.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: const Color(0xFF37364A),
|
||||
title: const Text("Qucik SSH"),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text('Hello, World!', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: null,
|
||||
backgroundColor: const Color(0xFF6264AE),
|
||||
shape: const CircleBorder(),
|
||||
child: const Icon(Icons.add, color: const Color(0xFF22202B)),
|
||||
),
|
||||
backgroundColor: const Color(0xFF22202B),
|
||||
),
|
||||
title: 'Quick SSH',
|
||||
|
||||
theme: MyThemes.lightTheme,
|
||||
darkTheme: MyThemes.darkTheme,
|
||||
|
||||
themeMode: ThemeMode.system,
|
||||
|
||||
home: HomeScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:QuickSSH/classes/ServerCommand.dart';
|
||||
|
||||
class AddClient extends StatefulWidget {
|
||||
const AddClient({super.key});
|
||||
|
||||
@override
|
||||
State<AddClient> createState() => _AddClientState();
|
||||
}
|
||||
|
||||
class _AddClientState extends State<AddClient> {
|
||||
final nameController = TextEditingController();
|
||||
final ipController = TextEditingController();
|
||||
final userController = TextEditingController();
|
||||
final cmdController = TextEditingController();
|
||||
final passController = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
nameController.dispose();
|
||||
ipController.dispose();
|
||||
userController.dispose();
|
||||
cmdController.dispose();
|
||||
passController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
backgroundColor: theme.surface,
|
||||
appBar: AppBar(
|
||||
backgroundColor: theme.surface,
|
||||
title: Text("Add command", style: TextStyle(color: theme.onSurface)),
|
||||
leading: Builder(
|
||||
builder: (context) {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.arrow_back_ios_rounded, color: theme.onSurface),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
style: TextStyle(color: theme.onSurface),
|
||||
controller: nameController,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: theme.primaryContainer,
|
||||
labelText: 'Command name',
|
||||
labelStyle: TextStyle(
|
||||
color: theme.onSurfaceVariant,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
style: TextStyle(color: theme.onSurface),
|
||||
controller: ipController,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: theme.primaryContainer,
|
||||
labelText: 'Host (IP address)',
|
||||
labelStyle: TextStyle(
|
||||
color: theme.onSurfaceVariant,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
style: TextStyle(color: theme.onSurface),
|
||||
controller: userController,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: theme.primaryContainer,
|
||||
labelText: 'Login as (user)',
|
||||
labelStyle: TextStyle(
|
||||
color: theme.onSurfaceVariant,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
style: TextStyle(color: theme.onSurface),
|
||||
controller: passController,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: theme.primaryContainer,
|
||||
labelText: 'Password',
|
||||
labelStyle: TextStyle(
|
||||
color: theme.onSurfaceVariant,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
style: TextStyle(color: theme.onSurface),
|
||||
controller: cmdController,
|
||||
minLines: 3,
|
||||
maxLines: 100,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: theme.primaryContainer,
|
||||
labelText: 'Command',
|
||||
labelStyle: TextStyle(
|
||||
color: theme.onSurfaceVariant,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_onSaved();
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: theme.primary,
|
||||
fixedSize: const Size(140, 40),
|
||||
),
|
||||
child: Text(
|
||||
'Add',
|
||||
style: TextStyle(
|
||||
color: theme.onPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onSaved() {
|
||||
// Create the object using the controller text
|
||||
final newCmd = ServerCommand(
|
||||
name: nameController.text,
|
||||
ip: ipController.text,
|
||||
username: userController.text,
|
||||
command: cmdController.text,
|
||||
password: passController.text,
|
||||
);
|
||||
|
||||
print("Saving: ${newCmd.name}");
|
||||
|
||||
// Send the object BACK to the previous screen (Home)
|
||||
Navigator.pop(context, newCmd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,319 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:QuickSSH/classes/ServerCommand.dart';
|
||||
|
||||
class EditClient extends StatefulWidget {
|
||||
final ServerCommand? existingCommand; // Null if adding, not null if editing
|
||||
final int? index;
|
||||
|
||||
const EditClient({super.key, this.existingCommand, this.index});
|
||||
|
||||
@override
|
||||
State<EditClient> createState() => _EditClientState();
|
||||
}
|
||||
|
||||
class _EditClientState extends State<EditClient> {
|
||||
final nameController = TextEditingController();
|
||||
final ipController = TextEditingController();
|
||||
final userController = TextEditingController();
|
||||
final cmdController = TextEditingController();
|
||||
final passController = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
nameController.dispose();
|
||||
ipController.dispose();
|
||||
userController.dispose();
|
||||
cmdController.dispose();
|
||||
passController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.existingCommand != null) {
|
||||
nameController.text = widget.existingCommand!.name;
|
||||
ipController.text = widget.existingCommand!.ip;
|
||||
userController.text = widget.existingCommand!.username;
|
||||
passController.text = widget.existingCommand!.password;
|
||||
cmdController.text = widget.existingCommand!.command;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: theme.surface,
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(
|
||||
backgroundColor: theme.surface,
|
||||
title: Text("Edit", style: TextStyle(color: theme.onSurface)),
|
||||
leading: Builder(
|
||||
builder: (context) {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.arrow_back_ios_rounded, color: theme.onSurface),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
style: TextStyle(color: theme.onSurface),
|
||||
controller: nameController,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: theme.primaryContainer,
|
||||
labelText: 'Command name',
|
||||
labelStyle: TextStyle(
|
||||
color: theme.onSurfaceVariant,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
style: TextStyle(color: theme.onSurface),
|
||||
controller: ipController,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: theme.primaryContainer,
|
||||
labelText: 'Host (IP address)',
|
||||
labelStyle: TextStyle(
|
||||
color: theme.onSurfaceVariant,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
style: TextStyle(color: theme.onSurface),
|
||||
controller: userController,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: theme.primaryContainer,
|
||||
labelText: 'Login as (user)',
|
||||
labelStyle: TextStyle(
|
||||
color: theme.onSurfaceVariant,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
style: TextStyle(color: theme.onSurface),
|
||||
controller: passController,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: theme.primaryContainer,
|
||||
labelText: 'Password',
|
||||
labelStyle: TextStyle(
|
||||
color: theme.onSurfaceVariant,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
style: TextStyle(color: theme.onSurface),
|
||||
controller: cmdController,
|
||||
minLines: 3,
|
||||
maxLines: 100,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: theme.primaryContainer,
|
||||
labelText: 'Command',
|
||||
labelStyle: TextStyle(
|
||||
color: theme.onSurfaceVariant,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide(color: Color.fromARGB(0, 0, 0, 0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(25.0),
|
||||
),
|
||||
),
|
||||
builder: (BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 400,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'Remove this command?',
|
||||
style: TextStyle(fontSize: 20),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context, "DELETE");
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: theme.error,
|
||||
fixedSize: const Size(140, 40),
|
||||
),
|
||||
child: Text(
|
||||
'Yes, remove',
|
||||
style: TextStyle(
|
||||
color: theme.surface,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: theme.onSurface,
|
||||
fixedSize: const Size(140, 40),
|
||||
),
|
||||
child: Text(
|
||||
'No',
|
||||
style: TextStyle(
|
||||
color: theme.surface,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: theme.error,
|
||||
fixedSize: const Size(140, 40),
|
||||
),
|
||||
child: Text(
|
||||
'Remove',
|
||||
style: TextStyle(
|
||||
color: const Color.fromARGB(255, 0, 0, 0),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: _save,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: theme.onSurface,
|
||||
fixedSize: const Size(140, 40),
|
||||
),
|
||||
child: Text(
|
||||
'Save',
|
||||
style: TextStyle(
|
||||
color: theme.surface,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _save() {
|
||||
final updatedCommand = ServerCommand(
|
||||
name: nameController.text,
|
||||
ip: ipController.text,
|
||||
username: userController.text,
|
||||
command: cmdController.text,
|
||||
password: passController.text,
|
||||
);
|
||||
|
||||
Navigator.pop(context, updatedCommand);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:QuickSSH/screens/edit_client.dart';
|
||||
import '../widgets/server_status_tile.dart';
|
||||
import 'add_client.dart';
|
||||
import 'package:QuickSSH/classes/ServerCommand.dart';
|
||||
import 'package:QuickSSH/services/storage_service.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
List<ServerCommand> allCommands = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadData();
|
||||
}
|
||||
|
||||
void _loadData() async {
|
||||
allCommands = await SecureStorageService.loadCommands();
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context).colorScheme;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: theme.surface,
|
||||
leading: Builder(
|
||||
builder: (context) {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.menu, color: theme.onSurface),
|
||||
onPressed: () {
|
||||
Scaffold.of(context).openDrawer();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
drawer: Drawer(
|
||||
backgroundColor: theme.primaryContainer,
|
||||
child: ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(
|
||||
"Settings",
|
||||
style: TextStyle(
|
||||
color: theme.onSurface,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(
|
||||
"Help",
|
||||
style: TextStyle(
|
||||
color: theme.onSurface,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemCount: allCommands.length,
|
||||
itemBuilder: (context, index) {
|
||||
// You can keep this as 'context' or rename it
|
||||
return ServerStatusTile(
|
||||
command: allCommands[index],
|
||||
onEdit: () => _editCommand(allCommands[index], index),
|
||||
);
|
||||
},
|
||||
),
|
||||
floatingActionButton: Builder(
|
||||
builder: (context) {
|
||||
return FloatingActionButton(
|
||||
backgroundColor: theme.primary,
|
||||
shape: const CircleBorder(),
|
||||
child: const Icon(
|
||||
Icons.add,
|
||||
color: Color.fromARGB(255, 0, 0, 0),
|
||||
size: 32,
|
||||
weight: 50,
|
||||
),
|
||||
onPressed: () {
|
||||
_addCommand();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
backgroundColor: theme.surface,
|
||||
);
|
||||
}
|
||||
|
||||
void _addCommand() async {
|
||||
// 1. Must be async
|
||||
print("Opening Add Screen...");
|
||||
|
||||
final result = await Navigator.push(
|
||||
// 2. Must have await
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const AddClient()),
|
||||
);
|
||||
|
||||
// This part only runs AFTER you come back from AddClient
|
||||
if (result != null) {
|
||||
print("Received data: ${result.name}");
|
||||
setState(() {
|
||||
allCommands.add(result);
|
||||
});
|
||||
SecureStorageService.saveCommands(allCommands);
|
||||
} else {
|
||||
print("Result was null - user might have just hit 'Back'");
|
||||
}
|
||||
}
|
||||
|
||||
_editCommand(ServerCommand cmdToEdit, int index) async {
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => EditClient(existingCommand: cmdToEdit),
|
||||
),
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
if (result == "DELETE") {
|
||||
setState(() {
|
||||
allCommands.removeAt(index);
|
||||
});
|
||||
SecureStorageService.saveCommands(allCommands);
|
||||
return;
|
||||
}
|
||||
|
||||
print("Received edited data: ${result.name}");
|
||||
setState(() {
|
||||
allCommands[index] = result;
|
||||
});
|
||||
SecureStorageService.saveCommands(allCommands);
|
||||
} else {
|
||||
print("Edit result was null - user might have just hit 'Back'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:QuickSSH/classes/ServerCommand.dart';
|
||||
import 'package:QuickSSH/services/SSHService.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class ServerStatusTile extends StatelessWidget {
|
||||
final ServerCommand command;
|
||||
final VoidCallback onEdit;
|
||||
|
||||
const ServerStatusTile({
|
||||
super.key,
|
||||
required this.command,
|
||||
required this.onEdit,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context).colorScheme;
|
||||
|
||||
return Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
color: theme.primaryContainer,
|
||||
child: InkWell(
|
||||
splashColor: const Color.fromARGB(
|
||||
47,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
), // Custom ripple color!
|
||||
highlightColor: Colors.transparent,
|
||||
|
||||
onDoubleTap: () {
|
||||
HapticFeedback.heavyImpact();
|
||||
_handleCommandTap(context, command);
|
||||
},
|
||||
|
||||
onLongPress: () {
|
||||
HapticFeedback.heavyImpact();
|
||||
onEdit();
|
||||
},
|
||||
|
||||
child: IgnorePointer(
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
command.name,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
color: theme.onSurface,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
"${command.username}@${command.ip}",
|
||||
style: TextStyle(color: theme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleCommandTap(BuildContext context, ServerCommand cmd) async {
|
||||
// Show a "Loading" snackbar
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
content: Text("Connecting to ${cmd.ip} as ${cmd.username}..."),
|
||||
duration: Duration(seconds: 2),
|
||||
backgroundColor: const Color.fromARGB(255, 56, 159, 243),
|
||||
),
|
||||
);
|
||||
|
||||
// Run the SSH command
|
||||
String output = await SSHService.execute(cmd);
|
||||
|
||||
// Show the final result from the server
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
content: Text(output.isEmpty ? "Command executed (no output)" : output),
|
||||
backgroundColor: output.contains("Error") ? Colors.red : Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user