Added blocked clients modal and request

This commit is contained in:
Juan Gilsanz Polo 2022-10-07 00:35:41 +02:00
parent 459d316cf3
commit acc4858ac4
8 changed files with 429 additions and 63 deletions

View file

@ -0,0 +1,37 @@
const List<String> services = [
"9Gag",
"Amazon",
"Bilibili",
"CloudFlare",
"Dailymotion",
"Discord",
"Disney+",
"EBay",
"Epic Games",
"Facebook",
"Hulu",
"Imgur",
"Instagram",
"Mail.ru",
"Netflix",
"OK.ru",
"Origin",
"Pinterest",
"QQ",
"Reddit",
"Skype",
"Snapchat",
"Spotify",
"Steam",
"Telegram",
"TikTok",
"Tinder",
"Twitch",
"Viber",
"Vimeo",
"VK.com",
"WeChat",
"Weibo",
"WhatsApp",
"YouTube"
];

View file

@ -185,5 +185,12 @@
"enableSafeSearch": "Enable safe search",
"blockedServices": "Blocked services",
"selectBlockedServices": "Select services to block",
"noBlockedServicesSelected": "No blocked services"
"noBlockedServicesSelected": "No blocked services",
"services": "Services",
"servicesBlocked": "services blocked",
"tagsSelected": "tags selected",
"upstreamServers": "Upstream servers",
"serverAddress": "Server address",
"noUpstreamServers": "No upstream servers.",
"willBeUsedGeneralServers": "General upstream servers will be used."
}

View file

@ -185,5 +185,12 @@
"enableSafeSearch": "Activar búsqueda segura",
"blockedServices": "Servicios bloqueados",
"selectBlockedServices": "Seleccionar servicios para bloquear",
"noBlockedServicesSelected": "No hay servicios bloqueados"
"noBlockedServicesSelected": "No hay servicios bloqueados",
"services": "Servicios",
"servicesBlocked": "servicios bloqueados",
"tagsSelected": "etiquetas seleccionadas",
"upstreamServers": "Servidores de salida",
"serverAddress": "Dirección del servidor",
"noUpstreamServers": "No hay servidores de salida.",
"willBeUsedGeneralServers": "Se usarán los servidores de salida generales."
}

View file

@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
import 'package:uuid/uuid.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/screens/clients/services_modal.dart';
import 'package:adguard_home_manager/screens/clients/tags_modal.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart';
@ -25,7 +26,7 @@ class _AddClientModalState extends State<AddClientModal> {
TextEditingController nameController = TextEditingController();
String? selectedTag;
List<String> selectedTags = [];
List<Map<dynamic, dynamic>> identifiersControllers = [
{
@ -41,11 +42,16 @@ class _AddClientModalState extends State<AddClientModal> {
bool? enableSafeSearch;
bool useGlobalSettingsServices = true;
List<String> blockedServices = [];
List<Map<dynamic, dynamic>> upstreamServers = [];
bool checkValidValues() {
if (
nameController.text != ''
nameController.text != '' &&
identifiersControllers.isNotEmpty &&
identifiersControllers[0]['controller'].text != ''
) {
return true;
}
@ -59,7 +65,20 @@ class _AddClientModalState extends State<AddClientModal> {
final serversProvider = Provider.of<ServersProvider>(context);
void createClient() {
final AddClient client = AddClient(
name: nameController.text,
ids: List<String>.from(identifiersControllers.map((e) => e['controller'].text)),
useGlobalSettings: useGlobalSettingsFiltering,
filteringEnabled: enableFiltering ?? false,
parentalEnabled: enableParentalControl ?? false,
safebrowsingEnabled: enableSafeBrowsing ?? false,
safesearchEnabled: enableSafeSearch ?? false,
useGlobalBlockedServices: useGlobalSettingsServices,
blockedServices: blockedServices,
upstreams: List<String>.from(upstreamServers.map((e) => e['controller'].text)),
tags: selectedTags
);
widget.onConfirm(client);
}
Widget sectionLabel(String label) {
@ -106,13 +125,37 @@ class _AddClientModalState extends State<AddClientModal> {
showDialog(
context: context,
builder: (context) => TagsModal(
selectedTag: selectedTag,
selectedTags: selectedTags,
tags: serversProvider.clients.data!.supportedTags,
onConfirm: (selected) => setState(() => selectedTag = selected),
onConfirm: (selected) => setState(() => selectedTags = selected),
)
);
}
void openServicesModal() {
showDialog(
context: context,
builder: (context) => ServicesModal(
blockedServices: blockedServices,
onConfirm: (values) => setState(() => blockedServices = values),
)
);
}
void updateServicesGlobalSettings(bool value) {
if (value == true) {
setState(() {
blockedServices = [];
useGlobalSettingsServices = true;
});
}
else if (value == false) {
setState(() {
useGlobalSettingsServices = false;
});
}
}
Widget settignsTile({
required String label,
required bool? value,
@ -196,6 +239,7 @@ class _AddClientModalState extends State<AddClientModal> {
padding: const EdgeInsets.symmetric(horizontal: 20),
child: TextFormField(
controller: nameController,
onChanged: (_) => checkValidValues(),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.badge_rounded),
border: const OutlineInputBorder(
@ -234,8 +278,8 @@ class _AddClientModalState extends State<AddClientModal> {
),
const SizedBox(height: 5),
Text(
selectedTag != null
? selectedTag!
selectedTags.isNotEmpty
? "${selectedTags.length} ${AppLocalizations.of(context)!.tagsSelected}"
: AppLocalizations.of(context)!.noTagsSelected,
style: const TextStyle(
color: Colors.grey
@ -275,6 +319,7 @@ class _AddClientModalState extends State<AddClientModal> {
width: MediaQuery.of(context).size.width - 108,
child: TextFormField(
controller: controller['controller'],
onChanged: (_) => checkValidValues(),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.tag),
border: const OutlineInputBorder(
@ -374,7 +419,7 @@ class _AddClientModalState extends State<AddClientModal> {
color: Theme.of(context).primaryColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(28),
child: InkWell(
onTap: () => setState(() => useGlobalSettingsServices = !useGlobalSettingsServices),
onTap: () => updateServicesGlobalSettings(!useGlobalSettingsServices),
borderRadius: BorderRadius.circular(28),
child: Padding(
padding: const EdgeInsets.symmetric(
@ -392,7 +437,7 @@ class _AddClientModalState extends State<AddClientModal> {
),
Switch(
value: useGlobalSettingsServices,
onChanged: (value) => setState(() => useGlobalSettingsServices = value),
onChanged: updateServicesGlobalSettings,
activeColor: Theme.of(context).primaryColor,
)
],
@ -406,7 +451,7 @@ class _AddClientModalState extends State<AddClientModal> {
color: Colors.transparent,
child: InkWell(
onTap: useGlobalSettingsServices == false
? () => {}
? openServicesModal
: null,
child: Padding(
padding: const EdgeInsets.symmetric(
@ -434,7 +479,9 @@ class _AddClientModalState extends State<AddClientModal> {
if (useGlobalSettingsServices == false) ...[
const SizedBox(height: 5),
Text(
AppLocalizations.of(context)!.noBlockedServicesSelected,
blockedServices.isNotEmpty
? "${blockedServices.length} ${AppLocalizations.of(context)!.servicesBlocked}"
: AppLocalizations.of(context)!.noBlockedServicesSelected,
style: const TextStyle(
color: Colors.grey
),
@ -447,6 +494,80 @@ class _AddClientModalState extends State<AddClientModal> {
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
sectionLabel(AppLocalizations.of(context)!.upstreamServers),
Padding(
padding: const EdgeInsets.only(right: 20),
child: IconButton(
onPressed: () => setState(() => upstreamServers.add({
'id': uuid.v4(),
'controller': TextEditingController()
})),
icon: const Icon(Icons.add)
),
)
],
),
if (upstreamServers.isNotEmpty) ...upstreamServers.map((controller) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: MediaQuery.of(context).size.width - 108,
child: TextFormField(
controller: controller['controller'],
onChanged: (_) => checkValidValues(),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.dns_rounded),
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10)
)
),
labelText: AppLocalizations.of(context)!.serverAddress,
),
),
),
const SizedBox(width: 20),
IconButton(
onPressed: () => setState(
() => upstreamServers = upstreamServers.where((e) => e['id'] != controller['id']).toList()
),
icon: const Icon(Icons.remove_circle_outline_outlined)
)
],
),
),
)).toList(),
if (upstreamServers.isEmpty) Container(
padding: const EdgeInsets.only(top: 10),
child: Column(
children: [
Text(
AppLocalizations.of(context)!.noUpstreamServers,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 18,
color: Colors.grey
),
),
const SizedBox(height: 10),
Text(
AppLocalizations.of(context)!.willBeUsedGeneralServers,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 15,
color: Colors.grey
),
),
],
),
),
],
),
),
@ -462,7 +583,10 @@ class _AddClientModalState extends State<AddClientModal> {
const SizedBox(width: 20),
TextButton(
onPressed: checkValidValues() == true
? createClient
? () {
createClient();
Navigator.pop(context);
}
: null,
child: Text(
AppLocalizations.of(context)!.confirm,

View file

@ -74,8 +74,31 @@ class ClientsFab extends StatelessWidget {
}
}
void confirmAddClient(AddClient client) {
void confirmAddClient(AddClient client) async {
ProcessModal processModal = ProcessModal(context: context);
processModal.open(AppLocalizations.of(context)!.addingClient);
final result = await postAddClient(server: serversProvider.selectedServer!, data: client.toJson());
processModal.close();
if (result['result'] == 'success') {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(AppLocalizations.of(context)!.clientAddedSuccessfully),
backgroundColor: Colors.green,
)
);
}
else {
appConfigProvider.addLog(result['log']);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(AppLocalizations.of(context)!.clientNotAdded),
backgroundColor: Colors.red,
)
);
}
}
void openBlockClient() {

View file

@ -0,0 +1,105 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/constants/services.dart';
class ServicesModal extends StatefulWidget {
final List<String> blockedServices;
final void Function(List<String>) onConfirm;
const ServicesModal({
Key? key,
required this.blockedServices,
required this.onConfirm,
}) : super(key: key);
@override
State<ServicesModal> createState() => _ServicesModalState();
}
class _ServicesModalState extends State<ServicesModal> {
List<String> blockedServices = [];
@override
void initState() {
blockedServices = widget.blockedServices;
super.initState();
}
void checkUncheckService(bool value, String service) {
if (value == true) {
setState(() {
blockedServices.add(service);
});
}
else if (value == false) {
setState(() {
blockedServices = blockedServices.where((s) => s != service).toList();
});
}
}
@override
Widget build(BuildContext context) {
return AlertDialog(
scrollable: true,
contentPadding: const EdgeInsets.symmetric(
horizontal: 0,
vertical: 20
),
title: Column(
children: [
const Icon(Icons.public),
const SizedBox(height: 20),
Text(AppLocalizations.of(context)!.services)
],
),
content: SizedBox(
width: double.minPositive,
height: MediaQuery.of(context).size.height*0.5,
child: ListView.builder(
shrinkWrap: true,
itemCount: services.length,
itemBuilder: (context, index) => CheckboxListTile(
title: Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
services[index],
style: const TextStyle(
fontWeight: FontWeight.normal
),
),
),
value: blockedServices.contains(services[index]),
checkboxShape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5)
),
onChanged: (value) => checkUncheckService(value!, services[index])
)
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(AppLocalizations.of(context)!.cancel)
),
TextButton(
onPressed: blockedServices.isNotEmpty
? () {
widget.onConfirm(blockedServices);
Navigator.pop(context);
}
: null,
child: Text(
AppLocalizations.of(context)!.confirm,
style: TextStyle(
color: blockedServices.isNotEmpty
? Theme.of(context).primaryColor
: Colors.grey
),
)
),
],
);
}
}

View file

@ -2,13 +2,13 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class TagsModal extends StatefulWidget {
final String? selectedTag;
final List<String> selectedTags;
final List<String> tags;
final void Function(String) onConfirm;
final void Function(List<String>) onConfirm;
const TagsModal({
Key? key,
this.selectedTag,
required this.selectedTags,
required this.tags,
required this.onConfirm,
}) : super(key: key);
@ -18,16 +18,29 @@ class TagsModal extends StatefulWidget {
}
class _TagsModalState extends State<TagsModal> {
String? selectedTag;
List<String> selectedTags = [];
@override
void initState() {
selectedTag = widget.selectedTag;
selectedTags = widget.selectedTags;
super.initState();
}
@override
Widget build(BuildContext context) {
void checkUncheckTag(bool value, String tag) {
if (value == true) {
setState(() {
selectedTags.add(tag);
});
}
else if (value == false) {
setState(() {
selectedTags = selectedTags.where((s) => s != tag).toList();
});
}
}
return AlertDialog(
scrollable: true,
contentPadding: const EdgeInsets.symmetric(
@ -47,16 +60,18 @@ class _TagsModalState extends State<TagsModal> {
child: ListView.builder(
shrinkWrap: true,
itemCount: widget.tags.length,
itemBuilder: (context, index) => RadioListTile(
itemBuilder: (context, index) => CheckboxListTile(
title: Text(
widget.tags[index],
style: const TextStyle(
fontWeight: FontWeight.normal
),
),
value: widget.tags[index],
groupValue: selectedTag,
onChanged: (value) => setState(() => selectedTag = value)
value: selectedTags.contains(widget.tags[index]),
checkboxShape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5)
),
onChanged: (value) => checkUncheckTag(value!, widget.tags[index])
)
),
),
@ -66,16 +81,16 @@ class _TagsModalState extends State<TagsModal> {
child: Text(AppLocalizations.of(context)!.cancel)
),
TextButton(
onPressed: selectedTag != null
onPressed: selectedTags.isNotEmpty
? () {
widget.onConfirm(selectedTag!);
widget.onConfirm(selectedTags);
Navigator.pop(context);
}
: null,
child: Text(
AppLocalizations.of(context)!.confirm,
style: TextStyle(
color: selectedTag != null
color: selectedTags.isNotEmpty
? Theme.of(context).primaryColor
: Colors.grey
),

View file

@ -17,7 +17,8 @@ Future<Map<String, dynamic>> apiRequest({
required Server server,
required String method,
required String urlPath,
Map<String, dynamic>? body
Map<String, dynamic>? body,
required String type,
}) async {
try {
HttpClient httpClient = HttpClient();
@ -77,7 +78,7 @@ Future<Map<String, dynamic>> apiRequest({
return {
'result': 'no_connection',
'log': AppLog(
type: 'login',
type: type,
dateTime: DateTime.now(),
message: 'SocketException'
)
@ -86,7 +87,7 @@ Future<Map<String, dynamic>> apiRequest({
return {
'result': 'no_connection',
'log': AppLog(
type: 'login',
type: type,
dateTime: DateTime.now(),
message: 'TimeoutException'
)
@ -96,7 +97,7 @@ Future<Map<String, dynamic>> apiRequest({
'result': 'ssl_error',
'message': 'HandshakeException',
'log': AppLog(
type: 'login',
type: type,
dateTime: DateTime.now(),
message: 'TimeoutException'
)
@ -105,7 +106,7 @@ Future<Map<String, dynamic>> apiRequest({
return {
'result': 'error',
'log': AppLog(
type: 'login',
type: type,
dateTime: DateTime.now(),
message: e.toString()
)
@ -121,7 +122,8 @@ Future login(Server server) async {
body: {
"name": server.user,
"password": server.password
}
},
type: 'login'
);
if (result['hasResponse'] == true) {
@ -135,7 +137,7 @@ Future login(Server server) async {
type: 'login',
dateTime: DateTime.now(),
message: 'invalid_username_password',
statusCode: result['statusCode'],
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};
@ -147,7 +149,7 @@ Future login(Server server) async {
type: 'login',
dateTime: DateTime.now(),
message: 'many_attempts',
statusCode: result['statusCode'],
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};
@ -159,7 +161,7 @@ Future login(Server server) async {
type: 'login',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'],
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};
@ -172,12 +174,12 @@ Future login(Server server) async {
Future getServerStatus(Server server) async {
final result = await Future.wait([
apiRequest(server: server, method: 'get', urlPath: '/stats'),
apiRequest(server: server, method: 'get', urlPath: '/status'),
apiRequest(server: server, method: 'get', urlPath: '/filtering/status'),
apiRequest(server: server, method: 'get', urlPath: '/safesearch/status'),
apiRequest(server: server, method: 'get', urlPath: '/safebrowsing/status'),
apiRequest(server: server, method: 'get', urlPath: '/parental/status'),
apiRequest(server: server, method: 'get', urlPath: '/stats', type: 'server_status'),
apiRequest(server: server, method: 'get', urlPath: '/status', type: 'server_status'),
apiRequest(server: server, method: 'get', urlPath: '/filtering/status', type: 'server_status'),
apiRequest(server: server, method: 'get', urlPath: '/safesearch/status', type: 'server_status'),
apiRequest(server: server, method: 'get', urlPath: '/safebrowsing/status', type: 'server_status'),
apiRequest(server: server, method: 'get', urlPath: '/parental/status', type: 'server_status'),
]);
if (
@ -243,7 +245,8 @@ Future updateFiltering(Server server, bool enable) async {
server: server,
body: {
'enabled': enable
}
},
type: 'update_filtering'
);
if (result['hasResponse'] == true) {
@ -254,10 +257,10 @@ Future updateFiltering(Server server, bool enable) async {
return {
'result': 'error',
'log': AppLog(
type: 'login',
type: 'update_filtering',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'],
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};
@ -274,11 +277,13 @@ Future updateSafeSearch(Server server, bool enable) async {
urlPath: '/safesearch/enable',
method: 'post',
server: server,
type: 'enable_safe_search'
)
: await apiRequest(
urlPath: '/safesearch/disable',
method: 'post',
server: server,
type: 'disable_safe_search'
);
if (result['hasResponse'] == true) {
@ -289,10 +294,10 @@ Future updateSafeSearch(Server server, bool enable) async {
return {
'result': 'error',
'log': AppLog(
type: 'login',
type: 'safe_search',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'],
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};
@ -309,11 +314,13 @@ Future updateSafeBrowsing(Server server, bool enable) async {
urlPath: '/safebrowsing/enable',
method: 'post',
server: server,
type: 'enable_safe_browsing'
)
: await apiRequest(
urlPath: '/safebrowsing/disable',
method: 'post',
server: server,
type: 'disable_safe_browsing'
);
if (result['hasResponse'] == true) {
@ -324,10 +331,10 @@ Future updateSafeBrowsing(Server server, bool enable) async {
return {
'result': 'error',
'log': AppLog(
type: 'login',
type: 'safe_browsing',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'],
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};
@ -344,11 +351,13 @@ Future updateParentalControl(Server server, bool enable) async {
urlPath: '/parental/enable',
method: 'post',
server: server,
type: 'enable_parental_control'
)
: await apiRequest(
urlPath: '/parental/disable',
method: 'post',
server: server,
type: 'disable_parental_control'
);
if (result['hasResponse'] == true) {
@ -359,10 +368,10 @@ Future updateParentalControl(Server server, bool enable) async {
return {
'result': 'error',
'log': AppLog(
type: 'login',
type: 'parental_control',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'],
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};
@ -381,6 +390,7 @@ Future updateGeneralProtection(Server server, bool enable) async {
body: {
'protection_enabled': enable
},
type: 'general_protection'
);
if (result['hasResponse'] == true) {
@ -391,10 +401,10 @@ Future updateGeneralProtection(Server server, bool enable) async {
return {
'result': 'error',
'log': AppLog(
type: 'login',
type: 'general_protection',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'],
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};
@ -407,8 +417,8 @@ Future updateGeneralProtection(Server server, bool enable) async {
Future getClients(Server server) async {
final result = await Future.wait([
apiRequest(server: server, method: 'get', urlPath: '/clients'),
apiRequest(server: server, method: 'get', urlPath: '/access/list'),
apiRequest(server: server, method: 'get', urlPath: '/clients', type: 'get_clients'),
apiRequest(server: server, method: 'get', urlPath: '/access/list', type: 'get_clients'),
]);
if (result[0]['hasResponse'] == true && result[1]['hasResponse'] == true) {
@ -453,6 +463,7 @@ Future requestAllowedBlockedClientsHosts(Server server, Map<String, List<String>
method: 'post',
server: server,
body: body,
type: 'get_clients'
);
if (result['hasResponse'] == true) {
@ -469,10 +480,10 @@ Future requestAllowedBlockedClientsHosts(Server server, Map<String, List<String>
return {
'result': 'error',
'log': AppLog(
type: 'login',
type: 'get_clients',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'],
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};
@ -494,7 +505,8 @@ Future getLogs({
final result = await apiRequest(
server: server,
method: 'get',
urlPath: '/querylog?limit=$count${offset != null ? '&offset=$offset' : ''}${olderThan != null ? '&older_than=${olderThan.toIso8601String()}' : ''}${responseStatus != null ? '&response_status=$responseStatus' : ''}${search != null ? '&search=$search' : ''}'
urlPath: '/querylog?limit=$count${offset != null ? '&offset=$offset' : ''}${olderThan != null ? '&older_than=${olderThan.toIso8601String()}' : ''}${responseStatus != null ? '&response_status=$responseStatus' : ''}${search != null ? '&search=$search' : ''}',
type: 'get_logs'
);
if (result['hasResponse'] == true) {
@ -508,7 +520,7 @@ Future getLogs({
return {
'result': 'error',
'log': AppLog(
type: 'logs',
type: 'get_logs',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'].toString(),
@ -528,7 +540,8 @@ Future getFilteringRules({
final result = await apiRequest(
server: server,
method: 'get',
urlPath: '/filtering/status'
urlPath: '/filtering/status',
type: 'get_filtering_rules'
);
if (result['hasResponse'] == true) {
@ -542,7 +555,7 @@ Future getFilteringRules({
return {
'result': 'error',
'log': AppLog(
type: 'logs',
type: 'get_filtering_rules',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'].toString(),
@ -565,6 +578,7 @@ Future postFilteringRules({
method: 'post',
server: server,
body: data,
type: 'post_filering_rules'
);
if (result['hasResponse'] == true) {
@ -575,10 +589,44 @@ Future postFilteringRules({
return {
'result': 'error',
'log': AppLog(
type: 'login',
type: 'post_filtering_rules',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'],
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};
}
}
else {
return result;
}
}
Future postAddClient({
required Server server,
required Map<String, dynamic> data,
}) async {
final result = await apiRequest(
urlPath: '/clients/add',
method: 'post',
server: server,
body: data,
type: 'add_client'
);
if (result['hasResponse'] == true) {
if (result['statusCode'] == 200) {
return {'result': 'success'};
}
else {
return {
'result': 'error',
'log': AppLog(
type: 'add_client',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result['statusCode'].toString(),
resBody: result['body']
)
};