Extracted dns

This commit is contained in:
Juan Gilsanz Polo 2023-05-24 20:40:45 +02:00
parent 5afe912e7e
commit 9e0eae7c57
22 changed files with 129 additions and 173 deletions

View file

@ -20,8 +20,9 @@ import 'package:adguard_home_manager/base.dart';
import 'package:adguard_home_manager/providers/logs_provider.dart'; import 'package:adguard_home_manager/providers/logs_provider.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/providers/clients_provider.dart'; import 'package:adguard_home_manager/providers/clients_provider.dart';
import 'package:adguard_home_manager/providers/filters_provider.dart'; import 'package:adguard_home_manager/providers/dns_provider.dart';
import 'package:adguard_home_manager/providers/rewrute_rules_provider.dart'; import 'package:adguard_home_manager/providers/filtering_provider.dart';
import 'package:adguard_home_manager/providers/rewrite_rules_provider.dart';
import 'package:adguard_home_manager/providers/dhcp_provider.dart'; import 'package:adguard_home_manager/providers/dhcp_provider.dart';
import 'package:adguard_home_manager/providers/status_provider.dart'; import 'package:adguard_home_manager/providers/status_provider.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/providers/servers_provider.dart';
@ -53,6 +54,7 @@ void main() async {
final FilteringProvider filtersProvider = FilteringProvider(); final FilteringProvider filtersProvider = FilteringProvider();
final DhcpProvider dhcpProvider = DhcpProvider(); final DhcpProvider dhcpProvider = DhcpProvider();
final RewriteRulesProvider rewriteRulesProvider = RewriteRulesProvider(); final RewriteRulesProvider rewriteRulesProvider = RewriteRulesProvider();
final DnsProvider dnsProvider = DnsProvider();
final LogsProvider logsProvider = LogsProvider(); final LogsProvider logsProvider = LogsProvider();
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
@ -121,6 +123,9 @@ void main() async {
ChangeNotifierProvider( ChangeNotifierProvider(
create: ((context) => rewriteRulesProvider) create: ((context) => rewriteRulesProvider)
), ),
ChangeNotifierProvider(
create: ((context) => dnsProvider)
),
ChangeNotifierProxyProvider<StatusProvider, FilteringProvider>( ChangeNotifierProxyProvider<StatusProvider, FilteringProvider>(
create: (context) => filtersProvider, create: (context) => filtersProvider,
update: (context, status, filtering) => filtering!..updateStatus(status), update: (context, status, filtering) => filtering!..updateStatus(status),

View file

@ -1,20 +1,4 @@
import 'dart:convert';
class DnsInfo { class DnsInfo {
int loadStatus = 0;
DnsInfoData? data;
DnsInfo({
required this.loadStatus,
this.data
});
}
DnsInfoData dnsInfoDataFromJson(String str) => DnsInfoData.fromJson(json.decode(str));
String dnsInfoDataToJson(DnsInfoData data) => json.encode(data.toJson());
class DnsInfoData {
List<String> upstreamDns; List<String> upstreamDns;
String upstreamDnsFile; String upstreamDnsFile;
List<String> bootstrapDns; List<String> bootstrapDns;
@ -34,9 +18,9 @@ class DnsInfoData {
List<String> localPtrUpstreams; List<String> localPtrUpstreams;
String blockingIpv4; String blockingIpv4;
String blockingIpv6; String blockingIpv6;
List<String> defaultLocalPtrUpstreams; List<String> defaultLocalPtrUpstreams;
DnsInfoData({
DnsInfo({
required this.upstreamDns, required this.upstreamDns,
required this.upstreamDnsFile, required this.upstreamDnsFile,
required this.bootstrapDns, required this.bootstrapDns,
@ -59,7 +43,7 @@ class DnsInfoData {
required this.defaultLocalPtrUpstreams, required this.defaultLocalPtrUpstreams,
}); });
factory DnsInfoData.fromJson(Map<String, dynamic> json) => DnsInfoData( factory DnsInfo.fromJson(Map<String, dynamic> json) => DnsInfo(
upstreamDns: json["upstream_dns"] != null ? List<String>.from(json["upstream_dns"].map((x) => x)) : [], upstreamDns: json["upstream_dns"] != null ? List<String>.from(json["upstream_dns"].map((x) => x)) : [],
upstreamDnsFile: json["upstream_dns_file"], upstreamDnsFile: json["upstream_dns_file"],
bootstrapDns: List<String>.from(json["bootstrap_dns"].map((x) => x)), bootstrapDns: List<String>.from(json["bootstrap_dns"].map((x) => x)),

View file

@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import 'package:adguard_home_manager/constants/enums.dart';
import 'package:adguard_home_manager/models/dns_info.dart';
class DnsProvider with ChangeNotifier {
LoadStatus _loadStatus = LoadStatus.loading;
DnsInfo? _dnsInfo;
LoadStatus get loadStatus {
return _loadStatus;
}
DnsInfo? get dnsInfo {
return _dnsInfo;
}
void setDnsInfoData(DnsInfo data) {
_dnsInfo = data;
notifyListeners();
}
void setDnsInfoLoadStatus(LoadStatus status, bool notify) {
_loadStatus = status;
if (notify == true) {
notifyListeners();
}
}
}

View file

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:sqflite/sqflite.dart'; import 'package:sqflite/sqflite.dart';
import 'package:adguard_home_manager/models/dns_info.dart'; import 'package:adguard_home_manager/models/dns_info.dart';
import 'package:adguard_home_manager/models/rewrite_rules.dart';
import 'package:adguard_home_manager/models/server.dart'; import 'package:adguard_home_manager/models/server.dart';
import 'package:adguard_home_manager/models/update_available.dart'; import 'package:adguard_home_manager/models/update_available.dart';
import 'package:adguard_home_manager/services/http_requests.dart'; import 'package:adguard_home_manager/services/http_requests.dart';
@ -17,11 +16,6 @@ class ServersProvider with ChangeNotifier {
List<Server> _serversList = []; List<Server> _serversList = [];
Server? _selectedServer; Server? _selectedServer;
final DnsInfo _dnsInfo = DnsInfo(
loadStatus: 0, // 0 = loading, 1 = loaded, 2 = error
data: null
);
final UpdateAvailable _updateAvailable = UpdateAvailable( final UpdateAvailable _updateAvailable = UpdateAvailable(
loadStatus: LoadStatus.loading, loadStatus: LoadStatus.loading,
data: null, data: null,
@ -35,10 +29,6 @@ class ServersProvider with ChangeNotifier {
return _selectedServer; return _selectedServer;
} }
DnsInfo get dnsInfo {
return _dnsInfo;
}
UpdateAvailable get updateAvailable { UpdateAvailable get updateAvailable {
return _updateAvailable; return _updateAvailable;
} }
@ -57,18 +47,6 @@ class ServersProvider with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
void setDnsInfoData(DnsInfoData data) {
_dnsInfo.data = data;
notifyListeners();
}
void setDnsInfoLoadStatus(int status, bool notify) {
_dnsInfo.loadStatus = status;
if (notify == true) {
notifyListeners();
}
}
void setUpdateAvailableLoadStatus(LoadStatus status, bool notify) { void setUpdateAvailableLoadStatus(LoadStatus status, bool notify) {
_updateAvailable.loadStatus = status; _updateAvailable.loadStatus = status;
if (notify == true) { if (notify == true) {

View file

@ -4,7 +4,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/constants/enums.dart'; import 'package:adguard_home_manager/constants/enums.dart';
import 'package:adguard_home_manager/providers/filters_provider.dart'; import 'package:adguard_home_manager/providers/filtering_provider.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/providers/servers_provider.dart';
import 'package:adguard_home_manager/services/http_requests.dart'; import 'package:adguard_home_manager/services/http_requests.dart';

View file

@ -9,7 +9,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/screens/filters/add_custom_rule.dart'; import 'package:adguard_home_manager/screens/filters/add_custom_rule.dart';
import 'package:adguard_home_manager/screens/filters/add_list_modal.dart'; import 'package:adguard_home_manager/screens/filters/add_list_modal.dart';
import 'package:adguard_home_manager/providers/filters_provider.dart'; import 'package:adguard_home_manager/providers/filtering_provider.dart';
import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/functions/snackbar.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/filtering.dart'; import 'package:adguard_home_manager/models/filtering.dart';

View file

@ -8,7 +8,7 @@ import 'package:adguard_home_manager/models/blocked_services.dart';
import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/functions/snackbar.dart';
import 'package:adguard_home_manager/classes/process_modal.dart'; import 'package:adguard_home_manager/classes/process_modal.dart';
import 'package:adguard_home_manager/constants/enums.dart'; import 'package:adguard_home_manager/constants/enums.dart';
import 'package:adguard_home_manager/providers/filters_provider.dart'; import 'package:adguard_home_manager/providers/filtering_provider.dart';
import 'package:adguard_home_manager/services/http_requests.dart'; import 'package:adguard_home_manager/services/http_requests.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/providers/servers_provider.dart';

View file

@ -17,7 +17,7 @@ import 'package:adguard_home_manager/screens/filters/update_interval_lists_modal
import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/functions/snackbar.dart';
import 'package:adguard_home_manager/providers/status_provider.dart'; import 'package:adguard_home_manager/providers/status_provider.dart';
import 'package:adguard_home_manager/classes/process_modal.dart'; import 'package:adguard_home_manager/classes/process_modal.dart';
import 'package:adguard_home_manager/providers/filters_provider.dart'; import 'package:adguard_home_manager/providers/filtering_provider.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/models/filtering.dart'; import 'package:adguard_home_manager/models/filtering.dart';
import 'package:adguard_home_manager/constants/enums.dart'; import 'package:adguard_home_manager/constants/enums.dart';

View file

@ -5,7 +5,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/screens/filters/custom_rules_list.dart'; import 'package:adguard_home_manager/screens/filters/custom_rules_list.dart';
import 'package:adguard_home_manager/screens/filters/filters_list.dart'; import 'package:adguard_home_manager/screens/filters/filters_list.dart';
import 'package:adguard_home_manager/providers/filters_provider.dart'; import 'package:adguard_home_manager/providers/filtering_provider.dart';
import 'package:adguard_home_manager/constants/enums.dart'; import 'package:adguard_home_manager/constants/enums.dart';
import 'package:adguard_home_manager/models/filtering.dart'; import 'package:adguard_home_manager/models/filtering.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';

View file

@ -15,7 +15,7 @@ import 'package:adguard_home_manager/widgets/options_modal.dart';
import 'package:adguard_home_manager/constants/enums.dart'; import 'package:adguard_home_manager/constants/enums.dart';
import 'package:adguard_home_manager/models/menu_option.dart'; import 'package:adguard_home_manager/models/menu_option.dart';
import 'package:adguard_home_manager/functions/copy_clipboard.dart'; import 'package:adguard_home_manager/functions/copy_clipboard.dart';
import 'package:adguard_home_manager/providers/filters_provider.dart'; import 'package:adguard_home_manager/providers/filtering_provider.dart';
import 'package:adguard_home_manager/models/filtering.dart'; import 'package:adguard_home_manager/models/filtering.dart';
import 'package:adguard_home_manager/functions/number_format.dart'; import 'package:adguard_home_manager/functions/number_format.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';

View file

@ -13,7 +13,7 @@ import 'package:adguard_home_manager/screens/filters/list_functions.dart';
import 'package:adguard_home_manager/widgets/custom_list_tile.dart'; import 'package:adguard_home_manager/widgets/custom_list_tile.dart';
import 'package:adguard_home_manager/functions/format_time.dart'; import 'package:adguard_home_manager/functions/format_time.dart';
import 'package:adguard_home_manager/providers/filters_provider.dart'; import 'package:adguard_home_manager/providers/filtering_provider.dart';
import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/functions/snackbar.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/models/filtering.dart'; import 'package:adguard_home_manager/models/filtering.dart';

View file

@ -5,7 +5,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/classes/process_modal.dart'; import 'package:adguard_home_manager/classes/process_modal.dart';
import 'package:adguard_home_manager/providers/filters_provider.dart'; import 'package:adguard_home_manager/providers/filtering_provider.dart';
import 'package:adguard_home_manager/models/filtering.dart'; import 'package:adguard_home_manager/models/filtering.dart';
import 'package:adguard_home_manager/constants/enums.dart'; import 'package:adguard_home_manager/constants/enums.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';

View file

@ -6,18 +6,14 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/providers/servers_provider.dart';
import 'package:adguard_home_manager/classes/process_modal.dart'; import 'package:adguard_home_manager/classes/process_modal.dart';
import 'package:adguard_home_manager/providers/dns_provider.dart';
import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/functions/snackbar.dart';
import 'package:adguard_home_manager/models/dns_info.dart'; import 'package:adguard_home_manager/models/dns_info.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/services/http_requests.dart'; import 'package:adguard_home_manager/services/http_requests.dart';
class BootstrapDnsScreen extends StatefulWidget { class BootstrapDnsScreen extends StatefulWidget {
final ServersProvider serversProvider; const BootstrapDnsScreen({Key? key}) : super(key: key);
const BootstrapDnsScreen({
Key? key,
required this.serversProvider,
}) : super(key: key);
@override @override
State<BootstrapDnsScreen> createState() => _BootstrapDnsScreenState(); State<BootstrapDnsScreen> createState() => _BootstrapDnsScreenState();
@ -54,7 +50,9 @@ class _BootstrapDnsScreenState extends State<BootstrapDnsScreen> {
@override @override
void initState() { void initState() {
for (var item in widget.serversProvider.dnsInfo.data!.bootstrapDns) { final dnsProvider = Provider.of<DnsProvider>(context, listen: false);
for (var item in dnsProvider.dnsInfo!.bootstrapDns) {
final controller = TextEditingController(); final controller = TextEditingController();
controller.text = item; controller.text = item;
bootstrapControllers.add({ bootstrapControllers.add({
@ -69,6 +67,7 @@ class _BootstrapDnsScreenState extends State<BootstrapDnsScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final serversProvider = Provider.of<ServersProvider>(context); final serversProvider = Provider.of<ServersProvider>(context);
final dnsProvider = Provider.of<DnsProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(context); final appConfigProvider = Provider.of<AppConfigProvider>(context);
void saveData() async { void saveData() async {
@ -82,9 +81,9 @@ class _BootstrapDnsScreenState extends State<BootstrapDnsScreen> {
processModal.close(); processModal.close();
if (result['result'] == 'success') { if (result['result'] == 'success') {
DnsInfoData data = serversProvider.dnsInfo.data!; DnsInfo data = dnsProvider.dnsInfo!;
data.bootstrapDns = List<String>.from(bootstrapControllers.map((e) => e['controller'].text)); data.bootstrapDns = List<String>.from(bootstrapControllers.map((e) => e['controller'].text));
serversProvider.setDnsInfoData(data); dnsProvider.setDnsInfoData(data);
showSnacbkar( showSnacbkar(
appConfigProvider: appConfigProvider, appConfigProvider: appConfigProvider,

View file

@ -8,7 +8,7 @@ import 'package:adguard_home_manager/widgets/custom_switch_list_tile.dart';
import 'package:adguard_home_manager/screens/settings/dns/clear_dns_cache_dialog.dart'; import 'package:adguard_home_manager/screens/settings/dns/clear_dns_cache_dialog.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/providers/servers_provider.dart';
import 'package:adguard_home_manager/providers/dns_provider.dart';
import 'package:adguard_home_manager/classes/process_modal.dart'; import 'package:adguard_home_manager/classes/process_modal.dart';
import 'package:adguard_home_manager/functions/clear_dns_cache.dart'; import 'package:adguard_home_manager/functions/clear_dns_cache.dart';
import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/functions/snackbar.dart';
@ -17,12 +17,7 @@ import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/services/http_requests.dart'; import 'package:adguard_home_manager/services/http_requests.dart';
class CacheConfigDnsScreen extends StatefulWidget { class CacheConfigDnsScreen extends StatefulWidget {
final ServersProvider serversProvider; const CacheConfigDnsScreen({Key? key}) : super(key: key);
const CacheConfigDnsScreen({
Key? key,
required this.serversProvider
}) : super(key: key);
@override @override
State<CacheConfigDnsScreen> createState() => _CacheConfigDnsScreenState(); State<CacheConfigDnsScreen> createState() => _CacheConfigDnsScreenState();
@ -60,10 +55,12 @@ class _CacheConfigDnsScreenState extends State<CacheConfigDnsScreen> {
@override @override
void initState() { void initState() {
cacheSizeController.text = widget.serversProvider.dnsInfo.data!.cacheSize.toString(); final dnsProvider = Provider.of<DnsProvider>(context, listen: false);
overrideMinTtlController.text = widget.serversProvider.dnsInfo.data!.cacheTtlMin.toString();
overrideMaxTtlController.text = widget.serversProvider.dnsInfo.data!.cacheTtlMax.toString(); cacheSizeController.text = dnsProvider.dnsInfo!.cacheSize.toString();
optimisticCache = widget.serversProvider.dnsInfo.data!.cacheOptimistic; overrideMinTtlController.text = dnsProvider.dnsInfo!.cacheTtlMin.toString();
overrideMaxTtlController.text = dnsProvider.dnsInfo!.cacheTtlMax.toString();
optimisticCache = dnsProvider.dnsInfo!.cacheOptimistic;
validData = true; validData = true;
super.initState(); super.initState();
} }
@ -71,6 +68,7 @@ class _CacheConfigDnsScreenState extends State<CacheConfigDnsScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final serversProvider = Provider.of<ServersProvider>(context); final serversProvider = Provider.of<ServersProvider>(context);
final dnsProvider = Provider.of<DnsProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(context); final appConfigProvider = Provider.of<AppConfigProvider>(context);
void saveData() async { void saveData() async {
@ -87,12 +85,12 @@ class _CacheConfigDnsScreenState extends State<CacheConfigDnsScreen> {
processModal.close(); processModal.close();
if (result['result'] == 'success') { if (result['result'] == 'success') {
DnsInfoData data = serversProvider.dnsInfo.data!; DnsInfo data = dnsProvider.dnsInfo!;
data.cacheSize = int.parse(cacheSizeController.text); data.cacheSize = int.parse(cacheSizeController.text);
data.cacheTtlMin = int.parse(overrideMinTtlController.text); data.cacheTtlMin = int.parse(overrideMinTtlController.text);
data.cacheTtlMax = int.parse(overrideMaxTtlController.text); data.cacheTtlMax = int.parse(overrideMaxTtlController.text);
data.cacheOptimistic = optimisticCache; data.cacheOptimistic = optimisticCache;
serversProvider.setDnsInfoData(data); dnsProvider.setDnsInfoData(data);
showSnacbkar( showSnacbkar(
appConfigProvider: appConfigProvider, appConfigProvider: appConfigProvider,

View file

@ -2,6 +2,8 @@
import 'dart:io'; import 'dart:io';
import 'package:adguard_home_manager/constants/enums.dart';
import 'package:adguard_home_manager/providers/dns_provider.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_split_view/flutter_split_view.dart'; import 'package:flutter_split_view/flutter_split_view.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -21,49 +23,32 @@ import 'package:adguard_home_manager/providers/servers_provider.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/services/http_requests.dart'; import 'package:adguard_home_manager/services/http_requests.dart';
class DnsSettings extends StatelessWidget { class DnsSettings extends StatefulWidget {
const DnsSettings({Key? key}) : super(key: key); const DnsSettings({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { State<DnsSettings> createState() => _DnsSettingsState();
final serversProvider = Provider.of<ServersProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(context);
return DnsSettingsWidget(
serversProvider: serversProvider,
appConfigProvider: appConfigProvider,
);
}
}
class DnsSettingsWidget extends StatefulWidget {
final ServersProvider serversProvider;
final AppConfigProvider appConfigProvider;
const DnsSettingsWidget({
required this.serversProvider,
required this.appConfigProvider,
Key? key
}) : super(key: key);
@override
State<DnsSettingsWidget> createState() => _DnsSettingsWidgetState();
} }
class _DnsSettingsWidgetState extends State<DnsSettingsWidget> { class _DnsSettingsState extends State<DnsSettings> {
void fetchData({bool? showRefreshIndicator}) async { void fetchData({bool? showRefreshIndicator}) async {
widget.serversProvider.setDnsInfoLoadStatus(0, showRefreshIndicator ?? false); final dnsProvider = Provider.of<DnsProvider>(context, listen: false);
final serversProvider = Provider.of<ServersProvider>(context, listen: false);
final appConfigProvider = Provider.of<AppConfigProvider>(context, listen: false);
final result = await getDnsInfo(server: widget.serversProvider.selectedServer!); dnsProvider.setDnsInfoLoadStatus(LoadStatus.loading, showRefreshIndicator ?? false);
final result = await getDnsInfo(server: serversProvider.selectedServer!);
if (mounted) { if (mounted) {
if (result['result'] == 'success') { if (result['result'] == 'success') {
widget.serversProvider.setDnsInfoData(result['data']); dnsProvider.setDnsInfoData(result['data']);
widget.serversProvider.setDnsInfoLoadStatus(1, true); dnsProvider.setDnsInfoLoadStatus(LoadStatus.loaded, true);
} }
else { else {
widget.appConfigProvider.addLog(result['log']); appConfigProvider.addLog(result['log']);
widget.serversProvider.setDnsInfoLoadStatus(2, true); dnsProvider.setDnsInfoLoadStatus(LoadStatus.error, true);
} }
} }
} }
@ -77,6 +62,7 @@ class _DnsSettingsWidgetState extends State<DnsSettingsWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final serversProvider = Provider.of<ServersProvider>(context); final serversProvider = Provider.of<ServersProvider>(context);
final dnsProvider = Provider.of<DnsProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(context); final appConfigProvider = Provider.of<AppConfigProvider>(context);
final width = MediaQuery.of(context).size.width; final width = MediaQuery.of(context).size.width;
@ -93,8 +79,8 @@ class _DnsSettingsWidgetState extends State<DnsSettingsWidget> {
} }
Widget generateBody() { Widget generateBody() {
switch (widget.serversProvider.dnsInfo.loadStatus) { switch (dnsProvider.loadStatus) {
case 0: case LoadStatus.loading:
return SizedBox( return SizedBox(
width: double.maxFinite, width: double.maxFinite,
child: Column( child: Column(
@ -115,63 +101,43 @@ class _DnsSettingsWidgetState extends State<DnsSettingsWidget> {
) )
); );
case 1: case LoadStatus.loaded:
return ListView( return ListView(
children: [ children: [
CustomListTile( CustomListTile(
title: AppLocalizations.of(context)!.upstreamDns, title: AppLocalizations.of(context)!.upstreamDns,
subtitle: AppLocalizations.of(context)!.upstreamDnsDescription, subtitle: AppLocalizations.of(context)!.upstreamDnsDescription,
onTap: () => navigate( onTap: () => navigate(const UpstreamDnsScreen()),
UpstreamDnsScreen(
serversProvider: serversProvider
)
),
icon: Icons.upload_rounded, icon: Icons.upload_rounded,
), ),
CustomListTile( CustomListTile(
title: AppLocalizations.of(context)!.bootstrapDns, title: AppLocalizations.of(context)!.bootstrapDns,
subtitle: AppLocalizations.of(context)!.bootstrapDnsDescription, subtitle: AppLocalizations.of(context)!.bootstrapDnsDescription,
onTap: () => navigate( onTap: () => navigate(const BootstrapDnsScreen()),
BootstrapDnsScreen(
serversProvider: serversProvider
)
),
icon: Icons.dns_rounded, icon: Icons.dns_rounded,
), ),
CustomListTile( CustomListTile(
title: AppLocalizations.of(context)!.privateReverseDnsServers, title: AppLocalizations.of(context)!.privateReverseDnsServers,
subtitle: AppLocalizations.of(context)!.privateReverseDnsDescription, subtitle: AppLocalizations.of(context)!.privateReverseDnsDescription,
onTap: () => navigate( onTap: () => navigate(const PrivateReverseDnsServersScreen()),
PrivateReverseDnsServersScreen(
serversProvider: serversProvider
)
),
icon: Icons.person_rounded, icon: Icons.person_rounded,
), ),
CustomListTile( CustomListTile(
title: AppLocalizations.of(context)!.dnsServerSettings, title: AppLocalizations.of(context)!.dnsServerSettings,
subtitle: AppLocalizations.of(context)!.dnsServerSettingsDescription, subtitle: AppLocalizations.of(context)!.dnsServerSettingsDescription,
onTap: () => navigate( onTap: () => navigate(const DnsServerSettingsScreen()),
DnsServerSettingsScreen(
serversProvider: serversProvider
)
),
icon: Icons.settings, icon: Icons.settings,
), ),
CustomListTile( CustomListTile(
title: AppLocalizations.of(context)!.dnsCacheConfig, title: AppLocalizations.of(context)!.dnsCacheConfig,
subtitle: AppLocalizations.of(context)!.dnsCacheConfigDescription, subtitle: AppLocalizations.of(context)!.dnsCacheConfigDescription,
onTap: () => navigate( onTap: () => navigate(const CacheConfigDnsScreen()),
CacheConfigDnsScreen(
serversProvider: serversProvider
)
),
icon: Icons.storage_rounded, icon: Icons.storage_rounded,
), ),
], ],
); );
case 2: case LoadStatus.error:
return SizedBox( return SizedBox(
width: double.maxFinite, width: double.maxFinite,
child: Column( child: Column(

View file

@ -10,18 +10,14 @@ import 'package:adguard_home_manager/widgets/custom_switch_list_tile.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/providers/servers_provider.dart';
import 'package:adguard_home_manager/classes/process_modal.dart'; import 'package:adguard_home_manager/classes/process_modal.dart';
import 'package:adguard_home_manager/functions/snackbar.dart';
import 'package:adguard_home_manager/models/dns_info.dart'; import 'package:adguard_home_manager/models/dns_info.dart';
import 'package:adguard_home_manager/providers/dns_provider.dart';
import 'package:adguard_home_manager/functions/snackbar.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/services/http_requests.dart'; import 'package:adguard_home_manager/services/http_requests.dart';
class DnsServerSettingsScreen extends StatefulWidget { class DnsServerSettingsScreen extends StatefulWidget {
final ServersProvider serversProvider; const DnsServerSettingsScreen({Key? key}) : super(key: key);
const DnsServerSettingsScreen({
Key? key,
required this.serversProvider
}) : super(key: key);
@override @override
State<DnsServerSettingsScreen> createState() => _DnsServerSettingsScreenState(); State<DnsServerSettingsScreen> createState() => _DnsServerSettingsScreenState();
@ -89,13 +85,15 @@ class _DnsServerSettingsScreenState extends State<DnsServerSettingsScreen> {
@override @override
void initState() { void initState() {
limitRequestsController.text = widget.serversProvider.dnsInfo.data!.ratelimit.toString(); final dnsProvider = Provider.of<DnsProvider>(context, listen: false);
enableEdns = widget.serversProvider.dnsInfo.data!.ednsCsEnabled;
enableDnssec = widget.serversProvider.dnsInfo.data!.dnssecEnabled; limitRequestsController.text = dnsProvider.dnsInfo!.ratelimit.toString();
disableIpv6Resolving = widget.serversProvider.dnsInfo.data!.disableIpv6; enableEdns = dnsProvider.dnsInfo!.ednsCsEnabled;
blockingMode = widget.serversProvider.dnsInfo.data!.blockingMode; enableDnssec = dnsProvider.dnsInfo!.dnssecEnabled;
ipv4controller.text = widget.serversProvider.dnsInfo.data!.blockingIpv4; disableIpv6Resolving = dnsProvider.dnsInfo!.disableIpv6;
ipv6controller.text = widget.serversProvider.dnsInfo.data!.blockingIpv6; blockingMode = dnsProvider.dnsInfo!.blockingMode;
ipv4controller.text = dnsProvider.dnsInfo!.blockingIpv4;
ipv6controller.text = dnsProvider.dnsInfo!.blockingIpv6;
isDataValid = true; isDataValid = true;
super.initState(); super.initState();
} }
@ -103,6 +101,7 @@ class _DnsServerSettingsScreenState extends State<DnsServerSettingsScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final serversProvider = Provider.of<ServersProvider>(context); final serversProvider = Provider.of<ServersProvider>(context);
final dnsProvider = Provider.of<DnsProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(context); final appConfigProvider = Provider.of<AppConfigProvider>(context);
void saveData() async { void saveData() async {
@ -120,7 +119,7 @@ class _DnsServerSettingsScreenState extends State<DnsServerSettingsScreen> {
processModal.close(); processModal.close();
if (result['result'] == 'success') { if (result['result'] == 'success') {
DnsInfoData data = serversProvider.dnsInfo.data!; DnsInfo data = dnsProvider.dnsInfo!;
data.ratelimit = int.parse(limitRequestsController.text); data.ratelimit = int.parse(limitRequestsController.text);
data.ednsCsEnabled = enableEdns; data.ednsCsEnabled = enableEdns;
data.dnssecEnabled = enableDnssec; data.dnssecEnabled = enableDnssec;
@ -128,7 +127,7 @@ class _DnsServerSettingsScreenState extends State<DnsServerSettingsScreen> {
data.blockingMode = blockingMode; data.blockingMode = blockingMode;
data.blockingIpv4 = ipv4controller.text; data.blockingIpv4 = ipv4controller.text;
data.blockingIpv6 = ipv6controller.text; data.blockingIpv6 = ipv6controller.text;
serversProvider.setDnsInfoData(data); dnsProvider.setDnsInfoData(data);
showSnacbkar( showSnacbkar(
appConfigProvider: appConfigProvider, appConfigProvider: appConfigProvider,

View file

@ -7,6 +7,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/widgets/custom_switch_list_tile.dart'; import 'package:adguard_home_manager/widgets/custom_switch_list_tile.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/providers/servers_provider.dart';
import 'package:adguard_home_manager/providers/dns_provider.dart';
import 'package:adguard_home_manager/classes/process_modal.dart'; import 'package:adguard_home_manager/classes/process_modal.dart';
import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/functions/snackbar.dart';
import 'package:adguard_home_manager/models/dns_info.dart'; import 'package:adguard_home_manager/models/dns_info.dart';
@ -14,12 +15,7 @@ import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/services/http_requests.dart'; import 'package:adguard_home_manager/services/http_requests.dart';
class PrivateReverseDnsServersScreen extends StatefulWidget { class PrivateReverseDnsServersScreen extends StatefulWidget {
final ServersProvider serversProvider; const PrivateReverseDnsServersScreen({Key? key}) : super(key: key);
const PrivateReverseDnsServersScreen({
Key? key,
required this.serversProvider,
}) : super(key: key);
@override @override
State<PrivateReverseDnsServersScreen> createState() => _PrivateReverseDnsServersScreenState(); State<PrivateReverseDnsServersScreen> createState() => _PrivateReverseDnsServersScreenState();
@ -69,10 +65,12 @@ class _PrivateReverseDnsServersScreenState extends State<PrivateReverseDnsServer
@override @override
void initState() { void initState() {
for (var item in widget.serversProvider.dnsInfo.data!.defaultLocalPtrUpstreams) { final dnsProvider = Provider.of<DnsProvider>(context, listen: false);
for (var item in dnsProvider.dnsInfo!.defaultLocalPtrUpstreams) {
defaultReverseResolvers.add(item); defaultReverseResolvers.add(item);
} }
for (var item in widget.serversProvider.dnsInfo.data!.localPtrUpstreams) { for (var item in dnsProvider.dnsInfo!.localPtrUpstreams) {
final controller = TextEditingController(); final controller = TextEditingController();
controller.text = item; controller.text = item;
reverseResolversControllers = [{ reverseResolversControllers = [{
@ -80,11 +78,11 @@ class _PrivateReverseDnsServersScreenState extends State<PrivateReverseDnsServer
'error': null 'error': null
}]; }];
} }
if (widget.serversProvider.dnsInfo.data!.localPtrUpstreams.isNotEmpty) { if (dnsProvider.dnsInfo!.localPtrUpstreams.isNotEmpty) {
editReverseResolvers = true; editReverseResolvers = true;
} }
usePrivateReverseDnsResolvers = widget.serversProvider.dnsInfo.data!.usePrivatePtrResolvers; usePrivateReverseDnsResolvers = dnsProvider.dnsInfo!.usePrivatePtrResolvers;
enableReverseResolve = widget.serversProvider.dnsInfo.data!.resolveClients; enableReverseResolve = dnsProvider.dnsInfo!.resolveClients;
validValues = true; validValues = true;
super.initState(); super.initState();
} }
@ -92,6 +90,7 @@ class _PrivateReverseDnsServersScreenState extends State<PrivateReverseDnsServer
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final serversProvider = Provider.of<ServersProvider>(context); final serversProvider = Provider.of<ServersProvider>(context);
final dnsProvider = Provider.of<DnsProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(context); final appConfigProvider = Provider.of<AppConfigProvider>(context);
void saveData() async { void saveData() async {
@ -111,13 +110,13 @@ class _PrivateReverseDnsServersScreenState extends State<PrivateReverseDnsServer
processModal.close(); processModal.close();
if (result['result'] == 'success') { if (result['result'] == 'success') {
DnsInfoData data = serversProvider.dnsInfo.data!; DnsInfo data = dnsProvider.dnsInfo!;
if (editReverseResolvers == true) { if (editReverseResolvers == true) {
data.localPtrUpstreams = List<String>.from(reverseResolversControllers.map((e) => e['controller'].text)); data.localPtrUpstreams = List<String>.from(reverseResolversControllers.map((e) => e['controller'].text));
} }
data.usePrivatePtrResolvers = usePrivateReverseDnsResolvers; data.usePrivatePtrResolvers = usePrivateReverseDnsResolvers;
data.resolveClients = enableReverseResolve; data.resolveClients = enableReverseResolve;
serversProvider.setDnsInfoData(data); dnsProvider.setDnsInfoData(data);
showSnacbkar( showSnacbkar(
appConfigProvider: appConfigProvider, appConfigProvider: appConfigProvider,

View file

@ -12,18 +12,14 @@ import 'package:adguard_home_manager/widgets/custom_radio_list_tile.dart';
import 'package:adguard_home_manager/models/dns_info.dart'; import 'package:adguard_home_manager/models/dns_info.dart';
import 'package:adguard_home_manager/classes/process_modal.dart'; import 'package:adguard_home_manager/classes/process_modal.dart';
import 'package:adguard_home_manager/providers/dns_provider.dart';
import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/functions/snackbar.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/services/http_requests.dart'; import 'package:adguard_home_manager/services/http_requests.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/providers/servers_provider.dart';
class UpstreamDnsScreen extends StatefulWidget { class UpstreamDnsScreen extends StatefulWidget {
final ServersProvider serversProvider; const UpstreamDnsScreen({Key? key}) : super(key: key);
const UpstreamDnsScreen({
Key? key,
required this.serversProvider,
}) : super(key: key);
@override @override
State<UpstreamDnsScreen> createState() => _UpstreamDnsScreenState(); State<UpstreamDnsScreen> createState() => _UpstreamDnsScreenState();
@ -50,7 +46,9 @@ class _UpstreamDnsScreenState extends State<UpstreamDnsScreen> {
@override @override
void initState() { void initState() {
for (var item in widget.serversProvider.dnsInfo.data!.upstreamDns) { final dnsProvider = Provider.of<DnsProvider>(context, listen: false);
for (var item in dnsProvider.dnsInfo!.upstreamDns) {
if (item == '#') { if (item == '#') {
dnsServers.add({ dnsServers.add({
'comment': item 'comment': item
@ -64,7 +62,7 @@ class _UpstreamDnsScreenState extends State<UpstreamDnsScreen> {
}); });
} }
} }
upstreamMode = widget.serversProvider.dnsInfo.data!.upstreamMode; upstreamMode = dnsProvider.dnsInfo!.upstreamMode;
validValues = true; validValues = true;
super.initState(); super.initState();
} }
@ -72,6 +70,7 @@ class _UpstreamDnsScreenState extends State<UpstreamDnsScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final serversProvider = Provider.of<ServersProvider>(context); final serversProvider = Provider.of<ServersProvider>(context);
final dnsProvider = Provider.of<DnsProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(context); final appConfigProvider = Provider.of<AppConfigProvider>(context);
final width = MediaQuery.of(context).size.width; final width = MediaQuery.of(context).size.width;
@ -154,10 +153,10 @@ class _UpstreamDnsScreenState extends State<UpstreamDnsScreen> {
processModal.close(); processModal.close();
if (result['result'] == 'success') { if (result['result'] == 'success') {
DnsInfoData data = serversProvider.dnsInfo.data!; DnsInfo data = dnsProvider.dnsInfo!;
data.upstreamDns = List<String>.from(dnsServers.map((e) => e['controller'] != null ? e['controller'].text : e['comment'])); data.upstreamDns = List<String>.from(dnsServers.map((e) => e['controller'] != null ? e['controller'].text : e['comment']));
data.upstreamMode = upstreamMode; data.upstreamMode = upstreamMode;
serversProvider.setDnsInfoData(data); dnsProvider.setDnsInfoData(data);
showSnacbkar( showSnacbkar(
appConfigProvider: appConfigProvider, appConfigProvider: appConfigProvider,

View file

@ -13,7 +13,7 @@ import 'package:adguard_home_manager/services/http_requests.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/functions/snackbar.dart';
import 'package:adguard_home_manager/constants/enums.dart'; import 'package:adguard_home_manager/constants/enums.dart';
import 'package:adguard_home_manager/providers/rewrute_rules_provider.dart'; import 'package:adguard_home_manager/providers/rewrite_rules_provider.dart';
import 'package:adguard_home_manager/models/rewrite_rules.dart'; import 'package:adguard_home_manager/models/rewrite_rules.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/providers/servers_provider.dart';
import 'package:adguard_home_manager/classes/process_modal.dart'; import 'package:adguard_home_manager/classes/process_modal.dart';

View file

@ -1808,7 +1808,7 @@ Future getDnsInfo({
if (result['statusCode'] == 200) { if (result['statusCode'] == 200) {
return { return {
'result': 'success' , 'result': 'success' ,
'data': DnsInfoData.fromJson(jsonDecode(result['body'])) 'data': DnsInfo.fromJson(jsonDecode(result['body']))
}; };
} }
else { else {