mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-04 20:30:35 +00:00
Added auth token to server modal and dns statistics request
This commit is contained in:
parent
360b6865be
commit
97e4fea015
9 changed files with 171 additions and 15 deletions
|
@ -6,6 +6,7 @@ import 'dart:io';
|
|||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'package:adguard_home_manager/models/dns_statistics.dart';
|
||||
import 'package:adguard_home_manager/models/server.dart';
|
||||
|
||||
Future login(Server server) async {
|
||||
|
@ -44,4 +45,32 @@ Future login(Server server) async {
|
|||
} catch (e) {
|
||||
return {'result': 'error'};
|
||||
}
|
||||
}
|
||||
|
||||
Future getDnsStatistics(Server server) async {
|
||||
try {
|
||||
final result = await http.get(
|
||||
Uri.parse("${server.connectionMethod}://${server.domain}${server.path ?? ""}${server.port != null ? ':${server.port}' : ""}/control/stats"),
|
||||
headers: {
|
||||
'Authorization': 'Basic ${server.authToken}'
|
||||
}
|
||||
);
|
||||
if (result.statusCode == 200) {
|
||||
return {
|
||||
'result': 'success',
|
||||
'data': DnsStatistics.fromJson(jsonDecode(result.body))
|
||||
};
|
||||
}
|
||||
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
Add a link
Reference in a new issue