mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-04 12:24:47 +00:00
Some improvements
This commit is contained in:
parent
d57572cc56
commit
c3690902c8
7 changed files with 355 additions and 393 deletions
106
lib/screens/settings/encryption/encryption_functions.dart
Normal file
106
lib/screens/settings/encryption/encryption_functions.dart
Normal file
|
@ -0,0 +1,106 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
String? validateDomain(BuildContext context, String domain) {
|
||||
RegExp regExp = RegExp(r'^([a-z0-9|-]+\.)*[a-z0-9|-]+\.[a-z]+$');
|
||||
if (regExp.hasMatch(domain)) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return AppLocalizations.of(context)!.domainNotValid;
|
||||
}
|
||||
}
|
||||
|
||||
String? validatePort(BuildContext context, String value) {
|
||||
if (int.tryParse(value) != null && int.parse(value) <= 65535) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return AppLocalizations.of(context)!.invalidPort;
|
||||
}
|
||||
}
|
||||
|
||||
String? validateCertificate(BuildContext context, String cert) {
|
||||
final regExp = RegExp(r'(-{3,}(\bBEGIN CERTIFICATE\b))|(-{3,}-{3,}(\END CERTIFICATE\b)-{3,})', multiLine: true);
|
||||
if (regExp.hasMatch(cert.replaceAll('\n', ''))) {
|
||||
return AppLocalizations.of(context)!.invalidCertificate;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String? validatePrivateKey(BuildContext context, String cert) {
|
||||
final regExp = RegExp(r'(-{3,}(\bBEGIN\b).*(PRIVATE KEY\b))|(-{3,}-{3,}(\bEND\b).*(PRIVATE KEY\b)-{3,})', multiLine: true);
|
||||
if (regExp.hasMatch(cert.replaceAll('\n', ''))) {
|
||||
return AppLocalizations.of(context)!.invalidPrivateKey;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String? validatePath(BuildContext context, String cert) {
|
||||
final regExp = RegExp(r'^(\/{0,1}(?!\/))[A-Za-z0-9\/\-_]+(\.([a-zA-Z]+))?$');
|
||||
if (regExp.hasMatch(cert)) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return AppLocalizations.of(context)!.invalidPath;
|
||||
}
|
||||
}
|
||||
|
||||
Widget generateStatus(bool localValidation, int dataValidApi) {
|
||||
if (localValidation == true) {
|
||||
if (dataValidApi == 0) {
|
||||
return const SizedBox(
|
||||
height: 25,
|
||||
width: 25,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 3,
|
||||
)
|
||||
);
|
||||
}
|
||||
else if (dataValidApi == 1) {
|
||||
return const Icon(
|
||||
Icons.check_circle_rounded,
|
||||
color: Colors.green,
|
||||
);
|
||||
}
|
||||
else if (dataValidApi == 2) {
|
||||
return const Icon(
|
||||
Icons.cancel_rounded,
|
||||
color: Colors.red,
|
||||
);
|
||||
}
|
||||
else {
|
||||
return const SizedBox();
|
||||
}
|
||||
}
|
||||
else {
|
||||
return const Icon(
|
||||
Icons.error_rounded,
|
||||
color: Colors.grey,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String generateStatusString(BuildContext context, bool localValidation, int dataValidApi) {
|
||||
if (localValidation == true) {
|
||||
if (dataValidApi == 0) {
|
||||
return AppLocalizations.of(context)!.validatingData;
|
||||
}
|
||||
else if (dataValidApi == 1) {
|
||||
return AppLocalizations.of(context)!.dataValid;
|
||||
}
|
||||
else if (dataValidApi == 2) {
|
||||
return AppLocalizations.of(context)!.dataNotValid;
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
return AppLocalizations.of(context)!.dataNotValid;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue