mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-04-28 17:48:10 +00:00
Changed allowed and blocked lists and added remove client
This commit is contained in:
parent
f678401fa8
commit
9f248d18a1
8 changed files with 227 additions and 27 deletions
|
@ -81,5 +81,11 @@
|
||||||
"clients": "Clients",
|
"clients": "Clients",
|
||||||
"allowed": "Allowed",
|
"allowed": "Allowed",
|
||||||
"blocked": "Blocked",
|
"blocked": "Blocked",
|
||||||
"noClientsList": "There are no clients on this list"
|
"noClientsList": "There are no clients on this list",
|
||||||
|
"activeClients": "Active",
|
||||||
|
"removeClient": "Remove client",
|
||||||
|
"removeClientMessage": "Are you sure you want to remove this client from the list?",
|
||||||
|
"confirm": "Confirm",
|
||||||
|
"removingClient": "Removing client...",
|
||||||
|
"clientNotRemoved": "Client could not be removed from the list"
|
||||||
}
|
}
|
|
@ -81,5 +81,11 @@
|
||||||
"clients": "Clientes",
|
"clients": "Clientes",
|
||||||
"allowed": "Permitidos",
|
"allowed": "Permitidos",
|
||||||
"blocked": "Bloqueados",
|
"blocked": "Bloqueados",
|
||||||
"noClientsList": "No hay clientes en esta lista"
|
"noClientsList": "No hay clientes en esta lista",
|
||||||
|
"activeClients": "Activos",
|
||||||
|
"removeClient": "Eliminar cliente",
|
||||||
|
"removeClientMessage": "Estás seguro que deseas eliminar este cliente de la lista?",
|
||||||
|
"confirm": "Confirmar",
|
||||||
|
"removingClient": "Eliminando cliente...",
|
||||||
|
"clientNotRemoved": "El cliente no pudo ser eliminado de la lista"
|
||||||
}
|
}
|
|
@ -5,20 +5,20 @@ ClientsAllowedBlocked allowedBlockedFromJson(String str) => ClientsAllowedBlocke
|
||||||
String allowedBlockedToJson(ClientsAllowedBlocked data) => json.encode(data.toJson());
|
String allowedBlockedToJson(ClientsAllowedBlocked data) => json.encode(data.toJson());
|
||||||
|
|
||||||
class ClientsAllowedBlocked {
|
class ClientsAllowedBlocked {
|
||||||
|
List<String> allowedClients;
|
||||||
|
List<String> disallowedClients;
|
||||||
|
List<String> blockedHosts;
|
||||||
|
|
||||||
ClientsAllowedBlocked({
|
ClientsAllowedBlocked({
|
||||||
required this.allowedClients,
|
required this.allowedClients,
|
||||||
required this.disallowedClients,
|
required this.disallowedClients,
|
||||||
required this.blockedHosts,
|
required this.blockedHosts,
|
||||||
});
|
});
|
||||||
|
|
||||||
final List<String> allowedClients;
|
|
||||||
final List<String> disallowedClients;
|
|
||||||
final List<String> blockedHosts;
|
|
||||||
|
|
||||||
factory ClientsAllowedBlocked.fromJson(Map<String, dynamic> json) => ClientsAllowedBlocked(
|
factory ClientsAllowedBlocked.fromJson(Map<String, dynamic> json) => ClientsAllowedBlocked(
|
||||||
allowedClients: List<String>.from(json["allowed_clients"].map((x) => x)),
|
allowedClients: json["allowed_clients"] != null ? List<String>.from(json["allowed_clients"].map((x) => x)) : [],
|
||||||
disallowedClients: List<String>.from(json["disallowed_clients"].map((x) => x)),
|
disallowedClients: json["disallowed_clients"] != null ? List<String>.from(json["disallowed_clients"].map((x) => x)) : [],
|
||||||
blockedHosts: List<String>.from(json["blocked_hosts"].map((x) => x)),
|
blockedHosts: json["blocked_hosts"] != null ? List<String>.from(json["blocked_hosts"].map((x) => x)) : [],
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sqflite/sqflite.dart';
|
import 'package:sqflite/sqflite.dart';
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/models/clients_allowed_blocked.dart';
|
||||||
import 'package:adguard_home_manager/models/clients.dart';
|
import 'package:adguard_home_manager/models/clients.dart';
|
||||||
import 'package:adguard_home_manager/services/http_requests.dart';
|
import 'package:adguard_home_manager/services/http_requests.dart';
|
||||||
import 'package:adguard_home_manager/models/server_status.dart';
|
import 'package:adguard_home_manager/models/server_status.dart';
|
||||||
|
@ -79,6 +80,11 @@ class ServersProvider with ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setAllowedDisallowedClientsBlockedDomains(ClientsAllowedBlocked data) {
|
||||||
|
_clients.data?.clientsAllowedBlocked = data;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
Future<bool> createServer(Server server) async {
|
Future<bool> createServer(Server server) async {
|
||||||
final saved = await saveServerIntoDb(server);
|
final saved = await saveServerIntoDb(server);
|
||||||
if (saved == true) {
|
if (saved == true) {
|
||||||
|
|
108
lib/screens/clients/blocked_allowed_list.dart
Normal file
108
lib/screens/clients/blocked_allowed_list.dart
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/models/clients_allowed_blocked.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/screens/clients/remove_domain_modal.dart';
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||||
|
import 'package:adguard_home_manager/services/http_requests.dart';
|
||||||
|
import 'package:adguard_home_manager/classes/process_modal.dart';
|
||||||
|
|
||||||
|
class BlockedAllowedList extends StatelessWidget {
|
||||||
|
final String type;
|
||||||
|
final List<String> data;
|
||||||
|
|
||||||
|
const BlockedAllowedList({
|
||||||
|
Key? key,
|
||||||
|
required this.type,
|
||||||
|
required this.data
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final serversProvider = Provider.of<ServersProvider>(context);
|
||||||
|
|
||||||
|
void confirmRemoveDomain(String domain) async {
|
||||||
|
Map<String, List<String>> body = {};
|
||||||
|
|
||||||
|
if (type == 'allowed') {
|
||||||
|
body = {
|
||||||
|
"allowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.allowedClients.where((client) => client != domain).toList() ?? [],
|
||||||
|
"disallowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.disallowedClients ?? [],
|
||||||
|
"blocked_hosts": serversProvider.clients.data!.clientsAllowedBlocked?.blockedHosts ?? [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (type == 'blocked') {
|
||||||
|
body = {
|
||||||
|
"allowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.allowedClients ?? [],
|
||||||
|
"disallowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.disallowedClients.where((client) => client != domain).toList() ?? [],
|
||||||
|
"blocked_hosts": serversProvider.clients.data!.clientsAllowedBlocked?.blockedHosts ?? [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ProcessModal processModal = ProcessModal(context: context);
|
||||||
|
processModal.open(AppLocalizations.of(context)!.removingClient);
|
||||||
|
|
||||||
|
final result = await requestAllowedBlockedClientsHosts(serversProvider.selectedServer!, body);
|
||||||
|
|
||||||
|
processModal.close();
|
||||||
|
|
||||||
|
if (result['result'] == 'success') {
|
||||||
|
serversProvider.setAllowedDisallowedClientsBlockedDomains(
|
||||||
|
ClientsAllowedBlocked(
|
||||||
|
allowedClients: body['allowed_clients'] ?? [],
|
||||||
|
disallowedClients: body['disallowed_clients'] ?? [],
|
||||||
|
blockedHosts: body['blocked_hosts'] ?? [],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!.clientNotRemoved),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.isNotEmpty) {
|
||||||
|
return ListView.builder(
|
||||||
|
padding: const EdgeInsets.only(top: 0),
|
||||||
|
itemCount: data.length,
|
||||||
|
itemBuilder: (context, index) => ListTile(
|
||||||
|
title: Text(data[index]),
|
||||||
|
trailing: IconButton(
|
||||||
|
onPressed: () => {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => RemoveDomainModal(
|
||||||
|
onConfirm: () => confirmRemoveDomain(data[index]),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.delete_rounded)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SizedBox(
|
||||||
|
width: double.maxFinite,
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
AppLocalizations.of(context)!.noClientsList,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
color: Colors.grey
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/screens/clients/clients_list.dart';
|
import 'package:adguard_home_manager/screens/clients/clients_list.dart';
|
||||||
|
import 'package:adguard_home_manager/screens/clients/blocked_allowed_list.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/models/server.dart';
|
import 'package:adguard_home_manager/models/server.dart';
|
||||||
import 'package:adguard_home_manager/services/http_requests.dart';
|
import 'package:adguard_home_manager/services/http_requests.dart';
|
||||||
|
@ -105,7 +106,7 @@ class _ClientsWidgetState extends State<ClientsWidget> {
|
||||||
tabs: [
|
tabs: [
|
||||||
Tab(
|
Tab(
|
||||||
icon: const Icon(Icons.devices),
|
icon: const Icon(Icons.devices),
|
||||||
text: AppLocalizations.of(context)!.clients,
|
text: AppLocalizations.of(context)!.activeClients,
|
||||||
),
|
),
|
||||||
Tab(
|
Tab(
|
||||||
icon: const Icon(Icons.check),
|
icon: const Icon(Icons.check),
|
||||||
|
@ -120,24 +121,31 @@ class _ClientsWidgetState extends State<ClientsWidget> {
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
}),
|
}),
|
||||||
body: TabBarView(
|
body: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
top: BorderSide(
|
||||||
|
color: Theme.of(context).brightness == Brightness.light
|
||||||
|
? const Color.fromRGBO(220, 220, 220, 1)
|
||||||
|
: const Color.fromRGBO(50, 50, 50, 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
child: TabBarView(
|
||||||
children: [
|
children: [
|
||||||
ClientsList(
|
ClientsList(
|
||||||
data: serversProvider.clients.data!.autoClientsData,
|
data: serversProvider.clients.data!.autoClientsData,
|
||||||
),
|
),
|
||||||
ClientsList(
|
BlockedAllowedList(
|
||||||
data: generateClientsList(
|
type: 'allowed',
|
||||||
serversProvider.clients.data!.autoClientsData,
|
data: serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients,
|
||||||
serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients,
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
ClientsList(
|
BlockedAllowedList(
|
||||||
data: generateClientsList(
|
type: 'blocked',
|
||||||
serversProvider.clients.data!.autoClientsData,
|
data: serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients,
|
||||||
serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients,
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
41
lib/screens/clients/remove_domain_modal.dart
Normal file
41
lib/screens/clients/remove_domain_modal.dart
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
class RemoveDomainModal extends StatelessWidget {
|
||||||
|
final void Function() onConfirm;
|
||||||
|
|
||||||
|
const RemoveDomainModal({
|
||||||
|
Key? key,
|
||||||
|
required this.onConfirm
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Column(
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.delete_rounded,
|
||||||
|
size: 26,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Text(AppLocalizations.of(context)!.removeClient)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
content: Text(AppLocalizations.of(context)!.removeClientMessage),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: Text(AppLocalizations.of(context)!.cancel)
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
onConfirm();
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.confirm)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -273,3 +273,28 @@ Future getClients(Server server) async {
|
||||||
return {'result': 'error'};
|
return {'result': 'error'};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future requestAllowedBlockedClientsHosts(Server server, Map<String, List<String>?> body) async {
|
||||||
|
try {
|
||||||
|
final result = await postRequest(
|
||||||
|
urlPath: '/access/set',
|
||||||
|
server: server,
|
||||||
|
body: body
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.statusCode == 200) {
|
||||||
|
return {'result': 'success'};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return {'result': 'error'};
|
||||||
|
}
|
||||||
|
} on SocketException {
|
||||||
|
return {'result': 'no_connection'};
|
||||||
|
} on TimeoutException {
|
||||||
|
return {'result': 'no_connection'};
|
||||||
|
} on HandshakeException {
|
||||||
|
return {'result': 'ssl_error'};
|
||||||
|
} catch (e) {
|
||||||
|
return {'result': 'error'};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue