mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-04 20:30:35 +00:00
Added server info screen
This commit is contained in:
parent
da14ed6bd7
commit
c78ae81122
8 changed files with 368 additions and 3 deletions
|
@ -247,5 +247,21 @@
|
|||
"listDeleted": "List deleted successfully",
|
||||
"listNotDeleted": "The list couldn't be deleted",
|
||||
"deleteList": "Delete list",
|
||||
"deleteListMessage": "Are you sure you want to delete this list? This action can't be reverted."
|
||||
"deleteListMessage": "Are you sure you want to delete this list? This action can't be reverted.",
|
||||
"serverSettings": "Server settings",
|
||||
"serverInformation": "Server information",
|
||||
"serverInformationDescription": "Server information and status",
|
||||
"loadingServerInfo": "Loading server information...",
|
||||
"serverInfoNotLoaded": "Server information couldn't be loaded.",
|
||||
"dnsAddresses": "DNS addresses",
|
||||
"seeDnsAddresses": "See DNS addresses",
|
||||
"dnsPort": "DNS port",
|
||||
"httpPort": "HTTP port",
|
||||
"protectionEnabled": "Protection enabled",
|
||||
"dhcpAvailable": "DHCP available",
|
||||
"serverRunning": "Server running",
|
||||
"serverVersion": "Server version",
|
||||
"serverLanguage": "Server language",
|
||||
"yes": "Yes",
|
||||
"no": "No"
|
||||
}
|
|
@ -247,5 +247,21 @@
|
|||
"listDeleted": "Lista eliminada correctamente",
|
||||
"listNotDeleted": "La lista no pudo ser eliminada",
|
||||
"deleteList": "Eliminar lista",
|
||||
"deleteListMessage": "¿Estás seguro que deseas eliminar esta lista? Esta acción no se puede revertir."
|
||||
"deleteListMessage": "¿Estás seguro que deseas eliminar esta lista? Esta acción no se puede revertir.",
|
||||
"serverSettings": "Ajustes del servidor",
|
||||
"serverInformation": "Información del servidor",
|
||||
"serverInformationDescription": "Información del servidor y estado",
|
||||
"loadingServerInfo": "Cargando información del servidor...",
|
||||
"serverInfoNotLoaded": "No se ha podido cargar la información del servidor.",
|
||||
"dnsAddresses": "Direcciones DNS",
|
||||
"seeDnsAddresses": "Ver direcciones DNS",
|
||||
"dnsPort": "Puerto DNS",
|
||||
"httpPort": "Puerto HTTP",
|
||||
"protectionEnabled": "Protección activada",
|
||||
"dhcpAvailable": "DHCP disponible",
|
||||
"serverRunning": "Servidor en ejecución",
|
||||
"serverVersion": "Versión del servidor",
|
||||
"serverLanguage": "Idioma del servidor",
|
||||
"yes": "Sí",
|
||||
"no": "No"
|
||||
}
|
60
lib/models/server_info.dart
Normal file
60
lib/models/server_info.dart
Normal file
|
@ -0,0 +1,60 @@
|
|||
import 'dart:convert';
|
||||
|
||||
class ServerInfo {
|
||||
int loadStatus = 0;
|
||||
ServerInfoData? data;
|
||||
|
||||
ServerInfo({
|
||||
required this.loadStatus,
|
||||
this.data
|
||||
});
|
||||
}
|
||||
|
||||
ServerInfoData serverInfoDataFromJson(String str) => ServerInfoData.fromJson(json.decode(str));
|
||||
|
||||
String serverInfoDataToJson(ServerInfoData data) => json.encode(data.toJson());
|
||||
|
||||
class ServerInfoData {
|
||||
final List<String> dnsAddresses;
|
||||
final int dnsPort;
|
||||
final int httpPort;
|
||||
final bool protectionEnabled;
|
||||
final bool dhcpAvailable;
|
||||
final bool running;
|
||||
final String version;
|
||||
final String language;
|
||||
|
||||
ServerInfoData({
|
||||
required this.dnsAddresses,
|
||||
required this.dnsPort,
|
||||
required this.httpPort,
|
||||
required this.protectionEnabled,
|
||||
required this.dhcpAvailable,
|
||||
required this.running,
|
||||
required this.version,
|
||||
required this.language,
|
||||
});
|
||||
|
||||
|
||||
factory ServerInfoData.fromJson(Map<String, dynamic> json) => ServerInfoData(
|
||||
dnsAddresses: List<String>.from(json["dns_addresses"].map((x) => x)),
|
||||
dnsPort: json["dns_port"],
|
||||
httpPort: json["http_port"],
|
||||
protectionEnabled: json["protection_enabled"],
|
||||
dhcpAvailable: json["dhcp_available"],
|
||||
running: json["running"],
|
||||
version: json["version"],
|
||||
language: json["language"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"dns_addresses": List<dynamic>.from(dnsAddresses.map((x) => x)),
|
||||
"dns_port": dnsPort,
|
||||
"http_port": httpPort,
|
||||
"protection_enabled": protectionEnabled,
|
||||
"dhcp_available": dhcpAvailable,
|
||||
"running": running,
|
||||
"version": version,
|
||||
"language": language,
|
||||
};
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:adguard_home_manager/widgets/bottom_nav_bar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
|
40
lib/screens/settings/dns_addresses_modal.dart
Normal file
40
lib/screens/settings/dns_addresses_modal.dart
Normal file
|
@ -0,0 +1,40 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
class DnsAddressesModal extends StatelessWidget {
|
||||
final List<String> dnsAddresses;
|
||||
|
||||
const DnsAddressesModal({
|
||||
Key? key,
|
||||
required this.dnsAddresses,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Column(
|
||||
children: [
|
||||
const Icon(Icons.route_rounded),
|
||||
const SizedBox(height: 20),
|
||||
Text(AppLocalizations.of(context)!.dnsAddresses)
|
||||
],
|
||||
),
|
||||
content: SizedBox(
|
||||
height: dnsAddresses.length*56 < 500
|
||||
? dnsAddresses.length*56 : 500,
|
||||
width: double.minPositive,
|
||||
child: ListView(
|
||||
children: dnsAddresses.map((address) => ListTile(
|
||||
title: Text(address),
|
||||
)).toList(),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(AppLocalizations.of(context)!.close)
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
184
lib/screens/settings/server_info.dart
Normal file
184
lib/screens/settings/server_info.dart
Normal file
|
@ -0,0 +1,184 @@
|
|||
import 'package:animations/animations.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/settings/custom_list_tile.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/dns_addresses_modal.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/models/server_info.dart';
|
||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||
|
||||
class ServerInformation extends StatelessWidget {
|
||||
const ServerInformation({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serversProvider = Provider.of<ServersProvider>(context);
|
||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||
|
||||
return ServerInformationWidget(
|
||||
serversProvider: serversProvider,
|
||||
appConfigProvider: appConfigProvider,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ServerInformationWidget extends StatefulWidget {
|
||||
final ServersProvider serversProvider;
|
||||
final AppConfigProvider appConfigProvider;
|
||||
|
||||
const ServerInformationWidget({
|
||||
Key? key,
|
||||
required this.serversProvider,
|
||||
required this.appConfigProvider,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ServerInformationWidget> createState() => _ServerInformationWidgetState();
|
||||
}
|
||||
|
||||
class _ServerInformationWidgetState extends State<ServerInformationWidget> {
|
||||
ServerInfo serverInfo = ServerInfo(loadStatus: 0);
|
||||
|
||||
void fetchServerInfo() async {
|
||||
final result = await getServerInfo(server: widget.serversProvider.selectedServer!);
|
||||
if (mounted) {
|
||||
if (result['result'] == 'success') {
|
||||
setState(() {
|
||||
serverInfo.loadStatus = 1;
|
||||
serverInfo.data = result['data'];
|
||||
});
|
||||
}
|
||||
else {
|
||||
widget.appConfigProvider.addLog(result['log']);
|
||||
setState(() => serverInfo.loadStatus = 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
fetchServerInfo();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget generateBody() {
|
||||
switch (serverInfo.loadStatus) {
|
||||
case 0:
|
||||
return SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 30),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.loadingServerInfo,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
case 1:
|
||||
return ListView(
|
||||
children: [
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.dnsAddresses,
|
||||
description: AppLocalizations.of(context)!.seeDnsAddresses,
|
||||
onTap: () {
|
||||
showModal(
|
||||
context: context,
|
||||
builder: (context) => DnsAddressesModal(
|
||||
dnsAddresses: serverInfo.data!.dnsAddresses
|
||||
)
|
||||
);
|
||||
},
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.dnsPort,
|
||||
description: serverInfo.data!.dnsPort.toString(),
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.httpPort,
|
||||
description: serverInfo.data!.httpPort.toString(),
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.protectionEnabled,
|
||||
description: serverInfo.data!.protectionEnabled == true
|
||||
? AppLocalizations.of(context)!.yes
|
||||
: AppLocalizations.of(context)!.no,
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.dhcpAvailable,
|
||||
description: serverInfo.data!.dhcpAvailable == true
|
||||
? AppLocalizations.of(context)!.yes
|
||||
: AppLocalizations.of(context)!.no,
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.serverRunning,
|
||||
description: serverInfo.data!.running == true
|
||||
? AppLocalizations.of(context)!.yes
|
||||
: AppLocalizations.of(context)!.no,
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.serverVersion,
|
||||
description: serverInfo.data!.version,
|
||||
),
|
||||
CustomListTile(
|
||||
label: AppLocalizations.of(context)!.serverLanguage,
|
||||
description: serverInfo.data!.language,
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
case 2:
|
||||
return SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
size: 50,
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.serverInfoNotLoaded,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
color: Colors.grey,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
default:
|
||||
return const SizedBox();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.serverInformation),
|
||||
),
|
||||
body: generateBody()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|||
|
||||
import 'package:adguard_home_manager/screens/settings/theme_modal.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/custom_list_tile.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/server_info.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/section_label.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/appbar.dart';
|
||||
import 'package:adguard_home_manager/screens/servers/servers.dart';
|
||||
|
@ -83,6 +84,19 @@ class Settings extends StatelessWidget {
|
|||
appBar: const SettingsAppBar(),
|
||||
body: ListView(
|
||||
children: [
|
||||
SectionLabel(label: AppLocalizations.of(context)!.serverSettings),
|
||||
CustomListTile(
|
||||
leadingIcon: Icons.info_rounded,
|
||||
label: AppLocalizations.of(context)!.serverInformation,
|
||||
description: AppLocalizations.of(context)!.serverInformationDescription,
|
||||
onTap: () => {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ServerInformation()
|
||||
)
|
||||
)
|
||||
},
|
||||
),
|
||||
SectionLabel(label: AppLocalizations.of(context)!.appSettings),
|
||||
CustomListTile(
|
||||
leadingIcon: Icons.light_mode_rounded,
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:adguard_home_manager/models/filtering.dart';
|
|||
import 'package:adguard_home_manager/models/logs.dart';
|
||||
import 'package:adguard_home_manager/models/filtering_status.dart';
|
||||
import 'package:adguard_home_manager/models/app_log.dart';
|
||||
import 'package:adguard_home_manager/models/server_info.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_allowed_blocked.dart';
|
||||
|
@ -880,3 +881,38 @@ Future deleteFilterList({
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Future getServerInfo({
|
||||
required Server server,
|
||||
}) async {
|
||||
final result = await apiRequest(
|
||||
urlPath: '/status',
|
||||
method: 'get',
|
||||
server: server,
|
||||
type: 'server_info'
|
||||
);
|
||||
|
||||
if (result['hasResponse'] == true) {
|
||||
if (result['statusCode'] == 200) {
|
||||
return {
|
||||
'result': 'success',
|
||||
'data': ServerInfoData.fromJson(jsonDecode(result['body']))
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {
|
||||
'result': 'error',
|
||||
'log': AppLog(
|
||||
type: 'server_info',
|
||||
dateTime: DateTime.now(),
|
||||
message: 'error_code_not_expected',
|
||||
statusCode: result['statusCode'].toString(),
|
||||
resBody: result['body']
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue