mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-04-22 06:49:11 +00:00
Added test upstream dns servers
This commit is contained in:
parent
3aa36c89aa
commit
c3f55e9ce9
6 changed files with 198 additions and 3 deletions
|
@ -695,5 +695,7 @@
|
|||
"resetEncryptionSettingsDescription": "Are you sure you want to reset to default values the encryption settings?",
|
||||
"resettingConfig": "Resetting configuration...",
|
||||
"configurationResetSuccessfully": "Configuration resetted successfully",
|
||||
"configurationResetError": "The configuration couldn't be resetted"
|
||||
"configurationResetError": "The configuration couldn't be resetted",
|
||||
"testUpstreamDnsServers": "Test upstream DNS servers",
|
||||
"errorTestUpstreamDns": "Error when testing upstream DNS servers."
|
||||
}
|
|
@ -695,5 +695,7 @@
|
|||
"resetEncryptionSettingsDescription": "Estás seguro que deseas restaurar a valores por defecto la configuración de encriptación?",
|
||||
"resettingConfig": "Reseteando configuración...",
|
||||
"configurationResetSuccessfully": "Configuración reseteada correctamente",
|
||||
"configurationResetError": "La configuración no ha podido ser reseteada"
|
||||
"configurationResetError": "La configuración no ha podido ser reseteada",
|
||||
"testUpstreamDnsServers": "Probar servidores DNS de subida",
|
||||
"errorTestUpstreamDns": "Error al probar los servidores DNS de subida."
|
||||
}
|
|
@ -5,6 +5,7 @@ import 'package:flutter_split_view/flutter_split_view.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/settings/dns/test_upstream_dns_modal.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/dns/clear_dns_cache_dialog.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/dns/cache_config.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/dns/dns_server_settings.dart';
|
||||
|
@ -84,6 +85,14 @@ class _DnsSettingsState extends State<DnsSettings> {
|
|||
title: Text(AppLocalizations.of(context)!.dnsSettings),
|
||||
surfaceTintColor: isDesktop(width) ? Colors.transparent : null,
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () => showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => const TestUpstreamDnsModal()
|
||||
),
|
||||
icon: const Icon(Icons.upload_rounded),
|
||||
tooltip: AppLocalizations.of(context)!.testUpstreamDnsServers,
|
||||
),
|
||||
PopupMenuButton(
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
|
|
168
lib/screens/settings/dns/test_upstream_dns_modal.dart
Normal file
168
lib/screens/settings/dns/test_upstream_dns_modal.dart
Normal file
|
@ -0,0 +1,168 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/constants/enums.dart';
|
||||
import 'package:adguard_home_manager/providers/dns_provider.dart';
|
||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||
|
||||
class _Item {
|
||||
final String url;
|
||||
final bool value;
|
||||
|
||||
const _Item({
|
||||
required this.url,
|
||||
required this.value
|
||||
});
|
||||
}
|
||||
|
||||
class TestUpstreamDnsModal extends StatefulWidget {
|
||||
const TestUpstreamDnsModal({super.key});
|
||||
|
||||
@override
|
||||
State<TestUpstreamDnsModal> createState() => _TestUpstreamDnsModalState();
|
||||
}
|
||||
|
||||
class _TestUpstreamDnsModalState extends State<TestUpstreamDnsModal> {
|
||||
LoadStatus loadStatus = LoadStatus.loading;
|
||||
List<_Item>? values;
|
||||
|
||||
void checkDns() async {
|
||||
final dnsProvider = Provider.of<DnsProvider>(context, listen: false);
|
||||
final result = await Provider.of<ServersProvider>(context, listen: false).apiClient2!.testUpstreamDns(
|
||||
body: {
|
||||
"bootstrap_dns": dnsProvider.dnsInfo!.bootstrapDns,
|
||||
"fallback_dns": [],
|
||||
"private_upstream": dnsProvider.dnsInfo!.defaultLocalPtrUpstreams,
|
||||
"upstream_dns": dnsProvider.dnsInfo!.upstreamDns
|
||||
}
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (result.successful == true) {
|
||||
setState(() {
|
||||
values = List<_Item>.from(
|
||||
(result.content as Map<String, dynamic>).entries.map((e) => _Item(
|
||||
url: e.key,
|
||||
value: e.value == "OK" ? true : false
|
||||
))
|
||||
);
|
||||
loadStatus = LoadStatus.loaded;
|
||||
});
|
||||
}
|
||||
else {
|
||||
setState(() => loadStatus = LoadStatus.error);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
checkDns();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.upload_rounded,
|
||||
size: 24,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.testUpstreamDnsServers,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSurface
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
content: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: 500
|
||||
),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
switch (loadStatus) {
|
||||
case LoadStatus.loading:
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator()
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
case LoadStatus.loaded:
|
||||
return SingleChildScrollView(
|
||||
child: Wrap(
|
||||
children: values!.map((v) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
v.url,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
...[
|
||||
const SizedBox(width: 8),
|
||||
if (v.value == true) const Icon(
|
||||
Icons.check_circle_rounded,
|
||||
color: Colors.green,
|
||||
size: 16,
|
||||
),
|
||||
if (v.value == false) const Icon(
|
||||
Icons.cancel_rounded,
|
||||
color: Colors.red,
|
||||
)
|
||||
]
|
||||
],
|
||||
),
|
||||
)).toList(),
|
||||
),
|
||||
);
|
||||
|
||||
case LoadStatus.error:
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_rounded,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
size: 30,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.errorTestUpstreamDns,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
default:
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(AppLocalizations.of(context)!.close)
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -186,7 +186,7 @@ class _UpstreamDnsScreenState extends State<UpstreamDnsScreen> {
|
|||
icon: const Icon(Icons.save_rounded),
|
||||
tooltip: AppLocalizations.of(context)!.save,
|
||||
),
|
||||
const SizedBox(width: 10)
|
||||
const SizedBox(width: 8)
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
|
|
|
@ -853,4 +853,18 @@ class ApiClientV2 {
|
|||
);
|
||||
return ApiResponse(successful: result.successful);
|
||||
}
|
||||
|
||||
Future<ApiResponse> testUpstreamDns({
|
||||
required Map<String, dynamic> body
|
||||
}) async {
|
||||
final result = await HttpRequestClient.post(
|
||||
urlPath: '/test_upstream_dns',
|
||||
server: server,
|
||||
body: body
|
||||
);
|
||||
return ApiResponse(
|
||||
successful: result.successful,
|
||||
content: result.body != null ? jsonDecode(result.body!) : null
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue