mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-04-23 07:19:11 +00:00
Added clients allowed and blocked lists
This commit is contained in:
parent
d4a792e5c8
commit
f678401fa8
7 changed files with 96 additions and 26 deletions
|
@ -80,5 +80,6 @@
|
||||||
"createdBy": "Created by",
|
"createdBy": "Created by",
|
||||||
"clients": "Clients",
|
"clients": "Clients",
|
||||||
"allowed": "Allowed",
|
"allowed": "Allowed",
|
||||||
"blocked": "Blocked"
|
"blocked": "Blocked",
|
||||||
|
"noClientsList": "There are no clients on this list"
|
||||||
}
|
}
|
|
@ -80,5 +80,6 @@
|
||||||
"createdBy": "Creado por",
|
"createdBy": "Creado por",
|
||||||
"clients": "Clientes",
|
"clients": "Clientes",
|
||||||
"allowed": "Permitidos",
|
"allowed": "Permitidos",
|
||||||
"blocked": "Bloqueados"
|
"blocked": "Bloqueados",
|
||||||
|
"noClientsList": "No hay clientes en esta lista"
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/models/clients_allowed_blocked.dart';
|
||||||
|
|
||||||
class Clients {
|
class Clients {
|
||||||
int loadStatus;
|
int loadStatus;
|
||||||
ClientsData? data;
|
ClientsData? data;
|
||||||
|
@ -18,11 +20,13 @@ class ClientsData {
|
||||||
final List<Client> clients;
|
final List<Client> clients;
|
||||||
final List<AutoClient> autoClientsData;
|
final List<AutoClient> autoClientsData;
|
||||||
final List<String> supportedTags;
|
final List<String> supportedTags;
|
||||||
|
ClientsAllowedBlocked? clientsAllowedBlocked;
|
||||||
|
|
||||||
ClientsData({
|
ClientsData({
|
||||||
required this.clients,
|
required this.clients,
|
||||||
required this.autoClientsData,
|
required this.autoClientsData,
|
||||||
required this.supportedTags,
|
required this.supportedTags,
|
||||||
|
this.clientsAllowedBlocked
|
||||||
});
|
});
|
||||||
|
|
||||||
factory ClientsData.fromJson(Map<String, dynamic> json) => ClientsData(
|
factory ClientsData.fromJson(Map<String, dynamic> json) => ClientsData(
|
||||||
|
|
29
lib/models/clients_allowed_blocked.dart
Normal file
29
lib/models/clients_allowed_blocked.dart
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
ClientsAllowedBlocked allowedBlockedFromJson(String str) => ClientsAllowedBlocked.fromJson(json.decode(str));
|
||||||
|
|
||||||
|
String allowedBlockedToJson(ClientsAllowedBlocked data) => json.encode(data.toJson());
|
||||||
|
|
||||||
|
class ClientsAllowedBlocked {
|
||||||
|
ClientsAllowedBlocked({
|
||||||
|
required this.allowedClients,
|
||||||
|
required this.disallowedClients,
|
||||||
|
required this.blockedHosts,
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<String> allowedClients;
|
||||||
|
final List<String> disallowedClients;
|
||||||
|
final List<String> blockedHosts;
|
||||||
|
|
||||||
|
factory ClientsAllowedBlocked.fromJson(Map<String, dynamic> json) => ClientsAllowedBlocked(
|
||||||
|
allowedClients: List<String>.from(json["allowed_clients"].map((x) => x)),
|
||||||
|
disallowedClients: List<String>.from(json["disallowed_clients"].map((x) => x)),
|
||||||
|
blockedHosts: List<String>.from(json["blocked_hosts"].map((x) => x)),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"allowed_clients": List<dynamic>.from(allowedClients.map((x) => x)),
|
||||||
|
"disallowed_clients": List<dynamic>.from(disallowedClients.map((x) => x)),
|
||||||
|
"blocked_hosts": List<dynamic>.from(blockedHosts.map((x) => x)),
|
||||||
|
};
|
||||||
|
}
|
|
@ -59,6 +59,10 @@ class _ClientsWidgetState extends State<ClientsWidget> {
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<AutoClient> generateClientsList(List<AutoClient> clients, List<String> ips) {
|
||||||
|
return clients.where((client) => ips.contains(client.ip)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final serversProvider = Provider.of<ServersProvider>(context);
|
final serversProvider = Provider.of<ServersProvider>(context);
|
||||||
|
@ -121,8 +125,18 @@ class _ClientsWidgetState extends State<ClientsWidget> {
|
||||||
ClientsList(
|
ClientsList(
|
||||||
data: serversProvider.clients.data!.autoClientsData,
|
data: serversProvider.clients.data!.autoClientsData,
|
||||||
),
|
),
|
||||||
Container(),
|
ClientsList(
|
||||||
Container()
|
data: generateClientsList(
|
||||||
|
serversProvider.clients.data!.autoClientsData,
|
||||||
|
serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
ClientsList(
|
||||||
|
data: generateClientsList(
|
||||||
|
serversProvider.clients.data!.autoClientsData,
|
||||||
|
serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients,
|
||||||
|
)
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/models/clients.dart';
|
import 'package:adguard_home_manager/models/clients.dart';
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ class ClientsList extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (data.isNotEmpty) {
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
padding: const EdgeInsets.only(top: 0),
|
padding: const EdgeInsets.only(top: 0),
|
||||||
itemCount: data.length,
|
itemCount: data.length,
|
||||||
|
@ -30,4 +32,20 @@ class ClientsList extends StatelessWidget {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
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
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
import 'package:adguard_home_manager/models/server_status.dart';
|
import 'package:adguard_home_manager/models/server_status.dart';
|
||||||
import 'package:adguard_home_manager/models/clients.dart';
|
import 'package:adguard_home_manager/models/clients.dart';
|
||||||
|
import 'package:adguard_home_manager/models/clients_allowed_blocked.dart';
|
||||||
import 'package:adguard_home_manager/models/server.dart';
|
import 'package:adguard_home_manager/models/server.dart';
|
||||||
|
|
||||||
Future<http.Response> getRequest({
|
Future<http.Response> getRequest({
|
||||||
|
@ -246,15 +247,17 @@ Future updateGeneralProtection(Server server, bool enable) async {
|
||||||
|
|
||||||
Future getClients(Server server) async {
|
Future getClients(Server server) async {
|
||||||
try {
|
try {
|
||||||
final result = await getRequest(
|
final result = await Future.wait([
|
||||||
urlPath: '/clients',
|
getRequest(urlPath: '/clients', server: server),
|
||||||
server: server,
|
getRequest(urlPath: '/access/list', server: server),
|
||||||
);
|
]);
|
||||||
|
|
||||||
if (result.statusCode == 200) {
|
if (result[0].statusCode == 200 && result[1].statusCode == 200) {
|
||||||
|
final clients = ClientsData.fromJson(jsonDecode(result[0].body));
|
||||||
|
clients.clientsAllowedBlocked = ClientsAllowedBlocked.fromJson(jsonDecode(result[1].body));
|
||||||
return {
|
return {
|
||||||
'result': 'success',
|
'result': 'success',
|
||||||
'data': ClientsData.fromJson(jsonDecode(result.body))
|
'data': clients
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue